refactor to reduce duplicate code
This commit is contained in:
parent
5c569f03c2
commit
b90a6413c2
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user