global: make LED optional

This commit is contained in:
King Kévin 2019-12-21 14:13:28 +01:00
parent 0774eaa7b2
commit 914eda7589
1 changed files with 16 additions and 8 deletions

View File

@ -64,21 +64,24 @@ char* b2s(uint64_t binary, uint8_t rjust)
}
/** switch on board LED */
void led_on(void)
inline void led_on(void)
{
#if defined(LED_PIN)
#if defined(BUSVOODOO)
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin push-pull
#endif
#endif // BUSVOODOO
#if defined(LED_ON) && LED_ON
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN));
#else
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN));
#endif
#endif // LED_ON
#endif // LED_PIN
}
/** switch off board LED */
void led_off(void)
inline void led_off(void)
{
#if defined(LED_PIN)
#if defined(BUSVOODOO)
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(LED_PIN)); // set LED pin to floating to disable LEDs
#else
@ -86,17 +89,20 @@ void led_off(void)
gpio_clear(GPIO(LED_PORT), GPIO(LED_PIN));
#else
gpio_set(GPIO(LED_PORT), GPIO(LED_PIN));
#endif
#endif
#endif // BUSVOODOO
#endif // LED_ON
#endif // LED_PIN
}
/** toggle board LED */
void led_toggle(void)
inline void led_toggle(void)
{
#if defined(LED_PIN)
#if defined(BUSVOODOO)
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to push-pull
#endif
#endif // BUSVOODOO
gpio_toggle(GPIO(LED_PORT), GPIO(LED_PIN));
#endif // LED_PIN
}
void sleep_us(uint32_t duration)
@ -178,6 +184,7 @@ void user_input_store(char c)
void board_setup(void)
{
#if defined(LED_PIN)
// setup LED
rcc_periph_clock_enable(RCC_GPIO(LED_PORT)); // enable clock for LED
#if defined(BUSVOODOO)
@ -186,6 +193,7 @@ void board_setup(void)
gpio_set_mode(GPIO(LED_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(LED_PIN)); // set LED pin to output push-pull do drive LED
#endif
led_off(); // switch off LED per default
#endif // LED_PIN
// setup button
#if defined(BUTTON_PORT) && defined(BUTTON_PIN)