Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Devices/lilygo-tdeck/Source/Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool initBoot() {
std::vector<tt::hal::gps::GpsConfiguration> gps_configurations;
gps_service->getGpsConfigurations(gps_configurations);
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");
} else {
LOGGER.error("Failed to configure internal GPS");
Expand Down
12 changes: 2 additions & 10 deletions Devices/lilygo-tdeck/lilygo,tdeck.dts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h>
Expand Down Expand Up @@ -30,15 +31,6 @@
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 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
Expand All @@ -55,7 +47,7 @@
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
};

uart1 {
uart0 {
compatible = "espressif,esp32-uart";
port = <UART_NUM_1>;
pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
Expand Down
10 changes: 6 additions & 4 deletions Devices/lilygo-tlora-pager/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "devices/TpagerKeyboard.h"
#include "devices/TpagerPower.h"
#include <driver/gpio.h>
#include <tactility/device.h>

#include <Tactility/hal/Configuration.h>
#include <Bq25896.h>
Expand All @@ -14,17 +15,18 @@ bool tpagerInit();
using namespace tt::hal;

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 tca8418 = std::make_shared<Tca8418>(I2C_NUM_0);
auto tca8418 = std::make_shared<Tca8418>(i2c);
auto keyboard = std::make_shared<TpagerKeyboard>(tca8418);

return std::vector<std::shared_ptr<tt::hal::Device>> {
tca8418,
std::make_shared<Bq25896>(I2C_NUM_0),
std::make_shared<Bq25896>(i2c),
bq27220,
std::make_shared<Drv2605>(I2C_NUM_0),
std::make_shared<Drv2605>(i2c),
Comment on lines +18 to +29

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Missing null validation on device_find_by_name across multiple device initialization paths.

In Devices/lilygo-tlora-pager/Source/Configuration.cpp, Devices/m5stack-cardputer-adv/Source/Configuration.cpp, Devices/m5stack-core2/Source/devices/Power.cpp, and Devices/m5stack-cores3/Source/InitBoot.cpp, calls to device_find_by_name do not validate the returned pointer before passing it to driver constructors. If the I2C controller device is not found or not ready, a nullptr will be passed to the drivers, causing crashes during I2C operations. The shared root cause is the lack of a null check after device_find_by_name; each file should validate the controller pointer and handle the error case (e.g., log an error and return early or return an empty device list).

power,
createTpagerSdCard(),
createDisplay(),
Expand Down
3 changes: 2 additions & 1 deletion Devices/m5stack-cardputer-adv/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "devices/CardputerPower.h"
#include <driver/gpio.h>

#include <tactility/device.h>
#include <Tactility/hal/Configuration.h>

#include <PwmBacklight.h>
Expand All @@ -16,7 +17,7 @@ static bool initBoot() {
}

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 {
createSdCard(),
createDisplay(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "CardputerKeyboard.h"
#include <Tactility/hal/i2c/I2c.h>
#include <tactility/drivers/i2c_controller.h>

constexpr auto* TAG = "CardputerKeyb";

Expand Down Expand Up @@ -151,5 +151,5 @@ bool CardputerKeyboard::stopLvgl() {
}

bool CardputerKeyboard::isAttached() const {
return tt::hal::i2c::masterHasDeviceAtAddress(keypad->getPort(), keypad->getAddress(), 100);
return i2c_controller_has_device_at_address(keypad->getController(), keypad->getAddress(), 100) == ERROR_NONE;
}
23 changes: 9 additions & 14 deletions Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h>
Expand Down Expand Up @@ -36,12 +37,14 @@
};
};

i2c_port_a {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>;
clock-frequency = <400000>;
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
port_a: grove0 {
compatible = "espressif,esp32-grove";
defaultMode = <GROVE_MODE_I2C>;
pinSdaRx = <&gpio0 2 GPIO_FLAG_NONE>;
pinSclTx = <&gpio0 1 GPIO_FLAG_NONE>;
uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
};

display_spi: spi0 {
Expand All @@ -68,12 +71,4 @@
pin-data-out = <&gpio0 42 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>;
};
};
23 changes: 9 additions & 14 deletions Devices/m5stack-cardputer/m5stack,cardputer.dts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h>
Expand All @@ -22,12 +23,14 @@
gpio-count = <49>;
};

i2c_port_a {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>;
clock-frequency = <400000>;
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
port_a: grove0 {
compatible = "espressif,esp32-grove";
defaultMode = <GROVE_MODE_I2C>;
pinSdaRx = <&gpio0 2 GPIO_FLAG_NONE>;
pinSclTx = <&gpio0 1 GPIO_FLAG_NONE>;
uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_0>;
i2cClockFrequency = <400000>;
};

display_spi: spi0 {
Expand Down Expand Up @@ -55,12 +58,4 @@
pin-data-out = <&gpio0 42 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>;
};
};
3 changes: 2 additions & 1 deletion Devices/m5stack-core2/Source/devices/Power.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <Axp192.h>
#include <tactility/device.h>

static std::shared_ptr<Axp192> axp192 = nullptr;

std::shared_ptr<Axp192> createAxp192() {
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));
return axp192;
}
Expand Down
23 changes: 9 additions & 14 deletions Devices/m5stack-core2/m5stack,core2.dts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h>
Expand Down Expand Up @@ -37,12 +38,14 @@
};
};

i2c_port_a {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>;
clock-frequency = <400000>;
pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
port_a: grove0 {
compatible = "espressif,esp32-grove";
defaultMode = <GROVE_MODE_I2C>;
pinSdaRx = <&gpio0 32 GPIO_FLAG_NONE>;
pinSclTx = <&gpio0 33 GPIO_FLAG_NONE>;
uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
};

spi0 {
Expand All @@ -63,12 +66,4 @@
pin-data-out = <&gpio0 2 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>;
};
};
5 changes: 3 additions & 2 deletions Devices/m5stack-cores3/Source/InitBoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ bool initPowerControl() {
bool initBoot() {
LOGGER.info("initBoot()");

axp2101 = std::make_shared<Axp2101>(I2C_NUM_0);
aw9523 = std::make_shared<Aw9523>(I2C_NUM_0);
auto controller = device_find_by_name("i2c_internal");
axp2101 = std::make_shared<Axp2101>(controller);
aw9523 = std::make_shared<Aw9523>(controller);

return initPowerControl() && initGpioExpander();
}
53 changes: 25 additions & 28 deletions Devices/m5stack-cores3/m5stack,cores3.dts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_grove.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h>
Expand Down Expand Up @@ -42,30 +43,34 @@
};
};

i2c_port_a {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>;
clock-frequency = <400000>;
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
port_a: grove0 {
compatible = "espressif,esp32-grove";
defaultMode = <GROVE_MODE_I2C>;
pinSdaRx = <&gpio0 2 GPIO_FLAG_NONE>;
pinSclTx = <&gpio0 1 GPIO_FLAG_NONE>;
uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
};

i2c_port_b {
compatible = "espressif,esp32-i2c";
status = "disabled";
port = <I2C_NUM_1>;
clock-frequency = <400000>;
pin-sda = <&gpio0 9 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
port_b: grove1 {
compatible = "espressif,esp32-grove";
defaultMode = <GROVE_MODE_UART>;
pinSdaRx = <&gpio0 9 GPIO_FLAG_NONE>;
pinSclTx = <&gpio0 8 GPIO_FLAG_NONE>;
uartPort = <UART_NUM_1>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
};

i2c_port_c {
compatible = "espressif,esp32-i2c";
status = "disabled";
port = <I2C_NUM_1>;
clock-frequency = <400000>;
pin-sda = <&gpio0 18 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 17 GPIO_FLAG_NONE>;
port_c: grove2 {
compatible = "espressif,esp32-grove";
defaultMode = <GROVE_MODE_UART>;
pinSdaRx = <&gpio0 17 GPIO_FLAG_NONE>;
pinSclTx = <&gpio0 18 GPIO_FLAG_NONE>;
uartPort = <UART_NUM_2>;
i2cPort = <I2C_NUM_1>;
i2cClockFrequency = <400000>;
};

spi0 {
Expand All @@ -89,12 +94,4 @@
pin-data-in = <&gpio0 14 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>;
};
};
2 changes: 1 addition & 1 deletion Devices/m5stack-stackchan/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ bool initBoot() {
}

// 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;
}

Expand Down
Loading
Loading