-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.cpp
More file actions
54 lines (47 loc) · 1.2 KB
/
key.cpp
File metadata and controls
54 lines (47 loc) · 1.2 KB
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
#include <avr/io.h>
#include "lamos.h"
extern unsigned int shift;
char delay;
void usart0();
bool getDuty();
void key(char);
namespace
{
bool pa6(char) { return PORTA.IN & PIN6_bm; }
void __attribute__((optimize("O0"))) scan() {
PORTA.OUTSET = PIN3_bm | PIN2_bm | PIN1_bm;
PORTB.OUTSET = PIN1_bm | PIN0_bm;
if (!pa6(0)) key(0);
else if (!pa6(PORTA.OUTCLR = PIN3_bm)) key(3);
else if (!pa6(PORTA.OUTCLR = PIN2_bm)) key(2);
else if (!pa6(PORTA.OUTCLR = PIN1_bm)) key(1);
else if (!pa6(PORTB.OUTCLR = PIN1_bm)) key(5);
else if (!pa6(PORTB.OUTCLR = PIN0_bm)) key(4);
PORTA.OUTCLR = PIN3_bm | PIN2_bm | PIN1_bm;
PORTB.OUTCLR = PIN1_bm | PIN0_bm;
PORTA.INTFLAGS = PIN6_bm;
PORTA.PIN6CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc;
}
} //anonymous
Service tca0([](){
if (USART0.CTRLB) usart0();
else {
if (getDuty()) {
TCB0.CCMPH = 30;
PORTA.OUTSET = PIN7_bm;
} else {
TCB0.CCMPH = 0;
if (!shift) PORTA.OUTCLR = PIN7_bm;
}
if (delay) { if (!--delay) scan(); }
else {
if (shift) { PORTA.OUTSET = PIN7_bm; shift--; }
else {
if (!TCB0.CTRLA) {
TCA0.SINGLE.CTRLA = 0;
PORTA.OUTCLR = PIN7_bm;
}
}
}
}
});