Skip to content

Commit 34e463d

Browse files
Gadgetoiddpgeorge
authored andcommitted
rp2/machine_adc: Add ADC support for RP2350B.
Signed-off-by: Damien George <[email protected]>
1 parent d0bc427 commit 34e463d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

ports/rp2/machine_adc.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
#include "hardware/adc.h"
3232
#include "machine_pin.h"
3333

34-
#define ADC_IS_VALID_GPIO(gpio) ((gpio) >= 26 && (gpio) <= 29)
35-
#define ADC_CHANNEL_FROM_GPIO(gpio) ((gpio) - 26)
36-
#define ADC_CHANNEL_TEMPSENSOR (4)
34+
#define ADC_IS_VALID_GPIO(gpio) ((gpio) >= ADC_BASE_PIN && (gpio) < (ADC_BASE_PIN + NUM_ADC_CHANNELS))
35+
#define ADC_CHANNEL_FROM_GPIO(gpio) ((gpio) - ADC_BASE_PIN)
3736

3837
static uint16_t adc_config_and_read_u16(uint32_t channel) {
3938
adc_select_input(channel);
@@ -47,7 +46,7 @@ static uint16_t adc_config_and_read_u16(uint32_t channel) {
4746
// MicroPython bindings for machine.ADC
4847

4948
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS \
50-
{ MP_ROM_QSTR(MP_QSTR_CORE_TEMP), MP_ROM_INT(ADC_CHANNEL_TEMPSENSOR) }, \
49+
{ MP_ROM_QSTR(MP_QSTR_CORE_TEMP), MP_ROM_INT(ADC_TEMPERATURE_CHANNEL_NUM) }, \
5150

5251
typedef struct _machine_adc_obj_t {
5352
mp_obj_base_t base;
@@ -75,7 +74,7 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
7574

7675
if (mp_obj_is_int(source)) {
7776
channel = mp_obj_get_int(source);
78-
if (!(channel >= 0 && channel <= ADC_CHANNEL_TEMPSENSOR)) {
77+
if (!(channel >= 0 && channel < NUM_ADC_CHANNELS)) {
7978
// Not a valid ADC channel, fallback to searching for a pin.
8079
channel = -1;
8180
}
@@ -116,7 +115,7 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
116115
adc_gpio_init(pin->id);
117116
channel = ADC_CHANNEL_FROM_GPIO(pin->id);
118117
}
119-
} else if (channel == ADC_CHANNEL_TEMPSENSOR) {
118+
} else if (channel == ADC_TEMPERATURE_CHANNEL_NUM) {
120119
// Enable temperature sensor.
121120
adc_set_temp_sensor_enabled(1);
122121
}

0 commit comments

Comments
 (0)