-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
138 lines (120 loc) · 2.75 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stm32f4xx.h>
#include <assert.h>
#define ARRAY_SIZE(arr) (sizeof((arr))/(sizeof(arr[0])))
struct Letter
{
int post_letter_wait_time;
int per_line_wait_time;
char led_status[7][5];
};
#define LINE_WAIT 2
#define LETTER_WAIT LINE_WAIT * 2
static const struct Letter letters[] =
{
{
LETTER_WAIT,
LINE_WAIT,
{
{0,1,1,1,0},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{0,1,1,1,0},
}
},
{
LETTER_WAIT,
LINE_WAIT,
{
{1,0,0,0,1},
{1,1,0,1,1},
{1,0,1,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
}
},
{
6 * LETTER_WAIT,
LINE_WAIT,
{
{0,1,1,1,0},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{0,1,1,1,0},
}
}
};
struct Pin
{
uint32_t AHB1_clock_periph;
GPIO_TypeDef * port;
uint16_t pin;
};
static struct Pin pins[] =
{
{RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_13},
{RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_15},
{RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_11},
{RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_13},
{RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_15},
{RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_9},
{RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_11},
};
void SysTick_Handler()
{
static int wait_count = 0;
wait_count--;
if (wait_count > 0)
return;
static int current_letter = 0;
static int current_line = 0;
if (current_line >= ARRAY_SIZE(letters[current_letter].led_status[0]))
{
wait_count = letters[current_letter].post_letter_wait_time;
current_letter = (current_letter + 1) % ARRAY_SIZE(letters);
current_line = 0;
for (int i = 0; i < ARRAY_SIZE(letters[current_letter].led_status); i++)
GPIO_ResetBits(pins[i].port, pins[i].pin);
return;
}
static_assert(ARRAY_SIZE(pins) == ARRAY_SIZE(letters[current_letter].led_status), "Uncompatible letter definition with pins array");
for (int i = 0; i < ARRAY_SIZE(letters[current_letter].led_status); i++)
{
if (letters[current_letter].led_status[i][current_line])
GPIO_SetBits(pins[i].port, pins[i].pin);
else
GPIO_ResetBits(pins[i].port, pins[i].pin);
}
current_line = (current_line + 1) % (ARRAY_SIZE(letters[current_letter].led_status[0]) + 1);
wait_count = letters[current_letter].per_line_wait_time;
return;
}
int main(void)
{
SystemInit();
// Initiate GPIO pins
for (int i = 0; i < ARRAY_SIZE(pins); i++)
RCC_AHB1PeriphClockCmd(pins[i].AHB1_clock_periph, ENABLE);
// GPIOD init
GPIO_InitTypeDef gpio_init;
gpio_init.GPIO_Mode = GPIO_Mode_OUT;
gpio_init.GPIO_OType = GPIO_OType_PP;
gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpio_init.GPIO_Speed = GPIO_Speed_100MHz;
for (int i = 0; i < ARRAY_SIZE(pins); i++)
{
gpio_init.GPIO_Pin = pins[i].pin;
GPIO_Init(pins[i].port, &gpio_init);
}
// Initiate SysTick
SysTick_Config(SystemCoreClock / 1000);
while(1);
return 0;
}