Replace third party libs with i2c bus drivers

This commit is contained in:
Rune Harlyk
2026-01-24 14:30:27 +01:00
committed by Rune Harlyk
parent d9e752777f
commit dbc74d6f88
16 changed files with 1005 additions and 252 deletions
-1
View File
@@ -1,7 +1,6 @@
#include <Arduino.h>
#include <ESPmDNS.h>
#include <WiFi.h>
#include <Wire.h>
#include <map>
#include <filesystem.h>
+9 -11
View File
@@ -40,12 +40,13 @@ void Peripherals::update() {
void Peripherals::updatePins() {
if (i2c_active) {
Wire.end();
I2CBus::instance().end();
}
if (state().sda != -1 && state().scl != -1) {
Wire.begin(state().sda, state().scl, state().frequency);
i2c_active = true;
esp_err_t err = I2CBus::instance().begin(static_cast<gpio_num_t>(state().sda),
static_cast<gpio_num_t>(state().scl), state().frequency);
i2c_active = (err == ESP_OK);
}
}
@@ -60,15 +61,12 @@ void Peripherals::getI2CScanProto(socket_message_I2CScanData &data) {
void Peripherals::scanI2C(uint8_t lower, uint8_t higher) {
addressList.clear();
for (uint8_t address = lower; address < higher; address++) {
Wire.beginTransmission(address);
if (Wire.endTransmission() == 0) {
addressList.emplace_back(address);
ESP_LOGI("Peripherals", "I2C device found at address 0x%02X", address);
}
auto devices = I2CBus::instance().scan(lower, higher);
for (auto addr : devices) {
addressList.emplace_back(addr);
ESP_LOGI("Peripherals", "I2C device found at address 0x%02X", addr);
}
uint8_t nDevices = addressList.size();
ESP_LOGI("Peripherals", "Scan complete - Found %d device(s)", nDevices);
ESP_LOGI("Peripherals", "Scan complete - Found %d device(s)", devices.size());
}
void Peripherals::getIMUProto(socket_message_IMUData &data) {