mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-20 15:35:05 +00:00
Compare commits
No commits in common. "61756bf5422e58bd6acb9e15f446c04c52509a8b" and "b2d1a786b14012e55ea7fd8f2227cda1a69a806b" have entirely different histories.
61756bf542
...
b2d1a786b1
@ -4,13 +4,13 @@
|
||||
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
|
||||
constexpr auto SDCARD_SPI_HOST = SPI3_HOST;
|
||||
constexpr auto SDCARD_PIN_CS = GPIO_NUM_5;
|
||||
#define SDCARD_SPI_HOST SPI3_HOST
|
||||
#define SDCARD_PIN_CS GPIO_NUM_5
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createYellowSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
@ -21,8 +21,10 @@ std::shared_ptr<SdCardDevice> createYellowSdCard() {
|
||||
SDCARD_SPI_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
@ -20,8 +20,10 @@ std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
SDCARD_SPI_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
|
||||
@ -5,13 +5,13 @@
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
constexpr auto SDCARD_SPI_HOST = SPI3_HOST;
|
||||
constexpr auto SDCARD_PIN_CS = GPIO_NUM_5;
|
||||
#define SDCARD_SPI_HOST SPI3_HOST
|
||||
#define SDCARD_PIN_CS GPIO_NUM_5
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createYellowSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
@ -22,8 +22,10 @@ std::shared_ptr<SdCardDevice> createYellowSdCard() {
|
||||
SDCARD_SPI_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
|
||||
@ -7,21 +7,23 @@
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7;
|
||||
#define CROWPANEL_SDCARD_PIN_CS GPIO_NUM_7
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
CROWPANEL_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector<gpio_num_t>(),
|
||||
{},
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -7,21 +7,23 @@
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7;
|
||||
#define CROWPANEL_SDCARD_PIN_CS GPIO_NUM_7
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
CROWPANEL_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector<gpio_num_t>(),
|
||||
{},
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
// See https://github.com/Elecrow-RD/CrowPanel-Advance-HMI-ESP32-AI-Display/blob/master/5.0/factory_code/factory_code.ino
|
||||
GPIO_NUM_0, // It's actually not connected, but in the demo pin 0 is used
|
||||
GPIO_NUM_NC,
|
||||
@ -17,7 +17,9 @@ std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
SdCardDevice::MountBehaviour::AtBoot
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -8,18 +8,20 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
GPIO_NUM_5,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector<gpio_num_t>(),
|
||||
{},
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -6,18 +6,20 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
GPIO_NUM_5,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector<gpio_num_t>(),
|
||||
{},
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
GPIO_NUM_10,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
@ -16,7 +16,9 @@ std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
SdCardDevice::MountBehaviour::AtBoot
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -3,5 +3,5 @@ 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
|
||||
REQUIRES Tactility esp_lcd ST7796 BQ25896 BQ27220 TCA8418 PwmBacklight driver esp_adc
|
||||
)
|
||||
|
||||
@ -6,8 +6,18 @@
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#include <PwmBacklight.h>
|
||||
#include <Bq25896.h>
|
||||
#include <Bq27220.h>
|
||||
#include <Tca8418.h>
|
||||
|
||||
constexpr auto* TAG = "TLoraPager";
|
||||
#define TAG "TLoraPager"
|
||||
|
||||
// Power on
|
||||
constexpr auto TDECK_POWERON_GPIO = GPIO_NUM_10;
|
||||
|
||||
std::shared_ptr<Bq27220> bq27220;
|
||||
std::shared_ptr<Tca8418> tca8418;
|
||||
std::shared_ptr<Bq25896> bq25896;
|
||||
|
||||
bool tpagerInit() {
|
||||
ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
@ -20,17 +30,25 @@ bool tpagerInit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](auto) {
|
||||
bq27220 = std::make_shared<Bq27220>(I2C_NUM_0);
|
||||
tt::hal::registerDevice(bq27220);
|
||||
|
||||
tca8418 = std::make_shared<Tca8418>(I2C_NUM_0);
|
||||
tt::hal::registerDevice(tca8418);
|
||||
|
||||
bq25896 = std::make_shared<Bq25896>(I2C_NUM_0);
|
||||
tt::hal::registerDevice(bq25896);
|
||||
bq25896->powerOn();
|
||||
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
bq27220->configureCapacity(1500, 1500);
|
||||
|
||||
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 = "Internal",
|
||||
.baudRate = 38400,
|
||||
.model = tt::hal::gps::GpsModel::UBLOX10
|
||||
})) {
|
||||
if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "Grove", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) {
|
||||
TT_LOG_I(TAG, "Configured internal GPS");
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to configure internal GPS");
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "hal/TpagerDisplay.h"
|
||||
#include "hal/TpagerEncoder.h"
|
||||
#include "hal/TpagerDisplayConstants.h"
|
||||
#include "hal/TpagerKeyboard.h"
|
||||
#include "hal/TpagerPower.h"
|
||||
#include "hal/TpagerSdCard.h"
|
||||
|
||||
#include <Bq25896.h>
|
||||
#include <Drv2605.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
#define TPAGER_SPI_TRANSFER_SIZE_LIMIT (TPAGER_LCD_HORIZONTAL_RESOLUTION * TPAGER_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8))
|
||||
@ -16,30 +13,12 @@ bool tpagerInit();
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
DeviceVector createDevices() {
|
||||
auto bq27220 = std::make_shared<Bq27220>(I2C_NUM_0);
|
||||
bq27220->configureCapacity(1500, 1500);
|
||||
auto power = std::make_shared<TpagerPower>(bq27220);
|
||||
|
||||
auto tca8418 = std::make_shared<Tca8418>(I2C_NUM_0);
|
||||
auto keyboard = std::make_shared<TpagerKeyboard>(tca8418);
|
||||
|
||||
return std::vector<std::shared_ptr<Device>> {
|
||||
tca8418,
|
||||
std::make_shared<Bq25896>(I2C_NUM_0),
|
||||
bq27220,
|
||||
std::make_shared<Drv2605>(I2C_NUM_0),
|
||||
power,
|
||||
createTpagerSdCard(),
|
||||
createDisplay(),
|
||||
keyboard,
|
||||
std::make_shared<TpagerEncoder>()
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration lilygo_tlora_pager = {
|
||||
.initBoot = tpagerInit,
|
||||
.createDevices = createDevices,
|
||||
.createDisplay = createDisplay,
|
||||
.createKeyboard = createKeyboard,
|
||||
.sdcard = createTpagerSdCard(),
|
||||
.power = tpager_get_power,
|
||||
.i2c = {
|
||||
i2c::Configuration {
|
||||
.name = "Shared",
|
||||
@ -62,28 +41,24 @@ extern const Configuration lilygo_tlora_pager = {
|
||||
.spi {spi::Configuration {
|
||||
.device = SPI2_HOST,
|
||||
.dma = SPI_DMA_CH_AUTO,
|
||||
.config = {
|
||||
.mosi_io_num = GPIO_NUM_34,
|
||||
.miso_io_num = GPIO_NUM_33,
|
||||
.sclk_io_num = GPIO_NUM_35,
|
||||
.quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported
|
||||
.quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported
|
||||
.data4_io_num = GPIO_NUM_NC,
|
||||
.data5_io_num = GPIO_NUM_NC,
|
||||
.data6_io_num = GPIO_NUM_NC,
|
||||
.data7_io_num = GPIO_NUM_NC,
|
||||
.data_io_default_level = false,
|
||||
.max_transfer_sz = TPAGER_SPI_TRANSFER_SIZE_LIMIT,
|
||||
.flags = 0,
|
||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
.intr_flags = 0
|
||||
},
|
||||
.config = {.mosi_io_num = GPIO_NUM_34, .miso_io_num = GPIO_NUM_33, .sclk_io_num = GPIO_NUM_35,
|
||||
.quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported
|
||||
.quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported
|
||||
.data4_io_num = GPIO_NUM_NC,
|
||||
.data5_io_num = GPIO_NUM_NC,
|
||||
.data6_io_num = GPIO_NUM_NC,
|
||||
.data7_io_num = GPIO_NUM_NC,
|
||||
.data_io_default_level = false,
|
||||
.max_transfer_sz = TPAGER_SPI_TRANSFER_SIZE_LIMIT,
|
||||
.flags = 0,
|
||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
.intr_flags = 0},
|
||||
.initMode = spi::InitMode::ByTactility,
|
||||
.isMutable = false,
|
||||
.lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display
|
||||
}},
|
||||
.uart {uart::Configuration {
|
||||
.name = "Internal",
|
||||
.name = "Grove",
|
||||
.port = UART_NUM_1,
|
||||
.rxPin = GPIO_NUM_4,
|
||||
.txPin = GPIO_NUM_12,
|
||||
|
||||
@ -1,141 +0,0 @@
|
||||
#include "TpagerEncoder.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/hal/Gpio.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;
|
||||
}
|
||||
}
|
||||
|
||||
void TpagerEncoder::initEncoder() {
|
||||
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,
|
||||
.flags = {.accum_count = 1},
|
||||
};
|
||||
|
||||
if (pcnt_new_unit(&unit_config, &encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter intialization failed");
|
||||
}
|
||||
|
||||
pcnt_glitch_filter_config_t filter_config = {
|
||||
.max_glitch_ns = 1000,
|
||||
};
|
||||
|
||||
if (pcnt_unit_set_glitch_filter(encPcntUnit, &filter_config) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter glitch filter config failed");
|
||||
}
|
||||
|
||||
pcnt_chan_config_t chan_1_config = {
|
||||
.edge_gpio_num = ENCODER_B,
|
||||
.level_gpio_num = ENCODER_A,
|
||||
};
|
||||
|
||||
pcnt_chan_config_t chan_2_config = {
|
||||
.edge_gpio_num = ENCODER_A,
|
||||
.level_gpio_num = ENCODER_B,
|
||||
};
|
||||
|
||||
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)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter channel config failed");
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter edge action config failed");
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter level action config failed");
|
||||
}
|
||||
|
||||
if ((pcnt_unit_add_watch_point(encPcntUnit, LOW_LIMIT) != ESP_OK) ||
|
||||
(pcnt_unit_add_watch_point(encPcntUnit, HIGH_LIMIT) != ESP_OK)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter watch point config failed");
|
||||
}
|
||||
|
||||
if (pcnt_unit_enable(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be enabled");
|
||||
}
|
||||
|
||||
if (pcnt_unit_clear_count(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be cleared");
|
||||
}
|
||||
|
||||
if (pcnt_unit_start(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be started");
|
||||
}
|
||||
}
|
||||
|
||||
int TpagerEncoder::getEncoderPulses() {
|
||||
int pulses = 0;
|
||||
pcnt_unit_get_count(encPcntUnit, &pulses);
|
||||
return pulses;
|
||||
}
|
||||
|
||||
|
||||
bool TpagerEncoder::startLvgl(lv_display_t* display) {
|
||||
initEncoder();
|
||||
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1,29 +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* _Nullable encHandle = nullptr;
|
||||
pcnt_unit_handle_t encPcntUnit = nullptr;
|
||||
|
||||
void initEncoder();
|
||||
|
||||
static void readCallback(lv_indev_t* indev, lv_indev_data_t* data);
|
||||
|
||||
public:
|
||||
|
||||
TpagerEncoder() {}
|
||||
~TpagerEncoder() {}
|
||||
|
||||
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();
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return encHandle; }
|
||||
};
|
||||
@ -7,12 +7,15 @@
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerKeyboard";
|
||||
#define TAG "tpager_keyboard"
|
||||
|
||||
constexpr auto BACKLIGHT = GPIO_NUM_46;
|
||||
#define ENCODER_A GPIO_NUM_40
|
||||
#define ENCODER_B GPIO_NUM_41
|
||||
#define ENCODER_ENTER GPIO_NUM_7
|
||||
#define BACKLIGHT GPIO_NUM_46
|
||||
|
||||
constexpr auto KB_ROWS = 4;
|
||||
constexpr auto KB_COLS = 11;
|
||||
#define KB_ROWS 4
|
||||
#define KB_COLS 11
|
||||
|
||||
// Lowercase Keymap
|
||||
static constexpr char keymap_lc[KB_ROWS][KB_COLS] = {
|
||||
@ -38,17 +41,58 @@ static constexpr char keymap_sy[KB_ROWS][KB_COLS] = {
|
||||
{'\0', '\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));
|
||||
static QueueHandle_t keyboardMsg;
|
||||
|
||||
static void keyboard_read_callback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
TpagerKeyboard* kb = (TpagerKeyboard*)lv_indev_get_user_data(indev);
|
||||
static bool enter_prev = false;
|
||||
char keypress = 0;
|
||||
|
||||
if (xQueueReceive(keyboard->queue, &keypress, pdMS_TO_TICKS(50)) == pdPASS) {
|
||||
TT_LOG_I(TAG, "Keypress: %c", keypress);
|
||||
// Defaults
|
||||
data->key = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
if (xQueueReceive(keyboardMsg, &keypress, pdMS_TO_TICKS(50)) == pdPASS) {
|
||||
data->key = keypress;
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
} else {
|
||||
data->key = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
}
|
||||
|
||||
static void encoder_read_callback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
TpagerKeyboard* kb = (TpagerKeyboard*)lv_indev_get_user_data(indev);
|
||||
const int enter_filter_threshold = 2;
|
||||
static int enter_filter = 0;
|
||||
const int pulses_click = 4;
|
||||
static int pulses_prev = 0;
|
||||
bool anyinput = false;
|
||||
|
||||
// Defaults
|
||||
data->enc_diff = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
int pulses = kb->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;
|
||||
anyinput = true;
|
||||
}
|
||||
|
||||
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;
|
||||
anyinput = true;
|
||||
}
|
||||
|
||||
if (anyinput) {
|
||||
kb->makeBacklightImpulse();
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +136,7 @@ void TpagerKeyboard::processKeyboard() {
|
||||
chr = keymap_lc[row][col];
|
||||
}
|
||||
|
||||
if (chr != '\0') xQueueSend(queue, &chr, portMAX_DELAY);
|
||||
if (chr != '\0') xQueueSend(keyboardMsg, (void*)&chr, portMAX_DELAY);
|
||||
}
|
||||
|
||||
for (int i = 0; i < keypad->released_key_count; i++) {
|
||||
@ -119,7 +163,9 @@ void TpagerKeyboard::processKeyboard() {
|
||||
|
||||
bool TpagerKeyboard::startLvgl(lv_display_t* display) {
|
||||
backlightOkay = initBacklight(BACKLIGHT, 30000, LEDC_TIMER_0, LEDC_CHANNEL_1);
|
||||
initEncoder();
|
||||
keypad->init(KB_ROWS, KB_COLS);
|
||||
gpio_input_enable(ENCODER_ENTER);
|
||||
|
||||
assert(inputTimer == nullptr);
|
||||
inputTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, [this] {
|
||||
@ -128,15 +174,21 @@ bool TpagerKeyboard::startLvgl(lv_display_t* display) {
|
||||
|
||||
assert(backlightImpulseTimer == nullptr);
|
||||
backlightImpulseTimer = std::make_unique<tt::Timer>(tt::Timer::Type::Periodic, [this] {
|
||||
processBacklightImpulse();
|
||||
processBacklightImpuse();
|
||||
});
|
||||
|
||||
kbHandle = lv_indev_create();
|
||||
lv_indev_set_type(kbHandle, LV_INDEV_TYPE_KEYPAD);
|
||||
lv_indev_set_read_cb(kbHandle, &readCallback);
|
||||
lv_indev_set_read_cb(kbHandle, &keyboard_read_callback);
|
||||
lv_indev_set_display(kbHandle, display);
|
||||
lv_indev_set_user_data(kbHandle, this);
|
||||
|
||||
encHandle = lv_indev_create();
|
||||
lv_indev_set_type(encHandle, LV_INDEV_TYPE_ENCODER);
|
||||
lv_indev_set_read_cb(encHandle, &encoder_read_callback);
|
||||
lv_indev_set_display(encHandle, display);
|
||||
lv_indev_set_user_data(encHandle, this);
|
||||
|
||||
inputTimer->start(20 / portTICK_PERIOD_MS);
|
||||
backlightImpulseTimer->start(50 / portTICK_PERIOD_MS);
|
||||
|
||||
@ -154,6 +206,8 @@ bool TpagerKeyboard::stopLvgl() {
|
||||
|
||||
lv_indev_delete(kbHandle);
|
||||
kbHandle = nullptr;
|
||||
lv_indev_delete(encHandle);
|
||||
encHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -161,6 +215,81 @@ bool TpagerKeyboard::isAttached() const {
|
||||
return tt::hal::i2c::masterHasDeviceAtAddress(keypad->getPort(), keypad->getAddress(), 100);
|
||||
}
|
||||
|
||||
void TpagerKeyboard::initEncoder(void) {
|
||||
const int low_limit = -127;
|
||||
const 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,
|
||||
.flags = {.accum_count = 1},
|
||||
};
|
||||
|
||||
if (pcnt_new_unit(&unit_config, &encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter intialization failed");
|
||||
}
|
||||
|
||||
pcnt_glitch_filter_config_t filter_config = {
|
||||
.max_glitch_ns = 5000,
|
||||
};
|
||||
if (pcnt_unit_set_glitch_filter(encPcntUnit, &filter_config) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter glitch filter config failed");
|
||||
}
|
||||
|
||||
pcnt_chan_config_t chan_1_config = {
|
||||
.edge_gpio_num = ENCODER_B,
|
||||
.level_gpio_num = ENCODER_A,
|
||||
};
|
||||
pcnt_chan_config_t chan_2_config = {
|
||||
.edge_gpio_num = ENCODER_A,
|
||||
.level_gpio_num = ENCODER_B,
|
||||
};
|
||||
|
||||
pcnt_channel_handle_t pcnt_chan_1 = NULL;
|
||||
pcnt_channel_handle_t pcnt_chan_2 = NULL;
|
||||
|
||||
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)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter channel config failed");
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter edge action config failed");
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter level action config failed");
|
||||
}
|
||||
|
||||
if ((pcnt_unit_add_watch_point(encPcntUnit, low_limit) != ESP_OK) ||
|
||||
(pcnt_unit_add_watch_point(encPcntUnit, high_limit) != ESP_OK)) {
|
||||
TT_LOG_E(TAG, "Pulsecounter watch point config failed");
|
||||
}
|
||||
|
||||
if (pcnt_unit_enable(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be enabled");
|
||||
}
|
||||
if (pcnt_unit_clear_count(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be cleared");
|
||||
}
|
||||
if (pcnt_unit_start(encPcntUnit) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Pulsecounter could not be started");
|
||||
}
|
||||
}
|
||||
|
||||
int TpagerKeyboard::getEncoderPulses() {
|
||||
int pulses = 0;
|
||||
pcnt_unit_get_count(encPcntUnit, &pulses);
|
||||
return pulses;
|
||||
}
|
||||
|
||||
|
||||
bool TpagerKeyboard::initBacklight(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel) {
|
||||
backlightPin = pin;
|
||||
backlightTimer = timer;
|
||||
@ -215,9 +344,16 @@ void TpagerKeyboard::makeBacklightImpulse() {
|
||||
setBacklightDuty(backlightImpulseDuty);
|
||||
}
|
||||
|
||||
void TpagerKeyboard::processBacklightImpulse() {
|
||||
void TpagerKeyboard::processBacklightImpuse() {
|
||||
if (backlightImpulseDuty > 64) {
|
||||
backlightImpulseDuty--;
|
||||
setBacklightDuty(backlightImpulseDuty);
|
||||
}
|
||||
}
|
||||
|
||||
extern std::shared_ptr<Tca8418> tca8418;
|
||||
std::shared_ptr<tt::hal::keyboard::KeyboardDevice> createKeyboard() {
|
||||
keyboardMsg = xQueueCreate(20, sizeof(char));
|
||||
|
||||
return std::make_shared<TpagerKeyboard>(tca8418);
|
||||
}
|
||||
|
||||
@ -5,38 +5,33 @@
|
||||
#include <Tca8418.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <driver/pulse_cnt.h>
|
||||
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice {
|
||||
|
||||
lv_indev_t* _Nullable kbHandle = nullptr;
|
||||
lv_indev_t* _Nullable encHandle = nullptr;
|
||||
pcnt_unit_handle_t encPcntUnit = 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;
|
||||
|
||||
std::shared_ptr<Tca8418> keypad;
|
||||
std::unique_ptr<tt::Timer> inputTimer;
|
||||
std::unique_ptr<tt::Timer> backlightImpulseTimer;
|
||||
|
||||
void initEncoder(void);
|
||||
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);
|
||||
void processBacklightImpuse();
|
||||
|
||||
public:
|
||||
|
||||
TpagerKeyboard(const std::shared_ptr<Tca8418>& tca) : keypad(tca) {
|
||||
queue = xQueueCreate(20, sizeof(char));
|
||||
}
|
||||
|
||||
~TpagerKeyboard() {
|
||||
vQueueDelete(queue);
|
||||
}
|
||||
TpagerKeyboard(std::shared_ptr<Tca8418> tca) : keypad(std::move(tca)) {}
|
||||
|
||||
std::string getName() const override { return "T-Lora Pager Keyboard"; }
|
||||
std::string getDescription() const override { return "T-Lora Pager I2C keyboard with encoder"; }
|
||||
@ -47,6 +42,9 @@ public:
|
||||
bool isAttached() const override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return kbHandle; }
|
||||
|
||||
int getEncoderPulses();
|
||||
bool setBacklightDuty(uint8_t duty);
|
||||
void makeBacklightImpulse();
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::keyboard::KeyboardDevice> createKeyboard();
|
||||
|
||||
@ -3,9 +3,14 @@
|
||||
#include <Bq25896.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
constexpr auto* TAG = "TpagerPower";
|
||||
#define TAG "power"
|
||||
|
||||
constexpr auto TPAGER_GAUGE_I2C_BUS_HANDLE = I2C_NUM_0;
|
||||
#define TPAGER_GAUGE_I2C_BUS_HANDLE I2C_NUM_0
|
||||
|
||||
/*
|
||||
TpagerPower::TpagerPower() : gauge(TPAGER_GAUGE_I2C_BUS_HANDLE) {
|
||||
gauge->configureCapacity(1500, 1500);
|
||||
}*/
|
||||
|
||||
TpagerPower::~TpagerPower() {}
|
||||
|
||||
@ -25,6 +30,12 @@ bool TpagerPower::supportsMetric(MetricType type) const {
|
||||
}
|
||||
|
||||
bool TpagerPower::getMetric(MetricType type, MetricData& data) {
|
||||
/* IsCharging, // bool
|
||||
Current, // int32_t, mAh - battery current: either during charging (positive value) or discharging (negative value)
|
||||
BatteryVoltage, // uint32_t, mV
|
||||
ChargeLevel, // uint8_t [0, 100]
|
||||
*/
|
||||
|
||||
uint16_t u16 = 0;
|
||||
int16_t s16 = 0;
|
||||
switch (type) {
|
||||
@ -77,3 +88,13 @@ void TpagerPower::powerOff() {
|
||||
bq25896->powerOff();
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<PowerDevice> power;
|
||||
extern std::shared_ptr<Bq27220> bq27220;
|
||||
|
||||
std::shared_ptr<PowerDevice> tpager_get_power() {
|
||||
if (power == nullptr) {
|
||||
power = std::make_shared<TpagerPower>(bq27220);
|
||||
}
|
||||
return power;
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ class TpagerPower : public PowerDevice {
|
||||
|
||||
public:
|
||||
|
||||
TpagerPower(const std::shared_ptr<Bq27220>& bq) : gauge(bq) {}
|
||||
TpagerPower(std::shared_ptr<Bq27220> bq) : gauge(std::move(bq)) {}
|
||||
~TpagerPower();
|
||||
|
||||
std::string getName() const final { return "T-LoRa Pager Power measument"; }
|
||||
@ -23,3 +23,5 @@ public:
|
||||
bool supportsPowerOff() const override { return true; }
|
||||
void powerOff() override;
|
||||
};
|
||||
|
||||
std::shared_ptr<PowerDevice> tpager_get_power();
|
||||
|
||||
@ -3,27 +3,29 @@
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
constexpr auto TPAGER_SDCARD_PIN_CS = GPIO_NUM_21;
|
||||
constexpr auto TPAGER_LCD_PIN_CS = GPIO_NUM_38;
|
||||
constexpr auto TPAGER_RADIO_PIN_CS = GPIO_NUM_36;
|
||||
#define TPAGER_SDCARD_PIN_CS GPIO_NUM_21
|
||||
#define TPAGER_LCD_PIN_CS GPIO_NUM_38
|
||||
#define TPAGER_RADIO_PIN_CS GPIO_NUM_36
|
||||
|
||||
std::shared_ptr<SdCardDevice> createTpagerSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
TPAGER_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector {
|
||||
TPAGER_RADIO_PIN_CS,
|
||||
TPAGER_LCD_PIN_CS
|
||||
}
|
||||
{TPAGER_RADIO_PIN_CS,
|
||||
TPAGER_LCD_PIN_CS}
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*)new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -7,25 +7,27 @@
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
constexpr auto TDECK_SDCARD_PIN_CS = GPIO_NUM_39;
|
||||
constexpr auto TDECK_LCD_PIN_CS = GPIO_NUM_12;
|
||||
constexpr auto TDECK_RADIO_PIN_CS = GPIO_NUM_9;
|
||||
#define TDECK_SDCARD_PIN_CS GPIO_NUM_39
|
||||
#define TDECK_LCD_PIN_CS GPIO_NUM_12
|
||||
#define TDECK_RADIO_PIN_CS GPIO_NUM_9
|
||||
|
||||
std::shared_ptr<SdCardDevice> createTdeckSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
TDECK_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector {
|
||||
{
|
||||
TDECK_RADIO_PIN_CS,
|
||||
TDECK_LCD_PIN_CS
|
||||
}
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -11,19 +11,21 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
CORE2_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector {
|
||||
{
|
||||
CORE2_LCD_PIN_CS
|
||||
}
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -5,26 +5,28 @@
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
|
||||
constexpr auto CORES3_SDCARD_PIN_CS = GPIO_NUM_4;
|
||||
constexpr auto CORES3_LCD_PIN_CS = GPIO_NUM_3;
|
||||
#define CORES3_SDCARD_PIN_CS GPIO_NUM_4
|
||||
#define CORES3_LCD_PIN_CS GPIO_NUM_3
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
CORES3_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector {
|
||||
{
|
||||
CORES3_LCD_PIN_CS
|
||||
},
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -13,21 +13,23 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createUnPhoneSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
UNPHONE_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
std::vector {
|
||||
{
|
||||
UNPHONE_LORA_PIN_CS,
|
||||
UNPHONE_LCD_PIN_CS,
|
||||
UNPHONE_TOUCH_PIN_CS
|
||||
}
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
GPIO_NUM_10,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
@ -13,7 +13,9 @@ std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
SdCardDevice::MountBehaviour::AtBoot
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
|
||||
@ -8,14 +8,12 @@ class Bq25896 final : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
public:
|
||||
|
||||
explicit Bq25896(i2c_port_t port) : I2cDevice(port, BQ25896_ADDRESS) {
|
||||
powerOn();
|
||||
}
|
||||
|
||||
std::string getName() const override { return "BQ25896"; }
|
||||
|
||||
std::string getDescription() const override { return "I2C 1 cell 3A buck battery charger with power path and PSEL"; }
|
||||
|
||||
explicit Bq25896(i2c_port_t port) : I2cDevice(port, BQ25896_ADDRESS) {}
|
||||
|
||||
void powerOff();
|
||||
|
||||
void powerOn();
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
class Bq27220 final : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
private:
|
||||
uint32_t accessKey;
|
||||
|
||||
bool unsealDevice();
|
||||
@ -14,7 +15,7 @@ class Bq27220 final : public tt::hal::i2c::I2cDevice {
|
||||
bool sendSubCommand(uint16_t subCmd, bool waitConfirm = false);
|
||||
bool writeConfig16(uint16_t address, uint16_t value);
|
||||
bool configPreamble(bool &isSealed);
|
||||
bool configEpilouge(bool isSealed);
|
||||
bool configEpilouge(const bool isSealed);
|
||||
|
||||
template<typename T>
|
||||
bool performConfigUpdate(T configUpdateFunc)
|
||||
@ -85,9 +86,9 @@ public:
|
||||
uint16_t full;
|
||||
};
|
||||
|
||||
std::string getName() const override { return "BQ27220"; }
|
||||
std::string getName() const final { return "BQ27220"; }
|
||||
|
||||
std::string getDescription() const override { return "I2C-controlled CEDV battery fuel gauge"; }
|
||||
std::string getDescription() const final { return "I2C-controlled CEDV battery fuel gauge"; }
|
||||
|
||||
explicit Bq27220(i2c_port_t port) : I2cDevice(port, BQ27220_ADDRESS), accessKey(0xFFFFFFFF) {}
|
||||
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility
|
||||
)
|
||||
@ -1,5 +0,0 @@
|
||||
# DRV2605 Haptic Driver
|
||||
|
||||
[Datasheet](https://www.ti.com/product/DRV2605)
|
||||
[Reference implementation](https://github.com/lewisxhe/SensorLib/blob/master/src/SensorDRV2605.hpp)
|
||||
[Usage in T-Lora Pager code from LilyGO](https://github.com/Xinyuan-LilyGO/LilyGoLib/blob/6b534a28b0ec31313e4a7e89c5e8b7e4437e6fd1/src/LilyGo_LoRa_Pager.cpp#L956)
|
||||
@ -1,61 +0,0 @@
|
||||
#include "Drv2605.h"
|
||||
|
||||
bool Drv2605::init() {
|
||||
uint8_t status;
|
||||
if (!readRegister8(static_cast<uint8_t>(Register::Status), status)) {
|
||||
TT_LOG_E(TAG, "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);
|
||||
return false;
|
||||
}
|
||||
|
||||
writeRegister(Register::Mode, 0x00); // Get out of standby
|
||||
|
||||
writeRegister(Register::RealtimePlaybackInput, 0x00); // Disable
|
||||
|
||||
writeRegister(Register::WaveSequence1, 1); // Strong click
|
||||
writeRegister(Register::WaveSequence2, 0); // End sequence
|
||||
|
||||
writeRegister(Register::OverdriveTimeOffset, 0); // No overdrive
|
||||
|
||||
writeRegister(Register::SustainTimeOffsetPostivie, 0);
|
||||
writeRegister(Register::SustainTimeOffsetNegative, 0);
|
||||
writeRegister(Register::BrakeTimeOffset, 0);
|
||||
writeRegister(Register::AudioInputLevelMax, 0x64);
|
||||
|
||||
// ERM open loop
|
||||
|
||||
uint8_t feedback;
|
||||
if (!readRegister(Register::Feedback, feedback)) {
|
||||
TT_LOG_E(TAG, "Failed to read feedback");
|
||||
return false;
|
||||
}
|
||||
|
||||
writeRegister(Register::Feedback, feedback & 0x7F); // N_ERM_LRA off
|
||||
|
||||
bitOnByIndex(static_cast<uint8_t>(Register::Control3), 5); // ERM_OPEN_LOOP on
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Drv2605::setWaveForm(uint8_t slot, uint8_t waveform) {
|
||||
writeRegister8(static_cast<uint8_t>(Register::WaveSequence1) + slot, waveform);
|
||||
}
|
||||
|
||||
void Drv2605::selectLibrary(uint8_t library) {
|
||||
writeRegister(Register::WaveLibrarySelect, library);
|
||||
}
|
||||
|
||||
void Drv2605::startPlayback() {
|
||||
writeRegister(Register::Go, 0x01);
|
||||
}
|
||||
|
||||
void Drv2605::stopPlayback() {
|
||||
writeRegister(Register::Go, 0x00);
|
||||
}
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/i2c/I2cDevice.h>
|
||||
|
||||
class Drv2605 : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
static constexpr auto* TAG = "DRV2605";
|
||||
static constexpr auto ADDRESS = 0x5A;
|
||||
|
||||
// Chip IDs
|
||||
enum class ChipId {
|
||||
DRV2604 = 0x04, // Has RAM. Doesn't havew licensed ROM library.
|
||||
DRV2605 = 0x03, // Has licensed ROM library. Doesn't have RAM.
|
||||
DRV2604L = 0x06, // Low-voltage variant of the DRV2604.
|
||||
DRV2605L = 0x07 // Low-voltage variant of the DRV2605.
|
||||
};
|
||||
|
||||
enum class Register {
|
||||
Status = 0x00,
|
||||
Mode = 0x01,
|
||||
RealtimePlaybackInput = 0x02,
|
||||
WaveLibrarySelect = 0x03,
|
||||
WaveSequence1 = 0x04,
|
||||
WaveSequence2 = 0x05,
|
||||
WaveSequence3 = 0x06,
|
||||
WaveSequence4 = 0x07,
|
||||
WaveSequence5 = 0x08,
|
||||
WaveSequence6 = 0x09,
|
||||
WaveSequence7 = 0x0A,
|
||||
WaveSequence8 = 0x0B,
|
||||
Go = 0x0C,
|
||||
OverdriveTimeOffset = 0x0D,
|
||||
SustainTimeOffsetPostivie = 0x0E,
|
||||
SustainTimeOffsetNegative = 0x0F,
|
||||
BrakeTimeOffset = 0x10,
|
||||
AudioControl = 0x11,
|
||||
AudioInputLevelMin = 0x12,
|
||||
AudioInputLevelMax = 0x13,
|
||||
AudioOutputLevelMin = 0x14,
|
||||
AudioOutputLevelMax = 0x15,
|
||||
RatedVoltage = 0x16,
|
||||
OverdriveClampVoltage = 0x17,
|
||||
AutoCalibrationCompensation = 0x18,
|
||||
AutoCalibrationBackEmf = 0x19,
|
||||
Feedback = 0x1A,
|
||||
Control1 = 0x1B,
|
||||
Control2 = 0x1C,
|
||||
Control3 = 0x1D,
|
||||
Control4 = 0x1E,
|
||||
Vbat = 0x21,
|
||||
LraResonancePeriod = 0x22,
|
||||
};
|
||||
|
||||
bool writeRegister(Register reg, const uint8_t value) const {
|
||||
return writeRegister8(static_cast<uint8_t>(reg), value);
|
||||
}
|
||||
|
||||
bool readRegister(Register reg, uint8_t& value) const {
|
||||
return readRegister8(static_cast<uint8_t>(reg), value);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
explicit Drv2605(i2c_port_t port) : I2cDevice(port, ADDRESS) {
|
||||
if (!init()) {
|
||||
TT_LOG_E(TAG, "Failed to initialize DRV2605");
|
||||
}
|
||||
}
|
||||
|
||||
std::string getName() const final { return "DRV2605"; }
|
||||
std::string getDescription() const final { return "Haptic driver for ERM/LRA with waveform library & auto-resonance tracking"; }
|
||||
|
||||
bool init();
|
||||
|
||||
void setWaveForm(uint8_t slot, uint8_t waveform);
|
||||
void selectLibrary(uint8_t library);
|
||||
void startPlayback();
|
||||
void stopPlayback();
|
||||
};
|
||||
@ -9,6 +9,8 @@
|
||||
|
||||
class Tca8418 final : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
private:
|
||||
|
||||
uint8_t tca8418_address;
|
||||
uint32_t last_update_micros;
|
||||
uint32_t this_update_micros;
|
||||
|
||||
@ -17,10 +17,6 @@ typedef std::shared_ptr<display::DisplayDevice> (*CreateDisplay)();
|
||||
typedef std::shared_ptr<keyboard::KeyboardDevice> (*CreateKeyboard)();
|
||||
typedef std::shared_ptr<power::PowerDevice> (*CreatePower)();
|
||||
|
||||
typedef std::vector<std::shared_ptr<Device>> DeviceVector;
|
||||
|
||||
typedef std::shared_ptr<Device> (*CreateDevice)();
|
||||
|
||||
enum class LvglInit {
|
||||
Default,
|
||||
None
|
||||
@ -37,23 +33,17 @@ struct Configuration {
|
||||
const LvglInit lvglInit = LvglInit::Default;
|
||||
|
||||
/** Display HAL functionality. */
|
||||
[[deprecated("use createDevices")]]
|
||||
const CreateDisplay _Nullable createDisplay = nullptr;
|
||||
|
||||
/** Keyboard HAL functionality. */
|
||||
[[deprecated("use createDevices")]]
|
||||
const CreateKeyboard _Nullable createKeyboard = nullptr;
|
||||
|
||||
/** An optional SD card interface. */
|
||||
[[deprecated("use createDevices")]]
|
||||
const std::shared_ptr<sdcard::SdCardDevice> _Nullable sdcard = nullptr;
|
||||
|
||||
/** An optional power interface for battery or other power delivery. */
|
||||
[[deprecated("use createDevices")]]
|
||||
const CreatePower _Nullable power = nullptr;
|
||||
|
||||
std::function<DeviceVector()> createDevices = [] { return std::vector<std::shared_ptr<Device>>(); };
|
||||
|
||||
/** A list of I2C interface configurations */
|
||||
const std::vector<i2c::Configuration> i2c = {};
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ public:
|
||||
Touch,
|
||||
SdCard,
|
||||
Keyboard,
|
||||
Encoder,
|
||||
Power,
|
||||
Gps
|
||||
};
|
||||
@ -96,16 +95,7 @@ std::vector<std::shared_ptr<DeviceType>> findDevices(Device::Type type) {
|
||||
}
|
||||
}
|
||||
|
||||
template<class DeviceType>
|
||||
void findDevices(Device::Type type, std::function<bool(const std::shared_ptr<DeviceType>&)> onDeviceFound) {
|
||||
auto devices_view = findDevices(type);
|
||||
for (auto& device : devices_view) {
|
||||
auto typed_device = std::static_pointer_cast<DeviceType>(device);
|
||||
if (!onDeviceFound(typed_device)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void findDevices(Device::Type type, std::function<bool(const std::shared_ptr<Device>&)> onDeviceFound);
|
||||
|
||||
/** Find the first device of the specified type and cast it to the specified class */
|
||||
template<class DeviceType>
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Device.h"
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::hal::encoder {
|
||||
|
||||
class Display;
|
||||
|
||||
class EncoderDevice : public Device {
|
||||
|
||||
public:
|
||||
|
||||
Type getType() const override { return Type::Encoder; }
|
||||
|
||||
virtual bool startLvgl(lv_display_t* display) = 0;
|
||||
virtual bool stopLvgl() = 0;
|
||||
|
||||
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
@ -16,8 +16,6 @@ public:
|
||||
|
||||
virtual bool startLvgl(lv_display_t* display) = 0;
|
||||
virtual bool stopLvgl() = 0;
|
||||
|
||||
/** @return true when the keyboard currently is physically attached */
|
||||
virtual bool isAttached() const = 0;
|
||||
|
||||
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
|
||||
|
||||
@ -13,45 +13,33 @@ namespace tt::app::launcher {
|
||||
constexpr auto* TAG = "Launcher";
|
||||
constexpr auto BUTTON_SIZE = 64;
|
||||
|
||||
class LauncherApp final : public App {
|
||||
static void onAppPressed(TT_UNUSED lv_event_t* e) {
|
||||
auto* appId = static_cast<const char*>(lv_event_get_user_data(e));
|
||||
service::loader::startApp(appId);
|
||||
}
|
||||
|
||||
static lv_obj_t* createAppButton(lv_obj_t* parent, const char* imageFile, const char* appId, int32_t horizontalMargin) {
|
||||
auto* apps_button = lv_button_create(parent);
|
||||
lv_obj_set_style_pad_all(apps_button, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_margin_hor(apps_button, horizontalMargin, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_shadow_width(apps_button, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_opa(apps_button, 0, LV_STATE_DEFAULT);
|
||||
static lv_obj_t* createAppButton(lv_obj_t* parent, const char* imageFile, const char* appId, int32_t horizontalMargin) {
|
||||
auto* apps_button = lv_button_create(parent);
|
||||
lv_obj_set_style_pad_all(apps_button, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_margin_hor(apps_button, horizontalMargin, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_shadow_width(apps_button, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(apps_button, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_opa(apps_button, 0, LV_PART_MAIN);
|
||||
|
||||
auto* button_image = lv_image_create(apps_button);
|
||||
lv_image_set_src(button_image, imageFile);
|
||||
lv_obj_set_style_image_recolor(button_image, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_image_recolor_opa(button_image, LV_OPA_COVER, LV_STATE_DEFAULT);
|
||||
// Ensure buttons are still tappable when the asset fails to load
|
||||
// Icon images are 40x40, so we get some extra padding too
|
||||
lv_obj_set_size(button_image, BUTTON_SIZE, BUTTON_SIZE);
|
||||
auto* button_image = lv_image_create(apps_button);
|
||||
lv_image_set_src(button_image, imageFile);
|
||||
lv_obj_set_style_image_recolor(button_image, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_image_recolor_opa(button_image, LV_OPA_COVER, LV_STATE_DEFAULT);
|
||||
// Ensure buttons are still tappable when the asset fails to load
|
||||
// Icon images are 40x40, so we get some extra padding too
|
||||
lv_obj_set_size(button_image, BUTTON_SIZE, BUTTON_SIZE);
|
||||
|
||||
lv_obj_add_event_cb(apps_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)appId);
|
||||
lv_obj_add_event_cb(apps_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)appId);
|
||||
|
||||
return apps_button;
|
||||
}
|
||||
return apps_button;
|
||||
}
|
||||
|
||||
static bool shouldShowPowerButton() {
|
||||
bool show_power_button = false;
|
||||
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&show_power_button](const auto& device) {
|
||||
if (device->supportsPowerOff()) {
|
||||
show_power_button = true;
|
||||
return false; // stop iterating
|
||||
} else {
|
||||
return true; // continue iterating
|
||||
}
|
||||
});
|
||||
return show_power_button;
|
||||
}
|
||||
|
||||
static void onAppPressed(TT_UNUSED lv_event_t* e) {
|
||||
auto* appId = static_cast<const char*>(lv_event_get_user_data(e));
|
||||
service::loader::startApp(appId);
|
||||
}
|
||||
class LauncherApp : public App {
|
||||
|
||||
static void onPowerOffPressed(lv_event_t* e) {
|
||||
auto power = hal::findFirstDevice<hal::power::PowerDevice>(hal::Device::Type::Power);
|
||||
@ -61,7 +49,6 @@ class LauncherApp final : public App {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void onCreate(TT_UNUSED AppContext& app) override {
|
||||
BootProperties boot_properties;
|
||||
if (loadBootProperties(boot_properties) && !boot_properties.autoStartAppId.empty()) {
|
||||
@ -74,7 +61,7 @@ public:
|
||||
auto* buttons_wrapper = lv_obj_create(parent);
|
||||
|
||||
lv_obj_align(buttons_wrapper, LV_ALIGN_CENTER, 0, 0);
|
||||
// lv_obj_set_style_pad_all(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_all(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_size(buttons_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_border_width(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_flex_grow(buttons_wrapper, 1);
|
||||
@ -101,18 +88,12 @@ public:
|
||||
createAppButton(buttons_wrapper, files_icon_path.c_str(), "Files", margin);
|
||||
createAppButton(buttons_wrapper, settings_icon_path.c_str(), "Settings", margin);
|
||||
|
||||
if (shouldShowPowerButton()) {
|
||||
auto* power_button = lv_btn_create(parent);
|
||||
lv_obj_set_style_pad_all(power_button, 8, 0);
|
||||
lv_obj_align(power_button, LV_ALIGN_BOTTOM_MID, 0, -10);
|
||||
lv_obj_add_event_cb(power_button, onPowerOffPressed, LV_EVENT_SHORT_CLICKED, nullptr);
|
||||
lv_obj_set_style_shadow_width(power_button, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_opa(power_button, 0, LV_PART_MAIN);
|
||||
|
||||
auto* power_label = lv_label_create(power_button);
|
||||
lv_label_set_text(power_label, LV_SYMBOL_POWER);
|
||||
lv_obj_set_style_text_color(power_label, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
||||
}
|
||||
auto* power_button = lv_btn_create(parent);
|
||||
lv_obj_set_style_pad_all(power_button, 8, 0);
|
||||
lv_obj_align(power_button, LV_ALIGN_BOTTOM_MID, 0, -10);
|
||||
lv_obj_add_event_cb(power_button, onPowerOffPressed, LV_EVENT_SHORT_CLICKED, nullptr);
|
||||
auto* power_label = lv_label_create(power_button);
|
||||
lv_label_set_text(power_label, LV_SYMBOL_POWER);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -88,6 +88,15 @@ std::vector<std::shared_ptr<Device>> findDevices(Device::Type type) {
|
||||
});
|
||||
}
|
||||
|
||||
void findDevices(Device::Type type, std::function<bool(const std::shared_ptr<Device>&)> onDeviceFound) {
|
||||
auto devices_view = findDevices(type);
|
||||
for (auto& device : devices_view) {
|
||||
if (!onDeviceFound(device)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Device>> getDevices() {
|
||||
return devices;
|
||||
}
|
||||
|
||||
@ -14,52 +14,6 @@
|
||||
|
||||
namespace tt::hal {
|
||||
|
||||
void initDevices(const Configuration& configuration) {
|
||||
if (configuration.sdcard != nullptr) {
|
||||
registerDevice(configuration.sdcard);
|
||||
}
|
||||
|
||||
if (configuration.power != nullptr) {
|
||||
std::shared_ptr<power::PowerDevice> power = configuration.power();
|
||||
registerDevice(power);
|
||||
}
|
||||
|
||||
if (configuration.createKeyboard) {
|
||||
auto keyboard = configuration.createKeyboard();
|
||||
if (keyboard != nullptr) {
|
||||
registerDevice(std::reinterpret_pointer_cast<Device>(keyboard));
|
||||
}
|
||||
}
|
||||
|
||||
auto devices = configuration.createDevices();
|
||||
for (auto& device : devices) {
|
||||
registerDevice(device);
|
||||
}
|
||||
|
||||
// TODO: Move
|
||||
auto sdcards = hal::findDevices<sdcard::SdCardDevice>(Device::Type::SdCard);
|
||||
if (!sdcards.empty()) {
|
||||
if (sdcards.size() == 1) {
|
||||
// Fixed mount path name
|
||||
auto sdcard = sdcards[0];
|
||||
TT_LOG_I(TAG, "Mounting sdcard at %s", TT_SDCARD_MOUNT_POINT);
|
||||
if (!sdcard->mount(TT_SDCARD_MOUNT_POINT)) {
|
||||
TT_LOG_W(TAG, "SD card mount failed (init can continue)");
|
||||
}
|
||||
} else {
|
||||
// Numbered mount path name
|
||||
for (int i = 0; i < sdcards.size(); i++) {
|
||||
auto sdcard = sdcards[i];
|
||||
std::string mount_path = TT_SDCARD_MOUNT_POINT + std::to_string(i);
|
||||
TT_LOG_I(TAG, "Mounting sdcard at %d", mount_path.c_str());
|
||||
if (!sdcard->mount(mount_path)) {
|
||||
TT_LOG_W(TAG, "SD card mount failed (init can continue)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init(const Configuration& configuration) {
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin);
|
||||
|
||||
@ -80,7 +34,18 @@ void init(const Configuration& configuration) {
|
||||
tt_check(configuration.initBoot(), "Init power failed");
|
||||
}
|
||||
|
||||
initDevices(configuration);
|
||||
if (configuration.sdcard != nullptr) {
|
||||
TT_LOG_I(TAG, "Mounting sdcard");
|
||||
if (!configuration.sdcard->mount(TT_SDCARD_MOUNT_POINT)) {
|
||||
TT_LOG_W(TAG, "SD card mount failed (init can continue)");
|
||||
}
|
||||
registerDevice(configuration.sdcard);
|
||||
}
|
||||
|
||||
if (configuration.power != nullptr) {
|
||||
std::shared_ptr<power::PowerDevice> power = configuration.power();
|
||||
registerDevice(power);
|
||||
}
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalEnd);
|
||||
}
|
||||
|
||||
@ -1,55 +1,43 @@
|
||||
#include <Tactility/app/display/DisplaySettings.h>
|
||||
#include "Tactility/app/display/DisplaySettings.h"
|
||||
#include "Tactility/lvgl/Keyboard.h"
|
||||
#include "Tactility/lvgl/Lvgl.h"
|
||||
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
#include "Tactility/hal/touch/TouchDevice.h"
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/hal/encoder/EncoderDevice.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/keyboard/KeyboardDevice.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <Tactility/lvgl/Keyboard.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/TactilityHeadless.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/lvgl/EspLvglPort.h>
|
||||
#include "Tactility/lvgl/EspLvglPort.h"
|
||||
#endif
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/TactilityHeadless.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
constexpr auto* TAG = "Lvgl";
|
||||
#define TAG "Lvgl"
|
||||
|
||||
static bool started = false;
|
||||
|
||||
// TODO: Move to hal init
|
||||
static void initDisplays(const hal::Configuration& config) {
|
||||
TT_LOG_I(TAG, "Init displays");
|
||||
if (config.createDisplay != nullptr) {
|
||||
auto display = config.createDisplay();
|
||||
if (display != nullptr) {
|
||||
hal::registerDevice(display);
|
||||
}
|
||||
static std::shared_ptr<hal::display::DisplayDevice> createDisplay(const hal::Configuration& config) {
|
||||
assert(config.createDisplay);
|
||||
auto display = config.createDisplay();
|
||||
assert(display != nullptr);
|
||||
|
||||
if (!display->start()) {
|
||||
TT_LOG_E(TAG, "Display start failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Start displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (auto& display : displays) {
|
||||
if (!display->start()) {
|
||||
TT_LOG_E(TAG, "Display start failed");
|
||||
}
|
||||
|
||||
if (display->supportsBacklightDuty()) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
|
||||
auto touch = display->getTouchDevice();
|
||||
if (touch != nullptr) {
|
||||
hal::registerDevice(touch);
|
||||
touch->start();
|
||||
}
|
||||
if (display->supportsBacklightDuty()) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
void init(const hal::Configuration& config) {
|
||||
@ -61,7 +49,25 @@ void init(const hal::Configuration& config) {
|
||||
}
|
||||
#endif
|
||||
|
||||
initDisplays(config);
|
||||
auto display = createDisplay(config);
|
||||
if (display == nullptr) {
|
||||
return;
|
||||
}
|
||||
hal::registerDevice(display);
|
||||
|
||||
auto touch = display->getTouchDevice();
|
||||
if (touch != nullptr) {
|
||||
touch->start();
|
||||
hal::registerDevice(touch);
|
||||
}
|
||||
|
||||
auto configuration = hal::getConfiguration();
|
||||
if (configuration->createKeyboard) {
|
||||
auto keyboard = configuration->createKeyboard();
|
||||
if (keyboard != nullptr) {
|
||||
hal::registerDevice(keyboard);
|
||||
}
|
||||
}
|
||||
|
||||
start();
|
||||
|
||||
@ -85,27 +91,20 @@ void start() {
|
||||
|
||||
// Start displays (their related touch devices start automatically within)
|
||||
|
||||
TT_LOG_I(TAG, "Start displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (auto display : displays) {
|
||||
if (display->supportsLvgl()) {
|
||||
if (display->startLvgl()) {
|
||||
TT_LOG_I(TAG, "Started %s", display->getName().c_str());
|
||||
auto lvgl_display = display->getLvglDisplay();
|
||||
assert(lvgl_display != nullptr);
|
||||
lv_display_rotation_t rotation = app::display::getRotation();
|
||||
if (rotation != lv_display_get_rotation(lvgl_display)) {
|
||||
lv_display_set_rotation(lvgl_display, rotation);
|
||||
}
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Start failed for %s", display->getName().c_str());
|
||||
if (display->supportsLvgl() && display->startLvgl()) {
|
||||
auto lvgl_display = display->getLvglDisplay();
|
||||
assert(lvgl_display != nullptr);
|
||||
lv_display_rotation_t rotation = app::display::getRotation();
|
||||
if (rotation != lv_display_get_rotation(lvgl_display)) {
|
||||
lv_display_set_rotation(lvgl_display, rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start touch
|
||||
|
||||
TT_LOG_I(TAG, "Start touch devices");
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (auto touch_device : touch_devices) {
|
||||
if (displays.size() > 0) {
|
||||
@ -113,17 +112,13 @@ void start() {
|
||||
auto display = displays[0];
|
||||
// Start any touch devices that haven't been started yet
|
||||
if (touch_device->supportsLvgl() && touch_device->getLvglIndev() == nullptr) {
|
||||
if (touch_device->startLvgl(display->getLvglDisplay())) {
|
||||
TT_LOG_I(TAG, "Started %s", touch_device->getName().c_str());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Start failed for %s", touch_device->getName().c_str());
|
||||
}
|
||||
touch_device->startLvgl(display->getLvglDisplay());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start keyboards
|
||||
TT_LOG_I(TAG, "Start keyboards");
|
||||
|
||||
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
|
||||
for (auto keyboard : keyboards) {
|
||||
if (displays.size() > 0) {
|
||||
@ -133,29 +128,14 @@ void start() {
|
||||
if (keyboard->startLvgl(display->getLvglDisplay())) {
|
||||
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
|
||||
hardware_keyboard_set_indev(keyboard_indev);
|
||||
TT_LOG_I(TAG, "Started %s", keyboard->getName().c_str());
|
||||
TT_LOG_I(TAG, "Keyboard started");
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Start failed for %s", keyboard->getName().c_str());
|
||||
TT_LOG_E(TAG, "Keyboard start failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start encoders
|
||||
TT_LOG_I(TAG, "Start encoders");
|
||||
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
|
||||
for (auto encoder : encoders) {
|
||||
if (displays.size() > 0) {
|
||||
// TODO: Consider implementing support for multiple displays
|
||||
auto display = displays[0];
|
||||
if (encoder->startLvgl(display->getLvglDisplay())) {
|
||||
TT_LOG_I(TAG, "Started %s", encoder->getName().c_str());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Start failed for %s", encoder->getName().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Restart services
|
||||
|
||||
if (service::getState("Gui") == service::State::Stopped) {
|
||||
|
||||
@ -26,11 +26,8 @@ class SdCardService final : public Service {
|
||||
}
|
||||
|
||||
void update() {
|
||||
// TODO: Support multiple SD cards
|
||||
auto sdcard = hal::findFirstDevice<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard);
|
||||
if (sdcard == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto sdcard = hal::getConfiguration()->sdcard;
|
||||
assert(sdcard);
|
||||
|
||||
if (lock(50)) {
|
||||
auto new_state = sdcard->getState();
|
||||
@ -53,12 +50,16 @@ class SdCardService final : public Service {
|
||||
public:
|
||||
|
||||
void onStart(ServiceContext& serviceContext) override {
|
||||
auto service = findServiceById<SdCardService>(manifest.id);
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, [service]() {
|
||||
service->update();
|
||||
});
|
||||
// We want to try and scan more often in case of startup or scan lock failure
|
||||
updateTimer->start(1000);
|
||||
if (hal::getConfiguration()->sdcard != nullptr) {
|
||||
auto service = findServiceById<SdCardService>(manifest.id);
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, [service]() {
|
||||
service->update();
|
||||
});
|
||||
// We want to try and scan more often in case of startup or scan lock failure
|
||||
updateTimer->start(1000);
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Timer not started: no SD card config");
|
||||
}
|
||||
}
|
||||
|
||||
void onStop(ServiceContext& serviceContext) override {
|
||||
|
||||
@ -197,9 +197,7 @@ class StatusbarService final : public Service {
|
||||
}
|
||||
|
||||
void updateSdCardIcon() {
|
||||
auto sdcards = hal::findDevices<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard);
|
||||
// TODO: Support multiple SD cards
|
||||
auto sdcard = sdcards.empty() ? nullptr : sdcards[0];
|
||||
auto sdcard = hal::getConfiguration()->sdcard;
|
||||
if (sdcard != nullptr) {
|
||||
auto state = sdcard->getState(50 / portTICK_PERIOD_MS);
|
||||
if (state != hal::sdcard::SdCardDevice::State::Timeout) {
|
||||
|
||||
@ -33,7 +33,7 @@ bool tt_hal_device_find(DeviceType type, DeviceId* deviceIds, uint16_t* count, u
|
||||
int16_t currentIndex = -1;
|
||||
uint16_t maxIndex = maxCount - 1;
|
||||
|
||||
findDevices<tt::hal::Device>(toTactilityDeviceType(type), [&](const auto& device) {
|
||||
findDevices(toTactilityDeviceType(type), [&](const std::shared_ptr<tt::hal::Device>& device) {
|
||||
currentIndex++;
|
||||
deviceIds[currentIndex] = device->getId();
|
||||
// Continue if there is storage capacity left
|
||||
|
||||
@ -24,6 +24,7 @@ namespace tt {
|
||||
* Calls can be done from ISR/IRQ mode unless otherwise specified.
|
||||
*/
|
||||
class MessageQueue {
|
||||
private:
|
||||
|
||||
struct QueueHandleDeleter {
|
||||
void operator()(QueueHandle_t handleToDelete) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user