11/*!
2- \file gd32f1x0_adc.h
3- \brief definitions for the ADC
2+ \file gd32f1x0_adc.h
3+ \brief definitions for the ADC
44
55 \version 2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
66 \version 2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
77 \version 2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
88 \version 2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
99 \version 2019-11-20, V3.2.0, firmware update for GD32F1x0(x=3,5,7,9)
10- \version 2020-09-21, V3.3.0, firmware update for GD32F1x0(x=3,5,7,9)
11- \version 2022-08-15, V3.4.0, firmware update for GD32F1x0(x=3,5)
1210*/
1311
1412/*
15- Copyright (c) 2022 , GigaDevice Semiconductor Inc.
13+ Copyright (c) 2019 , GigaDevice Semiconductor Inc.
1614
1715 Redistribution and use in source and binary forms, with or without modification,
1816are permitted provided that the following conditions are met:
@@ -68,6 +66,10 @@ OF SUCH DAMAGE.
6866#define ADC_IDATA3 REG32(ADC + 0x00000048U) /*!< ADC inserted data register 3 */
6967#define ADC_RDATA REG32(ADC + 0x0000004CU) /*!< ADC regular data register */
7068
69+ #ifdef GD32F170_190
70+ #define ADC_OVSAMPCTL REG32(ADC + 0x00000080U) /*!< ADC oversampling control register */
71+ #endif /* GD32F170_190 */
72+
7173/* bits definitions */
7274/* ADC_STAT */
7375#define ADC_STAT_WDE BIT(0) /*!< analog watchdog event flag */
@@ -90,6 +92,10 @@ OF SUCH DAMAGE.
9092#define ADC_CTL0_IWDEN BIT(22) /*!< analog watchdog enable on inserted channels */
9193#define ADC_CTL0_RWDEN BIT(23) /*!< analog watchdog enable on regular channels */
9294
95+ #ifdef GD32F170_190
96+ #define ADC_CTL0_DRES BITS(24,25) /*!< ADC data resolution */
97+ #endif /* GD32F170_190 */
98+
9399/* ADC_CTL1 */
94100#define ADC_CTL1_ADCON BIT(0) /*!< ADC converter on */
95101#define ADC_CTL1_CTN BIT(1) /*!< continuous conversion */
@@ -126,12 +132,20 @@ OF SUCH DAMAGE.
126132#define ADC_ISQ_ISQN BITS(0,4) /*!< n conversion in regular sequence */
127133#define ADC_ISQ_IL BITS(20,21) /*!< inserted sequence length */
128134
129- /* ADC_IDATAx x=0..3 */
135+ /* ADC_IDATAx x=0..3*/
130136#define ADC_IDATAX_IDATAN BITS(0,15) /*!< inserted channel x conversion data */
131137
132- /* ADC_RDATA */
138+ /* ADC_RDT */
133139#define ADC_RDATA_RDATA BITS(0,15) /*!< regular channel data */
134140
141+ #ifdef GD32F170_190
142+ /* ADC_OVCTL */
143+ #define ADC_OVSAMPCTL_OVSEN BIT(0) /*!< oversampling enable */
144+ #define ADC_OVSAMPCTL_OVSR BITS(2,4) /*!< oversampling ratio */
145+ #define ADC_OVSAMPCTL_OVSS BITS(5,8) /*!< oversampling shift */
146+ #define ADC_OVSAMPCTL_TOVS BIT(9) /*!< triggered oversampling */
147+ #endif /* GD32F170_190 */
148+
135149/* constants definitions */
136150/* ADC flag definitions */
137151#define ADC_FLAG_WDE ADC_STAT_WDE /*!< analog watchdog event flag */
@@ -207,6 +221,35 @@ OF SUCH DAMAGE.
207221#define ADC_RESOLUTION_8B CTL0_DRES(2) /*!< 8-bit ADC resolution */
208222#define ADC_RESOLUTION_6B CTL0_DRES(3) /*!< 6-bit ADC resolution */
209223
224+ #ifdef GD32F170_190
225+ /* ADC oversampling shift */
226+ #define OVSAMPCTL_OVSS (regval ) (BITS(5,8) & ((uint32_t)(regval) << 5))
227+ #define ADC_OVERSAMPLING_SHIFT_NONE OVSAMPCTL_OVSS(0) /*!< no oversampling shift */
228+ #define ADC_OVERSAMPLING_SHIFT_1B OVSAMPCTL_OVSS(1) /*!< 1-bit oversampling shift */
229+ #define ADC_OVERSAMPLING_SHIFT_2B OVSAMPCTL_OVSS(2) /*!< 2-bit oversampling shift */
230+ #define ADC_OVERSAMPLING_SHIFT_3B OVSAMPCTL_OVSS(3) /*!< 3-bit oversampling shift */
231+ #define ADC_OVERSAMPLING_SHIFT_4B OVSAMPCTL_OVSS(4) /*!< 4-bit oversampling shift */
232+ #define ADC_OVERSAMPLING_SHIFT_5B OVSAMPCTL_OVSS(5) /*!< 5-bit oversampling shift */
233+ #define ADC_OVERSAMPLING_SHIFT_6B OVSAMPCTL_OVSS(6) /*!< 6-bit oversampling shift */
234+ #define ADC_OVERSAMPLING_SHIFT_7B OVSAMPCTL_OVSS(7) /*!< 7-bit oversampling shift */
235+ #define ADC_OVERSAMPLING_SHIFT_8B OVSAMPCTL_OVSS(8) /*!< 8-bit oversampling shift */
236+
237+ /* ADC oversampling ratio */
238+ #define OVSAMPCTL_OVSR (regval ) (BITS(2,4) & ((uint32_t)(regval) << 2))
239+ #define ADC_OVERSAMPLING_RATIO_MUL2 OVSAMPCTL_OVSR(0) /*!< oversampling ratio multiple 2 */
240+ #define ADC_OVERSAMPLING_RATIO_MUL4 OVSAMPCTL_OVSR(1) /*!< oversampling ratio multiple 4 */
241+ #define ADC_OVERSAMPLING_RATIO_MUL8 OVSAMPCTL_OVSR(2) /*!< oversampling ratio multiple 8 */
242+ #define ADC_OVERSAMPLING_RATIO_MUL16 OVSAMPCTL_OVSR(3) /*!< oversampling ratio multiple 16 */
243+ #define ADC_OVERSAMPLING_RATIO_MUL32 OVSAMPCTL_OVSR(4) /*!< oversampling ratio multiple 32 */
244+ #define ADC_OVERSAMPLING_RATIO_MUL64 OVSAMPCTL_OVSR(5) /*!< oversampling ratio multiple 64 */
245+ #define ADC_OVERSAMPLING_RATIO_MUL128 OVSAMPCTL_OVSR(6) /*!< oversampling ratio multiple 128 */
246+ #define ADC_OVERSAMPLING_RATIO_MUL256 OVSAMPCTL_OVSR(7) /*!< oversampling ratio multiple 256 */
247+
248+ /* ADC triggered oversampling */
249+ #define ADC_OVERSAMPLING_ALL_CONVERT (0U) /*!< all oversampled conversions for a channel are done consecutively after a trigger */
250+ #define ADC_OVERSAMPLING_ONE_CONVERT (1U) /*!< each oversampled conversion for a channel needs a trigger */
251+ #endif /* GD32F170_190 */
252+
210253/* ADC channel group definitions */
211254#define ADC_REGULAR_CHANNEL ((uint8_t)0x01U) /*!< ADC regular channel group */
212255#define ADC_INSERTED_CHANNEL ((uint8_t)0x02U) /*!< ADC inserted channel group */
@@ -322,4 +365,15 @@ void adc_watchdog_disable(void);
322365/* configure ADC analog watchdog threshold */
323366void adc_watchdog_threshold_config (uint16_t low_threshold , uint16_t high_threshold );
324367
368+ #ifdef GD32F170_190
369+ /* configure ADC resolution */
370+ void adc_resolution_config (uint32_t resolution );
371+ /* configure ADC oversample mode */
372+ void adc_oversample_mode_config (uint8_t mode , uint16_t shift , uint8_t ratio );
373+ /* enable ADC oversample mode */
374+ void adc_oversample_mode_enable (void );
375+ /* disable ADC oversample mode */
376+ void adc_oversample_mode_disable (void );
377+ #endif /* GD32F170_190 */
378+
325379#endif /* GD32F1X0_ADC_H */
0 commit comments