22#include <linux/i2c-dev.h>
35 const char *
const compName
36 ) : LinuxI2cDriverComponentBase(compName),
42 void LinuxI2cDriver ::
47 LinuxI2cDriverComponentBase::init(instance);
53 if (-1 != this->m_fd) {
60 this->m_fd =
::open(device, O_RDWR);
61 return (-1 != this->m_fd);
71 Drv::I2cStatus LinuxI2cDriver ::
79 if (-1 == this->m_fd) {
80 return I2cStatus::I2C_OPEN_ERR;
85 for (U32
byte = 0;
byte < serBuffer.
getSize();
byte++) {
92 int stat = ioctl(this->m_fd, I2C_SLAVE, addr);
97 return I2cStatus::I2C_ADDRESS_ERR;
102 stat = write(this->m_fd, serBuffer.
getData(), serBuffer.
getSize());
107 return I2cStatus::I2C_WRITE_ERR;
109 return I2cStatus::I2C_OK;
112 Drv::I2cStatus LinuxI2cDriver ::
120 if (-1 == this->m_fd) {
121 return I2cStatus::I2C_OPEN_ERR;
128 int stat = ioctl(this->m_fd, I2C_SLAVE, addr);
133 return I2cStatus::I2C_ADDRESS_ERR;
138 stat = read(this->m_fd, serBuffer.
getData(), serBuffer.
getSize());
143 return I2cStatus::I2C_READ_ERR;
146 for (U32
byte = 0;
byte < serBuffer.
getSize();
byte++) {
152 return I2cStatus::I2C_OK;
155 Drv::I2cStatus LinuxI2cDriver ::
164 if (-1 == this->m_fd) {
165 return I2cStatus::I2C_OPEN_ERR;
177 struct i2c_msg rdwr_msgs[2] = {
179 .addr =
static_cast<U16
>(addr),
181 .len =
static_cast<U16
>(writeBuffer.
getSize()),
185 .addr =
static_cast<U16
>(addr),
187 .len =
static_cast<U16
>(readBuffer.
getSize()),
192 struct i2c_rdwr_ioctl_data rdwr_data = {
205 return I2cStatus::I2C_OTHER_ERR;
210 for (U32
byte = 0;
byte < writeBuffer.
getSize();
byte++) {
216 for (U32
byte = 0;
byte < readBuffer.
getSize();
byte++) {
223 return I2cStatus::I2C_OK;
PlatformIntType NATIVE_INT_TYPE
C++-compatible configuration header for fprime configuration.
bool open(const char *device)
static void logMsg(const char *fmt, POINTER_CAST a0=0, POINTER_CAST a1=0, POINTER_CAST a2=0, POINTER_CAST a3=0, POINTER_CAST a4=0, POINTER_CAST a5=0, POINTER_CAST a6=0, POINTER_CAST a7=0, POINTER_CAST a8=0, POINTER_CAST a9=0)