From 2c13fd53f47ece3080a9ca50664cd5d38d1e471c Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Jun 2019 22:51:38 +0700 Subject: [PATCH 1/5] support 10 neopixel of cplayground --- README.md | 2 +- src/boards.c | 40 +++++++++++-------- src/boards/circuitplayground_nrf52840/board.h | 5 ++- src/boards/feather_nrf52840_express/board.h | 6 ++- src/boards/metro_nrf52840_express/board.h | 6 ++- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f977929..32f83da 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ For other boards, please check the board definition for details. ### Making your own UF2 -To create your own UF2 DFU update image, simply use the [Python conversion script](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) on a .bin file or .hex file, specifying the family as **0xADA52840**. Be sure to compile your application to start at 0x26000 (152k). If using a .bin file with the conversion script you must specify this with the -b switch. +To create your own UF2 DFU update image, simply use the [Python conversion script](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) on a .bin file or .hex file, specifying the family as **0xADA52840**. If using a .bin file with the conversion script you must specify application address with the -b switch, this address depend on the SoftDevice size/version e.g S140 v6 is 0x26000 To create a UF2 image from a .bin file: ``` diff --git a/src/boards.c b/src/boards.c index 44890ed..e1993aa 100644 --- a/src/boards.c +++ b/src/boards.c @@ -34,7 +34,9 @@ #define SCHED_QUEUE_SIZE 30 /**< Maximum number of events in the scheduler queue. */ #if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) + void neopixel_init(void); void neopixel_write(uint8_t *pixels); + void neopixel_teardown(void); #endif //------------- IMPLEMENTATION -------------// @@ -67,9 +69,8 @@ void board_init(void) led_pwm_init(LED_SECONDARY, LED_SECONDARY_PIN); #endif -// use neopixel for use enumeration + // use neopixel for use enumeration #if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) - extern void neopixel_init(void); neopixel_init(); #endif @@ -93,7 +94,6 @@ void board_teardown(void) led_pwm_teardown(); #if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) - extern void neopixel_teardown(void); neopixel_teardown(); #endif // Button @@ -297,9 +297,9 @@ void led_state(uint32_t state) #define MAGIC_T1H 13UL | (0x8000) // 0.8125us #define CTOPVAL 20UL // 1.25us -#define NEO_NUMBYTE 3 +#define BYTE_PER_PIXEL 3 -static uint16_t pixels_pattern[NEO_NUMBYTE * 8 + 2]; +static uint16_t pixels_pattern[NEOPIXELS_NUMBER*BYTE_PER_PIXEL * 8 + 2]; // use PWM1 for neopixel void neopixel_init(void) @@ -347,29 +347,35 @@ void neopixel_init(void) void neopixel_teardown(void) { - uint8_t grb[3] = { 0, 0, 0 }; + uint8_t rgb[3] = { 0, 0, 0 }; NRFX_DELAY_US(50); // wait for previous write is complete - neopixel_write(grb); + neopixel_write(rgb); NRFX_DELAY_US(50); // wait for this write pwm_teardown(NRF_PWM1); } -// write 3 bytes color to a built-in neopixel +// write 3 bytes color RGB to built-in neopixel void neopixel_write (uint8_t *pixels) { - uint8_t grb[NEO_NUMBYTE] = {pixels[1], pixels[2], pixels[0]}; + // convert RGB to GRB + uint8_t grb[BYTE_PER_PIXEL] = {pixels[1], pixels[2], pixels[0]}; uint16_t pos = 0; // bit position - for ( uint16_t n = 0; n < NEO_NUMBYTE; n++ ) - { - uint8_t pix = grb[n]; - for ( uint8_t mask = 0x80; mask > 0; mask >>= 1 ) + // Set all neopixel to same value + for (uint16_t n = 0; n < NEOPIXELS_NUMBER; n++ ) + { + for(uint8_t c = 0; c < BYTE_PER_PIXEL; c++) { - pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H; - pos++; + uint8_t const pix = grb[c]; + + for ( uint8_t mask = 0x80; mask > 0; mask >>= 1 ) + { + pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H; + pos++; + } } } @@ -409,8 +415,8 @@ void neopixel_init(void) void neopixel_teardown(void) { - uint8_t grb[3] = { 0, 0, 0 }; - neopixel_write(grb); + uint8_t rgb[3] = { 0, 0, 0 }; + neopixel_write(rgb); nrf_gpio_cfg_default(LED_RGB_RED_PIN); nrf_gpio_cfg_default(LED_RGB_GREEN_PIN); nrf_gpio_cfg_default(LED_RGB_BLUE_PIN); diff --git a/src/boards/circuitplayground_nrf52840/board.h b/src/boards/circuitplayground_nrf52840/board.h index c926cad..e673c30 100644 --- a/src/boards/circuitplayground_nrf52840/board.h +++ b/src/boards/circuitplayground_nrf52840/board.h @@ -32,10 +32,11 @@ *------------------------------------------------------------------*/ #define LEDS_NUMBER 1 #define LED_PRIMARY_PIN _PINNUM(1, 14) +#define LED_STATE_ON 1 + #define LED_NEOPIXEL _PINNUM(0, 13) #define NEOPIXELS_NUMBER 10 #define BOARD_RGB_BRIGHTNESS 0x040404 -#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON @@ -68,7 +69,7 @@ //------------- UF2 -------------// #define UF2_PRODUCT_NAME "Adafruit Circuit Playground nRF52840" #define UF2_VOLUME_LABEL "CPLAYBTBOOT" -#define UF2_BOARD_ID "CircuitPlayground-nRF52840-revD" +#define UF2_BOARD_ID "nRF52840-CircuitPlayground-revD" #define UF2_INDEX_URL "https://www.adafruit.com/product/4300" #endif // _FEATHER_NRF52840_H diff --git a/src/boards/feather_nrf52840_express/board.h b/src/boards/feather_nrf52840_express/board.h index 9a256a2..d2384e9 100644 --- a/src/boards/feather_nrf52840_express/board.h +++ b/src/boards/feather_nrf52840_express/board.h @@ -33,10 +33,12 @@ #define LEDS_NUMBER 2 #define LED_PRIMARY_PIN _PINNUM(1, 15) #define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_NEOPIXEL 16 -#define BOARD_RGB_BRIGHTNESS 0x040404 #define LED_STATE_ON 1 +#define LED_NEOPIXEL _PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ diff --git a/src/boards/metro_nrf52840_express/board.h b/src/boards/metro_nrf52840_express/board.h index 0e68f01..4a9340f 100644 --- a/src/boards/metro_nrf52840_express/board.h +++ b/src/boards/metro_nrf52840_express/board.h @@ -33,10 +33,12 @@ #define LEDS_NUMBER 2 #define LED_PRIMARY_PIN _PINNUM(1, 13) #define LED_SECONDARY_PIN _PINNUM(1, 15) -#define LED_NEOPIXEL _PINNUM(0, 13) -#define BOARD_RGB_BRIGHTNESS 0x040404 #define LED_STATE_ON 1 +#define LED_NEOPIXEL _PINNUM(0, 13) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ From 661827c166989eeadbebe0ef7b4230793b678a4e Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 13 Jul 2019 19:59:09 -0400 Subject: [PATCH 2/5] update to rev C pins --- src/boards/circuitplayground_nrf52840/board.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/boards/circuitplayground_nrf52840/board.h b/src/boards/circuitplayground_nrf52840/board.h index e673c30..dc35965 100644 --- a/src/boards/circuitplayground_nrf52840/board.h +++ b/src/boards/circuitplayground_nrf52840/board.h @@ -42,14 +42,14 @@ /* BUTTON *------------------------------------------------------------------*/ #define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 01) // left button +#define BUTTON_1 _PINNUM(1, 02) // left button #define BUTTON_2 _PINNUM(1, 15) // right button -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_PULL NRF_GPIO_PIN_PULLDOWN /*------------------------------------------------------------------*/ /* UART *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(0, 29) +#define RX_PIN_NUMBER _PINNUM(0, 30) #define TX_PIN_NUMBER _PINNUM(0, 14) #define CTS_PIN_NUMBER 0 #define RTS_PIN_NUMBER 0 @@ -72,4 +72,4 @@ #define UF2_BOARD_ID "nRF52840-CircuitPlayground-revD" #define UF2_INDEX_URL "https://www.adafruit.com/product/4300" -#endif // _FEATHER_NRF52840_H +#endif // _CPLAY_NRF52840_H From 09daa09a5eb350972e2d907532811d0442c7f733 Mon Sep 17 00:00:00 2001 From: Ladyada Date: Sun, 4 Aug 2019 17:53:16 -0400 Subject: [PATCH 3/5] initial bootloader def (is using neopix instead of dotstar) --- src/boards/itsybitsy_nrf52840_express/board.h | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/boards/itsybitsy_nrf52840_express/board.h diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h new file mode 100644 index 0000000..aeaa28c --- /dev/null +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -0,0 +1,75 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach 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 _ITSYBITSY_NRF52840_H +#define _ITSYBITSY_NRF52840_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(0, 6) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#define BUTTON_1 _PINNUM(1, 29) // user switch +#define BUTTON_2 _PINNUM(1, 02) // D2 breakout +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART + *------------------------------------------------------------------*/ +#define RX_PIN_NUMBER _PINNUM(1, 25) +#define TX_PIN_NUMBER _PINNUM(1, 24) +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 +#define HWFC false + +// Used as model string in OTA mode +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "ItsyBitsy nRF52840 Express" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0051 +#define USB_DESC_CDC_ONLY_PID 0x0052 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Adafruit ItsyBitsy nRF52840 Express" +#define UF2_VOLUME_LABEL "ITSY840BOOT" +#define UF2_BOARD_ID "nRF52840-ItsyBitsy-revA" +#define UF2_INDEX_URL "https://www.adafruit.com/" + +#endif // _ITSY_NRF52840_H From d78322519a8253381519fecfbcac41f422c58eb5 Mon Sep 17 00:00:00 2001 From: Ladyada Date: Sun, 4 Aug 2019 21:03:13 -0400 Subject: [PATCH 4/5] this time with correct pins --- src/boards/itsybitsy_nrf52840_express/board.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h index aeaa28c..af3a41b 100644 --- a/src/boards/itsybitsy_nrf52840_express/board.h +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -34,7 +34,7 @@ #define LED_PRIMARY_PIN _PINNUM(0, 6) #define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) +#define LED_NEOPIXEL _PINNUM(0, 8) #define NEOPIXELS_NUMBER 1 #define BOARD_RGB_BRIGHTNESS 0x040404 @@ -42,15 +42,15 @@ /* BUTTON *------------------------------------------------------------------*/ #define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 29) // user switch +#define BUTTON_1 _PINNUM(0, 29) // user switch #define BUTTON_2 _PINNUM(1, 02) // D2 breakout #define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* UART *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER _PINNUM(1, 25) -#define TX_PIN_NUMBER _PINNUM(1, 24) +#define RX_PIN_NUMBER _PINNUM(0, 25) +#define TX_PIN_NUMBER _PINNUM(0, 24) #define CTS_PIN_NUMBER 0 #define RTS_PIN_NUMBER 0 #define HWFC false From 04290e7beaaaba1c264ae9a53d1fbe4eb21a47c9 Mon Sep 17 00:00:00 2001 From: Henry Gabryjelski Date: Wed, 14 Aug 2019 12:32:36 -0700 Subject: [PATCH 5/5] Fix bug in __DOSTIME__ macro --- src/usb/uf2/compile_date.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/usb/uf2/compile_date.h b/src/usb/uf2/compile_date.h index 6be46a4..d16f4ad 100644 --- a/src/usb/uf2/compile_date.h +++ b/src/usb/uf2/compile_date.h @@ -43,10 +43,10 @@ SOFTWARE. : (__DATE__ [2u] == 'y' ) ? 5u /*May*/ \ : (__DATE__ [2u] == 'n' ) ? 6u /*Jun*/ \ : (__DATE__ [2u] == 'l' ) ? 7u /*Jul*/ \ -: (__DATE__ [2u] == 'g' ) ? 8u /*Jul*/ \ -: (__DATE__ [2u] == 'p' ) ? 9u /*Jul*/ \ -: (__DATE__ [2u] == 't' ) ? 10u /*Jul*/ \ -: (__DATE__ [2u] == 'v' ) ? 11u /*Jul*/ \ +: (__DATE__ [2u] == 'g' ) ? 8u /*Aug*/ \ +: (__DATE__ [2u] == 'p' ) ? 9u /*Sep*/ \ +: (__DATE__ [2u] == 't' ) ? 10u /*Oct*/ \ +: (__DATE__ [2u] == 'v' ) ? 11u /*Nov*/ \ : 12u /*Dec*/ ) #define __DAY_INT__ ( \ @@ -71,12 +71,12 @@ SOFTWARE. #define __DOSDATE__ ( \ ((__YEAR_INT__ - 1980u) << 9u) | \ ( __MONTH_INT__ << 5u) | \ - ( __DAY_INT__ << 0u) ) + ( __DAY_INT__ << 0u) ) #define __DOSTIME__ ( \ - ( __HOUR_INT__ << 11u) | \ - ( __MONTH_INT__ << 5u) | \ - ( __DAY_INT__ << 0u) ) + ( __HOUR_INT__ << 11u) | \ + ( __MINUTE_INT__ << 5u) | \ + ( __SECONDS_INT__ << 0u) ) #endif // COMPILE_DATE_H