Skip to content

Commit b90a641

Browse files
committed
refactor to reduce duplicate code
1 parent 5c569f0 commit b90a641

File tree

12 files changed

+54
-202
lines changed

12 files changed

+54
-202
lines changed

ports/mimxrt10xx/boards/feather_m7_1011/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
&pin_GPIO_AD_13,// SWDIO
3435
&pin_GPIO_AD_12,// SWCLK
3536

@@ -41,25 +42,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
4142
&pin_GPIO_SD_08,
4243
&pin_GPIO_SD_07,
4344
&pin_GPIO_SD_06,
45+
NULL, // Must end in NULL.
4446
};
4547

46-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
47-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
48-
if (pin == _reset_forbidden_pins[i]) {
49-
return true;
50-
}
51-
}
52-
return false;
53-
}
54-
55-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
56-
if (_reset_forbidden(pin)) {
57-
return true;
58-
}
59-
60-
// Other reset variations would go here.
61-
62-
return false;
63-
}
64-
6548
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/feather_mimxrt1011/board.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
&pin_GPIO_AD_13,// SWDIO
3435
&pin_GPIO_AD_12,// SWCLK
3536

@@ -41,26 +42,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
4142
&pin_GPIO_SD_08,
4243
&pin_GPIO_SD_07,
4344
&pin_GPIO_SD_06,
45+
NULL, // Must end in NULL.
4446
};
4547

46-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
47-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
48-
if (pin == _reset_forbidden_pins[i]) {
49-
return true;
50-
}
51-
}
52-
return false;
53-
}
54-
55-
56-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
57-
if (_reset_forbidden(pin)) {
58-
return true;
59-
}
60-
61-
// Other reset variations would go here.
62-
63-
return false;
64-
}
65-
6648
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/feather_mimxrt1062/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
// SWD Pins
3435
&pin_GPIO_AD_B0_06,// SWDIO
3536
&pin_GPIO_AD_B0_07,// SWCLK
@@ -41,25 +42,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
4142
&pin_GPIO_SD_B1_09,
4243
&pin_GPIO_SD_B1_10,
4344
&pin_GPIO_SD_B1_11,
45+
NULL, // Must end in NULL.
4446
};
4547

46-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
47-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
48-
if (pin == _reset_forbidden_pins[i]) {
49-
return true;
50-
}
51-
}
52-
return false;
53-
}
54-
55-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
56-
if (_reset_forbidden(pin)) {
57-
return true;
58-
}
59-
60-
// Other reset variations would go here.
61-
62-
return false;
63-
}
64-
6548
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/imxrt1010_evk/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
&pin_GPIO_AD_13, // SWDIO
3435
&pin_GPIO_AD_12, // SWCLK
3536
// FLEX flash
@@ -43,25 +44,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
4344
// USB Pins
4445
&pin_GPIO_12,
4546
&pin_GPIO_13,
47+
NULL, // Must end in NULL.
4648
};
4749

48-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
49-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
50-
if (pin == _reset_forbidden_pins[i]) {
51-
return true;
52-
}
53-
}
54-
return false;
55-
}
56-
57-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
58-
if (_reset_forbidden(pin)) {
59-
return true;
60-
}
61-
62-
// Other reset variations would go here.
63-
64-
return false;
65-
}
66-
6750
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/imxrt1020_evk/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
// SWD Pins
3435
&pin_GPIO_AD_B0_00,// SWDIO
3536
&pin_GPIO_AD_B0_01,// SWCLK
@@ -45,25 +46,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
4546
// USB Pins
4647
&pin_GPIO_AD_B1_11,
4748
&pin_GPIO_AD_B1_12,
49+
NULL, // Must end in NULL.
4850
};
4951

50-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
51-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
52-
if (pin == _reset_forbidden_pins[i]) {
53-
return true;
54-
}
55-
}
56-
return false;
57-
}
58-
59-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
60-
if (_reset_forbidden(pin)) {
61-
return true;
62-
}
63-
64-
// Other reset variations would go here.
65-
66-
return false;
67-
}
68-
6952
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/imxrt1060_evk/board.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
// SWD Pins
3435
&pin_GPIO_AD_B0_06, // SWDIO
3536
&pin_GPIO_AD_B0_07, // SWCLK
@@ -51,26 +52,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
5152
// USB Pins
5253
&pin_GPIO_AD_B0_01,
5354
&pin_GPIO_AD_B0_03,
55+
NULL, // Must end in NULL.
5456
};
5557

56-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
57-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
58-
if (pin == _reset_forbidden_pins[i]) {
59-
return true;
60-
}
61-
}
62-
return false;
63-
}
64-
65-
66-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
67-
if (_reset_forbidden(pin)) {
68-
return true;
69-
}
70-
71-
// Other reset variations would go here.
72-
73-
return false;
74-
}
75-
7658
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/metro_m7_1011/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
// SWD Pins
3435
&pin_GPIO_AD_13,// SWDIO
3536
&pin_GPIO_AD_12,// SWCLK
@@ -42,25 +43,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
4243
&pin_GPIO_SD_08,
4344
&pin_GPIO_SD_07,
4445
&pin_GPIO_SD_06,
46+
NULL, // Must end in NULL.
4547
};
4648

47-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
48-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
49-
if (pin == _reset_forbidden_pins[i]) {
50-
return true;
51-
}
52-
}
53-
return false;
54-
}
55-
56-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
57-
if (_reset_forbidden(pin)) {
58-
return true;
59-
}
60-
61-
// Other reset variations would go here.
62-
63-
return false;
64-
}
65-
6649
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/sparkfun_teensy_micromod/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
&pin_GPIO_SD_B1_06,
3435
&pin_GPIO_SD_B1_07,
3536
&pin_GPIO_SD_B1_08,
@@ -49,25 +50,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
4950
&pin_GPIO_AD_B0_11,
5051
// Data strobe needs protection despite being grounded
5152
&pin_GPIO_SD_B1_05,
53+
NULL, // Must end in NULL.
5254
};
5355

54-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
55-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
56-
if (pin == _reset_forbidden_pins[i]) {
57-
return true;
58-
}
59-
}
60-
return false;
61-
}
62-
63-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
64-
if (_reset_forbidden(pin)) {
65-
return true;
66-
}
67-
68-
// Other reset variations would go here.
69-
70-
return false;
71-
}
72-
7356
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/teensy40/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
// FLEX flash
3435
&pin_GPIO_SD_B1_06,
3536
&pin_GPIO_SD_B1_07,
@@ -50,25 +51,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
5051
&pin_GPIO_AD_B0_11,
5152
// Data strobe needs protection despite being grounded
5253
&pin_GPIO_SD_B1_05,
54+
NULL, // Must end in NULL.
5355
};
5456

55-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
56-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
57-
if (pin == _reset_forbidden_pins[i]) {
58-
return true;
59-
}
60-
}
61-
return false;
62-
}
63-
64-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
65-
if (_reset_forbidden(pin)) {
66-
return true;
67-
}
68-
69-
// Other reset variations would go here.
70-
71-
return false;
72-
}
73-
7457
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/mimxrt10xx/boards/teensy41/board.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "shared-bindings/microcontroller/Pin.h"
3030

3131
// These pins should never ever be reset; doing so could interfere with basic operation.
32-
STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
32+
// Used in common-hal/microcontroller/Pin.c
33+
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
3334
// FLEX flash
3435
&pin_GPIO_SD_B1_06,
3536
&pin_GPIO_SD_B1_07,
@@ -50,25 +51,7 @@ STATIC const mcu_pin_obj_t *_reset_forbidden_pins[] = {
5051
&pin_GPIO_AD_B0_11,
5152
// Data strobe needs protection despite being grounded
5253
&pin_GPIO_SD_B1_05,
54+
NULL, // Must end in NULL.
5355
};
5456

55-
STATIC bool _reset_forbidden(const mcu_pin_obj_t *pin) {
56-
for (size_t i = 0; i < MP_ARRAY_SIZE(_reset_forbidden_pins); i++) {
57-
if (pin == _reset_forbidden_pins[i]) {
58-
return true;
59-
}
60-
}
61-
return false;
62-
}
63-
64-
bool mimxrt10xx_board_reset_pin_number(const mcu_pin_obj_t *pin) {
65-
if (_reset_forbidden(pin)) {
66-
return true;
67-
}
68-
69-
// Other reset variations would go here.
70-
71-
return false;
72-
}
73-
7457
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

0 commit comments

Comments
 (0)