kopia lustrzana https://github.com/micropython/micropython
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
rodzic
b3c62f3169
commit
e5ec9e8aff
|
@ -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 {
|
||||
|
|
Ładowanie…
Reference in New Issue