New logging and more (#446)

- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>`
- Changed default timezone to Europe/Amsterdam
- Fix for logic bug in unPhone hardware
- Fix for init/deinit in DRV2605 driver
- Other fixes
- Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
Ken Van Hoeylandt
2026-01-06 22:35:39 +01:00
committed by GitHub
parent 719f7bcece
commit f620255c41
188 changed files with 1973 additions and 1755 deletions
-1
View File
@@ -1,5 +1,4 @@
#include "Axp2101.h"
#include <Tactility/Log.h>
bool Axp2101::getBatteryVoltage(float& vbatMillis) const {
return readRegister14(0x34, vbatMillis);
+6 -6
View File
@@ -1,7 +1,7 @@
#include "Bq24295.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#define TAG "bq24295"
static const auto LOGGER = tt::Logger("BQ24295");
/** Reference:
* https://www.ti.com/lit/ds/symlink/bq24295.pdf
@@ -49,8 +49,8 @@ bool Bq24295::setWatchDogTimer(WatchDogTimer in) const {
if (readChargeTermination(value)) {
uint8_t bits_to_set = 0b00110000 & static_cast<uint8_t>(in);
uint8_t value_cleared = value & 0b11001111;
uint8_t to_set = bits_to_set & value_cleared;
TT_LOG_I(TAG, "WatchDogTimer: %02x -> %02x", value, to_set);
uint8_t to_set = bits_to_set | value_cleared;
LOGGER.info("WatchDogTimer: {:02x} -> {:02x}", value, to_set);
return writeRegister8(registers::CHARGE_TERMINATION, to_set);
}
@@ -96,9 +96,9 @@ bool Bq24295::getVersion(uint8_t& value) const {
void Bq24295::printInfo() const {
uint8_t version, status, charge_termination;
if (getStatus(status) && getVersion(version) && readChargeTermination(charge_termination)) {
TT_LOG_I(TAG, "Version %d, status %02x, charge termination %02x", version, status, charge_termination);
LOGGER.info("Version {}, status {:02x}, charge termination {:02x}", version, status, charge_termination);
} else {
TT_LOG_E(TAG, "Failed to retrieve version and/or status");
LOGGER.error("Failed to retrieve version and/or status");
}
}
-1
View File
@@ -6,7 +6,6 @@
class Bq24295 final : public tt::hal::i2c::I2cDevice {
private:
bool readChargeTermination(uint8_t& out) const;
+4 -4
View File
@@ -1,15 +1,15 @@
#include "Bq25896.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
constexpr auto* TAG = "BQ25896";
static const auto LOGGER = tt::Logger("BQ25896");
void Bq25896::powerOff() {
TT_LOG_I(TAG, "Power off");
LOGGER.info("Power off");
bitOn(0x09, BIT(5));
}
void Bq25896::powerOn() {
TT_LOG_I(TAG, "Power on");
LOGGER.info("Power on");
bitOff(0x09, BIT(5));
}
+12 -12
View File
@@ -1,9 +1,9 @@
#include "Bq27220.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include "esp_sleep.h"
#define TAG "bq27220"
static const auto LOGGER = tt::Logger("BQ27220");
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
@@ -93,14 +93,14 @@ bool Bq27220::configureCapacity(uint16_t designCapacity, uint16_t fullChargeCapa
return performConfigUpdate([this, designCapacity, fullChargeCapacity]() {
// Set the design capacity
if (!writeConfig16(registers::ROM_DESIGN_CAPACITY, designCapacity)) {
TT_LOG_E(TAG, "Failed to set design capacity!");
LOGGER.error("Failed to set design capacity!");
return false;
}
vTaskDelay(10 / portTICK_PERIOD_MS);
// Set full charge capacity
if (!writeConfig16(registers::ROM_FULL_CHARGE_CAPACITY, fullChargeCapacity)) {
TT_LOG_E(TAG, "Failed to set full charge capacity!");
LOGGER.error("Failed to set full charge capacity!");
return false;
}
vTaskDelay(10 / portTICK_PERIOD_MS);
@@ -260,7 +260,7 @@ bool Bq27220::sendSubCommand(uint16_t subCmd, bool waitConfirm)
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}
TT_LOG_E(TAG, "Subcommand x%X failed!", subCmd);
LOGGER.error("Subcommand 0x{:04X} failed!", subCmd);
return false;
}
@@ -298,28 +298,28 @@ bool Bq27220::configPreamble(bool &isSealed) {
// Check access settings
if(!getOperationStatus(status)) {
TT_LOG_E(TAG, "Cannot read initial operation status!");
LOGGER.error("Cannot read initial operation status!");
return false;
}
if (status.reg.SEC == OperationStatusSecSealed) {
isSealed = true;
if (!unsealDevice()) {
TT_LOG_E(TAG, "Unsealing device failure!");
LOGGER.error("Unsealing device failure!");
return false;
}
}
if (status.reg.SEC != OperationStatusSecFull) {
if (!unsealFullAccess()) {
TT_LOG_E(TAG, "Unsealing full access failure!");
LOGGER.error("Unsealing full access failure!");
return false;
}
}
// Send ENTER_CFG_UPDATE command (0x0090)
if (!sendSubCommand(registers::SUBCMD_ENTER_CFG_UPDATE)) {
TT_LOG_E(TAG, "Config Update Subcommand failure!");
LOGGER.error("Config Update Subcommand failure!");
}
// Confirm CFUPDATE mode by polling the OperationStatus() register until Bit 2 is set.
@@ -333,7 +333,7 @@ bool Bq27220::configPreamble(bool &isSealed) {
vTaskDelay(100 / portTICK_PERIOD_MS);
}
if (!isConfigUpdate) {
TT_LOG_E(TAG, "Update Mode timeout, maybe the access key for full permissions is invalid!");
LOGGER.error("Update Mode timeout, maybe the access key for full permissions is invalid!");
return false;
}
@@ -357,13 +357,13 @@ bool Bq27220::configEpilouge(const bool isSealed) {
vTaskDelay(100 / portTICK_PERIOD_MS);
}
if (timeout == 0) {
TT_LOG_E(TAG, "Timed out waiting to exit update mode.");
LOGGER.error("Timed out waiting to exit update mode.");
return false;
}
// If the device was previously in SEALED state, return to SEALED mode by sending the Control(0x0030) subcommand
if (isSealed) {
TT_LOG_D(TAG, "Restore Safe Mode!");
LOGGER.debug("Restore Safe Mode!");
exitSealMode();
}
return true;
@@ -1,10 +1,10 @@
#include "ButtonControl.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_lvgl_port.h>
constexpr auto* TAG = "ButtonControl";
static const auto LOGGER = tt::Logger("ButtonControl");
ButtonControl::ButtonControl(const std::vector<PinConfiguration>& pinConfigurations) : pinConfigurations(pinConfigurations) {
pinStates.resize(pinConfigurations.size());
@@ -73,7 +73,7 @@ void ButtonControl::updatePin(std::vector<PinConfiguration>::const_reference con
if (state.pressState) {
auto time_passed = tt::kernel::getMillis() - state.pressStartTime;
if (time_passed < 500) {
TT_LOG_D(TAG, "Trigger short press");
LOGGER.debug("Trigger short press");
state.triggerShortPress = true;
}
state.pressState = false;
@@ -103,7 +103,7 @@ bool ButtonControl::shouldInterruptDriverThread() const {
}
void ButtonControl::startThread() {
TT_LOG_I(TAG, "Start");
LOGGER.info("Start");
mutex.lock();
@@ -120,7 +120,7 @@ void ButtonControl::startThread() {
}
void ButtonControl::stopThread() {
TT_LOG_I(TAG, "Stop");
LOGGER.info("Stop");
mutex.lock();
interruptDriverThread = true;
@@ -3,6 +3,7 @@
#include <Tactility/hal/encoder/EncoderDevice.h>
#include <Tactility/hal/gpio/Gpio.h>
#include <Tactility/TactilityCore.h>
#include <Tactility/Thread.h>
class ButtonControl final : public tt::hal::encoder::EncoderDevice {
+20 -3
View File
@@ -1,16 +1,33 @@
#include "Drv2605.h"
#include <Tactility/Check.h>
#include <Tactility/Logger.h>
static const auto LOGGER = tt::Logger("DRV2605");
Drv2605::Drv2605(i2c_port_t port, bool autoPlayStartupBuzz) : I2cDevice(port, ADDRESS), autoPlayStartupBuzz(autoPlayStartupBuzz) {
if (!init()) {
LOGGER.error("Failed to initialize DRV2605");
tt_crash();
}
if (autoPlayStartupBuzz) {
setWaveFormForBuzz();
startPlayback();
}
}
bool Drv2605::init() {
uint8_t status;
if (!readRegister8(static_cast<uint8_t>(Register::Status), status)) {
TT_LOG_E(TAG, "Failed to read status");
LOGGER.error("Failed to read status");
return false;
}
status >>= 5;
ChipId chip_id = static_cast<ChipId>(status);
if (chip_id != ChipId::DRV2604 && chip_id != ChipId::DRV2604L && chip_id != ChipId::DRV2605 && chip_id != ChipId::DRV2605L) {
TT_LOG_E(TAG, "Unknown chip id %02x", chip_id);
LOGGER.error("Unknown chip id {:02x}", static_cast<uint8_t>(chip_id));
return false;
}
@@ -25,7 +42,7 @@ bool Drv2605::init() {
uint8_t feedback;
if (!readRegister(Register::Feedback, feedback)) {
TT_LOG_E(TAG, "Failed to read feedback");
LOGGER.error("Failed to read feedback");
return false;
}
+1 -13
View File
@@ -1,11 +1,9 @@
#pragma once
#include <Tactility/hal/i2c/I2cDevice.h>
#include <Tactility/Log.h>
class Drv2605 : public tt::hal::i2c::I2cDevice {
static constexpr auto* TAG = "DRV2605";
static constexpr auto ADDRESS = 0x5A;
bool autoPlayStartupBuzz;
@@ -64,16 +62,7 @@ class Drv2605 : public tt::hal::i2c::I2cDevice {
public:
explicit Drv2605(i2c_port_t port, bool autoPlayStartupBuzz = true) : I2cDevice(port, ADDRESS), autoPlayStartupBuzz(autoPlayStartupBuzz) {
if (!init()) {
TT_LOG_E(TAG, "Failed to initialize DRV2605");
}
if (autoPlayStartupBuzz) {
setWaveFormForBuzz();
startPlayback();
}
}
explicit Drv2605(i2c_port_t port, bool autoPlayStartupBuzz = true);
std::string getName() const final { return "DRV2605"; }
std::string getDescription() const final { return "Haptic driver for ERM/LRA with waveform library & auto-resonance tracking"; }
@@ -84,7 +73,6 @@ public:
void setWaveFormForClick();
/**
*
* @param slot a value from 0 to 7
* @param waveform
*/
@@ -1,13 +1,13 @@
#include "EspLcdDisplay.h"
#include "EspLcdDisplayDriver.h"
#include <assert.h>
#include <cassert>
#include <esp_lvgl_port_disp.h>
#include <Tactility/Check.h>
#include <Tactility/LogEsp.h>
#include <Tactility/Logger.h>
#include <Tactility/hal/touch/TouchDevice.h>
constexpr const char* TAG = "EspLcdDispDrv";
static const auto LOGGER = tt::Logger("EspLcdDisplay");
EspLcdDisplay::~EspLcdDisplay() {
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
@@ -17,12 +17,12 @@ EspLcdDisplay::~EspLcdDisplay() {
bool EspLcdDisplay::start() {
if (!createIoHandle(ioHandle)) {
TT_LOG_E(TAG, "Failed to create IO handle");
LOGGER.error("Failed to create IO handle");
return false;
}
if (!createPanelHandle(ioHandle, panelHandle)) {
TT_LOG_E(TAG, "Failed to create panel handle");
LOGGER.error("Failed to create panel handle");
esp_lcd_panel_io_del(ioHandle);
return false;
}
@@ -45,7 +45,7 @@ bool EspLcdDisplay::stop() {
}
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
TT_LOG_W(TAG, "DisplayDriver is still in use.");
LOGGER.warn("DisplayDriver is still in use.");
}
return true;
@@ -55,7 +55,7 @@ bool EspLcdDisplay::startLvgl() {
assert(lvglDisplay == nullptr);
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
TT_LOG_W(TAG, "DisplayDriver is still in use.");
LOGGER.warn("DisplayDriver is still in use.");
}
auto lvgl_port_config = getLvglPortDisplayConfig(ioHandle, panelHandle);
+15 -15
View File
@@ -1,13 +1,13 @@
#include "EspLcdDisplayV2.h"
#include "EspLcdDisplayDriver.h"
#include <assert.h>
#include <cassert>
#include <esp_lvgl_port_disp.h>
#include <Tactility/Check.h>
#include <Tactility/LogEsp.h>
#include <Tactility/Logger.h>
#include <Tactility/hal/touch/TouchDevice.h>
constexpr auto* TAG = "EspLcdDispV2";
static const auto LOGGER = tt::Logger("EspLcdDispV2");
inline unsigned int getBufferSize(const std::shared_ptr<EspLcdConfiguration>& configuration) {
if (configuration->bufferSize != DEFAULT_BUFFER_SIZE) {
@@ -25,17 +25,17 @@ EspLcdDisplayV2::~EspLcdDisplayV2() {
bool EspLcdDisplayV2::applyConfiguration() const {
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel");
LOGGER.error("Failed to reset panel");
return false;
}
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel");
LOGGER.error("Failed to init panel");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
@@ -43,27 +43,27 @@ bool EspLcdDisplayV2::applyConfiguration() const {
int gap_x = configuration->swapXY ? configuration->gapY : configuration->gapX;
int gap_y = configuration->swapXY ? configuration->gapX : configuration->gapY;
if (esp_lcd_panel_set_gap(panelHandle, gap_x, gap_y) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel gap");
LOGGER.error("Failed to set panel gap");
return false;
}
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to swap XY ");
LOGGER.error("Failed to swap XY ");
return false;
}
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
LOGGER.error("Failed to set panel to mirror");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn display on");
LOGGER.error("Failed to turn display on");
return false;
}
@@ -72,14 +72,14 @@ bool EspLcdDisplayV2::applyConfiguration() const {
bool EspLcdDisplayV2::start() {
if (!createIoHandle(ioHandle)) {
TT_LOG_E(TAG, "Failed to create IO handle");
LOGGER.error("Failed to create IO handle");
return false;
}
esp_lcd_panel_dev_config_t panel_config = createPanelConfig(configuration, configuration->resetPin);
if (!createPanelHandle(ioHandle, panel_config, panelHandle)) {
TT_LOG_E(TAG, "Failed to create panel handle");
LOGGER.error("Failed to create panel handle");
esp_lcd_panel_io_del(ioHandle);
ioHandle = nullptr;
return false;
@@ -111,7 +111,7 @@ bool EspLcdDisplayV2::stop() {
}
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
TT_LOG_W(TAG, "DisplayDriver is still in use.");
LOGGER.warn("DisplayDriver is still in use.");
}
return true;
@@ -121,7 +121,7 @@ bool EspLcdDisplayV2::startLvgl() {
assert(lvglDisplay == nullptr);
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
TT_LOG_W(TAG, "DisplayDriver is still in use.");
LOGGER.warn("DisplayDriver is still in use.");
}
auto lvgl_port_config = getLvglPortDisplayConfig(configuration, ioHandle, panelHandle);
@@ -1,12 +1,12 @@
#include "EspLcdSpiDisplay.h"
#include <esp_lcd_panel_commands.h>
#include <Tactility/LogEsp.h>
#include <Tactility/Logger.h>
constexpr auto* TAG = "EspLcdSpiDsp";
static const auto LOGGER = tt::Logger("EspLcdSpiDisplay");
bool EspLcdSpiDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
TT_LOG_I(TAG, "createIoHandle");
LOGGER.info("createIoHandle");
const esp_lcd_panel_io_spi_config_t panel_io_config = {
.cs_gpio_num = spiConfiguration->csPin,
@@ -33,7 +33,7 @@ bool EspLcdSpiDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
};
if (esp_lcd_new_panel_io_spi(spiConfiguration->spiHostDevice, &panel_io_config, &outHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
@@ -65,6 +65,6 @@ void EspLcdSpiDisplay::setGammaCurve(uint8_t index) {
auto io_handle = getIoHandle();
assert(io_handle != nullptr);
if (esp_lcd_panel_io_tx_param(io_handle, LCD_CMD_GAMSET, param, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set gamma");
LOGGER.error("Failed to set gamma");
}
}
+10 -9
View File
@@ -1,21 +1,22 @@
#include "EspLcdTouch.h"
#include <EspLcdTouchDriver.h>
#include <esp_lvgl_port_touch.h>
#include <Tactility/LogEsp.h>
constexpr const char* TAG = "EspLcdTouch";
#include <EspLcdTouchDriver.h>
#include <Tactility/Logger.h>
#include <esp_lvgl_port_touch.h>
static const auto LOGGER = tt::Logger("EspLcdTouch");
bool EspLcdTouch::start() {
if (!createIoHandle(ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Touch IO failed");
LOGGER.error("Touch IO failed");
return false;
}
config = createEspLcdTouchConfig();
if (!createTouchHandle(ioHandle, config, touchHandle)) {
TT_LOG_E(TAG, "Driver init failed");
LOGGER.error("Driver init failed");
esp_lcd_panel_io_del(ioHandle);
ioHandle = nullptr;
return false;
@@ -48,7 +49,7 @@ bool EspLcdTouch::startLvgl(lv_disp_t* display) {
}
if (touchDriver != nullptr && touchDriver.use_count() > 1) {
TT_LOG_W(TAG, "TouchDriver is still in use.");
LOGGER.warn("TouchDriver is still in use.");
}
const lvgl_port_touch_cfg_t touch_cfg = {
@@ -56,10 +57,10 @@ bool EspLcdTouch::startLvgl(lv_disp_t* display) {
.handle = touchHandle,
};
TT_LOG_I(TAG, "Adding touch to LVGL");
LOGGER.info("Adding touch to LVGL");
lvglDevice = lvgl_port_add_touch(&touch_cfg);
if (lvglDevice == nullptr) {
TT_LOG_E(TAG, "Adding touch failed");
LOGGER.error("Adding touch failed");
return false;
}
@@ -1,12 +1,12 @@
#include "EspLcdTouchDriver.h"
#include <Tactility/LogEsp.h>
#include <Tactility/Logger.h>
constexpr const char* TAG = "EspLcdTouchDriver";
static const auto LOGGER = tt::Logger("EspLcdTouchDriver");
bool EspLcdTouchDriver::getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* _Nullable strength, uint8_t* pointCount, uint8_t maxPointCount) {
if (esp_lcd_touch_read_data(handle) != ESP_OK) {
TT_LOG_E(TAG, "Read data failed");
LOGGER.error("Read data failed");
return false;
}
return esp_lcd_touch_get_coordinates(handle, x, y, strength, pointCount, maxPointCount);
@@ -1,8 +1,7 @@
#include "ChargeFromAdcVoltage.h"
#include <Tactility/Log.h>
#include <algorithm>
#include <Tactility/Logger.h>
constexpr auto TAG = "ChargeFromAdcV";
static const auto LOGGER = tt::Logger("ChargeFromAdcV");
constexpr auto MAX_VOLTAGE_SAMPLES = 15;
ChargeFromAdcVoltage::ChargeFromAdcVoltage(
@@ -11,12 +10,12 @@ ChargeFromAdcVoltage::ChargeFromAdcVoltage(
float voltageMax
) : configuration(configuration), chargeFromVoltage(voltageMin, voltageMax) {
if (adc_oneshot_new_unit(&configuration.adcConfig, &adcHandle) != ESP_OK) {
TT_LOG_E(TAG, "ADC config failed");
LOGGER.error("ADC config failed");
return;
}
if (adc_oneshot_config_channel(adcHandle, configuration.adcChannel, &configuration.adcChannelConfig) != ESP_OK) {
TT_LOG_E(TAG, "ADC channel config failed");
LOGGER.error("ADC channel config failed");
adc_oneshot_del_unit(adcHandle);
return;
@@ -33,10 +32,12 @@ bool ChargeFromAdcVoltage::readBatteryVoltageOnce(uint32_t& output) const {
int raw;
if (adc_oneshot_read(adcHandle, configuration.adcChannel, &raw) == ESP_OK) {
output = configuration.adcMultiplier * ((1000.f * configuration.adcRefVoltage) / 4096.f) * (float)raw;
TT_LOG_V(TAG, "Raw = %d, voltage = %lu", raw, output);
if (LOGGER.isLoggingVerbose()) {
LOGGER.verbose("Raw = {}, voltage = {}", raw, output);
}
return true;
} else {
TT_LOG_E(TAG, "Read failed");
LOGGER.error("Read failed");
return false;
}
}
@@ -1,9 +1,9 @@
#include "ChargeFromVoltage.h"
#include <Tactility/Logger.h>
#include <algorithm>
#include <Tactility/Log.h>
constexpr auto* TAG = "ChargeFromVoltage";
const static auto LOGGER = tt::Logger("ChargeFromVoltage");
uint8_t ChargeFromVoltage::estimateCharge(uint32_t milliVolt) const {
const float volts = std::min((float)milliVolt / 1000.f, batteryVoltageMax);
@@ -13,6 +13,6 @@ uint8_t ChargeFromVoltage::estimateCharge(uint32_t milliVolt) const {
const float voltage_percentage = (volts - batteryVoltageMin) / (batteryVoltageMax - batteryVoltageMin);
const float voltage_factor = std::min(1.0f, voltage_percentage);
const auto charge_level = (uint8_t) (voltage_factor * 100.f);
TT_LOG_D(TAG, "mV = %lu, scaled = %.2f, factor = %.2f, result = %d", milliVolt, volts, voltage_factor, charge_level);
LOGGER.debug("mV = {}, scaled = {}, factor = {:.2f}, result = {}", milliVolt, volts, voltage_factor, charge_level);
return charge_level;
}
-4
View File
@@ -1,13 +1,9 @@
#include "Ft5x06Touch.h"
#include <Tactility/Log.h>
#include <esp_lcd_touch_ft5x06.h>
#include <esp_err.h>
#include <esp_lvgl_port.h>
#define TAG "ft5x06"
bool Ft5x06Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
return esp_lcd_new_panel_io_i2c(configuration->port, &io_config, &outHandle) == ESP_OK;
+5 -5
View File
@@ -1,12 +1,12 @@
#include "Ft6x36Touch.h"
#include <Ft6x36Touch.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_err.h>
#include <esp_lvgl_port.h>
#define TAG "ft6x36"
static const auto LOGGER = tt::Logger("FT6x36");
void Ft6x36Touch::touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) {
auto* touch = (Ft6x36Touch*)lv_indev_get_driver_data(indev);
@@ -71,10 +71,10 @@ bool Ft6x36Touch::shouldInterruptDriverThread() const {
}
bool Ft6x36Touch::start() {
TT_LOG_I(TAG, "Start");
LOGGER.info("Start");
if (!driver.begin(FT6X36_DEFAULT_THRESHOLD, configuration->width, configuration->height)) {
TT_LOG_E(TAG, "driver.begin() failed");
LOGGER.error("driver.begin() failed");
return false;
}
@@ -95,7 +95,7 @@ bool Ft6x36Touch::start() {
}
bool Ft6x36Touch::stop() {
TT_LOG_I(TAG, "Stop");
LOGGER.info("Stop");
mutex.lock();
interruptDriverThread = true;
+1
View File
@@ -2,6 +2,7 @@
#include <Tactility/hal/touch/TouchDevice.h>
#include <Tactility/TactilityCore.h>
#include <Tactility/Thread.h>
#include <driver/i2c.h>
#include "ft6x36/FT6X36.h"
+11 -11
View File
@@ -1,15 +1,15 @@
#include "Gc9a01Display.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_lcd_gc9a01.h>
#include <esp_lcd_panel_commands.h>
#include <esp_lvgl_port.h>
constexpr auto TAG = "GC9A01";
static const auto LOGGER = tt::Logger("GC9A01");
bool Gc9a01Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
TT_LOG_I(TAG, "Starting");
LOGGER.info("Starting");
const esp_lcd_panel_io_spi_config_t panel_io_config = {
.cs_gpio_num = configuration->csPin,
@@ -36,7 +36,7 @@ bool Gc9a01Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
};
if (esp_lcd_new_panel_io_spi(configuration->spiHostDevice, &panel_io_config, &outHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
@@ -56,37 +56,37 @@ bool Gc9a01Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
};
if (esp_lcd_new_panel_gc9a01(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel");
LOGGER.error("Failed to reset panel");
return false;
}
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel");
LOGGER.error("Failed to init panel");
return false;
}
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to swap XY ");
LOGGER.error("Failed to swap XY ");
return false;
}
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
LOGGER.error("Failed to set panel to mirror");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn display on");
LOGGER.error("Failed to turn display on");
return false;
}
+3 -3
View File
@@ -1,12 +1,12 @@
#include "Gt911Touch.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/hal/i2c/I2c.h>
#include <esp_lcd_touch_gt911.h>
#include <esp_err.h>
#define TAG "GT911"
static const auto LOGGER = tt::Logger("GT911");
bool Gt911Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
@@ -21,7 +21,7 @@ bool Gt911Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
} else if (tt::hal::i2c::masterHasDeviceAtAddress(configuration->port, ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP)) {
io_config.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP;
} else {
TT_LOG_E(TAG, "No device found on I2C bus");
LOGGER.error("No device found on I2C bus");
return false;
}
+9 -9
View File
@@ -1,12 +1,12 @@
#include "Ili9488Display.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_lcd_ili9488.h>
#include <esp_lcd_panel_commands.h>
#include <esp_lvgl_port.h>
#define TAG "ILI9488"
static const auto LOGGER = tt::Logger("ILI9488");
bool Ili9488Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
const esp_lcd_panel_io_spi_config_t panel_io_config = {
@@ -50,37 +50,37 @@ bool Ili9488Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l
};
if (esp_lcd_new_panel_ili9488(ioHandle, &panel_config, configuration->bufferSize, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel");
LOGGER.error("Failed to reset panel");
return false;
}
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel");
LOGGER.error("Failed to init panel");
return false;
}
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to swap XY ");
LOGGER.error("Failed to swap XY ");
return false;
}
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
LOGGER.error("Failed to set panel to mirror");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn display on");
LOGGER.error("Failed to turn display on");
return false;
}
+7 -6
View File
@@ -1,8 +1,8 @@
#include "PwmBacklight.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#define TAG "pwm_backlight"
static const auto LOGGER = tt::Logger("PwmBacklight");
namespace driver::pwmbacklight {
@@ -16,7 +16,7 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel
backlightTimer = timer;
backlightChannel = channel;
TT_LOG_I(TAG, "Init");
LOGGER.info("Init");
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_8_BIT,
@@ -27,7 +27,7 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel
};
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
TT_LOG_E(TAG, "Timer config failed");
LOGGER.error("Timer config failed");
return false;
}
@@ -46,7 +46,8 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel
};
if (ledc_channel_config(&ledc_channel) != ESP_OK) {
TT_LOG_E(TAG, "Channel config failed");
LOGGER.error("Channel config failed");
return false;
}
isBacklightInitialized = true;
@@ -56,7 +57,7 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel
bool setBacklightDuty(uint8_t duty) {
if (!isBacklightInitialized) {
TT_LOG_E(TAG, "Not initialized");
LOGGER.error("Not initialized");
return false;
}
return ledc_set_duty(LEDC_LOW_SPEED_MODE, backlightChannel, duty) == ESP_OK &&
+14 -14
View File
@@ -1,15 +1,15 @@
#include "RgbDisplay.h"
#include <Tactility/Log.h>
#include <Tactility/Check.h>
#include <Tactility/hal/touch/TouchDevice.h>
#include <Tactility/Logger.h>
#include <esp_err.h>
#include <esp_lcd_panel_rgb.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lvgl_port.h>
#include <Tactility/Check.h>
#include <Tactility/hal/touch/TouchDevice.h>
constexpr auto TAG = "RgbDisplay";
static const auto LOGGER = tt::Logger("RgbDisplay");
RgbDisplay::~RgbDisplay() {
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
@@ -18,35 +18,35 @@ RgbDisplay::~RgbDisplay() {
}
bool RgbDisplay::start() {
TT_LOG_I(TAG, "Starting");
LOGGER.info("Starting");
if (esp_lcd_new_rgb_panel(&configuration->panelConfig, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel");
LOGGER.error("Failed to reset panel");
return false;
}
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel");
LOGGER.error("Failed to init panel");
return false;
}
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to swap XY");
LOGGER.error("Failed to swap XY");
return false;
}
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
LOGGER.error("Failed to set panel to mirror");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
@@ -64,7 +64,7 @@ bool RgbDisplay::stop() {
}
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
TT_LOG_W(TAG, "DisplayDriver is still in use.");
LOGGER.warn("DisplayDriver is still in use.");
}
auto touch_device = getTouchDevice();
@@ -80,7 +80,7 @@ bool RgbDisplay::startLvgl() {
assert(lvglDisplay == nullptr);
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
TT_LOG_W(TAG, "DisplayDriver is still in use.");
LOGGER.warn("DisplayDriver is still in use.");
}
auto display_config = getLvglPortDisplayConfig();
@@ -93,7 +93,7 @@ bool RgbDisplay::startLvgl() {
};
lvglDisplay = lvgl_port_add_disp_rgb(&display_config, &rgb_config);
TT_LOG_I(TAG, "Finished");
LOGGER.info("Finished");
auto touch_device = getTouchDevice();
if (touch_device != nullptr) {
+7 -7
View File
@@ -1,6 +1,6 @@
#include "Ssd1306Display.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_lcd_panel_commands.h>
#include <esp_lcd_panel_dev.h>
#include <esp_lcd_panel_ssd1306.h>
@@ -10,7 +10,7 @@
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#define TAG "ssd1306_display"
static const auto LOGGER = tt::Logger("Ssd1306Display");
// SSD1306 commands
#define SSD1306_CMD_SET_CHARGE_PUMP 0x8D
@@ -31,7 +31,7 @@ static bool ssd1306_i2c_send_cmd(i2c_port_t port, uint8_t addr, uint8_t cmd) {
uint8_t data[2] = {0x00, cmd}; // 0x00 = command mode
esp_err_t ret = i2c_master_write_to_device(port, addr, data, sizeof(data), pdMS_TO_TICKS(1000));
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to send command 0x%02X: %d", cmd, ret);
LOGGER.error("Failed to send command 0x{:02X}: {}", cmd, ret);
return false;
}
return true;
@@ -49,7 +49,7 @@ bool Ssd1306Display::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) {
};
if (esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)configuration->port, &io_config, &ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create IO handle");
LOGGER.error("Failed to create IO handle");
return false;
}
@@ -93,7 +93,7 @@ bool Ssd1306Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l
#endif
if (esp_lcd_new_panel_ssd1306(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
@@ -103,7 +103,7 @@ bool Ssd1306Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l
auto port = configuration->port;
auto addr = configuration->deviceAddress;
TT_LOG_I(TAG, "Sending Heltec V3 custom init sequence");
LOGGER.info("Sending Heltec V3 custom init sequence");
// Display off while configuring
ssd1306_i2c_send_cmd(port, addr, 0xAE);
@@ -170,7 +170,7 @@ bool Ssd1306Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l
vTaskDelay(pdMS_TO_TICKS(100)); // Let display stabilize
TT_LOG_I(TAG, "Heltec V3 display initialized successfully");
LOGGER.info("Heltec V3 display initialized successfully");
return true;
}
+13 -13
View File
@@ -1,16 +1,16 @@
#include "St7735Display.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_lcd_panel_commands.h>
#include <esp_lcd_panel_dev.h>
#include <esp_lcd_st7735.h>
#include <esp_lvgl_port.h>
constexpr auto TAG = "ST7735";
static const auto LOGGER = tt::Logger("ST7735");
bool St7735Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
TT_LOG_I(TAG, "Starting");
LOGGER.info("Starting");
const esp_lcd_panel_io_spi_config_t panel_io_config = {
.cs_gpio_num = configuration->csPin,
@@ -37,7 +37,7 @@ bool St7735Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
};
if (esp_lcd_new_panel_io_spi(configuration->spiHostDevice, &panel_io_config, &outHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
@@ -58,22 +58,22 @@ bool St7735Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
};
if (esp_lcd_new_panel_st7735(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel");
LOGGER.error("Failed to reset panel");
return false;
}
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel");
LOGGER.error("Failed to init panel");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
@@ -81,22 +81,22 @@ bool St7735Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
int gap_x = configuration->swapXY ? configuration->gapY : configuration->gapX;
int gap_y = configuration->swapXY ? configuration->gapX : configuration->gapY;
if (esp_lcd_panel_set_gap(panelHandle, gap_x, gap_y) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel gap");
LOGGER.error("Failed to set panel gap");
return false;
}
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to swap XY ");
LOGGER.error("Failed to swap XY ");
return false;
}
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
LOGGER.error("Failed to set panel to mirror");
return false;
}
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn display on");
LOGGER.error("Failed to turn display on");
return false;
}
@@ -165,6 +165,6 @@ void St7735Display::setGammaCurve(uint8_t index) {
auto io_handle = getIoHandle();
assert(io_handle != nullptr);
if (esp_lcd_panel_io_tx_param(io_handle, LCD_CMD_GAMSET, param, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set gamma");
LOGGER.error("Failed to set gamma");
}
}
@@ -1,5 +1,5 @@
#include "St7789i8080Display.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <driver/gpio.h>
#include <esp_lcd_panel_io.h>
#include <esp_lcd_panel_ops.h>
@@ -8,7 +8,7 @@
#include <freertos/task.h>
#include <lvgl.h>
constexpr auto TAG = "St7789i8080Display";
static const auto LOGGER = tt::Logger("St7789i8080Display");
static St7789i8080Display* g_display_instance = nullptr;
// ST7789 initialization commands
@@ -51,13 +51,13 @@ St7789i8080Display::St7789i8080Display(const Configuration& config)
// Validate configuration
if (!configuration.isValid()) {
TT_LOG_E(TAG, "Invalid configuration: resolution must be set");
LOGGER.error("Invalid configuration: resolution must be set");
return;
}
}
bool St7789i8080Display::createI80Bus() {
TT_LOG_I(TAG, "Creating I80 bus");
LOGGER.info("Creating I80 bus");
// Create I80 bus configuration
esp_lcd_i80_bus_config_t bus_cfg = {
@@ -78,7 +78,7 @@ bool St7789i8080Display::createI80Bus() {
esp_err_t ret = esp_lcd_new_i80_bus(&bus_cfg, &i80BusHandle);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to create I80 bus: %s", esp_err_to_name(ret));
LOGGER.error("Failed to create I80 bus: {}", esp_err_to_name(ret));
return false;
}
@@ -86,7 +86,7 @@ bool St7789i8080Display::createI80Bus() {
}
bool St7789i8080Display::createPanelIO() {
TT_LOG_I(TAG, "Creating panel IO");
LOGGER.info("Creating panel IO");
// Create panel IO with proper callback
esp_lcd_panel_io_i80_config_t io_cfg = {
@@ -114,7 +114,7 @@ bool St7789i8080Display::createPanelIO() {
esp_err_t ret = esp_lcd_new_panel_io_i80(i80BusHandle, &io_cfg, &ioHandle);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel IO: %s", esp_err_to_name(ret));
LOGGER.error("Failed to create panel IO: {}", esp_err_to_name(ret));
return false;
}
@@ -122,7 +122,7 @@ bool St7789i8080Display::createPanelIO() {
}
bool St7789i8080Display::createPanel() {
TT_LOG_I(TAG, "Configuring panel");
LOGGER.info("Configuring panel");
// Create ST7789 panel
esp_lcd_panel_dev_config_t panel_config = {
@@ -138,49 +138,49 @@ bool St7789i8080Display::createPanel() {
esp_err_t ret = esp_lcd_new_panel_st7789(ioHandle, &panel_config, &panelHandle);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to create ST7789 panel: %s", esp_err_to_name(ret));
LOGGER.error("Failed to create ST7789 panel: {}", esp_err_to_name(ret));
return false;
}
// Reset panel
ret = esp_lcd_panel_reset(panelHandle);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel: %s", esp_err_to_name(ret));
LOGGER.error("Failed to reset panel: {}", esp_err_to_name(ret));
return false;
}
// Initialize panel
ret = esp_lcd_panel_init(panelHandle);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel: %s", esp_err_to_name(ret));
LOGGER.error("Failed to init panel: {}", esp_err_to_name(ret));
return false;
}
// Set gap
ret = esp_lcd_panel_set_gap(panelHandle, configuration.gapX, configuration.gapY);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel gap: %s", esp_err_to_name(ret));
LOGGER.error("Failed to set panel gap: {}", esp_err_to_name(ret));
return false;
}
// Set inversion
ret = esp_lcd_panel_invert_color(panelHandle, configuration.invertColor);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel inversion: %s", esp_err_to_name(ret));
LOGGER.error("Failed to set panel inversion: {}", esp_err_to_name(ret));
return false;
}
// Set mirror
ret = esp_lcd_panel_mirror(panelHandle, configuration.mirrorX, configuration.mirrorY);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel mirror: %s", esp_err_to_name(ret));
LOGGER.error("Failed to set panel mirror: {}", esp_err_to_name(ret));
return false;
}
// Turn on display
ret = esp_lcd_panel_disp_on_off(panelHandle, true);
if (ret != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn display on: %s", esp_err_to_name(ret));
LOGGER.error("Failed to turn display on: {}", esp_err_to_name(ret));
return false;
}
@@ -188,7 +188,7 @@ bool St7789i8080Display::createPanel() {
}
void St7789i8080Display::sendInitCommands() {
TT_LOG_I(TAG, "Sending ST7789 init commands");
LOGGER.info("Sending ST7789 init commands");
for (const auto& cmd : st7789_init_cmds) {
esp_lcd_panel_io_tx_param(ioHandle, cmd.cmd, cmd.data, cmd.len & 0x7F);
if (cmd.len & 0x80) {
@@ -198,7 +198,7 @@ void St7789i8080Display::sendInitCommands() {
}
bool St7789i8080Display::start() {
TT_LOG_I(TAG, "Initializing I8080 ST7789 Display hardware...");
LOGGER.info("Initializing I8080 ST7789 Display hardware...");
// Configure RD pin if needed
if (configuration.rdPin != GPIO_NUM_NC) {
@@ -220,7 +220,7 @@ bool St7789i8080Display::start() {
size_t buffer_size = configuration.bufferSize * LV_COLOR_FORMAT_GET_SIZE(LV_COLOR_FORMAT_RGB565);
buf1 = (uint8_t*)heap_caps_malloc(buffer_size, MALLOC_CAP_DMA);
if (!buf1) {
TT_LOG_E(TAG, "Failed to allocate display buffer");
LOGGER.error("Failed to allocate display buffer");
return false;
}
@@ -239,7 +239,7 @@ bool St7789i8080Display::start() {
return false;
}
TT_LOG_I(TAG, "Display hardware initialized");
LOGGER.info("Display hardware initialized");
return true;
}
@@ -278,17 +278,17 @@ bool St7789i8080Display::stop() {
}
bool St7789i8080Display::startLvgl() {
TT_LOG_I(TAG, "Initializing LVGL for ST7789 display");
LOGGER.info("Initializing LVGL for ST7789 display");
// Don't reinitialize hardware if it's already done
if (!ioHandle) {
TT_LOG_I(TAG, "Hardware not initialized, calling start()");
LOGGER.info("Hardware not initialized, calling start()");
if (!start()) {
TT_LOG_E(TAG, "Hardware initialization failed");
LOGGER.error("Hardware initialization failed");
return false;
}
} else {
TT_LOG_I(TAG, "Hardware already initialized, skipping");
LOGGER.info("Hardware already initialized, skipping");
}
// Create LVGL display using lvgl_port
@@ -321,7 +321,7 @@ bool St7789i8080Display::startLvgl() {
// Create the LVGL display
lvglDisplay = lvgl_port_add_disp(&display_cfg);
if (!lvglDisplay) {
TT_LOG_E(TAG, "Failed to create LVGL display");
LOGGER.error("Failed to create LVGL display");
return false;
}
@@ -332,7 +332,7 @@ bool St7789i8080Display::startLvgl() {
esp_lcd_panel_io_register_event_callbacks(ioHandle, &cbs, lvglDisplay);
g_display_instance = this;
TT_LOG_I(TAG, "LVGL display created successfully");
LOGGER.info("LVGL display created successfully");
return true;
}
@@ -1,5 +1,5 @@
#include "St7796i8080Display.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <driver/gpio.h>
#include <esp_lcd_panel_io.h>
#include <esp_lcd_panel_ops.h>
@@ -8,7 +8,7 @@
#include <freertos/task.h>
#include <lvgl.h>
constexpr auto TAG = "St7796i8080Display";
static const auto LOGGER = tt::Logger("St7796i8080Display");
static St7796i8080Display* g_display_instance = nullptr;
St7796i8080Display::St7796i8080Display(const Configuration& config)
@@ -16,13 +16,13 @@ St7796i8080Display::St7796i8080Display(const Configuration& config)
// Validate configuration
if (!configuration.isValid()) {
TT_LOG_E(TAG, "Invalid configuration: resolution must be set");
LOGGER.error("Invalid configuration: resolution must be set");
return;
}
}
bool St7796i8080Display::createI80Bus() {
TT_LOG_I(TAG, "Creating I80 bus");
LOGGER.info("Creating I80 bus");
// Create I80 bus configuration
esp_lcd_i80_bus_config_t bus_cfg = {
@@ -42,7 +42,7 @@ bool St7796i8080Display::createI80Bus() {
};
if (esp_lcd_new_i80_bus(&bus_cfg, &i80BusHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create I80 bus");
LOGGER.error("Failed to create I80 bus");
return false;
}
@@ -50,7 +50,7 @@ bool St7796i8080Display::createI80Bus() {
}
bool St7796i8080Display::createPanelIO() {
TT_LOG_I(TAG, "Creating panel IO");
LOGGER.info("Creating panel IO");
// Create panel IO
esp_lcd_panel_io_i80_config_t io_cfg = {
@@ -77,7 +77,7 @@ bool St7796i8080Display::createPanelIO() {
};
if (esp_lcd_new_panel_io_i80(i80BusHandle, &io_cfg, &ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
@@ -85,7 +85,7 @@ bool St7796i8080Display::createPanelIO() {
}
bool St7796i8080Display::createPanel() {
TT_LOG_I(TAG, "Configuring panel");
LOGGER.info("Configuring panel");
// Create ST7796 panel
esp_lcd_panel_dev_config_t panel_config = {
@@ -100,43 +100,43 @@ bool St7796i8080Display::createPanel() {
};
if (esp_lcd_new_panel_st7796(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
// Reset panel
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel");
LOGGER.error("Failed to reset panel");
return false;
}
// Initialize panel
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel");
LOGGER.error("Failed to init panel");
return false;
}
// Set swap XY
if (esp_lcd_panel_swap_xy(panelHandle, configuration.swapXY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to swap XY ");
LOGGER.error("Failed to swap XY ");
return false;
}
// Set mirror
if (esp_lcd_panel_mirror(panelHandle, configuration.mirrorX, configuration.mirrorY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
LOGGER.error("Failed to set panel to mirror");
return false;
}
// Set inversion
if (esp_lcd_panel_invert_color(panelHandle, configuration.invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
// Turn on display
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn display on");
LOGGER.error("Failed to turn display on");
return false;
}
@@ -144,7 +144,7 @@ bool St7796i8080Display::createPanel() {
}
bool St7796i8080Display::start() {
TT_LOG_I(TAG, "Initializing I8080 ST7796 Display hardware...");
LOGGER.info("Initializing I8080 ST7796 Display hardware...");
// Calculate buffer size if needed
configuration.calculateBufferSize();
@@ -153,7 +153,7 @@ bool St7796i8080Display::start() {
size_t buffer_size = configuration.bufferSize * LV_COLOR_FORMAT_GET_SIZE(LV_COLOR_FORMAT_RGB565);
displayBuffer = (uint8_t*)heap_caps_malloc(buffer_size, MALLOC_CAP_DMA);
if (!displayBuffer) {
TT_LOG_E(TAG, "Failed to allocate display buffer");
LOGGER.error("Failed to allocate display buffer");
return false;
}
@@ -175,7 +175,7 @@ bool St7796i8080Display::start() {
return false;
}
TT_LOG_I(TAG, "Display hardware initialized");
LOGGER.info("Display hardware initialized");
return true;
}
@@ -214,17 +214,17 @@ bool St7796i8080Display::stop() {
}
bool St7796i8080Display::startLvgl() {
TT_LOG_I(TAG, "Initializing LVGL for ST7796 display");
LOGGER.info("Initializing LVGL for ST7796 display");
// Don't reinitialize hardware if it's already done
if (!ioHandle) {
TT_LOG_I(TAG, "Hardware not initialized, calling start()");
LOGGER.info("Hardware not initialized, calling start()");
if (!start()) {
TT_LOG_E(TAG, "Hardware initialization failed");
LOGGER.error("Hardware initialization failed");
return false;
}
} else {
TT_LOG_I(TAG, "Hardware already initialized, skipping");
LOGGER.info("Hardware already initialized, skipping");
}
// Create LVGL display using lvgl_port
@@ -257,12 +257,12 @@ bool St7796i8080Display::startLvgl() {
// Create the LVGL display
lvglDisplay = lvgl_port_add_disp(&display_cfg);
if (!lvglDisplay) {
TT_LOG_E(TAG, "Failed to create LVGL display");
LOGGER.error("Failed to create LVGL display");
return false;
}
g_display_instance = this;
TT_LOG_I(TAG, "LVGL display created successfully");
LOGGER.info("LVGL display created successfully");
return true;
}
+11 -11
View File
@@ -1,12 +1,12 @@
#include "St7796Display.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <esp_lcd_panel_dev.h>
#include <esp_lcd_st7796.h>
#include <esp_lvgl_port.h>
constexpr auto TAG = "ST7796";
static const auto LOGGER = tt::Logger("ST7796");
bool St7796Display::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) {
const esp_lcd_panel_io_spi_config_t panel_io_config = {
@@ -74,42 +74,42 @@ bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
};
if (esp_lcd_new_panel_st7796(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
LOGGER.error("Failed to create panel");
return false;
}
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to reset panel");
LOGGER.error("Failed to reset panel");
return false;
}
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to init panel");
LOGGER.error("Failed to init panel");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, configuration->invertColor) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
LOGGER.error("Failed to set panel to invert");
return false;
}
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to swap XY ");
LOGGER.error("Failed to swap XY ");
return false;
}
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
LOGGER.error("Failed to set panel to mirror");
return false;
}
if (esp_lcd_panel_set_gap(panelHandle, configuration->gapX, configuration->gapY) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel gap");
LOGGER.error("Failed to set panel gap");
return false;
}
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn display on");
LOGGER.error("Failed to turn display on");
return false;
}
@@ -168,6 +168,6 @@ void St7796Display::setGammaCurve(uint8_t index) {
};
/*if (esp_lcd_panel_io_tx_param(ioHandle , LCD_CMD_GAMSET, param, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set gamma");
LOGGER.error("Failed to set gamma");
}*/
}
-3
View File
@@ -1,7 +1,4 @@
#include "Tca8418.h"
#include <Tactility/Log.h>
constexpr auto TAG = "TCA8418";
namespace registers {
static const uint8_t CFG = 0x01U;
+7 -6
View File
@@ -1,10 +1,11 @@
#include "Xpt2046Power.h"
#include "Xpt2046Touch.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/hal/Device.h>
constexpr auto TAG = "Xpt2046Power";
static const auto LOGGER = tt::Logger("Xpt2046Power");
constexpr auto BATTERY_VOLTAGE_MIN = 3.2f;
constexpr auto BATTERY_VOLTAGE_MAX = 4.2f;
constexpr auto MAX_VOLTAGE_SAMPLES = 15;
@@ -13,12 +14,12 @@ static std::shared_ptr<Xpt2046Touch> findXp2046TouchDevice() {
// Make a safe copy
auto touch = tt::hal::findFirstDevice<tt::hal::touch::TouchDevice>(tt::hal::Device::Type::Touch);
if (touch == nullptr) {
TT_LOG_E(TAG, "Touch device not found");
LOGGER.error("Touch device not found");
return nullptr;
}
if (touch->getName() != "XPT2046") {
TT_LOG_E(TAG, "Touch device name mismatch");
LOGGER.error("Touch device name mismatch");
return nullptr;
}
@@ -30,7 +31,7 @@ static uint8_t estimateChargeLevelFromVoltage(uint32_t milliVolt) {
float voltage_percentage = (volts - BATTERY_VOLTAGE_MIN) / (BATTERY_VOLTAGE_MAX - BATTERY_VOLTAGE_MIN);
float voltage_factor = std::min(1.0f, voltage_percentage);
auto charge_level = (uint8_t) (voltage_factor * 100.f);
TT_LOG_V(TAG, "mV = %lu, scaled = %.2f, factor = %.2f, result = %d", milliVolt, volts, voltage_factor, charge_level);
LOGGER.verbose("mV = {}, scaled = {}, factor = {}, result = {}", milliVolt, volts, voltage_factor, charge_level);
return charge_level;
}
@@ -68,7 +69,7 @@ bool Xpt2046Power::readBatteryVoltageOnce(uint32_t& output) {
if (xptTouch == nullptr) {
xptTouch = findXp2046TouchDevice();
if (xptTouch == nullptr) {
TT_LOG_E(TAG, "XPT2046 touch device not found");
LOGGER.error("XPT2046 touch device not found");
return false;
}
}
-1
View File
@@ -1,6 +1,5 @@
#include "Xpt2046Touch.h"
#include <Tactility/Log.h>
#include <Tactility/lvgl/LvglSync.h>
#include <esp_err.h>
@@ -1,6 +1,6 @@
#include "Xpt2046SoftSpi.h"
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <Tactility/lvgl/LvglSync.h>
#include <driver/gpio.h>
@@ -13,7 +13,7 @@
#include <nvs_flash.h>
#include <rom/ets_sys.h>
constexpr auto* TAG = "Xpt2046SoftSpi";
static const auto LOGGER = tt::Logger("Xpt2046SoftSpi");
constexpr auto RERUN_CALIBRATE = false;
constexpr auto CMD_READ_Y = 0x90; // Try different commands if these don't work
@@ -55,7 +55,7 @@ static void ensureNvsInitialized() {
bool Xpt2046SoftSpi::start() {
ensureNvsInitialized();
TT_LOG_I(TAG, "Starting Xpt2046SoftSpi touch driver");
LOGGER.info("Starting Xpt2046SoftSpi touch driver");
// Configure GPIO pins
gpio_config_t io_conf = {};
@@ -70,7 +70,7 @@ bool Xpt2046SoftSpi::start() {
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
if (gpio_config(&io_conf) != ESP_OK) {
TT_LOG_E(TAG, "Failed to configure output pins");
LOGGER.error("Failed to configure output pins");
return false;
}
@@ -80,7 +80,7 @@ bool Xpt2046SoftSpi::start() {
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
if (gpio_config(&io_conf) != ESP_OK) {
TT_LOG_E(TAG, "Failed to configure input pin");
LOGGER.error("Failed to configure input pin");
return false;
}
@@ -89,31 +89,36 @@ bool Xpt2046SoftSpi::start() {
gpio_set_level(configuration->clkPin, 0); // CLK low
gpio_set_level(configuration->mosiPin, 0); // MOSI low
TT_LOG_I(TAG, "GPIO configured: MOSI=%d, MISO=%d, CLK=%d, CS=%d", configuration->mosiPin, configuration->misoPin, configuration->clkPin, configuration->csPin);
LOGGER.info("GPIO configured: MOSI={}, MISO={}, CLK={}, CS={}",
static_cast<int>(configuration->mosiPin),
static_cast<int>(configuration->misoPin),
static_cast<int>(configuration->clkPin),
static_cast<int>(configuration->csPin)
);
// Load or perform calibration
bool calibrationValid = true; //loadCalibration() && !RERUN_CALIBRATE;
if (calibrationValid) {
// Check if calibration values are valid (xMin != xMax, yMin != yMax)
if (cal.xMin == cal.xMax || cal.yMin == cal.yMax) {
TT_LOG_W(TAG, "Invalid calibration detected: xMin=%d, xMax=%d, yMin=%d, yMax=%d", cal.xMin, cal.xMax, cal.yMin, cal.yMax);
LOGGER.warn("Invalid calibration detected: xMin={}, xMax={}, yMin={}, yMax={}", cal.xMin, cal.xMax, cal.yMin, cal.yMax);
calibrationValid = false;
}
}
if (!calibrationValid) {
TT_LOG_W(TAG, "Calibration data not found, invalid, or forced recalibration");
LOGGER.warn("Calibration data not found, invalid, or forced recalibration");
calibrate();
saveCalibration();
} else {
TT_LOG_I(TAG, "Loaded calibration: xMin=%d, yMin=%d, xMax=%d, yMax=%d", cal.xMin, cal.yMin, cal.xMax, cal.yMax);
LOGGER.info("Loaded calibration: xMin={}, yMin={}, xMax={}, yMax={}", cal.xMin, cal.yMin, cal.xMax, cal.yMax);
}
return true;
}
bool Xpt2046SoftSpi::stop() {
TT_LOG_I(TAG, "Stopping Xpt2046SoftSpi touch driver");
LOGGER.info("Stopping Xpt2046SoftSpi touch driver");
// Stop LVLG if needed
if (lvglDevice != nullptr) {
@@ -125,13 +130,13 @@ bool Xpt2046SoftSpi::stop() {
bool Xpt2046SoftSpi::startLvgl(lv_display_t* display) {
if (lvglDevice != nullptr) {
TT_LOG_E(TAG, "LVGL was already started");
LOGGER.error("LVGL was already started");
return false;
}
lvglDevice = lv_indev_create();
if (!lvglDevice) {
TT_LOG_E(TAG, "Failed to create LVGL input device");
LOGGER.error("Failed to create LVGL input device");
return false;
}
@@ -139,7 +144,7 @@ bool Xpt2046SoftSpi::startLvgl(lv_display_t* display) {
lv_indev_set_read_cb(lvglDevice, touchReadCallback);
lv_indev_set_user_data(lvglDevice, this);
TT_LOG_I(TAG, "Xpt2046SoftSpi touch driver started successfully");
LOGGER.info("Xpt2046SoftSpi touch driver started successfully");
return true;
}
@@ -186,9 +191,9 @@ int Xpt2046SoftSpi::readSPI(uint8_t command) {
void Xpt2046SoftSpi::calibrate() {
const int samples = 8; // More samples for better accuracy
TT_LOG_I(TAG, "Calibration starting...");
LOGGER.info("Calibration starting...");
TT_LOG_I(TAG, "Touch TOP-LEFT corner");
LOGGER.info("Touch TOP-LEFT corner");
while (!isTouched()) {
vTaskDelay(pdMS_TO_TICKS(50));
@@ -203,9 +208,9 @@ void Xpt2046SoftSpi::calibrate() {
cal.xMin = sumX / samples;
cal.yMin = sumY / samples;
TT_LOG_I(TAG, "Top-left calibrated: xMin=%d, yMin=%d", cal.xMin, cal.yMin);
LOGGER.info("Top-left calibrated: xMin={}, yMin={}", cal.xMin, cal.yMin);
TT_LOG_I(TAG, "Touch BOTTOM-RIGHT corner");
LOGGER.info("Touch BOTTOM-RIGHT corner");
while (!isTouched()) {
vTaskDelay(pdMS_TO_TICKS(50));
@@ -220,13 +225,13 @@ void Xpt2046SoftSpi::calibrate() {
cal.xMax = sumX / samples;
cal.yMax = sumY / samples;
TT_LOG_I(TAG, "Bottom-right calibrated: xMax=%d, yMax=%d", cal.xMax, cal.yMax);
LOGGER.info("Bottom-right calibrated: xMax={}, yMax={}", cal.xMax, cal.yMax);
TT_LOG_I(TAG, "Calibration completed! xMin=%d, yMin=%d, xMax=%d, yMax=%d", cal.xMin, cal.yMin, cal.xMax, cal.yMax);
LOGGER.info("Calibration completed! xMin={}, yMin={}, xMax={}, yMax={}", cal.xMin, cal.yMin, cal.xMax, cal.yMax);
}
bool Xpt2046SoftSpi::loadCalibration() {
TT_LOG_W(TAG, "Calibration load disabled (using fresh calibration only).");
LOGGER.warn("Calibration load disabled (using fresh calibration only).");
return false;
}
@@ -234,16 +239,16 @@ void Xpt2046SoftSpi::saveCalibration() {
nvs_handle_t handle;
esp_err_t err = nvs_open("xpt2046", NVS_READWRITE, &handle);
if (err != ESP_OK) {
TT_LOG_E(TAG, "Failed to open NVS for writing (%s)", esp_err_to_name(err));
LOGGER.error("Failed to open NVS for writing ({})", esp_err_to_name(err));
return;
}
err = nvs_set_blob(handle, "cal", &cal, sizeof(cal));
if (err == ESP_OK) {
nvs_commit(handle);
TT_LOG_I(TAG, "Calibration saved to NVS");
LOGGER.info("Calibration saved to NVS");
} else {
TT_LOG_E(TAG, "Failed to write calibration data to NVS (%s)", esp_err_to_name(err));
LOGGER.error("Failed to write calibration data to NVS ({})", esp_err_to_name(err));
}
nvs_close(handle);
@@ -254,7 +259,7 @@ void Xpt2046SoftSpi::setCalibration(int xMin, int yMin, int xMax, int yMax) {
cal.yMin = yMin;
cal.xMax = xMax;
cal.yMax = yMax;
TT_LOG_I(TAG, "Manual calibration set: xMin=%d, yMin=%d, xMax=%d, yMax=%d", xMin, yMin, xMax, yMax);
LOGGER.info("Manual calibration set: xMin={}, yMin={}, xMax={}, yMax={}", xMin, yMin, xMax, yMax);
}
bool Xpt2046SoftSpi::getTouchPoint(Point& point) {
@@ -292,7 +297,7 @@ bool Xpt2046SoftSpi::getTouchPoint(Point& point) {
const int yRange = cal.yMax - cal.yMin;
if (xRange <= 0 || yRange <= 0) {
TT_LOG_W(TAG, "Invalid calibration: xRange=%d, yRange=%d", xRange, yRange);
LOGGER.warn("Invalid calibration: xRange={}, yRange={}", xRange, yRange);
return false;
}
@@ -337,7 +342,7 @@ bool Xpt2046SoftSpi::isTouched() {
// Debug logging (remove this once working)
if (touched) {
TT_LOG_D(TAG, "Touch detected: validSamples=%d, avgX=%d, avgY=%d", validSamples, xTotal / validSamples, yTotal / validSamples);
LOGGER.debug("Touch detected: validSamples={}, avgX={}, avgY={}", validSamples, xTotal / validSamples, yTotal / validSamples);
}
return touched;