2023-01-13 16:11:02 -07:00
|
|
|
// Copyright (C) 2023, Mark Qvist
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2018-06-20 00:45:11 -06:00
|
|
|
#include "ROM.h"
|
2024-02-09 07:29:54 -07:00
|
|
|
#include "Boards.h"
|
2024-01-19 03:08:55 -07:00
|
|
|
#include "Modem.h"
|
2018-06-20 00:45:11 -06:00
|
|
|
|
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
|
2024-01-21 04:32:57 -07:00
|
|
|
#define MIN_VERS 0x46
|
2022-01-09 15:40:30 -07:00
|
|
|
|
2018-06-20 09:45:22 -06:00
|
|
|
#define MODE_HOST 0x11
|
|
|
|
#define MODE_TNC 0x12
|
|
|
|
|
2022-10-30 11:58:12 -06: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 08:35:07 -07:00
|
|
|
#define M_FRQ_S 27388122
|
|
|
|
#define M_FRQ_R 27388061
|
|
|
|
bool console_active = false;
|
2024-01-19 03:08:55 -07:00
|
|
|
bool modem_installed = false;
|
2023-01-07 08:35:07 -07:00
|
|
|
|
2020-05-28 14:18:19 -06:00
|
|
|
#if defined(__AVR_ATmega1284P__)
|
2022-01-14 12:49:50 -07:00
|
|
|
#define PLATFORM PLATFORM_AVR
|
|
|
|
#define MCU_VARIANT MCU_1284P
|
2021-12-13 17:50:37 -07:00
|
|
|
#elif defined(__AVR_ATmega2560__)
|
2022-01-14 12:49:50 -07:00
|
|
|
#define PLATFORM PLATFORM_AVR
|
|
|
|
#define MCU_VARIANT MCU_2560
|
2022-01-09 15:40:30 -07:00
|
|
|
#elif defined(ESP32)
|
2022-01-14 12:49:50 -07:00
|
|
|
#define PLATFORM PLATFORM_ESP32
|
|
|
|
#define MCU_VARIANT MCU_ESP32
|
2024-01-20 03:46:38 -07:00
|
|
|
#elif defined(NRF52840_XXAA)
|
2024-01-19 03:08:55 -07:00
|
|
|
#define PLATFORM PLATFORM_NRF52
|
|
|
|
#define MCU_VARIANT MCU_NRF52
|
2018-04-05 10:10:42 -06:00
|
|
|
#else
|
2022-01-14 12:49:50 -07:00
|
|
|
#error "The firmware cannot be compiled for the selected MCU variant"
|
2018-04-05 10:10:42 -06:00
|
|
|
#endif
|
|
|
|
|
2022-05-29 06:48:53 -06:00
|
|
|
#define MTU 508
|
2018-04-05 10:10:42 -06:00
|
|
|
#define SINGLE_MTU 255
|
|
|
|
#define HEADER_L 1
|
2020-05-28 14:18:19 -06:00
|
|
|
#define MIN_L 1
|
|
|
|
|
2022-11-01 14:11:41 -06:00
|
|
|
#define CMD_L 64
|
2018-04-05 10:10:42 -06:00
|
|
|
|
|
|
|
// MCU dependent configuration parameters
|
|
|
|
|
2022-10-28 16:53:39 -06:00
|
|
|
#define HAS_DISPLAY false
|
|
|
|
#define HAS_BLUETOOTH false
|
2023-06-07 12:49:26 -06:00
|
|
|
#define HAS_TCXO false
|
2022-10-28 16:53:39 -06:00
|
|
|
#define HAS_PMU false
|
2022-12-04 12:00:21 -07:00
|
|
|
#define HAS_NP false
|
2024-01-19 03:08:55 -07:00
|
|
|
#define HAS_EEPROM false
|
2022-10-28 16:53:39 -06:00
|
|
|
|
2024-01-18 16:10:24 -07:00
|
|
|
#if defined(ENABLE_TCXO)
|
|
|
|
#define HAS_TCXO true
|
|
|
|
#endif
|
|
|
|
|
2018-04-05 10:10:42 -06: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 02:34:39 -06:00
|
|
|
|
2022-01-14 12:49:50 -07:00
|
|
|
#define BOARD_MODEL BOARD_RNODE
|
|
|
|
|
2024-01-19 03:08:55 -07:00
|
|
|
#define HAS_EEPROM true
|
|
|
|
|
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
|
|
|
|
|
2024-01-19 03:08:55 -07:00
|
|
|
#define HAS_EEPROM true
|
|
|
|
|
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
|
2024-01-19 03:08:55 -07:00
|
|
|
#define CONFIG_UART_BUFFER_SIZE 6144
|
|
|
|
#define CONFIG_QUEUE_SIZE 6144
|
|
|
|
#define CONFIG_QUEUE_MAX_LENGTH 200
|
|
|
|
|
|
|
|
#define EEPROM_SIZE 1024
|
|
|
|
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
|
|
|
|
|
|
|
|
#define GPS_BAUD_RATE 9600
|
|
|
|
#define PIN_GPS_TX 12
|
|
|
|
#define PIN_GPS_RX 34
|
2022-01-25 11:14:16 -07:00
|
|
|
|
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;
|
2022-10-30 11:58:12 -06:00
|
|
|
#define HAS_BLUETOOTH true
|
2023-01-11 04:40:20 -07:00
|
|
|
#define HAS_CONSOLE true
|
2024-01-19 03:08:55 -07:00
|
|
|
#define HAS_EEPROM true
|
2022-01-21 12:43:29 -07:00
|
|
|
#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 11:58:12 -06:00
|
|
|
#define HAS_DISPLAY true
|
2022-10-28 16:53:39 -06:00
|
|
|
#define HAS_PMU true
|
2022-10-30 11:58:12 -06:00
|
|
|
#define HAS_BLUETOOTH true
|
2023-01-11 04:38:28 -07:00
|
|
|
#define HAS_CONSOLE true
|
|
|
|
#define HAS_SD false
|
2024-01-19 03:08:55 -07:00
|
|
|
#define HAS_EEPROM true
|
2022-01-21 12:43:29 -07:00
|
|
|
#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 11:58:12 -06:00
|
|
|
#define HAS_BLUETOOTH true
|
2023-03-13 05:14:53 -06:00
|
|
|
#define HAS_CONSOLE true
|
2024-01-21 04:32:57 -07:00
|
|
|
#define HAS_EEPROM true
|
2023-03-13 05:14:53 -06:00
|
|
|
#elif BOARD_MODEL == BOARD_LORA32_V1_0
|
|
|
|
const int pin_cs = 18;
|
2023-04-01 10:27:21 -06:00
|
|
|
const int pin_reset = 14;
|
2023-03-13 05:14:53 -06:00
|
|
|
const int pin_dio = 26;
|
|
|
|
#if defined(EXTERNAL_LEDS)
|
|
|
|
const int pin_led_rx = 25;
|
|
|
|
const int pin_led_tx = 2;
|
|
|
|
#else
|
|
|
|
const int pin_led_rx = 2;
|
|
|
|
const int pin_led_tx = 2;
|
|
|
|
#endif
|
|
|
|
#define HAS_DISPLAY true
|
|
|
|
#define HAS_BLUETOOTH true
|
2023-01-11 04:40:20 -07:00
|
|
|
#define HAS_CONSOLE true
|
2024-01-21 04:32:57 -07:00
|
|
|
#define HAS_EEPROM true
|
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-10-28 16:53:39 -06:00
|
|
|
#define HAS_DISPLAY true
|
|
|
|
#define HAS_BLUETOOTH true
|
2023-01-11 04:40:20 -07:00
|
|
|
#define HAS_CONSOLE true
|
2024-01-21 04:32:57 -07:00
|
|
|
#define HAS_EEPROM true
|
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;
|
2024-01-18 16:10:24 -07:00
|
|
|
#if HAS_TCXO == true
|
|
|
|
const int pin_tcxo_enable = 33;
|
|
|
|
#endif
|
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-10-28 16:53:39 -06:00
|
|
|
#define HAS_DISPLAY true
|
|
|
|
#define HAS_BLUETOOTH true
|
|
|
|
#define HAS_PMU true
|
2023-01-11 04:40:20 -07:00
|
|
|
#define HAS_CONSOLE true
|
2024-01-21 04:32:57 -07:00
|
|
|
#define HAS_EEPROM true
|
2022-06-16 11:12:28 -06: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
|
2022-10-30 14:15:43 -06:00
|
|
|
#define HAS_DISPLAY true
|
2022-10-30 11:58:12 -06:00
|
|
|
#define HAS_BLUETOOTH true
|
2023-01-11 04:40:20 -07:00
|
|
|
#define HAS_CONSOLE true
|
2024-01-21 04:32:57 -07:00
|
|
|
#define HAS_EEPROM true
|
2022-06-11 08:42:49 -06:00
|
|
|
#elif BOARD_MODEL == BOARD_RNODE_NG_20
|
2022-12-04 12:00:21 -07:00
|
|
|
#define HAS_DISPLAY true
|
|
|
|
#define HAS_BLUETOOTH true
|
|
|
|
#define HAS_NP true
|
2023-01-11 04:40:20 -07:00
|
|
|
#define HAS_CONSOLE true
|
2024-01-21 04:32:57 -07:00
|
|
|
#define HAS_EEPROM true
|
2022-06-11 08:42:49 -06:00
|
|
|
const int pin_cs = 18;
|
|
|
|
const int pin_reset = 12;
|
|
|
|
const int pin_dio = 26;
|
2022-12-04 12:00:21 -07: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 08:42:49 -06:00
|
|
|
#endif
|
2022-12-04 12:00:21 -07:00
|
|
|
#elif BOARD_MODEL == BOARD_RNODE_NG_21
|
2022-10-28 16:53:39 -06:00
|
|
|
#define HAS_DISPLAY true
|
|
|
|
#define HAS_BLUETOOTH true
|
2023-01-06 14:29:23 -07:00
|
|
|
#define HAS_CONSOLE true
|
2022-12-04 12:00:21 -07:00
|
|
|
#define HAS_PMU true
|
|
|
|
#define HAS_NP true
|
2023-01-10 10:12:40 -07:00
|
|
|
#define HAS_SD false
|
2024-01-21 04:32:57 -07:00
|
|
|
#define HAS_EEPROM true
|
2022-06-11 08:42:49 -06:00
|
|
|
const int pin_cs = 18;
|
|
|
|
const int pin_reset = 23;
|
|
|
|
const int pin_dio = 26;
|
2023-01-09 14:27:52 -07: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 12:00:21 -07:00
|
|
|
#if HAS_NP == false
|
|
|
|
#if defined(EXTERNAL_LEDS)
|
2023-01-09 14:27:52 -07:00
|
|
|
const int pin_led_rx = 12;
|
2022-12-04 12:00:21 -07:00
|
|
|
const int pin_led_tx = 4;
|
|
|
|
#else
|
|
|
|
const int pin_led_rx = 25;
|
|
|
|
const int pin_led_tx = 25;
|
|
|
|
#endif
|
2022-06-11 08:42:49 -06:00
|
|
|
#endif
|
2024-02-08 09:53:23 -07:00
|
|
|
#elif BOARD_MODEL == BOARD_RNODE_NG_22
|
|
|
|
#define HAS_DISPLAY true
|
|
|
|
#define HAS_BLUETOOTH false // TODO: Implement
|
|
|
|
#define HAS_CONSOLE false // TODO: Implement
|
|
|
|
#define HAS_PMU true
|
|
|
|
#define HAS_NP true
|
|
|
|
#define HAS_SD false
|
|
|
|
#define HAS_EEPROM true
|
|
|
|
const int pin_cs = 7;
|
|
|
|
const int pin_reset = 8;
|
|
|
|
const int pin_dio = 33;
|
|
|
|
const int pin_np = 38;
|
|
|
|
const int pin_dac = 25;
|
|
|
|
const int pin_adc = 1;
|
|
|
|
const int SD_MISO = 2;
|
|
|
|
const int SD_MOSI = 11;
|
|
|
|
const int SD_CLK = 14;
|
|
|
|
const int SD_CS = 13;
|
|
|
|
#if HAS_NP == false
|
|
|
|
#if defined(EXTERNAL_LEDS)
|
|
|
|
const int pin_led_rx = 37;
|
|
|
|
const int pin_led_tx = 37;
|
|
|
|
#else
|
|
|
|
const int pin_led_rx = 37;
|
|
|
|
const int pin_led_tx = 37;
|
|
|
|
#endif
|
|
|
|
#endif
|
2024-01-19 03:08:55 -07:00
|
|
|
#endif
|
|
|
|
#elif PLATFORM == PLATFORM_NRF52
|
|
|
|
#if BOARD_MODEL == BOARD_RAK4630
|
|
|
|
#define HAS_EEPROM false
|
|
|
|
#define HAS_DISPLAY false // set for debugging
|
|
|
|
#define HAS_BLUETOOTH false
|
|
|
|
#define HAS_CONSOLE false
|
|
|
|
#define HAS_PMU false
|
|
|
|
#define HAS_NP false
|
|
|
|
#define HAS_SD false
|
|
|
|
#define HAS_TCXO true
|
2024-02-09 13:46:39 -07:00
|
|
|
#define HAS_RF_SWITCH_RX_TX true
|
|
|
|
#define HAS_BUSY true
|
2024-01-19 03:08:55 -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+0xED000-EEPROM_RESERVED
|
|
|
|
|
|
|
|
// following pins are for the sx1262
|
2024-02-09 14:05:04 -07:00
|
|
|
const int pin_rxen = 37;
|
2024-01-19 03:08:55 -07:00
|
|
|
const int pin_reset = 38;
|
|
|
|
const int pin_cs = 42;
|
|
|
|
const int pin_sclk = 43;
|
|
|
|
const int pin_mosi = 44;
|
|
|
|
const int pin_miso = 45;
|
2024-01-20 04:47:24 -07:00
|
|
|
const int pin_busy = 46;
|
2024-02-09 14:05:04 -07:00
|
|
|
const int pin_dio = 47;
|
2024-01-19 03:08:55 -07:00
|
|
|
const int pin_led_rx = LED_BLUE;
|
|
|
|
const int pin_led_tx = LED_GREEN;
|
2024-01-21 07:23:28 -07:00
|
|
|
const int pin_tcxo_enable = -1;
|
2024-01-19 03:08:55 -07:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#error An unsupported board was selected. Cannot compile RNode firmware.
|
2021-12-13 17:50:37 -07:00
|
|
|
#endif
|
|
|
|
|
2024-01-19 03:08:55 -07:00
|
|
|
bool mw_radio_online = false;
|
|
|
|
|
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
|
|
|
|
|
2018-06-20 00:45:11 -06:00
|
|
|
#define eeprom_addr(a) (a+EEPROM_OFFSET)
|
|
|
|
|
2024-02-09 13:46:39 -07:00
|
|
|
#ifndef HAS_RF_SWITCH_RX_TX
|
2024-01-20 15:40:28 -07:00
|
|
|
const int pin_rxen = -1;
|
2024-02-09 13:46:39 -07:00
|
|
|
const int pin_txen = -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAS_BUSY
|
2024-01-20 15:40:28 -07:00
|
|
|
const int pin_busy = -1;
|
|
|
|
#endif
|
|
|
|
|
2024-02-09 13:46:39 -07:00
|
|
|
#if (MODEM == SX1262 || MODEM == SX1280) && defined(NRF52840_XXAA)
|
2024-01-19 03:08:55 -07:00
|
|
|
SPIClass spiModem(NRF_SPIM2, pin_miso, pin_sclk, pin_mosi);
|
|
|
|
#endif
|
|
|
|
|
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-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
|
2023-09-17 08:23:35 -06:00
|
|
|
const int lora_rx_turnaround_ms = 66;
|
|
|
|
const int lora_post_tx_yield_slots = 6;
|
|
|
|
uint32_t post_tx_yield_timeout = 0;
|
|
|
|
#define LORA_PREAMBLE_SYMBOLS_HW 4
|
2023-11-02 11:09:29 -06:00
|
|
|
#define LORA_PREAMBLE_SYMBOLS_MIN 18
|
2023-09-17 08:23:35 -06:00
|
|
|
#define LORA_PREAMBLE_TARGET_MS 15
|
|
|
|
#define LORA_CAD_SYMBOLS 3
|
|
|
|
int csma_slot_ms = 50;
|
|
|
|
float csma_p_min = 0.1;
|
|
|
|
float csma_p_max = 0.8;
|
|
|
|
uint8_t csma_p = 0;
|
|
|
|
|
2023-09-14 05:00:40 -06:00
|
|
|
int lora_sf = 0;
|
|
|
|
int lora_cr = 5;
|
|
|
|
int lora_txp = 0xFF;
|
|
|
|
uint32_t lora_bw = 0;
|
|
|
|
uint32_t lora_freq = 0;
|
|
|
|
uint32_t lora_bitrate = 0;
|
|
|
|
long lora_preamble_symbols = 6;
|
|
|
|
float lora_symbol_time_ms = 0.0;
|
|
|
|
float lora_symbol_rate = 0.0;
|
|
|
|
float lora_us_per_byte = 0.0;
|
2018-04-05 10:10:42 -06:00
|
|
|
|
|
|
|
// Operational variables
|
2021-03-12 10:48:50 -07:00
|
|
|
bool radio_locked = true;
|
|
|
|
bool radio_online = false;
|
2023-09-14 14:32:26 -06:00
|
|
|
bool community_fw = true;
|
2021-03-12 10:48:50 -07:00
|
|
|
bool hw_ready = false;
|
2023-09-14 14:32:26 -06:00
|
|
|
bool radio_error = false;
|
|
|
|
bool disp_ready = false;
|
|
|
|
bool pmu_ready = false;
|
2021-03-12 10:48:50 -07:00
|
|
|
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
|
|
|
|
2022-10-28 16:53:39 -06:00
|
|
|
int current_rssi = -292;
|
2018-06-27 06:08:16 -06:00
|
|
|
int last_rssi = -292;
|
|
|
|
uint8_t last_rssi_raw = 0x00;
|
2022-10-28 16:53:39 -06:00
|
|
|
uint8_t last_snr_raw = 0x80;
|
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
|
2022-11-01 14:11:41 -06:00
|
|
|
uint8_t cmdbuf[CMD_L];
|
2018-04-05 10:10:42 -06:00
|
|
|
|
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;
|
|
|
|
|
2023-09-12 06:48:47 -06:00
|
|
|
#define STATUS_INTERVAL_MS 3
|
2024-01-19 03:08:55 -07:00
|
|
|
#if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
|
2023-09-12 06:48:47 -06:00
|
|
|
#define DCD_SAMPLES 2500
|
|
|
|
#define UTIL_UPDATE_INTERVAL_MS 1000
|
|
|
|
#define UTIL_UPDATE_INTERVAL (UTIL_UPDATE_INTERVAL_MS/STATUS_INTERVAL_MS)
|
|
|
|
#define AIRTIME_LONGTERM 3600
|
|
|
|
#define AIRTIME_LONGTERM_MS (AIRTIME_LONGTERM*1000)
|
|
|
|
#define AIRTIME_BINLEN_MS (STATUS_INTERVAL_MS*DCD_SAMPLES)
|
|
|
|
#define AIRTIME_BINS ((AIRTIME_LONGTERM*1000)/AIRTIME_BINLEN_MS)
|
|
|
|
bool util_samples[DCD_SAMPLES];
|
|
|
|
uint16_t airtime_bins[AIRTIME_BINS];
|
2023-09-12 13:51:51 -06:00
|
|
|
float longterm_bins[AIRTIME_BINS];
|
2023-09-12 06:48:47 -06:00
|
|
|
int dcd_sample = 0;
|
|
|
|
float local_channel_util = 0.0;
|
|
|
|
float total_channel_util = 0.0;
|
2023-09-12 13:51:51 -06:00
|
|
|
float longterm_channel_util = 0.0;
|
2023-09-12 06:48:47 -06:00
|
|
|
float airtime = 0.0;
|
|
|
|
float longterm_airtime = 0.0;
|
|
|
|
#define current_airtime_bin(void) (millis()%AIRTIME_LONGTERM_MS)/AIRTIME_BINLEN_MS
|
|
|
|
#endif
|
2023-09-13 12:05:05 -06:00
|
|
|
float st_airtime_limit = 0.0;
|
|
|
|
float lt_airtime_limit = 0.0;
|
|
|
|
bool airtime_lock = false;
|
2023-09-12 06:48:47 -06:00
|
|
|
|
2023-09-17 08:23:35 -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;
|
|
|
|
long dcd_wait_until = 0;
|
|
|
|
uint16_t dcd_count = 0;
|
|
|
|
uint16_t dcd_threshold = 2;
|
2018-04-26 07:52:43 -06:00
|
|
|
|
2023-09-12 06:48:47 -06:00
|
|
|
uint32_t status_interval_ms = STATUS_INTERVAL_MS;
|
2018-04-26 07:52:43 -06:00
|
|
|
uint32_t last_status_update = 0;
|
2023-09-17 08:23:35 -06:00
|
|
|
uint32_t last_dcd = 0;
|
2018-04-26 07:52:43 -06:00
|
|
|
|
|
|
|
// Status flags
|
|
|
|
const uint8_t SIG_DETECT = 0x01;
|
|
|
|
const uint8_t SIG_SYNCED = 0x02;
|
|
|
|
const uint8_t RX_ONGOING = 0x04;
|
|
|
|
|
2022-10-28 16:53:39 -06:00
|
|
|
// Power management
|
|
|
|
#define BATTERY_STATE_DISCHARGING 0x01
|
|
|
|
#define BATTERY_STATE_CHARGING 0x02
|
|
|
|
#define BATTERY_STATE_CHARGED 0x03
|
2022-10-30 15:27:30 -06:00
|
|
|
bool battery_installed = false;
|
2022-12-16 11:59:30 -07:00
|
|
|
bool battery_indeterminate = false;
|
2022-10-30 15:27:30 -06:00
|
|
|
bool external_power = false;
|
2022-12-16 11:59:30 -07:00
|
|
|
bool battery_ready = false;
|
2022-10-28 16:53:39 -06:00
|
|
|
float battery_voltage = 0.0;
|
|
|
|
float battery_percent = 0.0;
|
|
|
|
uint8_t battery_state = 0x00;
|
2022-11-01 14:11:41 -06:00
|
|
|
uint8_t display_intensity = 0xFF;
|
2023-09-19 10:32:29 -06:00
|
|
|
uint8_t display_addr = 0xFF;
|
2023-09-14 14:32:26 -06:00
|
|
|
bool display_diagnostics = true;
|
2022-11-01 14:11:41 -06:00
|
|
|
bool device_init_done = false;
|
2022-11-02 17:58:45 -06:00
|
|
|
bool eeprom_ok = false;
|
|
|
|
bool firmware_update_mode = false;
|
2022-10-28 16:53:39 -06:00
|
|
|
|
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
|