rp2/machine_adc: Initialise ADC GPIO when a Pin is referenced by int.
The change closes the gap in the API when an integer is used as Pin
reference. With the change, e.g. ADC(26), ADC(Pin(26)) and ADC("GP26")
behave identically and the GPIO is initialised in ACD/high-Z mode.
Only when using ADC channel numbers 0-3 are the corresponding GPIO left
uninitialised, and then the user is responsible for configuring the GPIO.
Signed-off-by: robert-hh <robert@hammelrath.com>
This commit is contained in:
parent
f61fac0ba6
commit
2b8de7436b
@ -74,14 +74,14 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
|
|||||||
const machine_pin_obj_t *pin = NULL;
|
const machine_pin_obj_t *pin = NULL;
|
||||||
|
|
||||||
if (mp_obj_is_int(source)) {
|
if (mp_obj_is_int(source)) {
|
||||||
// Get and validate channel number.
|
|
||||||
channel = mp_obj_get_int(source);
|
channel = mp_obj_get_int(source);
|
||||||
if (ADC_IS_VALID_GPIO(channel)) {
|
if (!(channel >= 0 && channel <= ADC_CHANNEL_TEMPSENSOR)) {
|
||||||
channel = ADC_CHANNEL_FROM_GPIO(channel);
|
// Not a valid ADC channel, fallback to searching for a pin.
|
||||||
} else if (!(channel >= 0 && channel <= ADC_CHANNEL_TEMPSENSOR)) {
|
channel = -1;
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid channel"));
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (channel == -1) {
|
||||||
// Get GPIO and check it has ADC capabilities.
|
// Get GPIO and check it has ADC capabilities.
|
||||||
pin = machine_pin_find(source);
|
pin = machine_pin_find(source);
|
||||||
bool valid_adc_pin = false;
|
bool valid_adc_pin = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user