support 10 neopixel of cplayground

This commit is contained in:
hathach 2019-06-17 22:51:38 +07:00
parent 95325465cc
commit 2c13fd53f4
5 changed files with 35 additions and 24 deletions

View File

@ -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:
```

View File

@ -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);

View File

@ -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

View File

@ -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
*------------------------------------------------------------------*/

View File

@ -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
*------------------------------------------------------------------*/