reset NeoPixels on CPB on soft reload
This commit is contained in:
parent
1831f5164c
commit
68f9aee992
|
@ -28,9 +28,8 @@
|
||||||
|
|
||||||
#include "boards/board.h"
|
#include "boards/board.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "common-hal/microcontroller/Pin.h"
|
||||||
|
#include "supervisor/shared/board.h"
|
||||||
#include "hal/include/hal_gpio.h"
|
#include "hal/include/hal_gpio.h"
|
||||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
|
||||||
#include "shared-bindings/neopixel_write/__init__.h"
|
|
||||||
|
|
||||||
void board_init(void)
|
void board_init(void)
|
||||||
{
|
{
|
||||||
|
@ -54,12 +53,5 @@ bool board_requests_safe_mode(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_board(void) {
|
void reset_board(void) {
|
||||||
uint8_t empty[30];
|
board_reset_user_neopixels();
|
||||||
memset(empty, 0, 30);
|
|
||||||
digitalio_digitalinout_obj_t neopixel_pin;
|
|
||||||
common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23);
|
|
||||||
common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false,
|
|
||||||
DRIVE_MODE_PUSH_PULL);
|
|
||||||
common_hal_neopixel_write(&neopixel_pin, empty, 30);
|
|
||||||
common_hal_digitalio_digitalinout_deinit(&neopixel_pin);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
// Increase stack size slightly due to CPX library import nesting
|
// Increase stack size slightly due to CPX library import nesting
|
||||||
#define CIRCUITPY_DEFAULT_STACK_SIZE (4760) //divisible by 8
|
#define CIRCUITPY_DEFAULT_STACK_SIZE (4760) //divisible by 8
|
||||||
|
|
||||||
|
#define USER_NEOPIXELS_PIN (&pin_PB23)
|
||||||
|
|
||||||
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
|
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
|
||||||
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
|
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
#include "boards/board.h"
|
#include "boards/board.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "common-hal/microcontroller/Pin.h"
|
||||||
#include "hal/include/hal_gpio.h"
|
#include "hal/include/hal_gpio.h"
|
||||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
#include "supervisor/shared/board.h"
|
||||||
#include "shared-bindings/neopixel_write/__init__.h"
|
|
||||||
|
|
||||||
void board_init(void)
|
void board_init(void)
|
||||||
{
|
{
|
||||||
|
@ -54,12 +53,5 @@ bool board_requests_safe_mode(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_board(void) {
|
void reset_board(void) {
|
||||||
uint8_t empty[30];
|
board_reset_user_neopixels();
|
||||||
memset(empty, 0, 30);
|
|
||||||
digitalio_digitalinout_obj_t neopixel_pin;
|
|
||||||
common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23);
|
|
||||||
common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false,
|
|
||||||
DRIVE_MODE_PUSH_PULL);
|
|
||||||
common_hal_neopixel_write(&neopixel_pin, empty, 30);
|
|
||||||
common_hal_digitalio_digitalinout_deinit(&neopixel_pin);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#define CALIBRATE_CRYSTALLESS 1
|
#define CALIBRATE_CRYSTALLESS 1
|
||||||
|
|
||||||
|
#define USER_NEOPIXELS_PIN (&pin_PB23)
|
||||||
|
|
||||||
// Explanation of how a user got into safe mode.
|
// Explanation of how a user got into safe mode.
|
||||||
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
|
#define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up"
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
#include "boards/board.h"
|
#include "boards/board.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "common-hal/microcontroller/Pin.h"
|
||||||
#include "hal/include/hal_gpio.h"
|
#include "hal/include/hal_gpio.h"
|
||||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
#include "supervisor/shared/board.h"
|
||||||
#include "shared-bindings/neopixel_write/__init__.h"
|
|
||||||
|
|
||||||
void board_init(void)
|
void board_init(void)
|
||||||
{
|
{
|
||||||
|
@ -54,12 +53,5 @@ bool board_requests_safe_mode(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_board(void) {
|
void reset_board(void) {
|
||||||
uint8_t empty[30];
|
board_reset_user_neopixels();
|
||||||
memset(empty, 0, 30);
|
|
||||||
digitalio_digitalinout_obj_t neopixel_pin;
|
|
||||||
common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23);
|
|
||||||
common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false,
|
|
||||||
DRIVE_MODE_PUSH_PULL);
|
|
||||||
common_hal_neopixel_write(&neopixel_pin, empty, 30);
|
|
||||||
common_hal_digitalio_digitalinout_deinit(&neopixel_pin);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
// Increase stack size slightly due to CPX library import nesting.
|
// Increase stack size slightly due to CPX library import nesting.
|
||||||
#define CIRCUITPY_DEFAULT_STACK_SIZE (4760) // divisible by 8
|
#define CIRCUITPY_DEFAULT_STACK_SIZE (4760) // divisible by 8
|
||||||
|
|
||||||
|
#define USER_NEOPIXELS_PIN (&pin_PB23)
|
||||||
|
|
||||||
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
|
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
|
||||||
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
|
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "mpconfigboard.h"
|
#include "mpconfigboard.h"
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "peripherals/nrf/pins.h"
|
#include "peripherals/nrf/pins.h"
|
||||||
|
#include "supervisor/shared/board.h"
|
||||||
|
|
||||||
#include "nrf_gpio.h"
|
#include "nrf_gpio.h"
|
||||||
|
|
||||||
|
@ -47,4 +48,6 @@ void reset_board(void) {
|
||||||
NRF_GPIO_PIN_S0S1,
|
NRF_GPIO_PIN_S0S1,
|
||||||
NRF_GPIO_PIN_NOSENSE);
|
NRF_GPIO_PIN_NOSENSE);
|
||||||
nrf_gpio_pin_write(POWER_SWITCH_PIN->number, false);
|
nrf_gpio_pin_write(POWER_SWITCH_PIN->number, false);
|
||||||
|
|
||||||
|
board_reset_user_neopixels();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@
|
||||||
// Disables onboard peripherals and neopixels to save power.
|
// Disables onboard peripherals and neopixels to save power.
|
||||||
#define POWER_SWITCH_PIN (&pin_P0_06)
|
#define POWER_SWITCH_PIN (&pin_P0_06)
|
||||||
|
|
||||||
|
#define USER_NEOPIXELS_PIN (&pin_P0_13)
|
||||||
|
|
||||||
#define DEFAULT_I2C_BUS_SCL (&pin_P0_04)
|
#define DEFAULT_I2C_BUS_SCL (&pin_P0_04)
|
||||||
#define DEFAULT_I2C_BUS_SDA (&pin_P0_05)
|
#define DEFAULT_I2C_BUS_SDA (&pin_P0_05)
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ uint32_t next_start_tick_us = 1000;
|
||||||
|
|
||||||
void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) {
|
void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) {
|
||||||
// To support both the SoftDevice + Neopixels we use the EasyDMA
|
// To support both the SoftDevice + Neopixels we use the EasyDMA
|
||||||
// feature from the NRF25. However this technique implies to
|
// feature from the NRF52. However this technique implies to
|
||||||
// generate a pattern and store it on the memory. The actual
|
// generate a pattern and store it on the memory. The actual
|
||||||
// memory used in bytes corresponds to the following formula:
|
// memory used in bytes corresponds to the following formula:
|
||||||
// totalMem = numBytes*8*2+(2*2)
|
// totalMem = numBytes*8*2+(2*2)
|
||||||
|
@ -113,22 +113,28 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
|
||||||
// using DWT
|
// using DWT
|
||||||
|
|
||||||
#define PATTERN_SIZE(numBytes) (numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t))
|
#define PATTERN_SIZE(numBytes) (numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t))
|
||||||
|
// Allocate PWM space for up to STACK_PIXELS on the stack, to avoid malloc'ing.
|
||||||
|
// We may need to write to the status neopixel or to Circuit Playground NeoPixels
|
||||||
|
// when we cannot malloc, between VM instantiations.
|
||||||
|
// We need space for at least 10 pixels for Circuit Playground, but let's choose 24
|
||||||
|
// to handle larger NeoPixel rings without malloc'ing.
|
||||||
|
#define STACK_PIXELS 24
|
||||||
|
|
||||||
uint32_t pattern_size = PATTERN_SIZE(numBytes);
|
uint32_t pattern_size = PATTERN_SIZE(numBytes);
|
||||||
uint16_t* pixels_pattern = NULL;
|
uint16_t* pixels_pattern = NULL;
|
||||||
bool pattern_on_heap = false;
|
bool pattern_on_heap = false;
|
||||||
|
|
||||||
// Use the stack to store 1 pixels worth of PWM data for the status led. uint32_t to ensure alignment.
|
// Use the stack to store STACK_PIXEL's worth of PWM data. uint32_t to ensure alignment.
|
||||||
// Make it at least as big as PATTERN_SIZE(3), for one pixel of RGB data.
|
// It is 3*STACK_PIXELS to handle RGB.
|
||||||
// PATTERN_SIZE is a multiple of 4, so we don't need round up to make sure one_pixel is large enough.
|
// PATTERN_SIZE is a multiple of 4, so we don't need round up to make sure one_pixel is large enough.
|
||||||
uint32_t one_pixel[PATTERN_SIZE(3)/sizeof(uint32_t)];
|
uint32_t stack_pixels[PATTERN_SIZE(3 * STACK_PIXELS) / sizeof(uint32_t)];
|
||||||
|
|
||||||
NRF_PWM_Type* pwm = find_free_pwm();
|
NRF_PWM_Type* pwm = find_free_pwm();
|
||||||
|
|
||||||
// only malloc if there is PWM device available
|
// only malloc if there is PWM device available
|
||||||
if ( pwm != NULL ) {
|
if ( pwm != NULL ) {
|
||||||
if (pattern_size <= sizeof(one_pixel)) {
|
if (pattern_size <= sizeof(stack_pixels)) {
|
||||||
pixels_pattern = (uint16_t *) one_pixel;
|
pixels_pattern = (uint16_t *) stack_pixels;
|
||||||
} else {
|
} else {
|
||||||
uint8_t sd_en = 0;
|
uint8_t sd_en = 0;
|
||||||
(void) sd_softdevice_is_enabled(&sd_en);
|
(void) sd_softdevice_is_enabled(&sd_en);
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Dan Halbert 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 "supervisor/shared/board.h"
|
||||||
|
|
||||||
|
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||||
|
#include "shared-bindings/neopixel_write/__init__.h"
|
||||||
|
|
||||||
|
#ifdef USER_NEOPIXELS_PIN
|
||||||
|
|
||||||
|
void board_reset_user_neopixels(void) {
|
||||||
|
// Turn off on-board NeoPixel string
|
||||||
|
uint8_t empty[30] = { 0 };
|
||||||
|
digitalio_digitalinout_obj_t neopixel_pin;
|
||||||
|
common_hal_digitalio_digitalinout_construct(&neopixel_pin, USER_NEOPIXELS_PIN);
|
||||||
|
common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false,
|
||||||
|
DRIVE_MODE_PUSH_PULL);
|
||||||
|
common_hal_neopixel_write(&neopixel_pin, empty, 30);
|
||||||
|
common_hal_digitalio_digitalinout_deinit(&neopixel_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Dan Halbert 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_SUPERVISOR_BOARD_H
|
||||||
|
#define MICROPY_INCLUDED_SUPERVISOR_BOARD_H
|
||||||
|
|
||||||
|
#include "py/mpconfig.h"
|
||||||
|
|
||||||
|
#ifdef USER_NEOPIXELS_PIN
|
||||||
|
|
||||||
|
void board_reset_user_neopixels(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_SUPERVISOR_BOARD_H
|
|
@ -2,6 +2,7 @@ SRC_SUPERVISOR = \
|
||||||
main.c \
|
main.c \
|
||||||
supervisor/port.c \
|
supervisor/port.c \
|
||||||
supervisor/shared/autoreload.c \
|
supervisor/shared/autoreload.c \
|
||||||
|
supervisor/shared/board.c \
|
||||||
supervisor/shared/display.c \
|
supervisor/shared/display.c \
|
||||||
supervisor/shared/filesystem.c \
|
supervisor/shared/filesystem.c \
|
||||||
supervisor/shared/flash.c \
|
supervisor/shared/flash.c \
|
||||||
|
|
Loading…
Reference in New Issue