stm32f0: stm32f1: led: initial implementation
This commit is contained in:
parent
ce71976939
commit
a5dc77550d
5 changed files with 74 additions and 0 deletions
10
include/led.h
Normal file
10
include/led.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
struct led {
|
||||
uint32_t port;
|
||||
uint32_t pin;
|
||||
int invert;
|
||||
};
|
||||
|
||||
void led_enable(struct led *led);
|
||||
void led_disable(struct led *led);
|
|
@ -4,6 +4,7 @@ obj-y += source/platform/usart.o
|
|||
obj-y += source/platform/stm32f0/alarm.o
|
||||
obj-y += source/platform/stm32f0/buzzer.o
|
||||
obj-y += source/platform/stm32f0/gpio.o
|
||||
obj-y += source/platform/stm32f0/led.o
|
||||
obj-y += source/platform/stm32f0/rcc.o
|
||||
obj-y += source/platform/stm32f0/rtc.o
|
||||
obj-y += source/platform/stm32f0/spi.o
|
||||
|
|
31
source/platform/stm32f0/led.c
Normal file
31
source/platform/stm32f0/led.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
#include <led.h>
|
||||
#include <macros.h>
|
||||
|
||||
struct led leds[] = {
|
||||
{ GPIOC, GPIO8, 0 },
|
||||
};
|
||||
size_t nleds = count_of(leds);
|
||||
|
||||
void led_enable(struct led *led)
|
||||
{
|
||||
if (!led)
|
||||
return;
|
||||
|
||||
if (led->invert)
|
||||
gpio_clear(led->port, led->pin);
|
||||
else
|
||||
gpio_set(led->port, led->pin);
|
||||
}
|
||||
|
||||
void led_disable(struct led *led)
|
||||
{
|
||||
if (!led)
|
||||
return;
|
||||
|
||||
if (led->invert)
|
||||
gpio_set(led->port, led->pin);
|
||||
else
|
||||
gpio_clear(led->port, led->pin);
|
||||
}
|
|
@ -4,6 +4,7 @@ obj-y += source/platform/usart.o
|
|||
obj-y += source/platform/stm32f1/alarm.o
|
||||
obj-y += source/platform/stm32f1/buzzer.o
|
||||
obj-y += source/platform/stm32f1/gpio.o
|
||||
obj-y += source/platform/stm32f1/led.o
|
||||
obj-y += source/platform/stm32f1/rcc.o
|
||||
obj-y += source/platform/stm32f1/rtc.o
|
||||
obj-y += source/platform/stm32f1/spi.o
|
||||
|
|
31
source/platform/stm32f1/led.c
Normal file
31
source/platform/stm32f1/led.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
#include <led.h>
|
||||
#include <macros.h>
|
||||
|
||||
struct led leds[] = {
|
||||
{ GPIOB, GPIO0, 1 },
|
||||
};
|
||||
size_t nleds = count_of(leds);
|
||||
|
||||
void led_enable(struct led *led)
|
||||
{
|
||||
if (!led)
|
||||
return;
|
||||
|
||||
if (led->invert)
|
||||
gpio_clear(led->port, led->pin);
|
||||
else
|
||||
gpio_set(led->port, led->pin);
|
||||
}
|
||||
|
||||
void led_disable(struct led *led)
|
||||
{
|
||||
if (!led)
|
||||
return;
|
||||
|
||||
if (led->invert)
|
||||
gpio_set(led->port, led->pin);
|
||||
else
|
||||
gpio_clear(led->port, led->pin);
|
||||
}
|
Loading…
Add table
Reference in a new issue