|
10 | 10 | #include <rtthread.h>
|
11 | 11 | #include <rtdevice.h>
|
12 | 12 | #include "drv_adc.h"
|
| 13 | +#include "drv_pinmux.h" |
13 | 14 |
|
14 | 15 | #define DBG_LEVEL DBG_LOG
|
15 | 16 | #include <rtdbg.h>
|
@@ -100,10 +101,101 @@ static const struct rt_adc_ops _adc_ops =
|
100 | 101 | .convert = _adc_convert,
|
101 | 102 | };
|
102 | 103 |
|
| 104 | + |
| 105 | +#if defined(BOARD_TYPE_MILKV_DUO) || defined(BOARD_TYPE_MILKV_DUO_SPINOR) |
| 106 | + |
| 107 | +/* |
| 108 | + * cv180xb supports |
| 109 | + * - adc1 & adc2 for active domain |
| 110 | + * - adc3 for no-die domain |
| 111 | + * |
| 112 | + * FIXME: currnet adc driver only support adc1 in active domain |
| 113 | + */ |
| 114 | +#ifdef BSP_USING_ADC_ACTIVE |
| 115 | +static const char *pinname_whitelist_adc1_active[] = { |
| 116 | + "ADC1", |
| 117 | + NULL, |
| 118 | +}; |
| 119 | +static const char *pinname_whitelist_adc2_active[] = { |
| 120 | + NULL, |
| 121 | +}; |
| 122 | +static const char *pinname_whitelist_adc3_active[] = { |
| 123 | + NULL, |
| 124 | +}; |
| 125 | +#endif |
| 126 | + |
| 127 | +#ifdef BSP_USING_ADC_NODIE |
| 128 | +static const char *pinname_whitelist_adc1_nodie[] = { |
| 129 | + NULL, |
| 130 | +}; |
| 131 | +static const char *pinname_whitelist_adc2_nodie[] = { |
| 132 | + NULL, |
| 133 | +}; |
| 134 | +static const char *pinname_whitelist_adc3_nodie[] = { |
| 135 | + NULL, |
| 136 | +}; |
| 137 | +#endif |
| 138 | + |
| 139 | +#elif defined(BOARD_TYPE_MILKV_DUO256M) || defined(BOARD_TYPE_MILKV_DUO256M_SPINOR) |
| 140 | + |
| 141 | +/* |
| 142 | + * sg2002 supports |
| 143 | + * - adc1 for active domain |
| 144 | + * - adc1/adc2/adc3 for no-die domain |
| 145 | + * |
| 146 | + * FIXME: currnet adc driver only support adc1 in active domain |
| 147 | + */ |
| 148 | + |
| 149 | +#ifdef BSP_USING_ADC_ACTIVE |
| 150 | +static const char *pinname_whitelist_adc1_active[] = { |
| 151 | + "ADC1", |
| 152 | + NULL, |
| 153 | +}; |
| 154 | +static const char *pinname_whitelist_adc2_active[] = { |
| 155 | + NULL, |
| 156 | +}; |
| 157 | +static const char *pinname_whitelist_adc3_active[] = { |
| 158 | + NULL, |
| 159 | +}; |
| 160 | +#endif |
| 161 | + |
| 162 | +#ifdef BSP_USING_ADC_NODIE |
| 163 | +static const char *pinname_whitelist_adc1_nodie[] = { |
| 164 | + NULL, |
| 165 | +}; |
| 166 | +static const char *pinname_whitelist_adc2_nodie[] = { |
| 167 | + NULL, |
| 168 | +}; |
| 169 | +static const char *pinname_whitelist_adc3_nodie[] = { |
| 170 | + NULL, |
| 171 | +}; |
| 172 | +#endif |
| 173 | + |
| 174 | +#else |
| 175 | + #error "Unsupported board type!" |
| 176 | +#endif |
| 177 | + |
| 178 | +static void rt_hw_adc_pinmux_config() |
| 179 | +{ |
| 180 | +#ifdef BSP_USING_ADC_ACTIVE |
| 181 | + pinmux_config(BSP_ACTIVE_ADC1_PINNAME, XGPIOB_3, pinname_whitelist_adc1_active); |
| 182 | + pinmux_config(BSP_ACTIVE_ADC2_PINNAME, XGPIOB_6, pinname_whitelist_adc2_active); |
| 183 | + /* cv1800b & sg2002 don't support ADC3 either in active domain */ |
| 184 | +#endif |
| 185 | + |
| 186 | +#ifdef BSP_USING_ADC_NODIE |
| 187 | + pinmux_config(BSP_NODIE_ADC1_PINNAME, PWR_GPIO_2, pinname_whitelist_adc1_nodie); |
| 188 | + pinmux_config(BSP_NODIE_ADC2_PINNAME, PWR_GPIO_1, pinname_whitelist_adc2_nodie); |
| 189 | + pinmux_config(BSP_NODIE_ADC3_PINNAME, PWR_VBAT_DET, pinname_whitelist_adc3_nodie); |
| 190 | +#endif |
| 191 | +} |
| 192 | + |
103 | 193 | int rt_hw_adc_init(void)
|
104 | 194 | {
|
105 | 195 | rt_uint8_t i;
|
106 | 196 |
|
| 197 | + rt_hw_adc_pinmux_config(); |
| 198 | + |
107 | 199 | for (i = 0; i < sizeof(adc_dev_config) / sizeof(adc_dev_config[0]); i++)
|
108 | 200 | {
|
109 | 201 | cvi_do_calibration(adc_dev_config[i].base);
|
|
0 commit comments