le_spi API Reference

Files

file  le_spi_common.h
 
file  le_spi_interface.h
 

Macros

#define LE_SPI_MAX_WRITE_SIZE   1024
 
#define LE_SPI_MAX_READ_SIZE   1024
 

Typedefs

typedef struct le_spi_DeviceHandle * le_spi_DeviceHandleRef_t
 
typedef void(* le_spi_DisconnectHandler_t) (void *)
 

Functions

void le_spi_ConnectService (void)
 
le_result_t le_spi_TryConnectService (void)
 
LE_FULL_API void le_spi_SetServerDisconnectHandler (le_spi_DisconnectHandler_t disconnectHandler, void *contextPtr)
 
void le_spi_DisconnectService (void)
 
le_result_t le_spi_Open (const char *LE_NONNULL deviceName, le_spi_DeviceHandleRef_t *handlePtr)
 
void le_spi_Close (le_spi_DeviceHandleRef_t handle)
 
void le_spi_Configure (le_spi_DeviceHandleRef_t handle, int32_t mode, uint8_t bits, uint32_t speed, int32_t msb)
 
le_result_t le_spi_WriteReadHD (le_spi_DeviceHandleRef_t handle, const uint8_t *writeDataPtr, size_t writeDataSize, uint8_t *readDataPtr, size_t *readDataSizePtr)
 
le_result_t le_spi_WriteHD (le_spi_DeviceHandleRef_t handle, const uint8_t *writeDataPtr, size_t writeDataSize)
 
le_result_t le_spi_ReadHD (le_spi_DeviceHandleRef_t handle, uint8_t *readDataPtr, size_t *readDataSizePtr)
 
le_result_t le_spi_WriteReadFD (le_spi_DeviceHandleRef_t handle, const uint8_t *writeDataPtr, size_t writeDataSize, uint8_t *readDataPtr, size_t *readDataSizePtr)
 

Detailed Description

Macro Definition Documentation

◆ LE_SPI_MAX_READ_SIZE

#define LE_SPI_MAX_READ_SIZE   1024

Max byte storage size for read buffer

◆ LE_SPI_MAX_WRITE_SIZE

#define LE_SPI_MAX_WRITE_SIZE   1024

Max byte storage size for write buffer

Typedef Documentation

◆ le_spi_DeviceHandleRef_t

typedef struct le_spi_DeviceHandle* le_spi_DeviceHandleRef_t

Handle for passing to related functions to access the SPI device

◆ le_spi_DisconnectHandler_t

typedef void(* le_spi_DisconnectHandler_t) (void *)

Type for handler called when a server disconnects.

Function Documentation

◆ le_spi_Close()

void le_spi_Close ( le_spi_DeviceHandleRef_t  handle)

Closes the device associated with the given handle and frees the associated resources.

Note
Once a handle is closed, it's not permitted to use it for future SPI access without first calling Open.
Parameters
[in]handleHandle for the SPI master to close

◆ le_spi_Configure()

void le_spi_Configure ( le_spi_DeviceHandleRef_t  handle,
int32_t  mode,
uint8_t  bits,
uint32_t  speed,
int32_t  msb 
)

Configures an SPI device's data sample settings. The required values should be included in your target's datasheet. Most common Mode values are 0 and 3.

These are the SPI Mode options:

Mode Clock Polarity Clock Phase Clock Edge
0 0 0 1
1 0 1 0
2 1 0 1
3 1 1 0
Note
This function should be called before any of the Read/Write functions to ensure the SPI bus configuration is in a known state.
Parameters
[in]handleHandle for the SPI master to configure
[in]modeChoose mode options for the bus per above table
[in]bitsbits per word, typically 8 bits per word
[in]speedmax speed (Hz), this is slave dependant
[in]msbset as 0 for MSB as first bit or 1 for LSB as first bit

◆ le_spi_ConnectService()

void le_spi_ConnectService ( void  )

Connect the current client thread to the service providing this API. Block until the service is available.

For each thread that wants to use this API, either ConnectService or TryConnectService must be called before any other functions in this API. Normally, ConnectService is automatically called for the main thread, but not for any other thread. For details, see Client Specific Functions.

This function is created automatically.

◆ le_spi_DisconnectService()

void le_spi_DisconnectService ( void  )

Disconnect the current client thread from the service providing this API.

Normally, this function doesn't need to be called. After this function is called, there's no longer a connection to the service, and the functions in this API can't be used. For details, see Client Specific Functions.

This function is created automatically.

◆ le_spi_Open()

le_result_t le_spi_Open ( const char *LE_NONNULL  deviceName,
le_spi_DeviceHandleRef_t handlePtr 
)

Handle for passing to related functions to access the SPI device Opens an SPI device so that the attached device may be accessed.

Returns
  • LE_OK on success
  • LE_BAD_PARAMETER if the device name string is bad
  • LE_NOT_FOUND if the SPI device file could not be found
  • LE_NOT_PERMITTED if the SPI device file can't be opened for read/write
  • LE_DUPLICATE if the given device file is already opened by another spiService client
  • LE_FAULT for non-specific failures
Parameters
[in]deviceNameHandle for the SPI master to open
[out]handlePtrHandle for passing to related functions in order to access the SPI device

◆ le_spi_ReadHD()

le_result_t le_spi_ReadHD ( le_spi_DeviceHandleRef_t  handle,
uint8_t *  readDataPtr,
size_t *  readDataSizePtr 
)

SPI Read for Half Duplex Communication

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform the read from
[out]readDataPtrRX response from slave with number of bytes reserved on master
[in,out]readDataSizePtr

◆ le_spi_SetServerDisconnectHandler()

LE_FULL_API void le_spi_SetServerDisconnectHandler ( le_spi_DisconnectHandler_t  disconnectHandler,
void *  contextPtr 
)

Set handler called when server disconnection is detected.

When a server connection is lost, call this handler then exit with LE_FATAL. If a program wants to continue without exiting, it should call longjmp() from inside the handler.

◆ le_spi_TryConnectService()

le_result_t le_spi_TryConnectService ( void  )

Try to connect the current client thread to the service providing this API. Return with an error if the service is not available.

For each thread that wants to use this API, either ConnectService or TryConnectService must be called before any other functions in this API. Normally, ConnectService is automatically called for the main thread, but not for any other thread. For details, see Client Specific Functions.

This function is created automatically.

Returns
  • LE_OK if the client connected successfully to the service.
  • LE_UNAVAILABLE if the server is not currently offering the service to which the client is bound.
  • LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
  • LE_COMM_ERROR if the Service Directory cannot be reached.

◆ le_spi_WriteHD()

le_result_t le_spi_WriteHD ( le_spi_DeviceHandleRef_t  handle,
const uint8_t *  writeDataPtr,
size_t  writeDataSize 
)

SPI Write for Half Duplex Communication

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform the write on
[in]writeDataPtrTX command/address being sent to slave with size
[in]writeDataSize

◆ le_spi_WriteReadFD()

le_result_t le_spi_WriteReadFD ( le_spi_DeviceHandleRef_t  handle,
const uint8_t *  writeDataPtr,
size_t  writeDataSize,
uint8_t *  readDataPtr,
size_t *  readDataSizePtr 
)

Simultaneous SPI Write and Read for full duplex communication

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform full duplex write-read on
[in]writeDataPtrTX command/address being sent to slave with size
[in]writeDataSize
[out]readDataPtrRX response from slave with same buffer size as TX
[in,out]readDataSizePtr

◆ le_spi_WriteReadHD()

le_result_t le_spi_WriteReadHD ( le_spi_DeviceHandleRef_t  handle,
const uint8_t *  writeDataPtr,
size_t  writeDataSize,
uint8_t *  readDataPtr,
size_t *  readDataSizePtr 
)

Performs SPI WriteRead Half Duplex. You can send send Read command/ address of data to read.

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform the write-read on
[in]writeDataPtrTX command/address being sent to slave with size
[in]writeDataSize
[out]readDataPtrRX response from slave with number of bytes reserved on master
[in,out]readDataSizePtr