Tizen(Headed) Native API
6.5
|
The SPI API provides functions to control SPI peripherals connected to the IoT device.
Required Header
#include <peripheral_io.h>
Overview
This SPI API provides functions to control SPI peripherals connected to the IoT device.
Realted Features
This API is related with the following feature:
It is recommended to use features in your application for reliability.
You can check if a IoT device supports the related features for this API
by using System Information, and control your application's actions accordingly.
To ensure your application is only running on the IoT device with specific features,
please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.
Functions | |
int | peripheral_spi_open (int bus, int cs, peripheral_spi_h *spi) |
Opens a SPI slave device. | |
int | peripheral_spi_close (peripheral_spi_h spi) |
Closes the SPI slave device. | |
int | peripheral_spi_set_mode (peripheral_spi_h spi, peripheral_spi_mode_e mode) |
Sets the SPI transfer mode. | |
int | peripheral_spi_set_bit_order (peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) |
Sets the SPI bit order. | |
int | peripheral_spi_set_bits_per_word (peripheral_spi_h spi, uint8_t bits) |
Sets the number of bits per word. | |
int | peripheral_spi_set_frequency (peripheral_spi_h spi, uint32_t freq_hz) |
Sets the frequency of the SPI bus. | |
int | peripheral_spi_read (peripheral_spi_h spi, uint8_t *data, uint32_t length) |
Reads the bytes data from the SPI slave device. | |
int | peripheral_spi_write (peripheral_spi_h spi, uint8_t *data, uint32_t length) |
Writes the bytes data to the SPI slave device. | |
int | peripheral_spi_transfer (peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length) |
Exchanges the bytes data to the SPI slave device. | |
Typedefs | |
typedef struct _peripheral_spi_s * | peripheral_spi_h |
The handle of a SPI peripherals. |
Typedef Documentation
typedef struct _peripheral_spi_s* peripheral_spi_h |
The handle of a SPI peripherals.
- Since :
- 4.0
Enumeration Type Documentation
Function Documentation
int peripheral_spi_close | ( | peripheral_spi_h | spi | ) |
Closes the SPI slave device.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Parameters:
-
[in] spi The SPI slave device handle
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
- See also:
- peripheral_spi_open()
int peripheral_spi_open | ( | int | bus, |
int | cs, | ||
peripheral_spi_h * | spi | ||
) |
Opens a SPI slave device.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Remarks:
- spi should be released with peripheral_spi_close()
- Parameters:
-
[in] bus The SPI bus number [in] cs The SPI chip select number [out] spi The SPI slave device handle
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
- Postcondition:
- peripheral_spi_close()
int peripheral_spi_read | ( | peripheral_spi_h | spi, |
uint8_t * | data, | ||
uint32_t | length | ||
) |
Reads the bytes data from the SPI slave device.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Parameters:
-
[in] spi The SPI slave device handle [out] data The data buffer to read [in] length The size of data buffer (in bytes)
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
- See also:
- peripheral_spi_write()
int peripheral_spi_set_bit_order | ( | peripheral_spi_h | spi, |
peripheral_spi_bit_order_e | bit_order | ||
) |
Sets the SPI bit order.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Remarks:
- ARTIK530 and Raspberry Pi 3 do not support LSB first bit order.
- Parameters:
-
[in] spi The SPI slave device handle [in] bit_order The transfer bit order
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
- See also:
- peripheral_spi_bit_order_e
int peripheral_spi_set_bits_per_word | ( | peripheral_spi_h | spi, |
uint8_t | bits | ||
) |
Sets the number of bits per word.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Parameters:
-
[in] spi The SPI slave device handle [in] bits The number of bits per word (in bits)
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
int peripheral_spi_set_frequency | ( | peripheral_spi_h | spi, |
uint32_t | freq_hz | ||
) |
Sets the frequency of the SPI bus.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Remarks:
- The frequencies supported are board dependent.
- Parameters:
-
[in] spi The SPI slave device handle [in] freq_hz Frequency to set (in Hz)
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
int peripheral_spi_set_mode | ( | peripheral_spi_h | spi, |
peripheral_spi_mode_e | mode | ||
) |
Sets the SPI transfer mode.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Parameters:
-
[in] spi The SPI slave device handle [in] mode The SPI transfer mode
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
- See also:
- peripheral_spi_mode_e
int peripheral_spi_transfer | ( | peripheral_spi_h | spi, |
uint8_t * | txdata, | ||
uint8_t * | rxdata, | ||
uint32_t | length | ||
) |
Exchanges the bytes data to the SPI slave device.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Parameters:
-
[in] spi The SPI slave device handle [in] txdata The data buffer to write [out] rxdata The data buffer to read [in] length The size of txdata and rxdata buffer (in bytes)
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
int peripheral_spi_write | ( | peripheral_spi_h | spi, |
uint8_t * | data, | ||
uint32_t | length | ||
) |
Writes the bytes data to the SPI slave device.
- Warning:
- This is not for use by third-party applications.
- Since :
- 4.0
- Privilege Level:
- platform
- Privilege:
- http://tizen.org/privilege/peripheralio
- Parameters:
-
[in] spi The SPI slave device handle [in] data The data buffer to write [in] length The size of data buffer (in bytes)
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
PERIPHERAL_ERROR_NONE Successful PERIPHERAL_ERROR_IO_ERROR I/O operation failed PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter PERIPHERAL_ERROR_NOT_SUPPORTED Not supported PERIPHERAL_ERROR_UNKNOWN Unknown internal error
- See also:
- peripheral_spi_read()