Skip to content
Open
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
31 changes: 10 additions & 21 deletions variants/rak3112/RAK3112Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <driver/rtc_io.h>

class RAK3112Board : public ESP32Board {
private:
bool adc_active_state;

public:
RefCountedDigitalPin periph_power;

Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions variants/rak3112/platformio.ini
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -35,6 +37,9 @@ build_flags =
build_src_filter = ${esp32_base.build_src_filter}
+<../variants/rak3112>
+<helpers/sensors>
; MQTT helpers need the MQTT-only libs (Timezone, ArduinoJson); the *_observer_mqtt envs add them back
-<helpers/MQTTMessageBuilder.cpp>
-<helpers/JWTHelper.cpp>
lib_deps =
${esp32_base.lib_deps}
${sensor_base.lib_deps}
Expand Down Expand Up @@ -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}
Expand Down