Merge develop into main branch (#137)

* SdCard HAL refactored (#135)

- Refactor SdCard HAL
- introduce Lockable

* Screenshot and FatFS improvements (#136)

- Fix screenshots on ESP32
- Improve Screenshot service
- Convert Screenshot app to class-based instead of structs
- Screenshot app now automatically updates when task is finished
- Enable FatFS long filename support

* Re-use common log messages (#138)

For consistency and binary size reduction

* Toolbar spinner should get margin to the right

* More TactilityC features (#139)

* Rewrote Loader

- Simplified Loader by removing custom threa
- Created DispatcherThread
- Move auto-starting apps to Boot app
- Fixed Dispatcher bug where it could get stuck not processing new
messages

* Hide AP settings if the AP is not saved

* Missing from previous commit

* Replace LV_EVENT_CLICKED with LV_EVENT_SHORT_CLICKED

* Refactored files app and created InputDialog (#140)

- Changed Files app so that it has a View and State
- Files app now allows for long-pressing on files to perform actions
- Files app now has rename and delete actions
- Created InputDialog app
- Improved AlertDialog app layout
This commit is contained in:
Ken Van Hoeylandt
2024-12-27 22:12:39 +00:00
committed by GitHub
parent 9033daa6dd
commit 50bd6e8bf6
144 changed files with 3244 additions and 2038 deletions
+16 -9
View File
@@ -19,25 +19,32 @@
#define TDECK_LCD_BACKLIGHT_LEDC_FREQUENCY (4000)
static bool init_spi() {
TT_LOG_I(TAG, LOG_MESSAGE_SPI_INIT_START_FMT, TDECK_SPI_HOST);
spi_bus_config_t bus_config = {
.mosi_io_num = TDECK_SPI_PIN_MOSI,
.miso_io_num = TDECK_SPI_PIN_MISO,
.sclk_io_num = TDECK_SPI_PIN_SCLK,
.quadwp_io_num = -1, // Quad SPI LCD driver is not yet supported
.quadhd_io_num = -1, // Quad SPI LCD driver is not yet supported
.data4_io_num = 0,
.data5_io_num = 0,
.data6_io_num = 0,
.data7_io_num = 0,
.max_transfer_sz = TDECK_SPI_TRANSFER_SIZE_LIMIT,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
};
return spi_bus_initialize(TDECK_SPI_HOST, &bus_config, SPI_DMA_CH_AUTO) == ESP_OK;
}
bool tdeck_init_hardware() {
TT_LOG_I(TAG, "Init SPI");
if (!init_spi()) {
TT_LOG_E(TAG, "Init SPI failed");
if (spi_bus_initialize(TDECK_SPI_HOST, &bus_config, SPI_DMA_CH_AUTO) != ESP_OK) {
TT_LOG_E(TAG, LOG_MESSAGE_SPI_INIT_FAILED_FMT, TDECK_SPI_HOST);
return false;
}
return true;
}
}
bool tdeck_init_hardware() {
return init_spi();
}
+2 -4
View File
@@ -2,21 +2,19 @@
#include "hal/TdeckDisplay.h"
#include "hal/TdeckKeyboard.h"
#include "hal/TdeckPower.h"
#include "hal/sdcard/Sdcard.h"
#include "hal/TdeckSdCard.h"
bool tdeck_init_power();
bool tdeck_init_hardware();
bool tdeck_init_lvgl();
extern const tt::hal::sdcard::SdCard tdeck_sdcard;
extern const tt::hal::Configuration lilygo_tdeck = {
.initBoot = tdeck_init_power,
.initHardware = tdeck_init_hardware,
.initLvgl = tdeck_init_lvgl,
.createDisplay = createDisplay,
.createKeyboard = createKeyboard,
.sdcard = &tdeck_sdcard,
.sdcard = createTdeckSdCard(),
.power = tdeck_get_power,
.i2c = {
tt::hal::i2c::Configuration {
+2 -2
View File
@@ -27,9 +27,9 @@ static bool tdeck_power_on() {
}
bool tdeck_init_power() {
ESP_LOGI(TAG, "Power on");
ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START);
if (!tdeck_power_on()) {
TT_LOG_E(TAG, "Power on failed");
TT_LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
return false;
}
-166
View File
@@ -1,166 +0,0 @@
#include "hal/sdcard/Sdcard.h"
#include "Check.h"
#include "Log.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "lvgl/LvglSync.h"
#define TAG "tdeck_sdcard"
#define TDECK_SDCARD_SPI_HOST SPI2_HOST
#define TDECK_SDCARD_PIN_CS GPIO_NUM_39
#define TDECK_SDCARD_SPI_FREQUENCY 800000U
#define TDECK_SDCARD_FORMAT_ON_MOUNT_FAILED false
#define TDECK_SDCARD_MAX_OPEN_FILES 4
#define TDECK_SDCARD_ALLOC_UNIT_SIZE (16 * 1024)
#define TDECK_SDCARD_STATUS_CHECK_ENABLED false
// Other
#define TDECK_LCD_PIN_CS GPIO_NUM_12
#define TDECK_RADIO_PIN_CS GPIO_NUM_9
typedef struct {
const char* mount_point;
sdmmc_card_t* card;
} MountData;
/**
* Before we can initialize the sdcard's SPI communications, we have to set all
* other SPI pins on the board high.
* See https://github.com/espressif/esp-idf/issues/1597
* See https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino
* @return success result
*/
static bool sdcard_init() {
TT_LOG_D(TAG, "init");
gpio_config_t config = {
.pin_bit_mask = BIT64(TDECK_SDCARD_PIN_CS) | BIT64(TDECK_RADIO_PIN_CS) | BIT64(TDECK_LCD_PIN_CS),
.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) {
TT_LOG_E(TAG, "GPIO init failed");
return false;
}
if (gpio_set_level(TDECK_SDCARD_PIN_CS, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set board CS pin high");
return false;
}
if (gpio_set_level(TDECK_RADIO_PIN_CS, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set radio CS pin high");
return false;
}
if (gpio_set_level(TDECK_LCD_PIN_CS, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set TFT CS pin high");
return false;
}
return true;
}
static void* _Nullable sdcard_mount(const char* mount_point) {
TT_LOG_I(TAG, "Mounting %s", mount_point);
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = TDECK_SDCARD_FORMAT_ON_MOUNT_FAILED,
.max_files = TDECK_SDCARD_MAX_OPEN_FILES,
.allocation_unit_size = TDECK_SDCARD_ALLOC_UNIT_SIZE,
.disk_status_check_enable = TDECK_SDCARD_STATUS_CHECK_ENABLED
};
// Init without card detect (CD) and write protect (WD)
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = TDECK_SDCARD_PIN_CS;
slot_config.host_id = TDECK_SDCARD_SPI_HOST;
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
// The following value is from T-Deck repo's UnitTest.ino project:
// https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino
// Observation: Using this automatically sets the bus to 20MHz
host.max_freq_khz = TDECK_SDCARD_SPI_FREQUENCY;
sdmmc_card_t* card;
esp_err_t ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
TT_LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT.");
} else {
TT_LOG_E(TAG, "Mounting failed (%s)", esp_err_to_name(ret));
}
return nullptr;
}
auto* data = static_cast<MountData*>(malloc(sizeof(MountData)));
*data = (MountData) {
.mount_point = mount_point,
.card = card,
};
return data;
}
static void* sdcard_init_and_mount(const char* mount_point) {
if (!sdcard_init()) {
TT_LOG_E(TAG, "Failed to set SPI CS pins high. This is a pre-requisite for mounting.");
return nullptr;
}
auto* data = static_cast<MountData*>(sdcard_mount(mount_point));
if (data == nullptr) {
TT_LOG_E(TAG, "Mount failed for %s", mount_point);
return nullptr;
}
sdmmc_card_print_info(stdout, data->card);
return data;
}
static void sdcard_unmount(void* context) {
auto* data = static_cast<MountData*>(context);
TT_LOG_I(TAG, "Unmounting %s", data->mount_point);
tt_assert(data != nullptr);
if (esp_vfs_fat_sdcard_unmount(data->mount_point, data->card) != ESP_OK) {
TT_LOG_E(TAG, "Unmount failed for %s", data->mount_point);
}
free(data);
}
// TODO: Refactor to "bool getStatus(Status* status)" method so that it can fail when the lvgl lock fails
static bool sdcard_is_mounted(void* context) {
auto* data = static_cast<MountData*>(context);
/**
* The SD card and the screen are on the same SPI bus.
* Writing and reading to the bus from 2 devices at the same time causes crashes.
* This work-around ensures that this check is only happening when LVGL isn't rendering.
*/
bool locked = tt::lvgl::lock(50); // TODO: Refactor to a more reliable locking mechanism
if (!locked) {
TT_LOG_W(TAG, "Failed to get LVGL lock");
}
bool result = (data != nullptr) && (sdmmc_get_status(data->card) == ESP_OK);
if (locked) {
tt::lvgl::unlock();
}
return result;
}
extern const tt::hal::sdcard::SdCard tdeck_sdcard = {
.mount = &sdcard_init_and_mount,
.unmount = &sdcard_unmount,
.is_mounted = &sdcard_is_mounted,
.mount_behaviour = tt::hal::sdcard::MountBehaviourAtBoot
};
@@ -0,0 +1,34 @@
#include "TdeckSdCard.h"
#include "lvgl/LvglSync.h"
#include "hal/SpiSdCard.h"
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>
#define TDECK_SDCARD_SPI_FREQUENCY 800000U
#define TDECK_SDCARD_PIN_CS GPIO_NUM_39
#define TDECK_LCD_PIN_CS GPIO_NUM_12
#define TDECK_RADIO_PIN_CS GPIO_NUM_9
std::shared_ptr<SdCard> createTdeckSdCard() {
auto* configuration = new tt::hal::SpiSdCard::Config(
TDECK_SDCARD_SPI_FREQUENCY,
TDECK_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
tt::lvgl::getLvglSyncLockable(),
{
TDECK_RADIO_PIN_CS,
TDECK_LCD_PIN_CS
}
);
auto* sdcard = (SdCard*) new SpiSdCard(
std::unique_ptr<SpiSdCard::Config>(configuration)
);
return std::shared_ptr<SdCard>(sdcard);
}
@@ -0,0 +1,7 @@
#pragma once
#include "hal/SdCard.h"
using namespace tt::hal;
std::shared_ptr<SdCard> createTdeckSdCard();