Skip to content

Commit

Permalink
Fix "__FlashStringHelper is ambiguous" with arduino-pico
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Mar 4, 2023
1 parent 7b2a2be commit 5a12948
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -91,6 +91,12 @@ jobs:
softwareserial: false
index_url: http://dan.drown.org/stm32duino/package_STM32duino_index.json

- core: rp2040:rp2040
board: rp2040:rp2040:rpipico
eeprom: true
softwareserial: true
index_url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
StreamUtils - Change log
========================

HEAD
----

* Fix "__FlashStringHelper is ambiguous" with arduino-pico (issue #30)

1.7.1 (2023/02/26)
-----

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -382,6 +382,7 @@ It has been tested on the following cores:
* [ESP32](https://github.com/espressif/arduino-esp32)
* [ESP8266](https://github.com/esp8266/Arduino)
* [nRF52](https://github.com/adafruit/Adafruit_nRF52_Arduino)
* [RP2040](https://github.com/earlephilhower/arduino-pico)
* [SAMD](https://github.com/arduino/ArduinoCore-samd)
* [STM32 Official](https://github.com/stm32duino/Arduino_Core_STM32)
* [STM32 Roger's Core](https://github.com/rogerclarkmelbourne/Arduino_STM32) (no EEPROM support)
Expand Down
10 changes: 10 additions & 0 deletions extras/test/CMakeLists.txt
Expand Up @@ -51,6 +51,16 @@ target_link_libraries(StreamUtilsTestNrf52 Nrf52Core doctest)

add_test(Nrf52 StreamUtilsTestNrf52)

#
# RP2040
#
add_subdirectory(cores/rp2040)

add_executable(StreamUtilsTestRp2040 ${SOURCES})
target_link_libraries(StreamUtilsTestRp2040 Rp2040Core doctest)

add_test(Rp2040 StreamUtilsTestRp2040)

#
# SAMD
#
Expand Down
3 changes: 3 additions & 0 deletions extras/test/cores/avr/WString.h
Expand Up @@ -7,6 +7,9 @@
#include <ostream>
#include <string>

class __FlashStringHelper;
#define F(s) (reinterpret_cast<const __FlashStringHelper*>(s + 42))

class String : private std::string {
public:
String() {}
Expand Down
6 changes: 0 additions & 6 deletions extras/test/cores/avr/avr/pgmspace.h
Expand Up @@ -3,12 +3,6 @@
#include <stdint.h>
#include <string.h>

class __FlashStringHelper;

inline const __FlashStringHelper* F(const char* s) {
return reinterpret_cast<const __FlashStringHelper*>(s + 42);
}

inline size_t strlen_P(const char* s) {
return strlen(s - 42);
}
Expand Down
10 changes: 10 additions & 0 deletions extras/test/cores/coreapi/Arduino.h
@@ -0,0 +1,10 @@
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
// Copyright Benoit Blanchon 2019-2023
// MIT License

#pragma once

#include "Common.h"
#include "Print.h"
#include "Stream.h"
#include "WString.h"
26 changes: 26 additions & 0 deletions extras/test/cores/coreapi/Client.h
@@ -0,0 +1,26 @@
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
// Copyright Benoit Blanchon 2019-2023
// MIT License

#pragma once

#include "Stream.h"
#include "WString.h"

namespace arduino {

using IPAddress = String;

class Client : public Stream {
public:
virtual int connect(IPAddress ip, uint16_t port) = 0;
virtual int connect(const char *host, uint16_t port) = 0;
virtual uint8_t connected() = 0;
virtual void stop() = 0;
virtual operator bool() = 0;

virtual int read() = 0;
virtual int read(uint8_t *buf, size_t size) = 0;
};

} // namespace arduino
13 changes: 13 additions & 0 deletions extras/test/cores/coreapi/Common.h
@@ -0,0 +1,13 @@
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
// Copyright Benoit Blanchon 2019-2023
// MIT License

#pragma once

#include <time.h>

inline unsigned long millis() {
return static_cast<unsigned long>(time(NULL));
}

inline void yield() {}
52 changes: 52 additions & 0 deletions extras/test/cores/coreapi/Print.h
@@ -0,0 +1,52 @@
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
// Copyright Benoit Blanchon 2019-2023
// MIT License

#pragma once

#include "WString.h"

#include <stdint.h>
#include <cstring>

namespace arduino {

struct Print {
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
virtual size_t write(uint8_t data) = 0;
virtual void flush() {}

virtual int availableForWrite() {
return 0;
}

size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}

size_t print(const String &s) {
return write(s.c_str(), s.length());
}

size_t print(const char *s) {
return write(s, std::strlen(s));
}

size_t println() {
return 0;
}

template <typename T>
size_t print(const T &value) {
return print(String(value));
}

template <typename T>
size_t println(const T &value) {
return print(value);
}
};

} // namespace arduino

using namespace arduino;
40 changes: 40 additions & 0 deletions extras/test/cores/coreapi/Stream.h
@@ -0,0 +1,40 @@
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
// Copyright Benoit Blanchon 2019-2023
// MIT License

#pragma once

#include "Print.h"

namespace arduino {

struct Stream : Print {
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;

size_t readBytes(char *buffer, size_t length) {
size_t count = 0;
while (count < length) {
int c = read();
if (c < 0)
break;
*buffer++ = (char)c;
count++;
}
return count;
}

String readString() {
String result;
int c;
while ((c = read()) >= 0) {
result += static_cast<char>(c);
}
return result;
}

void setTimeout(unsigned long) {}
};

} // namespace arduino
49 changes: 49 additions & 0 deletions extras/test/cores/coreapi/WString.h
@@ -0,0 +1,49 @@
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
// Copyright Benoit Blanchon 2019-2023
// MIT License

#pragma once

#include <ostream>
#include <string>

#include "../avr/avr/pgmspace.h"

namespace arduino {

class __FlashStringHelper;
#define F(s) (reinterpret_cast<const __FlashStringHelper*>(s + 42))

class String : private std::string {
public:
String() {}
String(const String& s) : std::string(s) {}
String(String&& s) : std::string(std::move(s)) {}
String(const char* s) : std::string(s) {}
String(int n) : std::string(std::to_string(n)) {}
String(size_t n) : std::string(std::to_string(n)) {}

String& operator=(const String& rhs) {
std::string::operator=(rhs);
return *this;
}

using std::string::c_str;
using std::string::length;
using std::string::operator+=;
using std::string::operator[];

void remove(unsigned int index, unsigned int count) {
erase(begin() + index, begin() + index + count);
}

friend bool operator==(const String& lhs, const char* rhs) {
return static_cast<const std::string&>(lhs) == rhs;
}

friend std::ostream& operator<<(std::ostream& lhs, const String& rhs) {
return lhs << static_cast<const std::string&>(rhs);
}
};

} // namespace arduino
19 changes: 19 additions & 0 deletions extras/test/cores/rp2040/CMakeLists.txt
@@ -0,0 +1,19 @@
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
# Copyright Benoit Blanchon 2019-2023
# MIT License

add_library(Rp2040Core
EEPROM.cpp
EEPROM.h
)

target_include_directories(Rp2040Core
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../coreapi
)

target_compile_definitions(Rp2040Core
PUBLIC
ARDUINO_ARCH_RP2040
)
1 change: 1 addition & 0 deletions extras/test/cores/rp2040/EEPROM.cpp
@@ -0,0 +1 @@
#include "../esp32/EEPROM.cpp"
1 change: 1 addition & 0 deletions extras/test/cores/rp2040/EEPROM.h
@@ -0,0 +1 @@
#include "../esp32/EEPROM.h"
9 changes: 5 additions & 4 deletions src/StreamUtils/Configuration.hpp
Expand Up @@ -34,17 +34,18 @@
#endif

#ifndef STREAMUTILS_ENABLE_EEPROM
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || \
defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) || \
defined(CORE_TEENSY)
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || \
defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_RP2040) || \
defined(ARDUINO_ARCH_STM32) || defined(CORE_TEENSY)
#define STREAMUTILS_ENABLE_EEPROM 1
#else
#define STREAMUTILS_ENABLE_EEPROM 0
#endif
#endif

#ifndef STREAMUTILS_USE_EEPROM_COMMIT
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || \
defined(ARDUINO_ARCH_RP2040)
#define STREAMUTILS_USE_EEPROM_COMMIT 1
#else
#define STREAMUTILS_USE_EEPROM_COMMIT 0
Expand Down
2 changes: 0 additions & 2 deletions src/StreamUtils/Streams/ProgmemStream.hpp
Expand Up @@ -8,8 +8,6 @@

#include "../Configuration.hpp"

class __FlashStringHelper;

namespace StreamUtils {

class ProgmemStream : public Stream {
Expand Down

0 comments on commit 5a12948

Please sign in to comment.