Skip to content
Draft
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
20 changes: 20 additions & 0 deletions variants/xiao_s3_wio/XiaoS3WIOBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ class XiaoS3WIOBoard : public ESP32Board {
const char* getManufacturerName() const override {
return "Xiao S3 WIO";
}
#ifdef PIN_VBAT_READ
// battery read support
pinMode(PIN_VBAT_READ, INPUT);
#endif

#define BATTERY_SAMPLES 8

uint16_t getBattMilliVolts() override {
#ifdef PIN_VBAT_READ
analogReadResolution(ADC_RESOLUTION);
uint32_t raw = 0;
for (int i = 0; i < 8; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / 8;
return (uint16_t)((float)raw * REAL_VBAT_MV_PER_LSB);
#else
return 0; // not supported
#endif
}
};
1 change: 1 addition & 0 deletions variants/xiao_s3_wio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ build_src_filter = ${Xiao_S3_WIO.build_src_filter}
+<../examples/simple_repeater/*.cpp>
build_flags =
${Xiao_S3_WIO.build_flags}
-D PIN_VBAT_READ=D1 ; optionnal voltage divider VBAT
-D ADVERT_NAME='"XiaoS3 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
Expand Down
26 changes: 26 additions & 0 deletions variants/xiao_s3_wio/variant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _VARIANT_Xiao_S3_WIO_
#define _VARIANT_Xiao_S3_WIO_

#include "WVariant.h"

// Number of pins defined in PinDescription array
#define PINS_COUNT (48)
#define NUM_DIGITAL_PINS (48)
#define NUM_ANALOG_INPUTS (1)
#define NUM_ANALOG_OUTPUTS (0)

// Setup for the voltage divider measurement :
// Label: D1, Analog, GPIO2
// 20k resistor wired from battery to D1
// and 20k resistor wired from D1 to ground
#define ADC_RESOLUTION 14

// built-ins
#define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096

#define VBAT_DIVIDER (0.5F) // 200K + 200K voltage divider on VBAT
#define VBAT_DIVIDER_COMP (2.0F) // Compensation factor for the VBAT divider

#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)

#endif