Skip to content

Commit 5dd679e

Browse files
committed
Fix REDIRECT_STDOUT_TO macro
1 parent f757d6e commit 5dd679e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

cores/arduino/Serial.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ UART::operator bool() {
203203
return _serial != NULL && _serial->obj != NULL;
204204
}
205205

206+
UART::operator mbed::FileHandle*() {
207+
#if defined(SERIAL_CDC)
208+
if (is_usb) {
209+
return &SerialUSB;
210+
}
211+
#endif
212+
}
213+
214+
206215
#if defined(SERIAL_CDC)
207216
uint32_t UART::baud() {
208217
if (is_usb) {

cores/arduino/Serial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Arduino.h"
2525
#include "api/HardwareSerial.h"
2626
#include "PinNames.h"
27+
#include <platform/FileHandle.h>
2728

2829
#ifdef __cplusplus
2930

@@ -52,6 +53,7 @@ class UART : public HardwareSerial {
5253
size_t write(const uint8_t*, size_t);
5354
using Print::write; // pull in write(str) and write(buf, size) from Print
5455
operator bool();
56+
operator mbed::FileHandle*(); // exposes the internal mbed object
5557

5658
#if defined(SERIAL_CDC)
5759
uint32_t baud();

cores/arduino/macros.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <Arduino.h>
2727
#include <PinNames.h>
28+
#include <platform/FileHandle.h>
2829

2930
// this is needed for backwards compatibility
3031
#define digitalPinToInterrupt(P) (P)
@@ -39,9 +40,9 @@
3940

4041
#define REDIRECT_STDOUT_TO(stream) namespace mbed { \
4142
FileHandle *mbed_override_console(int fd) { \
42-
return &stream; \
43+
return static_cast<mbed::FileHandle*>(stream); \
4344
} \
4445
FileHandle *mbed_target_override_console(int fd) { \
45-
return &stream; \
46+
return static_cast<mbed::FileHandle*>(stream); \
4647
} \
4748
}

0 commit comments

Comments
 (0)