Skip to content

Commit 78c2fa5

Browse files
authored
Merge pull request #7437 from dhalbert/improve-type-checking-error-msgs
Improve type validation error messages, especially for pins
2 parents 6fdaa78 + a974402 commit 78c2fa5

File tree

76 files changed

+270
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+270
-290
lines changed

locale/circuitpython.pot

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ msgstr ""
105105
msgid "%q failure: %d"
106106
msgstr ""
107107

108+
#: py/argcheck.c
109+
msgid "%q in %q must be of type %q, not %q"
110+
msgstr ""
111+
108112
#: ports/espressif/common-hal/espulp/ULP.c
109113
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
110114
#: shared-bindings/digitalio/DigitalInOut.c
@@ -172,12 +176,13 @@ msgstr ""
172176
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
173177
msgstr ""
174178

175-
#: py/argcheck.c py/obj.c py/objstrunicode.c
176-
msgid "%q must be of type %q"
179+
#: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c
180+
#: shared-bindings/canio/CAN.c shared-bindings/digitalio/Pull.c
181+
msgid "%q must be of type %q or %q, not %q"
177182
msgstr ""
178183

179-
#: py/objexcept.c shared-bindings/digitalio/Pull.c
180-
msgid "%q must be of type %q or None"
184+
#: py/argcheck.c py/obj.c py/objstrunicode.c
185+
msgid "%q must be of type %q, not %q"
181186
msgstr ""
182187

183188
#: ports/atmel-samd/common-hal/busio/UART.c
@@ -932,20 +937,8 @@ msgstr ""
932937
msgid "Error: Failure to bind"
933938
msgstr ""
934939

935-
#: ports/espressif/bindings/espulp/ULP.c py/enum.c
936-
#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
937-
#: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c
938-
#: shared-bindings/microcontroller/Pin.c
939-
#: shared-bindings/neopixel_write/__init__.c
940-
msgid "Expected a %q"
941-
msgstr ""
942-
943-
#: ports/raspberrypi/bindings/cyw43/__init__.c
944-
msgid "Expected a %q or %q"
945-
msgstr ""
946-
947940
#: shared-bindings/alarm/__init__.c
948-
msgid "Expected an %q"
941+
msgid "Expected a kind of %q"
949942
msgstr ""
950943

951944
#: ports/espressif/common-hal/_bleio/Adapter.c
@@ -1118,11 +1111,6 @@ msgstr ""
11181111
msgid "I2SOut not available"
11191112
msgstr ""
11201113

1121-
#: shared-bindings/aesio/aes.c
1122-
#, c-format
1123-
msgid "IV must be %d bytes long"
1124-
msgstr ""
1125-
11261114
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
11271115
msgid "In-buffer elements must be <= 4 bytes long"
11281116
msgstr ""
@@ -1583,10 +1571,6 @@ msgstr ""
15831571
msgid "Not playing"
15841572
msgstr ""
15851573

1586-
#: shared-bindings/_bleio/__init__.c
1587-
msgid "Not settable"
1588-
msgstr ""
1589-
15901574
#: ports/espressif/common-hal/paralleldisplay/ParallelBus.c
15911575
#, c-format
15921576
msgid "Number of data_pins must be 8 or 16, not %d"
@@ -1859,6 +1843,7 @@ msgstr ""
18591843
msgid "Random number generation error"
18601844
msgstr ""
18611845

1846+
#: shared-bindings/_bleio/__init__.c
18621847
#: shared-bindings/memorymonitor/AllocationSize.c
18631848
#: shared-bindings/pulseio/PulseIn.c shared-module/displayio/Bitmap.c
18641849
msgid "Read-only"
@@ -2045,7 +2030,10 @@ msgstr ""
20452030
msgid "The above exception was the direct cause of the following exception:"
20462031
msgstr ""
20472032

2033+
#: ports/espressif/boards/m5stack_atom_echo/mpconfigboard.h
20482034
#: ports/espressif/boards/m5stack_atom_lite/mpconfigboard.h
2035+
#: ports/espressif/boards/m5stack_atom_matrix/mpconfigboard.h
2036+
#: ports/espressif/boards/m5stack_atom_u/mpconfigboard.h
20492037
msgid "The central button was pressed at start up.\n"
20502038
msgstr ""
20512039

@@ -2969,14 +2957,6 @@ msgstr ""
29692957
msgid "exceptions must derive from BaseException"
29702958
msgstr ""
29712959

2972-
#: shared-bindings/canio/CAN.c
2973-
msgid "expected '%q' but got '%q'"
2974-
msgstr ""
2975-
2976-
#: shared-bindings/canio/CAN.c
2977-
msgid "expected '%q' or '%q' but got '%q'"
2978-
msgstr ""
2979-
29802960
#: py/objstr.c
29812961
msgid "expected ':' after format specifier"
29822962
msgstr ""

ports/espressif/bindings/esp32_camera/Camera.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,21 @@ STATIC mp_obj_t esp32_camera_camera_make_new(const mp_obj_type_t *type, size_t n
121121
validate_pins(MP_QSTR_data_pins, data_pins, MP_ARRAY_SIZE(data_pins), args[ARG_data_pins].u_obj, &data_pin_count);
122122
mp_arg_validate_length(data_pin_count, 8, MP_QSTR_data_pins);
123123

124-
const mcu_pin_obj_t *pixel_clock_pin = validate_obj_is_free_pin(args[ARG_pixel_clock_pin].u_obj);
125-
const mcu_pin_obj_t *vsync_pin = validate_obj_is_free_pin(args[ARG_vsync_pin].u_obj);
126-
const mcu_pin_obj_t *href_pin = validate_obj_is_free_pin(args[ARG_href_pin].u_obj);
124+
const mcu_pin_obj_t *pixel_clock_pin =
125+
validate_obj_is_free_pin(args[ARG_pixel_clock_pin].u_obj, MP_QSTR_pixel_clock_pin);
126+
const mcu_pin_obj_t *vsync_pin =
127+
validate_obj_is_free_pin(args[ARG_vsync_pin].u_obj, MP_QSTR_vsync_pin);
128+
const mcu_pin_obj_t *href_pin =
129+
validate_obj_is_free_pin(args[ARG_href_pin].u_obj, MP_QSTR_href_pin);
127130
busio_i2c_obj_t *i2c = MP_OBJ_TO_PTR(mp_arg_validate_type(args[ARG_i2c].u_obj, &busio_i2c_type, MP_QSTR_i2c));
128-
const mcu_pin_obj_t *external_clock_pin = validate_obj_is_free_pin_or_none(args[ARG_external_clock_pin].u_obj);
129-
const mcu_pin_obj_t *powerdown_pin = validate_obj_is_free_pin_or_none(args[ARG_powerdown_pin].u_obj);
130-
const mcu_pin_obj_t *reset_pin = validate_obj_is_free_pin_or_none(args[ARG_reset_pin].u_obj);
131-
const mp_int_t external_clock_frequency = mp_arg_validate_int_range(args[ARG_external_clock_frequency].u_int, 0, 40000000, MP_QSTR_clock_frequency);
131+
const mcu_pin_obj_t *external_clock_pin =
132+
validate_obj_is_free_pin_or_none(args[ARG_external_clock_pin].u_obj, MP_QSTR_external_clock_pin);
133+
const mcu_pin_obj_t *powerdown_pin =
134+
validate_obj_is_free_pin_or_none(args[ARG_powerdown_pin].u_obj, MP_QSTR_powerdown_pin);
135+
const mcu_pin_obj_t *reset_pin =
136+
validate_obj_is_free_pin_or_none(args[ARG_reset_pin].u_obj, MP_QSTR_reset_pin);
137+
const mp_int_t external_clock_frequency =
138+
mp_arg_validate_int_range(args[ARG_external_clock_frequency].u_int, 0, 40000000, MP_QSTR_external_clock_frequency);
132139

133140
camera_grab_mode_t grab_mode = validate_grab_mode(args[ARG_grab_mode].u_obj, MP_QSTR_grab_mode);
134141
framesize_t frame_size = validate_frame_size(args[ARG_frame_size].u_obj, MP_QSTR_frame_size);

ports/espressif/bindings/esp32_camera/__init__.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MAKE_PRINTER(esp32_camera, esp32_camera_grab_mode);
6969
MAKE_ENUM_TYPE(esp32_camera, GrabMode, esp32_camera_grab_mode);
7070

7171
camera_grab_mode_t validate_grab_mode(mp_obj_t obj, qstr arg_name) {
72-
return cp_enum_value(&esp32_camera_grab_mode_type, mp_arg_validate_type(obj, &esp32_camera_grab_mode_type, arg_name));
72+
return cp_enum_value(&esp32_camera_grab_mode_type, obj, arg_name);
7373
}
7474

7575
//| class PixelFormat:
@@ -100,7 +100,7 @@ MAKE_PRINTER(esp32_camera, esp32_camera_pixel_format);
100100
MAKE_ENUM_TYPE(esp32_camera, PixelFormat, esp32_camera_pixel_format);
101101

102102
pixformat_t validate_pixel_format(mp_obj_t obj, qstr arg_name) {
103-
return cp_enum_value(&esp32_camera_pixel_format_type, mp_arg_validate_type(obj, &esp32_camera_pixel_format_type, arg_name));
103+
return cp_enum_value(&esp32_camera_pixel_format_type, obj, arg_name);
104104
}
105105

106106
//| class FrameSize:
@@ -225,7 +225,7 @@ MAKE_PRINTER(esp32_camera, esp32_camera_frame_size);
225225
MAKE_ENUM_TYPE(esp32_camera, FrameSize, esp32_camera_frame_size);
226226

227227
framesize_t validate_frame_size(mp_obj_t obj, qstr arg_name) {
228-
return cp_enum_value(&esp32_camera_frame_size_type, mp_arg_validate_type(obj, &esp32_camera_frame_size_type, arg_name));
228+
return cp_enum_value(&esp32_camera_frame_size_type, obj, arg_name);
229229
}
230230

231231
//| class GainCeiling:
@@ -265,7 +265,7 @@ MAKE_PRINTER(esp32_camera, esp32_camera_gain_ceiling);
265265
MAKE_ENUM_TYPE(esp32_camera, GainCeiling, esp32_camera_gain_ceiling);
266266

267267
gainceiling_t validate_gain_ceiling(mp_obj_t obj, qstr arg_name) {
268-
return cp_enum_value(&esp32_camera_gain_ceiling_type, mp_arg_validate_type(obj, &esp32_camera_gain_ceiling_type, arg_name));
268+
return cp_enum_value(&esp32_camera_gain_ceiling_type, obj, arg_name);
269269
}
270270

271271
STATIC const mp_rom_map_elem_t esp32_camera_module_globals_table[] = {

ports/espressif/bindings/espulp/ULP.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,17 @@ STATIC mp_obj_t espulp_ulp_make_new(const mp_obj_type_t *type, size_t n_args, si
4444
return MP_OBJ_FROM_PTR(self);
4545
}
4646

47-
STATIC espulp_ulp_obj_t *get_ulp_obj(mp_obj_t self_in) {
48-
if (!mp_obj_is_type(self_in, &espulp_ulp_type)) {
49-
mp_raise_TypeError_varg(translate("Expected a %q"), MP_QSTR_ULP);
50-
}
51-
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
47+
STATIC void check_for_deinit(espulp_ulp_obj_t *self) {
5248
if (common_hal_espulp_ulp_deinited(self)) {
5349
raise_deinited_error();
5450
}
55-
return self;
5651
}
5752

5853
//| def deinit(self) -> None:
5954
//| """Deinitialises the ULP and releases it for another program."""
6055
//| ...
6156
STATIC mp_obj_t espulp_ulp_deinit(mp_obj_t self_in) {
62-
espulp_ulp_obj_t *self = get_ulp_obj(self_in);
57+
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
6358
common_hal_espulp_ulp_deinit(self);
6459
return mp_const_none;
6560
}
@@ -89,14 +84,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espulp_ulp___exit___obj, 4, 4, espulp
8984
//| The program will continue to run even when the running Python is halted."""
9085
//| ...
9186
STATIC mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
87+
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
88+
check_for_deinit(self);
89+
9290
enum { ARG_program, ARG_pins };
9391
static const mp_arg_t allowed_args[] = {
9492
{ MP_QSTR_program, MP_ARG_REQUIRED | MP_ARG_OBJ},
9593
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_tuple} },
9694
};
9795

9896
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
99-
espulp_ulp_obj_t *self = get_ulp_obj(pos_args[0]);
10097
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
10198

10299
mp_buffer_info_t bufinfo;
@@ -111,7 +108,7 @@ STATIC mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t
111108

112109
for (mp_uint_t i = 0; i < num_pins; i++) {
113110
mp_obj_t pin_obj = mp_obj_subscr(pins_in, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL);
114-
validate_obj_is_free_pin(pin_obj);
111+
validate_obj_is_free_pin(pin_obj, MP_QSTR_pin);
115112
const mcu_pin_obj_t *pin = ((const mcu_pin_obj_t *)pin_obj);
116113
if (pin->number >= 32) {
117114
raise_ValueError_invalid_pin();
@@ -129,7 +126,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espulp_ulp_run_obj, 2, espulp_ulp_run);
129126
//| ...
130127
//|
131128
STATIC mp_obj_t espulp_ulp_halt(mp_obj_t self_in) {
132-
common_hal_espulp_ulp_halt(get_ulp_obj(self_in));
129+
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
130+
check_for_deinit(self);
131+
132+
common_hal_espulp_ulp_halt(self);
133133
return mp_const_none;
134134
}
135135
STATIC MP_DEFINE_CONST_FUN_OBJ_1(espulp_ulp_halt_obj, espulp_ulp_halt);

ports/espressif/bindings/espulp/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
//|
6262

6363
STATIC mp_obj_t espulp_get_rtc_gpio_number(mp_obj_t pin_obj) {
64-
const mcu_pin_obj_t *pin = validate_obj_is_pin(pin_obj);
64+
const mcu_pin_obj_t *pin = validate_obj_is_pin(pin_obj, MP_QSTR_pin);
6565
mp_int_t number = common_hal_espulp_get_rtc_gpio_number(pin);
6666
if (number < 0) {
6767
return mp_const_none;

ports/espressif/common-hal/paralleldisplay/ParallelBus.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ void common_hal_paralleldisplay_parallelbus_construct(paralleldisplay_parallelbu
118118
const mcu_pin_obj_t *data_pins[8];
119119
for (int i = 0; i < 8; i++) {
120120
snprintf(buf, sizeof(buf), "GPIO%d", data0->number + i);
121-
data_pins[i] = validate_obj_is_free_pin(mp_obj_dict_get(MP_OBJ_FROM_PTR(&mcu_pin_globals), mp_obj_new_str(buf, strlen(buf))));
121+
data_pins[i] = validate_obj_is_free_pin(
122+
mp_obj_dict_get(MP_OBJ_FROM_PTR(&mcu_pin_globals), mp_obj_new_str(buf, strlen(buf))), MP_QSTR_pin);
122123
}
123124
common_hal_paralleldisplay_parallelbus_construct_nonsequential(self, 8, data_pins, command, chip_select, write, read, reset, frequency);
124125
}

ports/raspberrypi/bindings/cyw43/__init__.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,23 @@ STATIC mp_obj_t cyw43_get_power_management() {
116116
}
117117
STATIC MP_DEFINE_CONST_FUN_OBJ_0(cyw43_get_power_management_obj, cyw43_get_power_management);
118118

119-
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj) {
119+
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj, qstr arg_name) {
120120
if (!mp_obj_is_type(obj, &mcu_pin_type) && !mp_obj_is_type(obj, &cyw43_pin_type)) {
121-
mp_raise_TypeError_varg(translate("Expected a %q or %q"), mcu_pin_type.name, cyw43_pin_type.name);
121+
mp_raise_TypeError_varg(translate("%q must be of type %q or %q, not %q"), arg_name, mcu_pin_type.name, cyw43_pin_type.name, mp_obj_get_type(obj)->name);
122122
}
123123
return MP_OBJ_TO_PTR(obj);
124124
}
125125

126-
const mcu_pin_obj_t *validate_obj_is_free_pin_or_gpio29(mp_obj_t obj) {
127-
const mcu_pin_obj_t *pin = validate_obj_is_pin(obj);
126+
const mcu_pin_obj_t *validate_obj_is_free_pin_or_gpio29(mp_obj_t obj, qstr arg_name) {
127+
const mcu_pin_obj_t *pin = validate_obj_is_pin(obj, arg_name);
128128
if (obj != &pin_GPIO29) {
129129
assert_pin_free(pin);
130130
}
131131
return pin;
132132
}
133133

134-
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj) {
135-
const mcu_pin_obj_t *pin = validate_obj_is_pin_including_cyw43(obj);
134+
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj, qstr arg_name) {
135+
const mcu_pin_obj_t *pin = validate_obj_is_pin_including_cyw43(obj, arg_name);
136136
assert_pin_free(pin);
137137
return pin;
138138
}

ports/raspberrypi/bindings/cyw43/__init__.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
#include "common-hal/microcontroller/Pin.h"
3232

3333
extern const mp_obj_type_t cyw43_pin_type;
34-
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj);
35-
const mcu_pin_obj_t *validate_obj_is_free_pin_or_gpio29(mp_obj_t obj);
36-
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj);
34+
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj, qstr arg_name);
35+
const mcu_pin_obj_t *validate_obj_is_free_pin_or_gpio29(mp_obj_t obj, qstr arg_name);
36+
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj, qstr arg_name);
3737

3838
#define CONSTANT_CYW43_PM_VALUE(pm_mode, pm2_sleep_ret_ms, li_beacon_period, li_dtim_period, li_assoc) \
3939
(li_assoc << 20 | /* listen interval sent to ap */ \

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,25 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
222222
mp_get_buffer(args[ARG_init].u_obj, &init_bufinfo, MP_BUFFER_READ);
223223

224224
// We don't validate pin in use here because we may be ok sharing them within a PIO.
225-
const mcu_pin_obj_t *first_out_pin = validate_obj_is_pin_or_none(args[ARG_first_out_pin].u_obj);
225+
const mcu_pin_obj_t *first_out_pin =
226+
validate_obj_is_pin_or_none(args[ARG_first_out_pin].u_obj, MP_QSTR_first_out_pin);
226227
mp_int_t out_pin_count = mp_arg_validate_int_min(args[ARG_out_pin_count].u_int, 1, MP_QSTR_out_pin_count);
227228

228-
const mcu_pin_obj_t *first_in_pin = validate_obj_is_pin_or_none(args[ARG_first_in_pin].u_obj);
229+
const mcu_pin_obj_t *first_in_pin =
230+
validate_obj_is_pin_or_none(args[ARG_first_in_pin].u_obj, MP_QSTR_first_in_pin);
229231
mp_int_t in_pin_count = mp_arg_validate_int_min(args[ARG_in_pin_count].u_int, 1, MP_QSTR_in_pin_count);
230232

231-
const mcu_pin_obj_t *first_set_pin = validate_obj_is_pin_or_none(args[ARG_first_set_pin].u_obj);
233+
const mcu_pin_obj_t *first_set_pin =
234+
validate_obj_is_pin_or_none(args[ARG_first_set_pin].u_obj, MP_QSTR_first_set_pin);
232235
mp_int_t set_pin_count = mp_arg_validate_int_range(args[ARG_set_pin_count].u_int, 1, 5, MP_QSTR_set_pin_count);
233236

234-
const mcu_pin_obj_t *first_sideset_pin = validate_obj_is_pin_or_none(args[ARG_first_sideset_pin].u_obj);
235-
mp_int_t sideset_pin_count = mp_arg_validate_int_range(args[ARG_sideset_pin_count].u_int, 1, 5, MP_QSTR_set_pin_count);
237+
const mcu_pin_obj_t *first_sideset_pin =
238+
validate_obj_is_pin_or_none(args[ARG_first_sideset_pin].u_obj, MP_QSTR_first_sideset_pin);
239+
mp_int_t sideset_pin_count =
240+
mp_arg_validate_int_range(args[ARG_sideset_pin_count].u_int, 1, 5, MP_QSTR_set_pin_count);
236241

237-
const mcu_pin_obj_t *jmp_pin = validate_obj_is_pin_or_none(args[ARG_jmp_pin].u_obj);
242+
const mcu_pin_obj_t *jmp_pin =
243+
validate_obj_is_pin_or_none(args[ARG_jmp_pin].u_obj, MP_QSTR_jmp_pin);
238244
digitalio_pull_t jmp_pin_pull = validate_pull(args[ARG_jmp_pin_pull].u_rom_obj, MP_QSTR_jmp_pull);
239245

240246
mp_int_t pull_threshold =

ports/raspberrypi/bindings/rp2pio/__init__.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@
4343
//| """Return True if the pins have sequential GPIO numbers, False otherwise"""
4444
//| ...
4545
//|
46-
STATIC mp_obj_t rp2pio_pins_are_sequential(const mp_obj_t pins) {
46+
STATIC mp_obj_t rp2pio_pins_are_sequential(mp_obj_t pins_obj) {
4747
size_t len;
4848
mp_obj_t *items;
49-
mp_obj_get_array(pins, &len, &items);
50-
return mp_obj_new_bool(common_hal_rp2pio_pins_are_sequential(len, items));
49+
mp_obj_get_array(pins_obj, &len, &items);
50+
51+
const mcu_pin_obj_t *pins[len];
52+
for (size_t i = 0; i < len; i++) {
53+
pins[i] = validate_obj_is_pin(items[i], MP_QSTR_pins);
54+
}
55+
56+
return mp_obj_new_bool(common_hal_rp2pio_pins_are_sequential(len, pins));
5157
}
5258

5359
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_pins_are_sequential_obj, rp2pio_pins_are_sequential);

ports/raspberrypi/bindings/rp2pio/__init__.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626

2727
#pragma once
2828

29-
bool common_hal_rp2pio_pins_are_sequential(size_t len, mp_obj_t *items);
29+
#include "shared-bindings/microcontroller/Pin.h"
30+
31+
bool common_hal_rp2pio_pins_are_sequential(size_t len, const mcu_pin_obj_t **pins);

ports/raspberrypi/common-hal/analogio/AnalogIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define SPECIAL_PIN(pin) (pin->number == 29)
4545

4646
const mcu_pin_obj_t *common_hal_analogio_analogin_validate_pin(mp_obj_t obj) {
47-
return validate_obj_is_free_pin_or_gpio29(obj);
47+
return validate_obj_is_free_pin_or_gpio29(obj, MP_QSTR_pin);
4848
}
4949
#else
5050
#define SPECIAL_PIN(pin) false

ports/raspberrypi/common-hal/digitalio/DigitalInOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#define IS_CYW(self) ((self)->pin->base.type == &cyw43_pin_type)
4444

4545
const mcu_pin_obj_t *common_hal_digitalio_validate_pin(mp_obj_t obj) {
46-
return validate_obj_is_free_pin_including_cyw43(obj);
46+
return validate_obj_is_free_pin_including_cyw43(obj, MP_QSTR_pin);
4747
}
4848
#endif
4949

ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ STATIC void incrementalencoder_interrupt_handler(void *self_in);
6161

6262
void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t *self,
6363
const mcu_pin_obj_t *pin_a, const mcu_pin_obj_t *pin_b) {
64-
mp_obj_t pins[] = {MP_OBJ_FROM_PTR(pin_a), MP_OBJ_FROM_PTR(pin_b)};
64+
const mcu_pin_obj_t *pins[] = { pin_a, pin_b };
65+
6566
// Start out with swapped to match behavior with other ports.
6667
self->swapped = true;
6768
if (!common_hal_rp2pio_pins_are_sequential(2, pins)) {
68-
pins[0] = MP_OBJ_FROM_PTR(pin_b);
69-
pins[1] = MP_OBJ_FROM_PTR(pin_a);
69+
pins[0] = pin_b;
70+
pins[1] = pin_a;
7071
self->swapped = false;
7172
if (!common_hal_rp2pio_pins_are_sequential(2, pins)) {
7273
mp_raise_RuntimeError(translate("Pins must be sequential GPIO pins"));

0 commit comments

Comments
 (0)