21 #ifndef ARCH_ADC_HPP_INCLUDED 22 #define ARCH_ADC_HPP_INCLUDED 26 #include <type_traits> 31 template<
unsigned adc_no>
34 static_assert((adc_no >= 1) && (adc_no <= 3),
"invalid ADC number");
56 template<
unsigned value >
58 typename std::enable_if<
59 (adc_no == 1) || (value == 0),
63 template<
unsigned timer,
unsigned cc >
64 struct capture_compare_impl {
65 static constexpr uint32_t value =
66 (adc_no < 3) && (timer == 1) && (cc == 1) ? 0 :
67 (adc_no < 3) && (timer == 1) && (cc == 2) ? 1 :
68 (adc_no < 3) && (timer == 1) && (cc == 3) ? 2 :
69 (adc_no < 3) && (timer == 2) && (cc == 1) ? 3 :
70 (adc_no < 3) && (timer == 4) && (cc == 4) ? 6 :
71 (adc_no == 3) && (timer == 3) && (cc == 1) ? 0 :
72 (adc_no == 3) && (timer == 2) && (cc == 3) ? 1 :
73 (adc_no == 3) && (timer == 1) && (cc == 3) ? 2 :
74 (adc_no == 3) && (timer == 8) && (cc == 1) ? 3 :
75 (adc_no == 3) && (timer == 5) && (cc == 1) ? 5 :
76 (adc_no == 3) && (timer == 5) && (cc == 3) ? 6 :
78 static_assert((value & 0x7) == value,
"invalid timer / cc combination");
82 template<
unsigned timer>
83 struct trigger_output_impl {
84 static constexpr uint32_t value =
85 (adc_no < 3) && (timer == 3) ? 4 :
86 (adc_no == 3) && (timer == 8) ? 4 :
87 #if defined (STM32F10X_XL) 88 (adc_no < 3) && (timer == 8) ? 6 :
91 static_assert((value & 0x7) == value,
"invalid timer");
95 template<
unsigned channel,
unsigned rank, sample_time _sample_time>
96 struct regular_channel_config_impl {
97 static constexpr
unsigned smp_value = (unsigned)_sample_time;
99 static_assert(channel <= 17,
"invalid channel");
100 static_assert((rank >= 1) && (rank <= 16),
"invalid rank");
101 static_assert(smp_value < 8,
"invalid sample_time");
149 template<
unsigned timer,
unsigned cc>
153 template<
unsigned timer>
157 typename std::enable_if<
171 template<
unsigned value>
173 typename std::enable_if<
174 (value >= 1) && (value <= 16),
179 template<
unsigned channel,
unsigned rank, sample_time _sample_time>
190 template<
typename... Tp >
192 reglist< Tp... >::template strict_reset_to<
216 ADCx::CR2::ADON::set();
219 ADCx::CR2::ADON::clear();
227 ADCx::CR2::template
set<
238 ADCx::CR2::template clear<
245 while(ADCx::SR::EOC::test() ==
false);
256 #endif // ARCH_ADC_HPP_INCLUDED static __always_inline void set(void)
typename std::enable_if<(adc_no< 3), regval< typename ADCx::CR2::EXTSEL, 6 > >::type exti_line11
Definition: adc.hpp:160
regbits< type, 20, 4 > L
Regular channel sequence length.
Definition: adc.hpp:204
typename std::enable_if<(value >=1) &&(value<=16), regval< typename ADCx::SQR1::L, value - 1 > >::type regular_channel_sequence_length
Regular channel sequence length 1<=n<=16 (SQR1[23:20] L)
Definition: adc.hpp:176
static void enable_software_start_conversion(void)
Definition: adc.hpp:226
static void disable(void)
Definition: adc.hpp:218
static void disable_software_start_conversion(void)
Definition: adc.hpp:237
typename regular_channel_config_impl< channel, rank, _sample_time >::type regular_channel_config
Regular channel configuration.
Definition: adc.hpp:180
static void configure(void)
Configure ADC register using Tp type traits.
Definition: adc.hpp:191
Control register 2.
Definition: adc.hpp:89
sample_time
Sample time, for regular_channel_config<>
Definition: adc.hpp:42
Data alignment.
Definition: adc.hpp:164
typename dualmod_impl< 9 >::type alternate_trigger
1001: Alternate trigger mode only
Definition: adc.hpp:123
Regular sequence register 1.
Definition: adc.hpp:199
static void reset(void)
Definition: adc.hpp:203
static __always_inline Tp load(void)
typename dualmod_impl< 8 >::type slow_interleaved
1000: Slow interleaved mode only
Definition: adc.hpp:122
typename dualmod_impl< 2 >::type regular_simultaneous_alternate_trigger
0010: Combined regular simultaneous + alternate trigger mode
Definition: adc.hpp:116
Sample time register 1.
Definition: adc.hpp:112
typename dualmod_impl< 7 >::type fast_interleaved
0111: Fast interleaved mode only
Definition: adc.hpp:121
static uint16_t get_conversion_value(void)
Definition: adc.hpp:248
Regular sequence register 2.
Definition: adc.hpp:214
static void enable(void)
Definition: adc.hpp:215
typename dualmod_impl< 1 >::type regular_simultaneous_injected
0001: Combined regular simultaneous + injected simultaneous mode
Definition: adc.hpp:115
regbits< type, 20, 1 > EXTTRIG
External trigger conversion mode for regular channels.
Definition: adc.hpp:97
typename dualmod_impl< 4 >::type injected_simultaneous_slow_interleaved
0100: Combined injected simultaneous + slow Interleaved mode
Definition: adc.hpp:118
typename capture_compare_impl< timer, cc >::type capture_compare
CCx.
Definition: adc.hpp:150
Sample time register 2.
Definition: adc.hpp:130
typename dualmod_impl< 0 >::type independent
0000: Independent mode.
Definition: adc.hpp:114
typename dualmod_impl< 5 >::type injected_simultaneous
0101: Injected simultaneous mode only
Definition: adc.hpp:119
Regular sequence register 3.
Definition: adc.hpp:230
typename trigger_output_impl< timer >::type trigger_output
Definition: adc.hpp:154
Dual mode selection.
Definition: adc.hpp:112
typename dualmod_impl< 3 >::type injected_simultaneous_fast_interleaved
0011: Combined injected simultaneous + fast interleaved mode
Definition: adc.hpp:117
External event select for regular group.
Definition: adc.hpp:143
typename dualmod_impl< 6 >::type regular_simultaneous
0110: Regular simultaneous mode only
Definition: adc.hpp:120
Analog-to-digital converter (ADC)
Definition: adc.hpp:38
static __always_inline void clear(void)
regbits< type, 22, 1 > SWSTART
Start conversion of regular channels.
Definition: adc.hpp:95
static void wait_eoc(void)
Definition: adc.hpp:244
Control register 1.
Definition: adc.hpp:66