summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-06-16 14:55:53 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-06-16 14:55:53 -0700
commit3e23464b1ed11710714a4d6eaa98c2c84ec6f4dd (patch)
tree2ab279fa2858ec5a7bb0435dcb5303137e523a60
parentc7efd2cae963b4db7e8b589cf20207ef7639b303 (diff)
atmel-samd: Add user initiated safe mode and rework board.c for
board specific functionality. Fixes #155
-rw-r--r--atmel-samd/Makefile2
-rw-r--r--atmel-samd/boards/arduino_zero/board.c46
-rw-r--r--atmel-samd/boards/arduino_zero/init.c32
-rw-r--r--atmel-samd/boards/board.h42
-rw-r--r--atmel-samd/boards/circuitplayground_express/board.c49
-rw-r--r--atmel-samd/boards/circuitplayground_express/init.c18
-rw-r--r--atmel-samd/boards/circuitplayground_express/mpconfigboard.h3
-rw-r--r--atmel-samd/boards/feather_m0_adalogger/board.c35
-rw-r--r--atmel-samd/boards/feather_m0_adalogger/init.c20
-rw-r--r--atmel-samd/boards/feather_m0_basic/board.c35
-rw-r--r--atmel-samd/boards/feather_m0_basic/init.c20
-rw-r--r--atmel-samd/boards/feather_m0_express/board.c35
-rw-r--r--atmel-samd/boards/feather_m0_express/init.c20
-rw-r--r--atmel-samd/boards/gemma_m0/board.c35
-rw-r--r--atmel-samd/boards/gemma_m0/init.c18
-rw-r--r--atmel-samd/boards/metro_m0_express/board.c46
-rw-r--r--atmel-samd/boards/metro_m0_express/init.c31
-rw-r--r--atmel-samd/boards/trinket_m0/board.c35
-rw-r--r--atmel-samd/boards/trinket_m0/init.c18
-rw-r--r--atmel-samd/main.c17
20 files changed, 379 insertions, 178 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile
index e7de4aede..fbd89cc5a 100644
--- a/atmel-samd/Makefile
+++ b/atmel-samd/Makefile
@@ -210,7 +210,7 @@ SRC_C = \
asf/sam0/utils/cmsis/samd21/source/gcc/startup_samd21.c \
asf/sam0/utils/cmsis/samd21/source/system_samd21.c \
asf/sam0/utils/syscalls/gcc/syscalls.c \
- boards/$(BOARD)/init.c \
+ boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
freetouch/adafruit_ptc.c \
lib/fatfs/ff.c \
diff --git a/atmel-samd/boards/arduino_zero/board.c b/atmel-samd/boards/arduino_zero/board.c
new file mode 100644
index 000000000..519e5db1a
--- /dev/null
+++ b/atmel-samd/boards/arduino_zero/board.c
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+#include "asf/sam0/drivers/port/port.h"
+#include "mpconfigboard.h"
+
+void board_init(void)
+{
+ struct port_config pin_conf;
+ port_get_config_defaults(&pin_conf);
+
+ pin_conf.direction = PORT_PIN_DIR_OUTPUT;
+ port_pin_set_config(MICROPY_HW_LED_TX, &pin_conf);
+ port_pin_set_output_level(MICROPY_HW_LED_TX, true);
+
+ port_pin_set_config(MICROPY_HW_LED_RX, &pin_conf);
+ port_pin_set_output_level(MICROPY_HW_LED_RX, true);
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
diff --git a/atmel-samd/boards/arduino_zero/init.c b/atmel-samd/boards/arduino_zero/init.c
deleted file mode 100644
index 72a051aec..000000000
--- a/atmel-samd/boards/arduino_zero/init.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-#include "mpconfigboard.h"
-#include "asf/sam0/drivers/sercom/usart/usart.h"
-#include "asf/sam0/drivers/port/port.h"
-
-void board_init(void)
-{
- /* This function is meant to contain board-specific initialization code
- * for, e.g., the I/O pins. The initialization can rely on application-
- * specific board configuration, found in conf_board.h.
- */
- struct port_config pin_conf;
- port_get_config_defaults(&pin_conf);
-
- pin_conf.direction = PORT_PIN_DIR_OUTPUT;
- port_pin_set_config(MICROPY_HW_LED_TX, &pin_conf);
- port_pin_set_output_level(MICROPY_HW_LED_TX, true);
-
- port_pin_set_config(MICROPY_HW_LED_RX, &pin_conf);
- port_pin_set_output_level(MICROPY_HW_LED_RX, true);
-}
diff --git a/atmel-samd/boards/board.h b/atmel-samd/boards/board.h
new file mode 100644
index 000000000..a5d96c550
--- /dev/null
+++ b/atmel-samd/boards/board.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+// This file defines board specific functions.
+
+#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H__
+#define __MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H__
+
+#include <stdbool.h>
+
+// Initializes board related state once on start up.
+void board_init(void);
+
+// Returns true if the user initiates safe mode in a board specific way.
+// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific
+// way.
+bool board_requests_safe_mode(void);
+
+#endif // __MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_BOARD_H__
diff --git a/atmel-samd/boards/circuitplayground_express/board.c b/atmel-samd/boards/circuitplayground_express/board.c
new file mode 100644
index 000000000..9ed56d952
--- /dev/null
+++ b/atmel-samd/boards/circuitplayground_express/board.c
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+#include "asf/sam0/drivers/port/port.h"
+#include "common-hal/microcontroller/Pin.h"
+
+void board_init(void)
+{
+}
+
+// Check the status of the two buttons on CircuitPlayground Express. If both are
+// pressed, then boot into user safe mode.
+bool board_requests_safe_mode(void) {
+ struct port_config pin_conf;
+ port_get_config_defaults(&pin_conf);
+ pin_conf.direction = PORT_PIN_DIR_INPUT;
+ pin_conf.input_pull = PORT_PIN_PULL_DOWN;
+ port_pin_set_config(PIN_PA14, &pin_conf);
+ port_pin_set_config(PIN_PA28, &pin_conf);
+ bool safe_mode = port_pin_get_input_level(PIN_PA14) &&
+ port_pin_get_input_level(PIN_PA28);
+ reset_pin(PIN_PA14);
+ reset_pin(PIN_PA28);
+ return safe_mode;
+}
diff --git a/atmel-samd/boards/circuitplayground_express/init.c b/atmel-samd/boards/circuitplayground_express/init.c
deleted file mode 100644
index ac240b54b..000000000
--- a/atmel-samd/boards/circuitplayground_express/init.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-#include "mpconfigboard.h"
-#include "asf/sam0/drivers/port/port.h"
-
-void board_init(void)
-{
-}
diff --git a/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
index e551e5545..7ba716b3b 100644
--- a/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
+++ b/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
@@ -39,3 +39,6 @@
#include "flash_S25FL216K.h"
#define CALIBRATE_CRYSTALLESS 1
+
+// Explanation of how a user got into safe mode.
+#define BOARD_USER_SAFE_MODE "pressing both buttons at start up"
diff --git a/atmel-samd/boards/feather_m0_adalogger/board.c b/atmel-samd/boards/feather_m0_adalogger/board.c
new file mode 100644
index 000000000..06e67e11c
--- /dev/null
+++ b/atmel-samd/boards/feather_m0_adalogger/board.c
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+
+void board_init(void)
+{
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
diff --git a/atmel-samd/boards/feather_m0_adalogger/init.c b/atmel-samd/boards/feather_m0_adalogger/init.c
deleted file mode 100644
index 88608c0fb..000000000
--- a/atmel-samd/boards/feather_m0_adalogger/init.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-
-void board_init(void)
-{
- /* This function is meant to contain board-specific initialization code
- * for, e.g., the I/O pins. The initialization can rely on application-
- * specific board configuration, found in conf_board.h.
- */
-}
diff --git a/atmel-samd/boards/feather_m0_basic/board.c b/atmel-samd/boards/feather_m0_basic/board.c
new file mode 100644
index 000000000..06e67e11c
--- /dev/null
+++ b/atmel-samd/boards/feather_m0_basic/board.c
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+
+void board_init(void)
+{
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
diff --git a/atmel-samd/boards/feather_m0_basic/init.c b/atmel-samd/boards/feather_m0_basic/init.c
deleted file mode 100644
index 88608c0fb..000000000
--- a/atmel-samd/boards/feather_m0_basic/init.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-
-void board_init(void)
-{
- /* This function is meant to contain board-specific initialization code
- * for, e.g., the I/O pins. The initialization can rely on application-
- * specific board configuration, found in conf_board.h.
- */
-}
diff --git a/atmel-samd/boards/feather_m0_express/board.c b/atmel-samd/boards/feather_m0_express/board.c
new file mode 100644
index 000000000..06e67e11c
--- /dev/null
+++ b/atmel-samd/boards/feather_m0_express/board.c
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+
+void board_init(void)
+{
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
diff --git a/atmel-samd/boards/feather_m0_express/init.c b/atmel-samd/boards/feather_m0_express/init.c
deleted file mode 100644
index 88608c0fb..000000000
--- a/atmel-samd/boards/feather_m0_express/init.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-
-void board_init(void)
-{
- /* This function is meant to contain board-specific initialization code
- * for, e.g., the I/O pins. The initialization can rely on application-
- * specific board configuration, found in conf_board.h.
- */
-}
diff --git a/atmel-samd/boards/gemma_m0/board.c b/atmel-samd/boards/gemma_m0/board.c
new file mode 100644
index 000000000..06e67e11c
--- /dev/null
+++ b/atmel-samd/boards/gemma_m0/board.c
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+
+void board_init(void)
+{
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
diff --git a/atmel-samd/boards/gemma_m0/init.c b/atmel-samd/boards/gemma_m0/init.c
deleted file mode 100644
index ac240b54b..000000000
--- a/atmel-samd/boards/gemma_m0/init.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-#include "mpconfigboard.h"
-#include "asf/sam0/drivers/port/port.h"
-
-void board_init(void)
-{
-}
diff --git a/atmel-samd/boards/metro_m0_express/board.c b/atmel-samd/boards/metro_m0_express/board.c
new file mode 100644
index 000000000..519e5db1a
--- /dev/null
+++ b/atmel-samd/boards/metro_m0_express/board.c
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+#include "asf/sam0/drivers/port/port.h"
+#include "mpconfigboard.h"
+
+void board_init(void)
+{
+ struct port_config pin_conf;
+ port_get_config_defaults(&pin_conf);
+
+ pin_conf.direction = PORT_PIN_DIR_OUTPUT;
+ port_pin_set_config(MICROPY_HW_LED_TX, &pin_conf);
+ port_pin_set_output_level(MICROPY_HW_LED_TX, true);
+
+ port_pin_set_config(MICROPY_HW_LED_RX, &pin_conf);
+ port_pin_set_output_level(MICROPY_HW_LED_RX, true);
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
diff --git a/atmel-samd/boards/metro_m0_express/init.c b/atmel-samd/boards/metro_m0_express/init.c
deleted file mode 100644
index af8b08ff7..000000000
--- a/atmel-samd/boards/metro_m0_express/init.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-#include "mpconfigboard.h"
-#include "asf/sam0/drivers/port/port.h"
-
-void board_init(void)
-{
- /* This function is meant to contain board-specific initialization code
- * for, e.g., the I/O pins. The initialization can rely on application-
- * specific board configuration, found in conf_board.h.
- */
- struct port_config pin_conf;
- port_get_config_defaults(&pin_conf);
-
- pin_conf.direction = PORT_PIN_DIR_OUTPUT;
- port_pin_set_config(MICROPY_HW_LED_TX, &pin_conf);
- port_pin_set_output_level(MICROPY_HW_LED_TX, true);
-
- port_pin_set_config(MICROPY_HW_LED_RX, &pin_conf);
- port_pin_set_output_level(MICROPY_HW_LED_RX, true);
-}
diff --git a/atmel-samd/boards/trinket_m0/board.c b/atmel-samd/boards/trinket_m0/board.c
new file mode 100644
index 000000000..06e67e11c
--- /dev/null
+++ b/atmel-samd/boards/trinket_m0/board.c
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "boards/board.h"
+
+void board_init(void)
+{
+}
+
+bool board_requests_safe_mode(void) {
+ return false;
+}
diff --git a/atmel-samd/boards/trinket_m0/init.c b/atmel-samd/boards/trinket_m0/init.c
deleted file mode 100644
index ac240b54b..000000000
--- a/atmel-samd/boards/trinket_m0/init.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * \file
- *
- * \brief User board initialization template
- *
- */
-/*
- * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
- */
-
-#include "board.h"
-#include "conf_board.h"
-#include "mpconfigboard.h"
-#include "asf/sam0/drivers/port/port.h"
-
-void board_init(void)
-{
-}
diff --git a/atmel-samd/main.c b/atmel-samd/main.c
index 5eabd7d74..aaffcf90e 100644
--- a/atmel-samd/main.c
+++ b/atmel-samd/main.c
@@ -24,6 +24,8 @@
#include "asf/sam0/drivers/system/system.h"
#include <board.h>
+#include "boards/board.h"
+
#include "common-hal/analogio/AnalogIn.h"
#include "common-hal/audioio/AudioOut.h"
#include "common-hal/pulseio/PulseIn.h"
@@ -51,6 +53,7 @@ typedef enum {
NO_SAFE_MODE = 0,
BROWNOUT,
HARD_CRASH,
+ USER_SAFE_MODE,
} safe_mode_t;
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
@@ -331,6 +334,16 @@ bool start_mp(safe_mode_t safe_mode) {
mp_hal_stdout_tx_str("Auto-reload is off.\r\n");
}
}
+ // Output a user safe mode string if its set.
+ #ifdef BOARD_USER_SAFE_MODE
+ if (safe_mode == USER_SAFE_MODE) {
+ mp_hal_stdout_tx_str("\r\nYou requested starting safe mode by ");
+ mp_hal_stdout_tx_str(BOARD_USER_SAFE_MODE);
+ mp_hal_stdout_tx_str(".\r\nTo exit, please reset the board without ");
+ mp_hal_stdout_tx_str(BOARD_USER_SAFE_MODE);
+ mp_hal_stdout_tx_str(".\r\n");
+ } else
+ #endif
if (safe_mode != NO_SAFE_MODE) {
mp_hal_stdout_tx_str("\r\nYou are running in safe mode which means something really bad happened.\r\n");
if (safe_mode == HARD_CRASH) {
@@ -555,6 +568,10 @@ safe_mode_t samd21_init(void) {
return BROWNOUT;
}
+ if (board_requests_safe_mode()) {
+ return USER_SAFE_MODE;
+ }
+
return NO_SAFE_MODE;
}