Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Namespaces | Functions | Variables
i2c.h File Reference

Interface for the platform specific i2c protocols. More...

Go to the source code of this file.

Namespaces

namespace  lampda
 Program scope.
 
namespace  lampda::platform
 Handle the platform specific interactions.
 

Functions

void lampda::platform::i2c::i2c_setup (uint8_t i2cIndex, uint32_t baudrate, uint32_t timeout)
 Setup the i2c interface, needs to be called at program start.
 
void lampda::platform::i2c::i2c_turn_off (uint8_t i2cIndex)
 Turn of the i2c interface, all i2c functions will return an error after that, until i2c_setup is called again.
 
int lampda::platform::i2c::i2c_check_existence (uint8_t i2cIndex, uint8_t deviceAddr)
 Return 0 if the address exists on the I2C line.
 
int lampda::platform::i2c::lock_i2c ()
 
int lampda::platform::i2c::unlock_i2c ()
 
int lampda::platform::i2c::i2c_writeData (uint8_t i2cIndex, uint8_t deviceAddr, uint8_t registerAdd, uint8_t size, const uint8_t *buf, int stopBit)
 Write data to the two wire interface.
 
int lampda::platform::i2c::i2c_readData (uint8_t i2cIndex, uint8_t deviceAddr, uint8_t registerAdd, uint8_t size, uint8_t *buf, int stopBit)
 Read data from the two wire interface.
 
int lampda::platform::i2c::i2c_xfer_unlocked (uint8_t i2cIndex, uint8_t deviceAddr, int out_size, const uint8_t *out, int in_size, uint8_t *in, uint8_t flags)
 Does a range read/write.
 
int lampda::platform::i2c::i2c_xfer (uint8_t i2cIndex, uint8_t deviceAddr, int out_size, const uint8_t *out, int in_size, uint8_t *in, uint8_t flags)
 Does a range read/write.
 
int lampda::platform::i2c::i2c_read8 (uint8_t i2cIndex, uint8_t deviceAddr, uint8_t registerAdd, uint8_t *val, int stopBit)
 Read 8bits from the two wire interface.
 
int lampda::platform::i2c::i2c_write8 (uint8_t i2cIndex, uint8_t deviceAddr, uint8_t registerAdd, uint8_t val, int stopBit)
 Write 8bits from the two wire interface.
 
int lampda::platform::i2c::i2c_read16 (uint8_t i2cIndex, uint8_t deviceAddr, uint8_t registerAdd, uint16_t *val, int stopBit)
 Read 16bits from the two wire interface.
 
int lampda::platform::i2c::i2c_write16 (uint8_t i2cIndex, uint8_t deviceAddr, uint8_t registerAdd, uint16_t val, int stopBit)
 Write 16bits from the two wire interface.
 

Variables

static const uint8_t lampda::platform::i2c::pdNegociationI2cAddress = 0x22
 
static const uint8_t lampda::platform::i2c::chargeI2cAddress = 0x6B
 
static const uint8_t lampda::platform::i2c::imuI2cAddress = 0x6A
 
static const uint8_t lampda::platform::i2c::batteryBalancerI2cAddress = 0x08
 

Detailed Description

Interface for the platform specific i2c protocols.

Function Documentation

◆ i2c_read16()

int lampda::platform::i2c::i2c_read16 ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
uint8_t  registerAdd,
uint16_t *  val,
int  stopBit 
)
inline

Read 16bits from the two wire interface.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]registerAddThe address of the register to read
[in]valThe value read from register
[in]stopBitif > 0, will add a stopBit after message

◆ i2c_read8()

int lampda::platform::i2c::i2c_read8 ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
uint8_t  registerAdd,
uint8_t *  val,
int  stopBit 
)
inline

Read 8bits from the two wire interface.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]registerAddThe address of the register to read
[in]valThe value read from register
[in]stopBitif > 0, will add a stopBit after message

◆ i2c_readData()

int lampda::platform::i2c::i2c_readData ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
uint8_t  registerAdd,
uint8_t  size,
uint8_t *  buf,
int  stopBit 
)

Read data from the two wire interface.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]registerAddThe address of the register to read
[in]sizethe size of the data to read (in bytes)
[in,out]bufthe data to read, in an array of size size
[in]stopBitif > 0, will add a stopBit after message

◆ i2c_setup()

void lampda::platform::i2c::i2c_setup ( uint8_t  i2cIndex,
uint32_t  baudrate,
uint32_t  timeout 
)

Setup the i2c interface, needs to be called at program start.

Define the general i2c interface (in c style for compatibility) ALL FUNCTION RETURN 0 IN CASE OF SUCCESS !! THEY RETURN 1 IN FAILURE This is C style, not C++

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]baudrateThe baud rate of this interface (100000, 250000, 400000) in hertz
[in]timeoutThe tiemout in milliseconds after which a read or write fails

◆ i2c_turn_off()

void lampda::platform::i2c::i2c_turn_off ( uint8_t  i2cIndex)

Turn of the i2c interface, all i2c functions will return an error after that, until i2c_setup is called again.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)

◆ i2c_write16()

int lampda::platform::i2c::i2c_write16 ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
uint8_t  registerAdd,
uint16_t  val,
int  stopBit 
)
inline

Write 16bits from the two wire interface.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]registerAddThe address of the register to write
[in]valThe value written to register
[in]stopBitif > 0, will add a stopBit after message

◆ i2c_write8()

int lampda::platform::i2c::i2c_write8 ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
uint8_t  registerAdd,
uint8_t  val,
int  stopBit 
)
inline

Write 8bits from the two wire interface.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]registerAddThe address of the register to write
[in]valThe value written to register
[in]stopBitif > 0, will add a stopBit after message

◆ i2c_writeData()

int lampda::platform::i2c::i2c_writeData ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
uint8_t  registerAdd,
uint8_t  size,
const uint8_t *  buf,
int  stopBit 
)

Write data to the two wire interface.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]registerAddThe address of the register to write
[in]sizethe size of the data to write (in bytes)
[in,out]bufthe data to write, in an array of size size
[in]stopBitif > 0, will add a stopBit after message

◆ i2c_xfer()

int lampda::platform::i2c::i2c_xfer ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
int  out_size,
const uint8_t *  out,
int  in_size,
uint8_t *  in,
uint8_t  flags 
)
inline

Does a range read/write.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]out_sizeSize of the out buffer to read
[out]outThe buffer that will contain the read data
[in]in_sizeSize of the in buffer to write
[in]inThe buffer that contains the write data
[in]flagsFlags to set the stop bit, start/stop info, etc

◆ i2c_xfer_unlocked()

int lampda::platform::i2c::i2c_xfer_unlocked ( uint8_t  i2cIndex,
uint8_t  deviceAddr,
int  out_size,
const uint8_t *  out,
int  in_size,
uint8_t *  in,
uint8_t  flags 
)

Does a range read/write.

Parameters
[in]i2cIndexThe index of the i2c interface (from 0 to WIRE_INTERFACES_COUNT - 1)
[in]deviceAddrthe address of the target device
[in]out_sizeSize of the out buffer to read
[out]outThe buffer that will contain the read data
[in]in_sizeSize of the in buffer to write
[in]inThe buffer that contains the write data
[in]flagsFlags to set the stop bit, start/stop info, etc