Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards/adafruit-itsybitsy-m4: turn off APA102 LED on startup #19357

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}