Data Structures

struct  KI2CConf
 i2c configuration structure More...
 
struct  KI2C
 i2c bus data structure More...
 

Enumerations

enum  KI2CNum { K_I2C1 = 0, K_I2C2, K_I2C3 }
 Available i2c buses. More...
 
enum  I2CAddressingMode { K_ADDRESSINGMODE_7BIT = 0, K_ADDRESSINGMODE_10BIT }
 Expected addressing mode of i2c bus. More...
 
enum  I2CRole { K_MASTER = 0, K_SLAVE }
 Expected role of i2c bus. More...
 
enum  KI2CStatus {
  I2C_OK = 0, I2C_ERROR, I2C_ERROR_AF, I2C_ERROR_ADDR_TIMEOUT,
  I2C_ERROR_TIMEOUT, I2C_ERROR_NACK, I2C_ERROR_TXE_TIMEOUT, I2C_ERROR_BTF_TIMEOUT,
  I2C_ERROR_NULL_HANDLE
}
 i2c function status More...
 

Functions

void k_i2c_init (KI2CNum i2c, KI2CConf *conf)
 Setup and enable i2c bus. More...
 
void k_i2c_terminate (KI2CNum i2c)
 Terminate i2c bus. More...
 
KI2CConf k_i2c_conf_defaults (void)
 Generate KI2CConf with default I2C values. More...
 
void k_i2c_default_init ()
 Init DEFAULT_I2C bus with default config values. More...
 
void k_i2c_default_dev_init (KI2CNum i2c)
 Initialize i2c device with default config values. More...
 
KI2CStatus k_i2c_write (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 Transmit data over i2c bus to specified address. More...
 
KI2CStatus k_i2c_read (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 Read data over i2c bus from specified address. More...
 
KI2Ckprv_i2c_get (KI2CNum i2c)
 Fetches i2c bus data structure. More...
 
void kprv_i2c_dev_init (KI2CNum i2c)
 Low level hal device initialization This is implemented by the device specific hal. More...
 
void kprv_i2c_dev_terminate (KI2CNum i2c)
 Low level hal i2c termination This is implemented by the device specific hal. More...
 
KI2CStatus kprv_i2c_master_write (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 Low level hal i2c write (as master) This is implemented by the device specific hal. More...
 
KI2CStatus kprv_i2c_master_read (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 Low level hal i2c read (as master) This is implemented by the device specific hal. More...
 
KI2CStatus kprv_i2c_slave_write (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 Low level hal i2c write (as slave) This is implemented by the device specific hal. More...
 
KI2CStatus kprv_i2c_slave_read (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 Low level hal i2c read (as slave) This is implemented by the device specific hal. More...
 

Enumeration Type Documentation

Expected addressing mode of i2c bus.

Enumerator
K_ADDRESSINGMODE_7BIT 
K_ADDRESSINGMODE_10BIT 
enum I2CRole

Expected role of i2c bus.

Warning
Only the Master role is available as of v0.0.4
Enumerator
K_MASTER 
K_SLAVE 
enum KI2CNum

Available i2c buses.

Enumerator
K_I2C1 
K_I2C2 
K_I2C3 
enum KI2CStatus

i2c function status

Enumerator
I2C_OK 
I2C_ERROR 
I2C_ERROR_AF 
I2C_ERROR_ADDR_TIMEOUT 
I2C_ERROR_TIMEOUT 
I2C_ERROR_NACK 
I2C_ERROR_TXE_TIMEOUT 
I2C_ERROR_BTF_TIMEOUT 
I2C_ERROR_NULL_HANDLE 

Function Documentation

KI2CConf k_i2c_conf_defaults ( void  )

Generate KI2CConf with default I2C values.

Returns
KI2CConf
void k_i2c_default_dev_init ( KI2CNum  i2c)

Initialize i2c device with default config values.

Parameters
i2cI2C bus num to initialize
void k_i2c_default_init ( )

Init DEFAULT_I2C bus with default config values.

void k_i2c_init ( KI2CNum  i2c,
KI2CConf conf 
)

Setup and enable i2c bus.

Parameters
i2ci2c bus to initialize
confconfig values to initialize with
KI2CStatus k_i2c_read ( KI2CNum  i2c,
uint16_t  addr,
uint8_t *  ptr,
int  len 
)

Read data over i2c bus from specified address.

In order to ensure safe i2c sharing, this function is semaphore locked. There is one semaphore per bus. This function will block indefinitely while waiting for the semaphore.

Parameters
i2ci2c bus to read from
addraddress of target i2c device
ptrpointer to data buffer
lenlength of data to read
Returns
int I2C_OK on success, I2C_ERROR on error
void k_i2c_terminate ( KI2CNum  i2c)

Terminate i2c bus.

Parameters
i2ci2c bus to terminate
KI2CStatus k_i2c_write ( KI2CNum  i2c,
uint16_t  addr,
uint8_t *  ptr,
int  len 
)

Transmit data over i2c bus to specified address.

In order to ensure safe i2c sharing, this function is semaphore locked. There is one semaphore per bus. This function will block indefinitely while waiting for the semaphore.

Parameters
i2ci2c bus to transmit over
addraddress of target i2c device
ptrpointer to data buffer
lenlength of data in buffer
Returns
int I2C_OK on success, I2C_ERROR on error
void kprv_i2c_dev_init ( KI2CNum  i2c)

Low level hal device initialization This is implemented by the device specific hal.

Parameters
i2ci2c bus to initialize
void kprv_i2c_dev_terminate ( KI2CNum  i2c)

Low level hal i2c termination This is implemented by the device specific hal.

Parameters
i2ci2c bus to terminate
KI2C* kprv_i2c_get ( KI2CNum  i2c)

Fetches i2c bus data structure.

Parameters
i2cnumber of i2c bus to fetch
Returns
KI2C* pointer to data structure
KI2CStatus kprv_i2c_master_read ( KI2CNum  i2c,
uint16_t  addr,
uint8_t *  ptr,
int  len 
)

Low level hal i2c read (as master) This is implemented by the device specific hal.

Parameters
i2ci2c bus to read from
addri2c addr to read from
ptrdata buffer
lenlength of data expected to read
Returns
KI2CStatus I2C_OK on success, I2C_ERROR on error
KI2CStatus kprv_i2c_master_write ( KI2CNum  i2c,
uint16_t  addr,
uint8_t *  ptr,
int  len 
)

Low level hal i2c write (as master) This is implemented by the device specific hal.

Parameters
i2ci2c bus to write from
addri2c addr to write to
ptrdata buffer
lenlength of data in buffer
Returns
KI2CStatus I2C_OK on success, I2C_ERROR on error
KI2CStatus kprv_i2c_slave_read ( KI2CNum  i2c,
uint16_t  addr,
uint8_t *  ptr,
int  len 
)

Low level hal i2c read (as slave) This is implemented by the device specific hal.

Warning
Not implemented as of v0.0.4
Parameters
i2ci2c bus to read from
addri2c addr to read from
ptrdata buffer
lenlength of data expected to read
Returns
KI2CStatus I2C_OK on success, I2C_ERROR on error
KI2CStatus kprv_i2c_slave_write ( KI2CNum  i2c,
uint16_t  addr,
uint8_t *  ptr,
int  len 
)

Low level hal i2c write (as slave) This is implemented by the device specific hal.

Warning
Not implemented as of v0.0.4
Parameters
i2ci2c bus to write from
addri2c addr to write to
ptrdata buffer
lenlength of data in buffer
Returns
KI2CStatus I2C_OK on success, I2C_ERROR on error