Tab5 features, StackChan, fixes, drivers.... (#526)

This commit is contained in:
Shadowtrance
2026-05-29 07:31:25 +10:00
committed by GitHub
parent 5c78d55b04
commit a59fbf4ed5
140 changed files with 2500 additions and 835 deletions
+1 -1
View File
@@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd ST7789 PwmBacklight ButtonControl m5pm1-module
REQUIRES Tactility esp_lvgl_port esp_lcd ST7789 PwmBacklight ButtonControl m5pm1-module vfs fatfs
)
@@ -1,14 +1,101 @@
#include "devices/Display.h"
#include "devices/SdCard.h"
#include "devices/Power.h"
#include <driver/gpio.h>
#include <tactility/device.h>
#include <tactility/drivers/i2c_controller.h>
#include <drivers/m5pm1.h>
#include <Tactility/hal/Configuration.h>
#include <ButtonControl.h>
#include <PwmBacklight.h>
using namespace tt::hal;
static constexpr auto* TAG = "StickS3";
static constexpr uint8_t ES8311_I2C_ADDR = 0x18;
static error_t initSound(::Device* i2c_controller) {
// Init data from M5Unified:
// https://github.com/m5stack/M5Unified/blob/master/src/M5Unified.cpp#L454
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0x00, 0x80, // 0x00 RESET/ CSM POWER ON
0x01, 0x3F, // 0x01 CLOCK_MANAGER/ use MCLK pin (external), all clocks on
0x02, 0x00, // 0x02 CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK from ESP32 is correct ratio)
0x0D, 0x01, // 0x0D SYSTEM/ Power up analog circuitry
0x12, 0x00, // 0x12 SYSTEM/ power-up DAC - NOT default
0x13, 0x10, // 0x13 SYSTEM/ Enable output to HP drive - NOT default
0x32, 0xBF, // 0x32 DAC/ DAC volume (0xBF == ±0 dB )
0x37, 0x08, // 0x37 DAC/ Bypass DAC equalizer - NOT default
};
error_t error = i2c_controller_write_register_array(
i2c_controller,
ES8311_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311: %s", error_to_string(error));
return error;
}
// Enable speaker amp via M5PM1 driver
auto* m5pm1 = device_find_by_name("m5pm1");
if (m5pm1 != nullptr) {
m5pm1_set_speaker_enable(m5pm1, true);
} else {
LOG_W(TAG, "m5pm1 not found — speaker amp not enabled");
}
return ERROR_NONE;
}
static error_t initMicrophone(::Device* i2c_controller) {
// Init data from M5Unified:
// https://github.com/m5stack/M5Unified/blob/master/src/M5Unified.cpp#L842
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0x00, 0x80, // 0x00 RESET/ CSM POWER ON
0x01, 0x3F, // 0x01 CLOCK_MANAGER/ use MCLK pin (external), all clocks on
0x02, 0x00, // 0x02 CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK from ESP32 is correct ratio)
0x0D, 0x01, // 0x0D SYSTEM/ Power up analog circuitry
0x0E, 0x02, // 0x0E SYSTEM/ : Enable analog PGA, enable ADC modulator
0x14, 0x10, // ES8311_ADC_REG14 : select Mic1p-Mic1n / PGA GAIN (minimum)
0x17, 0xFF, // ES8311_ADC_REG17 : ADC_VOLUME (MAXGAIN) // (0xBF == ± 0 dB )
0x1C, 0x6A, // ES8311_ADC_REG1C : ADC Equalizer bypass, cancel DC offset in digital domain
};
error_t error = i2c_controller_write_register_array(
i2c_controller,
ES8311_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311: %s", error_to_string(error));
return error;
}
return ERROR_NONE;
}
bool initBoot() {
auto* i2c_internal = device_find_by_name("i2c_internal");
check(i2c_internal, "i2c_internal not found");
error_t error = initSound(i2c_internal);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311 speaker");
}
error = initMicrophone(i2c_internal);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311 microphone");
}
return driver::pwmbacklight::init(GPIO_NUM_38, 512);
}
@@ -16,7 +103,8 @@ static DeviceVector createDevices() {
return {
createPower(),
ButtonControl::createTwoButtonControl(11, 12), // top button, side button
createDisplay()
createDisplay(),
createSdCard()
};
}
@@ -0,0 +1,30 @@
#include "SdCard.h"
#include <tactility/device.h>
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
constexpr auto SDCARD_SPI_HOST = SPI3_HOST;
constexpr auto SDCARD_PIN_CS = GPIO_NUM_7;
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCardDevice::MountBehaviour::AtBoot,
nullptr,
std::vector<gpio_num_t>(),
SDCARD_SPI_HOST
);
auto* spi_controller = device_find_by_name("spi1");
check(spi_controller, "spi1 not found");
return std::make_shared<SpiSdCardDevice>(
std::move(configuration),
spi_controller
);
}
@@ -0,0 +1,8 @@
#pragma once
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <memory>
using tt::hal::sdcard::SdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard();
+1 -1
View File
@@ -4,7 +4,6 @@ name=StickS3
[apps]
launcherAppId=Launcher
autoStartAppId=ApWebServer
[hardware]
target=ESP32S3
@@ -14,6 +13,7 @@ spiRamMode=OCT
spiRamSpeed=80M
esptoolFlashFreq=80M
tinyUsb=true
bluetooth=true
[display]
size=1.14"
@@ -1,5 +1,6 @@
/dts-v1/;
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_ble.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_i2s.h>
@@ -12,6 +13,10 @@
compatible = "root";
model = "M5Stack StickS3";
ble0 {
compatible = "espressif,esp32-ble";
};
gpio0 {
compatible = "espressif,esp32-gpio";
gpio-count = <49>;
@@ -50,6 +55,15 @@
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
};
//DIY SD Card - https://wiki.bruce.computer/wiring-diagrams/m5sticks3/sd-card/
spi1 {
compatible = "espressif,esp32-spi";
host = <SPI3_HOST>;
pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>;
};
// Speaker and microphone (ES8311)
i2s0 {
compatible = "espressif,esp32-i2s";