Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2cDev_PPmod periodic sensor query #2315

Merged
merged 4 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
i2c timeouts and sanity check on ppmod
  • Loading branch information
htotoo committed Oct 19, 2024
commit a408d91d9082dbde310826167ab0dc5f03ed6b08
13 changes: 12 additions & 1 deletion firmware/common/i2cdev_ppmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ uint64_t I2cDev_PPmod::get_features_mask() {
if (success == false) {
return 0;
}
// sanity check
if (mask == UINT64_MAX) {
return 0;
}
return mask;
}

Expand All @@ -124,7 +128,10 @@ std::optional<I2cDev_PPmod::device_info> I2cDev_PPmod::readDeviceInfo() {
if (success == false) {
return std::nullopt;
}

// sanity check
if (info.application_count > 1000) {
return std::nullopt;
}
return info;
}

Expand All @@ -137,6 +144,10 @@ std::optional<I2cDev_PPmod::standalone_app_info> I2cDev_PPmod::getStandaloneAppI
if (success == false) {
return std::nullopt;
}
// sanity check
if (info.binary_size == UINT32_MAX) {
return std::nullopt;
}

return info;
}
Expand Down
11 changes: 8 additions & 3 deletions firmware/common/i2cdevmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ void I2cDev::got_success() {

bool I2cDev::i2c_read(uint8_t* reg, uint8_t reg_size, uint8_t* data, uint8_t bytes) {
if (bytes == 0) return false;
if (reg_size > 0 && reg) i2cbus.transmit(addr, reg, reg_size);
bool ret = i2cbus.receive(addr, data, bytes);
bool ret = true;
if (reg_size > 0 && reg) ret = i2cbus.transmit(addr, reg, reg_size, 150);
if (!ret) {
got_error();
return false;
}
ret = i2cbus.receive(addr, data, bytes, 150);
if (!ret)
got_error();
else
Expand All @@ -153,7 +158,7 @@ bool I2cDev::i2c_write(uint8_t* reg, uint8_t reg_size, uint8_t* data, uint8_t by
// Copy the data into the buffer after the register data
memcpy(buffer + reg_size, data, bytes);
// Transmit the combined data
bool result = i2cbus.transmit(addr, buffer, total_size);
bool result = i2cbus.transmit(addr, buffer, total_size, 150);
// Clean up the dynamically allocated buffer
delete[] buffer;
if (!result)
Expand Down
Loading