Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ESP32-DIV/.theia/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": []
}
4 changes: 2 additions & 2 deletions ESP32-DIV/BoardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ESP32-DIV/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
18 changes: 14 additions & 4 deletions ESP32-DIV/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -297,14 +297,16 @@ 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
#endif
#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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ESP32-DIV/subconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SUBCONFIG_H

#include <EEPROM.h>
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <ELECHOUSE_CC1101_ESP32DIV.h>
#include <PCF8574.h>
#include <RCSwitch.h>
#include <SPI.h>
Expand Down
51 changes: 30 additions & 21 deletions ESP32-DIV/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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++) {
Expand All @@ -836,6 +844,7 @@ bool initPcf8574Buttons() {
Serial.print(": ");
Serial.println(pcf.digitalRead(pin) ? "Released" : "Pressed");
}

return true;
}
#else
Expand Down