forked from 10110111/usb2ps2conv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled.c
59 lines (51 loc) · 1.05 KB
/
led.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "stm32f4xx_hal_conf.h"
#include "led.h"
#ifdef ENABLE_LED
# define LED_GPIO_PORT GPIOD
# define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
static const uint16_t ledPins[] =
{
GPIO_PIN_12,
GPIO_PIN_13,
GPIO_PIN_14,
GPIO_PIN_15,
};
#endif
void ledOn(const LED_ID led)
{
#ifdef ENABLE_LED
LED_GPIO_PORT->BSRR = ledPins[led];
#endif
}
void ledOff(const LED_ID led)
{
#ifdef ENABLE_LED
LED_GPIO_PORT->BSRR = (uint32_t)ledPins[led] << 16;
#endif
}
void ledsOn(void)
{
#ifdef ENABLE_LED
LED_GPIO_PORT->BSRR = ledPins[0]|ledPins[1]|ledPins[2]|ledPins[3];
#endif
}
void ledsOff(void)
{
#ifdef ENABLE_LED
LED_GPIO_PORT->BSRR = (uint32_t)(ledPins[0]|ledPins[1]|ledPins[2]|ledPins[3]) << 16;
#endif
}
void ledInit(void)
{
#ifdef ENABLE_LED
LED_GPIO_CLK_ENABLE();
GPIO_InitTypeDef init =
{
.Pin = ledPins[0]|ledPins[1]|ledPins[2]|ledPins[3],
.Mode = GPIO_MODE_OUTPUT_PP,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_LOW,
};
HAL_GPIO_Init(LED_GPIO_PORT, &init);
#endif
}