2025-02-20 22:24:46 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <MeshCore.h>
|
|
|
|
|
#include <Arduino.h>
|
2025-12-12 19:01:15 +07:00
|
|
|
#include <helpers/NRF52Board.h>
|
2025-02-20 22:24:46 +11:00
|
|
|
|
2025-03-11 15:38:37 +11:00
|
|
|
#define P_LORA_NSS 13 //P1.13 45
|
|
|
|
|
#define P_LORA_DIO_1 11 //P0.10 10
|
|
|
|
|
#define P_LORA_RESET 10 //P0.09 9
|
|
|
|
|
#define P_LORA_BUSY 16 //P0.29 29
|
|
|
|
|
#define P_LORA_MISO 15 //P0.02 2
|
|
|
|
|
#define P_LORA_SCLK 12 //P1.11 43
|
|
|
|
|
#define P_LORA_MOSI 14 //P1.15 47
|
|
|
|
|
#define SX126X_POWER_EN 21 //P0.13 13
|
|
|
|
|
#define SX126X_RXEN 2 //P0.17
|
2025-02-25 16:20:35 +11:00
|
|
|
#define SX126X_TXEN RADIOLIB_NC
|
2025-02-20 22:24:46 +11:00
|
|
|
#define SX126X_DIO2_AS_RF_SWITCH true
|
2025-02-25 16:20:35 +11:00
|
|
|
#define SX126X_DIO3_TCXO_VOLTAGE (1.8f)
|
2025-02-20 22:24:46 +11:00
|
|
|
|
2025-03-11 15:38:37 +11:00
|
|
|
#define PIN_VBAT_READ 17
|
2025-02-25 16:20:35 +11:00
|
|
|
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
|
2025-02-20 22:24:46 +11:00
|
|
|
|
2025-12-09 19:56:00 +01:00
|
|
|
class PromicroBoard : public NRF52BoardOTA {
|
2025-02-20 22:24:46 +11:00
|
|
|
protected:
|
2025-03-16 13:24:43 +11:00
|
|
|
uint8_t btn_prev_state;
|
2025-11-21 18:15:30 +11:00
|
|
|
float adc_mult = ADC_MULTIPLIER;
|
2025-02-20 22:24:46 +11:00
|
|
|
|
|
|
|
|
public:
|
2025-12-09 19:56:00 +01:00
|
|
|
PromicroBoard() : NRF52BoardOTA("ProMicro_OTA") {}
|
2025-03-16 13:24:43 +11:00
|
|
|
void begin();
|
2025-02-20 22:24:46 +11:00
|
|
|
|
|
|
|
|
#define BATTERY_SAMPLES 8
|
|
|
|
|
|
|
|
|
|
uint16_t getBattMilliVolts() override {
|
|
|
|
|
analogReadResolution(12);
|
|
|
|
|
|
|
|
|
|
uint32_t raw = 0;
|
|
|
|
|
for (int i = 0; i < BATTERY_SAMPLES; i++) {
|
|
|
|
|
raw += analogRead(PIN_VBAT_READ);
|
|
|
|
|
}
|
|
|
|
|
raw = raw / BATTERY_SAMPLES;
|
2025-11-21 18:15:30 +11:00
|
|
|
return (adc_mult * raw);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-21 23:44:17 +11:00
|
|
|
bool setAdcMultiplier(float multiplier) override {
|
2025-11-21 18:15:30 +11:00
|
|
|
if (multiplier == 0.0f) {
|
|
|
|
|
adc_mult = ADC_MULTIPLIER;}
|
|
|
|
|
else {
|
|
|
|
|
adc_mult = multiplier;
|
|
|
|
|
}
|
2025-11-21 23:44:17 +11:00
|
|
|
return true;
|
2025-11-21 18:15:30 +11:00
|
|
|
}
|
|
|
|
|
float getAdcMultiplier() const override {
|
2025-11-21 23:44:17 +11:00
|
|
|
if (adc_mult == 0.0f) {
|
|
|
|
|
return ADC_MULTIPLIER;
|
|
|
|
|
} else {
|
|
|
|
|
return adc_mult;
|
|
|
|
|
}
|
2025-02-20 22:24:46 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* getManufacturerName() const override {
|
2025-03-30 15:52:25 +11:00
|
|
|
return "ProMicro DIY";
|
2025-02-20 22:24:46 +11:00
|
|
|
}
|
|
|
|
|
|
2025-03-16 13:24:43 +11:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 21:30:51 +10:00
|
|
|
void powerOff() override {
|
|
|
|
|
sd_power_system_off();
|
|
|
|
|
}
|
2025-02-20 22:24:46 +11:00
|
|
|
};
|