6#include "dawn/porting/adc.hxx"
10#include <nuttx/analog/adc.h>
11#include <nuttx/analog/ioctl.h>
15#include "dawn/debug.hxx"
16#include "dawn/porting/config.hxx"
26int adc_open(
const char *path)
30 fd = open(path, O_RDWR);
31 DAWNINFO(
"ADC: open %s %d\n", path, fd);
34 DAWNERR(
"Failed to open ADC file %s (error %d)\n", path, errno);
56int adc_get_nchans(
int fd)
59 ret = ioctl(fd, ANIOC_GET_NCHANNELS,
nullptr);
67 if (CONFIG_ADC_FIFOSIZE <= ret)
69 DAWNERR(
"ADC channel count %d exceeds FIFO size %d\n", ret, CONFIG_ADC_FIFOSIZE);
84 ret = ioctl(fd, ANIOC_TRIGGER, 0);
87 DAWNERR(
"ANIOC_TRIGGER failed %d\n", errno);
102 ret = ioctl(fd, ANIOC_STOP, 0);
110 DAWNERR(
"ANIOC_STOP failed %d\n", errno);
121int adc_set_timer_freq(
int fd, uint32_t freq_hz)
125 ret = ioctl(fd, ANIOC_SET_TIMER_FREQ, freq_hz);
133 DAWNERR(
"ANIOC_SET_TIMER_FREQ failed %d\n", errno);
144int adc_get_samples_count(
int fd)
148 ret = ioctl(fd, ANIOC_SAMPLES_ON_READ, 0);
174 ret = read(fd, adc, len);
180 return static_cast<int>(ret);