Skip to content
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# PlatformIO specific files
test/README
examples/platformio/cfa_code_test.cpp
examples/platformio/hac_driver_test.cpp
examples/platformio/hw_multi_mutex_test.cpp
examples/platformio/hw_mutex_test.cpp

# Template files for CRSF for Arduino
templates/
Expand Down
4 changes: 2 additions & 2 deletions src/CFA_Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ See https://semver.org/ for more information. */
#define CRSFFORARDUINO_VERSION "1.1.0"
#define CRSFFORARDUINO_VERSION_DATE "2024-3-8"
#define CRSFFORARDUINO_VERSION_MAJOR 1
#define CRSFFORARDUINO_VERSION_MINOR 0
#define CRSFFORARDUINO_VERSION_PATCH 1
#define CRSFFORARDUINO_VERSION_MINOR 1
#define CRSFFORARDUINO_VERSION_PATCH 0

/* Failsafe Options
- CRSF_FAILSAFE_LQI_THRESHOLD: The minimum LQI value for the receiver to be considered connected.
Expand Down
13 changes: 11 additions & 2 deletions src/CRSFforArduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ namespace sketchLayer
* @brief Construct a new CRSFforArduino object.
*
*/
CRSFforArduino::CRSFforArduino()
CRSFforArduino::CRSFforArduino() : SerialReceiver()
{
}

/**
* @brief Construct a new CRSFforArduino object with the specified serial port.
*
* @param serialPort
*/
CRSFforArduino::CRSFforArduino(HardwareSerial *serialPort) : SerialReceiver(serialPort)
{
}

Expand All @@ -44,7 +53,7 @@ namespace sketchLayer
* @param rxPin
* @param txPin
*/
CRSFforArduino::CRSFforArduino(HardwareSerial *serialPort)
CRSFforArduino::CRSFforArduino(HardwareSerial *serialPort, int rxPin, int txPin) : SerialReceiver(serialPort, rxPin, txPin)
{
}

Expand Down
1 change: 1 addition & 0 deletions src/CRSFforArduino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace sketchLayer
public:
CRSFforArduino();
CRSFforArduino(HardwareSerial *serialPort);
CRSFforArduino(HardwareSerial *serialPort, int rxPin, int txPin);
~CRSFforArduino();
bool begin();
void end();
Expand Down
58 changes: 58 additions & 0 deletions src/SerialReceiver/SerialReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ namespace serialReceiverLayer
#elif defined(HAVE_HWSERIAL3)
_uart = &Serial3;
#endif
#elif defined(ARDUINO_ARCH_ESP32)
_uart = &Serial1;

#if defined(D0)
_rxPin = D0;
#else
_rxPin = 0;
#endif

#if defined(D1)
_txPin = D1;
#else
_txPin = 1;
#endif
#else
_uart = &Serial1;
#endif
Expand All @@ -62,6 +76,43 @@ namespace serialReceiverLayer
{
_uart = hwUartPort;

#if defined(ARDUINO_ARCH_ESP32)
#if defined(D0)
_rxPin = D0;
#else
_rxPin = 0;
#endif

#if defined(D1)
_txPin = D1;
#else
_txPin = 1;
#endif
#endif

#if CRSF_RC_ENABLED > 0
_rcChannels = new rcChannels_t;
_rcChannels->valid = false;
_rcChannels->failsafe = false;
memset(_rcChannels->value, 0, sizeof(_rcChannels->value));
#if CRSF_FLIGHTMODES_ENABLED > 0
_flightModes = new flightMode_t[FLIGHT_MODE_COUNT];
#endif
#endif
}

SerialReceiver::SerialReceiver(HardwareSerial *hwUartPort, int8_t rxPin, int8_t txPin)
{
_uart = hwUartPort;

#if defined(ARDUINO_ARCH_ESP32)
_rxPin = rxPin;
_txPin = txPin;
#else
(void)rxPin;
(void)txPin;
#endif

#if CRSF_RC_ENABLED > 0
_rcChannels = new rcChannels_t;
_rcChannels->valid = false;
Expand All @@ -77,6 +128,9 @@ namespace serialReceiverLayer
{
_uart = nullptr;

_rxPin = -1;
_txPin = -1;

#if CRSF_RC_ENABLED > 0
delete _rcChannels;
_rcChannels = nullptr;
Expand Down Expand Up @@ -155,7 +209,11 @@ namespace serialReceiverLayer
crsf = new CRSF();
crsf->begin();
crsf->setFrameTime(BAUD_RATE, 10);
#if defined(ARDUINO_ARCH_ESP32)
_uart->begin(BAUD_RATE, SERIAL_8N1, _rxPin, _txPin);
#else
_uart->begin(BAUD_RATE);
#endif

#if CRSF_TELEMETRY_ENABLED > 0
telemetry = new Telemetry();
Expand Down
4 changes: 4 additions & 0 deletions src/SerialReceiver/SerialReceiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace serialReceiverLayer
public:
SerialReceiver();
SerialReceiver(HardwareSerial *hwUartPort);
SerialReceiver(HardwareSerial *hwUartPort, int8_t rxPin, int8_t txPin);
virtual ~SerialReceiver();

bool begin();
Expand Down Expand Up @@ -116,6 +117,9 @@ namespace serialReceiverLayer
CRSF *crsf;
HardwareSerial *_uart;

int8_t _rxPin = -1;
int8_t _txPin = -1;

#if CRSF_TELEMETRY_ENABLED > 0
Telemetry *telemetry;
#endif
Expand Down