Data Structures

struct  KI2CConf
 
struct  KI2C
 

Macros

#define K_NUM_I2CS   YOTTA_CFG_HARDWARE_I2CCOUNT
 KubOS-HAL I2C Interface. More...
 
#define DEFAULT_I2C   YOTTA_CFG_HARDWARE_DEFAULTS_I2C
 

Enumerations

enum  KI2CNum { K_I2C1 = 0, K_I2C2 = 1 }
 
enum  I2CAddressingMode { K_ADDRESSINGMODE_7BIT = 0, K_ADDRESSINGMODE_10BIT }
 
enum  I2CRole { K_MASTER = 0, K_SLAVE }
 
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
}
 

Functions

void k_i2c_init (KI2CNum i2c, KI2CConf *conf)
 
void k_i2c_terminate (KI2CNum i2c)
 
KI2CConf k_i2c_conf_defaults (void)
 
void k_i2c_default_init ()
 
void k_i2c_default_dev_init (KI2CNum i2c)
 
KI2CStatus k_i2c_write (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 
KI2CStatus k_i2c_read (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 
KI2Ckprv_i2c_get (KI2CNum i2c)
 
void kprv_i2c_dev_init (KI2CNum i2c)
 
void kprv_i2c_dev_terminate (KI2CNum i2c)
 
KI2CStatus kprv_i2c_master_write (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 
KI2CStatus kprv_i2c_master_read (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 
KI2CStatus kprv_i2c_slave_write (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 
KI2CStatus kprv_i2c_slave_read (KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
 

Macro Definition Documentation

#define DEFAULT_I2C   YOTTA_CFG_HARDWARE_DEFAULTS_I2C

Default i2c bus. Derived from value in target.json

1 "config": {
2  "defaults": {
3  "i2c": "K_I2C1"
4  }
5 }
#define K_NUM_I2CS   YOTTA_CFG_HARDWARE_I2CCOUNT

KubOS-HAL I2C Interface.

Author
kubos.co Number of i2c buses available. Derived from value in target.json
1 "config": {
2  "hardware": {
3  "i2cCount": "2"
4  }
5 }

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 
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