-
Notifications
You must be signed in to change notification settings - Fork 8
/
leds_low.s
210 lines (193 loc) · 4.47 KB
/
leds_low.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
;
; Thymio-II Firmware
;
; Copyright (C) 2012 Philippe Retornaz <philippe dot retornaz at epfl dot ch>,
; Mobots group (http://mobots.epfl.ch), Robotics system laboratory (http://lsro.epfl.ch)
; EPFL Ecole polytechnique federale de Lausanne (http://www.epfl.ch)
;
; See authors.txt for more details about other contributors.
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU Lesser General Public License as published
; by the Free Software Foundation, version 3 of the License.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
; All the write access to the leds array MUST be atomic
; otherwise some data corruption might happens.
; near pointer, allocated & initialized in leds.c
.global _leds_index
.section .text
.global __leds_set
.global __leds_clr
.global _leds_tick_cb
; void leds_tick_cb(void)
_leds_tick_cb:
bclr LATC,#13 ; LED_CS = 0;
mov _led_index,w0 ; w0 = led_index
mov #SPI1BUF, w1 ; w1 = &SPI1BUF
mov.b [w0++],[w1] ; SPI1BUF = *led_index++
mov.b [w0++],[w1] ; ''
mov.b [w0++],[w1] ; ''
mov.b [w0++],[w1] ; ''
mov.b [w0++],[w1] ; ''
mov #(_led + 32 * 5),w1 ; w1 = &led[MAX_BRIGHTNESS * LED_BANK]
cpsne w1,w0 ; if(index == MAX_BRIGHTNESS * LED_BANK)
mov #_led,w0 ; w0 = &led[0]
mov w0, _led_index ; led_index = w0
; The leds will be latched later in the interrupt
return
; w0: pointer to leds array
; w1: count (0-32)
; w2: mask
__leds_set:
; 2 instructions to set one
subr w1,#31,w1
inc w1,w1
sl w1,#1,w1
bra w1
ior.b w2,[w0],[w0] ;1
add w0,#5,w0
ior.b w2,[w0],[w0] ;2
add w0,#5,w0
ior.b w2,[w0],[w0] ;3
add w0,#5,w0
ior.b w2,[w0],[w0] ;4
add w0,#5,w0
ior.b w2,[w0],[w0] ;5
add w0,#5,w0
ior.b w2,[w0],[w0] ;6
add w0,#5,w0
ior.b w2,[w0],[w0] ;7
add w0,#5,w0
ior.b w2,[w0],[w0] ;8
add w0,#5,w0
ior.b w2,[w0],[w0] ;9
add w0,#5,w0
ior.b w2,[w0],[w0] ;10
add w0,#5,w0
ior.b w2,[w0],[w0] ;11
add w0,#5,w0
ior.b w2,[w0],[w0] ;12
add w0,#5,w0
ior.b w2,[w0],[w0] ;13
add w0,#5,w0
ior.b w2,[w0],[w0] ;14
add w0,#5,w0
ior.b w2,[w0],[w0] ;15
add w0,#5,w0
ior.b w2,[w0],[w0] ;16
add w0,#5,w0
ior.b w2,[w0],[w0] ;17
add w0,#5,w0
ior.b w2,[w0],[w0] ;18
add w0,#5,w0
ior.b w2,[w0],[w0] ;19
add w0,#5,w0
ior.b w2,[w0],[w0] ;20
add w0,#5,w0
ior.b w2,[w0],[w0] ;21
add w0,#5,w0
ior.b w2,[w0],[w0] ;22
add w0,#5,w0
ior.b w2,[w0],[w0] ;23
add w0,#5,w0
ior.b w2,[w0],[w0] ;24
add w0,#5,w0
ior.b w2,[w0],[w0] ;25
add w0,#5,w0
ior.b w2,[w0],[w0] ;26
add w0,#5,w0
ior.b w2,[w0],[w0] ;27
add w0,#5,w0
ior.b w2,[w0],[w0] ;28
add w0,#5,w0
ior.b w2,[w0],[w0] ;29
add w0,#5,w0
ior.b w2,[w0],[w0] ;30
add w0,#5,w0
ior.b w2,[w0],[w0] ;31
add w0,#5,w0
ior.b w2,[w0],[w0] ;32
add w0,#5,w0
return;
; w0: pointer to leds array
; w1: count (0-32)
; w2: mask
__leds_clr:
; 2 instructions to set one
subr w1,#31,w1
inc w1,w1
sl w1,#1,w1
bra w1
and.b w2,[w0],[w0] ;1
add w0,#5,w0
and.b w2,[w0],[w0] ;2
add w0,#5,w0
and.b w2,[w0],[w0] ;3
add w0,#5,w0
and.b w2,[w0],[w0] ;4
add w0,#5,w0
and.b w2,[w0],[w0] ;5
add w0,#5,w0
and.b w2,[w0],[w0] ;6
add w0,#5,w0
and.b w2,[w0],[w0] ;7
add w0,#5,w0
and.b w2,[w0],[w0] ;8
add w0,#5,w0
and.b w2,[w0],[w0] ;9
add w0,#5,w0
and.b w2,[w0],[w0] ;10
add w0,#5,w0
and.b w2,[w0],[w0] ;11
add w0,#5,w0
and.b w2,[w0],[w0] ;12
add w0,#5,w0
and.b w2,[w0],[w0] ;13
add w0,#5,w0
and.b w2,[w0],[w0] ;14
add w0,#5,w0
and.b w2,[w0],[w0] ;15
add w0,#5,w0
and.b w2,[w0],[w0] ;16
add w0,#5,w0
and.b w2,[w0],[w0] ;17
add w0,#5,w0
and.b w2,[w0],[w0] ;18
add w0,#5,w0
and.b w2,[w0],[w0] ;19
add w0,#5,w0
and.b w2,[w0],[w0] ;20
add w0,#5,w0
and.b w2,[w0],[w0] ;21
add w0,#5,w0
and.b w2,[w0],[w0] ;22
add w0,#5,w0
and.b w2,[w0],[w0] ;23
add w0,#5,w0
and.b w2,[w0],[w0] ;24
add w0,#5,w0
and.b w2,[w0],[w0] ;25
add w0,#5,w0
and.b w2,[w0],[w0] ;26
add w0,#5,w0
and.b w2,[w0],[w0] ;27
add w0,#5,w0
and.b w2,[w0],[w0] ;28
add w0,#5,w0
and.b w2,[w0],[w0] ;29
add w0,#5,w0
and.b w2,[w0],[w0] ;30
add w0,#5,w0
and.b w2,[w0],[w0] ;31
add w0,#5,w0
and.b w2,[w0],[w0] ;32
add w0,#5,w0
return;