Skip to content

Commit

Permalink
Merge #19357
Browse files Browse the repository at this point in the history
19357: boards/adafruit-itsybitsy-m4: turn off APA102 LED on startup r=benpicco a=benpicco



Co-authored-by: Benjamin Valentin <benjamin.valentin@bht-berlin.de>
  • Loading branch information
bors[bot] and benpicco committed Mar 16, 2023
2 parents 19ab9c5 + ff7227d commit c4400e8
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 c4400e8

Please sign in to comment.