-
Notifications
You must be signed in to change notification settings - Fork 1
/
leds.c
44 lines (32 loc) · 989 Bytes
/
leds.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
/* STM32F4-CANBUS leds.c
* http://www.eraycanli.com */
#include "commons.h"
#include "leds.h"
void InitializeLEDS()
{
__GPIOD_CLK_ENABLE(); /* Enable GPIOD clock for leds */
GPIO_InitTypeDef GPIO_Leds;
GPIO_Leds.Mode = GPIO_MODE_OUTPUT_PP; /* Output push-pull mode */
GPIO_Leds.Pull = GPIO_NOPULL; /* No resistor */
GPIO_Leds.Speed = GPIO_SPEED_HIGH;
GPIO_Leds.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; /* PD12(Green) PD13(Orange) PD14(Red) PD15(Blue) */
HAL_GPIO_Init(GPIOD, &GPIO_Leds); /* Init GPIOD registers */
return;
}
void LedState(uint16_t led, uint8_t state)
{
switch(state)
{
case 1: /* ON */
HAL_GPIO_WritePin(GPIOD, led, GPIO_PIN_SET);
break;
case 0: /* OFF */
HAL_GPIO_WritePin(GPIOD, led, GPIO_PIN_RESET);
break;
case 2: /* Toggle */
HAL_GPIO_TogglePin(GPIOD, led);
break;
}
return;
}
/* leds.c */