![]() |
Laelaps
2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
|
#include <laeI2C.h>
Public Member Functions | |
LaeI2C () | |
Default constructor. | |
virtual | ~LaeI2C () |
Destructor. | |
virtual int | open (const std::string &strDevName) |
Open I2C bus device. More... | |
virtual int | close () |
Close I2C bus device. More... | |
virtual bool | check (uint_t addr) |
Check if an I2C slave endpoint exists. More... | |
virtual int | read (uint_t addr, byte_t buf[], size_t len) |
Read from a I2C slave endpoint device. More... | |
virtual int | write (uint_t addr, const byte_t buf[], size_t len) |
Write to an I2C slave endpoint device. More... | |
virtual int | transfer (uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen) |
Perform a write/read transfer to/from an I2C slave endpoint device. More... | |
virtual int | write_read (uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0) |
Perform a write/read transaction to/from an I2C slave endpoint device. More... | |
std::string | getDevName () |
Get associated I2C device name. More... | |
bool | isOpen () |
Check if device is open. More... | |
Protected Member Functions | |
void | lock () |
Lock the I2C bus. More... | |
void | unlock () |
Unlock the I2C bus. More... | |
Protected Attributes | |
std::string | m_strDevName |
I2C device name. | |
i2c_t | m_i2c |
I2C bus instance. | |
pthread_mutex_t | m_mutex |
mutual exclusion | |
|
virtual |
Check if an I2C slave endpoint exists.
addr | Endpoint I2C device's 7/10-bit address. |
Definition at line 162 of file laeI2C.cxx.
References m_i2c.
Referenced by laelaps::i2cTryOpen().
|
virtual |
Close I2C bus device.
Definition at line 144 of file laeI2C.cxx.
References I2CBusNone, laelaps::LAE_OK, lock(), m_i2c, m_strDevName, and unlock().
Referenced by Laelaps.WatchDog.WatchDog::attach(), laelaps::LaeRobot::disconnect(), laelaps::i2cTryOpen(), main(), Laelaps.WatchDog.WatchDog::open(), and ~LaeI2C().
|
inline |
Get associated I2C device name.
Definition at line 193 of file laeI2C.h.
References m_strDevName.
Referenced by laelaps::LaeI2CMux::getDevName().
|
inline |
Check if device is open.
Definition at line 203 of file laeI2C.h.
References m_i2c.
Referenced by Laelaps.WatchDog.WatchDog::cmdConfigDPin(), Laelaps.WatchDog.WatchDog::cmdEnableAuxPort5V(), Laelaps.WatchDog.WatchDog::cmdEnableAuxPortBatt(), Laelaps.WatchDog.WatchDog::cmdEnableMotorCtlrs(), Laelaps.WatchDog.WatchDog::cmdGetFwVersion(), Laelaps.WatchDog.WatchDog::cmdPetTheDog(), Laelaps.WatchDog.WatchDog::cmdReadAPin(), Laelaps.WatchDog.WatchDog::cmdReadDPin(), Laelaps.WatchDog.WatchDog::cmdReadEnables(), Laelaps.WatchDog.WatchDog::cmdReadVoltages(), Laelaps.WatchDog.WatchDog::cmdResetRgbLed(), Laelaps.WatchDog.WatchDog::cmdSetAlarms(), Laelaps.WatchDog.WatchDog::cmdSetBatterySoC(), Laelaps.WatchDog.WatchDog::cmdSetRgbLed(), Laelaps.WatchDog.WatchDog::cmdWriteDPin(), and laelaps::LaeI2CMux::isOpen().
|
inlineprotected |
Lock the I2C bus.
The lock()/unlock() primitives provide safe multi-threading access.
Definition at line 221 of file laeI2C.h.
Referenced by close(), open(), read(), transfer(), write(), and write_read().
|
virtual |
Open I2C bus device.
strDevName | I2C device name. |
Definition at line 114 of file laeI2C.cxx.
References laelaps::getRealDeviceName(), laelaps::LAE_ECODE_NO_DEV, laelaps::LAE_OK, lock(), m_i2c, m_strDevName, and unlock().
Referenced by laelaps::i2cTryOpen().
|
virtual |
Read from a I2C slave endpoint device.
Reads data from a device at the given address on the bound I2C bus.
addr | Endpoint I2C device's 7/10-bit address. | |
[out] | buf | Pointer to the buffer that will receive the data bytes. |
len | Number of bytes to read. |
Definition at line 167 of file laeI2C.cxx.
References laelaps::LAE_ECODE_IO, lock(), m_i2c, and unlock().
Referenced by laelaps::LaeI2CMux::read(), and laelaps::LaeI2CMux::readChannelStates().
|
virtual |
Perform a write/read transfer to/from an I2C slave endpoint device.
An I2C tranfer sends/receives one or more messages before the STOP is issued to terminate the operation. Each message does begin with a START.
addr | Endpoint I2C device's 7/10-bit address. | |
[in] | wbuf | Pointer to the buffer that contains the data to be written. |
wlen | Number of bytes to write. | |
[out] | rbuf | Pointer to the buffer that will receive the data. |
rlen | Number of bytes to read. |
Definition at line 221 of file laeI2C.cxx.
References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, lock(), m_i2c, and unlock().
|
inlineprotected |
Unlock the I2C bus.
The lock()/unlock() primitives provide safe multi-threading access.
Definition at line 235 of file laeI2C.h.
References laelaps::i2cTryOpen().
Referenced by close(), open(), read(), transfer(), write(), and write_read().
|
virtual |
Write to an I2C slave endpoint device.
Writes data to a device at the given address on the bound I2C bus.
addr | Endpoint I2C device's 7/10-bit address. | |
[in] | buf | Pointer to the buffer that will be written. |
len | Number of bytes to write. |
Definition at line 194 of file laeI2C.cxx.
References laelaps::LAE_ECODE_IO, lock(), m_i2c, and unlock().
Referenced by laelaps::LaeWd::cmdConfigDPin(), laelaps::LaeWd::cmdConfigOperation(), laelaps::LaeWd::cmdEnableAuxPort5V(), laelaps::LaeWd::cmdEnableAuxPortBatt(), laelaps::LaeWd::cmdPetTheDog(), laelaps::LaeWd::cmdResetRgbLed(), laelaps::LaeWd::cmdSetAlarms(), laelaps::LaeWd::cmdSetBatterySoC(), laelaps::LaeWd::cmdSetRgbLed(), laelaps::LaeWd::cmdWriteAPin(), laelaps::LaeWd::cmdWriteDPin(), laelaps::LaeI2CMux::setChannel(), and laelaps::LaeI2CMux::write().
|
virtual |
Perform a write/read transaction to/from an I2C slave endpoint device.
Before each message a START is issued. After each message, a STOP is issued.
addr | Endpoint I2C device's 7/10-bit address. | |
[in] | wbuf | Pointer to the buffer that contains the data to be written. |
wlen | Number of bytes to write. | |
[out] | rbuf | Pointer to the buffer that will receive the data. |
rlen | Number of bytes to read. | |
usec | Delay between write and read operations (usecs). |
Definition at line 249 of file laeI2C.cxx.
References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, lock(), m_i2c, and unlock().
Referenced by laelaps::LaeWd::cmdEnableMotorCtlrs(), sensor::vl6180::LaeRangeMuxSubproc::cmdGetAmbientLight(), laelaps::LaeWd::cmdGetFwVersion(), sensor::vl6180::LaeRangeMuxSubproc::cmdGetFwVersion(), sensor::vl6180::LaeRangeMuxSubproc::cmdGetIdent(), sensor::vl6180::LaeRangeMuxSubproc::cmdGetRanges(), sensor::vl6180::LaeRangeMuxSubproc::cmdGetTunes(), laelaps::LaeWd::cmdPetTheDog(), laelaps::LaeWd::cmdReadAPin(), laelaps::LaeWd::cmdReadDPin(), laelaps::LaeWd::cmdReadEnables(), laelaps::LaeWd::cmdReadVoltages(), laelaps::LaeWd::cmdTest(), sensor::vl6180::LaeRangeMuxSubproc::cmdTuneAls(), sensor::vl6180::LaeRangeMuxSubproc::cmdTuneToFSensor(), and laelaps::LaeI2CMux::transact().