Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make mbed core more compatible with older sketches #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extern analogin_config_t adcCurrentConfig;
#include "Serial.h"
#if defined(SERIAL_CDC)
#define Serial _UART_USB_
#define SerialUSB _UART_USB_
#else
#define Serial _UART1_
#endif
Expand Down
28 changes: 14 additions & 14 deletions cores/arduino/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void UART::on_rx() {
void UART::end() {
#if defined(SERIAL_CDC)
if (is_usb) {
return SerialUSB.end();
return _SerialUSB.end();
}
#endif
if (_serial->obj != NULL) {
Expand All @@ -139,7 +139,7 @@ void UART::end() {
int UART::available() {
#if defined(SERIAL_CDC)
if (is_usb) {
return SerialUSB.available();
return _SerialUSB.available();
}
#endif
return rx_buffer.available();
Expand All @@ -148,7 +148,7 @@ int UART::available() {
int UART::peek() {
#if defined(SERIAL_CDC)
if (is_usb) {
return SerialUSB.peek();
return _SerialUSB.peek();
}
#endif
return rx_buffer.peek();
Expand All @@ -157,7 +157,7 @@ int UART::peek() {
int UART::read() {
#if defined(SERIAL_CDC)
if (is_usb) {
return SerialUSB.read();
return _SerialUSB.read();
}
#endif
return rx_buffer.read_char();
Expand All @@ -170,7 +170,7 @@ void UART::flush() {
size_t UART::write(uint8_t c) {
#if defined(SERIAL_CDC)
if (is_usb) {
return SerialUSB.write(c);
return _SerialUSB.write(c);
}
#endif
while (!_serial->obj->writeable()) {}
Expand All @@ -181,7 +181,7 @@ size_t UART::write(uint8_t c) {
size_t UART::write(const uint8_t* c, size_t len) {
#if defined(SERIAL_CDC)
if (is_usb) {
return SerialUSB.write(c, len);
return _SerialUSB.write(c, len);
}
#endif
while (!_serial->obj->writeable()) {}
Expand All @@ -197,7 +197,7 @@ void UART::block_tx(int _a) {
UART::operator bool() {
#if defined(SERIAL_CDC)
if (is_usb) {
return SerialUSB;
return _SerialUSB;
}
#endif
return _serial != NULL && _serial->obj != NULL;
Expand All @@ -206,7 +206,7 @@ UART::operator bool() {
UART::operator mbed::FileHandle*() {
#if defined(SERIAL_CDC)
if (is_usb) {
return &SerialUSB;
return &_SerialUSB;
}
#endif
}
Expand All @@ -215,37 +215,37 @@ UART::operator mbed::FileHandle*() {
#if defined(SERIAL_CDC)
uint32_t UART::baud() {
if (is_usb) {
return SerialUSB.baud();
return _SerialUSB.baud();
}
return 0;
}
uint8_t UART::stopbits() {
if (is_usb) {
return SerialUSB.stopbits();
return _SerialUSB.stopbits();
}
return 0;
}
uint8_t UART::paritytype() {
if (is_usb) {
return SerialUSB.paritytype();
return _SerialUSB.paritytype();
}
return 0;
}
uint8_t UART::numbits() {
if (is_usb) {
return SerialUSB.numbits();
return _SerialUSB.numbits();
}
return 0;
}
bool UART::dtr() {
if (is_usb) {
return SerialUSB.dtr();
return _SerialUSB.dtr();
}
return false;
}
bool UART::rts() {
if (is_usb) {
return SerialUSB.rts();
return _SerialUSB.rts();
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/USB/PluggableUSBSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,6 @@ class USBSerial: public USBCDC, public ::mbed::Stream, public HardwareSerial {
};
}

extern arduino::USBSerial SerialUSB;
extern arduino::USBSerial _SerialUSB;

#endif
4 changes: 2 additions & 2 deletions cores/arduino/USB/USBSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void waitForPortClose() {
// wait for DTR be 0 (port closed) and timeout to be over
long start = millis();
static const int WAIT_TIMEOUT = 200;
while (SerialUSB.connected() || (millis() - start) < WAIT_TIMEOUT) {
while (_SerialUSB.connected() || (millis() - start) < WAIT_TIMEOUT) {
// the delay is needed to handle other "concurrent" IRQ events
delay(1);
}
Expand Down Expand Up @@ -122,6 +122,6 @@ bool USBSerial::connected()
return _terminal_connected;
}

USBSerial SerialUSB(false);
USBSerial _SerialUSB(false);

#endif
3 changes: 3 additions & 0 deletions libraries/Wire/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class MbedI2C : public HardwareI2C
virtual void onRequest(void(*)(void));

virtual size_t write(uint8_t data);
virtual size_t write(int data) {
return write ((uint8_t)data);
};
virtual size_t write(const uint8_t* data, int len);
using Print::write;
virtual int read();
Expand Down
6 changes: 3 additions & 3 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ build.zip.pattern={recipe.size.pattern}
# -----------------------

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_ARCH_MBED {build.library_discovery_phase_flag} {build.extra_flags} {compiler.c.extra_flags} "-I{build.core.path}/api/deprecated" {includes} "-iprefix{build.core.path}" "@{compiler.mbed.includes}" -o "{object_file}" "{source_file}"
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_ARCH_MBED {build.library_discovery_phase_flag} {build.extra_flags} {compiler.c.extra_flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" {includes} "-iprefix{build.core.path}" "@{compiler.mbed.includes}" -o "{object_file}" "{source_file}"

## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_ARCH_MBED {build.library_discovery_phase_flag} {includes} {build.extra_flags} {compiler.cpp.extra_flags} "-I{build.core.path}/api/deprecated" "-iprefix{build.core.path}" "@{compiler.mbed.includes}" "{source_file}" -o "{object_file}"
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_ARCH_MBED {build.library_discovery_phase_flag} {includes} {build.extra_flags} {compiler.cpp.extra_flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" "-iprefix{build.core.path}" "@{compiler.mbed.includes}" "{source_file}" -o "{object_file}"

## Compile asm files
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_ARCH_MBED {includes} {build.extra_flags} {compiler.cpp.extra_flags} "-I{build.core.path}/api/deprecated" "-iprefix{build.core.path}" "@{compiler.mbed.includes}" "{source_file}" -o "{object_file}"
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_ARCH_MBED {includes} {build.extra_flags} {compiler.cpp.extra_flags} "-I{build.core.path}/api/deprecated" "-I{build.core.path}/api/deprecated-avr-comp" "-iprefix{build.core.path}" "@{compiler.mbed.includes}" "{source_file}" -o "{object_file}"

## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
Expand Down