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

Mock of the board i2c. More...

Namespaces

namespace  simulator
 Simulator dedicated namespace.
 
namespace  simulator::mock_electrical
 Encapsulate the mock electrical simulation signals.
 
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.
 

Variables

static constexpr size_t simulator::numberOfMocks = 1
 
const std::array< std::unique_ptr< IntegratedCircuitMock_I >, numberOfMocks > simulator::icMocks
 
bool simulator::isI2cAvailable = false
 
std::atomic< bool > simulator::canRunComponentUpdateThread = false
 
std::thread simulator::componentUpdateThread
 

Detailed Description

Mock of the board i2c.

Function Documentation

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