Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devboard): Add support for Teensy 3.x and 4.x #37

Merged
merged 15 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ 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
**NB:** The entire Teensy 3.x line is discontinued by the manufacturer, and is _not_ recommended for new projects.
- Teensy 4.x

Compatibility with other microcontroller boards may be added in future, if there is demand for it. Keep in mind that this will be subject to hardware limitations of the host microcontroller itself.

Expand Down
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.4.0
* @date 2023-08-01
* @version 0.5.0
* @date 2023-09-17
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
4 changes: 2 additions & 2 deletions examples/gps_telemetry/gps_telemetry.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file gps_telemetry.ino
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief This example sketch demonstrates how to pass data from a GPS module into CRSF for Arduino & transmit it as telemetry.
* @version 0.4.0
* @date 2023-08-01
* @version 0.5.0
* @date 2023-09-17
*
* @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.4.0
version=0.5.0
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
54 changes: 54 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,60 @@ debug_tool = ${common_samd51.debugger}
lib_deps = ${common_samd51.lib_deps}
upload_protocol = ${common_samd51.sketch_upload_protocol}

; Teensy Boards
[env:teensy_30]
platform = teensy
board = teensy30
build_flags =
-DUSE_ABSTRACTION_LAYER
-DCRC_OPTIMISATION_LEVEL=0

[env:teensy_31]
platform = teensy
board = teensy31
build_flags =
-DUSE_ABSTRACTION_LAYER
-DCRC_OPTIMISATION_LEVEL=0

[env:teensy_32]
# I am pretty much having to fake Teensy 3.2 support here,
# because PlatformIO lumps Teensy 3.1 and Teensy 3.2 together as one board.
# Yet, the Arduino IDE sees Teensy 3.1 and Teensy 3.2 as two separate boards.
# This can cause a "false negative" in the Compatibility Table with Teensy 3.2.
platform = teensy
board = teensy31
build_flags =
-DUSE_ABSTRACTION_LAYER
-DCRC_OPTIMISATION_LEVEL=0

[env:teensy_35]
platform = teensy
board = teensy35
build_flags =
-DUSE_ABSTRACTION_LAYER
-DCRC_OPTIMISATION_LEVEL=0

[env:teensy_36]
platform = teensy
board = teensy36
build_flags =
-DUSE_ABSTRACTION_LAYER
-DCRC_OPTIMISATION_LEVEL=0

[env:teensy_40]
platform = teensy
board = teensy40
build_flags =
-DUSE_ABSTRACTION_LAYER
-DCRC_OPTIMISATION_LEVEL=0

[env:teensy_41]
platform = teensy
board = teensy41
build_flags =
-DUSE_ABSTRACTION_LAYER
-DCRC_OPTIMISATION_LEVEL=0

[platformio]
default_envs = adafruit_metro_m0
include_dir = src/include
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.4.0
* @date 2023-08-08
* @version 0.5.0
* @date 2023-09-17
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
4 changes: 2 additions & 2 deletions src/lib/CRSFforArduino/src/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.4.0
* @date 2023-08-08
* @version 0.5.0
* @date 2023-09-17
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
4 changes: 2 additions & 2 deletions src/lib/CRSFforArduino/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 CRSF for Arduino facilitates the use of ExpressLRS RC receivers in Arduino projects.
* @version 0.4.0
* @date 2023-08-08
* @version 0.5.0
* @date 2023-09-17
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief This is the implementation of the Compatibility Table.
* It is used to determine if the target development board is compatible with CRSF for Arduino.
* @version 0.4.0
* @date 2023-08-08
* @version 0.5.0
* @date 2023-09-17
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down Expand Up @@ -175,6 +175,55 @@ namespace hal
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif // ARDUINO_SAMD_ADAFRUIT

#elif defined(CORE_TEENSY)
#if defined(__MK20DX128__)
#if defined(ARDUINO_TEENSY30)
device.type.devboard = DEVBOARD_TEENSY_30;
#pragma message "Teensy 3.x is not recommended for new projects. Please consider using Teensy 4.0 or later instead."
#else
#warning "Devboard not supported. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif
#elif defined(__MK20DX256__)
/* PlatformIO treats Teensy 3.1 and Teensy 3.2 as the same board, but the Arduino IDE treats them
as two separate boards. To prevent a false negative, check for both boards. */
#if defined(ARDUINO_TEENSY31) || defined(ARDUINO_TEENSY32)
device.type.devboard = DEVBOARD_TEENSY_31_32;
#pragma message "Teensy 3.x is not recommended for new projects. Please consider using Teensy 4.0 or later instead."
#else // Incompatible devboards
#warning "Devboard not supported. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif
#elif defined(__MK64FX512__)
#if defined(ARDUINO_TEENSY35)
device.type.devboard = DEVBOARD_TEENSY_35;
#pragma message "Teensy 3.x is not recommended for new projects. Please consider using Teensy 4.0 or later instead."
#else // Incompatible devboards
#warning "Devboard not supported. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif
#elif defined(__MK66FX1M0__)
#if defined(ARDUINO_TEENSY36)
device.type.devboard = DEVBOARD_TEENSY_36;
#pragma message "Teensy 3.x is not recommended for new projects. Please consider using Teensy 4.0 or later instead."
#else // Incompatible devboards
#warning "Devboard not supported. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
#endif
#elif defined(__IMXRT1062__)
#if defined(ARDUINO_TEENSY40)
device.type.devboard = DEVBOARD_TEENSY_40;
#elif defined(ARDUINO_TEENSY41)
device.type.devboard = DEVBOARD_TEENSY_41;
#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

#else // Unsupported architecture
#error "Unsupported architecture. Please check the compatibility table."
device.type.devboard = DEVBOARD_IS_INCOMPATIBLE;
Expand All @@ -197,7 +246,26 @@ namespace hal
*/
bool CompatibilityTable::isDevboardCompatible(const char *name)
{
return strcmp(name, deviceNames[DEVBOARD_IS_INCOMPATIBLE]) != 0 ? true : false;
// Debug.
Serial.print("[Compatibility Table | DEBUG]: Board is ");

if (strcmp(name, deviceNames[DEVBOARD_IS_INCOMPATIBLE]) == 0)
{
// Debug.
Serial.println("incompatible.");

return false;
}

else
{
// Debug.
Serial.println("compatible.");

return true;
}

// return strcmp(name, deviceNames[DEVBOARD_IS_INCOMPATIBLE]) != 0 ? true : false;
}

/**
Expand All @@ -207,11 +275,18 @@ namespace hal
*/
const char *CompatibilityTable::getDevboardName()
{
if (device.type.devboard > DEVBOARD_COUNT)
if (device.type.devboard >= DEVBOARD_COUNT)
{
// Debug.
Serial.println("\r\n[Compatibility Table | FATAL ERROR]: Board index is out of bounds.");

return deviceNames[DEVBOARD_IS_INCOMPATIBLE];
}

// Debug.
Serial.print("\r\n[Compatibility Table | DEBUG]: Board is ");
Serial.println(deviceNames[device.type.devboard]);

return deviceNames[device.type.devboard];
}
} // namespace hal
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 This is the Compatibility Table header file.
* @version 0.4.0
* @date 2023-08-08
* @version 0.5.0
* @date 2023-09-17
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down Expand Up @@ -79,6 +79,14 @@ namespace hal
// Seeed Studio boards.
DEVBOARD_SEEEDSTUDIO_XIAO_M0,

// Teensy boards.
DEVBOARD_TEENSY_30,
DEVBOARD_TEENSY_31_32,
DEVBOARD_TEENSY_35,
DEVBOARD_TEENSY_36,
DEVBOARD_TEENSY_40,
DEVBOARD_TEENSY_41,

DEVBOARD_COUNT
} ct_devboards_t;

Expand Down Expand Up @@ -119,6 +127,12 @@ namespace hal
"Arduino MKRZERO",
"Arduino Nano 33 IoT",
"Arduino Zero",
"Seeed Studio Xiao SAMD21"};
"Seeed Studio Xiao SAMD21",
"Teensy 3.0",
"Teensy 3.1/3.2",
"Teensy 3.5",
"Teensy 3.6",
"Teensy 4.0",
"Teensy 4.1"};
};
} // namespace hal
35 changes: 33 additions & 2 deletions src/lib/CRSFforArduino/src/Hardware/DevBoards/DevBoards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file DevBoards.cpp
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief This is the DevBoards implementation file. It is used to configure CRSF for Arduino for specific development boards.
* @version 0.4.0
* @date 2023-08-08
* @version 0.5.0
* @date 2023-09-17
*
* @copyright Copyright (c) 2023, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
Expand Down Expand Up @@ -84,25 +84,46 @@ namespace hal
if (uart_port != nullptr)
{
uart_port->~Uart();

// Debug.
Serial.println("[Development Board | DEBUG]: Deleted previous UART port.");
}

// Set the UART port.
switch (port)
{
case 0:
uart_port = &Serial1;

// Debug.
Serial.println("[Development Board | DEBUG]: Using Serial1.");
break;

case 1: // TO-DO: Fix this.
uart_port = new Uart(&sercom2, rx, tx, SERCOM_RX_PAD_1, UART_TX_PAD_0);

// Debug.
Serial.println("[Development Board | DEBUG]: Using Serial2.");
break;

default:
uart_port = nullptr;

// Debug.
Serial.println("[Development Board | ERROR]: No UART port was defined.");
break;
}
#elif defined(TEENSYDUINO)
// 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.");
#else
uart_port = nullptr;

// Debug.
Serial.println("[Development Board | ERROR]: No UART port was defined.");
#endif
}

Expand All @@ -111,7 +132,9 @@ namespace hal
// If UART port was defined beforehand, delete it.
if (uart_port != nullptr)
{
#ifndef TEENSYDUINO
uart_port->~Uart();
#endif
}
}

Expand Down Expand Up @@ -157,6 +180,14 @@ namespace hal
return uart_port->write(c);
}

#if defined(TEENSYDUINO)
size_t DevBoards::write(const uint8_t *buffer, size_t size)
{
// Write a buffer to the UART port.
return uart_port->write(buffer, size);
}
#endif

DevBoards::operator bool()
{
// Return if the UART port is available.
Expand Down
Loading