Skip to content

Commit

Permalink
Add T-Display S3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
quadule committed Jan 28, 2024
1 parent f222ab9 commit f3351d9
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 36 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
target: [knobby, twatch]
target: [knobby, tdisplay-s3, twatch]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -56,6 +56,7 @@ jobs:
cd upload
mv ~/artifacts/*/* .
unzip -p knobby-firmware.zip firmware.bin > knobby.bin
unzip -p tdisplay-s3-firmware.zip firmware.bin > tdisplay-s3.bin
unzip -p twatch-firmware.zip firmware.bin > twatch.bin
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -75,13 +76,15 @@ jobs:
if: github.ref_type == 'tag'
run:
mv upload/knobby-firmware.zip upload/knobby-firmware-${{ github.ref_name }}.zip;
mv upload/tdisplay-s3-firmware.zip upload/tdisplay-s3-firmware-${{ github.ref_name }}.zip;
mv upload/twatch-firmware.zip upload/twatch-firmware-${{ github.ref_name }}.zip;
aws s3 cp
--metadata "{\"git-version\":\"$(git describe --match="" --dirty --always)\"}"
--recursive
upload
s3://knobby/firmware/;
unzip -d setup/firmware/knobby upload/knobby-firmware-${{ github.ref_name }}.zip;
unzip -d setup/firmware/tdisplay-s3 upload/tdisplay-s3-firmware-${{ github.ref_name }}.zip;
unzip -d setup/firmware/twatch upload/twatch-firmware-${{ github.ref_name }}.zip;
aws s3 cp
--metadata "{\"git-version\":\"$(git describe --match="" --dirty --always)\"}"
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.piolibdeps
.vscode/.browse.c_cpp.db*
.vscode/*.json
build/
setup/firmware/*/*.bin
sdkconfig.knobby
sdkconfig.twatch
!sdkconfig.defaults
sdkconfig.*
2 changes: 1 addition & 1 deletion flash.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
esptool.py --chip esp32 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 ota_data_initial.bin 0x10000 firmware.bin 0x3b0000 spiffs.bin
esptool.py --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 ota_data_initial.bin 0x10000 firmware.bin 0x3b0000 spiffs.bin
2 changes: 1 addition & 1 deletion flash.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
esptool.py --chip esp32 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 ota_data_initial.bin 0x10000 firmware.bin 0x3b0000 spiffs.bin
esptool.py --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 ota_data_initial.bin 0x10000 firmware.bin 0x3b0000 spiffs.bin
35 changes: 35 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,41 @@ build_flags =
lib_deps =
${common.lib_deps}

[env:tdisplay-s3]
board = lilygo-t-display-s3
build_flags =
${common.build_flags}
-DADC_EN=15
-DADC_PIN=4
-DBOARD_HAS_PSRAM=1
-DCONFIG_IDF_TARGET_ESP32S3=1
-DROTARY_ENCODER_A_PIN=2
-DROTARY_ENCODER_B_PIN=3
-DROTARY_ENCODER_BUTTON_PIN=1
-DROTARY_ENCODER_PULSE_COUNT=4
-DUSER_SETUP_LOADED=1
-DST7789_DRIVER=1
-DTFT_INVERSION_ON=1
-DTFT_PARALLEL_8_BIT=1
-DTFT_WIDTH=170
-DTFT_HEIGHT=320
-DTFT_D0=39
-DTFT_D1=40
-DTFT_D2=41
-DTFT_D3=42
-DTFT_D4=45
-DTFT_D5=46
-DTFT_D6=47
-DTFT_D7=48
-DTFT_WR=8
-DTFT_RD=9
-DTFT_CS=6
-DTFT_DC=7
-DTFT_RST=5
-DTFT_BL=38
lib_deps =
${common.lib_deps}

[env:twatch]
build_flags =
${common.build_flags}
Expand Down
2 changes: 1 addition & 1 deletion setup/firmware/knobby/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knobby",
"version": "2024.01.01",
"version": "2024.01.27",
"builds": [
{
"chipFamily": "ESP32",
Expand Down
15 changes: 15 additions & 0 deletions setup/firmware/tdisplay-s3/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "knobby",
"version": "2024.01.27",
"builds": [
{
"chipFamily": "ESP32-S3",
"parts": [
{ "path": "bootloader.bin", "offset": 4096 },
{ "path": "partitions.bin", "offset": 32768 },
{ "path": "ota_data_initial.bin", "offset": 57344 },
{ "path": "firmware.bin", "offset": 65536 }
]
}
]
}
2 changes: 1 addition & 1 deletion setup/firmware/twatch/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knobby",
"version": "2024.01.01",
"version": "2024.01.27",
"builds": [
{
"chipFamily": "ESP32",
Expand Down
1 change: 1 addition & 0 deletions setup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h1>knobby setup</h1>
<p>
<select onchange="document.getElementById('install-button').setAttribute('manifest', `firmware/${this.value}/manifest.json`)">
<option value="knobby">Original Knobby / Lilygo T-Display board</option>
<option value="tdisplay-s3">Lilygo T-Display S3 board</option>
<option value="twatch">Lilygo T-Watch encoder version</option>
</select>
</p>
Expand Down
68 changes: 39 additions & 29 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ void setup() {

knobby.setup();
rtc_gpio_hold_dis((gpio_num_t)ROTARY_ENCODER_BUTTON_PIN);
esp_pm_config_esp32_t pm_config_ls_enable = {
.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.min_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.light_sleep_enable = true
};
ESP_ERROR_CHECK(esp_pm_configure(&pm_config_ls_enable));
setLightSleepEnabled(true);
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));

#ifdef LILYGO_WATCH_2019_WITH_TOUCH
Expand All @@ -56,9 +51,9 @@ void setup() {
ttgo->power->setPowerOutPut(AXP202_LDO3, AXP202_OFF);
ttgo->power->setPowerOutPut(AXP202_LDO4, AXP202_OFF);
#else
ledcSetup(TFT_BL, 12000, 8);
ledcAttachPin(TFT_BL, TFT_BL);
ledcWrite(TFT_BL, 255);
ledcSetup(backlightChannel, 12000, 8);
ledcAttachPin(TFT_BL, backlightChannel);
ledcWrite(backlightChannel, 255);
tft.init();
tft.fillScreen(TFT_BLACK);
#endif
Expand Down Expand Up @@ -366,6 +361,23 @@ void setup() {
if (knobby.powerStatus() == PowerStatusPowered) knobby.printHeader();
}

void setLightSleepEnabled(bool enabled) {
#ifdef CONFIG_IDF_TARGET_ESP32S3
esp_pm_config_esp32s3_t pm_config_ls_enable = {
.max_freq_mhz = CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ,
.min_freq_mhz = CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ,
.light_sleep_enable = enabled
};
#else
esp_pm_config_esp32_t pm_config_ls_enable = {
.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.min_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.light_sleep_enable = enabled
};
#endif
ESP_ERROR_CHECK(esp_pm_configure(&pm_config_ls_enable));
}

void setupKnob() {
ESP32Encoder::useInternalWeakPullResistors = UP;
knob = ESP32Encoder();
Expand Down Expand Up @@ -434,12 +446,7 @@ void loop() {
#else
ledcDetachPin(TFT_BL);
digitalWrite(TFT_BL, HIGH);
esp_pm_config_esp32_t pm_config_ls_enable = {
.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.min_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.light_sleep_enable = true
};
ESP_ERROR_CHECK(esp_pm_configure(&pm_config_ls_enable));
setLightSleepEnabled(true);
#endif
} else if (inputDelta > inactivityMillis + 2 * inactivityFadeOutMillis) {
startDeepSleep();
Expand All @@ -452,18 +459,13 @@ void loop() {
#endif
uint32_t duty = min(max((int)round(fadeProgress * 255.0), minimumDuty), 255);
if (duty >= 250) {
esp_pm_config_esp32_t pm_config_ls_enable = {
.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.min_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.light_sleep_enable = false
};
ESP_ERROR_CHECK(esp_pm_configure(&pm_config_ls_enable));
setLightSleepEnabled(false);
}
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->setBrightness(duty);
#else
if (duty >= 250) ledcAttachPin(TFT_BL, TFT_BL);
ledcWrite(TFT_BL, duty);
if (duty >= 250) ledcAttachPin(TFT_BL, backlightChannel);
ledcWrite(backlightChannel, duty);
#endif
} else if (menuMode == VolumeControl && inputDelta > menuTimeoutMillis) {
setMenuMode(NowPlaying, VolumeButton);
Expand Down Expand Up @@ -1407,13 +1409,19 @@ void drawDeviceMenu() {
}

void drawVolumeControl() {
const uint8_t x = 10;
const uint8_t y = 30;
const uint8_t width = 220;
img.createSprite(width, 40);
const auto x = 10;
const auto y = 30;
const auto padding = 4;
const auto outerRadius = 5;
const auto outerWidth = screenWidth - x * 2;
const auto outerHeight = 32;
const auto innerRadius = 3;
const auto innerWidth = outerWidth - padding * 2;
const auto innerHeight = outerHeight - padding * 2;
img.createSprite(outerWidth, 40);
img.fillSprite(TFT_BLACK);
img.drawRoundRect(0, 0, width, 32, 5, TFT_WHITE);
img.fillRoundRect(4, 4, round(2.12 * menuIndex), 24, 3, TFT_DARKGREY);
img.drawRoundRect(0, 0, outerWidth, outerHeight, outerRadius, TFT_WHITE);
img.fillRoundRect(padding, padding, round(0.01 * menuIndex * innerWidth), innerHeight, innerRadius, TFT_DARKGREY);
img.pushSprite(x, y);
img.deleteSprite();

Expand Down Expand Up @@ -2122,9 +2130,11 @@ void startDeepSleep() {
struct timeval tod;
gettimeofday(&tod, NULL);
lastSleepSeconds = tod.tv_sec;
#ifndef CONFIG_IDF_TARGET_ESP32S3
rtc_gpio_isolate(GPIO_NUM_0); // button 1
rtc_gpio_isolate(GPIO_NUM_35); // button 2
rtc_gpio_isolate(GPIO_NUM_39);
#endif
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
esp_sleep_enable_ext0_wakeup((gpio_num_t)ROTARY_ENCODER_BUTTON_PIN, LOW);
#if CORE_DEBUG_LEVEL < ARDUHAL_LOG_LEVEL_DEBUG
Expand Down
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ bool contains(C&& c, T e) {
const char *hostname = "knobby";
const char *rootMenuItems[] = {"settings", "countries", "genres", "explore", "playlists", "now playing", "users", "devices"};
const char *settingsMenuItems[] = {"about", "update", "orientation", "add user", "log out", "reset settings"};
const uint8_t backlightChannel = 4;
const int screenWidth = TFT_HEIGHT;
const int screenHeight = TFT_WIDTH;
const int centerX = screenWidth / 2;
Expand Down Expand Up @@ -458,6 +459,7 @@ void playMenuPlaylist(MenuModes mode, uint16_t index);
void playUri(const char *uri, const char *name);
void setActiveDevice(SpotifyDevice_t *device);
void setActiveUser(SpotifyUser_t *user);
void setLightSleepEnabled(bool enabled);
void setMenuIndex(uint16_t newMenuIndex);
void setMenuMode(MenuModes newMode, uint16_t newMenuIndex);
void setStatusMessage(const char *message, unsigned long durationMs = statusMessageMillis);
Expand Down

0 comments on commit f3351d9

Please sign in to comment.