41 lines
715 B
C
41 lines
715 B
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;
|
|
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)
|
|
{
|
|
GPIOA_BSRR |= (1 << pio);
|
|
}
|
|
|
|
void pio_off(uint32_t pio)
|
|
{
|
|
GPIOA_BSRR |= (1 << (pio + 16));
|
|
}
|
|
|
|
void pio_toggle(uint32_t pio)
|
|
{
|
|
uint32_t reg;
|
|
reg = GPIOA_ODR;
|
|
if ((reg & (1 << pio)) == (1 << pio))
|
|
pio_off(pio);
|
|
else
|
|
pio_on(pio);
|
|
}
|
|
|