1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-28 16:01:18 +01:00

boards/stm32f4discovery: unified LED defines

This commit is contained in:
Hauke Petersen 2016-03-11 18:04:27 +01:00
parent d0d8ea33ab
commit cc29909e21
2 changed files with 31 additions and 59 deletions

View File

@ -19,45 +19,16 @@
*/
#include "board.h"
static void leds_init(void);
#include "periph/gpio.h"
void board_init(void)
{
/* initialize the boards LEDs, this is done first for debugging purposes */
leds_init();
/* 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);
/* initialize the CPU */
cpu_init();
}
/**
* @brief Initialize the boards on-board LEDs (LD3 and LD4)
*
* The LED initialization is hard-coded in this function. As the LEDs are soldered
* onto the board they are fixed to their CPU pins.
*
* The LEDs are connected to the following pins:
* - LD3: PD13
* - LD4: PD12
* - LD5: PD14
* - LD6: PD15
*/
static void leds_init(void)
{
/* enable clock for port GPIOD */
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
/* configure pins as general outputs */
LED_PORT->MODER &= ~(0xff000000);
LED_PORT->MODER |= 0x55000000;
/* set output speed high-speed */
LED_PORT->OSPEEDR |= 0xff000000;
/* set output type to push-pull */
LED_PORT->OTYPER &= ~(0xf000);
/* disable pull resistors */
LED_PORT->PUPDR &= ~(0xff000000);
/* turn all LEDs off */
LED_PORT->BSRRH = 0xf000;
}

View File

@ -42,37 +42,38 @@ extern "C" {
* @name LED pin definitions
* @{
*/
#define LED_PORT GPIOD
#define LD3_PIN (1 << 13)
#define LD4_PIN (1 << 12)
#define LD5_PIN (1 << 14)
#define LD6_PIN (1 << 15)
/** @} */
/**
* @name Macros for controlling the on-board LEDs.
* @{
*/
#define LD3_ON (LED_PORT->BSRRL = LD3_PIN)
#define LD3_OFF (LED_PORT->BSRRH = LD3_PIN)
#define LD3_TOGGLE (LED_PORT->ODR ^= LD3_PIN)
#define LD4_ON (LED_PORT->BSRRL = LD4_PIN)
#define LD4_OFF (LED_PORT->BSRRH = LD4_PIN)
#define LD4_TOGGLE (LED_PORT->ODR ^= LD4_PIN)
#define LD5_ON (LED_PORT->BSRRL = LD5_PIN)
#define LD5_OFF (LED_PORT->BSRRH = LD5_PIN)
#define LD5_TOGGLE (LED_PORT->ODR ^= LD5_PIN)
#define LD6_ON (LED_PORT->BSRRL = LD6_PIN)
#define LD6_OFF (LED_PORT->BSRRH = LD6_PIN)
#define LD6_TOGGLE (LED_PORT->ODR ^= LD6_PIN)
#define LED0_PIN GPIO_PIN(PORT_D, 13)
#define LED1_PIN GPIO_PIN(PORT_D, 12)
#define LED2_PIN GPIO_PIN(PORT_D, 14)
#define LED3_PIN GPIO_PIN(PORT_D, 15)
/* for compatability to other boards */
#define LED_GREEN_ON LD4_ON
#define LED_GREEN_OFF LD4_OFF
#define LED_GREEN_TOGGLE LD4_TOGGLE
#define LED_RED_ON LD5_ON
#define LED_RED_OFF LD5_OFF
#define LED_RED_TOGGLE LD5_TOGGLE
#define LED_PORT GPIOD
#define LED0_MASK (1 << 13)
#define LED1_MASK (1 << 12)
#define LED2_MASK (1 << 14)
#define LED3_MASK (1 << 15)
#define LED0_ON (LED_PORT->BSRRL = LED0_MASK)
#define LED0_OFF (LED_PORT->BSRRH = LED0_MASK)
#define LED0_TOGGLE (LED_PORT->ODR ^= LED0_MASK)
#define LED1_ON (LED_PORT->BSRRL = LED1_MASK)
#define LED1_OFF (LED_PORT->BSRRH = LED1_MASK)
#define LED1_TOGGLE (LED_PORT->ODR ^= LED1_MASK)
#define LED2_ON (LED_PORT->BSRRL = LED2_MASK)
#define LED2_OFF (LED_PORT->BSRRH = LED2_MASK)
#define LED2_TOGGLE (LED_PORT->ODR ^= LED2_MASK)
#define LED3_ON (LED_PORT->BSRRL = LED3_MASK)
#define LED3_OFF (LED_PORT->BSRRH = LED3_MASK)
#define LED3_TOGGLE (LED_PORT->ODR ^= LED3_MASK)
/** @} */
/**