|
@@ -1,54 +1,5 @@
|
|
|
// Modulos ADAU DSP WiFi + EEPROM (HTTP uploader + Sigma TCP bridge)
|
|
// Modulos ADAU DSP WiFi + EEPROM (HTTP uploader + Sigma TCP bridge)
|
|
|
// Build: 260304_13 (YYMMDD_rev)
|
|
// Build: 260304_13 (YYMMDD_rev)
|
|
|
-//
|
|
|
|
|
-// This is a clean restore to the last known good state (v1.3.0/_04)
|
|
|
|
|
-// with the chipAddr 0x01 fix applied. The receive loop is the original
|
|
|
|
|
-// simple byte-at-a-time approach which correctly handled large packets.
|
|
|
|
|
-//
|
|
|
|
|
-// Changes vs original:
|
|
|
|
|
-// - sendReadResponse() corrected to 6-byte SigmaTCP header format
|
|
|
|
|
-// - sendWriteAck() added after every DSP/EEPROM write
|
|
|
|
|
-// - chipAddrTo7bit() handles 0x01=DSP, 0x02=EEPROM chip indexes
|
|
|
|
|
-// - I2C read failure returns zeros instead of dropping connection
|
|
|
|
|
-// - registerSize derived from ADAU1401 address map
|
|
|
|
|
-// - DSPWriter::resetSafeload() at start of each TCP session
|
|
|
|
|
-// - WS2812 NeoPixel on GPIO 21 (Waveshare ESP32-S3 Zero)
|
|
|
|
|
-//
|
|
|
|
|
-// Changelog v1.3.0:
|
|
|
|
|
-// - FIX: sendReadResponse() header corrected to 6-byte SigmaTCP format
|
|
|
|
|
-// (was 4 bytes; SigmaStudio expects: 0x0B, totalLen_hi, totalLen_lo, status, dataLen_hi, dataLen_lo)
|
|
|
|
|
-// - ADD: sendWriteAck() — SigmaStudio expects a 4-byte ACK after every write
|
|
|
|
|
-// (was missing; caused immediate disconnect after first write)
|
|
|
|
|
-// - FIX: I2C read failure now returns zeros instead of dropping TCP connection
|
|
|
|
|
-// (SigmaStudio can probe/read a DSP that isn't responding yet without aborting)
|
|
|
|
|
-// - ADD: Hex dump of first bytes of each received command to Serial for diagnostics
|
|
|
|
|
-// - ADD: printHex() debug helper
|
|
|
|
|
-//
|
|
|
|
|
-// Changelog v1.4.0:
|
|
|
|
|
-// - FIX: TCP receive loop replaced with client.readBytes() + 3s per-packet timeout
|
|
|
|
|
-// Previous byte-at-a-time loop timed out mid-transfer on large program blocks
|
|
|
|
|
-// (e.g. 1490-byte program download) because client.available() returns 0
|
|
|
|
|
-// between TCP segments even when more data is in flight. Now we block-read
|
|
|
|
|
-// exactly the bytes needed to complete the current packet, so a large program
|
|
|
|
|
-// download can span multiple TCP segments without triggering a false idle timeout.
|
|
|
|
|
-// - FIX: Idle timeout now only applies between commands, not during active receive
|
|
|
|
|
-//
|
|
|
|
|
-// Changelog v1.2.0:
|
|
|
|
|
-// - ADD: WS2812 NeoPixel status LED (Waveshare ESP32-S3 Zero, GPIO 21)
|
|
|
|
|
-// OFF = idle / no TCP client
|
|
|
|
|
-// GREEN = DSP write in progress
|
|
|
|
|
-// BLUE = DSP read in progress
|
|
|
|
|
-// YELLOW = EEPROM write via TCP
|
|
|
|
|
-// MAGENTA = HTTP EEPROM upload in progress
|
|
|
|
|
-// RED flash = error (I2C fail, overflow, bad packet)
|
|
|
|
|
-//
|
|
|
|
|
-// Changelog v1.1.0:
|
|
|
|
|
-// - FIX: Buffer overflow check moved to BEFORE write
|
|
|
|
|
-// - FIX: chipAddrTo7bit() replaced with explicit lookup table
|
|
|
|
|
-// - FIX: registerSize now derived from ADAU1401 address range
|
|
|
|
|
-// - FIX: DSPWriter::resetSafeload() called at TCP session start
|
|
|
|
|
-// - FIX: Safeload dataLen validated as multiple of 4
|
|
|
|
|
-// - FIX: totalLen vs dataLen cross-validated on WRITE packets
|
|
|
|
|
|
|
|
|
|
#include <WiFi.h>
|
|
#include <WiFi.h>
|
|
|
#include <Wire.h>
|
|
#include <Wire.h>
|
|
@@ -101,7 +52,6 @@ static bool s_lcdOk = false;
|
|
|
#define NEOPIXEL_BRIGHT 40
|
|
#define NEOPIXEL_BRIGHT 40
|
|
|
|
|
|
|
|
Adafruit_NeoPixel statusLed(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
|
|
Adafruit_NeoPixel statusLed(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
|
|
|
-
|
|
|
|
|
static void ledSet(uint8_t r, uint8_t g, uint8_t b)
|
|
static void ledSet(uint8_t r, uint8_t g, uint8_t b)
|
|
|
{
|
|
{
|
|
|
statusLed.setPixelColor(0, statusLed.Color(r, g, b));
|
|
statusLed.setPixelColor(0, statusLed.Color(r, g, b));
|
|
@@ -250,31 +200,16 @@ static bool eepromWriteBlock(uint16_t memAddr, const uint8_t* data, uint16_t len
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static bool eepromReadBlock(uint16_t memAddr, uint8_t* out, uint16_t len)
|
|
|
|
|
|
|
+static bool i2cReadBlock(uint8_t addr7, uint16_t memAddr, uint8_t* out, uint16_t len)
|
|
|
{
|
|
{
|
|
|
- Wire.beginTransmission(EEPROM_7BIT);
|
|
|
|
|
|
|
+ Wire.beginTransmission(addr7);
|
|
|
Wire.write((uint8_t)(memAddr >> 8));
|
|
Wire.write((uint8_t)(memAddr >> 8));
|
|
|
Wire.write((uint8_t)(memAddr & 0xFF));
|
|
Wire.write((uint8_t)(memAddr & 0xFF));
|
|
|
if (Wire.endTransmission(false) != 0) return false;
|
|
if (Wire.endTransmission(false) != 0) return false;
|
|
|
uint16_t got = 0;
|
|
uint16_t got = 0;
|
|
|
while (got < len) {
|
|
while (got < len) {
|
|
|
uint8_t ask = (len - got) > 32 ? 32 : (len - got);
|
|
uint8_t ask = (len - got) > 32 ? 32 : (len - got);
|
|
|
- if (Wire.requestFrom((int)EEPROM_7BIT, (int)ask) != ask) return false;
|
|
|
|
|
- for (uint8_t i = 0; i < ask; i++) out[got++] = Wire.read();
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static bool dspReadBlock(uint16_t memAddr, uint8_t* out, uint16_t len)
|
|
|
|
|
-{
|
|
|
|
|
- Wire.beginTransmission(DSP_7BIT);
|
|
|
|
|
- Wire.write((uint8_t)(memAddr >> 8));
|
|
|
|
|
- Wire.write((uint8_t)(memAddr & 0xFF));
|
|
|
|
|
- if (Wire.endTransmission(false) != 0) return false;
|
|
|
|
|
- uint16_t got = 0;
|
|
|
|
|
- while (got < len) {
|
|
|
|
|
- uint8_t ask = (len - got) > 32 ? 32 : (len - got);
|
|
|
|
|
- if (Wire.requestFrom((int)DSP_7BIT, (int)ask) != ask) return false;
|
|
|
|
|
|
|
+ if (Wire.requestFrom((int)addr7, (int)ask) != ask) return false;
|
|
|
for (uint8_t i = 0; i < ask; i++) out[got++] = Wire.read();
|
|
for (uint8_t i = 0; i < ask; i++) out[got++] = Wire.read();
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
@@ -333,7 +268,6 @@ static void printHex(const char* label, const uint8_t* buf, uint16_t len, uint16
|
|
|
// NVS credential helpers
|
|
// NVS credential helpers
|
|
|
//=============================================================
|
|
//=============================================================
|
|
|
static Preferences s_prefs;
|
|
static Preferences s_prefs;
|
|
|
-
|
|
|
|
|
static bool loadWifiCreds()
|
|
static bool loadWifiCreds()
|
|
|
{
|
|
{
|
|
|
s_prefs.begin("wifi", true);
|
|
s_prefs.begin("wifi", true);
|
|
@@ -526,7 +460,7 @@ static void handleUploadStream() {
|
|
|
uint32_t remaining = uploadBytes; uint16_t addr = 0;
|
|
uint32_t remaining = uploadBytes; uint16_t addr = 0;
|
|
|
while (remaining) {
|
|
while (remaining) {
|
|
|
uint16_t n = remaining > sizeof(tmp) ? sizeof(tmp) : (uint16_t)remaining;
|
|
uint16_t n = remaining > sizeof(tmp) ? sizeof(tmp) : (uint16_t)remaining;
|
|
|
- if (!eepromReadBlock(addr, tmp, n)) { Serial.println("EEPROM read failed"); uploadFailed = true; break; }
|
|
|
|
|
|
|
+ if (!i2cReadBlock(EEPROM_7BIT, addr, tmp, n)) { Serial.println("EEPROM read failed"); uploadFailed = true; break; }
|
|
|
crc = crc32_update(crc, tmp, n);
|
|
crc = crc32_update(crc, tmp, n);
|
|
|
addr += n; remaining -= n; delay(0);
|
|
addr += n; remaining -= n; delay(0);
|
|
|
}
|
|
}
|
|
@@ -563,16 +497,16 @@ static void handleDspReset() {
|
|
|
static void handleDspStatus() {
|
|
static void handleDspStatus() {
|
|
|
// Core Register (0x081C) — 2 bytes, bit 0 = Run
|
|
// Core Register (0x081C) — 2 bytes, bit 0 = Run
|
|
|
uint8_t coreRaw[2] = {0, 0};
|
|
uint8_t coreRaw[2] = {0, 0};
|
|
|
- bool coreOk = dspReadBlock(dspRegister::CoreRegister, coreRaw, 2);
|
|
|
|
|
|
|
+ bool coreOk = i2cReadBlock(DSP_7BIT, dspRegister::CoreRegister, coreRaw, 2);
|
|
|
uint16_t coreVal = ((uint16_t)coreRaw[0] << 8) | coreRaw[1];
|
|
uint16_t coreVal = ((uint16_t)coreRaw[0] << 8) | coreRaw[1];
|
|
|
|
|
|
|
|
// GPIO All Register (0x0808) — 1 byte
|
|
// GPIO All Register (0x0808) — 1 byte
|
|
|
uint8_t gpio = 0;
|
|
uint8_t gpio = 0;
|
|
|
- bool gpioOk = dspReadBlock(dspRegister::GpioAllRegister, &gpio, 1);
|
|
|
|
|
|
|
+ bool gpioOk = i2cReadBlock(DSP_7BIT, dspRegister::GpioAllRegister, &gpio, 1);
|
|
|
|
|
|
|
|
// ADC0–3 (0x0809–0x080C) — 1 byte each, read as a 4-byte burst
|
|
// ADC0–3 (0x0809–0x080C) — 1 byte each, read as a 4-byte burst
|
|
|
uint8_t adc[4] = {0, 0, 0, 0};
|
|
uint8_t adc[4] = {0, 0, 0, 0};
|
|
|
- bool adcOk = dspReadBlock(dspRegister::Adc0, adc, 4);
|
|
|
|
|
|
|
+ bool adcOk = i2cReadBlock(DSP_7BIT, dspRegister::Adc0, adc, 4);
|
|
|
|
|
|
|
|
bool allOk = coreOk && gpioOk && adcOk;
|
|
bool allOk = coreOk && gpioOk && adcOk;
|
|
|
|
|
|
|
@@ -611,7 +545,7 @@ static void handleParamGet() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
uint8_t raw[4] = {0, 0, 0, 0};
|
|
uint8_t raw[4] = {0, 0, 0, 0};
|
|
|
- bool ok = dspReadBlock((uint16_t)addr, raw, 4);
|
|
|
|
|
|
|
+ bool ok = i2cReadBlock(DSP_7BIT, (uint16_t)addr, raw, 4);
|
|
|
|
|
|
|
|
// 5.23 fixed-point → float
|
|
// 5.23 fixed-point → float
|
|
|
int32_t fixed = ((int32_t)raw[0] << 24) | ((int32_t)raw[1] << 16) |
|
|
int32_t fixed = ((int32_t)raw[0] << 24) | ((int32_t)raw[1] << 16) |
|
|
@@ -685,9 +619,9 @@ static void handleWifiReset() {
|
|
|
//=============================================================
|
|
//=============================================================
|
|
|
static void handleGpioGet() {
|
|
static void handleGpioGet() {
|
|
|
uint8_t gpio = 0;
|
|
uint8_t gpio = 0;
|
|
|
- bool gpioOk = dspReadBlock(dspRegister::GpioAllRegister, &gpio, 1);
|
|
|
|
|
|
|
+ bool gpioOk = i2cReadBlock(DSP_7BIT, dspRegister::GpioAllRegister, &gpio, 1);
|
|
|
uint8_t mpcfg[2] = {0, 0};
|
|
uint8_t mpcfg[2] = {0, 0};
|
|
|
- bool cfgOk = dspReadBlock(dspRegister::MpCfg0, mpcfg, 2);
|
|
|
|
|
|
|
+ bool cfgOk = i2cReadBlock(DSP_7BIT, dspRegister::MpCfg0, mpcfg, 2);
|
|
|
bool ok = gpioOk && cfgOk;
|
|
bool ok = gpioOk && cfgOk;
|
|
|
char buf[100];
|
|
char buf[100];
|
|
|
snprintf(buf, sizeof(buf),
|
|
snprintf(buf, sizeof(buf),
|
|
@@ -1034,8 +968,8 @@ static void handleTcpBridgeClient(WiFiClient& client)
|
|
|
bool ok = false;
|
|
bool ok = false;
|
|
|
ledBlue();
|
|
ledBlue();
|
|
|
|
|
|
|
|
- if (target7 == EEPROM_7BIT) ok = eepromReadBlock(readHeader.address, readOut, readHeader.dataLen);
|
|
|
|
|
- else if (target7 == DSP_7BIT) ok = dspReadBlock (readHeader.address, readOut, readHeader.dataLen);
|
|
|
|
|
|
|
+ if (target7 == EEPROM_7BIT) ok = i2cReadBlock(EEPROM_7BIT, readHeader.address, readOut, readHeader.dataLen);
|
|
|
|
|
+ else if (target7 == DSP_7BIT) ok = i2cReadBlock(DSP_7BIT, readHeader.address, readOut, readHeader.dataLen);
|
|
|
else {
|
|
else {
|
|
|
Serial.printf("TCP unknown chipAddr (READ): 0x%02X\n", readHeader.chipAddr);
|
|
Serial.printf("TCP unknown chipAddr (READ): 0x%02X\n", readHeader.chipAddr);
|
|
|
}
|
|
}
|