94 lines
1.6 KiB
C
94 lines
1.6 KiB
C
/*
|
|
* (c) danielinux 2019
|
|
* GPLv.2
|
|
*
|
|
* See LICENSE for details
|
|
*/
|
|
#include <stdint.h>
|
|
#include "unicore-mx/stm32/gpio.h"
|
|
#include "unicore-mx/stm32/rcc.h"
|
|
#include "system.h"
|
|
#include "led.h"
|
|
#include "pinout.h"
|
|
|
|
|
|
/* LEDS mapping:
|
|
*
|
|
* E0 - Heartbeat
|
|
* E10 - 1
|
|
* B2 - 2
|
|
* E8 - 3
|
|
* E9 - 4
|
|
* E1 - 5
|
|
* E7 - 6
|
|
* B8 - 7
|
|
* B9 - 8
|
|
*/
|
|
|
|
#define NUM_LEDS 9
|
|
|
|
#define LD0 (1 << 0)
|
|
#define LD1 (1 << 10)
|
|
#define LD2 (1 << 2)
|
|
#define LD3 (1 << 8)
|
|
#define LD4 (1 << 9)
|
|
#define LD5 (1 << 1)
|
|
#define LD6 (1 << 7)
|
|
#define LD7 (1 << 8)
|
|
#define LD8 (1 << 9)
|
|
|
|
|
|
#define BANK_B_LD (LD2 | LD7 | LD8)
|
|
#define BANK_E_LD (LD0 | LD1 | LD3 | LD4 | LD5 | LD6)
|
|
|
|
|
|
struct pin Leds[9] = {
|
|
{ GPIOE, LD0 },
|
|
{ GPIOE, LD1 },
|
|
{ GPIOB, LD2 },
|
|
{ GPIOE, LD3 },
|
|
{ GPIOE, LD4 },
|
|
{ GPIOE, LD5 },
|
|
{ GPIOE, LD6 },
|
|
{ GPIOB, LD7 },
|
|
{ GPIOB, LD8 },
|
|
};
|
|
|
|
void led_setup(void)
|
|
{
|
|
rcc_periph_clock_enable(RCC_GPIOB);
|
|
rcc_periph_clock_enable(RCC_GPIOE);
|
|
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLDOWN, BANK_B_LD);
|
|
gpio_set(GPIOB, BANK_B_LD);
|
|
gpio_mode_setup(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLDOWN, BANK_E_LD);
|
|
gpio_set(GPIOE, BANK_E_LD);
|
|
}
|
|
|
|
void led_on(int led)
|
|
{
|
|
gpio_set(Leds[led].bank, Leds[led].pin);
|
|
}
|
|
|
|
void led_off(int led)
|
|
{
|
|
gpio_clear(Leds[led].bank, Leds[led].pin);
|
|
}
|
|
|
|
void led_toggle(int led)
|
|
{
|
|
if (gpio_get(Leds[led].bank, Leds[led].pin))
|
|
gpio_clear(Leds[led].bank, Leds[led].pin);
|
|
else
|
|
gpio_set(Leds[led].bank, Leds[led].pin);
|
|
}
|
|
|
|
void led_beat(int b)
|
|
{
|
|
if (b < 0 || b > 8)
|
|
return;
|
|
gpio_clear(GPIOB, BANK_B_LD);
|
|
gpio_clear(GPIOE, BANK_E_LD);
|
|
if (b != 0)
|
|
led_on(b);
|
|
}
|
|
|