Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions
SPI

SPI (Serial Peripheral Interface) API for Soletta. More...

Data Structures

struct  sol_spi_config
 SPI configuration struct. More...
 

Macros

#define SOL_SPI_DATA_BITS_DEFAULT   8
 Default value for bits per word when using SPI. More...
 

Typedefs

typedef struct sol_spi sol_spi
 A handle to a SPI bus. More...
 
typedef struct sol_spi_config sol_spi_config
 SPI configuration struct. More...
 

Enumerations

enum  sol_spi_mode { SOL_SPI_MODE_0 = 0, SOL_SPI_MODE_1, SOL_SPI_MODE_2, SOL_SPI_MODE_3 }
 SPI Transfer Modes. More...
 

Functions

void sol_spi_close (struct sol_spi *spi)
 Close an SPI bus. More...
 
enum sol_spi_mode sol_spi_mode_from_str (const char *spi_mode)
 Converts a string SPI mode name to sol_spi_mode. More...
 
const char * sol_spi_mode_to_str (enum sol_spi_mode spi_mode)
 Converts sol_spi_mode to a string name. More...
 
struct sol_spisol_spi_open (unsigned int bus, const struct sol_spi_config *config)
 Open an SPI bus. More...
 
int sol_spi_transfer (struct sol_spi *spi, const uint8_t *tx, uint8_t *rx, size_t count, void(*transfer_cb)(void *cb_data, struct sol_spi *spi, const uint8_t *tx, uint8_t *rx, ssize_t status), const void *cb_data)
 Perform a SPI asynchronous transfer. More...
 

Detailed Description

SPI (Serial Peripheral Interface) API for Soletta.

Macro Definition Documentation

#define SOL_SPI_DATA_BITS_DEFAULT   8

Default value for bits per word when using SPI.

Typedef Documentation

A handle to a SPI bus.

See Also
sol_spi_open()
sol_spi_close()
sol_spi_transfer()

SPI configuration struct.

This struct is used to configure an SPI bus during its creation.

See Also
sol_spi_open()

Enumeration Type Documentation

SPI Transfer Modes.

It may enable and disable clock polarity (cpol) and clock phase (cpha) to define a clock format to be used by the SPI bus.

Depending on CPOL parameter, SPI clock may be inverted or non-inverted.

CPHA parameter is used to shift the sampling phase. If CPHA=0 the data are sampled on the leading (first) clock edge.

If CPHA=1 the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling.

Enumerator
SOL_SPI_MODE_0 
SOL_SPI_MODE_1 

CPOL = 0 and CPHA = 0.

SOL_SPI_MODE_2 

CPOL = 0 and CPHA = 1.

SOL_SPI_MODE_3 

CPOL = 1 and CPHA = 0.

CPOL = 1 and CPHA = 1

Function Documentation

void sol_spi_close ( struct sol_spi spi)

Close an SPI bus.

Parameters
spiThe SPI bus handle
enum sol_spi_mode sol_spi_mode_from_str ( const char *  spi_mode)

Converts a string SPI mode name to sol_spi_mode.

This function converts a string SPI mode name to enumeration sol_spi_mode.

See Also
sol_spi_mode_to_str().
Parameters
spi_modeValid values are "mode0", "mode1", "mode2", "mode3".
Returns
enumeration sol_spi_mode
const char* sol_spi_mode_to_str ( enum sol_spi_mode  spi_mode)

Converts sol_spi_mode to a string name.

This function converts sol_spi_mode enumeration to a string SPI mode name.

See Also
sol_spi_mode_from_str().
Parameters
spi_modesol_spi_mode
Returns
String representation of the sol_spi_mode
struct sol_spi* sol_spi_open ( unsigned int  bus,
const struct sol_spi_config config 
)

Open an SPI bus.

Parameters
busThe SPI bus number to open
configThe SPI bus configuration
Returns
A new SPI bus handle
Note
For now it only supports one user of the bus at time, 2 or mode devices with different chip select on the same bus will cause concurrency errors.
int sol_spi_transfer ( struct sol_spi spi,
const uint8_t *  tx,
uint8_t *  rx,
size_t  count,
void(*)(void *cb_data, struct sol_spi *spi, const uint8_t *tx, uint8_t *rx, ssize_t status)  transfer_cb,
const void *  cb_data 
)

Perform a SPI asynchronous transfer.

Parameters
spiThe SPI bus handle
txThe output buffer
rxThe input buffer
countnumber of bytes to be transfer
transfer_cbcallback to be called when transmission finish, in case of success the status parameters on callback should be the same value as count, otherwise a error happen.
cb_datauser data, first parameter of transfer_cb
Returns
0 if the transfer started, -EBUSY if the bus is busy or -errno on error.

As SPI works in full-duplex, data are going in and out at same time, so both buffers must have the same count size. Caller should guarantee that both buffers will not be freed until callback is called. Also there is no transfer queue, calling this function when there is transfer happening would return false.