-
Notifications
You must be signed in to change notification settings - Fork 1
/
cn_test.cpp
45 lines (41 loc) · 958 Bytes
/
cn_test.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
#include <cstdint>
#include "Pins.hpp"
#include "Osc.hpp"
#include "Irq.hpp"
struct Leds {
void update(){
for(auto& i : m_rgb) i.off();
m_rgb[m_state++].on();
if(m_state == 3) m_state = 0;
}
private:
uint8_t m_state{0};
Pins m_rgb[3]{
{Pins::D1, Pins::OUT},
{Pins::C3, Pins::OUT},
{Pins::C15, Pins::OUT}
};
};
Leds leds;
Pins sw3{ Pins::C4, Pins::INPU };
int main()
{
//set osc to 24MHz
Osc osc;
osc.pll_set(osc.MUL12, osc.DIV4);
//set sw3 to icn falling, and enable
sw3.icn_falling();
sw3.icn( true );
//set isr function, pin C4 (sw3)
Irq::isr_func( Irq::CHANGE_NOTICE_C,
[]{
sw3.icn_flagclr(); //<--need to clear this flag also
leds.update();
}
);
//enable cn irq, and global
Irq::init( Irq::CHANGE_NOTICE_C, 1, 0, true );
Irq::global( true );
//let irq do its work
for(;;){ Osc::idle(); }
}