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_CIRCULAR) || defined(__DOXYGEN__) 68 #define SPI_USE_CIRCULAR FALSE 75 #if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) 76 #define SPI_USE_MUTUAL_EXCLUSION TRUE 83 #if !defined(SPI_SELECT_MODE) || defined(__DOXYGEN__) 84 #define SPI_SELECT_MODE SPI_SELECT_MODE_PAD 92 #if (SPI_SELECT_MODE != SPI_SELECT_MODE_NONE) && \ 93 (SPI_SELECT_MODE != SPI_SELECT_MODE_PAD) && \ 94 (SPI_SELECT_MODE != SPI_SELECT_MODE_PORT) && \ 95 (SPI_SELECT_MODE != SPI_SELECT_MODE_LINE) && \ 96 (SPI_SELECT_MODE != SPI_SELECT_MODE_LLD) 97 #error "invalid SPI_SELECT_MODE setting" 119 #if !defined(SPI_SUPPORTS_CIRCULAR) 120 #define SPI_SUPPORTS_CIRCULAR FALSE 131 #if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__) 139 #define spiSelectI(spip) \ 141 spi_lld_select(spip); \ 152 #define spiUnselectI(spip) \ 154 spi_lld_unselect(spip); \ 157 #elif SPI_SELECT_MODE == SPI_SELECT_MODE_LINE 158 #define spiSelectI(spip) \ 160 palClearLine((spip)->config->ssline); \ 163 #define spiUnselectI(spip) \ 165 palSetLine((spip)->config->ssline); \ 168 #elif SPI_SELECT_MODE == SPI_SELECT_MODE_PORT 169 #define spiSelectI(spip) \ 171 palClearPort((spip)->config->ssport, (spip)->config->ssmask); \ 174 #define spiUnselectI(spip) \ 176 palSetPort((spip)->config->ssport, (spip)->config->ssmask); \ 179 #elif SPI_SELECT_MODE == SPI_SELECT_MODE_PAD 180 #define spiSelectI(spip) \ 182 palClearPad((spip)->config->ssport, (spip)->config->sspad); \ 185 #define spiUnselectI(spip) \ 187 palSetPad((spip)->config->ssport, (spip)->config->sspad); \ 190 #elif SPI_SELECT_MODE == SPI_SELECT_MODE_NONE 191 #define spiSelectI(spip) 193 #define spiUnselectI(spip) 209 #define spiStartIgnoreI(spip, n) { \ 210 (spip)->state = SPI_ACTIVE; \ 211 spi_lld_ignore(spip, n); \ 231 #define spiStartExchangeI(spip, n, txbuf, rxbuf) { \ 232 (spip)->state = SPI_ACTIVE; \ 233 spi_lld_exchange(spip, n, txbuf, rxbuf); \ 251 #define spiStartSendI(spip, n, txbuf) { \ 252 (spip)->state = SPI_ACTIVE; \ 253 spi_lld_send(spip, n, txbuf); \ 271 #define spiStartReceiveI(spip, n, rxbuf) { \ 272 (spip)->state = SPI_ACTIVE; \ 273 spi_lld_receive(spip, n, rxbuf); \ 289 #define spiPolledExchange(spip, frame) spi_lld_polled_exchange(spip, frame) 296 #if (SPI_USE_WAIT == TRUE) || defined(__DOXYGEN__) 304 #define _spi_wakeup_isr(spip) { \ 305 osalSysLockFromISR(); \ 306 osalThreadResumeI(&(spip)->thread, MSG_OK); \ 307 osalSysUnlockFromISR(); \ 310 #define _spi_wakeup_isr(spip) 327 #define _spi_isr_code(spip) { \ 328 if ((spip)->config->end_cb) { \ 329 (spip)->state = SPI_COMPLETE; \ 330 (spip)->config->end_cb(spip); \ 331 if ((spip)->state == SPI_COMPLETE) \ 332 (spip)->state = SPI_READY; \ 335 (spip)->state = SPI_READY; \ 336 _spi_wakeup_isr(spip); \ 351 #define _spi_isr_code_half1(spip) { \ 352 if ((spip)->config->end_cb) { \ 353 (spip)->config->end_cb(spip); \ 370 #define _spi_isr_code_half2(spip) { \ 371 if ((spip)->config->end_cb) { \ 372 (spip)->state = SPI_COMPLETE; \ 373 (spip)->config->end_cb(spip); \ 374 if ((spip)->state == SPI_COMPLETE) \ 375 (spip)->state = SPI_ACTIVE; \ 395 const void *txbuf,
void *rxbuf);
398 #if SPI_SUPPORTS_CIRCULAR == TRUE 402 #if SPI_USE_WAIT == TRUE 408 #if SPI_USE_MUTUAL_EXCLUSION == TRUE
void spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
spistate_t
Driver state machine possible states.
void spiStartExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
Exchanges data on the SPI bus.
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
void spiObjectInit(SPIDriver *spip)
Initializes the standard part of a SPIDriver structure.
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
Exchanges data on the SPI bus.
void spiAbortI(SPIDriver *spip)
Aborts the ongoing SPI operation.
void spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
void spiAbort(SPIDriver *spip)
Aborts the ongoing SPI operation, if any.
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
void spiInit(void)
SPI Driver initialization.
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
Driver configuration structure.
void spiStartIgnore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
void spiIgnore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
PLATFORM SPI subsystem low level driver header.
void spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
void spiStartSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
Structure representing an SPI driver.
void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.