From d7aa790e4b6aa8a2d6ae8b49b308728ff3942003 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 21 Nov 2018 12:55:01 -0600 Subject: add trailing '/' to links missing them --- docs/drivers.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/drivers.rst b/docs/drivers.rst index ff67fcbfb..e2d1e467d 100644 --- a/docs/drivers.rst +++ b/docs/drivers.rst @@ -147,14 +147,14 @@ equivalent carbon dioxide (``eco2`` / ``eCO2``), and total volatile organic comp CCS811 Air Quality DHT Temperature and Humidity DS18x20 Temperature - HTU21D Temperature and Humidity + HTU21D Temperature and Humidity MAX31865 Thermocouple Amplifier, Temperature MAX31855 Thermocouple Amplifier, Temperature MAX31856 Thermocouple Amplifier, Temperature MCP9808 Temperature MP115A2 Barometric Pressure, Temperature MPL3115A2 Barometric Pressure, Altitude and Temperature Sensor - MPRLS Ported Absolute Pressure + MPRLS Ported Absolute Pressure SGP30 Air Quality SHT31-D Temperature and Humidity Si7021 Temperature and Humidity @@ -186,8 +186,8 @@ These sensors measure the ``distance`` to another object and may also measure li .. toctree:: - Garmin LIDARLite I2C - TFmini IR Time of Flight ~30cm - 12m + Garmin LIDARLite I2C + TFmini IR Time of Flight ~30cm - 12m VL6180x 5 - 100 mm VL53L0x ~30 - 1000 mm HC-SR04 Ultrasonic Range Sensors @@ -234,7 +234,7 @@ Miscellaneous Si4713 Stereo FM Transmitter AMG88xx Grid-Eye IR Camera Trellis 4x4 Keypad - NeoTrellis 4x4 Keypad + NeoTrellis 4x4 Keypad NeoTrellis M4 4x8 Keypad DRV2605 Haptic Motor Controller MAX9744 Audio Amplifier -- cgit v1.2.3 From 59430ea26dd8b140dd5792e298fed2e1bcae7eb1 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 21 Nov 2018 12:58:11 -0600 Subject: fix L3GD20 link --- docs/drivers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/drivers.rst b/docs/drivers.rst index e2d1e467d..d3573a547 100644 --- a/docs/drivers.rst +++ b/docs/drivers.rst @@ -122,7 +122,7 @@ Motion relating sensing including ``acceleration``, ``magnetic``, ``gyro``, and FXAS21002C Gyroscope FXOS8700 Accelerometer GPS Global Position - L3GD20 Gyroscope + L3GD20 Gyroscope LIS3DH Accelerometer LSM303 Accelerometer and Magnetometer LSM9DS0 Accelerometer, Magnetometer, Gyroscope and Temperature -- cgit v1.2.3 From 4254ae6d5b278bb4f54f70731067eb3bbccb36cb Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 21 Nov 2018 13:05:02 -0600 Subject: add 74HC595 --- docs/drivers.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/drivers.rst b/docs/drivers.rst index d3573a547..119706d33 100644 --- a/docs/drivers.rst +++ b/docs/drivers.rst @@ -247,3 +247,4 @@ Miscellaneous Matrix Keypad VS1053 Audio Codec FRAM Non-Volatile Memory + 74HC595 Shift Register -- cgit v1.2.3 From 5fe746f64352d3b6d3bec651d655ae302a971863 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 21 Nov 2018 19:46:49 -0500 Subject: Latest Feather nRF52840 pin revisions --- .../feather_nrf52840_express/mpconfigboard.h | 28 +++++------ .../feather_nrf52840_express/mpconfigboard.mk | 2 +- ports/nrf/boards/feather_nrf52840_express/pins.c | 56 ++++++++++++---------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h index 68914c626..c52b69cf4 100644 --- a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h @@ -33,14 +33,14 @@ #define MICROPY_HW_MCU_NAME "nRF52840" #define MICROPY_PY_SYS_PLATFORM "Feather52840Express" -#define MICROPY_HW_NEOPIXEL (&pin_P0_13) +#define MICROPY_HW_NEOPIXEL (&pin_P0_16) -#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(1, 9) -#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 11) -#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 12) -#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 14) -#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 8) -#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 8) +#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 17) +#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 22) +#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 23) +#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 21) +#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19) +#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 20) #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 @@ -55,12 +55,12 @@ #define BOARD_HAS_CRYSTAL 1 -#define DEFAULT_I2C_BUS_SCL (&pin_P1_11) -#define DEFAULT_I2C_BUS_SDA (&pin_P1_12) +#define DEFAULT_I2C_BUS_SCL (&pin_P0_11) +#define DEFAULT_I2C_BUS_SDA (&pin_P0_12) -#define DEFAULT_SPI_BUS_SCK (&pin_P0_20) -#define DEFAULT_SPI_BUS_MOSI (&pin_P0_23) -#define DEFAULT_SPI_BUS_MISO (&pin_P0_22) +#define DEFAULT_SPI_BUS_SCK (&pin_P0_14) +#define DEFAULT_SPI_BUS_MOSI (&pin_P0_13) +#define DEFAULT_SPI_BUS_MISO (&pin_P0_15) -#define DEFAULT_UART_BUS_RX (&pin_P1_00) -#define DEFAULT_UART_BUS_TX (&pin_P0_24) +#define DEFAULT_UART_BUS_RX (&pin_P0_24) +#define DEFAULT_UART_BUS_TX (&pin_P0_25) diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk index f03109319..905921a5d 100644 --- a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk @@ -22,4 +22,4 @@ NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICE_COUNT = 1 -EXTERNAL_FLASH_DEVICES = "GD25Q64C" +EXTERNAL_FLASH_DEVICES = "GD25Q16C" diff --git a/ports/nrf/boards/feather_nrf52840_express/pins.c b/ports/nrf/boards/feather_nrf52840_express/pins.c index 0f5eab31d..b85b72af0 100644 --- a/ports/nrf/boards/feather_nrf52840_express/pins.c +++ b/ports/nrf/boards/feather_nrf52840_express/pins.c @@ -3,39 +3,47 @@ #include "board_busses.h" STATIC const mp_rom_map_elem_t board_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_30) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_28) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_31) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_02) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_02) }, { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_03) }, - { MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_04) }, - { MP_ROM_QSTR(MP_QSTR_VDIV), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_31) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P1_13) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_P1_14) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_P0_29) }, + + { MP_ROM_QSTR(MP_QSTR_SWITCH), MP_ROM_PTR(&pin_P1_02) }, + + { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) }, + + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P0_26) }, { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_P0_27) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_26) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P0_06) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P0_07) }, - { MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P1_09) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_P0_16) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_20) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_23) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_15) }, - { MP_ROM_QSTR(MP_QSTR_TXD), MP_ROM_PTR(&pin_P0_24) }, - { MP_ROM_QSTR(MP_QSTR_RXD), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_TXD), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_RXD), MP_ROM_PTR(&pin_P0_24) }, - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P1_11) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P1_12) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_12) }, - { MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_P1_02) }, - { MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_RED_LED), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_BLUE_LED), MP_ROM_PTR(&pin_P1_10) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); -- cgit v1.2.3 From 324301e3bc23d3c5d2b7aebff745999c38532d19 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 23 Nov 2018 12:51:11 -0800 Subject: Update tinyusb to include control fixes. --- lib/tinyusb | 2 +- ports/atmel-samd/Makefile | 6 ++---- ports/nrf/Makefile | 9 +-------- supervisor/shared/usb/usb_msc_flash.c | 15 ++++----------- supervisor/supervisor.mk | 2 +- 5 files changed, 9 insertions(+), 25 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index c62d9a1fe..47fabe42e 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit c62d9a1fefa76bf59d43ff56ce6ca1e138a69c76 +Subproject commit 47fabe42edaae4a5da6aa0d48c664a9184578753 diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 23fb39779..99b8842c6 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -61,7 +61,6 @@ BASE_CFLAGS = \ -Wno-endif-labels \ -Wstrict-prototypes \ -Werror-implicit-function-declaration \ - -Wpointer-arith \ -Wfloat-equal \ -Wundef \ -Wshadow \ @@ -69,7 +68,6 @@ BASE_CFLAGS = \ -Wsign-compare \ -Wmissing-format-attribute \ -Wno-deprecated-declarations \ - -Wpacked \ -Wnested-externs \ -Wunreachable-code \ -Wcast-align \ @@ -265,8 +263,8 @@ SRC_C = \ lib/oofatfs/ff.c \ lib/oofatfs/option/ccsbcs.c \ lib/timeutils/timeutils.c \ - lib/tinyusb/src/portable/microchip/$(CHIP_FAMILY)/dcd.c \ - lib/tinyusb/src/portable/microchip/$(CHIP_FAMILY)/hal.c \ + lib/tinyusb/src/portable/microchip/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c \ + lib/tinyusb/src/portable/microchip/$(CHIP_FAMILY)/hal_$(CHIP_FAMILY).c \ lib/utils/buffer_helper.c \ lib/utils/context_manager_helpers.c \ lib/utils/interrupt_char.c \ diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 8d0d6d000..558731a44 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -218,14 +218,7 @@ ifeq ($(MCU_SUB_VARIANT),nrf52840) SRC_C += \ lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \ - lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \ - lib/tinyusb/src/common/tusb_fifo.c \ - lib/tinyusb/src/device/control.c \ - lib/tinyusb/src/device/usbd.c \ - lib/tinyusb/src/class/msc/msc_device.c \ - lib/tinyusb/src/class/cdc/cdc_device.c \ - lib/tinyusb/src/class/hid/hid_device.c \ - lib/tinyusb/src/tusb.c \ + lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c SRC_SHARED_MODULE += \ usb_hid/__init__.c \ diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index 13b5c3966..658aab0d8 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -133,17 +133,10 @@ int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer, return resplen; } -bool tud_lun_capacity_cb(uint8_t lun, uint32_t* last_valid_sector, uint16_t* sector_size) { - fs_user_mount_t * vfs = get_vfs(lun); - if (vfs == NULL || - disk_ioctl(vfs, GET_SECTOR_COUNT, last_valid_sector) != RES_OK || - disk_ioctl(vfs, GET_SECTOR_SIZE, sector_size) != RES_OK) { - return false; - } - // Subtract one from the sector count to get the last valid sector. - (*last_valid_sector)--; - - return true; +void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size) { + fs_user_mount_t * vfs = get_vfs(lun); + disk_ioctl(vfs, GET_SECTOR_COUNT, block_count); + disk_ioctl(vfs, GET_SECTOR_SIZE, block_size); } bool tud_msc_is_writable_cb(uint8_t lun) { diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index ac982d277..73c76ebb7 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -43,8 +43,8 @@ ifeq ($(USB),FALSE) endif else SRC_SUPERVISOR += lib/tinyusb/src/common/tusb_fifo.c \ - lib/tinyusb/src/device/control.c \ lib/tinyusb/src/device/usbd.c \ + lib/tinyusb/src/device/usbd_control.c \ lib/tinyusb/src/class/msc/msc_device.c \ lib/tinyusb/src/class/cdc/cdc_device.c \ lib/tinyusb/src/class/hid/hid_device.c \ -- cgit v1.2.3 From 15eeac5d4bc796f09b70ad7b3b52f8fc2175a344 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 23 Nov 2018 14:22:07 -0800 Subject: A few fixes for nRF52840 feather QSPI and neopixel --- .../nrf/boards/feather_nrf52840_express/mpconfigboard.h | 11 +++++++++-- .../nrf/boards/feather_nrf52840_express/mpconfigboard.mk | 2 +- ports/nrf/common-hal/microcontroller/Pin.c | 2 -- ports/nrf/common-hal/neopixel_write/__init__.c | 16 ++++++++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h index c52b69cf4..bd1cad504 100644 --- a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h @@ -35,12 +35,21 @@ #define MICROPY_HW_NEOPIXEL (&pin_P0_16) +#ifdef QSPI_FLASH_FILESYSTEM #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 17) #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 22) #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 23) #define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 21) #define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19) #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 20) +#endif + +#ifdef SPI_FLASH_FILESYSTEM +#define SPI_FLASH_MOSI_PIN &pin_P0_17 +#define SPI_FLASH_MISO_PIN &pin_P0_22 +#define SPI_FLASH_SCK_PIN &pin_P0_19 +#define SPI_FLASH_CS_PIN &pin_P0_20 +#endif #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 @@ -51,8 +60,6 @@ #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) -#define EXTERNAL_FLASH_QSPI_DUAL (1) - #define BOARD_HAS_CRYSTAL 1 #define DEFAULT_I2C_BUS_SCL (&pin_P0_11) diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk index 905921a5d..bc511e150 100644 --- a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk @@ -20,6 +20,6 @@ endif NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 -QSPI_FLASH_FILESYSTEM = 1 +SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICE_COUNT = 1 EXTERNAL_FLASH_DEVICES = "GD25Q16C" diff --git a/ports/nrf/common-hal/microcontroller/Pin.c b/ports/nrf/common-hal/microcontroller/Pin.c index 0522bfef3..02847e150 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.c +++ b/ports/nrf/common-hal/microcontroller/Pin.c @@ -48,7 +48,6 @@ STATIC uint32_t claimed_pins[GPIO_COUNT]; STATIC uint32_t never_reset_pins[GPIO_COUNT]; void reset_all_pins(void) { - return; for (size_t i = 0; i < GPIO_COUNT; i++) { claimed_pins[i] = never_reset_pins[i]; } @@ -77,7 +76,6 @@ void reset_all_pins(void) { // Mark pin as free and return it to a quiescent state. void reset_pin_number(uint8_t pin_number) { - return; if (pin_number == NO_PIN) { return; } diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c index ef5e8beb1..c4cb194f3 100644 --- a/ports/nrf/common-hal/neopixel_write/__init__.c +++ b/ports/nrf/common-hal/neopixel_write/__init__.c @@ -108,12 +108,21 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout // using DWT uint32_t pattern_size = numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t); uint16_t* pixels_pattern = NULL; + 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. + uint32_t one_pixel[8 * sizeof(uint16_t) + 1]; NRF_PWM_Type* pwm = find_free_pwm(); // only malloc if there is PWM device available if ( pwm != NULL ) { - pixels_pattern = (uint16_t *) m_malloc(pattern_size, false); + if (numBytes == 4) { + pixels_pattern = (uint16_t *) one_pixel; + } else { + pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); + pattern_on_heap = true; + } } // Use the identified device to choose the implementation @@ -193,7 +202,10 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout nrf_pwm_disable(pwm); nrf_pwm_pins_set(pwm, (uint32_t[]) {0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL} ); - m_free(pixels_pattern); + if (pattern_on_heap) { + m_free(pixels_pattern); + } + } // End of DMA implementation // --------------------------------------------------------------------- else { -- cgit v1.2.3