16 #ifndef __SILICON_LABS_SPIDRV_H__
17 #define __SILICON_LABS_SPIDRV_H__
23 #include "spidrv_config.h"
24 #if defined( EMDRV_SPIDRV_INCLUDE_SLAVE )
43 #define ECODE_EMDRV_SPIDRV_OK ( ECODE_OK )
44 #define ECODE_EMDRV_SPIDRV_ILLEGAL_HANDLE ( ECODE_EMDRV_SPIDRV_BASE | 0x00000001 )
45 #define ECODE_EMDRV_SPIDRV_PARAM_ERROR ( ECODE_EMDRV_SPIDRV_BASE | 0x00000002 )
46 #define ECODE_EMDRV_SPIDRV_BUSY ( ECODE_EMDRV_SPIDRV_BASE | 0x00000003 )
47 #define ECODE_EMDRV_SPIDRV_TIMER_ALLOC_ERROR ( ECODE_EMDRV_SPIDRV_BASE | 0x00000004 )
48 #define ECODE_EMDRV_SPIDRV_TIMEOUT ( ECODE_EMDRV_SPIDRV_BASE | 0x00000005 )
49 #define ECODE_EMDRV_SPIDRV_IDLE ( ECODE_EMDRV_SPIDRV_BASE | 0x00000006 )
50 #define ECODE_EMDRV_SPIDRV_ABORTED ( ECODE_EMDRV_SPIDRV_BASE | 0x00000007 )
51 #define ECODE_EMDRV_SPIDRV_MODE_ERROR ( ECODE_EMDRV_SPIDRV_BASE | 0x00000008 )
52 #define ECODE_EMDRV_SPIDRV_DMA_ALLOC_ERROR ( ECODE_EMDRV_SPIDRV_BASE | 0x00000009 )
116 int itemsTransferred );
126 #if defined( _USART_ROUTELOC0_MASK )
132 uint8_t portLocation;
152 unsigned int txDMACh;
153 unsigned int rxDMACh;
163 volatile enum { spidrvStateIdle = 0, spidrvStateTransferring = 1 } state;
165 volatile bool blockingCompleted;
167 #if defined( EMDRV_SPIDRV_INCLUDE_SLAVE )
176 #if defined( _USART_ROUTELOC0_MASK )
178 #if defined( USART0 )
179 #define SPIDRV_MASTER_USART0 \
183 _USART_ROUTELOC0_TXLOC_LOC0, \
184 _USART_ROUTELOC0_RXLOC_LOC0, \
185 _USART_ROUTELOC0_CLKLOC_LOC1, \
186 _USART_ROUTELOC0_CSLOC_LOC1, \
191 spidrvBitOrderMsbFirst, \
193 spidrvCsControlAuto, \
194 spidrvSlaveStartImmediate \
198 #if defined( USART1 )
199 #define SPIDRV_MASTER_USART1 \
203 _USART_ROUTELOC0_TXLOC_LOC11, \
204 _USART_ROUTELOC0_RXLOC_LOC11, \
205 _USART_ROUTELOC0_CLKLOC_LOC11, \
206 _USART_ROUTELOC0_CSLOC_LOC11, \
211 spidrvBitOrderMsbFirst, \
213 spidrvCsControlAuto, \
214 spidrvSlaveStartImmediate \
218 #if defined( USART2 )
219 #define SPIDRV_MASTER_USART2 \
223 _USART_ROUTELOC0_TXLOC_LOC0, \
224 _USART_ROUTELOC0_RXLOC_LOC0, \
225 _USART_ROUTELOC0_CLKLOC_LOC0, \
226 _USART_ROUTELOC0_CSLOC_LOC0, \
231 spidrvBitOrderMsbFirst, \
233 spidrvCsControlAuto, \
234 spidrvSlaveStartImmediate \
238 #if defined( USART3 )
239 #define SPIDRV_MASTER_USART3 \
243 _USART_ROUTELOC0_TXLOC_LOC0, \
244 _USART_ROUTELOC0_RXLOC_LOC0, \
245 _USART_ROUTELOC0_CLKLOC_LOC0, \
246 _USART_ROUTELOC0_CSLOC_LOC0, \
251 spidrvBitOrderMsbFirst, \
253 spidrvCsControlAuto, \
254 spidrvSlaveStartImmediate \
258 #if defined( USART4 )
259 #define SPIDRV_MASTER_USART4 \
263 _USART_ROUTELOC0_TXLOC_LOC0, \
264 _USART_ROUTELOC0_RXLOC_LOC0, \
265 _USART_ROUTELOC0_CLKLOC_LOC0, \
266 _USART_ROUTELOC0_CSLOC_LOC0, \
271 spidrvBitOrderMsbFirst, \
273 spidrvCsControlAuto, \
274 spidrvSlaveStartImmediate \
278 #if defined( USART5 )
279 #define SPIDRV_MASTER_USART5 \
283 _USART_ROUTELOC0_TXLOC_LOC0, \
284 _USART_ROUTELOC0_RXLOC_LOC0, \
285 _USART_ROUTELOC0_CLKLOC_LOC0, \
286 _USART_ROUTELOC0_CSLOC_LOC0, \
291 spidrvBitOrderMsbFirst, \
293 spidrvCsControlAuto, \
294 spidrvSlaveStartImmediate \
298 #if defined( USART0 )
299 #define SPIDRV_SLAVE_USART0 \
303 _USART_ROUTELOC0_TXLOC_LOC0, \
304 _USART_ROUTELOC0_RXLOC_LOC0, \
305 _USART_ROUTELOC0_CLKLOC_LOC1, \
306 _USART_ROUTELOC0_CSLOC_LOC1, \
311 spidrvBitOrderMsbFirst, \
313 spidrvCsControlAuto, \
314 spidrvSlaveStartImmediate \
318 #if defined( USART1 )
319 #define SPIDRV_SLAVE_USART1 \
323 _USART_ROUTELOC0_TXLOC_LOC11, \
324 _USART_ROUTELOC0_RXLOC_LOC11, \
325 _USART_ROUTELOC0_CLKLOC_LOC11, \
326 _USART_ROUTELOC0_CSLOC_LOC11, \
331 spidrvBitOrderMsbFirst, \
333 spidrvCsControlAuto, \
334 spidrvSlaveStartImmediate \
338 #if defined( USART2 )
339 #define SPIDRV_SLAVE_USART2 \
343 _USART_ROUTELOC0_TXLOC_LOC0, \
344 _USART_ROUTELOC0_RXLOC_LOC0, \
345 _USART_ROUTELOC0_CLKLOC_LOC0, \
346 _USART_ROUTELOC0_CSLOC_LOC0, \
351 spidrvBitOrderMsbFirst, \
353 spidrvCsControlAuto, \
354 spidrvSlaveStartImmediate \
358 #if defined( USART3 )
359 #define SPIDRV_SLAVE_USART3 \
363 _USART_ROUTELOC0_TXLOC_LOC0, \
364 _USART_ROUTELOC0_RXLOC_LOC0, \
365 _USART_ROUTELOC0_CLKLOC_LOC0, \
366 _USART_ROUTELOC0_CSLOC_LOC0, \
371 spidrvBitOrderMsbFirst, \
373 spidrvCsControlAuto, \
374 spidrvSlaveStartImmediate \
378 #if defined( USART4 )
379 #define SPIDRV_SLAVE_USART4 \
383 _USART_ROUTELOC0_TXLOC_LOC0, \
384 _USART_ROUTELOC0_RXLOC_LOC0, \
385 _USART_ROUTELOC0_CLKLOC_LOC0, \
386 _USART_ROUTELOC0_CSLOC_LOC0, \
391 spidrvBitOrderMsbFirst, \
393 spidrvCsControlAuto, \
394 spidrvSlaveStartImmediate \
398 #if defined( USART5 )
399 #define SPIDRV_SLAVE_USART5 \
403 _USART_ROUTELOC0_TXLOC_LOC0, \
404 _USART_ROUTELOC0_RXLOC_LOC0, \
405 _USART_ROUTELOC0_CLKLOC_LOC0, \
406 _USART_ROUTELOC0_CSLOC_LOC0, \
411 spidrvBitOrderMsbFirst, \
413 spidrvCsControlAuto, \
414 spidrvSlaveStartImmediate \
421 #define SPIDRV_MASTER_USART0 \
424 _USART_ROUTE_LOCATION_LOC1, \
429 spidrvBitOrderMsbFirst, \
431 spidrvCsControlAuto, \
432 spidrvSlaveStartImmediate \
436 #define SPIDRV_MASTER_USART1 \
439 _USART_ROUTE_LOCATION_LOC1, \
444 spidrvBitOrderMsbFirst, \
446 spidrvCsControlAuto, \
447 spidrvSlaveStartImmediate \
451 #if defined( _EZR32_LEOPARD_FAMILY ) || defined( _EZR32_WONDER_FAMILY )
452 #define SPIDRV_MASTER_USART2 \
455 _USART_ROUTE_LOCATION_LOC1, \
460 spidrvBitOrderMsbFirst, \
462 spidrvCsControlAuto, \
463 spidrvSlaveStartImmediate \
466 #define SPIDRV_MASTER_USART2 \
469 _USART_ROUTE_LOCATION_LOC0, \
474 spidrvBitOrderMsbFirst, \
476 spidrvCsControlAuto, \
477 spidrvSlaveStartImmediate \
482 #define SPIDRV_MASTER_USARTRF0 \
485 RF_USARTRF_LOCATION, \
490 spidrvBitOrderMsbFirst, \
492 spidrvCsControlAuto, \
493 spidrvSlaveStartImmediate \
497 #define SPIDRV_MASTER_USARTRF1 \
500 RF_USARTRF_LOCATION, \
505 spidrvBitOrderMsbFirst, \
507 spidrvCsControlAuto, \
508 spidrvSlaveStartImmediate \
512 #define SPIDRV_SLAVE_USART0 \
515 _USART_ROUTE_LOCATION_LOC1, \
520 spidrvBitOrderMsbFirst, \
522 spidrvCsControlAuto, \
523 spidrvSlaveStartImmediate \
527 #define SPIDRV_SLAVE_USART1 \
530 _USART_ROUTE_LOCATION_LOC1, \
535 spidrvBitOrderMsbFirst, \
537 spidrvCsControlAuto, \
538 spidrvSlaveStartImmediate \
542 #if defined( _EZR32_LEOPARD_FAMILY ) || defined( _EZR32_WONDER_FAMILY )
543 #define SPIDRV_SLAVE_USART2 \
546 _USART_ROUTE_LOCATION_LOC1, \
551 spidrvBitOrderMsbFirst, \
553 spidrvCsControlAuto, \
554 spidrvSlaveStartImmediate \
557 #define SPIDRV_SLAVE_USART2 \
560 _USART_ROUTE_LOCATION_LOC0, \
565 spidrvBitOrderMsbFirst, \
567 spidrvCsControlAuto, \
568 spidrvSlaveStartImmediate \
573 #define SPIDRV_SLAVE_USARTRF0 \
576 _USART_ROUTE_LOCATION_LOC1, \
581 spidrvBitOrderMsbFirst, \
583 spidrvCsControlAuto, \
584 spidrvSlaveStartImmediate \
596 uint32_t *frameLength );
599 int *itemsTransferred,
600 int *itemsRemaining );
615 const void *txBuffer,
621 const void *txBuffer,
642 uint32_t frameLength );
656 const void *txBuffer,
663 const void *txBuffer,
Clock management unit (CMU) API.
SPIDRV_SlaveStart_t slaveStartMode
Slave mode transfer start scheme.
Ecode_t SPIDRV_GetTransferStatus(SPIDRV_Handle_t handle, int *itemsTransferred, int *itemsRemaining)
Get the status of a SPI transfer.
SPIDRV_Type_t type
SPI type, master or slave.
Ecode_t SPIDRV_DeInit(SPIDRV_Handle_t handle)
Deinitialize a SPI driver instance.
Ecode_t SPIDRV_AbortTransfer(SPIDRV_Handle_t handle)
Abort an ongoing SPI transfer.
uint32_t RTCDRV_TimerID_t
Timer ID.
Ecode_t SPIDRV_STransferB(SPIDRV_Handle_t handle, const void *txBuffer, void *rxBuffer, int count, int timeoutMs)
Start a SPI slave blocking transfer.
Ecode_t SPIDRV_GetBitrate(SPIDRV_Handle_t handle, uint32_t *bitRate)
Get current SPI bus bitrate.
Ecode_t SPIDRV_MTransmitB(SPIDRV_Handle_t handle, const void *buffer, int count)
Start a SPI master blocking transmit transfer.
Energy Aware drivers error code definitions.
uint32_t dummyTxValue
The value to transmit when using SPI receive API functions.
enum SPIDRV_ClockMode SPIDRV_ClockMode_t
SPI clock mode (clock polarity and phase).
MSB bit is transmitted first.
Ecode_t SPIDRV_MTransfer(SPIDRV_Handle_t handle, const void *txBuffer, void *rxBuffer, int count, SPIDRV_Callback_t callback)
Start a SPI master transfer.
Ecode_t SPIDRV_MReceive(SPIDRV_Handle_t handle, void *buffer, int count, SPIDRV_Callback_t callback)
Start a SPI master receive transfer.
SPIDRV_BitOrder_t bitOrder
Bit order on SPI bus, MSB or LSB first.
USART_TypeDef * port
The USART used for SPI.
Ecode_t SPIDRV_MTransferSingleItemB(SPIDRV_Handle_t handle, uint32_t txValue, void *rxValue)
Start a SPI master blocking single item (frame) transfer.
Ecode_t SPIDRV_MTransferB(SPIDRV_Handle_t handle, const void *txBuffer, void *rxBuffer, int count)
Start a SPI master blocking transfer.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
SPIDRV_CsControl
SPI master chip select (CS) control scheme.
SPI mode 2: CLKPOL=1, CLKPHA=0.
RTCDRV timer API definition.
uint8_t portLocationRx
Location number for SPI Rx pin.
uint32_t bitRate
SPI bitrate.
SPIDRV_ClockMode
SPI clock mode (clock polarity and phase).
Ecode_t SPIDRV_SetFramelength(SPIDRV_Handle_t handle, uint32_t frameLength)
Set SPI framelength.
SPI mode 1: CLKPOL=0, CLKPHA=1.
Transfer is started when bus is idle (CS deasserted).
LSB bit is transmitted first.
uint32_t Ecode_t
Typedef for API function error code return values.
Ecode_t SPIDRV_SetBitrate(SPIDRV_Handle_t handle, uint32_t bitRate)
Set SPI bus bitrate.
Ecode_t SPIDRV_MTransmit(SPIDRV_Handle_t handle, const void *buffer, int count, SPIDRV_Callback_t callback)
Start a SPI master transmit transfer.
uint8_t portLocationClk
Location number for SPI Clk pin.
uint8_t portLocationCs
Location number for SPI Cs pin.
enum SPIDRV_BitOrder SPIDRV_BitOrder_t
SPI bus bit order.
struct SPIDRV_HandleData SPIDRV_HandleData_t
SPIDRV_SlaveStart
SPI slave transfer start scheme.
CS controlled by application.
uint8_t portLocationTx
Location number for SPI Tx pin.
static volatile uint8_t rxBuffer[RXBUFSIZE]
struct SPIDRV_Init SPIDRV_Init_t
Ecode_t SPIDRV_STransfer(SPIDRV_Handle_t handle, const void *txBuffer, void *rxBuffer, int count, SPIDRV_Callback_t callback, int timeoutMs)
Start a SPI slave transfer.
Ecode_t SPIDRV_STransmitB(SPIDRV_Handle_t handle, const void *buffer, int count, int timeoutMs)
Start a SPI slave blocking transmit transfer.
SPI mode 0: CLKPOL=0, CLKPHA=0.
DMADRV_PeripheralSignal_t
Peripherals that can trigger LDMA transfers.
Ecode_t SPIDRV_GetFramelength(SPIDRV_Handle_t handle, uint32_t *frameLength)
Get current SPI framelength.
Transfer is started immediately.
SPIDRV_BitOrder
SPI bus bit order.
Ecode_t SPIDRV_Init(SPIDRV_Handle_t handle, SPIDRV_Init_t *initData)
Initialize a SPI driver instance.
Ecode_t SPIDRV_STransmit(SPIDRV_Handle_t handle, const void *buffer, int count, SPIDRV_Callback_t callback, int timeoutMs)
Start a SPI slave transmit transfer.
CS controlled by SPI driver.
enum SPIDRV_CsControl SPIDRV_CsControl_t
SPI master chip select (CS) control scheme.
SPIDRV_Type
SPI driver instance type.
Ecode_t SPIDRV_SReceive(SPIDRV_Handle_t handle, void *buffer, int count, SPIDRV_Callback_t callback, int timeoutMs)
Start a SPI slave receive transfer.
void(* SPIDRV_Callback_t)(struct SPIDRV_HandleData *handle, Ecode_t transferStatus, int itemsTransferred)
SPIDRV transfer completion callback function.
SPI mode 3: CLKPOL=1, CLKPHA=1.
uint32_t frameLength
SPI framelength, valid numbers are 4..16.
Ecode_t SPIDRV_SReceiveB(SPIDRV_Handle_t handle, void *buffer, int count, int timeoutMs)
Start a SPI slave blocking receive transfer.
enum SPIDRV_SlaveStart SPIDRV_SlaveStart_t
SPI slave transfer start scheme.
SPIDRV_HandleData_t * SPIDRV_Handle_t
SPI driver instance handle.
SPIDRV_CsControl_t csControl
Select master mode chip select (CS) control scheme.
SPIDRV_ClockMode_t clockMode
SPI mode, CLKPOL/CLKPHASE setting.
Ecode_t SPIDRV_MReceiveB(SPIDRV_Handle_t handle, void *buffer, int count)
Start a SPI master blocking receive transfer.
enum SPIDRV_Type SPIDRV_Type_t
SPI driver instance type.