libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
g4/adc.h
Go to the documentation of this file.
1/** @defgroup adc_defines ADC Defines
2 *
3 * @brief <b>Defined Constants and Types for the STM32G4xx Analog to Digital
4 * converter</b>
5 *
6 * @ingroup STM32G4xx_defines
7 *
8 * @version 1.0.0
9 *
10 * @date 10 Jul 2020
11 *
12 *LGPL License Terms @ref lgpl_license
13 */
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * This library is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Lesser General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with this library. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31#ifndef LIBOPENCM3_ADC_H
32#define LIBOPENCM3_ADC_H
33
36
37/**@{*/
38
39/** @defgroup adc_reg_base ADC register base addresses
40@ingroup STM32xx_adc_defines
41@{*/
42#define ADC1 ADC1_BASE
43#define ADC2 ADC2_BASE
44#define ADC3 ADC3_BASE
45#define ADC4 ADC4_BASE
46#define ADC5 ADC5_BASE
47/**@}*/
48
49
50/*----------- ADC registers -------------------------------------- */
51/** ADC_GCOMP Gain compensation Register */
52#define ADC_GCOMP(adc) MMIO32((adc) + 0xC0)
53
54/*------- ADC_CR values ---------*/
55
56/* DEEPPWD: Deep power down */
57#define ADC_CR_DEEPPWD (1 << 29)
58
59/** ADVREGEN: ADC voltage regulator enable bit */
60#define ADC_CR_ADVREGEN (1 << 28)
61
62/*------- ADC_CFGR1 values ---------*/
63
64/** ALIGN: Data alignment */
65#define ADC_CFGR1_ALIGN (1 << 15)
66
67/** EXTSEL[4:0]: External trigger selection for regular group */
68#define ADC_CFGR1_EXTSEL_SHIFT 5
69#define ADC_CFGR1_EXTSEL_MASK (0x1f << ADC_CFGR1_EXTSEL_SHIFT)
70#define ADC_CFGR1_EXTSEL_VAL(x) ((x) << ADC_CFGR1_EXTSEL_SHIFT)
71
72/** CFGR1: ADC configuration register */
73#define ADC12_CFGR1_EXTSEL_TIM1_CC1 ADC_CFGR1_EXTSEL_VAL(0)
74#define ADC12_CFGR1_EXTSEL_TIM1_CC2 ADC_CFGR1_EXTSEL_VAL(1)
75#define ADC12_CFGR1_EXTSEL_TIM1_CC3 ADC_CFGR1_EXTSEL_VAL(2)
76#define ADC12_CFGR1_EXTSEL_TIM2_CC2 ADC_CFGR1_EXTSEL_VAL(3)
77#define ADC12_CFGR1_EXTSEL_TIM3_TRGO ADC_CFGR1_EXTSEL_VAL(4)
78#define ADC12_CFGR1_EXTSEL_TIM4_CC4 ADC_CFGR1_EXTSEL_VAL(5)
79#define ADC12_CFGR1_EXTSEL_EXTI11 ADC_CFGR1_EXTSEL_VAL(6)
80#define ADC12_CFGR1_EXTSEL_TIM8_TRGO ADC_CFGR1_EXTSEL_VAL(7)
81#define ADC12_CFGR1_EXTSEL_TIM8_TRGO2 ADC_CFGR1_EXTSEL_VAL(8)
82#define ADC12_CFGR1_EXTSEL_TIM1_TRGO ADC_CFGR1_EXTSEL_VAL(9)
83#define ADC12_CFGR1_EXTSEL_TIM1_TRGO2 ADC_CFGR1_EXTSEL_VAL(10)
84#define ADC12_CFGR1_EXTSEL_TIM2_TRGO ADC_CFGR1_EXTSEL_VAL(11)
85#define ADC12_CFGR1_EXTSEL_TIM4_TRGO ADC_CFGR1_EXTSEL_VAL(12)
86#define ADC12_CFGR1_EXTSEL_TIM6_TRGO ADC_CFGR1_EXTSEL_VAL(13)
87#define ADC12_CFGR1_EXTSEL_TIM15_TRGO ADC_CFGR1_EXTSEL_VAL(14)
88#define ADC12_CFGR1_EXTSEL_TIM3_CC4 ADC_CFGR1_EXTSEL_VAL(15)
89#define ADC12_CFGR1_EXTSEL_TIM20_TRGO ADC_CFGR1_EXTSEL_VAL(16)
90#define ADC12_CFGR1_EXTSEL_TIM20_TRGO2 ADC_CFGR1_EXTSEL_VAL(17)
91#define ADC12_CFGR1_EXTSEL_TIM20_CC1 ADC_CFGR1_EXTSEL_VAL(18)
92#define ADC12_CFGR1_EXTSEL_TIM20_CC2 ADC_CFGR1_EXTSEL_VAL(19)
93#define ADC12_CFGR1_EXTSEL_TIM20_CC3 ADC_CFGR1_EXTSEL_VAL(20)
94#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG1 ADC_CFGR1_EXTSEL_VAL(21)
95#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG3 ADC_CFGR1_EXTSEL_VAL(22)
96#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG5 ADC_CFGR1_EXTSEL_VAL(23)
97#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG6 ADC_CFGR1_EXTSEL_VAL(24)
98#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG7 ADC_CFGR1_EXTSEL_VAL(25)
99#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG8 ADC_CFGR1_EXTSEL_VAL(26)
100#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG9 ADC_CFGR1_EXTSEL_VAL(27)
101#define ADC12_CFGR1_EXTSEL_HRTIM_ADC_TRG10 ADC_CFGR1_EXTSEL_VAL(28)
102#define ADC12_CFGR1_EXTSEL_LPTIMOUT ADC_CFGR1_EXTSEL_VAL(29)
103#define ADC12_CFGR1_EXTSEL_TIM7_TRGO ADC_CFGR1_EXTSEL_VAL(30)
104
105#define ADC345_CFGR1_EXTSEL_TIM3_CC1 ADC_CFGR1_EXTSEL_VAL(0)
106#define ADC345_CFGR1_EXTSEL_TIM2_CC3 ADC_CFGR1_EXTSEL_VAL(1)
107#define ADC345_CFGR1_EXTSEL_TIM1_CC3 ADC_CFGR1_EXTSEL_VAL(2)
108#define ADC345_CFGR1_EXTSEL_TIM8_CC1 ADC_CFGR1_EXTSEL_VAL(3)
109#define ADC345_CFGR1_EXTSEL_TIM3_TRGO ADC_CFGR1_EXTSEL_VAL(4)
110#define ADC345_CFGR1_EXTSEL_EXTI2 ADC_CFGR1_EXTSEL_VAL(5)
111#define ADC345_CFGR1_EXTSEL_TIM4_CC1 ADC_CFGR1_EXTSEL_VAL(6)
112#define ADC345_CFGR1_EXTSEL_TIM8_TRGO ADC_CFGR1_EXTSEL_VAL(7)
113#define ADC345_CFGR1_EXTSEL_TIM8_TRGO2 ADC_CFGR1_EXTSEL_VAL(8)
114#define ADC345_CFGR1_EXTSEL_TIM1_TRGO ADC_CFGR1_EXTSEL_VAL(9)
115#define ADC345_CFGR1_EXTSEL_TIM1_TRGO2 ADC_CFGR1_EXTSEL_VAL(10)
116#define ADC345_CFGR1_EXTSEL_TIM2_TRGO ADC_CFGR1_EXTSEL_VAL(11)
117#define ADC345_CFGR1_EXTSEL_TIM4_TRGO ADC_CFGR1_EXTSEL_VAL(12)
118#define ADC345_CFGR1_EXTSEL_TIM6_TRGO ADC_CFGR1_EXTSEL_VAL(13)
119#define ADC345_CFGR1_EXTSEL_TIM15_TRGO ADC_CFGR1_EXTSEL_VAL(14)
120#define ADC345_CFGR1_EXTSEL_TIM2_CC1 ADC_CFGR1_EXTSEL_VAL(15)
121#define ADC345_CFGR1_EXTSEL_TIM20_TRGO ADC_CFGR1_EXTSEL_VAL(16)
122#define ADC345_CFGR1_EXTSEL_TIM20_TRGO2 ADC_CFGR1_EXTSEL_VAL(17)
123#define ADC345_CFGR1_EXTSEL_TIM20_CC1 ADC_CFGR1_EXTSEL_VAL(18)
124#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG2 ADC_CFGR1_EXTSEL_VAL(19)
125#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG4 ADC_CFGR1_EXTSEL_VAL(20)
126#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG1 ADC_CFGR1_EXTSEL_VAL(21)
127#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG3 ADC_CFGR1_EXTSEL_VAL(22)
128#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG5 ADC_CFGR1_EXTSEL_VAL(23)
129#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG6 ADC_CFGR1_EXTSEL_VAL(24)
130#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG7 ADC_CFGR1_EXTSEL_VAL(25)
131#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG8 ADC_CFGR1_EXTSEL_VAL(26)
132#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG9 ADC_CFGR1_EXTSEL_VAL(27)
133#define ADC345_CFGR1_EXTSEL_HRTIM_ADC_TRG10 ADC_CFGR1_EXTSEL_VAL(28)
134#define ADC345_CFGR1_EXTSEL_LPTIMOUT ADC_CFGR1_EXTSEL_VAL(29)
135#define ADC345_CFGR1_EXTSEL_TIM7_TRGO ADC_CFGR1_EXTSEL_VAL(30)
136
137/*------- ADC_CFGR2 values ---------*/
138
139/** ROVSE: Regular Oversampling Enable */
140#define ADC_CFGR2_ROVSE (1 << 0)
141
142/** JOVSE: Injected Oversampling Enable */
143#define ADC_CFGR2_JOVSE (1 << 1)
144
145/** OVSR[2:0]: Oversampling ratio */
146#define ADC_CFGR2_OVSR_SHIFT 2
147#define ADC_CFGR2_OVSR_MASK (0x7 << ADC_CFGR2_OVSR_SHIFT)
148#define ADC_CFGR2_OVSR_VAL(x) ((x) << ADC_CFGR2_OVSR_SHIFT)
149
150#define ADC_CFGR2_OVSR_2x ADC_CFGR2_OVSR_VAL(0)
151#define ADC_CFGR2_OVSR_4x ADC_CFGR2_OVSR_VAL(1)
152#define ADC_CFGR2_OVSR_8x ADC_CFGR2_OVSR_VAL(2)
153#define ADC_CFGR2_OVSR_16x ADC_CFGR2_OVSR_VAL(3)
154#define ADC_CFGR2_OVSR_32x ADC_CFGR2_OVSR_VAL(4)
155#define ADC_CFGR2_OVSR_64x ADC_CFGR2_OVSR_VAL(5)
156#define ADC_CFGR2_OVSR_128x ADC_CFGR2_OVSR_VAL(6)
157#define ADC_CFGR2_OVSR_256x ADC_CFGR2_OVSR_VAL(7)
158
159/** OVSS[3:0]: Oversampling shift */
160#define ADC_CFGR2_OVSS_SHIFT 5
161#define ADC_CFGR2_OVSS_MASK (0xf << ADC_CFGR2_OVSS_SHIFT)
162#define ADC_CFGR2_OVSS_VAL(x) ((x) << ADC_CFGR2_OVSS_SHIFT)
163
164/** TROVS: Triggered Regular Oversampling */
165#define ADC_CFGR2_TROVS (1 << 9)
166
167/** ROVSM: Regular Oversampling mode */
168#define ADC_CFGR2_ROVSM (1 << 10)
169
170/** GCOMP: Gain compensation mode */
171#define ADC_CFGR2_GCOMP (1 << 16)
172
173/** SWTRIG: Software trigger bit for sampling time control trigger mode */
174#define ADC_CFGR2_SWTRIG (1 << 25)
175
176/** BULB: Bulb sampling mode */
177#define ADC_CFGR2_BULB (1 << 26)
178
179/** SMPTRIG: Sampling time control trigger mode */
180#define ADC_CFGR2_SMPTRIG (1 << 27)
181
182/****************************************************************************/
183/* ADC_SMPRx ADC Sample Time Selection for Channels */
184/** @defgroup adc_sample ADC Sample Time Selection values
185@ingroup adc_defines
186
187@{*/
188#define ADC_SMPR_SMP_2DOT5CYC 0x0
189#define ADC_SMPR_SMP_6DOT5CYC 0x1
190#define ADC_SMPR_SMP_12DOT5CYC 0x2
191#define ADC_SMPR_SMP_24DOT5CYC 0x3
192#define ADC_SMPR_SMP_47DOT5CYC 0x4
193#define ADC_SMPR_SMP_92DOT5CYC 0x5
194#define ADC_SMPR_SMP_247DOT5CYC 0x6
195#define ADC_SMPR_SMP_640DOT5CYC 0x7
196
197#define ADC_SMPR1_SMP_PLUSONE (1 << 31)
198
199/**@}*/
200
201/* SMPx[2:0]: Channel x sampling time selection */
202
203/*------- ADC_T2 values ---------*/
204
205/* Bits 23:16 HT2[7:0]: Analog watchdog 2 higher threshold */
206
207/* Bit 7:0 LT2[7:0]: Analog watchdog 2 lower threshold */
208
209
210/*------- ADC_T3 values ---------*/
211
212/* Bits 23:16 HT3[7:0]: Analog watchdog 3 higher threshold */
213
214/* Bit 7:0 LT3[7:0]: Analog watchdog 3 lower threshold */
215
216
217/*------- ADC_DR values ---------*/
218
219/* Bits 15:0 RDATA[15:0]: Regular Data converted */
220
221
222/*------- ADC_JSQR values ---------*/
223
224#define ADC_JSQR_JL_LSB 0
225#define ADC_JSQR_JL_SHIFT 0
226#define ADC_JSQR_JSQ4_LSB 27
227#define ADC_JSQR_JSQ3_LSB 21
228#define ADC_JSQR_JSQ2_LSB 15
229#define ADC_JSQR_JSQ1_LSB 9
230
231#define ADC_JSQR_JSQ_VAL(n, val) ((val) << (((n) - 1) * 6 + 8))
232#define ADC_JSQR_JL_VAL(val) (((val) - 1) << ADC_JSQR_JL_SHIFT)
233
234/* Bits 31:27 JSQ4[4:0]: 4th conversion in the injected sequence */
235
236/* Bits 25:21 JSQ3[4:0]: 3rd conversion in the injected sequence */
237
238/* Bits 19:15 JSQ2[4:0]: 2nd conversion in the injected sequence */
239
240/* Bits 13:9 JSQ1[4:0]: 1st conversion in the injected sequence */
241
242/*
243 * JEXTEN[1:0]: External Trigger Enable and Polarity Selection for injected
244 * channels
245 */
246#define ADC_JSQR_JEXTEN_DISABLED (0x0 << 7)
247#define ADC_JSQR_JEXTEN_RISING_EDGE (0x1 << 7)
248#define ADC_JSQR_JEXTEN_FALLING_EDGE (0x2 << 7)
249#define ADC_JSQR_JEXTEN_BOTH_EDGES (0x3 << 7)
250
251#define ADC_JSQR_JEXTEN_MASK (0x3 << 7)
252
253/* JEXTSEL[3:0]: External Trigger Selection for injected group */
254#define ADC_JSQR_JEXTSEL_SHIFT 2
255
256#define ADC12_JSQR_JEXTSEL_TIM1_TRGO (0 << ADC_JSQR_JEXTSEL_SHIFT)
257#define ADC12_JSQR_JEXTSEL_TIM1_CC4 (1 << ADC_JSQR_JEXTSEL_SHIFT)
258#define ADC12_JSQR_JEXTSEL_TIM2_TRGO (2 << ADC_JSQR_JEXTSEL_SHIFT)
259#define ADC12_JSQR_JEXTSEL_TIM2_CC1 (3 << ADC_JSQR_JEXTSEL_SHIFT)
260#define ADC12_JSQR_JEXTSEL_TIM3_CC4 (4 << ADC_JSQR_JEXTSEL_SHIFT)
261#define ADC12_JSQR_JEXTSEL_TIM4_TRGO (5 << ADC_JSQR_JEXTSEL_SHIFT)
262#define ADC12_JSQR_JEXTSEL_EXTI15 (6 << ADC_JSQR_JEXTSEL_SHIFT)
263#define ADC12_JSQR_JEXTSEL_TIM8_CC4 (7 << ADC_JSQR_JEXTSEL_SHIFT)
264#define ADC12_JSQR_JEXTSEL_TIM1_TRGO2 (8 << ADC_JSQR_JEXTSEL_SHIFT)
265#define ADC12_JSQR_JEXTSEL_TIM8_TRGO (9 << ADC_JSQR_JEXTSEL_SHIFT)
266#define ADC12_JSQR_JEXTSEL_TIM8_TRGO2 (10 << ADC_JSQR_JEXTSEL_SHIFT)
267#define ADC12_JSQR_JEXTSEL_TIM3_CC3 (11 << ADC_JSQR_JEXTSEL_SHIFT)
268#define ADC12_JSQR_JEXTSEL_TIM3_TRGO (12 << ADC_JSQR_JEXTSEL_SHIFT)
269#define ADC12_JSQR_JEXTSEL_TIM3_CC1 (13 << ADC_JSQR_JEXTSEL_SHIFT)
270#define ADC12_JSQR_JEXTSEL_TIM6_TRGO (14 << ADC_JSQR_JEXTSEL_SHIFT)
271#define ADC12_JSQR_JEXTSEL_TIM15_TRGO (15 << ADC_JSQR_JEXTSEL_SHIFT)
272#define ADC12_JSQR_JEXTSEL_TIM20_TRGO (16 << ADC_JSQR_JEXTSEL_SHIFT)
273#define ADC12_JSQR_JEXTSEL_TIM20_TRGO2 (17 << ADC_JSQR_JEXTSEL_SHIFT)
274#define ADC12_JSQR_JEXTSEL_TIM20_CC4 (18 << ADC_JSQR_JEXTSEL_SHIFT)
275#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG2 (19 << ADC_JSQR_JEXTSEL_SHIFT)
276#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG4 (20 << ADC_JSQR_JEXTSEL_SHIFT)
277#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG5 (21 << ADC_JSQR_JEXTSEL_SHIFT)
278#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG6 (22 << ADC_JSQR_JEXTSEL_SHIFT)
279#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG7 (23 << ADC_JSQR_JEXTSEL_SHIFT)
280#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG8 (24 << ADC_JSQR_JEXTSEL_SHIFT)
281#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG9 (25 << ADC_JSQR_JEXTSEL_SHIFT)
282#define ADC12_JSQR_JEXTSEL_HRTIM_ADC_TRG10 (26 << ADC_JSQR_JEXTSEL_SHIFT)
283#define ADC12_JSQR_JEXTSEL_TIM16_CC1 (27 << ADC_JSQR_JEXTSEL_SHIFT)
284#define ADC12_JSQR_JEXTSEL_LPTIMOUT (29 << ADC_JSQR_JEXTSEL_SHIFT)
285#define ADC12_JSQR_JEXTSEL_TIM7_TRGO (30 << ADC_JSQR_JEXTSEL_SHIFT)
286
287#define ADC345_JSQR_JEXTSEL_TIM1_TRGO (0 << ADC_JSQR_JEXTSEL_SHIFT)
288#define ADC345_JSQR_JEXTSEL_TIM1_CC4 (1 << ADC_JSQR_JEXTSEL_SHIFT)
289#define ADC345_JSQR_JEXTSEL_TIM2_TRGO (2 << ADC_JSQR_JEXTSEL_SHIFT)
290#define ADC345_JSQR_JEXTSEL_TIM8_CC2 (3 << ADC_JSQR_JEXTSEL_SHIFT)
291#define ADC345_JSQR_JEXTSEL_TIM4_CC3 (4 << ADC_JSQR_JEXTSEL_SHIFT)
292#define ADC345_JSQR_JEXTSEL_TIM4_TRGO (5 << ADC_JSQR_JEXTSEL_SHIFT)
293#define ADC345_JSQR_JEXTSEL_TIM4_CC4 (6 << ADC_JSQR_JEXTSEL_SHIFT)
294#define ADC345_JSQR_JEXTSEL_TIM8_CC4 (7 << ADC_JSQR_JEXTSEL_SHIFT)
295#define ADC345_JSQR_JEXTSEL_TIM1_TRGO2 (8 << ADC_JSQR_JEXTSEL_SHIFT)
296#define ADC345_JSQR_JEXTSEL_TIM8_TRGO (9 << ADC_JSQR_JEXTSEL_SHIFT)
297#define ADC345_JSQR_JEXTSEL_TIM8_TRGO2 (10 << ADC_JSQR_JEXTSEL_SHIFT)
298#define ADC345_JSQR_JEXTSEL_TIM1_CC3 (11 << ADC_JSQR_JEXTSEL_SHIFT)
299#define ADC345_JSQR_JEXTSEL_TIM3_TRGO (12 << ADC_JSQR_JEXTSEL_SHIFT)
300#define ADC345_JSQR_JEXTSEL_EXTI3 (13 << ADC_JSQR_JEXTSEL_SHIFT)
301#define ADC345_JSQR_JEXTSEL_TIM6_TRGO (14 << ADC_JSQR_JEXTSEL_SHIFT)
302#define ADC345_JSQR_JEXTSEL_TIM15_TRGO (15 << ADC_JSQR_JEXTSEL_SHIFT)
303#define ADC345_JSQR_JEXTSEL_TIM20_TRGO (16 << ADC_JSQR_JEXTSEL_SHIFT)
304#define ADC345_JSQR_JEXTSEL_TIM20_TRGO2 (17 << ADC_JSQR_JEXTSEL_SHIFT)
305#define ADC345_JSQR_JEXTSEL_TIM20_CC2 (18 << ADC_JSQR_JEXTSEL_SHIFT)
306#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG2 (19 << ADC_JSQR_JEXTSEL_SHIFT)
307#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG4 (20 << ADC_JSQR_JEXTSEL_SHIFT)
308#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG5 (21 << ADC_JSQR_JEXTSEL_SHIFT)
309#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG6 (22 << ADC_JSQR_JEXTSEL_SHIFT)
310#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG7 (23 << ADC_JSQR_JEXTSEL_SHIFT)
311#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG8 (24 << ADC_JSQR_JEXTSEL_SHIFT)
312#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG9 (25 << ADC_JSQR_JEXTSEL_SHIFT)
313#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG10 (26 << ADC_JSQR_JEXTSEL_SHIFT)
314#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG1 (27 << ADC_JSQR_JEXTSEL_SHIFT)
315#define ADC345_JSQR_JEXTSEL_HRTIM_ADC_TRG3 (28 << ADC_JSQR_JEXTSEL_SHIFT)
316#define ADC345_JSQR_JEXTSEL_LPTIMOUT (29 << ADC_JSQR_JEXTSEL_SHIFT)
317#define ADC345_JSQR_JEXTSEL_TIM7_TRGO (30 << ADC_JSQR_JEXTSEL_SHIFT)
318
319#define ADC_JSQR_JEXTSEL_MASK (0x1F << ADC_JSQR_JEXTSEL_SHIFT)
320
321/* JL[1:0]: Injected channel sequence length */
322#define ADC_JSQR_JL_1_CONVERSION (0x0 << 0)
323#define ADC_JSQR_JL_2_CONVERSIONS (0x1 << 0)
324#define ADC_JSQR_JL_3_CONVERSIONS (0x2 << 0)
325#define ADC_JSQR_JL_4_CONVERSIONS (0x3 << 0)
326
327/*------- ADC_OFR1 values ---------*/
328
329/* OFFSET1_EN: Offset 1 Enable */
330#define ADC_OFR1_OFFSET1_EN (1 << 31)
331
332/* Bits 30:26 OFFSET1_CH[4:0]: Channel selection for the Data offset 1 */
333
334/*
335 * Bits 11:0 OFFSET1[11:0]: Data offset y for the channel programmed into bits
336 * OFFSET1_CH[4:0]
337 */
338
339
340/*------- ADC_OFR2 values ---------*/
341
342/* OFFSET2_EN: Offset 2 Enable */
343#define ADC_OFR2_OFFSET2_EN (1 << 31)
344
345/* Bits 30:26 OFFSET2_CH[4:0]: Channel selection for the Data offset 2 */
346
347/*
348 * Bits 11:0 OFFSET2[11:0]: Data offset y for the channel programmed into bits
349 * OFFSET2_CH[4:0]
350 */
351
352
353/*------- ADC_OFR3 values ---------*/
354
355/* OFFSET3_EN: Offset 3 Enable */
356#define ADC_OFR3_OFFSET3_EN (1 << 31)
357
358/* Bits 30:26 OFFSET3_CH[4:0]: Channel selection for the Data offset 3 */
359
360/*
361 * Bits 11:0 OFFSET3[11:0]: Data offset y for the channel programmed into bits
362 * OFFSET3_CH[4:0]
363 */
364
365
366/*------- ADC_OFR4 values ---------*/
367
368/* OFFSET4_EN: Offset 4 Enable */
369#define ADC_OFR4_OFFSET4_EN (1 << 31)
370
371/* Bits 30:26 OFFSET4_CH[4:0]: Channel selection for the Data offset 4 */
372
373/*
374 * Bits 11:0 OFFSET4[11:0]: Data offset y for the channel programmed into bits
375 * OFFSET4_CH[4:0]
376 */
377
378
379/*------- ADC_JDRy, y= 1..4 values -------*/
380
381/* Bits 15:0 JDATA[15:0]: Injected data */
382
383
384/*------- ADC_AWD2CR values ---------*/
385
386/* Bits 18:1 AWD2CH[18:1]: Analog watchdog 2 channel selection */
387
388
389/*------- ADC_AWD3CR values ---------*/
390
391/* Bits 18:1 AWD3CH[18:1]: Analog watchdog 3 channel selection */
392
393/*--------------- ADC_CSR values ------------------------*/
394
395/* Bit 26 JQOVF_SLV: Injected Context Queue Overflow flag of the slave ADC */
396#define ADC_CSR_JQOVF_SLV (1 << 26)
397
398/* Bit 25 AWD3_SLV: Analog watchdog 3 flag of the slave ADC */
399#define ADC_CSR_AWD3_SLV (1 << 25)
400
401/* Bit 24 AWD2_SLV: Analog watchdog 2 flag of the slave ADC */
402#define ADC_CSR_AWD2_SLV (1 << 24)
403
404/* Bit 23 AWD1_SLV: Analog watchdog 1 flag of the slave ADC */
405#define ADC_CSR_AWD1_SLV (1 << 23)
406
407/* Bit 22 JEOS_SLV: End of injected sequence flag of the slave ADC */
408#define ADC_CSR_JEOS_SLV (1 << 22)
409
410/* Bit 21 JEOC_SLV: End of injected conversion flag of the slave ADC */
411#define ADC_CSR_JEOC_SLV (1 << 21)
412
413/* Bit 20 OVR_SLV: Overrun flag of the slave ADC */
414#define ADC_CSR_OVR_SLV (1 << 20)
415
416/* Bit 19 EOS_SLV: End of regular sequence flag of the slave ADC */
417#define ADC_CSR_EOS_SLV (1 << 19)
418
419/* Bit 18 EOC_SLV: End of regular conversion of the slave ADC */
420#define ADC_CSR_EOC_SLV (1 << 18)
421
422/* Bit 17 EOSMP_SLV: End of Sampling phase flag of the slave ADC */
423#define ADC_CSR_EOSMP_SLV (1 << 17)
424
425/* Bit 16 ADRDY_SLV: Slave ADC ready */
426#define ADC_CSR_ADRDY_SLV (1 << 16)
427
428/* Bit 10 JQOVF_MST: Injected Context Queue Overflow flag of the master ADC */
429#define ADC_CSR_JQOVF_MST (1 << 10)
430
431/* Bit 9 AWD3_MST: Analog watchdog 3 flag of the master ADC */
432#define ADC_CSR_AWD3_MST (1 << 9)
433
434/* Bit 8 AWD2_MST: Analog watchdog 2 flag of the master ADC */
435#define ADC_CSR_AWD2_MST (1 << 8)
436
437/* Bit 7 AWD1_MST: Analog watchdog 1 flag of the master ADC */
438#define ADC_CSR_AWD1_MST (1 << 7)
439
440/* Bit 6 JEOS_MST: End of injected sequence flag of the master ADC */
441#define ADC_CSR_JEOS_MST (1 << 6)
442
443/* Bit 5 JEOC_MST: End of injected conversion flag of the master ADC */
444#define ADC_CSR_JEOC_MST (1 << 5)
445
446/* Bit 4 OVR_MST: Overrun flag of the master ADC */
447#define ADC_CSR_OVR_MST (1 << 4)
448
449/* Bit 3 EOS_MST: End of regular sequence flag of the master ADC */
450#define ADC_CSR_EOS_MST (1 << 3)
451
452/* Bit 2 EOC_MST: End of regular conversion of the master ADC */
453#define ADC_CSR_EOC_MST (1 << 2)
454
455/* Bit 1 EOSMP_MST: End of Sampling phase flag of the master ADC */
456#define ADC_CSR_EOSMP_MST (1 << 1)
457
458/* Bit 0 ADRDY_MST: Master ADC ready */
459#define ADC_CSR_ADRDY_MST (1 << 0)
460
461
462/** @addtogroup adc_ccr
463@{*/
464
465#define ADC_CCR_PRESC_MASK (0xf)
466#define ADC_CCR_PRESC_SHIFT (18)
467/** @defgroup adc_ccr_presc ADC clock prescaler
468 *@{*/
469#define ADC_CCR_PRESC_NODIV (0x0)
470#define ADC_CCR_PRESC_DIV2 (0x1)
471#define ADC_CCR_PRESC_DIV4 (0x2)
472#define ADC_CCR_PRESC_DIV6 (0x3)
473#define ADC_CCR_PRESC_DIV8 (0x4)
474#define ADC_CCR_PRESC_DIV10 (0x5)
475#define ADC_CCR_PRESC_DIV12 (0x6)
476#define ADC_CCR_PRESC_DIV16 (0x7)
477#define ADC_CCR_PRESC_DIV32 (0x8)
478#define ADC_CCR_PRESC_DIV64 (0x9)
479#define ADC_CCR_PRESC_DIV128 (0xa)
480#define ADC_CCR_PRESC_DIV256 (0xb)
481/**@}*/
482
483/* CKMODE[1:0]: ADC clock mode */
484#define ADC_CCR_CKMODE_CKX (0x0 << 16)
485#define ADC_CCR_CKMODE_DIV1 (0x1 << 16)
486#define ADC_CCR_CKMODE_DIV2 (0x2 << 16)
487#define ADC_CCR_CKMODE_DIV4 (0x3 << 16)
488
489#define ADC_CCR_CKMODE_MASK (0x3 << 16)
490
491/* MDMA[1:0]: Direct memory access mode for dual ADC mode */
492#define ADC_CCR_MDMA_DISABLE (0x0 << 14)
493/*#define ADC_CCR_MDMA_RESERVED (0x1 << 14)*/
494#define ADC_CCR_MDMA_12_10_BIT (0x2 << 14)
495#define ADC_CCR_MDMA_8_6_BIT (0x3 << 14)
496
497/* DMACFG: DMA configuration (for dual ADC mode) */
498#define ADC_CCR_DMACFG (1 << 13)
499
500/* DELAY: Delay between 2 sampling phases */
501#define ADC_CCR_DELAY_SHIFT 8
502
503/**@}*/
504
505/* DUAL[4:0]: Dual ADC mode selection */
506/****************************************************************************/
507/** @defgroup adc_multi_mode ADC Multi mode selection
508@ingroup adc_defines
509
510@{*/
511
512/** All ADCs independent */
513#define ADC_CCR_DUAL_INDEPENDENT 0x0
514
515/* Dual modes: (ADC1 master + ADC2 slave or ADC3 master + ADC4 slave) */
516/**
517 * Dual modes combined regular simultaneous +
518 * injected simultaneous mode.
519 */
520#define ADC_CCR_DUAL_REG_SIMUL_AND_INJECTED_SIMUL 0x1
521/**
522 * Dual mode Combined regular simultaneous +
523 * alternate trigger mode.
524 */
525#define ADC_CCR_DUAL_REG_SIMUL_AND_ALTERNATE_TRIG 0x2
526/**
527 * Dual mode Combined interleaved mode +
528 * injected simultaneous mode.
529 */
530#define ADC_CCR_DUAL_REG_INTERLEAVED_AND_INJECTED_SIMUL 0x3
531
532/** Dual mode Injected simultaneous mode only. */
533#define ADC_CCR_DUAL_INJECTED_SIMUL 0x5
534/** Dual mode Regular simultaneous mode only. */
535#define ADC_CCR_DUAL_REGULAR_SIMUL 0x6
536/** Dual mode Interleaved mode only. */
537#define ADC_CCR_DUAL_INTERLEAVED 0x7
538/** Dual mode Alternate trigger mode only. */
539#define ADC_CCR_DUAL_ALTERNATE_TRIG 0x9
540/**@}*/
541
542#define ADC_CCR_DUAL_MASK (0x1f)
543#define ADC_CCR_DUAL_SHIFT 0
544
545
546/*---------------- ADC_CDR values -----------------*/
547
548/* Bits 31:16 RDATA_SLV[15:0]: Regular data of the slave ADC */
549
550/* Bits 15:0 RDATA_MST[15:0]: Regular data of the master ADC. */
551
552/** @defgroup adc_channel ADC Channel Numbers
553 * @ingroup adc_defines
554 *
555 *@{*/
556#define ADC_CHANNEL_TEMP 16
557#define ADC_CHANNEL_VBAT 17
558#define ADC_CHANNEL_VREF 18
559/**@}*/
560
561#define ADC_CHANNEL_COUNT 19
562#define ADC_CHANNEL_IS_FAST(x) ((x) <= 5)
563
564
566
567void adc_enable_analog_watchdog_regular(uint32_t adc);
568void adc_disable_analog_watchdog_regular(uint32_t adc);
569void adc_enable_analog_watchdog_injected(uint32_t adc);
570void adc_disable_analog_watchdog_injected(uint32_t adc);
571void adc_enable_discontinuous_mode_regular(uint32_t adc, uint8_t length);
579 uint8_t channel);
580void adc_enable_eoc_interrupt_injected(uint32_t adc);
581void adc_disable_eoc_interrupt_injected(uint32_t adc);
582void adc_enable_eos_interrupt_injected(uint32_t adc);
583void adc_disable_eos_interrupt_injected(uint32_t adc);
584void adc_enable_all_awd_interrupt(uint32_t adc);
585void adc_disable_all_awd_interrupt(uint32_t adc);
586void adc_enable_eos_interrupt(uint32_t adc);
587void adc_disable_eos_interrupt(uint32_t adc);
588void adc_start_conversion_injected(uint32_t adc);
589void adc_disable_external_trigger_regular(uint32_t adc);
591void adc_set_watchdog_high_threshold(uint32_t adc, uint16_t threshold);
592void adc_set_watchdog_low_threshold(uint32_t adc, uint16_t threshold);
593void adc_set_injected_sequence(uint32_t adc, uint8_t length, uint8_t channel[]);
594bool adc_eoc_injected(uint32_t adc);
595bool adc_eos_injected(uint32_t adc);
596uint32_t adc_read_injected(uint32_t adc, uint8_t reg);
597void adc_set_injected_offset(uint32_t adc, uint8_t reg, uint32_t offset);
598void adc_set_clk_source(uint32_t adc, uint32_t source);
599void adc_set_clk_prescale(uint32_t adc, uint32_t prescale);
600void adc_set_multi_mode(uint32_t adc, uint32_t mode);
601void adc_enable_external_trigger_regular(uint32_t adc, uint32_t trigger,
602 uint32_t polarity);
603void adc_enable_external_trigger_injected(uint32_t adc, uint32_t trigger,
604 uint32_t polarity);
605bool adc_awd(uint32_t adc);
606void adc_enable_deeppwd(uint32_t adc);
607void adc_disable_deeppwd(uint32_t adc);
608
610
611/**@}*/
612
613
614#endif
615
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
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_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
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