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

A CANbus-enabled LED and GPIO controller -- firmware

License

Notifications You must be signed in to change notification settings

codeThatThinks/autotank-led-fw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autotank-led-fw

A CANbus-enabled LED and GPIO controller -- firmware

CANbus Commands

The default Dev ID is 0xA3

Command Extended ID Send Payload Recv Payload
28:8 7:0 Byte 0 Byte 1 Byte 2 Byte 3 Byte 0 Byte 1
Read Pins 0 Dev ID Dev ID In States Out States
Write Pins 1 Dev ID States
Write Pin 2 Dev ID Pin State
Truth Table 3 Dev ID Pin Enable Values
Pin Interrupt 4 Dev ID Pin Mode Dev ID Pin State
RGB Strip 1 5 Dev ID Mode Red Green Blue
RGB Strip 2 6 Dev ID Mode Red Green Blue

GPIO

Pin states use the following payload byte format (MSB first):

Byte n
7:4 Reserved Pin 4 Pin 3 Pin 2 Pin 1

Output Truth Table

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.

Each output pin has the following truth table:

Inputs IN2 IN1
00 01 10 11
IN4
IN3
00 X1 X2 X3 X4
01 X5 X6 X7 X8
10 X9 X10 X11 X12
11 X13 X14 X15 X16

Which is represented as the following payload byte format (MSB first):

Byte 2 Byte 3
X16 X15 X14 X13 X12 X11 X10 X9 X8 X7 X6 X5 X4 X3 X2 X1

Pin Interrupts

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.

The following interrupt modes are available:

Mode Value
Disabled 0
Rising Edge 1
Falling Edge 2
Any Change 3

RGB Strip

Two addressable RGB strips can be controlled via CANbus messages. Only WS2812-compatible LEDs which use the GRB color format can be controlled.

The following pattern modes are available:

Mode Value
Disabled 0
Solid Color 1
Rainbow 2

Development

This project uses PlatformIO.

Compiling

For actual hardware:

pio run

For ST Nucleo-144 dev board:

pio run -e nucleo

Flashing

Connect an ST-LINK to the programming header, apply 5V power, and run:

For actual hardware:

pio run --target upload

For ST Nucleo-144 dev board:

pio run -e nucleo --target upload