70 #if !defined(ADC_SAMPLE_RATE)
71 #if defined(STM32H7XX)
72 #define ADC_SAMPLE_RATE ADC_SMPR_SMP_384P5
73 #elif defined(STM32F3XX)
74 #define ADC_SAMPLE_RATE ADC_SMPR_SMP_601P5
76 #define ADC_SAMPLE_RATE ADC_SAMPLE_480
109 #ifdef AD1_10_CHANNEL
112 #ifdef AD1_11_CHANNEL
115 #ifdef AD1_12_CHANNEL
118 #ifdef AD1_13_CHANNEL
121 #ifdef AD1_14_CHANNEL
124 #ifdef AD1_15_CHANNEL
127 #ifdef AD1_16_CHANNEL
137 #ifndef ADC_BUF_DEPTH
138 #define ADC_BUF_DEPTH (MAX_AV_NB_SAMPLE/2)
149 #error ADC2_not implemented in ChibiOS
152 #error ADC3_not implemented in ChibiOS
159 adc_channels_num_t channel;
161 adc_watchdog_callback cb;
176 adccallback_t end_cb, adcerrorcallback_t
error_cb)
179 cfg->circular =
true;
180 cfg->num_channels = num_channels;
181 cfg->end_cb = end_cb;
185 #if defined(ADC_CFGR_RES_16BITS)
186 cfg->cfgr = ADC_CFGR_CONT | ADC_CFGR_RES_16BITS;
187 #elif defined(ADC_CFGR_RES_12BITS)
188 cfg->cfgr = ADC_CFGR_CONT | ADC_CFGR_RES_12BITS;
190 cfg->sqr1 = ADC_SQR1_NUM_CH(num_channels);
191 cfg->cr2 = ADC_CR2_SWSTART;
193 #if defined(ADC_CR2_TSVREFE)
194 cfg->cr2 |= ADC_CR2_TSVREFE;
199 for (
uint8_t i = 0; i < num_channels; i++) {
202 #if defined(STM32H7XX) || defined(STM32F3XX) || defined(STM32G4XX) || defined(STM32L4XX)
203 cfg->pcsel |= (1 << chan);
204 cfg->smpr[chan / 10] |= sample_rate << (3 * (chan % 10));
207 cfg->sqr[0] |= chan << (6 * (i + 1));
209 cfg->sqr[1] |= chan << (6 * (i - 4));
211 cfg->sqr[2] |= chan << (6 * (i - 9));
215 cfg->smpr2 |= sample_rate << (3 * chan);
217 cfg->smpr1 |= sample_rate << (3 * (chan - 10));
221 cfg->sqr3 |= chan << (5 * i);
223 cfg->sqr2 |= chan << (5 * (i - 6));
225 cfg->sqr3 |= chan << (5 * (i - 12));
245 if (adcp->state != ADC_STOP) {
252 const adcsample_t *buffer = adc_samples + (adcIsBufferComplete(adcp) ?
254 cacheBufferInvalidate(adc_samples,
sizeof(adc_samples));
264 for (
unsigned int sample = 0; sample < n; sample++) {
277 #pragma GCC diagnostic push
278 #pragma GCC diagnostic ignored "-Wtype-limits"
279 if ((adc_watchdog.adc == adcp) &&
281 (adc_watchdog.cb != NULL)) {
287 #pragma GCC diagnostic pop
290 chSysUnlockFromISR();
306 chSysUnlockFromISR();
315 #pragma GCC diagnostic push
316 #pragma GCC diagnostic ignored "-Wtype-limits"
318 #pragma GCC diagnostic pop
321 s->av_nb_sample = av_nb_sample;
374 adc_watchdog.adc = NULL;
375 adc_watchdog.cb = NULL;
376 adc_watchdog.channel = 0;
377 adc_watchdog.vmin = (1 << 12) - 1;
384 adcStart(&ADCD1, NULL);
389 void register_adc_watchdog(ADCDriver *adc, adc_channels_num_t channel, adcsample_t
vmin,
390 adc_watchdog_callback cb)
394 adc_watchdog.adc = adc;
395 adc_watchdog.channel = i;
396 adc_watchdog.vmin =
vmin;
397 adc_watchdog.cb = cb;
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
static struct adc_buf * adc1_buffers[ADC_NUM_CHANNELS]
void adc1callback(ADCDriver *adcp)
Adc1 callback.
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.
static IN_DMA_SECTION(adcsample_t adc_samples[ADC_NUM_CHANNELS *MAX_AV_NB_SAMPLE])
void adc_init(void)
Adc init.
static uint32_t adc1_sum_tmp[ADC_NUM_CHANNELS]
#define ADC_SAMPLE_RATE
#endif
static uint8_t adc1_samples_tmp[ADC_NUM_CHANNELS]
static void adcerrorcallback(ADCDriver *adcp, adcerror_t err)
Adc error callback.
static void adc_configure(ADCConversionGroup *cfg, uint8_t num_channels, const uint8_t channels[], uint32_t sample_rate, adccallback_t end_cb, adcerrorcallback_t error_cb)
Configure the ADC conversion group depending on the architecture.
static ADCConversionGroup adc1_group
static const uint8_t adc_channel_map[ADC_NUM_CHANNELS]
void gpio_setup_pin_analog(ioportid_t port, uint16_t pin)
Setup a gpio for analog use.
Some architecture independent helper functions for GPIOs.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
Specific RAM section for DMA usage on F7.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.