33#ifdef LIBOPENCM3_ADC_H
35#ifndef LIBOPENCM3_ADC_COMMON_V2_H
36#define LIBOPENCM3_ADC_COMMON_V2_H
42#define ADC_ISR(adc) MMIO32((adc) + 0x00)
44#define ADC_IER(adc) MMIO32((adc) + 0x04)
46#define ADC_CR(adc) MMIO32((adc) + 0x08)
48#define ADC_CFGR1(adc) MMIO32((adc) + 0x0C)
50#define ADC_CFGR2(adc) MMIO32((adc) + 0x10)
52#define ADC_SMPR1(adc) MMIO32((adc) + 0x14)
54#define ADC_TR1(adc) MMIO32((adc) + 0x20)
56#define ADC_DR(adc) MMIO32((adc) + 0x40)
60#define ADC_CCR(adc) MMIO32((adc) + 0x300 + 0x8)
70#define ADC_ISR_AWD1 (1 << 7)
72#define ADC_ISR_OVR (1 << 4)
74#define ADC_ISR_EOS (1 << 3)
75#define ADC_ISR_EOSEQ ADC_ISR_EOS
77#define ADC_ISR_EOC (1 << 2)
79#define ADC_ISR_EOSMP (1 << 1)
81#define ADC_ISR_ADRDY (1 << 0)
90#define ADC_IER_AWD1IE (1 << 7)
92#define ADC_IER_OVRIE (1 << 4)
94#define ADC_IER_EOSIE (1 << 3)
95#define ADC_IER_EOSEQIE ADC_IER_EOSIE
97#define ADC_IER_EOCIE (1 << 2)
99#define ADC_IER_EOSMPIE (1 << 1)
101#define ADC_IER_ADRDYIE (1 << 0)
110#define ADC_CR_ADCAL (1 << 31)
112#define ADC_CR_ADSTP (1 << 4)
114#define ADC_CR_ADSTART (1 << 2)
116#define ADC_CR_ADDIS (1 << 1)
118#define ADC_CR_ADEN (1 << 0)
126#define ADC_CFGR1_AWD1CH_SHIFT 26
127#define ADC_CFGR1_AWD1CH (0x1F << ADC_CFGR1_AWD1CH_SHIFT)
129#define ADC_CFGR1_AWD1CH_VAL(x) ((x) << ADC_CFGR1_AWD1CH_SHIFT)
132#define ADC_CFGR1_AWD1EN (1 << 23)
134#define ADC_CFGR1_AWD1SGL (1 << 22)
136#define ADC_CFGR1_DISCEN (1 << 16)
138#define ADC_CFGR1_AUTDLY (1 << 14)
140#define ADC_CFGR1_CONT (1 << 13)
142#define ADC_CFGR1_OVRMOD (1 << 12)
144#define ADC_CFGR1_EXTEN_MASK (0x3 << 10)
147#define ADC_CFGR1_EXTEN_DISABLED (0x0 << 10)
148#define ADC_CFGR1_EXTEN_RISING_EDGE (0x1 << 10)
149#define ADC_CFGR1_EXTEN_FALLING_EDGE (0x2 << 10)
150#define ADC_CFGR1_EXTEN_BOTH_EDGES (0x3 << 10)
153#define ADC_CFGR1_RES_MASK (0x3 << 3)
156#define ADC_CFGR1_RES_12_BIT (0x0 << 3)
157#define ADC_CFGR1_RES_10_BIT (0x1 << 3)
158#define ADC_CFGR1_RES_8_BIT (0x2 << 3)
159#define ADC_CFGR1_RES_6_BIT (0x3 << 3)
163#define ADC_CFGR1_DMACFG (1 << 1)
166#define ADC_CFGR1_DMAEN (1 << 0)
186#define ADC_TR1_LT_SHIFT 0
187#define ADC_TR1_LT_MASK 0xFFF
188#define ADC_TR1_LT (0xFFF << ADC_TR1_LT_SHIFT)
190#define ADC_TR1_LT_VAL(x) (((x) & ADC_TR1_LT_MASK) << ADC_TR1_LT_SHIFT)
192#define ADC_TR1_HT_SHIFT 16
193#define ADC_TR1_HT_MASK 0xFFF
194#define ADC_TR1_HT (0xFFF << ADC_TR1_HT_SHIFT)
196#define ADC_TR1_HT_VAL(x) (((x) & ADC_TR1_HT_MASK) << ADC_TR1_HT_SHIFT)
205#define ADC_CCR_VBATEN (1 << 24)
208#define ADC_CCR_TSEN (1 << 23)
211#define ADC_CCR_VREFEN (1 << 22)
void adc_set_sample_time_on_all_channels(uint32_t adc, uint8_t time)
ADC Set the Sample Time for All Channels.
void adc_enable_delayed_conversion_mode(uint32_t adc)
Enable Delayed Conversion Mode.
void adc_start_conversion_regular(uint32_t adc)
ADC Software Triggered Conversion on Regular Channels.
void adc_disable_temperature_sensor(void)
Disable the temperature sensor (only)
void adc_disable_overrun_interrupt(uint32_t adc)
ADC Disable the Overrun Interrupt.
void adc_power_off(uint32_t adc)
Turn off the ADC This will actually block if it needs to turn off a currently running conversion,...
void adc_enable_vrefint(void)
Enable the internal voltage reference (only) The channel this is available on is unfortunately not co...
void adc_enable_dma_circular_mode(uint32_t adc)
Enable circular mode for DMA transfers.
void adc_calibrate_async(uint32_t adc)
Start the ADC calibration and immediately return.
void adc_disable_vrefint(void)
Disable the internal voltage reference (only)
void adc_set_continuous_conversion_mode(uint32_t adc)
Enable Continuous Conversion Mode In this mode the ADC starts a new conversion of a single channel or...
bool adc_is_calibrating(uint32_t adc)
Is the ADC Calibrating?
void adc_clear_overrun_flag(uint32_t adc)
ADC Clear Overrun Flags.
void adc_set_single_conversion_mode(uint32_t adc)
Enable Single Conversion Mode In this mode the ADC performs a conversion of one channel or a channel ...
bool adc_is_power_on(uint32_t adc)
Is the ADC powered up and ready?
void adc_power_on_async(uint32_t adc)
Turn on the ADC (async)
void adc_set_resolution(uint32_t adc, uint16_t resolution)
ADC Set Resolution.
void adc_power_on(uint32_t adc)
Turn on the ADC.
uint32_t adc_read_regular(uint32_t adc)
ADC Read from the Regular Conversion Result Register.
void adc_enable_eoc_interrupt(uint32_t adc)
ADC Enable Regular End-Of-Conversion Interrupt.
void adc_disable_eoc_interrupt(uint32_t adc)
ADC Disable Regular End-Of-Conversion Interrupt.
bool adc_eos(uint32_t adc)
ADC Read the End-of-Sequence Flag for Regular Conversions.
void adc_enable_temperature_sensor(void)
Enable the temperature sensor (only) The channel this is available on is unfortunately not consistent...
void adc_disable_dma(uint32_t adc)
ADC Disable DMA Transfers.
void adc_set_left_aligned(uint32_t adc)
ADC Set the Data as Left Aligned.
void adc_power_off_async(uint32_t adc)
Turn off the ADC (async) This will actually block if it needs to turn off a currently running convers...
void adc_set_right_aligned(uint32_t adc)
ADC Set the Data as Right Aligned.
void adc_disable_delayed_conversion_mode(uint32_t adc)
Enable Delayed Conversion Mode.
void adc_enable_overrun_interrupt(uint32_t adc)
ADC Enable the Overrun Interrupt.
void adc_enable_dma(uint32_t adc)
ADC Enable DMA Transfers.
void adc_disable_dma_circular_mode(uint32_t adc)
Disable circular mode for DMA transfers.
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
ADC Set a Regular Channel Conversion Sequence.
bool adc_get_overrun_flag(uint32_t adc)
ADC Read the Overrun Flag.
bool adc_is_power_off(uint32_t adc)
Is the ADC powered down?
void adc_calibrate(uint32_t adc)
Start ADC calibration and wait for it to finish.
bool adc_eoc(uint32_t adc)
ADC Read the End-of-Conversion Flag.