-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (65 loc) · 1.47 KB
/
main.cpp
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
/*
* main.cpp
*
* Created on: Oct 11, 2020
* Author: imcha
*/
#include "flash.hpp"
#include "hardware.hpp"
#include "stm32l4xx_hal.h"
extern "C" void SystemClock_Config(void);
static void update(uint32_t time_ms) {
Key0.scan(time_ms);
Key1.scan(time_ms);
Key2.scan(time_ms);
KeyWKUP.scan(time_ms);
myBeep.run(time_ms);
}
Flash flash;
static void beep_on_key_pressed() {
constexpr uint32_t BEEP_TIME_MS = 100;
if (Key0.event_pressed() || Key1.event_pressed() || Key2.event_pressed() ||
KeyWKUP.event_pressed()) {
myBeep.on(BEEP_TIME_MS);
uart1.print((char*)"Hello CGeng\r\n");
}
}
uint64_t data[32];
int main(void) {
HAL_Init();
SystemClock_Config();
for (uint8_t i = 0; i < 32; i++) {
data[i] = i;
}
while (1) {
timer.exec();
uint32_t time_ms = HAL_GetTick();
update(time_ms);
uart1.Run();
beep_on_key_pressed();
if (Key0.pressed()) {
myRgb.Write(LedColor::BLUE);
} else if (Key1.pressed()) {
myRgb.Write(LedColor::RED);
} else if (Key2.pressed()) {
myRgb.Write(LedColor::GREEN);
} else if (KeyWKUP.pressed()) {
myRgb.Write(LedColor::WHITE);
} else {
myRgb.Write(LedColor::OFF);
}
if (Key0.event_pressed()) {
flash.Read(10);
}
if (Key1.event_pressed()) {
flash.Write(0, 1u << 32 | 2u);
}
if (Key2.event_pressed()) {
flash.WriteRow(0, (uint32_t)data);
}
if (KeyWKUP.event_pressed()) {
flash.Erase();
}
}
return 0;
}