Files
tactility/Devices/es3c28p/Source/Configuration.cpp
Adolfo Reyna 2dc216fb7b fix: MCP settings persistence + WebServer/DevServer coexistence + screensaver charging toggle
- McpSettings was hardcoded to /data/service/mcp/settings.properties,
  but ES3C28P uses storage.userDataLocation=SD so user data lives on
  /sdcard/tactility/. Settings appeared to save but on reload returned
  default false -> "enable and when I go back shows disabled".
  Fixed to use getUserDataPath()+"/settings/mcp.properties" pattern
  consistent with DisplaySettings/WebServerSettings, with
  findOrCreateParentDirectory() and isFile() guard.

- HttpServer ctrl_port collision: ESP-IDF default 32768 used by both
  WebServer (80) and DevelopmentService (6666). Second httpd_start()
  failed silently -> dashboard up but /api/mcp 404 and :6666 refused.
  Fixed with unique ctrl_port = 32768 + (port % 1000).
  Added CONFIG_HTTPD_MAX_URI_HANDLERS=20 (default 8 < 9 needed for
  7 handlers + 2 internal).

- DevService stack 5120 -> 8192 for /app/install handling.
- McpSystem video stream task stack 4096 -> 8192 and idle yield 50ms
  (was 5ms always) to avoid CPU starvation blocking httpd tasks.
  On RLCD, timer must always run: DisplayIdle early return on
  !supportsBacklightDuty() broke MCP manual activation (cachedSettings
  not loaded, backlight duty 0). Fixed to always load settings +
  start timer, log RLCD detection, guard setBacklightDuty with
  supportsBacklightDuty() and fallback duty 255.

- DisplaySettings: add disableScreensaverWhenCharging bool, persisted,
  with UI toggle in Display app (Settings->Display) using
  PowerDevice::IsCharging check via findDevices callback.
  When charging and flag enabled, screensaver activation skipped,
  and if already dimmed, wake on charging.

- ES3C28P Power driver: GPIO9 ADC1_CH8 2x divider 2500-4200mV spec from
  ~/Downloads official docs, TP4054 CHRG not connected to GPIO, so
  IsCharging inferred via voltage thresholds (<500mV no battery USB
  or >5000mV wall powered, >=4150mV high) + rising trend.

Verified: flashed es3c28p to /dev/cu.usbmodem101 (192.168.68.113),
WiFi FamReynaMesh RSSI -59, dashboard 200, :6666/info now works,
/api/mcp returns disabled correctly until enabled, persists to SD.
2026-07-11 20:26:01 -04:00

95 lines
3.2 KiB
C++

#include "PwmBacklight.h"
#include "devices/Display.h"
#include "devices/Power.h"
#include <driver/gpio.h>
#include <tactility/device.h>
#include <tactility/drivers/i2c_controller.h>
#include <tactility/log.h>
#include <tactility/error.h>
#include <tactility/freertos/freertos.h>
#include <Tactility/hal/Configuration.h>
using namespace tt::hal;
static constexpr auto* TAG = "ES3C28P";
static constexpr uint8_t ES8311_I2C_ADDR = 0x18;
static error_t initCodec(::Device* i2c_controller) {
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0x00, 0x80, // RESET/CSM POWER ON
0x01, 0x3F, // CLOCK_MANAGER/ use MCLK pin (external), all clocks on
0x02, 0x00, // CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK is correct ratio)
0x03, 0x10, // CLOCK_MANAGER/ fs_mode=0, adc_osr=16
0x04, 0x10, // CLOCK_MANAGER/ dac_osr=16
0x05, 0x00, // CLOCK_MANAGER/ adc_div=1, dac_div=1
0x06, 0x03, // CLOCK_MANAGER/ bclk_div=4
0x07, 0x00, // CLOCK_MANAGER/ lrck_h=0
0x08, 0xFF, // CLOCK_MANAGER/ lrck_l=255 (div=256)
0x09, 0x0C, // SDPIN_REG09/ DAC SDP format = standard I2S, word length = 16-bit
0x0A, 0x0C, // SDPOUT_REG0A/ ADC SDP format = standard I2S, word length = 16-bit
0x0D, 0x01, // SYSTEM/ Power up analog circuitry
0x0E, 0x02, // SYSTEM/ Enable analog PGA, enable ADC modulator
0x12, 0x00, // SYSTEM/ power-up DAC
0x13, 0x10, // SYSTEM/ Enable output to HP drive (headphone/speaker)
0x14, 0x1A, // SYSTEM/ Select Mic1p-Mic1n / max PGA gain (+30dB)
0x17, 0xFF, // ADC_REG17/ ADC Volume (MAXGAIN)
0x1C, 0x6A, // ADC_REG1C/ ADC Equalizer bypass, cancel DC offset in digital
0x32, 0xBF, // DAC_REG32/ DAC Volume (0xBF = 191)
0x37, 0x08, // DAC_REG37/ Bypass DAC equalizer
};
return i2c_controller_write_register_array(
i2c_controller,
ES8311_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
}
static bool initBoot() {
// 1. Initialize display backlight
if (!driver::pwmbacklight::init(LCD_PIN_BACKLIGHT)) {
return false;
}
// 2. Initialize and power on the FM8002E Audio Amplifier (GPIO 1, Active LOW)
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL << GPIO_NUM_1);
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_config(&io_conf);
// Drive LOW to enable the speaker amplifier
gpio_set_level(GPIO_NUM_1, 0);
// 3. Configure the ES8311 Codec over the I2C bus
auto* i2c_bus = device_find_by_name("i2c0");
if (i2c_bus != nullptr) {
error_t error = initCodec(i2c_bus);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to initialize ES8311 codec: %s", error_to_string(error));
}
} else {
LOG_E(TAG, "i2c0 bus not found, skipping ES8311 initialization");
}
return true;
}
static DeviceVector createDevices() {
return {
createDisplay(),
createPower()
};
}
extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.createDevices = createDevices
};