mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
Improve SD card setup and fix WiFi
This commit is contained in:
parent
6534bd3841
commit
e22dd87775
@ -122,5 +122,31 @@ extern const Configuration hardwareConfiguration = {
|
||||
.clk_flags = 0
|
||||
}
|
||||
}
|
||||
},
|
||||
.spi = {
|
||||
// SDCard
|
||||
spi::Configuration {
|
||||
.device = SPI3_HOST,
|
||||
.dma = SPI_DMA_CH_AUTO,
|
||||
.config = {
|
||||
.mosi_io_num = GPIO_NUM_44,
|
||||
.miso_io_num = GPIO_NUM_39,
|
||||
.sclk_io_num = GPIO_NUM_43,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.data4_io_num = GPIO_NUM_NC,
|
||||
.data5_io_num = GPIO_NUM_NC,
|
||||
.data6_io_num = GPIO_NUM_NC,
|
||||
.data7_io_num = GPIO_NUM_NC,
|
||||
.data_io_default_level = false,
|
||||
.max_transfer_sz = 0,
|
||||
.flags = 0,
|
||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
.intr_flags = 0
|
||||
},
|
||||
.initMode = spi::InitMode::ByTactility,
|
||||
.isMutable = false,
|
||||
.lock = nullptr
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
7
Devices/m5stack-tab5/Source/Drivers.cpp
Normal file
7
Devices/m5stack-tab5/Source/Drivers.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
extern "C" {
|
||||
|
||||
extern void register_device_drivers() {
|
||||
/* NO-OP */
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,127 +1,24 @@
|
||||
#include "SdCard.h"
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
|
||||
#include <driver/sdmmc_defs.h>
|
||||
#include <driver/sdmmc_host.h>
|
||||
#include <esp_check.h>
|
||||
#include <esp_ldo_regulator.h>
|
||||
#include <esp_vfs_fat.h>
|
||||
#include <sdmmc_cmd.h>
|
||||
constexpr auto SDCARD_PIN_CS = GPIO_NUM_42;
|
||||
|
||||
using tt::hal::sdcard::SdCardDevice;
|
||||
|
||||
static const auto LOGGER = tt::Logger("Tab5SdCard");
|
||||
|
||||
// ESP32-P4 Slot 0 uses IO MUX (fixed pins, not manually configurable)
|
||||
// CLK=43, CMD=44, D0=39, D1=40, D2=41, D3=42 (defined automatically by hardware)
|
||||
|
||||
class SdCardDeviceImpl final : public SdCardDevice {
|
||||
|
||||
class NoLock final : public tt::Lock {
|
||||
bool lock(TickType_t timeout) const override { return true; }
|
||||
void unlock() const override { /* NO-OP */ }
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::Lock> lock = std::make_shared<NoLock>();
|
||||
sdmmc_card_t* card = nullptr;
|
||||
bool mounted = false;
|
||||
std::string mountPath;
|
||||
|
||||
public:
|
||||
SdCardDeviceImpl() : SdCardDevice(MountBehaviour::AtBoot) {}
|
||||
~SdCardDeviceImpl() override {
|
||||
if (mounted) {
|
||||
unmount();
|
||||
}
|
||||
}
|
||||
|
||||
std::string getName() const override { return "SD Card"; }
|
||||
std::string getDescription() const override { return "SD card via SDMMC host"; }
|
||||
|
||||
bool mount(const std::string& newMountPath) override {
|
||||
if (mounted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = false,
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 64 * 1024,
|
||||
.disk_status_check_enable = false,
|
||||
.use_one_fat = false,
|
||||
};
|
||||
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
host.slot = SDMMC_HOST_SLOT_0;
|
||||
host.max_freq_khz = SDMMC_FREQ_DEFAULT; // 20MHz - more stable for initialization
|
||||
host.flags = SDMMC_HOST_FLAG_4BIT; // Force 4-bit mode
|
||||
// Configure LDO power supply for SD card (critical on ESP32-P4)
|
||||
esp_ldo_channel_handle_t ldo_handle = nullptr;
|
||||
esp_ldo_channel_config_t ldo_config = {
|
||||
.chan_id = 4, // LDO channel 4 for SD power
|
||||
.voltage_mv = 3300, // 3.3V
|
||||
.flags {
|
||||
.adjustable = 0,
|
||||
.owned_by_hw = 0,
|
||||
.bypass = 0
|
||||
}
|
||||
};
|
||||
|
||||
esp_err_t ldo_ret = esp_ldo_acquire_channel(&ldo_config, &ldo_handle);
|
||||
if (ldo_ret != ESP_OK) {
|
||||
LOGGER.warn("Failed to acquire LDO for SD power: {} (continuing anyway)", esp_err_to_name(ldo_ret));
|
||||
}
|
||||
|
||||
// Slot 0 uses IO MUX - pins are fixed and not specified
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
slot_config.width = 4;
|
||||
slot_config.cd = SDMMC_SLOT_NO_CD; // No card detect
|
||||
slot_config.wp = SDMMC_SLOT_NO_WP; // No write protect
|
||||
slot_config.flags = 0;
|
||||
|
||||
esp_err_t ret = esp_vfs_fat_sdmmc_mount(newMountPath.c_str(), &host, &slot_config, &mount_config, &card);
|
||||
if (ret != ESP_OK) {
|
||||
LOGGER.error("Failed to mount SD card: {}", esp_err_to_name(ret));
|
||||
card = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
mountPath = newMountPath;
|
||||
mounted = true;
|
||||
LOGGER.info("SD card mounted at {}", mountPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unmount() override {
|
||||
if (!mounted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
esp_err_t ret = esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card);
|
||||
if (ret != ESP_OK) {
|
||||
LOGGER.error("Failed to unmount SD card: {}", esp_err_to_name(ret));
|
||||
return false;
|
||||
}
|
||||
card = nullptr;
|
||||
mounted = false;
|
||||
LOGGER.info("SD card unmounted");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string getMountPath() const override {
|
||||
return mountPath;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::Lock> getLock() const override { return lock; }
|
||||
|
||||
State getState(TickType_t /*timeout*/) const override {
|
||||
return mounted ? State::Mounted : State::Unmounted;
|
||||
}
|
||||
};
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
return std::make_shared<SdCardDeviceImpl>();
|
||||
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
|
||||
SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::hal::spi::getLock(SPI3_HOST),
|
||||
std::vector<gpio_num_t>(),
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
return std::make_shared<SpiSdCardDevice>(
|
||||
std::move(configuration)
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <memory>
|
||||
|
||||
// Create SD card device for jc1060p470ciwy using SDMMC slot 0 (4-bit)
|
||||
std::shared_ptr<tt::hal::sdcard::SdCardDevice> createSdCard();
|
||||
using tt::hal::sdcard::SdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard();
|
||||
|
||||
@ -22,7 +22,14 @@ colorDepth=16
|
||||
CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16
|
||||
CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30
|
||||
CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y
|
||||
CONFIG_ESP_HOSTED_ENABLED=y
|
||||
CONFIG_ESP_HOSTED_P4_DEV_BOARD_FUNC_BOARD=y
|
||||
CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE=y
|
||||
CONFIG_SLAVE_IDF_TARGET_ESP32C6=y
|
||||
CONFIG_ESP_HOSTED_ENABLED=y
|
||||
CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE=y
|
||||
CONFIG_ESP_HOSTED_SDIO_SLOT_1=y
|
||||
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1=13
|
||||
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1=12
|
||||
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1=11
|
||||
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_1=10
|
||||
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_1=9
|
||||
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_1=8
|
||||
CONFIG_ESP_HOSTED_SDIO_GPIO_RESET_SLAVE=15
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user