I am interested in working on SPI devices available in linux. I have a specific controller which supports SPI in both master and slave mode. I have to configure the SPI controller in slave mode.
My question: Does the Linux frame work support SPI slaves? I will get asynchronous data on SPI bus, I have to read this data and process it, then send back a command.
Support of SPI Slave Mode has been in the Linux kernel from revision v4.13-rc1. From SPI Documentation of Linux Kernel:
This document (and Linux) supports both the master and slave sides of SPI interactions.
[...]
A "struct spi_device" encapsulates the controller-side interface between those two types of drivers.
[...]
/sys/devices/.../CTLR/slave ... virtual file for (un)registering the slave device for an SPI slave controller.
Writing the driver name of an SPI slave handler to this file registers the slave device; writing "(null)" unregisters the slave device.
Reading from this file shows the name of the slave device ("(null)" if not registered).
/sys/class/spi_slave/spiB ... symlink (or actual device node) to a logical node which could hold class related state for the SPI slave controller on bus "B". When registered, a single spiB.* device is present here, possible sharing the physical SPI bus segment with other SPI slave devices.
I do not have any example C++/C code to support this off-hand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With