8000 atmel-samd: Introduce board reset mechanic used on CircuitPlayground · sparkfun/circuitpython@a715bf6 · GitHub
[go: up one dir, main page]

Skip to content

Commit a715bf6

Browse files
committed
atmel-samd: Introduce board reset mechanic used on CircuitPlayground
Express to ensure the Neopixels are off after reloads.
1 parent 3e23464 commit a715bf6

File tree

10 files changed

+44
-2
lines changed

10 files changed

+44
-2
lines changed

atmel-samd/boards/arduino_zero/board.c

Lines changed: 3 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ void board_init(void)
4444
bool board_requests_safe_mode(void) {
4545
return false;
4646
}
47+
48+
void reset_board(void) {
49+
}

atmel-samd/boards/board.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ void board_init(void);
3939
// way.
4040
bool board_requests_safe_mode(void);
4141

42+
// Reset the state of off MCU components such as neopixels.
43+
void reset_board(void);
44+
4245
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H__

atmel-samd/boards/circuitplayground_express/board.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <string.h>
28+
2729
#include "boards/board.h"
2830
#include "asf/sam0/drivers/port/port.h"
2931
#include "common-hal/microcontroller/Pin.h"
32+
#include "shared-bindings/digitalio/DigitalInOut.h"
33+
#include "shared-bindings/neopixel_write/__init__.h"
34+
#include "samd21_pins.h"
3035

3136
void board_init(void)
3237
{
@@ -47,3 +52,14 @@ bool board_requests_safe_mode(void) {
4752
reset_pin(PIN_PA28);
4853
return safe_mode;
4954
}
55+
56+
void reset_board(void) {
57+
uint8_t empty[30];
58+
memset(empty, 0, 30);
59+
digitalio_digitalinout_obj_t neopixel_pin;
60+
common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23);
61+
common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false,
62+
DRIVE_MODE_PUSH_PULL);
63+
common_hal_neopixel_write(&neopixel_pin, empty, 30);
64+
common_hal_digitalio_digitalinout_deinit(&neopixel_pin);
65+
}

atmel-samd/boards/feather_m0_adalogger/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ void board_init(void)
3333
bool board_requests_safe_mode(void) {
3434
return false;
3535
}
36+
37+
void reset_board(void) {
38+
}

atmel-samd/boards/feather_m0_basic/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ void board_init(void)
3333
bool board_requests_safe_mode(void) {
3434
return false;
3535
}
36+
37+
void reset_board(void) {
38+
}

atmel-samd/boards/feather_m0_express/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ void board_init(void)
3333
bool board_requests_safe_mode(void) {
3434
return false;
3535
}
36+
37+
void reset_board(void) {
38+
}

atmel-samd/boards/gemma_m0/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ void board_init(void)
3333
bool board_requests_safe_mode(void) {
3434
return false;
3535
}
36+
37+
void reset_board(void) {
38+
}

atmel-samd/boards/metro_m0_express/board.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ void board_init(void)
4444
bool board_requests_safe_mode(void) {
4545
return false;
4646
}
47+
48+
void reset_board(void) {
49+
}

atmel-samd/boards/trinket_m0/board.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
#include "boards/board.h"
2828

29-
void board_init(void)
30-
{
29+
void board_init(void) {
3130
}
3231

3332
bool board_requests_safe_mode(void) {
3433
return false;
3534
}
35+
36+
void reset_board(void) {
37+
}

atmel-samd/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ int main(void) {
594594

595595
// Reset everything and prep MicroPython to run boot.py.
596596
reset_samd21();
597+
reset_board();
597598
reset_mp();
598599

599600
// Turn on autoreload by default but before boot.py in case it wants to change it.
@@ -656,6 +657,7 @@ int main(void) {
656657
autoreload_enable();
657658
}
658659
reset_samd21();
660+
reset_board();
659661
reset_mp();
660662
}
661663
if (exit_code == PYEXEC_FORCED_EXIT) {
@@ -665,6 +667,7 @@ int main(void) {
665667
first_run = false;
666668
skip_repl = start_mp(safe_mode);
667669
reset_samd21();
670+
reset_board();
668671
reset_mp();
669672
} else if (exit_code != 0) {
670673
break;

0 commit comments

Comments
 (0)
0