Skip to content

Commit 981a4aa

Browse files
committed
Add src/components/uart/serial_config.h
1 parent f961f9a commit 981a4aa

File tree

7 files changed

+46
-26
lines changed

7 files changed

+46
-26
lines changed

src/components/gps/controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bool GPSController::AddGPS(HardwareSerial *serial, uint32_t baudrate,
107107
return true;
108108
}
109109

110-
#ifdef HAS_SW_SERIAL
110+
#if HAS_SW_SERIAL
111111
/*!
112112
* @brief Adds a GPS software serial instance to the controller.
113113
* @param serial Pointer to the SoftwareSerial instance for GPS communication.

src/components/gps/controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
#ifndef WS_GPS_CONTROLLER_H
1717
#define WS_GPS_CONTROLLER_H
18+
#include "../uart/serial_config.h"
1819
#include "Wippersnapper_V2.h"
1920
#include "hardware.h"
2021
#include "model.h"
@@ -33,7 +34,7 @@ class GPSController {
3334
~GPSController();
3435
bool AddGPS(HardwareSerial *serial, uint32_t baudrate,
3536
wippersnapper_gps_GPSConfig *gps_config);
36-
#ifdef HAS_SW_SERIAL
37+
#if HAS_SW_SERIAL
3738
bool AddGPS(SoftwareSerial *serial, uint32_t baudrate,
3839
wippersnapper_gps_GPSConfig *gps_config);
3940
#endif // HAS_SW_SERIAL

src/components/gps/hardware.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
8383
if (_iface_type == GPS_IFACE_UART_HW ||
8484
_iface_type == GPS_IFACE_UART_SW) {
8585
// Flush the RX/TX buffers before sending
86-
#ifdef HAS_SW_SERIAL
86+
#if HAS_SW_SERIAL
8787
_sw_serial->flush();
8888
while (_sw_serial->available() > 0) {
8989
_sw_serial->read();
@@ -136,7 +136,7 @@ bool GPSHardware::SetInterface(HardwareSerial *serial, uint32_t baudrate) {
136136
return true;
137137
}
138138

139-
#ifdef HAS_SW_SERIAL
139+
#if HAS_SW_SERIAL
140140
/*!
141141
* @brief Sets a UART software serial interface for the GPS controller.
142142
* @param serial
@@ -286,7 +286,7 @@ bool GPSHardware::DetectMtkUart() {
286286
}
287287

288288
// Clear the tx and rx buffers before sending the command
289-
#ifdef HAS_SW_SERIAL
289+
#if HAS_SW_SERIAL
290290
_sw_serial->flush();
291291
while (_sw_serial->available() > 0) {
292292
_sw_serial->read();
@@ -301,7 +301,7 @@ bool GPSHardware::DetectMtkUart() {
301301
// Query MediaTek firmware version
302302
uint16_t timeout = MTK_QUERY_FW_TIMEOUT;
303303

304-
#ifdef HAS_SW_SERIAL
304+
#if HAS_SW_SERIAL
305305
while (_sw_serial->available() < MAX_NEMA_SENTENCE_LEN && timeout--) {
306306
delay(1);
307307
}
@@ -319,7 +319,7 @@ bool GPSHardware::DetectMtkUart() {
319319
size_t buf_len = MAX_NEMA_SENTENCE_LEN * 4; // +3 for \r\n and null terminator
320320
char buffer[buf_len];
321321
size_t available;
322-
#ifdef HAS_SW_SERIAL
322+
#if HAS_SW_SERIAL
323323
available = _sw_serial->available();
324324
#else
325325
available = _hw_serial->available();
@@ -331,7 +331,7 @@ bool GPSHardware::DetectMtkUart() {
331331
WS_DEBUG_PRINT(" bytes, reading ");
332332
WS_DEBUG_PRINTLN(bytes_to_read);
333333
for (size_t i = 0; i < bytes_to_read; i++) {
334-
#ifdef HAS_SW_SERIAL
334+
#if HAS_SW_SERIAL
335335
buffer[i] = _sw_serial->read();
336336
#else
337337
buffer[i] = _hw_serial->read();
@@ -346,7 +346,7 @@ bool GPSHardware::DetectMtkUart() {
346346
}
347347

348348
// Attempt to use Adafruit_GPS
349-
#ifdef HAS_SW_SERIAL
349+
#if HAS_SW_SERIAL
350350
_ada_gps = new Adafruit_GPS(_sw_serial);
351351
#else
352352
_ada_gps = new Adafruit_GPS(_hw_serial);

src/components/gps/hardware.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class GPSHardware {
7070
~GPSHardware();
7171
bool begin();
7272
bool SetInterface(HardwareSerial *serial, uint32_t baudrate);
73-
#ifdef HAS_SW_SERIAL
73+
#if HAS_SW_SERIAL
7474
bool SetInterface(SoftwareSerial *serial, uint32_t baudrate);
7575
#endif // HAS_SW_SERIAL
7676
bool SetInterface(TwoWire *wire);
@@ -130,7 +130,7 @@ class GPSHardware {
130130
GpsInterfaceType _iface_type; ///< Type of interface used by GPS
131131
GpsDriverType _driver_type; ///< Type of GPS driver used by GPS
132132
HardwareSerial *_hw_serial = nullptr; ///< Optional HardwareSerial instance
133-
#ifdef HAS_SW_SERIAL
133+
#if HAS_SW_SERIAL
134134
SoftwareSerial *_sw_serial = nullptr; ///< Optional SoftwareSerial instance
135135
#endif // HAS_SW_SERIAL
136136
TwoWire *_wire = nullptr; ///< Optional TwoWire instance

src/components/uart/drivers/drvUartPm25.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class drvUartPm25 : public drvUartBase {
9090

9191
delay(1000); // Wait for the sensor to boot
9292

93-
#ifdef HAS_SW_SERIAL
93+
#if HAS_SW_SERIAL
9494
return _pm25->begin_UART(_sw_serial);
9595
#else
9696
return _pm25->begin_UART(_hw_serial);

src/components/uart/hardware.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,13 @@
1515
#ifndef WS_UART_HARDWARE_H
1616
#define WS_UART_HARDWARE_H
1717
#include "Wippersnapper_V2.h"
18+
#include "serial_config.h"
1819
#include <Arduino.h>
1920
#include <HardwareSerial.h>
2021
#ifdef ARDUINO_ARCH_RP2040
2122
#include <SerialUART.h>
2223
#endif
2324

24-
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_SAMD) || \
25-
defined(ARDUINO_ARCH_ESP8266)
26-
// SAMD supports native Arduino SoftwareSerial API
27-
// ESP8266 supports SoftwareSerial in the ESP8266 Arduino core
28-
// RP2040/RP2350 supports a wrapper around SoftwareSerial and emulation via
29-
// PIOUART (see:
30-
// https://arduino-pico.readthedocs.io/en/latest/piouart.html#softwareserial-emulation)
31-
#include <SoftwareSerial.h>
32-
#define HAS_SW_SERIAL 1 ///< Indicates that the board supports SoftwareSerial
33-
#else
34-
#define HAS_SW_SERIAL \
35-
0 ///< Indicates that the board DOES NOT support SoftwareSerial
36-
#endif
37-
3825
/*!
3926
@brief Interface for interacting with the UART hardware.
4027
*/

src/components/uart/serial_config.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*!
2+
* @file src/components/uart/serial_config.h
3+
*
4+
* Serial configuration definitions for WipperSnapper components.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2025 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WS_UART_SERIAL_CONFIG_H
16+
#define WS_UART_SERIAL_CONFIG_H
17+
18+
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_SAMD) || \
19+
defined(ARDUINO_ARCH_ESP8266)
20+
// SAMD supports native Arduino SoftwareSerial API
21+
// ESP8266 supports SoftwareSerial in the ESP8266 Arduino core
22+
// RP2040/RP2350 supports a wrapper around SoftwareSerial and emulation via
23+
// PIOUART (see:
24+
// https://arduino-pico.readthedocs.io/en/latest/piouart.html#softwareserial-emulation)
25+
#include <SoftwareSerial.h>
26+
#define HAS_SW_SERIAL 1 ///< Indicates that the board supports SoftwareSerial
27+
#else
28+
#define HAS_SW_SERIAL \
29+
0 ///< Indicates that the board DOES NOT support SoftwareSerial
30+
#endif
31+
32+
#endif // WS_UART_SERIAL_CONFIG_H

0 commit comments

Comments
 (0)