-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootloader.s
96 lines (89 loc) · 1.39 KB
/
bootloader.s
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
.section .text
.global setup
.global putch
.global getch
.global wait
.global boot
setup:
; PA4: LED Output, PA5 Universal input (inverted), PA7 COIL output
ldi r18, 0b10010000
out 0x00, r18
; invert PA5 logic
ldi r18, 0b10000000
sts 0x415, r18
; Just for security ensure PortB is 0 and it's not inverted, so we don't kill the Piezo
clr r18
out 0x05, r18
; PB0: Piezo Output, PB1: RS485send, PB2 RS485 TxD, PB3 RS485 RxD
ldi r18, 0b00000111
out 0x04, r18
; PC3: Touch input
; disable all unnecessary inputs
ldi r18, 0x4
ldi r27, 0x4
; PORTA
ldi r26, 0x10
st X+, r18
st X+, r18
st X+, r18
st X+, r18
st X+, r18
inc r26 ; PA5
st X+, r18
st X+, r18
; PORTB
ldi r26, 0x30
st X+, r18
st X+, r18
st X+, r18
inc r26 ; PB3
st X+, r18
st X+, r18
st X+, r18
st X+, r18
; PORTC
ldi r26, 0x50
st X+, r18
st X+, r18
st X+, r18
inc r26 ; PC3
st X+, r18
st X+, r18
st X+, r18
st X+, r18
; enable 115200 UART, yay
ldi r18, 0b11000000
sts 0x806, r18
ldi r18, 116
sts 0x808, r18
ret
getch:
cbi 0x5, 1 ; enable input
; boot directly on button press
sbic 0xA, 3
rjmp boot
; wait for data
lds r18, 0x804
bst r18, 7
brtc getch
; recv data
lds r24, 0x800
lds r25, 0x801
ret
putch:
sbi 0x5, 1 ; enable output
; wait for free data
lds r18, 0x804
bst r18, 5
brtc putch
; send data
sts 0x802, r24
ret
wait:
clr r18
waitloop:
inc r18
brne waitloop
ret
boot:
jmp 0x8400