ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
spi.h File Reference

The one owner of the shared SPI bus for the peripheral drivers. More...

Go to the source code of this file.

Macros

#define PROTOCORE_SPI_HZ   1000000u
 Bus clock for the shared peripheral bus; 1 MHz is safe on every part on it.
#define PROTOCORE_SPI_MODE   0u
 Clock polarity and phase, as SPI mode 0..3. Mode 0 is what these parts use.
#define PROTOCORE_SPI_HOST   0u
 Controller the plain verbs drive.
#define PROTOCORE_SPI_QUADWP_PIN   (-1)
 Third and fourth data lines, for a quad-width bus; -1 leaves the bus single or dual.
#define PROTOCORE_SPI_QUADHD_PIN   (-1)

Functions

EMBED_BEGIN_DECLS EMBED_INLINE embed_bool protocore_spi_begin_on (uint8_t host, int mosi, int miso, int sclk, int quadwp, int quadhd)
EMBED_INLINE embed_bool protocore_spi_begin (void)
EMBED_INLINE embed_bool protocore_spi_txn_on (uint8_t host, uint32_t hz, uint8_t bit_order, uint8_t mode, const uint8_t *tx, uint8_t *rx, size_t len)
EMBED_INLINE embed_bool protocore_spi_txn_at (uint32_t hz, uint8_t bit_order, uint8_t mode, const uint8_t *tx, uint8_t *rx, size_t len)
EMBED_INLINE embed_bool protocore_spi_txn (const uint8_t *tx, uint8_t *rx, size_t len)
EMBED_INLINE embed_bool protocore_spi_write (const uint8_t *tx, size_t len)
EMBED_INLINE embed_bool protocore_spi_read (uint8_t *rx, size_t len)
EMBED_INLINE embed_bool protocore_spi_txn_ext_on (uint8_t host, uint32_t hz, uint8_t bit_order, uint8_t mode, uint16_t cmd, uint8_t cmd_bits, uint32_t addr, uint8_t addr_bits, uint8_t dummy_bits, uint8_t lanes, const uint8_t *tx, uint8_t *rx, size_t len)
EMBED_INLINE embed_bool protocore_spi_txn_ext (uint16_t cmd, uint8_t cmd_bits, uint32_t addr, uint8_t addr_bits, uint8_t dummy_bits, uint8_t lanes, const uint8_t *tx, uint8_t *rx, size_t len)
EMBED_INLINE void protocore_spi_cs_idle (uint8_t pin)
EMBED_INLINE void protocore_spi_cs_select (uint8_t pin)
EMBED_INLINE void protocore_spi_cs_release (uint8_t pin)

Detailed Description

The one owner of the shared SPI bus for the peripheral drivers.

The sibling of i2c.h, for the drivers whose part is on SPI rather than I2C (the interface bridge, the W5500 Ethernet, the radio modules). They share one bus and bring it up through these verbs. The pins come from PROTOCORE_SPI_MOSI_PIN / PROTOCORE_SPI_MISO_PIN / PROTOCORE_SPI_SCLK_PIN (default -1 = the platform's default host pins). Re-begin is idempotent, so per-driver calls are harmless.

SPI is symmetric: every clock shifts a bit out and a bit in, so one transfer verb covers the three shapes a driver needs. Pass a null rx to discard what comes back (a write), a null tx to clock zeros out (a read), or both to exchange.

protocore_spi_txn runs at the configured clock, bit order and mode; protocore_spi_txn_at names its own, which is what a bus carrying parts with different timing needs.

protocore_spi_txn_ext adds the framing a flash, a display controller or an ADC front end expects: a command, an address, dummy clocks, and a data phase one, two or four bits wide. The controller drives each phase, so the data buffer holds data alone.

Chip select is the caller's: which pin selects a part is a board fact, and a driver often holds it across several transfers. protocore_spi_cs_idle / protocore_spi_cs_select / protocore_spi_cs_release drive it through the GPIO seam.

The bodies compile wherever the platform states a bus.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file spi.h.

Macro Definition Documentation

◆ PROTOCORE_SPI_HZ

#define PROTOCORE_SPI_HZ   1000000u

Bus clock for the shared peripheral bus; 1 MHz is safe on every part on it.

Definition at line 44 of file spi.h.

Referenced by protocore_spi_txn().

◆ PROTOCORE_SPI_MODE

#define PROTOCORE_SPI_MODE   0u

Clock polarity and phase, as SPI mode 0..3. Mode 0 is what these parts use.

Definition at line 49 of file spi.h.

Referenced by protocore_spi_txn().

◆ PROTOCORE_SPI_HOST

#define PROTOCORE_SPI_HOST   0u

Controller the plain verbs drive.

Definition at line 54 of file spi.h.

Referenced by protocore_spi_txn_at().

◆ PROTOCORE_SPI_QUADWP_PIN

#define PROTOCORE_SPI_QUADWP_PIN   (-1)

Third and fourth data lines, for a quad-width bus; -1 leaves the bus single or dual.

Definition at line 59 of file spi.h.

◆ PROTOCORE_SPI_QUADHD_PIN

#define PROTOCORE_SPI_QUADHD_PIN   (-1)

Definition at line 62 of file spi.h.

Function Documentation

◆ protocore_spi_begin_on()

EMBED_BEGIN_DECLS EMBED_INLINE embed_bool protocore_spi_begin_on ( uint8_t host,
int mosi,
int miso,
int sclk,
int quadwp,
int quadhd )

Definition at line 167 of file spi.h.

◆ protocore_spi_begin()

EMBED_INLINE embed_bool protocore_spi_begin ( void )

Definition at line 178 of file spi.h.

◆ protocore_spi_txn_on()

EMBED_INLINE embed_bool protocore_spi_txn_on ( uint8_t host,
uint32_t hz,
uint8_t bit_order,
uint8_t mode,
const uint8_t * tx,
uint8_t * rx,
size_t len )

Definition at line 183 of file spi.h.

Referenced by protocore_spi_txn_at().

◆ protocore_spi_txn_at()

EMBED_INLINE embed_bool protocore_spi_txn_at ( uint32_t hz,
uint8_t bit_order,
uint8_t mode,
const uint8_t * tx,
uint8_t * rx,
size_t len )

Definition at line 196 of file spi.h.

References PROTOCORE_SPI_HOST, and protocore_spi_txn_on().

Referenced by protocore_spi_txn().

◆ protocore_spi_txn()

EMBED_INLINE embed_bool protocore_spi_txn ( const uint8_t * tx,
uint8_t * rx,
size_t len )

Definition at line 202 of file spi.h.

References PROTOCORE_SPI_HZ, PROTOCORE_SPI_MODE, and protocore_spi_txn_at().

Referenced by protocore_spi_read(), and protocore_spi_write().

◆ protocore_spi_write()

EMBED_INLINE embed_bool protocore_spi_write ( const uint8_t * tx,
size_t len )

Definition at line 207 of file spi.h.

References protocore_spi_txn().

◆ protocore_spi_read()

EMBED_INLINE embed_bool protocore_spi_read ( uint8_t * rx,
size_t len )

Definition at line 212 of file spi.h.

References protocore_spi_txn().

◆ protocore_spi_txn_ext_on()

EMBED_INLINE embed_bool protocore_spi_txn_ext_on ( uint8_t host,
uint32_t hz,
uint8_t bit_order,
uint8_t mode,
uint16_t cmd,
uint8_t cmd_bits,
uint32_t addr,
uint8_t addr_bits,
uint8_t dummy_bits,
uint8_t lanes,
const uint8_t * tx,
uint8_t * rx,
size_t len )

Definition at line 217 of file spi.h.

◆ protocore_spi_txn_ext()

EMBED_INLINE embed_bool protocore_spi_txn_ext ( uint16_t cmd,
uint8_t cmd_bits,
uint32_t addr,
uint8_t addr_bits,
uint8_t dummy_bits,
uint8_t lanes,
const uint8_t * tx,
uint8_t * rx,
size_t len )

Definition at line 238 of file spi.h.

◆ protocore_spi_cs_idle()

EMBED_INLINE void protocore_spi_cs_idle ( uint8_t pin)

Definition at line 254 of file spi.h.

◆ protocore_spi_cs_select()

EMBED_INLINE void protocore_spi_cs_select ( uint8_t pin)

Definition at line 259 of file spi.h.

◆ protocore_spi_cs_release()

EMBED_INLINE void protocore_spi_cs_release ( uint8_t pin)

Definition at line 264 of file spi.h.