Skip to content

Commit bd6edf0

Browse files
committed
stm32/pin: Add option to exclude legacy Pin methods and constants.
This is enabled by default, but disabled when MICROPY_PREVIEW_VERSION_2 is enabled. The intention is that these methods and constants are deprecated in MicroPython 2.x. Signed-off-by: Damien George <[email protected]>
1 parent 46a37a0 commit bd6edf0

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

ports/stm32/mpconfigboard_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
#define MICROPY_PY_PYB_LEGACY (1)
5353
#endif
5454

55+
// Whether to include legacy methods and constants in machine.Pin (which is also pyb.Pin).
56+
#ifndef MICROPY_PY_MACHINE_PIN_LEGACY
57+
#define MICROPY_PY_MACHINE_PIN_LEGACY (!MICROPY_PREVIEW_VERSION_2)
58+
#endif
59+
5560
// Whether machine.bootloader() will enter the bootloader via reset, or direct jump.
5661
#ifndef MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET
5762
#define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (1)

ports/stm32/pin.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ static mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_
280280
}
281281
}
282282

283+
#if MICROPY_PY_MACHINE_PIN_LEGACY
284+
283285
/// \classmethod mapper([fun])
284286
/// Get or set the pin mapper function.
285287
static mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) {
@@ -304,20 +306,6 @@ static mp_obj_t pin_map_dict(size_t n_args, const mp_obj_t *args) {
304306
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict);
305307
static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, MP_ROM_PTR(&pin_map_dict_fun_obj));
306308

307-
/// \classmethod af_list()
308-
/// Returns an array of alternate functions available for this pin.
309-
static mp_obj_t pin_af_list(mp_obj_t self_in) {
310-
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
311-
mp_obj_t result = mp_obj_new_list(0, NULL);
312-
313-
const pin_af_obj_t *af = self->af;
314-
for (mp_uint_t i = 0; i < self->num_af; i++, af++) {
315-
mp_obj_list_append(result, MP_OBJ_FROM_PTR(af));
316-
}
317-
return result;
318-
}
319-
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
320-
321309
/// \classmethod debug([state])
322310
/// Get or set the debugging state (`True` or `False` for on or off).
323311
static mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) {
@@ -330,6 +318,8 @@ static mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) {
330318
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
331319
static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, MP_ROM_PTR(&pin_debug_fun_obj));
332320

321+
#endif // MICROPY_PY_MACHINE_PIN_LEGACY
322+
333323
// init(mode, pull=None, alt=-1, *, value, alt)
334324
static mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
335325
static const mp_arg_t allowed_args[] = {
@@ -442,6 +432,8 @@ static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
442432
}
443433
static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
444434

435+
#if MICROPY_PY_MACHINE_PIN_LEGACY
436+
445437
/// \method name()
446438
/// Get the pin name.
447439
static mp_obj_t pin_name(mp_obj_t self_in) {
@@ -469,6 +461,20 @@ static mp_obj_t pin_names(mp_obj_t self_in) {
469461
}
470462
static MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names);
471463

464+
/// \classmethod af_list()
465+
/// Returns an array of alternate functions available for this pin.
466+
static mp_obj_t pin_af_list(mp_obj_t self_in) {
467+
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
468+
mp_obj_t result = mp_obj_new_list(0, NULL);
469+
470+
const pin_af_obj_t *af = self->af;
471+
for (mp_uint_t i = 0; i < self->num_af; i++, af++) {
472+
mp_obj_list_append(result, MP_OBJ_FROM_PTR(af));
473+
}
474+
return result;
475+
}
476+
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
477+
472478
/// \method port()
473479
/// Get the pin port.
474480
static mp_obj_t pin_port(mp_obj_t self_in) {
@@ -520,6 +526,8 @@ static mp_obj_t pin_af(mp_obj_t self_in) {
520526
}
521527
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
522528

529+
#endif // MICROPY_PY_MACHINE_PIN_LEGACY
530+
523531
static const mp_rom_map_elem_t pin_locals_dict_table[] = {
524532
// instance methods
525533
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) },
@@ -531,6 +539,7 @@ static const mp_rom_map_elem_t pin_locals_dict_table[] = {
531539
// Legacy names as used by pyb.Pin
532540
{ MP_ROM_QSTR(MP_QSTR_low), MP_ROM_PTR(&pin_off_obj) },
533541
{ MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&pin_on_obj) },
542+
#if MICROPY_PY_MACHINE_PIN_LEGACY
534543
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_name_obj) },
535544
{ MP_ROM_QSTR(MP_QSTR_names), MP_ROM_PTR(&pin_names_obj) },
536545
{ MP_ROM_QSTR(MP_QSTR_af_list), MP_ROM_PTR(&pin_af_list_obj) },
@@ -540,11 +549,14 @@ static const mp_rom_map_elem_t pin_locals_dict_table[] = {
540549
{ MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&pin_mode_obj) },
541550
{ MP_ROM_QSTR(MP_QSTR_pull), MP_ROM_PTR(&pin_pull_obj) },
542551
{ MP_ROM_QSTR(MP_QSTR_af), MP_ROM_PTR(&pin_af_obj) },
552+
#endif
543553

554+
#if MICROPY_PY_MACHINE_PIN_LEGACY
544555
// class methods
545556
{ MP_ROM_QSTR(MP_QSTR_mapper), MP_ROM_PTR(&pin_mapper_obj) },
546557
{ MP_ROM_QSTR(MP_QSTR_dict), MP_ROM_PTR(&pin_map_dict_obj) },
547558
{ MP_ROM_QSTR(MP_QSTR_debug), MP_ROM_PTR(&pin_debug_obj) },
559+
#endif
548560

549561
// class attributes
550562
{ MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&pin_board_pins_obj_type) },
@@ -562,12 +574,14 @@ static const mp_rom_map_elem_t pin_locals_dict_table[] = {
562574
{ MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_MODE_IT_RISING) },
563575
{ MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_MODE_IT_FALLING) },
564576

577+
#if MICROPY_PY_MACHINE_PIN_LEGACY
565578
// legacy class constants
566579
{ MP_ROM_QSTR(MP_QSTR_OUT_PP), MP_ROM_INT(GPIO_MODE_OUTPUT_PP) },
567580
{ MP_ROM_QSTR(MP_QSTR_OUT_OD), MP_ROM_INT(GPIO_MODE_OUTPUT_OD) },
568581
{ MP_ROM_QSTR(MP_QSTR_AF_PP), MP_ROM_INT(GPIO_MODE_AF_PP) },
569582
{ MP_ROM_QSTR(MP_QSTR_AF_OD), MP_ROM_INT(GPIO_MODE_AF_OD) },
570583
{ MP_ROM_QSTR(MP_QSTR_PULL_NONE), MP_ROM_INT(GPIO_NOPULL) },
584+
#endif
571585

572586
#include "genhdr/pins_af_const.h"
573587
};

0 commit comments

Comments
 (0)