diff --git a/CHANGELOG.md b/CHANGELOG.md index 83607321..68f6f0d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added -- Support for EEPROM +- Support for mock EEPROM (but only if board supports it) ### Changed - Move repository from https://github.com/ianfixes/arduino_ci to https://github.com/Arduino-CI/arduino_ci @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Removed ### Fixed +- Don't define `ostream& operator<<(nullptr_t)` if already defined by Apple ### Security diff --git a/SampleProjects/TestSomething/test/eeprom.cpp b/SampleProjects/TestSomething/test/eeprom.cpp index ead3e371..440d6f1c 100644 --- a/SampleProjects/TestSomething/test/eeprom.cpp +++ b/SampleProjects/TestSomething/test/eeprom.cpp @@ -1,5 +1,8 @@ #include #include + +// Only run EEPROM tests if there is hardware support! +#if defined(EEPROM_SIZE) || (defined(E2END) && E2END) #include unittest(length) @@ -7,4 +10,6 @@ unittest(length) assertEqual(EEPROM_SIZE, EEPROM.length()); } +#endif + unittest_main() diff --git a/cpp/arduino/EEPROM.h b/cpp/arduino/EEPROM.h index 75df36c6..39fa91f8 100644 --- a/cpp/arduino/EEPROM.h +++ b/cpp/arduino/EEPROM.h @@ -4,7 +4,7 @@ New version by Christopher Andrews 2015. Copy of https://github.com/arduino/ArduinoCore-megaavr/blob/c8a1dd996c783777ec46167cfd8ad3fd2e6df185/libraries/EEPROM/src/EEPROM.h - modified by James Foster 2020 to work with Arduino CI. + modified by James Foster in 2020 to work with Arduino CI. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -27,13 +27,24 @@ #include #include -// I see EEPROM_SIZE defined in various arv/io*.h files; why isn't it defined here? -#define EEPROM_SIZE (4096) -// Is this all the custom code required? +// different EEPROM implementations have different macros that leak out +#if !defined(EEPROM_SIZE) && defined(E2END) && (E2END) +#define EEPROM_SIZE (E2END + 1) +#endif + +// Does the current board have EEPROM? +#ifndef EEPROM_SIZE +// In lieu of an "EEPROM.h not found" error for unsupported boards +#error "EEPROM library not available for your board" +#endif + +// On a real device this would be in hardware, but we have a mock board! static uint8_t eeprom[EEPROM_SIZE]; inline uint8_t eeprom_read_byte( uint8_t* index ) { return eeprom[(unsigned long) index % EEPROM_SIZE]; } inline void eeprom_write_byte( uint8_t* index, uint8_t value ) { eeprom[(unsigned long) index % EEPROM_SIZE] = value; } +// Everything following is from the original (referenced above) + /*** EERef class. @@ -152,4 +163,4 @@ struct EEPROMClass{ }; static EEPROMClass EEPROM; -#endif \ No newline at end of file +#endif diff --git a/cpp/unittest/OstreamHelpers.h b/cpp/unittest/OstreamHelpers.h index a2cd8f45..14280d3a 100644 --- a/cpp/unittest/OstreamHelpers.h +++ b/cpp/unittest/OstreamHelpers.h @@ -2,4 +2,8 @@ #include +#if (defined __apple_build_version__) && (__apple_build_version__ >= 12000000) +// defined in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ostream:223:20 +#else inline std::ostream& operator << (std::ostream& out, const std::nullptr_t &np) { return out << "nullptr"; } +#endif