Skip to content

Commit

Permalink
boards/stm32f3discovery: unified LED defines
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Mar 15, 2016
1 parent 7b1208a commit d0d8ea3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 83 deletions.
47 changes: 9 additions & 38 deletions boards/stm32f3discovery/board.c
Expand Up @@ -19,49 +19,20 @@
*/

#include "board.h"

static void leds_init(void);
#include "periph/gpio.h"

void board_init(void)
{
/* initialize the boards LEDs */
leds_init();
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_init(LED4_PIN, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_init(LED5_PIN, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_init(LED6_PIN, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_init(LED7_PIN, GPIO_DIR_OUT, GPIO_NOPULL);

/* initialize the CPU */
cpu_init();
}

/**
* @brief Initialize the boards on-board LEDs (LD3 to LD10)
*
* 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: PE9
* - LD4: PE8
* - LD5: PE10
* - LD6: PE15
* - LD7: PE11
* - LD8: PE14
* - LD9: PE12
* - LD10: PE13
*/
static void leds_init(void)
{
/* enable clock for port GPIOE */
RCC->AHBENR |= RCC_AHBENR_GPIOEEN;

/* set output speed to 50MHz */
LED_PORT->OSPEEDR |= 0xffff0000;
/* set output type to push-pull */
LED_PORT->OTYPER &= ~(0x0000ff00);
/* configure pins as general outputs */
LED_PORT->MODER &= ~(0xffff0000);
LED_PORT->MODER |= 0x55550000;
/* disable pull resistors */
LED_PORT->PUPDR &= ~(0xffff0000);

/* turn all LEDs off */
LED_PORT->BRR = 0xff00;
}
94 changes: 49 additions & 45 deletions boards/stm32f3discovery/include/board.h
Expand Up @@ -28,55 +28,59 @@ extern "C" {
#endif

/**
* @name LED pin definitions
* @name Macros for controlling the on-board LEDs.
* @{
*/
#define LED0_PIN GPIO_PIN(PORT_E, 9)
#define LED1_PIN GPIO_PIN(PORT_E, 8)
#define LED2_PIN GPIO_PIN(PORT_E, 10)
#define LED3_PIN GPIO_PIN(PORT_E, 15)
#define LED4_PIN GPIO_PIN(PORT_E, 11)
#define LED5_PIN GPIO_PIN(PORT_E, 14)
#define LED6_PIN GPIO_PIN(PORT_E, 12)
#define LED7_PIN GPIO_PIN(PORT_E, 13)

#define LED_PORT GPIOE
#define LD3_PIN (1 << 9)
#define LD4_PIN (1 << 8)
#define LD5_PIN (1 << 10)
#define LD6_PIN (1 << 15)
#define LD7_PIN (1 << 11)
#define LD8_PIN (1 << 14)
#define LD9_PIN (1 << 12)
#define LD10_PIN (1 << 13)
/** @} */
#define LED0_MASK (1 << 9)
#define LED1_MASK (1 << 8)
#define LED2_MASK (1 << 10)
#define LED3_MASK (1 << 15)
#define LED4_MASK (1 << 11)
#define LED5_MASK (1 << 14)
#define LED6_MASK (1 << 12)
#define LED7_MASK (1 << 13)

/**
* @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 LD7_ON (LED_PORT->BSRRL = LD7_PIN)
#define LD7_OFF (LED_PORT->BSRRH = LD7_PIN)
#define LD7_TOGGLE (LED_PORT->ODR ^= LD7_PIN)
#define LD8_ON (LED_PORT->BSRRL = LD8_PIN)
#define LD8_OFF (LED_PORT->BSRRH = LD8_PIN)
#define LD8_TOGGLE (LED_PORT->ODR ^= LD8_PIN)
#define LD9_ON (LED_PORT->BSRRL = LD9_PIN)
#define LD9_OFF (LED_PORT->BSRRH = LD9_PIN)
#define LD9_TOGGLE (LED_PORT->ODR ^= LD9_PIN)
#define LD10_ON (LED_PORT->BSRRL = LD10_PIN)
#define LD10_OFF (LED_PORT->BSRRH = LD10_PIN)
#define LD10_TOGGLE (LED_PORT->ODR ^= LD10_PIN)
/* 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 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)

#define LED4_ON (LED_PORT->BSRRL = LED4_MASK)
#define LED4_OFF (LED_PORT->BSRRH = LED4_MASK)
#define LED4_TOGGLE (LED_PORT->ODR ^= LED4_MASK)

#define LED5_ON (LED_PORT->BSRRL = LED5_MASK)
#define LED5_OFF (LED_PORT->BSRRH = LED5_MASK)
#define LED5_TOGGLE (LED_PORT->ODR ^= LED5_MASK)

#define LED6_ON (LED_PORT->BSRRL = LED6_MASK)
#define LED6_OFF (LED_PORT->BSRRH = LED6_MASK)
#define LED6_TOGGLE (LED_PORT->ODR ^= LED6_MASK)

#define LED7_ON (LED_PORT->BSRRL = LED7_MASK)
#define LED7_OFF (LED_PORT->BSRRH = LED7_MASK)
#define LED7_TOGGLE (LED_PORT->ODR ^= LED7_MASK)
/** @} */

/**
Expand Down

0 comments on commit d0d8ea3

Please sign in to comment.