Wirepas SDK
i2c.h File Reference

Go to the source code of this file.

Typedefs

typedef void(* i2c_on_transfer_done_cb_f) (i2c_res_e res, i2c_xfer_t *xfer_p)
 

Functions

i2c_res_e I2C_init (i2c_conf_t *conf_p)
 Initialize I2C module. More...
 
i2c_res_e I2C_close (void)
 Close an already initialized I2C module. More...
 
i2c_res_e I2C_transfer (i2c_xfer_t *xfer_p, i2c_on_transfer_done_cb_f cb)
 Initiate an I2C transfer In case there is a write followed by a read, the read is initiated by a REPEATED START. Transfer must be finished before starting a new one. More...
 
i2c_res_e I2C_status (void)
 Return the status of the I2C driver. More...
 

Data Structures

struct  i2c_conf_t
 Simple minimal I2C master driver It only manages one I2C instance at a time. More...
 
struct  i2c_xfer_t
 

Enumerations

enum  i2c_res_e {
  I2C_RES_OK, I2C_RES_INVALID_CONFIG, I2C_RES_INVALID_XFER, I2C_RES_NOT_INITIALIZED,
  I2C_RES_ALREADY_INITIALIZED, I2C_RES_BUSY, I2C_RES_ANACK, I2C_RES_DNACK,
  I2C_RES_BUS_HANG
}
 

Typedef Documentation

◆ i2c_on_transfer_done_cb_f

typedef void(* i2c_on_transfer_done_cb_f) (i2c_res_e res, i2c_xfer_t *xfer_p)

User callback when transfer is done

Definition at line 54 of file i2c.h.

Function Documentation

◆ I2C_close()

i2c_res_e I2C_close ( void  )

Close an already initialized I2C module.

Returns
Return code of operation

◆ I2C_init()

i2c_res_e I2C_init ( i2c_conf_t conf_p)

Initialize I2C module.

Parameters
conf_pPointer to an i2c configuration
Returns
Return code of operation

◆ I2C_status()

i2c_res_e I2C_status ( void  )

Return the status of the I2C driver.

Returns
Return code of operation

◆ I2C_transfer()

i2c_res_e I2C_transfer ( i2c_xfer_t xfer_p,
i2c_on_transfer_done_cb_f  cb 
)

Initiate an I2C transfer In case there is a write followed by a read, the read is initiated by a REPEATED START. Transfer must be finished before starting a new one.

Parameters
xfer_pPointer to the transfer description
cbCallback to call at end of transfer (Can be NULL for a blocking call)
Returns
Return code of operation

Data Structure Documentation

◆ i2c_conf_t

struct i2c_conf_t

Simple minimal I2C master driver It only manages one I2C instance at a time.

Structure to configure the I2C

Definition at line 19 of file i2c.h.

Data Fields
uint32_t clock
bool pullup

◆ i2c_xfer_t

struct i2c_xfer_t

Structure to describe an I2C transfer In case of Read/Write transfer, Write is executed first and then the Read.

Definition at line 29 of file i2c.h.

Data Fields
uint8_t address
uint32_t custom
uint8_t * read_ptr
uint8_t read_size
uint8_t * write_ptr
uint8_t write_size

Enumeration Type Documentation

◆ i2c_res_e

enum i2c_res_e

Return codes of I2C functions

Enumerator
I2C_RES_OK 
I2C_RES_INVALID_CONFIG 
I2C_RES_INVALID_XFER 
I2C_RES_NOT_INITIALIZED 
I2C_RES_ALREADY_INITIALIZED 
I2C_RES_BUSY 
I2C_RES_ANACK 
I2C_RES_DNACK 
I2C_RES_BUS_HANG 

Definition at line 40 of file i2c.h.

41 {
42  I2C_RES_OK, //< Last operation was successful
43  I2C_RES_INVALID_CONFIG, //< Invalid initial parameters
44  I2C_RES_INVALID_XFER, //< Invalid transfer parameters
45  I2C_RES_NOT_INITIALIZED, //< Driver is not initialized
46  I2C_RES_ALREADY_INITIALIZED, //< Driver already initialized
47  I2C_RES_BUSY, //< Asynchronous transfer is ongoing
48  I2C_RES_ANACK, //< Slave responded with Address Nack
49  I2C_RES_DNACK, //< Slave responded with Data Nack
50  I2C_RES_BUS_HANG //< Slave did not respond during synchronous transfer
51 } i2c_res_e;
I2C_RES_BUS_HANG
@ I2C_RES_BUS_HANG
Definition: i2c.h:50
I2C_RES_ANACK
@ I2C_RES_ANACK
Definition: i2c.h:48
I2C_RES_DNACK
@ I2C_RES_DNACK
Definition: i2c.h:49
i2c_res_e
i2c_res_e
Definition: i2c.h:40
I2C_RES_INVALID_CONFIG
@ I2C_RES_INVALID_CONFIG
Definition: i2c.h:43
I2C_RES_BUSY
@ I2C_RES_BUSY
Definition: i2c.h:47
I2C_RES_INVALID_XFER
@ I2C_RES_INVALID_XFER
Definition: i2c.h:44
I2C_RES_NOT_INITIALIZED
@ I2C_RES_NOT_INITIALIZED
Definition: i2c.h:45
I2C_RES_OK
@ I2C_RES_OK
Definition: i2c.h:42
I2C_RES_ALREADY_INITIALIZED
@ I2C_RES_ALREADY_INITIALIZED
Definition: i2c.h:46