28#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
38#define SPI_SELECT_MODE_NONE 0
41#define SPI_SELECT_MODE_PAD 1
42#define SPI_SELECT_MODE_PORT 2
43#define SPI_SELECT_MODE_LINE 3
44#define SPI_SELECT_MODE_LLD 4
59#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
60#define SPI_USE_WAIT TRUE
67#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
68#define SPI_USE_MUTUAL_EXCLUSION TRUE
75#if !defined(SPI_SELECT_MODE) || defined(__DOXYGEN__)
76#define SPI_SELECT_MODE SPI_SELECT_MODE_PAD
84#if (SPI_SELECT_MODE != SPI_SELECT_MODE_NONE) && \
85 (SPI_SELECT_MODE != SPI_SELECT_MODE_PAD) && \
86 (SPI_SELECT_MODE != SPI_SELECT_MODE_PORT) && \
87 (SPI_SELECT_MODE != SPI_SELECT_MODE_LINE) && \
88 (SPI_SELECT_MODE != SPI_SELECT_MODE_LLD)
89#error "invalid SPI_SELECT_MODE setting"
94#if ((SPI_SELECT_MODE != SPI_SELECT_MODE_PAD) || \
95 (SPI_SELECT_MODE != SPI_SELECT_MODE_PORT) || \
96 (SPI_SELECT_MODE != SPI_SELECT_MODE_LINE)) && \
98#error "current SPI_SELECT_MODE requires HAL_USE_PAL"
141#if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__)
151#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LINE) || defined(__DOXYGEN__)
157#if (SPI_SELECT_MODE == SPI_SELECT_MODE_PORT) || defined(__DOXYGEN__)
167#if (SPI_SELECT_MODE == SPI_SELECT_MODE_PAD) || defined(__DOXYGEN__)
193#if (SPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
199#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
205#if defined(SPI_DRIVER_EXT_FIELDS)
206 SPI_DRIVER_EXT_FIELDS
233#define spiIsBufferComplete(spip) ((bool)((spip)->state == SPI_COMPLETE))
235#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__)
243#define spiSelectI(spip) \
245 spi_lld_select(spip); \
256#define spiUnselectI(spip) \
258 spi_lld_unselect(spip); \
261#elif SPI_SELECT_MODE == SPI_SELECT_MODE_LINE
262#define spiSelectI(spip) \
264 palClearLine((spip)->config->ssline); \
267#define spiUnselectI(spip) \
269 palSetLine((spip)->config->ssline); \
272#elif SPI_SELECT_MODE == SPI_SELECT_MODE_PORT
273#define spiSelectI(spip) \
275 palClearPort((spip)->config->ssport, (spip)->config->ssmask); \
278#define spiUnselectI(spip) \
280 palSetPort((spip)->config->ssport, (spip)->config->ssmask); \
283#elif SPI_SELECT_MODE == SPI_SELECT_MODE_PAD
284#define spiSelectI(spip) \
286 palClearPad((spip)->config->ssport, (spip)->config->sspad); \
289#define spiUnselectI(spip) \
291 palSetPad((spip)->config->ssport, (spip)->config->sspad); \
294#elif SPI_SELECT_MODE == SPI_SELECT_MODE_NONE
295#define spiSelectI(spip)
297#define spiUnselectI(spip)
313#define spiStartIgnoreI(spip, n) { \
314 (spip)->state = SPI_ACTIVE; \
315 spi_lld_ignore(spip, n); \
335#define spiStartExchangeI(spip, n, txbuf, rxbuf) { \
336 (spip)->state = SPI_ACTIVE; \
337 spi_lld_exchange(spip, n, txbuf, rxbuf); \
355#define spiStartSendI(spip, n, txbuf) { \
356 (spip)->state = SPI_ACTIVE; \
357 spi_lld_send(spip, n, txbuf); \
375#define spiStartReceiveI(spip, n, rxbuf) { \
376 (spip)->state = SPI_ACTIVE; \
377 spi_lld_receive(spip, n, rxbuf); \
393#define spiPolledExchange(spip, frame) spi_lld_polled_exchange(spip, frame)
400#if (SPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
408#define _spi_wakeup_isr(spip) { \
409 osalSysLockFromISR(); \
410 osalThreadResumeI(&(spip)->thread, MSG_OK); \
411 osalSysUnlockFromISR(); \
414#define _spi_wakeup_isr(spip)
431#define _spi_isr_code(spip) { \
432 if ((spip)->config->end_cb) { \
433 (spip)->state = SPI_COMPLETE; \
434 (spip)->config->end_cb(spip); \
435 if ((spip)->state == SPI_COMPLETE) \
436 (spip)->state = SPI_READY; \
439 (spip)->state = SPI_READY; \
440 _spi_wakeup_isr(spip); \
455#define _spi_isr_half_code(spip) { \
456 if ((spip)->config->end_cb) { \
457 (spip)->config->end_cb(spip); \
474#define _spi_isr_full_code(spip) { \
475 if ((spip)->config->end_cb) { \
476 (spip)->state = SPI_COMPLETE; \
477 (spip)->config->end_cb(spip); \
478 if ((spip)->state == SPI_COMPLETE) \
479 (spip)->state = SPI_ACTIVE; \
499 const void *txbuf,
void *rxbuf);
502#if SPI_SUPPORTS_CIRCULAR == TRUE
506#if SPI_USE_WAIT == TRUE
512#if SPI_USE_MUTUAL_EXCLUSION == TRUE
uint32_t ioportid_t
Port Identifier.
uint32_t ioportmask_t
Digital I/O port sized unsigned type.
uint32_t ioline_t
Type of an I/O line.
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
spistate_t
Driver state machine possible states.
#define spi_lld_driver_fields
Low level fields of the SPI driver structure.
void spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
void spiInit(void)
SPI Driver initialization.
void spiIgnore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
struct hal_spi_config SPIConfig
Type of a SPI driver configuration structure.
#define spi_lld_config_fields
Low level fields of the SPI configuration structure.
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
void spiObjectInit(SPIDriver *spip)
Initializes the standard part of a SPIDriver structure.
void spiStartSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
msg_t spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void spiStartIgnore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
struct hal_spi_driver SPIDriver
Type of a structure representing an SPI driver.
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
void(* spicallback_t)(SPIDriver *spip)
SPI notification callback type.
void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
Exchanges data on the SPI bus.
void spiStartExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
Exchanges data on the SPI bus.
spistate_t
Driver state machine possible states.
struct hal_spi_config SPIConfig
Type of a SPI driver configuration structure.
#define spiAbort(spip)
Compatibility API with SPI driver v1.
#define spiAbortI(spip)
Compatibility API with SPI driver v1.
struct ch_mutex mutex_t
Type of a mutex structure.
thread_t * thread_reference_t
Type of a thread reference.
PLATFORM SPI (v1) subsystem low level driver header.
Driver configuration structure.
ioportid_t ssport
The chip select port.
spicallback_t end_cb
Operation complete callback or NULL.
ioportmask_t ssmask
The chip select port mask.
bool circular
Enables the circular buffer mode.
uint_fast8_t sspad
The chip select pad number.
ioline_t ssline
The chip select line.
Structure representing an SPI driver.
const SPIConfig * config
Current configuration data.
thread_reference_t thread
Waiting thread.
mutex_t mutex
Mutex protecting the peripheral.
spistate_t state
Driver state.