Compare commits

...
7 changed files with 24 additions and 64 deletions

No files matched your search

+17
View File
@@ -21,6 +21,23 @@ void I2CBus::i2c_scan_() {
}
}
void I2CBus::dump_scan_results_() {
if (!this->scan_)
return;
ESP_LOGCONFIG(TAG, "Results from bus scan:");
if (this->scan_results_.empty()) {
ESP_LOGCONFIG(TAG, "Found no devices");
return;
}
for (const auto &s : this->scan_results_) {
if (s.second) {
ESP_LOGCONFIG(TAG, "Found device at address 0x%02X", s.first);
} else {
ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
}
}
}
void log_wrong_chip_id(uint8_t id, uint8_t expected) {
ESP_LOGE(TAG, "Wrong chip ID 0x%02X, expected 0x%02X", id, expected);
}
+2
View File
@@ -67,6 +67,8 @@ class I2CBus {
/// @brief Scans the I2C bus for devices. Devices presence is kept in an array of std::pair
/// that contains the address and the corresponding bool presence flag.
void i2c_scan_();
/// @brief Logs the scan results at config level, if the bus was scanned
void dump_scan_results_();
std::vector<std::pair<uint8_t, bool>> scan_results_; ///< array containing scan results
bool scan_{false}; ///< Should we scan ? Can be set in the yaml
};
+1 -14
View File
@@ -85,20 +85,7 @@ void ArduinoI2CBus::dump_config() {
ESP_LOGCONFIG(TAG, " Recovery: failed, SDA is held low on the bus");
break;
}
if (this->scan_) {
ESP_LOGI(TAG, "Results from bus scan:");
if (this->scan_results_.empty()) {
ESP_LOGI(TAG, "Found no devices");
} else {
for (const auto &s : this->scan_results_) {
if (s.second) {
ESP_LOGI(TAG, "Found device at address 0x%02X", s.first);
} else {
ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
}
}
}
}
this->dump_scan_results_();
}
ErrorCode ArduinoI2CBus::write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count,
+1 -14
View File
@@ -127,20 +127,7 @@ void IDFI2CBus::dump_config() {
ESP_LOGCONFIG(TAG, " Recovery: failed, SDA is held low on the bus");
break;
}
if (this->scan_) {
ESP_LOGCONFIG(TAG, "Results from bus scan:");
if (this->scan_results_.empty()) {
ESP_LOGCONFIG(TAG, "Found no devices");
} else {
for (const auto &s : this->scan_results_) {
if (s.second) {
ESP_LOGCONFIG(TAG, "Found device at address 0x%02X", s.first);
} else {
ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
}
}
}
}
this->dump_scan_results_();
}
ErrorCode IDFI2CBus::write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count, uint8_t *read_buffer,
+1 -8
View File
@@ -62,14 +62,7 @@ void HostI2CBus::dump_config() {
ESP_LOGE(TAG, " Setup Error: %s", this->first_error_.c_str());
}
if (this->scan_) {
ESP_LOGI(TAG, " Scan Results:");
for (const auto &s : this->scan_results_) {
if (s.second) {
ESP_LOGI(TAG, " 0x%02X: Found", s.first);
}
}
}
this->dump_scan_results_();
}
ErrorCode HostI2CBus::write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count,
+1 -14
View File
@@ -51,20 +51,7 @@ void SoftwareI2CBus::dump_config() {
if (this->recovered_) {
ESP_LOGCONFIG(TAG, " Recovery: bus successfully recovered");
}
if (this->scan_) {
ESP_LOGI(TAG, "Results from bus scan:");
if (this->scan_results_.empty()) {
ESP_LOGI(TAG, "Found no devices");
} else {
for (const auto &s : this->scan_results_) {
if (s.second) {
ESP_LOGI(TAG, "Found device at address 0x%02X", s.first);
} else {
ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
}
}
}
}
this->dump_scan_results_();
}
// Half of one clock period in microseconds, rounded up. The frequency is validated to be non-zero.
+1 -14
View File
@@ -60,20 +60,7 @@ void ZephyrI2CBus::dump_config() {
} else {
ESP_LOGCONFIG(TAG, " Recovery: bus successfully recovered");
}
if (this->scan_) {
ESP_LOGI(TAG, "Results from I2C bus scan:");
if (scan_results_.empty()) {
ESP_LOGI(TAG, "Found no I2C devices!");
} else {
for (const auto &s : scan_results_) {
if (s.second) {
ESP_LOGI(TAG, "Found I2C device at address 0x%02X", s.first);
} else {
ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
}
}
}
}
this->dump_scan_results_();
}
ErrorCode ZephyrI2CBus::write_readv(uint8_t address, const uint8_t *write_buffer, size_t write_count,