Skip to content

Commit a5dc7b6

Browse files
authored
Merge branch 'master' into tdd
2 parents 03e4168 + 972ad28 commit a5dc7b6

File tree

12 files changed

+582
-427
lines changed

12 files changed

+582
-427
lines changed

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ script:
2626
- bundle exec rspec --backtrace
2727
- cd SampleProjects/TestSomething
2828
- bundle install
29-
- bundle exec arduino_ci_remote.rb
29+
- bundle exec arduino_ci.rb

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99
### Added
1010
- Add `__AVR__` to defines when compiling
11+
- Add support for `diditalPinToPort()`, `digitalPinToBitMask()`, and `portOutputRegister()`
1112
- Support for mock EEPROM (but only if board supports it)
1213

1314
### Changed
1415
- Move repository from https://github.com/ianfixes/arduino_ci to https://github.com/Arduino-CI/arduino_ci
16+
- Revise math macros to avoid name clashes
1517

1618
### Deprecated
19+
- Deprecated `arduino_ci_remote.rb` in favor of `arduino_ci.rb`
1720

1821
### Removed
1922

Diff for: README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ $ bundle install --path vendor/bundle # adds packages to local library
9494
With that installed, just the following shell command each time you want the tests to execute:
9595

9696
```
97-
$ bundle exec arduino_ci_remote.rb
97+
$ bundle exec arduino_ci.rb
9898
```
9999

100-
`arduino_ci_remote.rb` is the main entry point for this library. This command will iterate over all the library's `examples/` and attempt to compile them. If you set up unit tests, it will run those as well.
100+
`arduino_ci.rb` is the main entry point for this library. This command will iterate over all the library's `examples/` and attempt to compile them. If you set up unit tests, it will run those as well.
101101

102102

103103
### Reference
104104

105-
For more information on the usage of `arduino_ci_remote.rb`, see [REFERENCE.md](REFERENCE.md). It contains information such as:
105+
For more information on the usage of `arduino_ci.rb`, see [REFERENCE.md](REFERENCE.md). It contains information such as:
106106

107107
* How to configure build options (platforms to test, Arduino library dependencies to install) with an `.arduino-ci.yml` file
108108
* Where to put unit test files
@@ -121,7 +121,7 @@ The following prerequisites must be fulfilled:
121121

122122
### Testing with remote CI
123123

124-
> **Note:** `arduino_ci_remote.rb` expects to be run from the root directory of your Arduino project library.
124+
> **Note:** `arduino_ci.rb` expects to be run from the root directory of your Arduino project library.
125125
126126

127127
#### Travis CI
@@ -135,7 +135,7 @@ sudo: false
135135
language: ruby
136136
script:
137137
- bundle install
138-
- bundle exec arduino_ci_remote.rb
138+
- bundle exec arduino_ci.rb
139139
```
140140
141141
@@ -149,7 +149,7 @@ Next, you'll need this in `appveyor.yml` in your repo.
149149
build: off
150150
test_script:
151151
- bundle install
152-
- bundle exec arduino_ci_remote.rb
152+
- bundle exec arduino_ci.rb
153153
```
154154

155155
## Known Problems

Diff for: REFERENCE.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build / Test Behavior of Arduino CI
22

3-
All tests are run via the same command: `bundle exec arduino_ci_remote.rb`.
3+
All tests are run via the same command: `bundle exec arduino_ci.rb`.
44

55
This script is responsible for detecting and runing all unit tests, on every combination of Arduino platform and C++ compiler. This is followed by attempting to detect and build every example on every "default" Arduino platform.
66

@@ -11,7 +11,7 @@ These defaults are specified in [misc/default.yml](misc/default.yml). You are f
1111

1212
## Directly Overriding Build Behavior (short term use)
1313

14-
When testing locally, it's often advantageous to limit the number of tests that are performed to only those tests that relate to the work you're doing; you'll get a faster turnaround time in seeing the results. For a full listing, see `bundle exec arduino_ci_remote.rb --help`.
14+
When testing locally, it's often advantageous to limit the number of tests that are performed to only those tests that relate to the work you're doing; you'll get a faster turnaround time in seeing the results. For a full listing, see `bundle exec arduino_ci.rb --help`.
1515

1616

1717
### `--skip-unittests` option
@@ -233,14 +233,14 @@ For most build environments, the only script that need be executed by the CI sys
233233
```shell
234234
# simplest build script
235235
bundle install
236-
bundle exec arduino_ci_remote.rb
236+
bundle exec arduino_ci.rb
237237
```
238238

239239
However, more flexible usage is available:
240240

241241
### Custom Versions of external Arduino Libraries
242242

243-
Sometimes you need a fork of an Arduino library instead of the version that will be installed via their GUI. `arduino_ci_remote.rb` won't overwrite existing downloaded libraries with fresh downloads, but it won't fetch the custom versions for you either.
243+
Sometimes you need a fork of an Arduino library instead of the version that will be installed via their GUI. `arduino_ci.rb` won't overwrite existing downloaded libraries with fresh downloads, but it won't fetch the custom versions for you either.
244244

245245
If this is the behavior you need, `ensure_arduino_installation.rb` is for you. It ensures that an Arduino binary is available on the system.
246246

@@ -261,7 +261,7 @@ git clone https://repository.com/custom_library_repo.git
261261
mv custom_library_repo $(bundle exec arduino_library_location.rb)
262262
263263
# now run CI
264-
bundle exec arduino_ci_remote.rb
264+
bundle exec arduino_ci.rb
265265
```
266266

267267
Note the use of subshell to execute `bundle exec arduino_library_location.rb`. This command simply returns the directory in which Arduino Libraries are (or should be) installed.

Diff for: SampleProjects/DoSomething/.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ sudo: false
22
language: ruby
33
script:
44
- bundle install
5-
- bundle exec arduino_ci_remote.rb
5+
- bundle exec arduino_ci.rb

Diff for: SampleProjects/DoSomething/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ At a minimum, you will need the following lines in your file:
3434
language: ruby
3535
script:
3636
- bundle install
37-
- bundle exec arduino_ci_remote.rb
37+
- bundle exec arduino_ci.rb
3838
```
3939
4040
This will install the necessary ruby gem, and run it. There are no command line arguments as of this writing, because all configuration is provided by...

Diff for: SampleProjects/TestSomething/test/outputRegister.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <ArduinoUnitTests.h>
2+
#include <Arduino.h>
3+
4+
// added to fix https://github.com/Arduino-CI/arduino_ci/issues/193
5+
// https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h#L337
6+
7+
#if defined(__AVR__)
8+
unittest(portOutputRegister)
9+
{
10+
uint8_t ss_pin = 12;
11+
uint8_t ss_port = digitalPinToPort(ss_pin);
12+
assertEqual(12, ss_port);
13+
uint8_t *ss_pin_reg = portOutputRegister(ss_port);
14+
assertEqual(GODMODE()->pMmapPort(ss_port), ss_pin_reg);
15+
uint8_t ss_pin_mask = digitalPinToBitMask(ss_pin);
16+
assertEqual(1, ss_pin_mask);
17+
18+
assertEqual((int) 1, (int) *ss_pin_reg); // verify initial value
19+
*(ss_pin_reg) &= ~ss_pin_mask; // set SS
20+
assertEqual((int) 0, (int) *ss_pin_reg); // verify value
21+
*(ss_pin_reg) |= ss_pin_mask; // clear SS
22+
assertEqual((int) 1, (int) *ss_pin_reg); // verify value
23+
}
24+
#endif
25+
26+
unittest_main()

Diff for: appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ test_script:
2424
- bundle exec rspec --backtrace
2525
- cd SampleProjects\TestSomething
2626
- bundle install
27-
- bundle exec arduino_ci_remote.rb
27+
- bundle exec arduino_ci.rb

Diff for: cpp/arduino/AvrMath.h

+117-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,126 @@
11
#pragma once
2+
#include "ArduinoDefines.h"
23
#include <math.h>
34

4-
#define constrain(x,l,h) ((x)<(l)?(l):((x)>(h)?(h):(x)))
5-
#define map(x,inMin,inMax,outMin,outMax) (((x)-(inMin))*((outMax)-(outMin))/((inMax)-(inMin))+outMin)
5+
#ifdef __cplusplus
66

7-
#define sq(x) ((x)*(x))
7+
template <class Amt, class Low, class High>
8+
auto constrain(const Amt &amt, const Low &low, const High &high)
9+
-> decltype(amt < low ? low : (amt > high ? high : amt)) {
10+
return (amt < low ? low : (amt > high ? high : amt));
11+
}
812

9-
#define radians(deg) ((deg)*DEG_TO_RAD)
10-
#define degrees(rad) ((rad)*RAD_TO_DEG)
13+
template <class X, class InMin, class InMax, class OutMin, class OutMax>
14+
auto map(const X &x, const InMin &inMin, const InMax &inMax,
15+
const OutMin &outMin, const OutMax &outMax)
16+
-> decltype((x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin) {
17+
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
18+
}
1119

12-
#ifdef abs
13-
#undef abs
14-
#endif
15-
#define abs(x) ((x)>0?(x):-(x))
20+
template <class T> auto radians(const T &deg) -> decltype(deg * DEG_TO_RAD) {
21+
return deg * DEG_TO_RAD;
22+
}
1623

17-
#ifdef max
18-
#undef max
19-
#endif
20-
#define max(a,b) ((a)>(b)?(a):(b))
24+
template <class T> auto degrees(const T &rad) -> decltype(rad * RAD_TO_DEG) {
25+
return rad * RAD_TO_DEG;
26+
}
2127

22-
#ifdef min
23-
#undef min
24-
#endif
25-
#define min(a,b) ((a)<(b)?(a):(b))
28+
template <class T> auto sq(const T &x) -> decltype(x * x) { return x * x; }
29+
30+
template <class T> auto abs(const T &x) -> decltype(x > 0 ? x : -x) {
31+
return x > 0 ? x : -x;
32+
}
33+
34+
template <class T, class L>
35+
auto min(const T &a, const L &b) -> decltype((b < a) ? b : a) {
36+
return (b < a) ? b : a;
37+
}
38+
39+
template <class T, class L>
40+
auto max(const T &a, const L &b) -> decltype((b < a) ? b : a) {
41+
return (a < b) ? b : a;
42+
}
43+
44+
#else // __cplusplus
45+
46+
#ifdef constrain
47+
#undef constrain
48+
#endif
49+
#define constrain(amt, low, high) \
50+
({ \
51+
__typeof__(amt) _amt = (amt); \
52+
__typeof__(low) _low = (low); \
53+
__typeof__(high) _high = (high); \
54+
(amt < low ? low : (amt > high ? high : amt)); \
55+
})
2656

57+
#ifdef map
58+
#undef map
59+
#endif
60+
#define map(x, inMin, inMax, outMin, outMax) \
61+
({ \
62+
__typeof__(x) _x = (x); \
63+
__typeof__(inMin) _inMin = (inMin); \
64+
__typeof__(inMax) _inMax = (inMax); \
65+
__typeof__(outMin) _outMin = (outMin); \
66+
__typeof__(outMax) _outMax = (outMax); \
67+
(_x - _inMin) * (_outMax - _outMin) / (_inMax - _inMin) + _outMin; \
68+
})
69+
70+
#ifdef radians
71+
#undef radians
72+
#endif
73+
#define radians(deg) \
74+
({ \
75+
__typeof__(deg) _deg = (deg); \
76+
_deg *DEG_TO_RAD; \
77+
})
78+
79+
#ifdef degrees
80+
#undef degrees
81+
#endif
82+
#define degrees(rad) \
83+
({ \
84+
__typeof__(rad) _rad = (rad); \
85+
_rad *RAD_TO_DEG; \
86+
})
87+
88+
#ifdef sq
89+
#undef sq
90+
#endif
91+
#define sq(x) \
92+
({ \
93+
__typeof__(x) _x = (x); \
94+
_x *_x; \
95+
})
96+
97+
#ifdef abs
98+
#undef abs
99+
#endif
100+
#define abs(x) \
101+
({ \
102+
__typeof__(x) _x = (x); \
103+
_x > 0 ? _x : -_x; \
104+
})
105+
106+
#ifdef min
107+
#undef min
108+
#endif
109+
#define min(a, b) \
110+
({ \
111+
__typeof__(a) _a = (a); \
112+
__typeof__(b) _b = (b); \
113+
_a < _b ? _a : _b; \
114+
})
115+
116+
#ifdef max
117+
#undef max
118+
#endif
119+
#define max(a, b) \
120+
({ \
121+
__typeof__(a) _a = (a); \
122+
__typeof__(b) _b = (b); \
123+
_a > _b ? _a : _b; \
124+
})
125+
126+
#endif

Diff for: cpp/arduino/Godmode.h

+25-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class GodmodeState {
5454
uint8_t mode;
5555
};
5656

57+
uint8_t mmapPorts[MOCK_PINS_COUNT];
58+
5759
static GodmodeState* instance;
5860

5961
public:
@@ -99,9 +101,15 @@ class GodmodeState {
99101
spi.readDelayMicros = 0;
100102
}
101103

104+
void resetMmapPorts() {
105+
for (int i = 0; i < MOCK_PINS_COUNT; ++i) {
106+
mmapPorts[i] = 1;
107+
}
108+
}
109+
102110
void resetEEPROM() {
103-
for(int i = 0; i < EEPROM_SIZE; ++i){
104-
eeprom[i] = 255;
111+
for(int i = 0; i < EEPROM_SIZE; ++i) {
112+
eeprom[i] = 255;
105113
}
106114
}
107115

@@ -111,6 +119,7 @@ class GodmodeState {
111119
resetInterrupts();
112120
resetPorts();
113121
resetSPI();
122+
resetMmapPorts();
114123
resetEEPROM();
115124
seed = 1;
116125
}
@@ -131,6 +140,9 @@ class GodmodeState {
131140
return instance->micros;
132141
}
133142

143+
uint8_t* pMmapPort(uint8_t port) { return &mmapPorts[port]; }
144+
uint8_t mmapPortValue(uint8_t port) { return mmapPorts[port]; }
145+
134146
// C++ 11, declare as public for better compiler error messages
135147
GodmodeState(GodmodeState const&) = delete;
136148
void operator=(GodmodeState const&) = delete;
@@ -158,5 +170,16 @@ void detachInterrupt(uint8_t interrupt);
158170
inline void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0) {}
159171
inline void noTone(uint8_t _pin) {}
160172

173+
// These definitions allow the following to compile (see issue #193):
174+
// https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h:341
175+
// we allow one byte per port which "wastes" 224 bytes, but makes the code easier
176+
#if defined(__AVR__)
177+
#define digitalPinToBitMask(pin) (1)
178+
#define digitalPinToPort(pin) (pin)
179+
#define portOutputRegister(port) (GODMODE()->pMmapPort(port))
180+
#else
181+
// we don't (yet) support other boards
182+
#endif
183+
161184

162185
GodmodeState* GODMODE();

0 commit comments

Comments
 (0)