diff --git a/ports/mimxrt10xx/boards/feather_m7_1011/board.c b/ports/mimxrt10xx/boards/feather_m7_1011/board.c index 3f7f3bd575..9587ea71e8 100644 --- a/ports/mimxrt10xx/boards/feather_m7_1011/board.c +++ b/ports/mimxrt10xx/boards/feather_m7_1011/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_AD_13,// SWDIO &pin_GPIO_AD_12,// SWCLK @@ -41,25 +42,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { &pin_GPIO_SD_08, &pin_GPIO_SD_07, &pin_GPIO_SD_06, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/feather_mimxrt1011/board.c b/ports/mimxrt10xx/boards/feather_mimxrt1011/board.c index cc93da4dd2..9587ea71e8 100644 --- a/ports/mimxrt10xx/boards/feather_mimxrt1011/board.c +++ b/ports/mimxrt10xx/boards/feather_mimxrt1011/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_AD_13,// SWDIO &pin_GPIO_AD_12,// SWCLK @@ -41,26 +42,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { &pin_GPIO_SD_08, &pin_GPIO_SD_07, &pin_GPIO_SD_06, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/feather_mimxrt1062/board.c b/ports/mimxrt10xx/boards/feather_mimxrt1062/board.c index 3a3b7f0efd..5a8de5a522 100644 --- a/ports/mimxrt10xx/boards/feather_mimxrt1062/board.c +++ b/ports/mimxrt10xx/boards/feather_mimxrt1062/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { // SWD Pins &pin_GPIO_AD_B0_06,// SWDIO &pin_GPIO_AD_B0_07,// SWCLK @@ -41,25 +42,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_09, &pin_GPIO_SD_B1_10, &pin_GPIO_SD_B1_11, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c index d4cd29b645..b839ffa666 100644 --- a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_AD_13, // SWDIO &pin_GPIO_AD_12, // SWCLK // FLEX flash @@ -43,25 +44,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { // USB Pins &pin_GPIO_12, &pin_GPIO_13, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/imxrt1020_evk/board.c b/ports/mimxrt10xx/boards/imxrt1020_evk/board.c index 64ca9c2b00..afbc0c58b5 100644 --- a/ports/mimxrt10xx/boards/imxrt1020_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1020_evk/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { // SWD Pins &pin_GPIO_AD_B0_00,// SWDIO &pin_GPIO_AD_B0_01,// SWCLK @@ -45,25 +46,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { // USB Pins &pin_GPIO_AD_B1_11, &pin_GPIO_AD_B1_12, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/imxrt1060_evk/board.c b/ports/mimxrt10xx/boards/imxrt1060_evk/board.c index 7406108109..f27f549c64 100644 --- a/ports/mimxrt10xx/boards/imxrt1060_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1060_evk/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { // SWD Pins &pin_GPIO_AD_B0_06, // SWDIO &pin_GPIO_AD_B0_07, // SWCLK @@ -51,26 +52,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { // USB Pins &pin_GPIO_AD_B0_01, &pin_GPIO_AD_B0_03, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/metro_m7_1011/board.c b/ports/mimxrt10xx/boards/metro_m7_1011/board.c index 8420ad4884..27cbd3eb96 100644 --- a/ports/mimxrt10xx/boards/metro_m7_1011/board.c +++ b/ports/mimxrt10xx/boards/metro_m7_1011/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { // SWD Pins &pin_GPIO_AD_13,// SWDIO &pin_GPIO_AD_12,// SWCLK @@ -42,25 +43,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { &pin_GPIO_SD_08, &pin_GPIO_SD_07, &pin_GPIO_SD_06, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/sparkfun_teensy_micromod/board.c b/ports/mimxrt10xx/boards/sparkfun_teensy_micromod/board.c index c9042c1fe3..fda0b1d202 100644 --- a/ports/mimxrt10xx/boards/sparkfun_teensy_micromod/board.c +++ b/ports/mimxrt10xx/boards/sparkfun_teensy_micromod/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_06, &pin_GPIO_SD_B1_07, &pin_GPIO_SD_B1_08, @@ -49,25 +50,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { &pin_GPIO_AD_B0_11, // Data strobe needs protection despite being grounded &pin_GPIO_SD_B1_05, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/teensy40/board.c b/ports/mimxrt10xx/boards/teensy40/board.c index 8bb1680f00..8ece1546d7 100644 --- a/ports/mimxrt10xx/boards/teensy40/board.c +++ b/ports/mimxrt10xx/boards/teensy40/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { // FLEX flash &pin_GPIO_SD_B1_06, &pin_GPIO_SD_B1_07, @@ -50,25 +51,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { &pin_GPIO_AD_B0_11, // Data strobe needs protection despite being grounded &pin_GPIO_SD_B1_05, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/teensy41/board.c b/ports/mimxrt10xx/boards/teensy41/board.c index 8bb1680f00..8ece1546d7 100644 --- a/ports/mimxrt10xx/boards/teensy41/board.c +++ b/ports/mimxrt10xx/boards/teensy41/board.c @@ -29,7 +29,8 @@ #include "shared-bindings/microcontroller/Pin.h" // These pins should never ever be reset; doing so could interfere with basic operation. -STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { // FLEX flash &pin_GPIO_SD_B1_06, &pin_GPIO_SD_B1_07, @@ -50,25 +51,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = { &pin_GPIO_AD_B0_11, // Data strobe needs protection despite being grounded &pin_GPIO_SD_B1_05, + NULL, // Must end in NULL. }; -STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { - for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) { - if (pin == _reset_forbidden_pins[i]) { - return true; - } - } - return false; -} - -bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { - if (_reset_forbidden(pin)) { - return true; - } - - // Other reset variations would go here. - - return false; -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Pin.c b/ports/mimxrt10xx/common-hal/microcontroller/Pin.c index 37a0c9c1a1..e891b56a24 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Pin.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Pin.c @@ -31,6 +31,22 @@ STATIC bool claimed_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT]; STATIC bool never_reset_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT]; +// Default is that no pins are forbidden to reset. +MP_WEAK const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { + NULL, +}; + +STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) { + const mcu_pin_obj_t **forbidden_pin = &mimxrt10xx_reset_forbidden_pins[0]; + while (*forbidden_pin) { + if (pin == *forbidden_pin) { + return true; + } + forbidden_pin++; + } + return false; +} + // There are two numbering systems used here: // IOMUXC index, used for iterating through pins and accessing reset information, // and GPIO port and number, used to store claimed and reset tagging. The two number @@ -55,10 +71,15 @@ MP_WEAK bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) { // Since i.MX pins need extra register and reset information to reset properly, // resetting pins by number alone has been removed. void common_hal_reset_pin(const mcu_pin_obj_t *pin) { + return; if (pin == NULL) { return; } + if (_reset_forbidden(pin)) { + return; + } + // Give the board a chance to reset the pin in a particular way, or not reset it at all. if (mimxrt10xx_board_reset_pin_number(pin)) { return; diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Pin.h b/ports/mimxrt10xx/common-hal/microcontroller/Pin.h index c519d468cb..1bfbe41a18 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Pin.h +++ b/ports/mimxrt10xx/common-hal/microcontroller/Pin.h @@ -35,6 +35,9 @@ void reset_all_pins(void); void claim_pin(const mcu_pin_obj_t *pin); +// List of pins that should never be reset. +extern const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[]; + // Allow the board to reset a pin in a board-specific way. This can be used // for LEDs or enable pins to put them in a state beside the default pull-up, // or to simply not reset the pin at all.