Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8ee763f3d | |||
| 9e3dc3dc15 | |||
| a321bfeb4c | |||
| f95cd7df4c |
@@ -311,11 +311,39 @@ def test_compile_missing_config():
|
|||||||
print("PASSED")
|
print("PASSED")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def test_es3c35p_uses_current_runtime_contract():
|
||||||
|
print("Running test_es3c35p_uses_current_runtime_contract...")
|
||||||
|
repository_root = os.path.abspath(os.path.join(SCRIPT_DIR, "..", "..", ".."))
|
||||||
|
device_dir = os.path.join(repository_root, "Devices", "es3c35p")
|
||||||
|
with open(os.path.join(device_dir, "device.properties")) as f:
|
||||||
|
properties = f.read()
|
||||||
|
with open(os.path.join(device_dir, "es3c35p.dts")) as f:
|
||||||
|
devicetree = f.read()
|
||||||
|
|
||||||
|
requirements = [
|
||||||
|
("apps.launcherAppId=tactility.launcher" in properties, "current launcher app id"),
|
||||||
|
("hardware.tinyUsb=" not in properties, "no obsolete hardware.tinyUsb property"),
|
||||||
|
('wifi0 {\n\t\tcompatible = "espressif,esp32-wifi-pinned";\n\t};' in devicetree,
|
||||||
|
"Wi-Fi enabled for web server and MCP"),
|
||||||
|
('ble0 {\n\t\tcompatible = "espressif,esp32-ble";\n\t};' in devicetree,
|
||||||
|
"BLE node matches hardware.bluetooth=true"),
|
||||||
|
]
|
||||||
|
missing = [description for condition, description in requirements if not condition]
|
||||||
|
if missing:
|
||||||
|
print("FAILED: " + ", ".join(missing))
|
||||||
|
return False
|
||||||
|
|
||||||
|
print("PASSED")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
tests = [
|
tests = [
|
||||||
test_compile_success,
|
test_compile_success,
|
||||||
test_compile_invalid_dts,
|
test_compile_invalid_dts,
|
||||||
test_compile_missing_config,
|
test_compile_missing_config,
|
||||||
|
test_es3c35p_uses_current_runtime_contract,
|
||||||
test_minmax_within_range_succeeds,
|
test_minmax_within_range_succeeds,
|
||||||
test_minmax_below_minimum_fails,
|
test_minmax_below_minimum_fails,
|
||||||
test_minmax_above_maximum_fails,
|
test_minmax_above_maximum_fails,
|
||||||
|
|||||||
Executable
+87
@@ -0,0 +1,87 @@
|
|||||||
|
#!/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.
|
After Width: | Height: | Size: 298 KiB |
@@ -19,3 +19,7 @@ display.dpi=143
|
|||||||
lvgl.colorDepth=16
|
lvgl.colorDepth=16
|
||||||
|
|
||||||
storage.userDataLocation=SD
|
storage.userDataLocation=SD
|
||||||
|
|
||||||
|
# Launcher clock and full-screen wallpaper
|
||||||
|
sdkconfig.CONFIG_LV_FONT_MONTSERRAT_48=y
|
||||||
|
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=1048576
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS "source/module.cpp"
|
||||||
|
REQUIRES TactilityKernel
|
||||||
|
)
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
general.vendor=LCDWIKI/Hosyond
|
||||||
|
general.name=ES3C35P
|
||||||
|
|
||||||
|
apps.launcherAppId=tactility.launcher
|
||||||
|
|
||||||
|
hardware.target=ESP32S3
|
||||||
|
hardware.flashSize=16MB
|
||||||
|
hardware.spiRam=true
|
||||||
|
hardware.spiRamMode=OCT
|
||||||
|
hardware.spiRamSpeed=120M
|
||||||
|
hardware.esptoolFlashFreq=120M
|
||||||
|
hardware.bluetooth=true
|
||||||
|
|
||||||
|
display.size=3.5"
|
||||||
|
display.shape=rectangle
|
||||||
|
display.dpi=165
|
||||||
|
|
||||||
|
lvgl.colorDepth=16
|
||||||
|
|
||||||
|
storage.userDataLocation=SD
|
||||||
|
|
||||||
|
dependencies.useDeprecatedHal=false
|
||||||
|
|
||||||
|
# Launcher clock and full-screen wallpaper
|
||||||
|
sdkconfig.CONFIG_LV_FONT_MONTSERRAT_48=y
|
||||||
|
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=1048576
|
||||||
|
sdkconfig.CONFIG_LV_IMAGE_HEADER_CACHE_DEF_CNT=16
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
dependencies:
|
||||||
|
- Platforms/platform-esp32
|
||||||
|
- Drivers/st77922-module
|
||||||
|
- Drivers/es8311-module
|
||||||
|
- Drivers/audio-stream-module
|
||||||
|
dts: es3c35p.dts
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/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";
|
||||||
|
};
|
||||||
|
|
||||||
|
ble0 {
|
||||||
|
compatible = "espressif,esp32-ble";
|
||||||
|
};
|
||||||
|
|
||||||
|
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>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
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>;
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#include <tactility/module.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
Module es3c35p_module = {
|
||||||
|
.name = "es3c35p"
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/../../Buildscripts/module.cmake")
|
||||||
|
|
||||||
|
file(GLOB_RECURSE SOURCE_FILES "source/*.c*")
|
||||||
|
|
||||||
|
tactility_add_module(st77922-module
|
||||||
|
SRCS ${SOURCE_FILES}
|
||||||
|
INCLUDE_DIRS include/
|
||||||
|
REQUIRES TactilityKernel platform-esp32 esp_lcd_st77922 driver
|
||||||
|
)
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
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
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
bindings: bindings
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tactility/bindings/bindings.h>
|
||||||
|
#include <drivers/st77922.h>
|
||||||
|
|
||||||
|
DEFINE_DEVICETREE(st77922, struct St77922Config)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tactility/bindings/bindings.h>
|
||||||
|
#include <drivers/st77922_touch.h>
|
||||||
|
|
||||||
|
DEFINE_DEVICETREE(st77922_touch, struct St77922TouchConfig)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <tactility/device.h>
|
||||||
|
|
||||||
|
struct St77922Config {
|
||||||
|
uint16_t horizontal_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;
|
||||||
|
uint8_t transaction_queue_depth;
|
||||||
|
struct Device* backlight;
|
||||||
|
};
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// 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;
|
||||||
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <tactility/module.h>
|
||||||
|
|
||||||
|
extern Module st77922_module;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// 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"
|
||||||
@@ -0,0 +1,270 @@
|
|||||||
|
// 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
|
||||||
|
};
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// 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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <esp_lcd_st77922.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const st77922_lcd_init_cmd_t* st77922_board_init_commands(size_t* count);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
// 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
|
||||||
|
};
|
||||||
@@ -494,6 +494,12 @@ 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),
|
||||||
|
|||||||
@@ -4,11 +4,26 @@
|
|||||||
#include <app/scheduler.h>
|
#include <app/scheduler.h>
|
||||||
#include <app/start.h>
|
#include <app/start.h>
|
||||||
|
|
||||||
|
#include <Tactility/DeprecatedPaths.h>
|
||||||
|
#include <Tactility/MountPoints.h>
|
||||||
|
#include <Tactility/Tactility.h>
|
||||||
|
#include <Tactility/app/setup/Setup.h>
|
||||||
|
#include <Tactility/file/File.h>
|
||||||
|
#include <Tactility/lvgl/Lvgl.h>
|
||||||
|
#include <Tactility/service/wifi/Wifi.h>
|
||||||
|
#include <Tactility/settings/BootSettings.h>
|
||||||
|
#include <Tactility/settings/Time.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <ctime>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
#include <lvgl/icons/launcher.h>
|
|
||||||
#include <lvgl/fonts.h>
|
#include <lvgl/fonts.h>
|
||||||
|
#include <lvgl/icons/launcher.h>
|
||||||
|
#include <lvgl/icons/statusbar.h>
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
|
|
||||||
#include <lvgl_window_manager/window_manager.h>
|
#include <lvgl_window_manager/window_manager.h>
|
||||||
@@ -20,64 +35,29 @@
|
|||||||
#include <tactility/log.h>
|
#include <tactility/log.h>
|
||||||
#include <tactility/memory.h>
|
#include <tactility/memory.h>
|
||||||
|
|
||||||
#include <Tactility/app/setup/Setup.h>
|
|
||||||
#include <Tactility/settings/BootSettings.h>
|
|
||||||
#include <Tactility/Tactility.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";
|
||||||
|
constexpr lv_color_t TEXT_COLOR = LV_COLOR_MAKE(0xF8, 0xF5, 0xF2);
|
||||||
|
constexpr lv_color_t MUTED_TEXT_COLOR = LV_COLOR_MAKE(0xDF, 0xD6, 0xD3);
|
||||||
|
constexpr lv_color_t ACCENT_COLOR = LV_COLOR_MAKE(0xEC, 0x75, 0x69);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
uint32_t getButtonPadding(UiDensity density, uint32_t buttonSize) {
|
struct LauncherWidgets {
|
||||||
if (density == LVGL_UI_DENSITY_COMPACT) {
|
lv_obj_t* timeLabel = nullptr;
|
||||||
return 0;
|
lv_obj_t* dateLabel = nullptr;
|
||||||
} else {
|
lv_obj_t* dataLabel = nullptr;
|
||||||
return buttonSize / 8;
|
lv_obj_t* statusLabel = nullptr;
|
||||||
}
|
lv_timer_t* updateTimer = nullptr;
|
||||||
}
|
};
|
||||||
|
|
||||||
int32_t computeButtonMargin(int32_t available_span, int32_t total_button_size) {
|
void onAppPressed(lv_event_t* event) {
|
||||||
const int32_t usable = std::max<int32_t>(0, available_span - (3 * total_button_size));
|
const auto* app_id = static_cast<const char*>(lv_event_get_user_data(event));
|
||||||
return std::min<int32_t>(usable / 16, total_button_size / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onAppPressed(lv_event_t* e) {
|
|
||||||
auto* appId = static_cast<const char*>(lv_event_get_user_data(e));
|
|
||||||
uint32_t instance_id = 0;
|
uint32_t instance_id = 0;
|
||||||
app_start(appId, 0, nullptr, &instance_id);
|
app_start(app_id, 0, nullptr, &instance_id);
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_t* createAppButton(lv_obj_t* parent, UiDensity uiDensity, const char* imageFile, const char* appId, int32_t itemMargin, bool isLandscape) {
|
|
||||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldShowPowerButton() {
|
bool shouldShowPowerButton() {
|
||||||
@@ -85,180 +65,288 @@ bool shouldShowPowerButton() {
|
|||||||
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; // stop iterating
|
return false;
|
||||||
} else {
|
|
||||||
return true; // continue iterating
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
return show_power_button;
|
return show_power_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onButtonsWrapperResized(lv_event_t* e);
|
int getBatteryPercentage() {
|
||||||
|
Device* power = nullptr;
|
||||||
|
device_for_each_of_type(&POWER_SUPPLY_TYPE, &power, [](Device* device, void* context) {
|
||||||
|
if (device_is_ready(device) && power_supply_supports_property(device, POWER_SUPPLY_PROP_CAPACITY)) {
|
||||||
|
*static_cast<Device**>(context) = device;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (power == nullptr) return -1;
|
||||||
|
|
||||||
// The screen object outlives this window's own widgets (lvgl-window-manager deletes and
|
PowerSupplyPropertyValue charge_level;
|
||||||
// recreates only the topmost window's widget on every app switch, not the screen itself), so
|
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CAPACITY, &charge_level) != ERROR_NONE) return -1;
|
||||||
// the LV_EVENT_SIZE_CHANGED callback registered on it must be removed once buttons_wrapper is
|
return std::clamp(charge_level.int_value, 0, 100);
|
||||||
// destroyed, to avoid a dangling user-data pointer the next time the display rotates while a
|
|
||||||
// different window is topmost.
|
|
||||||
void onButtonsWrapperDeleted(lv_event_t* e) {
|
|
||||||
auto* buttons_wrapper = lv_event_get_target_obj(e);
|
|
||||||
auto* screen = lv_obj_get_screen(buttons_wrapper);
|
|
||||||
lv_obj_remove_event_cb_with_user_data(screen, onButtonsWrapperResized, buttons_wrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-applies the flex direction and per-button margins when the display orientation changes
|
const char* getWifiStatusIcon(service::wifi::RadioState state) {
|
||||||
// while the launcher is the visible window (these are decided once at createWidgets() based on
|
using enum service::wifi::RadioState;
|
||||||
// the resolution at that time, so a later rotation needs this to catch up).
|
switch (state) {
|
||||||
void onButtonsWrapperResized(lv_event_t* e) {
|
case ConnectionActive: 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;
|
||||||
|
default: return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_0_BAR;
|
||||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
|
||||||
const auto button_padding = getButtonPadding(lvgl_get_ui_density(), button_size);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_set_flex_flow(buttons_wrapper, is_landscape_display ? LV_FLEX_FLOW_ROW : LV_FLEX_FLOW_COLUMN);
|
|
||||||
|
|
||||||
const int32_t margin = is_landscape_display
|
|
||||||
? computeButtonMargin(horizontal_px, total_button_size)
|
|
||||||
: computeButtonMargin(vertical_px, total_button_size);
|
|
||||||
|
|
||||||
const uint32_t child_count = lv_obj_get_child_count(buttons_wrapper);
|
|
||||||
for (uint32_t i = 0; i < child_count; i++) {
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void createWidgets(lv_obj_t* parent, void*) {
|
const char* getBatteryStatusIcon(int percentage) {
|
||||||
auto* buttons_wrapper = lv_obj_create(parent);
|
if (percentage < 0) return "";
|
||||||
|
if (percentage >= 95) return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_FULL;
|
||||||
|
if (percentage >= 64) return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_5;
|
||||||
|
if (percentage >= 32) return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_3;
|
||||||
|
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_1;
|
||||||
|
}
|
||||||
|
|
||||||
auto ui_density = lvgl_get_ui_density();
|
lv_obj_t* createAppButton(lv_obj_t* parent, const char* icon, const char* app_id, bool emphasized) {
|
||||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
auto* button = lv_button_create(parent);
|
||||||
const auto button_padding = getButtonPadding(ui_density, button_size);
|
lv_obj_set_size(button, 52, 52);
|
||||||
const auto total_button_size = button_size + (button_padding * 2);
|
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);
|
||||||
|
|
||||||
lv_obj_align(buttons_wrapper, LV_ALIGN_CENTER, 0, 0);
|
auto* image = lv_image_create(button);
|
||||||
lv_obj_set_size(buttons_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
lv_obj_set_size(image, 36, 36);
|
||||||
lv_obj_set_style_border_width(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
lv_obj_center(image);
|
||||||
lv_obj_set_flex_grow(buttons_wrapper, 1);
|
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*>(app_id));
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
// Fix for button selection
|
void updateInformation(LauncherWidgets& widgets) {
|
||||||
lv_obj_set_style_pad_all(buttons_wrapper, 6, LV_STATE_DEFAULT);
|
const std::time_t now = std::time(nullptr);
|
||||||
|
std::tm local_time {};
|
||||||
const auto* display = lv_obj_get_display(parent);
|
localtime_r(&now, &local_time);
|
||||||
const auto horizontal_px = lv_display_get_horizontal_resolution(display);
|
char time_buffer[12];
|
||||||
const auto vertical_px = lv_display_get_vertical_resolution(display);
|
char date_buffer[40];
|
||||||
const bool is_landscape_display = horizontal_px >= vertical_px;
|
if (local_time.tm_year >= 125) {
|
||||||
if (is_landscape_display) {
|
if (settings::isTimeFormat24Hour()) {
|
||||||
lv_obj_set_flex_flow(buttons_wrapper, LV_FLEX_FLOW_ROW);
|
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 {
|
} else {
|
||||||
lv_obj_set_flex_flow(buttons_wrapper, LV_FLEX_FLOW_COLUMN);
|
std::strcpy(time_buffer, "--:--");
|
||||||
|
std::strcpy(date_buffer, "Set date and time");
|
||||||
|
}
|
||||||
|
lv_label_set_text(widgets.timeLabel, time_buffer);
|
||||||
|
lv_label_set_text(widgets.dateLabel, date_buffer);
|
||||||
|
|
||||||
|
const auto wifi_state = service::wifi::getRadioState();
|
||||||
|
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_state == service::wifi::RadioState::ConnectionActive ? "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_state == service::wifi::RadioState::ConnectionActive ? "Wi-Fi connected" : "Wi-Fi offline",
|
||||||
|
sd_ready ? "SD ready" : "No SD");
|
||||||
|
}
|
||||||
|
lv_label_set_text(widgets.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(widgets.statusLabel, status_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onUpdateTimer(lv_timer_t* timer) {
|
||||||
|
updateInformation(*static_cast<LauncherWidgets*>(lv_timer_get_user_data(timer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getDefaultBackgroundPath() {
|
||||||
|
return std::string(file::MOUNT_POINT_SYSTEM) + "/app/Launcher/assets/" + BACKGROUND_ASSET;
|
||||||
|
}
|
||||||
|
|
||||||
|
void createWidgets(lv_obj_t* parent, void* user_data) {
|
||||||
|
auto& widgets = *static_cast<LauncherWidgets*>(user_data);
|
||||||
|
lv_obj_set_style_bg_color(parent, lv_color_hex(0x211A20), LV_PART_MAIN);
|
||||||
|
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);
|
||||||
|
const auto display_width = lv_display_get_horizontal_resolution(display);
|
||||||
|
const auto display_height = lv_display_get_vertical_resolution(display);
|
||||||
|
const bool is_portrait = display_height > display_width;
|
||||||
|
|
||||||
|
auto background_path = lvgl::PATH_PREFIX + getDefaultBackgroundPath();
|
||||||
|
std::string sd_card_path;
|
||||||
|
if (findFirstMountedSdCardPath(sd_card_path)) {
|
||||||
|
const auto custom_background_path = file::getChildPath(sd_card_path, CUSTOM_BACKGROUND_PATH);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int32_t margin = is_landscape_display
|
auto* background = lv_image_create(parent);
|
||||||
? computeButtonMargin(lv_display_get_horizontal_resolution(display), total_button_size)
|
lv_image_set_src(background, background_path.c_str());
|
||||||
: computeButtonMargin(lv_display_get_vertical_resolution(display), total_button_size);
|
lv_obj_align(background, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
lv_obj_add_flag(background, LV_OBJ_FLAG_IGNORE_LAYOUT);
|
||||||
|
|
||||||
auto* app_list_button = createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_APPS, "tactility.applist", margin, is_landscape_display);
|
widgets.timeLabel = lv_label_create(parent);
|
||||||
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_FOLDER, "tactility.files", margin, is_landscape_display);
|
lv_label_set_text(widgets.timeLabel, "--:--");
|
||||||
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_SETTINGS, "tactility.settings", margin, is_landscape_display);
|
lv_obj_set_style_text_color(widgets.timeLabel, TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
#if LV_FONT_MONTSERRAT_48
|
||||||
|
lv_obj_set_style_text_font(widgets.timeLabel, &lv_font_montserrat_48, LV_PART_MAIN);
|
||||||
|
#else
|
||||||
|
lv_obj_set_style_text_font(widgets.timeLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN);
|
||||||
|
#endif
|
||||||
|
lv_obj_align(widgets.timeLabel, LV_ALIGN_TOP_LEFT, 18, 58);
|
||||||
|
|
||||||
// The launcher's container is several levels below the screen, and LVGL only sends
|
widgets.dateLabel = lv_label_create(parent);
|
||||||
// LV_EVENT_SIZE_CHANGED to the screen object itself on a resolution change - so the
|
lv_obj_set_style_text_font(widgets.dateLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN);
|
||||||
// handler is attached there, with buttons_wrapper passed through as user data.
|
lv_obj_set_style_text_color(widgets.dateLabel, TEXT_COLOR, LV_PART_MAIN);
|
||||||
lv_obj_add_event_cb(lv_obj_get_screen(parent), onButtonsWrapperResized, LV_EVENT_SIZE_CHANGED, buttons_wrapper);
|
lv_obj_align(widgets.dateLabel, LV_ALIGN_TOP_LEFT, 20, 118);
|
||||||
lv_obj_add_event_cb(buttons_wrapper, onButtonsWrapperDeleted, LV_EVENT_DELETE, nullptr);
|
|
||||||
|
widgets.dataLabel = lv_label_create(parent);
|
||||||
|
lv_obj_set_width(widgets.dataLabel, is_portrait ? display_width - 40 : 225);
|
||||||
|
lv_label_set_long_mode(widgets.dataLabel, LV_LABEL_LONG_MODE_WRAP);
|
||||||
|
lv_obj_set_style_text_font(widgets.dataLabel, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_text_color(widgets.dataLabel, MUTED_TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
lv_obj_align(widgets.dataLabel, LV_ALIGN_TOP_LEFT, 20, 148);
|
||||||
|
|
||||||
|
widgets.statusLabel = lv_label_create(parent);
|
||||||
|
lv_obj_set_style_text_font(widgets.statusLabel, lvgl_get_statusbar_icon_font(), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_text_color(widgets.statusLabel, TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
lv_obj_align(widgets.statusLabel, LV_ALIGN_TOP_RIGHT, -15, 8);
|
||||||
|
|
||||||
|
auto* button_rail = lv_obj_create(parent);
|
||||||
|
if (is_portrait) {
|
||||||
|
lv_obj_set_size(button_rail, 184, 60);
|
||||||
|
lv_obj_align(button_rail, LV_ALIGN_BOTTOM_MID, 0, -7);
|
||||||
|
lv_obj_set_flex_flow(button_rail, LV_FLEX_FLOW_ROW);
|
||||||
|
} else {
|
||||||
|
lv_obj_set_size(button_rail, 60, 184);
|
||||||
|
lv_obj_align(button_rail, LV_ALIGN_RIGHT_MID, -7, 8);
|
||||||
|
lv_obj_set_flex_flow(button_rail, LV_FLEX_FLOW_COLUMN);
|
||||||
|
}
|
||||||
|
lv_obj_set_flex_align(button_rail, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
|
lv_obj_set_style_pad_all(button_rail, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_border_width(button_rail, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_opa(button_rail, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||||
|
lv_obj_clear_flag(button_rail, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
auto* app_list_button = createAppButton(button_rail, LVGL_ICON_LAUNCHER_APPS, "tactility.applist", true);
|
||||||
|
createAppButton(button_rail, LVGL_ICON_LAUNCHER_FOLDER, "tactility.files", false);
|
||||||
|
createAppButton(button_rail, LVGL_ICON_LAUNCHER_SETTINGS, "tactility.settings", false);
|
||||||
|
|
||||||
// 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_style_pad_all(power_button, 8, 0);
|
lv_obj_set_size(power_button, 36, 36);
|
||||||
lv_obj_align(power_button, LV_ALIGN_BOTTOM_MID, 0, -10);
|
lv_obj_align(power_button, LV_ALIGN_BOTTOM_LEFT, 16, -12);
|
||||||
lv_obj_add_event_cb(power_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)"tactility.poweroff");
|
lv_obj_set_style_radius(power_button, LV_RADIUS_CIRCLE, LV_PART_MAIN);
|
||||||
lv_obj_set_style_shadow_width(power_button, 0, LV_STATE_DEFAULT);
|
lv_obj_set_style_shadow_width(power_button, 0, LV_PART_MAIN);
|
||||||
lv_obj_set_style_bg_opa(power_button, 0, LV_PART_MAIN);
|
lv_obj_set_style_bg_color(power_button, lv_color_hex(0x211B20), 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*>("tactility.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, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
lv_obj_set_style_text_color(power_label, TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
lv_obj_center(power_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't have a touch device, we assume there's some other kind of input like a keyboard, an encoder or button control
|
|
||||||
// In that scenario we want to automatically have the app list button selected so the user doesn't have to press the widget selection
|
|
||||||
// an extra time.
|
|
||||||
if (!device_has_active_by_type(&POINTER_TYPE)) {
|
if (!device_has_active_by_type(&POINTER_TYPE)) {
|
||||||
// lv_obj_update_layout(parent); // Resolve flex layout first, so focus/state invalidate against final coords
|
|
||||||
lv_group_focus_obj(app_list_button);
|
lv_group_focus_obj(app_list_button);
|
||||||
lv_obj_add_state(app_list_button, LV_STATE_FOCUS_KEY);
|
lv_obj_add_state(app_list_button, LV_STATE_FOCUS_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateInformation(widgets);
|
||||||
|
widgets.updateTimer = lv_timer_create(onUpdateTimer, 1000, &widgets);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyWidgets(void* user_data) {
|
||||||
|
auto& widgets = *static_cast<LauncherWidgets*>(user_data);
|
||||||
|
if (widgets.updateTimer != nullptr) {
|
||||||
|
lv_timer_delete(widgets.updateTimer);
|
||||||
|
widgets.updateTimer = nullptr;
|
||||||
|
}
|
||||||
|
widgets.timeLabel = nullptr;
|
||||||
|
widgets.dateLabel = nullptr;
|
||||||
|
widgets.dataLabel = nullptr;
|
||||||
|
widgets.statusLabel = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void runAutoStart() {
|
void runAutoStart() {
|
||||||
settings::BootSettings boot_properties;
|
settings::BootSettings boot_properties;
|
||||||
AppManifest manifest;
|
AppManifest manifest;
|
||||||
if (
|
if (strcmp(CONFIG_TT_AUTO_START_APP_ID, "") != 0 &&
|
||||||
// Auto-start due to built-in requirement
|
app_manager_find_manifest(CONFIG_TT_AUTO_START_APP_ID, &manifest) == ERROR_NONE) {
|
||||||
strcmp(CONFIG_TT_AUTO_START_APP_ID, "") != 0 &&
|
|
||||||
app_manager_find_manifest(CONFIG_TT_AUTO_START_APP_ID, &manifest) == ERROR_NONE
|
|
||||||
) {
|
|
||||||
LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID);
|
LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID);
|
||||||
uint32_t app_launch_id;
|
uint32_t app_launch_id;
|
||||||
app_start(CONFIG_TT_AUTO_START_APP_ID, 0, nullptr, &app_launch_id);
|
app_start(CONFIG_TT_AUTO_START_APP_ID, 0, nullptr, &app_launch_id);
|
||||||
} else if (
|
} else if (settings::loadBootSettings(boot_properties) &&
|
||||||
// Auto-start due to user configuration
|
!boot_properties.autoStartAppId.empty() &&
|
||||||
settings::loadBootSettings(boot_properties) &&
|
app_manager_find_manifest(boot_properties.autoStartAppId.c_str(), &manifest) == ERROR_NONE) {
|
||||||
!boot_properties.autoStartAppId.empty() &&
|
|
||||||
app_manager_find_manifest(boot_properties.autoStartAppId.c_str(), &manifest) == ERROR_NONE
|
|
||||||
) {
|
|
||||||
LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
|
LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
|
||||||
uint32_t app_launch_id;
|
uint32_t app_launch_id;
|
||||||
app_start(boot_properties.autoStartAppId.c_str(), 0, nullptr, &app_launch_id);
|
app_start(boot_properties.autoStartAppId.c_str(), 0, nullptr, &app_launch_id);
|
||||||
} else {
|
} else if (!setup::isCompleted()) {
|
||||||
// No auto-start, consider running system setup
|
setup::start();
|
||||||
if (!setup::isCompleted()) {
|
|
||||||
setup::start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t appMain(int argc, char* argv[]) {
|
int32_t appMain(int argc, char* argv[]) {
|
||||||
uint32_t appInstanceId = app_scheduler_current_app_id();
|
uint32_t app_instance_id = app_scheduler_current_app_id();
|
||||||
runAutoStart();
|
runAutoStart();
|
||||||
|
|
||||||
|
LauncherWidgets widgets;
|
||||||
|
WindowId window = window_manager_create_ext(app_instance_id, createWidgets, destroyWidgets, &widgets);
|
||||||
|
|
||||||
TaskEventGroup event_group {};
|
TaskEventGroup event_group {};
|
||||||
task_event_group_construct(&event_group);
|
task_event_group_construct(&event_group);
|
||||||
|
|
||||||
AppEventSubscription sub {};
|
AppEventSubscription sub {};
|
||||||
check(app_event_subscribe(&sub, &event_group) == ERROR_NONE);
|
check(app_event_subscribe(&sub, &event_group) == ERROR_NONE);
|
||||||
|
|
||||||
WindowId window = window_manager_create(appInstanceId, createWidgets, nullptr);
|
|
||||||
|
|
||||||
// The launcher is meant to stay resident (it's the home screen) - it only gives up its
|
|
||||||
// thread when app-module's scheduler asks it to (e.g. another new-model app is started).
|
|
||||||
while (true) {
|
while (true) {
|
||||||
task_event_group_wait_any(&event_group, nullptr, portMAX_DELAY);
|
task_event_group_wait_any(&event_group, nullptr, portMAX_DELAY);
|
||||||
|
bool should_close = false;
|
||||||
bool shouldClose = false;
|
|
||||||
AppEvent event {};
|
AppEvent event {};
|
||||||
while (app_event_poll(&sub, &event) == ERROR_NONE) {
|
while (app_event_poll(&sub, &event) == ERROR_NONE) {
|
||||||
if (event.type == APP_EVENT_CLOSE) {
|
if (event.type == APP_EVENT_CLOSE) {
|
||||||
shouldClose = true;
|
should_close = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shouldClose) break;
|
if (should_close) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
window_manager_remove(window);
|
window_manager_remove(window);
|
||||||
@@ -275,16 +363,13 @@ extern const ::AppManifest manifest = {
|
|||||||
.category = APP_CATEGORY_SYSTEM,
|
.category = APP_CATEGORY_SYSTEM,
|
||||||
.location = { .type = APP_LOCATION_MEMORY, .location = reinterpret_cast<void*>(appMain) },
|
.location = { .type = APP_LOCATION_MEMORY, .location = reinterpret_cast<void*>(appMain) },
|
||||||
.flags = APP_MANIFEST_FLAG_HIDDEN,
|
.flags = APP_MANIFEST_FLAG_HIDDEN,
|
||||||
// No file IO, so callstack can be in external RAM
|
.stack = { .depth = 3072, .desired_memory_capability = MEMORY_CAPABILITY_EXTERNAL }
|
||||||
.stack = { .depth = 3072 , .desired_memory_capability = MEMORY_CAPABILITY_EXTERNAL }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Kept for Tactility/Private/Tactility/app/launcher/Launcher.h's existing declaration (still
|
|
||||||
// used by the old, unconverted CrashDiagnostics app to return to the launcher after a crash).
|
|
||||||
uint32_t start() {
|
uint32_t start() {
|
||||||
uint32_t instance_id = 0;
|
uint32_t instance_id = 0;
|
||||||
app_start(manifest.id, 0, nullptr, &instance_id);
|
app_start(manifest.id, 0, nullptr, &instance_id);
|
||||||
return instance_id;
|
return instance_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace tt::app::launcher
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ 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"
|
||||||
@@ -95,4 +99,3 @@ dependencies:
|
|||||||
rules:
|
rules:
|
||||||
- if: "target in [esp32, esp32s3, esp32p4]"
|
- if: "target in [esp32, esp32s3, esp32p4]"
|
||||||
idf: '5.5.2'
|
idf: '5.5.2'
|
||||||
|
|
||||||
|
|||||||
@@ -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, , 128k,
|
system, data, fat, , 512k,
|
||||||
|
|||||||
|
Reference in New Issue
Block a user