Skip to content

Commit

Permalink
Merge pull request #316 from adafruit/fix-imxrt-neopixel
Browse files Browse the repository at this point in the history
update neopixel driver for imxrt
  • Loading branch information
hathach authored Apr 24, 2023
2 parents 077b64d + 65dea90 commit 9e83143
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ports/mimxrt10xx/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ static inline uint8_t apply_percentage(uint8_t brightness)

void board_rgb_write(uint8_t const rgb[])
{
enum {
PIN_MASK = (1u << NEOPIXEL_PIN)
};

// neopixel color order is GRB
uint8_t const pixels[3] = { apply_percentage(rgb[1]), apply_percentage(rgb[0]), apply_percentage(rgb[2]) };
uint32_t const numBytes = 3;
Expand All @@ -307,22 +311,26 @@ void board_rgb_write(uint8_t const rgb[])
uint32_t const t0 = sys_freq/MAGIC_800_T0H;
uint32_t const t1 = sys_freq/MAGIC_800_T1H;

volatile uint32_t* reg_set = &NEOPIXEL_PORT->DR_SET;
volatile uint32_t* reg_clr = &NEOPIXEL_PORT->DR_CLEAR;

__disable_irq();

// Enable DWT in debug core. Useable when interrupts disabled, as opposed to Systick->VAL
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
DWT->CYCCNT = 0;

for(;;) {
while(1) {
cyc = (pix & mask) ? t1 : t0;
while((DWT->CYCCNT - start) < interval);

start = DWT->CYCCNT;

GPIO_PinWrite(NEOPIXEL_PORT, NEOPIXEL_PIN, 1);
*reg_set = PIN_MASK;
while((DWT->CYCCNT - start) < cyc);

GPIO_PinWrite(NEOPIXEL_PORT, NEOPIXEL_PIN, 0);
while((DWT->CYCCNT - start) < interval);
*reg_clr = PIN_MASK;

if(!(mask >>= 1)) {
if(p >= end) break;
Expand Down

0 comments on commit 9e83143

Please sign in to comment.