I2C updates

This commit is contained in:
Ken Van Hoeylandt 2026-06-13 00:31:01 +02:00
parent 023b220bfb
commit 133215664c
35 changed files with 216 additions and 222 deletions

View File

@ -58,7 +58,7 @@ bool initBoot() {
std::vector<tt::hal::gps::GpsConfiguration> gps_configurations; std::vector<tt::hal::gps::GpsConfiguration> gps_configurations;
gps_service->getGpsConfigurations(gps_configurations); gps_service->getGpsConfigurations(gps_configurations);
if (gps_configurations.empty()) { if (gps_configurations.empty()) {
if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "uart1", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) { if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "uart0", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) {
LOGGER.info("Configured internal GPS"); LOGGER.info("Configured internal GPS");
} else { } else {
LOGGER.error("Failed to configure internal GPS"); LOGGER.error("Failed to configure internal GPS");

View File

@ -3,6 +3,7 @@
#include <tactility/bindings/root.h> #include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h> #include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h> #include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h> #include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h> #include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h> #include <tactility/bindings/esp32_spi.h>
@ -30,15 +31,6 @@
pin-scl = <&gpio0 8 GPIO_FLAG_NONE>; pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
}; };
i2c_external: i2c1 {
compatible = "espressif,esp32-i2c";
status = "disabled";
port = <I2C_NUM_1>;
clock-frequency = <400000>;
pin-sda = <&gpio0 43 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 44 GPIO_FLAG_NONE>;
};
i2s0 { i2s0 {
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
@ -55,7 +47,7 @@
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
}; };
uart1 { uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <&gpio0 43 GPIO_FLAG_NONE>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;

View File

@ -4,6 +4,7 @@
#include "devices/TpagerKeyboard.h" #include "devices/TpagerKeyboard.h"
#include "devices/TpagerPower.h" #include "devices/TpagerPower.h"
#include <driver/gpio.h> #include <driver/gpio.h>
#include <tactility/device.h>
#include <Tactility/hal/Configuration.h> #include <Tactility/hal/Configuration.h>
#include <Bq25896.h> #include <Bq25896.h>
@ -14,17 +15,18 @@ bool tpagerInit();
using namespace tt::hal; using namespace tt::hal;
static DeviceVector createDevices() { static DeviceVector createDevices() {
auto bq27220 = std::make_shared<Bq27220>(I2C_NUM_0); auto* i2c = device_find_by_name("i2c0");
auto bq27220 = std::make_shared<Bq27220>(i2c);
auto power = std::make_shared<TpagerPower>(bq27220); auto power = std::make_shared<TpagerPower>(bq27220);
auto tca8418 = std::make_shared<Tca8418>(I2C_NUM_0); auto tca8418 = std::make_shared<Tca8418>(i2c);
auto keyboard = std::make_shared<TpagerKeyboard>(tca8418); auto keyboard = std::make_shared<TpagerKeyboard>(tca8418);
return std::vector<std::shared_ptr<tt::hal::Device>> { return std::vector<std::shared_ptr<tt::hal::Device>> {
tca8418, tca8418,
std::make_shared<Bq25896>(I2C_NUM_0), std::make_shared<Bq25896>(i2c),
bq27220, bq27220,
std::make_shared<Drv2605>(I2C_NUM_0), std::make_shared<Drv2605>(i2c),
power, power,
createTpagerSdCard(), createTpagerSdCard(),
createDisplay(), createDisplay(),

View File

@ -4,6 +4,7 @@
#include "devices/CardputerPower.h" #include "devices/CardputerPower.h"
#include <driver/gpio.h> #include <driver/gpio.h>
#include <tactility/device.h>
#include <Tactility/hal/Configuration.h> #include <Tactility/hal/Configuration.h>
#include <PwmBacklight.h> #include <PwmBacklight.h>
@ -16,7 +17,7 @@ static bool initBoot() {
} }
static DeviceVector createDevices() { static DeviceVector createDevices() {
auto tca8418 = std::make_shared<Tca8418>(I2C_NUM_0); auto tca8418 = std::make_shared<Tca8418>(device_find_by_name("i2c_internal"));
return { return {
createSdCard(), createSdCard(),
createDisplay(), createDisplay(),

View File

@ -3,6 +3,7 @@
#include <tactility/bindings/root.h> #include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h> #include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h> #include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h> #include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h> #include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h> #include <tactility/bindings/esp32_spi.h>
@ -36,12 +37,14 @@
}; };
}; };
i2c_port_a { port_a: grove0 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
port = <I2C_NUM_1>; defaultMode = <GROVE_MODE_I2C>;
clock-frequency = <400000>; pinSdaRx = <&gpio0 2 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; pinSclTx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
}; };
display_spi: spi0 { display_spi: spi0 {
@ -68,12 +71,4 @@
pin-data-out = <&gpio0 42 GPIO_FLAG_NONE>; pin-data-out = <&gpio0 42 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 46 GPIO_FLAG_NONE>; pin-data-in = <&gpio0 46 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 {
compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>;
pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <&gpio0 2 GPIO_FLAG_NONE>;
};
}; };

View File

@ -3,6 +3,7 @@
#include <tactility/bindings/root.h> #include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h> #include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h> #include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h> #include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h> #include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h> #include <tactility/bindings/esp32_spi.h>
@ -22,12 +23,14 @@
gpio-count = <49>; gpio-count = <49>;
}; };
i2c_port_a { port_a: grove0 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
port = <I2C_NUM_0>; defaultMode = <GROVE_MODE_I2C>;
clock-frequency = <400000>; pinSdaRx = <&gpio0 2 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; pinSclTx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_0>;
i2cClockFrequency = <400000>;
}; };
display_spi: spi0 { display_spi: spi0 {
@ -55,12 +58,4 @@
pin-data-out = <&gpio0 42 GPIO_FLAG_NONE>; pin-data-out = <&gpio0 42 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 46 GPIO_FLAG_NONE>; pin-data-in = <&gpio0 46 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 {
compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>;
pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <&gpio0 2 GPIO_FLAG_NONE>;
};
}; };

View File

@ -1,10 +1,11 @@
#include <Axp192.h> #include <Axp192.h>
#include <tactility/device.h>
static std::shared_ptr<Axp192> axp192 = nullptr; static std::shared_ptr<Axp192> axp192 = nullptr;
std::shared_ptr<Axp192> createAxp192() { std::shared_ptr<Axp192> createAxp192() {
assert(axp192 == nullptr); assert(axp192 == nullptr);
auto configuration = std::make_unique<Axp192::Configuration>(I2C_NUM_0); auto configuration = std::make_unique<Axp192::Configuration>(device_find_by_name("i2c_internal"));
axp192 = std::make_shared<Axp192>(std::move(configuration)); axp192 = std::make_shared<Axp192>(std::move(configuration));
return axp192; return axp192;
} }

View File

@ -2,6 +2,7 @@
#include <tactility/bindings/root.h> #include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_gpio.h> #include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h> #include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h> #include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h> #include <tactility/bindings/esp32_spi.h>
@ -37,12 +38,14 @@
}; };
}; };
i2c_port_a { port_a: grove0 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
port = <I2C_NUM_1>; defaultMode = <GROVE_MODE_I2C>;
clock-frequency = <400000>; pinSdaRx = <&gpio0 32 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 32 GPIO_FLAG_NONE>; pinSclTx = <&gpio0 33 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 33 GPIO_FLAG_NONE>; uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
}; };
spi0 { spi0 {
@ -63,12 +66,4 @@
pin-data-out = <&gpio0 2 GPIO_FLAG_NONE>; pin-data-out = <&gpio0 2 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 34 GPIO_FLAG_NONE>; pin-data-in = <&gpio0 34 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 {
compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>;
pin-tx = <&gpio0 33 GPIO_FLAG_NONE>;
pin-rx = <&gpio0 32 GPIO_FLAG_NONE>;
};
}; };

View File

@ -146,8 +146,9 @@ bool initPowerControl() {
bool initBoot() { bool initBoot() {
LOGGER.info("initBoot()"); LOGGER.info("initBoot()");
axp2101 = std::make_shared<Axp2101>(I2C_NUM_0); auto controller = device_find_by_name("i2c_internal");
aw9523 = std::make_shared<Aw9523>(I2C_NUM_0); axp2101 = std::make_shared<Axp2101>(controller);
aw9523 = std::make_shared<Aw9523>(controller);
return initPowerControl() && initGpioExpander(); return initPowerControl() && initGpioExpander();
} }

View File

@ -3,6 +3,7 @@
#include <tactility/bindings/root.h> #include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h> #include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h> #include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h> #include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h> #include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h> #include <tactility/bindings/esp32_spi.h>
@ -42,30 +43,34 @@
}; };
}; };
i2c_port_a { port_a: grove0 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
port = <I2C_NUM_1>; defaultMode = <GROVE_MODE_I2C>;
clock-frequency = <400000>; pinSdaRx = <&gpio0 2 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; pinSclTx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
}; };
i2c_port_b { port_b: grove1 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
status = "disabled"; defaultMode = <GROVE_MODE_UART>;
port = <I2C_NUM_1>; pinSdaRx = <&gpio0 9 GPIO_FLAG_NONE>;
clock-frequency = <400000>; pinSclTx = <&gpio0 8 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 9 GPIO_FLAG_NONE>; uartPort = <UART_NUM_1>;
pin-scl = <&gpio0 8 GPIO_FLAG_NONE>; i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
}; };
i2c_port_c { port_c: grove2 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
status = "disabled"; defaultMode = <GROVE_MODE_UART>;
port = <I2C_NUM_1>; pinSdaRx = <&gpio0 17 GPIO_FLAG_NONE>;
clock-frequency = <400000>; pinSclTx = <&gpio0 18 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 18 GPIO_FLAG_NONE>; uartPort = <UART_NUM_2>;
pin-scl = <&gpio0 17 GPIO_FLAG_NONE>; i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
}; };
spi0 { spi0 {
@ -89,12 +94,4 @@
pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>; pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 0 GPIO_FLAG_NONE>; pin-mclk = <&gpio0 0 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 {
compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>;
pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <&gpio0 2 GPIO_FLAG_NONE>;
};
}; };

View File

@ -231,7 +231,7 @@ bool initBoot() {
} }
// Keep Axp2101 C++ wrapper alive for Axp2101Power (backlight + battery) // Keep Axp2101 C++ wrapper alive for Axp2101Power (backlight + battery)
axp2101 = std::make_shared<Axp2101>(I2C_NUM_0); axp2101 = std::make_shared<Axp2101>(i2c);
return true; return true;
} }

View File

@ -67,30 +67,43 @@
// TODO: BMM150 magnetometer @ 0x10 — accessible only via BMI270 aux I2C // TODO: BMM150 magnetometer @ 0x10 — accessible only via BMI270 aux I2C
}; };
i2c_port_a { // TODO: Servo UART (SCS9009, 1 Mbaud) — TX=GPIO6, RX=GPIO7
compatible = "espressif,esp32-i2c"; uart_port_a: uart1 {
port = <I2C_NUM_1>; compatible = "espressif,esp32-uart";
clock-frequency = <400000>; status = "disabled";
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; port = <UART_NUM_1>;
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; pin-tx = <&gpio0 6 GPIO_FLAG_NONE>;
pin-rx = <&gpio0 7 GPIO_FLAG_NONE>;
}; };
i2c_port_b { port_a: grove0 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
status = "disabled"; defaultMode = <GROVE_MODE_I2C>;
port = <I2C_NUM_1>; pinSdaRx = <&gpio0 2 GPIO_FLAG_NONE>;
clock-frequency = <400000>; pinSclTx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 9 GPIO_FLAG_NONE>; uartPort = <UART_NUM_2>;
pin-scl = <&gpio0 8 GPIO_FLAG_NONE>; i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
}; };
i2c_port_c { port_b: grove1 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-grove";
status = "disabled"; defaultMode = <GROVE_MODE_UART>;
port = <I2C_NUM_1>; pinSdaRx = <&gpio0 9 GPIO_FLAG_NONE>;
clock-frequency = <400000>; pinSclTx = <&gpio0 8 GPIO_FLAG_NONE>;
pin-sda = <&gpio0 18 GPIO_FLAG_NONE>; uartPort = <UART_NUM_2>;
pin-scl = <&gpio0 17 GPIO_FLAG_NONE>; i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
};
port_c: grove2 {
compatible = "espressif,esp32-grove";
defaultMode = <GROVE_MODE_DISABLED>;
pinSdaRx = <&gpio0 17 GPIO_FLAG_NONE>;
pinSclTx = <&gpio0 18 GPIO_FLAG_NONE>;
uartPort = <UART_NUM_2>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
}; };
spi0 { spi0 {
@ -111,13 +124,4 @@
pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>; pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 0 GPIO_FLAG_NONE>; pin-mclk = <&gpio0 0 GPIO_FLAG_NONE>;
}; };
// TODO: Servo UART (SCS9009, 1 Mbaud) — TX=GPIO6, RX=GPIO7
uart_port_a: uart1 {
compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>;
pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <&gpio0 2 GPIO_FLAG_NONE>;
};
}; };

View File

@ -1,10 +1,11 @@
#include <Axp192.h> #include <Axp192.h>
#include <tactility/device.h>
static std::shared_ptr<Axp192> axp192 = nullptr; static std::shared_ptr<Axp192> axp192 = nullptr;
std::shared_ptr<Axp192> createAxp192() { std::shared_ptr<Axp192> createAxp192() {
assert(axp192 == nullptr); assert(axp192 == nullptr);
auto configuration = std::make_unique<Axp192::Configuration>(I2C_NUM_0); auto configuration = std::make_unique<Axp192::Configuration>(device_find_by_name("i2c_internal"));
axp192 = std::make_shared<Axp192>(std::move(configuration)); axp192 = std::make_shared<Axp192>(std::move(configuration));
return axp192; return axp192;
} }

View File

@ -1,4 +1,5 @@
#include "UnPhoneFeatures.h" #include "UnPhoneFeatures.h"
#include <tactility/device.h>
#include <Tactility/Logger.h> #include <Tactility/Logger.h>
#include <Tactility/LogMessages.h> #include <Tactility/LogMessages.h>
#include <Tactility/Preferences.h> #include <Tactility/Preferences.h>
@ -160,7 +161,7 @@ static bool unPhonePowerOn() {
bootStats.printInfo(); bootStats.printInfo();
bootStats.notifyBootStart(); bootStats.notifyBootStart();
bq24295 = std::make_shared<Bq24295>(I2C_NUM_0); bq24295 = std::make_shared<Bq24295>(device_find_by_name("i2c_internal"));
unPhoneFeatures = std::make_shared<UnPhoneFeatures>(bq24295); unPhoneFeatures = std::make_shared<UnPhoneFeatures>(bq24295);

View File

@ -8,7 +8,7 @@ class Aw9523 : public tt::hal::i2c::I2cDevice {
public: public:
explicit Aw9523(i2c_port_t port) : I2cDevice(port, AW9523_ADDRESS) {} explicit Aw9523(::Device* controller) : I2cDevice(controller, AW9523_ADDRESS) {}
std::string getName() const final { return "AW9523"; } std::string getName() const final { return "AW9523"; }
std::string getDescription() const final { return "GPIO expander with LED driver and I2C interface."; } std::string getDescription() const final { return "GPIO expander with LED driver and I2C interface."; }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <axp192/axp192.h> #include <axp192/axp192.h>
#include <tactility/device.h>
#include <Tactility/hal/power/PowerDevice.h> #include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/hal/i2c/I2c.h> #include <Tactility/hal/i2c/I2c.h>
@ -14,7 +15,7 @@ class Axp192 final : public tt::hal::power::PowerDevice {
public: public:
struct Configuration { struct Configuration {
i2c_port_t port; ::Device* controller;
TickType_t readTimeout = 50 / portTICK_PERIOD_MS; TickType_t readTimeout = 50 / portTICK_PERIOD_MS;
TickType_t writeTimeout = 50 / portTICK_PERIOD_MS; TickType_t writeTimeout = 50 / portTICK_PERIOD_MS;
}; };

View File

@ -1,10 +1,11 @@
#include "Axp192.h" #include "Axp192.h"
#include <tactility/drivers/i2c_controller.h>
constexpr auto TAG = "Axp192Power"; constexpr auto TAG = "Axp192Power";
int32_t Axp192::i2cRead(void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size) { int32_t Axp192::i2cRead(void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size) {
const auto* device = static_cast<Axp192*>(handle); const auto* device = static_cast<Axp192*>(handle);
if (tt::hal::i2c::masterReadRegister(device->configuration->port, address, reg, buffer, size, device->configuration->readTimeout)) { if (i2c_controller_read_register(device->configuration->controller, address, reg, buffer, size, device->configuration->readTimeout) == ERROR_NONE) {
return AXP192_OK; return AXP192_OK;
} else { } else {
return 1; return 1;
@ -13,7 +14,7 @@ int32_t Axp192::i2cRead(void* handle, uint8_t address, uint8_t reg, uint8_t* buf
int32_t Axp192::i2cWrite(void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size) { int32_t Axp192::i2cWrite(void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size) {
const auto* device = static_cast<Axp192*>(handle); const auto* device = static_cast<Axp192*>(handle);
if (tt::hal::i2c::masterWriteRegister(device->configuration->port, address, reg, buffer, size, device->configuration->writeTimeout)) { if (i2c_controller_write_register(device->configuration->controller, address, reg, buffer, size, device->configuration->writeTimeout) == ERROR_NONE) {
return AXP192_OK; return AXP192_OK;
} else { } else {
return 1; return 1;

View File

@ -54,5 +54,5 @@ bool Axp2101::getVBusVoltage(float& out) const {
} }
bool Axp2101::setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const { bool Axp2101::setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const {
return tt::hal::i2c::masterWriteRegisterArray(port, address, bytePairs, bytePairsSize, DEFAULT_TIMEOUT); return i2c_controller_write_register_array(controller, address, bytePairs, bytePairsSize, DEFAULT_TIMEOUT) == ERROR_NONE;
} }

View File

@ -19,7 +19,7 @@ public:
CHARGE_STATUS_STANDBY = 0b00 CHARGE_STATUS_STANDBY = 0b00
}; };
explicit Axp2101(i2c_port_t port) : I2cDevice(port, AXP2101_ADDRESS) {} explicit Axp2101(::Device* controller) : I2cDevice(controller, AXP2101_ADDRESS) {}
std::string getName() const override { return "AXP2101"; } std::string getName() const override { return "AXP2101"; }
std::string getDescription() const override { return "Power management with I2C interface."; } std::string getDescription() const override { return "Power management with I2C interface."; }

View File

@ -22,7 +22,7 @@ public:
Enabled160s = 0b110000 Enabled160s = 0b110000
}; };
explicit Bq24295(i2c_port_t port) : I2cDevice(port, BQ24295_ADDRESS) {} explicit Bq24295(::Device* controller) : I2cDevice(controller, BQ24295_ADDRESS) {}
bool getWatchDogTimer(WatchDogTimer& out) const; bool getWatchDogTimer(WatchDogTimer& out) const;
bool setWatchDogTimer(WatchDogTimer in) const; bool setWatchDogTimer(WatchDogTimer in) const;

View File

@ -8,7 +8,7 @@ class Bq25896 final : public tt::hal::i2c::I2cDevice {
public: public:
explicit Bq25896(i2c_port_t port) : I2cDevice(port, BQ25896_ADDRESS) { explicit Bq25896(::Device* controller) : I2cDevice(controller, BQ25896_ADDRESS) {
powerOn(); powerOn();
} }

View File

@ -89,7 +89,7 @@ public:
std::string getDescription() const override { return "I2C-controlled CEDV battery fuel gauge"; } std::string getDescription() const override { return "I2C-controlled CEDV battery fuel gauge"; }
explicit Bq27220(i2c_port_t port) : I2cDevice(port, BQ27220_ADDRESS), accessKey(0xFFFFFFFF) {} explicit Bq27220(::Device* controller) : I2cDevice(controller, BQ27220_ADDRESS), accessKey(0xFFFFFFFF) {}
bool configureCapacity(uint16_t designCapacity, uint16_t fullChargeCapacity); bool configureCapacity(uint16_t designCapacity, uint16_t fullChargeCapacity);
bool getVoltage(uint16_t &value); bool getVoltage(uint16_t &value);

View File

@ -5,7 +5,7 @@
static const auto LOGGER = tt::Logger("DRV2605"); static const auto LOGGER = tt::Logger("DRV2605");
Drv2605::Drv2605(i2c_port_t port, bool autoPlayStartupBuzz) : I2cDevice(port, ADDRESS), autoPlayStartupBuzz(autoPlayStartupBuzz) { Drv2605::Drv2605(::Device* controller, bool autoPlayStartupBuzz) : I2cDevice(controller, ADDRESS), autoPlayStartupBuzz(autoPlayStartupBuzz) {
check(init(), "Initialize DRV2605"); check(init(), "Initialize DRV2605");
if (autoPlayStartupBuzz) { if (autoPlayStartupBuzz) {

View File

@ -62,7 +62,7 @@ class Drv2605 : public tt::hal::i2c::I2cDevice {
public: public:
explicit Drv2605(i2c_port_t port, bool autoPlayStartupBuzz = true); explicit Drv2605(::Device* controller, bool autoPlayStartupBuzz = true);
std::string getName() const final { return "DRV2605"; } std::string getName() const final { return "DRV2605"; }
std::string getDescription() const final { return "Haptic driver for ERM/LRA with waveform library & auto-resonance tracking"; } std::string getDescription() const final { return "Haptic driver for ERM/LRA with waveform library & auto-resonance tracking"; }

View File

@ -2,6 +2,7 @@
#include <Tactility/hal/touch/TouchDevice.h> #include <Tactility/hal/touch/TouchDevice.h>
#include <Tactility/TactilityCore.h> #include <Tactility/TactilityCore.h>
#include <tactility/device.h>
#include <driver/i2c.h> #include <driver/i2c.h>
#include <EspLcdTouch.h> #include <EspLcdTouch.h>
@ -14,7 +15,7 @@ public:
public: public:
Configuration( Configuration(
i2c_port_t port, ::Device* controller,
uint16_t xMax, uint16_t xMax,
uint16_t yMax, uint16_t yMax,
bool swapXy = false, bool swapXy = false,
@ -24,7 +25,7 @@ public:
gpio_num_t pinInterrupt = GPIO_NUM_NC, gpio_num_t pinInterrupt = GPIO_NUM_NC,
unsigned int pinResetLevel = 0, unsigned int pinResetLevel = 0,
unsigned int pinInterruptLevel = 0 unsigned int pinInterruptLevel = 0
) : port(port), ) : controller(controller),
xMax(xMax), xMax(xMax),
yMax(yMax), yMax(yMax),
swapXy(swapXy), swapXy(swapXy),
@ -36,7 +37,7 @@ public:
pinInterruptLevel(pinInterruptLevel) pinInterruptLevel(pinInterruptLevel)
{} {}
i2c_port_t port; ::Device* controller;
uint16_t xMax; uint16_t xMax;
uint16_t yMax; uint16_t yMax;
bool swapXy; bool swapXy;

View File

@ -45,7 +45,7 @@ public:
std::string getDescription() const final { return "I2C-controlled keyboard scan IC"; } std::string getDescription() const final { return "I2C-controlled keyboard scan IC"; }
explicit Tca8418(i2c_port_t port) : I2cDevice(port, TCA8418_ADDRESS) { explicit Tca8418(::Device* controller) : I2cDevice(controller, TCA8418_ADDRESS) {
delta_micros = 0; delta_micros = 0;
last_update_micros = 0; last_update_micros = 0;
this_update_micros = 0; this_update_micros = 0;

View File

@ -7,14 +7,14 @@ properties:
type: int type: int
required: true required: true
description: "One of enum Esp32GroveMode" description: "One of enum Esp32GroveMode"
pinSclTx:
type: phandle-array
required: true
description: SCL (I2C) or TX (UART) pin
pinSdaRx: pinSdaRx:
type: phandle-array type: phandle-array
required: true required: true
description: SDA (I2C) or RX (UART) pin description: SDA (I2C) or RX (UART) pin
pinSclTx:
type: phandle-array
required: true
description: SCL (I2C) or TX (UART) pin
uartPort: uartPort:
type: int type: int
required: true required: true

View File

@ -12,8 +12,8 @@ extern "C" {
struct Esp32GroveConfig { struct Esp32GroveConfig {
enum GroveMode defaultMode; enum GroveMode defaultMode;
struct GpioPinSpec pinSclTx;
struct GpioPinSpec pinSdaRx; struct GpioPinSpec pinSdaRx;
struct GpioPinSpec pinSclTx;
uart_port_t uartPort; uart_port_t uartPort;
i2c_port_t i2cPort; i2c_port_t i2cPort;
uint32_t i2cClockFrequency; uint32_t i2cClockFrequency;

View File

@ -1,16 +1,16 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
#include <tactility/check.h>
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/driver.h> #include <tactility/driver.h>
#include <tactility/drivers/esp32_grove.h> #include <tactility/drivers/esp32_grove.h>
#include <tactility/drivers/esp32_i2c.h>
#include "../../../../TactilityKernel/include/tactility/check.h" #include <tactility/drivers/esp32_i2c_master.h>
#include <tactility/drivers/esp32_uart.h>
#include <tactility/log.h>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <new> #include <new>
#include <tactility/drivers/esp32_i2c.h>
#include <tactility/drivers/esp32_uart.h>
#include <tactility/log.h>
#define TAG "esp32_grove" #define TAG "esp32_grove"
@ -54,7 +54,7 @@ static error_t stop_child(Device* device) {
if (data->current_mode == GROVE_MODE_UART) { if (data->current_mode == GROVE_MODE_UART) {
delete static_cast<Esp32UartConfig*>(data->child_config); delete static_cast<Esp32UartConfig*>(data->child_config);
} else if (data->current_mode == GROVE_MODE_I2C) { } else if (data->current_mode == GROVE_MODE_I2C) {
delete static_cast<Esp32I2cConfig*>(data->child_config); delete static_cast<Esp32I2cMasterConfig*>(data->child_config);
} }
data->child_config = nullptr; data->child_config = nullptr;
} }
@ -89,13 +89,15 @@ static error_t start_child(Device* device, GroveMode mode) {
data->child_device = nullptr; data->child_device = nullptr;
return ERROR_OUT_OF_MEMORY; return ERROR_OUT_OF_MEMORY;
} }
std::snprintf(data->child_name, name_len, "%s_child", device->name);
data->child_device->name = data->child_name;
data->child_device->parent = device;
data->child_device->parent = device;
const char* compatible = nullptr; const char* compatible = nullptr;
if (mode == GROVE_MODE_UART) { if (mode == GROVE_MODE_UART) {
// Device name
std::snprintf(data->child_name, name_len, "%s_uart", device->name);
data->child_device->name = data->child_name;
// Device config
auto* uart_cfg = new(std::nothrow) struct Esp32UartConfig(); auto* uart_cfg = new(std::nothrow) struct Esp32UartConfig();
if (!uart_cfg) { if (!uart_cfg) {
delete[] data->child_name; delete[] data->child_name;
@ -114,7 +116,11 @@ static error_t start_child(Device* device, GroveMode mode) {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
LOG_I(TAG, "%s: starting UART mode on port %d", device->name, (int)uart_cfg->port); LOG_I(TAG, "%s: starting UART mode on port %d", device->name, (int)uart_cfg->port);
} else if (mode == GROVE_MODE_I2C) { } else if (mode == GROVE_MODE_I2C) {
auto* i2c_cfg = new(std::nothrow) struct Esp32I2cConfig(); // Device name
std::snprintf(data->child_name, name_len, "%s_i2c", device->name);
data->child_device->name = data->child_name;
// Device config
auto* i2c_cfg = new (std::nothrow) struct Esp32I2cMasterConfig();
if (!i2c_cfg) { if (!i2c_cfg) {
delete[] data->child_name; delete[] data->child_name;
data->child_name = nullptr; data->child_name = nullptr;
@ -122,18 +128,21 @@ static error_t start_child(Device* device, GroveMode mode) {
data->child_device = nullptr; data->child_device = nullptr;
return ERROR_OUT_OF_MEMORY; return ERROR_OUT_OF_MEMORY;
} }
std::memset(i2c_cfg, 0, sizeof(Esp32I2cConfig)); std::memset(i2c_cfg, 0, sizeof(Esp32I2cMasterConfig));
i2c_cfg->port = config->i2cPort; i2c_cfg->port = static_cast<i2c_port_num_t>(config->i2cPort);
i2c_cfg->clockFrequency = config->i2cClockFrequency; i2c_cfg->clockFrequency = config->i2cClockFrequency;
i2c_cfg->pinSda = config->pinSdaRx; i2c_cfg->pinSda = config->pinSdaRx;
i2c_cfg->pinScl = config->pinSclTx; i2c_cfg->pinScl = config->pinSclTx;
i2c_cfg->clkSource = 0; // Default
data->child_config = i2c_cfg; data->child_config = i2c_cfg;
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c-master";
LOG_I(TAG, "%s: starting I2C mode on port %d", device->name, (int)i2c_cfg->port); LOG_I(TAG, "%s: starting I2C mode on port %d", device->name, (int)config->i2cPort);
} else { } else {
LOG_E(TAG, "%s: unknown mode %d", device->name, mode); LOG_E(TAG, "%s: unknown mode %d", device->name, mode);
if (data->child_name != nullptr) {
delete[] data->child_name; delete[] data->child_name;
data->child_name = nullptr; data->child_name = nullptr;
}
delete data->child_device; delete data->child_device;
data->child_device = nullptr; data->child_device = nullptr;
return ERROR_INVALID_ARGUMENT; return ERROR_INVALID_ARGUMENT;
@ -154,6 +163,7 @@ static error_t start_child(Device* device, GroveMode mode) {
static error_t start_device(Device* device) { static error_t start_device(Device* device) {
const auto* config = GET_CONFIG(device); const auto* config = GET_CONFIG(device);
auto* data = new(std::nothrow) Esp32GroveInternal(); auto* data = new(std::nothrow) Esp32GroveInternal();
if (!data) return ERROR_OUT_OF_MEMORY; if (!data) return ERROR_OUT_OF_MEMORY;
device_set_driver_data(device, data); device_set_driver_data(device, data);

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <tactility/hal/Device.h> #include <tactility/hal/Device.h>
#include <tactility/drivers/i2c_controller.h>
#include "I2c.h" #include "I2c.h"
namespace tt::hal::i2c { namespace tt::hal::i2c {
@ -15,7 +16,7 @@ class I2cDevice : public Device {
protected: protected:
i2c_port_t port; ::Device* controller;
uint8_t address; uint8_t address;
static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS; static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS;
@ -36,11 +37,11 @@ protected:
public: public:
explicit I2cDevice(i2c_port_t port, uint32_t address) : port(port), address(address) {} explicit I2cDevice(::Device* controller, uint32_t address) : controller(controller), address(address) {}
Type getType() const override { return Type::I2c; } Type getType() const override { return Type::I2c; }
i2c_port_t getPort() const { return port; } ::Device* getController() const { return controller; }
uint8_t getAddress() const { return address; } uint8_t getAddress() const { return address; }
}; };

View File

@ -3,12 +3,14 @@
#include <string> #include <string>
#include <cstdint> #include <cstdint>
struct Device;
namespace tt::app::i2cscanner { namespace tt::app::i2cscanner {
std::string getAddressText(uint8_t address); std::string getAddressText(uint8_t address);
std::string getPortNamesForDropdown(); std::string getPortNamesForDropdown();
bool getActivePortAtIndex(int32_t index, int32_t& out); bool getActivePortAtIndex(int32_t index, struct Device** out);
} }

View File

@ -1,7 +1,8 @@
#include "Tactility/app/i2cscanner/I2cHelpers.h" #include "Tactility/app/i2cscanner/I2cHelpers.h"
#include <Tactility/StringUtils.h> #include <Tactility/StringUtils.h>
#include <Tactility/hal/i2c/I2c.h>
#include <tactility/drivers/i2c_controller.h>
#include <iomanip> #include <iomanip>
#include <vector> #include <vector>
@ -19,31 +20,36 @@ std::string getAddressText(uint8_t address) {
std::string getPortNamesForDropdown() { std::string getPortNamesForDropdown() {
std::vector<std::string> config_names; std::vector<std::string> config_names;
for (int port = 0; port < I2C_NUM_MAX; ++port) { device_for_each_of_type(&I2C_CONTROLLER_TYPE, &config_names, [](auto* device, auto* context) {
auto native_port = static_cast<i2c_port_t>(port); auto* names = static_cast<std::vector<std::string>*>(context);
if (hal::i2c::isStarted(native_port)) { if (device_is_ready(device)) {
auto* name = hal::i2c::getName(native_port); names->push_back(device->name);
if (name != nullptr) {
config_names.push_back(name);
}
}
} }
return true;
});
return string::join(config_names, "\n"); return string::join(config_names, "\n");
} }
bool getActivePortAtIndex(int32_t index, int32_t& out) { bool getActivePortAtIndex(int32_t index, struct Device** out) {
int current_index = -1; struct Context {
for (int port = 0; port < I2C_NUM_MAX; ++port) { int32_t targetIndex;
auto native_port = static_cast<i2c_port_t>(port); int32_t currentIndex;
if (hal::i2c::isStarted(native_port)) { struct Device* foundDevice;
current_index++; } context = { index, 0, nullptr };
if (current_index == index) {
out = port; device_for_each_of_type(&I2C_CONTROLLER_TYPE, &context, [](auto* device, auto* ctx) {
return true; auto* c = static_cast<Context*>(ctx);
} if (device_is_ready(device)) {
} if (c->currentIndex == c->targetIndex) {
} c->foundDevice = device;
return false; return false;
} }
c->currentIndex++;
}
return true;
});
*out = context.foundDevice;
return context.foundDevice != nullptr;
}
} }

View File

@ -3,7 +3,7 @@
#include <Tactility/Assets.h> #include <Tactility/Assets.h>
#include <Tactility/app/AppContext.h> #include <Tactility/app/AppContext.h>
#include <Tactility/hal/i2c/I2cDevice.h> #include <tactility/drivers/i2c_controller.h>
#include <Tactility/Logger.h> #include <Tactility/Logger.h>
#include <Tactility/LogMessages.h> #include <Tactility/LogMessages.h>
#include <Tactility/lvgl/LvglSync.h> #include <Tactility/lvgl/LvglSync.h>
@ -33,7 +33,7 @@ class I2cScannerApp final : public App {
std::unique_ptr<Timer> scanTimer = nullptr; std::unique_ptr<Timer> scanTimer = nullptr;
// State // State
ScanState scanState = ScanStateInitial; ScanState scanState = ScanStateInitial;
i2c_port_t port = I2C_NUM_0; struct Device* portDevice = nullptr;
std::vector<uint8_t> scannedAddresses; std::vector<uint8_t> scannedAddresses;
// Widgets // Widgets
lv_obj_t* scanButtonLabelWidget = nullptr; lv_obj_t* scanButtonLabelWidget = nullptr;
@ -54,7 +54,7 @@ class I2cScannerApp final : public App {
void onScanTimer(); void onScanTimer();
bool shouldStopScanTimer(); bool shouldStopScanTimer();
bool getPort(i2c_port_t* outPort); bool getPort(struct Device** outPort);
bool addAddressToList(uint8_t address); bool addAddressToList(uint8_t address);
bool hasScanThread(); bool hasScanThread();
void startScanning(); void startScanning();
@ -140,8 +140,10 @@ void I2cScannerApp::onShow(AppContext& app, lv_obj_t* parent) {
lv_obj_add_flag(scan_list, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(scan_list, LV_OBJ_FLAG_HIDDEN);
scanListWidget = scan_list; scanListWidget = scan_list;
int32_t first_port; struct Device* dummy;
if (getActivePortAtIndex(0, first_port)) { if (getActivePortAtIndex(selected_bus, &dummy)) {
selectBus(selected_bus);
} else if (getActivePortAtIndex(0, &dummy)) {
lv_dropdown_set_selected(port_dropdown, 0); lv_dropdown_set_selected(port_dropdown, 0);
selectBus(0); selectBus(0);
} }
@ -184,9 +186,9 @@ void I2cScannerApp::onPressScanCallback(lv_event_t* event) {
// endregion Callbacks // endregion Callbacks
bool I2cScannerApp::getPort(i2c_port_t* outPort) { bool I2cScannerApp::getPort(struct Device** outPort) {
if (mutex.lock(100 / portTICK_PERIOD_MS)) { if (mutex.lock(100 / portTICK_PERIOD_MS)) {
*outPort = this->port; *outPort = this->portDevice;
mutex.unlock(); mutex.unlock();
return true; return true;
} else { } else {
@ -219,21 +221,21 @@ bool I2cScannerApp::shouldStopScanTimer() {
void I2cScannerApp::onScanTimer() { void I2cScannerApp::onScanTimer() {
logger.info("Scan thread started"); logger.info("Scan thread started");
i2c_port_t safe_port; struct Device* safe_port;
if (!getPort(&safe_port)) { if (!getPort(&safe_port)) {
logger.error("Failed to get I2C port"); logger.error("Failed to get I2C port");
onScanTimerFinished(); onScanTimerFinished();
return; return;
} }
if (!hal::i2c::isStarted(safe_port)) { if (!device_is_ready(safe_port)) {
logger.error("I2C port not started"); logger.error("I2C port not started");
onScanTimerFinished(); onScanTimerFinished();
return; return;
} }
for (uint8_t address = 0; address < 128; ++address) { for (uint8_t address = 0; address < 128; ++address) {
if (hal::i2c::masterHasDeviceAtAddress(safe_port, address, 10 / portTICK_PERIOD_MS)) { if (i2c_controller_has_device_at_address(safe_port, address, 10 / portTICK_PERIOD_MS) == ERROR_NONE) {
logger.info("Found device at address 0x{:02X}", address); logger.info("Found device at address 0x{:02X}", address);
if (!shouldStopScanTimer()) { if (!shouldStopScanTimer()) {
addAddressToList(address); addAddressToList(address);
@ -305,14 +307,14 @@ void I2cScannerApp::onSelectBus(lv_event_t* event) {
} }
void I2cScannerApp::selectBus(int32_t selected) { void I2cScannerApp::selectBus(int32_t selected) {
int32_t found_port; struct Device* found_device;
if (!getActivePortAtIndex(selected, found_port)) { if (!getActivePortAtIndex(selected, &found_device)) {
return; return;
} }
if (mutex.lock(100 / portTICK_PERIOD_MS)) { if (mutex.lock(100 / portTICK_PERIOD_MS)) {
scannedAddresses.clear(); scannedAddresses.clear();
port = static_cast<i2c_port_t>(found_port); portDevice = found_device;
scanState = ScanStateInitial; scanState = ScanStateInitial;
mutex.unlock(); mutex.unlock();
} }
@ -334,16 +336,6 @@ void I2cScannerApp::onPressScan(lv_event_t* event) {
updateViews(); updateViews();
} }
static bool findDeviceName(const std::vector<std::shared_ptr<hal::i2c::I2cDevice>>& devices, i2c_port_t port, uint8_t address, std::string& outName) {
for (auto& device : devices) {
if (device->getPort() == port && device->getAddress() == address) {
outName = device->getName();
return true;
}
}
return false;
}
void I2cScannerApp::updateViews() { void I2cScannerApp::updateViews() {
if (mutex.lock(100 / portTICK_PERIOD_MS)) { if (mutex.lock(100 / portTICK_PERIOD_MS)) {
if (scanState == ScanStateScanning) { if (scanState == ScanStateScanning) {
@ -358,19 +350,11 @@ void I2cScannerApp::updateViews() {
if (scanState == ScanStateStopped) { if (scanState == ScanStateStopped) {
lv_obj_remove_flag(scanListWidget, LV_OBJ_FLAG_HIDDEN); lv_obj_remove_flag(scanListWidget, LV_OBJ_FLAG_HIDDEN);
auto devices = hal::findDevices<hal::i2c::I2cDevice>(hal::Device::Type::I2c);
if (!scannedAddresses.empty()) { if (!scannedAddresses.empty()) {
for (auto address: scannedAddresses) { for (auto address: scannedAddresses) {
std::string address_text = getAddressText(address); std::string address_text = getAddressText(address);
std::string device_name;
if (findDeviceName(devices, port, address, device_name)) {
auto text = std::format("{} - {}", address_text, device_name);
lv_list_add_text(scanListWidget, text.c_str());
} else {
lv_list_add_text(scanListWidget, address_text.c_str()); lv_list_add_text(scanListWidget, address_text.c_str());
} }
}
} else { } else {
lv_list_add_text(scanListWidget, "No devices found"); lv_list_add_text(scanListWidget, "No devices found");
} }

View File

@ -5,24 +5,24 @@
namespace tt::hal::i2c { namespace tt::hal::i2c {
bool I2cDevice::read(uint8_t* data, size_t dataSize, TickType_t timeout) { bool I2cDevice::read(uint8_t* data, size_t dataSize, TickType_t timeout) {
return masterRead(port, address, data, dataSize, timeout); return i2c_controller_read(controller, address, data, dataSize, timeout) == ERROR_NONE;
} }
bool I2cDevice::write(const uint8_t* data, uint16_t dataSize, TickType_t timeout) { bool I2cDevice::write(const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
return masterWrite(port, address, data, dataSize, timeout); return i2c_controller_write(controller, address, data, dataSize, timeout) == ERROR_NONE;
} }
bool I2cDevice::writeRead(const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) { bool I2cDevice::writeRead(const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) {
return masterWriteRead(port, address, writeData, writeDataSize, readData, readDataSize, timeout); return i2c_controller_write_read(controller, address, writeData, writeDataSize, readData, readDataSize, timeout) == ERROR_NONE;
} }
bool I2cDevice::writeRegister(uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) { bool I2cDevice::writeRegister(uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
return masterWriteRegister(port, address, reg, data, dataSize, timeout); return i2c_controller_write_register(controller, address, reg, data, dataSize, timeout) == ERROR_NONE;
} }
bool I2cDevice::readRegister12(uint8_t reg, float& out) const { bool I2cDevice::readRegister12(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0}; std::uint8_t data[2] = {0};
if (masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT)) { if (i2c_controller_read_register(controller, address, reg, data, 2, DEFAULT_TIMEOUT) == ERROR_NONE) {
out = (data[0] & 0x0F) << 8 | data[1]; out = (data[0] & 0x0F) << 8 | data[1];
return true; return true;
} else { } else {
@ -32,7 +32,7 @@ bool I2cDevice::readRegister12(uint8_t reg, float& out) const {
bool I2cDevice::readRegister14(uint8_t reg, float& out) const { bool I2cDevice::readRegister14(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0}; std::uint8_t data[2] = {0};
if (masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT)) { if (i2c_controller_read_register(controller, address, reg, data, 2, DEFAULT_TIMEOUT) == ERROR_NONE) {
out = (data[0] & 0x3F) << 8 | data[1]; out = (data[0] & 0x3F) << 8 | data[1];
return true; return true;
} else { } else {
@ -42,7 +42,7 @@ bool I2cDevice::readRegister14(uint8_t reg, float& out) const {
bool I2cDevice::readRegister16(uint8_t reg, uint16_t& out) const { bool I2cDevice::readRegister16(uint8_t reg, uint16_t& out) const {
std::uint8_t data[2] = {0}; std::uint8_t data[2] = {0};
if (masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT)) { if (i2c_controller_read_register(controller, address, reg, data, 2, DEFAULT_TIMEOUT) == ERROR_NONE) {
out = data[0] << 8 | data[1]; out = data[0] << 8 | data[1];
return true; return true;
} else { } else {
@ -51,11 +51,11 @@ bool I2cDevice::readRegister16(uint8_t reg, uint16_t& out) const {
} }
bool I2cDevice::readRegister8(uint8_t reg, uint8_t& result) const { bool I2cDevice::readRegister8(uint8_t reg, uint8_t& result) const {
return masterWriteRead(port, address, &reg, 1, &result, 1, DEFAULT_TIMEOUT); return i2c_controller_write_read(controller, address, &reg, 1, &result, 1, DEFAULT_TIMEOUT) == ERROR_NONE;
} }
bool I2cDevice::writeRegister8(uint8_t reg, uint8_t value) const { bool I2cDevice::writeRegister8(uint8_t reg, uint8_t value) const {
return masterWriteRegister(port, address, reg, &value, 1, DEFAULT_TIMEOUT); return i2c_controller_write_register(controller, address, reg, &value, 1, DEFAULT_TIMEOUT) == ERROR_NONE;
} }
bool I2cDevice::bitOn(uint8_t reg, uint8_t bitmask) const { bool I2cDevice::bitOn(uint8_t reg, uint8_t bitmask) const {

View File

@ -19,6 +19,9 @@ enum GroveMode {
/** /**
* @brief API for Grove drivers. * @brief API for Grove drivers.
*
* The grove driver is meant for external interfaces with two wires that can be used as UART, I2C or GPIO as needed.
* It can be used with the Grove connector, but also with others such as Stemma QT.
*/ */
struct GroveApi { struct GroveApi {
/** /**