RNode_Firmware_CE/Config.h

340 lines
8.6 KiB
C
Raw Normal View History

#include "ROM.h"
2018-04-05 18:10:42 +02:00
#ifndef CONFIG_H
#define CONFIG_H
#define MAJ_VERS 0x01
2022-12-16 19:59:57 +01:00
#define MIN_VERS 0x36
2022-01-09 23:40:30 +01:00
#define PLATFORM_AVR 0x90
#define PLATFORM_ESP32 0x80
2018-04-05 18:10:42 +02:00
#define MCU_1284P 0x91
2021-12-14 01:50:37 +01:00
#define MCU_2560 0x92
2022-01-09 23:40:30 +01:00
#define MCU_ESP32 0x81
2018-04-05 18:10:42 +02:00
#define BOARD_RNODE 0x31
#define BOARD_HMBRW 0x32
#define BOARD_TBEAM 0x33
#define BOARD_HUZZAH32 0x34
#define BOARD_GENERIC_ESP32 0x35
#define BOARD_LORA32_V2_0 0x36
#define BOARD_LORA32_V2_1 0x37
2022-06-16 19:12:28 +02:00
#define BOARD_HELTEC32_V2 0x38
2022-06-11 16:42:49 +02:00
#define BOARD_RNODE_NG_20 0x40
#define BOARD_RNODE_NG_21 0x41
2022-01-14 20:49:50 +01:00
2018-06-20 17:45:22 +02:00
#define MODE_HOST 0x11
#define MODE_TNC 0x12
2022-10-30 18:58:12 +01:00
#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;
uint32_t bt_ssp_pin = 0;
bool bt_ready = false;
bool bt_enabled = false;
bool bt_allow_pairing = false;
2023-01-07 16:35:07 +01:00
#define M_FRQ_S 27388122
#define M_FRQ_R 27388061
bool console_active = false;
bool sx1276_installed = false;
2020-05-28 22:18:19 +02:00
#if defined(__AVR_ATmega1284P__)
2022-01-14 20:49:50 +01:00
#define PLATFORM PLATFORM_AVR
#define MCU_VARIANT MCU_1284P
2021-12-14 01:50:37 +01:00
#elif defined(__AVR_ATmega2560__)
2022-01-14 20:49:50 +01:00
#define PLATFORM PLATFORM_AVR
#define MCU_VARIANT MCU_2560
2022-01-09 23:40:30 +01:00
#elif defined(ESP32)
2022-01-14 20:49:50 +01:00
#define PLATFORM PLATFORM_ESP32
#define MCU_VARIANT MCU_ESP32
2018-04-05 18:10:42 +02:00
#else
2022-01-14 20:49:50 +01:00
#error "The firmware cannot be compiled for the selected MCU variant"
2018-04-05 18:10:42 +02:00
#endif
#define MTU 508
2018-04-05 18:10:42 +02:00
#define SINGLE_MTU 255
#define HEADER_L 1
2020-05-28 22:18:19 +02:00
#define MIN_L 1
#define CMD_L 64
2018-04-05 18:10:42 +02:00
// MCU dependent configuration parameters
#define HAS_DISPLAY false
#define HAS_BLUETOOTH false
#define HAS_PMU false
2022-12-04 20:00:21 +01:00
#define HAS_NP false
2018-04-05 18:10:42 +02:00
#if MCU_VARIANT == MCU_1284P
const int pin_cs = 4;
const int pin_reset = 3;
const int pin_dio = 2;
const int pin_led_rx = 12;
const int pin_led_tx = 13;
2018-04-26 10:34:39 +02:00
2022-01-14 20:49:50 +01:00
#define BOARD_MODEL BOARD_RNODE
2020-05-29 14:58:10 +02:00
#define CONFIG_UART_BUFFER_SIZE 6144
#define CONFIG_QUEUE_SIZE 6144
#define CONFIG_QUEUE_MAX_LENGTH 200
#define EEPROM_SIZE 4096
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
2022-01-09 23:40:30 +01:00
#elif MCU_VARIANT == MCU_2560
2022-01-21 22:08:55 +01:00
const int pin_cs = 5;
const int pin_reset = 4;
2021-12-14 01:50:37 +01:00
const int pin_dio = 2;
const int pin_led_rx = 12;
const int pin_led_tx = 13;
2022-01-14 20:49:50 +01:00
#define BOARD_MODEL BOARD_HMBRW
#define CONFIG_UART_BUFFER_SIZE 768
#define CONFIG_QUEUE_SIZE 5120
#define CONFIG_QUEUE_MAX_LENGTH 24
2021-12-14 01:50:37 +01:00
#define EEPROM_SIZE 4096
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
2022-01-09 23:40:30 +01:00
#elif MCU_VARIANT == MCU_ESP32
2022-01-25 19:14:16 +01:00
// Board models for ESP32 based builds are
// defined by the build target in the makefile.
// If you are not using make to compile this
// firmware, you can manually define model here.
//
// #define BOARD_MODEL BOARD_GENERIC_ESP32
#if BOARD_MODEL == BOARD_GENERIC_ESP32
const int pin_cs = 4;
const int pin_reset = 36;
const int pin_dio = 39;
const int pin_led_rx = 14;
const int pin_led_tx = 32;
2022-10-30 18:58:12 +01:00
#define HAS_BLUETOOTH true
#elif BOARD_MODEL == BOARD_TBEAM
const int pin_cs = 18;
const int pin_reset = 23;
const int pin_dio = 26;
const int pin_led_rx = 2;
const int pin_led_tx = 4;
2022-10-30 18:58:12 +01:00
#define HAS_DISPLAY true
#define HAS_PMU true
2022-10-30 18:58:12 +01:00
#define HAS_BLUETOOTH true
#elif BOARD_MODEL == BOARD_HUZZAH32
const int pin_cs = 4;
const int pin_reset = 36;
const int pin_dio = 39;
const int pin_led_rx = 14;
const int pin_led_tx = 32;
2022-10-30 18:58:12 +01:00
#define HAS_BLUETOOTH true
2022-01-21 22:45:26 +01:00
#elif BOARD_MODEL == BOARD_LORA32_V2_0
2022-01-24 19:30:00 +01:00
const int pin_cs = 18;
const int pin_reset = 12;
const int pin_dio = 26;
#if defined(EXTERNAL_LEDS)
2022-01-24 20:33:58 +01:00
const int pin_led_rx = 2;
const int pin_led_tx = 0;
2022-01-24 19:30:00 +01:00
#else
2022-01-24 20:33:58 +01:00
const int pin_led_rx = 22;
const int pin_led_tx = 22;
2022-01-24 19:30:00 +01:00
#endif
#define HAS_DISPLAY true
#define HAS_BLUETOOTH true
2022-01-21 22:45:26 +01:00
#elif BOARD_MODEL == BOARD_LORA32_V2_1
const int pin_cs = 18;
const int pin_reset = 23;
const int pin_dio = 26;
2022-01-22 21:43:52 +01:00
#if defined(EXTERNAL_LEDS)
const int pin_led_rx = 15;
const int pin_led_tx = 4;
#else
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
2022-06-16 19:12:28 +02:00
#elif BOARD_MODEL == BOARD_HELTEC32_V2
const int pin_cs = 18;
const int pin_reset = 23;
const int pin_dio = 26;
#if defined(EXTERNAL_LEDS)
const int pin_led_rx = 36;
const int pin_led_tx = 37;
#else
const int pin_led_rx = 25;
const int pin_led_tx = 25;
#endif
#define HAS_DISPLAY true
2022-10-30 18:58:12 +01:00
#define HAS_BLUETOOTH true
2022-06-11 16:42:49 +02:00
#elif BOARD_MODEL == BOARD_RNODE_NG_20
2022-12-04 20:00:21 +01:00
#define HAS_DISPLAY true
#define HAS_BLUETOOTH true
#define HAS_NP true
2022-06-11 16:42:49 +02:00
const int pin_cs = 18;
const int pin_reset = 12;
const int pin_dio = 26;
2022-12-04 20:00:21 +01:00
const int pin_np = 4;
#if HAS_NP == false
#if defined(EXTERNAL_LEDS)
const int pin_led_rx = 2;
const int pin_led_tx = 0;
#else
const int pin_led_rx = 22;
const int pin_led_tx = 22;
#endif
2022-06-11 16:42:49 +02:00
#endif
2022-12-04 20:00:21 +01:00
#elif BOARD_MODEL == BOARD_RNODE_NG_21
#define HAS_DISPLAY true
#define HAS_BLUETOOTH true
2023-01-06 22:29:23 +01:00
#define HAS_CONSOLE true
2022-12-04 20:00:21 +01:00
#define HAS_PMU true
#define HAS_NP true
2023-01-09 22:27:52 +01:00
#define HAS_SD true
2022-06-11 16:42:49 +02:00
const int pin_cs = 18;
const int pin_reset = 23;
const int pin_dio = 26;
2023-01-09 22:27:52 +01:00
const int pin_np = 12;
const int pin_dac = 25;
const int pin_adc = 34;
const int SD_MISO = 2;
const int SD_MOSI = 15;
const int SD_CLK = 14;
const int SD_CS = 13;
2022-12-04 20:00:21 +01:00
#if HAS_NP == false
#if defined(EXTERNAL_LEDS)
2023-01-09 22:27:52 +01:00
const int pin_led_rx = 12;
2022-12-04 20:00:21 +01:00
const int pin_led_tx = 4;
#else
const int pin_led_rx = 25;
const int pin_led_tx = 25;
#endif
2022-06-11 16:42:49 +02:00
#endif
#else
#error An unsupported board was selected. Cannot compile RNode firmware.
#endif
2022-01-14 20:49:50 +01:00
bool mw_radio_online = false;
2022-01-14 21:12:33 +01:00
#define CONFIG_UART_BUFFER_SIZE 6144
2022-01-09 23:40:30 +01:00
#define CONFIG_QUEUE_SIZE 6144
#define CONFIG_QUEUE_MAX_LENGTH 200
2022-01-09 23:40:30 +01:00
#define EEPROM_SIZE 1024
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
2022-01-11 02:54:32 +01:00
#define GPS_BAUD_RATE 9600
#define PIN_GPS_TX 12
#define PIN_GPS_RX 34
2021-12-14 01:50:37 +01:00
#endif
2022-01-14 20:49:50 +01:00
#if BOARD_MODEL == BOARD_TBEAM
2022-01-22 22:34:03 +01:00
#define I2C_SDA 21
#define I2C_SCL 22
#define PMU_IRQ 35
2022-01-14 20:49:50 +01:00
#endif
#define eeprom_addr(a) (a+EEPROM_OFFSET)
2018-04-05 18:10:42 +02:00
// MCU independent configuration parameters
2022-01-10 22:14:30 +01:00
const long serial_baudrate = 115200;
2018-04-26 16:47:03 +02:00
const int lora_rx_turnaround_ms = 50;
2018-04-05 18:10:42 +02:00
// SX1276 RSSI offset to get dBm value from
// packet RSSI register
2022-01-09 23:40:30 +01:00
const int rssi_offset = 157;
2018-04-05 18:10:42 +02:00
// Default LoRa settings
2018-06-20 16:32:30 +02:00
int lora_sf = 0;
int lora_cr = 5;
int lora_txp = 0xFF;
2018-04-05 18:10:42 +02:00
uint32_t lora_bw = 0;
uint32_t lora_freq = 0;
// Operational variables
2021-03-12 18:48:50 +01:00
bool radio_locked = true;
bool radio_online = false;
2022-10-29 16:42:46 +02:00
bool community_fw = true;
2021-03-12 18:48:50 +01:00
bool hw_ready = false;
2022-10-29 16:42:46 +02:00
bool radio_error = false;
bool disp_ready = false;
bool pmu_ready = false;
2021-03-12 18:48:50 +01:00
bool promisc = false;
bool implicit = false;
uint8_t implicit_l = 0;
2018-06-27 11:42:48 +02:00
2018-06-20 17:45:22 +02:00
uint8_t op_mode = MODE_HOST;
uint8_t model = 0x00;
uint8_t hwrev = 0x00;
2021-12-14 01:50:37 +01:00
int current_rssi = -292;
2018-06-27 14:08:16 +02:00
int last_rssi = -292;
uint8_t last_rssi_raw = 0x00;
uint8_t last_snr_raw = 0x80;
2018-04-05 18:10:42 +02:00
uint8_t seq = 0xFF;
2022-01-14 20:49:50 +01:00
uint16_t read_len = 0;
2021-12-14 01:50:37 +01:00
2020-05-28 22:18:19 +02:00
// Incoming packet buffer
2018-04-05 18:10:42 +02:00
uint8_t pbuf[MTU];
2020-05-28 22:18:19 +02:00
// KISS command buffer
uint8_t cmdbuf[CMD_L];
2018-04-05 18:10:42 +02:00
2020-05-28 22:18:19 +02:00
// LoRa transmit buffer
uint8_t tbuf[MTU];
2018-06-27 10:22:44 +02:00
2018-04-05 18:10:42 +02:00
uint32_t stat_rx = 0;
uint32_t stat_tx = 0;
2018-04-26 15:52:43 +02:00
bool stat_signal_detected = false;
bool stat_signal_synced = false;
bool stat_rx_ongoing = false;
bool dcd = false;
bool dcd_led = false;
bool dcd_waiting = false;
uint16_t dcd_count = 0;
uint16_t dcd_threshold = 15;
uint32_t status_interval_ms = 3;
uint32_t last_status_update = 0;
// Status flags
const uint8_t SIG_DETECT = 0x01;
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
2022-10-30 22:27:30 +01:00
bool battery_installed = false;
bool battery_indeterminate = false;
2022-10-30 22:27:30 +01:00
bool external_power = false;
bool battery_ready = false;
float battery_voltage = 0.0;
float battery_percent = 0.0;
uint8_t battery_state = 0x00;
uint8_t display_intensity = 0xFF;
bool device_init_done = false;
bool eeprom_ok = false;
bool firmware_update_mode = false;
2021-12-26 11:27:32 +01:00
// Boot flags
#define START_FROM_BOOTLOADER 0x01
#define START_FROM_POWERON 0x02
#define START_FROM_BROWNOUT 0x03
#define START_FROM_JTAG 0x04
2022-01-24 19:30:00 +01:00
#endif