Data Structures

struct  KSPIConf
 Spi configuration structure. More...
 
struct  KSPI
 Spi bus data structure. More...
 

Enumerations

enum  KSPINum { K_SPI_NO_BUS = 0, K_SPI1, K_SPI2, K_SPI3 }
 Available spi buses. More...
 
enum  SPIRole { K_SPI_MASTER = 0, K_SPI_SLAVE }
 Expected role of spi bus. More...
 
enum  SPIDirection { K_SPI_DIRECTION_2LINES = 0, K_SPI_DIRECTION_2LINES_RXONLY, K_SPI_DIRECTION_1LINE }
 Spi direction mode. More...
 
enum  SPIDataSize { K_SPI_DATASIZE_8BIT = 0, K_SPI_DATASIZE_16BIT }
 Spi data size. More...
 
enum  SPIClockPolarity { K_SPI_CPOL_LOW = 0, K_SPI_CPOL_HIGH }
 Spi clock polarity. More...
 
enum  SPIClockPhase { K_SPI_CPHA_1EDGE = 0, K_SPI_CPHA_2EDGE }
 Spi clock phase. More...
 
enum  SPIFirstBit { K_SPI_FIRSTBIT_MSB = 0, K_SPI_FIRSTBIT_LSB }
 Spi first bit order/endianess. More...
 
enum  KSPIStatus {
  SPI_OK, SPI_ERROR, SPI_ERROR_BUSY, SPI_ERROR_TIMEOUT,
  SPI_ERROR_NULL_HANDLE, SPI_ERROR_CONFIG
}
 Spi status values. More...
 

Functions

void k_spi_init (KSPINum spi, KSPIConf *conf)
 Setup and enable spi bus. More...
 
void k_spi_terminate (KSPINum spi)
 Terminate spi bus. More...
 
KSPIConf k_spi_conf_defaults (void)
 
KSPIStatus k_spi_write (KSPINum spi, uint8_t *buffer, uint32_t len)
 Write data over spi bus. More...
 
KSPIStatus k_spi_read (KSPINum spi, uint8_t *buffer, uint32_t len)
 Read data over spi bus. More...
 
KSPIStatus k_spi_write_read (KSPINum spi, uint8_t *txBuffer, uint8_t *rxBuffer, uint32_t len)
 Write and read data over spi bus. More...
 
KSPIkprv_spi_get (KSPINum spi)
 Fetches spi bus data structure. More...
 
KSPIStatus kprv_spi_write (KSPINum spi, uint8_t *buffer, uint32_t len)
 Low level hal spi write. More...
 
KSPIStatus kprv_spi_read (KSPINum spi, uint8_t *buffer, uint32_t len)
 Low level hal spi read. More...
 
KSPIStatus kprv_spi_write_read (KSPINum spi, uint8_t *txBuffer, uint8_t *rxBuffer, uint32_t len)
 Low level spi write & read. More...
 
KSPIStatus kprv_spi_dev_init (KSPINum spi)
 Low level spi initialization. More...
 
KSPIStatus kprv_spi_dev_terminate (KSPINum spi)
 Low level spi termination. More...
 

Enumeration Type Documentation

enum KSPINum

Available spi buses.

Enumerator
K_SPI_NO_BUS 
K_SPI1 
K_SPI2 
K_SPI3 
enum KSPIStatus

Spi status values.

Enumerator
SPI_OK 
SPI_ERROR 
SPI_ERROR_BUSY 
SPI_ERROR_TIMEOUT 
SPI_ERROR_NULL_HANDLE 
SPI_ERROR_CONFIG 

Spi clock phase.

Enumerator
K_SPI_CPHA_1EDGE 
K_SPI_CPHA_2EDGE 

Spi clock polarity.

Enumerator
K_SPI_CPOL_LOW 
K_SPI_CPOL_HIGH 

Spi data size.

Note
MSP430F5 does not support 16-bit mode
Enumerator
K_SPI_DATASIZE_8BIT 
K_SPI_DATASIZE_16BIT 

Spi direction mode.

Note
MSP430F5 does not support 1-line mode
Enumerator
K_SPI_DIRECTION_2LINES 
K_SPI_DIRECTION_2LINES_RXONLY 
K_SPI_DIRECTION_1LINE 

Spi first bit order/endianess.

Enumerator
K_SPI_FIRSTBIT_MSB 
K_SPI_FIRSTBIT_LSB 
enum SPIRole

Expected role of spi bus.

Warning
Only the Master role is available as of v0.1.0
Enumerator
K_SPI_MASTER 
K_SPI_SLAVE 

Function Documentation

KSPIConf k_spi_conf_defaults ( void  )
void k_spi_init ( KSPINum  spi,
KSPIConf conf 
)

Setup and enable spi bus.

Parameters
spispi bus to initialize
confconfig values to initialize with
KSPIStatus k_spi_read ( KSPINum  spi,
uint8_t *  buffer,
uint32_t  len 
)

Read data over spi bus.

In order to ensure safe spi sharing, this function is semaphore locked. There is one semaphore per bus. This function will block indefinitely while waiting for the semaphore.

Parameters
spispi bus to read from
bufferpointer to data buffer
lenlength of data to read
Returns
KSPIStatus SPI_OK on success, otherwise failure
void k_spi_terminate ( KSPINum  spi)

Terminate spi bus.

Parameters
spispi bus to terminate
KSPIStatus k_spi_write ( KSPINum  spi,
uint8_t *  buffer,
uint32_t  len 
)

Write data over spi bus.

In order to ensure safe spi sharing, this function is semaphore locked. There is one semaphore per bus. This function will block indefinitely while waiting for the semaphore.

Parameters
spispi bus to write to
bufferpointer to data buffer
lenlength of data to write
Returns
KSPIStatus SPI_OK on success, otherwise failure
KSPIStatus k_spi_write_read ( KSPINum  spi,
uint8_t *  txBuffer,
uint8_t *  rxBuffer,
uint32_t  len 
)

Write and read data over spi bus.

In order to ensure safe spi sharing, this function is semaphore locked. There is one semaphore per bus. This function will block indefinitely while waiting for the semaphore.

Parameters
spispi bus to write to
txBufferpointer to data buffer to write from
rxBufferpointer to data buffer to read into
lenlength of data to write and read
Returns
KSPIStatus SPI_OK on success, otherwise failure
KSPIStatus kprv_spi_dev_init ( KSPINum  spi)

Low level spi initialization.

This is implemented by the hardware specific hal

Parameters
spispi bus to initialize
Returns
KSPIStatus SPI_OK on success, otherwise failure
KSPIStatus kprv_spi_dev_terminate ( KSPINum  spi)

Low level spi termination.

This is implemented by the hardware specific hal

Parameters
spispi bus to terminate
Returns
KSPIStatus SPI_OK on success, otherwise failure
KSPI* kprv_spi_get ( KSPINum  spi)

Fetches spi bus data structure.

Parameters
spinumber of spi bus to fetch
Returns
KSPI* pointer to data structure
KSPIStatus kprv_spi_read ( KSPINum  spi,
uint8_t *  buffer,
uint32_t  len 
)

Low level hal spi read.

This is implemented by the hardware specific hal

Parameters
spispi bus to read from
bufferpointer to data buffer
lenlength of data to read
Returns
KSPIStatus SPI_OK on success, otherwise failure
KSPIStatus kprv_spi_write ( KSPINum  spi,
uint8_t *  buffer,
uint32_t  len 
)

Low level hal spi write.

This is implemented by the hardware specific hal

Parameters
spispi bus to write to
bufferpointer to data buffer
lenlength of data to write
Returns
KSPIStatus SPI_OK on success, otherwise failure
KSPIStatus kprv_spi_write_read ( KSPINum  spi,
uint8_t *  txBuffer,
uint8_t *  rxBuffer,
uint32_t  len 
)

Low level spi write & read.

This is implemented by the hardware specific hal

Parameters
spispi bus to write to
txBufferpointer to data buffer to write from
rxBufferpointer to data buffer to read into
lenlength of data to write and read
Returns
KSPIStatus SPI_OK on success, otherwise failure