2018-06-20 00:45:11 -06:00
|
|
|
#include "ROM.h"
|
|
|
|
|
2022-02-13 14:58:04 -07:00
|
|
|
#include "Platform.h"
|
|
|
|
|
2018-04-05 10:10:42 -06:00
|
|
|
#ifndef CONFIG_H
|
|
|
|
#define CONFIG_H
|
|
|
|
|
2018-06-20 00:45:11 -06:00
|
|
|
#define MAJ_VERS 0x01
|
2022-01-28 08:40:30 -07:00
|
|
|
#define MIN_VERS 0x1B
|
2022-01-09 15:40:30 -07:00
|
|
|
|
2022-01-21 12:43:29 -07: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-02-13 14:36:24 -07:00
|
|
|
|
2022-02-13 18:20:21 -07:00
|
|
|
#define SERIAL_INTERRUPT 0x1
|
|
|
|
#define SERIAL_POLLING 0x2
|
|
|
|
|
2018-06-20 09:45:22 -06:00
|
|
|
#define MODE_HOST 0x11
|
|
|
|
#define MODE_TNC 0x12
|
|
|
|
|
2018-04-05 10:10:42 -06:00
|
|
|
#define MTU 500
|
|
|
|
#define SINGLE_MTU 255
|
|
|
|
#define HEADER_L 1
|
2020-05-28 14:18:19 -06:00
|
|
|
#define MIN_L 1
|
|
|
|
|
2018-04-05 10:10:42 -06:00
|
|
|
#define CMD_L 4
|
|
|
|
|
|
|
|
// MCU dependent configuration parameters
|
|
|
|
|
|
|
|
#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 02:34:39 -06:00
|
|
|
|
2022-01-14 12:49:50 -07:00
|
|
|
#define BOARD_MODEL BOARD_RNODE
|
2022-02-13 18:20:21 -07:00
|
|
|
#define SERIAL_EVENTS SERIAL_INTERRUPT
|
2022-01-14 12:49:50 -07:00
|
|
|
|
2020-05-29 06:58:10 -06:00
|
|
|
#define CONFIG_UART_BUFFER_SIZE 6144
|
|
|
|
#define CONFIG_QUEUE_SIZE 6144
|
2022-01-21 12:43:29 -07:00
|
|
|
#define CONFIG_QUEUE_MAX_LENGTH 200
|
2018-06-20 00:45:11 -06:00
|
|
|
|
|
|
|
#define EEPROM_SIZE 4096
|
|
|
|
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
|
2022-01-09 15:40:30 -07:00
|
|
|
|
|
|
|
#elif MCU_VARIANT == MCU_2560
|
2022-01-21 14:08:55 -07:00
|
|
|
const int pin_cs = 5;
|
|
|
|
const int pin_reset = 4;
|
2021-12-13 17:50:37 -07:00
|
|
|
const int pin_dio = 2;
|
|
|
|
const int pin_led_rx = 12;
|
|
|
|
const int pin_led_tx = 13;
|
|
|
|
|
2022-01-14 12:49:50 -07:00
|
|
|
#define BOARD_MODEL BOARD_HMBRW
|
2022-02-13 18:20:21 -07:00
|
|
|
#define SERIAL_EVENTS SERIAL_INTERRUPT
|
2022-01-14 12:49:50 -07:00
|
|
|
|
2022-01-21 12:43:29 -07:00
|
|
|
#define CONFIG_UART_BUFFER_SIZE 768
|
|
|
|
#define CONFIG_QUEUE_SIZE 5120
|
|
|
|
#define CONFIG_QUEUE_MAX_LENGTH 24
|
2021-12-13 17:50:37 -07:00
|
|
|
|
|
|
|
#define EEPROM_SIZE 4096
|
|
|
|
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
|
2022-01-09 15:40:30 -07:00
|
|
|
|
|
|
|
#elif MCU_VARIANT == MCU_ESP32
|
|
|
|
|
2022-01-25 11:14:16 -07: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
|
|
|
|
|
2022-01-21 12:43:29 -07:00
|
|
|
#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;
|
|
|
|
#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;
|
|
|
|
#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-01-21 14:45:26 -07:00
|
|
|
#elif BOARD_MODEL == BOARD_LORA32_V2_0
|
2022-01-24 11:30:00 -07:00
|
|
|
const int pin_cs = 18;
|
|
|
|
const int pin_reset = 12;
|
|
|
|
const int pin_dio = 26;
|
|
|
|
#if defined(EXTERNAL_LEDS)
|
2022-01-24 12:33:58 -07:00
|
|
|
const int pin_led_rx = 2;
|
|
|
|
const int pin_led_tx = 0;
|
2022-01-24 11:30:00 -07:00
|
|
|
#else
|
2022-01-24 12:33:58 -07:00
|
|
|
const int pin_led_rx = 22;
|
|
|
|
const int pin_led_tx = 22;
|
2022-01-24 11:30:00 -07:00
|
|
|
#endif
|
2022-01-21 14:45:26 -07: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 13:43:52 -07: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
|
2022-01-21 12:43:29 -07:00
|
|
|
#else
|
|
|
|
#error An unsupported board was selected. Cannot compile RNode firmware.
|
|
|
|
#endif
|
2022-02-13 14:36:24 -07:00
|
|
|
|
2022-02-13 18:20:21 -07:00
|
|
|
#define SERIAL_EVENTS SERIAL_POLLING
|
|
|
|
|
2022-01-14 13:12:33 -07:00
|
|
|
#define CONFIG_UART_BUFFER_SIZE 6144
|
2022-01-09 15:40:30 -07:00
|
|
|
#define CONFIG_QUEUE_SIZE 6144
|
2022-01-21 12:43:29 -07:00
|
|
|
#define CONFIG_QUEUE_MAX_LENGTH 200
|
2022-01-09 15:40:30 -07:00
|
|
|
|
|
|
|
#define EEPROM_SIZE 1024
|
|
|
|
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
|
2022-01-10 18:54:32 -07:00
|
|
|
|
|
|
|
#define GPS_BAUD_RATE 9600
|
|
|
|
#define PIN_GPS_TX 12
|
|
|
|
#define PIN_GPS_RX 34
|
2022-02-13 14:36:24 -07:00
|
|
|
#elif MCU_VARIANT == MCU_LINUX
|
|
|
|
const int pin_cs = -1;
|
|
|
|
const int pin_reset = -1;
|
|
|
|
const int pin_dio = -1;
|
|
|
|
const int pin_led_rx = -1;
|
|
|
|
const int pin_led_tx = -1;
|
|
|
|
|
2022-02-16 07:53:56 -07:00
|
|
|
#define BOARD_MODEL BOARD_HMBRW
|
2022-02-13 18:20:21 -07:00
|
|
|
#define SERIAL_EVENTS SERIAL_POLLING
|
2022-02-13 14:36:24 -07: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
|
2021-12-13 17:50:37 -07:00
|
|
|
#endif
|
|
|
|
|
2022-01-14 12:49:50 -07:00
|
|
|
#if BOARD_MODEL == BOARD_TBEAM
|
2022-01-22 14:34:03 -07:00
|
|
|
#define I2C_SDA 21
|
|
|
|
#define I2C_SCL 22
|
|
|
|
#define PMU_IRQ 35
|
2022-01-14 12:49:50 -07:00
|
|
|
#endif
|
2022-02-13 14:36:24 -07:00
|
|
|
|
|
|
|
#if LIBRARY_TYPE == LIBRARY_C
|
|
|
|
// We need standard int types before we go any further
|
|
|
|
#include <cstdint>
|
|
|
|
#endif
|
|
|
|
|
2018-06-20 00:45:11 -06:00
|
|
|
#define eeprom_addr(a) (a+EEPROM_OFFSET)
|
|
|
|
|
2018-04-05 10:10:42 -06:00
|
|
|
// MCU independent configuration parameters
|
2022-01-10 14:14:30 -07:00
|
|
|
const long serial_baudrate = 115200;
|
2018-04-26 08:47:03 -06:00
|
|
|
const int lora_rx_turnaround_ms = 50;
|
2018-04-05 10:10:42 -06:00
|
|
|
|
2019-11-07 07:26:21 -07:00
|
|
|
// SX1276 RSSI offset to get dBm value from
|
|
|
|
// packet RSSI register
|
2022-01-09 15:40:30 -07:00
|
|
|
const int rssi_offset = 157;
|
2019-11-07 07:26:21 -07:00
|
|
|
|
2018-04-05 10:10:42 -06:00
|
|
|
// Default LoRa settings
|
2018-06-20 08:32:30 -06:00
|
|
|
int lora_sf = 0;
|
|
|
|
int lora_cr = 5;
|
|
|
|
int lora_txp = 0xFF;
|
2018-04-05 10:10:42 -06:00
|
|
|
uint32_t lora_bw = 0;
|
|
|
|
uint32_t lora_freq = 0;
|
|
|
|
|
|
|
|
// Operational variables
|
2021-03-12 10:48:50 -07:00
|
|
|
bool radio_locked = true;
|
|
|
|
bool radio_online = false;
|
|
|
|
bool hw_ready = false;
|
|
|
|
bool promisc = false;
|
|
|
|
bool implicit = false;
|
|
|
|
uint8_t implicit_l = 0;
|
2018-06-27 03:42:48 -06:00
|
|
|
|
2018-06-20 09:45:22 -06:00
|
|
|
uint8_t op_mode = MODE_HOST;
|
2018-06-20 00:45:11 -06:00
|
|
|
uint8_t model = 0x00;
|
|
|
|
uint8_t hwrev = 0x00;
|
2021-12-13 17:50:37 -07:00
|
|
|
|
2018-06-27 06:08:16 -06:00
|
|
|
int last_rssi = -292;
|
|
|
|
uint8_t last_rssi_raw = 0x00;
|
2020-05-21 04:41:39 -06:00
|
|
|
uint8_t last_snr_raw = 0x00;
|
2018-04-05 10:10:42 -06:00
|
|
|
uint8_t seq = 0xFF;
|
2022-01-14 12:49:50 -07:00
|
|
|
uint16_t read_len = 0;
|
2021-12-13 17:50:37 -07:00
|
|
|
|
2020-05-28 14:18:19 -06:00
|
|
|
// Incoming packet buffer
|
2018-04-05 10:10:42 -06:00
|
|
|
uint8_t pbuf[MTU];
|
2020-05-28 14:18:19 -06:00
|
|
|
|
|
|
|
// KISS command buffer
|
2018-04-05 10:10:42 -06:00
|
|
|
uint8_t cbuf[CMD_L];
|
|
|
|
|
2020-05-28 14:18:19 -06:00
|
|
|
// LoRa transmit buffer
|
|
|
|
uint8_t tbuf[MTU];
|
2018-06-27 02:22:44 -06:00
|
|
|
|
2018-04-05 10:10:42 -06:00
|
|
|
uint32_t stat_rx = 0;
|
|
|
|
uint32_t stat_tx = 0;
|
|
|
|
|
2018-04-26 07:52:43 -06: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;
|
|
|
|
|
2021-12-26 03:27:32 -07: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 11:30:00 -07:00
|
|
|
#endif
|