#include <zephyr.h>
#include <drivers/adc.h>
static const struct device *adc_dev;
static int16_t sample_buffer[1];
void adc_init() {
adc_dev = device_get_binding("ADC_0");
struct adc_channel_cfg channel_cfg = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 1,
};
adc_channel_setup(adc_dev, &channel_cfg);
}
void read_adc() {
struct adc_sequence sequence = {
.channels = BIT(1),
.buffer = sample_buffer,
.buffer_size = sizeof(sample_buffer),
.resolution = 10,
};
adc_read(adc_dev, &sequence);
}
#include <zephyr.h>
#include <drivers/adc.h>
static const struct device *adc_dev;
static int16_t sample_buffer[1];
void adc_init() {
adc_dev = device_get_binding("ADC_0");
struct adc_channel_cfg channel_cfg = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 1,
};
adc_channel_setup(adc_dev, &channel_cfg);
}
void read_adc() {
struct adc_sequence sequence = {
.channels = BIT(1),
.buffer = sample_buffer,
.buffer_size = sizeof(sample_buffer),
.resolution = 10,
};
adc_read(adc_dev, &sequence);
}