35 #include <sys/types.h>
47 static uint8_t adc0_channels[] = {ADC0_CHANNELS};
50 .channels = adc0_channels,
51 .channels_cnt = ADC0_CHANNELS_CNT,
52 .buf_length = ADC0_BUF_LENGTH
62 .channels_cnt = ADC1_CHANNELS_CNT,
63 .buf_length = ADC1_BUF_LENGTH
117 if(asprintf(&temp,
"/dev/iio:device%d", adc->
dev_id) < 0) {
122 int fd = open(temp, O_RDONLY | O_NONBLOCK);
135 int ret = read(
fd, buf, size);
155 sprintf(filename,
"scan_elemens/in_voltage%d_en", adc->
channels[i]);
173 if (asprintf(&temp,
"/sys/bus/iio/devices/iio:device%d/%s", dev_id, filename) < 0) {
178 FILE *
fd = fopen(temp,
"w");
186 fprintf(
fd,
"%d",
val);
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
void adc_init(void)
Adc init.
int adc_read(struct adc_t *adc, uint16_t *buf, uint16_t size)
Read the ADC buffer from the driver.
static void adc_dev_init(struct adc_t *adc)
Initialize an ADC device.
void adc_enable(struct adc_t *adc, uint8_t value)
Start or stop the ADC readings.
static void write_sysfs_int(uint8_t dev_id, char *filename, int val)
Write an int to a sysfs file.
uint16_t buf_length
ADC buffer length.
uint8_t * channels
Channels used in the iio device.
uint8_t dev_id
The iio device ID.
uint8_t channels_cnt
Amount of channels.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.