Device migrations, drivers and fixes (#571)

Device migrations:

- cyd-4848S040c
- guition-jc1060p470ciwy
- guition-jc2432w328c
- guition-jc3248w535c (known issue with display and touch, Shadowtrance will look into it)
- guition-jc8048w550c
- heltec-wifi-lora-32-v3
- lilygo-tdeck-max (excluding graphics)
- lilygo-tdisplay
- lilygo-tdisplay-s3
- lilygo-tdongle-s3
- lilygo-tlora-pager

Driver migrations:

- Implemented haptic driver interface in kernel
- AXS15231b
- BQ25896
- BQ27220
- CST328
- CST6xx
- DRV2605
- JD9165
- Custom LilyGO driver for T-Lora Pager
- SSD1306
- ST7701
- ST7735
- SY6970
- TCA8418

Fixes/improvements:

- Boot app: support for multiple power devices, improved UI
- lvgl_devices and related code: fixes for mapping
- Support for arrays in dts parser
This commit is contained in:
Ken Van Hoeylandt
2026-07-18 15:01:42 +02:00
committed by GitHub
parent 3b5a401594
commit d896657bf9
290 changed files with 9113 additions and 6719 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lcd ST7796 BQ25896 BQ27220 TCA8418 DRV2605 PwmBacklight driver esp_adc platform-esp32
INCLUDE_DIRS "source"
REQUIRES Tactility driver esp_adc platform-esp32 lilygo-module
)
@@ -1,38 +0,0 @@
#include "devices/Display.h"
#include "devices/TpagerEncoder.h"
#include "devices/TpagerKeyboard.h"
#include "devices/TpagerPower.h"
#include <tactility/device.h>
#include <Tactility/hal/Configuration.h>
#include <Bq25896.h>
#include <Drv2605.h>
bool tpagerInit();
using namespace tt::hal;
static DeviceVector createDevices() {
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);
auto keyboard = std::make_shared<TpagerKeyboard>(tca8418);
return std::vector<std::shared_ptr<tt::hal::Device>> {
tca8418,
std::make_shared<Bq25896>(i2c),
bq27220,
std::make_shared<Drv2605>(i2c),
power,
createDisplay(),
keyboard,
std::make_shared<TpagerEncoder>()
};
}
extern const Configuration hardwareConfiguration = {
.initBoot = tpagerInit,
.createDevices = createDevices
};
@@ -1,57 +0,0 @@
#include <Bq27220.h>
#include <Tactility/LogMessages.h>
#include <Tactility/SystemEvents.h>
#include <Tactility/service/gps/GpsService.h>
#include <Tactility/hal/gps/GpsConfiguration.h>
#include <driver/gpio.h>
#include <PwmBacklight.h>
#include <tactility/log.h>
constexpr auto* TAG = "T-Lora Pager";
bool tpagerInit() {
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
/* 32 Khz and higher gives an issue where the screen starts dimming again above 80% brightness
* when moving the brightness slider rapidly from a lower setting to 100%.
* This is not a slider bug (data was debug-traced) */
if (!driver::pwmbacklight::init(GPIO_NUM_42, 30000)) {
LOG_E(TAG, "Backlight init failed");
return false;
}
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](auto) {
tt::hal::findDevices([](auto device) {
if (device->getName() == "BQ27220") {
auto bq27220 = std::reinterpret_pointer_cast<Bq27220>(device);
if (bq27220 != nullptr) {
bq27220->configureCapacity(1500, 1500);
return false;
}
}
return true;
});
auto gps_service = tt::service::gps::findGpsService();
if (gps_service != nullptr) {
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 = "uart0",
.baudRate = 38400,
.model = tt::hal::gps::GpsModel::UBLOX10
})) {
LOG_I(TAG, "Configured internal GPS");
} else {
LOG_E(TAG, "Failed to configure internal GPS");
}
}
}
});
return true;
}
@@ -1,15 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <tactility/bindings/bindings.h>
#include <tactility/drivers/root.h>
#include <drivers/TloraPager.h>
DEFINE_DEVICETREE(tlora_pager, struct RootConfig)
#ifdef __cplusplus
}
#endif
@@ -1,33 +0,0 @@
#include "Display.h"
#include <PwmBacklight.h>
#include <St7796Display.h>
#define TPAGER_LCD_SPI_HOST SPI2_HOST
#define TPAGER_LCD_PIN_CS GPIO_NUM_38
#define TPAGER_LCD_PIN_DC GPIO_NUM_37 // RS
#define TPAGER_LCD_HORIZONTAL_RESOLUTION 222
#define TPAGER_LCD_VERTICAL_RESOLUTION 480
#define TPAGER_LCD_SPI_TRANSFER_HEIGHT (TPAGER_LCD_VERTICAL_RESOLUTION / 10)
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
auto configuration = std::make_unique<St7796Display::Configuration>(
TPAGER_LCD_SPI_HOST,
TPAGER_LCD_PIN_CS,
TPAGER_LCD_PIN_DC,
480, // w
222, // h
nullptr,
true, //swapXY
true, //mirrorX
true, //mirrorY
true, //invertColor
0, //gapX
49 //gapY
);
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
auto display = std::make_shared<St7796Display>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}
@@ -1,5 +0,0 @@
#pragma once
#include <Tactility/hal/display/DisplayDevice.h>
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
@@ -1,213 +0,0 @@
#include "TpagerEncoder.h"
#include <driver/gpio.h>
#include <tactility/log.h>
constexpr auto* TAG = "TpagerEncoder";
constexpr auto ENCODER_A = GPIO_NUM_40;
constexpr auto ENCODER_B = GPIO_NUM_41;
constexpr auto ENCODER_ENTER = GPIO_NUM_7;
void TpagerEncoder::readCallback(lv_indev_t* indev, lv_indev_data_t* data) {
TpagerEncoder* encoder = static_cast<TpagerEncoder*>(lv_indev_get_user_data(indev));
constexpr int enter_filter_threshold = 2;
static int enter_filter = 0;
constexpr int pulses_click = 4;
static int pulses_prev = 0;
// Defaults
data->enc_diff = 0;
data->state = LV_INDEV_STATE_RELEASED;
int pulses = encoder->getEncoderPulses();
int pulse_diff = (pulses - pulses_prev);
if ((pulse_diff > pulses_click) || (pulse_diff < -pulses_click)) {
data->enc_diff = pulse_diff / pulses_click;
pulses_prev = pulses;
}
bool enter = !gpio_get_level(ENCODER_ENTER);
if (enter && (enter_filter < enter_filter_threshold)) {
enter_filter++;
}
if (!enter && (enter_filter > 0)) {
enter_filter--;
}
if (enter_filter == enter_filter_threshold) {
data->state = LV_INDEV_STATE_PRESSED;
}
}
bool TpagerEncoder::initEncoder() {
assert(encPcntUnit == nullptr);
constexpr int LOW_LIMIT = -127;
constexpr int HIGH_LIMIT = 126;
// Accum. count makes it that over- and underflows are automatically compensated.
// Prerequisite: watchpoints at low and high limit
pcnt_unit_config_t unit_config = {
.low_limit = LOW_LIMIT,
.high_limit = HIGH_LIMIT,
.intr_priority = 0,
.flags = {
.accum_count = 1
},
};
if (pcnt_new_unit(&unit_config, &encPcntUnit) != ESP_OK) {
LOG_E(TAG, "Pulsecounter initialization failed");
return false;
}
pcnt_glitch_filter_config_t filter_config = {
.max_glitch_ns = 1000,
};
if (pcnt_unit_set_glitch_filter(encPcntUnit, &filter_config) != ESP_OK) {
LOG_E(TAG, "Pulsecounter glitch filter config failed");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
pcnt_chan_config_t chan_1_config = {
.edge_gpio_num = ENCODER_B,
.level_gpio_num = ENCODER_A,
.flags {
.invert_edge_input = 0,
.invert_level_input = 0,
.virt_edge_io_level = 0,
.virt_level_io_level = 0,
.io_loop_back = 0
}
};
pcnt_chan_config_t chan_2_config = {
.edge_gpio_num = ENCODER_A,
.level_gpio_num = ENCODER_B,
.flags {
.invert_edge_input = 0,
.invert_level_input = 0,
.virt_edge_io_level = 0,
.virt_level_io_level = 0,
.io_loop_back = 0
}
};
pcnt_channel_handle_t pcnt_chan_1 = nullptr;
pcnt_channel_handle_t pcnt_chan_2 = nullptr;
if ((pcnt_new_channel(encPcntUnit, &chan_1_config, &pcnt_chan_1) != ESP_OK) ||
(pcnt_new_channel(encPcntUnit, &chan_2_config, &pcnt_chan_2) != ESP_OK)) {
LOG_E(TAG, "Pulsecounter channel config failed");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
// Second argument is rising edge, third argument is falling edge
if ((pcnt_channel_set_edge_action(pcnt_chan_1, PCNT_CHANNEL_EDGE_ACTION_DECREASE, PCNT_CHANNEL_EDGE_ACTION_INCREASE) != ESP_OK) ||
(pcnt_channel_set_edge_action(pcnt_chan_2, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_DECREASE) != ESP_OK)) {
LOG_E(TAG, "Pulsecounter edge action config failed");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
// Second argument is low level, third argument is high level
if ((pcnt_channel_set_level_action(pcnt_chan_1, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_INVERSE) != ESP_OK) ||
(pcnt_channel_set_level_action(pcnt_chan_2, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_INVERSE) != ESP_OK)) {
LOG_E(TAG, "Pulsecounter level action config failed");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
if ((pcnt_unit_add_watch_point(encPcntUnit, LOW_LIMIT) != ESP_OK) ||
(pcnt_unit_add_watch_point(encPcntUnit, HIGH_LIMIT) != ESP_OK)) {
LOG_E(TAG, "Pulsecounter watch point config failed");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
if (pcnt_unit_enable(encPcntUnit) != ESP_OK) {
LOG_E(TAG, "Pulsecounter could not be enabled");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
if (pcnt_unit_clear_count(encPcntUnit) != ESP_OK) {
LOG_E(TAG, "Pulsecounter could not be cleared");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
if (pcnt_unit_start(encPcntUnit) != ESP_OK) {
LOG_E(TAG, "Pulsecounter could not be started");
pcnt_del_unit(encPcntUnit);
encPcntUnit = nullptr;
return false;
}
return true;
}
int TpagerEncoder::getEncoderPulses() const {
int pulses = 0;
pcnt_unit_get_count(encPcntUnit, &pulses);
return pulses;
}
bool TpagerEncoder::deinitEncoder() {
assert(encPcntUnit != nullptr);
if (pcnt_unit_stop(encPcntUnit) != ESP_OK) {
LOG_W(TAG, "Failed to stop encoder");
}
if (pcnt_del_unit(encPcntUnit) != ESP_OK) {
LOG_W(TAG, "Failed to delete encoder");
encPcntUnit = nullptr;
return false;
}
LOG_I(TAG, "Deinitialized");
return true;
}
bool TpagerEncoder::startLvgl(lv_display_t* display) {
if (encPcntUnit == nullptr && !initEncoder()) {
return false;
}
gpio_input_enable(ENCODER_ENTER);
encHandle = lv_indev_create();
lv_indev_set_type(encHandle, LV_INDEV_TYPE_ENCODER);
lv_indev_set_read_cb(encHandle, &readCallback);
lv_indev_set_display(encHandle, display);
lv_indev_set_user_data(encHandle, this);
return true;
}
bool TpagerEncoder::stopLvgl() {
lv_indev_delete(encHandle);
encHandle = nullptr;
if (encPcntUnit != nullptr && !deinitEncoder()) {
// We're not returning false as LVGL as effectively deinitialized
LOG_W(TAG, "Deinitialization failed");
}
return true;
}
@@ -1,30 +0,0 @@
#pragma once
#include <Tactility/hal/encoder/EncoderDevice.h>
#include <driver/pulse_cnt.h>
class TpagerEncoder final : public tt::hal::encoder::EncoderDevice {
lv_indev_t* encHandle = nullptr;
pcnt_unit_handle_t encPcntUnit = nullptr;
bool initEncoder();
bool deinitEncoder();
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
public:
TpagerEncoder() {}
~TpagerEncoder() override {}
std::string getName() const override { return "T-Lora Pager Encoder"; }
std::string getDescription() const override { return "The encoder wheel next to the display"; }
bool startLvgl(lv_display_t* display) override;
bool stopLvgl() override;
int getEncoderPulses() const;
lv_indev_t* getLvglIndev() override { return encHandle; }
};
@@ -1,219 +0,0 @@
#include "TpagerKeyboard.h"
#include <driver/i2c.h>
#include <driver/gpio.h>
#include <tactility/log.h>
constexpr auto* TAG = "TpagerKeyboard";
constexpr auto BACKLIGHT = GPIO_NUM_46;
constexpr auto KB_ROWS = 4;
constexpr auto KB_COLS = 10;
// Lowercase Keymap
static constexpr char keymap_lc[KB_ROWS][KB_COLS] = {
{'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'},
{'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', LV_KEY_ENTER},
{'\0', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '\0', LV_KEY_BACKSPACE},
{' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
};
// Uppercase Keymap
static constexpr char keymap_uc[KB_ROWS][KB_COLS] = {
{'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'},
{'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', LV_KEY_ENTER},
{'\0', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '\0', LV_KEY_BACKSPACE},
{' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
};
// Symbol Keymap
static constexpr char keymap_sy[KB_ROWS][KB_COLS] = {
{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'},
{'.', '/', '+', '-', '=', ':', '\'', '"', '@', '\t'},
{'\0', '_', '$', ';', '?', '!', ',', '.', '\0', LV_KEY_BACKSPACE},
{' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}
};
void TpagerKeyboard::readCallback(lv_indev_t* indev, lv_indev_data_t* data) {
auto keyboard = static_cast<TpagerKeyboard*>(lv_indev_get_user_data(indev));
char keypress = 0;
if (xQueueReceive(keyboard->queue, &keypress, 0) == pdPASS) {
data->key = keypress;
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->key = 0;
data->state = LV_INDEV_STATE_RELEASED;
}
}
void TpagerKeyboard::processKeyboard() {
static bool shift_pressed = false;
static bool sym_pressed = false;
static bool cap_toggle = false;
static bool cap_toggle_armed = true;
bool anykey_pressed = false;
if (keypad->update()) {
anykey_pressed = (keypad->pressed_key_count > 0);
for (int i = 0; i < keypad->pressed_key_count; i++) {
auto row = keypad->pressed_list[i].row;
auto col = keypad->pressed_list[i].col;
auto hold = keypad->pressed_list[i].hold_time;
if ((row == 2) && (col == 0)) {
sym_pressed = true;
}
if ((row == 2) && (col == 8)) {
shift_pressed = true;
}
}
if ((sym_pressed && shift_pressed) && cap_toggle_armed) {
cap_toggle = !cap_toggle;
cap_toggle_armed = false;
}
for (int i = 0; i < keypad->pressed_key_count; i++) {
auto row = keypad->pressed_list[i].row;
auto col = keypad->pressed_list[i].col;
auto hold = keypad->pressed_list[i].hold_time;
char chr = '\0';
if (sym_pressed) {
chr = keymap_sy[row][col];
} else if (shift_pressed || cap_toggle) {
chr = keymap_uc[row][col];
} else {
chr = keymap_lc[row][col];
}
if (chr != '\0') xQueueSend(queue, &chr, 50 / portTICK_PERIOD_MS);
}
for (int i = 0; i < keypad->released_key_count; i++) {
auto row = keypad->released_list[i].row;
auto col = keypad->released_list[i].col;
if ((row == 2) && (col == 0)) {
sym_pressed = false;
}
if ((row == 2) && (col == 8)) {
shift_pressed = false;
}
}
if ((!sym_pressed && !shift_pressed) && !cap_toggle_armed) {
cap_toggle_armed = true;
}
if (anykey_pressed) {
makeBacklightImpulse();
}
}
}
bool TpagerKeyboard::startLvgl(lv_display_t* display) {
backlightOkay = initBacklight(BACKLIGHT, 30000, LEDC_TIMER_0, LEDC_CHANNEL_1);
keypad->init(KB_ROWS, KB_COLS);
assert(inputTimer == nullptr);
inputTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, tt::kernel::millisToTicks(20), [this] {
processKeyboard();
});
assert(backlightImpulseTimer == nullptr);
backlightImpulseTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, tt::kernel::millisToTicks(50), [this] {
processBacklightImpulse();
});
kbHandle = lv_indev_create();
lv_indev_set_type(kbHandle, LV_INDEV_TYPE_KEYPAD);
lv_indev_set_read_cb(kbHandle, &readCallback);
lv_indev_set_display(kbHandle, display);
lv_indev_set_user_data(kbHandle, this);
inputTimer->start();
backlightImpulseTimer->start();
return true;
}
bool TpagerKeyboard::stopLvgl() {
assert(inputTimer);
inputTimer->stop();
inputTimer = nullptr;
assert(backlightImpulseTimer);
backlightImpulseTimer->stop();
backlightImpulseTimer = nullptr;
lv_indev_delete(kbHandle);
kbHandle = nullptr;
return true;
}
bool TpagerKeyboard::isAttached() const {
return i2c_controller_has_device_at_address(keypad->getController(), keypad->getAddress(), 100) == ERROR_NONE;
}
bool TpagerKeyboard::initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel) {
backlightPin = pin;
backlightTimer = timer;
backlightChannel = channel;
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_8_BIT,
.timer_num = backlightTimer,
.freq_hz = frequencyHz,
.clk_cfg = LEDC_AUTO_CLK,
.deconfigure = false
};
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
LOG_E(TAG, "Backlight timer config failed");
return false;
}
ledc_channel_config_t ledc_channel = {
.gpio_num = backlightPin,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = backlightChannel,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = backlightTimer,
.duty = 0,
.hpoint = 0,
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
.flags = {
.output_invert = 0
}
};
if (ledc_channel_config(&ledc_channel) != ESP_OK) {
LOG_E(TAG, "Backlight channel config failed");
}
return true;
}
bool TpagerKeyboard::setBacklightDuty(uint8_t duty) {
if (!backlightOkay) {
LOG_E(TAG, "Backlight not ready");
return false;
}
return (ledc_set_duty(LEDC_LOW_SPEED_MODE, backlightChannel, duty) == ESP_OK) &&
(ledc_update_duty(LEDC_LOW_SPEED_MODE, backlightChannel) == ESP_OK);
}
void TpagerKeyboard::makeBacklightImpulse() {
backlightImpulseDuty = 255;
setBacklightDuty(backlightImpulseDuty);
}
void TpagerKeyboard::processBacklightImpulse() {
if (backlightImpulseDuty > 64) {
backlightImpulseDuty--;
setBacklightDuty(backlightImpulseDuty);
}
}
@@ -1,52 +0,0 @@
#pragma once
#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tactility/Timer.h>
#include <Tca8418.h>
#include <driver/gpio.h>
#include <driver/ledc.h>
#include <freertos/queue.h>
class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice {
lv_indev_t* kbHandle = nullptr;
gpio_num_t backlightPin = GPIO_NUM_NC;
ledc_timer_t backlightTimer;
ledc_channel_t backlightChannel;
bool backlightOkay = false;
int backlightImpulseDuty = 0;
QueueHandle_t queue = nullptr;
std::shared_ptr<Tca8418> keypad;
std::unique_ptr<tt::Timer> inputTimer;
std::unique_ptr<tt::Timer> backlightImpulseTimer;
bool initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel);
void processKeyboard();
void processBacklightImpulse();
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
public:
explicit TpagerKeyboard(const std::shared_ptr<Tca8418>& tca) : keypad(tca) {
queue = xQueueCreate(20, sizeof(char));
}
~TpagerKeyboard() override {
vQueueDelete(queue);
}
std::string getName() const override { return "T-Lora Pager Keyboard"; }
std::string getDescription() const override { return "T-Lora Pager I2C keyboard with encoder"; }
bool startLvgl(lv_display_t* display) override;
bool stopLvgl() override;
bool isAttached() const override;
lv_indev_t* getLvglIndev() override { return kbHandle; }
bool setBacklightDuty(uint8_t duty);
void makeBacklightImpulse();
};
@@ -1,77 +0,0 @@
#include "TpagerPower.h"
#include <Bq25896.h>
#include <tactility/log.h>
constexpr auto* TAG = "TpagerPower";
TpagerPower::~TpagerPower() {}
bool TpagerPower::supportsMetric(MetricType type) const {
switch (type) {
using enum MetricType;
case IsCharging:
case Current:
case BatteryVoltage:
case ChargeLevel:
return true;
default:
return false;
}
return false; // Safety guard for when new enum values are introduced
}
bool TpagerPower::getMetric(MetricType type, MetricData& data) {
uint16_t u16 = 0;
int16_t s16 = 0;
switch (type) {
using enum MetricType;
case IsCharging:
Bq27220::BatteryStatus status;
if (gauge->getBatteryStatus(status)) {
data.valueAsBool = !status.reg.DSG;
return true;
}
return false;
case Current:
if (gauge->getCurrent(s16)) {
data.valueAsInt32 = s16;
return true;
} else {
return false;
}
case BatteryVoltage:
if (gauge->getVoltage(u16)) {
data.valueAsUint32 = u16;
return true;
} else {
return false;
}
case ChargeLevel:
if (gauge->getStateOfCharge(u16)) {
data.valueAsUint8 = u16;
return true;
} else {
return false;
}
default:
return false;
}
}
void TpagerPower::powerOff() {
auto device = tt::hal::findDevice([](auto device) {
return device->getName() == "BQ25896";
});
if (device == nullptr) {
LOG_E(TAG, "BQ25896 not found");
return;
}
auto bq25896 = std::reinterpret_pointer_cast<Bq25896>(device);
if (bq25896 != nullptr) {
bq25896->powerOff();
}
}
@@ -1,25 +0,0 @@
#pragma once
#include "Tactility/hal/power/PowerDevice.h"
#include <Bq27220.h>
#include <memory>
using tt::hal::power::PowerDevice;
class TpagerPower : public PowerDevice {
std::shared_ptr<Bq27220> gauge;
public:
TpagerPower(const std::shared_ptr<Bq27220>& bq) : gauge(bq) {}
~TpagerPower();
std::string getName() const final { return "T-LoRa Pager Power measument"; }
std::string getDescription() const final { return "Power measurement interface via I2C fuel gauge"; }
bool supportsMetric(MetricType type) const override;
bool getMetric(MetricType type, MetricData& data) override;
bool supportsPowerOff() const override { return true; }
void powerOff() override;
};
@@ -1,30 +0,0 @@
#include "TloraPager.h"
#include <tactility/driver.h>
#include <esp_log.h>
extern "C" {
extern struct Module lilygo_tlora_pager_module;
static int start(Device* device) {
return 0;
}
static int stop(Device* device) {
return 0;
}
Driver tlora_pager_driver = {
.name = "T-Lora Pager",
.compatible = (const char*[]) { "lilygo,tlora-pager", nullptr },
.start_device = start,
.stop_device = stop,
.api = nullptr,
.device_type = nullptr,
.owner = &lilygo_tlora_pager_module,
.internal = nullptr
};
}
@@ -1,11 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <tactility/drivers/root.h>
#ifdef __cplusplus
}
#endif
@@ -1,31 +0,0 @@
#include <tactility/check.h>
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
extern Driver tlora_pager_driver;
static error_t start() {
/* We crash when construct fails, because if a single driver fails to construct,
* there is no guarantee that the previously constructed drivers can be destroyed */
check(driver_construct_add(&tlora_pager_driver) == ERROR_NONE);
return ERROR_NONE;
}
static error_t stop() {
/* We crash when destruct fails, because if a single driver fails to destruct,
* there is no guarantee that the previously destroyed drivers can be recovered */
check(driver_remove_destruct(&tlora_pager_driver) == ERROR_NONE);
return ERROR_NONE;
}
struct Module lilygo_tlora_pager_module = {
.name = "lilygo-tlora-pager",
.start = start,
.stop = stop,
.symbols = nullptr,
.internal = nullptr
};
}
+6 -1
View File
@@ -1,4 +1,9 @@
dependencies:
- Platforms/platform-esp32
bindings: ./
- Drivers/st7796-module
- Drivers/bq27220-module
- Drivers/tca8418-module
- Drivers/bq25896-module
- Drivers/drv2605-module
- Drivers/lilygo-module
dts: lilygo,tlora-pager.dts
+126 -13
View File
@@ -1,6 +1,6 @@
/dts-v1/;
#include <bindings/tlora_pager.h>
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_wifi_pinned.h>
#include <tactility/bindings/esp32_gpio.h>
@@ -9,11 +9,18 @@
#include <tactility/bindings/esp32_spi.h>
#include <tactility/bindings/esp32_uart.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <tactility/bindings/display_placeholder.h>
#include <tactility/bindings/esp32_pwm_ledc.h>
#include <tactility/bindings/pwm_backlight.h>
#include <bindings/st7796.h>
#include <bindings/bq27220.h>
#include <bindings/tca8418.h>
#include <bindings/bq25896.h>
#include <bindings/drv2605.h>
#include <lilygo/bindings/tpager_encoder.h>
// Reference: https://wiki.lilygo.cc/get_started/en/LoRa_GPS/T-LoraPager/T-LoraPager.html#Pin-Overview
// Reference: https://wiki.lilygo.cc/get_started/en/LoRa_GPS/T-LoraPager/T-LoraPager.html
/ {
compatible = "lilygo,tlora-pager";
compatible = "root";
model = "LilyGO T-Lora Pager";
wifi0 {
@@ -37,26 +44,124 @@
clock-frequency = <100000>;
pin-sda = <&gpio0 3 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 2 GPIO_FLAG_NONE>;
bq27220 {
compatible = "ti,bq27220";
reg = <0x55>;
};
// ALT (shift) is row 2 col 8; SYM (symbol layer) is row 2 col 0.
keyboard {
compatible = "ti,tca8418";
reg = <0x34>;
rows = <4>;
columns = <10>;
keymap-lc = [
113 119 101 114 116 121 117 105 111 112 // q w e r t y u i o p
97 115 100 102 103 104 106 107 108 10 // a s d f g h j k l ENTER
0 122 120 99 118 98 110 109 0 8 // z x c v b n m BACKSPACE
32 0 0 0 0 0 0 0 0 0 // SPC
];
keymap-uc = [
81 87 69 82 84 89 85 73 79 80 // Q W E R T Y U I O P
65 83 68 70 71 72 74 75 76 10 // A S D F G H J K L ENTER
0 90 88 67 86 66 78 77 0 8 // Z X C V B N M BACKSPACE
32 0 0 0 0 0 0 0 0 0 // SPC
];
keymap-sy = [
49 50 51 52 53 54 55 56 57 48 // 1 2 3 4 5 6 7 8 9 0
46 47 43 45 61 58 39 34 64 9 // . / + - = : ' " @ TAB
0 95 36 59 63 33 44 46 0 8 // _ $ ; ? ! , . BACKSPACE
32 0 0 0 0 0 0 0 0 0 // SPC
];
shift-row = <2>;
shift-col = <8>;
sym-row = <2>;
sym-col = <0>;
};
bq25896 {
compatible = "ti,bq25896";
reg = <0x6B>;
};
// Plays a 3x strong-click "buzz" once at boot to confirm the motor works (matches the
// deprecated HAL's Drv2605 default autoPlayStartupBuzz=true).
drv2605 {
compatible = "ti,drv2605";
reg = <0x5A>;
};
};
// Keyboard backlight (LED_PWM), GPIO46. The keypress-triggered flash/decay effect from the
// pre-migration driver isn't reproduced here - kernel drivers don't have a home for that kind
// of UI policy (same reasoning as the encoder/touch drivers elsewhere). Off by default; app
// code can drive brightness via the generic pwm-backlight API if desired.
keyboard_backlight_pwm {
compatible = "espressif,esp32-pwm-ledc";
pin = <&gpio0 46 GPIO_FLAG_NONE>;
period-ns = <33333>;
ledc-timer = <1>;
ledc-channel = <1>;
};
keyboard_backlight {
compatible = "pwm-backlight";
status = "disabled";
pwm = <&keyboard_backlight_pwm>;
};
display_backlight_pwm {
compatible = "espressif,esp32-pwm-ledc";
pin = <&gpio0 42 GPIO_FLAG_NONE>;
// 32 KHz and higher causes the screen to start dimming again above 80% brightness
// when moving the brightness slider rapidly from a lower setting to 100% (debug-traced, not a slider bug).
period-ns = <33333>;
ledc-timer = <0>;
ledc-channel = <0>;
};
display_backlight {
compatible = "pwm-backlight";
// Off by default so display power-on won't show the screen from before the last power loss.
// The display backlight is turned on during the boot process.
status = "disabled";
pwm = <&display_backlight_pwm>;
};
spi0 {
compatible = "espressif,esp32-spi";
host = <SPI2_HOST>;
cs-gpios = <&gpio0 36 GPIO_FLAG_NONE>, // Display
<&gpio0 21 GPIO_FLAG_NONE>; // SD card
cs-gpios = <&gpio0 21 GPIO_FLAG_NONE>, // SD
<&gpio0 38 GPIO_FLAG_NONE>, // Display
<&gpio0 36 GPIO_FLAG_NONE>, // Lora
<&gpio0 39 GPIO_FLAG_NONE>; // NFC
pin-mosi = <&gpio0 34 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 33 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 35 GPIO_FLAG_NONE>;
display@0 {
compatible = "display-placeholder";
};
sdcard@1 {
miso-pull-up;
sdcard@0 {
compatible = "espressif,esp32-sdspi";
status = "disabled"; // Must be started after display
frequency-khz = <20000>;
};
display@1 {
compatible = "sitronix,st7796";
horizontal-resolution = <480>;
vertical-resolution = <222>;
swap-xy;
mirror-x;
mirror-y;
invert-color;
bgr-order;
gap-x = <0>;
gap-y = <49>;
pixel-clock-hz = <80000000>;
transaction-queue-depth = <2>;
pin-dc = <&gpio0 37 GPIO_FLAG_NONE>;
backlight = <&display_backlight>;
};
};
// ES8311
@@ -84,4 +189,12 @@
pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
};
// Encoder wheel next to the display.
encoder {
compatible = "lilygo,tpager-encoder";
pin-a = <&gpio0 40 GPIO_FLAG_NONE>;
pin-b = <&gpio0 41 GPIO_FLAG_NONE>;
pin-enter = <&gpio0 7 GPIO_FLAG_NONE>;
};
};
@@ -1,5 +0,0 @@
description: LilyGO T-Lora Pager
include: ["root.yaml"]
compatible: "lilygo,tlora-pager"
@@ -0,0 +1,72 @@
#include <tactility/check.h>
#include <tactility/driver.h>
#include <tactility/module.h>
#include <Tactility/LogMessages.h>
#include <Tactility/SystemEvents.h>
#include <Tactility/hal/Configuration.h>
#include <Tactility/hal/gps/GpsConfiguration.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/service/gps/GpsService.h>
#include <tactility/log.h>
#include <tactility/lvgl_module.h>
#include <lilygo/drivers/tpager_encoder_input.h>
constexpr auto* TAG = "T-Lora Pager";
// Legacy placeholder (required until legacy HAL is cleaned up everywhere). All board
// peripherals are kernel drivers now (see the .dts): display (st7796), battery (bq27220),
// charger power-off (bq25896), haptics (drv2605), keyboard (tca8418) and the encoder wheel
// (lilygo,tpager-encoder, bound to LVGL below).
extern const tt::hal::Configuration hardwareConfiguration = {};
extern "C" {
static void subscribe_events() {
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent) {
// The kernel tpager_encoder device is already started by kernel_init(); this just
// registers it as an LVGL input device, which requires LVGL to be up first.
lvgl_lock();
tpager_encoder::init();
lvgl_unlock();
auto gps_service = tt::service::gps::findGpsService();
if (gps_service != nullptr) {
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 = "uart0",
.baudRate = 38400,
.model = tt::hal::gps::GpsModel::UBLOX10
})) {
LOG_I(TAG, "Configured internal GPS");
} else {
LOG_E(TAG, "Failed to configure internal GPS");
}
}
}
});
}
static error_t start() {
subscribe_events();
return ERROR_NONE;
}
static error_t stop() {
return ERROR_NONE;
}
struct Module lilygo_tlora_pager_module = {
.name = "lilygo-tlora-pager",
.start = start,
.stop = stop,
.symbols = nullptr,
.internal = nullptr
};
}