Firmware SDK
twr_spi

Driver for SPI bus. More...

Enumerations

enum  twr_spi_speed_t {
  TWR_SPI_SPEED_125_KHZ = 0 ,
  TWR_SPI_SPEED_250_KHZ = 1 ,
  TWR_SPI_SPEED_500_KHZ = 2 ,
  TWR_SPI_SPEED_1_MHZ = 3 ,
  TWR_SPI_SPEED_2_MHZ = 4 ,
  TWR_SPI_SPEED_4_MHZ = 5 ,
  TWR_SPI_SPEED_8_MHZ = 6 ,
  TWR_SPI_SPEED_16_MHZ = 7
}
 SPI communication speed. More...
 
enum  twr_spi_mode_t {
  TWR_SPI_MODE_0 = 0 ,
  TWR_SPI_MODE_1 = 1 ,
  TWR_SPI_MODE_2 = 2 ,
  TWR_SPI_MODE_3 = 3
}
 SPI mode of operation. More...
 
enum  twr_spi_event_t { TWR_SPI_EVENT_DONE = 1 }
 SPI event. More...
 

Functions

void twr_spi_init (twr_spi_speed_t speed, twr_spi_mode_t mode)
 Initialize SPI channel. More...
 
void twr_spi_set_speed (twr_spi_speed_t speed)
 Set SPI communication speed. More...
 
void twr_spi_set_timing (uint16_t cs_delay, uint16_t delay, uint16_t cs_quit)
 Set SPI timing. More...
 
twr_spi_speed_t twr_spi_get_speed (void)
 Get SPI communication speed. More...
 
void twr_spi_set_mode (twr_spi_mode_t mode)
 Set SPI mode of operation. More...
 
void twr_spi_set_manual_cs_control (bool manual_cs_control)
 Enable manual control of CS pin. More...
 
twr_spi_mode_t twr_spi_get_mode (void)
 Get SPI mode of operation. More...
 
bool twr_spi_is_ready (void)
 Check if is ready for transfer. More...
 
bool twr_spi_transfer (const void *source, void *destination, size_t length)
 Execute SPI transfer. More...
 
bool twr_spi_async_transfer (const void *source, void *destination, size_t length, void(*event_handler)(twr_spi_event_t event, void *event_param), void(*event_param))
 Execute async SPI transfer. More...
 

Detailed Description

Driver for SPI bus.

Enumeration Type Documentation

◆ twr_spi_event_t

SPI event.

Enumerator
TWR_SPI_EVENT_DONE 

SPI event is completed.

Definition at line 60 of file twr_spi.h.

◆ twr_spi_mode_t

SPI mode of operation.

Enumerator
TWR_SPI_MODE_0 

SPI mode of operation is 0 (CPOL = 0, CPHA = 0)

TWR_SPI_MODE_1 

SPI mode of operation is 1 (CPOL = 0, CPHA = 1)

TWR_SPI_MODE_2 

SPI mode of operation is 2 (CPOL = 1, CPHA = 0)

TWR_SPI_MODE_3 

SPI mode of operation is 3 (CPOL = 1, CPHA = 1)

Definition at line 42 of file twr_spi.h.

◆ twr_spi_speed_t

SPI communication speed.

Enumerator
TWR_SPI_SPEED_125_KHZ 

SPI communication speed is 125 kHz.

TWR_SPI_SPEED_250_KHZ 

SPI communication speed is 250 kHz.

TWR_SPI_SPEED_500_KHZ 

SPI communication speed is 500 kHz.

TWR_SPI_SPEED_1_MHZ 

SPI communication speed is 1 MHz.

TWR_SPI_SPEED_2_MHZ 

SPI communication speed is 2 MHz.

TWR_SPI_SPEED_4_MHZ 

SPI communication speed is 4 MHz.

TWR_SPI_SPEED_8_MHZ 

SPI communication speed is 8 MHz.

TWR_SPI_SPEED_16_MHZ 

SPI communication speed is 16 MHz.

Definition at line 12 of file twr_spi.h.

Function Documentation

◆ twr_spi_async_transfer()

bool twr_spi_async_transfer ( const void *  source,
void *  destination,
size_t  length,
void(*)(twr_spi_event_t event, void *event_param)  event_handler,
void *  event_param 
)

Execute async SPI transfer.

Parameters
[in]sourcePointer to source buffer
[out]destinationPointer to destination buffer
[in]lengthNumber of bytes to be transferred
[in]event_handlerFunction address (can be NULL)
[in]event_paramOptional event parameter (can be NULL)

Definition at line 267 of file twr_spi.c.

Referenced by twr_ls013b7dh03_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_spi_get_mode()

twr_spi_mode_t twr_spi_get_mode ( void  )

Get SPI mode of operation.

Returns
SPI mode of operation

Definition at line 177 of file twr_spi.c.

◆ twr_spi_get_speed()

twr_spi_speed_t twr_spi_get_speed ( void  )

Get SPI communication speed.

Returns
SPI communication speed

Definition at line 150 of file twr_spi.c.

◆ twr_spi_init()

void twr_spi_init ( twr_spi_speed_t  speed,
twr_spi_mode_t  mode 
)

Initialize SPI channel.

Parameters
[in]speedSPI communication speed
[in]modeSPI mode of operation

Definition at line 64 of file twr_spi.c.

Referenced by twr_ls013b7dh03_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_spi_is_ready()

bool twr_spi_is_ready ( void  )

Check if is ready for transfer.

Returns
true If ready
false If not ready

Definition at line 187 of file twr_spi.c.

Referenced by twr_ls013b7dh03_is_ready(), and twr_ls013b7dh03_update().

Here is the caller graph for this function:

◆ twr_spi_set_manual_cs_control()

void twr_spi_set_manual_cs_control ( bool  manual_cs_control)

Enable manual control of CS pin.

Parameters
[in]manual_cs_controlenable manual control

Definition at line 182 of file twr_spi.c.

◆ twr_spi_set_mode()

void twr_spi_set_mode ( twr_spi_mode_t  mode)

Set SPI mode of operation.

Parameters
[in]modeSPI mode of operation

Definition at line 155 of file twr_spi.c.

Referenced by twr_spi_init().

Here is the caller graph for this function:

◆ twr_spi_set_speed()

void twr_spi_set_speed ( twr_spi_speed_t  speed)

Set SPI communication speed.

Parameters
[in]speedSPI communication speed

Definition at line 119 of file twr_spi.c.

Referenced by twr_spi_init().

Here is the caller graph for this function:

◆ twr_spi_set_timing()

void twr_spi_set_timing ( uint16_t  cs_delay,
uint16_t  delay,
uint16_t  cs_quit 
)

Set SPI timing.

Parameters
[in]cs_delayin us
[in]delayin us
[in]cs_quitin us

Definition at line 141 of file twr_spi.c.

◆ twr_spi_transfer()

bool twr_spi_transfer ( const void *  source,
void *  destination,
size_t  length 
)

Execute SPI transfer.

Parameters
[in]sourcePointer to source buffer
[out]destinationPointer to destination buffer
[in]lengthNumber of bytes to be transferred

Definition at line 192 of file twr_spi.c.

Here is the call graph for this function: