mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Read battery voltage on Minewsemi ME25LS01
This commit is contained in:
parent
70a9990f45
commit
aa3c702ffd
5 changed files with 22 additions and 73 deletions
|
|
@ -9,10 +9,11 @@ void MinewsemiME25LS01Board::begin() {
|
||||||
startup_reason = BD_STARTUP_NORMAL;
|
startup_reason = BD_STARTUP_NORMAL;
|
||||||
btn_prev_state = HIGH;
|
btn_prev_state = HIGH;
|
||||||
|
|
||||||
|
pinMode(PIN_VBAT_READ, INPUT);
|
||||||
|
|
||||||
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
|
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
|
||||||
|
|
||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
// pinMode(BATTERY_PIN, INPUT);
|
|
||||||
pinMode(BUTTON_PIN, INPUT);
|
pinMode(BUTTON_PIN, INPUT);
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -31,7 +32,6 @@ void MinewsemiME25LS01Board::begin() {
|
||||||
delay(10); // give sx1262 some time to power up
|
delay(10); // give sx1262 some time to power up
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static BLEDfu bledfu;
|
static BLEDfu bledfu;
|
||||||
|
|
||||||
static void connect_callback(uint16_t conn_handle) {
|
static void connect_callback(uint16_t conn_handle) {
|
||||||
|
|
@ -47,7 +47,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
|
bool MinewsemiME25LS01Board::startOTAUpdate(const char* id, char reply[]) {
|
||||||
// Config the peripheral connection with maximum bandwidth
|
// Config the peripheral connection with maximum bandwidth
|
||||||
// more SRAM required by SoftDevice
|
// more SRAM required by SoftDevice
|
||||||
// Note: All config***() function must be called before begin()
|
// Note: All config***() function must be called before begin()
|
||||||
|
|
@ -58,7 +58,7 @@ bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
|
||||||
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
||||||
Bluefruit.setTxPower(4);
|
Bluefruit.setTxPower(4);
|
||||||
// Set the BLE device name
|
// Set the BLE device name
|
||||||
Bluefruit.setName("T1000E_OTA");
|
Bluefruit.setName("Minewsemi_OTA");
|
||||||
|
|
||||||
Bluefruit.Periph.setConnectCallback(connect_callback);
|
Bluefruit.Periph.setConnectCallback(connect_callback);
|
||||||
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
|
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
|
||||||
|
|
@ -89,4 +89,3 @@ bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
|
||||||
strcpy(reply, "OK - started");
|
strcpy(reply, "OK - started");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
#define LR11X0_DIO_AS_RF_SWITCH true
|
#define LR11X0_DIO_AS_RF_SWITCH true
|
||||||
#define LR11X0_DIO3_TCXO_VOLTAGE 1.6
|
#define LR11X0_DIO3_TCXO_VOLTAGE 1.6
|
||||||
|
|
||||||
// built-ins
|
#define PIN_VBAT_READ BATTERY_PIN
|
||||||
//#define PIN_VBAT_READ 5
|
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
|
||||||
//#define ADC_MULTIPLIER (3 * 1.73 * 1000)
|
|
||||||
|
|
||||||
class MinewsemiME25LS01Board : public mesh::MainBoard {
|
class MinewsemiME25LS01Board : public mesh::MainBoard {
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -28,43 +28,23 @@ protected:
|
||||||
public:
|
public:
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
|
#define BATTERY_SAMPLES 8
|
||||||
|
|
||||||
uint16_t getBattMilliVolts() override {
|
uint16_t getBattMilliVolts() override {
|
||||||
#ifdef BATTERY_PIN
|
|
||||||
#ifdef PIN_3V3_EN
|
|
||||||
digitalWrite(PIN_3V3_EN, HIGH);
|
|
||||||
#endif
|
|
||||||
analogReference(AR_INTERNAL_3_0);
|
|
||||||
analogReadResolution(12);
|
analogReadResolution(12);
|
||||||
delay(10);
|
|
||||||
float volts = (analogRead(BATTERY_PIN) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096;
|
|
||||||
#ifdef PIN_3V3_EN
|
|
||||||
digitalWrite(PIN_3V3_EN, LOW);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
analogReference(AR_DEFAULT); // put back to default
|
uint32_t raw = 0;
|
||||||
analogReadResolution(10);
|
for (int i = 0; i < BATTERY_SAMPLES; i++) {
|
||||||
|
raw += analogRead(PIN_VBAT_READ);
|
||||||
return volts * 1000;
|
}
|
||||||
#else
|
raw = raw / BATTERY_SAMPLES;
|
||||||
return 0;
|
return (ADC_MULTIPLIER * raw);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getStartupReason() const override { return startup_reason; }
|
uint8_t getStartupReason() const override { return startup_reason; }
|
||||||
|
|
||||||
const char* getManufacturerName() const override {
|
const char* getManufacturerName() const override {
|
||||||
return "m25ls01";
|
return "Minewsemi";
|
||||||
}
|
|
||||||
|
|
||||||
int buttonStateChanged() {
|
|
||||||
#ifdef BUTTON_PIN
|
|
||||||
uint8_t v = digitalRead(BUTTON_PIN);
|
|
||||||
if (v != btn_prev_state) {
|
|
||||||
btn_prev_state = v;
|
|
||||||
return (v == LOW) ? 1 : -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void powerOff() override {
|
void powerOff() override {
|
||||||
|
|
@ -81,10 +61,6 @@ public:
|
||||||
digitalWrite(BUZZER_EN, LOW);
|
digitalWrite(BUZZER_EN, LOW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PIN_3V3_EN
|
|
||||||
digitalWrite(PIN_3V3_EN, LOW);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LED_PIN
|
#ifdef LED_PIN
|
||||||
digitalWrite(LED_PIN, LOW);
|
digitalWrite(LED_PIN, LOW);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -108,5 +84,5 @@ public:
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool startOTAUpdate(const char* id, char reply[]) override;
|
bool startOTAUpdate(const char* id, char reply[]) override;
|
||||||
};
|
};
|
||||||
|
|
@ -8,7 +8,6 @@ build_flags = ${nrf52_base.build_flags}
|
||||||
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
|
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
BluetoothOTA
|
BluetoothOTA
|
||||||
lvgl
|
|
||||||
lib5b4
|
lib5b4
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${nrf52_base.lib_deps}
|
${nrf52_base.lib_deps}
|
||||||
|
|
@ -67,7 +66,6 @@ build_flags = ${me25ls01.build_flags}
|
||||||
;-D PIN_BUZZER_EN=37
|
;-D PIN_BUZZER_EN=37
|
||||||
build_src_filter = ${me25ls01.build_src_filter}
|
build_src_filter = ${me25ls01.build_src_filter}
|
||||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||||
;+<helpers/ui/buzzer.cpp>
|
|
||||||
+<../examples/companion_radio/*.cpp>
|
+<../examples/companion_radio/*.cpp>
|
||||||
lib_deps = ${me25ls01.lib_deps}
|
lib_deps = ${me25ls01.lib_deps}
|
||||||
adafruit/RTClib @ ^2.1.3
|
adafruit/RTClib @ ^2.1.3
|
||||||
|
|
@ -92,9 +90,6 @@ build_flags = ${me25ls01.build_flags}
|
||||||
-D MAX_NEIGHBOURS=8
|
-D MAX_NEIGHBOURS=8
|
||||||
-D DISPLAY_CLASS=NullDisplayDriver
|
-D DISPLAY_CLASS=NullDisplayDriver
|
||||||
build_src_filter = ${me25ls01.build_src_filter}
|
build_src_filter = ${me25ls01.build_src_filter}
|
||||||
;+<helpers/nrf52/SerialBLEInterface.cpp>
|
|
||||||
;+<helpers/ui/buzzer.cpp>
|
|
||||||
;+<../examples/companion_radio/*.cpp>
|
|
||||||
+<../examples/simple_repeater>
|
+<../examples/simple_repeater>
|
||||||
lib_deps = ${me25ls01.lib_deps}
|
lib_deps = ${me25ls01.lib_deps}
|
||||||
adafruit/RTClib @ ^2.1.3
|
adafruit/RTClib @ ^2.1.3
|
||||||
|
|
@ -121,10 +116,6 @@ build_flags = ${me25ls01.build_flags}
|
||||||
-D MAX_NEIGHBOURS=8
|
-D MAX_NEIGHBOURS=8
|
||||||
-D DISPLAY_CLASS=NullDisplayDriver
|
-D DISPLAY_CLASS=NullDisplayDriver
|
||||||
build_src_filter = ${me25ls01.build_src_filter}
|
build_src_filter = ${me25ls01.build_src_filter}
|
||||||
;+<helpers/nrf52/SerialBLEInterface.cpp>
|
|
||||||
;+<helpers/ui/buzzer.cpp>
|
|
||||||
;+<../examples/companion_radio/*.cpp>
|
|
||||||
;+<../examples/simple_repeater>
|
|
||||||
+<../examples/simple_room_server>
|
+<../examples/simple_room_server>
|
||||||
lib_deps = ${me25ls01.lib_deps}
|
lib_deps = ${me25ls01.lib_deps}
|
||||||
adafruit/RTClib @ ^2.1.3
|
adafruit/RTClib @ ^2.1.3
|
||||||
|
|
@ -149,11 +140,6 @@ build_flags = ${me25ls01.build_flags}
|
||||||
-D MAX_NEIGHBOURS=8
|
-D MAX_NEIGHBOURS=8
|
||||||
-D DISPLAY_CLASS=NullDisplayDriver
|
-D DISPLAY_CLASS=NullDisplayDriver
|
||||||
build_src_filter = ${me25ls01.build_src_filter}
|
build_src_filter = ${me25ls01.build_src_filter}
|
||||||
;+<helpers/nrf52/SerialBLEInterface.cpp>
|
|
||||||
;+<helpers/ui/buzzer.cpp>
|
|
||||||
;+<../examples/companion_radio/*.cpp>
|
|
||||||
;+<../examples/simple_repeater>
|
|
||||||
;+<../examples/simple_room_server>
|
|
||||||
+<../examples/simple_secure_chat/main.cpp>
|
+<../examples/simple_secure_chat/main.cpp>
|
||||||
lib_deps = ${me25ls01.lib_deps}
|
lib_deps = ${me25ls01.lib_deps}
|
||||||
adafruit/RTClib @ ^2.1.3
|
adafruit/RTClib @ ^2.1.3
|
||||||
|
|
@ -173,11 +159,6 @@ build_flags = ${me25ls01.build_flags}
|
||||||
-D DISPLAY_CLASS=NullDisplayDriver
|
-D DISPLAY_CLASS=NullDisplayDriver
|
||||||
build_src_filter = ${me25ls01.build_src_filter}
|
build_src_filter = ${me25ls01.build_src_filter}
|
||||||
+<helpers/nrf52/*.cpp>
|
+<helpers/nrf52/*.cpp>
|
||||||
;+<helpers/nrf52/SerialBLEInterface.cpp>
|
|
||||||
;+<helpers/ui/buzzer.cpp>
|
|
||||||
;+<../examples/companion_radio/*.cpp>
|
|
||||||
;+<../examples/simple_repeater>
|
|
||||||
;+<../examples/simple_room_server>
|
|
||||||
+<../examples/companion_radio>
|
+<../examples/companion_radio>
|
||||||
lib_deps = ${me25ls01.lib_deps}
|
lib_deps = ${me25ls01.lib_deps}
|
||||||
adafruit/RTClib @ ^2.1.3
|
adafruit/RTClib @ ^2.1.3
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ const uint32_t g_ADigitalPinMap[PINS_COUNT + 1] =
|
||||||
28, // P0.28
|
28, // P0.28
|
||||||
29, // P0.29,
|
29, // P0.29,
|
||||||
30, // P0.30
|
30, // P0.30
|
||||||
31, // P0.31,
|
31, // P0.31, BATTERY_PIN
|
||||||
32, // P1.00
|
32, // P1.00
|
||||||
33, // P1.01, LORA_DIO_1
|
33, // P1.01, LORA_DIO_1
|
||||||
34, // P1.02
|
34, // P1.02
|
||||||
|
|
@ -60,8 +60,8 @@ void initVariant()
|
||||||
pinMode(BATTERY_PIN, INPUT);
|
pinMode(BATTERY_PIN, INPUT);
|
||||||
pinMode(PIN_BUTTON1, INPUT);
|
pinMode(PIN_BUTTON1, INPUT);
|
||||||
|
|
||||||
pinMode(PIN_3V3_EN, OUTPUT);
|
// pinMode(PIN_3V3_EN, OUTPUT);
|
||||||
pinMode(PIN_3V3_ACC_EN, OUTPUT);
|
// pinMode(PIN_3V3_ACC_EN, OUTPUT);
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
pinMode(P_LORA_TX_LED, OUTPUT);
|
pinMode(P_LORA_TX_LED, OUTPUT);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,19 @@
|
||||||
|
|
||||||
#include "WVariant.h"
|
#include "WVariant.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Low frequency clock source
|
// Low frequency clock source
|
||||||
|
|
||||||
#define USE_LFXO // 32.768 kHz crystal oscillator
|
#define USE_LFXO // 32.768 kHz crystal oscillator
|
||||||
#define VARIANT_MCK (64000000ul)
|
#define VARIANT_MCK (64000000ul)
|
||||||
// #define USE_LFRC // 32.768 kHz RC oscillator
|
// #define USE_LFRC // 32.768 kHz RC oscillator
|
||||||
|
|
||||||
// Power
|
// Power
|
||||||
#define PIN_3V3_EN (32 + 5) // P1.6 Power to Sensors
|
#define BATTERY_PIN (31)
|
||||||
#define PIN_3V3_ACC_EN -1
|
|
||||||
|
|
||||||
#define BATTERY_PIN (-1) // P0.2/AIN0
|
|
||||||
#define BATTERY_IMMUTABLE
|
#define BATTERY_IMMUTABLE
|
||||||
#define ADC_MULTIPLIER (2.0F)
|
#define ADC_MULTIPLIER (2.0F)
|
||||||
|
|
||||||
#define ADC_RESOLUTION (14)
|
#define ADC_RESOLUTION (14)
|
||||||
#define BATTERY_SENSE_RES (12)
|
#define BATTERY_SENSE_RES (12)
|
||||||
|
|
||||||
#define AREF_VOLTAGE (3.0)
|
|
||||||
|
|
||||||
// Number of pins
|
// Number of pins
|
||||||
#define PINS_COUNT (48)
|
#define PINS_COUNT (48)
|
||||||
#define NUM_DIGITAL_PINS (48)
|
#define NUM_DIGITAL_PINS (48)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue