#define CONFIG_H
#define MAJ_VERS 0x01
- #define MIN_VERS 0x1E
+ #define MIN_VERS 0x28
#define PLATFORM_AVR 0x90
#define PLATFORM_ESP32 0x80
#elif defined(ESP32)
#define PLATFORM PLATFORM_ESP32
#define MCU_VARIANT MCU_ESP32
+
+ #define CABLE_STATE_DISCONNECTED 0x00
+ #define CABLE_STATE_CONNECTED 0x01
+ uint8_t cable_state = CABLE_STATE_DISCONNECTED;
+
+ #define BT_STATE_NA 0xff
+ #define BT_STATE_OFF 0x00
+ #define BT_STATE_ON 0x01
+ #define BT_STATE_PAIRING 0x02
+ #define BT_STATE_CONNECTED 0x03
+ uint8_t bt_state = BT_STATE_NA;
#else
#error "The firmware cannot be compiled for the selected MCU variant"
#endif
// MCU dependent configuration parameters
+ #define HAS_DISPLAY false
+ #define HAS_BLUETOOTH false
+ #define HAS_PMU false
+
#if MCU_VARIANT == MCU_1284P
const int pin_cs = 4;
const int pin_reset = 3;
const int pin_dio = 26;
const int pin_led_rx = 2;
const int pin_led_tx = 4;
+ #define HAS_PMU true
#elif BOARD_MODEL == BOARD_HUZZAH32
const int pin_cs = 4;
const int pin_reset = 36;
const int pin_led_rx = 22;
const int pin_led_tx = 22;
#endif
+ #define HAS_DISPLAY true
+ #define HAS_BLUETOOTH true
#elif BOARD_MODEL == BOARD_LORA32_V2_1
const int pin_cs = 18;
const int pin_reset = 23;
const int pin_led_rx = 25;
const int pin_led_tx = 25;
#endif
+ #define HAS_DISPLAY true
+ #define HAS_BLUETOOTH true
+ #define HAS_PMU true
#elif BOARD_MODEL == BOARD_HELTEC32_V2
const int pin_cs = 18;
const int pin_reset = 23;
const int pin_led_rx = 22;
const int pin_led_tx = 22;
#endif
+ #define HAS_DISPLAY true
+ #define HAS_BLUETOOTH true
#elif BOARD_MODEL == BOARD_RNODE_NG_21
const int pin_cs = 18;
const int pin_reset = 23;
const int pin_led_rx = 25;
const int pin_led_tx = 25;
#endif
+ #define HAS_DISPLAY true
+ #define HAS_BLUETOOTH true
+ #define HAS_PMU true
#else
#error An unsupported board was selected. Cannot compile RNode firmware.
#endif
+ bool mw_radio_online = false;
+
#define CONFIG_UART_BUFFER_SIZE 6144
#define CONFIG_QUEUE_SIZE 6144
#define CONFIG_QUEUE_MAX_LENGTH 200
bool radio_locked = true;
bool radio_online = false;
bool hw_ready = false;
+ bool disp_ready = false;
+ bool pmu_ready = false;
bool promisc = false;
bool implicit = false;
uint8_t implicit_l = 0;
uint8_t model = 0x00;
uint8_t hwrev = 0x00;
+ int current_rssi = -292;
int last_rssi = -292;
uint8_t last_rssi_raw = 0x00;
- uint8_t last_snr_raw = 0x00;
+ uint8_t last_snr_raw = 0x80;
uint8_t seq = 0xFF;
uint16_t read_len = 0;
const uint8_t SIG_SYNCED = 0x02;
const uint8_t RX_ONGOING = 0x04;
+ // Power management
+ #define BATTERY_STATE_DISCHARGING 0x01
+ #define BATTERY_STATE_CHARGING 0x02
+ #define BATTERY_STATE_CHARGED 0x03
+ float battery_voltage = 0.0;
+ float battery_percent = 0.0;
+ uint8_t battery_state = 0x00;
+
// Boot flags
#define START_FROM_BOOTLOADER 0x01
#define START_FROM_POWERON 0x02
#define CMD_BLINK 0x30
#define CMD_RANDOM 0x40
+ #define CMD_FB_EXT 0x41
+ #define CMD_FB_READ 0x42
+ #define CMD_FB_WRITE 0x43
+
#define CMD_BOARD 0x47
#define CMD_PLATFORM 0x48
#define CMD_MCU 0x49
#include <SPI.h>
#include "Utilities.h"
-
-
FIFOBuffer serialFIFO;
uint8_t serialBuffer[CONFIG_UART_BUFFER_SIZE+1];
LoRa.setPins(pin_cs, pin_reset, pin_dio);
#if MCU_VARIANT == MCU_ESP32
- #if BOARD_MODEL == BOARD_TBEAM
- Wire.begin(I2C_SDA, I2C_SCL);
- initPMU();
+ #if HAS_PMU == true
+ pmu_ready = init_pmu();
#endif
kiss_indicate_reset();
// Validate board health, EEPROM and config
validateStatus();
+
+ #if HAS_DISPLAY
+ disp_ready = display_init();
+ #endif
+
+ #if HAS_BLUETOOTH
+ bt_ready = bt_init();
+ #endif
}
void lora_receive() {
if (frame_len == 0 && command == CMD_UNKNOWN) {
command = sbyte;
} else if (command == CMD_DATA) {
+ cable_state = CABLE_STATE_CONNECTED;
if (sbyte == FESC) {
ESCAPE = true;
} else {
set_implicit_length(sbyte);
kiss_indicate_implicit_length();
} else if (command == CMD_RADIO_STATE) {
+ cable_state = CABLE_STATE_CONNECTED;
if (sbyte == 0xFF) {
kiss_indicate_radiostate();
} else if (sbyte == 0x00) {
kiss_indicate_random(getRandom());
} else if (command == CMD_DETECT) {
if (sbyte == DETECT_REQ) {
+ cable_state = CABLE_STATE_CONNECTED;
kiss_indicate_detect();
}
} else if (command == CMD_PROMISC) {
eeprom_conf_save();
} else if (command == CMD_CONF_DELETE) {
eeprom_conf_delete();
+ } else if (command == CMD_FB_EXT) {
+ #if HAS_DISPLAY == true
+ if (sbyte == 0xFF) {
+ kiss_indicate_fbstate();
+ } else if (sbyte == 0x00) {
+ ext_fb_disable();
+ kiss_indicate_fbstate();
+ } else if (sbyte == 0x01) {
+ ext_fb_enable();
+ kiss_indicate_fbstate();
+ }
+ #endif
+ } else if (command == CMD_FB_WRITE) {
+ if (sbyte == FESC) {
+ ESCAPE = true;
+ } else {
+ if (ESCAPE) {
+ if (sbyte == TFEND) sbyte = FEND;
+ if (sbyte == TFESC) sbyte = FESC;
+ ESCAPE = false;
+ }
+ cbuf[frame_len++] = sbyte;
+ }
+
+ if (frame_len == 9) {
+ uint8_t line = cbuf[0];
+ if (line > 63) line = 63;
+ int fb_o = line*8;
+ memcpy(fb+fb_o, cbuf+1, 8);
+ }
+ } else if (command == CMD_FB_READ) {
+ if (sbyte != 0x00) {
+ kiss_indicate_fb();
+ }
}
}
}
#endif
uint8_t status = LoRa.modemStatus();
+ current_rssi = LoRa.currentRssi();
last_status_update = millis();
#if MCU_VARIANT == MCU_ESP32
#else
if (!fifo_isempty_locked(&serialFIFO)) serial_poll();
#endif
+
+ #if HAS_DISPLAY
+ if (disp_ready) {
+ update_display();
+ }
+ #endif
+
+ #if HAS_PMU
+ if (pmu_ready) {
+ update_pmu();
+ }
+ #endif
}
volatile bool serial_polling = false;
#include "Framing.h"
#include "MD5.h"
+#if HAS_DISPLAY == true
+ #include "Display.h"
+#endif
+
+#if HAS_BLUETOOTH == true
+ #include "Bluetooth.h"
+#endif
+
+#if HAS_PMU == true
+ #include "Power.h"
+#endif
+
#if MCU_VARIANT == MCU_ESP32
#include "soc/rtc_wdt.h"
#define ISR_VECT IRAM_ATTR
Serial.write(FEND);
}
+void kiss_indicate_fbstate() {
+ Serial.write(FEND);
+ Serial.write(CMD_FB_EXT);
+ #if HAS_DISPLAY
+ if (disp_ext_fb) {
+ Serial.write(0x01);
+ } else {
+ Serial.write(0x00);
+ }
+ #else
+ Serial.write(0xFF)
+ #endif
+ Serial.write(FEND);
+}
+
+void kiss_indicate_fb() {
+ Serial.write(FEND);
+ Serial.write(CMD_FB_READ);
+ #if HAS_DISPLAY
+ for (int i = 0; i < 512; i++) {
+ uint8_t byte = fb[i];
+ if (byte == FEND) { Serial.write(FESC); byte = TFEND; }
+ if (byte == FESC) { Serial.write(FESC); byte = TFESC; }
+ Serial.write(byte);
+ }
+ #else
+ Serial.write(0xFF)
+ #endif
+ Serial.write(FEND);
+}
+
void kiss_indicate_ready() {
Serial.write(FEND);
Serial.write(CMD_READY);
inline uint16_t fifo16_len(FIFOBuffer16 *f) {
return (f->end - f->begin);
}
-
-#if BOARD_MODEL == BOARD_TBEAM
- #include <axp20x.h>
- AXP20X_Class PMU;
-
- bool initPMU()
- {
- if (PMU.begin(Wire, AXP192_SLAVE_ADDRESS) == AXP_FAIL) {
- return false;
- }
- /*
- * The charging indicator can be turned on or off
- * * * */
- PMU.setChgLEDMode(AXP20X_LED_OFF);
-
- /*
- * The default ESP32 power supply has been turned on,
- * no need to set, please do not set it, if it is turned off,
- * it will not be able to program
- *
- * PMU.setDCDC3Voltage(3300);
- * PMU.setPowerOutPut(AXP192_DCDC3, AXP202_ON);
- *
- * * * */
-
- /*
- * Turn off unused power sources to save power
- * **/
-
- PMU.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
- PMU.setPowerOutPut(AXP192_DCDC2, AXP202_OFF);
- PMU.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
- PMU.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
- PMU.setPowerOutPut(AXP192_EXTEN, AXP202_OFF);
-
- /*
- * Set the power of LoRa and GPS module to 3.3V
- **/
- PMU.setLDO2Voltage(3300); //LoRa VDD
- PMU.setLDO3Voltage(3300); //GPS VDD
- PMU.setDCDC1Voltage(3300); //3.3V Pin next to 21 and 22 is controlled by DCDC1
-
- PMU.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
-
- // Turn on SX1276
- PMU.setPowerOutPut(AXP192_LDO2, AXP202_ON);
-
- // Turn off GPS
- PMU.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
-
- pinMode(PMU_IRQ, INPUT_PULLUP);
- attachInterrupt(PMU_IRQ, [] {
- // pmu_irq = true;
- }, FALLING);
-
- PMU.adc1Enable(AXP202_VBUS_VOL_ADC1 |
- AXP202_VBUS_CUR_ADC1 |
- AXP202_BATT_CUR_ADC1 |
- AXP202_BATT_VOL_ADC1,
- AXP202_ON);
-
- PMU.enableIRQ(AXP202_VBUS_REMOVED_IRQ |
- AXP202_VBUS_CONNECT_IRQ |
- AXP202_BATT_REMOVED_IRQ |
- AXP202_BATT_CONNECT_IRQ,
- AXP202_ON);
- PMU.clearIRQ();
-
- return true;
- }
-
- void disablePeripherals()
- {
- PMU.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
- PMU.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
- PMU.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
- }
-
-#endif