MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / sendSubCommand

Method sendSubCommand

Drivers/BQ27220/Source/Bq27220.cpp:239–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237}
238
239bool Bq27220::sendSubCommand(uint16_t subCmd, bool waitConfirm)
240{
241 uint8_t buffer[3];
242 buffer[0] = 0x00;
243 buffer[1] = lowByte(subCmd);
244 buffer[2] = highByte(subCmd);
245 if (!write(buffer, ARRAYSIZE(buffer))) {
246 return false;
247 }
248 if (!waitConfirm) {
249 vTaskDelay(10 / portTICK_PERIOD_MS);
250 return true;
251 }
252 constexpr uint8_t statusReg = 0x00;
253 int waitCount = 20;
254 vTaskDelay(10 / portTICK_PERIOD_MS);
255 while (waitCount--) {
256 writeRead(&statusReg, 1, buffer, 2);
257 uint16_t *value = reinterpret_cast<uint16_t *>(buffer);
258 if (*value == 0xFFA5) {
259 return true;
260 }
261 vTaskDelay(100 / portTICK_PERIOD_MS);
262 }
263 LOGGER.error("Subcommand 0x{:04X} failed!", subCmd);
264 return false;
265}
266
267bool Bq27220::writeConfig16(uint16_t address, uint16_t value) {
268 constexpr uint8_t fixedDataLength = 0x06;

Callers

nothing calls this directly

Calls 4

lowByteFunction · 0.85
highByteFunction · 0.85
errorMethod · 0.80
writeFunction · 0.50

Tested by

no test coverage detected