From 2c13fd53f47ece3080a9ca50664cd5d38d1e471c Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Jun 2019 22:51:38 +0700 Subject: [PATCH] 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 *------------------------------------------------------------------*/