Skip to content

Commit 26952d5

Browse files
authored
fix(targets): Refine ESP32 compatibility (#99)
1 parent 4fe3827 commit 26952d5

File tree

6 files changed

+79
-4
lines changed

6 files changed

+79
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# PlatformIO specific files
88
test/README
99
examples/platformio/cfa_code_test.cpp
10+
examples/platformio/hac_driver_test.cpp
11+
examples/platformio/hw_multi_mutex_test.cpp
12+
examples/platformio/hw_mutex_test.cpp
1013

1114
# Template files for CRSF for Arduino
1215
templates/

src/CFA_Config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ See https://semver.org/ for more information. */
3939
#define CRSFFORARDUINO_VERSION "1.1.0"
4040
#define CRSFFORARDUINO_VERSION_DATE "2024-3-8"
4141
#define CRSFFORARDUINO_VERSION_MAJOR 1
42-
#define CRSFFORARDUINO_VERSION_MINOR 0
43-
#define CRSFFORARDUINO_VERSION_PATCH 1
42+
#define CRSFFORARDUINO_VERSION_MINOR 1
43+
#define CRSFFORARDUINO_VERSION_PATCH 0
4444

4545
/* Failsafe Options
4646
- CRSF_FAILSAFE_LQI_THRESHOLD: The minimum LQI value for the receiver to be considered connected.

src/CRSFforArduino.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ namespace sketchLayer
3434
* @brief Construct a new CRSFforArduino object.
3535
*
3636
*/
37-
CRSFforArduino::CRSFforArduino()
37+
CRSFforArduino::CRSFforArduino() : SerialReceiver()
38+
{
39+
}
40+
41+
/**
42+
* @brief Construct a new CRSFforArduino object with the specified serial port.
43+
*
44+
* @param serialPort
45+
*/
46+
CRSFforArduino::CRSFforArduino(HardwareSerial *serialPort) : SerialReceiver(serialPort)
3847
{
3948
}
4049

@@ -44,7 +53,7 @@ namespace sketchLayer
4453
* @param rxPin
4554
* @param txPin
4655
*/
47-
CRSFforArduino::CRSFforArduino(HardwareSerial *serialPort)
56+
CRSFforArduino::CRSFforArduino(HardwareSerial *serialPort, int rxPin, int txPin) : SerialReceiver(serialPort, rxPin, txPin)
4857
{
4958
}
5059

src/CRSFforArduino.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace sketchLayer
3737
public:
3838
CRSFforArduino();
3939
CRSFforArduino(HardwareSerial *serialPort);
40+
CRSFforArduino(HardwareSerial *serialPort, int rxPin, int txPin);
4041
~CRSFforArduino();
4142
bool begin();
4243
void end();

src/SerialReceiver/SerialReceiver.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ namespace serialReceiverLayer
4343
#elif defined(HAVE_HWSERIAL3)
4444
_uart = &Serial3;
4545
#endif
46+
#elif defined(ARDUINO_ARCH_ESP32)
47+
_uart = &Serial1;
48+
49+
#if defined(D0)
50+
_rxPin = D0;
51+
#else
52+
_rxPin = 0;
53+
#endif
54+
55+
#if defined(D1)
56+
_txPin = D1;
57+
#else
58+
_txPin = 1;
59+
#endif
4660
#else
4761
_uart = &Serial1;
4862
#endif
@@ -62,6 +76,43 @@ namespace serialReceiverLayer
6276
{
6377
_uart = hwUartPort;
6478

79+
#if defined(ARDUINO_ARCH_ESP32)
80+
#if defined(D0)
81+
_rxPin = D0;
82+
#else
83+
_rxPin = 0;
84+
#endif
85+
86+
#if defined(D1)
87+
_txPin = D1;
88+
#else
89+
_txPin = 1;
90+
#endif
91+
#endif
92+
93+
#if CRSF_RC_ENABLED > 0
94+
_rcChannels = new rcChannels_t;
95+
_rcChannels->valid = false;
96+
_rcChannels->failsafe = false;
97+
memset(_rcChannels->value, 0, sizeof(_rcChannels->value));
98+
#if CRSF_FLIGHTMODES_ENABLED > 0
99+
_flightModes = new flightMode_t[FLIGHT_MODE_COUNT];
100+
#endif
101+
#endif
102+
}
103+
104+
SerialReceiver::SerialReceiver(HardwareSerial *hwUartPort, int8_t rxPin, int8_t txPin)
105+
{
106+
_uart = hwUartPort;
107+
108+
#if defined(ARDUINO_ARCH_ESP32)
109+
_rxPin = rxPin;
110+
_txPin = txPin;
111+
#else
112+
(void)rxPin;
113+
(void)txPin;
114+
#endif
115+
65116
#if CRSF_RC_ENABLED > 0
66117
_rcChannels = new rcChannels_t;
67118
_rcChannels->valid = false;
@@ -77,6 +128,9 @@ namespace serialReceiverLayer
77128
{
78129
_uart = nullptr;
79130

131+
_rxPin = -1;
132+
_txPin = -1;
133+
80134
#if CRSF_RC_ENABLED > 0
81135
delete _rcChannels;
82136
_rcChannels = nullptr;
@@ -155,7 +209,11 @@ namespace serialReceiverLayer
155209
crsf = new CRSF();
156210
crsf->begin();
157211
crsf->setFrameTime(BAUD_RATE, 10);
212+
#if defined(ARDUINO_ARCH_ESP32)
213+
_uart->begin(BAUD_RATE, SERIAL_8N1, _rxPin, _txPin);
214+
#else
158215
_uart->begin(BAUD_RATE);
216+
#endif
159217

160218
#if CRSF_TELEMETRY_ENABLED > 0
161219
telemetry = new Telemetry();

src/SerialReceiver/SerialReceiver.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ namespace serialReceiverLayer
7575
public:
7676
SerialReceiver();
7777
SerialReceiver(HardwareSerial *hwUartPort);
78+
SerialReceiver(HardwareSerial *hwUartPort, int8_t rxPin, int8_t txPin);
7879
virtual ~SerialReceiver();
7980

8081
bool begin();
@@ -116,6 +117,9 @@ namespace serialReceiverLayer
116117
CRSF *crsf;
117118
HardwareSerial *_uart;
118119

120+
int8_t _rxPin = -1;
121+
int8_t _txPin = -1;
122+
119123
#if CRSF_TELEMETRY_ENABLED > 0
120124
Telemetry *telemetry;
121125
#endif

0 commit comments

Comments
 (0)