2016-01-11 12:45:09 -04:00
|
|
|
#pragma once
|
2015-08-20 09:21:26 -03:00
|
|
|
|
|
|
|
#include "AP_HAL_Linux.h"
|
2015-12-30 19:38:56 -04:00
|
|
|
|
2015-08-20 09:21:26 -03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-01-07 12:37:46 -04:00
|
|
|
#define IIO_ANALOG_IN_COUNT 8
|
|
|
|
#define IIO_ANALOG_IN_DIR "/sys/bus/iio/devices/iio:device0/"
|
2016-02-17 23:09:50 -04:00
|
|
|
|
2016-01-25 15:13:48 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF
|
|
|
|
// Note that echo BB-ADC cape should be loaded
|
|
|
|
#define IIO_VOLTAGE_SCALING 0.00142602816
|
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
2016-02-16 15:41:58 -04:00
|
|
|
#define IIO_VOLTAGE_SCALING 3.0*1.8/4095.0
|
2017-12-16 14:59:09 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
|
2018-02-22 15:36:35 -04:00
|
|
|
#define IIO_VOLTAGE_SCALING 1.8/4095.0
|
2017-12-13 15:35:47 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
|
|
|
|
#define IIO_VOLTAGE_SCALING 3.0*1.8/4095.0
|
2016-01-07 12:37:46 -04:00
|
|
|
#else
|
2016-01-25 15:13:48 -04:00
|
|
|
#define IIO_VOLTAGE_SCALING 1.0
|
2016-01-07 12:37:46 -04:00
|
|
|
#endif
|
2015-08-20 09:21:26 -03:00
|
|
|
|
2016-01-11 12:48:07 -04:00
|
|
|
class AnalogSource_IIO : public AP_HAL::AnalogSource {
|
2015-08-20 09:21:26 -03:00
|
|
|
public:
|
2016-01-11 12:48:07 -04:00
|
|
|
friend class AnalogIn_IIO;
|
2016-01-25 15:13:48 -04:00
|
|
|
AnalogSource_IIO(int16_t pin, float initial_value, float voltage_scaling);
|
2019-02-21 19:08:12 -04:00
|
|
|
float read_average() override;
|
|
|
|
float read_latest() override;
|
2021-09-22 16:48:45 -03:00
|
|
|
bool set_pin(uint8_t p) override;
|
2019-02-21 19:08:12 -04:00
|
|
|
float voltage_average() override;
|
|
|
|
float voltage_latest() override;
|
|
|
|
float voltage_average_ratiometric() override { return voltage_average(); }
|
2015-08-20 09:21:26 -03:00
|
|
|
private:
|
|
|
|
float _value;
|
|
|
|
float _latest;
|
|
|
|
float _sum_value;
|
2016-01-25 15:13:48 -04:00
|
|
|
float _voltage_scaling;
|
2015-08-20 09:21:26 -03:00
|
|
|
uint8_t _sum_count;
|
|
|
|
int16_t _pin;
|
2016-01-11 12:45:09 -04:00
|
|
|
int _pin_fd;
|
2016-01-07 14:22:50 -04:00
|
|
|
int fd_analog_sources[IIO_ANALOG_IN_COUNT];
|
2018-10-11 20:35:32 -03:00
|
|
|
HAL_Semaphore _semaphore;
|
2015-08-20 09:21:26 -03:00
|
|
|
|
2016-01-07 13:52:53 -04:00
|
|
|
void init_pins(void);
|
2016-01-07 14:22:50 -04:00
|
|
|
void select_pin(void);
|
2015-08-20 09:21:26 -03:00
|
|
|
|
2016-01-25 15:13:48 -04:00
|
|
|
static const char *analog_sources[];
|
2015-08-20 09:21:26 -03:00
|
|
|
};
|
|
|
|
|
2016-01-11 12:48:07 -04:00
|
|
|
class AnalogIn_IIO : public AP_HAL::AnalogIn {
|
2015-08-20 09:21:26 -03:00
|
|
|
public:
|
2016-01-11 12:48:07 -04:00
|
|
|
AnalogIn_IIO();
|
2019-02-21 19:08:12 -04:00
|
|
|
void init() override;
|
|
|
|
AP_HAL::AnalogSource* channel(int16_t n) override;
|
2015-08-20 09:21:26 -03:00
|
|
|
|
|
|
|
// we don't yet know how to get the board voltage
|
2019-02-21 19:08:12 -04:00
|
|
|
float board_voltage(void) override { return 5.0f; }
|
2015-08-20 09:21:26 -03:00
|
|
|
};
|