jamesbowman / spidriver

SPI driver public repo
https://spidriver.com/
BSD 3-Clause "New" or "Revised" License
178 stars 56 forks source link

Changing bit shift order of spidriver #24

Open boxofrox opened 4 years ago

boxofrox commented 4 years ago

I'm using the spidriver to interface with a PN532 NFC module. The former uses most-significant bit (MSB) first shifting while the latter uses least-significant bit (LSB) first shifting on the SPI bus.

It seems from the datasheet for the spidrivers microcontroller, the hardware SPI shift order can be configured, and would be a nice feature to have.

Unfortunately, I don't know Forth to implement a PR. Instead, I've modified the spicli tool [1] to add "lsb" and "msb" commands to reverse the bits in bytes before transmitting and after receiving, and it works well enough that writing shell scripts against spicli remains clean and readable.

[1]: https://github.com/boxofrox/spidriver/tree/feature/bit-shift-order

brouhaha commented 1 year ago

Having this functionality in SPIDriver would be useful to eme as well, but for now I'm following boxorox' approach of reversing the bits in my Python program.