libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
adc.c
Go to the documentation of this file.
1/** @addtogroup adc_file ADC peripheral API
2 * @ingroup peripheral_apis
3 *
4 * @brief <b>libopencm3 STM32G4xx ADC</b>
5 *
6 * @version 1.0.0
7 *
8 * @date 10 Jul 2020
9 *
10 * LGPL License Terms @ref lgpl_license
11 */
12
13/*
14 * This file is part of the libopencm3 project.
15 *
16 * This library is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Lesser General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 */
29
31
32/**@{*/
33
34/*---------------------------------------------------------------------------*/
35/** @brief ADC Enable Analog Watchdog for Regular Conversions
36 *
37 * The analog watchdog allows the monitoring of an analog signal between two
38 * threshold levels. The thresholds must be preset. Comparison is done before
39 * data alignment takes place, so the thresholds are left-aligned.
40 *
41 * @param[in] adc Unsigned int32. ADC block register address base @ref
42 * adc_reg_base
43 */
44
46{
48}
49
50/*---------------------------------------------------------------------------*/
51/** @brief ADC Enable Analog Watchdog for Regular Conversions
52 *
53 * The analog watchdog allows the monitoring of an analog signal between two
54 * threshold levels. The thresholds must be preset. Comparison is done before
55 * data alignment takes place, so the thresholds are left-aligned.
56 *
57 * @param[in] adc Unsigned int32. ADC block register address base @ref
58 * adc_reg_base
59 */
61{
62 ADC_CFGR1(adc) &= ~ADC_CFGR1_AWD1EN;
63}
64
65/*---------------------------------------------------------------------------*/
66/** @brief ADC Enable Analog Watchdog for Injected Conversions
67 *
68 * The analog watchdog allows the monitoring of an analog signal between two
69 * threshold levels. The thresholds must be preset. Comparison is done before
70 * data alignment takes place, so the thresholds are left-aligned.
71 *
72 * @param[in] adc Unsigned int32. ADC block register address base @ref
73 * adc_reg_base
74 */
75
77{
79}
80
81/*---------------------------------------------------------------------------*/
82/** @brief ADC Disable Analog Watchdog for Injected Conversions
83 *
84 * @param[in] adc Unsigned int32. ADC block register address base @ref
85 * adc_reg_base
86 */
87
89{
90 ADC_CFGR1(adc) &= ~ADC_CFGR1_JAWD1EN;
91}
92
93/*---------------------------------------------------------------------------*/
94/** @brief ADC Enable Discontinuous Mode for Regular Conversions
95 *
96 * In this mode the ADC converts, on each trigger, a subgroup of up to 8 of the
97 * defined regular channel group. The subgroup is defined by the number of
98 * consecutive channels to be converted. After a subgroup has been converted
99 * the next trigger will start conversion of the immediately following subgroup
100 * of the same length or until the whole group has all been converted. When the
101 * whole group has been converted, the next trigger will restart conversion of
102 * the subgroup at the beginning of the whole group.
103 *
104 * @param[in] adc ADC block register address base @ref adc_reg_base
105 * @param[in] length Number of channels in the group @ref adc_cr1_discnum
106 */
107void adc_enable_discontinuous_mode_regular(uint32_t adc, uint8_t length)
108{
109 if ((length-1) > 7) {
110 return;
111 }
113 ADC_CFGR1(adc) |= ((length-1) << ADC_CFGR1_DISCNUM_SHIFT);
114}
115
116/*---------------------------------------------------------------------------*/
117/** @brief ADC Disable Discontinuous Mode for Regular Conversions
118 *
119 * @param[in] adc Unsigned int32. ADC block register address base @ref
120 * adc_reg_base
121 */
122
124{
125 ADC_CFGR1(adc) &= ~ADC_CFGR1_DISCEN;
126}
127
128/*---------------------------------------------------------------------------*/
129/** @brief ADC Enable Discontinuous Mode for Injected Conversions
130 *
131 * In this mode the ADC converts sequentially one channel of the defined group
132 * of injected channels, cycling back to the first channel in the group once
133 * the entire group has been converted.
134 *
135 * @param[in] adc Unsigned int32. ADC block register address base @ref
136 * adc_reg_base
137 */
138
140{
142}
143
144/*---------------------------------------------------------------------------*/
145/** @brief ADC Disable Discontinuous Mode for Injected Conversions
146 *
147 * @param[in] adc Unsigned int32. ADC block register address base @ref
148 * adc_reg_base
149 */
150
152{
153 ADC_CFGR1(adc) &= ~ADC_CFGR1_JDISCEN;
154}
155
156/*---------------------------------------------------------------------------*/
157/** @brief ADC Enable Automatic Injected Conversions
158 *
159 * The ADC converts a defined injected group of channels immediately after the
160 * regular channels have been converted. The external trigger on the injected
161 * channels is disabled as required.
162 *
163 * @param[in] adc Unsigned int32. ADC block register address base @ref
164 * adc_reg_base
165 */
166
168{
171}
172
173/*---------------------------------------------------------------------------*/
174/** @brief ADC Disable Automatic Injected Conversions
175 *
176 * @param[in] adc Unsigned int32. ADC block register address base @ref
177 * adc_reg_base
178 */
179
181{
182 ADC_CFGR1(adc) &= ~ADC_CFGR1_JAUTO;
183}
184/*---------------------------------------------------------------------------*/
185/** @brief ADC Enable Analog Watchdog for All Regular and/or Injected Channels
186 *
187 * The analog watchdog allows the monitoring of an analog signal between two
188 * threshold levels. The thresholds must be preset. Comparison is done before
189 * data alignment takes place, so the thresholds are left-aligned.
190 *
191 * @note The analog watchdog must be enabled for either or both of the regular
192 * or injected channels. If neither are enabled, the analog watchdog feature
193 * will be disabled.
194 *
195 * @ref adc_enable_analog_watchdog_injected, @ref
196 * adc_enable_analog_watchdog_regular.
197 *
198 * @param[in] adc Unsigned int32. ADC block register address base @ref
199 * adc_reg_base
200 */
201
203{
204 ADC_CFGR1(adc) &= ~ADC_CFGR1_AWD1SGL;
205}
206
207/*---------------------------------------------------------------------------*/
208/** @brief ADC Enable Analog Watchdog for a Selected Channel
209 *
210 * The analog watchdog allows the monitoring of an analog signal between two
211 * threshold levels. The thresholds must be preset. Comparison is done before
212 * data alignment takes place, so the thresholds are left-aligned.
213 *
214 * @note The analog watchdog must be enabled for either or both of the regular
215 * or injected channels. If neither are enabled, the analog watchdog feature
216 * will be disabled. If both are enabled, the same channel number is monitored
217 * @ref adc_enable_analog_watchdog_injected, @ref
218 * adc_enable_analog_watchdog_regular.
219 *
220 * @param[in] adc Unsigned int32. ADC block register address base @ref
221 * adc_reg_base
222 * @param[in] channel Unsigned int8. ADC channel numbe
223 * @ref adc_watchdog_channel
224 */
225
227 uint8_t channel)
228{
229 ADC_CFGR1(adc) = (ADC_CFGR1(adc) & ~ADC_CFGR1_AWD1CH) |
230 ADC_CFGR1_AWD1CH_VAL(channel);
231
233}
234
235
236/*---------------------------------------------------------------------------*/
237/** @brief ADC Enable Injected End-Of-Conversion Interrupt
238 *
239 * @param[in] adc Unsigned int32. ADC block register address base @ref
240 * adc_reg_base
241 */
242
244{
245 ADC_IER(adc) |= ADC_IER_JEOCIE;
246}
247
248/*---------------------------------------------------------------------------*/
249/** @brief ADC Disable Injected End-Of-Conversion Interrupt
250 *
251 * @param[in] adc Unsigned int32. ADC block register address base @ref
252 * adc_reg_base
253 */
254
256{
257 ADC_IER(adc) &= ~ADC_IER_JEOCIE;
258}
259
260/*---------------------------------------------------------------------------*/
261/** @brief ADC Enable Injected End-Of-Sequence Interrupt
262 *
263 * @param[in] adc Unsigned int32. ADC block register address base @ref
264 * adc_reg_base
265 */
266
268{
269 ADC_IER(adc) |= ADC_IER_JEOSIE;
270}
271
272/*---------------------------------------------------------------------------*/
273/** @brief ADC Disable Injected End-Of-Sequence Interrupt
274 *
275 * @param[in] adc Unsigned int32. ADC block register address base @ref
276 * adc_reg_base
277 */
278
280{
281 ADC_IER(adc) &= ~ADC_IER_JEOSIE;
282}
283
284
285/*---------------------------------------------------------------------------*/
286/** @brief ADC Enable Analog Watchdog Interrupt
287 *
288 * @param[in] adc Unsigned int32. ADC block register address base @ref
289 * adc_reg_base
290 */
291
293{
294 ADC_IER(adc) |= ADC_IER_AWD1IE;
295 ADC_IER(adc) |= ADC_IER_AWD2IE;
296 ADC_IER(adc) |= ADC_IER_AWD3IE;
297}
298
299/*---------------------------------------------------------------------------*/
300/** @brief ADC Disable Analog Watchdog Interrupt
301 *
302 * @param[in] adc Unsigned int32. ADC block register address base @ref
303 * adc_reg_base
304 */
305
307{
308 ADC_IER(adc) &= ~ADC_IER_AWD1IE;
309 ADC_IER(adc) &= ~ADC_IER_AWD2IE;
310 ADC_IER(adc) &= ~ADC_IER_AWD3IE;
311}
312
313/*---------------------------------------------------------------------------*/
314/** @brief ADC Enable Regular End-Of-Sequence Interrupt
315 *
316 * @param[in] adc Unsigned int32. ADC block register address base @ref
317 * adc_reg_base
318 */
319
320void adc_enable_eos_interrupt(uint32_t adc)
321{
322 ADC_IER(adc) |= ADC_IER_EOSIE;
323}
324
325/*---------------------------------------------------------------------------*/
326/** @brief ADC Disable Regular End-Of-Sequence Interrupt
327 *
328 * @param[in] adc Unsigned int32. ADC block register address base @ref
329 * adc_reg_base
330 */
331
333{
334 ADC_IER(adc) &= ~ADC_IER_EOSIE;
335}
336
337
338/*---------------------------------------------------------------------------*/
339/** @brief ADC Software Triggered Conversion on Injected Channels
340 *
341 * This starts conversion on a set of defined injected channels.
342 * Depending on the configuration bits JEXTEN, a conversion will start
343 * immediately (software trigger configuration) or once an injected hardware
344 * trigger event occurs (hardware trigger configuration).
345 *
346 * @param[in] adc Unsigned int32. ADC block register address base @ref
347 * adc_reg_base
348 */
349
351{
352 /* Start conversion on injected channels. */
353 ADC_CR(adc) |= ADC_CR_JADSTART;
354}
355
356
357/** ADC Set Analog Watchdog Upper Threshold.
358 * @param[in] adc ADC block register address base
359 * @ref adc_reg_base
360 * @param[in] threshold Upper threshold value
361 */
362void adc_set_watchdog_high_threshold(uint32_t adc, uint16_t threshold)
363{
364 uint32_t reg32 = 0;
365 uint32_t mask = 0xf000ffff;
366
367 reg32 |= (threshold << 16);
368 reg32 &= ~mask; /* clear masked bits. */
369
370 ADC_TR1(adc) = (ADC_TR1(adc) & mask) | reg32;
371 ADC_TR2(adc) = (ADC_TR2(adc) & mask) | reg32;
372 ADC_TR3(adc) = (ADC_TR3(adc) & mask) | reg32;
373}
374
375/** ADC Set Analog Watchdog Lower Threshold.
376 * @param[in] adc ADC block register address base
377 * @ref adc_reg_base
378 * @param[in] threshold Lower threshold value
379 */
380void adc_set_watchdog_low_threshold(uint32_t adc, uint16_t threshold)
381{
382 uint32_t reg32 = 0;
383 uint32_t mask = 0xfffff000;
384 reg32 = (uint32_t)threshold;
385 reg32 &= ~mask; /* clear masked bits. */
386
387 ADC_TR1(adc) = (ADC_TR1(adc) & mask) | reg32;
388 ADC_TR2(adc) = (ADC_TR2(adc) & mask) | reg32;
389 ADC_TR3(adc) = (ADC_TR3(adc) & mask) | reg32;
390}
391
392
393/*---------------------------------------------------------------------------*/
394/** @brief ADC Set an Injected Channel Conversion Sequence
395 *
396 * Defines a sequence of channels to be converted as an injected group with a
397 * length from 1 to 4 channels. If this is called during conversion, the current
398 * conversion is reset and conversion begins again with the newly defined group.
399 *
400 * @param[in] adc Unsigned int32. ADC block register address base
401 * @ref adc_reg_base
402 * @param[in] length Unsigned int8. Number of channels in the group.
403 * @param[in] channel Unsigned int8[]. Set of channels in sequence, integers
404 * 0..18
405 */
406
407void adc_set_injected_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
408{
409 uint32_t reg32 = 0;
410 uint8_t i = 0;
411
412 /* Maximum sequence length is 4 channels. Minimum sequence is 1.*/
413 if ((length - 1) > 3) {
414 return;
415 }
416
417 for (i = 0; i < length; i++) {
418 reg32 |= ADC_JSQR_JSQ_VAL(4 - i, channel[length - i - 1]);
419 }
420
421 reg32 |= ADC_JSQR_JL_VAL(length);
422
423 ADC_JSQR(adc) = reg32;
424}
425
426/*---------------------------------------------------------------------------*/
427/** @brief ADC Read the End-of-Conversion Flag for Injected Conversion
428 *
429 * This flag is set by hardware at the end of each injected conversion of a
430 * channel when a new data is available in the corresponding ADCx_JDRy register.
431 *
432 * @param[in] adc Unsigned int32. ADC block register address base
433 * @ref adc_reg_base
434 * @returns bool. End of conversion flag.
435 */
436
437bool adc_eoc_injected(uint32_t adc)
438{
439 return ADC_ISR(adc) & ADC_ISR_JEOC;
440}
441
442/*---------------------------------------------------------------------------*/
443/** @brief ADC Read the End-of-Sequence Flag for Injected Conversions
444 *
445 * This flag is set after all channels of an injected group have been
446 * converted.
447 *
448 * @param[in] adc Unsigned int32. ADC block register address base
449 * @ref adc_reg_base
450 * @returns bool. End of conversion flag.
451 */
452bool adc_eos_injected(uint32_t adc)
453{
454 return ADC_ISR(adc) & ADC_ISR_JEOS;
455}
456
457
458/*---------------------------------------------------------------------------*/
459/** @brief ADC Read from an Injected Conversion Result Register
460 *
461 * The result read back from the selected injected result register (one of four)
462 * is 12 bits, right or left aligned within the first 16 bits. The result can
463 * have a negative value if the injected channel offset has been set @see
464 * adc_set_injected_offset.
465 *
466 * @param[in] adc Unsigned int32. ADC block register address base @ref
467 * adc_reg_base
468 * @param[in] reg Unsigned int8. Register number (1 ... 4).
469 * @returns Unsigned int32 conversion result.
470 */
471
472uint32_t adc_read_injected(uint32_t adc, uint8_t reg)
473{
474 switch (reg) {
475 case 1:
476 return ADC_JDR1(adc);
477 case 2:
478 return ADC_JDR2(adc);
479 case 3:
480 return ADC_JDR3(adc);
481 case 4:
482 return ADC_JDR4(adc);
483 }
484 return 0;
485}
486
487/*---------------------------------------------------------------------------*/
488/** @brief ADC Set the Injected Channel Data Offset
489 *
490 * This value is subtracted from the injected channel results after conversion
491 * is complete, and can result in negative results. A separate value can be
492 * specified for each injected data register.
493 *
494 * @param[in] adc Unsigned int32. ADC block register address base
495 * @ref adc_reg_base
496 * @param[in] reg Unsigned int8. Register number (1 ... 4).
497 * @param[in] offset Unsigned int32.
498*/
499
500void adc_set_injected_offset(uint32_t adc, uint8_t reg, uint32_t offset)
501{
502 switch (reg) {
503 case 1:
505 ADC_OFR1(adc) |= offset;
506 break;
507 case 2:
509 ADC_OFR2(adc) |= offset;
510 break;
511 case 3:
513 ADC_OFR3(adc) |= offset;
514 break;
515 case 4:
517 ADC_OFR4(adc) |= offset;
518 break;
519 }
520}
521
522/*---------------------------------------------------------------------------*/
523/** @brief ADC Set Clock Source
524 *
525 * The ADC clock taken from the APB2 clock can be scaled down by 2, 4, 6 or 8.
526 *
527 * @param adc peripheral of choice @ref adc_reg_base
528 * @param[in] source Unsigned int32. Source value for ADC Clock @ref
529 * adc_ccr_adcpre
530 */
531void adc_set_clk_source(uint32_t adc, uint32_t source)
532{
533 uint32_t reg32 = ((ADC_CCR(adc) & ~ADC_CCR_CKMODE_MASK) | source);
534 ADC_CCR(adc) = reg32;
535}
536
537/*---------------------------------------------------------------------------*/
538/** @brief ADC Set Clock Prescale
539 *
540 * The ADC clock taken from the APB2 clock can be scaled down by 2, 4, 6 or 8.
541 *
542 * @param adc peripheral of choice @ref adc_reg_base
543 * @param[in] prescale Prescale value for ADC Clock @ref adc_ccr_presc
544 */
545void adc_set_clk_prescale(uint32_t adc, uint32_t prescale)
546{
547 uint32_t reg32 = ADC_CCR(adc);
548
550 ADC_CCR(adc) = (reg32 | (prescale << ADC_CCR_PRESC_SHIFT));
551}
552
553/*---------------------------------------------------------------------------*/
554/** @brief ADC set multi mode
555 *
556 * The multiple mode can uses these arrangement:
557 * - ADC1 as master and ADC2 as slave
558 * - ADC3 as master and ADC4 as slave
559 *
560 * This setting is applied to ADC master only (ADC1 or ADC3).
561 *
562 * The various modes possible are described in the reference manual.
563 *
564 * @param adc peripheral of choice @ref adc_reg_base
565 * @param[in] mode Multiple mode selection from @ref adc_multi_mode
566 */
567void adc_set_multi_mode(uint32_t adc, uint32_t mode)
568{
570 ADC_CCR(adc) |= (mode << ADC_CCR_DUAL_SHIFT);
571}
572
573/*---------------------------------------------------------------------------*/
574/** @brief ADC Enable an External Trigger for Regular Channels
575 *
576 * This enables an external trigger for set of defined regular channels, and
577 * sets the polarity of the trigger event: rising or falling edge or both. Note
578 * that if the trigger polarity is zero, triggering is disabled.
579 *
580 * @param[in] adc Unsigned int32. ADC block register address base @ref
581 * adc_reg_base
582 * @param[in] trigger Unsigned int32. Trigger identifier
583 * @ref adc_trigger_regular
584 * @param[in] polarity Unsigned int32. Trigger polarity @ref
585 * adc_trigger_polarity_regular
586 */
587
588void adc_enable_external_trigger_regular(uint32_t adc, uint32_t trigger,
589 uint32_t polarity)
590{
591 uint32_t reg32 = ADC_CFGR1(adc);
592
594 reg32 |= (trigger | polarity);
595 ADC_CFGR1(adc) = reg32;
596}
597
598/*---------------------------------------------------------------------------*/
599/** @brief ADC Disable an External Trigger for Regular Channels
600 *
601 * @param[in] adc Unsigned int32. ADC block register address base
602 * @ref adc_reg_base
603 */
604
606{
607 ADC_CFGR1(adc) &= ~ADC_CFGR1_EXTEN_MASK;
608}
609
610/*---------------------------------------------------------------------------*/
611/** @brief ADC Enable an External Trigger for Injected Channels
612 *
613 * This enables an external trigger for set of defined injected channels, and
614 * sets the polarity of the trigger event: rising or falling edge or both.
615 *
616 * @param[in] adc Unsigned int32. ADC block register address base
617 * @ref adc_reg_base
618 * @param[in] trigger Unsigned int8. Trigger identifier
619 * @ref adc_trigger_injected
620 * @param[in] polarity Unsigned int32. Trigger polarity
621 * @ref adc_trigger_polarity_injected
622*/
623
624void adc_enable_external_trigger_injected(uint32_t adc, uint32_t trigger,
625 uint32_t polarity)
626{
627 uint32_t reg32 = ADC_JSQR(adc);
628
630 reg32 |= (trigger | polarity);
631 ADC_JSQR(adc) = reg32;
632}
633
634/*---------------------------------------------------------------------------*/
635/** @brief ADC Disable an External Trigger for Injected Channels
636 *
637 * @param[in] adc Unsigned int32. ADC block register address base @ref
638 * adc_reg_base
639 */
640
642{
643 ADC_JSQR(adc) &= ~ADC_JSQR_JEXTEN_MASK;
644}
645
646
647/*---------------------------------------------------------------------------*/
648/** @brief ADC Read the Analog Watchdog Flag
649 *
650 * This flag is set when the converted voltage crosses the high or low
651 * thresholds.
652 *
653 * @param[in] adc Unsigned int32. ADC block register address base
654 * @ref adc_reg_base
655 * @returns bool. AWD flag.
656 */
657
658bool adc_awd(uint32_t adc)
659{
660 return (ADC_ISR(adc) & ADC_ISR_AWD1) &&
661 (ADC_ISR(adc) & ADC_ISR_AWD2) &&
662 (ADC_ISR(adc) & ADC_ISR_AWD3);
663}
664
665/*---------------------------------------------------------------------------*/
666/** @brief ADC Enable Deep-Power-Down Mdoe
667 *
668 * Deep-power-down mode allows additional power saving by internally switching
669 * off to reduce leakage currents.
670 *
671 * @param[in] adc Unsigned int32. ADC block register address base @ref
672 * adc_reg_base
673 */
674void adc_enable_deeppwd(uint32_t adc)
675{
676 ADC_CR(adc) |= ADC_CR_DEEPPWD;
677}
678
679/*---------------------------------------------------------------------------*/
680/** @brief ADC Disable Deep-Power-Down Mdoe
681 *
682 * Deep-power-down mode allows additional power saving by internally switching
683 * off to reduce leakage currents.
684 *
685 * @param[in] adc Unsigned int32. ADC block register address base @ref
686 * adc_reg_base
687 */
688void adc_disable_deeppwd(uint32_t adc)
689{
690 ADC_CR(adc) &= ~ADC_CR_DEEPPWD;
691}
692
693
694/**
695 * Enable the ADC Voltage regulator
696 * Before any use of the ADC, the ADC Voltage regulator must be enabled.
697 * You must wait up to 10uSecs afterwards before trying anything else.
698 * @param[in] adc ADC block register address base
699 * @sa adc_disable_regulator
700 */
701void adc_enable_regulator(uint32_t adc)
702{
703 ADC_CR(adc) |= ADC_CR_ADVREGEN;
704}
705
706/**
707 * Disable the ADC Voltage regulator
708 * You can disable the adc vreg when not in use to save power
709 * @param[in] adc ADC block register address base
710 * @sa adc_enable_regulator
711 */
712void adc_disable_regulator(uint32_t adc)
713{
714 ADC_CR(adc) &= ~ADC_CR_ADVREGEN;
715}
716
717/**@}*/
718
719
#define ADC_CCR_PRESC_SHIFT
Definition: g4/adc.h:466
#define ADC_CCR_PRESC_MASK
Definition: g4/adc.h:465
#define ADC_CFGR1_AWD1CH_VAL(x)
AWD1CH: Analog watchdog 1 channel selection.
#define ADC_CFGR1_AWD1SGL
AWD1SGL: Enable the watchdog 1 on a single channel or on all channels.
#define ADC_CFGR1_EXTEN_MASK
#define ADC_CFGR1_AWD1EN
AWD1EN: Analog watchdog 1 enable on regular channels.
#define ADC_CFGR1_DISCEN
DISCEN: Discontinuous mode for regular channels.
#define ADC_JSQR_JL_VAL(val)
Definition: g4/adc.h:232
#define ADC_IER_AWD3IE
#define ADC_CR_JADSTART
#define ADC_CFGR1_JAUTO
#define ADC_JSQR_JSQ_VAL(n, val)
Definition: g4/adc.h:231
#define ADC_ISR_JEOC
#define ADC_CFGR1_JAWD1EN
#define ADC_IER_JEOSIE
#define ADC_OFR4_OFFSET4_EN
Definition: g4/adc.h:369
#define ADC_IER_AWD2IE
#define ADC_OFR1_OFFSET1_EN
Definition: g4/adc.h:330
#define ADC_CFGR1_DISCNUM_SHIFT
#define ADC_ISR_AWD3
#define ADC_CCR_DUAL_MASK
Definition: g4/adc.h:542
#define ADC_CCR_DUAL_SHIFT
Definition: g4/adc.h:543
#define ADC_CFGR1_JDISCEN
#define ADC_CR_ADVREGEN
ADVREGEN: ADC voltage regulator enable bit.
Definition: g4/adc.h:60
#define ADC_CR_DEEPPWD
Definition: g4/adc.h:57
#define ADC_JSQR_JEXTSEL_MASK
Definition: g4/adc.h:319
#define ADC_ISR_AWD2
#define ADC_OFR2_OFFSET2_EN
Definition: g4/adc.h:343
#define ADC_OFR3_OFFSET3_EN
Definition: g4/adc.h:356
#define ADC_IER_JEOCIE
#define ADC_CFGR1_EXTSEL_MASK
Definition: g4/adc.h:69
#define ADC_ISR_JEOS
#define ADC_JSQR_JEXTEN_MASK
Definition: g4/adc.h:251
void adc_disable_automatic_injected_group_conversion(uint32_t adc)
ADC Disable Automatic Injected Conversions.
Definition: adc.c:180
void adc_set_watchdog_high_threshold(uint32_t adc, uint16_t threshold)
ADC Set Analog Watchdog Upper Threshold.
Definition: adc.c:362
void adc_enable_discontinuous_mode_injected(uint32_t adc)
ADC Enable Discontinuous Mode for Injected Conversions.
Definition: adc.c:139
void adc_disable_eos_interrupt(uint32_t adc)
ADC Disable Regular End-Of-Sequence Interrupt.
Definition: adc.c:332
void adc_disable_regulator(uint32_t adc)
Disable the ADC Voltage regulator You can disable the adc vreg when not in use to save power.
Definition: adc.c:712
void adc_disable_discontinuous_mode_regular(uint32_t adc)
ADC Disable Discontinuous Mode for Regular Conversions.
Definition: adc.c:123
void adc_enable_all_awd_interrupt(uint32_t adc)
ADC Enable Analog Watchdog Interrupt.
Definition: adc.c:292
void adc_disable_deeppwd(uint32_t adc)
ADC Disable Deep-Power-Down Mdoe.
Definition: adc.c:688
void adc_enable_eos_interrupt(uint32_t adc)
ADC Enable Regular End-Of-Sequence Interrupt.
Definition: adc.c:320
void adc_start_conversion_injected(uint32_t adc)
ADC Software Triggered Conversion on Injected Channels.
Definition: adc.c:350
void adc_enable_discontinuous_mode_regular(uint32_t adc, uint8_t length)
ADC Enable Discontinuous Mode for Regular Conversions.
Definition: adc.c:107
void adc_disable_eoc_interrupt_injected(uint32_t adc)
ADC Disable Injected End-Of-Conversion Interrupt.
Definition: adc.c:255
void adc_set_injected_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
ADC Set an Injected Channel Conversion Sequence.
Definition: adc.c:407
void adc_enable_deeppwd(uint32_t adc)
ADC Enable Deep-Power-Down Mdoe.
Definition: adc.c:674
void adc_enable_analog_watchdog_on_all_channels(uint32_t adc)
ADC Enable Analog Watchdog for All Regular and/or Injected Channels.
Definition: adc.c:202
void adc_enable_external_trigger_regular(uint32_t adc, uint32_t trigger, uint32_t polarity)
ADC Enable an External Trigger for Regular Channels.
Definition: adc.c:588
void adc_disable_all_awd_interrupt(uint32_t adc)
ADC Disable Analog Watchdog Interrupt.
Definition: adc.c:306
void adc_enable_external_trigger_injected(uint32_t adc, uint32_t trigger, uint32_t polarity)
ADC Enable an External Trigger for Injected Channels.
Definition: adc.c:624
void adc_disable_external_trigger_injected(uint32_t adc)
ADC Disable an External Trigger for Injected Channels.
Definition: adc.c:641
void adc_enable_eos_interrupt_injected(uint32_t adc)
ADC Enable Injected End-Of-Sequence Interrupt.
Definition: adc.c:267
void adc_enable_automatic_injected_group_conversion(uint32_t adc)
ADC Enable Automatic Injected Conversions.
Definition: adc.c:167
void adc_set_clk_prescale(uint32_t adc, uint32_t prescale)
ADC Set Clock Prescale.
Definition: adc.c:545
void adc_set_multi_mode(uint32_t adc, uint32_t mode)
ADC set multi mode.
Definition: adc.c:567
void adc_enable_regulator(uint32_t adc)
Enable the ADC Voltage regulator Before any use of the ADC, the ADC Voltage regulator must be enabled...
Definition: adc.c:701
bool adc_awd(uint32_t adc)
ADC Read the Analog Watchdog Flag.
Definition: adc.c:658
void adc_enable_eoc_interrupt_injected(uint32_t adc)
ADC Enable Injected End-Of-Conversion Interrupt.
Definition: adc.c:243
void adc_enable_analog_watchdog_injected(uint32_t adc)
ADC Enable Analog Watchdog for Injected Conversions.
Definition: adc.c:76
uint32_t adc_read_injected(uint32_t adc, uint8_t reg)
ADC Read from an Injected Conversion Result Register.
Definition: adc.c:472
void adc_disable_eos_interrupt_injected(uint32_t adc)
ADC Disable Injected End-Of-Sequence Interrupt.
Definition: adc.c:279
void adc_set_injected_offset(uint32_t adc, uint8_t reg, uint32_t offset)
ADC Set the Injected Channel Data Offset.
Definition: adc.c:500
void adc_enable_analog_watchdog_on_selected_channel(uint32_t adc, uint8_t channel)
ADC Enable Analog Watchdog for a Selected Channel.
Definition: adc.c:226
void adc_disable_analog_watchdog_injected(uint32_t adc)
ADC Disable Analog Watchdog for Injected Conversions.
Definition: adc.c:88
void adc_enable_analog_watchdog_regular(uint32_t adc)
ADC Enable Analog Watchdog for Regular Conversions.
Definition: adc.c:45
bool adc_eoc_injected(uint32_t adc)
ADC Read the End-of-Conversion Flag for Injected Conversion.
Definition: adc.c:437
void adc_set_watchdog_low_threshold(uint32_t adc, uint16_t threshold)
ADC Set Analog Watchdog Lower Threshold.
Definition: adc.c:380
bool adc_eos_injected(uint32_t adc)
ADC Read the End-of-Sequence Flag for Injected Conversions.
Definition: adc.c:452
void adc_set_clk_source(uint32_t adc, uint32_t source)
ADC Set Clock Source.
Definition: adc.c:531
void adc_disable_external_trigger_regular(uint32_t adc)
ADC Disable an External Trigger for Regular Channels.
Definition: adc.c:605
void adc_disable_discontinuous_mode_injected(uint32_t adc)
ADC Disable Discontinuous Mode for Injected Conversions.
Definition: adc.c:151
void adc_disable_analog_watchdog_regular(uint32_t adc)
ADC Enable Analog Watchdog for Regular Conversions.
Definition: adc.c:60
#define ADC_IER_AWD1IE
AWD1IE: Analog watchdog 1 interrupt enable.
Definition: adc_common_v2.h:90
#define ADC_IER_EOSIE
EOSIE: End of regular sequence of conversions interrupt enable.
Definition: adc_common_v2.h:94
#define ADC_ISR_AWD1
AWD1: Analog watchdog 1 flag.
Definition: adc_common_v2.h:70
#define ADC_TR3(adc)
#define ADC_CR(adc)
Control Register.
Definition: adc_common_v2.h:46
#define ADC_ISR(adc)
ADC interrupt and status register.
Definition: adc_common_v2.h:42
#define ADC_CCR(adc)
Common Configuration register.
Definition: adc_common_v2.h:60
#define ADC_JDR3(adc)
#define ADC_IER(adc)
Interrupt Enable Register.
Definition: adc_common_v2.h:44
#define ADC_OFR1(adc)
#define ADC_JDR4(adc)
#define ADC_JDR1(adc)
#define ADC_OFR4(adc)
#define ADC_JSQR(adc)
#define ADC_OFR3(adc)
#define ADC_JDR2(adc)
#define ADC_OFR2(adc)
#define ADC_TR2(adc)
#define ADC_CFGR1(adc)
Configuration Register 1.
Definition: adc_common_v2.h:48
#define ADC_TR1(adc)
Watchdog Threshold Register 1.
Definition: adc_common_v2.h:54