Skip to content

Commit

Permalink
boards/adafruit-itsybitsy-m4: turn off APA102 LED on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Mar 16, 2023
1 parent 777857a commit ff7227d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions boards/adafruit-itsybitsy-m4/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,39 @@ static mtd_spi_nor_t samd51_nor_dev = {

mtd_dev_t *mtd0 = (mtd_dev_t *)&samd51_nor_dev;
#endif /* MODULE_MTD */

static inline void _toggle(unsigned n)
{
n *= 2;
while (--n) {
/* This might break if the GPIO driver gets more optimized, but
* with the current implementation the toggle is slow enough :) */
gpio_toggle(APA102_PARAM_CLK_PIN);
}
}

void board_init(void)
{
/* if the real driver is used, it will deal with the LED */
if (IS_USED(MODULE_APA102)) {
return;
}

/* bootloader leaves on an annoyingly bright LED - turn it off manually */
gpio_init(APA102_PARAM_DATA_PIN, GPIO_OUT);
gpio_init(APA102_PARAM_CLK_PIN, GPIO_OUT);

/* start frame - 32 zero bits */
gpio_clear(APA102_PARAM_DATA_PIN);
_toggle(32);

/* LED frame: 3 start bits (1), 5 alpha bits (0), 24 color bits (0) */
gpio_set(APA102_PARAM_DATA_PIN);
_toggle(3);
gpio_clear(APA102_PARAM_DATA_PIN);
_toggle(29); /* 5 alpha + 8 red + 8 green + 8 blue */

/* end frame - 32 one bits */
gpio_set(APA102_PARAM_DATA_PIN);
_toggle(32);
}

0 comments on commit ff7227d

Please sign in to comment.