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);
void adc_enable(struct adc_t *adc, uint8_t value)
Start or stop the ADC readings.
uint16_t buf_length
ADC buffer length.
int adc_read(struct adc_t *adc, uint16_t *buf, uint16_t size)
Read the ADC buffer from the driver.
static void write_sysfs_int(uint8_t dev_id, char *filename, int val)
Write an int to a sysfs file.
uint8_t channels_cnt
Amount of channels.
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
uint8_t * channels
Channels used in the iio device.
static void adc_dev_init(struct adc_t *adc)
Initialize an ADC device.
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
uint8_t dev_id
The iio device ID.
void adc_init(void)
Initialize the ADC.