|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include <string.h> |
| 28 | + |
| 29 | +#include "boards/board.h" |
| 30 | +#include "common-hal/microcontroller/Pin.h" |
| 31 | +#include "hal/include/hal_gpio.h" |
| 32 | +#include "shared-bindings/digitalio/DigitalInOut.h" |
| 33 | +#include "shared-bindings/neopixel_write/__init__.h" |
| 34 | +#include "samd21_pins.h" |
| 35 | + |
| 36 | +void board_init(void) |
| 37 | +{ |
| 38 | +} |
| 39 | + |
| 40 | +// Check the status of the two buttons on CircuitPlayground Express. If both are |
| 41 | +// pressed, then boot into user safe mode. |
| 42 | +bool board_requests_safe_mode(void) { |
| 43 | + gpio_set_pin_function(PIN_PA14, GPIO_PIN_FUNCTION_OFF); |
| 44 | + gpio_set_pin_direction(PIN_PA14, GPIO_DIRECTION_IN); |
| 45 | + gpio_set_pin_pull_mode(PIN_PA14, GPIO_PULL_DOWN); |
| 46 | + |
| 47 | + gpio_set_pin_function(PIN_PA28, GPIO_PIN_FUNCTION_OFF); |
| 48 | + gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_IN); |
| 49 | + gpio_set_pin_pull_mode(PIN_PA28, GPIO_PULL_DOWN); |
| 50 | + bool safe_mode = gpio_get_pin_level(PIN_PA14) && |
| 51 | + gpio_get_pin_level(PIN_PA28); |
| 52 | + reset_pin(PIN_PA14); |
| 53 | + reset_pin(PIN_PA28); |
| 54 | + return safe_mode; |
| 55 | +} |
| 56 | + |
| 57 | +void reset_board(void) { |
| 58 | + uint8_t empty[30]; |
| 59 | + memset(empty, 0, 30); |
| 60 | + digitalio_digitalinout_obj_t neopixel_pin; |
| 61 | + common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23); |
| 62 | + common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false, |
| 63 | + DRIVE_MODE_PUSH_PULL); |
| 64 | + common_hal_neopixel_write(&neopixel_pin, empty, 30); |
| 65 | + common_hal_digitalio_digitalinout_deinit(&neopixel_pin); |
| 66 | +} |
0 commit comments