diff options
| author | Damien <damien.p.george@gmail.com> | 2013-10-18 23:44:05 +0100 |
|---|---|---|
| committer | Damien <damien.p.george@gmail.com> | 2013-10-18 23:44:05 +0100 |
| commit | 995b8aabb1ee786a4070d6d8392750ff878d53fa (patch) | |
| tree | 94a997dc8a4e6e89d048786fb6812a12bc99f4b8 /stm/led.c | |
| parent | 5ac1b2efbd5dfb2a62fe984dc9dc8a7127fb5e82 (diff) | |
Partially implement proper flash storage.
Diffstat (limited to 'stm/led.c')
| -rw-r--r-- | stm/led.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/stm/led.c b/stm/led.c new file mode 100644 index 000000000..a6255540f --- /dev/null +++ b/stm/led.c @@ -0,0 +1,47 @@ +#include <stm32f4xx.h> +#include <stm32f4xx_gpio.h> +#include "led.h" + +#define PYB_LED_R_PORT (GPIOA) +#define PYB_LED_R1_PIN (GPIO_Pin_8) +#define PYB_LED_R2_PIN (GPIO_Pin_10) +#define PYB_LED_G_PORT (GPIOC) +#define PYB_LED_G1_PIN (GPIO_Pin_4) +#define PYB_LED_G2_PIN (GPIO_Pin_5) + +void led_init() { + // set the output high (so LED is off) + PYB_LED_R_PORT->BSRRL = PYB_LED_R1_PIN; + PYB_LED_R_PORT->BSRRL = PYB_LED_R2_PIN; + PYB_LED_G_PORT->BSRRL = PYB_LED_G1_PIN; + PYB_LED_G_PORT->BSRRL = PYB_LED_G2_PIN; + // make them open drain outputs + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = PYB_LED_R1_PIN | PYB_LED_R2_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(PYB_LED_R_PORT, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = PYB_LED_G1_PIN | PYB_LED_G2_PIN; + GPIO_Init(PYB_LED_G_PORT, &GPIO_InitStructure); +} + +void led_state(pyb_led_t led, int state) { + GPIO_TypeDef *port; + uint32_t pin; + switch (led) { + case PYB_LED_R1: port = PYB_LED_R_PORT; pin = PYB_LED_R1_PIN; break; + case PYB_LED_R2: port = PYB_LED_R_PORT; pin = PYB_LED_R2_PIN; break; + case PYB_LED_G1: port = PYB_LED_G_PORT; pin = PYB_LED_G1_PIN; break; + case PYB_LED_G2: port = PYB_LED_G_PORT; pin = PYB_LED_G2_PIN; break; + default: return; + } + if (state == 0) { + // LED off, output is high + port->BSRRL = pin; + } else { + // LED on, output is low + port->BSRRH = pin; + } +} |
