mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-17 23:55:04 +00:00
Compare commits
4 Commits
139d35cb69
...
80c716d97f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80c716d97f | ||
|
|
8f3604018c | ||
|
|
594e85b1d7 | ||
|
|
8af6204ba1 |
@ -46,6 +46,8 @@ def parse_binding(file_path: str, binding_dirs: list[str]) -> Binding:
|
||||
description=details.get('description', '').strip(),
|
||||
default=details.get('default', None),
|
||||
element_type=details.get('element-type', None),
|
||||
min=details.get('min', None),
|
||||
max=details.get('max', None),
|
||||
)
|
||||
properties_dict[name] = prop
|
||||
filename = os.path.basename(file_path)
|
||||
|
||||
@ -118,6 +118,25 @@ def resolve_phandle_array_entries(device_property, devices):
|
||||
entries.append(str(item))
|
||||
return entries
|
||||
|
||||
def validate_property_range(device: Device, binding_property, value) -> None:
|
||||
"""Enforces a binding's optional min/max on int-typed properties. Silently skips
|
||||
values that aren't parseable as a plain integer literal (e.g. a passed-through
|
||||
symbolic #define) - those can't be range-checked at compile time."""
|
||||
if binding_property.min is None and binding_property.max is None:
|
||||
return
|
||||
try:
|
||||
numeric_value = int(value, 0) if isinstance(value, str) else int(value)
|
||||
except (TypeError, ValueError):
|
||||
return
|
||||
if binding_property.min is not None and numeric_value < binding_property.min:
|
||||
raise DevicetreeException(
|
||||
f"Device '{device.node_name}' property '{binding_property.name}' value {numeric_value} is below minimum {binding_property.min}"
|
||||
)
|
||||
if binding_property.max is not None and numeric_value > binding_property.max:
|
||||
raise DevicetreeException(
|
||||
f"Device '{device.node_name}' property '{binding_property.name}' value {numeric_value} is above maximum {binding_property.max}"
|
||||
)
|
||||
|
||||
def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], devices: list[Device]) -> list:
|
||||
compatible_property = find_device_property(device, "compatible")
|
||||
if compatible_property is None:
|
||||
@ -168,6 +187,7 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de
|
||||
|
||||
if device_property is None:
|
||||
if binding_property.default is not None:
|
||||
validate_property_range(device, binding_property, binding_property.default)
|
||||
temp_prop = DeviceProperty(
|
||||
name=binding_property.name,
|
||||
type=binding_property.type,
|
||||
@ -184,6 +204,7 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de
|
||||
else:
|
||||
raise DevicetreeException(f"Device {device.node_name} doesn't have property '{binding_property.name}' and no default value is set")
|
||||
else:
|
||||
validate_property_range(device, binding_property, device_property.value)
|
||||
result.append(property_to_string(device_property, devices))
|
||||
|
||||
return result, phandle_arrays
|
||||
|
||||
@ -40,6 +40,8 @@ class BindingProperty:
|
||||
description: str
|
||||
default: object = None
|
||||
element_type: str = None
|
||||
min: object = None
|
||||
max: object = None
|
||||
|
||||
@dataclass
|
||||
class Binding:
|
||||
|
||||
@ -76,6 +76,139 @@ def test_compile_invalid_dts():
|
||||
print("PASSED")
|
||||
return True
|
||||
|
||||
def write_minmax_config(tmp_dir, device_property_line, binding_min=0, binding_max=3, binding_default=1):
|
||||
config_dir = os.path.join(tmp_dir, "minmax_data")
|
||||
bindings_dir = os.path.join(config_dir, "bindings")
|
||||
os.makedirs(bindings_dir)
|
||||
|
||||
with open(os.path.join(config_dir, "devicetree.yaml"), "w") as f:
|
||||
f.write("dts: test.dts\nbindings: bindings")
|
||||
|
||||
with open(os.path.join(config_dir, "test.dts"), "w") as f:
|
||||
f.write(f"""/dts-v1/;
|
||||
|
||||
/ {{
|
||||
compatible = "test,root";
|
||||
model = "Test Model";
|
||||
|
||||
test-device@0 {{
|
||||
compatible = "test,minmax-device";
|
||||
{device_property_line}
|
||||
}};
|
||||
}};
|
||||
""")
|
||||
|
||||
with open(os.path.join(bindings_dir, "test,root.yaml"), "w") as f:
|
||||
f.write("description: Test root binding\ncompatible: \"test,root\"\nproperties:\n model:\n type: string\n")
|
||||
|
||||
with open(os.path.join(bindings_dir, "test,minmax-device.yaml"), "w") as f:
|
||||
f.write(f"""description: Test min/max binding
|
||||
compatible: "test,minmax-device"
|
||||
properties:
|
||||
ranged-prop:
|
||||
type: int
|
||||
default: {binding_default}
|
||||
min: {binding_min}
|
||||
max: {binding_max}
|
||||
""")
|
||||
|
||||
return config_dir
|
||||
|
||||
def test_minmax_within_range_succeeds():
|
||||
print("Running test_minmax_within_range_succeeds...")
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
config_dir = write_minmax_config(tmp_dir, "ranged-prop = <2>;")
|
||||
output_dir = os.path.join(tmp_dir, "output")
|
||||
os.makedirs(output_dir)
|
||||
|
||||
result = run_compiler(config_dir, output_dir)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f"FAILED: Compilation should have succeeded: {result.stderr} {result.stdout}")
|
||||
return False
|
||||
|
||||
print("PASSED")
|
||||
return True
|
||||
|
||||
def test_minmax_below_minimum_fails():
|
||||
print("Running test_minmax_below_minimum_fails...")
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
config_dir = write_minmax_config(tmp_dir, "ranged-prop = <-1>;")
|
||||
output_dir = os.path.join(tmp_dir, "output")
|
||||
os.makedirs(output_dir)
|
||||
|
||||
result = run_compiler(config_dir, output_dir)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("FAILED: Compilation should have failed for a below-minimum value")
|
||||
return False
|
||||
|
||||
if "below minimum" not in result.stdout:
|
||||
print(f"FAILED: Expected 'below minimum' error message, got: {result.stdout}")
|
||||
return False
|
||||
|
||||
print("PASSED")
|
||||
return True
|
||||
|
||||
def test_minmax_above_maximum_fails():
|
||||
print("Running test_minmax_above_maximum_fails...")
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
config_dir = write_minmax_config(tmp_dir, "ranged-prop = <7>;")
|
||||
output_dir = os.path.join(tmp_dir, "output")
|
||||
os.makedirs(output_dir)
|
||||
|
||||
result = run_compiler(config_dir, output_dir)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("FAILED: Compilation should have failed for an above-maximum value")
|
||||
return False
|
||||
|
||||
if "above maximum" not in result.stdout:
|
||||
print(f"FAILED: Expected 'above maximum' error message, got: {result.stdout}")
|
||||
return False
|
||||
|
||||
print("PASSED")
|
||||
return True
|
||||
|
||||
def test_minmax_out_of_range_default_fails():
|
||||
print("Running test_minmax_out_of_range_default_fails...")
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
# Property omitted from the .dts entirely, so the (invalid) binding default is used.
|
||||
config_dir = write_minmax_config(tmp_dir, "", binding_default=9)
|
||||
output_dir = os.path.join(tmp_dir, "output")
|
||||
os.makedirs(output_dir)
|
||||
|
||||
result = run_compiler(config_dir, output_dir)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("FAILED: Compilation should have failed for an out-of-range default value")
|
||||
return False
|
||||
|
||||
if "above maximum" not in result.stdout:
|
||||
print(f"FAILED: Expected 'above maximum' error message, got: {result.stdout}")
|
||||
return False
|
||||
|
||||
print("PASSED")
|
||||
return True
|
||||
|
||||
def test_minmax_symbolic_value_skips_validation():
|
||||
print("Running test_minmax_symbolic_value_skips_validation...")
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
# A passed-through symbolic constant can't be range-checked at compile time and must
|
||||
# not be rejected just because a min/max is declared.
|
||||
config_dir = write_minmax_config(tmp_dir, "ranged-prop = <SOME_DEFINE>;")
|
||||
output_dir = os.path.join(tmp_dir, "output")
|
||||
os.makedirs(output_dir)
|
||||
|
||||
result = run_compiler(config_dir, output_dir)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f"FAILED: Compilation should have succeeded for a symbolic value: {result.stderr} {result.stdout}")
|
||||
return False
|
||||
|
||||
print("PASSED")
|
||||
return True
|
||||
|
||||
def test_compile_missing_config():
|
||||
print("Running test_compile_missing_config...")
|
||||
with tempfile.TemporaryDirectory() as output_dir:
|
||||
@ -96,7 +229,12 @@ if __name__ == "__main__":
|
||||
tests = [
|
||||
test_compile_success,
|
||||
test_compile_invalid_dts,
|
||||
test_compile_missing_config
|
||||
test_compile_missing_config,
|
||||
test_minmax_within_range_succeeds,
|
||||
test_minmax_below_minimum_fails,
|
||||
test_minmax_above_maximum_fails,
|
||||
test_minmax_out_of_range_default_fails,
|
||||
test_minmax_symbolic_value_skips_validation
|
||||
]
|
||||
|
||||
failed = 0
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd RgbDisplay GT911 PwmBacklight driver vfs fatfs
|
||||
INCLUDE_DIRS "source"
|
||||
REQUIRES Tactility
|
||||
)
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
#include <PwmBacklight.h>
|
||||
#include "devices/Display.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
//Display Reset
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_46, GPIO_MODE_OUTPUT));
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_46, 0));
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_46, 1));
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
return driver::pwmbacklight::init(GPIO_NUM_21);
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay()
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,107 +0,0 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <Gt911Touch.h>
|
||||
#include <PwmBacklight.h>
|
||||
#include <RgbDisplay.h>
|
||||
#include <tactility/check.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
// Note for future changes: Reset pin is 41 and interrupt pin is 40
|
||||
auto* i2c = device_find_by_name("i2c0");
|
||||
check(i2c);
|
||||
auto configuration = std::make_unique<Gt911Touch::Configuration>(
|
||||
i2c,
|
||||
800,
|
||||
480
|
||||
);
|
||||
|
||||
return std::make_shared<Gt911Touch>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
auto touch = createTouch();
|
||||
|
||||
constexpr uint32_t bufferPixels = 800 * 10;
|
||||
|
||||
esp_lcd_rgb_panel_config_t rgb_panel_config = {
|
||||
.clk_src = LCD_CLK_SRC_DEFAULT,
|
||||
.timings = {
|
||||
.pclk_hz = 14000000,
|
||||
.h_res = 800,
|
||||
.v_res = 480,
|
||||
.hsync_pulse_width = 4,
|
||||
.hsync_back_porch = 8,
|
||||
.hsync_front_porch = 8,
|
||||
.vsync_pulse_width = 4,
|
||||
.vsync_back_porch = 16,
|
||||
.vsync_front_porch = 16,
|
||||
.flags = {
|
||||
.hsync_idle_low = false,
|
||||
.vsync_idle_low = false,
|
||||
.de_idle_high = false,
|
||||
.pclk_active_neg = true,
|
||||
.pclk_idle_high = true
|
||||
}
|
||||
},
|
||||
.data_width = 16,
|
||||
.bits_per_pixel = 0,
|
||||
.num_fbs = 2,
|
||||
.bounce_buffer_size_px = bufferPixels,
|
||||
.sram_trans_align = 8,
|
||||
.psram_trans_align = 64,
|
||||
.hsync_gpio_num = GPIO_NUM_NC,
|
||||
.vsync_gpio_num = GPIO_NUM_NC,
|
||||
.de_gpio_num = GPIO_NUM_38,
|
||||
.pclk_gpio_num = GPIO_NUM_5,
|
||||
.disp_gpio_num = GPIO_NUM_NC,
|
||||
.data_gpio_nums = {
|
||||
GPIO_NUM_17, // B
|
||||
GPIO_NUM_18, // B
|
||||
GPIO_NUM_48, // B
|
||||
GPIO_NUM_47, // B
|
||||
GPIO_NUM_39, // B
|
||||
GPIO_NUM_11, // G
|
||||
GPIO_NUM_12, // G
|
||||
GPIO_NUM_13, // G
|
||||
GPIO_NUM_14, // G
|
||||
GPIO_NUM_15, // G
|
||||
GPIO_NUM_16, // G
|
||||
GPIO_NUM_6, // R
|
||||
GPIO_NUM_7, // R
|
||||
GPIO_NUM_8, // R
|
||||
GPIO_NUM_9, // R
|
||||
GPIO_NUM_10, // R
|
||||
},
|
||||
.flags = {
|
||||
.disp_active_low = false,
|
||||
.refresh_on_demand = false,
|
||||
.fb_in_psram = true,
|
||||
.double_fb = true,
|
||||
.no_fb = false,
|
||||
.bb_invalidate_cache = false
|
||||
}
|
||||
};
|
||||
|
||||
RgbDisplay::BufferConfiguration buffer_config = {
|
||||
.size = (800 * 480),
|
||||
.useSpi = true,
|
||||
.doubleBuffer = true,
|
||||
.bounceBufferMode = true,
|
||||
.avoidTearing = false
|
||||
};
|
||||
|
||||
auto configuration = std::make_unique<RgbDisplay::Configuration>(
|
||||
rgb_panel_config,
|
||||
buffer_config,
|
||||
touch,
|
||||
LV_COLOR_FORMAT_RGB565,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
driver::pwmbacklight::setBacklightDuty
|
||||
);
|
||||
|
||||
return std::make_shared<RgbDisplay>(std::move(configuration));
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -6,6 +6,9 @@
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_usbhost.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/rgb_display.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
// Reference: https://github.com/bigtreetech/PandaTouch_PlatformIO/blob/master/docs/PINOUT.md
|
||||
/ {
|
||||
@ -33,6 +36,15 @@
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
|
||||
|
||||
touch0 {
|
||||
// Reset pin 41 and interrupt pin 40 exist on the board but are not wired up here
|
||||
// (unverified - left disconnected like the original deprecated-HAL config).
|
||||
compatible = "goodix,gt911";
|
||||
reg = <0x5D>;
|
||||
x-max = <800>;
|
||||
y-max = <480>;
|
||||
};
|
||||
};
|
||||
|
||||
i2c_external: i2c1 {
|
||||
@ -43,6 +55,49 @@
|
||||
pin-scl = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display0 {
|
||||
compatible = "espressif,esp32-rgb-display";
|
||||
horizontal-resolution = <800>;
|
||||
vertical-resolution = <480>;
|
||||
pixel-clock-hz = <14000000>;
|
||||
hsync-pulse-width = <4>;
|
||||
hsync-back-porch = <8>;
|
||||
hsync-front-porch = <8>;
|
||||
vsync-pulse-width = <4>;
|
||||
vsync-back-porch = <16>;
|
||||
vsync-front-porch = <16>;
|
||||
pclk-active-neg;
|
||||
pclk-idle-high;
|
||||
num-fbs = <2>;
|
||||
double-fb;
|
||||
bounce-buffer-size-px = <8000>;
|
||||
pin-de = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
pin-pclk = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
pin-reset = <&gpio0 46 GPIO_FLAG_NONE>;
|
||||
pin-data0 = <&gpio0 17 GPIO_FLAG_NONE>; // B
|
||||
pin-data1 = <&gpio0 18 GPIO_FLAG_NONE>; // B
|
||||
pin-data2 = <&gpio0 48 GPIO_FLAG_NONE>; // B
|
||||
pin-data3 = <&gpio0 47 GPIO_FLAG_NONE>; // B
|
||||
pin-data4 = <&gpio0 39 GPIO_FLAG_NONE>; // B
|
||||
pin-data5 = <&gpio0 11 GPIO_FLAG_NONE>; // G
|
||||
pin-data6 = <&gpio0 12 GPIO_FLAG_NONE>; // G
|
||||
pin-data7 = <&gpio0 13 GPIO_FLAG_NONE>; // G
|
||||
pin-data8 = <&gpio0 14 GPIO_FLAG_NONE>; // G
|
||||
pin-data9 = <&gpio0 15 GPIO_FLAG_NONE>; // G
|
||||
pin-data10 = <&gpio0 16 GPIO_FLAG_NONE>; // G
|
||||
pin-data11 = <&gpio0 6 GPIO_FLAG_NONE>; // R
|
||||
pin-data12 = <&gpio0 7 GPIO_FLAG_NONE>; // R
|
||||
pin-data13 = <&gpio0 8 GPIO_FLAG_NONE>; // R
|
||||
pin-data14 = <&gpio0 9 GPIO_FLAG_NONE>; // R
|
||||
pin-data15 = <&gpio0 10 GPIO_FLAG_NONE>; // R
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
|
||||
usbhost0 {
|
||||
compatible = "espressif,esp32-usbhost";
|
||||
|
||||
|
||||
@ -12,6 +12,8 @@ hardware.esptoolFlashFreq=120M
|
||||
hardware.bluetooth=true
|
||||
hardware.usbHostEnabled=true
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=Internal
|
||||
|
||||
display.size=5"
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/rgb-display-module
|
||||
- Drivers/gt911-module
|
||||
dts: bigtreetech,panda-touch.dts
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@ -74,7 +74,8 @@
|
||||
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
|
||||
miso-pull-up;
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port ILI934x XPT2046 PwmBacklight driver vfs fatfs
|
||||
REQUIRES TactilityKernel driver
|
||||
)
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
#include "devices/Display.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT);
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay()
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,46 +0,0 @@
|
||||
#include "Display.h"
|
||||
#include "Xpt2046Touch.h"
|
||||
#include <Ili934xDisplay.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch(esp_lcd_spi_bus_handle_t spiDevice) {
|
||||
auto configuration = std::make_unique<Xpt2046Touch::Configuration>(
|
||||
spiDevice,
|
||||
TOUCH_CS_PIN,
|
||||
LCD_HORIZONTAL_RESOLUTION,
|
||||
LCD_VERTICAL_RESOLUTION,
|
||||
true, // swapXY
|
||||
false, // mirrorX
|
||||
true // mirrorY
|
||||
);
|
||||
return std::make_shared<Xpt2046Touch>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
auto spi_configuration = std::make_shared<Ili934xDisplay::SpiConfiguration>(Ili934xDisplay::SpiConfiguration {
|
||||
.spiHostDevice = LCD_SPI_HOST,
|
||||
.csPin = LCD_PIN_CS,
|
||||
.dcPin = LCD_PIN_DC,
|
||||
.pixelClockFrequency = 40'000'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
Ili934xDisplay::Configuration panel_configuration = {
|
||||
.horizontalResolution = LCD_HORIZONTAL_RESOLUTION,
|
||||
.verticalResolution = LCD_VERTICAL_RESOLUTION,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = true,
|
||||
.mirrorX = true,
|
||||
.mirrorY = true,
|
||||
.invertColor = false,
|
||||
.swapBytes = true,
|
||||
.bufferSize = LCD_BUFFER_SIZE,
|
||||
.touch = createTouch(spi_configuration->spiHostDevice),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = LCD_PIN_RST,
|
||||
.rgbElementOrder = LCD_RGB_ELEMENT_ORDER_RGB
|
||||
};
|
||||
|
||||
return std::make_shared<Ili934xDisplay>(panel_configuration, spi_configuration, true);
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
#include <memory>
|
||||
|
||||
// Display
|
||||
constexpr auto LCD_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto LCD_PIN_CS = GPIO_NUM_15;
|
||||
constexpr auto LCD_PIN_DC = GPIO_NUM_2;
|
||||
constexpr auto LCD_PIN_RST = GPIO_NUM_NC; // tied to ESP32 RST
|
||||
constexpr auto LCD_PIN_CLK = GPIO_NUM_14;
|
||||
constexpr auto LCD_PIN_MOSI = GPIO_NUM_13;
|
||||
constexpr auto LCD_PIN_MISO = GPIO_NUM_12;
|
||||
constexpr auto LCD_HORIZONTAL_RESOLUTION = 240;
|
||||
constexpr auto LCD_VERTICAL_RESOLUTION = 320;
|
||||
constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10;
|
||||
constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT;
|
||||
|
||||
// Backlight
|
||||
constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_27;
|
||||
|
||||
// Touch
|
||||
constexpr auto TOUCH_CS_PIN = GPIO_NUM_33;
|
||||
constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36;
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -5,9 +5,10 @@
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -23,6 +24,15 @@
|
||||
gpio-count = <40>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
@ -33,11 +43,23 @@
|
||||
<&gpio0 33 GPIO_FLAG_NONE>; // Touch
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
compatible = "ilitek,ili9341";
|
||||
horizontal-resolution = <240>;
|
||||
vertical-resolution = <320>;
|
||||
swap-xy;
|
||||
mirror-x;
|
||||
mirror-y;
|
||||
pixel-clock-hz = <40000000>;
|
||||
pin-dc = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "pointer-placeholder";
|
||||
compatible = "xptek,xpt2046";
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
swap-xy;
|
||||
mirror-y;
|
||||
};
|
||||
};
|
||||
|
||||
@ -61,4 +83,4 @@
|
||||
pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
|
||||
pin-rx = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -7,6 +7,8 @@ hardware.target=ESP32
|
||||
hardware.flashSize=4MB
|
||||
hardware.spiRam=false
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.4"
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/ili9341-module
|
||||
- Drivers/xpt2046-module
|
||||
dts: cyd,2432s024r.dts
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port ILI934x XPT2046SoftSPI PwmBacklight driver vfs fatfs
|
||||
REQUIRES TactilityKernel driver
|
||||
)
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
#include "devices/Display.h"
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
// Set the RGB LED Pins to output and turn them off
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); // Red
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); // Green
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT)); // Blue
|
||||
|
||||
// 0 on, 1 off
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_4, 1)); // Red
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_16, 1)); // Green
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_17, 1)); // Blue
|
||||
|
||||
return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT);
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,49 +0,0 @@
|
||||
#include "Display.h"
|
||||
#include "Xpt2046SoftSpi.h"
|
||||
#include <Ili934xDisplay.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto configuration = std::make_unique<Xpt2046SoftSpi::Configuration>(
|
||||
TOUCH_MOSI_PIN,
|
||||
TOUCH_MISO_PIN,
|
||||
TOUCH_SCK_PIN,
|
||||
TOUCH_CS_PIN,
|
||||
LCD_HORIZONTAL_RESOLUTION,
|
||||
LCD_VERTICAL_RESOLUTION,
|
||||
false, // swapXY
|
||||
true, // mirrorX
|
||||
false // mirrorY
|
||||
);
|
||||
|
||||
return std::make_shared<Xpt2046SoftSpi>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
Ili934xDisplay::Configuration panel_configuration = {
|
||||
.horizontalResolution = LCD_HORIZONTAL_RESOLUTION,
|
||||
.verticalResolution = LCD_VERTICAL_RESOLUTION,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = false,
|
||||
.mirrorX = true,
|
||||
.mirrorY = false,
|
||||
.invertColor = false,
|
||||
.swapBytes = true,
|
||||
.bufferSize = LCD_BUFFER_SIZE,
|
||||
.touch = createTouch(),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = GPIO_NUM_NC,
|
||||
.rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR
|
||||
};
|
||||
|
||||
auto spi_configuration = std::make_shared<Ili934xDisplay::SpiConfiguration>(Ili934xDisplay::SpiConfiguration {
|
||||
.spiHostDevice = LCD_SPI_HOST,
|
||||
.csPin = LCD_PIN_CS,
|
||||
.dcPin = LCD_PIN_DC,
|
||||
.pixelClockFrequency = 40'000'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
return std::make_shared<Ili934xDisplay>(panel_configuration, spi_configuration, true);
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
#include <memory>
|
||||
|
||||
// Display
|
||||
constexpr auto LCD_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto LCD_PIN_CS = GPIO_NUM_15;
|
||||
constexpr auto LCD_PIN_DC = GPIO_NUM_2;
|
||||
constexpr auto LCD_HORIZONTAL_RESOLUTION = 240;
|
||||
constexpr auto LCD_VERTICAL_RESOLUTION = 320;
|
||||
constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10;
|
||||
constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT;
|
||||
|
||||
// Display backlight (PWM)
|
||||
constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_21;
|
||||
|
||||
// Touch (Software SPI)
|
||||
constexpr auto TOUCH_MISO_PIN = GPIO_NUM_39;
|
||||
constexpr auto TOUCH_MOSI_PIN = GPIO_NUM_32;
|
||||
constexpr auto TOUCH_SCK_PIN = GPIO_NUM_25;
|
||||
constexpr auto TOUCH_CS_PIN = GPIO_NUM_33;
|
||||
constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36;
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -1,23 +0,0 @@
|
||||
#include <tactility/module.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
struct Module cyd_2432s028r_module = {
|
||||
.name = "cyd-2432s028r",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -7,8 +7,9 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046_softspi.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -32,21 +33,43 @@
|
||||
pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
};
|
||||
|
||||
touch {
|
||||
compatible = "xptek,xpt2046-softspi";
|
||||
pin-mosi = <&gpio0 32 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-sck = <&gpio0 25 GPIO_FLAG_NONE>;
|
||||
pin-cs = <&gpio0 33 GPIO_FLAG_NONE>;
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
mirror-x;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display
|
||||
<&gpio0 33 GPIO_FLAG_NONE>; // Touch
|
||||
cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>;
|
||||
pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "pointer-placeholder";
|
||||
display@0 {
|
||||
compatible = "ilitek,ili9341";
|
||||
horizontal-resolution = <240>;
|
||||
vertical-resolution = <320>;
|
||||
mirror-x;
|
||||
bgr-order;
|
||||
pixel-clock-hz = <40000000>;
|
||||
pin-dc = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -7,12 +7,17 @@ hardware.target=ESP32
|
||||
hardware.flashSize=4MB
|
||||
hardware.spiRam=false
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=143
|
||||
|
||||
touch.calibrationSupported=true
|
||||
touch.calibrationRequired=false
|
||||
|
||||
cdn.warningMessage=There are 3 hardware variants of this board. This build works on the original variant only ("v1").
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/ili9341-module
|
||||
- Drivers/xpt2046-softspi-module
|
||||
dts: cyd,2432s028r.dts
|
||||
|
||||
34
Devices/cyd-2432s028r/source/module.cpp
Normal file
34
Devices/cyd-2432s028r/source/module.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Set the RGB LED pins to output and turn them off (0 on, 1 off)
|
||||
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); // Red
|
||||
gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT); // Green
|
||||
gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT); // Blue
|
||||
|
||||
gpio_set_level(GPIO_NUM_4, 1); // Red
|
||||
gpio_set_level(GPIO_NUM_16, 1); // Green
|
||||
gpio_set_level(GPIO_NUM_17, 1); // Blue
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
struct Module cyd_2432s028r_module = {
|
||||
.name = "cyd-2432s028r",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port ST7789 XPT2046SoftSPI PwmBacklight driver vfs fatfs
|
||||
REQUIRES TactilityKernel driver
|
||||
)
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
#include "devices/Display.h"
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
// Set the RGB LED Pins to output and turn them off
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); // Red
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); // Green
|
||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT)); // Blue
|
||||
|
||||
// 0 on, 1 off
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_4, 1)); // Red
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_16, 1)); // Green
|
||||
ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_17, 1)); // Blue
|
||||
|
||||
return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT);
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,50 +0,0 @@
|
||||
#include "Display.h"
|
||||
#include "Xpt2046SoftSpi.h"
|
||||
#include <St7789Display.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
constexpr auto* TAG = "CYD";
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto configuration = std::make_unique<Xpt2046SoftSpi::Configuration>(
|
||||
TOUCH_MOSI_PIN,
|
||||
TOUCH_MISO_PIN,
|
||||
TOUCH_SCK_PIN,
|
||||
TOUCH_CS_PIN,
|
||||
LCD_HORIZONTAL_RESOLUTION,
|
||||
LCD_VERTICAL_RESOLUTION,
|
||||
false, // swapXY
|
||||
true, // mirrorX
|
||||
false // mirrorY
|
||||
);
|
||||
|
||||
return std::make_shared<Xpt2046SoftSpi>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
St7789Display::Configuration panel_configuration = {
|
||||
.horizontalResolution = LCD_HORIZONTAL_RESOLUTION,
|
||||
.verticalResolution = LCD_VERTICAL_RESOLUTION,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = false,
|
||||
.mirrorX = false,
|
||||
.mirrorY = false,
|
||||
.invertColor = false,
|
||||
.bufferSize = LCD_BUFFER_SIZE,
|
||||
.touch = createTouch(),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = GPIO_NUM_NC,
|
||||
.lvglSwapBytes = false
|
||||
};
|
||||
|
||||
auto spi_configuration = std::make_shared<St7789Display::SpiConfiguration>(St7789Display::SpiConfiguration {
|
||||
.spiHostDevice = LCD_SPI_HOST,
|
||||
.csPin = LCD_PIN_CS,
|
||||
.dcPin = LCD_PIN_DC,
|
||||
.pixelClockFrequency = 62'500'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
return std::make_shared<St7789Display>(panel_configuration, spi_configuration);
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
// Display
|
||||
constexpr auto LCD_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto LCD_PIN_CS = GPIO_NUM_15;
|
||||
constexpr auto LCD_PIN_DC = GPIO_NUM_2;
|
||||
constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_21;
|
||||
constexpr auto LCD_HORIZONTAL_RESOLUTION = 240;
|
||||
constexpr auto LCD_VERTICAL_RESOLUTION = 320;
|
||||
constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10;
|
||||
constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT;
|
||||
|
||||
// Touch (Software SPI)
|
||||
constexpr auto TOUCH_MISO_PIN = GPIO_NUM_39;
|
||||
constexpr auto TOUCH_MOSI_PIN = GPIO_NUM_32;
|
||||
constexpr auto TOUCH_SCK_PIN = GPIO_NUM_25;
|
||||
constexpr auto TOUCH_CS_PIN = GPIO_NUM_33;
|
||||
constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36;
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -1,23 +0,0 @@
|
||||
#include <tactility/module.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
struct Module cyd_2432s028rv3_module = {
|
||||
.name = "cyd-2432s028rv3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -7,8 +7,9 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/xpt2046_softspi.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -32,21 +33,41 @@
|
||||
pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
};
|
||||
|
||||
touch {
|
||||
compatible = "xptek,xpt2046-softspi";
|
||||
pin-mosi = <&gpio0 32 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-sck = <&gpio0 25 GPIO_FLAG_NONE>;
|
||||
pin-cs = <&gpio0 33 GPIO_FLAG_NONE>;
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
mirror-x;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display
|
||||
<&gpio0 33 GPIO_FLAG_NONE>; // Touch
|
||||
cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>;
|
||||
pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "pointer-placeholder";
|
||||
display@0 {
|
||||
compatible = "sitronix,st7789";
|
||||
horizontal-resolution = <240>;
|
||||
vertical-resolution = <320>;
|
||||
pixel-clock-hz = <62500000>;
|
||||
pin-dc = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
};
|
||||
|
||||
@ -57,7 +78,7 @@
|
||||
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -7,12 +7,17 @@ hardware.target=ESP32
|
||||
hardware.flashSize=4MB
|
||||
hardware.spiRam=false
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=143
|
||||
|
||||
touch.calibrationSupported=true
|
||||
touch.calibrationRequired=false
|
||||
|
||||
cdn.warningMessage=There are 3 hardware variants of this board. This build only supports board version 3.
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/st7789-module
|
||||
- Drivers/xpt2046-softspi-module
|
||||
dts: cyd,2432s028rv3.dts
|
||||
|
||||
33
Devices/cyd-2432s028rv3/source/module.cpp
Normal file
33
Devices/cyd-2432s028rv3/source/module.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Set the RGB LED pins to output and turn them off (0 on, 1 off)
|
||||
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); // Red
|
||||
gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT); // Green
|
||||
gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT); // Blue
|
||||
|
||||
gpio_set_level(GPIO_NUM_4, 1); // Red
|
||||
gpio_set_level(GPIO_NUM_16, 1); // Green
|
||||
gpio_set_level(GPIO_NUM_17, 1); // Blue
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
struct Module cyd_2432s028rv3_module = {
|
||||
.name = "cyd-2432s028rv3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
static bool initBoot() {
|
||||
static bool init_boot() {
|
||||
if (!driver::pwmbacklight::init(LCD_PIN_BACKLIGHT)) {
|
||||
return false;
|
||||
}
|
||||
@ -42,6 +42,6 @@ static tt::hal::DeviceVector createDevices() {
|
||||
}
|
||||
|
||||
extern const tt::hal::Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.initBoot = init_boot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port ILI934x XPT2046SoftSPI PwmBacklight driver vfs fatfs
|
||||
REQUIRES TactilityKernel driver
|
||||
)
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
#include "devices/Display.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
static bool initBoot() {
|
||||
return driver::pwmbacklight::init(LCD_BACKLIGHT_PIN);
|
||||
}
|
||||
|
||||
static tt::hal::DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const tt::hal::Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,51 +0,0 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <Xpt2046SoftSpi.h>
|
||||
#include <Ili934xDisplay.h>
|
||||
#include <PwmBacklight.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto config = std::make_unique<Xpt2046SoftSpi::Configuration>(
|
||||
TOUCH_MOSI_PIN,
|
||||
TOUCH_MISO_PIN,
|
||||
TOUCH_SCK_PIN,
|
||||
TOUCH_CS_PIN,
|
||||
LCD_HORIZONTAL_RESOLUTION,
|
||||
LCD_VERTICAL_RESOLUTION,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
return std::make_shared<Xpt2046SoftSpi>(std::move(config));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
Ili934xDisplay::Configuration panel_configuration = {
|
||||
.horizontalResolution = LCD_HORIZONTAL_RESOLUTION,
|
||||
.verticalResolution = LCD_VERTICAL_RESOLUTION,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = false,
|
||||
.mirrorX = true,
|
||||
.mirrorY = false,
|
||||
.invertColor = false,
|
||||
.swapBytes = true,
|
||||
.bufferSize = LCD_BUFFER_SIZE,
|
||||
.touch = createTouch(),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = GPIO_NUM_NC,
|
||||
.rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR
|
||||
};
|
||||
|
||||
auto spi_configuration = std::make_shared<Ili934xDisplay::SpiConfiguration>(Ili934xDisplay::SpiConfiguration {
|
||||
.spiHostDevice = LCD_SPI_HOST,
|
||||
.csPin = LCD_PIN_CS,
|
||||
.dcPin = LCD_PIN_DC,
|
||||
.pixelClockFrequency = 40'000'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
return std::make_shared<Ili934xDisplay>(panel_configuration, spi_configuration, true);
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
#include <memory>
|
||||
|
||||
// Display
|
||||
constexpr auto LCD_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto LCD_PIN_CS = GPIO_NUM_15;
|
||||
constexpr auto LCD_PIN_DC = GPIO_NUM_2;
|
||||
constexpr auto LCD_HORIZONTAL_RESOLUTION = 240;
|
||||
constexpr auto LCD_VERTICAL_RESOLUTION = 320;
|
||||
constexpr auto LCD_BUFFER_HEIGHT = (LCD_VERTICAL_RESOLUTION / 10);
|
||||
constexpr auto LCD_BUFFER_SIZE = (LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT);
|
||||
|
||||
// Touch (Software SPI)
|
||||
constexpr auto TOUCH_MISO_PIN = GPIO_NUM_39;
|
||||
constexpr auto TOUCH_MOSI_PIN = GPIO_NUM_32;
|
||||
constexpr auto TOUCH_SCK_PIN = GPIO_NUM_25;
|
||||
constexpr auto TOUCH_CS_PIN = GPIO_NUM_33;
|
||||
constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36;
|
||||
|
||||
// Backlight
|
||||
constexpr auto LCD_BACKLIGHT_PIN = GPIO_NUM_21;
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -5,8 +5,9 @@
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046_softspi.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -22,21 +23,43 @@
|
||||
gpio-count = <40>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <512>;
|
||||
};
|
||||
|
||||
touch {
|
||||
compatible = "xptek,xpt2046-softspi";
|
||||
pin-mosi = <&gpio0 32 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-sck = <&gpio0 25 GPIO_FLAG_NONE>;
|
||||
pin-cs = <&gpio0 33 GPIO_FLAG_NONE>;
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
mirror-x;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display
|
||||
<&gpio0 33 GPIO_FLAG_NONE>; // Touch
|
||||
cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>;
|
||||
pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "pointer-placeholder";
|
||||
display@0 {
|
||||
compatible = "ilitek,ili9341";
|
||||
horizontal-resolution = <240>;
|
||||
vertical-resolution = <320>;
|
||||
mirror-x;
|
||||
bgr-order;
|
||||
pixel-clock-hz = <40000000>;
|
||||
pin-dc = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
};
|
||||
|
||||
@ -47,7 +70,7 @@
|
||||
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -7,10 +7,15 @@ hardware.target=ESP32
|
||||
hardware.flashSize=4MB
|
||||
hardware.spiRam=false
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=143
|
||||
|
||||
touch.calibrationSupported=true
|
||||
touch.calibrationRequired=false
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/ili9341-module
|
||||
- Drivers/xpt2046-softspi-module
|
||||
dts: cyd,e32r28t.dts
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port ST7789 XPT2046 PwmBacklight EstimatedPower driver vfs fatfs
|
||||
REQUIRES TactilityKernel driver
|
||||
)
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
#include "devices/Display.h"
|
||||
#include "devices/Power.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
return driver::pwmbacklight::init(DISPLAY_BACKLIGHT_PIN);
|
||||
}
|
||||
|
||||
static tt::hal::DeviceVector createDevices() {
|
||||
return {
|
||||
createPower(),
|
||||
createDisplay(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,52 +0,0 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <Xpt2046Touch.h>
|
||||
#include <St7789Display.h>
|
||||
#include <PwmBacklight.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
|
||||
// Create the XPT2046 touch device (hardware/esp_lcd driver)
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto config = std::make_unique<Xpt2046Touch::Configuration>(
|
||||
DISPLAY_SPI_HOST, // spi device / bus (SPI2_HOST)
|
||||
TOUCH_CS_PIN, // touch CS (IO33)
|
||||
(uint16_t)DISPLAY_HORIZONTAL_RESOLUTION, // x max
|
||||
(uint16_t)DISPLAY_VERTICAL_RESOLUTION, // y max
|
||||
false, // swapXy
|
||||
true, // mirrorX
|
||||
true // mirrorY
|
||||
);
|
||||
|
||||
return std::make_shared<Xpt2046Touch>(std::move(config));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
// Create the ST7789 panel configuration
|
||||
St7789Display::Configuration panel_configuration = {
|
||||
.horizontalResolution = DISPLAY_HORIZONTAL_RESOLUTION,
|
||||
.verticalResolution = DISPLAY_VERTICAL_RESOLUTION,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = false,
|
||||
.mirrorX = false,
|
||||
.mirrorY = false,
|
||||
.invertColor = false,
|
||||
.bufferSize = DISPLAY_DRAW_BUFFER_SIZE, // 0 -> default 1/10 screen
|
||||
.touch = createTouch(),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = GPIO_NUM_NC,
|
||||
.lvglSwapBytes = false,
|
||||
.rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR // BGR for this display
|
||||
};
|
||||
|
||||
// Create the SPI configuration (from EspLcdSpiDisplay base class)
|
||||
auto spi_configuration = std::make_shared<EspLcdSpiDisplay::SpiConfiguration>(EspLcdSpiDisplay::SpiConfiguration {
|
||||
.spiHostDevice = DISPLAY_SPI_HOST,
|
||||
.csPin = DISPLAY_PIN_CS,
|
||||
.dcPin = DISPLAY_PIN_DC,
|
||||
.pixelClockFrequency = 40'000'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
return std::make_shared<St7789Display>(panel_configuration, spi_configuration);
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_common.h"
|
||||
#include <memory>
|
||||
|
||||
// Display (ST7789P3 on this board)
|
||||
constexpr auto DISPLAY_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto DISPLAY_PIN_CS = GPIO_NUM_15;
|
||||
constexpr auto DISPLAY_PIN_DC = GPIO_NUM_2;
|
||||
constexpr auto DISPLAY_HORIZONTAL_RESOLUTION = 240;
|
||||
constexpr auto DISPLAY_VERTICAL_RESOLUTION = 320;
|
||||
constexpr auto DISPLAY_DRAW_BUFFER_HEIGHT = (DISPLAY_VERTICAL_RESOLUTION / 10);
|
||||
constexpr auto DISPLAY_DRAW_BUFFER_SIZE = (DISPLAY_HORIZONTAL_RESOLUTION * DISPLAY_DRAW_BUFFER_HEIGHT);
|
||||
constexpr auto DISPLAY_BACKLIGHT_PIN = GPIO_NUM_27;
|
||||
|
||||
// Touch (XPT2046, resistive, shared SPI with display)
|
||||
constexpr auto TOUCH_MISO_PIN = GPIO_NUM_12;
|
||||
constexpr auto TOUCH_MOSI_PIN = GPIO_NUM_13;
|
||||
constexpr auto TOUCH_SCK_PIN = GPIO_NUM_14;
|
||||
constexpr auto TOUCH_CS_PIN = GPIO_NUM_33;
|
||||
constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36;
|
||||
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -1,12 +0,0 @@
|
||||
#include "Power.h"
|
||||
|
||||
#include <ChargeFromAdcVoltage.h>
|
||||
#include <EstimatedPower.h>
|
||||
|
||||
std::shared_ptr<tt::hal::power::PowerDevice> createPower() {
|
||||
ChargeFromAdcVoltage::Configuration configuration;
|
||||
// 2.0 ratio, but +.11 added as display voltage sag compensation.
|
||||
configuration.adcMultiplier = 2.11;
|
||||
|
||||
return std::make_shared<EstimatedPower>(configuration);
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
|
||||
std::shared_ptr<tt::hal::power::PowerDevice> createPower();
|
||||
@ -1,13 +1,16 @@
|
||||
/dts-v1/;
|
||||
|
||||
#include <tactility/bindings/root.h>
|
||||
#include <tactility/bindings/battery_sense.h>
|
||||
#include <tactility/bindings/esp32_adc_oneshot.h>
|
||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/xpt2046.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -31,6 +34,31 @@
|
||||
pin-scl = <&gpio0 25 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
adc0 {
|
||||
compatible = "espressif,esp32-adc-oneshot";
|
||||
unit-id = <ADC_UNIT_1>;
|
||||
channels = <ADC_CHANNEL_6 ADC_ATTEN_DB_12 ADC_BITWIDTH_DEFAULT>;
|
||||
};
|
||||
|
||||
// Matches the deprecated HAL's old ChargeFromAdcVoltage config: adcMultiplier=2.11,
|
||||
// adcRefVoltage=3.3 (default), voltageMin/Max=3.2/4.2 (default, same as battery-sense's own
|
||||
// fixed curve - see TactilityKernel/source/drivers/battery_sense.cpp).
|
||||
battery-sense {
|
||||
compatible = "battery-sense";
|
||||
io-channel = <&adc0 0>;
|
||||
reference-voltage-mv = <3300>;
|
||||
multiplier = <2110>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <40000>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
@ -39,13 +67,23 @@
|
||||
pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
compatible = "sitronix,st7789";
|
||||
horizontal-resolution = <240>;
|
||||
vertical-resolution = <320>;
|
||||
bgr-order;
|
||||
pixel-clock-hz = <40000000>;
|
||||
pin-dc = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "pointer-placeholder";
|
||||
compatible = "xptek,xpt2046";
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
mirror-x;
|
||||
mirror-y;
|
||||
};
|
||||
};
|
||||
|
||||
@ -56,7 +94,7 @@
|
||||
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -7,10 +7,15 @@ hardware.target=ESP32
|
||||
hardware.flashSize=4MB
|
||||
hardware.spiRam=false
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=125
|
||||
|
||||
touch.calibrationSupported=true
|
||||
touch.calibrationRequired=false
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/st7789-module
|
||||
- Drivers/xpt2046-module
|
||||
dts: cyd,e32r32p.dts
|
||||
|
||||
@ -81,7 +81,8 @@
|
||||
pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
|
||||
miso-pull-up;
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port ILI934x XPT2046 PwmBacklight driver
|
||||
REQUIRES TactilityKernel driver
|
||||
)
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
#include "PwmBacklight.h"
|
||||
#include "devices/Display.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
return driver::pwmbacklight::init(GPIO_NUM_27);
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,49 +0,0 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <Ili934xDisplay.h>
|
||||
#include <Xpt2046Touch.h>
|
||||
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
std::shared_ptr<Xpt2046Touch> createTouch() {
|
||||
auto configuration = std::make_unique<Xpt2046Touch::Configuration>(
|
||||
LCD_SPI_HOST,
|
||||
TOUCH_PIN_CS,
|
||||
LCD_HORIZONTAL_RESOLUTION,
|
||||
LCD_VERTICAL_RESOLUTION,
|
||||
false,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
return std::make_shared<Xpt2046Touch>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
Ili934xDisplay::Configuration panel_configuration = {
|
||||
.horizontalResolution = LCD_HORIZONTAL_RESOLUTION,
|
||||
.verticalResolution = LCD_VERTICAL_RESOLUTION,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = false,
|
||||
.mirrorX = true,
|
||||
.mirrorY = false,
|
||||
.invertColor = false,
|
||||
.swapBytes = true,
|
||||
.bufferSize = LCD_BUFFER_SIZE,
|
||||
.touch = createTouch(),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = GPIO_NUM_NC,
|
||||
.rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR
|
||||
};
|
||||
|
||||
auto spi_configuration = std::make_shared<Ili934xDisplay::SpiConfiguration>(Ili934xDisplay::SpiConfiguration {
|
||||
.spiHostDevice = LCD_SPI_HOST,
|
||||
.csPin = LCD_PIN_CS,
|
||||
.dcPin = LCD_PIN_DC,
|
||||
.pixelClockFrequency = 40'000'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
return std::make_shared<Ili934xDisplay>(panel_configuration, spi_configuration, true);
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
constexpr auto LCD_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto LCD_PIN_CS = GPIO_NUM_15;
|
||||
constexpr auto TOUCH_PIN_CS = GPIO_NUM_33;
|
||||
constexpr auto LCD_PIN_DC = GPIO_NUM_2; // RS
|
||||
constexpr auto LCD_HORIZONTAL_RESOLUTION = 240;
|
||||
constexpr auto LCD_VERTICAL_RESOLUTION = 320;
|
||||
constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10;
|
||||
constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT;
|
||||
constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8;
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -7,10 +7,15 @@ hardware.target=ESP32
|
||||
hardware.flashSize=4MB
|
||||
hardware.spiRam=false
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=143
|
||||
|
||||
touch.calibrationSupported=true
|
||||
touch.calibrationRequired=false
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/ili9341-module
|
||||
- Drivers/xpt2046-module
|
||||
dts: elecrow,crowpanel-basic-28.dts
|
||||
|
||||
@ -7,8 +7,9 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/ili9341.h>
|
||||
#include <bindings/xpt2046.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -32,6 +33,15 @@
|
||||
pin-scl = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <40000>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
@ -41,13 +51,23 @@
|
||||
pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
max-transfer-size = <65536>;
|
||||
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
compatible = "ilitek,ili9341";
|
||||
horizontal-resolution = <240>;
|
||||
vertical-resolution = <320>;
|
||||
mirror-x;
|
||||
bgr-order;
|
||||
pixel-clock-hz = <40000000>;
|
||||
pin-dc = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "pointer-placeholder";
|
||||
compatible = "xptek,xpt2046";
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
mirror-x;
|
||||
};
|
||||
};
|
||||
|
||||
@ -58,7 +78,7 @@
|
||||
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -15,4 +15,7 @@ display.size=3.5"
|
||||
display.shape=rectangle
|
||||
display.dpi=165
|
||||
|
||||
touch.calibrationSupported=true
|
||||
touch.calibrationRequired=false
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
@ -77,7 +77,8 @@
|
||||
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
|
||||
miso-pull-up;
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port RgbDisplay GT911 PwmBacklight driver
|
||||
INCLUDE_DIRS "source"
|
||||
REQUIRES Tactility
|
||||
)
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
#include "devices/Display.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static bool initBoot() {
|
||||
// Note: I tried 100 Hz to 100 kHz and couldn't get the flickering to stop
|
||||
return driver::pwmbacklight::init(GPIO_NUM_2);
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,109 +0,0 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <Gt911Touch.h>
|
||||
#include <PwmBacklight.h>
|
||||
#include <RgbDisplay.h>
|
||||
#include <tactility/check.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
// Note for future changes: Reset pin is 38 and interrupt pin is 18
|
||||
// or INT = NC, schematic and other info floating around is kinda conflicting...
|
||||
auto* i2c = device_find_by_name("i2c0");
|
||||
check(i2c);
|
||||
auto configuration = std::make_unique<Gt911Touch::Configuration>(
|
||||
i2c,
|
||||
800,
|
||||
480
|
||||
);
|
||||
|
||||
return std::make_shared<Gt911Touch>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
auto touch = createTouch();
|
||||
|
||||
constexpr uint32_t bufferPixels = 800 * 10;
|
||||
|
||||
esp_lcd_rgb_panel_config_t rgb_panel_config = {
|
||||
.clk_src = LCD_CLK_SRC_DEFAULT,
|
||||
.timings = {
|
||||
.pclk_hz = 15000000,
|
||||
.h_res = 800,
|
||||
.v_res = 480,
|
||||
.hsync_pulse_width = 4,
|
||||
.hsync_back_porch = 43,
|
||||
.hsync_front_porch = 8,
|
||||
.vsync_pulse_width = 4,
|
||||
.vsync_back_porch = 12,
|
||||
.vsync_front_porch = 8,
|
||||
.flags = {
|
||||
.hsync_idle_low = false,
|
||||
.vsync_idle_low = false,
|
||||
.de_idle_high = false,
|
||||
.pclk_active_neg = true,
|
||||
.pclk_idle_high = false
|
||||
}
|
||||
},
|
||||
.data_width = 16,
|
||||
.bits_per_pixel = 0,
|
||||
.num_fbs = 2,
|
||||
.bounce_buffer_size_px = bufferPixels,
|
||||
.sram_trans_align = 8,
|
||||
.psram_trans_align = 64,
|
||||
.hsync_gpio_num = GPIO_NUM_39,
|
||||
.vsync_gpio_num = GPIO_NUM_41,
|
||||
.de_gpio_num = GPIO_NUM_40 ,
|
||||
.pclk_gpio_num = GPIO_NUM_0,
|
||||
.disp_gpio_num = GPIO_NUM_NC,
|
||||
.data_gpio_nums = {
|
||||
GPIO_NUM_8, // B0
|
||||
GPIO_NUM_3, // B1
|
||||
GPIO_NUM_46, // B2
|
||||
GPIO_NUM_9, // B3
|
||||
GPIO_NUM_1, // B4
|
||||
GPIO_NUM_5, // G0
|
||||
GPIO_NUM_6, // G1
|
||||
GPIO_NUM_7, // G2
|
||||
GPIO_NUM_15, // G3
|
||||
GPIO_NUM_16, // G4
|
||||
GPIO_NUM_4, // G5
|
||||
GPIO_NUM_45, // R0
|
||||
GPIO_NUM_48, // R1
|
||||
GPIO_NUM_47, // R2
|
||||
GPIO_NUM_21, // R3
|
||||
GPIO_NUM_14, // R4
|
||||
},
|
||||
.flags = {
|
||||
.disp_active_low = false,
|
||||
.refresh_on_demand = false,
|
||||
.fb_in_psram = true,
|
||||
.double_fb = true,
|
||||
.no_fb = false,
|
||||
.bb_invalidate_cache = false
|
||||
}
|
||||
};
|
||||
|
||||
RgbDisplay::BufferConfiguration buffer_config = {
|
||||
.size = (800 * 480),
|
||||
.useSpi = true,
|
||||
.doubleBuffer = true,
|
||||
.bounceBufferMode = true,
|
||||
.avoidTearing = false
|
||||
};
|
||||
|
||||
auto configuration = std::make_unique<RgbDisplay::Configuration>(
|
||||
rgb_panel_config,
|
||||
buffer_config,
|
||||
touch,
|
||||
LV_COLOR_FORMAT_RGB565,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
driver::pwmbacklight::setBacklightDuty
|
||||
);
|
||||
|
||||
auto display = std::make_shared<RgbDisplay>(std::move(configuration));
|
||||
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -12,6 +12,8 @@ hardware.tinyUsb=true
|
||||
hardware.esptoolFlashFreq=120M
|
||||
hardware.bluetooth=true
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=5.0"
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/rgb-display-module
|
||||
- Drivers/gt911-module
|
||||
dts: elecrow,crowpanel-basic-50.dts
|
||||
|
||||
@ -8,6 +8,9 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <bindings/rgb_display.h>
|
||||
#include <bindings/gt911.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -34,6 +37,16 @@
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 20 GPIO_FLAG_NONE>;
|
||||
|
||||
touch0 {
|
||||
// Reset pin 38 and interrupt pin 18 (or INT = NC) exist on the board but are not
|
||||
// wired up here - conflicting schematic info, unverified (matches the original
|
||||
// deprecated-HAL config).
|
||||
compatible = "goodix,gt911";
|
||||
reg = <0x5D>;
|
||||
x-max = <800>;
|
||||
y-max = <480>;
|
||||
};
|
||||
};
|
||||
|
||||
spi0 {
|
||||
@ -50,6 +63,49 @@
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
pin-backlight = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display0 {
|
||||
compatible = "espressif,esp32-rgb-display";
|
||||
horizontal-resolution = <800>;
|
||||
vertical-resolution = <480>;
|
||||
pixel-clock-hz = <15000000>;
|
||||
hsync-pulse-width = <4>;
|
||||
hsync-back-porch = <43>;
|
||||
hsync-front-porch = <8>;
|
||||
vsync-pulse-width = <4>;
|
||||
vsync-back-porch = <12>;
|
||||
vsync-front-porch = <8>;
|
||||
pclk-active-neg;
|
||||
num-fbs = <2>;
|
||||
double-fb;
|
||||
bounce-buffer-size-px = <8000>;
|
||||
pin-hsync = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-vsync = <&gpio0 41 GPIO_FLAG_NONE>;
|
||||
pin-de = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||
pin-pclk = <&gpio0 0 GPIO_FLAG_NONE>;
|
||||
pin-data0 = <&gpio0 8 GPIO_FLAG_NONE>; // B0
|
||||
pin-data1 = <&gpio0 3 GPIO_FLAG_NONE>; // B1
|
||||
pin-data2 = <&gpio0 46 GPIO_FLAG_NONE>; // B2
|
||||
pin-data3 = <&gpio0 9 GPIO_FLAG_NONE>; // B3
|
||||
pin-data4 = <&gpio0 1 GPIO_FLAG_NONE>; // B4
|
||||
pin-data5 = <&gpio0 5 GPIO_FLAG_NONE>; // G0
|
||||
pin-data6 = <&gpio0 6 GPIO_FLAG_NONE>; // G1
|
||||
pin-data7 = <&gpio0 7 GPIO_FLAG_NONE>; // G2
|
||||
pin-data8 = <&gpio0 15 GPIO_FLAG_NONE>; // G3
|
||||
pin-data9 = <&gpio0 16 GPIO_FLAG_NONE>; // G4
|
||||
pin-data10 = <&gpio0 4 GPIO_FLAG_NONE>; // G5
|
||||
pin-data11 = <&gpio0 45 GPIO_FLAG_NONE>; // R0
|
||||
pin-data12 = <&gpio0 48 GPIO_FLAG_NONE>; // R1
|
||||
pin-data13 = <&gpio0 47 GPIO_FLAG_NONE>; // R2
|
||||
pin-data14 = <&gpio0 21 GPIO_FLAG_NONE>; // R3
|
||||
pin-data15 = <&gpio0 14 GPIO_FLAG_NONE>; // R4
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
|
||||
uart0 {
|
||||
compatible = "espressif,esp32-uart";
|
||||
port = <UART_NUM_0>;
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@ -21,3 +21,5 @@ display.dpi=143
|
||||
cdn.infoMessage=To put the device into bootloader mode: <br/>1. Press the trackball and then the reset button at the same time,<br/>2. Let go of the reset button, then the trackball.<br/><br/>When this website reports that flashing is finished, you likely have to press the reset button.
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
sdkconfig.CONFIG_CODEC_DUMMY_SUPPORT=y
|
||||
@ -3,4 +3,7 @@ dependencies:
|
||||
- Drivers/st7789-module
|
||||
- Drivers/gt911-module
|
||||
- Drivers/lilygo-module
|
||||
- Drivers/es7210-module
|
||||
- Drivers/dummy-i2s-amp-module
|
||||
- Drivers/audio-stream-module
|
||||
dts: lilygo,tdeck.dts
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
|
||||
#include <bindings/gt911.h>
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/es7210.h>
|
||||
#include <bindings/dummy_i2s_amp.h>
|
||||
|
||||
#include <lilygo/bindings/tdeck_keyboard.h>
|
||||
#include <lilygo/bindings/tdeck_keyboard_backlight.h>
|
||||
@ -64,6 +66,34 @@
|
||||
pin-click = <&gpio0 0 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
// i2s0 and i2s1 are declared before i2c0 so i2s1 has started before the es7210 codec (below) references it.
|
||||
// Speaker I2S (MAX98357A amplifier)
|
||||
i2s0 {
|
||||
compatible = "espressif,esp32-i2s";
|
||||
port = <I2S_NUM_0>;
|
||||
pin-bclk = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-ws = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
// Microphone I2S (ES7210), separate port from the speaker
|
||||
i2s1 {
|
||||
compatible = "espressif,esp32-i2s";
|
||||
port = <I2S_NUM_1>;
|
||||
pin-bclk = <&gpio0 47 GPIO_FLAG_NONE>;
|
||||
pin-ws = <&gpio0 21 GPIO_FLAG_NONE>;
|
||||
pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
pin-mclk = <&gpio0 48 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
// MAX98357A class-D speaker amplifier. No I2C. Per schematic, SD_MODE/GAIN_SLOT is
|
||||
// tied via fixed resistors (R21/R22), not driven by an MCU GPIO -- the amp is always
|
||||
// enabled when powered, so no enable-gpio is wired here.
|
||||
speaker0 {
|
||||
compatible = "maxim,max98357a";
|
||||
i2s = <&i2s0>;
|
||||
};
|
||||
|
||||
i2c_internal: i2c0 {
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
@ -90,14 +120,18 @@
|
||||
compatible = "lilygo,tdeck-keyboard-backlight";
|
||||
reg = <0x55>;
|
||||
};
|
||||
};
|
||||
|
||||
i2s0 {
|
||||
compatible = "espressif,esp32-i2s";
|
||||
port = <I2S_NUM_0>;
|
||||
pin-bclk = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-ws = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
// ES7210 microphone ADC. Per schematic all 4 MSM381A3729H9CP mic capsules are
|
||||
// populated (MIC1-4), and AD0/AD1 are unconnected (default low -> address 0x40).
|
||||
// Stock LilyGO firmware drives MIC1/MIC2 at 0dB and MIC3/MIC4 at 37.5dB gain --
|
||||
// the es7210 driver here applies a single gain to all active mics, so per-pair
|
||||
// gain differentiation is not yet replicated.
|
||||
es7210 {
|
||||
compatible = "everest,es7210";
|
||||
reg = <0x40>;
|
||||
i2s = <&i2s1>;
|
||||
mic-mask = <15>;
|
||||
};
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility ButtonControl XPT2046SoftSPI PwmBacklight EstimatedPower ST7789-i8080 driver vfs fatfs
|
||||
REQUIRES TactilityKernel driver
|
||||
)
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
#include "devices/Power.h"
|
||||
#include "devices/Display.h"
|
||||
|
||||
#include <ButtonControl.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
bool initBoot();
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
std::make_shared<Power>(),
|
||||
ButtonControl::createOneButtonControl(0)
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,48 +0,0 @@
|
||||
#include "devices/Power.h"
|
||||
#include "devices/Display.h"
|
||||
|
||||
#include "PwmBacklight.h"
|
||||
#include <Tactility/SystemEvents.h>
|
||||
#include <tactility/log.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
#define TAG "thmi"
|
||||
|
||||
static bool powerOn() {
|
||||
gpio_config_t power_signal_config = {
|
||||
.pin_bit_mask = (1ULL << THMI_POWERON_GPIO) | (1ULL << THMI_POWEREN_GPIO),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (gpio_config(&power_signal_config) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gpio_set_level(THMI_POWERON_GPIO, 1) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gpio_set_level(THMI_POWEREN_GPIO, 1) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initBoot() {
|
||||
LOG_I(TAG, "Powering on the board...");
|
||||
if (!powerOn()) {
|
||||
LOG_E(TAG, "Failed to power on the board.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!driver::pwmbacklight::init(DISPLAY_BL, 30000)) {
|
||||
LOG_E(TAG, "Failed to initialize backlight.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
#include <Xpt2046SoftSpi.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
|
||||
#include "Display.h"
|
||||
#include "PwmBacklight.h"
|
||||
#include "St7789i8080Display.h"
|
||||
|
||||
static bool touchSpiInitialized = false;
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto config = std::make_unique<Xpt2046SoftSpi::Configuration>(
|
||||
TOUCH_MOSI_PIN,
|
||||
TOUCH_MISO_PIN,
|
||||
TOUCH_SCK_PIN,
|
||||
TOUCH_CS_PIN,
|
||||
DISPLAY_HORIZONTAL_RESOLUTION,
|
||||
DISPLAY_VERTICAL_RESOLUTION
|
||||
);
|
||||
|
||||
return std::make_shared<Xpt2046SoftSpi>(std::move(config));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
// Create configuration
|
||||
auto config = St7789i8080Display::Configuration(
|
||||
DISPLAY_CS, // CS
|
||||
DISPLAY_DC, // DC
|
||||
DISPLAY_WR, // WR
|
||||
DISPLAY_RD, // RD
|
||||
{ DISPLAY_I80_D0, DISPLAY_I80_D1, DISPLAY_I80_D2, DISPLAY_I80_D3,
|
||||
DISPLAY_I80_D4, DISPLAY_I80_D5, DISPLAY_I80_D6, DISPLAY_I80_D7 }, // D0..D7
|
||||
DISPLAY_RST, // RST
|
||||
DISPLAY_BL // BL
|
||||
);
|
||||
|
||||
// Set resolution explicitly
|
||||
config.horizontalResolution = DISPLAY_HORIZONTAL_RESOLUTION;
|
||||
config.verticalResolution = DISPLAY_VERTICAL_RESOLUTION;
|
||||
config.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
|
||||
config.touch = createTouch();
|
||||
config.invertColor = false;
|
||||
|
||||
auto display = std::make_shared<St7789i8080Display>(config);
|
||||
return display;
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include <driver/gpio.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
#include "driver/spi_common.h"
|
||||
|
||||
class St7789i8080Display;
|
||||
|
||||
constexpr auto DISPLAY_CS = GPIO_NUM_6;
|
||||
constexpr auto DISPLAY_DC = GPIO_NUM_7;
|
||||
constexpr auto DISPLAY_WR = GPIO_NUM_8;
|
||||
constexpr auto DISPLAY_RD = GPIO_NUM_NC;
|
||||
constexpr auto DISPLAY_RST = GPIO_NUM_NC;
|
||||
constexpr auto DISPLAY_BL = GPIO_NUM_38;
|
||||
constexpr auto DISPLAY_I80_D0 = GPIO_NUM_48;
|
||||
constexpr auto DISPLAY_I80_D1 = GPIO_NUM_47;
|
||||
constexpr auto DISPLAY_I80_D2 = GPIO_NUM_39;
|
||||
constexpr auto DISPLAY_I80_D3 = GPIO_NUM_40;
|
||||
constexpr auto DISPLAY_I80_D4 = GPIO_NUM_41;
|
||||
constexpr auto DISPLAY_I80_D5 = GPIO_NUM_42;
|
||||
constexpr auto DISPLAY_I80_D6 = GPIO_NUM_45;
|
||||
constexpr auto DISPLAY_I80_D7 = GPIO_NUM_46;
|
||||
constexpr auto DISPLAY_HORIZONTAL_RESOLUTION = 240;
|
||||
constexpr auto DISPLAY_VERTICAL_RESOLUTION = 320;
|
||||
|
||||
// Touch (XPT2046, resistive)
|
||||
constexpr auto TOUCH_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto TOUCH_MISO_PIN = GPIO_NUM_4;
|
||||
constexpr auto TOUCH_MOSI_PIN = GPIO_NUM_3;
|
||||
constexpr auto TOUCH_SCK_PIN = GPIO_NUM_1;
|
||||
constexpr auto TOUCH_CS_PIN = GPIO_NUM_2;
|
||||
constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_9;
|
||||
|
||||
// Factory function for registration
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@ -1,90 +0,0 @@
|
||||
#include "Power.h"
|
||||
|
||||
#include <driver/adc.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "Power";
|
||||
|
||||
bool Power::adcInitCalibration() {
|
||||
bool calibrated = false;
|
||||
|
||||
esp_err_t efuse_read_result = esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP_FIT);
|
||||
if (efuse_read_result == ESP_ERR_NOT_SUPPORTED) {
|
||||
LOG_W(TAG, "Calibration scheme not supported, skip software calibration");
|
||||
} else if (efuse_read_result == ESP_ERR_INVALID_VERSION) {
|
||||
LOG_W(TAG, "eFuse not burnt, skip software calibration");
|
||||
} else if (efuse_read_result == ESP_OK) {
|
||||
calibrated = true;
|
||||
LOG_I(TAG, "Calibration success");
|
||||
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, static_cast<adc_bits_width_t>(ADC_WIDTH_BIT_DEFAULT), 0, &adcCharacteristics);
|
||||
} else {
|
||||
LOG_W(TAG, "eFuse read failed, skipping calibration");
|
||||
}
|
||||
|
||||
return calibrated;
|
||||
}
|
||||
|
||||
uint32_t Power::adcReadValue() const {
|
||||
int adc_raw = adc1_get_raw(ADC1_CHANNEL_4);
|
||||
LOG_D(TAG, "Raw data: %d", adc_raw);
|
||||
|
||||
uint32_t voltage;
|
||||
|
||||
if (calibrated) {
|
||||
voltage = esp_adc_cal_raw_to_voltage(adc_raw, &adcCharacteristics);
|
||||
LOG_D(TAG, "Calibrated data: %d mV", (int)voltage);
|
||||
} else {
|
||||
voltage = (adc_raw * 3300) / 4095; // fallback
|
||||
LOG_D(TAG, "Estimated data: %d mV", (int)voltage);
|
||||
}
|
||||
|
||||
return voltage;
|
||||
}
|
||||
|
||||
bool Power::ensureInitialized() {
|
||||
if (!initialized) {
|
||||
|
||||
if (adc1_config_width(ADC_WIDTH_BIT_12) != ESP_OK) {
|
||||
LOG_E(TAG, "ADC1 config width failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_11) != ESP_OK) {
|
||||
LOG_E(TAG, "ADC1 config attenuation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
calibrated = adcInitCalibration();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Power::supportsMetric(MetricType type) const {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case BatteryVoltage:
|
||||
case ChargeLevel:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Power::getMetric(MetricType type, MetricData& data) {
|
||||
if (!ensureInitialized()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case MetricType::BatteryVoltage:
|
||||
data.valueAsUint32 = adcReadValue() * 2;
|
||||
return true;
|
||||
case MetricType::ChargeLevel:
|
||||
data.valueAsUint8 = chargeFromAdcVoltage.estimateCharge(adcReadValue() * 2);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <esp_adc_cal.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <ChargeFromVoltage.h>
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
|
||||
constexpr auto THMI_POWEREN_GPIO = GPIO_NUM_10;
|
||||
constexpr auto THMI_POWERON_GPIO = GPIO_NUM_14;
|
||||
|
||||
using tt::hal::power::PowerDevice;
|
||||
|
||||
class Power final : public PowerDevice {
|
||||
|
||||
ChargeFromVoltage chargeFromAdcVoltage = ChargeFromVoltage(3.3f, 4.2f);
|
||||
esp_adc_cal_characteristics_t adcCharacteristics;
|
||||
bool initialized = false;
|
||||
bool calibrated = false;
|
||||
|
||||
bool adcInitCalibration();
|
||||
uint32_t adcReadValue() const;
|
||||
|
||||
bool ensureInitialized();
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const override { return "T-HMI Power"; }
|
||||
std::string getDescription() const override { return "Power measurement via ADC"; }
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
};
|
||||
@ -12,10 +12,15 @@ hardware.tinyUsb=true
|
||||
hardware.esptoolFlashFreq=120M
|
||||
hardware.bluetooth=true
|
||||
|
||||
dependencies.useDeprecatedHal=false
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=125
|
||||
|
||||
touch.calibrationSupported=true
|
||||
touch.calibrationRequired=false
|
||||
|
||||
lvgl.colorDepth=16
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/xpt2046-softspi-module
|
||||
- Drivers/st7789-i8080-module
|
||||
- Drivers/button-control-module
|
||||
dts: lilygo,thmi.dts
|
||||
|
||||
@ -1,14 +1,19 @@
|
||||
/dts-v1/;
|
||||
|
||||
#include <tactility/bindings/root.h>
|
||||
#include <tactility/bindings/battery_sense.h>
|
||||
#include <tactility/bindings/esp32_adc_oneshot.h>
|
||||
#include <tactility/bindings/esp32_ble.h>
|
||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_sdmmc.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_i8080.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/gpio_hog.h>
|
||||
#include <bindings/button_control.h>
|
||||
#include <bindings/st7789_i8080.h>
|
||||
#include <bindings/xpt2046_softspi.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@ -28,23 +33,84 @@
|
||||
compatible = "espressif,esp32-gpio";
|
||||
gpio-count = <49>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
cs-gpios = <&gpio0 6 GPIO_FLAG_NONE>, // Display
|
||||
<&gpio0 2 GPIO_FLAG_NONE>; // Touch
|
||||
pin-mosi = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 1 GPIO_FLAG_NONE>;
|
||||
|
||||
// Board power-enable pins. Must be asserted before the i8080 bus/display below start, since
|
||||
// devicetree devices are constructed and started earlier (kernel_init()) than the deprecated
|
||||
// HAL's initBoot() used to run. gpio-hog nodes run in declaration order, so they must stay
|
||||
// before the i8080 bus node.
|
||||
power_on {
|
||||
compatible = "tactility,gpio-hog";
|
||||
pin = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||
};
|
||||
|
||||
power_en {
|
||||
compatible = "tactility,gpio-hog";
|
||||
pin = <&gpio0 10 GPIO_FLAG_NONE>;
|
||||
mode = <GPIO_HOG_MODE_OUTPUT_HIGH>;
|
||||
};
|
||||
|
||||
adc0 {
|
||||
compatible = "espressif,esp32-adc-oneshot";
|
||||
unit-id = <ADC_UNIT_1>;
|
||||
channels = <ADC_CHANNEL_4 ADC_ATTEN_DB_12 ADC_BITWIDTH_DEFAULT>;
|
||||
};
|
||||
|
||||
// Battery voltage sits behind a 2:1 divider before reaching the ADC (see the deprecated HAL's
|
||||
// old Power.cpp: adcReadValue() * 2). 3300mV matches its uncalibrated fallback reference
|
||||
// voltage. Charge-percent curve is battery-sense's own fixed 3200-4200mV estimate (see
|
||||
// TactilityKernel/source/drivers/battery_sense.cpp) rather than the old driver's 3300-4200mV
|
||||
// ChargeFromVoltage curve - a shared kernel driver, not a per-board tunable.
|
||||
battery-sense {
|
||||
compatible = "battery-sense";
|
||||
io-channel = <&adc0 0>;
|
||||
reference-voltage-mv = <3300>;
|
||||
multiplier = <2000>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so display power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
frequency-hz = <30000>;
|
||||
};
|
||||
|
||||
i8080_0 {
|
||||
compatible = "espressif,esp32-i8080";
|
||||
pin-dc = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-wr = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
pin-d0 = <&gpio0 48 GPIO_FLAG_NONE>;
|
||||
pin-d1 = <&gpio0 47 GPIO_FLAG_NONE>;
|
||||
pin-d2 = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-d3 = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||
pin-d4 = <&gpio0 41 GPIO_FLAG_NONE>;
|
||||
pin-d5 = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
pin-d6 = <&gpio0 45 GPIO_FLAG_NONE>;
|
||||
pin-d7 = <&gpio0 46 GPIO_FLAG_NONE>;
|
||||
// horizontal-resolution * vertical-resolution / 10 (partial buffer) * 2 bytes/pixel
|
||||
max-transfer-bytes = <15360>;
|
||||
cs-gpios = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
compatible = "sitronix,st7789-i8080";
|
||||
horizontal-resolution = <240>;
|
||||
vertical-resolution = <320>;
|
||||
pixel-clock-hz = <16000000>;
|
||||
backlight = <&display_backlight>;
|
||||
gamma-curve = <2>;
|
||||
};
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
touch {
|
||||
compatible = "xptek,xpt2046-softspi";
|
||||
pin-mosi = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
pin-sck = <&gpio0 1 GPIO_FLAG_NONE>;
|
||||
pin-cs = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
};
|
||||
|
||||
sdmmc0 {
|
||||
|
||||
@ -122,7 +122,8 @@
|
||||
pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||
|
||||
miso-pull-up;
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
status = "disabled";
|
||||
|
||||
@ -104,7 +104,8 @@
|
||||
pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||
|
||||
miso-pull-up;
|
||||
|
||||
sdcard@0 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
frequency-khz = <20000>;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_io_expander esp_io_expander_tca95xx_16bit BQ24295 XPT2046
|
||||
INCLUDE_DIRS "source"
|
||||
REQUIRES Tactility bq24295-module
|
||||
)
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
#include "UnPhoneFeatures.h"
|
||||
#include "devices/Hx8357Display.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
bool initBoot();
|
||||
|
||||
static tt::hal::DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const tt::hal::Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@ -1,197 +0,0 @@
|
||||
#include "UnPhoneFeatures.h"
|
||||
#include <tactility/device.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/Preferences.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <esp_sleep.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "unPhone";
|
||||
|
||||
std::shared_ptr<UnPhoneFeatures> unPhoneFeatures;
|
||||
static std::unique_ptr<tt::Thread> powerThread;
|
||||
|
||||
static const char* bootCountKey = "boot_count";
|
||||
static const char* powerOffCountKey = "power_off_count";
|
||||
static const char* powerSleepKey = "power_sleep_key";
|
||||
|
||||
class DeviceStats {
|
||||
|
||||
tt::Preferences preferences = tt::Preferences("unphone");
|
||||
|
||||
int32_t getValue(const char* key) {
|
||||
int32_t value = 0;
|
||||
preferences.optInt32(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
void setValue(const char* key, int32_t value) {
|
||||
preferences.putInt32(key, value);
|
||||
}
|
||||
|
||||
void increaseValue(const char* key) {
|
||||
int32_t new_value = getValue(key) + 1;
|
||||
setValue(key, new_value);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void notifyBootStart() {
|
||||
increaseValue(bootCountKey);
|
||||
}
|
||||
|
||||
void notifyPowerOff() {
|
||||
increaseValue(powerOffCountKey);
|
||||
}
|
||||
|
||||
void notifyPowerSleep() {
|
||||
increaseValue(powerSleepKey);
|
||||
}
|
||||
|
||||
void printInfo() {
|
||||
LOG_I(TAG, "Device stats:");
|
||||
LOG_I(TAG, " boot: %d", (int)getValue(bootCountKey));
|
||||
LOG_I(TAG, " power off: %d", (int)getValue(powerOffCountKey));
|
||||
LOG_I(TAG, " power sleep: %d", (int)getValue(powerSleepKey));
|
||||
}
|
||||
};
|
||||
|
||||
DeviceStats bootStats;
|
||||
|
||||
enum class PowerState {
|
||||
Initial,
|
||||
On,
|
||||
Off
|
||||
};
|
||||
|
||||
#define DEBUG_POWER_STATES false
|
||||
|
||||
#if DEBUG_POWER_STATES
|
||||
/** Helper method to use the buzzer to signal the different power stages */
|
||||
static void powerInfoBuzz(uint8_t count) {
|
||||
if (DEBUG_POWER_STATES) {
|
||||
uint8_t index = 0;
|
||||
while (index < count) {
|
||||
unPhoneFeatures.setVibePower(true);
|
||||
tt::kernel::delayMillis(50);
|
||||
unPhoneFeatures.setVibePower(false);
|
||||
|
||||
index++;
|
||||
|
||||
if (index < count) {
|
||||
tt::kernel::delayMillis(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void updatePowerSwitch() {
|
||||
static PowerState last_state = PowerState::Initial;
|
||||
|
||||
if (!unPhoneFeatures->isPowerSwitchOn()) {
|
||||
if (last_state != PowerState::Off) {
|
||||
last_state = PowerState::Off;
|
||||
LOG_W(TAG, "Power off");
|
||||
}
|
||||
|
||||
if (!unPhoneFeatures->isUsbPowerConnected()) { // and usb unplugged we go into shipping mode
|
||||
LOG_W(TAG, "Shipping mode until USB connects");
|
||||
|
||||
#if DEBUG_POWER_STATES
|
||||
unPhoneFeatures.setExpanderPower(true);
|
||||
powerInfoBuzz(3);
|
||||
unPhoneFeatures.setExpanderPower(false);
|
||||
#endif
|
||||
|
||||
unPhoneFeatures->turnPeripheralsOff();
|
||||
|
||||
bootStats.notifyPowerOff();
|
||||
|
||||
unPhoneFeatures->setShipping(true); // tell BM to stop supplying power until USB connects
|
||||
} else { // When power switch is off, but USB is plugged in, we wait (deep sleep) until USB is unplugged.
|
||||
LOG_W(TAG, "Waiting for USB disconnect to power off");
|
||||
|
||||
#if DEBUG_POWER_STATES
|
||||
powerInfoBuzz(2);
|
||||
#endif
|
||||
|
||||
unPhoneFeatures->turnPeripheralsOff();
|
||||
|
||||
bootStats.notifyPowerSleep();
|
||||
|
||||
// Deep sleep for 1 minute, then awaken to check power state again
|
||||
// GPIO trigger from power switch also awakens the device
|
||||
unPhoneFeatures->wakeOnPowerSwitch();
|
||||
esp_sleep_enable_timer_wakeup(60000000);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
} else {
|
||||
if (last_state != PowerState::On) {
|
||||
last_state = PowerState::On;
|
||||
LOG_W(TAG, "Power on");
|
||||
|
||||
#if DEBUG_POWER_STATES
|
||||
powerInfoBuzz(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t powerSwitchMain() { // check power switch every 10th of sec
|
||||
while (true) {
|
||||
updatePowerSwitch();
|
||||
tt::kernel::delayMillis(200);
|
||||
}
|
||||
}
|
||||
|
||||
static void startPowerSwitchThread() {
|
||||
powerThread = std::make_unique<tt::Thread>(
|
||||
"unphone_power_switch",
|
||||
4096,
|
||||
[]() { return powerSwitchMain(); }
|
||||
);
|
||||
powerThread->start();
|
||||
}
|
||||
|
||||
std::shared_ptr<Bq24295> bq24295;
|
||||
|
||||
static bool unPhonePowerOn() {
|
||||
// Print early, in case of early crash (info will be from previous boot)
|
||||
bootStats.printInfo();
|
||||
bootStats.notifyBootStart();
|
||||
|
||||
bq24295 = std::make_shared<Bq24295>(device_find_by_name("i2c_internal"));
|
||||
|
||||
unPhoneFeatures = std::make_shared<UnPhoneFeatures>(bq24295);
|
||||
|
||||
if (!unPhoneFeatures->init()) {
|
||||
LOG_E(TAG, "UnPhoneFeatures init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
unPhoneFeatures->printInfo();
|
||||
|
||||
unPhoneFeatures->setBacklightPower(false);
|
||||
unPhoneFeatures->setVibePower(false);
|
||||
unPhoneFeatures->setIrPower(false);
|
||||
unPhoneFeatures->setExpanderPower(false);
|
||||
|
||||
// Turn off the device if power switch is on off state,
|
||||
// instead of waiting for the Thread to start and continue booting
|
||||
updatePowerSwitch();
|
||||
startPowerSwitchThread();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initBoot() {
|
||||
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
|
||||
if (!unPhonePowerOn()) {
|
||||
LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1,306 +0,0 @@
|
||||
#include "UnPhoneFeatures.h"
|
||||
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/rtc_io.h>
|
||||
#include <esp_io_expander.h>
|
||||
#include <esp_sleep.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "unPhoneFeatures";
|
||||
|
||||
namespace pin {
|
||||
static const gpio_num_t BUTTON1 = GPIO_NUM_45; // left button
|
||||
static const gpio_num_t BUTTON2 = GPIO_NUM_0; // middle button
|
||||
static const gpio_num_t BUTTON3 = GPIO_NUM_21; // right button
|
||||
static const gpio_num_t IR_LEDS = GPIO_NUM_12;
|
||||
static const gpio_num_t LED_RED = GPIO_NUM_13;
|
||||
static const gpio_num_t POWER_SWITCH = GPIO_NUM_18;
|
||||
} // namespace pin
|
||||
|
||||
namespace expanderpin {
|
||||
static const esp_io_expander_pin_num_t BACKLIGHT = IO_EXPANDER_PIN_NUM_2;
|
||||
static const esp_io_expander_pin_num_t EXPANDER_POWER = IO_EXPANDER_PIN_NUM_0; // enable exp brd if high
|
||||
static const esp_io_expander_pin_num_t LED_GREEN = IO_EXPANDER_PIN_NUM_9;
|
||||
static const esp_io_expander_pin_num_t LED_BLUE = IO_EXPANDER_PIN_NUM_13;
|
||||
static const esp_io_expander_pin_num_t USB_VSENSE = IO_EXPANDER_PIN_NUM_14;
|
||||
static const esp_io_expander_pin_num_t VIBE = IO_EXPANDER_PIN_NUM_7;
|
||||
} // namespace expanderpin
|
||||
|
||||
// TODO: Make part of a new type of UnPhoneFeatures data struct that holds all the thread-related data
|
||||
QueueHandle_t interruptQueue;
|
||||
|
||||
static void IRAM_ATTR navButtonInterruptHandler(void* args) {
|
||||
int pinNumber = (int)args;
|
||||
xQueueSendFromISR(interruptQueue, &pinNumber, NULL);
|
||||
}
|
||||
|
||||
static int32_t buttonHandlingThreadMain(const bool* interrupted) {
|
||||
int pinNumber;
|
||||
while (!*interrupted) {
|
||||
if (xQueueReceive(interruptQueue, &pinNumber, portMAX_DELAY)) {
|
||||
// The buttons might generate more than 1 click because of how they are built
|
||||
LOG_I(TAG, "Pressed button %d", pinNumber);
|
||||
if (pinNumber == pin::BUTTON1) {
|
||||
tt::app::stop();
|
||||
}
|
||||
|
||||
// Debounce all events for a short period of time
|
||||
// This is easier than keeping track when each button was last pressed
|
||||
tt::kernel::delayMillis(50);
|
||||
xQueueReset(interruptQueue);
|
||||
tt::kernel::delayMillis(50);
|
||||
xQueueReset(interruptQueue);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UnPhoneFeatures::~UnPhoneFeatures() {
|
||||
if (buttonHandlingThread.getState() != tt::Thread::State::Stopped) {
|
||||
buttonHandlingThreadInterruptRequest = true;
|
||||
buttonHandlingThread.join();
|
||||
}
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::initPowerSwitch() {
|
||||
gpio_config_t config = {
|
||||
.pin_bit_mask = BIT64(pin::POWER_SWITCH),
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_POSEDGE,
|
||||
};
|
||||
|
||||
if (gpio_config(&config) != ESP_OK) {
|
||||
LOG_E(TAG, "Power pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rtc_gpio_pullup_en(pin::POWER_SWITCH) == ESP_OK &&
|
||||
rtc_gpio_pulldown_en(pin::POWER_SWITCH) == ESP_OK) {
|
||||
return true;
|
||||
} else {
|
||||
LOG_E(TAG, "Failed to set RTC for power switch");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::initNavButtons() {
|
||||
if (!initGpioExpander()) {
|
||||
LOG_E(TAG, "GPIO expander init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
interruptQueue = xQueueCreate(4, sizeof(int));
|
||||
|
||||
buttonHandlingThread.setName("unphone_buttons");
|
||||
buttonHandlingThread.setPriority(tt::Thread::Priority::High);
|
||||
buttonHandlingThread.setStackSize(3072);
|
||||
buttonHandlingThread.setMainFunction(
|
||||
[this] {
|
||||
return buttonHandlingThreadMain(&this->buttonHandlingThreadInterruptRequest);
|
||||
}
|
||||
);
|
||||
buttonHandlingThread.start();
|
||||
|
||||
uint64_t pin_mask =
|
||||
BIT64(pin::BUTTON1) |
|
||||
BIT64(pin::BUTTON2) |
|
||||
BIT64(pin::BUTTON3);
|
||||
|
||||
gpio_config_t config = {
|
||||
.pin_bit_mask = pin_mask,
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
/**
|
||||
* We have to listen to the button release (= positive signal).
|
||||
* If we listen to button press, the buttons might create more than 1 signal
|
||||
* when they are continuously pressed.
|
||||
*/
|
||||
.intr_type = GPIO_INTR_POSEDGE,
|
||||
};
|
||||
|
||||
if (gpio_config(&config) != ESP_OK) {
|
||||
LOG_E(TAG, "Nav button pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
gpio_install_isr_service(0) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON1, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON1)) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON2, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON2)) != ESP_OK ||
|
||||
gpio_isr_handler_add(pin::BUTTON3, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON3)) != ESP_OK
|
||||
) {
|
||||
LOG_E(TAG, "Nav buttons ISR init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::initOutputPins() {
|
||||
uint64_t output_pin_mask =
|
||||
BIT64(pin::IR_LEDS) |
|
||||
BIT64(pin::LED_RED);
|
||||
|
||||
gpio_config_t config = {
|
||||
.pin_bit_mask = output_pin_mask,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (gpio_config(&config) != ESP_OK) {
|
||||
LOG_E(TAG, "Output pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::initGpioExpander() {
|
||||
// ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_110 corresponds with 0x26 from the docs at
|
||||
// https://gitlab.com/hamishcunningham/unphonelibrary/-/blob/main/unPhone.h?ref_type=heads#L206
|
||||
if (esp_io_expander_new_i2c_tca95xx_16bit(I2C_NUM_0, ESP_IO_EXPANDER_I2C_TCA9555_ADDRESS_110, &ioExpander) != ESP_OK) {
|
||||
LOG_E(TAG, "IO expander init failed");
|
||||
return false;
|
||||
}
|
||||
assert(ioExpander != nullptr);
|
||||
|
||||
// Output pins
|
||||
|
||||
/**
|
||||
* Important:
|
||||
* If you clear the pins too late, the display or vibration motor might briefly turn on.
|
||||
*/
|
||||
|
||||
esp_io_expander_set_dir(ioExpander, expanderpin::BACKLIGHT, IO_EXPANDER_OUTPUT);
|
||||
esp_io_expander_set_level(ioExpander, expanderpin::BACKLIGHT, 0);
|
||||
|
||||
esp_io_expander_set_dir(ioExpander, expanderpin::EXPANDER_POWER, IO_EXPANDER_OUTPUT);
|
||||
|
||||
esp_io_expander_set_dir(ioExpander, expanderpin::LED_GREEN, IO_EXPANDER_OUTPUT);
|
||||
esp_io_expander_set_level(ioExpander, expanderpin::LED_GREEN, 0);
|
||||
|
||||
esp_io_expander_set_dir(ioExpander, expanderpin::LED_BLUE, IO_EXPANDER_OUTPUT);
|
||||
esp_io_expander_set_level(ioExpander, expanderpin::LED_BLUE, 0);
|
||||
|
||||
esp_io_expander_set_dir(ioExpander, expanderpin::VIBE, IO_EXPANDER_OUTPUT);
|
||||
esp_io_expander_set_level(ioExpander, expanderpin::VIBE, 0);
|
||||
|
||||
// Input pins
|
||||
|
||||
esp_io_expander_set_dir(ioExpander, expanderpin::USB_VSENSE, IO_EXPANDER_INPUT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::init() {
|
||||
LOG_I(TAG, "init");
|
||||
|
||||
if (!initGpioExpander()) {
|
||||
LOG_E(TAG, "GPIO expander init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initNavButtons()) {
|
||||
LOG_E(TAG, "Input pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initOutputPins()) {
|
||||
LOG_E(TAG, "Output pin init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initPowerSwitch()) {
|
||||
LOG_E(TAG, "Power button init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void UnPhoneFeatures::printInfo() const {
|
||||
esp_io_expander_print_state(ioExpander);
|
||||
batteryManagement->printInfo();
|
||||
bool backlight_power;
|
||||
const char* backlight_power_state = getBacklightPower(backlight_power) && backlight_power ? "on" : "off";
|
||||
LOG_I(TAG, "Backlight: %s", backlight_power_state);
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::setRgbLed(bool red, bool green, bool blue) const {
|
||||
assert(ioExpander != nullptr);
|
||||
return gpio_set_level(pin::LED_RED, red ? 1U : 0U) == ESP_OK &&
|
||||
esp_io_expander_set_level(ioExpander, expanderpin::LED_GREEN, green ? 1U : 0U) == ESP_OK &&
|
||||
esp_io_expander_set_level(ioExpander, expanderpin::LED_BLUE, blue ? 1U : 0U) == ESP_OK;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::setBacklightPower(bool on) const {
|
||||
assert(ioExpander != nullptr);
|
||||
return esp_io_expander_set_level(ioExpander, expanderpin::BACKLIGHT, on ? 1U : 0U) == ESP_OK;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::getBacklightPower(bool& on) const {
|
||||
assert(ioExpander != nullptr);
|
||||
uint32_t level_mask;
|
||||
if (esp_io_expander_get_level(ioExpander, expanderpin::BACKLIGHT, &level_mask) == ESP_OK) {
|
||||
on = level_mask != 0U;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::setIrPower(bool on) const {
|
||||
assert(ioExpander != nullptr);
|
||||
return gpio_set_level(pin::IR_LEDS, on ? 1U : 0U) == ESP_OK;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::setVibePower(bool on) const {
|
||||
assert(ioExpander != nullptr);
|
||||
return esp_io_expander_set_level(ioExpander, expanderpin::VIBE, on ? 1U : 0U) == ESP_OK;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::setExpanderPower(bool on) const {
|
||||
assert(ioExpander != nullptr);
|
||||
return esp_io_expander_set_level(ioExpander, expanderpin::EXPANDER_POWER, on ? 1U : 0U) == ESP_OK;
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::isPowerSwitchOn() const {
|
||||
return gpio_get_level(pin::POWER_SWITCH) > 0;
|
||||
}
|
||||
|
||||
void UnPhoneFeatures::turnPeripheralsOff() const {
|
||||
setExpanderPower(false);
|
||||
setBacklightPower(false);
|
||||
setIrPower(false);
|
||||
setRgbLed(false, false, false);
|
||||
setVibePower(false);
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::setShipping(bool on) const {
|
||||
if (on) {
|
||||
LOG_W(TAG, "setShipping: on");
|
||||
batteryManagement->setWatchDogTimer(Bq24295::WatchDogTimer::Disabled);
|
||||
batteryManagement->setBatFetOn(false);
|
||||
} else {
|
||||
LOG_W(TAG, "setShipping: off");
|
||||
batteryManagement->setWatchDogTimer(Bq24295::WatchDogTimer::Enabled40s);
|
||||
batteryManagement->setBatFetOn(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void UnPhoneFeatures::wakeOnPowerSwitch() const {
|
||||
esp_sleep_enable_ext0_wakeup(pin::POWER_SWITCH, 1);
|
||||
}
|
||||
|
||||
bool UnPhoneFeatures::isUsbPowerConnected() const {
|
||||
return batteryManagement->isUsbPowerConnected();
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Bq24295.h>
|
||||
#include <Tactility/Thread.h>
|
||||
#include <esp_io_expander_tca95xx_16bit.h>
|
||||
|
||||
/**
|
||||
* Easy access to GPIO pins
|
||||
*/
|
||||
class UnPhoneFeatures final {
|
||||
|
||||
private:
|
||||
|
||||
esp_io_expander_handle_t ioExpander = nullptr;
|
||||
tt::Thread buttonHandlingThread;
|
||||
bool buttonHandlingThreadInterruptRequest = false;
|
||||
|
||||
bool initNavButtons();
|
||||
static bool initOutputPins();
|
||||
static bool initPowerSwitch();
|
||||
bool initGpioExpander();
|
||||
|
||||
std::shared_ptr<Bq24295> batteryManagement;
|
||||
|
||||
public:
|
||||
|
||||
explicit UnPhoneFeatures(std::shared_ptr<Bq24295> bq24295) : batteryManagement(std::move(bq24295)) {
|
||||
assert(batteryManagement != nullptr);
|
||||
}
|
||||
|
||||
~UnPhoneFeatures();
|
||||
|
||||
bool init();
|
||||
|
||||
bool setBacklightPower(bool on) const;
|
||||
bool getBacklightPower(bool& on) const;
|
||||
bool setIrPower(bool on) const;
|
||||
bool setVibePower(bool on) const;
|
||||
bool setExpanderPower(bool on) const;
|
||||
|
||||
bool isPowerSwitchOn() const;
|
||||
|
||||
void turnPeripheralsOff() const;
|
||||
|
||||
/** Battery management (BQ24295) will stop supplying power until USB connects */
|
||||
bool setShipping(bool on) const;
|
||||
|
||||
void wakeOnPowerSwitch() const;
|
||||
|
||||
bool isUsbPowerConnected() const;
|
||||
|
||||
bool setRgbLed(bool red, bool green, bool blue) const;
|
||||
|
||||
void printInfo() const;
|
||||
};
|
||||
@ -1,119 +0,0 @@
|
||||
#include "Hx8357Display.h"
|
||||
#include "Touch.h"
|
||||
|
||||
#include <UnPhoneFeatures.h>
|
||||
|
||||
#include <hx8357/disp_spi.h>
|
||||
#include <hx8357/hx8357.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "Hx8357Display";
|
||||
|
||||
constexpr auto BUFFER_SIZE = (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_DRAW_BUFFER_HEIGHT * LV_COLOR_DEPTH / 8);
|
||||
|
||||
extern std::shared_ptr<UnPhoneFeatures> unPhoneFeatures;
|
||||
|
||||
bool Hx8357Display::start() {
|
||||
LOG_I(TAG, "start");
|
||||
|
||||
disp_spi_add_device(SPI2_HOST);
|
||||
|
||||
hx8357_reset(GPIO_NUM_46);
|
||||
hx8357_init(UNPHONE_LCD_PIN_DC);
|
||||
uint8_t madctl = (1U << MADCTL_BIT_INDEX_COLUMN_ADDRESS_ORDER);
|
||||
hx8357_set_madctl(madctl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Hx8357Display::stop() {
|
||||
LOG_I(TAG, "stop");
|
||||
disp_spi_remove_device();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Hx8357Display::startLvgl() {
|
||||
LOG_I(TAG, "startLvgl");
|
||||
|
||||
if (lvglDisplay != nullptr) {
|
||||
LOG_W(TAG, "LVGL was already started");
|
||||
return false;
|
||||
}
|
||||
|
||||
lvglDisplay = lv_display_create(UNPHONE_LCD_HORIZONTAL_RESOLUTION, UNPHONE_LCD_VERTICAL_RESOLUTION);
|
||||
lv_display_set_physical_resolution(lvglDisplay, UNPHONE_LCD_HORIZONTAL_RESOLUTION, UNPHONE_LCD_VERTICAL_RESOLUTION);
|
||||
lv_display_set_color_format(lvglDisplay, LV_COLOR_FORMAT_NATIVE);
|
||||
|
||||
// TODO malloc to use SPIRAM
|
||||
buffer = static_cast<uint8_t*>(heap_caps_malloc(BUFFER_SIZE, MALLOC_CAP_DMA));
|
||||
assert(buffer != nullptr);
|
||||
|
||||
lv_display_set_buffers(
|
||||
lvglDisplay,
|
||||
buffer,
|
||||
nullptr,
|
||||
BUFFER_SIZE,
|
||||
LV_DISPLAY_RENDER_MODE_PARTIAL
|
||||
);
|
||||
|
||||
lv_display_set_flush_cb(lvglDisplay, hx8357_flush);
|
||||
|
||||
if (lvglDisplay == nullptr) {
|
||||
LOG_I(TAG, "Failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
unPhoneFeatures->setBacklightPower(true);
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr) {
|
||||
touch_device->startLvgl(lvglDisplay);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Hx8357Display::stopLvgl() {
|
||||
LOG_I(TAG, "stopLvgl");
|
||||
|
||||
if (lvglDisplay == nullptr) {
|
||||
LOG_W(TAG, "LVGL was already stopped");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Just in case
|
||||
disp_wait_for_pending_transactions();
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr && touch_device->getLvglIndev() != nullptr) {
|
||||
LOG_I(TAG, "Stopping touch device");
|
||||
touch_device->stopLvgl();
|
||||
}
|
||||
|
||||
lv_display_delete(lvglDisplay);
|
||||
lvglDisplay = nullptr;
|
||||
|
||||
heap_caps_free(buffer);
|
||||
buffer = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> Hx8357Display::getTouchDevice() {
|
||||
if (touchDevice == nullptr) {
|
||||
touchDevice = std::reinterpret_pointer_cast<tt::hal::touch::TouchDevice>(createTouch());
|
||||
LOG_I(TAG, "Created touch device");
|
||||
}
|
||||
|
||||
return touchDevice;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
return std::make_shared<Hx8357Display>();
|
||||
}
|
||||
|
||||
bool Hx8357Display::Hx8357Driver::drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) {
|
||||
lv_area_t area = { xStart, yStart, xEnd, yEnd };
|
||||
hx8357_flush(nullptr, &area, (uint8_t*)pixelData);
|
||||
return true;
|
||||
}
|
||||
@ -1,66 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/display/DisplayDriver.h>
|
||||
|
||||
#include <esp_lcd_types.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
#define UNPHONE_LCD_SPI_HOST SPI2_HOST
|
||||
#define UNPHONE_LCD_PIN_CS GPIO_NUM_48
|
||||
#define UNPHONE_LCD_PIN_DC GPIO_NUM_47
|
||||
#define UNPHONE_LCD_PIN_RESET GPIO_NUM_46
|
||||
#define UNPHONE_LCD_SPI_FREQUENCY 27000000
|
||||
#define UNPHONE_LCD_HORIZONTAL_RESOLUTION 320
|
||||
#define UNPHONE_LCD_VERTICAL_RESOLUTION 480
|
||||
#define UNPHONE_LCD_DRAW_BUFFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15)
|
||||
|
||||
class Hx8357Display : public tt::hal::display::DisplayDevice {
|
||||
|
||||
uint8_t* buffer = nullptr;
|
||||
lv_display_t* lvglDisplay = nullptr;
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> touchDevice;
|
||||
std::shared_ptr<tt::hal::display::DisplayDriver> nativeDisplay;
|
||||
|
||||
class Hx8357Driver : public tt::hal::display::DisplayDriver {
|
||||
public:
|
||||
tt::hal::display::ColorFormat getColorFormat() const override { return tt::hal::display::ColorFormat::RGB888; }
|
||||
uint16_t getPixelWidth() const override { return UNPHONE_LCD_HORIZONTAL_RESOLUTION; }
|
||||
uint16_t getPixelHeight() const override { return UNPHONE_LCD_VERTICAL_RESOLUTION; }
|
||||
bool drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) override;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const final { return "HX8357"; }
|
||||
std::string getDescription() const final { return "SPI display"; }
|
||||
|
||||
bool start() override;
|
||||
|
||||
bool stop() override;
|
||||
|
||||
bool supportsLvgl() const override { return true; }
|
||||
|
||||
bool startLvgl() override;
|
||||
|
||||
bool stopLvgl() override;
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> getTouchDevice() override;
|
||||
|
||||
lv_display_t* getLvglDisplay() const override { return lvglDisplay; }
|
||||
|
||||
// TODO: Set to true after fixing UnPhoneDisplayDriver
|
||||
bool supportsDisplayDriver() const override { return false; }
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDriver> getDisplayDriver() override {
|
||||
if (nativeDisplay == nullptr) {
|
||||
nativeDisplay = std::make_shared<Hx8357Driver>();
|
||||
}
|
||||
assert(nativeDisplay != nullptr);
|
||||
return nativeDisplay;
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user