Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit db33230

Browse files
Initial commit
0 parents  commit db33230

21 files changed

+2017
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.pio
2+
*.sublime-project
3+
*.sublime-workspace

LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License
2+
3+
Copyright 2021 Ian Glen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme.md

+310
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
# autotank-led-fw
2+
3+
A CANbus-enabled LED and GPIO controller -- firmware
4+
5+
6+
## CANbus Commands
7+
8+
The default Dev ID is `0xA3`
9+
10+
<table>
11+
<tr>
12+
<th>Command</th>
13+
<th colspan="2">Extended ID</th>
14+
<th></th>
15+
<th colspan="4">Send Payload</th>
16+
<th></th>
17+
<th colspan="2">Recv Payload</th>
18+
</tr>
19+
<tr>
20+
<th></th>
21+
<th>28:8</th>
22+
<th>7:0</th>
23+
<th></th>
24+
<th>Byte 0</th>
25+
<th>Byte 1</th>
26+
<th>Byte 2</th>
27+
<th>Byte 3</th>
28+
<th></th>
29+
<th>Byte 0</th>
30+
<th>Byte 1</th>
31+
</tr>
32+
<tr>
33+
<td>Read Pins</td>
34+
<td>0</td>
35+
<td>Dev ID</td>
36+
<td></td>
37+
<td>Dev ID</td>
38+
<td></td>
39+
<td></td>
40+
<td></td>
41+
<td></td>
42+
<td>In States</td>
43+
<td>Out States</td>
44+
</tr>
45+
<tr>
46+
<td>Write Pins</td>
47+
<td>1</td>
48+
<td>Dev ID</td>
49+
<td></td>
50+
<td>States</td>
51+
<td></td>
52+
<td></td>
53+
<td></td>
54+
<td></td>
55+
<td></td>
56+
<td></td>
57+
</tr>
58+
<tr>
59+
<td>Write Pin</td>
60+
<td>2</td>
61+
<td>Dev ID</td>
62+
<td></td>
63+
<td>Pin</td>
64+
<td>State</td>
65+
<td></td>
66+
<td></td>
67+
<td></td>
68+
<td></td>
69+
<td></td>
70+
</tr>
71+
<tr>
72+
<td>Truth Table</td>
73+
<td>3</td>
74+
<td>Dev ID</td>
75+
<td></td>
76+
<td>Pin</td>
77+
<td>Enable</td>
78+
<td colspan="2">Values</td>
79+
<td></td>
80+
<td></td>
81+
<td></td>
82+
</tr>
83+
<tr>
84+
<td>Pin Interrupt</td>
85+
<td>4</td>
86+
<td>Dev ID</td>
87+
<td></td>
88+
<td>Pin</td>
89+
<td>Mode</td>
90+
<td>Dev ID</td>
91+
<td></td>
92+
<td></td>
93+
<td>Pin</td>
94+
<td>State</td>
95+
</tr>
96+
<tr>
97+
<td>RGB Strip 1</td>
98+
<td>5</td>
99+
<td>Dev ID</td>
100+
<td></td>
101+
<td>Mode</td>
102+
<td>Red</td>
103+
<td>Green</td>
104+
<td>Blue</td>
105+
<td></td>
106+
<td></td>
107+
<td></td>
108+
</tr>
109+
<tr>
110+
<td>RGB Strip 2</td>
111+
<td>6</td>
112+
<td>Dev ID</td>
113+
<td></td>
114+
<td>Mode</td>
115+
<td>Red</td>
116+
<td>Green</td>
117+
<td>Blue</td>
118+
<td></td>
119+
<td></td>
120+
<td></td>
121+
</tr>
122+
</table>
123+
124+
125+
## GPIO
126+
127+
Pin states use the following payload byte format (MSB first):
128+
129+
<table>
130+
<tr>
131+
<th colspan="8">Byte n</th>
132+
</tr>
133+
<tr>
134+
<td colspan="4">7:4 <i>Reserved</i></td>
135+
<td>Pin 4</td>
136+
<td>Pin 3</td>
137+
<td>Pin 2</td>
138+
<td>Pin 1</td>
139+
</tr>
140+
</table>
141+
142+
143+
## Output Truth Table
144+
145+
As an alternative to writing output pins states, a logic truth table can be enabled to automatically set output pins based on input pin states. Writes are ignored when a truth table is enabled for a pin.
146+
147+
Each output pin has the following truth table:
148+
149+
<table>
150+
<tr>
151+
<th colspan="2" rowspan="2">Inputs</th>
152+
<th colspan="4">IN2 IN1</th>
153+
</tr>
154+
<tr>
155+
<th>00</th>
156+
<th>01</th>
157+
<th>10</th>
158+
<th>11</th>
159+
</tr>
160+
<tr>
161+
<th rowspan="4">IN4<br>IN3</th>
162+
<th>00</th>
163+
<td>X<sub>1</sub></td>
164+
<td>X<sub>2</sub></td>
165+
<td>X<sub>3</sub></td>
166+
<td>X<sub>4</sub></td>
167+
</tr>
168+
<tr>
169+
<th>01</th>
170+
<td>X<sub>5</sub></td>
171+
<td>X<sub>6</sub></td>
172+
<td>X<sub>7</sub></td>
173+
<td>X<sub>8</sub></td>
174+
</tr>
175+
<tr>
176+
<th>10</th>
177+
<td>X<sub>9</sub></td>
178+
<td>X<sub>10</sub></td>
179+
<td>X<sub>11</sub></td>
180+
<td>X<sub>12</sub></td>
181+
</tr>
182+
<tr>
183+
<th>11</th>
184+
<td>X<sub>13</sub></td>
185+
<td>X<sub>14</sub></td>
186+
<td>X<sub>15</sub></td>
187+
<td>X<sub>16</sub></td>
188+
</tr>
189+
</table>
190+
191+
Which is represented as the following payload byte format (MSB first):
192+
193+
<table>
194+
<tr>
195+
<th colspan="8">Byte 2</th>
196+
<th colspan="8">Byte 3</th>
197+
</tr>
198+
<tr>
199+
<td>X<sub>16</sub></td>
200+
<td>X<sub>15</sub></td>
201+
<td>X<sub>14</sub></td>
202+
<td>X<sub>13</sub></td>
203+
<td>X<sub>12</sub></td>
204+
<td>X<sub>11</sub></td>
205+
<td>X<sub>10</sub></td>
206+
<td>X<sub>9</sub></td>
207+
<td>X<sub>8</sub></td>
208+
<td>X<sub>7</sub></td>
209+
<td>X<sub>6</sub></td>
210+
<td>X<sub>5</sub></td>
211+
<td>X<sub>4</sub></td>
212+
<td>X<sub>3</sub></td>
213+
<td>X<sub>2</sub></td>
214+
<td>X<sub>1</sub></td>
215+
</tr>
216+
</table>
217+
218+
219+
## Pin Interrupts
220+
221+
CANbus messages can be sent in response to pin change events by enabling a pin interrupt. One interrupt can be configured for each pin. Messages will be sent to the device ID provided with the configuration command.
222+
223+
The following interrupt modes are available:
224+
225+
<table>
226+
<tr>
227+
<th>Mode</th>
228+
<th>Value</th>
229+
</tr>
230+
<tr>
231+
<td>Disabled</td>
232+
<td>0</td>
233+
</tr>
234+
<tr>
235+
<td>Rising Edge</td>
236+
<td>1</td>
237+
</tr>
238+
<tr>
239+
<td>Falling Edge</td>
240+
<td>2</td>
241+
</tr>
242+
<tr>
243+
<td>Any Change</td>
244+
<td>3</td>
245+
</tr>
246+
</table>
247+
248+
249+
## RGB Strip
250+
251+
Two addressable RGB strips can be controlled via CANbus messages. Only WS2812-compatible LEDs which use the GRB color format can be controlled.
252+
253+
The following pattern modes are available:
254+
255+
<table>
256+
<tr>
257+
<th>Mode</th>
258+
<th>Value</th>
259+
</tr>
260+
<tr>
261+
<td>Disabled</td>
262+
<td>0</td>
263+
</tr>
264+
<tr>
265+
<td>Solid Color</td>
266+
<td>1</td>
267+
</tr>
268+
<tr>
269+
<td>Rainbow</td>
270+
<td>2</td>
271+
</tr>
272+
</table>
273+
274+
275+
## Development
276+
277+
This project uses PlatformIO.
278+
279+
280+
### Compiling
281+
282+
For actual hardware:
283+
284+
```
285+
pio run
286+
```
287+
288+
For ST Nucleo-144 dev board:
289+
290+
```
291+
pio run -e nucleo
292+
293+
```
294+
295+
### Flashing
296+
297+
Connect an ST-LINK to the programming header, apply 5V power, and run:
298+
299+
For actual hardware:
300+
301+
```
302+
pio run --target upload
303+
```
304+
305+
For ST Nucleo-144 dev board:
306+
307+
```
308+
pio run -e nucleo --target upload
309+
310+
```

0 commit comments

Comments
 (0)