rp2/machine_adc.c: Initialise the ADC GPIO when a Pin is referred.

The change closes the gap when an integer was used as Pin reference.
With that change, e.g. ADC(26), ADC(Pin(26)) and ADC("GP26") behave
identical and the GPIO is initialised in high-Z mode. Only when using
ADC channel numbers the ADC is not initialised and that step is left
to the user code.

Signed-off-by: robert-hh <robert@hammelrath.com>
pull/13509/head
robert-hh 2024-01-24 16:48:43 +01:00
rodzic b3c62f3169
commit e5ec9e8aff
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 32EC5F755D5A3A93
1 zmienionych plików z 3 dodań i 6 usunięć

Wyświetl plik

@ -73,12 +73,9 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
bool is_ext = false;
const machine_pin_obj_t *pin = NULL;
if (mp_obj_is_int(source)) {
// Get and validate channel number.
channel = mp_obj_get_int(source);
if (ADC_IS_VALID_GPIO(channel)) {
channel = ADC_CHANNEL_FROM_GPIO(channel);
} else if (!(channel >= 0 && channel <= ADC_CHANNEL_TEMPSENSOR)) {
if (mp_obj_is_int(source) && (channel = mp_obj_get_int(source)) <= ADC_CHANNEL_TEMPSENSOR) {
// Validate channel number.
if (channel < 0) {
mp_raise_ValueError(MP_ERROR_TEXT("invalid channel"));
}
} else {