...
For example code on using SPI, check out the ‘smoke_spi’ project: https://github.com/uw-midsun/firmware_xiv/blob/master/projects/smoke_spi/src/main.c
Although the SPI protocol is universal (ish), ICs tend to implement their own set of commands to use. Again going back to our MPPTs as an example:
...
This is all fine and good, but it could get pretty annoying to pack the right values into the right places every time you want to send a message, especially if you’re mixing data types like having two uint16_ts and one uint32_t. To facilitate this, we use something called code generation.
Code Generation
We actually define all our CAN messages in a separate repo called codegen-tooling-msxivthe codegen/can_messages.asciipb
file, found here: https://github.com/uw-midsun/codegen-tooling-msxivfirmware_xiv/blob/master/codegen/can_messages.asciipb. Have a quick look at this file. In general, we define messages similar to the following:
...
Once we have these definitions, we generate CAN_TRANSMIT, CAN_PACK, and CAN_UNPACK functions for every message. For detailed instructions on generating To generate these messages you can check the repo README, or , just use make codegen
. Also see this writeup: Codegen Tooling.
Once the code is generated, it’s placed in the firmware_xiv repo under libraries/codegen-tooling/inc
. Here’s the definitions generated from the above example:
...