81 vector<uint8_t> registerAddress, vector<uint8_t> data)
84#if defined(__arm__) || defined(__aarch64__)
85 if (m_i2cFileDescriptor > -1)
87 vector<uint8_t> i2cBytes = registerAddress;
88 i2cBytes.insert(i2cBytes.end(), data.begin(), data.end());
89 struct i2c_msg msgs[1];
90 struct i2c_rdwr_ioctl_data msgset[1];
91 msgs[0].addr = chipAddress;
93 msgs[0].len = i2cBytes.size();
94 msgs[0].buf = i2cBytes.data();
95 msgset[0].msgs = msgs;
97 string debugString(__func__);
98 debugString +=
" , 0x";
99 for (uint32_t count = 0; count < registerAddress.size(); count++)
103 sprintf(regCh,
"%02x", registerAddress[count]);
104 debugString += string(regCh);
106 debugString +=
" <--> 0x";
107 for (uint32_t count = 0; count < data.size(); count++)
111 sprintf(dataCh,
"%02x", data[count]);
112 debugString += string(dataCh);
117 printf(
"%s", debugString.c_str());
119 if (ioctl(m_i2cFileDescriptor, I2C_RDWR, &msgset) < 0)
121 error =
I2CError(
"ioctl(I2C_RDWR) in i2c_write", debugString,
134 error =
I2CError(
"I2C bus is not opened yet");
141 vector<uint8_t> registerAddress, vector<uint8_t> &readData)
144 string debugString(__func__);
145#if defined(__arm__) || defined(__aarch64__)
146 uint8_t *readBytes = (uint8_t*) calloc((m_dataSize + 1), 1);
147 if (readBytes == NULL)
149 error =
I2CError(
"Unable to allocate memory for i2c read");
157 vector<uint8_t> i2cBytes = registerAddress;
158 struct i2c_msg msgs[2];
159 struct i2c_rdwr_ioctl_data msgset[1];
160 msgs[0].addr = chipAddress;
162 msgs[0].len = i2cBytes.size();
163 msgs[0].buf = i2cBytes.data();
164 msgs[1].addr = chipAddress;
165 msgs[1].flags = I2C_M_RD;
166 msgs[1].len = m_dataSize;
167 msgs[1].buf = readBytes;
168 msgset[0].msgs = msgs;
170 debugString +=
" , 0x";
171 for (uint32_t count = 0; count < registerAddress.size(); count++)
175 sprintf(regCh,
"%02x", registerAddress[count]);
176 debugString += string(regCh);
178 if (ioctl(m_i2cFileDescriptor, I2C_RDWR, &msgset) < 0 )
181 error =
I2CError(
"ioctl(I2C_RDWR) in i2c_read", debugString,
191 for (uint16_t count = 0; count < m_dataSize; ++count)
193 readData.push_back(readBytes[count]);
197 if (readBytes != NULL)
205 printf(
"%s <--> 0x", debugString.c_str());
206 for (uint32_t count = 0; count < readData.size(); count++)
208 printf(
"%02x", readData[count]);
247#if defined(__arm__) || defined(__aarch64__)
248 if (m_i2cFileDescriptor > -1)
250 error =
genericWrite(chipAddress, registerArray, dataArray);
266 vector<uint8_t> dataArray;
267#if defined(__arm__) || defined(__aarch64__)
268 if (m_i2cFileDescriptor > -1)
270 error =
genericRead(chipAddress, registerArray, dataArray);