diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..caf3250 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,11 @@ +blank_issues_enabled: false +contact_links: + - name: ✨ Feature Request or Idea + url: https://github.com/markqvist/Reticulum/discussions/new?category=ideas + about: Propose and discuss features and ideas + - name: 💬 Questions, Help & Discussion + about: Ask anything, or get help + url: https://github.com/markqvist/Reticulum/discussions/new/choose + - name: 📖 Read the Reticulum Manual + url: https://markqvist.github.io/Reticulum/manual/ + about: The complete documentation for Reticulum diff --git a/.github/ISSUE_TEMPLATE/🐛-bug-report.md b/.github/ISSUE_TEMPLATE/🐛-bug-report.md new file mode 100644 index 0000000..77ad6c2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/🐛-bug-report.md @@ -0,0 +1,35 @@ +--- +name: "\U0001F41B Bug Report" +about: Report a reproducible bug +title: '' +labels: '' +assignees: '' + +--- + +**Read the Contribution Guidelines** +Before creating a bug report on this issue tracker, you **must** read the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md). Issues that do not follow the contribution guidelines **will be deleted without comment**. + +- The issue tracker is used by developers of this project. **Do not use it to ask general questions, or for support requests**. +- Ideas and feature requests can be made on the [Discussions](https://github.com/markqvist/Reticulum/discussions). **Only** feature requests accepted by maintainers and developers are tracked and included on the issue tracker. **Do not post feature requests here**. +- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), delete this section from your bug report. + +**Describe the Bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Describe in detail how to reproduce the bug. + +**Expected Behavior** +A clear and concise description of what you expected to happen. + +**Logs & Screenshots** +Please include any relevant log output. If applicable, also add screenshots to help explain your problem. + +**System Information** +- OS and version +- Python version +- Program version + +**Additional context** +Add any other context about the problem here. diff --git a/Bluetooth.h b/Bluetooth.h index 28264f1..869f6fb 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -14,21 +14,30 @@ // along with this program. If not, see . #if MCU_VARIANT == MCU_ESP32 -#include "BluetoothSerial.h" -#include "esp_bt_main.h" -#include "esp_bt_device.h" + #elif MCU_VARIANT == MCU_NRF52 -#include -#include #endif #if MCU_VARIANT == MCU_ESP32 -BluetoothSerial SerialBT; + #if HAS_BLUETOOTH == true + #include "BluetoothSerial.h" + #include "esp_bt_main.h" + #include "esp_bt_device.h" + BluetoothSerial SerialBT; + #elif HAS_BLE == true + #include "esp_bt_main.h" + #include "esp_bt_device.h" + // TODO: Remove + #define SerialBT Serial + #endif + #elif MCU_VARIANT == MCU_NRF52 -BLEUart SerialBT; -BLEDis bledis; -BLEBas blebas; + #include + #include + BLEUart SerialBT; + BLEDis bledis; + BLEBas blebas; #endif #define BT_PAIRING_TIMEOUT 35000 @@ -42,114 +51,201 @@ char bt_dh[BT_DEV_HASH_LEN]; char bt_devname[11]; #if MCU_VARIANT == MCU_ESP32 + #if HAS_BLUETOOTH == true - void bt_confirm_pairing(uint32_t numVal) { - bt_ssp_pin = numVal; - kiss_indicate_btpin(); - if (bt_allow_pairing) { - SerialBT.confirmReply(true); - } else { - SerialBT.confirmReply(false); - } - } - - void bt_stop() { - if (bt_state != BT_STATE_OFF) { - SerialBT.end(); - bt_allow_pairing = false; - bt_state = BT_STATE_OFF; - } - } - - void bt_start() { - if (bt_state == BT_STATE_OFF) { - SerialBT.begin(bt_devname); - bt_state = BT_STATE_ON; - } - } - - void bt_enable_pairing() { - if (bt_state == BT_STATE_OFF) bt_start(); - bt_allow_pairing = true; - bt_pairing_started = millis(); - bt_state = BT_STATE_PAIRING; - } - - void bt_disable_pairing() { - bt_allow_pairing = false; - bt_ssp_pin = 0; - bt_state = BT_STATE_ON; - } - - void bt_pairing_complete(boolean success) { - if (success) { - bt_disable_pairing(); - } else { - bt_ssp_pin = 0; - } - } - - void bt_connection_callback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){ - if(event == ESP_SPP_SRV_OPEN_EVT) { - bt_state = BT_STATE_CONNECTED; - cable_state = CABLE_STATE_DISCONNECTED; - } - - if(event == ESP_SPP_CLOSE_EVT ){ - bt_state = BT_STATE_ON; - } - } - - bool bt_setup_hw() { - if (!bt_ready) { - if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) { - bt_enabled = true; + void bt_confirm_pairing(uint32_t numVal) { + bt_ssp_pin = numVal; + kiss_indicate_btpin(); + if (bt_allow_pairing) { + SerialBT.confirmReply(true); } else { - bt_enabled = false; + SerialBT.confirmReply(false); } - if (btStart()) { - if (esp_bluedroid_init() == ESP_OK) { - if (esp_bluedroid_enable() == ESP_OK) { - const uint8_t* bda_ptr = esp_bt_dev_get_address(); - char *data = (char*)malloc(BT_DEV_ADDR_LEN+1); - for (int i = 0; i < BT_DEV_ADDR_LEN; i++) { - data[i] = bda_ptr[i]; - } - data[BT_DEV_ADDR_LEN] = EEPROM.read(eeprom_addr(ADDR_SIGNATURE)); - unsigned char *hash = MD5::make_hash(data, BT_DEV_ADDR_LEN); - memcpy(bt_dh, hash, BT_DEV_HASH_LEN); - sprintf(bt_devname, "RNode %02X%02X", bt_dh[14], bt_dh[15]); - free(data); + } - SerialBT.enableSSP(); - SerialBT.onConfirmRequest(bt_confirm_pairing); - SerialBT.onAuthComplete(bt_pairing_complete); - SerialBT.register_callback(bt_connection_callback); - - bt_ready = true; - return true; + void bt_stop() { + if (bt_state != BT_STATE_OFF) { + SerialBT.end(); + bt_allow_pairing = false; + bt_state = BT_STATE_OFF; + } + } + void bt_start() { + if (bt_state == BT_STATE_OFF) { + SerialBT.begin(bt_devname); + bt_state = BT_STATE_ON; + } + } + + void bt_enable_pairing() { + if (bt_state == BT_STATE_OFF) bt_start(); + bt_allow_pairing = true; + bt_pairing_started = millis(); + bt_state = BT_STATE_PAIRING; + } + + void bt_disable_pairing() { + bt_allow_pairing = false; + bt_ssp_pin = 0; + bt_state = BT_STATE_ON; + } + + void bt_pairing_complete(boolean success) { + if (success) { + bt_disable_pairing(); + } else { + bt_ssp_pin = 0; + } + } + + void bt_connection_callback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){ + if(event == ESP_SPP_SRV_OPEN_EVT) { + bt_state = BT_STATE_CONNECTED; + cable_state = CABLE_STATE_DISCONNECTED; + } + + if(event == ESP_SPP_CLOSE_EVT ){ + bt_state = BT_STATE_ON; + } + } + + bool bt_setup_hw() { + if (!bt_ready) { + if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) { + bt_enabled = true; + } else { + bt_enabled = false; + } + if (btStart()) { + if (esp_bluedroid_init() == ESP_OK) { + if (esp_bluedroid_enable() == ESP_OK) { + const uint8_t* bda_ptr = esp_bt_dev_get_address(); + char *data = (char*)malloc(BT_DEV_ADDR_LEN+1); + for (int i = 0; i < BT_DEV_ADDR_LEN; i++) { + data[i] = bda_ptr[i]; + } + data[BT_DEV_ADDR_LEN] = EEPROM.read(eeprom_addr(ADDR_SIGNATURE)); + unsigned char *hash = MD5::make_hash(data, BT_DEV_ADDR_LEN); + memcpy(bt_dh, hash, BT_DEV_HASH_LEN); + sprintf(bt_devname, "RNode %02X%02X", bt_dh[14], bt_dh[15]); + free(data); + + SerialBT.enableSSP(); + SerialBT.onConfirmRequest(bt_confirm_pairing); + SerialBT.onAuthComplete(bt_pairing_complete); + SerialBT.register_callback(bt_connection_callback); + + bt_ready = true; + return true; + + } else { return false; } } else { return false; } } else { return false; } } else { return false; } - } else { return false; } - } - - bool bt_init() { - bt_state = BT_STATE_OFF; - if (bt_setup_hw()) { - if (bt_enabled && !console_active) bt_start(); - return true; - } else { - return false; - } - } - - void update_bt() { - if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) { - bt_disable_pairing(); } - } + + bool bt_init() { + bt_state = BT_STATE_OFF; + if (bt_setup_hw()) { + if (bt_enabled && !console_active) bt_start(); + return true; + } else { + return false; + } + } + + void update_bt() { + if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) { + bt_disable_pairing(); + } + } + + #elif HAS_BLE == true + void bt_stop() { + if (bt_state != BT_STATE_OFF) { + bt_allow_pairing = false; + bt_state = BT_STATE_OFF; + } + } + + void bt_disable_pairing() { + bt_allow_pairing = false; + bt_ssp_pin = 0; + bt_state = BT_STATE_ON; + } + + void bt_connect_callback(uint16_t conn_handle) { + bt_state = BT_STATE_CONNECTED; + cable_state = CABLE_STATE_DISCONNECTED; + } + + void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) { + bt_state = BT_STATE_ON; + } + + bool bt_setup_hw() { + if (!bt_ready) { + if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) { + bt_enabled = true; + } else { + bt_enabled = false; + } + if (btStart()) { + if (esp_bluedroid_init() == ESP_OK) { + if (esp_bluedroid_enable() == ESP_OK) { + const uint8_t* bda_ptr = esp_bt_dev_get_address(); + char *data = (char*)malloc(BT_DEV_ADDR_LEN+1); + for (int i = 0; i < BT_DEV_ADDR_LEN; i++) { + data[i] = bda_ptr[i]; + } + data[BT_DEV_ADDR_LEN] = EEPROM.read(eeprom_addr(ADDR_SIGNATURE)); + unsigned char *hash = MD5::make_hash(data, BT_DEV_ADDR_LEN); + memcpy(bt_dh, hash, BT_DEV_HASH_LEN); + sprintf(bt_devname, "RNode %02X%02X", bt_dh[14], bt_dh[15]); + free(data); + + // TODO: Implement GAP & GATT for RNode comms over BLE + + bt_ready = true; + return true; + + } else { return false; } + } else { return false; } + } else { return false; } + } else { return false; } + } + + void bt_start() { + if (bt_state == BT_STATE_OFF) { + bt_state = BT_STATE_ON; + // TODO: Implement + } + } + + bool bt_init() { + bt_state = BT_STATE_OFF; + if (bt_setup_hw()) { + if (bt_enabled && !console_active) bt_start(); + return true; + } else { + return false; + } + } + + void bt_enable_pairing() { + if (bt_state == BT_STATE_OFF) bt_start(); + bt_allow_pairing = true; + bt_pairing_started = millis(); + bt_state = BT_STATE_PAIRING; + } + + void update_bt() { + if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) { + bt_disable_pairing(); + } + } + #endif #elif MCU_VARIANT == MCU_NRF52 uint8_t eeprom_read(uint32_t mapped_addr); @@ -243,8 +339,8 @@ bool bt_setup_hw() { void bt_start() { if (bt_state == BT_STATE_OFF) { Bluefruit.setName(bt_devname); - bledis.setManufacturer("Adafruit Industries"); - bledis.setModel("Bluefruit Feather52"); + bledis.setManufacturer(BLE_MANUFACTURER); + bledis.setModel(BLE_MODEL); // start device information service bledis.begin(); diff --git a/Boards.h b/Boards.h index 22dbb99..99c3454 100644 --- a/Boards.h +++ b/Boards.h @@ -18,14 +18,14 @@ #ifndef BOARDS_H #define BOARDS_H - #define PLATFORM_AVR 0x90 - #define PLATFORM_ESP32 0x80 - #define PLATFORM_NRF52 0x70 + #define PLATFORM_AVR 0x90 + #define PLATFORM_ESP32 0x80 + #define PLATFORM_NRF52 0x70 - #define MCU_1284P 0x91 - #define MCU_2560 0x92 - #define MCU_ESP32 0x81 - #define MCU_NRF52 0x71 + #define MCU_1284P 0x91 + #define MCU_2560 0x92 + #define MCU_ESP32 0x81 + #define MCU_NRF52 0x71 #define BOARD_RNODE 0x31 #define BOARD_HMBRW 0x32 @@ -36,6 +36,7 @@ #define BOARD_LORA32_V2_1 0x37 #define BOARD_LORA32_V1_0 0x39 #define BOARD_HELTEC32_V2 0x38 + #define BOARD_HELTEC32_V3 0x3A #define BOARD_RNODE_NG_20 0x40 #define BOARD_RNODE_NG_21 0x41 #define BOARD_RNODE_NG_22 0x42 @@ -75,10 +76,14 @@ #define HAS_DISPLAY false #define HAS_BLUETOOTH false + #define HAS_BLE false #define HAS_TCXO false #define HAS_PMU false #define HAS_NP false #define HAS_EEPROM false + #define HAS_INPUT false + #define HAS_SLEEP false + #define VALIDATE_FIRMWARE true #if defined(ENABLE_TCXO) #define HAS_TCXO true @@ -148,6 +153,7 @@ #define DISPLAY OLED #define HAS_PMU true #define HAS_BLUETOOTH true + #define HAS_BLE true #define HAS_CONSOLE true #define HAS_SD false #define HAS_EEPROM true @@ -184,6 +190,7 @@ #define HAS_DISPLAY true #define DISPLAY OLED #define HAS_BLUETOOTH true + #define HAS_BLE true #define HAS_CONSOLE true #define HAS_EEPROM true const int pin_cs = 18; @@ -201,6 +208,7 @@ #define HAS_DISPLAY true #define DISPLAY OLED #define HAS_BLUETOOTH true + #define HAS_BLE true #define HAS_CONSOLE true #define HAS_EEPROM true const int pin_cs = 18; @@ -218,6 +226,7 @@ #define HAS_DISPLAY true #define DISPLAY OLED #define HAS_BLUETOOTH true + #define HAS_BLE true #define HAS_PMU true #define HAS_CONSOLE true #define HAS_EEPROM true @@ -242,7 +251,7 @@ #define HAS_CONSOLE true #define HAS_EEPROM true const int pin_cs = 18; - const int pin_reset = 23; + const int pin_reset = 14; const int pin_dio = 26; #if defined(EXTERNAL_LEDS) const int pin_led_rx = 36; @@ -252,6 +261,43 @@ const int pin_led_tx = 25; #endif + #elif BOARD_MODEL == BOARD_HELTEC32_V3 + #define IS_ESP32S3 true + #define HAS_DISPLAY true + #define HAS_BLUETOOTH false + #define HAS_BLE true + #define HAS_CONSOLE false + #define HAS_EEPROM true + #define HAS_INPUT true + #define HAS_SLEEP true + #define PIN_WAKEUP GPIO_NUM_0 + #define WAKEUP_LEVEL 0 + + const int pin_btn_usr1 = 0; + + #if defined(EXTERNAL_LEDS) + const int pin_led_rx = 13; + const int pin_led_tx = 14; + #else + const int pin_led_rx = 35; + const int pin_led_tx = 35; + #endif + + #define MODEM SX1262 + #define HAS_TCXO true + const int pin_tcxo_enable = -1; + #define HAS_BUSY true + #define DIO2_AS_RF_SWITCH true + + // Following pins are for the SX1262 + const int pin_cs = 8; + const int pin_busy = 13; + const int pin_dio = 14; + const int pin_reset = 12; + const int pin_mosi = 10; + const int pin_miso = 11; + const int pin_sclk = 9; + #elif BOARD_MODEL == BOARD_RNODE_NG_20 #define HAS_DISPLAY true #define DISPLAY OLED @@ -311,14 +357,20 @@ #define HAS_DISPLAY true #define DISPLAY OLED + #define HAS_CONSOLE false + #define HAS_BLUETOOTH false #define HAS_BLE true - #define HAS_BLUETOOTH false // TODO: Implement - #define HAS_CONSOLE false // TODO: Implement #define HAS_PMU true #define HAS_NP false #define HAS_SD false #define HAS_EEPROM true + // #define HAS_INPUT true + // #define HAS_SLEEP true + // #define PIN_WAKEUP GPIO_NUM_0 + // #define WAKEUP_LEVEL 0 + // const int pin_btn_usr1 = 0; + const int pin_cs = 7; const int pin_reset = 8; const int pin_sclk = 5; @@ -360,7 +412,8 @@ #define DISP_DC WB_IO1 #define DISP_RESET -1 #define DISP_BUSY WB_IO4 - #define HAS_BLUETOOTH true + #define HAS_BLUETOOTH false + #define HAS_BLE true #define HAS_CONSOLE false #define HAS_PMU true #define HAS_NP false @@ -373,8 +426,10 @@ #define CONFIG_QUEUE_MAX_LENGTH 200 #define EEPROM_SIZE 200 #define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED + #define BLE_MANUFACTURER "RAK Wireless" + #define BLE_MODEL "RAK4640" - // following pins are for the sx1262 + // Following pins are for the sx1262 const int pin_rxen = 37; const int pin_reset = 38; const int pin_cs = 42; diff --git a/Config.h b/Config.h index b411c44..cc3cc7d 100644 --- a/Config.h +++ b/Config.h @@ -20,7 +20,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x46 + #define MIN_VERS 0x47 #define MODE_HOST 0x11 #define MODE_TNC 0x12 diff --git a/Console/build.py b/Console/build.py index 4b20f6f..72fa515 100644 --- a/Console/build.py +++ b/Console/build.py @@ -4,9 +4,9 @@ import sys import shutil packages = { - "rns": "rns-0.7.1-py3-none-any.whl", - "nomadnet": "nomadnet-0.4.6-py3-none-any.whl", - "lxmf": "lxmf-0.3.9-py3-none-any.whl", + "rns": "rns-0.7.3-py3-none-any.whl", + "nomadnet": "nomadnet-0.4.8-py3-none-any.whl", + "lxmf": "lxmf-0.4.3-py3-none-any.whl", "rnsh": "rnsh-0.1.3-py3-none-any.whl", } diff --git a/Device.h b/Device.h index 5b77055..e354847 100644 --- a/Device.h +++ b/Device.h @@ -22,7 +22,6 @@ #include "esp_partition.h" #endif - // Forward declaration from Utilities.h void eeprom_update(int mapped_addr, uint8_t byte); uint8_t eeprom_read(uint32_t addr); @@ -129,12 +128,14 @@ void device_validate_partitions() { partition.type = ESP_PARTITION_TYPE_APP; esp_partition_get_sha256(&partition, dev_bootloader_hash); esp_partition_get_sha256(esp_ota_get_running_partition(), dev_firmware_hash); - for (uint8_t i = 0; i < DEV_HASH_LEN; i++) { - if (dev_firmware_hash_target[i] != dev_firmware_hash[i]) { - fw_signature_validated = false; - break; + #if VALIDATE_FIRMWARE + for (uint8_t i = 0; i < DEV_HASH_LEN; i++) { + if (dev_firmware_hash_target[i] != dev_firmware_hash[i]) { + fw_signature_validated = false; + break; + } } - } + #endif } #endif @@ -151,7 +152,7 @@ bool device_init() { mbedtls_md_init(&ctx); mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(md_type), 0); mbedtls_md_starts(&ctx); - #if HAS_BLUETOOTH == true + #if HAS_BLUETOOTH == true || HAS_BLE == true mbedtls_md_update(&ctx, dev_bt_mac, BT_DEV_ADDR_LEN); #else // TODO: Get from BLE stack instead diff --git a/Display.h b/Display.h index 6505695..3eecc5b 100644 --- a/Display.h +++ b/Display.h @@ -48,7 +48,11 @@ #define DISP_ADDR 0x3C #define SCL_OLED 15 #define SDA_OLED 4 - #endif +#elif BOARD_MODEL == BOARD_HELTEC32_V3 + #define DISP_RST 21 + #define DISP_ADDR 0x3C + #define SCL_OLED 18 + #define SDA_OLED 17 #elif BOARD_MODEL == BOARD_RNODE_NG_21 #if BOARD_TYPE == OLED #define DISP_RST -1 @@ -172,6 +176,18 @@ bool display_init() { Wire.begin(SDA_OLED, SCL_OLED); #elif BOARD_MODEL == BOARD_HELTEC32_V2 Wire.begin(SDA_OLED, SCL_OLED); + #elif BOARD_MODEL == BOARD_HELTEC32_V3 + // enable vext / pin 36 + pinMode(Vext, OUTPUT); + digitalWrite(Vext, LOW); + delay(50); + int pin_display_en = 21; + pinMode(pin_display_en, OUTPUT); + digitalWrite(pin_display_en, LOW); + delay(50); + digitalWrite(pin_display_en, HIGH); + delay(50); + Wire.begin(SDA_OLED, SCL_OLED); #elif BOARD_MODEL == BOARD_LORA32_V1_0 int pin_display_en = 16; digitalWrite(pin_display_en, LOW); @@ -238,7 +254,12 @@ bool display_init() { #elif DISPLAY == EINK_BW disp_mode = DISP_MODE_PORTRAIT; #endif - // add more eink compatible boards here + #elif BOARD_MODEL == BOARD_HELTEC32_V3 + disp_mode = DISP_MODE_PORTRAIT; + // Antenna conx up + display.setRotation(1); + // USB-C up + // display.setRotation(3); #else disp_mode = DISP_MODE_PORTRAIT; display.setRotation(3); diff --git a/Input.h b/Input.h new file mode 100644 index 0000000..996a09c --- /dev/null +++ b/Input.h @@ -0,0 +1,95 @@ +// Copyright (C) 2024, 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 . + +#ifndef INPUT_H + #define INPUT_H + + #define PIN_BUTTON pin_btn_usr1 + + #define PRESSED LOW + #define RELEASED HIGH + + #define EVENT_ALL 0x00 + #define EVENT_CLICKS 0x01 + #define EVENT_BUTTON_DOWN 0x11 + #define EVENT_BUTTON_UP 0x12 + #define EVENT_BUTTON_CLICK 0x13 + #define EVENT_BUTTON_DOUBLE_CLICK 0x14 + #define EVENT_BUTTON_TRIPLE_CLICK 0x15 + + int button_events = EVENT_CLICKS; + int button_state = RELEASED; + int debounce_state = button_state; + unsigned long button_debounce_last = 0; + unsigned long button_debounce_delay = 25; + unsigned long button_down_last = 0; + unsigned long button_up_last = 0; + + // Forward declaration + void button_event(uint8_t event, unsigned long duration); + + void input_init() { + pinMode(PIN_BUTTON, INPUT_PULLUP); + } + + void input_get_all_events() { + button_events = EVENT_ALL; + } + + void input_get_click_events() { + button_events = EVENT_CLICKS; + } + + void input_read() { + int button_reading = digitalRead(PIN_BUTTON); + if (button_reading != debounce_state) { + button_debounce_last = millis(); + debounce_state = button_reading; + } + + if ((millis() - button_debounce_last) > button_debounce_delay) { + if (button_reading != button_state) { + // State changed + int previous_state = button_state; + button_state = button_reading; + + if (button_events == EVENT_ALL) { + if (button_state == PRESSED) { + button_event(EVENT_BUTTON_DOWN, 0); + } else if (button_state == RELEASED) { + button_event(EVENT_BUTTON_UP, 0); + } + } else if (button_events == EVENT_CLICKS) { + if (previous_state == PRESSED && button_state == RELEASED) { + button_up_last = millis(); + button_event(EVENT_BUTTON_CLICK, button_up_last-button_down_last); + } else if (previous_state == RELEASED && button_state == PRESSED) { + button_down_last = millis(); + } + } + } + } + + } + + bool button_pressed() { + if (button_state == PRESSED) { + return true; + } else { + return false; + } + } + +#endif \ No newline at end of file diff --git a/Makefile b/Makefile index 27068dc..6f893a3 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +ESP_IDF_VER = 2.0.15 + all: release clean: @@ -93,6 +95,9 @@ firmware-heltec32_v2: firmware-heltec32_v2_extled: arduino-cli compile --fqbn esp32:esp32:heltec_wifi_lora_32_V2 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x38\" \"-DEXTERNAL_LEDS=true\"" +firmware-heltec32_v3: + arduino-cli compile --fqbn esp32:esp32:heltec_wifi_lora_32_V3 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3A\"" + firmware-rnode_ng_20: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x40\"" @@ -143,11 +148,18 @@ upload-lora32_v21: python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-heltec32_v2: - arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:heltec_wifi_lora_32_V2 + arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:heltec_wifi_lora_32_V2 @sleep 1 - rnodeconf /dev/ttyUSB0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bin) + rnodeconf /dev/ttyUSB1 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bin) @sleep 3 - python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin + +upload-heltec32_v3: + arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:heltec_wifi_lora_32_V3 + @sleep 1 + rnodeconf /dev/ttyUSB1 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bin) + @sleep 3 + python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin upload-rnode_ng_20: arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:ttgo-lora32 @@ -184,7 +196,7 @@ upload-rak4630: release: release-all -release-all: console-site spiffs-image release-rnode release-tbeam release-tbeam_sx1262 release-lora32_v10 release-lora32_v20 release-lora32_v21 release-lora32_v10_extled release-lora32_v20_extled release-lora32_v21_extled release-lora32_v21_tcxo release-featheresp32 release-genericesp32 release-heltec32_v2 release-heltec32_v2_extled release-rnode_ng_20 release-rnode_ng_21 release-t3s3 release-hashes +release-all: console-site spiffs-image release-rnode release-tbeam release-tbeam_sx1262 release-lora32_v10 release-lora32_v20 release-lora32_v21 release-lora32_v10_extled release-lora32_v20_extled release-lora32_v21_extled release-lora32_v21_tcxo release-featheresp32 release-genericesp32 release-heltec32_v2 release-heltec32_v3 release-heltec32_v2_extled release-rnode_ng_20 release-rnode_ng_21 release-t3s3 release-hashes release-hashes: python ./release_hashes.py > ./Release/release.json @@ -196,7 +208,7 @@ release-rnode: release-tbeam: arduino-cli compile --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam.boot_app0 cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bin build/rnode_firmware_tbeam.bin cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_tbeam.bootloader cp build/esp32.esp32.t-beam/RNode_Firmware.ino.partitions.bin build/rnode_firmware_tbeam.partitions @@ -205,7 +217,7 @@ release-tbeam: release-tbeam_sx1262: arduino-cli compile --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\" \"-DMODEM=0x03\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam_sx1262.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam_sx1262.boot_app0 cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bin build/rnode_firmware_tbeam_sx1262.bin cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_tbeam_sx1262.bootloader cp build/esp32.esp32.t-beam/RNode_Firmware.ino.partitions.bin build/rnode_firmware_tbeam_sx1262.partitions @@ -214,7 +226,7 @@ release-tbeam_sx1262: release-lora32_v10: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x39\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v10.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v10.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_lora32v10.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_lora32v10.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_lora32v10.partitions @@ -223,7 +235,7 @@ release-lora32_v10: release-lora32_v20: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x36\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v20.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v20.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_lora32v20.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_lora32v20.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_lora32v20.partitions @@ -232,7 +244,7 @@ release-lora32_v20: release-lora32_v21: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x37\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v21.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v21.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_lora32v21.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_lora32v21.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_lora32v21.partitions @@ -241,7 +253,7 @@ release-lora32_v21: release-lora32_v10_extled: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x39\" \"-DEXTERNAL_LEDS=true\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v10.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v10.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_lora32v10.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_lora32v10.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_lora32v10.partitions @@ -250,7 +262,7 @@ release-lora32_v10_extled: release-lora32_v20_extled: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x36\" \"-DEXTERNAL_LEDS=true\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v20.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v20.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_lora32v20.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_lora32v20.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_lora32v20.partitions @@ -259,7 +271,7 @@ release-lora32_v20_extled: release-lora32_v21_extled: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x37\" \"-DEXTERNAL_LEDS=true\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v21.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v21.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_lora32v21.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_lora32v21.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_lora32v21.partitions @@ -268,7 +280,7 @@ release-lora32_v21_extled: release-lora32_v21_tcxo: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x37\" \"-DENABLE_TCXO=true\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v21_tcxo.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_lora32v21_tcxo.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_lora32v21_tcxo.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_lora32v21_tcxo.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_lora32v21_tcxo.partitions @@ -277,16 +289,25 @@ release-lora32_v21_tcxo: release-heltec32_v2: arduino-cli compile --fqbn esp32:esp32:heltec_wifi_lora_32_V2 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x38\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_heltec32v2.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_heltec32v2.boot_app0 cp build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bin build/rnode_firmware_heltec32v2.bin cp build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_heltec32v2.bootloader cp build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.partitions.bin build/rnode_firmware_heltec32v2.partitions zip --junk-paths ./Release/rnode_firmware_heltec32v2.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_heltec32v2.boot_app0 build/rnode_firmware_heltec32v2.bin build/rnode_firmware_heltec32v2.bootloader build/rnode_firmware_heltec32v2.partitions rm -r build +release-heltec32_v3: + arduino-cli compile --fqbn esp32:esp32:heltec_wifi_lora_32_V3 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3A\"" + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_heltec32v3.boot_app0 + cp build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bin build/rnode_firmware_heltec32v3.bin + cp build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_heltec32v3.bootloader + cp build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_heltec32v3.partitions + zip --junk-paths ./Release/rnode_firmware_heltec32v3.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_heltec32v3.boot_app0 build/rnode_firmware_heltec32v3.bin build/rnode_firmware_heltec32v3.bootloader build/rnode_firmware_heltec32v3.partitions + rm -r build + release-heltec32_v2_extled: arduino-cli compile --fqbn esp32:esp32:heltec_wifi_lora_32_V2 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x38\" \"-DEXTERNAL_LEDS=true\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_heltec32v2.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_heltec32v2.boot_app0 cp build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bin build/rnode_firmware_heltec32v2.bin cp build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_heltec32v2.bootloader cp build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.partitions.bin build/rnode_firmware_heltec32v2.partitions @@ -295,7 +316,7 @@ release-heltec32_v2_extled: release-rnode_ng_20: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x40\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_ng20.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_ng20.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_ng20.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_ng20.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_ng20.partitions @@ -304,7 +325,7 @@ release-rnode_ng_20: release-rnode_ng_21: arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x41\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_ng21.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_ng21.boot_app0 cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bin build/rnode_firmware_ng21.bin cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_ng21.bootloader cp build/esp32.esp32.ttgo-lora32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_ng21.partitions @@ -313,7 +334,7 @@ release-rnode_ng_21: release-t3s3: arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_t3s3.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_t3s3.boot_app0 cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_t3s3.bin cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_t3s3.bootloader cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_t3s3.partitions @@ -322,7 +343,7 @@ release-t3s3: release-featheresp32: arduino-cli compile --fqbn esp32:esp32:featheresp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_featheresp32.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_featheresp32.boot_app0 cp build/esp32.esp32.featheresp32/RNode_Firmware.ino.bin build/rnode_firmware_featheresp32.bin cp build/esp32.esp32.featheresp32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_featheresp32.bootloader cp build/esp32.esp32.featheresp32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_featheresp32.partitions @@ -331,7 +352,7 @@ release-featheresp32: release-genericesp32: arduino-cli compile --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.*/tools/partitions/boot_app0.bin build/rnode_firmware_esp32_generic.boot_app0 + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ESP_IDF_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_esp32_generic.boot_app0 cp build/esp32.esp32.esp32/RNode_Firmware.ino.bin build/rnode_firmware_esp32_generic.bin cp build/esp32.esp32.esp32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_esp32_generic.bootloader cp build/esp32.esp32.esp32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_esp32_generic.partitions diff --git a/README.md b/README.md index 0ba700e..34a7cdb 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,13 @@ The RNode Firmware supports the following boards: - Handheld v2.x RNodes from [unsigned.io](https://unsigned.io/shop/product/handheld-rnode) - Original v1.x RNodes from [unsigned.io](https://unsigned.io/shop/product/rnode) -- LilyGO T-Beam v1.1 devices +- LilyGO T-Beam v1.1 devices with SX1276/8 LoRa chips +- LilyGO T-Beam v1.1 devices with SX1262/8 LoRa chips - LilyGO LoRa32 v1.0 devices - LilyGO LoRa32 v2.0 devices -- LilyGO LoRa32 v2.1 devices +- LilyGO LoRa32 v2.1 devices (with and without TCXO) - Heltec LoRa32 v2 devices +- Heltec LoRa32 v3 devices - Homebrew RNodes based on ATmega1284p boards - Homebrew RNodes based on ATmega2560 boards - Homebrew RNodes based on Adafruit Feather ESP32 boards diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index c6b1327..1f6e4d7 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -33,7 +33,7 @@ volatile uint16_t queued_bytes = 0; volatile uint16_t queue_cursor = 0; volatile uint16_t current_packet_start = 0; volatile bool serial_buffering = false; -#if HAS_BLUETOOTH +#if HAS_BLUETOOTH || HAS_BLE == true bool bt_init_ran = false; #endif @@ -60,8 +60,17 @@ void setup() { } #endif - // Seed the PRNG - randomSeed(analogRead(0)); + // Seed the PRNG for CSMA R-value selection + # if MCU_VARIANT == MCU_ESP32 + // On ESP32, get the seed value from the + // hardware RNG + int seed_val = (int)esp_random(); + #else + // Otherwise, get a pseudo-random seed + // value from an unconnected analog pin + int seed_val = analogRead(0); + #endif + randomSeed(seed_val); // Initialise serial communication memset(serialBuffer, 0, sizeof(serialBuffer)); @@ -79,6 +88,10 @@ void setup() { serial_interrupt_init(); // Configure input and output pins + #if HAS_INPUT + input_init(); + #endif + #if HAS_NP == false pinMode(pin_led_rx, OUTPUT); pinMode(pin_led_tx, OUTPUT); @@ -161,12 +174,9 @@ void setup() { pmu_ready = init_pmu(); #endif - #if HAS_BLUETOOTH + #if HAS_BLUETOOTH || HAS_BLE == true bt_init(); bt_init_ran = true; - #elif HAS_BLE - // TODO: Implement BLE on ESP32S3 instead of this hack - bt_ready = true; #endif if (console_active) { @@ -911,7 +921,7 @@ void serialCallback(uint8_t sbyte) { } #endif } else if (command == CMD_BT_CTRL) { - #if HAS_BLUETOOTH + #if HAS_BLUETOOTH || HAS_BLE if (sbyte == 0x00) { bt_stop(); bt_conf_save(false); @@ -1291,9 +1301,26 @@ void loop() { if (pmu_ready) update_pmu(); #endif - #if HAS_BLUETOOTH + #if HAS_BLUETOOTH || HAS_BLE == true if (!console_active && bt_ready) update_bt(); #endif + + #if HAS_INPUT + input_read(); + #endif +} + +void sleep_now() { + #if HAS_SLEEP == true + esp_sleep_enable_ext0_wakeup(PIN_WAKEUP, WAKEUP_LEVEL); + esp_deep_sleep_start(); + #endif +} + +void button_event(uint8_t event, unsigned long duration) { + if (duration > 2000) { + sleep_now(); + } } volatile bool serial_polling = false; @@ -1323,7 +1350,7 @@ void buffer_serial() { uint8_t c = 0; - #if HAS_BLUETOOTH + #if HAS_BLUETOOTH || HAS_BLE == true while ( c < MAX_CYCLES && ( (bt_state != BT_STATE_CONNECTED && Serial.available()) || (bt_state == BT_STATE_CONNECTED && SerialBT.available()) ) @@ -1338,7 +1365,7 @@ void buffer_serial() { if (!fifo_isfull_locked(&serialFIFO)) { fifo_push_locked(&serialFIFO, Serial.read()); } - #elif HAS_BLUETOOTH + #elif HAS_BLUETOOTH || HAS_BLE == true if (bt_state == BT_STATE_CONNECTED) { if (!fifo_isfull(&serialFIFO)) { fifo_push(&serialFIFO, SerialBT.read()); diff --git a/ROM.h b/ROM.h index b186318..a945d97 100644 --- a/ROM.h +++ b/ROM.h @@ -25,6 +25,7 @@ #define PRODUCT_T32_20 0xB0 #define PRODUCT_T32_21 0xB1 #define PRODUCT_H32_V2 0xC0 + #define PRODUCT_H32_V3 0xC1 #define MODEL_A1 0xA1 #define MODEL_A6 0xA6 #define MODEL_A4 0xA4 @@ -41,6 +42,8 @@ #define MODEL_BB 0xBB #define MODEL_C4 0xC4 #define MODEL_C9 0xC9 + #define MODEL_C5 0xC5 + #define MODEL_CA 0xCA #define MODEL_E4 0xE4 #define MODEL_E9 0xE9 #define MODEL_E3 0xE3 diff --git a/Release/console_image.bin b/Release/console_image.bin index 06319e8..26896ea 100644 Binary files a/Release/console_image.bin and b/Release/console_image.bin differ diff --git a/Utilities.h b/Utilities.h index 816df3b..22080de 100644 --- a/Utilities.h +++ b/Utilities.h @@ -51,7 +51,7 @@ uint8_t eeprom_read(uint32_t mapped_addr); #include "Display.h" #endif -#if HAS_BLUETOOTH == true +#if HAS_BLUETOOTH == true || HAS_BLE == true void kiss_indicate_btpin(); #include "Bluetooth.h" #endif @@ -60,11 +60,20 @@ uint8_t eeprom_read(uint32_t mapped_addr); #include "Power.h" #endif +#if HAS_INPUT == true + #include "Input.h" +#endif + #if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52 #include "Device.h" #endif #if MCU_VARIANT == MCU_ESP32 - #if BOARD_MODEL != BOARD_RNODE_NG_22 + #if BOARD_MODEL == BOARD_HELTEC32_V3 + //https://github.com/espressif/esp-idf/issues/8855 + #include "hal/wdt_hal.h" + #elif BOARD_MODEL == BOARD_RNODE_NG_22 + #include "hal/wdt_hal.h" + #else BOARD_MODEL != BOARD_RNODE_NG_22 #include "soc/rtc_wdt.h" #endif #define ISR_VECT IRAM_ATTR @@ -196,6 +205,11 @@ uint8_t boot_vector = 0x00; void led_tx_on() { digitalWrite(pin_led_tx, HIGH); } void led_tx_off() { digitalWrite(pin_led_tx, LOW); } #endif + #elif BOARD_MODEL == BOARD_HELTEC32_V3 + void led_rx_on() { digitalWrite(pin_led_rx, HIGH); } + void led_rx_off() { digitalWrite(pin_led_rx, LOW); } + void led_tx_on() { digitalWrite(pin_led_tx, HIGH); } + void led_tx_off() { digitalWrite(pin_led_tx, LOW); } #elif BOARD_MODEL == BOARD_LORA32_V2_1 void led_rx_on() { digitalWrite(pin_led_rx, HIGH); } void led_rx_off() { digitalWrite(pin_led_rx, LOW); } @@ -623,7 +637,7 @@ int8_t led_standby_direction = 0; #endif void serial_write(uint8_t byte) { - #if HAS_BLUETOOTH + #if HAS_BLUETOOTH || HAS_BLE == true if (bt_state != BT_STATE_CONNECTED) { Serial.write(byte); } else { @@ -823,7 +837,7 @@ void kiss_indicate_battery() { } void kiss_indicate_btpin() { - #if HAS_BLUETOOTH + #if HAS_BLUETOOTH || HAS_BLE == true serial_write(FEND); serial_write(CMD_BT_PIN); escaped_serial_write(bt_ssp_pin>>24); @@ -1277,7 +1291,7 @@ bool eeprom_product_valid() { #if PLATFORM == PLATFORM_AVR if (rval == PRODUCT_RNODE || rval == PRODUCT_HMBRW) { #elif PLATFORM == PLATFORM_ESP32 - if (rval == PRODUCT_RNODE || rval == BOARD_RNODE_NG_20 || rval == BOARD_RNODE_NG_21 || rval == PRODUCT_HMBRW || rval == PRODUCT_TBEAM || rval == PRODUCT_T32_10 || rval == PRODUCT_T32_20 || rval == PRODUCT_T32_21 || rval == PRODUCT_H32_V2) { + if (rval == PRODUCT_RNODE || rval == BOARD_RNODE_NG_20 || rval == BOARD_RNODE_NG_21 || rval == PRODUCT_HMBRW || rval == PRODUCT_TBEAM || rval == PRODUCT_T32_10 || rval == PRODUCT_T32_20 || rval == PRODUCT_T32_21 || rval == PRODUCT_H32_V2 || rval == PRODUCT_H32_V3) { #elif PLATFORM == PLATFORM_NRF52 if (rval == PRODUCT_HMBRW) { #else @@ -1315,6 +1329,8 @@ bool eeprom_model_valid() { if (model == MODEL_B4 || model == MODEL_B9) { #elif BOARD_MODEL == BOARD_HELTEC32_V2 if (model == MODEL_C4 || model == MODEL_C9) { + #elif BOARD_MODEL == BOARD_HELTEC32_V3 + if (model == MODEL_C5 || model == MODEL_CA) { #elif BOARD_MODEL == BOARD_RAK4630 if (model == MODEL_FF) { #elif BOARD_MODEL == BOARD_HUZZAH32 diff --git a/arduino-cli.yaml b/arduino-cli.yaml index b7b1622..cfbe258 100644 --- a/arduino-cli.yaml +++ b/arduino-cli.yaml @@ -2,3 +2,4 @@ board_manager: additional_urls: - https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - https://raw.githubusercontent.com/RAKwireless/RAKwireless-Arduino-BSP-Index/main/package_rakwireless_index.json + - http://unsigned.io/arduino/package_unsignedio_UnsignedBoards_index.json diff --git a/sx126x.cpp b/sx126x.cpp index 22df326..7057d76 100644 --- a/sx126x.cpp +++ b/sx126x.cpp @@ -127,7 +127,7 @@ bool sx126x::preInit() { pinMode(_ss, OUTPUT); digitalWrite(_ss, HIGH); - #if BOARD_MODEL == BOARD_RNODE_NG_22 + #if BOARD_MODEL == BOARD_RNODE_NG_22 || BOARD_MODEL == BOARD_HELTEC32_V3 SPI.begin(pin_sclk, pin_miso, pin_mosi, pin_cs); #else SPI.begin(); @@ -717,8 +717,8 @@ void sx126x::sleep() void sx126x::enableTCXO() { #if HAS_TCXO - #if BOARD_MODEL == BOARD_RAK4630 - uint8_t buf[4] = {MODE_TCXO_1_8V_6X, 0x00, 0x00, 0xFF}; + #if BOARD_MODEL == BOARD_RAK4630 || BOARD_MODEL == BOARD_HELTEC32_V3 + uint8_t buf[4] = {MODE_TCXO_3_3V_6X, 0x00, 0x00, 0xFF}; #elif BOARD_MODEL == BOARD_TBEAM uint8_t buf[4] = {MODE_TCXO_1_8V_6X, 0x00, 0x00, 0xFF}; #elif BOARD_MODEL == BOARD_RNODE_NG_22