Boards own their FEM control through handleCommand() ("get/set
radio.fem.rxgain|txgain"). Use that instead of a parallel set of FEM
virtuals on MainBoard, so any board that implements the commands works
in KISS with no extra code.
- Remove the six FEM virtuals from MainBoard and the board overrides.
- KissModem talks to the board in one adapter. A gain counts as
controllable only if "get" replies exactly "> on" or "> off". "set"
is checked by reading the state back, never by its reply wording.
- SetFemState always replies with the read-back state once the
requested bits pass the capability check.
- Guard the boards' prefs writes against a NULL store. KISS attaches
no prefs, so "set radio.fem.*" would dereference NULL.
- Wio Tracker L1 1W TX gain is exposed again, matching its CLI.
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
#include <Arduino.h>
|
|
#include <Wire.h>
|
|
|
|
#include "WioTrackerL1Board.h"
|
|
|
|
void WioTrackerL1Board::begin() {
|
|
NRF52BoardDCDC::begin();
|
|
btn_prev_state = HIGH;
|
|
|
|
pinMode(PIN_VBAT_READ, INPUT); // VBAT ADC input
|
|
// Set all button pins to INPUT_PULLUP
|
|
pinMode(PIN_BUTTON1, INPUT_PULLUP);
|
|
pinMode(PIN_BUTTON2, INPUT_PULLUP);
|
|
pinMode(PIN_BUTTON3, INPUT_PULLUP);
|
|
pinMode(PIN_BUTTON4, INPUT_PULLUP);
|
|
pinMode(PIN_BUTTON5, INPUT_PULLUP);
|
|
pinMode(PIN_BUTTON6, INPUT_PULLUP);
|
|
|
|
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
|
|
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
|
|
#endif
|
|
|
|
Wire.begin();
|
|
|
|
pinMode(SX126X_POWER_EN, OUTPUT);
|
|
|
|
#ifdef P_LORA_TX_LED
|
|
pinMode(P_LORA_TX_LED, OUTPUT);
|
|
digitalWrite(P_LORA_TX_LED, LOW);
|
|
#endif
|
|
|
|
delay(10); // give sx1262 some time to power up
|
|
}
|
|
|
|
bool WioTrackerL1Board::setLoRaFemPaGainEnabled(bool enable) {
|
|
_is_pa_enabled = enable;
|
|
digitalWrite(SX126X_POWER_EN, enable ? HIGH : LOW); // enable/disable the 1W PA
|
|
return true;
|
|
}
|
|
|
|
void WioTrackerL1Board::attachDynamicPrefs(KeyValueStore* prefs) {
|
|
_prefs = prefs;
|
|
|
|
char gain[8];
|
|
|
|
gain[0] = 0;
|
|
_prefs->getByKey("fem_txgain", gain, 7); // get initial values
|
|
setLoRaFemPaGainEnabled(strcmp(gain, "1") == 0);
|
|
}
|
|
|
|
bool WioTrackerL1Board::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) {
|
|
if (strcmp(command, "get radio.fem.rxgain") == 0) {
|
|
strcpy(reply, "Error: unsupported");
|
|
return true;
|
|
}
|
|
if (memcmp(command, "set radio.fem.rxgain ", 21) == 0) {
|
|
strcpy(reply, "Error: unsupported");
|
|
return true;
|
|
}
|
|
|
|
if (strcmp(command, "get radio.fem.txgain") == 0) {
|
|
sprintf(reply, "> %s", isLoRaFemPaGainEnabled() ? "on" : "off");
|
|
return true;
|
|
}
|
|
if (memcmp(command, "set radio.fem.txgain ", 21) == 0) {
|
|
if (memcmp(&command[21], "on", 2) == 0) {
|
|
if (setLoRaFemPaGainEnabled(true)) {
|
|
if (_prefs) _prefs->setByKey("fem_txgain", "1");
|
|
strcpy(reply, "OK - LoRa FEM TX gain on");
|
|
} else {
|
|
strcpy(reply, "Error: failed to apply LoRa FEM TX gain");
|
|
}
|
|
} else if (memcmp(&command[21], "off", 3) == 0) {
|
|
if (setLoRaFemPaGainEnabled(false)) {
|
|
if (_prefs) _prefs->setByKey("fem_txgain", "0");
|
|
strcpy(reply, "OK - LoRa FEM TX gain off");
|
|
} else {
|
|
strcpy(reply, "Error: failed to apply LoRa FEM TX gain");
|
|
}
|
|
} else {
|
|
strcpy(reply, "Error: state must be on or off");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
return false; // not handled
|
|
}
|