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
+1 -1
View File
@@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source" "Source/hal"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_touch_gt911 driver vfs fatfs esp_adc
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_touch_gt911 driver esp_adc
)
+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();
+1 -2
View File
@@ -1,12 +1,11 @@
#include "M5stackCore2.h"
#include "M5stackShared.h"
#include "hal/M5stackPower.h"
extern const tt::hal::Configuration m5stack_core2 = {
.initBoot = m5stack_bootstrap,
.initLvgl = m5stack_lvgl_init,
.createDisplay = createDisplay,
.sdcard = &m5stack_sdcard,
.sdcard = createM5SdCard(),
.power = m5stack_get_power,
.i2c = {
tt::hal::i2c::Configuration {
@@ -1,12 +1,11 @@
#include "M5stackCoreS3.h"
#include "M5stackShared.h"
#include "hal/M5stackPower.h"
const tt::hal::Configuration m5stack_cores3 = {
.initBoot = m5stack_bootstrap,
.initLvgl = m5stack_lvgl_init,
.createDisplay = createDisplay,
.sdcard = &m5stack_sdcard,
.sdcard = createM5SdCard(),
.power = m5stack_get_power,
.i2c = {
tt::hal::i2c::Configuration {
+2 -3
View File
@@ -3,9 +3,8 @@
#include "hal/Power.h"
#include "hal/M5stackTouch.h"
#include "hal/M5stackDisplay.h"
#include "hal/sdcard/Sdcard.h"
#include "hal/M5stackPower.h"
#include "hal/M5stackSdCard.h"
extern bool m5stack_bootstrap();
extern bool m5stack_lvgl_init();
extern const tt::hal::sdcard::SdCard m5stack_sdcard;
-137
View File
@@ -1,137 +0,0 @@
#include "Check.h"
#include "Log.h"
#include "hal/sdcard/Sdcard.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#define TAG "m5stack_sdcard"
#define SDCARD_SPI_HOST SPI2_HOST
#define SDCARD_PIN_CS GPIO_NUM_4
#define SDCARD_SPI_FREQUENCY 800000U
#define SDCARD_FORMAT_ON_MOUNT_FAILED false
#define SDCARD_MAX_OPEN_FILES 4
#define SDCARD_ALLOC_UNIT_SIZE (16 * 1024)
#define SDCARD_STATUS_CHECK_ENABLED false
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(GPIO_NUM_4) | BIT64(GPIO_NUM_5),
.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(GPIO_NUM_4, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set board CS pin high");
return false;
}
if (gpio_set_level(GPIO_NUM_5, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set board CS pin high");
return false;
}
return true;
}
static void* 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 = SDCARD_FORMAT_ON_MOUNT_FAILED,
.max_files = SDCARD_MAX_OPEN_FILES,
.allocation_unit_size = SDCARD_ALLOC_UNIT_SIZE,
.disk_status_check_enable = SDCARD_STATUS_CHECK_ENABLED,
.use_one_fat = false
};
sdmmc_card_t* card;
// Init without card detect (CD) and write protect (WD)
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = SDCARD_PIN_CS;
slot_config.host_id = SDCARD_SPI_HOST;
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
host.max_freq_khz = SDCARD_SPI_FREQUENCY;
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 NULL;
}
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);
}
static bool sdcard_is_mounted(void* context) {
auto* data = static_cast<MountData*>(context);
return (data != nullptr) && (sdmmc_get_status(data->card) == ESP_OK);
}
extern const tt::hal::sdcard::SdCard m5stack_sdcard = {
.mount = &sdcard_init_and_mount,
.unmount = &sdcard_unmount,
.is_mounted = &sdcard_is_mounted,
.mount_behaviour = tt::hal::sdcard::MountBehaviourAnytime
};
@@ -0,0 +1,31 @@
#include "M5stackSdCard.h"
#include "lvgl/LvglSync.h"
#include "hal/SpiSdCard.h"
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>
#define SDCARD_PIN_CS GPIO_NUM_4
#define SDCARD_SPI_FREQUENCY 800000U
std::shared_ptr<SdCard> createM5SdCard() {
auto* configuration = new tt::hal::SpiSdCard::Config(
SDCARD_SPI_FREQUENCY,
SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
tt::lvgl::getLvglSyncLockable(),
{
GPIO_NUM_5
}
);
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> createM5SdCard();
@@ -5,11 +5,10 @@
#include "src/lv_init.h"
#include "SdlDisplay.h"
#include "SdlKeyboard.h"
#include "SimulatorSdCard.h"
#define TAG "hardware"
extern const tt::hal::sdcard::SdCard simulatorSdcard;
static bool initBoot() {
lv_init();
lvgl_task_start();
@@ -31,7 +30,7 @@ extern const tt::hal::Configuration hardware = {
.initBoot = initBoot,
.createDisplay = createDisplay,
.createKeyboard = createKeyboard,
.sdcard = &simulatorSdcard,
.sdcard = std::make_shared<SimulatorSdCard>(),
.power = simulatorPower,
.i2c = {
tt::hal::i2c::Configuration {
@@ -0,0 +1,26 @@
#pragma once
#include "hal/SdCard.h"
using namespace tt::hal;
class SimulatorSdCard : public SdCard {
private:
State state;
public:
SimulatorSdCard() : SdCard(MountBehaviourAtBoot), state(StateUnmounted) {}
bool mount(const char* mountPath) override {
state = StateMounted;
return true;
}
bool unmount() override {
state = StateUnmounted;
return true;
}
State getState() const override {
return state;
}
};
@@ -1,26 +0,0 @@
#include "Tactility.h"
#include "hal/sdcard/Sdcard.h"
static uint32_t fake_handle = 0;
static void* _Nullable sdcard_mount(TT_UNUSED const char* mount_point) {
return &fake_handle;
}
static void* sdcard_init_and_mount(TT_UNUSED const char* mount_point) {
return &fake_handle;
}
static void sdcard_unmount(TT_UNUSED void* context) {
}
static bool sdcard_is_mounted(TT_UNUSED void* context) {
return TT_SCREENSHOT_MODE;
}
extern const tt::hal::sdcard::SdCard simulatorSdcard = {
.mount = &sdcard_init_and_mount,
.unmount = &sdcard_unmount,
.is_mounted = &sdcard_is_mounted,
.mount_behaviour = tt::hal::sdcard::MountBehaviourAtBoot
};
+32 -37
View File
@@ -1,4 +1,4 @@
#include "Config.h"
#include "YellowConfig.h"
#include "TactilityCore.h"
#include "hal/YellowTouchConstants.h"
#include <driver/spi_common.h>
@@ -6,6 +6,8 @@
#define TAG "twodotfour_bootstrap"
static bool init_i2c() {
TT_LOG_I(TAG, LOG_MESSAGE_I2C_INIT_START);
const i2c_config_t i2c_conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = GPIO_NUM_33,
@@ -18,12 +20,12 @@ static bool init_i2c() {
};
if (i2c_param_config(TWODOTFOUR_TOUCH_I2C_PORT, &i2c_conf) != ESP_OK) {
TT_LOG_E(TAG, "i2c config failed");
TT_LOG_E(TAG, LOG_MESSAGE_I2C_INIT_CONFIG_FAILED );
return false;
}
if (i2c_driver_install(TWODOTFOUR_TOUCH_I2C_PORT, i2c_conf.mode, 0, 0, 0) != ESP_OK) {
TT_LOG_E(TAG, "i2c driver install failed");
TT_LOG_E(TAG, LOG_MESSAGE_I2C_INIT_DRIVER_INSTALL_FAILED);
return false;
}
@@ -31,35 +33,46 @@ static bool init_i2c() {
}
static bool init_spi2() {
const spi_bus_config_t bus_config = {
.mosi_io_num = TWODOTFOUR_SPI2_PIN_MOSI,
.miso_io_num = GPIO_NUM_NC,
.sclk_io_num = TWODOTFOUR_SPI2_PIN_SCLK,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.max_transfer_sz = TWODOTFOUR_SPI2_TRANSACTION_LIMIT
};
TT_LOG_I(TAG, LOG_MESSAGE_SPI_INIT_START_FMT, SPI2_HOST);
if (spi_bus_initialize(SPI2_HOST, &bus_config, SPI_DMA_CH_AUTO) != ESP_OK) {
TT_LOG_E(TAG, "SPI bus init failed");
return false;
}
const spi_bus_config_t bus_config = {
.mosi_io_num = TWODOTFOUR_SPI2_PIN_MOSI,
.miso_io_num = GPIO_NUM_NC,
.sclk_io_num = TWODOTFOUR_SPI2_PIN_SCLK,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.max_transfer_sz = TWODOTFOUR_SPI2_TRANSACTION_LIMIT
};
return true;
if (spi_bus_initialize(SPI2_HOST, &bus_config, SPI_DMA_CH_AUTO) != ESP_OK) {
TT_LOG_E(TAG, LOG_MESSAGE_SPI_INIT_FAILED_FMT, SPI2_HOST);
return false;
}
return true;
}
static bool init_spi3() {
TT_LOG_I(TAG, LOG_MESSAGE_SPI_INIT_START_FMT, SPI3_HOST);
const spi_bus_config_t bus_config = {
.mosi_io_num = TWODOTFOUR_SPI3_PIN_MOSI,
.miso_io_num = TWODOTFOUR_SPI3_PIN_MISO,
.sclk_io_num = TWODOTFOUR_SPI3_PIN_SCLK,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.max_transfer_sz = TWODOTFOUR_SPI3_TRANSACTION_LIMIT
.data4_io_num = 0,
.data5_io_num = 0,
.data6_io_num = 0,
.data7_io_num = 0,
.max_transfer_sz = TWODOTFOUR_SPI3_TRANSACTION_LIMIT,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
};
if (spi_bus_initialize(SPI3_HOST, &bus_config, SPI_DMA_CH_AUTO) != ESP_OK) {
TT_LOG_E(TAG, "SPI bus init failed");
TT_LOG_E(TAG, LOG_MESSAGE_SPI_INIT_FAILED_FMT, SPI3_HOST);
return false;
}
@@ -67,23 +80,5 @@ static bool init_spi3() {
}
bool twodotfour_boot() {
TT_LOG_I(TAG, "Init I2C");
if (!init_i2c()) {
TT_LOG_E(TAG, "Init I2C failed");
return false;
}
TT_LOG_I(TAG, "Init SPI2");
if (!init_spi2()) {
TT_LOG_E(TAG, "Init SPI2 failed");
return false;
}
TT_LOG_I(TAG, "Init SPI3");
if (!init_spi3()) {
TT_LOG_E(TAG, "Init SPI3 failed");
return false;
}
return true;
return init_i2c() && init_spi2() && init_spi3();
}
-79
View File
@@ -1,79 +0,0 @@
#include "hal/sdcard/Sdcard.h"
#include "Check.h"
#include "Log.h"
#include "Config.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#define TAG "twodotfour_sdcard"
typedef struct {
const char* mount_point;
sdmmc_card_t* card;
} MountData;
static void* 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 = TWODOTFOUR_SDCARD_FORMAT_ON_MOUNT_FAILED,
.max_files = TWODOTFOUR_SDCARD_MAX_OPEN_FILES,
.allocation_unit_size = TWODOTFOUR_SDCARD_ALLOC_UNIT_SIZE,
.disk_status_check_enable = TWODOTFOUR_SDCARD_STATUS_CHECK_ENABLED
};
sdmmc_card_t* card;
// Init without card detect (CD) and write protect (WD)
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = TWODOTFOUR_SDCARD_PIN_CS;
slot_config.host_id = TWODOTFOUR_SDCARD_SPI_HOST;
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
host.max_freq_khz = TWODOTFOUR_SDCARD_SPI_FREQUENCY;
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
};
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);
}
static bool sdcard_is_mounted(void* context) {
auto* data = static_cast<MountData*>(context);
return (data != nullptr) && (sdmmc_get_status(data->card) == ESP_OK);
}
extern const tt::hal::sdcard::SdCard twodotfour_sdcard = {
.mount = &sdcard_mount,
.unmount = &sdcard_unmount,
.is_mounted = &sdcard_is_mounted,
.mount_behaviour = tt::hal::sdcard::MountBehaviourAnytime
};
+2 -3
View File
@@ -1,16 +1,15 @@
#include "YellowBoard.h"
#include "hal/YellowDisplay.h"
#include "hal/YellowSdCard.h"
bool twodotfour_lvgl_init();
bool twodotfour_boot();
extern const tt::hal::sdcard::SdCard twodotfour_sdcard;
const tt::hal::Configuration yellow_board_24inch_cap = {
.initBoot = &twodotfour_boot,
.initLvgl = &twodotfour_lvgl_init,
.createDisplay = createDisplay,
.sdcard = &twodotfour_sdcard,
.sdcard = createYellowSdCard(),
.power = nullptr,
.i2c = {
tt::hal::i2c::Configuration {
@@ -15,12 +15,3 @@
#define TWODOTFOUR_SPI3_PIN_MOSI GPIO_NUM_23
#define TWODOTFOUR_SPI3_PIN_MISO GPIO_NUM_19
#define TWODOTFOUR_SPI3_TRANSACTION_LIMIT 8192 // TODO: Determine proper limit
// SD Card
#define TWODOTFOUR_SDCARD_SPI_HOST SPI3_HOST
#define TWODOTFOUR_SDCARD_PIN_CS GPIO_NUM_5
#define TWODOTFOUR_SDCARD_SPI_FREQUENCY 800000U
#define TWODOTFOUR_SDCARD_FORMAT_ON_MOUNT_FAILED false
#define TWODOTFOUR_SDCARD_MAX_OPEN_FILES 4
#define TWODOTFOUR_SDCARD_ALLOC_UNIT_SIZE (16 * 1024)
#define TWODOTFOUR_SDCARD_STATUS_CHECK_ENABLED false
@@ -0,0 +1,31 @@
#include "YellowSdCard.h"
#define TAG "twodotfour_sdcard"
#include "lvgl/LvglSync.h"
#include "hal/SpiSdCard.h"
#define SDCARD_SPI_HOST SPI3_HOST
#define SDCARD_PIN_CS GPIO_NUM_5
#define SDCARD_SPI_FREQUENCY 800000U
std::shared_ptr<SdCard> createYellowSdCard() {
auto* configuration = new tt::hal::SpiSdCard::Config(
SDCARD_SPI_FREQUENCY,
SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
nullptr,
std::vector<gpio_num_t>(),
SDCARD_SPI_HOST
);
auto* sdcard = (SdCard*) new SpiSdCard(
std::unique_ptr<SpiSdCard::Config>(configuration)
);
return std::shared_ptr<SdCard>(sdcard);
}
@@ -0,0 +1,8 @@
#pragma once
#include "hal/SdCard.h"
using namespace tt::hal;
std::shared_ptr<SdCard> createYellowSdCard();