Soletta™ Framework
|
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_spi * | sol_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... | |
SPI (Serial Peripheral Interface) API for Soletta.
#define SOL_SPI_DATA_BITS_DEFAULT 8 |
Default value for bits per word when using SPI.
A handle to a SPI bus.
typedef struct sol_spi_config sol_spi_config |
SPI configuration struct.
This struct is used to configure an SPI bus during its creation.
enum sol_spi_mode |
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 |
void sol_spi_close | ( | struct sol_spi * | spi | ) |
Close an SPI bus.
spi | The 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.
spi_mode | Valid values are "mode0", "mode1", "mode2", "mode3". |
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.
spi_mode | sol_spi_mode |
struct sol_spi* sol_spi_open | ( | unsigned int | bus, |
const struct sol_spi_config * | config | ||
) |
Open an SPI bus.
bus | The SPI bus number to open |
config | The SPI bus configuration |
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.
spi | The SPI bus handle |
tx | The output buffer |
rx | The input buffer |
count | number of bytes to be transfer |
transfer_cb | callback 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_data | user data, first parameter of transfer_cb |
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.