Skip to content

SPI: chip select over any pin type, SpiSlots for a shared bus - #1

Merged
neu-rah merged 1 commit into
mainfrom
claude/project-thread-1sjq4p
Oct 2, 2026
Merged

neu-rah merged 1 commit into
mainfrom
claude/project-thread-1sjq4p

Conversation

@neu-rah

@neu-rah neu-rah commented Oct 2, 2026

Copy link
Copy Markdown
Member

Requested by Roy · project thread

Before: the only chip-select layer, ChipSelect<PortAddr, Bit>, takes a raw AVR PORTx address, 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 with begin/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: SpiSlots folds over its pins by slot index for select/deselect, and xfer(slot, tx, rx, n) keeps the slot selected for the whole exchange. setup() calls the core's spi_setup(hz, mode) when it has one, else spi_init(hz) (the AVR core takes its mode as a template parameter). ChipSelect is unchanged. Checked with g++/clang++ (-Wall -Wextra -Wpedantic -Werror) on a host mock and with avr-g++ 7.3 over the real AvrSpiCore (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

…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
@neu-rah neu-rah self-assigned this Oct 2, 2026
@neu-rah
neu-rah marked this pull request as ready for review October 2, 2026 23:58
@neu-rah
neu-rah merged commit bca1b6a into main Oct 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants