feat: added application layer for spi bus gateway - #205
feat: added application layer for spi bus gateway #205IM-TechieScientist wants to merge 3 commits into
Conversation
Reviewer's GuideAdds a full SPI bus gateway application layer (SCPI commands through gateway → system bus → Pico SPI LL), and introduces a digital pattern generator SCPI interface, wiring both into the common protocol, build system, and docs. Sequence diagram for BUS:SPI:TRANsact? SPI gateway flowsequenceDiagram
actor Client
participant scpi_core as scpi_t
participant spi_protocol as scpi_cmd_bus_spi_transact_q
participant spi_gateway as spi_gateway_transact
participant system_spi as SPI_transact
participant spi_ll as SPI_LL_transfer
Client->>scpi_core: BUS:SPI:TRANsact?
scpi_core->>spi_protocol: scpi_cmd_bus_spi_transact_q
spi_protocol->>spi_gateway: spi_gateway_transact(tx_data, tx_len, response_buffer, read_len)
spi_gateway->>system_spi: SPI_transact(handle, tx_data, tx_len, response_buffer, read_len)
system_spi->>spi_ll: SPI_LL_select(bus)
system_spi->>spi_ll: SPI_LL_transfer(bus, tx_data, NULL, tx_len, dummy_byte)
system_spi->>spi_ll: SPI_LL_transfer(bus, NULL, response_buffer, read_len, dummy_byte)
system_spi->>spi_ll: SPI_LL_deselect(bus)
spi_ll-->>system_spi: bytes_read
system_spi-->>spi_gateway: bytes_read
spi_gateway-->>spi_protocol: bytes_read
spi_protocol-->>scpi_core: SCPI_ResultArbitraryBlock(context, response_buffer, bytes_read)
scpi_core-->>Client: arbitrary block response
Sequence diagram for PG:STARt digital pattern generator flowsequenceDiagram
actor Client
participant scpi_core as scpi_t
participant pg_protocol as scpi_cmd_pattern_generator_start
participant pg_commands as pg_start
participant pattern_generator as pattern_generator_start
Client->>scpi_core: PG:STARt
scpi_core->>pg_protocol: scpi_cmd_pattern_generator_start
pg_protocol->>pg_commands: pg_start()
pg_commands->>pattern_generator: pattern_generator_start(pg, pattern_buffer, pattern_words, mode)
pattern_generator-->>pg_commands: result
pg_commands-->>pg_protocol: bool
alt [start succeeded]
pg_protocol-->>scpi_core: SCPI_RES_OK
else [start failed]
pg_protocol->>scpi_core: SCPI_ErrorPush(SCPI_ERROR_EXECUTION_ERROR)
pg_protocol-->>scpi_core: SCPI_RES_ERR
end
scpi_core-->>Client: command completion status
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
4796f4d to
8979a78
Compare
There was a problem hiding this comment.
Sorry @IM-TechieScientist, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
There was a problem hiding this comment.
Pull request overview
Adds a new SPI bus gateway across platform → system → application layers, exposing SPI1 via SCPI commands and documenting usage/defaults. This builds on the SPI LL interface work referenced in the stacked PR (#204) and advances Issue #203 (SPI SCPI gateway).
Changes:
- Introduces a low-level SPI platform interface (
spi_ll.*) and a hardware-independent system SPI bus API (system/bus/spi.*). - Adds SCPI command handlers and gateway state for SPI operations (open/configure/write/read/exchange/transact).
- Updates build configuration and README to include/describe the SPI gateway and its defaults.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/system/bus/spi.h | New hardware-independent SPI bus interface API. |
| src/system/bus/spi.c | System-layer SPI handle lifecycle + transfer helpers built on spi_ll. |
| src/platform/spi_ll.h | New RP2040/Pico SDK-facing SPI low-level interface. |
| src/platform/spi_ll.c | Low-level SPI1 init/deinit, CS control, and blocking transfers. |
| src/application/protocol/common.c | Registers new SPI SCPI commands in the command table. |
| src/application/protocol/bus/spi.h | Declares SPI SCPI command handler functions. |
| src/application/protocol/bus/spi.c | Implements SPI SCPI command handlers backed by the gateway API. |
| src/application/gateway/spi_commands.h | Declares SPI gateway configuration/state and transfer entrypoints. |
| src/application/gateway/spi_commands.c | Implements SPI gateway state machine and calls into system SPI API. |
| README.md | Documents SPI gateway defaults and available SCPI commands. |
| CMakeLists.txt | Adds new SPI source files to the firmware build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| gpio_init(config->cs_gpio); | ||
| gpio_set_dir(config->cs_gpio, GPIO_OUT); | ||
|
|
| return (SPI_BitOrder)bit_order; | ||
| } | ||
|
|
||
| size_t SPI_get_bus_count(void) { return SPI_LL_BUS_COUNT; } |
| bool spi_gateway_set_mode(uint32_t mode) | ||
| { | ||
| if (gateway_spi || mode > SPI_GATEWAY_DEFAULT_MODE + 3u) { | ||
| return false; | ||
| } |
Adds the application layer for the SPI bus gateway. Follows up on #204 and working on #203.
Commands added:
Defaults:
PR is stacked on #204. Actual PR size is about 500 lines. Will rebase as previous prs are merged.