]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added compatibility for Adafruit FeatherESP32, generic ESP32 and ATmega2560
authorMark Qvist <mark@unsigned.io>
Fri, 21 Jan 2022 19:43:29 +0000 (20:43 +0100)
committerMark Qvist <mark@unsigned.io>
Fri, 21 Jan 2022 19:43:29 +0000 (20:43 +0100)
Config.h
Makefile
RNode_Firmware.ino
Utilities.h
arduino-cli.yaml

index adfbdd97728362184c594468243599eccac8dc17..18ce9e16d5bb86339212f91be35aba12ac3dc066 100644 (file)
--- a/Config.h
+++ b/Config.h
        #define MCU_2560  0x92
        #define MCU_ESP32 0x81
 
-       #define BOARD_RNODE 0x31
-       #define BOARD_HMBRW 0x32
-       #define BOARD_TBEAM 0x33
+       #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
 
        #define MODE_HOST 0x11
        #define MODE_TNC  0x12
@@ -53,7 +57,7 @@
 
                #define CONFIG_UART_BUFFER_SIZE 6144
                #define CONFIG_QUEUE_SIZE 6144
-               #define CONFIG_QUEUE_MAX_LENGTH 250
+               #define CONFIG_QUEUE_MAX_LENGTH 200
 
                #define EEPROM_SIZE 4096
                #define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
 
                #define BOARD_MODEL BOARD_HMBRW
 
-               #define CONFIG_UART_BUFFER_SIZE 1024
-               #define CONFIG_QUEUE_SIZE 4096
-               #define CONFIG_QUEUE_MAX_LENGTH 80
+               #define CONFIG_UART_BUFFER_SIZE 768
+               #define CONFIG_QUEUE_SIZE 5120
+               #define CONFIG_QUEUE_MAX_LENGTH 24
 
                #define EEPROM_SIZE 4096
                #define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
 
        #elif MCU_VARIANT == MCU_ESP32
-               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;
 
-               #define BOARD_MODEL BOARD_TBEAM
+               #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;
+               #else
+                       #error An unsupported board was selected. Cannot compile RNode firmware.
+               #endif
 
                #define CONFIG_UART_BUFFER_SIZE 6144
                #define CONFIG_QUEUE_SIZE 6144
-               #define CONFIG_QUEUE_MAX_LENGTH 250
+               #define CONFIG_QUEUE_MAX_LENGTH 200
 
                #define EEPROM_SIZE 1024
                #define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
index a8df61d23a256055f15b3bbbea707f86e6623eb4..d05cfece89baba54bf9ce0fe9296ebd7d1dd880d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,29 +2,54 @@ prep:
        arduino-cli core update-index --config-file arduino-cli.yaml
        arduino-cli core install unsignedio:avr
 
+prep-esp32:
+       arduino-cli core update-index --config-file arduino-cli.yaml
+       arduino-cli core install esp32:esp32
+
+prep-samd:
+       arduino-cli core update-index --config-file arduino-cli.yaml
+       arduino-cli core install adafruit:samd
+
+
+
 firmware:
        arduino-cli compile --fqbn unsignedio:avr:rnode
 
-release:
-       arduino-cli compile --fqbn unsignedio:avr:rnode -e
-       cp build/unsignedio.avr.rnode/RNode_Firmware.ino.hex Precompiled/rnode_firmware_latest.hex
-       rm -r build
+firmware-tbeam:
+       arduino-cli compile --fqbn esp32:esp32:t-beam --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\""
 
-upload:
-       arduino-cli upload -p /dev/ttyUSB0 --fqbn unsignedio:avr:rnode
+firmware-featheresp32:
+       arduino-cli compile --fqbn esp32:esp32:featheresp32 --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\""
+
+firmware-genericesp32:
+       arduino-cli compile --fqbn esp32:esp32:esp32 --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\""
+
+firmware-mega2560:
+       arduino-cli compile --fqbn arduino:avr:mega
 
-prep-tbeam:
-       arduino-cli core update-index --config-file arduino-cli.yaml
-       arduino-cli core install esp32:esp32
 
-firmware-tbeam:
-       arduino-cli compile --fqbn esp32:esp32:t-beam
+
+upload:
+       arduino-cli upload -p /dev/ttyUSB0 --fqbn unsignedio:avr:rnode
 
 upload-tbeam:
        arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:t-beam
 
+upload-featheresp32:
+       arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:featheresp32
+
+upload-mega2560:
+       arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:mega
+
+release-all: release-rnode release-tbeam release-featheresp32 release-genericesp32
+
+release-rnode:
+       arduino-cli compile --fqbn unsignedio:avr:rnode -e
+       cp build/unsignedio.avr.rnode/RNode_Firmware.ino.hex Precompiled/rnode_firmware_latest.hex
+       rm -r build
+
 release-tbeam:
-       arduino-cli compile --fqbn esp32:esp32:t-beam -e
+       arduino-cli compile --fqbn esp32:esp32:t-beam -e --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\""
        cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.2/tools/partitions/boot_app0.bin build/rnode_firmware_latest_tbeam.boot_app0
        cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bin build/rnode_firmware_latest_tbeam.bin
        cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_latest_tbeam.bootloader
@@ -32,13 +57,25 @@ release-tbeam:
        zip --junk-paths ./Precompiled/rnode_firmware_latest_tbeam.zip ./Precompiled/esptool/esptool.py build/rnode_firmware_latest_tbeam.boot_app0 build/rnode_firmware_latest_tbeam.bin build/rnode_firmware_latest_tbeam.bootloader build/rnode_firmware_latest_tbeam.partitions
        rm -r build
 
-firmware-mega2560:
-       arduino-cli compile --fqbn arduino:avr:mega
+release-featheresp32:
+       arduino-cli compile --fqbn esp32:esp32:featheresp32 -e --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\""
+       cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.2/tools/partitions/boot_app0.bin build/rnode_firmware_latest_featheresp32.boot_app0
+       cp build/esp32.esp32.featheresp32/RNode_Firmware.ino.bin build/rnode_firmware_latest_featheresp32.bin
+       cp build/esp32.esp32.featheresp32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_latest_featheresp32.bootloader
+       cp build/esp32.esp32.featheresp32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_latest_featheresp32.partitions
+       zip --junk-paths ./Precompiled/rnode_firmware_latest_featheresp32.zip ./Precompiled/esptool/esptool.py build/rnode_firmware_latest_featheresp32.boot_app0 build/rnode_firmware_latest_featheresp32.bin build/rnode_firmware_latest_featheresp32.bootloader build/rnode_firmware_latest_featheresp32.partitions
+       rm -r build
+
+release-genericesp32:
+       arduino-cli compile --fqbn esp32:esp32:esp32 -e --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\""
+       cp ~/.arduino15/packages/esp32/hardware/esp32/2.0.2/tools/partitions/boot_app0.bin build/rnode_firmware_latest_esp32_generic.boot_app0
+       cp build/esp32.esp32.esp32/RNode_Firmware.ino.bin build/rnode_firmware_latest_esp32_generic.bin
+       cp build/esp32.esp32.esp32/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_latest_esp32_generic.bootloader
+       cp build/esp32.esp32.esp32/RNode_Firmware.ino.partitions.bin build/rnode_firmware_latest_esp32_generic.partitions
+       zip --junk-paths ./Precompiled/rnode_firmware_latest_esp32_generic.zip ./Precompiled/esptool/esptool.py build/rnode_firmware_latest_esp32_generic.boot_app0 build/rnode_firmware_latest_esp32_generic.bin build/rnode_firmware_latest_esp32_generic.bootloader build/rnode_firmware_latest_esp32_generic.partitions
+       rm -r build
 
 release-mega2560:
        arduino-cli compile --fqbn arduino:avr:mega -e
        cp build/arduino.avr.mega/RNode_Firmware.ino.hex Precompiled/rnode_firmware_latest_m2560.hex
-       rm -r build
-
-upload-mega2560:
-       arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:mega
\ No newline at end of file
+       rm -r build
\ No newline at end of file
index 00f11f9eeb889434a1ba55e35e918ec0728ba430..350b69adb70eb9644017ff9e3dc394a21838d63f 100644 (file)
@@ -64,9 +64,12 @@ void setup() {
   // pins for the LoRa module
   LoRa.setPins(pin_cs, pin_reset, pin_dio);
 
-  #if MCU_VARIANT == MCU_ESP32    
-    Wire.begin(I2C_SDA, I2C_SCL);
-    initPMU();
+  #if MCU_VARIANT == MCU_ESP32
+    #if BOARD_MODEL == BOARD_TBEAM
+      Wire.begin(I2C_SDA, I2C_SCL);
+      initPMU();
+    #endif
+
     kiss_indicate_reset();
   #endif
 
@@ -645,8 +648,14 @@ void checkModemStatus() {
 }
 
 void validateStatus() {
-  #if MCU_VARIANT == MCU_1284P || MCU_VARIANT == MCU_2560
+  #if MCU_VARIANT == MCU_1284P
+      uint8_t boot_flags = OPTIBOOT_MCUSR;
+      uint8_t F_POR = PORF;
+      uint8_t F_BOR = BORF;
+      uint8_t F_WDR = WDRF;
+  #elif MCU_VARIANT == MCU_2560
       uint8_t boot_flags = OPTIBOOT_MCUSR;
+      if (boot_flags == 0x00) boot_flags = 0x03;
       uint8_t F_POR = PORF;
       uint8_t F_BOR = BORF;
       uint8_t F_WDR = WDRF;
@@ -742,7 +751,7 @@ void loop() {
     buffer_serial();
     if (!fifo_isempty(&serialFIFO)) serial_poll();
   #else
-    if (!fifo_isempty_locked(&serialFIFO)) serial_poll();    
+    if (!fifo_isempty_locked(&serialFIFO)) serial_poll();
   #endif
 }
 
index 705b6761945f6047563c7b40f40da51ce1a09553..b5534b7fd63cc403821af9b168afcc09182b14e9 100644 (file)
@@ -36,10 +36,22 @@ uint8_t boot_vector = 0x00;
        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
 #elif MCU_VARIANT == MCU_ESP32
-       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, LOW); }
-       void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
+       #if BOARD_MODEL == BOARD_TBEAM
+               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, LOW); }
+               void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
+       #elif BOARD_MODEL == BOARD_HUZZAH32
+               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_GENERIC_ESP32
+               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); }
+       #endif
 #endif
 
 void hard_reset(void) {
index 1d887592969f7a6d94e5c6d59a6bce81616a5fc7..c9580b95971ceecc1321e886169ccc6de55b573d 100644 (file)
@@ -2,3 +2,4 @@ board_manager:
   additional_urls:
   - https://unsigned.io/arduino/package_unsignedio_UnsignedBoards_index.json
   - https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
+  - https://adafruit.github.io/arduino-board-index/package_adafruit_index.json