32#ifndef LIBOPENCM3_ADC_H
33#define LIBOPENCM3_ADC_H
45#define ADC_CHANNEL_TEMP 12
46#define ADC_CHANNEL_VREF 13
47#define ADC_CHANNEL_VBAT 14
54#define ADC_AWD1TR(adc) MMIO32((adc) + 0x20)
56#define ADC_AWD2TR(adc) MMIO32((adc) + 0x22)
58#define ADC_AWD3TR(adc) MMIO32((adc) + 0x2c)
61#define ADC_AWD2CR(adc) MMIO32((adc) + 0xA0)
63#define ADC_AWD3CR(adc) MMIO32((adc) + 0xA4)
66#define ADC_CALFACT(adc) MMIO32((adc) + 0xB4)
75#define ADC_ISR_CCRDY (1 << 13)
83#define ADC_IER_CCRDYIE (1 << 13)
90#define ADC_CCR_PRESC_MASK (0xf)
91#define ADC_CCR_PRESC_SHIFT (18)
94#define ADC_CCR_PRESC_NODIV (0x0)
95#define ADC_CCR_PRESC_DIV2 (0x1)
96#define ADC_CCR_PRESC_DIV4 (0x2)
97#define ADC_CCR_PRESC_DIV6 (0x3)
98#define ADC_CCR_PRESC_DIV8 (0x4)
99#define ADC_CCR_PRESC_DIV10 (0x5)
100#define ADC_CCR_PRESC_DIV12 (0x6)
101#define ADC_CCR_PRESC_DIV16 (0x7)
102#define ADC_CCR_PRESC_DIV32 (0x8)
103#define ADC_CCR_PRESC_DIV64 (0x9)
104#define ADC_CCR_PRESC_DIV128 (0xa)
105#define ADC_CCR_PRESC_DIV256 (0xb)
114#define ADC_CR_ADVREGEN (1 << 28)
122#define ADC_CFGR1_ALIGN (1 << 5)
125#define ADC_CFGR1_EXTSEL_SHIFT 6
126#define ADC_CFGR1_EXTSEL (0x7 << ADC_CFGR1_EXTSEL_SHIFT)
127#define ADC_CFGR1_EXTSEL_VAL(x) ((x) << ADC_CFGR1_EXTSEL_SHIFT)
130#define ADC_CFGR1_EXTSEL_TIM1_TRGO2 0x0
131#define ADC_CFGR1_EXTSEL_TIM1_CC4 0x1
132#define ADC_CFGR1_EXTSEL_TIM2_TRGO 0x2
133#define ADC_CFGR1_EXTSEL_TIM3_TRGO 0x3
134#define ADC_CFGR1_EXTSEL_TIM15_TRGO 0x4
135#define ADC_CFGR1_EXTSEL_TIM6_TRGO 0x5
136#define ADC_CFGR1_EXTSEL_TIM4_TRGO 0x6
137#define ADC_CFGR1_EXTSEL_EXTI11 0x7
141#define ADC_CFGR1_CHSELRMOD (1 << 21)
148#define ADC_CFGR2_CKMODE_SHIFT (30)
149#define ADC_CFGR2_CKMODE_MASK (0x3)
152#define ADC_CFGR2_CKMODE_ADCCLK (0x0)
153#define ADC_CFGR2_CKMODE_PCLK_DIV2 (0x1)
154#define ADC_CFGR2_CKMODE_PCLK_DIV4 (0x2)
155#define ADC_CFGR2_CKMODE_PCLK (0x3)
159#define ADC_CFGR2_LFTRIG (1 << 29)
162#define ADC_CFGR2_TOVS (1 << 9)
164#define ADC_CFGR2_OVSS_SHIFT (5)
165#define ADC_CFGR2_OVSS_MASK (0xf)
168#define ADC_CFGR2_OVSS_BITS(bits) (bits)
171#define ADC_CFGR2_OVSR_SHIFT (2)
172#define ADC_CFGR2_OVSR_MASK (0x7)
175#define ADC_CFGR2_OVSR_2x (0x0)
176#define ADC_CFGR2_OVSR_4x (0x1)
177#define ADC_CFGR2_OVSR_8x (0x2)
178#define ADC_CFGR2_OVSR_16x (0x3)
179#define ADC_CFGR2_OVSR_32x (0x4)
180#define ADC_CFGR2_OVSR_64x (0x5)
181#define ADC_CFGR2_OVSR_128x (0x6)
182#define ADC_CFGR2_OVSR_256x (0x7)
186#define ADC_CFGR2_OVSE (1 << 0)
194#define ADC_SMPR_SMPSEL_SHIFT 0x8
195#define ADC_SMPR_SMPSEL_MASK 0x7ffff
196#define ADC_SMPR_SMPSEL_CHANNEL_SHIFT(channel) ((channel) + ADC_SMPR_SMPSEL_SHIFT)
197#define ADC_SMPR_SMPSEL_CHANNEL_MASK (1)
200#define ADC_SMPR_SMPSEL_SMP1 0x0
201#define ADC_SMPR_SMPSEL_SMP2 0x1
205#define ADC_SMPR_SMP1_SHIFT 0x0
206#define ADC_SMPR_SMP1_MASK 0x7
209#define ADC_SMPR_SMP2_SHIFT 0x4
210#define ADC_SMPR_SMP2_MASK 0x7
214#define ADC_SMPR_SMPx_001DOT5CYC 0x0
215#define ADC_SMPR_SMPx_003DOT5CYC 0x1
216#define ADC_SMPR_SMPx_007DOT5CYC 0x2
217#define ADC_SMPR_SMPx_012DOT5CYC 0x3
218#define ADC_SMPR_SMPx_019DOT5CYC 0x4
219#define ADC_SMPR_SMPx_039DOT5CYC 0x5
220#define ADC_SMPR_SMPx_079DOT5CYC 0x6
221#define ADC_SMPR_SMPx_160DOT5CYC 0x7
230#define ADC_AWDTR1_LT_SHIFT 0
231#define ADC_AWDTR1_LT (0xFFF << ADC_TR1_LT_SHIFT)
232#define ADC_AWDTR1_LT_VAL(x) ((x) << ADC_TR1_LT_SHIFT)
234#define ADC_AWDTR1_HT_SHIFT 16
235#define ADC_AWDTR1_HT (0xFFF << ADC_TR1_HT_SHIFT)
236#define ADC_AWDTR1_HT_VAL(x) ((x) << ADC_TR1_HT_SHIFT)
243#define ADC_AWDTR2_LT_SHIFT 0
244#define ADC_AWDTR2_LT (0xFFF << ADC_TR2_LT_SHIFT)
245#define ADC_AWDTR2_LT_VAL(x) ((x) << ADC_TR2_LT_SHIFT)
247#define ADC_AWDTR2_HT_SHIFT 16
248#define ADC_AWDTR2_HT (0xFFF << ADC_TR2_HT_SHIFT)
249#define ADC_AWDTR2_HT_VAL(x) ((x) << ADC_TR2_HT_SHIFT)
257#define ADC_CHSELR_MAX_CHANNELS 18
260#define ADC_CHSELR_MAX_SQS 8
262#define ADC_CHSELR_SQS_MAX_CHANNEL 14
264#define ADC_CHSELR_SQx_MASK 0xf
265#define ADC_CHSELR_SQx_SHIFT(seqnum) (4 * ((seqnum)-1))
268#define ADC_CHSELR_SQx(seqnum, value) ((value) << ADC_CHSELR_SQx_SHIFT(seqnum))
271#define ADC_CHSELR_SQx_EOS 0xf
278#define ADC_AWDTR3_LT_SHIFT 0
279#define ADC_AWDTR3_LT (0xFFF << ADC_TR3_LT_SHIFT)
280#define ADC_AWDTR3_LT_VAL(x) ((x) << ADC_TR3_LT_SHIFT)
282#define ADC_AWDTR3_HT_SHIFT 16
283#define ADC_AWDTR3_HT (0xFFF << ADC_TR3_HT_SHIFT)
284#define ADC_AWDTR3_HT_VAL(x) ((x) << ADC_TR3_HT_SHIFT)
292#define ADC_AW2CR_AWD2CHx_EN(x) (1 << x)
300#define ADC_AW3CR_AWD3CHx_EN(x) (1 << x)
308#define ADC_CLKSOURCE_ADC ADC_CFGR2_CKMODE_ADCCLK
309#define ADC_CLKSOURCE_PCLK ADC_CFGR2_CKMODE_PCLK
310#define ADC_CLKSOURCE_PCLK_DIV2 ADC_CFGR2_CKMODE_PCLK_DIV2
311#define ADC_CLKSOURCE_PCLK_DIV4 ADC_CFGR2_CKMODE_PCLK_DIV4
316#define ADC_SMPTIME_001DOT5 ADC_SMPR_SMPx_001DOT5CYC
317#define ADC_SMPTIME_003DOT5 ADC_SMPR_SMPx_003DOT5CYC
318#define ADC_SMPTIME_007DOT5 ADC_SMPR_SMPx_007DOT5CYC
319#define ADC_SMPTIME_012DOT5 ADC_SMPR_SMPx_012DOT5CYC
320#define ADC_SMPTIME_019DOT5 ADC_SMPR_SMPx_019DOT5CYC
321#define ADC_SMPTIME_039DOT5 ADC_SMPR_SMPx_039DOT5CYC
322#define ADC_SMPTIME_079DOT5 ADC_SMPR_SMPx_079DOT5CYC
323#define ADC_SMPTIME_160DOT5 ADC_SMPR_SMPx_160DOT5CYC
void adc_disable_regulator(uint32_t adc)
Disable the ADC Voltage regulator.
void adc_set_clk_prescale(uint32_t adc, uint32_t prescale)
ADC Set Clock Prescale.
void adc_set_selection_sample_time(uint32_t adc, uint8_t selection, uint8_t time)
ADC Set the Sample Time for Given Selection.
void adc_enable_regulator(uint32_t adc)
Enable the ADC Voltage regulator.
void adc_set_channel_sample_time_selection(uint32_t adc, uint8_t channel, uint8_t selection)
ADC Set the Sample Time Selection for a Single Channel.
void adc_set_clk_source(uint32_t adc, uint32_t source)
ADC Set Clock Source.