Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b0a22e756f | |||
| a60c9840ca |
@@ -1,87 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
"""Convert an image to an uncompressed LVGL RGB565 launcher background."""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import shutil
|
|
||||||
import struct
|
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
LV_IMAGE_HEADER_MAGIC = 0x19
|
|
||||||
LV_COLOR_FORMAT_RGB565 = 0x12
|
|
||||||
|
|
||||||
|
|
||||||
def parse_args() -> argparse.Namespace:
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description=(
|
|
||||||
"Create an uncompressed LVGL .bin image for "
|
|
||||||
"/sdcard/tactility/launcher/background.bin. Use a square image sized "
|
|
||||||
"to the display's longest edge to support both orientations without scaling "
|
|
||||||
"(for example, 320x320 for a 320x240 display)."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
parser.add_argument("input", type=Path, help="Source image")
|
|
||||||
parser.add_argument("output", type=Path, help="Destination .bin file")
|
|
||||||
parser.add_argument("--width", type=int, required=True, help="Output width")
|
|
||||||
parser.add_argument("--height", type=int, required=True, help="Output height")
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
args = parse_args()
|
|
||||||
if args.width <= 0 or args.width > 65535 or args.height <= 0 or args.height > 65535:
|
|
||||||
raise SystemExit("width and height must be between 1 and 65535")
|
|
||||||
|
|
||||||
magick = shutil.which("magick")
|
|
||||||
if magick is None:
|
|
||||||
raise SystemExit("ImageMagick is required (the 'magick' command was not found)")
|
|
||||||
|
|
||||||
command = [
|
|
||||||
magick,
|
|
||||||
str(args.input),
|
|
||||||
"-resize",
|
|
||||||
f"{args.width}x{args.height}^",
|
|
||||||
"-gravity",
|
|
||||||
"center",
|
|
||||||
"-extent",
|
|
||||||
f"{args.width}x{args.height}",
|
|
||||||
"-depth",
|
|
||||||
"8",
|
|
||||||
"rgb:-",
|
|
||||||
]
|
|
||||||
rgb888 = subprocess.run(command, check=True, stdout=subprocess.PIPE).stdout
|
|
||||||
expected_size = args.width * args.height * 3
|
|
||||||
if len(rgb888) != expected_size:
|
|
||||||
raise SystemExit(f"unexpected ImageMagick output: {len(rgb888)} bytes, expected {expected_size}")
|
|
||||||
|
|
||||||
rgb565 = bytearray(args.width * args.height * 2)
|
|
||||||
for source_offset in range(0, len(rgb888), 3):
|
|
||||||
r, g, b = rgb888[source_offset : source_offset + 3]
|
|
||||||
pixel = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
|
|
||||||
destination_offset = (source_offset // 3) * 2
|
|
||||||
struct.pack_into("<H", rgb565, destination_offset, pixel)
|
|
||||||
|
|
||||||
stride = args.width * 2
|
|
||||||
header = struct.pack(
|
|
||||||
"<BBHHHHH",
|
|
||||||
LV_IMAGE_HEADER_MAGIC,
|
|
||||||
LV_COLOR_FORMAT_RGB565,
|
|
||||||
0,
|
|
||||||
args.width,
|
|
||||||
args.height,
|
|
||||||
stride,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
|
|
||||||
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
args.output.write_bytes(header + rgb565)
|
|
||||||
print(
|
|
||||||
f"Wrote {args.output} ({args.width}x{args.height}, "
|
|
||||||
f"{len(header) + len(rgb565)} bytes, uncompressed RGB565)"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 298 KiB |
@@ -21,7 +21,3 @@ lvgl.colorDepth=16
|
|||||||
storage.userDataLocation=SD
|
storage.userDataLocation=SD
|
||||||
|
|
||||||
dependencies.useDeprecatedHal=false
|
dependencies.useDeprecatedHal=false
|
||||||
|
|
||||||
# Launcher clock and full-screen wallpaper
|
|
||||||
sdkconfig.CONFIG_LV_FONT_MONTSERRAT_48=y
|
|
||||||
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=1048576
|
|
||||||
|
|||||||
@@ -91,7 +91,6 @@
|
|||||||
compatible = "everest,es8311";
|
compatible = "everest,es8311";
|
||||||
reg = <0x18>;
|
reg = <0x18>;
|
||||||
i2s = <&i2s0>;
|
i2s = <&i2s0>;
|
||||||
input-gain-percent = <100>;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
idf_component_register(
|
|
||||||
SRCS "source/module.cpp"
|
|
||||||
REQUIRES TactilityKernel
|
|
||||||
)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
dependencies:
|
|
||||||
- Platforms/platform-esp32
|
|
||||||
- Drivers/st77922-module
|
|
||||||
- Drivers/es8311-module
|
|
||||||
- Drivers/audio-stream-module
|
|
||||||
dts: es3c35p.dts
|
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
/dts-v1/;
|
|
||||||
|
|
||||||
#include <tactility/bindings/root.h>
|
|
||||||
#include <tactility/bindings/esp32_adc_oneshot.h>
|
|
||||||
#include <tactility/bindings/esp32_ble.h>
|
|
||||||
#include <tactility/bindings/esp32_gpio.h>
|
|
||||||
#include <tactility/bindings/esp32_i2c.h>
|
|
||||||
#include <tactility/bindings/esp32_i2s.h>
|
|
||||||
#include <tactility/bindings/esp32_pwm_ledc.h>
|
|
||||||
#include <tactility/bindings/esp32_sdmmc.h>
|
|
||||||
#include <tactility/bindings/esp32_spi.h>
|
|
||||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
|
||||||
#include <tactility/bindings/battery_sense.h>
|
|
||||||
#include <tactility/bindings/gpio_hog.h>
|
|
||||||
#include <tactility/bindings/pwm_backlight.h>
|
|
||||||
#include <bindings/st77922.h>
|
|
||||||
#include <bindings/st77922_touch.h>
|
|
||||||
#include <bindings/es8311.h>
|
|
||||||
|
|
||||||
/ {
|
|
||||||
compatible = "root";
|
|
||||||
model = "LCDWIKI/Hosyond ES3C35P";
|
|
||||||
|
|
||||||
wifi0 {
|
|
||||||
compatible = "espressif,esp32-wifi-pinned";
|
|
||||||
status = "disabled";
|
|
||||||
};
|
|
||||||
|
|
||||||
ble0 {
|
|
||||||
compatible = "espressif,esp32-ble";
|
|
||||||
status = "disabled";
|
|
||||||
};
|
|
||||||
|
|
||||||
gpio0 {
|
|
||||||
compatible = "espressif,esp32-gpio";
|
|
||||||
gpio-count = <49>;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* FM8002E speaker amplifier enable, active-low on GPIO1. */
|
|
||||||
amp_enable {
|
|
||||||
compatible = "gpio-hog";
|
|
||||||
pin = <&gpio0 1 GPIO_FLAG_NONE>;
|
|
||||||
mode = <GPIO_HOG_MODE_OUTPUT_LOW>;
|
|
||||||
};
|
|
||||||
|
|
||||||
adc0 {
|
|
||||||
compatible = "espressif,esp32-adc-oneshot";
|
|
||||||
unit-id = <ADC_UNIT_1>;
|
|
||||||
clk-src = <ADC_RTC_CLK_SRC_DEFAULT>;
|
|
||||||
channels = <ADC_CHANNEL_7 ADC_ATTEN_DB_12 ADC_BITWIDTH_DEFAULT>;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* BAT+ through a 200K/200K divider into GPIO8 / ADC1_CH7. */
|
|
||||||
battery-sense {
|
|
||||||
compatible = "battery-sense";
|
|
||||||
io-channel = <&adc0 0>;
|
|
||||||
reference-voltage-mv = <3300>;
|
|
||||||
multiplier = <2000>;
|
|
||||||
};
|
|
||||||
|
|
||||||
i2s0 {
|
|
||||||
compatible = "espressif,esp32-i2s";
|
|
||||||
port = <I2S_NUM_0>;
|
|
||||||
pin-bclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
|
||||||
pin-ws = <&gpio0 21 GPIO_FLAG_NONE>;
|
|
||||||
pin-data-out = <&gpio0 15 GPIO_FLAG_NONE>;
|
|
||||||
pin-data-in = <&gpio0 16 GPIO_FLAG_NONE>;
|
|
||||||
pin-mclk = <&gpio0 17 GPIO_FLAG_NONE>;
|
|
||||||
};
|
|
||||||
|
|
||||||
i2c0 {
|
|
||||||
compatible = "espressif,esp32-i2c";
|
|
||||||
port = <I2C_NUM_0>;
|
|
||||||
clock-frequency = <400000>;
|
|
||||||
pin-sda = <&gpio0 38 GPIO_FLAG_NONE>;
|
|
||||||
pin-scl = <&gpio0 39 GPIO_FLAG_NONE>;
|
|
||||||
|
|
||||||
touch@55 {
|
|
||||||
compatible = "sitronix,st77922-touch";
|
|
||||||
reg = <0x55>;
|
|
||||||
x-max = <320>;
|
|
||||||
y-max = <480>;
|
|
||||||
pin-reset = <&gpio0 48 GPIO_FLAG_NONE>;
|
|
||||||
pin-interrupt = <&gpio0 47 GPIO_FLAG_NONE>;
|
|
||||||
};
|
|
||||||
|
|
||||||
es8311: es8311@18 {
|
|
||||||
compatible = "everest,es8311";
|
|
||||||
reg = <0x18>;
|
|
||||||
i2s = <&i2s0>;
|
|
||||||
input-gain-percent = <100>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
display_backlight_pwm {
|
|
||||||
compatible = "espressif,esp32-pwm-ledc";
|
|
||||||
pin = <&gpio0 41 GPIO_FLAG_NONE>;
|
|
||||||
period-ns = <200000>;
|
|
||||||
ledc-timer = <0>;
|
|
||||||
ledc-channel = <0>;
|
|
||||||
};
|
|
||||||
|
|
||||||
display_backlight {
|
|
||||||
compatible = "pwm-backlight";
|
|
||||||
status = "disabled";
|
|
||||||
pwm = <&display_backlight_pwm>;
|
|
||||||
};
|
|
||||||
|
|
||||||
spi0 {
|
|
||||||
compatible = "espressif,esp32-spi";
|
|
||||||
host = <SPI2_HOST>;
|
|
||||||
pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
|
|
||||||
pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
|
|
||||||
pin-miso = <&gpio0 13 GPIO_FLAG_NONE>;
|
|
||||||
pin-wp = <&gpio0 14 GPIO_FLAG_NONE>;
|
|
||||||
pin-hd = <&gpio0 9 GPIO_FLAG_NONE>;
|
|
||||||
cs-gpios = <&gpio0 10 GPIO_FLAG_NONE>;
|
|
||||||
/* Accommodate the driver's 1/10-frame DMA staging transfers, matching
|
|
||||||
* the vendor LVGL port's full-frame refresh path. */
|
|
||||||
max-transfer-size = <65536>;
|
|
||||||
|
|
||||||
display@0 {
|
|
||||||
compatible = "sitronix,st77922";
|
|
||||||
horizontal-resolution = <320>;
|
|
||||||
vertical-resolution = <480>;
|
|
||||||
/* 80 MHz works in the vendor demo, but produces visible QSPI corruption on
|
|
||||||
* some modules/cables. The component's 40 MHz default is reliably clean. */
|
|
||||||
pixel-clock-hz = <40000000>;
|
|
||||||
backlight = <&display_backlight>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
sdmmc0 {
|
|
||||||
compatible = "espressif,esp32-sdmmc";
|
|
||||||
pin-clk = <&gpio0 5 GPIO_FLAG_NONE>;
|
|
||||||
pin-cmd = <&gpio0 4 GPIO_FLAG_NONE>;
|
|
||||||
pin-d0 = <&gpio0 6 GPIO_FLAG_NONE>;
|
|
||||||
pin-d1 = <&gpio0 7 GPIO_FLAG_NONE>;
|
|
||||||
pin-d2 = <&gpio0 2 GPIO_FLAG_NONE>;
|
|
||||||
pin-d3 = <&gpio0 3 GPIO_FLAG_NONE>;
|
|
||||||
slot = <SDMMC_HOST_SLOT_1>;
|
|
||||||
bus-width = <4>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include <tactility/module.h>
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
Module es3c35p_module = {
|
|
||||||
.name = "es3c35p"
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${SOURCE_FILES}
|
||||||
|
INCLUDE_DIRS "source"
|
||||||
|
REQUIRES TactilityKernel driver
|
||||||
|
)
|
||||||
+14
-15
@@ -1,5 +1,6 @@
|
|||||||
general.vendor=LCDWIKI/Hosyond
|
general.vendor=WaveShare
|
||||||
general.name=ES3C35P
|
general.name=ESP32-S3-RLCD-4.2
|
||||||
|
general.incubating=true
|
||||||
|
|
||||||
apps.launcherAppId=Launcher
|
apps.launcherAppId=Launcher
|
||||||
|
|
||||||
@@ -8,21 +9,19 @@ hardware.flashSize=16MB
|
|||||||
hardware.spiRam=true
|
hardware.spiRam=true
|
||||||
hardware.spiRamMode=OCT
|
hardware.spiRamMode=OCT
|
||||||
hardware.spiRamSpeed=120M
|
hardware.spiRamSpeed=120M
|
||||||
hardware.esptoolFlashFreq=120M
|
|
||||||
hardware.tinyUsb=true
|
hardware.tinyUsb=true
|
||||||
|
hardware.esptoolFlashFreq=120M
|
||||||
hardware.bluetooth=true
|
hardware.bluetooth=true
|
||||||
|
|
||||||
display.size=3.5"
|
|
||||||
display.shape=rectangle
|
|
||||||
display.dpi=165
|
|
||||||
|
|
||||||
lvgl.colorDepth=16
|
|
||||||
|
|
||||||
storage.userDataLocation=SD
|
|
||||||
|
|
||||||
dependencies.useDeprecatedHal=false
|
dependencies.useDeprecatedHal=false
|
||||||
|
|
||||||
# Launcher clock and full-screen wallpaper
|
storage.userDataLocation=SD
|
||||||
sdkconfig.CONFIG_LV_FONT_MONTSERRAT_48=y
|
|
||||||
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=1048576
|
display.size=4.2"
|
||||||
sdkconfig.CONFIG_LV_IMAGE_HEADER_CACHE_DEF_CNT=16
|
display.shape=rectangle
|
||||||
|
display.dpi=120
|
||||||
|
|
||||||
|
lvgl.colorDepth=16
|
||||||
|
lvgl.uiDensity=compact
|
||||||
|
lvgl.fontSize=20
|
||||||
|
lvgl.theme=DefaultDark
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
dependencies:
|
||||||
|
- Platforms/platform-esp32
|
||||||
|
- Drivers/st7305-module
|
||||||
|
- Drivers/button-control-module
|
||||||
|
dts: waveshare,esp32-s3-rlcd.dts
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#include <tactility/module.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
Module waveshare_esp32_s3_rlcd_module = {
|
||||||
|
.name = "waveshare-esp32-s3-rlcd"
|
||||||
|
};
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
#include <tactility/bindings/root.h>
|
||||||
|
#include <tactility/bindings/esp32_ble.h>
|
||||||
|
#include <tactility/bindings/esp32_gpio.h>
|
||||||
|
#include <tactility/bindings/esp32_i2c_master.h>
|
||||||
|
#include <tactility/bindings/esp32_i2s.h>
|
||||||
|
#include <tactility/bindings/esp32_sdmmc.h>
|
||||||
|
#include <tactility/bindings/esp32_spi.h>
|
||||||
|
#include <tactility/bindings/esp32_uart.h>
|
||||||
|
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||||
|
|
||||||
|
#include <bindings/button_control.h>
|
||||||
|
#include <bindings/st7305.h>
|
||||||
|
|
||||||
|
/ {
|
||||||
|
compatible = "root";
|
||||||
|
model = "Waveshare ESP32-S3-RLCD-4.2";
|
||||||
|
|
||||||
|
wifi0 {
|
||||||
|
compatible = "espressif,esp32-wifi-pinned";
|
||||||
|
status = "disabled";
|
||||||
|
};
|
||||||
|
|
||||||
|
ble0 {
|
||||||
|
compatible = "espressif,esp32-ble";
|
||||||
|
status = "disabled";
|
||||||
|
};
|
||||||
|
|
||||||
|
gpio0 {
|
||||||
|
compatible = "espressif,esp32-gpio";
|
||||||
|
gpio-count = <49>;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Audio bus pins from the RLCD-specific MicroPython configuration.
|
||||||
|
i2s0 {
|
||||||
|
compatible = "espressif,esp32-i2s";
|
||||||
|
port = <I2S_NUM_0>;
|
||||||
|
pin-bclk = <&gpio0 9 GPIO_FLAG_NONE>;
|
||||||
|
pin-ws = <&gpio0 45 GPIO_FLAG_NONE>;
|
||||||
|
pin-data-out = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||||
|
pin-data-in = <&gpio0 10 GPIO_FLAG_NONE>;
|
||||||
|
pin-mclk = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c0 {
|
||||||
|
compatible = "espressif,esp32-i2c-master";
|
||||||
|
port = <I2C_NUM_0>;
|
||||||
|
clock-frequency = <400000>;
|
||||||
|
pin-sda = <&gpio0 13 GPIO_FLAG_NONE>;
|
||||||
|
pin-scl = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||||
|
};
|
||||||
|
|
||||||
|
spi0 {
|
||||||
|
compatible = "espressif,esp32-spi";
|
||||||
|
host = <SPI2_HOST>;
|
||||||
|
cs-gpios = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||||
|
pin-mosi = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||||
|
pin-sclk = <&gpio0 11 GPIO_FLAG_NONE>;
|
||||||
|
max-transfer-size = <15000>;
|
||||||
|
|
||||||
|
display@0 {
|
||||||
|
compatible = "sitronix,st7305";
|
||||||
|
horizontal-resolution = <400>;
|
||||||
|
vertical-resolution = <300>;
|
||||||
|
pixel-clock-hz = <20000000>;
|
||||||
|
pin-dc = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||||
|
pin-reset = <&gpio0 41 GPIO_FLAG_NONE>;
|
||||||
|
invert-color;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
buttons {
|
||||||
|
compatible = "tactility,button-control";
|
||||||
|
pin-primary = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||||
|
pin-secondary = <&gpio0 0 GPIO_FLAG_NONE>;
|
||||||
|
};
|
||||||
|
|
||||||
|
sdmmc0 {
|
||||||
|
compatible = "espressif,esp32-sdmmc";
|
||||||
|
pin-clk = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||||
|
pin-cmd = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||||
|
pin-d0 = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||||
|
pin-d3 = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||||
|
slot = <SDMMC_HOST_SLOT_1>;
|
||||||
|
bus-width = <1>;
|
||||||
|
pullups;
|
||||||
|
};
|
||||||
|
|
||||||
|
uart0 {
|
||||||
|
compatible = "espressif,esp32-uart";
|
||||||
|
port = <UART_NUM_0>;
|
||||||
|
pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
|
||||||
|
pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -553,14 +553,9 @@ error_t close_stream(AudioStreamHandle handle_base) {
|
|||||||
Device* codec = is_input ? data->input_codec : data->output_codec;
|
Device* codec = is_input ? data->input_codec : data->output_codec;
|
||||||
AudioStreamHandleImpl** slot = is_input ? &data->open_input : &data->open_output;
|
AudioStreamHandleImpl** slot = is_input ? &data->open_input : &data->open_output;
|
||||||
|
|
||||||
// Determine if underlying codec is shared (BOTH codec used for both directions)
|
|
||||||
// In that case we must NOT close the codec if the other direction is still active.
|
|
||||||
Device* other_codec = is_input ? data->output_codec : data->input_codec;
|
|
||||||
AudioStreamHandleImpl** other_slot = is_input ? &data->open_output : &data->open_input;
|
|
||||||
bool codec_shared = (codec != nullptr && other_codec != nullptr && codec == other_codec);
|
|
||||||
|
|
||||||
xSemaphoreTake(data->mutex, portMAX_DELAY);
|
xSemaphoreTake(data->mutex, portMAX_DELAY);
|
||||||
if (handle->closing) {
|
if (handle->closing) {
|
||||||
|
// Already being closed by another caller (e.g. concurrent set_enabled + app close).
|
||||||
xSemaphoreGive(data->mutex);
|
xSemaphoreGive(data->mutex);
|
||||||
return ERROR_NONE;
|
return ERROR_NONE;
|
||||||
}
|
}
|
||||||
@@ -568,16 +563,14 @@ error_t close_stream(AudioStreamHandle handle_base) {
|
|||||||
if (*slot == handle) {
|
if (*slot == handle) {
|
||||||
*slot = nullptr;
|
*slot = nullptr;
|
||||||
}
|
}
|
||||||
bool other_still_open = (other_slot != nullptr && *other_slot != nullptr && *other_slot != reinterpret_cast<AudioStreamHandleImpl*>(1));
|
|
||||||
bool must_drain = (handle->busy_count > 0);
|
bool must_drain = (handle->busy_count > 0);
|
||||||
bool should_close_codec = !codec_shared || !other_still_open;
|
|
||||||
xSemaphoreGive(data->mutex);
|
xSemaphoreGive(data->mutex);
|
||||||
|
|
||||||
if (must_drain && handle->drain_semaphore != nullptr) {
|
if (must_drain && handle->drain_semaphore != nullptr) {
|
||||||
xSemaphoreTake(handle->drain_semaphore, portMAX_DELAY);
|
xSemaphoreTake(handle->drain_semaphore, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (should_close_codec && codec != nullptr) {
|
if (codec != nullptr) {
|
||||||
audio_codec_close(codec);
|
audio_codec_close(codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,3 @@ properties:
|
|||||||
type: phandle
|
type: phandle
|
||||||
required: true
|
required: true
|
||||||
description: "I2S controller device that carries audio data"
|
description: "I2S controller device that carries audio data"
|
||||||
input-gain-percent:
|
|
||||||
type: int
|
|
||||||
default: 100
|
|
||||||
description: "Extra digital gain multiplier applied by audio_stream on top of the ES8311's own 24dB hardware ADC gain, as an integer percentage (100 = 1.0x / no extra boost). For quiet MEMS mic capsules that are still quiet even at max hardware gain."
|
|
||||||
|
|||||||
@@ -25,14 +25,6 @@ struct Es8311Config {
|
|||||||
uint8_t address;
|
uint8_t address;
|
||||||
/** I2S controller device that carries audio data */
|
/** I2S controller device that carries audio data */
|
||||||
struct Device* i2s_device;
|
struct Device* i2s_device;
|
||||||
/**
|
|
||||||
* Extra fixed digital gain multiplier applied by audio_stream on top of the ES8311's
|
|
||||||
* own hardware ADC gain (0..24dB), as an integer percentage (100 = 1.0x / no extra boost).
|
|
||||||
* Small MEMS mic capsules can still sound quiet even near max hardware gain; this is for
|
|
||||||
* boards where 24dB hardware gain alone isn't enough. devicetree has no float property type,
|
|
||||||
* hence the x100 integer encoding.
|
|
||||||
*/
|
|
||||||
uint16_t input_gain_percent;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ struct Es8311Data {
|
|||||||
bool is_open = false;
|
bool is_open = false;
|
||||||
AudioCodecDirection open_direction = AUDIO_CODEC_DIR_BOTH;
|
AudioCodecDirection open_direction = AUDIO_CODEC_DIR_BOTH;
|
||||||
esp_codec_dev_sample_info_t open_sample_info = {};
|
esp_codec_dev_sample_info_t open_sample_info = {};
|
||||||
float input_gain = 1.0f;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GET_CONFIG(device) (static_cast<const Es8311Config*>((device)->config))
|
#define GET_CONFIG(device) (static_cast<const Es8311Config*>((device)->config))
|
||||||
@@ -54,36 +53,16 @@ error_t open(Device* device, const struct AudioCodecStreamConfig* config) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (data->is_open) {
|
if (data->is_open) {
|
||||||
// ES8311 is configured for WORK_MODE_BOTH, so an already-open device
|
// open_direction == BOTH already serves INPUT-only or OUTPUT-only requests on the
|
||||||
// can serve the opposite direction without reopening, provided sample
|
// same sample settings -- only an exact direction mismatch (e.g. requesting BOTH
|
||||||
// settings match. Promote open_direction to BOTH when we see a
|
// while opened for INPUT only) needs a reopen.
|
||||||
// complementary request.
|
bool direction_compatible = data->open_direction == config->direction
|
||||||
bool is_complementary = (data->open_direction == AUDIO_CODEC_DIR_OUTPUT && config->direction == AUDIO_CODEC_DIR_INPUT)
|
|| data->open_direction == AUDIO_CODEC_DIR_BOTH;
|
||||||
|| (data->open_direction == AUDIO_CODEC_DIR_INPUT && config->direction == AUDIO_CODEC_DIR_OUTPUT);
|
|
||||||
bool direction_compatible = (data->open_direction == config->direction)
|
|
||||||
|| (data->open_direction == AUDIO_CODEC_DIR_BOTH)
|
|
||||||
|| (config->direction == AUDIO_CODEC_DIR_BOTH)
|
|
||||||
|| is_complementary;
|
|
||||||
bool same_config = direction_compatible
|
bool same_config = direction_compatible
|
||||||
&& data->open_sample_info.bits_per_sample == sample_info.bits_per_sample
|
&& data->open_sample_info.bits_per_sample == sample_info.bits_per_sample
|
||||||
&& data->open_sample_info.channel == sample_info.channel
|
&& data->open_sample_info.channel == sample_info.channel
|
||||||
&& data->open_sample_info.sample_rate == sample_info.sample_rate;
|
&& data->open_sample_info.sample_rate == sample_info.sample_rate;
|
||||||
if (same_config) {
|
return same_config ? ERROR_NONE : ERROR_RESOURCE;
|
||||||
// If we opened OUTPUT then INPUT (or vice versa), mark as BOTH
|
|
||||||
if (is_complementary) {
|
|
||||||
data->open_direction = AUDIO_CODEC_DIR_BOTH;
|
|
||||||
}
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
// Different sample config for opposite direction - ES8311 can only have one
|
|
||||||
// sample rate at a time (native 44100 resampled via audio-stream), so if
|
|
||||||
// codec rates differ we must fail. But if both sides use native 44100 (audio-stream
|
|
||||||
// always opens codec with native rate), we allow it.
|
|
||||||
if (direction_compatible) {
|
|
||||||
// Allow if both use same native rate path (audio-stream opens with codec's native)
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esp_codec_dev_open(data->codec_device, &sample_info) != ESP_CODEC_DEV_OK) {
|
if (esp_codec_dev_open(data->codec_device, &sample_info) != ESP_CODEC_DEV_OK) {
|
||||||
@@ -165,8 +144,8 @@ error_t set_volume(Device* device, AudioCodecDirection direction, float volume_p
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (direction == AUDIO_CODEC_DIR_INPUT) {
|
if (direction == AUDIO_CODEC_DIR_INPUT) {
|
||||||
// ES8311 ADC gain supports 0..42dB (0,6,12,18,24,30,36,42) – max hardware to restore old +30dB+ behavior
|
// ES8311 ADC gain range is roughly 0..24 dB; map 0..100% linearly onto it.
|
||||||
float db = (volume_percent / 100.0f) * 42.0f;
|
float db = (volume_percent / 100.0f) * 24.0f;
|
||||||
return (esp_codec_dev_set_in_gain(data->codec_device, db) == ESP_CODEC_DEV_OK) ? ERROR_NONE : ERROR_RESOURCE;
|
return (esp_codec_dev_set_in_gain(data->codec_device, db) == ESP_CODEC_DEV_OK) ? ERROR_NONE : ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,8 +172,7 @@ error_t get_volume(Device* device, AudioCodecDirection direction, float* volume_
|
|||||||
if (esp_codec_dev_get_in_gain(data->codec_device, &db) != ESP_CODEC_DEV_OK) {
|
if (esp_codec_dev_get_in_gain(data->codec_device, &db) != ESP_CODEC_DEV_OK) {
|
||||||
return ERROR_RESOURCE;
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
*volume_percent = (db / 42.0f) * 100.0f;
|
*volume_percent = (db / 24.0f) * 100.0f;
|
||||||
if (*volume_percent > 100.0f) *volume_percent = 100.0f;
|
|
||||||
return ERROR_NONE;
|
return ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,12 +235,6 @@ error_t get_capabilities(Device* device, AudioCodecDirection* supported_directio
|
|||||||
return ERROR_NONE;
|
return ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_t get_input_gain_multiplier(Device* device, float* gain) {
|
|
||||||
auto* data = GET_DATA(device);
|
|
||||||
*gain = data->input_gain;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct AudioCodecApi API = {
|
static const struct AudioCodecApi API = {
|
||||||
.open = open,
|
.open = open,
|
||||||
.close = close,
|
.close = close,
|
||||||
@@ -275,7 +247,7 @@ static const struct AudioCodecApi API = {
|
|||||||
.get_native_sample_rate = get_native_sample_rate,
|
.get_native_sample_rate = get_native_sample_rate,
|
||||||
.get_native_channels = get_native_channels,
|
.get_native_channels = get_native_channels,
|
||||||
.get_capabilities = get_capabilities,
|
.get_capabilities = get_capabilities,
|
||||||
.get_input_gain_multiplier = get_input_gain_multiplier,
|
.get_input_gain_multiplier = nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
@@ -285,11 +257,6 @@ static const struct AudioCodecApi API = {
|
|||||||
error_t start_device(Device* device) {
|
error_t start_device(Device* device) {
|
||||||
const auto* config = GET_CONFIG(device);
|
const auto* config = GET_CONFIG(device);
|
||||||
|
|
||||||
if (config->input_gain_percent > 2000) {
|
|
||||||
LOG_E(TAG, "Invalid input_gain_percent %u (must be 0..2000)", config->input_gain_percent);
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* i2c_controller = device_get_parent(device);
|
auto* i2c_controller = device_get_parent(device);
|
||||||
if (i2c_controller == nullptr || device_get_type(i2c_controller) != &I2C_CONTROLLER_TYPE) {
|
if (i2c_controller == nullptr || device_get_type(i2c_controller) != &I2C_CONTROLLER_TYPE) {
|
||||||
LOG_E(TAG, "Parent is not an I2C controller");
|
LOG_E(TAG, "Parent is not an I2C controller");
|
||||||
@@ -303,9 +270,6 @@ error_t start_device(Device* device) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto* data = new Es8311Data();
|
auto* data = new Es8311Data();
|
||||||
data->input_gain = (float) config->input_gain_percent / 100.0f;
|
|
||||||
if (data->input_gain < 0.0f) data->input_gain = 1.0f;
|
|
||||||
if (config->input_gain_percent == 0) data->input_gain = 1.0f; // default when not set (devicetree default 100, but 0 means unset)
|
|
||||||
|
|
||||||
data->ctrl_if = audio_codec_adapter_new_i2c_ctrl(i2c_controller, config->address);
|
data->ctrl_if = audio_codec_adapter_new_i2c_ctrl(i2c_controller, config->address);
|
||||||
data->data_if = audio_codec_adapter_new_i2s_data(i2s_controller);
|
data->data_if = audio_codec_adapter_new_i2s_data(i2s_controller);
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/../../Buildscripts/module.cmake")
|
|||||||
|
|
||||||
file(GLOB_RECURSE SOURCE_FILES "source/*.c*")
|
file(GLOB_RECURSE SOURCE_FILES "source/*.c*")
|
||||||
|
|
||||||
tactility_add_module(st77922-module
|
tactility_add_module(st7305-module
|
||||||
SRCS ${SOURCE_FILES}
|
SRCS ${SOURCE_FILES}
|
||||||
INCLUDE_DIRS include/
|
INCLUDE_DIRS include/
|
||||||
REQUIRES TactilityKernel platform-esp32 esp_lcd_st77922 driver
|
REQUIRES TactilityKernel platform-esp32 esp_lcd driver
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
description: Sitronix ST7305 monochrome reflective LCD panel
|
||||||
|
|
||||||
|
compatible: "sitronix,st7305"
|
||||||
|
|
||||||
|
bus: spi
|
||||||
|
|
||||||
|
properties:
|
||||||
|
horizontal-resolution:
|
||||||
|
type: int
|
||||||
|
required: true
|
||||||
|
description: Horizontal resolution in pixels
|
||||||
|
vertical-resolution:
|
||||||
|
type: int
|
||||||
|
required: true
|
||||||
|
description: Vertical resolution in pixels
|
||||||
|
pixel-clock-hz:
|
||||||
|
type: int
|
||||||
|
default: 20000000
|
||||||
|
description: SPI pixel clock frequency in Hz
|
||||||
|
transaction-queue-depth:
|
||||||
|
type: int
|
||||||
|
default: 10
|
||||||
|
description: Size of the internal SPI transaction queue
|
||||||
|
pin-dc:
|
||||||
|
type: phandles
|
||||||
|
required: true
|
||||||
|
description: Data/Command GPIO pin
|
||||||
|
pin-reset:
|
||||||
|
type: phandles
|
||||||
|
required: true
|
||||||
|
description: Active-low reset GPIO pin
|
||||||
|
invert-color:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
description: Enable the ST7305 display inversion used by the Waveshare RLCD panel
|
||||||
+2
-2
@@ -2,6 +2,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tactility/bindings/bindings.h>
|
#include <tactility/bindings/bindings.h>
|
||||||
#include <drivers/st77922.h>
|
#include <drivers/st7305.h>
|
||||||
|
|
||||||
DEFINE_DEVICETREE(st77922, struct St77922Config)
|
DEFINE_DEVICETREE(st7305, struct St7305Config)
|
||||||
+13
-8
@@ -1,20 +1,25 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <tactility/device.h>
|
#include <tactility/drivers/gpio.h>
|
||||||
|
|
||||||
struct St77922Config {
|
struct St7305Config {
|
||||||
uint16_t horizontal_resolution;
|
uint16_t horizontal_resolution;
|
||||||
uint16_t vertical_resolution;
|
uint16_t vertical_resolution;
|
||||||
bool mirror_x;
|
|
||||||
bool mirror_y;
|
|
||||||
bool invert_color;
|
|
||||||
bool bgr_order;
|
|
||||||
uint32_t bits_per_pixel;
|
|
||||||
uint32_t pixel_clock_hz;
|
uint32_t pixel_clock_hz;
|
||||||
uint8_t transaction_queue_depth;
|
uint8_t transaction_queue_depth;
|
||||||
struct Device* backlight;
|
struct GpioPinSpec pin_dc;
|
||||||
|
struct GpioPinSpec pin_reset;
|
||||||
|
bool invert_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+2
-3
@@ -1,14 +1,13 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <tactility/module.h>
|
||||||
#include <esp_lcd_st77922.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const st77922_lcd_init_cmd_t* st77922_board_init_commands(size_t* count);
|
extern struct Module st7305_module;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#include <tactility/driver.h>
|
||||||
|
#include <tactility/module.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
extern Driver st7305_driver;
|
||||||
|
|
||||||
|
static Driver* const st7305_drivers[] = {
|
||||||
|
&st7305_driver,
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
Module st7305_module = {
|
||||||
|
.name = "st7305",
|
||||||
|
.drivers = st7305_drivers
|
||||||
|
};
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
@@ -0,0 +1,512 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#include <drivers/st7305.h>
|
||||||
|
#include <st7305_module.h>
|
||||||
|
|
||||||
|
#include <tactility/check.h>
|
||||||
|
#include <tactility/device.h>
|
||||||
|
#include <tactility/driver.h>
|
||||||
|
#include <tactility/drivers/display.h>
|
||||||
|
#include <tactility/drivers/esp32_spi.h>
|
||||||
|
#include <tactility/drivers/spi_controller.h>
|
||||||
|
#include <tactility/error.h>
|
||||||
|
#include <tactility/log.h>
|
||||||
|
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
#include <esp_err.h>
|
||||||
|
#include <esp_heap_caps.h>
|
||||||
|
#include <esp_lcd_io_spi.h>
|
||||||
|
#include <esp_lcd_panel_io.h>
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/semphr.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#define TAG "ST7305"
|
||||||
|
#define GET_CONFIG(device) (static_cast<const St7305Config*>((device)->config))
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr uint16_t PANEL_WIDTH = 400;
|
||||||
|
constexpr uint16_t PANEL_HEIGHT = 300;
|
||||||
|
constexpr size_t PANEL_BUFFER_SIZE = PANEL_WIDTH * PANEL_HEIGHT / 8;
|
||||||
|
constexpr uint8_t PANEL_COLUMN_START = 0x12;
|
||||||
|
constexpr uint8_t PANEL_COLUMN_END = 0x2A;
|
||||||
|
constexpr uint8_t PANEL_ROW_START = 0x00;
|
||||||
|
constexpr uint8_t PANEL_ROW_END = 0xC7;
|
||||||
|
|
||||||
|
constexpr uint8_t CMD_SLEEP_IN = 0x10;
|
||||||
|
constexpr uint8_t CMD_SLEEP_OUT = 0x11;
|
||||||
|
constexpr uint8_t CMD_INVERSION_OFF = 0x20;
|
||||||
|
constexpr uint8_t CMD_INVERSION_ON = 0x21;
|
||||||
|
constexpr uint8_t CMD_DISPLAY_OFF = 0x28;
|
||||||
|
constexpr uint8_t CMD_DISPLAY_ON = 0x29;
|
||||||
|
constexpr uint8_t CMD_COLUMN_ADDRESS = 0x2A;
|
||||||
|
constexpr uint8_t CMD_ROW_ADDRESS = 0x2B;
|
||||||
|
constexpr uint8_t CMD_MEMORY_WRITE = 0x2C;
|
||||||
|
|
||||||
|
struct InitCommand {
|
||||||
|
uint8_t command;
|
||||||
|
const uint8_t* data;
|
||||||
|
size_t data_size;
|
||||||
|
uint16_t delay_ms;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t INIT_D6[] = { 0x17, 0x02 };
|
||||||
|
static const uint8_t INIT_D1[] = { 0x01 };
|
||||||
|
static const uint8_t INIT_C0[] = { 0x11, 0x04 };
|
||||||
|
static const uint8_t INIT_C1[] = { 0x41, 0x41, 0x41, 0x41 };
|
||||||
|
static const uint8_t INIT_C2[] = { 0x19, 0x19, 0x19, 0x19 };
|
||||||
|
static const uint8_t INIT_C4[] = { 0x41, 0x41, 0x41, 0x41 };
|
||||||
|
// Keep the second value exactly as the proven MicroPython RLCD sequence: decimal 19 (0x13).
|
||||||
|
static const uint8_t INIT_C5[] = { 0x19, 0x13, 0x19, 0x19 };
|
||||||
|
static const uint8_t INIT_D8[] = { 0xA6, 0xE9 };
|
||||||
|
static const uint8_t INIT_B2[] = { 0x05 };
|
||||||
|
static const uint8_t INIT_B3[] = { 0xE5, 0xF6, 0x05, 0x46, 0x77, 0x77, 0x77, 0x77, 0x76, 0x45 };
|
||||||
|
static const uint8_t INIT_B4[] = { 0x05, 0x46, 0x77, 0x77, 0x77, 0x77, 0x76, 0x45 };
|
||||||
|
static const uint8_t INIT_62[] = { 0x32, 0x03, 0x1F };
|
||||||
|
static const uint8_t INIT_B7[] = { 0x13 };
|
||||||
|
static const uint8_t INIT_B0[] = { 0x64 };
|
||||||
|
static const uint8_t INIT_C9[] = { 0x00 };
|
||||||
|
static const uint8_t INIT_36[] = { 0x48 };
|
||||||
|
static const uint8_t INIT_3A[] = { 0x11 };
|
||||||
|
static const uint8_t INIT_B9[] = { 0x20 };
|
||||||
|
static const uint8_t INIT_B8[] = { 0x29 };
|
||||||
|
static const uint8_t INIT_2A[] = { PANEL_COLUMN_START, PANEL_COLUMN_END };
|
||||||
|
static const uint8_t INIT_2B[] = { PANEL_ROW_START, PANEL_ROW_END };
|
||||||
|
static const uint8_t INIT_35[] = { 0x00 };
|
||||||
|
static const uint8_t INIT_D0[] = { 0xFF };
|
||||||
|
|
||||||
|
// Command order and voltage values are intentionally identical to lib/rlcd.py in the supplied
|
||||||
|
// MicroPython project. The inversion command sits between these two groups and display-on follows.
|
||||||
|
static const InitCommand INIT_SEQUENCE_BEFORE_INVERSION[] = {
|
||||||
|
{ 0xD6, INIT_D6, sizeof(INIT_D6), 0 },
|
||||||
|
{ 0xD1, INIT_D1, sizeof(INIT_D1), 0 },
|
||||||
|
{ 0xC0, INIT_C0, sizeof(INIT_C0), 0 },
|
||||||
|
{ 0xC1, INIT_C1, sizeof(INIT_C1), 0 },
|
||||||
|
{ 0xC2, INIT_C2, sizeof(INIT_C2), 0 },
|
||||||
|
{ 0xC4, INIT_C4, sizeof(INIT_C4), 0 },
|
||||||
|
{ 0xC5, INIT_C5, sizeof(INIT_C5), 0 },
|
||||||
|
{ 0xD8, INIT_D8, sizeof(INIT_D8), 0 },
|
||||||
|
{ 0xB2, INIT_B2, sizeof(INIT_B2), 0 },
|
||||||
|
{ 0xB3, INIT_B3, sizeof(INIT_B3), 0 },
|
||||||
|
{ 0xB4, INIT_B4, sizeof(INIT_B4), 0 },
|
||||||
|
{ 0x62, INIT_62, sizeof(INIT_62), 0 },
|
||||||
|
{ 0xB7, INIT_B7, sizeof(INIT_B7), 0 },
|
||||||
|
{ 0xB0, INIT_B0, sizeof(INIT_B0), 0 },
|
||||||
|
{ CMD_SLEEP_OUT, nullptr, 0, 200 },
|
||||||
|
{ 0xC9, INIT_C9, sizeof(INIT_C9), 0 },
|
||||||
|
{ 0x36, INIT_36, sizeof(INIT_36), 0 },
|
||||||
|
{ 0x3A, INIT_3A, sizeof(INIT_3A), 0 },
|
||||||
|
{ 0xB9, INIT_B9, sizeof(INIT_B9), 0 },
|
||||||
|
{ 0xB8, INIT_B8, sizeof(INIT_B8), 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const InitCommand INIT_SEQUENCE_AFTER_INVERSION[] = {
|
||||||
|
{ CMD_COLUMN_ADDRESS, INIT_2A, sizeof(INIT_2A), 0 },
|
||||||
|
{ CMD_ROW_ADDRESS, INIT_2B, sizeof(INIT_2B), 0 },
|
||||||
|
{ 0x35, INIT_35, sizeof(INIT_35), 0 },
|
||||||
|
{ 0xD0, INIT_D0, sizeof(INIT_D0), 0 },
|
||||||
|
{ 0x38, nullptr, 0, 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
struct St7305Internal {
|
||||||
|
esp_lcd_panel_io_handle_t io_handle;
|
||||||
|
SemaphoreHandle_t transfer_done;
|
||||||
|
uint8_t* panel_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int pin_or_unused(const GpioPinSpec& pin) {
|
||||||
|
return pin.gpio_controller == nullptr ? -1 : static_cast<int>(pin.pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IRAM_ATTR on_color_transfer_done(
|
||||||
|
esp_lcd_panel_io_handle_t,
|
||||||
|
esp_lcd_panel_io_event_data_t*,
|
||||||
|
void* user_context
|
||||||
|
) {
|
||||||
|
auto* internal = static_cast<St7305Internal*>(user_context);
|
||||||
|
BaseType_t high_task_woken = pdFALSE;
|
||||||
|
xSemaphoreGiveFromISR(internal->transfer_done, &high_task_woken);
|
||||||
|
return high_task_woken == pdTRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool send_command(
|
||||||
|
esp_lcd_panel_io_handle_t io_handle,
|
||||||
|
uint8_t command,
|
||||||
|
const void* data = nullptr,
|
||||||
|
size_t data_size = 0
|
||||||
|
) {
|
||||||
|
esp_err_t result = esp_lcd_panel_io_tx_param(io_handle, command, data, data_size);
|
||||||
|
if (result != ESP_OK) {
|
||||||
|
LOG_E(TAG, "Command 0x%02X failed: %s", command, esp_err_to_name(result));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t Size>
|
||||||
|
static bool send_init_sequence(esp_lcd_panel_io_handle_t io_handle, const InitCommand (&sequence)[Size]) {
|
||||||
|
for (const auto& item : sequence) {
|
||||||
|
if (!send_command(io_handle, item.command, item.data, item.data_size)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (item.delay_ms > 0) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(item.delay_ms));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool perform_hardware_reset(const St7305Config* config) {
|
||||||
|
const int reset_pin = pin_or_unused(config->pin_reset);
|
||||||
|
if (reset_pin < 0) {
|
||||||
|
LOG_E(TAG, "Reset pin is required");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpio_config_t io_config = {
|
||||||
|
.pin_bit_mask = 1ULL << reset_pin,
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
};
|
||||||
|
esp_err_t result = gpio_config(&io_config);
|
||||||
|
if (result != ESP_OK) {
|
||||||
|
LOG_E(TAG, "Failed to configure reset pin: %s", esp_err_to_name(result));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Active-low reset, matching RLCD.reset(): released -> asserted -> released.
|
||||||
|
if (gpio_set_level(static_cast<gpio_num_t>(reset_pin), 1) != ESP_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(50));
|
||||||
|
if (gpio_set_level(static_cast<gpio_num_t>(reset_pin), 0) != ESP_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(20));
|
||||||
|
if (gpio_set_level(static_cast<gpio_num_t>(reset_pin), 1) != ESP_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(50));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool set_address_window(esp_lcd_panel_io_handle_t io_handle) {
|
||||||
|
return send_command(io_handle, CMD_COLUMN_ADDRESS, INIT_2A, sizeof(INIT_2A)) &&
|
||||||
|
send_command(io_handle, CMD_ROW_ADDRESS, INIT_2B, sizeof(INIT_2B));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool send_panel_buffer(St7305Internal* internal) {
|
||||||
|
if (!set_address_window(internal->io_handle)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parameter transactions can leave a callback signal on some ESP-IDF versions. Drain it so
|
||||||
|
// this wait can only be completed by the color transaction queued immediately below.
|
||||||
|
xSemaphoreTake(internal->transfer_done, 0);
|
||||||
|
esp_err_t result = esp_lcd_panel_io_tx_color(
|
||||||
|
internal->io_handle,
|
||||||
|
CMD_MEMORY_WRITE,
|
||||||
|
internal->panel_buffer,
|
||||||
|
PANEL_BUFFER_SIZE
|
||||||
|
);
|
||||||
|
if (result != ESP_OK) {
|
||||||
|
LOG_E(TAG, "Panel transfer failed: %s", esp_err_to_name(result));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
xSemaphoreTake(internal->transfer_done, portMAX_DELAY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converts Tactility's DISPLAY_COLOR_FORMAT_MONOCHROME (row-major, MSB-first, bit 1 = white)
|
||||||
|
// into the ST7305's column-major 2x4 packing. The working MicroPython canvas uses bit 1 = black
|
||||||
|
// and enables panel inversion, so each LVGL source pair is inverted before it is packed.
|
||||||
|
static void pack_monochrome_frame(const uint8_t* source, uint8_t* destination) {
|
||||||
|
constexpr size_t source_stride = PANEL_WIDTH / 8;
|
||||||
|
constexpr size_t destination_column_stride = PANEL_HEIGHT / 4;
|
||||||
|
|
||||||
|
for (uint16_t byte_x = 0; byte_x < PANEL_WIDTH / 2; byte_x++) {
|
||||||
|
const uint16_t x = byte_x * 2;
|
||||||
|
const uint8_t source_pair_shift = static_cast<uint8_t>(6 - (x & 0x07));
|
||||||
|
|
||||||
|
for (uint16_t block_y = 0; block_y < PANEL_HEIGHT / 4; block_y++) {
|
||||||
|
uint8_t packed = 0;
|
||||||
|
for (uint8_t local_y = 0; local_y < 4; local_y++) {
|
||||||
|
const uint16_t y = PANEL_HEIGHT - 1 - (block_y * 4 + local_y);
|
||||||
|
const uint8_t white_pair =
|
||||||
|
(source[y * source_stride + x / 8] >> source_pair_shift) & 0x03;
|
||||||
|
const uint8_t black_pair = white_pair ^ 0x03;
|
||||||
|
packed |= static_cast<uint8_t>(black_pair << (6 - local_y * 2));
|
||||||
|
}
|
||||||
|
destination[byte_x * destination_column_stride + block_y] = packed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool initialize_panel(Device* device) {
|
||||||
|
auto* internal = static_cast<St7305Internal*>(device_get_driver_data(device));
|
||||||
|
const auto* config = GET_CONFIG(device);
|
||||||
|
|
||||||
|
if (!send_init_sequence(internal->io_handle, INIT_SEQUENCE_BEFORE_INVERSION)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!send_command(
|
||||||
|
internal->io_handle,
|
||||||
|
config->invert_color ? CMD_INVERSION_ON : CMD_INVERSION_OFF
|
||||||
|
)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!send_init_sequence(internal->io_handle, INIT_SEQUENCE_AFTER_INVERSION)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!send_command(internal->io_handle, CMD_DISPLAY_ON)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Python reference starts with an all-zero hardware buffer. With inversion enabled this
|
||||||
|
// clears retained GRAM to reflective white before LVGL submits its first full frame.
|
||||||
|
memset(internal->panel_buffer, 0, PANEL_BUFFER_SIZE);
|
||||||
|
return send_panel_buffer(internal);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// region DisplayApi
|
||||||
|
|
||||||
|
static error_t st7305_reset(Device* device) {
|
||||||
|
return perform_hardware_reset(GET_CONFIG(device)) ? ERROR_NONE : ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t st7305_init(Device* device) {
|
||||||
|
return initialize_panel(device) ? ERROR_NONE : ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t st7305_draw_bitmap(
|
||||||
|
Device* device,
|
||||||
|
int32_t x_start,
|
||||||
|
int32_t y_start,
|
||||||
|
int32_t x_end,
|
||||||
|
int32_t y_end,
|
||||||
|
const void* color_data
|
||||||
|
) {
|
||||||
|
if (x_start != 0 || y_start != 0 || x_end != PANEL_WIDTH || y_end != PANEL_HEIGHT ||
|
||||||
|
color_data == nullptr) {
|
||||||
|
LOG_E(TAG, "ST7305 requires a complete %ux%u frame", PANEL_WIDTH, PANEL_HEIGHT);
|
||||||
|
return ERROR_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* internal = static_cast<St7305Internal*>(device_get_driver_data(device));
|
||||||
|
pack_monochrome_frame(static_cast<const uint8_t*>(color_data), internal->panel_buffer);
|
||||||
|
return send_panel_buffer(internal) ? ERROR_NONE : ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t st7305_invert_color(Device* device, bool invert) {
|
||||||
|
auto* internal = static_cast<St7305Internal*>(device_get_driver_data(device));
|
||||||
|
return send_command(internal->io_handle, invert ? CMD_INVERSION_ON : CMD_INVERSION_OFF)
|
||||||
|
? ERROR_NONE
|
||||||
|
: ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t st7305_disp_on_off(Device* device, bool on) {
|
||||||
|
auto* internal = static_cast<St7305Internal*>(device_get_driver_data(device));
|
||||||
|
return send_command(internal->io_handle, on ? CMD_DISPLAY_ON : CMD_DISPLAY_OFF)
|
||||||
|
? ERROR_NONE
|
||||||
|
: ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t st7305_disp_sleep(Device* device, bool sleep) {
|
||||||
|
auto* internal = static_cast<St7305Internal*>(device_get_driver_data(device));
|
||||||
|
if (!send_command(internal->io_handle, sleep ? CMD_SLEEP_IN : CMD_SLEEP_OUT)) {
|
||||||
|
return ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(sleep ? 10 : 120));
|
||||||
|
return ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DisplayColorFormat st7305_get_color_format(Device*) {
|
||||||
|
return DISPLAY_COLOR_FORMAT_MONOCHROME;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint16_t st7305_get_resolution_x(Device*) {
|
||||||
|
return PANEL_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint16_t st7305_get_resolution_y(Device*) {
|
||||||
|
return PANEL_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void st7305_get_frame_buffer(Device*, uint8_t, void** out_buffer) {
|
||||||
|
*out_buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t st7305_get_frame_buffer_count(Device*) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const DisplayApi st7305_display_api = {
|
||||||
|
.capabilities = DISPLAY_CAPABILITY_INVERT_COLOR | DISPLAY_CAPABILITY_ON_OFF |
|
||||||
|
DISPLAY_CAPABILITY_SLEEP | DISPLAY_CAPABILITY_REQUIRES_FULL_FRAME,
|
||||||
|
.reset = st7305_reset,
|
||||||
|
.init = st7305_init,
|
||||||
|
.draw_bitmap = st7305_draw_bitmap,
|
||||||
|
.mirror = nullptr,
|
||||||
|
.swap_xy = nullptr,
|
||||||
|
.get_swap_xy = nullptr,
|
||||||
|
.get_mirror_x = nullptr,
|
||||||
|
.get_mirror_y = nullptr,
|
||||||
|
.set_gap = nullptr,
|
||||||
|
.get_gap_x = nullptr,
|
||||||
|
.get_gap_y = nullptr,
|
||||||
|
.invert_color = st7305_invert_color,
|
||||||
|
.disp_on_off = st7305_disp_on_off,
|
||||||
|
.disp_sleep = st7305_disp_sleep,
|
||||||
|
.get_color_format = st7305_get_color_format,
|
||||||
|
.get_resolution_x = st7305_get_resolution_x,
|
||||||
|
.get_resolution_y = st7305_get_resolution_y,
|
||||||
|
.get_frame_buffer = st7305_get_frame_buffer,
|
||||||
|
.get_frame_buffer_count = st7305_get_frame_buffer_count,
|
||||||
|
.get_backlight = nullptr,
|
||||||
|
.has_capability = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Driver lifecycle
|
||||||
|
|
||||||
|
static error_t start(Device* device) {
|
||||||
|
auto* parent = device_get_parent(device);
|
||||||
|
check(device_get_type(parent) == &SPI_CONTROLLER_TYPE);
|
||||||
|
|
||||||
|
const auto* config = GET_CONFIG(device);
|
||||||
|
if (config->horizontal_resolution != PANEL_WIDTH ||
|
||||||
|
config->vertical_resolution != PANEL_HEIGHT) {
|
||||||
|
LOG_E(TAG, "Unsupported resolution %ux%u", config->horizontal_resolution, config->vertical_resolution);
|
||||||
|
return ERROR_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
GpioPinSpec cs_pin;
|
||||||
|
if (esp32_spi_get_cs_pin(device, &cs_pin) != ERROR_NONE) {
|
||||||
|
LOG_E(TAG, "Failed to resolve CS pin");
|
||||||
|
return ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* internal = static_cast<St7305Internal*>(calloc(1, sizeof(St7305Internal)));
|
||||||
|
if (internal == nullptr) {
|
||||||
|
return ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal->transfer_done = xSemaphoreCreateBinary();
|
||||||
|
if (internal->transfer_done == nullptr) {
|
||||||
|
free(internal);
|
||||||
|
return ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal->panel_buffer = static_cast<uint8_t*>(
|
||||||
|
heap_caps_malloc(PANEL_BUFFER_SIZE, MALLOC_CAP_DMA | MALLOC_CAP_8BIT)
|
||||||
|
);
|
||||||
|
if (internal->panel_buffer == nullptr) {
|
||||||
|
vSemaphoreDelete(internal->transfer_done);
|
||||||
|
free(internal);
|
||||||
|
return ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto* spi_config = static_cast<const Esp32SpiConfig*>(parent->config);
|
||||||
|
esp_lcd_panel_io_spi_config_t io_config = {
|
||||||
|
.cs_gpio_num = pin_or_unused(cs_pin),
|
||||||
|
.dc_gpio_num = pin_or_unused(config->pin_dc),
|
||||||
|
.spi_mode = 0,
|
||||||
|
.pclk_hz = config->pixel_clock_hz,
|
||||||
|
.trans_queue_depth = config->transaction_queue_depth,
|
||||||
|
.on_color_trans_done = on_color_transfer_done,
|
||||||
|
.user_ctx = internal,
|
||||||
|
.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,
|
||||||
|
.dc_low_on_param = 0,
|
||||||
|
.octal_mode = 0,
|
||||||
|
.quad_mode = 0,
|
||||||
|
// The panel is write-only. Match the working MicroPython SPI configuration instead
|
||||||
|
// of enabling ESP-IDF's bidirectional three-wire mode on MOSI; direction switching
|
||||||
|
// in that mode can corrupt long framebuffer writes and show up as vertical stripes.
|
||||||
|
.sio_mode = 0,
|
||||||
|
.lsb_first = 0,
|
||||||
|
.cs_high_active = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_err_t result = esp_lcd_new_panel_io_spi(
|
||||||
|
static_cast<esp_lcd_spi_bus_handle_t>(spi_config->host),
|
||||||
|
&io_config,
|
||||||
|
&internal->io_handle
|
||||||
|
);
|
||||||
|
if (result != ESP_OK) {
|
||||||
|
LOG_E(TAG, "Failed to create panel IO: %s", esp_err_to_name(result));
|
||||||
|
heap_caps_free(internal->panel_buffer);
|
||||||
|
vSemaphoreDelete(internal->transfer_done);
|
||||||
|
free(internal);
|
||||||
|
return ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
device_set_driver_data(device, internal);
|
||||||
|
if (!perform_hardware_reset(config) || !initialize_panel(device)) {
|
||||||
|
LOG_E(TAG, "Failed to initialize panel");
|
||||||
|
device_set_driver_data(device, nullptr);
|
||||||
|
esp_lcd_panel_io_del(internal->io_handle);
|
||||||
|
heap_caps_free(internal->panel_buffer);
|
||||||
|
vSemaphoreDelete(internal->transfer_done);
|
||||||
|
free(internal);
|
||||||
|
return ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_I(TAG, "Initialized %ux%u reflective LCD at %lu Hz",
|
||||||
|
PANEL_WIDTH,
|
||||||
|
PANEL_HEIGHT,
|
||||||
|
static_cast<unsigned long>(config->pixel_clock_hz));
|
||||||
|
return ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t stop(Device* device) {
|
||||||
|
auto* internal = static_cast<St7305Internal*>(device_get_driver_data(device));
|
||||||
|
if (internal == nullptr) {
|
||||||
|
return ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
send_command(internal->io_handle, CMD_DISPLAY_OFF);
|
||||||
|
if (esp_lcd_panel_io_del(internal->io_handle) != ESP_OK) {
|
||||||
|
LOG_E(TAG, "Failed to delete panel IO");
|
||||||
|
return ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int reset_pin = pin_or_unused(GET_CONFIG(device)->pin_reset);
|
||||||
|
if (reset_pin >= 0) {
|
||||||
|
gpio_reset_pin(static_cast<gpio_num_t>(reset_pin));
|
||||||
|
}
|
||||||
|
|
||||||
|
heap_caps_free(internal->panel_buffer);
|
||||||
|
vSemaphoreDelete(internal->transfer_done);
|
||||||
|
free(internal);
|
||||||
|
device_set_driver_data(device, nullptr);
|
||||||
|
return ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
Driver st7305_driver = {
|
||||||
|
.name = "st7305",
|
||||||
|
.compatible = (const char*[]) { "sitronix,st7305", nullptr },
|
||||||
|
.start_device = start,
|
||||||
|
.stop_device = stop,
|
||||||
|
.api = &st7305_display_api,
|
||||||
|
.device_type = &DISPLAY_TYPE,
|
||||||
|
.owner = &st7305_module,
|
||||||
|
.internal = nullptr
|
||||||
|
};
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
description: Touch interface integrated in the Sitronix ST77922 TDDI
|
|
||||||
|
|
||||||
include: ["i2c-device.yaml"]
|
|
||||||
|
|
||||||
compatible: "sitronix,st77922-touch"
|
|
||||||
|
|
||||||
bus: i2c
|
|
||||||
|
|
||||||
properties:
|
|
||||||
x-max:
|
|
||||||
type: int
|
|
||||||
required: true
|
|
||||||
description: Maximum X coordinate
|
|
||||||
y-max:
|
|
||||||
type: int
|
|
||||||
required: true
|
|
||||||
description: Maximum Y coordinate
|
|
||||||
swap-xy:
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
description: Swap the X and Y axes
|
|
||||||
mirror-x:
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
description: Mirror the X axis
|
|
||||||
mirror-y:
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
description: Mirror the Y axis
|
|
||||||
pin-reset:
|
|
||||||
type: phandles
|
|
||||||
default: GPIO_PIN_SPEC_NONE
|
|
||||||
description: Reset GPIO pin
|
|
||||||
pin-interrupt:
|
|
||||||
type: phandles
|
|
||||||
default: GPIO_PIN_SPEC_NONE
|
|
||||||
description: Interrupt GPIO pin
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
description: Sitronix ST77922 QSPI display panel
|
|
||||||
|
|
||||||
compatible: "sitronix,st77922"
|
|
||||||
|
|
||||||
bus: spi
|
|
||||||
|
|
||||||
properties:
|
|
||||||
horizontal-resolution:
|
|
||||||
type: int
|
|
||||||
required: true
|
|
||||||
description: Horizontal resolution in pixels
|
|
||||||
vertical-resolution:
|
|
||||||
type: int
|
|
||||||
required: true
|
|
||||||
description: Vertical resolution in pixels
|
|
||||||
mirror-x:
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
description: Mirror the X axis
|
|
||||||
mirror-y:
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
description: Mirror the Y axis
|
|
||||||
invert-color:
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
description: Invert the panel's color output
|
|
||||||
bgr-order:
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
description: Use BGR element order instead of RGB
|
|
||||||
bits-per-pixel:
|
|
||||||
type: int
|
|
||||||
default: 16
|
|
||||||
description: Color depth in bits per pixel
|
|
||||||
pixel-clock-hz:
|
|
||||||
type: int
|
|
||||||
default: 80000000
|
|
||||||
description: QSPI pixel clock frequency in Hz
|
|
||||||
transaction-queue-depth:
|
|
||||||
type: int
|
|
||||||
default: 10
|
|
||||||
description: Size of the internal SPI transaction queue
|
|
||||||
backlight:
|
|
||||||
type: phandle
|
|
||||||
default: "NULL"
|
|
||||||
description: Optional reference to this display's backlight device
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <tactility/bindings/bindings.h>
|
|
||||||
#include <drivers/st77922_touch.h>
|
|
||||||
|
|
||||||
DEFINE_DEVICETREE(st77922_touch, struct St77922TouchConfig)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <tactility/drivers/gpio.h>
|
|
||||||
|
|
||||||
struct St77922TouchConfig {
|
|
||||||
uint8_t address;
|
|
||||||
uint16_t x_max;
|
|
||||||
uint16_t y_max;
|
|
||||||
bool swap_xy;
|
|
||||||
bool mirror_x;
|
|
||||||
bool mirror_y;
|
|
||||||
struct GpioPinSpec pin_reset;
|
|
||||||
struct GpioPinSpec pin_interrupt;
|
|
||||||
};
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <tactility/module.h>
|
|
||||||
|
|
||||||
extern Module st77922_module;
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
#include <tactility/driver.h>
|
|
||||||
#include <tactility/module.h>
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
extern Driver st77922_driver;
|
|
||||||
extern Driver st77922_touch_driver;
|
|
||||||
|
|
||||||
static Driver* const st77922_drivers[] = {
|
|
||||||
&st77922_driver,
|
|
||||||
&st77922_touch_driver,
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
Module st77922_module = {
|
|
||||||
.name = "st77922",
|
|
||||||
.drivers = st77922_drivers
|
|
||||||
};
|
|
||||||
|
|
||||||
} // extern "C"
|
|
||||||
@@ -1,270 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
#include <drivers/st77922.h>
|
|
||||||
#include <st77922_module.h>
|
|
||||||
#include "st77922_init.h"
|
|
||||||
|
|
||||||
#include <tactility/check.h>
|
|
||||||
#include <tactility/device.h>
|
|
||||||
#include <tactility/driver.h>
|
|
||||||
#include <tactility/drivers/display.h>
|
|
||||||
#include <tactility/drivers/esp32_spi.h>
|
|
||||||
#include <tactility/drivers/spi_controller.h>
|
|
||||||
#include <tactility/log.h>
|
|
||||||
|
|
||||||
#include <esp_err.h>
|
|
||||||
#include <esp_heap_caps.h>
|
|
||||||
#include <esp_lcd_io_spi.h>
|
|
||||||
#include <esp_lcd_panel_io.h>
|
|
||||||
#include <esp_lcd_panel_ops.h>
|
|
||||||
#include <esp_lcd_st77922.h>
|
|
||||||
#include <freertos/semphr.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#define TAG "ST77922"
|
|
||||||
#define GET_CONFIG(device) (static_cast<const St77922Config*>((device)->config))
|
|
||||||
|
|
||||||
struct St77922Internal {
|
|
||||||
esp_lcd_panel_io_handle_t io_handle;
|
|
||||||
esp_lcd_panel_handle_t panel_handle;
|
|
||||||
SemaphoreHandle_t draw_done;
|
|
||||||
uint8_t* transfer_buffer;
|
|
||||||
size_t transfer_buffer_size;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool IRAM_ATTR transfer_done(esp_lcd_panel_io_handle_t, esp_lcd_panel_io_event_data_t*, void* context) {
|
|
||||||
auto* internal = static_cast<St77922Internal*>(context);
|
|
||||||
BaseType_t task_woken = pdFALSE;
|
|
||||||
xSemaphoreGiveFromISR(internal->draw_done, &task_woken);
|
|
||||||
return task_woken == pdTRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t start(Device* device) {
|
|
||||||
auto* parent = device_get_parent(device);
|
|
||||||
check(device_get_type(parent) == &SPI_CONTROLLER_TYPE);
|
|
||||||
const auto* spi = static_cast<const Esp32SpiConfig*>(parent->config);
|
|
||||||
const auto* config = GET_CONFIG(device);
|
|
||||||
|
|
||||||
GpioPinSpec cs;
|
|
||||||
if (esp32_spi_get_cs_pin(device, &cs) != ERROR_NONE) {
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* internal = static_cast<St77922Internal*>(calloc(1, sizeof(St77922Internal)));
|
|
||||||
if (internal == nullptr) {
|
|
||||||
return ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
internal->draw_done = xSemaphoreCreateBinary();
|
|
||||||
if (internal->draw_done == nullptr) {
|
|
||||||
free(internal);
|
|
||||||
return ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
// The vendor port renders a complete frame in PSRAM, then copies it through a
|
|
||||||
// 1/10-frame DMA buffer. Besides making full-frame refresh possible, this keeps
|
|
||||||
// the panel's GRAM synchronized when animated objects invalidate old and new
|
|
||||||
// positions in separate LVGL regions.
|
|
||||||
const size_t bytes_per_pixel = config->bits_per_pixel / 8;
|
|
||||||
const size_t rows_per_transfer = config->vertical_resolution > 10
|
|
||||||
? config->vertical_resolution / 10 : config->vertical_resolution;
|
|
||||||
internal->transfer_buffer_size =
|
|
||||||
static_cast<size_t>(config->horizontal_resolution) * rows_per_transfer * bytes_per_pixel;
|
|
||||||
if (spi->max_transfer_size > 0
|
|
||||||
&& internal->transfer_buffer_size > static_cast<size_t>(spi->max_transfer_size)) {
|
|
||||||
internal->transfer_buffer_size = static_cast<size_t>(spi->max_transfer_size);
|
|
||||||
}
|
|
||||||
internal->transfer_buffer = static_cast<uint8_t*>(heap_caps_malloc(
|
|
||||||
internal->transfer_buffer_size, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
|
|
||||||
if (internal->transfer_buffer == nullptr) {
|
|
||||||
vSemaphoreDelete(internal->draw_done);
|
|
||||||
free(internal);
|
|
||||||
return ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_lcd_panel_io_spi_config_t io_config = {
|
|
||||||
.cs_gpio_num = static_cast<int>(cs.pin),
|
|
||||||
.dc_gpio_num = -1,
|
|
||||||
.spi_mode = 0,
|
|
||||||
.pclk_hz = config->pixel_clock_hz,
|
|
||||||
.trans_queue_depth = config->transaction_queue_depth,
|
|
||||||
.on_color_trans_done = transfer_done,
|
|
||||||
.user_ctx = internal,
|
|
||||||
.lcd_cmd_bits = 32,
|
|
||||||
.lcd_param_bits = 8,
|
|
||||||
.cs_ena_pretrans = 0,
|
|
||||||
.cs_ena_posttrans = 0,
|
|
||||||
.flags = {
|
|
||||||
.dc_high_on_cmd = 0,
|
|
||||||
.dc_low_on_data = 0,
|
|
||||||
.dc_low_on_param = 0,
|
|
||||||
.octal_mode = 0,
|
|
||||||
.quad_mode = 1,
|
|
||||||
.sio_mode = 0,
|
|
||||||
.lsb_first = 0,
|
|
||||||
.cs_high_active = 0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
esp_err_t result = esp_lcd_new_panel_io_spi(
|
|
||||||
static_cast<esp_lcd_spi_bus_handle_t>(spi->host), &io_config, &internal->io_handle);
|
|
||||||
if (result != ESP_OK) {
|
|
||||||
LOG_E(TAG, "Failed to create panel IO: %s", esp_err_to_name(result));
|
|
||||||
heap_caps_free(internal->transfer_buffer);
|
|
||||||
vSemaphoreDelete(internal->draw_done);
|
|
||||||
free(internal);
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t init_count = 0;
|
|
||||||
st77922_vendor_config_t vendor = {
|
|
||||||
.init_cmds = st77922_board_init_commands(&init_count),
|
|
||||||
.init_cmds_size = static_cast<uint16_t>(init_count),
|
|
||||||
.flags = { .use_qspi_interface = 1 },
|
|
||||||
};
|
|
||||||
esp_lcd_panel_dev_config_t panel_config = {
|
|
||||||
.reset_gpio_num = -1,
|
|
||||||
.rgb_ele_order = config->bgr_order ? LCD_RGB_ELEMENT_ORDER_BGR : LCD_RGB_ELEMENT_ORDER_RGB,
|
|
||||||
.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE,
|
|
||||||
.bits_per_pixel = config->bits_per_pixel,
|
|
||||||
.flags = { .reset_active_high = false },
|
|
||||||
.vendor_config = &vendor,
|
|
||||||
};
|
|
||||||
result = esp_lcd_new_panel_st77922(internal->io_handle, &panel_config, &internal->panel_handle);
|
|
||||||
bool ok = result == ESP_OK;
|
|
||||||
ok = ok && esp_lcd_panel_reset(internal->panel_handle) == ESP_OK;
|
|
||||||
ok = ok && esp_lcd_panel_init(internal->panel_handle) == ESP_OK;
|
|
||||||
ok = ok && ((!config->mirror_x && !config->mirror_y)
|
|
||||||
|| esp_lcd_panel_mirror(internal->panel_handle, config->mirror_x, config->mirror_y) == ESP_OK);
|
|
||||||
ok = ok && (!config->invert_color || esp_lcd_panel_invert_color(internal->panel_handle, true) == ESP_OK);
|
|
||||||
ok = ok && esp_lcd_panel_disp_on_off(internal->panel_handle, true) == ESP_OK;
|
|
||||||
if (!ok) {
|
|
||||||
LOG_E(TAG, "Failed to bring up panel: %s", esp_err_to_name(result));
|
|
||||||
if (internal->panel_handle != nullptr) esp_lcd_panel_del(internal->panel_handle);
|
|
||||||
esp_lcd_panel_io_del(internal->io_handle);
|
|
||||||
heap_caps_free(internal->transfer_buffer);
|
|
||||||
vSemaphoreDelete(internal->draw_done);
|
|
||||||
free(internal);
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
device_set_driver_data(device, internal);
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t stop(Device* device) {
|
|
||||||
auto* internal = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
if (esp_lcd_panel_del(internal->panel_handle) != ESP_OK
|
|
||||||
|| esp_lcd_panel_io_del(internal->io_handle) != ESP_OK) {
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
heap_caps_free(internal->transfer_buffer);
|
|
||||||
vSemaphoreDelete(internal->draw_done);
|
|
||||||
free(internal);
|
|
||||||
device_set_driver_data(device, nullptr);
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t reset(Device* device) {
|
|
||||||
auto* data = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
return esp_lcd_panel_reset(data->panel_handle) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
static error_t init(Device* device) {
|
|
||||||
auto* data = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
return esp_lcd_panel_init(data->panel_handle) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
static error_t draw_bitmap(Device* device, int32_t xs, int32_t ys, int32_t xe, int32_t ye, const void* pixels) {
|
|
||||||
auto* data = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
const auto* config = GET_CONFIG(device);
|
|
||||||
const size_t row_bytes = static_cast<size_t>(xe - xs) * config->bits_per_pixel / 8;
|
|
||||||
if (row_bytes == 0 || row_bytes > data->transfer_buffer_size) {
|
|
||||||
return ERROR_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t rows_per_transfer = data->transfer_buffer_size / row_bytes;
|
|
||||||
const auto* source = static_cast<const uint8_t*>(pixels);
|
|
||||||
int32_t chunk_y = ys;
|
|
||||||
while (chunk_y < ye) {
|
|
||||||
const size_t remaining_rows = static_cast<size_t>(ye - chunk_y);
|
|
||||||
const size_t chunk_rows = remaining_rows < rows_per_transfer ? remaining_rows : rows_per_transfer;
|
|
||||||
const size_t chunk_bytes = chunk_rows * row_bytes;
|
|
||||||
memcpy(data->transfer_buffer, source, chunk_bytes);
|
|
||||||
|
|
||||||
xSemaphoreTake(data->draw_done, 0);
|
|
||||||
if (esp_lcd_panel_draw_bitmap(
|
|
||||||
data->panel_handle, xs, chunk_y, xe, chunk_y + static_cast<int32_t>(chunk_rows),
|
|
||||||
data->transfer_buffer) != ESP_OK) {
|
|
||||||
LOG_E(TAG, "Failed to queue color transfer at y=%ld", static_cast<long>(chunk_y));
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
if (xSemaphoreTake(data->draw_done, pdMS_TO_TICKS(1000)) != pdTRUE) {
|
|
||||||
LOG_E(TAG, "Timed out waiting for color transfer at y=%ld", static_cast<long>(chunk_y));
|
|
||||||
return ERROR_TIMEOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
source += chunk_bytes;
|
|
||||||
chunk_y += static_cast<int32_t>(chunk_rows);
|
|
||||||
}
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
static error_t mirror(Device* device, bool x, bool y) {
|
|
||||||
auto* data = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
return esp_lcd_panel_mirror(data->panel_handle, x, y) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
static bool get_mirror_x(Device* device) { return GET_CONFIG(device)->mirror_x; }
|
|
||||||
static bool get_mirror_y(Device* device) { return GET_CONFIG(device)->mirror_y; }
|
|
||||||
static error_t invert(Device* device, bool value) {
|
|
||||||
auto* data = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
return esp_lcd_panel_invert_color(data->panel_handle, value) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
static error_t on_off(Device* device, bool value) {
|
|
||||||
auto* data = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
return esp_lcd_panel_disp_on_off(data->panel_handle, value) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
static error_t sleep(Device* device, bool value) {
|
|
||||||
auto* data = static_cast<St77922Internal*>(device_get_driver_data(device));
|
|
||||||
return esp_lcd_panel_disp_sleep(data->panel_handle, value) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
static DisplayColorFormat color_format(Device*) { return DISPLAY_COLOR_FORMAT_RGB565_SWAPPED; }
|
|
||||||
static uint16_t resolution_x(Device* device) { return GET_CONFIG(device)->horizontal_resolution; }
|
|
||||||
static uint16_t resolution_y(Device* device) { return GET_CONFIG(device)->vertical_resolution; }
|
|
||||||
static void frame_buffer(Device*, uint8_t, void** output) { *output = nullptr; }
|
|
||||||
static uint8_t frame_buffer_count(Device*) { return 0; }
|
|
||||||
static error_t backlight(Device* device, Device** output) {
|
|
||||||
*output = GET_CONFIG(device)->backlight;
|
|
||||||
return *output == nullptr ? ERROR_NOT_SUPPORTED : ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const DisplayApi display_api = {
|
|
||||||
.capabilities = DISPLAY_CAPABILITY_CAP_MIRROR | DISPLAY_CAPABILITY_INVERT_COLOR |
|
|
||||||
DISPLAY_CAPABILITY_ON_OFF | DISPLAY_CAPABILITY_SLEEP | DISPLAY_CAPABILITY_BACKLIGHT |
|
|
||||||
DISPLAY_CAPABILITY_REQUIRES_FULL_FRAME,
|
|
||||||
.reset = reset,
|
|
||||||
.init = init,
|
|
||||||
.draw_bitmap = draw_bitmap,
|
|
||||||
.mirror = mirror,
|
|
||||||
.swap_xy = nullptr,
|
|
||||||
.get_swap_xy = nullptr,
|
|
||||||
.get_mirror_x = get_mirror_x,
|
|
||||||
.get_mirror_y = get_mirror_y,
|
|
||||||
.set_gap = nullptr,
|
|
||||||
.get_gap_x = nullptr,
|
|
||||||
.get_gap_y = nullptr,
|
|
||||||
.invert_color = invert,
|
|
||||||
.disp_on_off = on_off,
|
|
||||||
.disp_sleep = sleep,
|
|
||||||
.get_color_format = color_format,
|
|
||||||
.get_resolution_x = resolution_x,
|
|
||||||
.get_resolution_y = resolution_y,
|
|
||||||
.get_frame_buffer = frame_buffer,
|
|
||||||
.get_frame_buffer_count = frame_buffer_count,
|
|
||||||
.get_backlight = backlight,
|
|
||||||
.has_capability = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
Driver st77922_driver = {
|
|
||||||
.name = "st77922",
|
|
||||||
.compatible = (const char*[]) { "sitronix,st77922", nullptr },
|
|
||||||
.start_device = start,
|
|
||||||
.stop_device = stop,
|
|
||||||
.api = &display_api,
|
|
||||||
.device_type = &DISPLAY_TYPE,
|
|
||||||
.owner = &st77922_module,
|
|
||||||
.internal = nullptr
|
|
||||||
};
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
#include "st77922_init.h"
|
|
||||||
|
|
||||||
// Initialization sequence supplied with the LCDWIKI/Hosyond ES3C35P vendor ESP-IDF demo.
|
|
||||||
static const st77922_lcd_init_cmd_t init_commands[] = {
|
|
||||||
{0xF1, (uint8_t []){0x00}, 1, 0},
|
|
||||||
{0x60, (uint8_t []){0x00, 0x00, 0x00}, 3, 0},
|
|
||||||
{0x65, (uint8_t []){0x80}, 1, 0},
|
|
||||||
{0x79, (uint8_t []){0x06}, 1, 0},
|
|
||||||
{0x7B, (uint8_t []){0x00, 0x08, 0x08}, 3, 0},
|
|
||||||
{0x80, (uint8_t []){0x55, 0x62, 0x2F, 0x17, 0xF0, 0x52, 0x70, 0xD2, 0x52, 0x62, 0xEA}, 11, 0},
|
|
||||||
{0x81, (uint8_t []){0x26, 0x52, 0x72, 0x27}, 4, 0},
|
|
||||||
{0x84, (uint8_t []){0x92, 0x25}, 2, 0},
|
|
||||||
{0x87, (uint8_t []){0x10, 0x10, 0x58, 0x00, 0x02, 0x3A}, 6, 0},
|
|
||||||
{0x88, (uint8_t []){0x00, 0x00, 0x2C, 0x10, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x06}, 15, 0},
|
|
||||||
{0x89, (uint8_t []){0x00, 0x00, 0x00}, 3, 0},
|
|
||||||
{0x8A, (uint8_t []){0x13, 0x00, 0x2C, 0x00, 0x00, 0x2C, 0x10, 0x10, 0x00, 0x3E, 0x19}, 11, 0},
|
|
||||||
{0x8B, (uint8_t []){0x15, 0xB1, 0xB1, 0x44, 0x96, 0x2C, 0x10, 0x97, 0x8E}, 9, 0},
|
|
||||||
{0x8C, (uint8_t []){0x1D, 0xB1, 0xB1, 0x44, 0x96, 0x2C, 0x10, 0x50, 0x0F, 0x01, 0xC5, 0x12, 0x09}, 13, 0},
|
|
||||||
{0x8D, (uint8_t []){0x0C}, 1, 0},
|
|
||||||
{0x8E, (uint8_t []){0x33, 0x01, 0x0C, 0x13, 0x01, 0x01}, 6, 0},
|
|
||||||
{0xB3, (uint8_t []){0x00, 0x30}, 2, 0},
|
|
||||||
{0xF1, (uint8_t []){0x00}, 1, 0},
|
|
||||||
{0x71, (uint8_t []){0xD0}, 1, 0},
|
|
||||||
{0x66, (uint8_t []){0x02, 0x3F}, 2, 0},
|
|
||||||
{0xBE, (uint8_t []){0x26, 0x00, 0x9D}, 3, 0},
|
|
||||||
{0x70, (uint8_t []){0x01, 0xA0, 0x11, 0x40, 0xE0, 0x00, 0x11, 0x69, 0x11, 0x00, 0x00, 0x1A}, 12, 0},
|
|
||||||
{0x90, (uint8_t []){0x04, 0x04, 0x55, 0x74, 0x00, 0x40, 0x43, 0x27, 0x27}, 9, 0},
|
|
||||||
{0x91, (uint8_t []){0x04, 0x04, 0x55, 0x75, 0x00, 0x40, 0x42, 0x27, 0x27}, 9, 0},
|
|
||||||
{0x92, (uint8_t []){0x04, 0x44, 0x55, 0xC0, 0x06, 0x00, 0x07, 0x05, 0x90, 0x27}, 10, 0},
|
|
||||||
{0x93, (uint8_t []){0x04, 0x43, 0x11, 0x00, 0x00, 0x00, 0x00, 0x05, 0x90, 0x27}, 10, 0},
|
|
||||||
{0x94, (uint8_t []){0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 6, 0},
|
|
||||||
{0x95, (uint8_t []){0x96, 0x16, 0x00, 0x00, 0xFF}, 5, 0},
|
|
||||||
{0x96, (uint8_t []){0x44, 0x53, 0x03, 0x12, 0x23, 0x24, 0x06, 0x05, 0x94, 0x27, 0x00, 0x44}, 12, 0},
|
|
||||||
{0x97, (uint8_t []){0x44, 0x53, 0x47, 0x56, 0x20, 0x20, 0x02, 0x01, 0x94, 0x27, 0x00, 0x44}, 12, 0},
|
|
||||||
{0xBA, (uint8_t []){0x55, 0x94, 0x2D, 0x94, 0x27}, 5, 0},
|
|
||||||
{0x9A, (uint8_t []){0x40, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00}, 7, 0},
|
|
||||||
{0x9B, (uint8_t []){0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00}, 7, 0},
|
|
||||||
{0x9C, (uint8_t []){0x5C, 0x12, 0x00, 0x00, 0x10, 0x12, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00}, 13, 0},
|
|
||||||
{0x9D, (uint8_t []){0x8A, 0x51, 0x00, 0x00, 0x00, 0x80, 0x1E, 0x01}, 8, 0},
|
|
||||||
{0x9E, (uint8_t []){0x51, 0x00, 0x00, 0x00, 0x80, 0x1E, 0x01}, 7, 0},
|
|
||||||
{0xB4, (uint8_t []){0x1D, 0x1C, 0x1E, 0x0B, 0x14, 0x02, 0x13, 0x09, 0x1E, 0x00, 0x1E, 0x10}, 12, 0},
|
|
||||||
{0xB5, (uint8_t []){0x1D, 0x1C, 0x1E, 0x0A, 0x15, 0x03, 0x11, 0x08, 0x1E, 0x01, 0x1E, 0x12}, 12, 0},
|
|
||||||
{0xB6, (uint8_t []){0x77, 0x77, 0x00, 0x0A, 0xFF, 0x0A, 0xFF}, 7, 0},
|
|
||||||
{0x86, (uint8_t []){0xCD, 0x04, 0xB1, 0x02, 0x58, 0x12, 0x58, 0x0C, 0x13, 0x01, 0xA5, 0x00, 0xA5, 0xA5}, 14, 0},
|
|
||||||
{0xB7, (uint8_t []){0x07, 0x0A, 0x0E, 0x06, 0x05, 0x03, 0x2B, 0x03, 0x03, 0x42, 0x07, 0x10, 0x10, 0x2E, 0x3F, 0x0D}, 16, 0},
|
|
||||||
{0xB8, (uint8_t []){0x07, 0x0A, 0x0D, 0x05, 0x05, 0x02, 0x2B, 0x02, 0x03, 0x42, 0x06, 0x10, 0x0F, 0x2E, 0x3F, 0x0D}, 16, 0},
|
|
||||||
{0xB9, (uint8_t []){0x23, 0x23}, 2, 0},
|
|
||||||
{0xBF, (uint8_t []){0x10, 0x14, 0x14, 0x0B, 0x0B, 0x0B}, 6, 0},
|
|
||||||
{0xF2, (uint8_t []){0x00}, 1, 0},
|
|
||||||
{0x73, (uint8_t []){0x04, 0xDA, 0x12, 0x54, 0x47}, 5, 0},
|
|
||||||
{0x77, (uint8_t []){0x6B, 0x5B, 0xFD, 0xC3, 0xC5}, 5, 0},
|
|
||||||
{0x7A, (uint8_t []){0x15, 0x27}, 2, 0},
|
|
||||||
{0x7B, (uint8_t []){0x04, 0x57}, 2, 0},
|
|
||||||
{0x7E, (uint8_t []){0x01, 0x0E}, 2, 0},
|
|
||||||
{0xBF, (uint8_t []){0x36}, 1, 0},
|
|
||||||
{0xE3, (uint8_t []){0x40, 0x40}, 2, 0},
|
|
||||||
{0xF0, (uint8_t []){0x00}, 1, 0},
|
|
||||||
{0xD0, (uint8_t []){0x00}, 1, 0},
|
|
||||||
{0x2A, (uint8_t []){0x00, 0x00, 0x01, 0x3F}, 4, 0},
|
|
||||||
{0x2B, (uint8_t []){0x00, 0x00, 0x01, 0xDF}, 4, 0},
|
|
||||||
{0x21, NULL, 0, 0},
|
|
||||||
{0x11, NULL, 0, 120},
|
|
||||||
{0x29, NULL, 0, 0},
|
|
||||||
{0x2C, NULL, 0, 0},
|
|
||||||
{0x3A, (uint8_t []){0x01}, 1, 0},
|
|
||||||
{0x36, (uint8_t []){0x00}, 1, 0},
|
|
||||||
{0x35, (uint8_t []){0x01}, 1, 20},
|
|
||||||
};
|
|
||||||
|
|
||||||
const st77922_lcd_init_cmd_t* st77922_board_init_commands(size_t* count) {
|
|
||||||
*count = sizeof(init_commands) / sizeof(init_commands[0]);
|
|
||||||
return init_commands;
|
|
||||||
}
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
#include <drivers/st77922_touch.h>
|
|
||||||
#include <st77922_module.h>
|
|
||||||
|
|
||||||
#include <tactility/check.h>
|
|
||||||
#include <tactility/device.h>
|
|
||||||
#include <tactility/driver.h>
|
|
||||||
#include <tactility/drivers/gpio_controller.h>
|
|
||||||
#include <tactility/drivers/i2c_controller.h>
|
|
||||||
#include <tactility/drivers/pointer.h>
|
|
||||||
#include <tactility/log.h>
|
|
||||||
|
|
||||||
#include <freertos/task.h>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#define TAG "ST77922 touch"
|
|
||||||
#define GET_CONFIG(device) (static_cast<const St77922TouchConfig*>((device)->config))
|
|
||||||
|
|
||||||
static constexpr uint16_t REG_MAX_TOUCHES = 0x0009;
|
|
||||||
static constexpr uint16_t REG_TOUCH_INFO = 0x0010;
|
|
||||||
static constexpr uint16_t REG_TOUCH_POINT0 = 0x0014;
|
|
||||||
static constexpr uint8_t MAX_POINTS = 10;
|
|
||||||
static constexpr TickType_t TIMEOUT = pdMS_TO_TICKS(1000);
|
|
||||||
|
|
||||||
struct TouchPoint {
|
|
||||||
uint16_t x;
|
|
||||||
uint16_t y;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct St77922TouchInternal {
|
|
||||||
Device* i2c;
|
|
||||||
GpioDescriptor* reset;
|
|
||||||
uint8_t supported_points;
|
|
||||||
uint8_t point_count;
|
|
||||||
TouchPoint points[MAX_POINTS];
|
|
||||||
bool swap_xy;
|
|
||||||
bool mirror_x;
|
|
||||||
bool mirror_y;
|
|
||||||
};
|
|
||||||
|
|
||||||
static error_t read_register(Device* i2c, uint16_t reg, uint8_t* data, size_t size, TickType_t timeout) {
|
|
||||||
const uint8_t address[] = {
|
|
||||||
static_cast<uint8_t>(reg >> 8),
|
|
||||||
static_cast<uint8_t>(reg & 0xFF),
|
|
||||||
};
|
|
||||||
return i2c_controller_write_read(i2c, 0x55, address, sizeof(address), data, size, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t start(Device* device) {
|
|
||||||
auto* parent = device_get_parent(device);
|
|
||||||
check(device_get_type(parent) == &I2C_CONTROLLER_TYPE);
|
|
||||||
const auto* config = GET_CONFIG(device);
|
|
||||||
|
|
||||||
auto* internal = static_cast<St77922TouchInternal*>(calloc(1, sizeof(St77922TouchInternal)));
|
|
||||||
if (internal == nullptr) {
|
|
||||||
return ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
internal->i2c = parent;
|
|
||||||
internal->supported_points = 1;
|
|
||||||
internal->swap_xy = config->swap_xy;
|
|
||||||
internal->mirror_x = config->mirror_x;
|
|
||||||
internal->mirror_y = config->mirror_y;
|
|
||||||
|
|
||||||
if (config->pin_reset.gpio_controller != nullptr) {
|
|
||||||
internal->reset = gpio_descriptor_acquire(config->pin_reset.gpio_controller,
|
|
||||||
config->pin_reset.pin, GPIO_FLAG_DIRECTION_OUTPUT | GPIO_FLAG_ACTIVE_LOW, GPIO_OWNER_GPIO);
|
|
||||||
if (internal->reset == nullptr) {
|
|
||||||
free(internal);
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
if (gpio_descriptor_set_level(internal->reset, true) != ERROR_NONE) {
|
|
||||||
gpio_descriptor_release(internal->reset);
|
|
||||||
free(internal);
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
|
||||||
gpio_descriptor_set_level(internal->reset, false);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t supported = 0;
|
|
||||||
if (read_register(parent, REG_MAX_TOUCHES, &supported, 1, TIMEOUT) == ERROR_NONE
|
|
||||||
&& supported > 0 && supported <= MAX_POINTS) {
|
|
||||||
internal->supported_points = supported;
|
|
||||||
}
|
|
||||||
LOG_I(TAG, "Controller reports %u touch points", internal->supported_points);
|
|
||||||
device_set_driver_data(device, internal);
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t stop(Device* device) {
|
|
||||||
auto* internal = static_cast<St77922TouchInternal*>(device_get_driver_data(device));
|
|
||||||
if (internal->reset != nullptr) {
|
|
||||||
gpio_descriptor_release(internal->reset);
|
|
||||||
}
|
|
||||||
free(internal);
|
|
||||||
device_set_driver_data(device, nullptr);
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t enter_sleep(Device*) { return ERROR_NOT_SUPPORTED; }
|
|
||||||
static error_t exit_sleep(Device*) { return ERROR_NOT_SUPPORTED; }
|
|
||||||
|
|
||||||
static error_t read_data(Device* device, TickType_t timeout) {
|
|
||||||
auto* internal = static_cast<St77922TouchInternal*>(device_get_driver_data(device));
|
|
||||||
uint8_t touch_info = 0;
|
|
||||||
if (read_register(internal->i2c, REG_TOUCH_INFO, &touch_info, 1, timeout) != ERROR_NONE) {
|
|
||||||
internal->point_count = 0;
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
if ((touch_info & 0x08) == 0) {
|
|
||||||
internal->point_count = 0;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t data[7 * MAX_POINTS] = {};
|
|
||||||
const size_t read_size = 7 * internal->supported_points;
|
|
||||||
if (read_register(internal->i2c, REG_TOUCH_POINT0, data, read_size, timeout) != ERROR_NONE) {
|
|
||||||
internal->point_count = 0;
|
|
||||||
return ERROR_RESOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal->point_count = 0;
|
|
||||||
for (uint8_t index = 0; index < internal->supported_points; index++) {
|
|
||||||
const uint8_t offset = index * 7;
|
|
||||||
if ((data[offset] & 0x80) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
internal->points[internal->point_count++] = {
|
|
||||||
.x = static_cast<uint16_t>(((data[offset] & 0x3F) << 8) | data[offset + 1]),
|
|
||||||
.y = static_cast<uint16_t>(((data[offset + 2] & 0x3F) << 8) | data[offset + 3]),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool get_touched_points(Device* device, uint16_t* x, uint16_t* y, uint16_t* strength,
|
|
||||||
uint8_t* count, uint8_t maximum) {
|
|
||||||
auto* internal = static_cast<St77922TouchInternal*>(device_get_driver_data(device));
|
|
||||||
const auto* config = GET_CONFIG(device);
|
|
||||||
*count = std::min(internal->point_count, maximum);
|
|
||||||
for (uint8_t index = 0; index < *count; index++) {
|
|
||||||
uint16_t point_x = internal->points[index].x;
|
|
||||||
uint16_t point_y = internal->points[index].y;
|
|
||||||
if (internal->swap_xy) {
|
|
||||||
std::swap(point_x, point_y);
|
|
||||||
}
|
|
||||||
const uint16_t max_x = internal->swap_xy ? config->y_max : config->x_max;
|
|
||||||
const uint16_t max_y = internal->swap_xy ? config->x_max : config->y_max;
|
|
||||||
x[index] = internal->mirror_x ? max_x - point_x : point_x;
|
|
||||||
y[index] = internal->mirror_y ? max_y - point_y : point_y;
|
|
||||||
if (strength != nullptr) {
|
|
||||||
strength[index] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return *count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t set_swap_xy(Device* device, bool value) {
|
|
||||||
static_cast<St77922TouchInternal*>(device_get_driver_data(device))->swap_xy = value;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
static error_t get_swap_xy(Device* device, bool* value) {
|
|
||||||
*value = static_cast<St77922TouchInternal*>(device_get_driver_data(device))->swap_xy;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
static error_t set_mirror_x(Device* device, bool value) {
|
|
||||||
static_cast<St77922TouchInternal*>(device_get_driver_data(device))->mirror_x = value;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
static error_t get_mirror_x(Device* device, bool* value) {
|
|
||||||
*value = static_cast<St77922TouchInternal*>(device_get_driver_data(device))->mirror_x;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
static error_t set_mirror_y(Device* device, bool value) {
|
|
||||||
static_cast<St77922TouchInternal*>(device_get_driver_data(device))->mirror_y = value;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
static error_t get_mirror_y(Device* device, bool* value) {
|
|
||||||
*value = static_cast<St77922TouchInternal*>(device_get_driver_data(device))->mirror_y;
|
|
||||||
return ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const PointerApi pointer_api = {
|
|
||||||
.enter_sleep = enter_sleep,
|
|
||||||
.exit_sleep = exit_sleep,
|
|
||||||
.read_data = read_data,
|
|
||||||
.get_touched_points = get_touched_points,
|
|
||||||
.set_swap_xy = set_swap_xy,
|
|
||||||
.get_swap_xy = get_swap_xy,
|
|
||||||
.set_mirror_x = set_mirror_x,
|
|
||||||
.get_mirror_x = get_mirror_x,
|
|
||||||
.set_mirror_y = set_mirror_y,
|
|
||||||
.get_mirror_y = get_mirror_y,
|
|
||||||
};
|
|
||||||
|
|
||||||
Driver st77922_touch_driver = {
|
|
||||||
.name = "st77922-touch",
|
|
||||||
.compatible = (const char*[]) { "sitronix,st77922-touch", nullptr },
|
|
||||||
.start_device = start,
|
|
||||||
.stop_device = stop,
|
|
||||||
.api = &pointer_api,
|
|
||||||
.device_type = &POINTER_TYPE,
|
|
||||||
.owner = &st77922_module,
|
|
||||||
.internal = nullptr
|
|
||||||
};
|
|
||||||
@@ -42,10 +42,6 @@ dependencies:
|
|||||||
version: "1.3.4"
|
version: "1.3.4"
|
||||||
rules:
|
rules:
|
||||||
- if: "target in [esp32, esp32s3]"
|
- if: "target in [esp32, esp32s3]"
|
||||||
espressif/esp_lcd_st77922:
|
|
||||||
version: "1.0.3"
|
|
||||||
rules:
|
|
||||||
- if: "target in [esp32s3]"
|
|
||||||
espressif/esp_lcd_gc9a01: "2.0.3"
|
espressif/esp_lcd_gc9a01: "2.0.3"
|
||||||
espressif/esp_lcd_jd9165:
|
espressif/esp_lcd_jd9165:
|
||||||
version: "1.0.3"
|
version: "1.0.3"
|
||||||
@@ -89,3 +85,4 @@ dependencies:
|
|||||||
rules:
|
rules:
|
||||||
- if: "target in [esp32s3, esp32p4]"
|
- if: "target in [esp32s3, esp32p4]"
|
||||||
idf: '5.5.2'
|
idf: '5.5.2'
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,6 @@ enum LvglFontSize {
|
|||||||
FONT_SIZE_LARGE,
|
FONT_SIZE_LARGE,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum LvglFontScale {
|
|
||||||
FONT_SCALE_SMALL,
|
|
||||||
FONT_SCALE_DEFAULT,
|
|
||||||
FONT_SCALE_LARGE,
|
|
||||||
};
|
|
||||||
|
|
||||||
void lvgl_set_text_font_scale(enum LvglFontScale font_scale);
|
|
||||||
enum LvglFontScale lvgl_get_text_font_scale(void);
|
|
||||||
|
|
||||||
const lv_font_t* lvgl_get_shared_icon_font();
|
const lv_font_t* lvgl_get_shared_icon_font();
|
||||||
uint32_t lvgl_get_shared_icon_font_height();
|
uint32_t lvgl_get_shared_icon_font_height();
|
||||||
|
|
||||||
|
|||||||
@@ -13,30 +13,8 @@ extern const lv_font_t TT_LVGL_LAUNCHER_FONT_ICON_SYMBOL;
|
|||||||
extern const lv_font_t TT_LVGL_STATUSBAR_FONT_ICON_SYMBOL;
|
extern const lv_font_t TT_LVGL_STATUSBAR_FONT_ICON_SYMBOL;
|
||||||
extern const lv_font_t TT_LVGL_SHARED_FONT_ICON_SYMBOL;
|
extern const lv_font_t TT_LVGL_SHARED_FONT_ICON_SYMBOL;
|
||||||
|
|
||||||
static enum LvglFontScale text_font_scale = FONT_SCALE_DEFAULT;
|
|
||||||
|
|
||||||
void lvgl_set_text_font_scale(enum LvglFontScale font_scale) {
|
|
||||||
check(font_scale >= FONT_SCALE_SMALL && font_scale <= FONT_SCALE_LARGE);
|
|
||||||
text_font_scale = font_scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum LvglFontScale lvgl_get_text_font_scale(void) {
|
|
||||||
return text_font_scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum LvglFontSize resolve_text_font_size(enum LvglFontSize font_size) {
|
|
||||||
int resolved = (int)font_size + (int)text_font_scale - (int)FONT_SCALE_DEFAULT;
|
|
||||||
if (resolved < FONT_SIZE_SMALL) {
|
|
||||||
return FONT_SIZE_SMALL;
|
|
||||||
}
|
|
||||||
if (resolved > FONT_SIZE_LARGE) {
|
|
||||||
return FONT_SIZE_LARGE;
|
|
||||||
}
|
|
||||||
return (enum LvglFontSize)resolved;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t lvgl_get_text_font_height(enum LvglFontSize font_size) {
|
uint32_t lvgl_get_text_font_height(enum LvglFontSize font_size) {
|
||||||
switch (resolve_text_font_size(font_size)) {
|
switch (font_size) {
|
||||||
case FONT_SIZE_SMALL: return TT_LVGL_TEXT_FONT_SMALL_SIZE;
|
case FONT_SIZE_SMALL: return TT_LVGL_TEXT_FONT_SMALL_SIZE;
|
||||||
case FONT_SIZE_DEFAULT: return TT_LVGL_TEXT_FONT_DEFAULT_SIZE;
|
case FONT_SIZE_DEFAULT: return TT_LVGL_TEXT_FONT_DEFAULT_SIZE;
|
||||||
case FONT_SIZE_LARGE: return TT_LVGL_TEXT_FONT_LARGE_SIZE;
|
case FONT_SIZE_LARGE: return TT_LVGL_TEXT_FONT_LARGE_SIZE;
|
||||||
@@ -44,7 +22,7 @@ uint32_t lvgl_get_text_font_height(enum LvglFontSize font_size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const lv_font_t* lvgl_get_text_font(enum LvglFontSize font_size) {
|
const lv_font_t* lvgl_get_text_font(enum LvglFontSize font_size) {
|
||||||
switch (resolve_text_font_size(font_size)) {
|
switch (font_size) {
|
||||||
case FONT_SIZE_SMALL: return &TT_LVGL_TEXT_FONT_SMALL_SYMBOL;
|
case FONT_SIZE_SMALL: return &TT_LVGL_TEXT_FONT_SMALL_SYMBOL;
|
||||||
case FONT_SIZE_DEFAULT: return &TT_LVGL_TEXT_FONT_DEFAULT_SYMBOL;
|
case FONT_SIZE_DEFAULT: return &TT_LVGL_TEXT_FONT_DEFAULT_SYMBOL;
|
||||||
case FONT_SIZE_LARGE: return &TT_LVGL_TEXT_FONT_LARGE_SYMBOL;
|
case FONT_SIZE_LARGE: return &TT_LVGL_TEXT_FONT_LARGE_SYMBOL;
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
|
|||||||
DEFINE_MODULE_SYMBOL(lvgl_is_running),
|
DEFINE_MODULE_SYMBOL(lvgl_is_running),
|
||||||
DEFINE_MODULE_SYMBOL(lvgl_get_ui_density),
|
DEFINE_MODULE_SYMBOL(lvgl_get_ui_density),
|
||||||
// lvgl_fonts
|
// lvgl_fonts
|
||||||
DEFINE_MODULE_SYMBOL(lvgl_set_text_font_scale),
|
|
||||||
DEFINE_MODULE_SYMBOL(lvgl_get_text_font_scale),
|
|
||||||
DEFINE_MODULE_SYMBOL(lvgl_get_shared_icon_font),
|
DEFINE_MODULE_SYMBOL(lvgl_get_shared_icon_font),
|
||||||
DEFINE_MODULE_SYMBOL(lvgl_get_shared_icon_font_height),
|
DEFINE_MODULE_SYMBOL(lvgl_get_shared_icon_font_height),
|
||||||
DEFINE_MODULE_SYMBOL(lvgl_get_text_font),
|
DEFINE_MODULE_SYMBOL(lvgl_get_text_font),
|
||||||
@@ -437,12 +435,6 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
|
|||||||
// lv_image
|
// lv_image
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_create),
|
DEFINE_MODULE_SYMBOL(lv_image_create),
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_set_src),
|
DEFINE_MODULE_SYMBOL(lv_image_set_src),
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_set_scale),
|
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_set_scale_x),
|
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_set_scale_y),
|
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_get_scale),
|
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_get_scale_x),
|
|
||||||
DEFINE_MODULE_SYMBOL(lv_image_get_scale_y),
|
|
||||||
// lv_anim
|
// lv_anim
|
||||||
DEFINE_MODULE_SYMBOL(lv_anim_init),
|
DEFINE_MODULE_SYMBOL(lv_anim_init),
|
||||||
DEFINE_MODULE_SYMBOL(lv_anim_set_duration),
|
DEFINE_MODULE_SYMBOL(lv_anim_set_duration),
|
||||||
@@ -481,4 +473,4 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
|
|||||||
DEFINE_MODULE_SYMBOL(lv_area_get_width),
|
DEFINE_MODULE_SYMBOL(lv_area_get_width),
|
||||||
DEFINE_MODULE_SYMBOL(lv_area_get_height),
|
DEFINE_MODULE_SYMBOL(lv_area_get_height),
|
||||||
MODULE_SYMBOL_TERMINATOR
|
MODULE_SYMBOL_TERMINATOR
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace tt::settings::display {
|
|
||||||
enum class FontSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace tt::lvgl {
|
namespace tt::lvgl {
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
@@ -16,9 +12,6 @@ static constexpr auto* PATH_PREFIX = "A:/";
|
|||||||
|
|
||||||
bool isStarted();
|
bool isStarted();
|
||||||
|
|
||||||
/** Applies the selected semantic text size to the LVGL theme and future widgets. */
|
|
||||||
void applyFontSize(settings::display::FontSize fontSize);
|
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
|
|||||||
@@ -18,26 +18,16 @@ enum class ScreensaverType {
|
|||||||
Mystify,
|
Mystify,
|
||||||
MatrixRain,
|
MatrixRain,
|
||||||
StackChan,
|
StackChan,
|
||||||
McpScreen,
|
|
||||||
Count // Sentinel for bounds checking - must be last
|
Count // Sentinel for bounds checking - must be last
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class FontSize {
|
|
||||||
Small,
|
|
||||||
Default,
|
|
||||||
Large,
|
|
||||||
Count
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DisplaySettings {
|
struct DisplaySettings {
|
||||||
Orientation orientation;
|
Orientation orientation;
|
||||||
FontSize fontSize = FontSize::Default;
|
|
||||||
uint8_t gammaCurve;
|
uint8_t gammaCurve;
|
||||||
uint8_t backlightDuty;
|
uint8_t backlightDuty;
|
||||||
bool backlightTimeoutEnabled;
|
bool backlightTimeoutEnabled;
|
||||||
uint32_t backlightTimeoutMs; // 0 = Never
|
uint32_t backlightTimeoutMs; // 0 = Never
|
||||||
ScreensaverType screensaverType = ScreensaverType::BouncingBalls;
|
ScreensaverType screensaverType = ScreensaverType::BouncingBalls;
|
||||||
bool disableScreensaverWhenCharging = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Compares default settings with the function parameter to return the difference */
|
/** Compares default settings with the function parameter to return the difference */
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
#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
|
|
||||||
@@ -14,9 +14,6 @@ bool isValidAppVersionName(const std::string& version);
|
|||||||
bool isValidAppVersionCode(const std::string& version);
|
bool isValidAppVersionCode(const std::string& version);
|
||||||
bool isValidName(const std::string& name);
|
bool isValidName(const std::string& name);
|
||||||
|
|
||||||
/** Parses a comma-separated flags string (e.g. "HideStatusBar,Hidden") into appFlags bitmask. */
|
|
||||||
uint16_t parseAppFlagsString(const std::string& raw);
|
|
||||||
|
|
||||||
/** Parses a V1 (sectioned INI, e.g. "[app]versionName=...") manifest map. */
|
/** Parses a V1 (sectioned INI, e.g. "[app]versionName=...") manifest map. */
|
||||||
bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest& manifest);
|
bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest& manifest);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
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
|
|
||||||
|
namespace tt::app::files {
|
||||||
|
|
||||||
|
bool isSupportedAppFile(const std::string& filename);
|
||||||
|
bool isSupportedImageFile(const std::string& filename);
|
||||||
|
bool isSupportedTextFile(const std::string& filename);
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifdef ESP_PLATFORM
|
|
||||||
|
|
||||||
#include <lvgl.h>
|
|
||||||
#include <mutex>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <tactility/device.h>
|
|
||||||
#include <tactility/drivers/audio_stream.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;
|
|
||||||
Device* audioStreamDevice = nullptr;
|
|
||||||
AudioStreamHandle audioHandle = 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
@@ -37,7 +37,6 @@ class DisplayIdleService final : public Service {
|
|||||||
bool backlightOff = false;
|
bool backlightOff = false;
|
||||||
|
|
||||||
static void stopScreensaverCb(lv_event_t* e);
|
static void stopScreensaverCb(lv_event_t* e);
|
||||||
void stopScreensaverLocked();
|
|
||||||
|
|
||||||
/** @pre Caller must hold LVGL lock */
|
/** @pre Caller must hold LVGL lock */
|
||||||
void activateScreensaver();
|
void activateScreensaver();
|
||||||
@@ -64,7 +63,6 @@ public:
|
|||||||
* arbitrary threads while the timer is running.
|
* arbitrary threads while the timer is running.
|
||||||
*/
|
*/
|
||||||
void stopScreensaver();
|
void stopScreensaver();
|
||||||
void startMcpScreensaver();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the screensaver is currently active.
|
* Check if the screensaver is currently active.
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ private:
|
|||||||
static esp_err_t handleApiAppsInstall(httpd_req_t* request);
|
static esp_err_t handleApiAppsInstall(httpd_req_t* request);
|
||||||
static esp_err_t handleApiWifi(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 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
|
// Dynamic asset serving
|
||||||
static esp_err_t handleAssets(httpd_req_t* request);
|
static esp_err_t handleAssets(httpd_req_t* request);
|
||||||
|
|||||||
@@ -151,8 +151,6 @@ namespace app {
|
|||||||
namespace apwebserver { extern const AppManifest manifest; }
|
namespace apwebserver { extern const AppManifest manifest; }
|
||||||
namespace crashdiagnostics { extern const AppManifest manifest; }
|
namespace crashdiagnostics { extern const AppManifest manifest; }
|
||||||
namespace webserversettings { extern const AppManifest manifest; }
|
namespace webserversettings { extern const AppManifest manifest; }
|
||||||
namespace mcpsettings { extern const AppManifest manifest; }
|
|
||||||
namespace mcpoverride { extern const AppManifest manifest; }
|
|
||||||
#if CONFIG_TT_TDECK_WORKAROUND == 1
|
#if CONFIG_TT_TDECK_WORKAROUND == 1
|
||||||
namespace keyboardsettings { extern const AppManifest manifest; } // T-Deck only for now
|
namespace keyboardsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||||
namespace trackballsettings { extern const AppManifest manifest; } // T-Deck only for now
|
namespace trackballsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||||
@@ -215,8 +213,6 @@ static void registerInternalApps() {
|
|||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
addAppManifest(app::apwebserver::manifest);
|
addAppManifest(app::apwebserver::manifest);
|
||||||
addAppManifest(app::webserversettings::manifest);
|
addAppManifest(app::webserversettings::manifest);
|
||||||
addAppManifest(app::mcpsettings::manifest);
|
|
||||||
// mcpoverride internal only via McpScreensaver, not shown in launcher
|
|
||||||
addAppManifest(app::crashdiagnostics::manifest);
|
addAppManifest(app::crashdiagnostics::manifest);
|
||||||
addAppManifest(app::development::manifest);
|
addAppManifest(app::development::manifest);
|
||||||
#if defined(CONFIG_TT_TDECK_WORKAROUND)
|
#if defined(CONFIG_TT_TDECK_WORKAROUND)
|
||||||
|
|||||||
@@ -56,34 +56,6 @@ bool isValidName(const std::string& name) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t parseAppFlagsString(const std::string& raw) {
|
|
||||||
uint16_t flags = AppManifest::Flags::None;
|
|
||||||
if (raw.empty()) {
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto parts = string::split(raw, ",");
|
|
||||||
for (auto& part : parts) {
|
|
||||||
std::string trimmed = string::trim(part, " \t\r\n");
|
|
||||||
if (trimmed.empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::string lower = string::lowercase(trimmed);
|
|
||||||
|
|
||||||
if (lower == "hidestatusbar" || lower == "hide_statusbar" || lower == "hide-statusbar" || lower == "hide_status_bar") {
|
|
||||||
flags |= AppManifest::Flags::HideStatusBar;
|
|
||||||
} else if (lower == "hidden") {
|
|
||||||
flags |= AppManifest::Flags::Hidden;
|
|
||||||
} else if (lower == "none" || lower == "0" || lower == "") {
|
|
||||||
// keep as none, no additional flag
|
|
||||||
} else {
|
|
||||||
LOG_W(TAG, "Unknown app flag \"%s\" - ignoring", trimmed.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The V1 format's first line is always the literal "[manifest]" section header; V2 files are flat from the first line onward. */
|
/** The V1 format's first line is always the literal "[manifest]" section header; V2 files are flat from the first line onward. */
|
||||||
static bool detectIsV1Format(const std::string& filePath) {
|
static bool detectIsV1Format(const std::string& filePath) {
|
||||||
std::string first_line;
|
std::string first_line;
|
||||||
|
|||||||
@@ -71,12 +71,6 @@ bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional: [app]flags - e.g. "HideStatusBar" or "HideStatusBar,Hidden"
|
|
||||||
auto flags_it = map.find("[app]flags");
|
|
||||||
if (flags_it != map.end()) {
|
|
||||||
manifest.appFlags = parseAppFlagsString(flags_it->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,12 +71,6 @@ bool parseManifestV2(const std::map<std::string, std::string>& map, AppManifest&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional: app.flags - e.g. "HideStatusBar" or "HideStatusBar,Hidden"
|
|
||||||
auto flags_it = map.find("app.flags");
|
|
||||||
if (flags_it != map.end()) {
|
|
||||||
manifest.appFlags = parseAppFlagsString(flags_it->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <Tactility/app/App.h>
|
#include <Tactility/app/App.h>
|
||||||
#include <Tactility/hal/display/DisplayDevice.h>
|
#include <Tactility/hal/display/DisplayDevice.h>
|
||||||
#include <Tactility/lvgl/Lvgl.h>
|
|
||||||
#include <Tactility/lvgl/Toolbar.h>
|
#include <Tactility/lvgl/Toolbar.h>
|
||||||
#include <Tactility/settings/DisplaySettings.h>
|
#include <Tactility/settings/DisplaySettings.h>
|
||||||
|
|
||||||
@@ -31,8 +30,6 @@ class HalDisplayApp final : public App {
|
|||||||
lv_obj_t* timeoutSwitch = nullptr;
|
lv_obj_t* timeoutSwitch = nullptr;
|
||||||
lv_obj_t* timeoutDropdown = nullptr;
|
lv_obj_t* timeoutDropdown = nullptr;
|
||||||
lv_obj_t* screensaverDropdown = nullptr;
|
lv_obj_t* screensaverDropdown = nullptr;
|
||||||
lv_obj_t* disableWhenChargingWrapper = nullptr;
|
|
||||||
lv_obj_t* disableWhenChargingSwitch = nullptr;
|
|
||||||
|
|
||||||
static void onBacklightSliderEvent(lv_event_t* event) {
|
static void onBacklightSliderEvent(lv_event_t* event) {
|
||||||
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||||
@@ -75,29 +72,6 @@ class HalDisplayApp final : public App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onFontSizeChanged(lv_event_t* event) {
|
|
||||||
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
|
|
||||||
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
|
||||||
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
|
|
||||||
if (selected_index >= static_cast<uint32_t>(settings::display::FontSize::Count)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto selected_size = static_cast<settings::display::FontSize>(selected_index);
|
|
||||||
if (selected_size != app->displaySettings.fontSize) {
|
|
||||||
app->displaySettings.fontSize = selected_size;
|
|
||||||
app->displaySettingsUpdated = true;
|
|
||||||
lvgl::applyFontSize(selected_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onDisableWhenChargingChanged(lv_event_t* event) {
|
|
||||||
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
|
|
||||||
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
|
||||||
bool enabled = lv_obj_has_state(sw, LV_STATE_CHECKED);
|
|
||||||
app->displaySettings.disableScreensaverWhenCharging = enabled;
|
|
||||||
app->displaySettingsUpdated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onTimeoutSwitch(lv_event_t* event) {
|
static void onTimeoutSwitch(lv_event_t* event) {
|
||||||
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
|
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
|
||||||
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||||
@@ -110,17 +84,11 @@ class HalDisplayApp final : public App {
|
|||||||
if (app->screensaverDropdown) {
|
if (app->screensaverDropdown) {
|
||||||
lv_obj_clear_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
lv_obj_clear_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
if (app->disableWhenChargingWrapper) {
|
|
||||||
lv_obj_clear_state(app->disableWhenChargingWrapper, LV_STATE_DISABLED);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
lv_obj_add_state(app->timeoutDropdown, LV_STATE_DISABLED);
|
lv_obj_add_state(app->timeoutDropdown, LV_STATE_DISABLED);
|
||||||
if (app->screensaverDropdown) {
|
if (app->screensaverDropdown) {
|
||||||
lv_obj_add_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
lv_obj_add_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
if (app->disableWhenChargingWrapper) {
|
|
||||||
lv_obj_add_state(app->disableWhenChargingWrapper, LV_STATE_DISABLED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,23 +208,6 @@ public:
|
|||||||
// Set the dropdown to match current orientation enum
|
// Set the dropdown to match current orientation enum
|
||||||
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(displaySettings.orientation));
|
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(displaySettings.orientation));
|
||||||
|
|
||||||
// Font size
|
|
||||||
|
|
||||||
auto* font_size_wrapper = lv_obj_create(main_wrapper);
|
|
||||||
lv_obj_set_size(font_size_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
|
||||||
lv_obj_set_style_pad_all(font_size_wrapper, 0, LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_border_width(font_size_wrapper, 0, LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
auto* font_size_label = lv_label_create(font_size_wrapper);
|
|
||||||
lv_label_set_text(font_size_label, "Font size");
|
|
||||||
lv_obj_align(font_size_label, LV_ALIGN_LEFT_MID, 0, 0);
|
|
||||||
|
|
||||||
auto* font_size_dropdown = lv_dropdown_create(font_size_wrapper);
|
|
||||||
lv_dropdown_set_options(font_size_dropdown, "Small\nDefault\nLarge");
|
|
||||||
lv_obj_align(font_size_dropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
|
||||||
lv_obj_add_event_cb(font_size_dropdown, onFontSizeChanged, LV_EVENT_VALUE_CHANGED, this);
|
|
||||||
lv_dropdown_set_selected(font_size_dropdown, static_cast<uint16_t>(displaySettings.fontSize));
|
|
||||||
|
|
||||||
// Screen timeout
|
// Screen timeout
|
||||||
|
|
||||||
if (hal_display->supportsBacklightDuty()) {
|
if (hal_display->supportsBacklightDuty()) {
|
||||||
@@ -320,33 +271,13 @@ public:
|
|||||||
|
|
||||||
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
||||||
// Note: order correlates with settings::display::ScreensaverType enum order
|
// Note: order correlates with settings::display::ScreensaverType enum order
|
||||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan\nMcpScreen");
|
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan");
|
||||||
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||||
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
|
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
|
||||||
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
|
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
|
||||||
if (!displaySettings.backlightTimeoutEnabled) {
|
if (!displaySettings.backlightTimeoutEnabled) {
|
||||||
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
|
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable screensaver when charging toggle
|
|
||||||
disableWhenChargingWrapper = lv_obj_create(main_wrapper);
|
|
||||||
lv_obj_set_size(disableWhenChargingWrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
|
||||||
lv_obj_set_style_pad_all(disableWhenChargingWrapper, 0, LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_border_width(disableWhenChargingWrapper, 0, LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
auto* charging_label = lv_label_create(disableWhenChargingWrapper);
|
|
||||||
lv_label_set_text(charging_label, "Disable on charging");
|
|
||||||
lv_obj_align(charging_label, LV_ALIGN_LEFT_MID, 0, 0);
|
|
||||||
|
|
||||||
disableWhenChargingSwitch = lv_switch_create(disableWhenChargingWrapper);
|
|
||||||
if (displaySettings.disableScreensaverWhenCharging) {
|
|
||||||
lv_obj_add_state(disableWhenChargingSwitch, LV_STATE_CHECKED);
|
|
||||||
}
|
|
||||||
lv_obj_align(disableWhenChargingSwitch, LV_ALIGN_RIGHT_MID, 0, 0);
|
|
||||||
lv_obj_add_event_cb(disableWhenChargingSwitch, onDisableWhenChargingChanged, LV_EVENT_VALUE_CHANGED, this);
|
|
||||||
if (!displaySettings.backlightTimeoutEnabled) {
|
|
||||||
lv_obj_add_state(disableWhenChargingWrapper, LV_STATE_DISABLED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
#include <Tactility/StringUtils.h>
|
#include <Tactility/StringUtils.h>
|
||||||
#include <Tactility/TactilityCore.h>
|
#include <Tactility/TactilityCore.h>
|
||||||
namespace tt::app::files { constexpr auto* TAG = "Files"; bool isSupportedAppFile(const std::string& filename) { return filename.ends_with(".app"); } bool isSupportedImageFile(const std::string& filename) { return string::lowercase(filename).ends_with(".png"); } bool isSupportedTextFile(const std::string& filename) { std::string l=string::lowercase(filename); return l.ends_with(".txt")||l.ends_with(".ini")||l.ends_with(".json")||l.ends_with(".yaml")||l.ends_with(".yml")||l.ends_with(".lua")||l.ends_with(".js")||l.ends_with(".properties"); } bool isSupportedAudioFile(const std::string& filename) { std::string l=string::lowercase(filename); return l.ends_with(".mp3")||l.ends_with(".wav")||l.ends_with(".ogg")||l.ends_with(".flac"); } } // namespace
|
|
||||||
|
namespace tt::app::files {
|
||||||
|
|
||||||
|
constexpr auto* TAG = "Files";
|
||||||
|
|
||||||
|
bool isSupportedAppFile(const std::string& filename) {
|
||||||
|
return filename.ends_with(".app");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSupportedImageFile(const std::string& filename) {
|
||||||
|
// Currently only the PNG library is built into Tactility
|
||||||
|
return string::lowercase(filename).ends_with(".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSupportedTextFile(const std::string& filename) {
|
||||||
|
std::string filename_lower = string::lowercase(filename);
|
||||||
|
return filename_lower.ends_with(".txt") ||
|
||||||
|
filename_lower.ends_with(".ini") ||
|
||||||
|
filename_lower.ends_with(".json") ||
|
||||||
|
filename_lower.ends_with(".yaml") ||
|
||||||
|
filename_lower.ends_with(".yml") ||
|
||||||
|
filename_lower.ends_with(".lua") ||
|
||||||
|
filename_lower.ends_with(".js") ||
|
||||||
|
filename_lower.ends_with(".properties");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tt::app::filebrowser
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <Tactility/app/files/SupportedFiles.h>
|
#include <Tactility/app/files/SupportedFiles.h>
|
||||||
#include <Tactility/Bundle.h>
|
|
||||||
#include <Tactility/app/files/View.h>
|
#include <Tactility/app/files/View.h>
|
||||||
|
|
||||||
#include <Tactility/Platform.h>
|
#include <Tactility/Platform.h>
|
||||||
@@ -229,17 +228,9 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
|||||||
if (kernel::getPlatform() == kernel::PlatformEsp) {
|
if (kernel::getPlatform() == kernel::PlatformEsp) {
|
||||||
notes::start(processed_filepath);
|
notes::start(processed_filepath);
|
||||||
} else {
|
} else {
|
||||||
|
// Remove forward slash, because we need a relative path
|
||||||
notes::start(processed_filepath.substr(1));
|
notes::start(processed_filepath.substr(1));
|
||||||
}
|
}
|
||||||
} else if (isSupportedAudioFile(filename)) {
|
|
||||||
#ifdef ESP_PLATFORM
|
|
||||||
auto bundle = std::make_shared<Bundle>();
|
|
||||||
bundle->putString("file", processed_filepath);
|
|
||||||
auto loader = service::loader::findLoaderService();
|
|
||||||
if (loader) {
|
|
||||||
loader->start("one.tactility.mp3player", bundle);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
LOG_W(TAG, "Opening files of this type is not supported");
|
LOG_W(TAG, "Opening files of this type is not supported");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <Tactility/service/displayidle/DisplayIdleService.h>
|
#include <Tactility/service/displayidle/DisplayIdleService.h>
|
||||||
#endif
|
#endif
|
||||||
#include <Tactility/app/App.h>
|
#include <Tactility/app/App.h>
|
||||||
#include <Tactility/lvgl/Lvgl.h>
|
|
||||||
#include <Tactility/lvgl/Toolbar.h>
|
#include <Tactility/lvgl/Toolbar.h>
|
||||||
#include <Tactility/settings/DisplaySettings.h>
|
#include <Tactility/settings/DisplaySettings.h>
|
||||||
|
|
||||||
@@ -70,21 +69,6 @@ class KernelDisplayApp final : public App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onFontSizeChanged(lv_event_t* event) {
|
|
||||||
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
|
|
||||||
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
|
||||||
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
|
|
||||||
if (selected_index >= static_cast<uint32_t>(settings::display::FontSize::Count)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto selected_size = static_cast<settings::display::FontSize>(selected_index);
|
|
||||||
if (selected_size != app->displaySettings.fontSize) {
|
|
||||||
app->displaySettings.fontSize = selected_size;
|
|
||||||
app->displaySettingsUpdated = true;
|
|
||||||
lvgl::applyFontSize(selected_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onTimeoutSwitch(lv_event_t* event) {
|
static void onTimeoutSwitch(lv_event_t* event) {
|
||||||
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
|
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
|
||||||
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||||
@@ -199,23 +183,6 @@ public:
|
|||||||
// Set the dropdown to match current orientation enum
|
// Set the dropdown to match current orientation enum
|
||||||
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(displaySettings.orientation));
|
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(displaySettings.orientation));
|
||||||
|
|
||||||
// Font size
|
|
||||||
|
|
||||||
auto* font_size_wrapper = lv_obj_create(main_wrapper);
|
|
||||||
lv_obj_set_size(font_size_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
|
||||||
lv_obj_set_style_pad_all(font_size_wrapper, 0, LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_border_width(font_size_wrapper, 0, LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
auto* font_size_label = lv_label_create(font_size_wrapper);
|
|
||||||
lv_label_set_text(font_size_label, "Font size");
|
|
||||||
lv_obj_align(font_size_label, LV_ALIGN_LEFT_MID, 0, 0);
|
|
||||||
|
|
||||||
auto* font_size_dropdown = lv_dropdown_create(font_size_wrapper);
|
|
||||||
lv_dropdown_set_options(font_size_dropdown, "Small\nDefault\nLarge");
|
|
||||||
lv_obj_align(font_size_dropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
|
||||||
lv_obj_add_event_cb(font_size_dropdown, onFontSizeChanged, LV_EVENT_VALUE_CHANGED, this);
|
|
||||||
lv_dropdown_set_selected(font_size_dropdown, static_cast<uint16_t>(displaySettings.fontSize));
|
|
||||||
|
|
||||||
// Screen timeout
|
// Screen timeout
|
||||||
// Note: DisplayIdleService doesn't act on these settings for kernel-driver displays yet
|
// Note: DisplayIdleService doesn't act on these settings for kernel-driver displays yet
|
||||||
// (it only looks up the deprecated tt::hal::display::DisplayDevice), so these currently
|
// (it only looks up the deprecated tt::hal::display::DisplayDevice), so these currently
|
||||||
|
|||||||
@@ -1,51 +1,75 @@
|
|||||||
#include <Tactility/Tactility.h>
|
#include <Tactility/Tactility.h>
|
||||||
|
|
||||||
#include <Tactility/Paths.h>
|
|
||||||
#include <Tactility/app/AppContext.h>
|
#include <Tactility/app/AppContext.h>
|
||||||
#include <Tactility/app/AppPaths.h>
|
#include <Tactility/app/AppPaths.h>
|
||||||
#include <Tactility/app/AppRegistration.h>
|
#include <Tactility/app/AppRegistration.h>
|
||||||
#include <Tactility/app/setup/Setup.h>
|
#include <Tactility/app/setup/Setup.h>
|
||||||
#include <Tactility/file/File.h>
|
|
||||||
#include <Tactility/lvgl/Lvgl.h>
|
|
||||||
#include <Tactility/service/loader/Loader.h>
|
#include <Tactility/service/loader/Loader.h>
|
||||||
#include <Tactility/service/wifi/Wifi.h>
|
|
||||||
#include <Tactility/settings/BootSettings.h>
|
#include <Tactility/settings/BootSettings.h>
|
||||||
#include <Tactility/settings/Time.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <tactility/device.h>
|
#include <tactility/device.h>
|
||||||
#include <tactility/drivers/power_supply.h>
|
#include <tactility/drivers/power_supply.h>
|
||||||
#include <tactility/log.h>
|
#include <tactility/log.h>
|
||||||
#include <tactility/lvgl_fonts.h>
|
#include <tactility/lvgl_fonts.h>
|
||||||
#include <tactility/lvgl_icon_launcher.h>
|
#include <tactility/lvgl_icon_launcher.h>
|
||||||
#include <tactility/lvgl_icon_statusbar.h>
|
|
||||||
#include <tactility/lvgl_module.h>
|
#include <tactility/lvgl_module.h>
|
||||||
|
|
||||||
namespace tt::app::launcher {
|
namespace tt::app::launcher {
|
||||||
|
|
||||||
constexpr auto* TAG = "Launcher";
|
constexpr auto* TAG = "Launcher";
|
||||||
constexpr auto* BACKGROUND_ASSET = "color-field.png";
|
|
||||||
constexpr auto* CUSTOM_BACKGROUND_PATH = "tactility/launcher/background.bin";
|
static uint32_t getButtonPadding(UiDensity density, uint32_t buttonSize) {
|
||||||
constexpr lv_color_t TEXT_COLOR = LV_COLOR_MAKE(0xF8, 0xF5, 0xF2);
|
if (density == LVGL_UI_DENSITY_COMPACT) {
|
||||||
constexpr lv_color_t MUTED_TEXT_COLOR = LV_COLOR_MAKE(0xDF, 0xD6, 0xD3);
|
return 0;
|
||||||
constexpr lv_color_t ACCENT_COLOR = LV_COLOR_MAKE(0xEC, 0x75, 0x69);
|
} else {
|
||||||
|
return buttonSize / 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t computeButtonMargin(int32_t available_span, int32_t total_button_size) {
|
||||||
|
const int32_t usable = std::max<int32_t>(0, available_span - (3 * total_button_size));
|
||||||
|
return std::min<int32_t>(usable / 16, total_button_size / 2);
|
||||||
|
}
|
||||||
|
|
||||||
class LauncherApp final : public App {
|
class LauncherApp final : public App {
|
||||||
lv_obj_t* timeLabel = nullptr;
|
|
||||||
lv_obj_t* dateLabel = nullptr;
|
|
||||||
lv_obj_t* dataLabel = nullptr;
|
|
||||||
lv_obj_t* statusLabel = nullptr;
|
|
||||||
lv_timer_t* updateTimer = nullptr;
|
|
||||||
|
|
||||||
static void onAppPressed(lv_event_t* event) {
|
static lv_obj_t* createAppButton(lv_obj_t* parent, UiDensity uiDensity, const char* imageFile, const char* appId, int32_t itemMargin, bool isLandscape) {
|
||||||
const auto* app_id = static_cast<const char*>(lv_event_get_user_data(event));
|
const auto button_size = lvgl_get_launcher_icon_font_height();
|
||||||
start(app_id);
|
const auto button_padding = getButtonPadding(uiDensity, button_size);
|
||||||
|
auto* apps_button = lv_button_create(parent);
|
||||||
|
|
||||||
|
lv_obj_set_style_pad_all(apps_button, static_cast<int32_t>(button_padding), LV_STATE_DEFAULT);
|
||||||
|
if (isLandscape) {
|
||||||
|
lv_obj_set_style_margin_hor(apps_button, itemMargin, LV_STATE_DEFAULT);
|
||||||
|
} else {
|
||||||
|
lv_obj_set_style_margin_ver(apps_button, itemMargin, LV_STATE_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_set_style_shadow_width(apps_button, 0, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_bg_opa(apps_button, 0, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
// create the image first
|
||||||
|
auto* button_image = lv_image_create(apps_button);
|
||||||
|
lv_obj_set_style_text_font(button_image, lvgl_get_launcher_icon_font(), LV_STATE_DEFAULT);
|
||||||
|
lv_image_set_src(button_image, imageFile);
|
||||||
|
lv_obj_set_style_text_color(button_image, lv_theme_get_color_primary(button_image), LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_image_recolor(button_image, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_image_recolor_opa(button_image, LV_OPA_COVER, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
// Ensure it's square (Material Symbols are slightly wider than tall)
|
||||||
|
lv_obj_set_size(button_image, button_size, button_size);
|
||||||
|
|
||||||
|
lv_obj_add_event_cb(apps_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)appId);
|
||||||
|
|
||||||
|
return apps_button;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onAppPressed(lv_event_t* e) {
|
||||||
|
auto* appId = static_cast<const char*>(lv_event_get_user_data(e));
|
||||||
|
start(appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool shouldShowPowerButton() {
|
static bool shouldShowPowerButton() {
|
||||||
@@ -53,307 +77,139 @@ class LauncherApp final : public App {
|
|||||||
device_for_each_of_type(&POWER_SUPPLY_TYPE, &show_power_button, [](Device* device, void* context) {
|
device_for_each_of_type(&POWER_SUPPLY_TYPE, &show_power_button, [](Device* device, void* context) {
|
||||||
if (device_is_ready(device) && power_supply_supports_power_off(device)) {
|
if (device_is_ready(device) && power_supply_supports_power_off(device)) {
|
||||||
*static_cast<bool*>(context) = true;
|
*static_cast<bool*>(context) = true;
|
||||||
return false;
|
return false; // stop iterating
|
||||||
|
} else {
|
||||||
|
return true; // continue iterating
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
return show_power_button;
|
return show_power_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getBatteryPercentage() {
|
// The screen object outlives the launcher's views (it's recreated by GuiService::redraw()
|
||||||
Device* power = nullptr;
|
// via lv_obj_clean() on every app switch), so the LV_EVENT_SIZE_CHANGED callback registered
|
||||||
device_for_each_of_type(&POWER_SUPPLY_TYPE, &power, [](Device* device, void* context) {
|
// on it must be removed once buttons_wrapper is destroyed, to avoid a dangling user-data
|
||||||
if (device_is_ready(device) && power_supply_supports_property(device, POWER_SUPPLY_PROP_CAPACITY)) {
|
// pointer on the next rotation while a different app is visible.
|
||||||
*static_cast<Device**>(context) = device;
|
static void onButtonsWrapperDeleted(lv_event_t* e) {
|
||||||
return false;
|
auto* buttons_wrapper = lv_event_get_target_obj(e);
|
||||||
}
|
auto* screen = lv_obj_get_screen(buttons_wrapper);
|
||||||
return true;
|
lv_obj_remove_event_cb_with_user_data(screen, onButtonsWrapperResized, buttons_wrapper);
|
||||||
});
|
|
||||||
|
|
||||||
if (power == nullptr) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
PowerSupplyPropertyValue charge_level;
|
|
||||||
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CAPACITY, &charge_level) != ERROR_NONE) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return std::clamp(charge_level.int_value, 0, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* getWifiStatusIcon(service::wifi::RadioState state) {
|
// Re-applies the flex direction and per-button margins when the display orientation
|
||||||
using enum service::wifi::RadioState;
|
// changes while the launcher is the visible app (these are decided once at onShow()
|
||||||
switch (state) {
|
// based on the resolution at that time, so a later rotation needs this to catch up).
|
||||||
case ConnectionActive:
|
static void onButtonsWrapperResized(lv_event_t* e) {
|
||||||
return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_4_BAR;
|
auto* buttons_wrapper = static_cast<lv_obj_t*>(lv_event_get_user_data(e));
|
||||||
case Off:
|
const auto* display = lv_obj_get_display(buttons_wrapper);
|
||||||
case OffPending:
|
|
||||||
return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_OFF;
|
const auto button_size = lvgl_get_launcher_icon_font_height();
|
||||||
default:
|
const auto button_padding = getButtonPadding(lvgl_get_ui_density(), button_size);
|
||||||
return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_0_BAR;
|
const auto total_button_size = button_size + (button_padding * 2);
|
||||||
|
|
||||||
|
const auto horizontal_px = lv_display_get_horizontal_resolution(display);
|
||||||
|
const auto vertical_px = lv_display_get_vertical_resolution(display);
|
||||||
|
const bool is_landscape_display = horizontal_px >= vertical_px;
|
||||||
|
const auto current_flow = lv_obj_get_style_flex_flow(buttons_wrapper, LV_PART_MAIN);
|
||||||
|
const bool was_landscape = current_flow == LV_FLEX_FLOW_ROW;
|
||||||
|
if (is_landscape_display == was_landscape) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static const char* getBatteryStatusIcon(int percentage) {
|
lv_obj_set_flex_flow(buttons_wrapper, is_landscape_display ? LV_FLEX_FLOW_ROW : LV_FLEX_FLOW_COLUMN);
|
||||||
if (percentage < 0) {
|
|
||||||
return "";
|
const int32_t margin = is_landscape_display
|
||||||
} else if (percentage >= 95) {
|
? computeButtonMargin(horizontal_px, total_button_size)
|
||||||
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_FULL;
|
: computeButtonMargin(vertical_px, total_button_size);
|
||||||
} else if (percentage >= 64) {
|
|
||||||
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_5;
|
const uint32_t child_count = lv_obj_get_child_count(buttons_wrapper);
|
||||||
} else if (percentage >= 32) {
|
for (uint32_t i = 0; i < child_count; i++) {
|
||||||
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_3;
|
auto* button = lv_obj_get_child(buttons_wrapper, i);
|
||||||
|
lv_obj_set_style_margin_hor(button, is_landscape_display ? margin : 0, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_margin_ver(button, is_landscape_display ? 0 : margin, LV_STATE_DEFAULT);
|
||||||
}
|
}
|
||||||
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static lv_obj_t* createAppButton(
|
|
||||||
lv_obj_t* parent,
|
|
||||||
const char* icon,
|
|
||||||
const char* appId,
|
|
||||||
bool emphasized
|
|
||||||
) {
|
|
||||||
auto* button = lv_button_create(parent);
|
|
||||||
lv_obj_set_size(button, 52, 52);
|
|
||||||
lv_obj_set_style_radius(button, 15, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_shadow_width(button, 0, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_border_width(button, emphasized ? 2 : 1, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_border_color(button, emphasized ? ACCENT_COLOR : lv_color_hex(0x746568), LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_border_opa(button, emphasized ? LV_OPA_COVER : LV_OPA_60, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_bg_color(button, lv_color_hex(0x211B20), LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_bg_opa(button, emphasized ? LV_OPA_80 : LV_OPA_70, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_bg_color(button, lv_color_hex(0x392C32), LV_STATE_PRESSED);
|
|
||||||
lv_obj_set_style_transform_scale(button, 238, LV_STATE_PRESSED);
|
|
||||||
lv_obj_set_style_outline_color(button, ACCENT_COLOR, LV_STATE_FOCUSED);
|
|
||||||
lv_obj_set_style_outline_width(button, 2, LV_STATE_FOCUSED);
|
|
||||||
lv_obj_set_style_outline_pad(button, 2, LV_STATE_FOCUSED);
|
|
||||||
|
|
||||||
auto* image = lv_image_create(button);
|
|
||||||
lv_obj_set_size(image, 36, 36);
|
|
||||||
lv_obj_center(image);
|
|
||||||
lv_obj_set_style_text_font(image, lvgl_get_launcher_icon_font(), LV_STATE_DEFAULT);
|
|
||||||
lv_image_set_src(image, icon);
|
|
||||||
lv_obj_set_style_image_recolor(image, TEXT_COLOR, LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_image_recolor_opa(image, LV_OPA_COVER, LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
lv_obj_add_event_cb(button, onAppPressed, LV_EVENT_SHORT_CLICKED, const_cast<char*>(appId));
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateInformation() {
|
|
||||||
const std::time_t now = std::time(nullptr);
|
|
||||||
std::tm local_time {};
|
|
||||||
localtime_r(&now, &local_time);
|
|
||||||
|
|
||||||
char time_buffer[12];
|
|
||||||
char date_buffer[40];
|
|
||||||
if (local_time.tm_year >= 125) {
|
|
||||||
if (settings::isTimeFormat24Hour()) {
|
|
||||||
std::strftime(time_buffer, sizeof(time_buffer), "%H:%M", &local_time);
|
|
||||||
} else {
|
|
||||||
std::strftime(time_buffer, sizeof(time_buffer), "%I:%M", &local_time);
|
|
||||||
if (time_buffer[0] == '0') {
|
|
||||||
std::memmove(time_buffer, time_buffer + 1, std::strlen(time_buffer));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::strftime(date_buffer, sizeof(date_buffer), "%A, %B %e", &local_time);
|
|
||||||
} else {
|
|
||||||
std::strcpy(time_buffer, "--:--");
|
|
||||||
std::strcpy(date_buffer, "Set date and time");
|
|
||||||
}
|
|
||||||
lv_label_set_text(timeLabel, time_buffer);
|
|
||||||
lv_label_set_text(dateLabel, date_buffer);
|
|
||||||
|
|
||||||
const auto wifi_state = service::wifi::getRadioState();
|
|
||||||
const bool wifi_connected = wifi_state == service::wifi::RadioState::ConnectionActive;
|
|
||||||
std::string sd_card_path;
|
|
||||||
const bool sd_ready = findFirstMountedSdCardPath(sd_card_path);
|
|
||||||
const int battery_percentage = getBatteryPercentage();
|
|
||||||
|
|
||||||
char data_buffer[80];
|
|
||||||
if (battery_percentage >= 0) {
|
|
||||||
std::snprintf(
|
|
||||||
data_buffer,
|
|
||||||
sizeof(data_buffer),
|
|
||||||
"%s • %s • %d%%",
|
|
||||||
wifi_connected ? "Wi-Fi connected" : "Wi-Fi offline",
|
|
||||||
sd_ready ? "SD ready" : "No SD",
|
|
||||||
battery_percentage
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
std::snprintf(
|
|
||||||
data_buffer,
|
|
||||||
sizeof(data_buffer),
|
|
||||||
"%s • %s",
|
|
||||||
wifi_connected ? "Wi-Fi connected" : "Wi-Fi offline",
|
|
||||||
sd_ready ? "SD ready" : "No SD"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
lv_label_set_text(dataLabel, data_buffer);
|
|
||||||
|
|
||||||
char status_buffer[24];
|
|
||||||
std::snprintf(
|
|
||||||
status_buffer,
|
|
||||||
sizeof(status_buffer),
|
|
||||||
"%s%s",
|
|
||||||
getWifiStatusIcon(wifi_state),
|
|
||||||
getBatteryStatusIcon(battery_percentage)
|
|
||||||
);
|
|
||||||
lv_label_set_text(statusLabel, status_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onUpdateTimer(lv_timer_t* timer) {
|
|
||||||
static_cast<LauncherApp*>(lv_timer_get_user_data(timer))->updateInformation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void onCreate(AppContext& app) override {
|
void onCreate(AppContext& app) override {
|
||||||
settings::BootSettings boot_properties;
|
settings::BootSettings boot_properties;
|
||||||
if (
|
if (
|
||||||
std::strcmp(CONFIG_TT_AUTO_START_APP_ID, "") != 0 &&
|
// Auto-start due to built-in requirement
|
||||||
|
strcmp(CONFIG_TT_AUTO_START_APP_ID, "") != 0 &&
|
||||||
findAppManifestById(CONFIG_TT_AUTO_START_APP_ID) != nullptr
|
findAppManifestById(CONFIG_TT_AUTO_START_APP_ID) != nullptr
|
||||||
) {
|
) {
|
||||||
LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID);
|
LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID);
|
||||||
start(CONFIG_TT_AUTO_START_APP_ID);
|
start(CONFIG_TT_AUTO_START_APP_ID);
|
||||||
} else if (
|
} else if (
|
||||||
|
// Auto-start due to user configuration
|
||||||
settings::loadBootSettings(boot_properties) &&
|
settings::loadBootSettings(boot_properties) &&
|
||||||
!boot_properties.autoStartAppId.empty() &&
|
!boot_properties.autoStartAppId.empty() &&
|
||||||
findAppManifestById(boot_properties.autoStartAppId) != nullptr
|
findAppManifestById(boot_properties.autoStartAppId) != nullptr
|
||||||
) {
|
) {
|
||||||
LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
|
LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
|
||||||
start(boot_properties.autoStartAppId);
|
start(boot_properties.autoStartAppId);
|
||||||
} else if (!setup::isCompleted()) {
|
} else {
|
||||||
setup::start();
|
// No auto-start, consider running system setup
|
||||||
|
if (!setup::isCompleted()) {
|
||||||
|
setup::start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||||
lv_obj_set_style_bg_color(parent, lv_color_hex(0x211A20), LV_PART_MAIN);
|
auto* buttons_wrapper = lv_obj_create(parent);
|
||||||
lv_obj_set_style_bg_opa(parent, LV_OPA_COVER, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_pad_all(parent, 0, LV_PART_MAIN);
|
|
||||||
lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
auto* display = lv_obj_get_display(parent);
|
auto ui_density = lvgl_get_ui_density();
|
||||||
const auto display_width = lv_display_get_horizontal_resolution(display);
|
const auto button_size = lvgl_get_launcher_icon_font_height();
|
||||||
const auto display_height = lv_display_get_vertical_resolution(display);
|
const auto button_padding = getButtonPadding(ui_density, button_size);
|
||||||
const bool is_portrait = display_height > display_width;
|
const auto total_button_size = button_size + (button_padding * 2);
|
||||||
|
|
||||||
auto background_path = lvgl::PATH_PREFIX + app.getPaths()->getAssetsPath(BACKGROUND_ASSET);
|
lv_obj_align(buttons_wrapper, LV_ALIGN_CENTER, 0, 0);
|
||||||
std::string sd_card_path;
|
lv_obj_set_size(buttons_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||||
if (findFirstMountedSdCardPath(sd_card_path)) {
|
lv_obj_set_style_border_width(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
||||||
const auto custom_background_path = file::getChildPath(sd_card_path, CUSTOM_BACKGROUND_PATH);
|
lv_obj_set_flex_grow(buttons_wrapper, 1);
|
||||||
if (file::isFile(custom_background_path)) {
|
|
||||||
const auto lvgl_custom_background_path = lvgl::PATH_PREFIX + custom_background_path;
|
|
||||||
lv_image_header_t header {};
|
|
||||||
if (lv_image_decoder_get_info(lvgl_custom_background_path.c_str(), &header) == LV_RESULT_OK) {
|
|
||||||
if (header.w >= display_width && header.h >= display_height) {
|
|
||||||
background_path = lvgl_custom_background_path;
|
|
||||||
LOG_I(
|
|
||||||
TAG,
|
|
||||||
"Using SD background %s (%ux%u, format 0x%02x)",
|
|
||||||
custom_background_path.c_str(),
|
|
||||||
header.w,
|
|
||||||
header.h,
|
|
||||||
header.cf
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
LOG_W(
|
|
||||||
TAG,
|
|
||||||
"Ignoring undersized SD background %s (%ux%u for %dx%d display)",
|
|
||||||
custom_background_path.c_str(),
|
|
||||||
header.w,
|
|
||||||
header.h,
|
|
||||||
display_width,
|
|
||||||
display_height
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG_W(TAG, "Ignoring invalid SD background %s", custom_background_path.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* background = lv_image_create(parent);
|
// Fix for button selection
|
||||||
lv_image_set_src(background, background_path.c_str());
|
lv_obj_set_style_pad_all(buttons_wrapper, 6, LV_STATE_DEFAULT);
|
||||||
lv_obj_align(background, LV_ALIGN_CENTER, 0, 0);
|
|
||||||
lv_obj_add_flag(background, LV_OBJ_FLAG_IGNORE_LAYOUT);
|
|
||||||
|
|
||||||
timeLabel = lv_label_create(parent);
|
const auto* display = lv_obj_get_display(parent);
|
||||||
lv_label_set_text(timeLabel, "--:--");
|
const auto horizontal_px = lv_display_get_horizontal_resolution(display);
|
||||||
lv_obj_set_style_text_color(timeLabel, TEXT_COLOR, LV_PART_MAIN);
|
const auto vertical_px = lv_display_get_vertical_resolution(display);
|
||||||
#if LV_FONT_MONTSERRAT_48
|
const bool is_landscape_display = horizontal_px >= vertical_px;
|
||||||
lv_obj_set_style_text_font(timeLabel, &lv_font_montserrat_48, LV_PART_MAIN);
|
if (is_landscape_display) {
|
||||||
#else
|
lv_obj_set_flex_flow(buttons_wrapper, LV_FLEX_FLOW_ROW);
|
||||||
lv_obj_set_style_text_font(timeLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN);
|
|
||||||
#endif
|
|
||||||
lv_obj_align(timeLabel, LV_ALIGN_TOP_LEFT, 18, 58);
|
|
||||||
|
|
||||||
dateLabel = lv_label_create(parent);
|
|
||||||
lv_obj_set_style_text_font(dateLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_text_color(dateLabel, TEXT_COLOR, LV_PART_MAIN);
|
|
||||||
lv_obj_align(dateLabel, LV_ALIGN_TOP_LEFT, 20, 118);
|
|
||||||
|
|
||||||
dataLabel = lv_label_create(parent);
|
|
||||||
lv_obj_set_width(dataLabel, is_portrait ? display_width - 40 : 225);
|
|
||||||
lv_label_set_long_mode(dataLabel, LV_LABEL_LONG_MODE_WRAP);
|
|
||||||
lv_obj_set_style_text_font(dataLabel, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_text_color(dataLabel, MUTED_TEXT_COLOR, LV_PART_MAIN);
|
|
||||||
lv_obj_align(dataLabel, LV_ALIGN_TOP_LEFT, 20, 148);
|
|
||||||
|
|
||||||
statusLabel = lv_label_create(parent);
|
|
||||||
lv_obj_set_style_text_font(statusLabel, lvgl_get_statusbar_icon_font(), LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_text_color(statusLabel, TEXT_COLOR, LV_PART_MAIN);
|
|
||||||
lv_obj_align(statusLabel, LV_ALIGN_TOP_RIGHT, -15, 8);
|
|
||||||
|
|
||||||
auto* buttonRail = lv_obj_create(parent);
|
|
||||||
if (is_portrait) {
|
|
||||||
lv_obj_set_size(buttonRail, 184, 60);
|
|
||||||
lv_obj_align(buttonRail, LV_ALIGN_BOTTOM_MID, 0, -7);
|
|
||||||
lv_obj_set_flex_flow(buttonRail, LV_FLEX_FLOW_ROW);
|
|
||||||
} else {
|
} else {
|
||||||
lv_obj_set_size(buttonRail, 60, 184);
|
lv_obj_set_flex_flow(buttons_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||||
lv_obj_align(buttonRail, LV_ALIGN_RIGHT_MID, -7, 8);
|
|
||||||
lv_obj_set_flex_flow(buttonRail, LV_FLEX_FLOW_COLUMN);
|
|
||||||
}
|
}
|
||||||
lv_obj_set_flex_align(buttonRail, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_set_style_pad_all(buttonRail, 0, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_border_width(buttonRail, 0, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_bg_opa(buttonRail, LV_OPA_TRANSP, LV_PART_MAIN);
|
|
||||||
lv_obj_clear_flag(buttonRail, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
createAppButton(buttonRail, LVGL_ICON_LAUNCHER_APPS, "AppList", true);
|
const int32_t margin = is_landscape_display
|
||||||
createAppButton(buttonRail, LVGL_ICON_LAUNCHER_FOLDER, "Files", false);
|
? computeButtonMargin(lv_display_get_horizontal_resolution(display), total_button_size)
|
||||||
createAppButton(buttonRail, LVGL_ICON_LAUNCHER_SETTINGS, "Settings", false);
|
: computeButtonMargin(lv_display_get_vertical_resolution(display), total_button_size);
|
||||||
|
|
||||||
|
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_APPS, "AppList", margin, is_landscape_display);
|
||||||
|
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_FOLDER, "Files", margin, is_landscape_display);
|
||||||
|
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_SETTINGS, "Settings", margin, is_landscape_display);
|
||||||
|
|
||||||
|
// The launcher's container is several levels below the screen, and LVGL only sends
|
||||||
|
// LV_EVENT_SIZE_CHANGED to the screen object itself on a resolution change - so the
|
||||||
|
// handler is attached there, with buttons_wrapper passed through as user data.
|
||||||
|
lv_obj_add_event_cb(lv_obj_get_screen(parent), onButtonsWrapperResized, LV_EVENT_SIZE_CHANGED, buttons_wrapper);
|
||||||
|
lv_obj_add_event_cb(buttons_wrapper, onButtonsWrapperDeleted, LV_EVENT_DELETE, nullptr);
|
||||||
|
|
||||||
|
// Some devices (e.g. T-Lora Pager) have no other way to power off, so the
|
||||||
|
// button stays in the launcher; the confirmation flow lives in the PowerOff app.
|
||||||
if (shouldShowPowerButton()) {
|
if (shouldShowPowerButton()) {
|
||||||
auto* power_button = lv_button_create(parent);
|
auto* power_button = lv_button_create(parent);
|
||||||
lv_obj_set_size(power_button, 36, 36);
|
lv_obj_set_style_pad_all(power_button, 8, 0);
|
||||||
lv_obj_align(power_button, LV_ALIGN_BOTTOM_LEFT, 16, -12);
|
lv_obj_align(power_button, LV_ALIGN_BOTTOM_MID, 0, -10);
|
||||||
lv_obj_set_style_radius(power_button, LV_RADIUS_CIRCLE, LV_PART_MAIN);
|
lv_obj_add_event_cb(power_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)"PowerOff");
|
||||||
lv_obj_set_style_shadow_width(power_button, 0, LV_PART_MAIN);
|
lv_obj_set_style_shadow_width(power_button, 0, LV_STATE_DEFAULT);
|
||||||
lv_obj_set_style_bg_color(power_button, lv_color_hex(0x211B20), LV_PART_MAIN);
|
lv_obj_set_style_bg_opa(power_button, 0, LV_PART_MAIN);
|
||||||
lv_obj_set_style_bg_opa(power_button, LV_OPA_70, LV_PART_MAIN);
|
|
||||||
lv_obj_add_event_cb(power_button, onAppPressed, LV_EVENT_SHORT_CLICKED, const_cast<char*>("PowerOff"));
|
|
||||||
|
|
||||||
auto* power_label = lv_label_create(power_button);
|
auto* power_label = lv_label_create(power_button);
|
||||||
lv_label_set_text(power_label, LV_SYMBOL_POWER);
|
lv_label_set_text(power_label, LV_SYMBOL_POWER);
|
||||||
lv_obj_set_style_text_color(power_label, TEXT_COLOR, LV_PART_MAIN);
|
lv_obj_set_style_text_color(power_label, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
||||||
lv_obj_center(power_label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateInformation();
|
|
||||||
updateTimer = lv_timer_create(onUpdateTimer, 1000, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onHide(AppContext& app) override {
|
|
||||||
if (updateTimer != nullptr) {
|
|
||||||
lv_timer_delete(updateTimer);
|
|
||||||
updateTimer = nullptr;
|
|
||||||
}
|
|
||||||
timeLabel = nullptr;
|
|
||||||
dateLabel = nullptr;
|
|
||||||
dataLabel = nullptr;
|
|
||||||
statusLabel = nullptr;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -361,7 +217,7 @@ extern const AppManifest manifest = {
|
|||||||
.appId = "Launcher",
|
.appId = "Launcher",
|
||||||
.appName = "Launcher",
|
.appName = "Launcher",
|
||||||
.appCategory = Category::System,
|
.appCategory = Category::System,
|
||||||
.appFlags = AppManifest::Flags::Hidden | AppManifest::Flags::HideStatusBar,
|
.appFlags = AppManifest::Flags::Hidden,
|
||||||
.createApp = create<LauncherApp>
|
.createApp = create<LauncherApp>
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -369,4 +225,4 @@ LaunchId start() {
|
|||||||
return app::start(manifest.appId);
|
return app::start(manifest.appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tt::app::launcher
|
} // namespace
|
||||||
|
|||||||
@@ -1,141 +0,0 @@
|
|||||||
#ifdef ESP_PLATFORM
|
|
||||||
|
|
||||||
#include <Tactility/Tactility.h>
|
|
||||||
#include <Tactility/mcp/McpSystem.h>
|
|
||||||
#include <Tactility/lvgl/Toolbar.h>
|
|
||||||
#include <Tactility/lvgl/LvglSync.h>
|
|
||||||
#include <tactility/log.h>
|
|
||||||
|
|
||||||
constexpr auto* TAG = "McpOverrideApp";
|
|
||||||
|
|
||||||
#include <lvgl.h>
|
|
||||||
#include <tactility/lvgl_icon_shared.h>
|
|
||||||
#include <esp_heap_caps.h>
|
|
||||||
|
|
||||||
namespace tt::app::mcpoverride {
|
|
||||||
|
|
||||||
|
|
||||||
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 {
|
|
||||||
LOG_I(TAG, "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) {
|
|
||||||
LOG_E(TAG, "Failed to allocate %u 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 {
|
|
||||||
LOG_I(TAG, "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
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
#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/log.h>
|
|
||||||
|
|
||||||
constexpr auto* TAG = "McpSettingsApp";
|
|
||||||
|
|
||||||
#include <lvgl.h>
|
|
||||||
#include <tactility/lvgl_icon_shared.h>
|
|
||||||
|
|
||||||
#include <esp_netif.h>
|
|
||||||
#include <esp_wifi.h>
|
|
||||||
|
|
||||||
namespace tt::app::mcpsettings {
|
|
||||||
|
|
||||||
|
|
||||||
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://";
|
|
||||||
bool ip_added = false;
|
|
||||||
|
|
||||||
// Try getting station IP first (we are connected to home Wi-Fi)
|
|
||||||
esp_netif_t* sta_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
|
||||||
if (sta_netif != nullptr) {
|
|
||||||
esp_netif_ip_info_t ip_info;
|
|
||||||
if (esp_netif_get_ip_info(sta_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;
|
|
||||||
ip_added = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no station IP, check if the AP interface has a valid IP address
|
|
||||||
if (!ip_added) {
|
|
||||||
esp_netif_t* ap_netif = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
|
|
||||||
if (ap_netif != nullptr) {
|
|
||||||
esp_netif_ip_info_t ip_info;
|
|
||||||
if (esp_netif_get_ip_info(ap_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;
|
|
||||||
ip_added = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback if no active IP address is detected on either interface
|
|
||||||
if (!ip_added) {
|
|
||||||
if (wsSettings.wifiMode == settings::webserver::WiFiMode::AccessPoint) {
|
|
||||||
url += "192.168.4.1";
|
|
||||||
} else {
|
|
||||||
url = "Connecting...";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
LOG_W(TAG, "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) {
|
|
||||||
LOG_I(TAG, "MCP server state changed to %s", 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
|
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
#include <tactility/device.h>
|
#include <tactility/device.h>
|
||||||
#include <tactility/drivers/backlight.h>
|
#include <tactility/drivers/backlight.h>
|
||||||
#include <tactility/log.h>
|
#include <tactility/log.h>
|
||||||
#include <tactility/lvgl_fonts.h>
|
|
||||||
#include <tactility/lvgl_module.h>
|
#include <tactility/lvgl_module.h>
|
||||||
#include <tactility/lvgl_pointer.h>
|
#include <tactility/lvgl_pointer.h>
|
||||||
#include <tactility/module.h>
|
#include <tactility/module.h>
|
||||||
@@ -28,49 +27,6 @@ bool isStarted() {
|
|||||||
return module_is_started(&lvgl_module);
|
return module_is_started(&lvgl_module);
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyFontSize(settings::display::FontSize fontSize) {
|
|
||||||
LvglFontScale scale;
|
|
||||||
switch (fontSize) {
|
|
||||||
using enum settings::display::FontSize;
|
|
||||||
case Small:
|
|
||||||
scale = FONT_SCALE_SMALL;
|
|
||||||
break;
|
|
||||||
case Large:
|
|
||||||
scale = FONT_SCALE_LARGE;
|
|
||||||
break;
|
|
||||||
case Default:
|
|
||||||
default:
|
|
||||||
scale = FONT_SCALE_DEFAULT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
lvgl_set_text_font_scale(scale);
|
|
||||||
const lv_font_t* font = lvgl_get_text_font(FONT_SIZE_DEFAULT);
|
|
||||||
|
|
||||||
for (lv_display_t* display = lv_display_get_next(nullptr);
|
|
||||||
display != nullptr;
|
|
||||||
display = lv_display_get_next(display)) {
|
|
||||||
#if LV_USE_THEME_DEFAULT
|
|
||||||
if (lv_display_get_theme(display) == lv_theme_default_get()) {
|
|
||||||
lv_obj_t* screen = lv_display_get_screen_active(display);
|
|
||||||
lv_theme_default_init(
|
|
||||||
display,
|
|
||||||
lv_theme_get_color_primary(screen),
|
|
||||||
lv_theme_get_color_secondary(screen),
|
|
||||||
LV_THEME_DEFAULT_DARK,
|
|
||||||
font
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// The display layers are independent inheritance roots. Updating all of them makes
|
|
||||||
// the new size visible immediately in regular screens, overlays, and the status bar.
|
|
||||||
lv_obj_set_style_text_font(lv_display_get_screen_active(display), font, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_text_font(lv_display_get_layer_top(display), font, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_text_font(lv_display_get_layer_sys(display), font, LV_PART_MAIN);
|
|
||||||
lv_obj_set_style_text_font(lv_display_get_layer_bottom(display), font, LV_PART_MAIN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void attachDevices() {
|
void attachDevices() {
|
||||||
LOG_I(TAG, "Adding devices");
|
LOG_I(TAG, "Adding devices");
|
||||||
|
|
||||||
@@ -99,7 +55,6 @@ void attachDevices() {
|
|||||||
if (rotation != lv_display_get_rotation(primary_lvgl_display)) {
|
if (rotation != lv_display_get_rotation(primary_lvgl_display)) {
|
||||||
lv_display_set_rotation(primary_lvgl_display, rotation);
|
lv_display_set_rotation(primary_lvgl_display, rotation);
|
||||||
}
|
}
|
||||||
applyFontSize(settings.fontSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start touch
|
// Start touch
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -7,13 +7,11 @@
|
|||||||
#include "MatrixRainScreensaver.h"
|
#include "MatrixRainScreensaver.h"
|
||||||
#include "MystifyScreensaver.h"
|
#include "MystifyScreensaver.h"
|
||||||
#include "StackChanScreensaver.h"
|
#include "StackChanScreensaver.h"
|
||||||
#include "McpScreensaver.h"
|
|
||||||
|
|
||||||
|
#include <tactility/log.h>
|
||||||
#include <Tactility/CoreDefines.h>
|
#include <Tactility/CoreDefines.h>
|
||||||
#include <Tactility/hal/display/DisplayDevice.h>
|
#include <Tactility/hal/display/DisplayDevice.h>
|
||||||
#include <Tactility/hal/power/PowerDevice.h>
|
|
||||||
#include <Tactility/lvgl/LvglSync.h>
|
#include <Tactility/lvgl/LvglSync.h>
|
||||||
#include <Tactility/mcp/McpSystem.h>
|
|
||||||
#include <Tactility/service/ServiceContext.h>
|
#include <Tactility/service/ServiceContext.h>
|
||||||
#include <Tactility/service/ServiceManifest.h>
|
#include <Tactility/service/ServiceManifest.h>
|
||||||
#include <Tactility/service/ServiceRegistration.h>
|
#include <Tactility/service/ServiceRegistration.h>
|
||||||
@@ -30,22 +28,6 @@ static std::shared_ptr<hal::display::DisplayDevice> getDisplay() {
|
|||||||
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isDeviceCharging() {
|
|
||||||
bool charging = false;
|
|
||||||
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&charging](const auto& power) {
|
|
||||||
if (!power->supportsMetric(hal::power::PowerDevice::MetricType::IsCharging)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
hal::power::PowerDevice::MetricData data;
|
|
||||||
if (power->getMetric(hal::power::PowerDevice::MetricType::IsCharging, data) && data.valueAsBool) {
|
|
||||||
charging = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
return charging;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DisplayIdleService::stopScreensaverCb(lv_event_t* e) {
|
void DisplayIdleService::stopScreensaverCb(lv_event_t* e) {
|
||||||
auto* self = static_cast<DisplayIdleService*>(lv_event_get_user_data(e));
|
auto* self = static_cast<DisplayIdleService*>(lv_event_get_user_data(e));
|
||||||
lv_event_stop_bubbling(e);
|
lv_event_stop_bubbling(e);
|
||||||
@@ -121,9 +103,6 @@ void DisplayIdleService::activateScreensaver() {
|
|||||||
case settings::display::ScreensaverType::StackChan:
|
case settings::display::ScreensaverType::StackChan:
|
||||||
screensaver = std::make_unique<StackChanScreensaver>();
|
screensaver = std::make_unique<StackChanScreensaver>();
|
||||||
break;
|
break;
|
||||||
case settings::display::ScreensaverType::McpScreen:
|
|
||||||
screensaver = std::make_unique<McpScreensaver>();
|
|
||||||
break;
|
|
||||||
case settings::display::ScreensaverType::None:
|
case settings::display::ScreensaverType::None:
|
||||||
default:
|
default:
|
||||||
// Just black screen, no animated screensaver
|
// Just black screen, no animated screensaver
|
||||||
@@ -200,28 +179,19 @@ void DisplayIdleService::tick() {
|
|||||||
displayDimmed = false;
|
displayDimmed = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool charging_blocks = cachedDisplaySettings.disableScreensaverWhenCharging && isDeviceCharging();
|
|
||||||
if (!displayDimmed && inactive_ms >= cachedDisplaySettings.backlightTimeoutMs) {
|
if (!displayDimmed && inactive_ms >= cachedDisplaySettings.backlightTimeoutMs) {
|
||||||
if (charging_blocks) {
|
if (!lvgl::lock(100)) {
|
||||||
// Skip screensaver while charging
|
return; // Retry on next tick
|
||||||
} else {
|
|
||||||
if (!lvgl::lock(100)) {
|
|
||||||
return; // Retry on next tick
|
|
||||||
}
|
|
||||||
activateScreensaver();
|
|
||||||
lvgl::unlock();
|
|
||||||
// Turn off backlight for "None" screensaver (just black screen)
|
|
||||||
if (cachedDisplaySettings.screensaverType == settings::display::ScreensaverType::None) {
|
|
||||||
display->setBacklightDuty(0);
|
|
||||||
}
|
|
||||||
displayDimmed = true;
|
|
||||||
}
|
}
|
||||||
} else if (displayDimmed) {
|
activateScreensaver();
|
||||||
if (inactive_ms < kWakeActivityThresholdMs) {
|
lvgl::unlock();
|
||||||
stopScreensaver();
|
// Turn off backlight for "None" screensaver (just black screen)
|
||||||
} else if (charging_blocks) {
|
if (cachedDisplaySettings.screensaverType == settings::display::ScreensaverType::None) {
|
||||||
stopScreensaver();
|
display->setBacklightDuty(0);
|
||||||
}
|
}
|
||||||
|
displayDimmed = true;
|
||||||
|
} else if (displayDimmed && (inactive_ms < kWakeActivityThresholdMs)) {
|
||||||
|
stopScreensaver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,61 +254,6 @@ bool DisplayIdleService::isScreensaverActive() const {
|
|||||||
return screensaverOverlay != nullptr;
|
return screensaverOverlay != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayIdleService::startMcpScreensaver() {
|
|
||||||
if (!lvgl::lock(200)) {
|
|
||||||
LOG_W(TAG, "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 if the display supports it
|
|
||||||
auto display = getDisplay();
|
|
||||||
if (display != nullptr && display->supportsBacklightDuty()) {
|
|
||||||
uint8_t duty = cachedDisplaySettings.backlightDuty;
|
|
||||||
if (duty == 0) duty = 255; // ensure visible if settings not loaded / default
|
|
||||||
display->setBacklightDuty(duty);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
LOG_I(TAG, "MCP screensaver activated");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DisplayIdleService::reloadSettings() {
|
void DisplayIdleService::reloadSettings() {
|
||||||
// Set flag for thread-safe reload - actual reload happens in tick()
|
// Set flag for thread-safe reload - actual reload happens in tick()
|
||||||
settingsReloadRequested.store(true, std::memory_order_release);
|
settingsReloadRequested.store(true, std::memory_order_release);
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
#ifdef ESP_PLATFORM
|
|
||||||
|
|
||||||
#include "McpScreensaver.h"
|
|
||||||
#include <Tactility/mcp/McpSystem.h>
|
|
||||||
#include <tactility/log.h>
|
|
||||||
|
|
||||||
constexpr auto* TAG = "McpScreensaver";
|
|
||||||
#include <esp_heap_caps.h>
|
|
||||||
|
|
||||||
namespace tt::service::displayidle {
|
|
||||||
|
|
||||||
|
|
||||||
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) {
|
|
||||||
LOG_E(TAG, "Failed to allocate %uB 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
|
|
||||||
|
|
||||||
LOG_I(TAG, "McpScreensaver started (%dx%d)", (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;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_I(TAG, "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
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#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
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,6 @@
|
|||||||
#include <Tactility/service/webserver/AssetVersion.h>
|
#include <Tactility/service/webserver/AssetVersion.h>
|
||||||
#include <Tactility/service/ServiceManifest.h>
|
#include <Tactility/service/ServiceManifest.h>
|
||||||
#include <Tactility/settings/WebServerSettings.h>
|
#include <Tactility/settings/WebServerSettings.h>
|
||||||
#include <Tactility/settings/McpSettings.h>
|
|
||||||
#include <Tactility/mcp/McpSystem.h>
|
|
||||||
#include <Tactility/MountPoints.h>
|
#include <Tactility/MountPoints.h>
|
||||||
#include <Tactility/file/File.h>
|
#include <Tactility/file/File.h>
|
||||||
#include <Tactility/lvgl/Statusbar.h>
|
#include <Tactility/lvgl/Statusbar.h>
|
||||||
@@ -217,8 +215,7 @@ bool WebServerService::onStart(ServiceContext& service) {
|
|||||||
lock.lock();
|
lock.lock();
|
||||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||||
g_settingsCached = true;
|
g_settingsCached = true;
|
||||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
serverEnabled = g_cachedSettings.webServerEnabled;
|
||||||
serverEnabled = g_cachedSettings.webServerEnabled || mcpSettings.mcpEnabled;
|
|
||||||
}
|
}
|
||||||
// Subscribe to settings change events to refresh cache
|
// Subscribe to settings change events to refresh cache
|
||||||
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
||||||
@@ -262,17 +259,13 @@ void WebServerService::onStop(ServiceContext& service) {
|
|||||||
void WebServerService::setEnabled(bool enabled) {
|
void WebServerService::setEnabled(bool enabled) {
|
||||||
auto lock = mutex.asScopedLock();
|
auto lock = mutex.asScopedLock();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (!httpServer || !httpServer->isStarted()) {
|
if (!httpServer || !httpServer->isStarted()) {
|
||||||
startServer();
|
startServer();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Stop only if both web server and MCP are disabled
|
if (httpServer && httpServer->isStarted()) {
|
||||||
auto wsSettings = settings::webserver::loadOrGetDefault();
|
|
||||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
|
||||||
bool anyEnabled = wsSettings.webServerEnabled || mcpSettings.mcpEnabled;
|
|
||||||
if (!anyEnabled && httpServer && httpServer->isStarted()) {
|
|
||||||
stopServer();
|
stopServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -521,11 +514,6 @@ bool WebServerService::startServer() {
|
|||||||
LOG_I(TAG, "HTTP server started successfully on port %u", (unsigned)settings.webServerPort);
|
LOG_I(TAG, "HTTP server started successfully on port %u", (unsigned)settings.webServerPort);
|
||||||
publish_event(this, WebServerEvent::WebServerStarted);
|
publish_event(this, WebServerEvent::WebServerStarted);
|
||||||
|
|
||||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
|
||||||
if (mcpSettings.mcpEnabled) {
|
|
||||||
mcp::startVideoStreamServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show statusbar icon
|
// Show statusbar icon
|
||||||
if (statusbarIconId >= 0) {
|
if (statusbarIconId >= 0) {
|
||||||
lvgl::statusbar_icon_set_image(statusbarIconId, LVGL_ICON_STATUSBAR_CLOUD);
|
lvgl::statusbar_icon_set_image(statusbarIconId, LVGL_ICON_STATUSBAR_CLOUD);
|
||||||
@@ -545,8 +533,6 @@ void WebServerService::stopServer() {
|
|||||||
httpServer->stop();
|
httpServer->stop();
|
||||||
httpServer.reset();
|
httpServer.reset();
|
||||||
|
|
||||||
mcp::stopVideoStreamServer();
|
|
||||||
|
|
||||||
// Stop AP mode WiFi if we started it
|
// Stop AP mode WiFi if we started it
|
||||||
if (apWifiInitialized || apNetif != nullptr) {
|
if (apWifiInitialized || apNetif != nullptr) {
|
||||||
stopApMode();
|
stopApMode();
|
||||||
@@ -1039,24 +1025,15 @@ esp_err_t WebServerService::handleApiGet(httpd_req_t* request) {
|
|||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// API POST dispatcher - all POST endpoints require authentication except MCP
|
// API POST dispatcher - all POST endpoints require authentication
|
||||||
esp_err_t WebServerService::handleApiPost(httpd_req_t* request) {
|
esp_err_t WebServerService::handleApiPost(httpd_req_t* request) {
|
||||||
const char* uri = request->uri;
|
|
||||||
|
|
||||||
// MCP endpoints are unauthenticated (local network)
|
|
||||||
if (strncmp(uri, "/api/mcp", 8) == 0) {
|
|
||||||
return handleApiMcp(request);
|
|
||||||
}
|
|
||||||
if (strncmp(uri, "/api/screen/raw", 15) == 0) {
|
|
||||||
return handleApiScreenRaw(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool authPassed = false;
|
bool authPassed = false;
|
||||||
esp_err_t authResult = validateRequestAuth(request, authPassed);
|
esp_err_t authResult = validateRequestAuth(request, authPassed);
|
||||||
if (!authPassed) {
|
if (!authPassed) {
|
||||||
return authResult;
|
return authResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* uri = request->uri;
|
||||||
if (strncmp(uri, "/api/apps/run", 13) == 0) {
|
if (strncmp(uri, "/api/apps/run", 13) == 0) {
|
||||||
return handleApiAppsRun(request);
|
return handleApiAppsRun(request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,11 @@ static std::string getSettingsFilePath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto* SETTINGS_KEY_ORIENTATION = "orientation";
|
constexpr auto* SETTINGS_KEY_ORIENTATION = "orientation";
|
||||||
constexpr auto* SETTINGS_KEY_FONT_SIZE = "fontSize";
|
|
||||||
constexpr auto* SETTINGS_KEY_GAMMA_CURVE = "gammaCurve";
|
constexpr auto* SETTINGS_KEY_GAMMA_CURVE = "gammaCurve";
|
||||||
constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
|
constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
|
||||||
constexpr auto* SETTINGS_KEY_TIMEOUT_ENABLED = "backlightTimeoutEnabled";
|
constexpr auto* SETTINGS_KEY_TIMEOUT_ENABLED = "backlightTimeoutEnabled";
|
||||||
constexpr auto* SETTINGS_KEY_TIMEOUT_MS = "backlightTimeoutMs";
|
constexpr auto* SETTINGS_KEY_TIMEOUT_MS = "backlightTimeoutMs";
|
||||||
constexpr auto* SETTINGS_KEY_SCREENSAVER_TYPE = "screensaverType";
|
constexpr auto* SETTINGS_KEY_SCREENSAVER_TYPE = "screensaverType";
|
||||||
constexpr auto* SETTINGS_KEY_DISABLE_WHEN_CHARGING = "disableScreensaverWhenCharging";
|
|
||||||
|
|
||||||
static Orientation getDefaultOrientation() {
|
static Orientation getDefaultOrientation() {
|
||||||
auto* display = lv_display_get_default();
|
auto* display = lv_display_get_default();
|
||||||
@@ -72,34 +70,6 @@ static bool fromString(const std::string& str, Orientation& orientation) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string toString(FontSize font_size) {
|
|
||||||
switch (font_size) {
|
|
||||||
using enum FontSize;
|
|
||||||
case Small:
|
|
||||||
return "Small";
|
|
||||||
case Default:
|
|
||||||
return "Default";
|
|
||||||
case Large:
|
|
||||||
return "Large";
|
|
||||||
default:
|
|
||||||
std::unreachable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool fromString(const std::string& str, FontSize& font_size) {
|
|
||||||
if (str == "Small") {
|
|
||||||
font_size = FontSize::Small;
|
|
||||||
return true;
|
|
||||||
} else if (str == "Default") {
|
|
||||||
font_size = FontSize::Default;
|
|
||||||
return true;
|
|
||||||
} else if (str == "Large") {
|
|
||||||
font_size = FontSize::Large;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string toString(ScreensaverType type) {
|
static std::string toString(ScreensaverType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
using enum ScreensaverType;
|
using enum ScreensaverType;
|
||||||
@@ -113,8 +83,6 @@ static std::string toString(ScreensaverType type) {
|
|||||||
return "MatrixRain";
|
return "MatrixRain";
|
||||||
case StackChan:
|
case StackChan:
|
||||||
return "StackChan";
|
return "StackChan";
|
||||||
case McpScreen:
|
|
||||||
return "McpScreen";
|
|
||||||
default:
|
default:
|
||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
@@ -136,9 +104,6 @@ static bool fromString(const std::string& str, ScreensaverType& type) {
|
|||||||
} else if (str == "StackChan") {
|
} else if (str == "StackChan") {
|
||||||
type = ScreensaverType::StackChan;
|
type = ScreensaverType::StackChan;
|
||||||
return true;
|
return true;
|
||||||
} else if (str == "McpScreen") {
|
|
||||||
type = ScreensaverType::McpScreen;
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -161,12 +126,6 @@ bool load(DisplaySettings& settings) {
|
|||||||
orientation = getDefaultOrientation();
|
orientation = getDefaultOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto font_size_entry = map.find(SETTINGS_KEY_FONT_SIZE);
|
|
||||||
FontSize font_size = FontSize::Default;
|
|
||||||
if (font_size_entry != map.end()) {
|
|
||||||
fromString(font_size_entry->second, font_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto gamma_entry = map.find(SETTINGS_KEY_GAMMA_CURVE);
|
auto gamma_entry = map.find(SETTINGS_KEY_GAMMA_CURVE);
|
||||||
int gamma_curve = 0;
|
int gamma_curve = 0;
|
||||||
if (gamma_entry != map.end()) {
|
if (gamma_entry != map.end()) {
|
||||||
@@ -200,20 +159,12 @@ bool load(DisplaySettings& settings) {
|
|||||||
fromString(screensaver_entry->second, screensaver_type);
|
fromString(screensaver_entry->second, screensaver_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disable_when_charging = false;
|
|
||||||
auto charging_entry = map.find(SETTINGS_KEY_DISABLE_WHEN_CHARGING);
|
|
||||||
if (charging_entry != map.end()) {
|
|
||||||
disable_when_charging = (charging_entry->second == "1" || charging_entry->second == "true" || charging_entry->second == "True");
|
|
||||||
}
|
|
||||||
|
|
||||||
settings.orientation = orientation;
|
settings.orientation = orientation;
|
||||||
settings.fontSize = font_size;
|
|
||||||
settings.gammaCurve = gamma_curve;
|
settings.gammaCurve = gamma_curve;
|
||||||
settings.backlightDuty = backlight_duty;
|
settings.backlightDuty = backlight_duty;
|
||||||
settings.backlightTimeoutEnabled = timeout_enabled;
|
settings.backlightTimeoutEnabled = timeout_enabled;
|
||||||
settings.backlightTimeoutMs = timeout_ms;
|
settings.backlightTimeoutMs = timeout_ms;
|
||||||
settings.screensaverType = screensaver_type;
|
settings.screensaverType = screensaver_type;
|
||||||
settings.disableScreensaverWhenCharging = disable_when_charging;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -221,13 +172,11 @@ bool load(DisplaySettings& settings) {
|
|||||||
DisplaySettings getDefault() {
|
DisplaySettings getDefault() {
|
||||||
return DisplaySettings {
|
return DisplaySettings {
|
||||||
.orientation = getDefaultOrientation(),
|
.orientation = getDefaultOrientation(),
|
||||||
.fontSize = FontSize::Default,
|
|
||||||
.gammaCurve = 1,
|
.gammaCurve = 1,
|
||||||
.backlightDuty = 200,
|
.backlightDuty = 200,
|
||||||
.backlightTimeoutEnabled = false,
|
.backlightTimeoutEnabled = false,
|
||||||
.backlightTimeoutMs = 60000,
|
.backlightTimeoutMs = 60000,
|
||||||
.screensaverType = ScreensaverType::BouncingBalls,
|
.screensaverType = ScreensaverType::BouncingBalls
|
||||||
.disableScreensaverWhenCharging = false
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,11 +193,9 @@ bool save(const DisplaySettings& settings) {
|
|||||||
map[SETTINGS_KEY_BACKLIGHT_DUTY] = std::to_string(settings.backlightDuty);
|
map[SETTINGS_KEY_BACKLIGHT_DUTY] = std::to_string(settings.backlightDuty);
|
||||||
map[SETTINGS_KEY_GAMMA_CURVE] = std::to_string(settings.gammaCurve);
|
map[SETTINGS_KEY_GAMMA_CURVE] = std::to_string(settings.gammaCurve);
|
||||||
map[SETTINGS_KEY_ORIENTATION] = toString(settings.orientation);
|
map[SETTINGS_KEY_ORIENTATION] = toString(settings.orientation);
|
||||||
map[SETTINGS_KEY_FONT_SIZE] = toString(settings.fontSize);
|
|
||||||
map[SETTINGS_KEY_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
|
map[SETTINGS_KEY_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
|
||||||
map[SETTINGS_KEY_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
|
map[SETTINGS_KEY_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
|
||||||
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
|
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
|
||||||
map[SETTINGS_KEY_DISABLE_WHEN_CHARGING] = settings.disableScreensaverWhenCharging ? "1" : "0";
|
|
||||||
auto settings_path = getSettingsFilePath();
|
auto settings_path = getSettingsFilePath();
|
||||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
#include <Tactility/settings/McpSettings.h>
|
|
||||||
#include <Tactility/file/PropertiesFile.h>
|
|
||||||
#include <Tactility/file/File.h>
|
|
||||||
#include <tactility/log.h>
|
|
||||||
|
|
||||||
constexpr auto* TAG = "McpSettings";
|
|
||||||
#include <Tactility/Paths.h>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace tt::settings::mcp {
|
|
||||||
|
|
||||||
|
|
||||||
static std::string getSettingsFilePath() {
|
|
||||||
return getUserDataPath() + "/settings/mcp.properties";
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr auto* KEY_MCP_ENABLED = "mcpEnabled";
|
|
||||||
|
|
||||||
bool load(McpSettings& settings) {
|
|
||||||
auto settings_path = getSettingsFilePath();
|
|
||||||
if (!file::isFile(settings_path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
std::map<std::string, std::string> map;
|
|
||||||
if (!file::loadPropertiesFile(settings_path, 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();
|
|
||||||
if (!save(settings)) {
|
|
||||||
LOG_W(TAG, "Failed to save default MCP settings");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool save(const McpSettings& settings) {
|
|
||||||
std::map<std::string, std::string> map;
|
|
||||||
map[KEY_MCP_ENABLED] = settings.mcpEnabled ? "true" : "false";
|
|
||||||
|
|
||||||
auto settings_path = getSettingsFilePath();
|
|
||||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
|
||||||
LOG_E(TAG, "Failed to create parent dir for %s", settings_path.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file::savePropertiesFile(settings_path, map)) {
|
|
||||||
LOG_E(TAG, "Failed to save MCP settings to %s", settings_path.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
@@ -81,70 +81,3 @@ TEST_CASE("parseManifestV2() should fail when the app id is invalid") {
|
|||||||
AppManifest manifest;
|
AppManifest manifest;
|
||||||
CHECK_EQ(parseManifestV2(properties, manifest), false);
|
CHECK_EQ(parseManifestV2(properties, manifest), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("parseAppFlagsString() should parse various flag combinations") {
|
|
||||||
CHECK_EQ(parseAppFlagsString(""), 0);
|
|
||||||
CHECK_EQ(parseAppFlagsString("None"), 0);
|
|
||||||
CHECK_EQ(parseAppFlagsString("HideStatusBar"), AppManifest::Flags::HideStatusBar);
|
|
||||||
CHECK_EQ(parseAppFlagsString("hidden"), AppManifest::Flags::Hidden);
|
|
||||||
CHECK_EQ(parseAppFlagsString("HideStatusBar,Hidden"), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
|
||||||
CHECK_EQ(parseAppFlagsString(" hidestatusbar , hidden "), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
|
||||||
CHECK_EQ(parseAppFlagsString("HideStatusBar, Hidden"), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("parseManifest() should parse V1 flags for fullscreen") {
|
|
||||||
TestFile file("test-manifest-v1-flags.properties");
|
|
||||||
file.writeData(
|
|
||||||
"[manifest]\n"
|
|
||||||
"version=0.1\n"
|
|
||||||
"[target]\n"
|
|
||||||
"sdk=0.0.0\n"
|
|
||||||
"platforms=esp32\n"
|
|
||||||
"[app]\n"
|
|
||||||
"id=one.tactility.sdktest\n"
|
|
||||||
"versionName=0.1.0\n"
|
|
||||||
"versionCode=1\n"
|
|
||||||
"name=SDK Test\n"
|
|
||||||
"flags=HideStatusBar\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
AppManifest manifest;
|
|
||||||
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
|
||||||
CHECK_EQ(manifest.appFlags & AppManifest::Flags::HideStatusBar, AppManifest::Flags::HideStatusBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("parseManifest() should parse V2 flags for fullscreen") {
|
|
||||||
TestFile file("test-manifest-v2-flags.properties");
|
|
||||||
file.writeData(
|
|
||||||
"manifest.version=0.1\n"
|
|
||||||
"target.sdk=0.0.0\n"
|
|
||||||
"target.platforms=esp32\n"
|
|
||||||
"app.id=one.tactility.sdktest\n"
|
|
||||||
"app.version.name=0.1.0\n"
|
|
||||||
"app.version.code=1\n"
|
|
||||||
"app.name=SDK Test\n"
|
|
||||||
"app.flags=HideStatusBar\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
AppManifest manifest;
|
|
||||||
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
|
||||||
CHECK_EQ(manifest.appFlags & AppManifest::Flags::HideStatusBar, AppManifest::Flags::HideStatusBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("parseManifest() should parse combined flags") {
|
|
||||||
TestFile file("test-manifest-v2-flags2.properties");
|
|
||||||
file.writeData(
|
|
||||||
"manifest.version=0.1\n"
|
|
||||||
"target.sdk=0.0.0\n"
|
|
||||||
"target.platforms=esp32\n"
|
|
||||||
"app.id=one.tactility.sdktest\n"
|
|
||||||
"app.version.name=0.1.0\n"
|
|
||||||
"app.version.code=1\n"
|
|
||||||
"app.name=SDK Test\n"
|
|
||||||
"app.flags=HideStatusBar,Hidden\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
AppManifest manifest;
|
|
||||||
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
|
||||||
CHECK_EQ(manifest.appFlags, (AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,4 +3,4 @@
|
|||||||
nvs, data, nvs, 0x9000, 0x6000,
|
nvs, data, nvs, 0x9000, 0x6000,
|
||||||
phy_init, data, phy, 0xf000, 0x1000,
|
phy_init, data, phy, 0xf000, 0x1000,
|
||||||
factory, app, factory, 0x10000, 4M,
|
factory, app, factory, 0x10000, 4M,
|
||||||
system, data, fat, , 512k,
|
system, data, fat, , 100k,
|
||||||
|
|||||||
|
Reference in New Issue
Block a user