From 047050d032f0ca1b5343bf6547e48b91224a1ac0 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 11 Mar 2016 18:04:26 +0100 Subject: [PATCH] boards/spark-core: unified LED defines --- boards/spark-core/board.c | 43 +++++++-------------------- boards/spark-core/include/board.h | 49 ++++++++++++++++--------------- 2 files changed, 37 insertions(+), 55 deletions(-) diff --git a/boards/spark-core/board.c b/boards/spark-core/board.c index 3ab63f2da7..b783065d43 100644 --- a/boards/spark-core/board.c +++ b/boards/spark-core/board.c @@ -20,16 +20,22 @@ */ #include "board.h" -#include "cpu.h" - -static void leds_init(void); +#include "periph/gpio.h" void board_init(void) { + /* initialize the boards LEDs */ + gpio_init(LED0_PIN, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(LED1_PIN, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(LED2_PIN, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init(LED3_PIN, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_set(LED0_PIN); + gpio_set(LED1_PIN); + gpio_set(LED2_PIN); + gpio_set(LED3_PIN); + /* initialize the CPU */ cpu_init(); - /* initialize the boards LEDs */ - leds_init(); /* disable systick interrupt, set by the spark bootloader */ SysTick->CTRL = 0; /* signal to spark bootloader: do not enable IWDG! set Stop Mode Flag! */ @@ -37,30 +43,3 @@ void board_init(void) /* configure the RIOT vector table location to internal flash + spark bootloader offset */ SCB->VTOR = LOCATION_VTABLE; } - -/** - * @brief Initialize the boards on-board LEDs - * - * The LEDs initialization is hard-coded in this function. As the LED is soldered - * onto the board it is fixed to its CPU pins. - * - */ -static void leds_init(void) -{ - /* enable clock for port A */ - RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; - - /* reset pins */ - LED_PORT->CR[1] &= ~(0xf << (4*(LED_RED_PIN - 8)) | - 0xf << (4*(LED_GREEN_PIN - 8)) | - 0xf << (4*(LED_BLUE_PIN - 8)) | - 0xf << (4*(LED_WHITE_PIN - 8))); - - /* set pins to out */ - LED_PORT->CR[1] |= (0x3 << (4*(LED_RED_PIN - 8)) | - 0x3 << (4*(LED_GREEN_PIN - 8)) | - 0x3 << (4*(LED_BLUE_PIN - 8)) | - 0x3 << (4*(LED_WHITE_PIN - 8))); - - LED_PORT->BSRR = (1 << LED_RED_PIN) | (1 << LED_GREEN_PIN) | (1 << LED_BLUE_PIN) | (1 << LED_WHITE_PIN); -} diff --git a/boards/spark-core/include/board.h b/boards/spark-core/include/board.h index e42641b8bb..3e0895eecd 100644 --- a/boards/spark-core/include/board.h +++ b/boards/spark-core/include/board.h @@ -41,32 +41,35 @@ #define XTIMER_MASK (0xffff0000) /** - * @name LED pin definitions + * @brief Macros for controlling the on-board LEDs * @{ */ -#define LED_PORT (GPIOA) -#define LED_RED_PIN (9) -#define LED_GREEN_PIN (10) -#define LED_BLUE_PIN (8) -#define LED_WHITE_PIN (13) -/** @} */ +#define LED0_PIN GPIO_PIN(PORT_A, 9) +#define LED1_PIN GPIO_PIN(PORT_A, 10) +#define LED2_PIN GPIO_PIN(PORT_A, 8) +#define LED3_PIN GPIO_PIN(PORT_A, 13) -/** - * @name Macros for controlling the on-board LEDs. - * @{ - */ -#define LED_RED_ON (LED_PORT->BRR = (1<BSRR = (1<ODR ^= (1<BRR = (1<BSRR = (1<ODR ^= (1<BRR = (1<BSRR = (1<ODR ^= (1<BRR = (1<BSRR = (1<ODR ^= (1<BRR = LED0_MASK) +#define LED0_OFF (LED_PORT->BSRR = LED0_MASK) +#define LED0_TOGGLE (LED_PORT->ODR ^= LED0_MASK) + +#define LED1_ON (LED_PORT->BRR = LED1_MASK) +#define LED1_OFF (LED_PORT->BSRR = LED1_MASK) +#define LED1_TOGGLE (LED_PORT->ODR ^= LED1_MASK) + +#define LED2_ON (LED_PORT->BRR = LED2_MASK) +#define LED2_OFF (LED_PORT->BSRR = LED2_MASK) +#define LED2_TOGGLE (LED_PORT->ODR ^= LED2_MASK) + +#define LED3_ON (LED_PORT->BRR = LED3_MASK) +#define LED3_OFF (LED_PORT->BSRR = LED3_MASK) +#define LED3_TOGGLE (LED_PORT->ODR ^= LED3_MASK) /** @} */ /**