SmartSnippets DA1459x SDK
Files | Data Structures | Macros | Typedefs | Enumerations | Functions

Inter Integrated Circuit adapter. More...

Files

file  ad_i2c.h
 I2C device access API.
 

Data Structures

struct  ad_i2c_io_conf_t
 I2C I/O configuration. More...
 
struct  ad_i2c_driver_conf_t
 I2C driver configuration. More...
 
struct  ad_i2c_controller_conf_t
 I2C controller configuration. More...
 

Macros

#define CONFIG_I2C_USE_ASYNC_TRANSACTIONS   (1)
 Controls whether I2C asynchronous transaction API will be used. More...
 
#define CONFIG_I2C_USE_SYNC_TRANSACTIONS   (1)
 Controls whether I2C synchronous transaction API will be used. More...
 

Typedefs

typedef void * ad_i2c_handle_t
 I2C Handle returned by ad_i2c_open()
 
typedef void(* ad_i2c_user_cb) (void *user_data, HW_I2C_ABORT_SOURCE error)
 Asynchronous callback function. More...
 

Enumerations

enum  AD_I2C_ERROR
 I2C adapter error codes. More...
 

Functions

void ad_i2c_init (void)
 Initialize adapter. More...
 
ad_i2c_handle_t ad_i2c_open (const ad_i2c_controller_conf_t *conf)
 Open I2C controller. More...
 
int ad_i2c_reconfig (ad_i2c_handle_t p, const ad_i2c_driver_conf_t *conf)
 Reconfigure I2C controller. More...
 
int ad_i2c_close (ad_i2c_handle_t p, bool force)
 Close I2C controller. More...
 
int ad_i2c_io_config (HW_I2C_ID id, const ad_i2c_io_conf_t *io, AD_IO_CONF_STATE state)
 Initialize controller pins to on / off io configuration. More...
 
int ad_i2c_write (ad_i2c_handle_t p, const uint8_t *wbuf, size_t wlen, uint8_t condition_flags)
 Perform a blocking write transaction. More...
 
int ad_i2c_write_with_to (ad_i2c_handle_t p, const uint8_t *wbuf, size_t wlen, uint8_t condition_flags, OS_TICK_TIME timeout)
 Perform a blocking write transaction with time out. More...
 
int ad_i2c_read (ad_i2c_handle_t p, uint8_t *rbuf, size_t rlen, uint8_t condition_flags)
 Perform a blocking read transaction. More...
 
int ad_i2c_read_with_to (ad_i2c_handle_t p, uint8_t *rbuf, size_t rlen, uint8_t condition_flags, OS_TICK_TIME timeout)
 Perform a blocking read transaction with time out. More...
 
int ad_i2c_write_read (ad_i2c_handle_t p, const uint8_t *wbuf, size_t wlen, uint8_t *rbuf, size_t rlen, uint8_t condition_flags)
 Perform synchronous write/read transaction. More...
 
int ad_i2c_write_read_with_to (ad_i2c_handle_t p, const uint8_t *wbuf, size_t wlen, uint8_t *rbuf, size_t rlen, uint8_t condition_flags, OS_TICK_TIME timeout)
 Perform synchronous write/read transaction with time out. More...
 
void ad_i2c_wait_while_master_busy (ad_i2c_handle_t p)
 Wait while I2C master device is busy. More...
 
int ad_i2c_write_async (ad_i2c_handle_t p, const uint8_t *wbuf, size_t wlen, ad_i2c_user_cb cb, void *user_data, uint8_t condition_flags)
 Perform a non blocking write transaction. More...
 
int ad_i2c_read_async (ad_i2c_handle_t p, uint8_t *rbuf, size_t rlen, ad_i2c_user_cb cb, void *user_data, uint8_t condition_flags)
 Perform a non blocking read transaction. More...
 
int ad_i2c_write_read_async (ad_i2c_handle_t p, const uint8_t *wbuf, size_t wlen, uint8_t *rbuf, size_t rlen, ad_i2c_user_cb cb, void *user_data, uint8_t condition_flags)
 Perform write and asynchronous read I2C transaction. More...
 

Detailed Description

Inter Integrated Circuit adapter.

Macro Definition Documentation

◆ CONFIG_I2C_USE_ASYNC_TRANSACTIONS

#define CONFIG_I2C_USE_ASYNC_TRANSACTIONS   (1)

Controls whether I2C asynchronous transaction API will be used.

I2C asynchronous transaction API (see "ad_i2c_xx_async" API) maintains state in RAM for every I2C bus declared. If the API is not to be used, setting this macro to 0 will save RAM.

◆ CONFIG_I2C_USE_SYNC_TRANSACTIONS

#define CONFIG_I2C_USE_SYNC_TRANSACTIONS   (1)

Controls whether I2C synchronous transaction API will be used.

I2C synchronous transaction API (see "ad_i2c_write_read", "ad_i2c_write", "ad_i2c_read" functions) maintains state in retention RAM for every I2C bus declared. If the API is not to be used, setting this macro to 0 will save retention RAM.

Typedef Documentation

◆ ad_i2c_user_cb

typedef void(* ad_i2c_user_cb) (void *user_data, HW_I2C_ABORT_SOURCE error)

Asynchronous callback function.

Enumeration Type Documentation

◆ AD_I2C_ERROR

I2C adapter error codes.

Function Documentation

◆ ad_i2c_close()

int ad_i2c_close ( ad_i2c_handle_t  p,
bool  force 
)

Close I2C controller.

This function:

  • Aborts ongoing transactions
  • De-initializes the drivers associated with the controller
  • Resets controller interface IOs (as specified in ad_i2c_open())
  • Releases the controller resources
Parameters
[in]phandle returned from ad_i2c_open()
[in]forceforce close even if controller is occupied
Returns
0: success, <0: error code
See also
ad_i2c_open()

◆ ad_i2c_init()

void ad_i2c_init ( void  )

Initialize adapter.

◆ ad_i2c_io_config()

int ad_i2c_io_config ( HW_I2C_ID  id,
const ad_i2c_io_conf_t io,
AD_IO_CONF_STATE  state 
)

Initialize controller pins to on / off io configuration.

This function should be called for setting pins to the correct level before external devices are powered up (e.g on system init). It does not need to be called before every ad_i2c_open() call.

Parameters
[in]idcontroller instance
[in]iocontroller io configuration
[in]stateon/off io configuration
Returns
0: success, <0: error code

◆ ad_i2c_open()

ad_i2c_handle_t ad_i2c_open ( const ad_i2c_controller_conf_t conf)

Open I2C controller.

This function:

  • Acquires the resources needed for using the controller
  • Configures the controller interface IOs
  • Initializes the drivers associated with the controller
Parameters
[in]confcontroller configuration
Returns
>0: non-NULL handle that should be used in subsequent API calls, NULL: error
Note
The function will block until it acquires all controller resources

◆ ad_i2c_read()

int ad_i2c_read ( ad_i2c_handle_t  p,
uint8_t *  rbuf,
size_t  rlen,
uint8_t  condition_flags 
)

Perform a blocking read transaction.

This function performs a synchronous read only transaction

Parameters
[in]phandle returned from ad_i2c_open()
[out]rbufbuffer for incoming data
[in]rlennumber of bytes to read
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

Returns
0 on success, value from HW_I2C_ABORT_SOURCE enum on failure
See also
ad_i2c_open()

◆ ad_i2c_read_async()

int ad_i2c_read_async ( ad_i2c_handle_t  p,
uint8_t *  rbuf,
size_t  rlen,
ad_i2c_user_cb  cb,
void *  user_data,
uint8_t  condition_flags 
)

Perform a non blocking read transaction.

This function performs an asynchronous read only transaction Caller task should retry until function returns no error Callback will be called when transaction is completed

Parameters
[in]phandle returned from ad_i2c_open()
[out]rbufbuffer for incoming data
[in]rlennumber of bytes to read
[in]cbcallback to call after transaction is over (from ISR context)
[in]user_datauser data passed to cb callback
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

Returns
0 on success, <0: error
See also
ad_i2c_open()

◆ ad_i2c_read_with_to()

int ad_i2c_read_with_to ( ad_i2c_handle_t  p,
uint8_t *  rbuf,
size_t  rlen,
uint8_t  condition_flags,
OS_TICK_TIME  timeout 
)

Perform a blocking read transaction with time out.

This function performs a synchronous read only transaction

Parameters
[in]phandle returned from ad_i2c_open()
[out]rbufbuffer for incoming data
[in]rlennumber of bytes to read
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

[in]timeouttime in OS ticks that is expected for read to complete. If time out occurs AD_I2C_ERROR_TRANSFER_TIMEOUT error is returned.

:: OS_EVENT_FOREVER
function will block for ever expecting the completion of transfer. It behaves as ad_i2c_read() function.

:: 0
will poll once and check if the transaction is completed.

Returns
0 on success, value from HW_I2C_ABORT_SOURCE enum on failure
See also
ad_i2c_open()

◆ ad_i2c_reconfig()

int ad_i2c_reconfig ( ad_i2c_handle_t  p,
const ad_i2c_driver_conf_t conf 
)

Reconfigure I2C controller.

This function will apply a new I2C driver configuration.

Parameters
[in]phandle returned from ad_i2c_open()
[in]confpointer to driver configuration
Returns
0: success, <0: error code
See also
ad_i2c_open()

◆ ad_i2c_wait_while_master_busy()

void ad_i2c_wait_while_master_busy ( ad_i2c_handle_t  p)

Wait while I2C master device is busy.

Parameters
[in]ppointer returned from ad_i2c_open()
See also
ad_i2c_open()

◆ ad_i2c_write()

int ad_i2c_write ( ad_i2c_handle_t  p,
const uint8_t *  wbuf,
size_t  wlen,
uint8_t  condition_flags 
)

Perform a blocking write transaction.

This function performs a synchronous write only transaction

Parameters
[in]phandle returned from ad_i2c_open()
[in]wbufbuffer containing the data to be sent to the device
[in]wlensize of data to be sent to the device
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

Returns
0 on success, value from HW_I2C_ABORT_SOURCE enum on failure
See also
ad_i2c_open()

◆ ad_i2c_write_async()

int ad_i2c_write_async ( ad_i2c_handle_t  p,
const uint8_t *  wbuf,
size_t  wlen,
ad_i2c_user_cb  cb,
void *  user_data,
uint8_t  condition_flags 
)

Perform a non blocking write transaction.

This function performs an asynchronous write only transaction Caller task should retry until function returns no error Callback will be called when transaction is completed

Parameters
[in]phandle returned from ad_i2c_open()
[in]wbufbuffer containing the data to be sent to the device
[in]wlensize of data to be sent to the device
[in]cbcallback to call after transaction is over (from ISR context)
[in]user_datauser data passed to cb callback
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

Returns
0 on success, <0: error
See also
ad_i2c_open()

◆ ad_i2c_write_read()

int ad_i2c_write_read ( ad_i2c_handle_t  p,
const uint8_t *  wbuf,
size_t  wlen,
uint8_t *  rbuf,
size_t  rlen,
uint8_t  condition_flags 
)

Perform synchronous write/read transaction.

This function performs a synchronous write and read transaction on I2C bus.

Parameters
[in]phandle returned from ad_i2c_open()
[in]wbufbuffer containing the data to be sent to the device
[in]wlensize of data to be sent to the device
[out]rbufbuffer to store the data read from the device
[in]rlensize of buffer pointed by rbuf
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

Returns
0 on success, value from HW_I2C_ABORT_SOURCE enum on failure
See also
ad_i2c_open()

◆ ad_i2c_write_read_async()

int ad_i2c_write_read_async ( ad_i2c_handle_t  p,
const uint8_t *  wbuf,
size_t  wlen,
uint8_t *  rbuf,
size_t  rlen,
ad_i2c_user_cb  cb,
void *  user_data,
uint8_t  condition_flags 
)

Perform write and asynchronous read I2C transaction.

This function performs asynchronous write and read transaction.

Parameters
[in]phandle returned from ad_i2c_open()
[in]wbufdata to send
[in]wlennumber of bytes to write
[out]rbufbuffer to store the data read from the device
[in]rlensize of buffer pointed by rbuf
[in]cbcallback to call after transaction is over (from ISR context)
[in]user_datauser data to pass to cb
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

Returns
0 on success, <0: error
See also
ad_i2c_open()

◆ ad_i2c_write_read_with_to()

int ad_i2c_write_read_with_to ( ad_i2c_handle_t  p,
const uint8_t *  wbuf,
size_t  wlen,
uint8_t *  rbuf,
size_t  rlen,
uint8_t  condition_flags,
OS_TICK_TIME  timeout 
)

Perform synchronous write/read transaction with time out.

This function performs a synchronous write and read transaction on I2C bus.

Parameters
[in]phandle returned from ad_i2c_open()
[in]wbufbuffer containing the data to be sent to the device
[in]wlensize of data to be sent to the device
[out]rbufbuffer to store the data read from the device
[in]rlensize of buffer pointed by rbuf
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

[in]timeouttime in OS ticks that is expected for transaction to complete. If time out occurs AD_I2C_ERROR_TRANSFER_TIMEOUT error is returned.

:: OS_EVENT_FOREVER
function will block for ever expecting the completion of transfer. It behaves as ad_i2c_write_read() function.

:: 0
will poll once and check if the transaction is completed.

Returns
0 on success, value from HW_I2C_ABORT_SOURCE enum on failure
See also
ad_i2c_open()

◆ ad_i2c_write_with_to()

int ad_i2c_write_with_to ( ad_i2c_handle_t  p,
const uint8_t *  wbuf,
size_t  wlen,
uint8_t  condition_flags,
OS_TICK_TIME  timeout 
)

Perform a blocking write transaction with time out.

This function performs a synchronous write only transaction

Parameters
[in]phandle returned from ad_i2c_open()
[in]wbufbuffer containing the data to be sent to the device
[in]wlensize of data to be sent to the device
[in]condition_flagsPossible values for flags are:

HW_I2C_F_NONE
No STOP or RESTART conditions will be generated at the end of the transaction.

HW_I2C_F_ADD_STOP
STOP condition will be generated at the end of the transaction.

HW_I2C_F_ADD_RESTART
RESTART condition will be generated at the beginning of the transaction.

[in]timeouttime in OS ticks that is expected for write to complete. If time out occurs AD_I2C_ERROR_TRANSFER_TIMEOUT error is returned.

:: OS_EVENT_FOREVER
function will block for ever expecting the completion of transfer. It behaves as ad_i2c_write() function.

:: 0
will poll once and check if the transaction is completed.

Returns
0 on success, value from HW_I2C_ABORT_SOURCE enum on failure
See also
ad_i2c_open()