From 9df75db3d90447ef4f96ca4ba9bdc2e04fd464c4 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 5 Oct 2020 11:52:45 -0700 Subject: [PATCH 1/7] Don't define ostream& operator() if already defined by Apple (#171) * Don't define ostream& operator() if already defined by Apple. --- CHANGELOG.md | 1 + cpp/unittest/OstreamHelpers.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68cc609c..bfeb713c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,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/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 From c512f287d430858a6fc39913d305ab3e791ca195 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 5 Oct 2020 12:22:22 -0700 Subject: [PATCH 2/7] Only include EEPROM if board supports it. --- CHANGELOG.md | 2 +- SampleProjects/TestSomething/.arduino-ci.yml | 1 + SampleProjects/TestSomething/test/eeprom.cpp | 11 +++++++++++ cpp/arduino/EEPROM.h | 7 ++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83607321..d2e5d9cc 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; added mega2560 to TestSomething config) ### Changed - Move repository from https://github.com/ianfixes/arduino_ci to https://github.com/Arduino-CI/arduino_ci diff --git a/SampleProjects/TestSomething/.arduino-ci.yml b/SampleProjects/TestSomething/.arduino-ci.yml index c418bdbe..16298baf 100644 --- a/SampleProjects/TestSomething/.arduino-ci.yml +++ b/SampleProjects/TestSomething/.arduino-ci.yml @@ -4,6 +4,7 @@ unittest: platforms: - uno - due + - mega2560 compile: platforms: diff --git a/SampleProjects/TestSomething/test/eeprom.cpp b/SampleProjects/TestSomething/test/eeprom.cpp index ead3e371..0068a8e9 100644 --- a/SampleProjects/TestSomething/test/eeprom.cpp +++ b/SampleProjects/TestSomething/test/eeprom.cpp @@ -2,9 +2,20 @@ #include #include +#ifdef EEPROM_SIZE + unittest(length) { assertEqual(EEPROM_SIZE, EEPROM.length()); } +#else + +unittest(eeprom) +{ + assertTrue(true); +} + +#endif + unittest_main() diff --git a/cpp/arduino/EEPROM.h b/cpp/arduino/EEPROM.h index 75df36c6..a3c40f39 100644 --- a/cpp/arduino/EEPROM.h +++ b/cpp/arduino/EEPROM.h @@ -27,8 +27,8 @@ #include #include -// I see EEPROM_SIZE defined in various arv/io*.h files; why isn't it defined here? -#define EEPROM_SIZE (4096) +#ifdef EEPROM_SIZE + // Is this all the custom code required? static uint8_t eeprom[EEPROM_SIZE]; inline uint8_t eeprom_read_byte( uint8_t* index ) { return eeprom[(unsigned long) index % EEPROM_SIZE]; } @@ -152,4 +152,5 @@ struct EEPROMClass{ }; static EEPROMClass EEPROM; -#endif \ No newline at end of file +#endif +#endif From 524d35284027cd71118209bda2dbca41534bb4c0 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 5 Oct 2020 17:11:51 -0700 Subject: [PATCH 3/7] Add EEPROM_SIZE to mega boards. --- SampleProjects/TestSomething/test/eeprom.cpp | 7 ------- cpp/arduino/avr/iomxx0_1.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/SampleProjects/TestSomething/test/eeprom.cpp b/SampleProjects/TestSomething/test/eeprom.cpp index 0068a8e9..f773a046 100644 --- a/SampleProjects/TestSomething/test/eeprom.cpp +++ b/SampleProjects/TestSomething/test/eeprom.cpp @@ -9,13 +9,6 @@ unittest(length) assertEqual(EEPROM_SIZE, EEPROM.length()); } -#else - -unittest(eeprom) -{ - assertTrue(true); -} - #endif unittest_main() diff --git a/cpp/arduino/avr/iomxx0_1.h b/cpp/arduino/avr/iomxx0_1.h index 374c5f40..553d46d6 100644 --- a/cpp/arduino/avr/iomxx0_1.h +++ b/cpp/arduino/avr/iomxx0_1.h @@ -351,6 +351,17 @@ Last two letters: EEAR address. */ #define __EEPROM_REG_LOCATIONS__ 1F2021 +/* According to https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf, + * the Atmel ATmega640/V-1280/V-1281/V-2560/V-2561/V microcontrollers each have + * 4Kbytes of EEPROM and since this file is included from things that seem + * to match that description, it would be helpful to know that EEPROM is + * available and know its size. This macro is defined for many other models, + * so we will add it here. + * + * See https://github.com/Arduino-CI/arduino_ci/issues/166#issuecomment-703904394. + */ +#define EEPROM_SIZE (4096) + #define GTCCR _SFR_IO8(0x23) #define TSM 7 #define PSRASY 1 From 8ed2732c5904c1aa0689068093ccd4b7d64ed906 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 5 Oct 2020 18:21:05 -0700 Subject: [PATCH 4/7] Move `EEPROM_SIZE` macro to `misc/default.yml`. --- cpp/arduino/avr/iomxx0_1.h | 11 ----------- misc/default.yml | 1 + 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/cpp/arduino/avr/iomxx0_1.h b/cpp/arduino/avr/iomxx0_1.h index 553d46d6..374c5f40 100644 --- a/cpp/arduino/avr/iomxx0_1.h +++ b/cpp/arduino/avr/iomxx0_1.h @@ -351,17 +351,6 @@ Last two letters: EEAR address. */ #define __EEPROM_REG_LOCATIONS__ 1F2021 -/* According to https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf, - * the Atmel ATmega640/V-1280/V-1281/V-2560/V-2561/V microcontrollers each have - * 4Kbytes of EEPROM and since this file is included from things that seem - * to match that description, it would be helpful to know that EEPROM is - * available and know its size. This macro is defined for many other models, - * so we will add it here. - * - * See https://github.com/Arduino-CI/arduino_ci/issues/166#issuecomment-703904394. - */ -#define EEPROM_SIZE (4096) - #define GTCCR _SFR_IO8(0x23) #define TSM 7 #define PSRASY 1 diff --git a/misc/default.yml b/misc/default.yml index 67d7f87f..1d2629de 100644 --- a/misc/default.yml +++ b/misc/default.yml @@ -100,6 +100,7 @@ platforms: features: defines: - __AVR_ATmega2560__ + - EEPROM_SIZE=(4096) warnings: flags: cplayClassic: From fadc74334bb16088d862cf7bc7bfea3d800c2f83 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 5 Oct 2020 21:42:28 -0700 Subject: [PATCH 5/7] Use E2END to calculate EEPROM_SIZE. --- cpp/arduino/EEPROM.h | 3 +++ misc/default.yml | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cpp/arduino/EEPROM.h b/cpp/arduino/EEPROM.h index a3c40f39..7eef18b3 100644 --- a/cpp/arduino/EEPROM.h +++ b/cpp/arduino/EEPROM.h @@ -27,6 +27,9 @@ #include #include +#if !defined(EEPROM_SIZE) && defined(E2END) && (E2END) +#define EEPROM_SIZE (E2END + 1) +#endif #ifdef EEPROM_SIZE // Is this all the custom code required? diff --git a/misc/default.yml b/misc/default.yml index 1d2629de..67d7f87f 100644 --- a/misc/default.yml +++ b/misc/default.yml @@ -100,7 +100,6 @@ platforms: features: defines: - __AVR_ATmega2560__ - - EEPROM_SIZE=(4096) warnings: flags: cplayClassic: From 0ee51702bd76681dc4967eb66215b6ba0dec1531 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 5 Oct 2020 21:51:34 -0700 Subject: [PATCH 6/7] EEPROM is tested by uno and due so we don't need to add mega2560 (one less file changed). --- SampleProjects/TestSomething/.arduino-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/SampleProjects/TestSomething/.arduino-ci.yml b/SampleProjects/TestSomething/.arduino-ci.yml index 16298baf..c418bdbe 100644 --- a/SampleProjects/TestSomething/.arduino-ci.yml +++ b/SampleProjects/TestSomething/.arduino-ci.yml @@ -4,7 +4,6 @@ unittest: platforms: - uno - due - - mega2560 compile: platforms: From 4605207bc2ac30b8475b13b1a1b4ff41713f81a2 Mon Sep 17 00:00:00 2001 From: James Foster Date: Tue, 6 Oct 2020 22:23:27 -0700 Subject: [PATCH 7/7] Simplify reference to EEPROM library. --- CHANGELOG.md | 2 +- SampleProjects/TestSomething/test/eeprom.cpp | 5 +++-- cpp/arduino/EEPROM.h | 15 +++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3101da3..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 mock EEPROM (but only if board supports it; added mega2560 to TestSomething config) +- 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 diff --git a/SampleProjects/TestSomething/test/eeprom.cpp b/SampleProjects/TestSomething/test/eeprom.cpp index f773a046..440d6f1c 100644 --- a/SampleProjects/TestSomething/test/eeprom.cpp +++ b/SampleProjects/TestSomething/test/eeprom.cpp @@ -1,8 +1,9 @@ #include #include -#include -#ifdef EEPROM_SIZE +// Only run EEPROM tests if there is hardware support! +#if defined(EEPROM_SIZE) || (defined(E2END) && E2END) +#include unittest(length) { diff --git a/cpp/arduino/EEPROM.h b/cpp/arduino/EEPROM.h index 7eef18b3..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,16 +27,24 @@ #include #include +// different EEPROM implementations have different macros that leak out #if !defined(EEPROM_SIZE) && defined(E2END) && (E2END) #define EEPROM_SIZE (E2END + 1) #endif -#ifdef EEPROM_SIZE -// Is this all the custom code required? +// 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. @@ -156,4 +164,3 @@ struct EEPROMClass{ static EEPROMClass EEPROM; #endif -#endif