Skip to content

Commit 2c13fd5

Browse files
committed
support 10 neopixel of cplayground
1 parent 9532546 commit 2c13fd5

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ For other boards, please check the board definition for details.
7676

7777
### Making your own UF2
7878

79-
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.
79+
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
8080

8181
To create a UF2 image from a .bin file:
8282
```

src/boards.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
#define SCHED_QUEUE_SIZE 30 /**< Maximum number of events in the scheduler queue. */
3535

3636
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
37+
void neopixel_init(void);
3738
void neopixel_write(uint8_t *pixels);
39+
void neopixel_teardown(void);
3840
#endif
3941

4042
//------------- IMPLEMENTATION -------------//
@@ -67,9 +69,8 @@ void board_init(void)
6769
led_pwm_init(LED_SECONDARY, LED_SECONDARY_PIN);
6870
#endif
6971

70-
// use neopixel for use enumeration
72+
// use neopixel for use enumeration
7173
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
72-
extern void neopixel_init(void);
7374
neopixel_init();
7475
#endif
7576

@@ -93,7 +94,6 @@ void board_teardown(void)
9394
led_pwm_teardown();
9495

9596
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN)
96-
extern void neopixel_teardown(void);
9797
neopixel_teardown();
9898
#endif
9999
// Button
@@ -297,9 +297,9 @@ void led_state(uint32_t state)
297297
#define MAGIC_T1H 13UL | (0x8000) // 0.8125us
298298
#define CTOPVAL 20UL // 1.25us
299299

300-
#define NEO_NUMBYTE 3
300+
#define BYTE_PER_PIXEL 3
301301

302-
static uint16_t pixels_pattern[NEO_NUMBYTE * 8 + 2];
302+
static uint16_t pixels_pattern[NEOPIXELS_NUMBER*BYTE_PER_PIXEL * 8 + 2];
303303

304304
// use PWM1 for neopixel
305305
void neopixel_init(void)
@@ -347,29 +347,35 @@ void neopixel_init(void)
347347

348348
void neopixel_teardown(void)
349349
{
350-
uint8_t grb[3] = { 0, 0, 0 };
350+
uint8_t rgb[3] = { 0, 0, 0 };
351351

352352
NRFX_DELAY_US(50); // wait for previous write is complete
353353

354-
neopixel_write(grb);
354+
neopixel_write(rgb);
355355
NRFX_DELAY_US(50); // wait for this write
356356

357357
pwm_teardown(NRF_PWM1);
358358
}
359359

360-
// write 3 bytes color to a built-in neopixel
360+
// write 3 bytes color RGB to built-in neopixel
361361
void neopixel_write (uint8_t *pixels)
362362
{
363-
uint8_t grb[NEO_NUMBYTE] = {pixels[1], pixels[2], pixels[0]};
363+
// convert RGB to GRB
364+
uint8_t grb[BYTE_PER_PIXEL] = {pixels[1], pixels[2], pixels[0]};
364365
uint16_t pos = 0; // bit position
365-
for ( uint16_t n = 0; n < NEO_NUMBYTE; n++ )
366-
{
367-
uint8_t pix = grb[n];
368366

369-
for ( uint8_t mask = 0x80; mask > 0; mask >>= 1 )
367+
// Set all neopixel to same value
368+
for (uint16_t n = 0; n < NEOPIXELS_NUMBER; n++ )
369+
{
370+
for(uint8_t c = 0; c < BYTE_PER_PIXEL; c++)
370371
{
371-
pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H;
372-
pos++;
372+
uint8_t const pix = grb[c];
373+
374+
for ( uint8_t mask = 0x80; mask > 0; mask >>= 1 )
375+
{
376+
pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H;
377+
pos++;
378+
}
373379
}
374380
}
375381

@@ -409,8 +415,8 @@ void neopixel_init(void)
409415

410416
void neopixel_teardown(void)
411417
{
412-
uint8_t grb[3] = { 0, 0, 0 };
413-
neopixel_write(grb);
418+
uint8_t rgb[3] = { 0, 0, 0 };
419+
neopixel_write(rgb);
414420
nrf_gpio_cfg_default(LED_RGB_RED_PIN);
415421
nrf_gpio_cfg_default(LED_RGB_GREEN_PIN);
416422
nrf_gpio_cfg_default(LED_RGB_BLUE_PIN);

src/boards/circuitplayground_nrf52840/board.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
*------------------------------------------------------------------*/
3333
#define LEDS_NUMBER 1
3434
#define LED_PRIMARY_PIN _PINNUM(1, 14)
35+
#define LED_STATE_ON 1
36+
3537
#define LED_NEOPIXEL _PINNUM(0, 13)
3638
#define NEOPIXELS_NUMBER 10
3739
#define BOARD_RGB_BRIGHTNESS 0x040404
38-
#define LED_STATE_ON 1
3940

4041
/*------------------------------------------------------------------*/
4142
/* BUTTON
@@ -68,7 +69,7 @@
6869
//------------- UF2 -------------//
6970
#define UF2_PRODUCT_NAME "Adafruit Circuit Playground nRF52840"
7071
#define UF2_VOLUME_LABEL "CPLAYBTBOOT"
71-
#define UF2_BOARD_ID "CircuitPlayground-nRF52840-revD"
72+
#define UF2_BOARD_ID "nRF52840-CircuitPlayground-revD"
7273
#define UF2_INDEX_URL "https://www.adafruit.com/product/4300"
7374

7475
#endif // _FEATHER_NRF52840_H

src/boards/feather_nrf52840_express/board.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
#define LEDS_NUMBER 2
3434
#define LED_PRIMARY_PIN _PINNUM(1, 15)
3535
#define LED_SECONDARY_PIN _PINNUM(1, 10)
36-
#define LED_NEOPIXEL 16
37-
#define BOARD_RGB_BRIGHTNESS 0x040404
3836
#define LED_STATE_ON 1
3937

38+
#define LED_NEOPIXEL _PINNUM(0, 16)
39+
#define NEOPIXELS_NUMBER 1
40+
#define BOARD_RGB_BRIGHTNESS 0x040404
41+
4042
/*------------------------------------------------------------------*/
4143
/* BUTTON
4244
*------------------------------------------------------------------*/

src/boards/metro_nrf52840_express/board.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
#define LEDS_NUMBER 2
3434
#define LED_PRIMARY_PIN _PINNUM(1, 13)
3535
#define LED_SECONDARY_PIN _PINNUM(1, 15)
36+
#define LED_STATE_ON 1
37+
3638
#define LED_NEOPIXEL _PINNUM(0, 13)
39+
#define NEOPIXELS_NUMBER 1
3740
#define BOARD_RGB_BRIGHTNESS 0x040404
38-
#define LED_STATE_ON 1
3941

4042
/*------------------------------------------------------------------*/
4143
/* BUTTON

0 commit comments

Comments
 (0)