Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e4b95396dd | |||
| 4003065074 | |||
| 300ddb3a7f | |||
| b8bf59fedf | |||
| 68a6ca0ce3 | |||
| 430f8889ac | |||
| e0a92ea50e | |||
| 0ae9b43f87 | |||
| 598af546fd | |||
| cd921e1aa9 | |||
| 41004a3c6f | |||
| 28ff01561a | |||
| 68bf8f5a01 | |||
| bf7e40f0f1 | |||
| 71cc05e276 | |||
| 94b5cdbfc4 | |||
| 5c535490ea |
+5
-2
@@ -54,6 +54,8 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
|
||||
set(EXCLUDE_COMPONENTS "Simulator")
|
||||
|
||||
idf_build_set_property(LINK_OPTIONS "-Wl,--allow-multiple-definition" APPEND)
|
||||
|
||||
# Panic handler wrapping is only available on Xtensa architecture
|
||||
if (CONFIG_IDF_TARGET_ARCH_XTENSA)
|
||||
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
|
||||
@@ -104,8 +106,9 @@ if (NOT DEFINED ENV{ESP_IDF_VERSION})
|
||||
target_compile_definitions(freertos_kernel PUBLIC "projCOVERAGE_TEST=0")
|
||||
|
||||
# EmbedTLS
|
||||
set(ENABLE_TESTING OFF)
|
||||
set(ENABLE_PROGRAMS OFF)
|
||||
set(ENABLE_TESTING OFF CACHE BOOL "" FORCE)
|
||||
set(ENABLE_PROGRAMS OFF CACHE BOOL "" FORCE)
|
||||
set(MBEDTLS_FATAL_WARNINGS OFF CACHE BOOL "" FORCE)
|
||||
add_subdirectory(Libraries/mbedtls)
|
||||
|
||||
# SDL
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port ILI934x FT6x36 PwmBacklight driver vfs fatfs
|
||||
)
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "PwmBacklight.h"
|
||||
#include "devices/Display.h"
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/drivers/i2c_controller.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/freertos/freertos.h>
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static constexpr auto* TAG = "ES3C28P";
|
||||
static constexpr uint8_t ES8311_I2C_ADDR = 0x18;
|
||||
|
||||
static error_t initCodec(::Device* i2c_controller) {
|
||||
static constexpr uint8_t ENABLED_BULK_DATA[] = {
|
||||
0x00, 0x80, // RESET/CSM POWER ON
|
||||
0x01, 0x3F, // CLOCK_MANAGER/ use MCLK pin (external), all clocks on
|
||||
0x02, 0x00, // CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK is correct ratio)
|
||||
0x03, 0x10, // CLOCK_MANAGER/ fs_mode=0, adc_osr=16
|
||||
0x04, 0x10, // CLOCK_MANAGER/ dac_osr=16
|
||||
0x05, 0x00, // CLOCK_MANAGER/ adc_div=1, dac_div=1
|
||||
0x06, 0x03, // CLOCK_MANAGER/ bclk_div=4
|
||||
0x07, 0x00, // CLOCK_MANAGER/ lrck_h=0
|
||||
0x08, 0xFF, // CLOCK_MANAGER/ lrck_l=255 (div=256)
|
||||
0x09, 0x0C, // SDPIN_REG09/ DAC SDP format = standard I2S, word length = 16-bit
|
||||
0x0A, 0x0C, // SDPOUT_REG0A/ ADC SDP format = standard I2S, word length = 16-bit
|
||||
0x0D, 0x01, // SYSTEM/ Power up analog circuitry
|
||||
0x0E, 0x02, // SYSTEM/ Enable analog PGA, enable ADC modulator
|
||||
0x12, 0x00, // SYSTEM/ power-up DAC
|
||||
0x13, 0x10, // SYSTEM/ Enable output to HP drive (headphone/speaker)
|
||||
0x14, 0x1A, // SYSTEM/ Select Mic1p-Mic1n / max PGA gain (+30dB)
|
||||
0x17, 0xFF, // ADC_REG17/ ADC Volume (MAXGAIN)
|
||||
0x1C, 0x6A, // ADC_REG1C/ ADC Equalizer bypass, cancel DC offset in digital
|
||||
0x32, 0xBF, // DAC_REG32/ DAC Volume (0xBF = 191)
|
||||
0x37, 0x08, // DAC_REG37/ Bypass DAC equalizer
|
||||
};
|
||||
|
||||
return i2c_controller_write_register_array(
|
||||
i2c_controller,
|
||||
ES8311_I2C_ADDR,
|
||||
ENABLED_BULK_DATA,
|
||||
sizeof(ENABLED_BULK_DATA),
|
||||
pdMS_TO_TICKS(1000)
|
||||
);
|
||||
}
|
||||
|
||||
static bool initBoot() {
|
||||
// 1. Initialize display backlight
|
||||
if (!driver::pwmbacklight::init(LCD_PIN_BACKLIGHT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. Initialize and power on the FM8002E Audio Amplifier (GPIO 1, Active LOW)
|
||||
gpio_config_t io_conf = {};
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.pin_bit_mask = (1ULL << GPIO_NUM_1);
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
|
||||
// Drive LOW to enable the speaker amplifier
|
||||
gpio_set_level(GPIO_NUM_1, 0);
|
||||
|
||||
// 3. Configure the ES8311 Codec over the I2C bus
|
||||
auto* i2c_bus = device_find_by_name("i2c0");
|
||||
if (i2c_bus != nullptr) {
|
||||
error_t error = initCodec(i2c_bus);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to initialize ES8311 codec: %s", error_to_string(error));
|
||||
}
|
||||
} else {
|
||||
LOG_E(TAG, "i2c0 bus not found, skipping ES8311 initialization");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay()
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <Ft6x36Touch.h>
|
||||
#include <Ili934xDisplay.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto configuration = std::make_unique<Ft6x36Touch::Configuration>(
|
||||
I2C_NUM_0,
|
||||
240, // xMax (native portrait width)
|
||||
320, // yMax (native portrait height)
|
||||
true, // swapXy
|
||||
true, // mirrorX
|
||||
false, // mirrorY
|
||||
GPIO_NUM_18, // Touch Reset (RST)
|
||||
GPIO_NUM_17 // Touch Interrupt (INT)
|
||||
);
|
||||
|
||||
return std::make_shared<Ft6x36Touch>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
Ili934xDisplay::Configuration panel_configuration = {
|
||||
.horizontalResolution = LCD_HORIZONTAL_RESOLUTION,
|
||||
.verticalResolution = LCD_VERTICAL_RESOLUTION,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = true,
|
||||
.mirrorX = false,
|
||||
.mirrorY = false,
|
||||
.invertColor = true,
|
||||
.swapBytes = true,
|
||||
.bufferSize = LCD_BUFFER_SIZE,
|
||||
.touch = createTouch(),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = GPIO_NUM_NC,
|
||||
.rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR
|
||||
};
|
||||
|
||||
auto spi_configuration = std::make_shared<Ili934xDisplay::SpiConfiguration>(Ili934xDisplay::SpiConfiguration {
|
||||
.spiHostDevice = LCD_SPI_HOST,
|
||||
.csPin = LCD_PIN_CS,
|
||||
.dcPin = LCD_PIN_DC,
|
||||
.pixelClockFrequency = 40'000'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
return std::make_shared<Ili934xDisplay>(panel_configuration, spi_configuration, true);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
#include <memory>
|
||||
|
||||
// Display
|
||||
constexpr auto LCD_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto LCD_PIN_CS = GPIO_NUM_10;
|
||||
constexpr auto LCD_PIN_DC = GPIO_NUM_46;
|
||||
constexpr auto LCD_HORIZONTAL_RESOLUTION = 320;
|
||||
constexpr auto LCD_VERTICAL_RESOLUTION = 240;
|
||||
constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10;
|
||||
constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT;
|
||||
|
||||
// Backlight pin
|
||||
constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_45;
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <tactility/module.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
struct Module es3c28p_module = {
|
||||
.name = "es3c28p",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
general.vendor=LCDWIKI
|
||||
general.name=ES3C28P
|
||||
|
||||
apps.launcherAppId=Launcher
|
||||
|
||||
hardware.target=ESP32S3
|
||||
hardware.flashSize=16MB
|
||||
hardware.spiRam=true
|
||||
hardware.spiRamMode=OCT
|
||||
hardware.spiRamSpeed=120M
|
||||
hardware.tinyUsb=true
|
||||
hardware.usbHostEnabled=false
|
||||
hardware.esptoolFlashFreq=120M
|
||||
hardware.bluetooth=true
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=143
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
storage.userDataLocation=SD
|
||||
@@ -0,0 +1,3 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
dts: es3c28p.dts
|
||||
@@ -0,0 +1,81 @@
|
||||
/dts-v1/;
|
||||
|
||||
#include <tactility/bindings/root.h>
|
||||
#include <tactility/bindings/esp32_ble.h>
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_sdmmc.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_i2s.h>
|
||||
#include <tactility/bindings/esp32_usbhost.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
model = "LCDWIKI ES3C28P";
|
||||
|
||||
ble0 {
|
||||
compatible = "espressif,esp32-ble";
|
||||
};
|
||||
|
||||
gpio0 {
|
||||
compatible = "espressif,esp32-gpio";
|
||||
gpio-count = <49>;
|
||||
};
|
||||
|
||||
i2c0 {
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <100000>;
|
||||
pin-sda = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 15 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
i2s0 {
|
||||
compatible = "espressif,esp32-i2s";
|
||||
port = <I2S_NUM_0>;
|
||||
pin-bclk = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
pin-ws = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-data-out = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
pin-data-in = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
pin-mclk = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_spi: spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
sdmmc0 {
|
||||
compatible = "espressif,esp32-sdmmc";
|
||||
pin-clk = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
pin-cmd = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||
pin-d0 = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-d1 = <&gpio0 41 GPIO_FLAG_NONE>;
|
||||
pin-d2 = <&gpio0 48 GPIO_FLAG_NONE>;
|
||||
pin-d3 = <&gpio0 47 GPIO_FLAG_NONE>;
|
||||
slot = <SDMMC_HOST_SLOT_1>;
|
||||
bus-width = <4>;
|
||||
};
|
||||
|
||||
usbhost0 {
|
||||
compatible = "espressif,esp32-usbhost";
|
||||
status = "disabled";
|
||||
|
||||
usbhosthid0 {
|
||||
compatible = "espressif,esp32-usbhost-hid";
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
usbhostmidi0 {
|
||||
compatible = "espressif,esp32-usbhost-midi";
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
usbhostmsc0 {
|
||||
compatible = "espressif,esp32-usbhost-msc";
|
||||
status = "disabled";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd EspLcdCompat esp_lcd_ili9881c esp_lcd_st7123 esp_lcd_touch_st7123 GT911 PwmBacklight driver esp_driver_i2c vfs fatfs ina226-module
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd EspLcdCompat esp_lcd_ili9881c esp_lcd_st7123 esp_lcd_touch_st7123 GT911 PwmBacklight driver vfs fatfs ina226-module
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <esp_lcd_types.h>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
#include <hal/gpio_types.h>
|
||||
|
||||
constexpr auto DEFAULT_BUFFER_SIZE = 0;
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ bool EspLcdSpiDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
|
||||
.user_ctx = nullptr,
|
||||
.lcd_cmd_bits = 8,
|
||||
.lcd_param_bits = 8,
|
||||
.cs_ena_pretrans = 0,
|
||||
.cs_ena_posttrans = 0,
|
||||
.flags = {
|
||||
.dc_high_on_cmd = 0,
|
||||
.dc_low_on_data = 0,
|
||||
|
||||
@@ -48,6 +48,11 @@ bool EspLcdTouch::startLvgl(lv_disp_t* display) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (touchHandle == nullptr) {
|
||||
LOGGER.error("Cannot start LVGL touch: touchHandle is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (touchDriver != nullptr && touchDriver.use_count() > 1) {
|
||||
LOGGER.warn("TouchDriver is still in use.");
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel
|
||||
.timer_sel = backlightTimer,
|
||||
.duty = 0,
|
||||
.hpoint = 0,
|
||||
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
|
||||
.flags = {
|
||||
.output_invert = 0
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ endif ()
|
||||
|
||||
set(DEVICETREE_LOCATION "${PROJECT_ROOT}/Devices/${TACTILITY_DEVICE_ID}")
|
||||
|
||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||
|
||||
# Check if device has Bluetooth enabled
|
||||
# Fixes the sdkconfig bluetooth enable options from getting nuked on non-P4+C6 builds when idf build runs
|
||||
if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
@@ -32,7 +34,7 @@ endif()
|
||||
#
|
||||
|
||||
execute_process(
|
||||
COMMAND python -m pip install lark==1.3.1 pyyaml==6.0.3
|
||||
COMMAND ${Python3_EXECUTABLE} -m pip install --break-system-packages lark==1.3.1 pyyaml==6.0.3
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
@@ -41,7 +43,7 @@ execute_process(
|
||||
#
|
||||
|
||||
execute_process(
|
||||
COMMAND python "${PROJECT_ROOT}/Buildscripts/DevicetreeCompiler/dependencies.py" "${DEVICETREE_LOCATION}"
|
||||
COMMAND ${Python3_EXECUTABLE} "${PROJECT_ROOT}/Buildscripts/DevicetreeCompiler/dependencies.py" "${DEVICETREE_LOCATION}"
|
||||
WORKING_DIRECTORY "${PROJECT_ROOT}"
|
||||
OUTPUT_VARIABLE DEVICE_DEPENDENCIES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
@@ -107,7 +109,7 @@ add_custom_target(AlwaysRun
|
||||
add_custom_command(
|
||||
OUTPUT "${GENERATED_DIR}/devicetree.c"
|
||||
"${GENERATED_DIR}/devicetree.h"
|
||||
COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py"
|
||||
COMMAND ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py"
|
||||
"${DEVICETREE_LOCATION}" "${GENERATED_DIR}"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
DEPENDS AlwaysRun "${DEVICETREE_LOCATION}/devicetree.yaml" # AlwaysRun ensures it always gets built
|
||||
@@ -119,3 +121,4 @@ set_source_files_properties("${GENERATED_DIR}/devicetree.h" PROPERTIES GENERATED
|
||||
# Update target for generated code
|
||||
target_sources(${COMPONENT_LIB} PRIVATE "${GENERATED_DIR}/devicetree.c")
|
||||
target_include_directories(${COMPONENT_LIB} PRIVATE "${GENERATED_DIR}")
|
||||
add_dependencies(${COMPONENT_LIB} Generated)
|
||||
|
||||
@@ -29,7 +29,6 @@ dependencies:
|
||||
espressif/esp_lcd_touch_ft5x06: "1.0.6~1"
|
||||
espressif/esp_io_expander: "1.0.1"
|
||||
espressif/esp_io_expander_tca95xx_16bit: "1.0.1"
|
||||
espressif/esp_lcd_axs15231b: "2.0.2"
|
||||
lambage/esp_lcd_touch_ft6336u: "1.0.8"
|
||||
espressif/esp_lcd_st7701:
|
||||
version: "1.1.3"
|
||||
@@ -81,5 +80,6 @@ dependencies:
|
||||
version: "1.1.4"
|
||||
rules:
|
||||
- if: "target in [esp32s3, esp32p4]"
|
||||
idf: '5.5.2'
|
||||
espressif/mdns: "*"
|
||||
idf: '>=5.2.0'
|
||||
|
||||
|
||||
@@ -38,9 +38,11 @@
|
||||
#define __QRCODE_H_
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef unsigned char bool;
|
||||
static const bool false = 0;
|
||||
static const bool true = 1;
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
|
||||
// C23 has bool, true, false as standard keywords
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -6,7 +6,7 @@ idf_component_register(
|
||||
SRCS ${SOURCES}
|
||||
INCLUDE_DIRS "include/"
|
||||
PRIV_INCLUDE_DIRS "private/"
|
||||
REQUIRES TactilityKernel driver esp_driver_i2c vfs fatfs
|
||||
REQUIRES TactilityKernel driver vfs fatfs
|
||||
)
|
||||
|
||||
idf_component_optional_requires(PRIVATE bt usb espressif__usb_host_hid espressif__usb_host_msc)
|
||||
|
||||
@@ -167,4 +167,11 @@ bool ble_hci_gate_wait_idle(int max_ms);
|
||||
#endif
|
||||
#endif // CONFIG_ESP_HOSTED_ENABLED
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_BT_NIMBLE_ENABLED
|
||||
|
||||
@@ -815,7 +815,9 @@ static error_t api_scan_start(struct Device* device) {
|
||||
|
||||
struct ble_gap_disc_params disc_params = {};
|
||||
disc_params.passive = 0;
|
||||
disc_params.filter_duplicates = 1;
|
||||
disc_params.filter_duplicates = 0;
|
||||
disc_params.itvl = 160; // 100 ms
|
||||
disc_params.window = 160; // 100 ms
|
||||
|
||||
uint8_t own_addr_type;
|
||||
ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
|
||||
@@ -21,6 +21,14 @@ constexpr auto* TAG = "esp32_ble_scan";
|
||||
// Using BleCtx* (not Device*) so we avoid keeping a static Device reference.
|
||||
static BleCtx* s_scan_ctx = nullptr;
|
||||
|
||||
struct LoggedDevice {
|
||||
ble_addr_t addr;
|
||||
bool has_name;
|
||||
};
|
||||
constexpr size_t MAX_LOGGED_DEVICES = 128;
|
||||
static LoggedDevice s_logged_devices[MAX_LOGGED_DEVICES];
|
||||
static size_t s_logged_count = 0;
|
||||
|
||||
// ---- Scan data helpers ----
|
||||
|
||||
void ble_scan_clear_results(struct Device* device) {
|
||||
@@ -28,6 +36,8 @@ void ble_scan_clear_results(struct Device* device) {
|
||||
xSemaphoreTake(ctx->scan_mutex, portMAX_DELAY);
|
||||
ctx->scan_count = 0;
|
||||
memset(ctx->scan_results, 0, sizeof(ctx->scan_results));
|
||||
s_logged_count = 0;
|
||||
memset(s_logged_devices, 0, sizeof(s_logged_devices));
|
||||
xSemaphoreGive(ctx->scan_mutex);
|
||||
}
|
||||
|
||||
@@ -49,7 +59,8 @@ int ble_gap_disc_event_handler(struct ble_gap_event* event, void* arg) {
|
||||
record.connected = false;
|
||||
|
||||
struct ble_hs_adv_fields fields;
|
||||
if (ble_hs_adv_parse_fields(&fields, disc.data, disc.length_data) == 0) {
|
||||
bool parsed_fields = (ble_hs_adv_parse_fields(&fields, disc.data, disc.length_data) == 0);
|
||||
if (parsed_fields) {
|
||||
if (fields.name != nullptr && fields.name_len > 0) {
|
||||
size_t copy_len = std::min<size_t>(fields.name_len, BT_NAME_MAX);
|
||||
memcpy(record.name, fields.name, copy_len);
|
||||
@@ -57,6 +68,7 @@ int ble_gap_disc_event_handler(struct ble_gap_event* event, void* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
bool should_publish = false;
|
||||
{
|
||||
xSemaphoreTake(ctx->scan_mutex, portMAX_DELAY);
|
||||
bool found = false;
|
||||
@@ -65,32 +77,99 @@ int ble_gap_disc_event_handler(struct ble_gap_event* event, void* arg) {
|
||||
// Deduplicate: merge name from SCAN_RSP without clobbering ADV_IND name
|
||||
if (record.name[0] != '\0') {
|
||||
memcpy(ctx->scan_results[i].name, record.name, BT_NAME_MAX + 1);
|
||||
} else {
|
||||
// If this packet doesn't have a name, keep the previously discovered name
|
||||
memcpy(record.name, ctx->scan_results[i].name, BT_NAME_MAX + 1);
|
||||
}
|
||||
ctx->scan_results[i].rssi = record.rssi;
|
||||
found = true;
|
||||
should_publish = (record.name[0] != '\0');
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found && ctx->scan_count < 64) {
|
||||
if (!found && record.name[0] != '\0' && ctx->scan_count < 64) {
|
||||
ctx->scan_results[ctx->scan_count] = record;
|
||||
ctx->scan_addrs[ctx->scan_count] = disc.addr; // full addr (type+val)
|
||||
ctx->scan_count++;
|
||||
should_publish = true;
|
||||
}
|
||||
xSemaphoreGive(ctx->scan_mutex);
|
||||
}
|
||||
|
||||
// USB Serial logging for unique devices
|
||||
bool logged_already = false;
|
||||
size_t found_idx = 0;
|
||||
for (size_t i = 0; i < s_logged_count; ++i) {
|
||||
if (s_logged_devices[i].addr.type == disc.addr.type &&
|
||||
memcmp(s_logged_devices[i].addr.val, disc.addr.val, BT_ADDR_LEN) == 0) {
|
||||
logged_already = true;
|
||||
found_idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool name_updated = false;
|
||||
if (logged_already) {
|
||||
if (!s_logged_devices[found_idx].has_name && record.name[0] != '\0') {
|
||||
s_logged_devices[found_idx].has_name = true;
|
||||
name_updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!logged_already && s_logged_count < MAX_LOGGED_DEVICES) {
|
||||
s_logged_devices[s_logged_count].addr = disc.addr;
|
||||
s_logged_devices[s_logged_count].has_name = (record.name[0] != '\0');
|
||||
s_logged_count++;
|
||||
}
|
||||
|
||||
if (!logged_already || name_updated) {
|
||||
char mac_str[18];
|
||||
snprintf(mac_str, sizeof(mac_str), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
disc.addr.val[5], disc.addr.val[4], disc.addr.val[3],
|
||||
disc.addr.val[2], disc.addr.val[1], disc.addr.val[0]);
|
||||
|
||||
char extra_info[128] = "";
|
||||
int pos = 0;
|
||||
if (parsed_fields) {
|
||||
if (fields.appearance_is_present) {
|
||||
pos += snprintf(extra_info + pos, sizeof(extra_info) - pos, " App:0x%04x", fields.appearance);
|
||||
}
|
||||
if (fields.num_uuids16 > 0) {
|
||||
pos += snprintf(extra_info + pos, sizeof(extra_info) - pos, " UUID16:%d", (int)fields.num_uuids16);
|
||||
if (fields.uuids16 != nullptr) {
|
||||
uint16_t u16 = fields.uuids16[0].value;
|
||||
pos += snprintf(extra_info + pos, sizeof(extra_info) - pos, "(0x%04x)", (int)u16);
|
||||
}
|
||||
}
|
||||
if (fields.num_uuids128 > 0) {
|
||||
pos += snprintf(extra_info + pos, sizeof(extra_info) - pos, " UUID128:%d", (int)fields.num_uuids128);
|
||||
}
|
||||
if (fields.mfg_data_len > 0) {
|
||||
pos += snprintf(extra_info + pos, sizeof(extra_info) - pos, " Mfg:%d", (int)fields.mfg_data_len);
|
||||
}
|
||||
}
|
||||
LOG_I(TAG, "[BLE SCAN] Unique Device: MAC=%s RSSI=%d Name=%s%s%s",
|
||||
mac_str, (int)record.rssi, record.name[0] ? record.name : "<null>",
|
||||
extra_info, name_updated ? " (Name Updated)" : "");
|
||||
}
|
||||
|
||||
if (should_publish) {
|
||||
struct BtEvent e = {};
|
||||
e.type = BT_EVENT_PEER_FOUND;
|
||||
e.peer = record;
|
||||
ble_publish_event(device, e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case BLE_GAP_EVENT_DISC_COMPLETE:
|
||||
LOG_I(TAG, "Scan complete (reason=%d)", event->disc_complete.reason);
|
||||
// Keep scan_active=true; resolveNextUnnamedPeer clears it and fires ScanFinished
|
||||
// once name resolution finishes, so the UI spinner stays active throughout.
|
||||
ble_resolve_next_unnamed_peer(device, 0);
|
||||
ble_set_scan_active(device, false);
|
||||
{
|
||||
struct BtEvent e = {};
|
||||
e.type = BT_EVENT_SCAN_FINISHED;
|
||||
ble_publish_event(device, e);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <driver/gpio.h>
|
||||
#include <soc/soc.h>
|
||||
#include <soc/gpio_periph.h>
|
||||
#include <soc/gpio_struct.h>
|
||||
#include <soc/io_mux_reg.h>
|
||||
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/esp32_gpio.h>
|
||||
@@ -65,30 +69,34 @@ static error_t set_flags(GpioDescriptor* descriptor, gpio_flags_t flags) {
|
||||
}
|
||||
|
||||
static error_t get_flags(GpioDescriptor* descriptor, gpio_flags_t* flags) {
|
||||
gpio_io_config_t esp_config;
|
||||
if (gpio_get_io_config(static_cast<gpio_num_t>(descriptor->pin), &esp_config) != ESP_OK) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto pin = static_cast<gpio_num_t>(descriptor->pin);
|
||||
gpio_flags_t output = 0;
|
||||
|
||||
if (esp_config.pu) {
|
||||
// Read pull-up, pull-down, input-enable from IO MUX register
|
||||
uint32_t pin_mux = REG_READ(GPIO_PIN_MUX_REG[pin]);
|
||||
if (pin_mux & FUN_PU) {
|
||||
output |= GPIO_FLAG_PULL_UP;
|
||||
}
|
||||
|
||||
if (esp_config.pd) {
|
||||
if (pin_mux & FUN_PD) {
|
||||
output |= GPIO_FLAG_PULL_DOWN;
|
||||
}
|
||||
|
||||
if (esp_config.ie) {
|
||||
if (pin_mux & FUN_IE) {
|
||||
output |= GPIO_FLAG_DIRECTION_INPUT;
|
||||
}
|
||||
|
||||
if (esp_config.oe) {
|
||||
// Read output-enable from GPIO matrix
|
||||
bool oe = false;
|
||||
if (pin < 32) {
|
||||
oe = (GPIO.enable & (1UL << pin)) != 0;
|
||||
} else {
|
||||
oe = (GPIO.enable1.data & (1UL << (pin - 32))) != 0;
|
||||
}
|
||||
if (oe) {
|
||||
output |= GPIO_FLAG_DIRECTION_OUTPUT;
|
||||
}
|
||||
|
||||
if (esp_config.oe_inv) {
|
||||
// Read output-inversion from GPIO matrix
|
||||
if (GPIO.func_out_sel_cfg[pin].inv_sel) {
|
||||
output |= GPIO_FLAG_ACTIVE_LOW;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <driver/i2c_master.h>
|
||||
|
||||
#include <new>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <tactility/error_esp32.h>
|
||||
#include <tactility/driver.h>
|
||||
@@ -39,12 +41,48 @@ struct Esp32I2cMasterInternal {
|
||||
#define lock(data) mutex_lock(&data->mutex);
|
||||
#define unlock(data) mutex_unlock(&data->mutex);
|
||||
|
||||
struct MyI2cMasterDev {
|
||||
void* master_bus;
|
||||
uint16_t device_address;
|
||||
};
|
||||
|
||||
static esp_err_t my_i2c_master_device_change_address(i2c_master_dev_handle_t i2c_dev, uint16_t new_device_address, int timeout_ms) {
|
||||
if (i2c_dev == nullptr) return ESP_ERR_INVALID_ARG;
|
||||
auto* dev = reinterpret_cast<MyI2cMasterDev*>(i2c_dev);
|
||||
dev->device_address = new_device_address;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t my_i2c_master_transmit_multi_buffer(i2c_master_dev_handle_t dev_handle, uint8_t reg, const uint8_t* data, uint16_t data_size, int timeout_ms) {
|
||||
uint32_t total_size = data_size + 1;
|
||||
if (total_size <= 128) {
|
||||
uint8_t temp_buf[128];
|
||||
temp_buf[0] = reg;
|
||||
if (data_size > 0 && data != nullptr) {
|
||||
std::memcpy(temp_buf + 1, data, data_size);
|
||||
}
|
||||
return i2c_master_transmit(dev_handle, temp_buf, total_size, timeout_ms);
|
||||
} else {
|
||||
uint8_t* temp_buf = (uint8_t*)std::malloc(total_size);
|
||||
if (temp_buf == nullptr) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
temp_buf[0] = reg;
|
||||
if (data_size > 0 && data != nullptr) {
|
||||
std::memcpy(temp_buf + 1, data, data_size);
|
||||
}
|
||||
esp_err_t ret = i2c_master_transmit(dev_handle, temp_buf, total_size, timeout_ms);
|
||||
std::free(temp_buf);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Switches the device's target address only when it differs from the currently configured one.
|
||||
static esp_err_t ensure_address(Esp32I2cMasterInternal* driver_data, uint8_t address, int timeout_ms) {
|
||||
if (driver_data->current_address == address) {
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t esp_error = i2c_master_device_change_address(driver_data->dev_handle, address, timeout_ms);
|
||||
esp_err_t esp_error = my_i2c_master_device_change_address(driver_data->dev_handle, address, timeout_ms);
|
||||
if (esp_error == ESP_OK) {
|
||||
driver_data->current_address = address;
|
||||
}
|
||||
@@ -149,11 +187,7 @@ static error_t write_register(Device* device, uint8_t address, uint8_t reg, cons
|
||||
if (esp_error != ESP_OK) {
|
||||
LOG_E(TAG, "change_address(0x%02X) failed: %s", address, esp_err_to_name(esp_error));
|
||||
} else {
|
||||
i2c_master_transmit_multi_buffer_info_t buffers[2] = {
|
||||
{.write_buffer = ®, .buffer_size = 1},
|
||||
{.write_buffer = data, .buffer_size = data_size}
|
||||
};
|
||||
esp_error = i2c_master_multi_buffer_transmit(driver_data->dev_handle, buffers, 2, timeout_ms);
|
||||
esp_error = my_i2c_master_transmit_multi_buffer(driver_data->dev_handle, reg, data, data_size, timeout_ms);
|
||||
if (esp_error != ESP_OK) {
|
||||
LOG_E(TAG, "write_register(0x%02X, reg=0x%02X) failed: %s", address, reg, esp_err_to_name(esp_error));
|
||||
}
|
||||
@@ -212,7 +246,6 @@ static error_t start(Device* device) {
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = ((sda_spec.flags & GPIO_FLAG_PULL_UP) != 0) || ((scl_spec.flags & GPIO_FLAG_PULL_UP) != 0),
|
||||
.allow_pd = 0,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -307,7 +340,7 @@ extern Module platform_esp32_module;
|
||||
|
||||
Driver esp32_i2c_master_driver = {
|
||||
.name = "esp32_i2c_master",
|
||||
.compatible = (const char*[]) { "espressif,esp32-i2c-master", nullptr },
|
||||
.compatible = (const char*[]) { "espressif,esp32-i2c", "espressif,esp32-i2c-master", nullptr },
|
||||
.start_device = start,
|
||||
.stop_device = stop,
|
||||
.api = &ESP32_I2C_MASTER_API,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <tactility/drivers/esp32_i2s.h>
|
||||
|
||||
#include <new>
|
||||
#include <cstring>
|
||||
|
||||
#define TAG "esp32_i2s"
|
||||
|
||||
@@ -112,13 +113,19 @@ static i2s_data_bit_width_t to_esp32_bits_per_sample(uint8_t bits) {
|
||||
}
|
||||
|
||||
static void get_esp32_std_config(Esp32I2sInternal* internal, const I2sConfig* config, i2s_std_config_t* std_cfg) {
|
||||
i2s_slot_mode_t slot_mode = I2S_SLOT_MODE_STEREO;
|
||||
if ((config->channel_left != I2S_CHANNEL_NONE && config->channel_right == I2S_CHANNEL_NONE) ||
|
||||
(config->channel_left == I2S_CHANNEL_NONE && config->channel_right != I2S_CHANNEL_NONE)) {
|
||||
slot_mode = I2S_SLOT_MODE_MONO;
|
||||
}
|
||||
|
||||
std_cfg->clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(config->sample_rate);
|
||||
std_cfg->slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
|
||||
std_cfg->slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), slot_mode);
|
||||
|
||||
if (config->communication_format & I2S_FORMAT_STAND_MSB) {
|
||||
std_cfg->slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
|
||||
std_cfg->slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), slot_mode);
|
||||
} else if (config->communication_format & (I2S_FORMAT_STAND_PCM_SHORT | I2S_FORMAT_STAND_PCM_LONG)) {
|
||||
std_cfg->slot_cfg = I2S_STD_PCM_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
|
||||
std_cfg->slot_cfg = I2S_STD_PCM_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), slot_mode);
|
||||
}
|
||||
|
||||
if (config->channel_left != I2S_CHANNEL_NONE && config->channel_right == I2S_CHANNEL_NONE) {
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
#include <freertos/task.h>
|
||||
#include <sdmmc_cmd.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
#ifndef SDMMC_SLOT_FLAG_UHS1
|
||||
#define SDMMC_SLOT_FLAG_UHS1 0
|
||||
#endif
|
||||
|
||||
#if SOC_SD_PWR_CTRL_SUPPORTED
|
||||
#include <sd_pwr_ctrl_by_on_chip_ldo.h>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <esp_vfs_fat.h>
|
||||
#include <sdmmc_cmd.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
#define TAG "esp32_sdspi_fs"
|
||||
|
||||
|
||||
@@ -110,7 +110,6 @@ static error_t start(Device* device) {
|
||||
.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 = dts_config->max_transfer_size,
|
||||
.flags = 0,
|
||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <tactility/drivers/esp32_gpio_helpers.h>
|
||||
|
||||
#include <new>
|
||||
#include <cstring>
|
||||
|
||||
#define TAG "esp32_uart"
|
||||
|
||||
@@ -264,10 +265,6 @@ static error_t open(Device* device) {
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, // Flow control is not yet exposed via UartConfig
|
||||
.rx_flow_ctrl_thresh = 0,
|
||||
.source_clk = UART_SCLK_DEFAULT,
|
||||
.flags = {
|
||||
.allow_pd = 0,
|
||||
.backup_before_sleep = 0
|
||||
}
|
||||
};
|
||||
|
||||
if (dts_config->pin_cts.gpio_controller != nullptr || dts_config->pin_rts.gpio_controller != nullptr) {
|
||||
|
||||
@@ -70,8 +70,6 @@ static error_t start_device(struct Device* device) {
|
||||
.root_port_unpowered = false,
|
||||
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
||||
.enum_filter_cb = nullptr,
|
||||
.fifo_settings_custom = {},
|
||||
.peripheral_map = cfg->peripheral_map,
|
||||
};
|
||||
|
||||
esp_err_t ret = usb_host_install(&host_cfg);
|
||||
|
||||
@@ -26,6 +26,7 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
esp_http_client
|
||||
esp-tls
|
||||
esp_wifi
|
||||
mdns
|
||||
json # Effectively cJSON
|
||||
nvs_flash
|
||||
spiffs
|
||||
|
||||
@@ -26,6 +26,12 @@ void statusbar_icon_set_image(int8_t id, const std::string& image);
|
||||
/** Update the visibility for an icon on the statusbar. Does not need to be called with LVGL lock. */
|
||||
void statusbar_icon_set_visibility(int8_t id, bool visible);
|
||||
|
||||
/** Set the battery text. Does not need to be called with LVGL lock. */
|
||||
void statusbar_set_battery_text(const std::string& text);
|
||||
|
||||
/** Set the battery text visibility. Does not need to be called with LVGL lock. */
|
||||
void statusbar_set_battery_visibility(bool visible);
|
||||
|
||||
int statusbar_get_height();
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -18,6 +18,7 @@ enum class ScreensaverType {
|
||||
Mystify,
|
||||
MatrixRain,
|
||||
StackChan,
|
||||
McpScreen, // MCP LLM-driven canvas
|
||||
Count // Sentinel for bounds checking - must be last
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace tt::settings::mcp {
|
||||
|
||||
struct McpSettings {
|
||||
bool mcpEnabled = false; // Enable MCP server endpoints on system web server
|
||||
};
|
||||
|
||||
bool load(McpSettings& settings);
|
||||
McpSettings getDefault();
|
||||
McpSettings loadOrGetDefault();
|
||||
bool save(const McpSettings& settings);
|
||||
|
||||
} // namespace tt::settings::mcp
|
||||
@@ -7,5 +7,6 @@ namespace tt::app::files {
|
||||
bool isSupportedAppFile(const std::string& filename);
|
||||
bool isSupportedImageFile(const std::string& filename);
|
||||
bool isSupportedTextFile(const std::string& filename);
|
||||
bool isSupportedAudioFile(const std::string& filename);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <tactility/device.h>
|
||||
|
||||
namespace tt::mcp {
|
||||
|
||||
struct McpSystemState {
|
||||
std::mutex mutex;
|
||||
bool overrideActive = false;
|
||||
|
||||
// UI elements when McpOverrideApp is active
|
||||
lv_obj_t* drawArea = nullptr;
|
||||
uint16_t* framebuffer = nullptr;
|
||||
size_t framebufferSize = 0;
|
||||
uint16_t displayWidth = 320;
|
||||
uint16_t displayHeight = 240;
|
||||
uint16_t drawWidth = 320;
|
||||
uint16_t drawHeight = 240;
|
||||
int drawColor = 1; // 0 = white, 1 = black
|
||||
|
||||
// Audio device status
|
||||
Device* i2sDevice = nullptr;
|
||||
volatile bool audioBusy = false;
|
||||
volatile bool audioRunning = false; // Used to abort play/record loop
|
||||
|
||||
// Video streaming state
|
||||
volatile bool streamRunning = false;
|
||||
void* streamTaskHandle = nullptr; // use void* to avoid freertos header inclusion dependency
|
||||
uint32_t framesDrawn = 0;
|
||||
uint32_t tcpBytesReceived = 0;
|
||||
uint32_t lastDrawMs = 0;
|
||||
double lastFps = 0.0;
|
||||
};
|
||||
|
||||
McpSystemState& getState();
|
||||
|
||||
bool clearScreen(int color);
|
||||
bool drawText(const std::string& text, int x, int y, int size);
|
||||
bool drawRgb565(const uint8_t* data, size_t size, int x, int y, int w, int h);
|
||||
bool drawBmp(const uint8_t* data, size_t size, int x, int y);
|
||||
bool drawPbm(const uint8_t* data, size_t size, int x, int y);
|
||||
std::string getScreenshotPbmBase64();
|
||||
|
||||
bool playTone(int frequency, int durationMs, int volume, std::string& error);
|
||||
bool recordVoice(int durationSec, const std::string& filename, size_t& recordedBytes, std::string& error);
|
||||
bool playAudioFile(const std::string& filename, int volume, std::string& error);
|
||||
bool playWavMemory(const uint8_t* data, size_t size, int volume, std::string& error);
|
||||
bool playMp3File(const std::string& filename, int volume, std::string& error);
|
||||
bool playMp3Memory(const uint8_t* data, size_t size, int volume, std::string& error);
|
||||
|
||||
bool getBatteryStatus(double& voltage_v, int& percentage_pct, std::string& error);
|
||||
bool setLedColor(int r, int g, int b, const std::string& mode, std::string& error);
|
||||
bool getSensors(double& temp_c, double& hum_pct, std::string& imu_json, std::string& error);
|
||||
bool scanBleDevices(int duration_ms, std::string& devices_json, std::string& error);
|
||||
bool writeSdFile(const std::string& filename, const std::string& content, std::string& error);
|
||||
bool readSdFile(const std::string& filename, std::string& content, std::string& error);
|
||||
bool downloadSdFile(const std::string& url, const std::string& filename, std::string& error);
|
||||
|
||||
bool startVideoStreamServer();
|
||||
void stopVideoStreamServer();
|
||||
bool getVideoStreamStats(std::string& stats_json);
|
||||
|
||||
bool listApps(std::string& apps_json, std::string& error);
|
||||
bool runApp(const std::string& appId, std::string& error);
|
||||
bool listSdFiles(const std::string& directory, std::string& files_json, std::string& error);
|
||||
|
||||
} // namespace tt::mcp
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -57,6 +57,12 @@ public:
|
||||
*/
|
||||
void startScreensaver();
|
||||
|
||||
/**
|
||||
* Force the MCP screensaver specifically, regardless of the current
|
||||
* screensaver type setting. Safe to call from any thread (acquires LVGL lock).
|
||||
*/
|
||||
void startMcpScreensaver();
|
||||
|
||||
/**
|
||||
* Force the screensaver to stop immediately and restore backlight.
|
||||
* @note Not thread-safe. Call from LVGL/main context only, not from
|
||||
|
||||
@@ -76,6 +76,8 @@ private:
|
||||
static esp_err_t handleApiAppsInstall(httpd_req_t* request);
|
||||
static esp_err_t handleApiWifi(httpd_req_t* request);
|
||||
static esp_err_t handleApiScreenshot(httpd_req_t* request);
|
||||
static esp_err_t handleApiMcp(httpd_req_t* request);
|
||||
static esp_err_t handleApiScreenRaw(httpd_req_t* request);
|
||||
|
||||
// Dynamic asset serving
|
||||
static esp_err_t handleAssets(httpd_req_t* request);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <Tactility/PartitionsEsp.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <cstring>
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
#include <nvs_flash.h>
|
||||
|
||||
@@ -120,6 +120,7 @@ namespace app {
|
||||
namespace apwebserver { extern const AppManifest manifest; }
|
||||
namespace crashdiagnostics { extern const AppManifest manifest; }
|
||||
namespace webserversettings { extern const AppManifest manifest; }
|
||||
namespace mcpsettings { extern const AppManifest manifest; }
|
||||
#if CONFIG_TT_TDECK_WORKAROUND == 1
|
||||
namespace keyboardsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||
namespace trackballsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||
@@ -170,6 +171,7 @@ static void registerInternalApps() {
|
||||
#ifdef ESP_PLATFORM
|
||||
addAppManifest(app::apwebserver::manifest);
|
||||
addAppManifest(app::webserversettings::manifest);
|
||||
addAppManifest(app::mcpsettings::manifest);
|
||||
addAppManifest(app::crashdiagnostics::manifest);
|
||||
addAppManifest(app::development::manifest);
|
||||
#if defined(CONFIG_TT_TDECK_WORKAROUND)
|
||||
@@ -337,9 +339,22 @@ void run(const Configuration& config, Module* dtsModules[], DtsDevice dtsDevices
|
||||
#ifdef ESP_PLATFORM
|
||||
initEsp();
|
||||
#endif
|
||||
file::setFindLockFunction(file::findLock);
|
||||
settings::initTimeZone();
|
||||
hal::init(*config.hardware);
|
||||
|
||||
LOGGER.info("DEBUG: Listing /sdcard");
|
||||
file::listDirectory("/sdcard", [](const dirent& entry) {
|
||||
LOGGER.info("DEBUG: /sdcard entry: {} (dir={})", entry.d_name, entry.d_type == DT_DIR);
|
||||
});
|
||||
if (file::isDirectory("/sdcard/app")) {
|
||||
LOGGER.info("DEBUG: Listing /sdcard/app");
|
||||
file::listDirectory("/sdcard/app", [](const dirent& entry) {
|
||||
LOGGER.info("DEBUG: /sdcard/app entry: {}", entry.d_name);
|
||||
});
|
||||
} else {
|
||||
LOGGER.info("DEBUG: /sdcard/app is NOT a directory");
|
||||
}
|
||||
|
||||
network::ntp::init();
|
||||
bluetooth::systemStart();
|
||||
|
||||
|
||||
@@ -10,8 +10,19 @@
|
||||
|
||||
constexpr auto* TAG = "Tactility";
|
||||
|
||||
#include <cJSON.h>
|
||||
#include <esp_heap_caps.h>
|
||||
|
||||
namespace tt {
|
||||
|
||||
static void* cjson_psram_malloc(size_t size) {
|
||||
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
}
|
||||
|
||||
static void cjson_psram_free(void* ptr) {
|
||||
heap_caps_free(ptr);
|
||||
}
|
||||
|
||||
static void initNetwork() {
|
||||
LOG_I(TAG, "Init network");
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
@@ -19,6 +30,13 @@ static void initNetwork() {
|
||||
}
|
||||
|
||||
void initEsp() {
|
||||
cJSON_Hooks hooks = {
|
||||
.malloc_fn = cjson_psram_malloc,
|
||||
.free_fn = cjson_psram_free
|
||||
};
|
||||
cJSON_InitHooks(&hooks);
|
||||
LOG_I(TAG, "cJSON hooks initialized to use PSRAM");
|
||||
|
||||
check(initPartitionsEsp(), "Failed to init partitions");
|
||||
initNetwork();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ static bool untarFile(minitar* mp, const minitar_entry* entry, const std::string
|
||||
}
|
||||
|
||||
// Note: fchmod() doesn't exist on ESP-IDF and chmod() does nothing on that platform
|
||||
if (chmod(absolute_path.c_str(), entry->metadata.mode) < 0) {
|
||||
return false;
|
||||
}
|
||||
chmod(absolute_path.c_str(), entry->metadata.mode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,8 @@ public:
|
||||
|
||||
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
||||
// Note: order correlates with settings::display::ScreensaverType enum order
|
||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan");
|
||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan\nMCP Screen");
|
||||
|
||||
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
|
||||
|
||||
@@ -10,8 +10,10 @@ bool isSupportedAppFile(const std::string& filename) {
|
||||
}
|
||||
|
||||
bool isSupportedImageFile(const std::string& filename) {
|
||||
// Currently only the PNG library is built into Tactility
|
||||
return string::lowercase(filename).ends_with(".png");
|
||||
std::string filename_lower = string::lowercase(filename);
|
||||
return filename_lower.ends_with(".png") ||
|
||||
filename_lower.ends_with(".jpg") ||
|
||||
filename_lower.ends_with(".jpeg");
|
||||
}
|
||||
|
||||
bool isSupportedTextFile(const std::string& filename) {
|
||||
@@ -26,4 +28,9 @@ bool isSupportedTextFile(const std::string& filename) {
|
||||
filename_lower.ends_with(".properties");
|
||||
}
|
||||
|
||||
bool isSupportedAudioFile(const std::string& filename) {
|
||||
std::string filename_lower = string::lowercase(filename);
|
||||
return filename_lower.ends_with(".mp3");
|
||||
}
|
||||
|
||||
} // namespace tt::app::filebrowser
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <Tactility/app/imageviewer/ImageViewer.h>
|
||||
#include <Tactility/app/inputdialog/InputDialog.h>
|
||||
#include <Tactility/app/notes/Notes.h>
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/Bundle.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/kernel/Platform.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
@@ -233,6 +235,10 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
||||
// Remove forward slash, because we need a relative path
|
||||
notes::start(processed_filepath.substr(1));
|
||||
}
|
||||
} else if (isSupportedAudioFile(filename)) {
|
||||
auto parameters = std::make_shared<Bundle>();
|
||||
parameters->putString("file", processed_filepath);
|
||||
app::start("one.tactility.mp3player", parameters);
|
||||
} else {
|
||||
LOGGER.warn("Opening files of this type is not supported");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <tactility/lvgl_icon_shared.h>
|
||||
#include <esp_heap_caps.h>
|
||||
|
||||
namespace tt::app::mcpoverride {
|
||||
|
||||
static const auto LOGGER = Logger("McpOverrideApp");
|
||||
|
||||
class McpOverrideApp final : public App {
|
||||
|
||||
public:
|
||||
void onCreate(AppContext& app) override {
|
||||
// Prepare global state
|
||||
auto& state = mcp::getState();
|
||||
state.overrideActive = false;
|
||||
}
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
LOGGER.info("onShow: Starting MCP Override display canvas");
|
||||
auto& state = mcp::getState();
|
||||
|
||||
lv_obj_remove_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_all(parent, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_row(parent, 0, LV_PART_MAIN);
|
||||
|
||||
// Standard toolbar so the user can navigate back
|
||||
lv_obj_t* toolbar = lvgl::toolbar_create(parent, app);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
lv_obj_t* title_label = lv_label_create(toolbar);
|
||||
lv_label_set_text(title_label, "MCP Override Screen");
|
||||
|
||||
// Create drawing canvas
|
||||
state.drawArea = lv_canvas_create(parent);
|
||||
lv_obj_set_width(state.drawArea, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(state.drawArea, 1);
|
||||
lv_obj_set_style_radius(state.drawArea, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_border_width(state.drawArea, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_all(state.drawArea, 0, LV_PART_MAIN);
|
||||
lv_obj_remove_flag(state.drawArea, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
// Get display metrics
|
||||
lv_display_t* display = lv_obj_get_display(parent);
|
||||
state.displayWidth = lv_display_get_horizontal_resolution(display);
|
||||
state.displayHeight = lv_display_get_vertical_resolution(display);
|
||||
|
||||
lv_obj_update_layout(parent);
|
||||
state.drawWidth = lv_obj_get_content_width(state.drawArea);
|
||||
state.drawHeight = lv_obj_get_content_height(state.drawArea);
|
||||
|
||||
// Allocate framebuffer
|
||||
size_t required_size = (size_t)state.drawWidth * state.drawHeight * sizeof(uint16_t);
|
||||
if (state.framebuffer == nullptr || state.framebufferSize != required_size) {
|
||||
if (state.framebuffer != nullptr) {
|
||||
heap_caps_free(state.framebuffer);
|
||||
state.framebuffer = nullptr;
|
||||
}
|
||||
state.framebuffer = (uint16_t*)heap_caps_malloc(required_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (state.framebuffer == nullptr) {
|
||||
state.framebuffer = (uint16_t*)heap_caps_malloc(required_size, MALLOC_CAP_8BIT);
|
||||
}
|
||||
state.framebufferSize = state.framebuffer == nullptr ? 0 : required_size;
|
||||
}
|
||||
|
||||
if (state.framebuffer == nullptr) {
|
||||
LOGGER.error("Failed to allocate {} bytes framebuffer", (unsigned)required_size);
|
||||
lv_obj_t* error = lv_label_create(state.drawArea);
|
||||
lv_label_set_text(error, "Framebuffer allocation failed");
|
||||
lv_obj_center(error);
|
||||
return;
|
||||
}
|
||||
|
||||
lv_canvas_set_buffer(
|
||||
state.drawArea,
|
||||
state.framebuffer,
|
||||
state.drawWidth,
|
||||
state.drawHeight,
|
||||
LV_COLOR_FORMAT_RGB565
|
||||
);
|
||||
|
||||
// Initialize welcome/waiting screen if LLM hasn't written anything yet
|
||||
if (!state.overrideActive) {
|
||||
// Fill with a nice dark blue/slate color
|
||||
for (size_t i = 0; i < (size_t)state.drawWidth * state.drawHeight; ++i) {
|
||||
state.framebuffer[i] = 0x18E3;
|
||||
}
|
||||
state.drawColor = 1;
|
||||
|
||||
lv_obj_t* welcome_label = lv_label_create(state.drawArea);
|
||||
lv_label_set_text(welcome_label, "Waiting for LLM...");
|
||||
lv_obj_set_style_text_color(welcome_label, lv_color_white(), LV_PART_MAIN);
|
||||
lv_obj_align(welcome_label, LV_ALIGN_CENTER, 0, -20);
|
||||
|
||||
lv_obj_t* desc_label = lv_label_create(state.drawArea);
|
||||
lv_label_set_text_fmt(desc_label, "Display Resolution: %ux%u", state.drawWidth, state.drawHeight);
|
||||
lv_obj_set_style_text_color(desc_label, lv_palette_lighten(LV_PALETTE_BLUE, 3), LV_PART_MAIN);
|
||||
lv_obj_align(desc_label, LV_ALIGN_CENTER, 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
void onHide(AppContext& app) override {
|
||||
LOGGER.info("onHide: Tearing down MCP Override canvas");
|
||||
auto& state = mcp::getState();
|
||||
state.drawArea = nullptr;
|
||||
if (state.framebuffer != nullptr) {
|
||||
heap_caps_free(state.framebuffer);
|
||||
state.framebuffer = nullptr;
|
||||
state.framebufferSize = 0;
|
||||
}
|
||||
state.overrideActive = false;
|
||||
|
||||
// Stop any running tone or recording to prevent stuck state
|
||||
state.audioRunning = false;
|
||||
}
|
||||
|
||||
void onDestroy(AppContext& app) override {
|
||||
onHide(app);
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.appId = "one.tactility.mcpscreen", // Keep the original appId for compatibility
|
||||
.appName = "MCP Override Screen",
|
||||
.appIcon = LVGL_ICON_SHARED_TOOLBAR,
|
||||
.appCategory = Category::System,
|
||||
.createApp = create<McpOverrideApp>
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -0,0 +1,177 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/settings/WebServerSettings.h>
|
||||
#include <Tactility/service/webserver/WebServerService.h>
|
||||
#include <Tactility/lvgl/Toolbar.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/Logger.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <tactility/lvgl_icon_shared.h>
|
||||
|
||||
#include <esp_netif.h>
|
||||
#include <esp_wifi.h>
|
||||
|
||||
namespace tt::app::mcpsettings {
|
||||
|
||||
static const auto LOGGER = tt::Logger("McpSettingsApp");
|
||||
|
||||
class McpSettingsApp final : public App {
|
||||
|
||||
settings::mcp::McpSettings mcpSettings;
|
||||
settings::mcp::McpSettings originalSettings;
|
||||
settings::webserver::WebServerSettings wsSettings;
|
||||
bool updated = false;
|
||||
|
||||
lv_obj_t* switchMcpEnabled = nullptr;
|
||||
lv_obj_t* labelUrlValue = nullptr;
|
||||
|
||||
static void onMcpEnabledSwitch(lv_event_t* e) {
|
||||
auto* app = static_cast<McpSettingsApp*>(lv_event_get_user_data(e));
|
||||
bool enabled = lv_obj_has_state(app->switchMcpEnabled, LV_STATE_CHECKED);
|
||||
getMainDispatcher().dispatch([app, enabled] {
|
||||
app->mcpSettings.mcpEnabled = enabled;
|
||||
app->updated = true;
|
||||
if (lvgl::lock(100)) {
|
||||
app->updateUrlDisplay();
|
||||
lvgl::unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void updateUrlDisplay() {
|
||||
if (!labelUrlValue) return;
|
||||
|
||||
if (!mcpSettings.mcpEnabled) {
|
||||
lv_label_set_text(labelUrlValue, "Disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string url = "http://";
|
||||
|
||||
if (wsSettings.wifiMode == settings::webserver::WiFiMode::AccessPoint) {
|
||||
url += "192.168.4.1";
|
||||
} else {
|
||||
esp_netif_t* netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
||||
if (netif != nullptr) {
|
||||
esp_netif_ip_info_t ip_info;
|
||||
if (esp_netif_get_ip_info(netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) {
|
||||
char ip_str[16];
|
||||
snprintf(ip_str, sizeof(ip_str), IPSTR, IP2STR(&ip_info.ip));
|
||||
url += ip_str;
|
||||
} else {
|
||||
url = "Connecting...";
|
||||
}
|
||||
} else {
|
||||
url = "Not connected";
|
||||
}
|
||||
}
|
||||
|
||||
if (url.starts_with("http://")) {
|
||||
if (wsSettings.webServerPort != 80) {
|
||||
url += ":" + std::to_string(wsSettings.webServerPort);
|
||||
}
|
||||
url += "/api/mcp";
|
||||
}
|
||||
|
||||
lv_label_set_text(labelUrlValue, url.c_str());
|
||||
}
|
||||
|
||||
public:
|
||||
void onCreate(AppContext& app) override {
|
||||
mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
originalSettings = mcpSettings;
|
||||
wsSettings = settings::webserver::loadOrGetDefault();
|
||||
}
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
||||
|
||||
lv_obj_t* toolbar = lvgl::toolbar_create(parent, app);
|
||||
|
||||
// MCP Enable toggle on toolbar
|
||||
switchMcpEnabled = lvgl::toolbar_add_switch_action(toolbar);
|
||||
if (mcpSettings.mcpEnabled) {
|
||||
lv_obj_add_state(switchMcpEnabled, LV_STATE_CHECKED);
|
||||
}
|
||||
lv_obj_add_event_cb(switchMcpEnabled, onMcpEnabledSwitch, LV_EVENT_VALUE_CHANGED, this);
|
||||
|
||||
auto* main_wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_flex_flow(main_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_width(main_wrapper, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(main_wrapper, 1);
|
||||
|
||||
// URL Display
|
||||
auto* url_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(url_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(url_wrapper, 10, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(url_wrapper, 1, LV_STATE_DEFAULT);
|
||||
lv_obj_set_flex_flow(url_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_flex_cross_place(url_wrapper, LV_FLEX_ALIGN_START, 0);
|
||||
|
||||
auto* url_title = lv_label_create(url_wrapper);
|
||||
lv_label_set_text(url_title, "MCP Endpoint URL:");
|
||||
|
||||
labelUrlValue = lv_label_create(url_wrapper);
|
||||
if (lv_display_get_color_format(lv_obj_get_display(parent)) == LV_COLOR_FORMAT_L8) {
|
||||
lv_obj_set_style_text_color(labelUrlValue, lv_theme_get_color_secondary(labelUrlValue), LV_PART_MAIN);
|
||||
} else {
|
||||
lv_obj_set_style_text_color(labelUrlValue, lv_palette_main(LV_PALETTE_BLUE), 0);
|
||||
}
|
||||
|
||||
updateUrlDisplay();
|
||||
|
||||
// Info / Documentation text
|
||||
auto* info_label = lv_label_create(main_wrapper);
|
||||
lv_label_set_long_mode(info_label, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_width(info_label, LV_PCT(95));
|
||||
if (lv_display_get_color_format(lv_obj_get_display(parent)) != LV_COLOR_FORMAT_L8) {
|
||||
lv_obj_set_style_text_color(info_label, lv_palette_main(LV_PALETTE_GREY), 0);
|
||||
}
|
||||
lv_label_set_text(info_label,
|
||||
"MCP (Model Context Protocol) Screen service allows LLMs to interact with the device "
|
||||
"screen, audio, and tools directly.\n\n"
|
||||
"Endpoints:\n"
|
||||
"- POST /api/mcp (JSON-RPC tools)\n"
|
||||
"- POST /api/screen/raw (big-endian RGB565 writes)\n\n"
|
||||
"To show the LLM canvas, select 'MCP Screen' in Settings -> Display -> Screensaver. "
|
||||
"The canvas also pops up automatically when an LLM sends a draw command.");
|
||||
}
|
||||
|
||||
void onHide(AppContext& app) override {
|
||||
if (updated) {
|
||||
const auto copy = mcpSettings;
|
||||
const bool mcpStateChanged = (copy.mcpEnabled != originalSettings.mcpEnabled);
|
||||
|
||||
getMainDispatcher().dispatch([copy, mcpStateChanged]{
|
||||
// Save to properties file
|
||||
if (!settings::mcp::save(copy)) {
|
||||
LOGGER.warn("Failed to persist MCP settings");
|
||||
}
|
||||
|
||||
// Publish WebServerSettingsChanged event so the HTTP server restarts/refreshes if needed
|
||||
service::webserver::getPubsub()->publish(service::webserver::WebServerEvent::WebServerSettingsChanged);
|
||||
|
||||
if (mcpStateChanged) {
|
||||
LOGGER.info("MCP server state changed to {}", copy.mcpEnabled ? "enabled" : "disabled");
|
||||
service::webserver::setWebServerEnabled(copy.mcpEnabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.appId = "McpSettings",
|
||||
.appName = "MCP Screen",
|
||||
.appIcon = LVGL_ICON_SHARED_SETTINGS,
|
||||
.appCategory = Category::Settings,
|
||||
.createApp = create<McpSettingsApp>
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -18,6 +18,14 @@
|
||||
#include <host/ble_gatt.h>
|
||||
#include <host/ble_hs.h>
|
||||
#include <host/ble_uuid.h>
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include <esp_timer.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/queue.h>
|
||||
@@ -63,6 +71,8 @@ struct HidHostCtx {
|
||||
bool securityInitiated = false;
|
||||
bool typeResolutionDone = false;
|
||||
bool readyBlockFired = false;
|
||||
bool encrypted = false;
|
||||
bool dscsDiscovered = false;
|
||||
lv_indev_t* kbIndev = nullptr;
|
||||
lv_indev_t* mouseIndev = nullptr;
|
||||
lv_obj_t* mouseCursor = nullptr;
|
||||
@@ -179,16 +189,16 @@ static void hidHostMouseReadCb(lv_indev_t* /*indev*/, lv_indev_data_t* data) {
|
||||
data->point.y = (lv_coord_t)cy;
|
||||
break;
|
||||
case LV_DISPLAY_ROTATION_90:
|
||||
data->point.x = (lv_coord_t)cy;
|
||||
data->point.y = (lv_coord_t)(oh - cx - 1);
|
||||
data->point.x = (lv_coord_t)(ow - cy - 1);
|
||||
data->point.y = (lv_coord_t)cx;
|
||||
break;
|
||||
case LV_DISPLAY_ROTATION_180:
|
||||
data->point.x = (lv_coord_t)(ow - cx - 1);
|
||||
data->point.y = (lv_coord_t)(oh - cy - 1);
|
||||
break;
|
||||
case LV_DISPLAY_ROTATION_270:
|
||||
data->point.x = (lv_coord_t)(ow - cy - 1);
|
||||
data->point.y = (lv_coord_t)cx;
|
||||
data->point.x = (lv_coord_t)cy;
|
||||
data->point.y = (lv_coord_t)(oh - cx - 1);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -206,10 +216,29 @@ static void hidHostMouseReadCb(lv_indev_t* /*indev*/, lv_indev_data_t* data) {
|
||||
}
|
||||
|
||||
static void hidHostHandleMouseReport(const uint8_t* data, uint16_t len) {
|
||||
if (len < 3) return;
|
||||
bool btn = (data[0] & 0x01) != 0;
|
||||
int8_t dx = (int8_t)data[1];
|
||||
int8_t dy = (int8_t)data[2];
|
||||
int32_t dx = 0;
|
||||
int32_t dy = 0;
|
||||
bool btn = false;
|
||||
|
||||
if (len >= 5) {
|
||||
// 12-bit packed coordinate format (Logitech/high-res HID mice)
|
||||
btn = (data[0] & 0x01) != 0;
|
||||
|
||||
int16_t raw_x = data[2] | ((data[3] & 0x0F) << 8);
|
||||
if (raw_x & 0x0800) raw_x |= 0xF000; // sign extend 12-bit to 16-bit
|
||||
dx = (int16_t)raw_x;
|
||||
|
||||
int16_t raw_y = (data[3] >> 4) | (data[4] << 4);
|
||||
if (raw_y & 0x0800) raw_y |= 0xF000; // sign extend 12-bit to 16-bit
|
||||
dy = (int16_t)raw_y;
|
||||
} else if (len >= 3) {
|
||||
// Standard 3-byte boot protocol
|
||||
btn = (data[0] & 0x01) != 0;
|
||||
dx = (int8_t)data[1];
|
||||
dy = (int8_t)data[2];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
lv_display_t* disp = lv_display_get_default();
|
||||
int32_t w = disp ? lv_display_get_horizontal_resolution(disp) : 320;
|
||||
@@ -246,17 +275,33 @@ static void hidHostHandleMouseReport(const uint8_t* data, uint16_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Asynchronous coordination helpers ----
|
||||
|
||||
static void hidHostOnDscsDiscovered(HidHostCtx& ctx) {
|
||||
ctx.dscsDiscovered = true;
|
||||
if (ctx.encrypted) {
|
||||
ctx.rptRefReadIdx = 0;
|
||||
hidHostStartRptRefRead(ctx);
|
||||
} else {
|
||||
LOGGER.info("Descriptors discovered, waiting for encryption");
|
||||
}
|
||||
}
|
||||
|
||||
static void hidHostOnEncrypted(HidHostCtx& ctx) {
|
||||
ctx.encrypted = true;
|
||||
if (ctx.dscsDiscovered) {
|
||||
ctx.rptRefReadIdx = 0;
|
||||
hidHostStartRptRefRead(ctx);
|
||||
} else {
|
||||
LOGGER.info("Encryption established, waiting for descriptor discovery");
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Timer callback for post-encryption CCCD retry ----
|
||||
|
||||
static void hidEncRetryTimerCb(void* /*arg*/) {
|
||||
if (hid_host_ctx) {
|
||||
if (!hid_host_ctx->typeResolutionDone) {
|
||||
LOGGER.warn("Post-encryption delay — type resolution timed out, proceeding");
|
||||
hid_host_ctx->typeResolutionDone = true;
|
||||
hid_host_ctx->subscribeIdx = 0;
|
||||
} else {
|
||||
LOGGER.info("Post-encryption delay complete — starting CCCD subscriptions");
|
||||
}
|
||||
LOGGER.info("CCCD delay complete — starting subscriptions");
|
||||
hidHostSubscribeNext(*hid_host_ctx);
|
||||
}
|
||||
}
|
||||
@@ -387,7 +432,12 @@ static void hidHostReadReportMap(HidHostCtx& ctx) {
|
||||
LOGGER.info("No Report Map char — skipping type resolution");
|
||||
ctx.typeResolutionDone = true;
|
||||
ctx.subscribeIdx = 0;
|
||||
if (hid_enc_retry_timer) {
|
||||
esp_timer_stop(hid_enc_retry_timer);
|
||||
esp_timer_start_once(hid_enc_retry_timer, 500 * 1000);
|
||||
} else {
|
||||
hidHostSubscribeNext(ctx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int rc = ble_gattc_read_long(ctx.connHandle, ctx.rptMapHandle, 0,
|
||||
@@ -411,15 +461,26 @@ static void hidHostReadReportMap(HidHostCtx& ctx) {
|
||||
}
|
||||
ctx.typeResolutionDone = true;
|
||||
ctx.subscribeIdx = 0;
|
||||
LOGGER.info("Type resolution complete — delaying CCCD subscriptions by 500ms");
|
||||
if (hid_enc_retry_timer) {
|
||||
esp_timer_stop(hid_enc_retry_timer);
|
||||
esp_timer_start_once(hid_enc_retry_timer, 500 * 1000);
|
||||
} else {
|
||||
hidHostSubscribeNext(ctx);
|
||||
}
|
||||
return 0;
|
||||
}, nullptr);
|
||||
if (rc != 0) {
|
||||
LOGGER.warn("Report map read_long failed rc={} — skipping", rc);
|
||||
ctx.typeResolutionDone = true;
|
||||
ctx.subscribeIdx = 0;
|
||||
if (hid_enc_retry_timer) {
|
||||
esp_timer_stop(hid_enc_retry_timer);
|
||||
esp_timer_start_once(hid_enc_retry_timer, 500 * 1000);
|
||||
} else {
|
||||
hidHostSubscribeNext(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- CCCD subscription chain ----
|
||||
@@ -471,6 +532,19 @@ static void hidHostSubscribeNext(HidHostCtx& ctx) {
|
||||
}
|
||||
getMainDispatcher().dispatch([] {
|
||||
if (!hid_host_ctx || hid_host_ctx->kbIndev != nullptr) return;
|
||||
|
||||
bool has_keyboard = false;
|
||||
for (const auto& rpt : hid_host_ctx->inputRpts) {
|
||||
if (rpt.type == HidReportType::Keyboard || rpt.type == HidReportType::Unknown) {
|
||||
has_keyboard = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_keyboard) {
|
||||
LOGGER.info("No keyboard reports found — skipping keyboard indev registration");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tt::lvgl::lock(1000)) { LOGGER.warn("LVGL lock failed for kb indev"); return; }
|
||||
auto* kb = lv_indev_create();
|
||||
lv_indev_set_type(kb, LV_INDEV_TYPE_KEYPAD);
|
||||
@@ -555,12 +629,10 @@ static int hidHostDscDiscCb(uint16_t conn_handle, const struct ble_gatt_error* e
|
||||
hidHostDscDiscCb, nullptr);
|
||||
if (rc != 0) {
|
||||
LOGGER.warn("disc_all_dscs[{}] failed rc={}", next_idx, rc);
|
||||
ctx.rptRefReadIdx = 0;
|
||||
hidHostStartRptRefRead(ctx);
|
||||
hidHostOnDscsDiscovered(ctx);
|
||||
}
|
||||
} else {
|
||||
ctx.rptRefReadIdx = 0;
|
||||
hidHostStartRptRefRead(ctx);
|
||||
hidHostOnDscsDiscovered(ctx);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -606,8 +678,7 @@ static int hidHostChrDiscCb(uint16_t conn_handle, const struct ble_gatt_error* e
|
||||
hidHostDscDiscCb, nullptr);
|
||||
if (rc != 0) {
|
||||
LOGGER.warn("disc_all_dscs[0] failed rc={}", rc);
|
||||
ctx.rptRefReadIdx = 0;
|
||||
hidHostStartRptRefRead(ctx);
|
||||
hidHostOnDscsDiscovered(ctx);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -654,6 +725,11 @@ static int hidHostGapCb(struct ble_gap_event* event, void* /*arg*/) {
|
||||
if (event->connect.status == 0) {
|
||||
ctx.connHandle = event->connect.conn_handle;
|
||||
LOGGER.info("Connected (handle={})", ctx.connHandle);
|
||||
|
||||
// Initiate security immediately to encrypt the link for HOGP (HID over GATT)
|
||||
ble_gap_security_initiate(ctx.connHandle);
|
||||
ctx.securityInitiated = true;
|
||||
|
||||
int rc = ble_gattc_disc_all_svcs(ctx.connHandle, hidHostSvcDiscCb, nullptr);
|
||||
if (rc != 0) {
|
||||
LOGGER.warn("disc_all_svcs failed rc={}", rc);
|
||||
@@ -717,14 +793,8 @@ static int hidHostGapCb(struct ble_gap_event* event, void* /*arg*/) {
|
||||
case BLE_GAP_EVENT_ENC_CHANGE:
|
||||
if (event->enc_change.conn_handle == ctx.connHandle) {
|
||||
if (event->enc_change.status == 0) {
|
||||
LOGGER.info("Encryption established — retrying CCCD in 500ms");
|
||||
ctx.subscribeIdx = 0;
|
||||
if (hid_enc_retry_timer) {
|
||||
esp_timer_stop(hid_enc_retry_timer);
|
||||
esp_timer_start_once(hid_enc_retry_timer, 500 * 1000);
|
||||
} else {
|
||||
hidHostSubscribeNext(ctx);
|
||||
}
|
||||
LOGGER.info("Encryption established — notifying state machine");
|
||||
hidHostOnEncrypted(ctx);
|
||||
} else {
|
||||
LOGGER.warn("Encryption failed status={}", event->enc_change.status);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ struct StatusbarData {
|
||||
uint8_t time_minutes = 0;
|
||||
bool time_set = false;
|
||||
kernel::SystemEventSubscription systemEventSubscription = 0;
|
||||
std::string battery_text;
|
||||
bool battery_text_visible = false;
|
||||
};
|
||||
|
||||
static StatusbarData statusbar_data;
|
||||
@@ -47,7 +49,7 @@ typedef struct {
|
||||
lv_obj_t obj;
|
||||
lv_obj_t* time;
|
||||
lv_obj_t* icons[STATUSBAR_ICON_LIMIT];
|
||||
lv_obj_t* battery_icon;
|
||||
lv_obj_t* battery_label;
|
||||
PubSub<void*>::SubscriptionHandle pubsub_subscription;
|
||||
} Statusbar;
|
||||
|
||||
@@ -199,6 +201,13 @@ lv_obj_t* statusbar_create(lv_obj_t* parent) {
|
||||
update_icon(image, &(statusbar_data.icons[i]));
|
||||
}
|
||||
statusbar_data.mutex.unlock();
|
||||
|
||||
statusbar->battery_label = lv_label_create(obj);
|
||||
lv_obj_set_style_text_color(statusbar->battery_label, lv_color_white(), LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_all(statusbar->battery_label, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_margin_right(statusbar->battery_label, 4, LV_STATE_DEFAULT);
|
||||
lv_obj_add_flag(statusbar->battery_label, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -219,6 +228,12 @@ static void update_main(Statusbar* statusbar) {
|
||||
for (int i = 0; i < STATUSBAR_ICON_LIMIT; ++i) {
|
||||
update_icon(statusbar->icons[i], &(statusbar_data.icons[i]));
|
||||
}
|
||||
if (statusbar_data.battery_text_visible && !statusbar_data.battery_text.empty()) {
|
||||
lv_label_set_text(statusbar->battery_label, statusbar_data.battery_text.c_str());
|
||||
lv_obj_remove_flag(statusbar->battery_label, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_obj_add_flag(statusbar->battery_label, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
statusbar_data.mutex.unlock();
|
||||
}
|
||||
}
|
||||
@@ -306,6 +321,20 @@ void statusbar_icon_set_visibility(int8_t id, bool visible) {
|
||||
statusbar_data.pubsub->publish(nullptr);
|
||||
}
|
||||
|
||||
void statusbar_set_battery_text(const std::string& text) {
|
||||
statusbar_data.mutex.lock();
|
||||
statusbar_data.battery_text = text;
|
||||
statusbar_data.mutex.unlock();
|
||||
statusbar_data.pubsub->publish(nullptr);
|
||||
}
|
||||
|
||||
void statusbar_set_battery_visibility(bool visible) {
|
||||
statusbar_data.mutex.lock();
|
||||
statusbar_data.battery_text_visible = visible;
|
||||
statusbar_data.mutex.unlock();
|
||||
statusbar_data.pubsub->publish(nullptr);
|
||||
}
|
||||
|
||||
int statusbar_get_height() {
|
||||
const auto icon_size = lvgl_get_statusbar_icon_font_height();
|
||||
const auto vertical_padding = static_cast<uint32_t>((static_cast<float>(icon_size) * 0.1f));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -126,11 +126,14 @@ esp_err_t DevelopmentService::handleAppInstall(httpd_req_t* request) {
|
||||
// Skip newline after reading boundary
|
||||
auto content_headers_data = network::receiveTextUntil(request, "\r\n\r\n");
|
||||
content_left -= content_headers_data.length();
|
||||
auto content_headers = string::split(content_headers_data, "\r\n")
|
||||
| std::views::filter([](const std::string& line) {
|
||||
return line.length() > 0;
|
||||
})
|
||||
| std::ranges::to<std::vector>();
|
||||
auto raw_headers = string::split(content_headers_data, "\r\n");
|
||||
std::vector<std::string> content_headers;
|
||||
content_headers.reserve(raw_headers.size());
|
||||
for (const auto& line : raw_headers) {
|
||||
if (line.length() > 0) {
|
||||
content_headers.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
auto content_disposition_map = network::parseContentDisposition(content_headers);
|
||||
if (content_disposition_map.empty()) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "MatrixRainScreensaver.h"
|
||||
#include "MystifyScreensaver.h"
|
||||
#include "StackChanScreensaver.h"
|
||||
#include "McpScreensaver.h"
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/CoreDefines.h>
|
||||
@@ -15,6 +16,7 @@
|
||||
#include <Tactility/service/ServiceContext.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
@@ -103,6 +105,9 @@ void DisplayIdleService::activateScreensaver() {
|
||||
case settings::display::ScreensaverType::StackChan:
|
||||
screensaver = std::make_unique<StackChanScreensaver>();
|
||||
break;
|
||||
case settings::display::ScreensaverType::McpScreen:
|
||||
screensaver = std::make_unique<McpScreensaver>();
|
||||
break;
|
||||
case settings::display::ScreensaverType::None:
|
||||
default:
|
||||
// Just black screen, no animated screensaver
|
||||
@@ -259,6 +264,60 @@ void DisplayIdleService::reloadSettings() {
|
||||
settingsReloadRequested.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
void DisplayIdleService::startMcpScreensaver() {
|
||||
if (!lvgl::lock(200)) {
|
||||
LOGGER.warn("startMcpScreensaver: failed to acquire LVGL lock");
|
||||
return;
|
||||
}
|
||||
|
||||
if (screensaverOverlay != nullptr) {
|
||||
// Screensaver already active — if drawArea is registered we're done,
|
||||
// otherwise stop the current one so we can replace it with McpScreensaver.
|
||||
const auto& mcpState = mcp::getState();
|
||||
if (mcpState.drawArea != nullptr) {
|
||||
lvgl::unlock();
|
||||
return; // McpScreensaver already running
|
||||
}
|
||||
// Wrong screensaver type active — tear it down first
|
||||
if (screensaver) {
|
||||
screensaver->stop();
|
||||
screensaver.reset();
|
||||
}
|
||||
lv_obj_delete(screensaverOverlay);
|
||||
screensaverOverlay = nullptr;
|
||||
}
|
||||
|
||||
screensaverActiveCounter = 0;
|
||||
backlightOff = false;
|
||||
|
||||
// Ensure backlight is active and set to configured duty cycle
|
||||
auto display = getDisplay();
|
||||
if (display) {
|
||||
display->setBacklightDuty(cachedDisplaySettings.backlightDuty);
|
||||
}
|
||||
|
||||
lv_coord_t screenW = lv_display_get_horizontal_resolution(nullptr);
|
||||
|
||||
lv_coord_t screenH = lv_display_get_vertical_resolution(nullptr);
|
||||
|
||||
lv_obj_t* top = lv_layer_top();
|
||||
screensaverOverlay = lv_obj_create(top);
|
||||
lv_obj_remove_style_all(screensaverOverlay);
|
||||
lv_obj_set_size(screensaverOverlay, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_pos(screensaverOverlay, 0, 0);
|
||||
lv_obj_set_style_bg_color(screensaverOverlay, lv_color_black(), 0);
|
||||
lv_obj_set_style_bg_opa(screensaverOverlay, LV_OPA_COVER, 0);
|
||||
lv_obj_add_flag(screensaverOverlay, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_add_event_cb(screensaverOverlay, stopScreensaverCb, LV_EVENT_CLICKED, this);
|
||||
|
||||
screensaver = std::make_unique<McpScreensaver>();
|
||||
screensaver->start(screensaverOverlay, screenW, screenH);
|
||||
|
||||
lvgl::unlock();
|
||||
displayDimmed = true;
|
||||
LOGGER.info("MCP screensaver activated");
|
||||
}
|
||||
|
||||
std::shared_ptr<DisplayIdleService> findService() {
|
||||
return std::static_pointer_cast<DisplayIdleService>(
|
||||
findServiceById("DisplayIdle")
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "McpScreensaver.h"
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <esp_heap_caps.h>
|
||||
|
||||
namespace tt::service::displayidle {
|
||||
|
||||
static const auto LOGGER = Logger("McpScreensaver");
|
||||
|
||||
void McpScreensaver::start(lv_obj_t* overlay, lv_coord_t screenW, lv_coord_t screenH) {
|
||||
auto& state = mcp::getState();
|
||||
|
||||
// Full-screen canvas on the overlay
|
||||
lv_obj_t* canvas = lv_canvas_create(overlay);
|
||||
lv_obj_set_size(canvas, screenW, screenH);
|
||||
lv_obj_set_pos(canvas, 0, 0);
|
||||
lv_obj_set_style_radius(canvas, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_border_width(canvas, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_all(canvas, 0, LV_PART_MAIN);
|
||||
lv_obj_remove_flag(canvas, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
// Allocate framebuffer (prefer SPIRAM)
|
||||
size_t requiredSize = (size_t)screenW * screenH * sizeof(uint16_t);
|
||||
framebuffer = (uint16_t*)heap_caps_malloc(requiredSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (framebuffer == nullptr) {
|
||||
framebuffer = (uint16_t*)heap_caps_malloc(requiredSize, MALLOC_CAP_8BIT);
|
||||
}
|
||||
framebufferSize = (framebuffer != nullptr) ? requiredSize : 0;
|
||||
|
||||
if (framebuffer == nullptr) {
|
||||
LOGGER.error("Failed to allocate {}B framebuffer", (unsigned)requiredSize);
|
||||
lv_obj_t* err = lv_label_create(canvas);
|
||||
lv_label_set_text(err, "Framebuffer alloc failed");
|
||||
lv_obj_center(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fill with a dark slate background (inverted for display path)
|
||||
size_t pixelCount = (size_t)screenW * screenH;
|
||||
for (size_t i = 0; i < pixelCount; ++i) {
|
||||
framebuffer[i] = ~0x18E3; // dark blue-grey
|
||||
}
|
||||
|
||||
lv_canvas_set_buffer(canvas, framebuffer, screenW, screenH, LV_COLOR_FORMAT_RGB565);
|
||||
|
||||
// Waiting label (removed on first MCP draw via lv_obj_clean)
|
||||
lv_obj_t* waitLabel = lv_label_create(canvas);
|
||||
lv_label_set_text(waitLabel, "Waiting for LLM...");
|
||||
lv_obj_set_style_text_color(waitLabel, lv_color_black(), LV_PART_MAIN); // white on screen (inverted)
|
||||
lv_obj_align(waitLabel, LV_ALIGN_CENTER, 0, -20);
|
||||
|
||||
lv_obj_t* resLabel = lv_label_create(canvas);
|
||||
lv_label_set_text_fmt(resLabel, "Display: %dx%d", (int)screenW, (int)screenH);
|
||||
lv_color_t resColor = lv_palette_lighten(LV_PALETTE_BLUE, 3);
|
||||
lv_obj_set_style_text_color(resLabel, lv_color_make(~resColor.red, ~resColor.green, ~resColor.blue), LV_PART_MAIN);
|
||||
lv_obj_align(resLabel, LV_ALIGN_CENTER, 0, 10);
|
||||
|
||||
// Register with McpSystemState
|
||||
std::lock_guard<std::mutex> lock(state.mutex);
|
||||
state.drawArea = canvas;
|
||||
state.framebuffer = framebuffer;
|
||||
state.framebufferSize = framebufferSize;
|
||||
state.displayWidth = (uint16_t)screenW;
|
||||
state.displayHeight = (uint16_t)screenH;
|
||||
state.drawWidth = (uint16_t)screenW;
|
||||
state.drawHeight = (uint16_t)screenH;
|
||||
// Don't reset overrideActive — if the LLM already drew, we keep the content
|
||||
|
||||
LOGGER.info("McpScreensaver started ({}x{})", (int)screenW, (int)screenH);
|
||||
}
|
||||
|
||||
void McpScreensaver::stop() {
|
||||
auto& state = mcp::getState();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state.mutex);
|
||||
state.drawArea = nullptr;
|
||||
state.framebuffer = nullptr;
|
||||
state.framebufferSize = 0;
|
||||
state.overrideActive = false;
|
||||
}
|
||||
|
||||
if (framebuffer != nullptr) {
|
||||
heap_caps_free(framebuffer);
|
||||
framebuffer = nullptr;
|
||||
framebufferSize = 0;
|
||||
}
|
||||
|
||||
LOGGER.info("McpScreensaver stopped");
|
||||
}
|
||||
|
||||
void McpScreensaver::update(lv_coord_t /*screenW*/, lv_coord_t /*screenH*/) {
|
||||
// MCP draws on demand via HTTP — no per-frame animation needed
|
||||
}
|
||||
|
||||
} // namespace tt::service::displayidle
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "Screensaver.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace tt::service::displayidle {
|
||||
|
||||
/**
|
||||
* MCP Screen screensaver.
|
||||
* Creates a full-screen LVGL canvas on the overlay and registers it in
|
||||
* McpSystemState so that MCP HTTP draw commands can paint to it.
|
||||
* Dismissed by a touch event (handled by the parent DisplayIdle overlay).
|
||||
*/
|
||||
class McpScreensaver final : public Screensaver {
|
||||
uint16_t* framebuffer = nullptr;
|
||||
size_t framebufferSize = 0;
|
||||
|
||||
public:
|
||||
McpScreensaver() = default;
|
||||
~McpScreensaver() override = default;
|
||||
|
||||
void start(lv_obj_t* overlay, lv_coord_t screenW, lv_coord_t screenH) override;
|
||||
void stop() override;
|
||||
void update(lv_coord_t screenW, lv_coord_t screenH) override;
|
||||
};
|
||||
|
||||
} // namespace tt::service::displayidle
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -199,7 +199,7 @@ bool GuiService::onStart(ServiceContext& service) {
|
||||
|
||||
thread = new Thread(
|
||||
GUI_TASK_NAME,
|
||||
4096, // Last known minimum was 2800 for launching desktop
|
||||
8192, // Last known minimum was 2800 for launching desktop, increased to 8192 to prevent stack overflow on complex layouts/MCP settings
|
||||
guiMain
|
||||
);
|
||||
thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <tactility/lvgl_icon_statusbar.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
namespace tt::service::statusbar {
|
||||
|
||||
@@ -102,6 +104,13 @@ static const char* getPowerStatusIcon() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hal::power::PowerDevice::MetricData charging_data;
|
||||
if (power->supportsMetric(hal::power::PowerDevice::MetricType::IsCharging) &&
|
||||
power->getMetric(hal::power::PowerDevice::MetricType::IsCharging, charging_data) &&
|
||||
charging_data.valueAsBool) {
|
||||
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_BOLT;
|
||||
}
|
||||
|
||||
hal::power::PowerDevice::MetricData charge_level;
|
||||
if (!power->getMetric(hal::power::PowerDevice::MetricType::ChargeLevel, charge_level)) {
|
||||
return nullptr;
|
||||
@@ -210,6 +219,29 @@ class StatusbarService final : public Service {
|
||||
}
|
||||
power_last_icon = desired_icon;
|
||||
}
|
||||
|
||||
std::shared_ptr<hal::power::PowerDevice> power;
|
||||
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&power](const auto& device) {
|
||||
if (device->supportsMetric(hal::power::PowerDevice::MetricType::ChargeLevel)) {
|
||||
power = device;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (power != nullptr) {
|
||||
hal::power::PowerDevice::MetricData charge_level;
|
||||
if (power->getMetric(hal::power::PowerDevice::MetricType::ChargeLevel, charge_level)) {
|
||||
uint8_t charge = charge_level.valueAsUint8;
|
||||
std::string battery_text = std::format("{}%", charge);
|
||||
lvgl::statusbar_set_battery_text(battery_text);
|
||||
lvgl::statusbar_set_battery_visibility(true);
|
||||
} else {
|
||||
lvgl::statusbar_set_battery_visibility(false);
|
||||
}
|
||||
} else {
|
||||
lvgl::statusbar_set_battery_visibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
void updateUsbIcon() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,8 @@
|
||||
#include <Tactility/service/webserver/AssetVersion.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/settings/WebServerSettings.h>
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Logger.h>
|
||||
@@ -67,7 +69,9 @@ static const char* getChipModelName(esp_chip_model_t model) {
|
||||
case CHIP_ESP32C6: return "ESP32-C6";
|
||||
case CHIP_ESP32H2: return "ESP32-H2";
|
||||
case CHIP_ESP32P4: return "ESP32-P4";
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION) || defined(CONFIG_IDF_TARGET_ESP32C5_MP_VERSION)
|
||||
case CHIP_ESP32C5: return "ESP32-C5";
|
||||
#endif
|
||||
case CHIP_ESP32C61: return "ESP32-C61";
|
||||
default: return "Unknown";
|
||||
}
|
||||
@@ -214,7 +218,9 @@ bool WebServerService::onStart(ServiceContext& service) {
|
||||
lock.lock();
|
||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||
g_settingsCached = true;
|
||||
serverEnabled = g_cachedSettings.webServerEnabled;
|
||||
|
||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
serverEnabled = g_cachedSettings.webServerEnabled || mcpSettings.mcpEnabled;
|
||||
}
|
||||
// Subscribe to settings change events to refresh cache
|
||||
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
||||
@@ -228,10 +234,10 @@ bool WebServerService::onStart(ServiceContext& service) {
|
||||
|
||||
// Start HTTP server only if enabled in settings (default: OFF to save memory)
|
||||
if (serverEnabled) {
|
||||
LOGGER.info("WebServer enabled in settings, starting HTTP server...");
|
||||
LOGGER.info("WebServer or MCP enabled in settings, starting HTTP server...");
|
||||
setEnabled(true);
|
||||
} else {
|
||||
LOGGER.info("WebServer disabled in settings, NOT starting HTTP server (saves ~10KB RAM)");
|
||||
LOGGER.info("WebServer and MCP disabled in settings, NOT starting HTTP server (saves RAM)");
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
@@ -260,11 +266,16 @@ void WebServerService::setEnabled(bool enabled) {
|
||||
lock.lock();
|
||||
|
||||
if (enabled) {
|
||||
// Start unconditionally if explicitly requested
|
||||
if (!httpServer || !httpServer->isStarted()) {
|
||||
startServer();
|
||||
}
|
||||
} else {
|
||||
if (httpServer && httpServer->isStarted()) {
|
||||
// Stop only if both web server and MCP are disabled
|
||||
auto wsSettings = settings::webserver::loadOrGetDefault();
|
||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
bool anyEnabled = wsSettings.webServerEnabled || mcpSettings.mcpEnabled;
|
||||
if (!anyEnabled && httpServer && httpServer->isStarted()) {
|
||||
stopServer();
|
||||
}
|
||||
}
|
||||
@@ -500,7 +511,7 @@ bool WebServerService::startServer() {
|
||||
settings.webServerPort,
|
||||
"0.0.0.0",
|
||||
handlers,
|
||||
8192 // Stack size
|
||||
12288 // Stack size (forces allocation in internal SRAM instead of PSRAM)
|
||||
);
|
||||
|
||||
httpServer->start();
|
||||
@@ -521,6 +532,11 @@ bool WebServerService::startServer() {
|
||||
settings.wifiMode == settings::webserver::WiFiMode::AccessPoint ? "AP" : "Station");
|
||||
}
|
||||
|
||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
if (mcpSettings.mcpEnabled) {
|
||||
mcp::startVideoStreamServer();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -532,6 +548,8 @@ void WebServerService::stopServer() {
|
||||
httpServer->stop();
|
||||
httpServer.reset();
|
||||
|
||||
mcp::stopVideoStreamServer();
|
||||
|
||||
// Stop AP mode WiFi if we started it
|
||||
if (apWifiInitialized || apNetif != nullptr) {
|
||||
stopApMode();
|
||||
@@ -1026,13 +1044,22 @@ esp_err_t WebServerService::handleApiGet(httpd_req_t* request) {
|
||||
|
||||
// API POST dispatcher - all POST endpoints require authentication
|
||||
esp_err_t WebServerService::handleApiPost(httpd_req_t* request) {
|
||||
const char* uri = request->uri;
|
||||
|
||||
// Route MCP endpoints unauthenticated
|
||||
if (strncmp(uri, "/api/mcp", 8) == 0) {
|
||||
return handleApiMcp(request);
|
||||
}
|
||||
if (strncmp(uri, "/api/screen/raw", 15) == 0) {
|
||||
return handleApiScreenRaw(request);
|
||||
}
|
||||
|
||||
bool authPassed = false;
|
||||
esp_err_t authResult = validateRequestAuth(request, authPassed);
|
||||
if (!authPassed) {
|
||||
return authResult;
|
||||
}
|
||||
|
||||
const char* uri = request->uri;
|
||||
if (strncmp(uri, "/api/apps/run", 13) == 0) {
|
||||
return handleApiAppsRun(request);
|
||||
}
|
||||
@@ -1332,11 +1359,14 @@ esp_err_t WebServerService::handleApiAppsInstall(httpd_req_t* request) {
|
||||
content_left -= content_headers_data.length();
|
||||
|
||||
// Split headers into lines and filter empty ones
|
||||
auto content_headers = string::split(content_headers_data, "\r\n")
|
||||
| std::views::filter([](const std::string& line) {
|
||||
return line.length() > 0;
|
||||
})
|
||||
| std::ranges::to<std::vector>();
|
||||
auto raw_headers = string::split(content_headers_data, "\r\n");
|
||||
std::vector<std::string> content_headers;
|
||||
content_headers.reserve(raw_headers.size());
|
||||
for (const auto& line : raw_headers) {
|
||||
if (line.length() > 0) {
|
||||
content_headers.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
auto content_disposition_map = network::parseContentDisposition(content_headers);
|
||||
if (content_disposition_map.empty()) {
|
||||
|
||||
@@ -107,6 +107,23 @@ static bool decrypt(const std::string& ssidInput, std::string& ssidOutput) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Strip PKCS#7 padding
|
||||
if (result_length > 0) {
|
||||
uint8_t pad_val = result[result_length - 1];
|
||||
if (pad_val >= 1 && pad_val <= 16 && pad_val <= result_length) {
|
||||
bool valid_padding = true;
|
||||
for (size_t i = result_length - pad_val; i < result_length; ++i) {
|
||||
if (result[i] != pad_val) {
|
||||
valid_padding = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valid_padding) {
|
||||
result[result_length - pad_val] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ssidOutput = reinterpret_cast<char*>(result);
|
||||
free(result);
|
||||
return true;
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
|
||||
#include <esp_wifi_default.h>
|
||||
#include <esp_mac.h>
|
||||
#include <esp_netif.h>
|
||||
#include <mdns.h>
|
||||
#include <lwip/esp_netif_net_stack.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <atomic>
|
||||
@@ -543,6 +546,28 @@ static void dispatchEnable(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
wifi->netif = esp_netif_create_default_wifi_sta();
|
||||
|
||||
if (wifi->netif != nullptr) {
|
||||
uint8_t mac[6];
|
||||
char hostname[32];
|
||||
if (esp_read_mac(mac, ESP_MAC_WIFI_STA) == ESP_OK) {
|
||||
snprintf(hostname, sizeof(hostname), "kidsOS-%02X%02X", mac[4], mac[5]);
|
||||
} else {
|
||||
strncpy(hostname, "kidsOS", sizeof(hostname));
|
||||
}
|
||||
LOGGER.info("Setting DHCP Hostname to '{}'", hostname);
|
||||
esp_netif_set_hostname(wifi->netif, hostname);
|
||||
|
||||
// Initialize mDNS
|
||||
esp_err_t mdns_err = mdns_init();
|
||||
if (mdns_err == ESP_OK) {
|
||||
LOGGER.info("mDNS initialized, setting hostname to '{}.local'", hostname);
|
||||
mdns_hostname_set(hostname);
|
||||
mdns_instance_name_set("kidsOS Tactility Device");
|
||||
} else {
|
||||
LOGGER.error("Failed to initialize mDNS: {}", (int)mdns_err);
|
||||
}
|
||||
}
|
||||
|
||||
// Warning: this is the memory-intensive operation
|
||||
// It uses over 117kB of RAM with default settings for S3 on IDF v5.1.2
|
||||
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
@@ -83,6 +83,8 @@ static std::string toString(ScreensaverType type) {
|
||||
return "MatrixRain";
|
||||
case StackChan:
|
||||
return "StackChan";
|
||||
case McpScreen:
|
||||
return "McpScreen";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
@@ -104,6 +106,9 @@ static bool fromString(const std::string& str, ScreensaverType& type) {
|
||||
} else if (str == "StackChan") {
|
||||
type = ScreensaverType::StackChan;
|
||||
return true;
|
||||
} else if (str == "McpScreen") {
|
||||
type = ScreensaverType::McpScreen;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace tt::settings::mcp {
|
||||
|
||||
static const auto LOGGER = Logger("McpSettings");
|
||||
constexpr auto* SETTINGS_FILE = "/data/service/mcp/settings.properties";
|
||||
|
||||
constexpr auto* KEY_MCP_ENABLED = "mcpEnabled";
|
||||
|
||||
bool load(McpSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mcp_enabled = map.find(KEY_MCP_ENABLED);
|
||||
settings.mcpEnabled = (mcp_enabled != map.end())
|
||||
? (mcp_enabled->second == "1" || mcp_enabled->second == "true")
|
||||
: false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
McpSettings getDefault() {
|
||||
return McpSettings{
|
||||
.mcpEnabled = false
|
||||
};
|
||||
}
|
||||
|
||||
McpSettings loadOrGetDefault() {
|
||||
McpSettings settings;
|
||||
if (!load(settings)) {
|
||||
settings = getDefault();
|
||||
file::findOrCreateDirectory("/data/service/mcp", 0755);
|
||||
save(settings);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
bool save(const McpSettings& settings) {
|
||||
file::findOrCreateDirectory("/data/service/mcp", 0755);
|
||||
|
||||
std::map<std::string, std::string> map;
|
||||
map[KEY_MCP_ENABLED] = settings.mcpEnabled ? "true" : "false";
|
||||
|
||||
if (!file::savePropertiesFile(SETTINGS_FILE, map)) {
|
||||
LOGGER.error("Failed to save MCP settings to {}", SETTINGS_FILE);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <symbols/esp_http_client.h>
|
||||
|
||||
#include <esp_http_client.h>
|
||||
#include <esp_idf_version.h>
|
||||
|
||||
const esp_elfsym esp_http_client_symbols[] = {
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_init),
|
||||
@@ -23,11 +24,15 @@ const esp_elfsym esp_http_client_symbols[] = {
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_get_user_data),
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_set_user_data),
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_get_errno),
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_get_and_clear_last_tls_error),
|
||||
#endif
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_set_method),
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_set_timeout_ms),
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_delete_header),
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_delete_all_headers),
|
||||
#endif
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_open),
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_write),
|
||||
ESP_ELFSYM_EXPORT(esp_http_client_fetch_headers),
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <getopt.h>
|
||||
#include <dirent.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_idf_version.h>
|
||||
#include <esp_random.h>
|
||||
#include <esp_sntp.h>
|
||||
#include <esp_netif.h>
|
||||
@@ -61,6 +62,8 @@
|
||||
#include <driver/i2s_common.h>
|
||||
#include <driver/i2s_std.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/drivers/i2s_controller.h>
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32P4
|
||||
#include <driver/ppa.h>
|
||||
@@ -263,7 +266,9 @@ const esp_elfsym main_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(tolower),
|
||||
ESP_ELFSYM_EXPORT(toupper),
|
||||
// ESP-IDF
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
|
||||
ESP_ELFSYM_EXPORT(esp_log),
|
||||
#endif
|
||||
ESP_ELFSYM_EXPORT(esp_log_write),
|
||||
ESP_ELFSYM_EXPORT(esp_log_timestamp),
|
||||
ESP_ELFSYM_EXPORT(esp_err_to_name),
|
||||
@@ -423,7 +428,23 @@ const esp_elfsym main_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_read),
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_register_event_callback),
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_preload_data),
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_tune_rate),
|
||||
#endif
|
||||
// tactility/device.h (kernel device discovery)
|
||||
ESP_ELFSYM_EXPORT(device_find_by_name),
|
||||
ESP_ELFSYM_EXPORT(device_find_first_active_by_type),
|
||||
ESP_ELFSYM_EXPORT(device_is_ready),
|
||||
ESP_ELFSYM_EXPORT(device_lock),
|
||||
ESP_ELFSYM_EXPORT(device_try_lock),
|
||||
ESP_ELFSYM_EXPORT(device_unlock),
|
||||
// tactility/drivers/i2s_controller.h
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_read),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_write),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_set_config),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_get_config),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_reset),
|
||||
ESP_ELFSYM_EXPORT(I2S_CONTROLLER_TYPE),
|
||||
// driver/i2s_std.h
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_init_std_mode),
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_clock),
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace tt {
|
||||
#ifdef CONFIG_ESP_WIFI_ENABLED
|
||||
|
||||
static CpuAffinity getEspWifiAffinity() {
|
||||
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 1
|
||||
#if CONFIG_SOC_CPU_CORES_NUM == 1
|
||||
return 0;
|
||||
#elif defined(CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0)
|
||||
return 0;
|
||||
@@ -28,7 +28,7 @@ static CpuAffinity getEspWifiAffinity() {
|
||||
|
||||
// Warning: Must watch ESP WiFi, as this task is used by WiFi
|
||||
static CpuAffinity getEspMainSchedulerAffinity() {
|
||||
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 1
|
||||
#if CONFIG_SOC_CPU_CORES_NUM == 1
|
||||
return 0;
|
||||
#elif defined(CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0)
|
||||
return 0;
|
||||
@@ -41,7 +41,7 @@ static CpuAffinity getEspMainSchedulerAffinity() {
|
||||
}
|
||||
|
||||
static CpuAffinity getFreeRtosTimerAffinity() {
|
||||
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 1
|
||||
#if CONFIG_SOC_CPU_CORES_NUM == 1
|
||||
return 0;
|
||||
#elif defined(CONFIG_FREERTOS_TIMER_TASK_NO_AFFINITY)
|
||||
return None;
|
||||
@@ -50,11 +50,11 @@ static CpuAffinity getFreeRtosTimerAffinity() {
|
||||
#elif defined(CONFIG_FREERTOS_TIMER_TASK_AFFINITY_CPU1)
|
||||
return 1;
|
||||
#else
|
||||
static_assert(false);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 1
|
||||
#if CONFIG_SOC_CPU_CORES_NUM == 1
|
||||
static const CpuAffinityConfiguration esp = {
|
||||
.system = 0,
|
||||
.graphics = 0,
|
||||
@@ -63,7 +63,7 @@ static const CpuAffinityConfiguration esp = {
|
||||
.apps = 0,
|
||||
.timer = getFreeRtosTimerAffinity()
|
||||
};
|
||||
#elif CONFIG_FREERTOS_NUMBER_OF_CORES == 2
|
||||
#elif CONFIG_SOC_CPU_CORES_NUM == 2
|
||||
static const CpuAffinityConfiguration esp = {
|
||||
.system = 0,
|
||||
.graphics = 1,
|
||||
@@ -94,7 +94,7 @@ static const CpuAffinityConfiguration simulator = {
|
||||
const CpuAffinityConfiguration& getCpuAffinityConfiguration() {
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 2
|
||||
#if CONFIG_SOC_CPU_CORES_NUM == 2
|
||||
// WiFi uses the main dispatcher to defer operations in the background
|
||||
assert(esp.wifi == esp.mainDispatcher);
|
||||
#endif // CORES
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
b581c2abc643da397b98d269bb63a6fed8f7efa94df054b00d3e333c387ddb78
|
||||
@@ -0,0 +1 @@
|
||||
{"version":"1.0","algorithm":"sha256","created_at":"2025-11-29T02:16:24.972824+00:00","files":[{"path":"CMakeLists.txt","size":115,"hash":"ddcc34d3ac2ee5238581367fc4fd5d564d568f224dc47bc7718424c96775bc57"},{"path":"README.md","size":2415,"hash":"589710be7e62dac281b4bbc1261615b77a8e8247ac7e80af867ef772508b7f5f"},{"path":"esp_lcd_touch_ft6x36.c","size":12037,"hash":"42ec067b1ebb135f75ab8eb9a73b557037e72e39a62047117353d9b00e98d369"},{"path":"idf_component.yml","size":409,"hash":"2f7bf7b2b3218704fbc383c445a162c3bf62b39eede92de824b2fec9992e5cec"},{"path":"license.txt","size":11560,"hash":"3ddf9be5c28fe27dad143a5dc76eea25222ad1dd68934a047064e56ed2fa40c5"},{"path":"include/esp_lcd_touch_ft6x36.h","size":1698,"hash":"d5c5c521ccf4784cf3aca293ff671c55786565ee9301532bb887adac4129160a"}]}
|
||||
@@ -0,0 +1,5 @@
|
||||
idf_component_register(
|
||||
SRCS "esp_lcd_touch_ft6x36.c"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES "esp_lcd"
|
||||
)
|
||||
@@ -0,0 +1,67 @@
|
||||
# ESP LCD Touch FT6x36 Controller
|
||||
|
||||
[](https://components.espressif.com/components/lambage/esp_lcd_touch_ft6x36)
|
||||
|
||||
This repository is forked from https://github.com/cfscn/esp_lcd_touch_ft6x36
|
||||
|
||||
Implementation of the FT6x36 touch controller with esp_lcd_touch component.
|
||||
|
||||
| Touch controller | Communication interface | Component name | Link to datasheet |
|
||||
| :--------------: | :---------------------: | :------------: | :---------------: |
|
||||
| FT6x36 | I2C | esp_lcd_touch_ft6x36 | [PDF](https://www.buydisplay.com/download/ic/FT6236-FT6336-FT6436L-FT6436_Datasheet.pdf) |
|
||||
|
||||
[^1]: **NOTE:** This controller should work via I2C or SPI communication interface. But it was tested on HW only via I2C communication interface.
|
||||
|
||||
## Add to project
|
||||
|
||||
Packages from this repository are uploaded to [Espressif's component service](https://components.espressif.com/).
|
||||
You can add them to your project via `idf.py add-dependancy`, e.g.
|
||||
```
|
||||
idf.py add-dependency esp_lcd_touch_ft6x36==1.0.0
|
||||
```
|
||||
|
||||
Alternatively, you can create `idf_component.yml`. More is in [Espressif's documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html).
|
||||
|
||||
## Example use
|
||||
|
||||
I2C initialization of the touch component.
|
||||
|
||||
```
|
||||
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_FT6x36_CONFIG();
|
||||
|
||||
esp_lcd_touch_config_t tp_cfg = {
|
||||
.x_max = CONFIG_LCD_HRES,
|
||||
.y_max = CONFIG_LCD_VRES,
|
||||
.rst_gpio_num = -1,
|
||||
.int_gpio_num = -1,
|
||||
.levels = {
|
||||
.reset = 0,
|
||||
.interrupt = 0,
|
||||
},
|
||||
.flags = {
|
||||
.swap_xy = 0,
|
||||
.mirror_x = 0,
|
||||
.mirror_y = 0,
|
||||
},
|
||||
};
|
||||
|
||||
esp_lcd_touch_handle_t tp;
|
||||
esp_lcd_touch_new_i2c_ft6x36(io_handle, &tp_cfg, &tp);
|
||||
```
|
||||
|
||||
Read data from the touch controller and store it in RAM memory. It should be called regularly in poll.
|
||||
|
||||
```
|
||||
esp_lcd_touch_read_data(tp);
|
||||
```
|
||||
|
||||
Get one X and Y coordinates with strength of touch.
|
||||
|
||||
```
|
||||
uint16_t touch_x[1];
|
||||
uint16_t touch_y[1];
|
||||
uint16_t touch_strength[1];
|
||||
uint8_t touch_cnt = 0;
|
||||
|
||||
bool touchpad_pressed = esp_lcd_touch_get_coordinates(tp, touch_x, touch_y, touch_strength, &touch_cnt, 1);
|
||||
```
|
||||
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 CFSoft Systems (Chengdu) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_touch.h"
|
||||
|
||||
static const char *TAG = "FT6x36";
|
||||
|
||||
/* Registers */
|
||||
#define FT62XX_G_FT5201ID 0xA8 // FocalTech's panel ID
|
||||
#define FT62XX_REG_NUMTOUCHES 0x02 // Number of touch points
|
||||
|
||||
#define FT62XX_NUM_X 0x33 // Touch X position
|
||||
#define FT62XX_NUM_Y 0x34 // Touch Y position
|
||||
|
||||
#define FT62XX_REG_MODE 0x00 // Device mode, either WORKING or FACTORY
|
||||
#define FT62XX_REG_READDATA 0x00 // Read data from register
|
||||
#define FT62XX_REG_CALIBRATE 0x02 // Calibrate mode
|
||||
#define FT62XX_REG_WORKMODE 0x00 // Work mode
|
||||
#define FT62XX_REG_FACTORYMODE 0x40 // Factory mode
|
||||
#define FT62XX_REG_THRESHHOLD 0x80 // Threshold for touch detection
|
||||
#define FT62XX_REG_POINTRATE 0x88 // Point rate
|
||||
#define FT62XX_REG_FIRMVERS 0xA6 // Firmware version
|
||||
#define FT62XX_REG_CHIPID 0xA3 // Chip selecting
|
||||
#define FT62XX_REG_VENDID 0xA8 // FocalTech's panel ID
|
||||
|
||||
#define FT62XX_VENDID 0x11 // FocalTech's panel ID
|
||||
#define FT6336_VENDID 0x88 // FocalTech's panel ID
|
||||
#define FT6206_CHIPID 0x06 // Chip selecting
|
||||
#define FT3236_CHIPID 0x33 // Chip selecting
|
||||
#define FT6236_CHIPID 0x36 // Chip selecting
|
||||
#define FT6236U_CHIPID 0x64 // Chip selecting
|
||||
#define FT6336U_CHIPID 0x64 // Chip selecting
|
||||
|
||||
#define FT62XX_DEFAULT_THRESHOLD 60 // Default threshold for touch detection (lowered from 128 to improve sensitivity on battery/floating ground)
|
||||
|
||||
/*******************************************************************************
|
||||
* Function definitions
|
||||
*******************************************************************************/
|
||||
static esp_err_t esp_lcd_touch_ft6x36_read_data(esp_lcd_touch_handle_t tp);
|
||||
static bool esp_lcd_touch_ft6x36_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num);
|
||||
static esp_err_t esp_lcd_touch_ft6x36_del(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/* I2C read */
|
||||
static esp_err_t touch_ft6x36_i2c_write(esp_lcd_touch_handle_t tp, uint8_t reg, uint8_t data);
|
||||
static esp_err_t touch_ft6x36_i2c_read(esp_lcd_touch_handle_t tp, uint8_t reg, uint8_t *data, uint8_t len);
|
||||
|
||||
/* FT6x36 init */
|
||||
static esp_err_t touch_ft6x36_init(esp_lcd_touch_handle_t tp);
|
||||
/* FT6x36 reset */
|
||||
static esp_err_t touch_ft6x36_reset(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/*******************************************************************************
|
||||
* Public API functions
|
||||
*******************************************************************************/
|
||||
|
||||
esp_err_t esp_lcd_touch_new_i2c_ft6x36(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *out_touch)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
assert(config != NULL);
|
||||
assert(out_touch != NULL);
|
||||
|
||||
/* Prepare main structure */
|
||||
esp_lcd_touch_handle_t esp_lcd_touch_ft6x36 = heap_caps_calloc(1, sizeof(esp_lcd_touch_t), MALLOC_CAP_DEFAULT);
|
||||
ESP_GOTO_ON_FALSE(esp_lcd_touch_ft6x36, ESP_ERR_NO_MEM, err, TAG, "no mem for FT6x36 controller");
|
||||
|
||||
/* Communication interface */
|
||||
esp_lcd_touch_ft6x36->io = io;
|
||||
|
||||
/* Only supported callbacks are set */
|
||||
esp_lcd_touch_ft6x36->read_data = esp_lcd_touch_ft6x36_read_data;
|
||||
esp_lcd_touch_ft6x36->get_xy = esp_lcd_touch_ft6x36_get_xy;
|
||||
esp_lcd_touch_ft6x36->del = esp_lcd_touch_ft6x36_del;
|
||||
|
||||
/* Mutex */
|
||||
esp_lcd_touch_ft6x36->data.lock.owner = portMUX_FREE_VAL;
|
||||
|
||||
/* Save config */
|
||||
memcpy(&esp_lcd_touch_ft6x36->config, config, sizeof(esp_lcd_touch_config_t));
|
||||
|
||||
/* Prepare pin for touch interrupt */
|
||||
if (esp_lcd_touch_ft6x36->config.int_gpio_num != GPIO_NUM_NC)
|
||||
{
|
||||
const gpio_config_t int_gpio_config = {
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.intr_type = (esp_lcd_touch_ft6x36->config.levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE),
|
||||
.pin_bit_mask = BIT64(esp_lcd_touch_ft6x36->config.int_gpio_num)};
|
||||
ret = gpio_config(&int_gpio_config);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed");
|
||||
|
||||
/* Register interrupt callback */
|
||||
if (esp_lcd_touch_ft6x36->config.interrupt_callback)
|
||||
{
|
||||
esp_lcd_touch_register_interrupt_callback(esp_lcd_touch_ft6x36, esp_lcd_touch_ft6x36->config.interrupt_callback);
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare pin for touch controller reset */
|
||||
if (esp_lcd_touch_ft6x36->config.rst_gpio_num != GPIO_NUM_NC)
|
||||
{
|
||||
const gpio_config_t rst_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = BIT64(esp_lcd_touch_ft6x36->config.rst_gpio_num)};
|
||||
ret = gpio_config(&rst_gpio_config);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed");
|
||||
}
|
||||
|
||||
/* Reset controller */
|
||||
ret = touch_ft6x36_reset(esp_lcd_touch_ft6x36);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "FT6x36 reset failed");
|
||||
|
||||
/* Init controller */
|
||||
ret = touch_ft6x36_init(esp_lcd_touch_ft6x36);
|
||||
ESP_GOTO_ON_ERROR(ret, err, TAG, "FT6x36 init failed");
|
||||
|
||||
*out_touch = esp_lcd_touch_ft6x36;
|
||||
|
||||
err:
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Error (0x%x)! Touch controller FT6x36 initialization failed!", ret);
|
||||
if (esp_lcd_touch_ft6x36)
|
||||
{
|
||||
esp_lcd_touch_ft6x36_del(esp_lcd_touch_ft6x36);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_ft6x36_read_data(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
esp_err_t err;
|
||||
uint8_t data[16];
|
||||
uint8_t points, touches;
|
||||
size_t i = 0;
|
||||
|
||||
assert(tp != NULL);
|
||||
|
||||
/* Read number of touched points */
|
||||
err = touch_ft6x36_i2c_read(tp, FT62XX_REG_NUMTOUCHES, &points, 1);
|
||||
ESP_RETURN_ON_ERROR(err, TAG, "I2C read error!");
|
||||
|
||||
if (points > 2 || points == 0)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* Number of touched points */
|
||||
points = (points > CONFIG_ESP_LCD_TOUCH_MAX_POINTS ? CONFIG_ESP_LCD_TOUCH_MAX_POINTS : points);
|
||||
|
||||
err = touch_ft6x36_i2c_read(tp, FT62XX_REG_READDATA, data, 16);
|
||||
ESP_RETURN_ON_ERROR(err, TAG, "I2C read error!");
|
||||
|
||||
/* Number of touched points */
|
||||
touches = data[0x02];
|
||||
|
||||
/* Check if the number of touched points is correct */
|
||||
if (points != touches)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
portENTER_CRITICAL(&tp->data.lock);
|
||||
|
||||
/* Number of touched points */
|
||||
tp->data.points = points;
|
||||
|
||||
/* Fill all coordinates */
|
||||
for (i = 0; i < points; i++)
|
||||
{
|
||||
tp->data.coords[i].x = ((data[0x03 + i * 6] & 0x0F) << 8) | data[0x04 + i * 6];
|
||||
tp->data.coords[i].y = ((data[0x05 + i * 6] & 0x0F) << 8) | data[0x06 + i * 6];
|
||||
}
|
||||
|
||||
portEXIT_CRITICAL(&tp->data.lock);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static bool esp_lcd_touch_ft6x36_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(x != NULL);
|
||||
assert(y != NULL);
|
||||
assert(point_num != NULL);
|
||||
assert(max_point_num > 0);
|
||||
|
||||
portENTER_CRITICAL(&tp->data.lock);
|
||||
|
||||
/* Count of points */
|
||||
*point_num = (tp->data.points > max_point_num ? max_point_num : tp->data.points);
|
||||
|
||||
for (size_t i = 0; i < *point_num; i++)
|
||||
{
|
||||
x[i] = tp->data.coords[i].x;
|
||||
y[i] = tp->data.coords[i].y;
|
||||
|
||||
if (strength)
|
||||
{
|
||||
strength[i] = tp->data.coords[i].strength;
|
||||
}
|
||||
}
|
||||
|
||||
/* Invalidate */
|
||||
tp->data.points = 0;
|
||||
|
||||
portEXIT_CRITICAL(&tp->data.lock);
|
||||
|
||||
return (*point_num > 0);
|
||||
}
|
||||
|
||||
static esp_err_t esp_lcd_touch_ft6x36_del(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
/* Reset GPIO pin settings */
|
||||
if (tp->config.int_gpio_num != GPIO_NUM_NC)
|
||||
{
|
||||
gpio_reset_pin(tp->config.int_gpio_num);
|
||||
if (tp->config.interrupt_callback)
|
||||
{
|
||||
gpio_isr_handler_remove(tp->config.int_gpio_num);
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset GPIO pin settings */
|
||||
if (tp->config.rst_gpio_num != GPIO_NUM_NC)
|
||||
{
|
||||
gpio_reset_pin(tp->config.rst_gpio_num);
|
||||
}
|
||||
|
||||
free(tp);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Private API function
|
||||
*******************************************************************************/
|
||||
|
||||
static esp_err_t touch_ft6x36_init(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint8_t vend_id, chip_id, firm_vers, point_rate, thresh, reg_val;
|
||||
|
||||
assert(tp != NULL);
|
||||
|
||||
/* Read vendor ID */
|
||||
ESP_RETURN_ON_ERROR(touch_ft6x36_i2c_read(tp, FT62XX_REG_VENDID, &vend_id, 1), TAG, "Read vendor ID error");
|
||||
|
||||
/* Read chip ID */
|
||||
ESP_RETURN_ON_ERROR(touch_ft6x36_i2c_read(tp, FT62XX_REG_CHIPID, &chip_id, 1), TAG, "Read chip ID error");
|
||||
|
||||
/* Read firmware version */
|
||||
ESP_RETURN_ON_ERROR(touch_ft6x36_i2c_read(tp, FT62XX_REG_FIRMVERS, &firm_vers, 1), TAG, "Read firmware version error");
|
||||
|
||||
/* Read point rate */
|
||||
ESP_RETURN_ON_ERROR(touch_ft6x36_i2c_read(tp, FT62XX_REG_POINTRATE, &point_rate, 1), TAG, "Read point rate error");
|
||||
|
||||
/* Read threshold */
|
||||
ESP_RETURN_ON_ERROR(touch_ft6x36_i2c_read(tp, FT62XX_REG_THRESHHOLD, &thresh, 1), TAG, "Read threshold error");
|
||||
|
||||
/* Print out the values */
|
||||
ESP_LOGI(TAG, "Vend ID: 0x%02X", vend_id);
|
||||
ESP_LOGI(TAG, "Chip ID: 0x%02X", chip_id);
|
||||
ESP_LOGI(TAG, "Firm V: %d", firm_vers);
|
||||
ESP_LOGI(TAG, "Point Rate Hz: %d", point_rate);
|
||||
ESP_LOGI(TAG, "Thresh: %d", thresh);
|
||||
|
||||
/* Dump all registers */
|
||||
ESP_LOGI(TAG, "Dumping all registers:");
|
||||
for (int16_t i = 0; i < 0x10; i++)
|
||||
{
|
||||
/* Read register */
|
||||
if (touch_ft6x36_i2c_read(tp, i, ®_val, 1) == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG, "I2C $%02X = 0x%02X", i, reg_val);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to read register 0x%02X", i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the values are valid */
|
||||
if (vend_id != FT62XX_VENDID && vend_id != FT6336_VENDID)
|
||||
{
|
||||
ESP_LOGE(TAG, "Invalid vendor ID: 0x%02X", vend_id);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Check if the chip ID is supported */
|
||||
if (chip_id != FT6206_CHIPID && chip_id != FT6236_CHIPID && chip_id != FT6236U_CHIPID && chip_id != FT6336U_CHIPID && chip_id != FT3236_CHIPID)
|
||||
{
|
||||
ESP_LOGE(TAG, "Unsupported chip ID: 0x%02X", chip_id);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Set to work mode */
|
||||
ret |= touch_ft6x36_i2c_write(tp, FT62XX_REG_MODE, FT62XX_REG_WORKMODE);
|
||||
|
||||
/* Set threshold */
|
||||
ret |= touch_ft6x36_i2c_write(tp, FT62XX_REG_THRESHHOLD, FT62XX_DEFAULT_THRESHOLD);
|
||||
|
||||
/* Set point rate */
|
||||
ret |= touch_ft6x36_i2c_write(tp, FT62XX_REG_POINTRATE, 0x0E);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Reset controller */
|
||||
static esp_err_t touch_ft6x36_reset(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
if (tp->config.rst_gpio_num != GPIO_NUM_NC)
|
||||
{
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, tp->config.levels.reset), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, !tp->config.levels.reset), TAG, "GPIO set level error!");
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t touch_ft6x36_i2c_write(esp_lcd_touch_handle_t tp, uint8_t reg, uint8_t data)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
// *INDENT-OFF*
|
||||
/* Write data */
|
||||
return esp_lcd_panel_io_tx_param(tp->io, reg, (uint8_t[]){data}, 1);
|
||||
// *INDENT-ON*
|
||||
}
|
||||
|
||||
static esp_err_t touch_ft6x36_i2c_read(esp_lcd_touch_handle_t tp, uint8_t reg, uint8_t *data, uint8_t len)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(data != NULL);
|
||||
|
||||
/* Read data */
|
||||
return esp_lcd_panel_io_rx_param(tp->io, reg, data, len);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
dependencies:
|
||||
esp_lcd_touch:
|
||||
public: true
|
||||
version: ^1.0.4
|
||||
idf: '>=4.4.2'
|
||||
description: ESP LCD Touch FT6x36 - touch controller FT6x36
|
||||
repository: git://github.com/lambage/esp_lcd_touch_ft6x36.git
|
||||
repository_info:
|
||||
commit_sha: c2772def5d1168bb3ba85c1334dd07ea99b977ec
|
||||
path: components/esp_lcd_touch_ft6x36
|
||||
url: https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch
|
||||
version: 1.0.8
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 CFSoft Systems (Chengdu) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief ESP LCD touch: FT6x36
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_lcd_touch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Create a new FT6x36 touch driver
|
||||
*
|
||||
* @note The I2C communication should be initialized before use this function.
|
||||
*
|
||||
* @param io LCD/Touch panel IO handle
|
||||
* @param config: Touch configuration
|
||||
* @param out_touch: Touch instance handle
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NO_MEM if there is no memory for allocating main structure
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_new_i2c_ft6x36(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *out_touch);
|
||||
|
||||
/**
|
||||
* @brief I2C address of the FT6x36 controller
|
||||
*
|
||||
*/
|
||||
#define ESP_LCD_TOUCH_IO_I2C_FT6x36_ADDRESS (0x38)
|
||||
|
||||
/**
|
||||
* @brief Touch IO configuration structure
|
||||
*
|
||||
*/
|
||||
#define ESP_LCD_TOUCH_IO_I2C_FT6x36_CONFIG() \
|
||||
{ \
|
||||
.dev_addr = ESP_LCD_TOUCH_IO_I2C_FT6x36_ADDRESS, \
|
||||
.control_phase_bytes = 1, \
|
||||
.dc_bit_offset = 0, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.flags = \
|
||||
{ \
|
||||
.disable_control_phase = 1, \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Reference in New Issue
Block a user