58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
/*
|
|
* (c) danielinux 2019
|
|
* GPLv.2
|
|
*
|
|
* See LICENSE for details
|
|
*/
|
|
#include <stdint.h>
|
|
#include "system.h"
|
|
#include "led.h"
|
|
|
|
void led_setup(uint32_t led)
|
|
{
|
|
uint32_t reg;
|
|
if (led == BLUE_LED) {
|
|
AHB1_CLOCK_ER |= GPIOB_AHB1_CLOCK_ER;
|
|
reg = GPIOB_MODE & ~ (0x03 << (led * 2));
|
|
GPIOB_MODE = reg | (1 << (led * 2));
|
|
reg = GPIOB_PUPD & (0x03 << (led * 2));
|
|
GPIOB_PUPD = reg | (0x02 << (led * 2));
|
|
} else {
|
|
AHB1_CLOCK_ER |= GPIOA_AHB1_CLOCK_ER;
|
|
reg = GPIOA_MODE & ~ (0x03 << (led * 2));
|
|
GPIOA_MODE = reg | (1 << (led * 2));
|
|
reg = GPIOA_PUPD & (0x03 << (led * 2));
|
|
GPIOA_PUPD = reg | (0x02 << (led * 2));
|
|
}
|
|
led_off(led);
|
|
}
|
|
|
|
void pio_on(uint32_t pio)
|
|
{
|
|
if (pio == BLUE_LED)
|
|
GPIOB_BSRR |= (1 << pio);
|
|
else
|
|
GPIOA_BSRR |= (1 << pio);
|
|
}
|
|
|
|
void pio_off(uint32_t pio)
|
|
{
|
|
if (pio == BLUE_LED)
|
|
GPIOB_BSRR |= (1 << (pio + 16));
|
|
else
|
|
GPIOA_BSRR |= (1 << (pio + 16));
|
|
}
|
|
|
|
void pio_toggle(uint32_t pio)
|
|
{
|
|
uint32_t reg;
|
|
if (pio == BLUE_LED)
|
|
reg = GPIOB_ODR;
|
|
else
|
|
reg = GPIOA_ODR;
|
|
if ((reg & (1 << pio)) == (1 << pio))
|
|
pio_off(pio);
|
|
else
|
|
pio_on(pio);
|
|
}
|
|
|