machine_adc.c 16.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * This file is part of the MicroPython project, http://micropython.org/
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2019 Damien P. George
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "py/runtime.h"
#include "py/mphal.h"
29
#include "adc.h"
30

31
#if defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32H7) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL)
32 33 34 35 36
#define ADC_V2 (1)
#else
#define ADC_V2 (0)
#endif

37
#if defined(STM32F4)
38 39 40
#define ADCx_COMMON ADC_COMMON_REGISTER(0)
#elif defined(STM32F7)
#define ADCx_COMMON ADC123_COMMON
41 42
#elif defined(STM32L4)
#define ADCx_COMMON __LL_ADC_COMMON_INSTANCE(0)
43 44
#endif

45
#if defined(STM32F0) || defined(STM32G0) || defined(STM32L0) || defined(STM32WL)
46 47
#define ADC_STAB_DELAY_US (1)
#define ADC_TEMPSENSOR_DELAY_US (10)
48 49
#elif defined(STM32G4)
#define ADC_STAB_DELAY_US (1) // TODO: Check if this is enough
50 51 52 53 54 55 56
#elif defined(STM32L4)
#define ADC_STAB_DELAY_US (10)
#elif defined(STM32WB)
#define ADC_STAB_DELAY_US (1)
#endif

#if defined(STM32F0)
57
#define ADC_SAMPLETIME_DEFAULT      ADC_SAMPLETIME_13CYCLES_5
58 59 60 61
#define ADC_SAMPLETIME_DEFAULT_INT  ADC_SAMPLETIME_239CYCLES_5
#elif defined(STM32F4) || defined(STM32F7)
#define ADC_SAMPLETIME_DEFAULT      ADC_SAMPLETIME_15CYCLES
#define ADC_SAMPLETIME_DEFAULT_INT  ADC_SAMPLETIME_480CYCLES
62 63 64
#elif defined(STM32G4)
#define ADC_SAMPLETIME_DEFAULT      ADC_SAMPLETIME_12CYCLES_5
#define ADC_SAMPLETIME_DEFAULT_INT  ADC_SAMPLETIME_247CYCLES_5
65 66 67
#elif defined(STM32H7)
#define ADC_SAMPLETIME_DEFAULT      ADC_SAMPLETIME_8CYCLES_5
#define ADC_SAMPLETIME_DEFAULT_INT  ADC_SAMPLETIME_387CYCLES_5
68
#elif defined(STM32G0) || defined(STM32L0) || defined(STM32WL)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#define ADC_SAMPLETIME_DEFAULT      ADC_SAMPLETIME_12CYCLES_5
#define ADC_SAMPLETIME_DEFAULT_INT  ADC_SAMPLETIME_160CYCLES_5
#elif defined(STM32L4) || defined(STM32WB)
#define ADC_SAMPLETIME_DEFAULT      ADC_SAMPLETIME_12CYCLES_5
#define ADC_SAMPLETIME_DEFAULT_INT  ADC_SAMPLETIME_247CYCLES_5
#endif

// Timeout for waiting for end-of-conversion
#define ADC_EOC_TIMEOUT_MS (10)

// This is a synthesised channel representing the maximum ADC reading (useful to scale other channels)
#define ADC_CHANNEL_VREF (0xffff)

static inline void adc_stabilisation_delay_us(uint32_t us) {
    mp_hal_delay_us(us + 1);
}

STATIC void adc_wait_eoc(ADC_TypeDef *adc, int32_t timeout_ms) {
    uint32_t t0 = mp_hal_ticks_ms();
    #if ADC_V2
89
    while (!(adc->ISR & ADC_ISR_EOC))
90
    #else
91
    while (!(adc->SR & ADC_SR_EOC))
92 93 94 95 96 97 98 99 100 101 102 103 104 105
    #endif
    {
        if (mp_hal_ticks_ms() - t0 > timeout_ms) {
            break; // timeout
        }
    }
}

#if defined(STM32H7)
STATIC const uint8_t adc_cr_to_bits_table[] = {16, 14, 12, 10, 8, 8, 8, 8};
#else
STATIC const uint8_t adc_cr_to_bits_table[] = {12, 10, 8, 6};
#endif

106
void adc_config(ADC_TypeDef *adc, uint32_t bits) {
107
    // Configure ADC clock source and enable ADC clock
108
    #if defined(STM32G0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL)
109
    __HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
110 111 112
    __HAL_RCC_ADC_CLK_ENABLE();
    #else
    if (adc == ADC1) {
113
        #if defined(STM32G4) || defined(STM32H7)
114 115 116 117 118 119 120
        __HAL_RCC_ADC12_CLK_ENABLE();
        #else
        __HAL_RCC_ADC1_CLK_ENABLE();
        #endif
    }
    #if defined(ADC2)
    if (adc == ADC2) {
121
        #if defined(STM32G4) || defined(STM32H7)
122 123 124 125 126 127 128 129
        __HAL_RCC_ADC12_CLK_ENABLE();
        #else
        __HAL_RCC_ADC2_CLK_ENABLE();
        #endif
    }
    #endif
    #if defined(ADC3)
    if (adc == ADC3) {
130 131 132
        #if defined(ADC345_COMMON)
        __HAL_RCC_ADC345_CLK_ENABLE();
        #else
133
        __HAL_RCC_ADC3_CLK_ENABLE();
134
        #endif
135 136 137 138
    }
    #endif
    #endif

139 140
    // Configure clock mode
    #if defined(STM32F0)
141
    adc->CFGR2 = 2 << ADC_CFGR2_CKMODE_Pos; // PCLK/4 (synchronous clock mode)
142
    #elif defined(STM32F4) || defined(STM32F7) || defined(STM32L4)
143
    ADCx_COMMON->CCR = 0; // ADCPR=PCLK/2
144 145
    #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
    ADC12_COMMON->CCR = 3 << ADC_CCR_CKMODE_Pos;
146 147 148
    #elif defined(STM32H7)
    ADC12_COMMON->CCR = 3 << ADC_CCR_CKMODE_Pos;
    ADC3_COMMON->CCR = 3 << ADC_CCR_CKMODE_Pos;
149
    #elif defined(STM32L0)
150
    ADC1_COMMON->CCR = 0; // ADCPR=PCLK/2
151 152
    #elif defined(STM32WB)
    ADC1_COMMON->CCR = 0 << ADC_CCR_PRESC_Pos | 0 << ADC_CCR_CKMODE_Pos; // PRESC=1, MODE=ASYNC
153 154
    #elif defined(STM32WL)
    ADC_COMMON->CCR = 0 << ADC_CCR_PRESC_Pos; // PRESC=1
155 156 157 158 159 160 161 162
    #endif

    #if defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
    if (adc->CR & ADC_CR_DEEPPWD) {
        adc->CR = 0; // disable deep powerdown
    }
    #endif

163
    #if defined(STM32H7) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL)
164 165 166 167 168 169 170 171 172 173
    if (!(adc->CR & ADC_CR_ADVREGEN)) {
        adc->CR = ADC_CR_ADVREGEN; // enable VREG
        #if defined(STM32H7)
        mp_hal_delay_us(10); // T_ADCVREG_STUP
        #elif defined(STM32L4) || defined(STM32WB)
        mp_hal_delay_us(20); // T_ADCVREG_STUP
        #endif
    }
    #endif

174
    #if ADC_V2
175 176
    if (!(adc->CR & ADC_CR_ADEN)) {
        // ADC isn't enabled so calibrate it now
177
        #if defined(STM32F0) || defined(STM32G0) || defined(STM32L0) || defined(STM32WL)
178
        LL_ADC_StartCalibration(adc);
179
        #elif defined(STM32G4) || defined(STM32L4) || defined(STM32WB)
180 181 182 183 184
        LL_ADC_StartCalibration(adc, LL_ADC_SINGLE_ENDED);
        #else
        LL_ADC_StartCalibration(adc, LL_ADC_CALIB_OFFSET_LINEARITY, LL_ADC_SINGLE_ENDED);
        #endif
        while (LL_ADC_IsCalibrationOnGoing(adc)) {
185 186 187
        }
    }

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    if (adc->CR & ADC_CR_ADEN) {
        // ADC enabled, need to disable it to change configuration
        if (adc->CR & ADC_CR_ADSTART) {
            adc->CR |= ADC_CR_ADSTP;
            while (adc->CR & ADC_CR_ADSTP) {
            }
        }
        adc->CR |= ADC_CR_ADDIS;
        while (adc->CR & ADC_CR_ADDIS) {
        }
    }
    #endif

    // Find resolution, defaulting to last element in table
    uint32_t res;
    for (res = 0; res <= MP_ARRAY_SIZE(adc_cr_to_bits_table); ++res) {
        if (adc_cr_to_bits_table[res] == bits) {
            break;
        }
    }

    #if defined(STM32F0) || defined(STM32L0)

    uint32_t cfgr1_clr = ADC_CFGR1_CONT | ADC_CFGR1_EXTEN | ADC_CFGR1_ALIGN | ADC_CFGR1_RES | ADC_CFGR1_DMAEN;
    uint32_t cfgr1 = res << ADC_CFGR1_RES_Pos;
    adc->CFGR1 = (adc->CFGR1 & ~cfgr1_clr) | cfgr1;

    #elif defined(STM32F4) || defined(STM32F7)

    uint32_t cr1_clr = ADC_CR1_RES;
    uint32_t cr1 = res << ADC_CR1_RES_Pos;
    adc->CR1 = (adc->CR1 & ~cr1_clr) | cr1;
    uint32_t cr2_clr = ADC_CR2_EXTEN | ADC_CR2_ALIGN | ADC_CR2_DMA | ADC_CR2_CONT;
    uint32_t cr2 = 0;
    adc->CR2 = (adc->CR2 & ~cr2_clr) | cr2;
    adc->SQR1 = 1 << ADC_SQR1_L_Pos; // 1 conversion in regular sequence

    #elif defined(STM32H7) || defined(STM32L4) || defined(STM32WB)

    uint32_t cfgr_clr = ADC_CFGR_CONT | ADC_CFGR_EXTEN | ADC_CFGR_RES;
    #if defined(STM32H7)
    cfgr_clr |= ADC_CFGR_DMNGT;
    #else
    cfgr_clr |= ADC_CFGR_ALIGN | ADC_CFGR_DMAEN;
    #endif
    uint32_t cfgr = res << ADC_CFGR_RES_Pos;
    adc->CFGR = (adc->CFGR & ~cfgr_clr) | cfgr;

    #endif
}

STATIC int adc_get_bits(ADC_TypeDef *adc) {
240
    #if defined(STM32F0) || defined(STM32G0) || defined(STM32L0) || defined(STM32WL)
241 242 243
    uint32_t res = (adc->CFGR1 & ADC_CFGR1_RES) >> ADC_CFGR1_RES_Pos;
    #elif defined(STM32F4) || defined(STM32F7)
    uint32_t res = (adc->CR1 & ADC_CR1_RES) >> ADC_CR1_RES_Pos;
244
    #elif defined(STM32G4) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
245 246 247 248 249 250 251 252
    uint32_t res = (adc->CFGR & ADC_CFGR_RES) >> ADC_CFGR_RES_Pos;
    #endif
    return adc_cr_to_bits_table[res];
}

STATIC void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
    #if ADC_V2
    if (!(adc->CR & ADC_CR_ADEN)) {
253
        if (adc->CR & 0x3f) {
254 255 256
            // Cannot enable ADC with CR!=0
            return;
        }
257
        adc->ISR = ADC_ISR_ADRDY; // clear ADRDY
258 259 260 261 262 263 264 265 266 267 268 269
        adc->CR |= ADC_CR_ADEN;
        adc_stabilisation_delay_us(ADC_STAB_DELAY_US);
        while (!(adc->ISR & ADC_ISR_ADRDY)) {
        }
    }
    #else
    if (!(adc->CR2 & ADC_CR2_ADON)) {
        adc->CR2 |= ADC_CR2_ADON;
        adc_stabilisation_delay_us(ADC_STAB_DELAY_US);
    }
    #endif

270
    #if defined(STM32F0) || defined(STM32G0) || defined(STM32L0)
271 272 273 274 275 276 277 278 279 280 281

    if (channel == ADC_CHANNEL_VREFINT) {
        ADC1_COMMON->CCR |= ADC_CCR_VREFEN;
    } else if (channel == ADC_CHANNEL_TEMPSENSOR) {
        ADC1_COMMON->CCR |= ADC_CCR_TSEN;
        adc_stabilisation_delay_us(ADC_TEMPSENSOR_DELAY_US);
    #if defined(ADC_CHANNEL_VBAT)
    } else if (channel == ADC_CHANNEL_VBAT) {
        ADC1_COMMON->CCR |= ADC_CCR_VBATEN;
    #endif
    }
282 283 284
    #if defined(STM32G0)
    adc->SMPR = sample_time << ADC_SMPR_SMP1_Pos; // select sample time from SMP1 (default)
    #else
285
    adc->SMPR = sample_time << ADC_SMPR_SMP_Pos; // select sample time
286
    #endif
287 288 289 290 291
    adc->CHSELR = 1 << channel; // select channel for conversion

    #elif defined(STM32F4) || defined(STM32F7)

    if (channel == ADC_CHANNEL_VREFINT || channel == ADC_CHANNEL_TEMPSENSOR) {
292
        ADCx_COMMON->CCR = (ADCx_COMMON->CCR & ~ADC_CCR_VBATE) | ADC_CCR_TSVREFE;
293 294 295 296
        if (channel == ADC_CHANNEL_TEMPSENSOR) {
            adc_stabilisation_delay_us(ADC_TEMPSENSOR_DELAY_US);
        }
    } else if (channel == ADC_CHANNEL_VBAT) {
297
        ADCx_COMMON->CCR |= ADC_CCR_VBATE;
298 299 300 301 302 303 304 305 306 307 308 309 310 311
    }

    adc->SQR3 = (channel & 0x1f) << ADC_SQR3_SQ1_Pos; // select channel for first conversion

    __IO uint32_t *smpr;
    if (channel <= 9) {
        smpr = &adc->SMPR2;
    } else {
        smpr = &adc->SMPR1;
        channel -= 10;
    }
    *smpr = (*smpr & ~(7 << (channel * 3))) | sample_time << (channel * 3); // select sample time

    #elif defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
312 313 314
    #if defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
    ADC_Common_TypeDef *adc_common = ADC12_COMMON;
    #elif defined(STM32H7)
315
    adc->PCSEL |= 1 << channel;
316 317
    ADC_Common_TypeDef *adc_common = adc == ADC3 ? ADC3_COMMON : ADC12_COMMON;
    #elif defined(STM32L4)
318
    ADC_Common_TypeDef *adc_common = ADCx_COMMON;
319 320 321 322 323 324 325 326 327 328 329
    #elif defined(STM32WB)
    ADC_Common_TypeDef *adc_common = ADC1_COMMON;
    #endif
    if (channel == ADC_CHANNEL_VREFINT) {
        adc_common->CCR |= ADC_CCR_VREFEN;
    } else if (channel == ADC_CHANNEL_TEMPSENSOR) {
        adc_common->CCR |= ADC_CCR_TSEN;
        adc_stabilisation_delay_us(ADC_TEMPSENSOR_DELAY_US);
    } else if (channel == ADC_CHANNEL_VBAT) {
        adc_common->CCR |= ADC_CCR_VBATEN;
    }
330
    adc->SQR1 = (channel & 0x1f) << ADC_SQR1_SQ1_Pos | (1 - 1) << ADC_SQR1_L_Pos;
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
    __IO uint32_t *smpr;
    if (channel <= 9) {
        smpr = &adc->SMPR1;
    } else {
        smpr = &adc->SMPR2;
        channel -= 10;
    }
    *smpr = (*smpr & ~(7 << (channel * 3))) | sample_time << (channel * 3); // select sample time

    #endif
}

STATIC uint32_t adc_read_channel(ADC_TypeDef *adc) {
    #if ADC_V2
    adc->CR |= ADC_CR_ADSTART;
    #else
    adc->CR2 |= ADC_CR2_SWSTART;
    #endif
    adc_wait_eoc(adc, ADC_EOC_TIMEOUT_MS);
    uint32_t value = adc->DR;
    return value;
}

354
uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
355 356 357 358
    if (channel == ADC_CHANNEL_VREF) {
        return 0xffff;
    }

359
    // Select, configure and read the channel.
360 361
    adc_config_channel(adc, channel, sample_time);
    uint32_t raw = adc_read_channel(adc);
362 363 364 365 366

    // If VBAT was sampled then deselect it to prevent battery drain.
    adc_deselect_vbat(adc, channel);

    // Scale raw reading to 16 bit value using a Taylor expansion (for bits <= 16).
367 368 369 370 371 372 373 374 375 376 377 378 379
    uint32_t bits = adc_get_bits(adc);
    #if defined(STM32H7)
    if (bits < 8) {
        // For 6 and 7 bits
        return raw << (16 - bits) | raw << (16 - 2 * bits) | raw >> (3 * bits - 16);
    }
    #endif
    return raw << (16 - bits) | raw >> (2 * bits - 16);
}

/******************************************************************************/
// MicroPython bindings for machine.ADC

380 381
#if !BUILDING_MBOOT

382 383 384 385 386 387 388 389 390 391 392 393
const mp_obj_type_t machine_adc_type;

typedef struct _machine_adc_obj_t {
    mp_obj_base_t base;
    ADC_TypeDef *adc;
    uint32_t channel;
    uint32_t sample_time;
} machine_adc_obj_t;

STATIC void machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
    machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in);
    unsigned adc_id = 1;
394 395 396 397 398 399
    #if defined(ADC2)
    if (self->adc == ADC2) {
        adc_id = 2;
    }
    #endif
    #if defined(ADC3)
400 401 402 403
    if (self->adc == ADC3) {
        adc_id = 3;
    }
    #endif
404 405 406 407 408 409 410 411 412 413 414 415 416 417
    mp_printf(print, "<ADC%u channel=%u>", adc_id, self->channel);
}

// ADC(id)
STATIC mp_obj_t machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
    // Check number of arguments
    mp_arg_check_num(n_args, n_kw, 1, 1, false);

    mp_obj_t source = all_args[0];

    uint32_t channel;
    uint32_t sample_time = ADC_SAMPLETIME_DEFAULT;
    ADC_TypeDef *adc;
    if (mp_obj_is_int(source)) {
418 419 420
        #if defined(STM32WL)
        adc = ADC;
        #else
421
        adc = ADC1;
422
        #endif
423 424
        channel = mp_obj_get_int(source);
        if (channel == ADC_CHANNEL_VREFINT
425 426 427
            #if defined(STM32G4)
            || channel == ADC_CHANNEL_TEMPSENSOR_ADC1
            #else
428
            || channel == ADC_CHANNEL_TEMPSENSOR
429
            #endif
430 431 432 433 434 435 436 437 438
            #if defined(ADC_CHANNEL_VBAT)
            || channel == ADC_CHANNEL_VBAT
            #endif
            ) {
            sample_time = ADC_SAMPLETIME_DEFAULT_INT;
        }
    } else {
        const pin_obj_t *pin = pin_find(source);
        if (pin->adc_num & PIN_ADC1) {
439 440 441
            #if defined(STM32WL)
            adc = ADC;
            #else
442
            adc = ADC1;
443
            #endif
444 445 446 447
        #if defined(ADC2)
        } else if (pin->adc_num & PIN_ADC2) {
            adc = ADC2;
        #endif
448
        #if defined(ADC3)
449 450 451 452 453
        } else if (pin->adc_num & PIN_ADC3) {
            adc = ADC3;
        #endif
        } else {
            // No ADC function on given pin
454
            mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%q) does not have ADC capabilities"), pin->name);
455 456 457 458 459 460 461 462 463
        }
        channel = pin->adc_channel;

        // Configure the GPIO pin in ADC mode
        mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
    }

    adc_config(adc, 12);

464
    machine_adc_obj_t *o = mp_obj_malloc(machine_adc_obj_t, &machine_adc_type);
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
    o->adc = adc;
    o->channel = channel;
    o->sample_time = sample_time;

    return MP_OBJ_FROM_PTR(o);
}

// read_u16()
STATIC mp_obj_t machine_adc_read_u16(mp_obj_t self_in) {
    machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in);
    return MP_OBJ_NEW_SMALL_INT(adc_config_and_read_u16(self->adc, self->channel, self->sample_time));
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_u16_obj, machine_adc_read_u16);

STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = {
    { MP_ROM_QSTR(MP_QSTR_read_u16), MP_ROM_PTR(&machine_adc_read_u16_obj) },

    { MP_ROM_QSTR(MP_QSTR_VREF), MP_ROM_INT(ADC_CHANNEL_VREF) },
    { MP_ROM_QSTR(MP_QSTR_CORE_VREF), MP_ROM_INT(ADC_CHANNEL_VREFINT) },
484 485 486
    #if defined(STM32G4)
    { MP_ROM_QSTR(MP_QSTR_CORE_TEMP), MP_ROM_INT(ADC_CHANNEL_TEMPSENSOR_ADC1) },
    #else
487
    { MP_ROM_QSTR(MP_QSTR_CORE_TEMP), MP_ROM_INT(ADC_CHANNEL_TEMPSENSOR) },
488
    #endif
489 490 491 492 493 494 495 496 497 498 499
    #if defined(ADC_CHANNEL_VBAT)
    { MP_ROM_QSTR(MP_QSTR_CORE_VBAT), MP_ROM_INT(ADC_CHANNEL_VBAT) },
    #endif
};
STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table);

const mp_obj_type_t machine_adc_type = {
    { &mp_type_type },
    .name = MP_QSTR_ADC,
    .print = machine_adc_print,
    .make_new = machine_adc_make_new,
500
    .locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict,
501
};
502 503

#endif