20 #include <sys/ioctl.h>
21 #include <linux/i2c.h>
22 #include <linux/i2c-dev.h>
35 const char *
const compName
45 if (-1 != this->m_fd) {
52 this->m_fd =
::open(device, O_RDWR);
53 return (-1 != this->m_fd);
71 if (-1 == this->m_fd) {
77 for (U32
byte = 0;
byte < serBuffer.
getSize();
byte++) {
84 int stat = ioctl(this->m_fd, I2C_SLAVE, addr);
94 stat =
static_cast<int>(write(this->m_fd, serBuffer.
getData(), serBuffer.
getSize()));
112 if (-1 == this->m_fd) {
120 int stat = ioctl(this->m_fd, I2C_SLAVE, addr);
130 stat =
static_cast<int>(read(this->m_fd, serBuffer.
getData(), serBuffer.
getSize()));
138 for (U32
byte = 0;
byte < serBuffer.
getSize();
byte++) {
156 if (-1 == this->m_fd) {
169 struct i2c_msg rdwr_msgs[2];
172 rdwr_msgs[0].addr =
static_cast<U16
>(addr);
173 rdwr_msgs[0].flags = 0;
174 rdwr_msgs[0].len =
static_cast<U16
>(writeBuffer.
getSize());
175 rdwr_msgs[0].buf = writeBuffer.
getData();
178 rdwr_msgs[1].addr =
static_cast<U16
>(addr);
179 rdwr_msgs[1].flags = I2C_M_RD;
180 rdwr_msgs[1].len =
static_cast<U16
>(readBuffer.
getSize());
181 rdwr_msgs[1].buf = readBuffer.
getData();
183 struct i2c_rdwr_ioctl_data rdwr_data;
184 rdwr_data.msgs = rdwr_msgs;
200 for (U32
byte = 0;
byte < writeBuffer.
getSize();
byte++) {
206 for (U32
byte = 0;
byte < readBuffer.
getSize();
byte++) {
PlatformIntType NATIVE_INT_TYPE
C++-compatible configuration header for fprime configuration.
@ I2C_OPEN_ERR
I2C driver failed to open device.
@ I2C_OTHER_ERR
Other errors that don't fit.
@ I2C_WRITE_ERR
I2C write failed.
@ I2C_OK
Transaction okay.
@ I2C_ADDRESS_ERR
I2C address invalid.
@ I2C_READ_ERR
I2C read failed.
Auto-generated base for LinuxI2cDriver component.
LinuxI2cDriver(const char *const compName)
bool open(const char *device)
static void log(const char *format,...)
log a formated string with supplied arguments