diff --git a/variants/rak3112/RAK3112Board.h b/variants/rak3112/RAK3112Board.h index 8ba3197cf6c..8045ee06501 100644 --- a/variants/rak3112/RAK3112Board.h +++ b/variants/rak3112/RAK3112Board.h @@ -6,22 +6,17 @@ // built-ins #ifndef PIN_VBAT_READ - #define PIN_VBAT_READ 1 + #define PIN_VBAT_READ 1 // WB_A0, VBAT via the WisBlock base board divider #endif -#ifndef PIN_ADC_CTRL - #define PIN_ADC_CTRL 36 -#endif -#define PIN_ADC_CTRL_ACTIVE LOW -#define PIN_ADC_CTRL_INACTIVE HIGH -#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000) +// WisBlock base boards (RAK19007 etc.) divide VBAT with 1M / 1.5M (nominal x1.667); 1.73 compensates +// for ADC loading of the high-impedance divider (same empirical value as Meshtastic's RAK4631) +#define ADC_MULTIPLIER 1.73f #define BATTERY_SAMPLES 8 +// NOTE: no ADC enable pin on the RAK3112. GPIO33-37 belong to the octal PSRAM and must not be touched. #include class RAK3112Board : public ESP32Board { -private: - bool adc_active_state; - public: RefCountedDigitalPin periph_power; @@ -30,13 +25,6 @@ class RAK3112Board : public ESP32Board { void begin() { ESP32Board::begin(); - // Auto-detect correct ADC_CTRL pin polarity (different for boards >3.2) - pinMode(PIN_ADC_CTRL, INPUT); - adc_active_state = !digitalRead(PIN_ADC_CTRL); - - pinMode(PIN_ADC_CTRL, OUTPUT); - digitalWrite(PIN_ADC_CTRL, !adc_active_state); // Initially inactive - periph_power.begin(); esp_reset_reason_t reason = esp_reset_reason(); @@ -81,13 +69,14 @@ class RAK3112Board : public ESP32Board { uint16_t getBattMilliVolts() override { analogReadResolution(12); - uint32_t raw = 0; + // analogReadMilliVolts() applies the eFuse ADC calibration + uint32_t mv = 0; for (int i = 0; i < BATTERY_SAMPLES; i++) { - raw += analogRead(PIN_VBAT_READ); + mv += analogReadMilliVolts(PIN_VBAT_READ); } - raw = raw / BATTERY_SAMPLES; + mv = mv / BATTERY_SAMPLES; - return (ADC_MULTIPLIER * raw) / 4096; + return (uint16_t)(ADC_MULTIPLIER * mv); } const char* getManufacturerName() const override { diff --git a/variants/rak3112/platformio.ini b/variants/rak3112/platformio.ini index a7d27a65b77..15ea863716b 100644 --- a/variants/rak3112/platformio.ini +++ b/variants/rak3112/platformio.ini @@ -1,6 +1,8 @@ [rak3112] extends = esp32_base board = esp32-s3-devkitc-1 +; RAK3112 (ESP32-S3R8) has 8MB octal PSRAM; the devkitc-1 default (qio_qspi) fails to detect it +board_build.arduino.memory_type = qio_opi build_flags = ${esp32_base.build_flags} ${sensor_base.build_flags} @@ -35,6 +37,9 @@ build_flags = build_src_filter = ${esp32_base.build_src_filter} +<../variants/rak3112> + +; MQTT helpers need the MQTT-only libs (Timezone, ArduinoJson); the *_observer_mqtt envs add them back + - + - lib_deps = ${esp32_base.lib_deps} ${sensor_base.lib_deps} @@ -273,12 +278,10 @@ lib_deps = extends = rak3112 build_flags = ${rak3112.build_flags} - -D ADVERT_NAME='"RAK3112 v3 Sensor"' + -D ADVERT_NAME='"RAK3112 Sensor"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 -D ADMIN_PASSWORD='"password"' - -D ENV_PIN_SDA=33 - -D ENV_PIN_SCL=34 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${rak3112.build_src_filter}