diff --git a/ESP32-DIV/.theia/launch.json b/ESP32-DIV/.theia/launch.json new file mode 100644 index 00000000..a2ea02c4 --- /dev/null +++ b/ESP32-DIV/.theia/launch.json @@ -0,0 +1,6 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + "version": "0.2.0", + "configurations": [] +} diff --git a/ESP32-DIV/BoardConfig.h b/ESP32-DIV/BoardConfig.h index 94d0741a..560fe4be 100644 --- a/ESP32-DIV/BoardConfig.h +++ b/ESP32-DIV/BoardConfig.h @@ -4,8 +4,8 @@ // Leave all lines commented to use the ESP32-DIV V2 wiring. // #define BOARD_CYD -// #define BOARD_ESP32_DIV_V1 - #define BOARD_ESP32_DIV_V2 + #define BOARD_ESP32_DIV_V1 +// #define BOARD_ESP32_DIV_V2 // Set to 0 to hide the on-screen touch nav bar (5 footer buttons). // Touch button input will still work when this is disabled. diff --git a/ESP32-DIV/config.h b/ESP32-DIV/config.h index 01f2744c..bba42e39 100644 --- a/ESP32-DIV/config.h +++ b/ESP32-DIV/config.h @@ -35,7 +35,7 @@ #include "esp_gap_bt_api.h" #include "arduinoFFT.h" -#include "ELECHOUSE_CC1101_SRC_DRV.h" +#include "ELECHOUSE_CC1101_ESP32DIV.h" #include "utils.h" #include "shared.h" diff --git a/ESP32-DIV/shared.h b/ESP32-DIV/shared.h index 1c239c6c..aa5cf5f4 100644 --- a/ESP32-DIV/shared.h +++ b/ESP32-DIV/shared.h @@ -73,7 +73,7 @@ uint16_t uiUniversalColor(); #define ESP32DIV_NAME "ESP32-DIV" #endif #ifndef ESP32DIV_VERSION -#define ESP32DIV_VERSION "v1.7.0" +#define ESP32DIV_VERSION "v1.7.k" #endif @@ -279,7 +279,7 @@ static const uint8_t OBF_WB[] = {75, 97, 110, 109, 122, 92, 109, 107, 96, 38, #if defined(BOARD_CYD) #define XPT2046_MOSI 32 #elif defined(BOARD_ESP32_DIV_V1) -#define XPT2046_MOSI 23 +#define XPT2046_MOSI 32 #else #define XPT2046_MOSI 35 #endif @@ -288,7 +288,7 @@ static const uint8_t OBF_WB[] = {75, 97, 110, 109, 122, 92, 109, 107, 96, 38, #if defined(BOARD_CYD) #define XPT2046_MISO 39 #elif defined(BOARD_ESP32_DIV_V1) -#define XPT2046_MISO 19 +#define XPT2046_MISO 35 #else #define XPT2046_MISO 37 #endif @@ -297,7 +297,7 @@ static const uint8_t OBF_WB[] = {75, 97, 110, 109, 122, 92, 109, 107, 96, 38, #if defined(BOARD_CYD) #define XPT2046_CLK 25 #elif defined(BOARD_ESP32_DIV_V1) -#define XPT2046_CLK 18 +#define XPT2046_CLK 25 #else #define XPT2046_CLK 36 #endif @@ -305,6 +305,8 @@ static const uint8_t OBF_WB[] = {75, 97, 110, 109, 122, 92, 109, 107, 96, 38, #ifndef XPT2046_IRQ #if defined(BOARD_CYD) #define XPT2046_IRQ 36 +#elif defined(BOARD_ESP32_DIV_V1) +#define XPT2046_IRQ 34 #else #define XPT2046_IRQ 255 #endif @@ -630,7 +632,15 @@ static const uint8_t OBF_WB[] = {75, 97, 110, 109, 122, 92, 109, 107, 96, 38, /*──────────────────── Battery ────────────────────*/ #ifndef BATTERY_ADC_PIN +#if defined(BOARD_ESP32_DIV_V1) +#define BATTERY_ADC_PIN 36 +#elif defined(BOARD_CYD) +// CYD has no onboard battery monitor #define BATTERY_ADC_PIN -1 +//#else +// Verify the correct ADC pin for V2 hardware +//#define BATTERY_ADC_PIN -1 +#endif #endif #ifndef BATTERY_VDIV_R1 #define BATTERY_VDIV_R1 200000.0f diff --git a/ESP32-DIV/subconfig.h b/ESP32-DIV/subconfig.h index 1967a30b..d430356a 100644 --- a/ESP32-DIV/subconfig.h +++ b/ESP32-DIV/subconfig.h @@ -2,7 +2,7 @@ #define SUBCONFIG_H #include -#include +#include #include #include #include diff --git a/ESP32-DIV/utils.cpp b/ESP32-DIV/utils.cpp index 0a99030d..b1dea342 100644 --- a/ESP32-DIV/utils.cpp +++ b/ESP32-DIV/utils.cpp @@ -472,22 +472,28 @@ void requestStatusBarRedraw() { const float R1 = 100000.0; const float R2 = 100000.0; -float readBatteryVoltage() { - const int sampleCount = 10; - long sum = 0; +float readBatteryVoltage() +{ + static bool adcInitialized = false; - for (int i = 0; i < sampleCount; i++) { - sum += analogRead(BATTERY_ADC_PIN); - delay(5); - } + if (!adcInitialized) + { + analogSetPinAttenuation(BATTERY_ADC_PIN, ADC_11db); + adcInitialized = true; + } - float averageADC = sum / (float)sampleCount; + const int sampleCount = 16; + uint32_t sum = 0; - float pinVoltage = (averageADC / 4095.0) * 2.2; + for (int i = 0; i < sampleCount; i++) + { + sum += analogReadMilliVolts(BATTERY_ADC_PIN); + delayMicroseconds(500); + } - float outputVoltage = pinVoltage * 2.0; + float avgMv = sum / (float)sampleCount; - return outputVoltage; + return (avgMv / 1000.0f) * 2.0f; } float readInternalTemperature() { @@ -810,24 +816,26 @@ bool initPcf8574Buttons() { pcf.pinMode(BTN_SELECT, INPUT_PULLUP); #if PCF8574_AUTO_DETECT - for (uint8_t addr = PCF8574_ADDR_MIN; addr <= PCF8574_ADDR_MAX; addr++) { - if (pcf.begin(addr)) { - s_pcf8574Addr = addr; - Serial.printf("[PCF8574] auto-detected at 0x%02X\n", addr); - break; - } - } - if (s_pcf8574Addr == 0) { - Serial.println("[PCF8574] not found (scanned 0x20-0x27)"); + + // Address is fixed in the PCF8574 constructor, so begin() takes no arguments. + if (!pcf.begin()) { + Serial.printf("[PCF8574] not found at 0x%02X\n", PCF8574_I2C_ADDR); return false; } + + s_pcf8574Addr = PCF8574_I2C_ADDR; + Serial.printf("[PCF8574] using PCF8574 at 0x%02X\n", s_pcf8574Addr); + #else - if (!pcf.begin(PCF8574_I2C_ADDR)) { + + if (!pcf.begin()) { Serial.printf("[PCF8574] not found at fixed address 0x%02X\n", PCF8574_I2C_ADDR); return false; } + s_pcf8574Addr = PCF8574_I2C_ADDR; Serial.printf("[PCF8574] using fixed address 0x%02X\n", s_pcf8574Addr); + #endif for (int pin = 0; pin < 8; pin++) { @@ -836,6 +844,7 @@ bool initPcf8574Buttons() { Serial.print(": "); Serial.println(pcf.digitalRead(pin) ? "Released" : "Pressed"); } + return true; } #else