Skip to content

Commit

Permalink
refactor(compatibility table): Use USB VIDs & PIDs to detect compatib…
Browse files Browse the repository at this point in the history
…le development boards (#28)

The Compatibility Table leverages the USB Vendor ID & Product ID to determine whether-or-not a development board is compatible with CRSF for Arduino.
  • Loading branch information
ZZ-Cat authored Jul 19, 2023
1 parent b7b32d5 commit 436459a
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 82 deletions.
4 changes: 2 additions & 2 deletions examples/channels/channels.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file channels.ino
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief This example sketch shows how to receive RC channels from a CRSF receiver using the CRSF for Arduino library.
* @version 0.3.2
* @date 2023-06-03
* @version 0.3.3
* @date 2023-07-18
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=CRSFforArduino
version=0.3.2
version=0.3.3
author=Cassandra Robinson <nicad.heli.flier@gmail.com>
maintainer=Cassandra Robinson <nicad.heli.flier@gmail.com>
sentence=An Arduino Library for communicating with ExpressLRS receivers.
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ board_build.f_cpu = ${common.cpu_speed}
build_flags = ${common.compile_flags}
lib_deps = ${common.lib_deps}

[env:adafruit_grand_central_m4]
board = adafruit_grand_central_m4
[env:adafruit_grandcentral_m4]
board = adafruit_grandcentral_m4
board_build.f_cpu = ${common.cpu_speed}
build_flags = ${common.compile_flags}
debug_tool = ${common.debugger}
Expand Down
4 changes: 2 additions & 2 deletions src/CRSFforArduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file CRSFforArduino.h
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief Top level header for CRSF for Arduino, to help with Arduino IDE compatibility.
* @version 0.3.2
* @date 2023-06-03
* @version 0.3.3
* @date 2023-07-18
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
82 changes: 49 additions & 33 deletions src/lib/CRSFforArduino/CRSFforArduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file CRSFforArduino.cpp
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief CRSF for Arduino facilitates the use of ExpressLRS RC receivers in Arduino projects.
* @version 0.3.2
* @date 2023-06-03
* @version 0.3.3
* @date 2023-07-18
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down Expand Up @@ -331,62 +331,78 @@ Sercom *CRSFforArduino::_getSercom()
/* Get the SERCOM instance for the current UART.
This adds compatibility with most development boards on the market today. */

#if defined(__SAMD21E18A__)
#if USB_VID == 0x239A
// Adafruit devboards

/* Adafruit QtPy M0 & Trinket M0. */
#if defined(ADAFRUIT_QTPY_M0) || defined(ADAFRUIT_TRINKET_M0)
sercom = SERCOM0;
#endif

#elif defined(__SAMD21G18A__)
#if defined(__SAMD21G18A__)
// Devboards that use the SAMD21G18A chip.

/* Adafruit Feather M0 , Feather M0 Express, ItsyBitsy M0 & Metro M0 Express. */
#if defined(ADAFRUIT_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0_EXPRESS) || defined(ADAFRUIT_ITSYBITSY_M0) || \
defined(ADAFRUIT_METRO_M0_EXPRESS)
sercom = SERCOM0;

/* The entire lineup of Arduino MKR boards. */
#elif defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRGSM1400) || \
defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(ARDUINO_SAMD_MKRWAN1300) || \
defined(ARDUINO_SAMD_MKRWAN1310) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKRZERO) || \
defined(ARDUINO_SAMD_NANO_33_IOT)
sercom = SERCOM5;
#if USB_PID == 0x800B || USB_PID == 0x801B || USB_PID == 0x800F || USB_PID == 0x8013
// Adafruit Feather M0, Feather M0 Express, ItsyBitsy M0 & Metro M0 Express.

/* Arduino Zero. */
#elif defined(ARDUINO_SAMD_ZERO)
sercom = SERCOM0;
#endif

#elif defined(__SAMD51G19A__)
// Devboards that use the SAMD51G19A chip.

#if USB_PID == 0x802B
// Adafruit ItsyBitsy M4 Express.

/* Adafruit ItsyBitsy M4 Express. */
#if defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS)
sercom = SERCOM3;
#endif

#elif defined(__SAMD51J19A__)
// Devboards that use the SAMD51J19A chip.

#if USB_PID == 0x8031
// Adafruit Feather M4 Express.

/* Adafruit Feather M4 Express. */
#if defined(ADAFRUIT_FEATHER_M4_EXPRESS)
sercom = SERCOM5;
;
#elif USB_PID == 0x8037 || USB_PID == 0x8020
// Adafruit Metro M4 Airlift Lite & Metro M4 Express.

/* Adafruit Metro M4 Airlift Lite & Metro M4 Express. */
#elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || defined(ADAFRUIT_METRO_M4_EXPRESS)
sercom = SERCOM3;
#endif

#elif defined(__SAMD51P20A__)
// Devboards that use the SAMD51P20A chip.

#if USB_PID == 0x8020
// Adafruit Grand Central M4.

/* Adafruit Grand Central M4. */
#if defined(ADAFRUIT_GRAND_CENTRAL_M4)
sercom = SERCOM0;
#endif

#elif defined(__SAME51J19A__)
// Devboards that use the SAME51J19A chip.

#if USB_PID == 0x80CD
// Adafruit Feather M4 CAN.

/* Adafruit Feather M4 CAN. */
#if defined(ADAFRUIT_FEATHER_M4_CAN)
sercom = SERCOM5;
#endif

#endif

#elif USB_VID == 0x2341
// Arduino devboards

#if defined(__SAMD21G18A__)
// Devboards that use the SAMD21G18A chip.

// All Arduino MKR boards use the same SERCOM instance.
#if USB_PID == 0x8050 || USB_PID == 0x8052 || USB_PID == 0x8055 || USB_PID == 0x8056 || USB_PID == 0x8053 || USB_PID == 0x8059 || USB_PID == 0x8054 || USB_PID == 0x804F
// Arduino MKR FOX 1200, MKR GSM 1400, MKR NB 1500, MKR Vidor 4000, MKR WAN 1300, MKR WAN 1310, MKR WIFI 1010 & MKR ZERO.

sercom = SERCOM5;

#elif USB_PID == 0x804D
// Arduino Zero.

sercom = SERCOM0;
#endif
#endif
#endif

return sercom;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/CRSFforArduino/CRSFforArduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file CRSFforArduino.h
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief CRSF for Arduino facilitates the use of ExpressLRS RC receivers in Arduino projects.
* @version 0.3.2
* @date 2023-06-03
* @version 0.3.3
* @date 2023-07-18
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
148 changes: 113 additions & 35 deletions src/lib/CompatibilityTable/CompatibilityTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file CompatibilityTable.cpp
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief Compatibility Table is used to determine if the current device is compatible with CRSF for Arduino.
* @version 0.3.2
* @date 2023-06-03
* @version 0.3.3
* @date 2023-07-18
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand All @@ -28,61 +28,139 @@

CompatibilityTable::CompatibilityTable()
{
// TEMPORARILY DISABLED: Arduino IDE must be 1.7.0 or greater
// #if ARDUINO >= 10700

// Arduino SAMD Architecture
#if defined(ARDUINO_ARCH_SAMD)
#if defined(ADAFRUIT_FEATHER_M0)

// Adafruit devboards
#if USB_VID == 0x239A

#if defined(__SAMD21G18A__)
// Adafruit Feather M0
#if USB_PID == 0x800B
device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_M0;
#elif defined(ADAFRUIT_FEATHER_M0_EXPRESS)
// Adafruit Feather M0 Express
#elif USB_PID == 0x801B
device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_M0_EXPRESS;
#elif defined(ADAFRUIT_ITSYBITSY_M0)
// Adafruit ItsyBitsy M0
#elif USB_PID == 0x800F
device.type.devboard = DEVBOARD_ADAFRUIT_ITSYBITSY_M0_EXPRESS;
#elif defined(ADAFRUIT_METRO_M0_EXPRESS)
// Adafruit Metro M0 Express
#elif USB_PID == 0x8013
device.type.devboard = DEVBOARD_ADAFRUIT_METRO_M0_EXPRESS;
#elif defined(ADAFRUIT_QTPY_M0)
device.type.devboard = DEVBOARD_ADAFRUIT_QTPY_M0;
#elif defined(ADAFRUIT_TRINKET_M0)
device.type.devboard = DEVBOARD_ADAFRUIT_TRINKET_M0;
#elif defined(ADAFRUIT_FEATHER_M4_EXPRESS)
// Device is not supported
#else
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#warning "Devboard not supported. Please check the compatibility table."
#endif

#elif defined(__SAMD51J19A__)
// Adafruit Feather M4 Express
#if USB_PID == 0x8031
device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_M4_EXPRESS;
#elif defined(ADAFRUIT_GRAND_CENTRAL_M4)
device.type.devboard = DEVBOARD_ADAFRUIT_GRAND_CENTRAL_M4;
#elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS)
device.type.devboard = DEVBOARD_ADAFRUIT_ITSYBITSY_M4_EXPRESS;
#elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
device.type.devboard = DEVBOARD_ADAFRUIT_METRO_M4_AIRLIFT_LITE;
#elif defined(ADAFRUIT_METRO_M4_EXPRESS)
// Adafruit Metro M4 Express
#elif USB_PID == 0x8020
device.type.devboard = DEVBOARD_ADAFRUIT_METRO_M4_EXPRESS;
#elif defined(ADAFRUIT_FEATHER_M4_CAN)
// Adafruit Metro M4 AirLift Lite
#elif USB_PID == 0x8037
device.type.devboard = DEVBOARD_ADAFRUIT_METRO_M4_AIRLIFT_LITE;
// Device is not supported
#else
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#warning "Devboard not supported. Please check the compatibility table."
#endif

#elif defined(__SAMD51G19A__)
// Adafruit ItsyBitsy M4 Express
#if USB_PID == 0x802B
device.type.devboard = DEVBOARD_ADAFRUIT_ITSYBITSY_M4_EXPRESS;
// Device is not supported
#else
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#warning "Devboard not supported. Please check the compatibility table."
#endif

#elif defined(__SAMD51P20A__)
// Adafruit Grand Central M4
#if USB_PID == 0x8020
device.type.devboard = DEVBOARD_ADAFRUIT_GRAND_CENTRAL_M4;
// Device is not supported
#else
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#warning "Devboard not supported. Please check the compatibility table."
#endif

#elif defined(__SAME51J19A__)
// Adafruit Feather M4 CAN
#if USB_PID == 0x80CD
device.type.devboard = DEVBOARD_ADAFRUIT_FEATHER_M4_CAN;
#elif defined(ARDUINO_SAMD_MKR1000)
device.type.devboard = DEVBOARD_ARDUINO_MKR1000;
#elif defined(ARDUINO_SAMD_MKRFox1200)
device.type.devboard = DEVBOARD_ARDUINO_MKRFox1200;
#elif defined(ARDUINO_SAMD_MKRGSM1400)
// Device is not supported
#else
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#warning "Devboard not supported. Please check the compatibility table."
#endif
#else // Incompatible devboards
#warning "Devboard not supported. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif

// Arduino devboards
#elif USB_VID == 0x2341

#if defined(__SAMD21G18A__)
// Arduino MKRFOX1200
#if USB_PID == 0x8050
device.type.devboard = DEVBOARD_ARDUINO_MKRFOX1200;
// Arduino MKRGSM1400
#elif USB_PID == 0x8052
device.type.devboard = DEVBOARD_ARDUINO_MKRGSM1400;
#elif defined(ARDUINO_SAMD_MKRNB1500)
// Arduino MKRNB1500
#elif USB_PID == 0x8055
device.type.devboard = DEVBOARD_ARDUINO_MKRNB1500;
#elif defined(ARDUINO_SAMD_MKRVIDOR4000)
// Arduino MKRVIDOR4000
#elif USB_PID == 0x8056
device.type.devboard = DEVBOARD_ARDUINO_MKRVIDOR4000;
#elif defined(ARDUINO_SAMD_MKRWAN1300)
// Arduino MKRWAN1300
#elif USB_PID == 0x8053
device.type.devboard = DEVBOARD_ARDUINO_MKRWAN1300;
#elif defined(ARDUINO_SAMD_MKRWAN1310)
// Arduino MKRWAN1310
#elif USB_PID == 0x8059
device.type.devboard = DEVBOARD_ARDUINO_MKRWAN1310;
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
// Arduino MKRWiFi1010
#elif USB_PID == 0x8054
device.type.devboard = DEVBOARD_ARDUINO_MKRWIFI1010;
#elif defined(ARDUINO_SAMD_MKRZERO)
// Arduino MKRZERO
#elif USB_PID == 0x804F
device.type.devboard = DEVBOARD_ARDUINO_MKRZERO;
#elif defined(ARDUINO_SAMD_NANO_33_IOT)
device.type.devboard = DEVBOARD_ARDUINO_NANO_33_IOT;
#elif defined(ARDUINO_SAMD_ZERO)
// Arduino Zero
#elif USB_PID == 0x804D
device.type.devboard = DEVBOARD_ARDUINO_ZERO;
// Device is not supported
#else
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#warning "Devboard not supported. Please check the compatibility table."
#endif // ADAFRUIT_FEATHER_M0 etc
#else
#endif

#else // Incompatible devboards
#warning "Devboard not supported. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif

#else // Incompatible devboards
#warning "Devboard not supported. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif // ARDUINO_SAMD_ADAFRUIT

#else // Unsupported architecture
#error "Unsupported architecture. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif // ARDUINO_ARCH_SAMD

// #else
// #error "This library requires Arduino IDE 1.7.0 or greater. Please update your IDE."
// #endif // ARDUINO >= 10700
}

bool CompatibilityTable::isDevboardCompatible(const char *name)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/CompatibilityTable/CompatibilityTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file CompatibilityTable.h
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief Compatibility Table is used to determine if the current device is compatible with CRSF for Arduino.
* @version 0.3.2
* @date 2023-06-03
* @version 0.3.3
* @date 2023-07-18
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion src/library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
"name": "CRSFforArduino",
"version": "0.3.2",
"version": "0.3.3",
"description": "Arduino library for Crossfire protocol",
"keywords": [
"adafruit",
Expand Down
4 changes: 2 additions & 2 deletions src/src/main_rc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file main_rc.cpp
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief This file demonstrates the full capabilities of CRSF for Arduino.
* @version 0.3.2
* @date 2023-06-03
* @version 0.3.3
* @date 2023-07-18
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down

0 comments on commit 436459a

Please sign in to comment.