Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Buildscripts/properties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,59 @@ function(GET_PROPERTY_FILE_CONTENT PROPERTY_FILE RESULT_VAR)
set(${RESULT_VAR} "${file_content}" PARENT_SCOPE)
endfunction()

function(READ_PROPERTIES_TO_MAP PROPERTY_FILE RESULT_VAR)
get_filename_component(PROPERTY_FILE_ABS ${PROPERTY_FILE} ABSOLUTE)
if (NOT EXISTS ${PROPERTY_FILE_ABS})
message(FATAL_ERROR "Property file not found: ${PROPERTY_FILE}")
endif ()

file(STRINGS ${PROPERTY_FILE_ABS} lines)
set(current_section "")
set(map_content "")

foreach(line IN LISTS lines)
string(STRIP "${line}" line)
if (line STREQUAL "" OR line MATCHES "^#")
continue()
endif ()

if (line MATCHES "^\\[.*\\]$")
set(current_section "${line}")
elseif (line MATCHES "^([^=]+)=(.*)$")
set(key "${CMAKE_MATCH_1}")
set(value "${CMAKE_MATCH_2}")
string(STRIP "${key}" key)
string(STRIP "${value}" value)
# Remove optional quotes from value
if (value MATCHES "^\"(.*)\"$")
set(value "${CMAKE_MATCH_1}")
endif ()

list(APPEND map_content "${current_section}${key}" "${value}")
endif ()
endforeach()

set(${RESULT_VAR} "${map_content}" PARENT_SCOPE)
endfunction()

function(GET_VALUE_FROM_MAP MAP_VAR KEY_NAME RESULT_VAR)
list(FIND ${MAP_VAR} "${KEY_NAME}" key_index)
if (key_index EQUAL -1)
set(${RESULT_VAR} "" PARENT_SCOPE)
return()
endif ()

math(EXPR value_index "${key_index} + 1")
list(GET ${MAP_VAR} ${value_index} value)
set(${RESULT_VAR} "${value}" PARENT_SCOPE)
endfunction()

function(KEY_EXISTS_IN_MAP MAP_VAR KEY_NAME RESULT_VAR)
list(FIND ${MAP_VAR} "${KEY_NAME}" key_index)
if (key_index EQUAL -1)
set(${RESULT_VAR} FALSE PARENT_SCOPE)
else ()
set(${RESULT_VAR} TRUE PARENT_SCOPE)
endif ()
endfunction()

1 change: 0 additions & 1 deletion Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/heltec-wifi-lora-32-v3/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ infoMessage=Due to the small size of the screen, the icons don't render properly
theme=Mono
colorDepth=16
uiScale=70
uiDensity=compact
1 change: 0 additions & 1 deletion Devices/lilygo-tdisplay/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
2 changes: 1 addition & 1 deletion Devices/lilygo-tdisplay/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ dpi=242

[lvgl]
colorDepth=16

uiDensity=compact
1 change: 0 additions & 1 deletion Devices/lilygo-tdongle-s3/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/lilygo-tdongle-s3/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ dpi=186

[lvgl]
colorDepth=16
uiDensity=compact
1 change: 0 additions & 1 deletion Devices/m5stack-cardputer-adv/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ static DeviceVector createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/m5stack-cardputer-adv/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ dpi=139

[lvgl]
colorDepth=16
uiDensity=compact
1 change: 0 additions & 1 deletion Devices/m5stack-cardputer/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ static DeviceVector createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/m5stack-cardputer/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ dpi=139

[lvgl]
colorDepth=16
uiDensity=compact
1 change: 0 additions & 1 deletion Devices/m5stack-stickc-plus/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ static DeviceVector createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/m5stack-stickc-plus/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ dpi=242

[lvgl]
colorDepth=16
uiDensity=compact
1 change: 0 additions & 1 deletion Devices/m5stack-stickc-plus2/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ static DeviceVector createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/m5stack-stickc-plus2/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ dpi=242

[lvgl]
colorDepth=16
uiDensity=compact
102 changes: 92 additions & 10 deletions Devices/m5stack-tab5/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#include "devices/SdCard.h"
#include <driver/gpio.h>

#include <tactility/drivers/i2c_controller.h>

#include <Tactility/hal/Configuration.h>
#include <Tactility/hal/i2c/I2c.h>

using namespace tt::hal;

static const auto LOGGER = tt::Logger("Tab5");
static constexpr auto* TAG = "Tab5";

static DeviceVector createDevices() {
return {
Expand All @@ -16,7 +18,7 @@ static DeviceVector createDevices() {
};
}

static bool initBoot() {
static error_t initPower(::Device* i2c_controller) {
/*
PI4IOE5V6408-1 (0x43)
- Bit 0: RF internal/external switch
Expand Down Expand Up @@ -63,26 +65,106 @@ static bool initBoot() {
};

constexpr auto IO_EXPANDER1_ADDRESS = 0x43;
if (!i2c::masterWriteRegisterArray(I2C_NUM_0, IO_EXPANDER1_ADDRESS, reg_data_io1_1, sizeof(reg_data_io1_1))) {
LOGGER.error("IO expander 1 init failed in phase 1");
return false;
auto error = i2c_controller_write_register_array(i2c_controller, IO_EXPANDER1_ADDRESS, reg_data_io1_1, sizeof(reg_data_io1_1), pdMS_TO_TICKS(100));
if (error != ERROR_NONE) {
LOG_E(TAG, "IO expander 1 init failed in phase 1");
return ERROR_UNDEFINED;
}

constexpr auto IO_EXPANDER2_ADDRESS = 0x44;
if (!i2c::masterWriteRegisterArray(I2C_NUM_0, IO_EXPANDER2_ADDRESS, reg_data_io2, sizeof(reg_data_io2))) {
LOGGER.error("IO expander 2 init failed");
return false;
error = i2c_controller_write_register_array(i2c_controller, IO_EXPANDER2_ADDRESS, reg_data_io2, sizeof(reg_data_io2), pdMS_TO_TICKS(100));
if (error != ERROR_NONE) {
LOG_E(TAG, "IO expander 2 init failed");
return ERROR_UNDEFINED;
}

// The M5Stack code applies this, but it's not known why
// TODO: Remove and test it extensively
tt::kernel::delayTicks(10);

if (!i2c::masterWriteRegisterArray(I2C_NUM_0, IO_EXPANDER1_ADDRESS, reg_data_io1_2, sizeof(reg_data_io1_2))) {
LOGGER.error("IO expander 1 init failed in phase 2");
error = i2c_controller_write_register_array(i2c_controller, IO_EXPANDER1_ADDRESS, reg_data_io1_2, sizeof(reg_data_io1_2), pdMS_TO_TICKS(100));
if (error != ERROR_NONE) {
LOG_E(TAG, "IO expander 1 init failed in phase 2");
return ERROR_UNDEFINED;
}

return ERROR_NONE;
}

static error_t initSound(::Device* i2c_controller) {
// Init data from M5Unified:
// https://github.com/m5stack/M5Unified/blob/master/src/M5Unified.cpp
static constexpr uint8_t ES8388_I2C_ADDR = 0x10;
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0, 0x80, // RESET/ CSM POWER ON
0, 0x00,
0, 0x00,
0, 0x0E,
1, 0x00,
2, 0x0A, // CHIP POWER: power up all
3, 0xFF, // ADC POWER: power down all
4, 0x3C, // DAC POWER: power up and LOUT1/ROUT1/LOUT2/ROUT2 enable
5, 0x00, // ChipLowPower1
6, 0x00, // ChipLowPower2
7, 0x7C, // VSEL
8, 0x00, // set I2S slave mode
// reg9-22 == adc
23, 0x18, // I2S format (16bit)
24, 0x00, // I2S MCLK ratio (128)
25, 0x20, // DAC unmute
26, 0x00, // LDACVOL 0x00~0xC0
27, 0x00, // RDACVOL 0x00~0xC0
28, 0x08, // enable digital click free power up and down
29, 0x00,
38, 0x00, // DAC CTRL16
39, 0xB8, // LEFT Ch MIX
42, 0xB8, // RIGHTCh MIX
43, 0x08, // ADC and DAC separate
45, 0x00, // 0x00=1.5k VREF analog output / 0x10=40kVREF analog output
46, 0x21,
47, 0x21,
48, 0x21,
49, 0x21
};

error_t error = i2c_controller_write_register_array(
i2c_controller,
ES8388_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8388: %s", error_to_string(error));
return error;
}

constexpr auto IO_EXPANDER1_ADDRESS = 0x43;
constexpr auto AMP_REGISTER = 0x05;
// Note: to disable the amplifier, reset the bits
error = i2c_controller_register8_set_bits(i2c_controller, IO_EXPANDER1_ADDRESS, AMP_REGISTER, 0b00000010, pdMS_TO_TICKS(100));
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable amplifier: %s", error_to_string(error));
return error;
}

return ERROR_NONE;
}

static bool initBoot() {
auto* i2c0 = device_find_by_name("i2c0");
check(i2c0, "i2c0 not found");

auto error = initPower(i2c0);
if (error != ERROR_NONE) {
return false;
}

error = initSound(i2c0);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8388");
}

return true;
}

Expand Down
16 changes: 14 additions & 2 deletions Devices/m5stack-tab5/m5stack,tab5.dts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h>
#include <tactility/bindings/esp32_spi.h>

/ {
Expand All @@ -14,15 +15,15 @@
gpio-count = <57>;
};

i2c_internal {
i2c_internal: i2c0 {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>;
clock-frequency = <400000>;
pin-sda = <&gpio0 31 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 32 GPIO_FLAG_NONE>;
};

i2c_port_a {
i2c_port_a: i2c1 {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>;
clock-frequency = <400000>;
Expand All @@ -37,4 +38,15 @@
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 43 GPIO_FLAG_NONE>;
};

// ES8388 and ES7210
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 27 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 29 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 26 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 28 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 30 GPIO_FLAG_NONE>;
};
};
13 changes: 13 additions & 0 deletions Devices/simulator/device.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[general]
vendor=Simulator
name=Tab5Simulator

[apps]
launcherAppId=Launcher

[hardware]
target=POSIX

[lvgl]
colorDepth=16
fontSize=14
1 change: 0 additions & 1 deletion Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ static bool initBoot() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/waveshare-esp32-s3-geek/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dpi=143

[lvgl]
colorDepth=16
uiDensity=compact

[sdkconfig]
# Fix error "PSRAM space not enough for the Flash instructions" on boot:
Expand Down
1 change: 0 additions & 1 deletion Devices/waveshare-s3-lcd-13/Source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ static bool initBoot() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/waveshare-s3-lcd-13/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ dpi=261

[lvgl]
colorDepth=16
uiDensity=compact
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ static bool initBoot() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/waveshare-s3-touch-lcd-128/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dpi=265

[lvgl]
colorDepth=16
uiDensity=compact

[sdkconfig]
# Fix error "PSRAM space not enough for the Flash instructions" on boot:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.uiDensity = UiDensity::Compact,
.createDevices = createDevices
};
1 change: 1 addition & 0 deletions Devices/waveshare-s3-touch-lcd-147/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ warningMessage=Touch doesn't work yet

[lvgl]
colorDepth=16
uiDensity=compact
Loading