Skip to content
Discussion options

You must be logged in to vote

@mishal There are a number of ways of approaching this. One approach I use is that a device driver constructor takes a 2-tuple arg. Elements are as follows:

  1. The initialised SPI bus instance.
  2. A dict containing init args e.g. {"baudrate": 1_000_000, "polarity": 1}

Whenever the device driver needs to use the SPI it does something like

spi = arb[0]
spi.init(**arb[1])  # Init works fine with a subset of args
cs(0)  # Assert the CS\ line (possibly after a brief delay)
# Do the transfers
cs(1)

I don't interrogate the SPI bus as every device "knows" what settings it needs.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@mishal
Comment options

Comment options

You must be logged in to vote
1 reply
@mishal
Comment options

Answer selected by mishal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants