Skip to content

Add #include "Stream.h" to cores\arduino\USBAPI.h #156

Open
@MichaelJonker

Description

@MichaelJonker

Hello,
I propose to add #include "Stream.h" to the header file hardware\arduino\avr\cores\arduino\USBAPI.h (e.g. following the #include "Arduino.h"), as such the USBAPI.h can be included without relying on Stream.h being included already before.

Motivation:
Currently Stream.h, which is required by USAPI.h, is imported by HardwareSerial.h, which itself is #included by Arduino.h before the #include "USBAPI.h". If the effective inclusion of HardwareSerial.h is disabled (which can be achieved by a #define HardwareSerial_h before inclusion of Arduino.h) then Stream.h is not included leading to an error in the USBAPI.h header.

Context:
When using library HardwareSerialRS485, the loading of HardwareSerial is inhibited with a #define HardwareSerial_h. Until now this #define could be included in the HardwareSerialRS485.h header file (which also has a #include "Stream.h"). As of IDE 1.6.6, the #include "Arduino.h" has been moved to the very first line of the sketch, invalidating this option.

Hence, as an alternative solution, the board.txt mechanism will be used to define RS485 aware boards and adding lines like Arduino_Uno_RS485.compiler.cpp.extra_flags=-DHardwareSerial_h.
This works fine and the loading of HardwareSerial is properly blocked. However, on Atmel32U4 based devices, where USBAPI.h is loaded, the absence of Stream.h is now causing a problem. (Which, for the time being, has to be solved with a not so elegant construction).

Thanks for your attention

Michael Jonker

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions