Skip to content

Commit cc1ff90

Browse files
Allow specifying NUM_SERIAL_PORTS explicitly
For AVR-based unittests, this was autodetected based on the registers defined in `avr/io.h`, just like on an actual build. For non-AVR targets, `NUM_SERIAL_PORTS` would always be 0. Now, any existing define on the compiler commandline (i.e. from `.arduino-ci.yaml`) takes precedence over any autodetected value.
1 parent 2617508 commit cc1ff90

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

cpp/arduino/Godmode.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ unsigned long micros();
2020

2121
#define MOCK_PINS_COUNT 256
2222

23-
#if defined(UBRR3H)
24-
#define NUM_SERIAL_PORTS 4
25-
#elif defined(UBRR2H)
26-
#define NUM_SERIAL_PORTS 3
27-
#elif defined(UBRR1H)
28-
#define NUM_SERIAL_PORTS 2
29-
#elif defined(UBRRH) || defined(UBRR0H)
30-
#define NUM_SERIAL_PORTS 1
31-
#else
32-
#define NUM_SERIAL_PORTS 0
23+
#if (!defined NUM_SERIAL_PORTS)
24+
#if defined(UBRR3H)
25+
#define NUM_SERIAL_PORTS 4
26+
#elif defined(UBRR2H)
27+
#define NUM_SERIAL_PORTS 3
28+
#elif defined(UBRR1H)
29+
#define NUM_SERIAL_PORTS 2
30+
#elif defined(UBRRH) || defined(UBRR0H)
31+
#define NUM_SERIAL_PORTS 1
32+
#else
33+
#define NUM_SERIAL_PORTS 0
34+
#endif
3335
#endif
3436

3537
class GodmodeState {

cpp/arduino/HardwareSerial.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ class HardwareSerial : public StreamTape
4444
operator bool() { return true; }
4545
};
4646

47-
#if defined(UBRRH) || defined(UBRR0H)
47+
#if NUM_SERIAL_PORTS >= 1
4848
extern HardwareSerial Serial;
4949
#define HAVE_HWSERIAL0
5050
#endif
51-
#if defined(UBRR1H)
51+
#if NUM_SERIAL_PORTS >= 2
5252
extern HardwareSerial Serial1;
5353
#define HAVE_HWSERIAL1
5454
#endif
55-
#if defined(UBRR2H)
55+
#if NUM_SERIAL_PORTS >= 3
5656
extern HardwareSerial Serial2;
5757
#define HAVE_HWSERIAL2
5858
#endif
59-
#if defined(UBRR3H)
59+
#if NUM_SERIAL_PORTS >= 4
6060
extern HardwareSerial Serial3;
6161
#define HAVE_HWSERIAL3
6262
#endif

0 commit comments

Comments
 (0)