From 3e23464b1ed11710714a4d6eaa98c2c84ec6f4dd Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 16 Jun 2017 14:55:53 -0700 Subject: [PATCH] atmel-samd: Add user initiated safe mode and rework board.c for board specific functionality. Fixes #155 --- atmel-samd/Makefile | 2 +- atmel-samd/boards/arduino_zero/board.c | 46 +++++++++++++++++ atmel-samd/boards/arduino_zero/init.c | 32 ------------ atmel-samd/boards/board.h | 42 ++++++++++++++++ .../boards/circuitplayground_express/board.c | 49 +++++++++++++++++++ .../boards/circuitplayground_express/init.c | 18 ------- .../circuitplayground_express/mpconfigboard.h | 3 ++ .../boards/feather_m0_adalogger/board.c | 35 +++++++++++++ atmel-samd/boards/feather_m0_adalogger/init.c | 20 -------- atmel-samd/boards/feather_m0_basic/board.c | 35 +++++++++++++ atmel-samd/boards/feather_m0_basic/init.c | 20 -------- atmel-samd/boards/feather_m0_express/board.c | 35 +++++++++++++ atmel-samd/boards/feather_m0_express/init.c | 20 -------- atmel-samd/boards/gemma_m0/board.c | 35 +++++++++++++ atmel-samd/boards/gemma_m0/init.c | 18 ------- atmel-samd/boards/metro_m0_express/board.c | 46 +++++++++++++++++ atmel-samd/boards/metro_m0_express/init.c | 31 ------------ atmel-samd/boards/trinket_m0/board.c | 35 +++++++++++++ atmel-samd/boards/trinket_m0/init.c | 18 ------- atmel-samd/main.c | 17 +++++++ 20 files changed, 379 insertions(+), 178 deletions(-) create mode 100644 atmel-samd/boards/arduino_zero/board.c delete mode 100644 atmel-samd/boards/arduino_zero/init.c create mode 100644 atmel-samd/boards/board.h create mode 100644 atmel-samd/boards/circuitplayground_express/board.c delete mode 100644 atmel-samd/boards/circuitplayground_express/init.c create mode 100644 atmel-samd/boards/feather_m0_adalogger/board.c delete mode 100644 atmel-samd/boards/feather_m0_adalogger/init.c create mode 100644 atmel-samd/boards/feather_m0_basic/board.c delete mode 100644 atmel-samd/boards/feather_m0_basic/init.c create mode 100644 atmel-samd/boards/feather_m0_express/board.c delete mode 100644 atmel-samd/boards/feather_m0_express/init.c create mode 100644 atmel-samd/boards/gemma_m0/board.c delete mode 100644 atmel-samd/boards/gemma_m0/init.c create mode 100644 atmel-samd/boards/metro_m0_express/board.c delete mode 100644 atmel-samd/boards/metro_m0_express/init.c create mode 100644 atmel-samd/boards/trinket_m0/board.c delete mode 100644 atmel-samd/boards/trinket_m0/init.c diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile index e7de4aede0..fbd89cc5ad 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 0000000000..519e5db1a2 --- /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 72a051aec1..0000000000 --- a/atmel-samd/boards/arduino_zero/init.c +++ /dev/null @@ -1,32 +0,0 @@ -/** - * \file - * - * \brief User board initialization template - * - */ -/* - * Support and FAQ: visit Atmel Support - */ - -#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 0000000000..a5d96c5508 --- /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 + +// 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 0000000000..9ed56d952d --- /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 ac240b54b7..0000000000 --- a/atmel-samd/boards/circuitplayground_express/init.c +++ /dev/null @@ -1,18 +0,0 @@ -/** - * \file - * - * \brief User board initialization template - * - */ -/* - * Support and FAQ: visit Atmel Support - */ - -#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 e551e5545e..7ba716b3b7 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 0000000000..06e67e11cc --- /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 88608c0fbe..0000000000 --- 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 Atmel Support - */ - -#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 0000000000..06e67e11cc --- /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 88608c0fbe..0000000000 --- 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 Atmel Support - */ - -#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 0000000000..06e67e11cc --- /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 88608c0fbe..0000000000 --- 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 Atmel Support - */ - -#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 0000000000..06e67e11cc --- /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 ac240b54b7..0000000000 --- a/atmel-samd/boards/gemma_m0/init.c +++ /dev/null @@ -1,18 +0,0 @@ -/** - * \file - * - * \brief User board initialization template - * - */ -/* - * Support and FAQ: visit Atmel Support - */ - -#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 0000000000..519e5db1a2 --- /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 af8b08ff7f..0000000000 --- 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 Atmel Support - */ - -#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 0000000000..06e67e11cc --- /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 ac240b54b7..0000000000 --- a/atmel-samd/boards/trinket_m0/init.c +++ /dev/null @@ -1,18 +0,0 @@ -/** - * \file - * - * \brief User board initialization template - * - */ -/* - * Support and FAQ: visit Atmel Support - */ - -#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 5eabd7d748..aaffcf90ea 100644 --- a/atmel-samd/main.c +++ b/atmel-samd/main.c @@ -24,6 +24,8 @@ #include "asf/sam0/drivers/system/system.h" #include +#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; }