OpenMPTL - STM32F10X
C++ Microprocessor Template Library
adc.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 /*
22  * This program contains derivative representations of CMSIS System
23  * View Description (SVD) files, and is subject to the "End User
24  * License Agreement for STMicroelectronics" (see "STM_License.html"
25  * in the containing directory).
26  */
27 
28 #ifndef ARCH_REG_ADC_HPP_INCLUDED
29 #define ARCH_REG_ADC_HPP_INCLUDED
30 
31 #include <register.hpp>
32 
33 namespace mptl {
34 /**
35  * Analog-to-digital converter (ADC)
36  */
37 template<unsigned adc_no>
38 struct ADC
39 {
40  static_assert((adc_no >= 1) && (adc_no <= 3), "invalid index for register");
41 
42  static constexpr reg_addr_t base_addr =
43  adc_no == 1 ? 0x40012400 :
44  adc_no == 2 ? 0x40012800 :
45  adc_no == 3 ? 0x40013C00 :
46  0;
47 
48  /**
49  * Status register
50  */
51  struct SR
52  : public reg< uint32_t, base_addr + 0x0, rw, 0x00000000 >
53  {
55 
56  using STRT = regbits< type, 4, 1 >; /**< Regular channel start flag */
57  using JSTRT = regbits< type, 3, 1 >; /**< Injected channel start flag */
58  using JEOC = regbits< type, 2, 1 >; /**< Injected channel end of conversion */
59  using EOC = regbits< type, 1, 1 >; /**< Regular channel end of conversion */
60  using AWD = regbits< type, 0, 1 >; /**< Analog watchdog flag */
61  };
62 
63  /**
64  * Control register 1
65  */
66  struct CR1
67  : public reg< uint32_t, base_addr + 0x4, rw, 0x00000000 >
68  {
70 
71  using AWDEN = regbits< type, 23, 1 >; /**< Analog watchdog enable on regular channels */
72  using JAWDEN = regbits< type, 22, 1 >; /**< Analog watchdog enable on injected channels */
73  using DUALMOD = regbits< type, 16, 4 >; /**< Dual mode selection */
74  using DISCNUM = regbits< type, 13, 3 >; /**< Discontinuous mode channel count */
75  using JDISCEN = regbits< type, 12, 1 >; /**< Discontinuous mode on injected channels */
76  using DISCEN = regbits< type, 11, 1 >; /**< Discontinuous mode on regular channels */
77  using JAUTO = regbits< type, 10, 1 >; /**< Automatic injected group conversion */
78  using AWDSGL = regbits< type, 9, 1 >; /**< Enable the watchdog on a single channel in scan mode */
79  using SCAN = regbits< type, 8, 1 >; /**< Scan mode */
80  using JEOCIE = regbits< type, 7, 1 >; /**< Interrupt enable for injected channels */
81  using AWDIE = regbits< type, 6, 1 >; /**< Analog watchdog interrupt enable */
82  using EOCIE = regbits< type, 5, 1 >; /**< Interrupt enable for EOC */
83  using AWDCH = regbits< type, 0, 5 >; /**< Analog watchdog channel select bits */
84  };
85 
86  /**
87  * Control register 2
88  */
89  struct CR2
90  : public reg< uint32_t, base_addr + 0x8, rw, 0x00000000 >
91  {
93 
94  using TSVREFE = regbits< type, 23, 1 >; /**< Temperature sensor and VREFINT enable */
95  using SWSTART = regbits< type, 22, 1 >; /**< Start conversion of regular channels */
96  using JSWSTART = regbits< type, 21, 1 >; /**< Start conversion of injected channels */
97  using EXTTRIG = regbits< type, 20, 1 >; /**< External trigger conversion mode for regular channels */
98  using EXTSEL = regbits< type, 17, 3 >; /**< External event select for regular group */
99  using JEXTTRIG = regbits< type, 15, 1 >; /**< External trigger conversion mode for injected channels */
100  using JEXTSEL = regbits< type, 12, 3 >; /**< External event select for injected group */
101  using ALIGN = regbits< type, 11, 1 >; /**< Data alignment */
102  using DMA = regbits< type, 8, 1 >; /**< Direct memory access mode */
103  using RSTCAL = regbits< type, 3, 1 >; /**< Reset calibration */
104  using CAL = regbits< type, 2, 1 >; /**< A/D calibration */
105  using CONT = regbits< type, 1, 1 >; /**< Continuous conversion */
106  using ADON = regbits< type, 0, 1 >; /**< A/D converter ON / OFF */
107  };
108 
109  /**
110  * Sample time register 1
111  */
112  struct SMPR1
113  : public reg< uint32_t, base_addr + 0xc, rw, 0x00000000 >
114  {
116 
117  using SMP10 = regbits< type, 0, 3 >; /**< Channel 10 sample time selection */
118  using SMP11 = regbits< type, 3, 3 >; /**< Channel 11 sample time selection */
119  using SMP12 = regbits< type, 6, 3 >; /**< Channel 12 sample time selection */
120  using SMP13 = regbits< type, 9, 3 >; /**< Channel 13 sample time selection */
121  using SMP14 = regbits< type, 12, 3 >; /**< Channel 14 sample time selection */
122  using SMP15 = regbits< type, 15, 3 >; /**< Channel 15 sample time selection */
123  using SMP16 = regbits< type, 18, 3 >; /**< Channel 16 sample time selection */
124  using SMP17 = regbits< type, 21, 3 >; /**< Channel 17 sample time selection */
125  };
126 
127  /**
128  * Sample time register 2
129  */
130  struct SMPR2
131  : public reg< uint32_t, base_addr + 0x10, rw, 0x00000000 >
132  {
134 
135  using SMP0 = regbits< type, 0, 3 >; /**< Channel 0 sample time selection */
136  using SMP1 = regbits< type, 3, 3 >; /**< Channel 1 sample time selection */
137  using SMP2 = regbits< type, 6, 3 >; /**< Channel 2 sample time selection */
138  using SMP3 = regbits< type, 9, 3 >; /**< Channel 3 sample time selection */
139  using SMP4 = regbits< type, 12, 3 >; /**< Channel 4 sample time selection */
140  using SMP5 = regbits< type, 15, 3 >; /**< Channel 5 sample time selection */
141  using SMP6 = regbits< type, 18, 3 >; /**< Channel 6 sample time selection */
142  using SMP7 = regbits< type, 21, 3 >; /**< Channel 7 sample time selection */
143  using SMP8 = regbits< type, 24, 3 >; /**< Channel 8 sample time selection */
144  using SMP9 = regbits< type, 27, 3 >; /**< Channel 9 sample time selection */
145  };
146 
147  /**
148  * Sample time register: provides SMPR1 or SMPR2, depending on channel
149  *
150  * NOTE: this is not from the reference manual
151  */
152  template<unsigned channel>
153  struct SMPRx
154  : public std::conditional< (channel > 9), SMPR1, SMPR2 >::type
155  {
156  static_assert(channel <= 17, "invalid channel");
157  using type = typename std::conditional< (channel > 9), SMPR1, SMPR2 >::type;
159  };
160 
161  /**
162  * Injected channel data offset register x
163  */
164  template<unsigned jofr_no>
165  struct JOFR
166  : public reg< uint32_t, base_addr + 0x14 + (jofr_no - 1) * 4, rw, 0x00000000 >
167  {
168  static_assert((jofr_no >= 1) && (jofr_no <= 4), "invalid index for JOFR register");
169  using type = reg< uint32_t, base_addr + 0x14 + (jofr_no - 1) * 4, rw, 0x00000000 >;
170 
171  using JOFFSET = regbits< type, 0, 12 >; /**< Data offset for injected channel x */
172  };
173 
174  /**
175  * Watchdog higher threshold register
176  */
177  struct HTR
178  : public reg< uint32_t, base_addr + 0x24, rw, 0x00000FFF >
179  {
181 
182  using HT = regbits< type, 0, 12 >; /**< Analog watchdog higher threshold */
183  };
184 
185  /**
186  * Watchdog lower threshold register
187  */
188  struct LTR
189  : public reg< uint32_t, base_addr + 0x28, rw, 0x00000000 >
190  {
192 
193  using LT = regbits< type, 0, 12 >; /**< Analog watchdog lower threshold */
194  };
195 
196  /**
197  * Regular sequence register 1
198  */
199  struct SQR1
200  : public reg< uint32_t, base_addr + 0x2c, rw, 0x00000000 >
201  {
203 
204  using L = regbits< type, 20, 4 >; /**< Regular channel sequence length */
205  using SQ16 = regbits< type, 15, 5 >; /**< 16th conversion in regular sequence */
206  using SQ15 = regbits< type, 10, 5 >; /**< 15th conversion in regular sequence */
207  using SQ14 = regbits< type, 5, 5 >; /**< 14th conversion in regular sequence */
208  using SQ13 = regbits< type, 0, 5 >; /**< 13th conversion in regular sequence */
209  };
210 
211  /**
212  * Regular sequence register 2
213  */
214  struct SQR2
215  : public reg< uint32_t, base_addr + 0x30, rw, 0x00000000 >
216  {
218 
219  using SQ12 = regbits< type, 25, 5 >; /**< 12th conversion in regular sequence */
220  using SQ11 = regbits< type, 20, 5 >; /**< 11th conversion in regular sequence */
221  using SQ10 = regbits< type, 15, 5 >; /**< 10th conversion in regular sequence */
222  using SQ9 = regbits< type, 10, 5 >; /**< 9th conversion in regular sequence */
223  using SQ8 = regbits< type, 5, 5 >; /**< 8th conversion in regular sequence */
224  using SQ7 = regbits< type, 0, 5 >; /**< 7th conversion in regular sequence */
225  };
226 
227  /**
228  * Regular sequence register 3
229  */
230  struct SQR3
231  : public reg< uint32_t, base_addr + 0x34, rw, 0x00000000 >
232  {
234 
235  using SQ6 = regbits< type, 25, 5 >; /**< 6th conversion in regular sequence */
236  using SQ5 = regbits< type, 20, 5 >; /**< 5th conversion in regular sequence */
237  using SQ4 = regbits< type, 15, 5 >; /**< 4th conversion in regular sequence */
238  using SQ3 = regbits< type, 10, 5 >; /**< 3rd conversion in regular sequence */
239  using SQ2 = regbits< type, 5, 5 >; /**< 2nd conversion in regular sequence */
240  using SQ1 = regbits< type, 0, 5 >; /**< 1st conversion in regular sequence */
241  };
242 
243  /**
244  * Regular sequence register: provides SQR1, SQR2 or SQR3, depending on channel
245  *
246  * NOTE: this is not from the reference manual
247  */
248  template<unsigned rank>
249  struct SQRx
250  : public std::conditional< (rank > 12), SQR1,
251  typename std::conditional< (rank > 6), SQR2, SQR3 >::type >::type
252  {
253  static_assert((rank >= 1) && (rank <= 16), "invalid rank");
254 
255  using type = typename std::conditional< (rank > 12), SQR1,
256  typename std::conditional< (rank > 6), SQR2, SQR3 >::type >::type;
257 
258  using SQ = regbits< type, ((rank - 1) % 6) * 5, 5 >;
259  };
260 
261  /**
262  * Injected sequence register
263  */
264  struct JSQR
265  : public reg< uint32_t, base_addr + 0x38, rw, 0x00000000 >
266  {
268 
269  using JL = regbits< type, 20, 2 >; /**< Injected sequence length */
270  using JSQ4 = regbits< type, 15, 5 >; /**< 4th conversion in injected sequence */
271  using JSQ3 = regbits< type, 10, 5 >; /**< 3rd conversion in injected sequence */
272  using JSQ2 = regbits< type, 5, 5 >; /**< 2nd conversion in injected sequence */
273  using JSQ1 = regbits< type, 0, 5 >; /**< 1st conversion in injected sequence */
274  };
275 
276  /**
277  * Injected data register x
278  */
279  template<unsigned jdr_no>
280  struct JDR
281  : public reg< uint32_t, base_addr + 0x3c + (jdr_no - 1) * 4, ro, 0x00000000 >
282  {
283  static_assert((jdr_no >= 1) && (jdr_no <= 4), "invalid index for JDR register");
284  using type = reg< uint32_t, base_addr + 0x3c + (jdr_no - 1) * 4, ro, 0x00000000 >;
285 
286  using JDATA = regbits< type, 0, 16 >; /**< Injected data */
287  };
288 
289  /**
290  * regular data register
291  */
292  struct DR
293  : public reg< uint32_t, base_addr + 0x4c, ro, 0x00000000 >
294  {
296 
297  using DATA = regbits< type, 0, 16 >; /**< Regular data */
298  using ADC2DATA = regbits< type, 16, 16 >; /**< ADC2 data */
299  };
300 };
301 
302 } // namespace mptl
303 
304 #endif // ARCH_REG_ADC_HPP_INCLUDED
Status register.
Definition: adc.hpp:51
regular data register
Definition: adc.hpp:292
uintptr_t reg_addr_t
Control register 2.
Definition: adc.hpp:89
Regular sequence register: provides SQR1, SQR2 or SQR3, depending on channel.
Definition: adc.hpp:249
Injected sequence register.
Definition: adc.hpp:264
Regular sequence register 1.
Definition: adc.hpp:199
typename std::conditional<(channel > 9), SMPR1, SMPR2 >::type type
Definition: adc.hpp:157
Sample time register: provides SMPR1 or SMPR2, depending on channel.
Definition: adc.hpp:153
Injected channel data offset register x.
Definition: adc.hpp:165
Sample time register 1.
Definition: adc.hpp:112
Regular sequence register 2.
Definition: adc.hpp:214
static constexpr reg_addr_t base_addr
Definition: adc.hpp:42
reg< uint32_t, base_addr+0x0, rw, 0x00000000 > type
Definition: adc.hpp:54
Sample time register 2.
Definition: adc.hpp:130
typename std::conditional<(rank > 12), SQR1, typename std::conditional<(rank > 6), SQR2, SQR3 >::type >::type type
Definition: adc.hpp:256
Regular sequence register 3.
Definition: adc.hpp:230
Watchdog higher threshold register.
Definition: adc.hpp:177
Analog-to-digital converter (ADC)
Definition: adc.hpp:38
Watchdog lower threshold register.
Definition: adc.hpp:188
Injected data register x.
Definition: adc.hpp:280
Control register 1.
Definition: adc.hpp:66