diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 2e862265..e3deac04 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -32,16 +32,27 @@ body: Please select the board you are using. Please note that only the boards listed below are supported. options: + - Adafruit Feather ESP32 + - Adafruit Feather ESP32-S2 + - Adafruit Feather ESP32-S3 (2 MB PSRAM) + - Adafruit Feather ESP32-S3 (No PSRAM) - Adafruit Feather M0 (Any variants EG Bluefruit LE, LoRa, etc) - Adafruit Feather M0 Express - Adafruit Feather M4 Express - Adafruit Feather M4 CAN Express - Adafruit Grand Central M4 + - Adafruit ItsyBitsy ESP32 - Adafruit ItsyBitsy M0 Express - Adafruit ItsyBitsy M4 Express + - Adafruit Metro ESP32-S2 - Adafruit Metro M0 Express - Adafruit Metro M4 Express - Adafruit Metro M4 AirLift Lite + - Adafruit QtPy ESP32 + - Adafruit QtPy ESP32 Pico + - Adafruit QtPy ESP32-C3 + - Adafruit QtPy ESP32-S2 + - Adafruit QtPy ESP32-S3 - Adafruit QtPy M0 - Adafruit Trinket M0 - Arduino MKR 1000 @@ -54,8 +65,22 @@ body: - Arduino MKR WiFi 1010 - Arduino MKR ZERO - Arduino Nano 33 IoT + - Arduino Nano ESP32 - Arduino Zero + - Espressif ESP32-C3 DevKitC-02 + - Espressif ESP32-C3 DevKitM-1 + - Espressif ESP32-S3 DevKitC-1-N8 + - SparkFun ESP32 RedBoard IoT + - SparkFun ESP32 Thing + - SparkFun ESP32 Thing Plus + - SparkFun ESP32-S2 Thing Plus - Seeed Studio XIAO SAMD21 + - Teensy 3.0 + - Teensy 3.1/3.2 + - Teensy 3.5 + - Teensy 3.6 + - Teensy 4.0 + - Teensy 4.1 validations: required: true - type: dropdown diff --git a/README.md b/README.md index 14da0495..14617665 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,17 @@ This provides you with up to 16 11-bit full resolution channels & telemetry with If you want to use CRSF for Arduino in the Arduino IDE, you need these: - [Arduino IDE](https://www.arduino.cc/en/software) -- [Arduino SAMD Board Support Pack](https://github.com/arduino/ArduinoCore-samd) -- [Adafruit SAMD Board Support Pack](https://github.com/adafruit/ArduinoCore-samd) -- [Adafruit_ZeroDMA](https://github.com/adafruit/Adafruit_ZeroDMA) + - ESP32 targets: + - Additional Boards URL: `https://espressif.github.io/arduino-esp32/package_esp32_index.json` + - [Arduino ESP32 Board Support Pack](https://github.com/espressif/arduino-esp32) + - SAMD21 & SAMD51 targets: + - Additional Boards URL: `https://adafruit.github.io/arduino-board-index/package_adafruit_index.json` + - [Arduino SAMD Board Support Pack](https://github.com/arduino/ArduinoCore-samd) + - [Adafruit SAMD Board Support Pack](https://github.com/adafruit/ArduinoCore-samd) + - [Adafruit_ZeroDMA](https://github.com/adafruit/Adafruit_ZeroDMA) + - Teensy 3.x & Teensy 4.x targets: + - Additional Boards URL: `https://www.pjrc.com/teensy/package_teensy_index.json` + - [Teensy Board Support Pack](https://github.com/PaulStoffregen/cores) ## Prerequisites - Visual Studio Code & PlatformIO @@ -336,6 +344,27 @@ For example, if you are using an Adafruit Metro M4 Express, you would use `pio r CRSF for Arduino is designed to be compatible with modern hardware. While CRSF for Arduino is primarily developed on the Adafruit Metro M4 Express, here is a list of target development boards CRSF for Arduino is compatible with (Keep in mind that this list is not exhaustive, & actual compatibility with everything listed here may be untested): +- ESP32 based boards: + - Adafruit Feather ESP32 + - Adafruit Feather ESP32-S2 + - Adafruit Feather ESP32-S3 (2 MB PSRAM) + - Adafruit Feather ESP32-S3 (NO PSRAM) + - Adafruit ItsyBitsy ESP32 + - Adafruit Metro ESP32-S2 + - Adafruit QtPy ESP32 + - Adafruit QtPy ESP32 Pico + - Adafruit QtPy ESP32-C3 + - Adafruit QtPy ESP32-S2 + - Adafruit QtPy ESP32-S3 + - Arduino Nano ESP32 + - Espressif ESP32-C3-DevKit + - Espressif ESP32-S3-DevKit + - Seeed Studio XIAO ESP32-C3 + - Seeed Studio XIAO ESP32-S3 + - SparkFun ESP32 RedBoard IoT + - SparkFun ESP32 Thing + - SparkFun ESP32 Thing Plus + - SparkFun ESP32-S2 Thing Plus - SAMD21 based boards: - Adafruit Feather M0 & all of its variants, including the Adafruit Feather M0 Express - Adafruit ItsyBitsy M0 Express @@ -362,7 +391,7 @@ While CRSF for Arduino is primarily developed on the Adafruit Metro M4 Express, - Adafruit Metro M4 Express AirLift Lite - SAME51 based boards: - Adafruit Feather M4 CAN Express -- Teensy 3.x +- Teensy 3.x **NB:** The entire Teensy 3.x line is discontinued by the manufacturer, and is _not_ recommended for new projects. - Teensy 4.x diff --git a/platformio.ini b/platformio.ini index 2cdbee02..6587a0be 100644 --- a/platformio.ini +++ b/platformio.ini @@ -251,6 +251,147 @@ debug_tool = ${common_samd51.debugger} lib_deps = ${common_samd51.lib_deps} upload_protocol = ${common_samd51.sketch_upload_protocol} +; ESP32 Boards +[env:adafruit_qtpy_esp32] +platform = espressif32 +board = adafruit_qtpy_esp32 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:adafruit_qtpy_esp32c3] +platform = espressif32 +board = adafruit_qtpy_esp32c3 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:adafruit_qtpy_esp32s2] +platform = espressif32 +board = adafruit_qtpy_esp32s2 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:adafruit_qtpy_esp32s3_nopsram] +platform = espressif32 +board = adafruit_qtpy_esp32s3_nopsram +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:featheresp32-s2] +platform = espressif32 +board = featheresp32-s2 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:adafruit_feather_esp32s3] +platform = espressif32 +board = adafruit_feather_esp32s3 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:adafruit_feather_esp32s3_nopsram] +platform = espressif32 +board = adafruit_feather_esp32s3_nopsram +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:featheresp32] +platform = espressif32 +board = featheresp32 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:adafruit_itsybitsy_esp32] +platform = espressif32 +board = adafruit_itsybitsy_esp32 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:adafruit_metro_esp32s2] +platform = espressif32 +board = adafruit_metro_esp32s2 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:arduino_nano_esp32] +platform = espressif32 +board = arduino_nano_esp32 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:esp32-c3-devkitc-02] +platform = espressif32 +board = esp32-c3-devkitc-02 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:esp32-c3-devkitm-1] +platform = espressif32 +board = esp32-c3-devkitm-1 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:esp32-s3-devkitc-1] +platform = espressif32 +board = esp32-s3-devkitc-1 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:seeed_xiao_esp32c3] +platform = espressif32 +board = seeed_xiao_esp32c3 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:seeed_xiao_esp32s3] +platform = espressif32 +board = seeed_xiao_esp32s3 +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:sparkfun_esp32_iot_redboard] +platform = espressif32 +board = sparkfun_esp32_iot_redboard +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:esp32thing] +platform = espressif32 +board = esp32thing +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:esp32thing_plus] +platform = espressif32 +board = esp32thing_plus +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + +[env:sparkfun_esp32s2_thing_plus] +platform = espressif32 +board = sparkfun_esp32s2_thing_plus +build_flags = + -DUSE_ABSTRACTION_LAYER + -DCRC_OPTIMISATION_LEVEL=0 + ; Teensy Boards [env:teensy_30] platform = teensy @@ -306,7 +447,8 @@ build_flags = -DCRC_OPTIMISATION_LEVEL=0 [platformio] -default_envs = adafruit_metro_m0 +default_envs = adafruit_metro_m4 +core_dir = $PROJECT_DIR/.pio/core include_dir = src/include lib_dir = src/lib src_dir = src/src diff --git a/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.cpp b/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.cpp index 9d8511bc..a97123b7 100644 --- a/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.cpp +++ b/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.cpp @@ -38,8 +38,63 @@ namespace hal // TEMPORARILY DISABLED: Arduino IDE must be 1.7.0 or greater // #if ARDUINO >= 10700 +// Arduino ESP32 Architecture +#if defined(ARDUINO_ARCH_ESP32) + +// Adafruit devboards +#if defined(ARDUINO_FEATHER_ESP32) + device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_ESP32; +#elif defined(ARDUINO_METRO_ESP32S2) + device.type.devboard = DEVBOARD_ADAFRUIT_METRO_ESP32S2; +#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_NOPSRAM) + device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_ESP32S2; +#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3) + device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_ESP32S3; +#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S3_NOPSRAM) + device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_ESP32S3_NOPSRAM; +#elif defined(ARDUINO_ADAFRUIT_ITSYBITSY_ESP32) + device.type.devboard = DEVBOARD_ADAFRUIT_ITSYBITSY_ESP32; +#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32C3) + device.type.devboard = DEVBOARD_ADAFRUIT_QTPY_ESP32C3; +#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) + device.type.devboard = DEVBOARD_ADAFRUIT_QTPY_ESP32S2; +#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) + device.type.devboard = DEVBOARD_ADAFRUIT_QTPY_ESP32S3; +#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO) + device.type.devboard = DEVBOARD_ADAFRUIT_QTPY_ESP32_PICO; + +// Espressif devboards. +#elif defined(ARDUINO_ESP32C3_DEV) + device.type.devboard = DEVBOARD_ESPRESSIF_ESP32C3_DEVKIT; +#elif defined(ARDUINO_ESP32S3_DEV) + device.type.devboard = DEVBOARD_ESPRESSIF_ESP32S3_DEVKIT; + +// Seeed Studio ESP32 devboards. +#elif defined(ARDUINO_XIAO_ESP32C3) + device.type.devboard = DEVBOARD_SEEEDSTUDIO_XIAO_ESP32C3; +#elif defined(ARDUINO_XIAO_ESP32S3) + device.type.devboard = DEVBOARD_SEEEDSTUDIO_XIAO_ESP32S3; + +// SparkFun ESP32 devboards. +#elif defined(ARDUINO_ESP32_IOT_REDBOARD) + device.type.devboard = DEVBOARD_SPARKFUN_REDBOARD_ESP32_IOT; +#elif defined(ARDUINO_ESP32_THING) + device.type.devboard = DEVBOARD_SPARKFUN_THING_ESP32; +#elif defined(ARDUINO_ESP32_THING_PLUS) + device.type.devboard = DEVBOARD_SPARKFUN_THING_PLUS_ESP32; +#elif defined(ARDUINO_ESP32S2_THING_PLUS) + device.type.devboard = DEVBOARD_SPARKFUN_THING_PLUS_ESP32S2; + +// Arduino devboards +#elif defined(ARDUINO_NANO_ESP32) + device.type.devboard = DEVBOARD_ARDUINO_NANO_ESP32; +#else +#warning "Devboard not supported. Please check the compatibility table." + device.type.devboard = DEVBOARD_IS_INCOMPATIBLE; +#endif + // Arduino SAMD Architecture -#if defined(ARDUINO_ARCH_SAMD) +#elif defined(ARDUINO_ARCH_SAMD) // Adafruit devboards #if USB_VID == 0x239A diff --git a/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.h b/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.h index 4891dbc3..4286cd47 100644 --- a/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.h +++ b/src/lib/CRSFforArduino/src/Hardware/CompatibilityTable/CompatibilityTable.h @@ -45,6 +45,18 @@ namespace hal // Unknown device. DEVBOARD_IS_INCOMPATIBLE = 0, + // Adafruit ESP32 boards. + DEVBOARD_ADAFRUIT_FEATHER_ESP32, + DEVBOARD_ADAFRUIT_FEATHER_ESP32S2, + DEVBOARD_ADAFRUIT_FEATHER_ESP32S3, + DEVBOARD_ADAFRUIT_FEATHER_ESP32S3_NOPSRAM, + DEVBOARD_ADAFRUIT_ITSYBITSY_ESP32, + DEVBOARD_ADAFRUIT_METRO_ESP32S2, + DEVBOARD_ADAFRUIT_QTPY_ESP32C3, + DEVBOARD_ADAFRUIT_QTPY_ESP32_PICO, + DEVBOARD_ADAFRUIT_QTPY_ESP32S2, + DEVBOARD_ADAFRUIT_QTPY_ESP32S3, + // Adafruit SAMD21 boards. DEVBOARD_ADAFRUIT_FEATHER_M0, DEVBOARD_ADAFRUIT_FEATHER_M0_EXPRESS, @@ -63,6 +75,9 @@ namespace hal // Adafruit SAME51 boards. DEVBOARD_ADAFRUIT_FEATHER_M4_CAN, + // Arduino ESP32 boards. + DEVBOARD_ARDUINO_NANO_ESP32, + // Arduino SAMD21 boards. DEVBOARD_ARDUINO_MKR1000, DEVBOARD_ARDUINO_MKRFOX1200, @@ -76,9 +91,21 @@ namespace hal DEVBOARD_ARDUINO_NANO_33_IOT, DEVBOARD_ARDUINO_ZERO, + // Espresif ESP32 boards. + DEVBOARD_ESPRESSIF_ESP32C3_DEVKIT, + DEVBOARD_ESPRESSIF_ESP32S3_DEVKIT, + // Seeed Studio boards. + DEVBOARD_SEEEDSTUDIO_XIAO_ESP32C3, + DEVBOARD_SEEEDSTUDIO_XIAO_ESP32S3, DEVBOARD_SEEEDSTUDIO_XIAO_M0, + // SparkFun Boards + DEVBOARD_SPARKFUN_REDBOARD_ESP32_IOT, + DEVBOARD_SPARKFUN_THING_ESP32, + DEVBOARD_SPARKFUN_THING_PLUS_ESP32, + DEVBOARD_SPARKFUN_THING_PLUS_ESP32S2, + // Teensy boards. DEVBOARD_TEENSY_30, DEVBOARD_TEENSY_31_32, @@ -104,6 +131,16 @@ namespace hal const char *deviceNames[DEVBOARD_COUNT] = { "Incompatible device", + "Adafruit Feather ESP32", + "Adafruit Feather ESP32-S2", + "Adafruit Feather ESP32-S3", + "Adafruit Feather ESP32-S3 (no PSRAM)", + "Adafruit ItsyBitsy ESP32", + "Adafruit Metro ESP32-S2", + "Adafruit QT Py ESP32 C3", + "Adafruit QT Py ESP32 Pico", + "Adafruit QT Py ESP32-S2", + "Adafruit QT Py ESP32-S3", "Adafruit Feather M0", "Adafruit Feather M0 Express", "Adafruit ItsyBitsy M0 Express", @@ -116,6 +153,7 @@ namespace hal "Adafruit Metro M4 AirLift Lite", "Adafruit Metro M4 Express", "Adafruit Feather M4 CAN", + "Arduino Nano ESP32", "Arduino MKR1000", "Arduino MKRFOX1200", "Arduino MKRGSM1400", @@ -127,7 +165,15 @@ namespace hal "Arduino MKRZERO", "Arduino Nano 33 IoT", "Arduino Zero", + "Espressif ESP32-C3 DevKit", + "Espressif ESP32-S3 DevKit", + "Seeed Studio Xiao ESP32-C3", + "Seeed Studio Xiao ESP32-S3", "Seeed Studio Xiao SAMD21", + "SparkFun RedBoard ESP32 IoT", + "SparkFun Thing ESP32", + "SparkFun Thing Plus ESP32", + "SparkFun Thing Plus ESP32-S2", "Teensy 3.0", "Teensy 3.1/3.2", "Teensy 3.5", diff --git a/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.cpp b/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.cpp index 3bed25b1..64ccaa1b 100644 --- a/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.cpp +++ b/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.cpp @@ -117,6 +117,12 @@ namespace hal // Default to Serial1 if Teensyduino is being used. May expand this in the future, if requested. uart_port = &Serial1; + // Debug. + Serial.println("[Development Board | DEBUG]: Using Serial1."); +#elif defined(ARDUINO_ARCH_ESP32) + // Default to Serial1 if ESP32 is being used. May expand this in the future, if requested. + uart_port = &Serial1; + // Debug. Serial.println("[Development Board | DEBUG]: Using Serial1."); #else @@ -132,13 +138,13 @@ namespace hal // If UART port was defined beforehand, delete it. if (uart_port != nullptr) { -#ifndef TEENSYDUINO +#if not(defined(TEENSYDUINO) || defined(ARDUINO_ARCH_ESP32)) uart_port->~Uart(); #endif } } - void DevBoards::begin(unsigned long baudrate, uint16_t config) + void DevBoards::begin(unsigned long baudrate, int config) { // Begin the UART port. uart_port->begin(baudrate, config); @@ -180,7 +186,7 @@ namespace hal return uart_port->write(c); } -#if defined(TEENSYDUINO) +#if defined(TEENSYDUINO) || defined(ARDUINO_ARCH_ESP32) size_t DevBoards::write(const uint8_t *buffer, size_t size) { // Write a buffer to the UART port. diff --git a/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.h b/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.h index 6526f65b..caeeec06 100644 --- a/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.h +++ b/src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.h @@ -36,7 +36,7 @@ namespace hal { class DevBoards -#ifndef TEENSYDUINO +#if not(defined(TEENSYDUINO) || defined(ARDUINO_ARCH_ESP32)) : private HardwareSerial #endif { @@ -48,14 +48,14 @@ namespace hal void clearUART(); // Hardware Serial functions. - void begin(unsigned long baudrate, uint16_t config = SERIAL_8N1); + void begin(unsigned long baudrate, int config = SERIAL_8N1); void end(); int available(void); int peek(void); int read(void); void flush(void); size_t write(uint8_t c); -#if defined(TEENSYDUINO) +#if defined(TEENSYDUINO) || defined(ARDUINO_ARCH_ESP32) size_t write(const uint8_t *buffer, size_t size); #else using Print::write; // pull in write(str) and write(buf, size) from Print diff --git a/src/lib/CRSFforArduino/src/SerialReceiver/CRSF/CRSF.cpp b/src/lib/CRSFforArduino/src/SerialReceiver/CRSF/CRSF.cpp index bee203b2..caf8a01b 100644 --- a/src/lib/CRSFforArduino/src/SerialReceiver/CRSF/CRSF.cpp +++ b/src/lib/CRSFforArduino/src/SerialReceiver/CRSF/CRSF.cpp @@ -100,7 +100,7 @@ namespace serialReceiver } // Assume the full frame lenthg is 5 bytes until the frame length byte is received. - const int fullFrameLength = framePosition < 3 ? 5 : min(rxFrame.frame.frameLength + CRSF_FRAME_LENGTH_ADDRESS + CRSF_FRAME_LENGTH_FRAMELENGTH, CRSF_FRAME_SIZE_MAX); + const int fullFrameLength = framePosition < 3 ? 5 : min(rxFrame.frame.frameLength + CRSF_FRAME_LENGTH_ADDRESS + CRSF_FRAME_LENGTH_FRAMELENGTH, (int)CRSF_FRAME_SIZE_MAX); if (framePosition < fullFrameLength) { diff --git a/src/library.json b/src/library.json index 9ce8b9f0..ca27cf49 100644 --- a/src/library.json +++ b/src/library.json @@ -31,7 +31,11 @@ ], "license": "GPL-3.0-or-later", "frameworks": "arduino", - "platforms": "atmelsam", + "platforms": [ + "atmelsam", + "espressif32", + "teensy" + ], "headers": [ "Arduino.h", "CRSFforArduino.h"