Repository navigation
Waveshare ESP32-S3 Touch AMOLED 1.8" board support #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Loelin
wants to merge
9
commits into
TactilityProject:develop
from
Loelin:waveshare-s3-touch-amoled-18
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
af56730
Add WiFi AP mode in base driver
KenVanHoeylandt 899beb8
Remove webserver, update devices
KenVanHoeylandt d936e86
Remove launcher override
KenVanHoeylandt feca0bd
Fixes
KenVanHoeylandt d3551bd
Waveshare S3 Touch AMOLED 1.8": add device support
Loelin 2378b0e
Add PCF85063A RTC driver; declare it on the 1.8 board
Loelin 1fcb6b4
waveshare-s3-touch-amoled-18: set UI insets to 22 px on all edges
Loelin 9c73e2a
pcf85063: drop removed Driver.owner field
Loelin ccfcfca
waveshare-s3-touch-amoled-18: LCD/touch/BLE reliability fixes and bus…
Loelin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| dependencies: | ||
| - Platforms/platform-esp32 | ||
| - Drivers/st7735-module | ||
| - Drivers/button-control-module | ||
| dts: lilygo,tdongle-s3.dts | ||
| dts-only: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| dependencies: | ||
| - Platforms/platform-esp32 | ||
| - Drivers/qmi8658-module | ||
| - Drivers/st7789-module | ||
| - Platforms/platform-esp32 | ||
| - Drivers/qmi8658-module | ||
| - Drivers/st7789-module | ||
| dts: waveshare,s3-lcd-13.dts | ||
| dts-only: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| file(GLOB_RECURSE SOURCE_FILES source/*.c*) | ||
|
|
||
| idf_component_register( | ||
| SRCS ${SOURCE_FILES} | ||
| INCLUDE_DIRS "source" | ||
| REQUIRES TactilityKernel Tactility TactilityFreeRtos lvgl-module lvgl-window-manager-module esp_driver_i2c esp_driver_gpio | ||
| ) | ||
|
|
||
| # Board-local link-time hooks (see source/lvgl_scaling.cpp and source/lvgl_insets.cpp): keep the | ||
| # Material theme's widget sizes usable while tightening its spacing, and keep the UI clear of the | ||
| # top/bottom edges. No core Tactility/LVGL source is modified. | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=window_manager_configure" APPEND) | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_display_create" APPEND) | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_style_set_pad_top" APPEND) | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_style_set_pad_bottom" APPEND) | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_style_set_pad_left" APPEND) | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_style_set_pad_right" APPEND) | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_style_set_pad_row" APPEND) | ||
| idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=lv_style_set_pad_column" APPEND) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| general.vendor=Waveshare | ||
| general.name=S3 Touch AMOLED 1.8" | ||
| general.incubating=true | ||
|
|
||
| apps.launcherAppId=tactility.launcher | ||
|
|
||
| hardware.target=ESP32S3 | ||
| hardware.flashSize=16MB | ||
| hardware.spiRam=true | ||
| hardware.spiRamMode=OCT | ||
| hardware.spiRamSpeed=120M | ||
| hardware.tinyUsbMsc=true | ||
| hardware.esptoolFlashFreq=120M | ||
| hardware.bluetooth=true | ||
|
|
||
| storage.userDataLocation=Internal | ||
|
|
||
| display.size=1.8" | ||
| display.shape=rectangle | ||
| display.dpi=322 | ||
|
|
||
| lvgl.colorDepth=16 | ||
| lvgl.uiDensity=default | ||
| lvgl.fontSize=22 | ||
|
|
||
| sdkconfig.CONFIG_TASK_WDT_TIMEOUT_S=10 | ||
| sdkconfig.CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=131072 | ||
| # LVGL v9 symbol (v8 was LV_DISP_DEF_REFR_PERIOD). Upstream moved this out of device.py, | ||
| # so pin it per-device: 10 ms keeps the panel above the 16 ms animation tick. | ||
| sdkconfig.CONFIG_LV_DEF_REFR_PERIOD=10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| dependencies: | ||
| - Platforms/platform-esp32 | ||
| - Drivers/sh8601-module | ||
| - Drivers/axp2101-module | ||
| - Drivers/pcf85063-module | ||
| - Drivers/qmi8658-module | ||
| - Drivers/ft5x06-module | ||
| - Drivers/es8311-module | ||
| - Drivers/audio-stream-module | ||
| - Drivers/tca9534-module | ||
| dts: waveshare,s3-touch-amoled-18.dts |
225 changes: 225 additions & 0 deletions
225
Devices/waveshare-s3-touch-amoled-18/source/bluetooth_reconnect.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Board-local Bluetooth auto-reconnect for the Waveshare S3 Touch AMOLED 1.8. | ||
| // | ||
| // Tactility's own auto-connect runs on the "bt-events" thread | ||
| // (Tactility/Source/bluetooth/Bluetooth.cpp). That thread can be blocked while the radio is on, | ||
| // so saved peers (e.g. a BLE keyboard) never get reconnected. This task subscribes to the kernel | ||
| // BT driver directly - its own subscription and its own thread, so it doesn't depend on bt-events | ||
| // - and, whenever the radio is on, scans for and reconnects every saved peer it sees. | ||
|
|
||
| #include <sdkconfig.h> | ||
|
|
||
| #if defined(CONFIG_BT_NIMBLE_ENABLED) | ||
|
|
||
| #include <Tactility/Thread.h> | ||
| #include <Tactility/bluetooth/Bluetooth.h> | ||
| #include <Tactility/bluetooth/BluetoothPairedDevice.h> | ||
|
|
||
| #include <tactility/concurrent/task_event_group.h> | ||
| #include <tactility/device.h> | ||
| #include <tactility/drivers/bluetooth.h> | ||
| #include <tactility/error.h> | ||
| #include <tactility/log.h> | ||
|
|
||
| #include <array> | ||
| #include <atomic> | ||
| #include <cstring> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| namespace tt::bluetooth { | ||
|
|
||
| // The core HID host resolves a peer's address type from a scan cache that is filled in by the | ||
| // (blocked) bt-events thread. The helper that fills it is internal to Tactility (declared in | ||
| // Private/Tactility/bluetooth/BluetoothPrivate.h, which isn't exported to components), so it is | ||
| // re-declared here to prime that cache with the address type this task learns from its own scan. | ||
| void cacheScanAddr(const uint8_t addr[6], uint8_t addr_type); | ||
|
|
||
| } // namespace tt::bluetooth | ||
|
|
||
| namespace { | ||
|
|
||
| constexpr auto* TAG = "WsBtReconnect"; | ||
|
|
||
| // How long the task blocks per wait, and how many of those slices make up one periodic retry. | ||
| // The slice bounds how quickly stop() is noticed; the total paces the retry scan. | ||
| constexpr TickType_t WAIT_SLICE = pdMS_TO_TICKS(500); | ||
| constexpr int RETRY_SLICES = 40; // ~20 s | ||
| // This task runs the same heavy work the core dispatches to the main task (settings::loadAll() | ||
| // plus tt::bluetooth::connect() -> hidHostConnect()), so it needs at least the main task's stack | ||
| // (CONFIG_ESP_MAIN_TASK_STACK_SIZE, 6144). Sized to match NimBLE's host task. | ||
| constexpr size_t TASK_STACK_SIZE = 8192; | ||
|
|
||
| // The advertised name must fit the 31-byte legacy advertising payload (<= 26 chars alongside the | ||
| // advertising flags). "S3 Touch AMOLED 1.8" fits, but it is pinned here so a change to the (longer) | ||
| // UI device name can't silently break advertising. | ||
| constexpr const char* ADVERTISED_NAME = "S3 Touch AMOLED 1.8"; | ||
|
|
||
| std::atomic<bool> reconnect_running { false }; | ||
| std::unique_ptr<tt::Thread> reconnect_thread; | ||
|
|
||
| struct SavedPeer { | ||
| std::array<uint8_t, 6> addr; | ||
| int profile_id; | ||
| bool attempted; | ||
| }; | ||
|
|
||
| // Only ever touched by the task. | ||
| std::vector<SavedPeer> saved_peers; | ||
| Device* bt_device = nullptr; | ||
|
|
||
| void refresh_saved_peers() { | ||
| saved_peers.clear(); | ||
| for (const auto& peer : tt::bluetooth::settings::loadAll()) { | ||
| saved_peers.push_back(SavedPeer { .addr = peer.addr, .profile_id = peer.profileId, .attempted = false }); | ||
| } | ||
| } | ||
|
|
||
| SavedPeer* find_saved_peer(const BtAddr addr) { | ||
| for (auto& peer : saved_peers) { | ||
| if (std::memcmp(peer.addr.data(), addr, 6) == 0) { | ||
| return &peer; | ||
| } | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| void connect_peer(const BtPeerRecord& record) { | ||
| SavedPeer* peer = find_saved_peer(record.addr); | ||
| if (peer == nullptr || peer->attempted) { | ||
| return; | ||
| } | ||
| peer->attempted = true; | ||
|
|
||
| // Prime the core HID host cache with the address type from our own scan. | ||
| tt::bluetooth::cacheScanAddr(record.addr, record.addr_type); | ||
|
|
||
| const auto hex = tt::bluetooth::settings::addrToHex(peer->addr); | ||
| LOG_I(TAG, "Reconnecting saved peer %s (profile=%d)", hex.c_str(), peer->profile_id); | ||
| tt::bluetooth::connect(peer->addr, peer->profile_id); | ||
| } | ||
|
|
||
| void scan_if_idle() { | ||
| if (bt_device == nullptr || saved_peers.empty()) { | ||
| return; | ||
| } | ||
| if (!tt::bluetooth::isRadioOnOrPending(bt_device)) { | ||
| return; | ||
| } | ||
| if (bluetooth_is_scanning(bt_device)) { | ||
| return; | ||
| } | ||
| for (auto& peer : saved_peers) { | ||
| peer.attempted = false; | ||
| } | ||
| bluetooth_scan_start(bt_device); | ||
| } | ||
|
|
||
| int32_t task_main() { | ||
| TaskEventGroup event_group {}; | ||
| task_event_group_construct(&event_group); | ||
|
|
||
| // Wait for the Bluetooth device to be constructed and started (the module starts before the | ||
| // devicetree's devices do). | ||
| while (reconnect_running.load()) { | ||
| if (device_get_first_active_by_type(&BLUETOOTH_TYPE, &bt_device) == ERROR_NONE) { | ||
| break; | ||
| } | ||
| bt_device = nullptr; | ||
| vTaskDelay(pdMS_TO_TICKS(500)); | ||
| } | ||
|
|
||
| BtEventSubscription subscription {}; | ||
| if (!reconnect_running.load() || bt_device == nullptr || | ||
| bluetooth_event_subscribe(bt_device, &subscription, &event_group) != ERROR_NONE) { | ||
| if (bt_device != nullptr) { | ||
| device_put(bt_device); | ||
| bt_device = nullptr; | ||
| } | ||
| task_event_group_destruct(&event_group); | ||
| return 0; | ||
| } | ||
|
|
||
| // Advertise a name that fits the legacy advertising payload (see ADVERTISED_NAME). The driver | ||
| // restarts advertising with it if the radio is already on. | ||
| if (bluetooth_set_device_name(bt_device, ADVERTISED_NAME) != ERROR_NONE) { | ||
| LOG_W(TAG, "Failed to set the advertised Bluetooth name"); | ||
| } | ||
|
|
||
| refresh_saved_peers(); | ||
| scan_if_idle(); | ||
|
|
||
| int slices = 0; | ||
| while (reconnect_running.load()) { | ||
| task_event_group_wait_any(&event_group, nullptr, WAIT_SLICE); | ||
|
|
||
| BtEvent event {}; | ||
| while (bluetooth_event_poll(&subscription, &event) == ERROR_NONE) { | ||
| switch (event.type) { | ||
| case BT_EVENT_RADIO_STATE_CHANGED: | ||
| if (event.radio_state == BT_RADIO_STATE_ON) { | ||
| refresh_saved_peers(); | ||
| scan_if_idle(); | ||
| } | ||
| break; | ||
| case BT_EVENT_SCAN_FINISHED: | ||
| LOG_I(TAG, "Scan finished"); | ||
| break; | ||
| case BT_EVENT_PEER_FOUND: | ||
| connect_peer(event.peer); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Periodic retry: pick up newly paired peers and rescan when nothing connected yet. | ||
| if (++slices >= RETRY_SLICES) { | ||
| slices = 0; | ||
| refresh_saved_peers(); | ||
| scan_if_idle(); | ||
| } | ||
| } | ||
|
|
||
| bluetooth_event_unsubscribe(bt_device, &subscription); | ||
| device_put(bt_device); | ||
| bt_device = nullptr; | ||
| task_event_group_destruct(&event_group); | ||
| return 0; | ||
| } | ||
|
|
||
| void task_start() { | ||
| reconnect_thread = std::make_unique<tt::Thread>( | ||
| "ws-bt-reconnect", | ||
| TASK_STACK_SIZE, | ||
| []() -> int32_t { return task_main(); } | ||
| ); | ||
| reconnect_thread->start(); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| void waveshare_bluetooth_reconnect_start() { | ||
| if (reconnect_running.exchange(true)) { | ||
| return; | ||
| } | ||
| task_start(); | ||
| } | ||
|
|
||
| void waveshare_bluetooth_reconnect_stop() { | ||
| if (!reconnect_running.exchange(false)) { | ||
| return; | ||
| } | ||
| if (reconnect_thread != nullptr) { | ||
| reconnect_thread->join(); | ||
| reconnect_thread.reset(); | ||
| } | ||
| } | ||
|
|
||
| #else | ||
|
|
||
| void waveshare_bluetooth_reconnect_start() {} | ||
| void waveshare_bluetooth_reconnect_stop() {} | ||
|
|
||
| #endif // CONFIG_BT_NIMBLE_ENABLED |
14 changes: 14 additions & 0 deletions
14
Devices/waveshare-s3-touch-amoled-18/source/bluetooth_reconnect.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
|
|
||
| /** | ||
| * Board-local Bluetooth auto-reconnect for the Waveshare S3 Touch AMOLED 1.8. | ||
| * | ||
| * Starts a task that scans and reconnects saved (paired) BLE peers. It runs its own kernel BT | ||
| * event subscription on its own thread instead of relying on Tactility's "bt-events" thread, | ||
| * which can block while the radio is on. | ||
| */ | ||
| void waveshare_bluetooth_reconnect_start(); | ||
|
|
||
| /** Stops the task, if running. */ | ||
| void waveshare_bluetooth_reconnect_stop(); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be merged. Should be fixed in the BT driver properly. I still need to refactor that driver though, which might help with this problem.