From c06cd235114756cc6bb1f4975c0535fe971aa31c Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 11 Mar 2016 18:04:26 +0100 Subject: [PATCH] boards/pba-d-01-kw2x: unified LED defines --- boards/pba-d-01-kw2x/board.c | 33 ++++------------- boards/pba-d-01-kw2x/include/board.h | 55 +++++++++------------------- 2 files changed, 25 insertions(+), 63 deletions(-) diff --git a/boards/pba-d-01-kw2x/board.c b/boards/pba-d-01-kw2x/board.c index 31084fb597..a31e8d3c82 100644 --- a/boards/pba-d-01-kw2x/board.c +++ b/boards/pba-d-01-kw2x/board.c @@ -21,34 +21,15 @@ */ #include "board.h" - -static void leds_init(void); +#include "periph/gpio.h" void board_init(void) { - leds_init(); + /* initialize the on-board 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); + + /* initialize the CPU core */ cpu_init(); } - -/** - * @brief Initialize the boards on-board RGB-LED - * - */ -static void leds_init(void) -{ - /* enable clock */ - LED_B_PORT_CLKEN(); - LED_G_PORT_CLKEN(); - LED_R_PORT_CLKEN(); - /* configure pins as gpio */ - LED_B_PORT_BASE->PCR[LED_B_PIN] = PORT_PCR_MUX(1); - LED_G_PORT_BASE->PCR[LED_G_PIN] = PORT_PCR_MUX(1); - LED_R_PORT_BASE->PCR[LED_R_PIN] = PORT_PCR_MUX(1); - LED_B_GPIO_BASE->PDDR |= (1 << LED_B_PIN); - LED_G_GPIO_BASE->PDDR |= (1 << LED_G_PIN); - LED_R_GPIO_BASE->PDDR |= (1 << LED_R_PIN); - /* turn all LEDs off */ - LED_B_GPIO_BASE->PSOR |= (1 << LED_B_PIN); - LED_G_GPIO_BASE->PSOR |= (1 << LED_G_PIN); - LED_R_GPIO_BASE->PSOR |= (1 << LED_R_PIN); -} diff --git a/boards/pba-d-01-kw2x/include/board.h b/boards/pba-d-01-kw2x/include/board.h index 238232965b..7e08ea6531 100644 --- a/boards/pba-d-01-kw2x/include/board.h +++ b/boards/pba-d-01-kw2x/include/board.h @@ -31,47 +31,28 @@ extern "C" #endif /** - * @name LED pin definitions + * @brief LED pin definitions and handlers * @{ */ -#define LED_R_PORT_CLKEN() (SIM->SCGC5 |= (SIM_SCGC5_PORTD_MASK)) /**< Clock Enable for PORTD*/ -#define LED_G_PORT_CLKEN() (SIM->SCGC5 |= (SIM_SCGC5_PORTD_MASK)) /**< Clock Enable for PORTD*/ -#define LED_B_PORT_CLKEN() (SIM->SCGC5 |= (SIM_SCGC5_PORTA_MASK)) /**< Clock Enable for PORTA*/ -#define LED_R_PORT_BASE PORTD /**< PORT base for the Red LED */ -#define LED_G_PORT_BASE PORTD /**< PORT base for the Green LED */ -#define LED_B_PORT_BASE PORTA /**< PORT base for the Blue LED */ -#define LED_R_GPIO_BASE GPIOD /**< GPIO base for Red LED */ -#define LED_G_GPIO_BASE GPIOD /**< GPIO base for Green LED */ -#define LED_B_GPIO_BASE GPIOA /**< GPIO base for Blue LED */ -#define LED_R_PIN 6 /**< Red LED connected to PINx*/ -#define LED_G_PIN 4 /**< Green LED connected to PINx*/ -#define LED_B_PIN 4 /**< Blue LED connected to PINx*/ -#define LED_R_GPIO GPIO_PIN(PORT_D, LED_R_PIN) /**< GPIO-Device for Red LED */ -#define LED_G_GPIO GPIO_PIN(PORT_D, LED_G_PIN) /**< GPIO-Device for Green LED */ -#define LED_B_GPIO GPIO_PIN(PORT_A, LED_B_PIN) /**< GPIO-Device for Blue LED */ -/** @} */ +#define LED2_PIN GPIO_PIN(PORT_D, 6) +#define LED1_PIN GPIO_PIN(PORT_D, 4) +#define LED0_PIN GPIO_PIN(PORT_A, 4) -/** - * @name Macros for controlling the on-board LEDs. - * @{ - */ -#define LED_B_ON (LED_B_GPIO_BASE->PCOR = (1 << LED_B_PIN)) -#define LED_B_OFF (LED_B_GPIO_BASE->PSOR = (1 << LED_B_PIN)) -#define LED_B_TOGGLE (LED_B_GPIO_BASE->PTOR = (1 << LED_B_PIN)) -#define LED_G_ON (LED_G_GPIO_BASE->PCOR = (1 << LED_G_PIN)) -#define LED_G_OFF (LED_G_GPIO_BASE->PSOR = (1 << LED_G_PIN)) -#define LED_G_TOGGLE (LED_G_GPIO_BASE->PTOR = (1 << LED_G_PIN)) -#define LED_R_ON (LED_R_GPIO_BASE->PCOR = (1 << LED_R_PIN)) -#define LED_R_OFF (LED_R_GPIO_BASE->PSOR = (1 << LED_R_PIN)) -#define LED_R_TOGGLE (LED_R_GPIO_BASE->PTOR = (1 << LED_R_PIN)) +#define LED0_MASK (1 << 6) +#define LED1_MASK (1 << 4) +#define LED2_MASK (1 << 4) -/* for compatability to other boards */ -#define LED_GREEN_ON LED_G_ON -#define LED_GREEN_OFF LED_G_OFF -#define LED_GREEN_TOGGLE LED_G_TOGGLE -#define LED_RED_ON LED_R_ON -#define LED_RED_OFF LED_R_OFF -#define LED_RED_TOGGLE LED_R_TOGGLE +#define LED0_ON (GPIOD->PCOR = LED0_MASK) +#define LED0_OFF (GPIOD->PSOR = LED0_MASK) +#define LED0_TOGGLE (GPIOD->PTOR = LED0_MASK) + +#define LED1_ON (GPIOD->PCOR = LED1_MASK) +#define LED1_OFF (GPIOD->PSOR = LED1_MASK) +#define LED1_TOGGLE (GPIOD->PTOR = LED1_MASK) + +#define LED2_ON (GPIOA->PCOR = LED2_MASK) +#define LED2_OFF (GPIOA->PSOR = LED2_MASK) +#define LED2_TOGGLE (GPIOA->PTOR = LED2_MASK) /** @} */ /**