Skip to content

Commit 3502211

Browse files
authored
Merge pull request Arduino-CI#174 from jgfoster/eeprom
Add Mock Support for EEPROM
2 parents 3c437aa + 4605207 commit 3502211

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99
### Added
10-
- Support for EEPROM
10+
- Support for mock EEPROM (but only if board supports it)
1111

1212
### Changed
1313
- 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/).
1717
### Removed
1818

1919
### Fixed
20+
- Don't define `ostream& operator<<(nullptr_t)` if already defined by Apple
2021

2122
### Security
2223

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#include <ArduinoUnitTests.h>
22
#include <Arduino.h>
3+
4+
// Only run EEPROM tests if there is hardware support!
5+
#if defined(EEPROM_SIZE) || (defined(E2END) && E2END)
36
#include <EEPROM.h>
47

58
unittest(length)
69
{
710
assertEqual(EEPROM_SIZE, EEPROM.length());
811
}
912

13+
#endif
14+
1015
unittest_main()

cpp/arduino/EEPROM.h

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
New version by Christopher Andrews 2015.
55
66
Copy of https://github.com/arduino/ArduinoCore-megaavr/blob/c8a1dd996c783777ec46167cfd8ad3fd2e6df185/libraries/EEPROM/src/EEPROM.h
7-
modified by James Foster 2020 to work with Arduino CI.
7+
modified by James Foster in 2020 to work with Arduino CI.
88
99
This library is free software; you can redistribute it and/or
1010
modify it under the terms of the GNU Lesser General Public
@@ -27,13 +27,24 @@
2727
#include <inttypes.h>
2828
#include <avr/io.h>
2929

30-
// I see EEPROM_SIZE defined in various arv/io*.h files; why isn't it defined here?
31-
#define EEPROM_SIZE (4096)
32-
// Is this all the custom code required?
30+
// different EEPROM implementations have different macros that leak out
31+
#if !defined(EEPROM_SIZE) && defined(E2END) && (E2END)
32+
#define EEPROM_SIZE (E2END + 1)
33+
#endif
34+
35+
// Does the current board have EEPROM?
36+
#ifndef EEPROM_SIZE
37+
// In lieu of an "EEPROM.h not found" error for unsupported boards
38+
#error "EEPROM library not available for your board"
39+
#endif
40+
41+
// On a real device this would be in hardware, but we have a mock board!
3342
static uint8_t eeprom[EEPROM_SIZE];
3443
inline uint8_t eeprom_read_byte( uint8_t* index ) { return eeprom[(unsigned long) index % EEPROM_SIZE]; }
3544
inline void eeprom_write_byte( uint8_t* index, uint8_t value ) { eeprom[(unsigned long) index % EEPROM_SIZE] = value; }
3645

46+
// Everything following is from the original (referenced above)
47+
3748
/***
3849
EERef class.
3950
@@ -152,4 +163,4 @@ struct EEPROMClass{
152163
};
153164

154165
static EEPROMClass EEPROM;
155-
#endif
166+
#endif

cpp/unittest/OstreamHelpers.h

+4
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
#include <ostream>
44

5+
#if (defined __apple_build_version__) && (__apple_build_version__ >= 12000000)
6+
// defined in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ostream:223:20
7+
#else
58
inline std::ostream& operator << (std::ostream& out, const std::nullptr_t &np) { return out << "nullptr"; }
9+
#endif

0 commit comments

Comments
 (0)