Repository navigation
SPI: chip select over any pin type, SpiSlots for a shared bus - #1
Merged
Merged
Conversation
…etup CsPin<Pin> is the chip-select layer over a pin type with begin/on/off, so it is not tied to AVR port addresses (ChipSelect<PortAddr, Bit> stays as the older AVR-only form). SpiSlots<Pins...> declares a shared bus's chip selects statically, one slot each, all driven high before the bus starts; select/deselect/xfer take a slot index. SpiMaster::setup(hz, mode) uses the core's spi_setup when it has one, else the clock only. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017oSawkJZHswQeBpugzmKPx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Roy · project thread
Before: the only chip-select layer,
ChipSelect<PortAddr, Bit>, takes a raw AVRPORTxaddress, so it works only on AVR. A bus with several devices has no way to say which chip selects it has.After:
CsPin<Pin>takes any pin type withbegin/on/off(OneChip's, OnePin's).SpiSlots<Pins...>declares a shared bus's chip selects statically, one slot each, and drives them all high before the bus starts.SpiMaster::setup(hz, mode)sets a device's own clock and mode before talking to it.This is the base for SPI discovery in OneMachine (InternetOfPins/OneMachine, same branch name), where the runtime question is which slot holds which device.
How:
SpiSlotsfolds over its pins by slot index forselect/deselect, andxfer(slot, tx, rx, n)keeps the slot selected for the whole exchange.setup()calls the core'sspi_setup(hz, mode)when it has one, elsespi_init(hz)(the AVR core takes its mode as a template parameter).ChipSelectis unchanged. Checked with g++/clang++ (-Wall -Wextra -Wpedantic -Werror) on a host mock and with avr-g++ 7.3 over the realAvrSpiCore(208 B for begin + setup + one xfer).Merge this first: OneChip's ESP8266 core and OneMachine's SPI scan build on it.
🤖 Generated with Claude Code
https://claude.ai/code/session_017oSawkJZHswQeBpugzmKPx
Generated by Claude Code