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 <damien@micropython.org>
This commit is contained in:
Damien George
2024-12-10 23:29:30 +11:00
parent 46a37a09fd
commit bd6edf00bb
2 changed files with 33 additions and 14 deletions

View File

@@ -52,6 +52,11 @@
#define MICROPY_PY_PYB_LEGACY (1) #define MICROPY_PY_PYB_LEGACY (1)
#endif #endif
// Whether to include legacy methods and constants in machine.Pin (which is also pyb.Pin).
#ifndef MICROPY_PY_MACHINE_PIN_LEGACY
#define MICROPY_PY_MACHINE_PIN_LEGACY (!MICROPY_PREVIEW_VERSION_2)
#endif
// Whether machine.bootloader() will enter the bootloader via reset, or direct jump. // Whether machine.bootloader() will enter the bootloader via reset, or direct jump.
#ifndef MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET #ifndef MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET
#define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (1) #define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (1)

View File

@@ -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_
} }
} }
#if MICROPY_PY_MACHINE_PIN_LEGACY
/// \classmethod mapper([fun]) /// \classmethod mapper([fun])
/// Get or set the pin mapper function. /// Get or set the pin mapper function.
static mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) { 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) {
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict); static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict);
static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, MP_ROM_PTR(&pin_map_dict_fun_obj)); static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, MP_ROM_PTR(&pin_map_dict_fun_obj));
/// \classmethod af_list()
/// Returns an array of alternate functions available for this pin.
static mp_obj_t pin_af_list(mp_obj_t self_in) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t result = mp_obj_new_list(0, NULL);
const pin_af_obj_t *af = self->af;
for (mp_uint_t i = 0; i < self->num_af; i++, af++) {
mp_obj_list_append(result, MP_OBJ_FROM_PTR(af));
}
return result;
}
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
/// \classmethod debug([state]) /// \classmethod debug([state])
/// Get or set the debugging state (`True` or `False` for on or off). /// Get or set the debugging state (`True` or `False` for on or off).
static mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) { 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) {
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug); static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, MP_ROM_PTR(&pin_debug_fun_obj)); static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, MP_ROM_PTR(&pin_debug_fun_obj));
#endif // MICROPY_PY_MACHINE_PIN_LEGACY
// init(mode, pull=None, alt=-1, *, value, alt) // init(mode, pull=None, alt=-1, *, value, alt)
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) { 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) {
static const mp_arg_t allowed_args[] = { 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
} }
static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq); static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
#if MICROPY_PY_MACHINE_PIN_LEGACY
/// \method name() /// \method name()
/// Get the pin name. /// Get the pin name.
static mp_obj_t pin_name(mp_obj_t self_in) { 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) {
} }
static MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names); static MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names);
/// \classmethod af_list()
/// Returns an array of alternate functions available for this pin.
static mp_obj_t pin_af_list(mp_obj_t self_in) {
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t result = mp_obj_new_list(0, NULL);
const pin_af_obj_t *af = self->af;
for (mp_uint_t i = 0; i < self->num_af; i++, af++) {
mp_obj_list_append(result, MP_OBJ_FROM_PTR(af));
}
return result;
}
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list);
/// \method port() /// \method port()
/// Get the pin port. /// Get the pin port.
static mp_obj_t pin_port(mp_obj_t self_in) { 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) {
} }
static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af); static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
#endif // MICROPY_PY_MACHINE_PIN_LEGACY
static const mp_rom_map_elem_t pin_locals_dict_table[] = { static const mp_rom_map_elem_t pin_locals_dict_table[] = {
// instance methods // instance methods
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) }, { 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[] = {
// Legacy names as used by pyb.Pin // Legacy names as used by pyb.Pin
{ MP_ROM_QSTR(MP_QSTR_low), MP_ROM_PTR(&pin_off_obj) }, { MP_ROM_QSTR(MP_QSTR_low), MP_ROM_PTR(&pin_off_obj) },
{ MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&pin_on_obj) }, { MP_ROM_QSTR(MP_QSTR_high), MP_ROM_PTR(&pin_on_obj) },
#if MICROPY_PY_MACHINE_PIN_LEGACY
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_name_obj) }, { MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_name_obj) },
{ MP_ROM_QSTR(MP_QSTR_names), MP_ROM_PTR(&pin_names_obj) }, { MP_ROM_QSTR(MP_QSTR_names), MP_ROM_PTR(&pin_names_obj) },
{ MP_ROM_QSTR(MP_QSTR_af_list), MP_ROM_PTR(&pin_af_list_obj) }, { 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[] = {
{ MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&pin_mode_obj) }, { MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&pin_mode_obj) },
{ MP_ROM_QSTR(MP_QSTR_pull), MP_ROM_PTR(&pin_pull_obj) }, { MP_ROM_QSTR(MP_QSTR_pull), MP_ROM_PTR(&pin_pull_obj) },
{ MP_ROM_QSTR(MP_QSTR_af), MP_ROM_PTR(&pin_af_obj) }, { MP_ROM_QSTR(MP_QSTR_af), MP_ROM_PTR(&pin_af_obj) },
#endif
#if MICROPY_PY_MACHINE_PIN_LEGACY
// class methods // class methods
{ MP_ROM_QSTR(MP_QSTR_mapper), MP_ROM_PTR(&pin_mapper_obj) }, { MP_ROM_QSTR(MP_QSTR_mapper), MP_ROM_PTR(&pin_mapper_obj) },
{ MP_ROM_QSTR(MP_QSTR_dict), MP_ROM_PTR(&pin_map_dict_obj) }, { MP_ROM_QSTR(MP_QSTR_dict), MP_ROM_PTR(&pin_map_dict_obj) },
{ MP_ROM_QSTR(MP_QSTR_debug), MP_ROM_PTR(&pin_debug_obj) }, { MP_ROM_QSTR(MP_QSTR_debug), MP_ROM_PTR(&pin_debug_obj) },
#endif
// class attributes // class attributes
{ MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&pin_board_pins_obj_type) }, { 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[] = {
{ MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_MODE_IT_RISING) }, { MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_MODE_IT_RISING) },
{ MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_MODE_IT_FALLING) }, { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_MODE_IT_FALLING) },
#if MICROPY_PY_MACHINE_PIN_LEGACY
// legacy class constants // legacy class constants
{ MP_ROM_QSTR(MP_QSTR_OUT_PP), MP_ROM_INT(GPIO_MODE_OUTPUT_PP) }, { MP_ROM_QSTR(MP_QSTR_OUT_PP), MP_ROM_INT(GPIO_MODE_OUTPUT_PP) },
{ MP_ROM_QSTR(MP_QSTR_OUT_OD), MP_ROM_INT(GPIO_MODE_OUTPUT_OD) }, { MP_ROM_QSTR(MP_QSTR_OUT_OD), MP_ROM_INT(GPIO_MODE_OUTPUT_OD) },
{ MP_ROM_QSTR(MP_QSTR_AF_PP), MP_ROM_INT(GPIO_MODE_AF_PP) }, { MP_ROM_QSTR(MP_QSTR_AF_PP), MP_ROM_INT(GPIO_MODE_AF_PP) },
{ MP_ROM_QSTR(MP_QSTR_AF_OD), MP_ROM_INT(GPIO_MODE_AF_OD) }, { MP_ROM_QSTR(MP_QSTR_AF_OD), MP_ROM_INT(GPIO_MODE_AF_OD) },
{ MP_ROM_QSTR(MP_QSTR_PULL_NONE), MP_ROM_INT(GPIO_NOPULL) }, { MP_ROM_QSTR(MP_QSTR_PULL_NONE), MP_ROM_INT(GPIO_NOPULL) },
#endif
#include "genhdr/pins_af_const.h" #include "genhdr/pins_af_const.h"
}; };