arduino_ci 0.2.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +49 -20
  3. data/REFERENCE.md +636 -0
  4. data/cpp/arduino/Arduino.h +1 -1
  5. data/cpp/arduino/AvrMath.h +117 -17
  6. data/cpp/arduino/Client.h +27 -0
  7. data/cpp/arduino/EEPROM.h +64 -0
  8. data/cpp/arduino/Godmode.cpp +11 -0
  9. data/cpp/arduino/Godmode.h +58 -9
  10. data/cpp/arduino/HardwareSerial.h +9 -28
  11. data/cpp/arduino/IPAddress.h +59 -0
  12. data/cpp/arduino/Print.h +9 -12
  13. data/cpp/arduino/Printable.h +8 -0
  14. data/cpp/arduino/SPI.h +11 -3
  15. data/cpp/arduino/Server.h +5 -0
  16. data/cpp/arduino/Udp.h +27 -0
  17. data/cpp/arduino/Wire.h +234 -0
  18. data/cpp/arduino/avr/io.h +10 -1
  19. data/cpp/arduino/avr/pgmspace.h +76 -46
  20. data/cpp/arduino/ci/StreamTape.h +36 -0
  21. data/cpp/unittest/OstreamHelpers.h +4 -0
  22. data/exe/arduino_ci.rb +427 -0
  23. data/exe/arduino_ci_remote.rb +2 -385
  24. data/exe/arduino_library_location.rb +2 -2
  25. data/exe/ensure_arduino_installation.rb +7 -1
  26. data/lib/arduino_ci.rb +1 -0
  27. data/lib/arduino_ci/arduino_backend.rb +222 -0
  28. data/lib/arduino_ci/arduino_downloader.rb +43 -73
  29. data/lib/arduino_ci/arduino_downloader_linux.rb +17 -55
  30. data/lib/arduino_ci/arduino_downloader_osx.rb +21 -33
  31. data/lib/arduino_ci/arduino_downloader_windows.rb +11 -53
  32. data/lib/arduino_ci/arduino_installation.rb +18 -80
  33. data/lib/arduino_ci/ci_config.rb +15 -9
  34. data/lib/arduino_ci/cpp_library.rb +266 -48
  35. data/lib/arduino_ci/host.rb +59 -4
  36. data/lib/arduino_ci/library_properties.rb +96 -0
  37. data/lib/arduino_ci/version.rb +1 -1
  38. data/misc/default.yml +55 -4
  39. metadata +21 -87
  40. data/cpp/arduino/Arduino.h.orig +0 -143
  41. data/exe/libasan.rb +0 -29
  42. data/lib/arduino_ci/arduino_cmd.rb +0 -328
  43. data/lib/arduino_ci/arduino_cmd_linux.rb +0 -17
  44. data/lib/arduino_ci/arduino_cmd_linux_builder.rb +0 -19
  45. data/lib/arduino_ci/arduino_cmd_osx.rb +0 -17
  46. data/lib/arduino_ci/arduino_cmd_windows.rb +0 -17
@@ -9,12 +9,12 @@ Where possible, variable names from the Arduino library are used to avoid confli
9
9
 
10
10
  #include "ArduinoDefines.h"
11
11
 
12
+ #include "IPAddress.h"
12
13
  #include "WCharacter.h"
13
14
  #include "WString.h"
14
15
  #include "Print.h"
15
16
  #include "Stream.h"
16
17
  #include "HardwareSerial.h"
17
- #include "SPI.h"
18
18
 
19
19
  typedef bool boolean;
20
20
  typedef uint8_t byte;
@@ -1,26 +1,126 @@
1
1
  #pragma once
2
+ #include "ArduinoDefines.h"
2
3
  #include <math.h>
3
4
 
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
6
6
 
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
+ }
8
12
 
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
+ }
11
19
 
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
+ }
16
23
 
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
+ }
21
27
 
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
+ })
26
56
 
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
@@ -0,0 +1,27 @@
1
+ #pragma once
2
+
3
+ #include <Stream.h>
4
+ #include <IPAddress.h>
5
+
6
+ class Client : public Stream {
7
+ public:
8
+ Client() {
9
+ // The Stream mock defines a String buffer but never puts anyting in it!
10
+ if (!mGodmodeDataIn) {
11
+ mGodmodeDataIn = new String;
12
+ }
13
+ }
14
+ ~Client() {
15
+ if (mGodmodeDataIn) {
16
+ delete mGodmodeDataIn;
17
+ mGodmodeDataIn = nullptr;
18
+ }
19
+ }
20
+ virtual size_t write(uint8_t value) {
21
+ mGodmodeDataIn->concat(value);
22
+ return 1;
23
+ }
24
+
25
+ protected:
26
+ uint8_t *rawIPAddress(IPAddress &addr) { return addr.raw_address(); }
27
+ };
@@ -0,0 +1,64 @@
1
+ #pragma once
2
+
3
+ #include <cassert>
4
+ #include <inttypes.h>
5
+ #include <Godmode.h>
6
+
7
+ // Does the current board have EEPROM?
8
+ #ifndef EEPROM_SIZE
9
+ // In lieu of an "EEPROM.h not found" error for unsupported boards
10
+ #error "EEPROM library not available for your board"
11
+ #endif
12
+
13
+ class EEPROMClass {
14
+ private:
15
+ GodmodeState* state;
16
+ public:
17
+ // constructor
18
+ EEPROMClass() {
19
+ state = GODMODE();
20
+ }
21
+ // array subscript operator
22
+ uint8_t &operator[](const int index) {
23
+ assert(index < EEPROM_SIZE);
24
+ return state->eeprom[index];
25
+ }
26
+
27
+ uint8_t read(const int index) {
28
+ assert(index < EEPROM_SIZE);
29
+ return state->eeprom[index];
30
+ }
31
+
32
+ void write(const int index, const uint8_t value) {
33
+ assert(index < EEPROM_SIZE);
34
+ state->eeprom[index] = value;
35
+ }
36
+
37
+ void update(const int index, const uint8_t value) {
38
+ assert(index < EEPROM_SIZE);
39
+ state->eeprom[index] = value;
40
+ }
41
+
42
+ uint16_t length() { return EEPROM_SIZE; }
43
+
44
+ // read any object
45
+ template <typename T> T &get(const int index, T &object) {
46
+ uint8_t *ptr = (uint8_t *)&object;
47
+ for (int i = 0; i < sizeof(T); ++i) {
48
+ *ptr++ = read(index + i);
49
+ }
50
+ return object;
51
+ }
52
+
53
+ // write any object
54
+ template <typename T> const T &put(const int index, T &object) {
55
+ const uint8_t *ptr = (const uint8_t *)&object;
56
+ for (int i = 0; i < sizeof(T); ++i) {
57
+ write(index + i, *ptr++);
58
+ }
59
+ return object;
60
+ }
61
+ };
62
+
63
+ // global available in Godmode.cpp
64
+ extern EEPROMClass EEPROM;
@@ -1,6 +1,7 @@
1
1
  #include "Godmode.h"
2
2
  #include "HardwareSerial.h"
3
3
  #include "SPI.h"
4
+ #include "Wire.h"
4
5
 
5
6
  GodmodeState* GODMODE() {
6
7
  return GodmodeState::getInstance();
@@ -109,3 +110,13 @@ inline std::ostream& operator << ( std::ostream& out, const PinHistory<T>& ph )
109
110
 
110
111
  // defined in SPI.h
111
112
  SPIClass SPI = SPIClass(&GODMODE()->spi.dataIn, &GODMODE()->spi.dataOut);
113
+
114
+ // defined in Wire.h
115
+ TwoWire Wire = TwoWire();
116
+
117
+ #if defined(EEPROM_SIZE)
118
+ #include <EEPROM.h>
119
+ EEPROMClass EEPROM;
120
+ #endif
121
+
122
+ volatile uint8_t __ARDUINO_CI_SFR_MOCK[1024];
@@ -1,6 +1,8 @@
1
1
  #pragma once
2
2
  #include "ArduinoDefines.h"
3
+ #if defined(__AVR__)
3
4
  #include <avr/io.h>
5
+ #endif
4
6
  #include "WString.h"
5
7
  #include "PinHistory.h"
6
8
 
@@ -18,16 +20,29 @@ unsigned long micros();
18
20
 
19
21
  #define MOCK_PINS_COUNT 256
20
22
 
21
- #if defined(UBRR3H)
22
- #define NUM_SERIAL_PORTS 4
23
- #elif defined(UBRR2H)
24
- #define NUM_SERIAL_PORTS 3
25
- #elif defined(UBRR1H)
26
- #define NUM_SERIAL_PORTS 2
27
- #elif defined(UBRRH) || defined(UBRR0H)
28
- #define NUM_SERIAL_PORTS 1
23
+ #if (!defined NUM_SERIAL_PORTS)
24
+ #if defined(UBRR3H)
25
+ #define NUM_SERIAL_PORTS 4
26
+ #elif defined(UBRR2H)
27
+ #define NUM_SERIAL_PORTS 3
28
+ #elif defined(UBRR1H)
29
+ #define NUM_SERIAL_PORTS 2
30
+ #elif defined(UBRRH) || defined(UBRR0H)
31
+ #define NUM_SERIAL_PORTS 1
32
+ #else
33
+ #define NUM_SERIAL_PORTS 0
34
+ #endif
35
+ #endif
36
+
37
+ // different EEPROM implementations have different macros that leak out
38
+ #if !defined(EEPROM_SIZE) && defined(E2END) && (E2END)
39
+ // public value indicates that feature is available
40
+ #define EEPROM_SIZE (E2END + 1)
41
+ // local array size
42
+ #define _EEPROM_SIZE EEPROM_SIZE
29
43
  #else
30
- #define NUM_SERIAL_PORTS 0
44
+ // feature is not available but we want to have the array so other code compiles
45
+ #define _EEPROM_SIZE (0)
31
46
  #endif
32
47
 
33
48
  class GodmodeState {
@@ -43,6 +58,8 @@ class GodmodeState {
43
58
  uint8_t mode;
44
59
  };
45
60
 
61
+ uint8_t mmapPorts[MOCK_PINS_COUNT];
62
+
46
63
  static GodmodeState* instance;
47
64
 
48
65
  public:
@@ -54,6 +71,7 @@ class GodmodeState {
54
71
  struct PortDef serialPort[NUM_SERIAL_PORTS];
55
72
  struct InterruptDef interrupt[MOCK_PINS_COUNT]; // not sure how to get actual number
56
73
  struct PortDef spi;
74
+ uint8_t eeprom[_EEPROM_SIZE];
57
75
 
58
76
  void resetPins() {
59
77
  for (int i = 0; i < MOCK_PINS_COUNT; ++i) {
@@ -87,12 +105,28 @@ class GodmodeState {
87
105
  spi.readDelayMicros = 0;
88
106
  }
89
107
 
108
+ void resetMmapPorts() {
109
+ for (int i = 0; i < MOCK_PINS_COUNT; ++i) {
110
+ mmapPorts[i] = 1;
111
+ }
112
+ }
113
+
114
+ void resetEEPROM() {
115
+ #if defined(EEPROM_SIZE)
116
+ for(int i = 0; i < EEPROM_SIZE; ++i) {
117
+ eeprom[i] = 255;
118
+ }
119
+ #endif
120
+ }
121
+
90
122
  void reset() {
91
123
  resetClock();
92
124
  resetPins();
93
125
  resetInterrupts();
94
126
  resetPorts();
95
127
  resetSPI();
128
+ resetMmapPorts();
129
+ resetEEPROM();
96
130
  seed = 1;
97
131
  }
98
132
 
@@ -112,6 +146,9 @@ class GodmodeState {
112
146
  return instance->micros;
113
147
  }
114
148
 
149
+ uint8_t* pMmapPort(uint8_t port) { return &mmapPorts[port]; }
150
+ uint8_t mmapPortValue(uint8_t port) { return mmapPorts[port]; }
151
+
115
152
  // C++ 11, declare as public for better compiler error messages
116
153
  GodmodeState(GodmodeState const&) = delete;
117
154
  void operator=(GodmodeState const&) = delete;
@@ -139,5 +176,17 @@ void detachInterrupt(uint8_t interrupt);
139
176
  inline void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0) {}
140
177
  inline void noTone(uint8_t _pin) {}
141
178
 
179
+ // These definitions allow the following to compile (see issue #193):
180
+ // https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h:341
181
+ // we allow one byte per port which "wastes" 224 bytes, but makes the code easier
182
+ #if defined(__AVR__)
183
+ #define digitalPinToBitMask(pin) (1)
184
+ #define digitalPinToPort(pin) (pin)
185
+ #define portInputRegister(port) (GODMODE()->pMmapPort(port))
186
+ #define portOutputRegister(port) (GODMODE()->pMmapPort(port))
187
+ #else
188
+ // we don't (yet) support other boards
189
+ #endif
190
+
142
191
 
143
192
  GodmodeState* GODMODE();
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  //#include <inttypes.h>
4
- #include "Stream.h"
4
+ #include "ci/StreamTape.h"
5
5
 
6
6
  // definitions neeeded for Serial.begin's config arg
7
7
  #define SERIAL_5N1 0x00
@@ -29,53 +29,34 @@
29
29
  #define SERIAL_7O2 0x3C
30
30
  #define SERIAL_8O2 0x3E
31
31
 
32
- class HardwareSerial : public Stream, public ObservableDataStream
32
+ class HardwareSerial : public StreamTape
33
33
  {
34
- protected:
35
- String* mGodmodeDataOut;
36
-
37
34
  public:
38
- HardwareSerial(String* dataIn, String* dataOut, unsigned long* delay): Stream(), ObservableDataStream() {
39
- mGodmodeDataIn = dataIn;
40
- mGodmodeDataOut = dataOut;
41
- mGodmodeMicrosDelay = delay;
42
- }
35
+ HardwareSerial(String* dataIn, String* dataOut, unsigned long* delay): StreamTape(dataIn, dataOut, delay) {}
36
+
43
37
  void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
44
38
  void begin(unsigned long baud, uint8_t config) {
45
39
  *mGodmodeMicrosDelay = 1000000 / baud;
46
40
  }
47
41
  void end() {}
48
42
 
49
- // virtual int available(void);
50
- // virtual int peek(void);
51
- // virtual int read(void);
52
- // virtual int availableForWrite(void);
53
- // virtual void flush(void);
54
- virtual size_t write(uint8_t aChar) {
55
- mGodmodeDataOut->append(String((char)aChar));
56
- advertiseByte((unsigned char)aChar);
57
- return 1;
58
- }
59
-
60
- // https://stackoverflow.com/a/4271276
61
- using Print::write; // pull in write(str) and write(buf, size) from Print
43
+ // support "if (Serial1) {}" sorts of things
62
44
  operator bool() { return true; }
63
-
64
45
  };
65
46
 
66
- #if defined(UBRRH) || defined(UBRR0H)
47
+ #if NUM_SERIAL_PORTS >= 1
67
48
  extern HardwareSerial Serial;
68
49
  #define HAVE_HWSERIAL0
69
50
  #endif
70
- #if defined(UBRR1H)
51
+ #if NUM_SERIAL_PORTS >= 2
71
52
  extern HardwareSerial Serial1;
72
53
  #define HAVE_HWSERIAL1
73
54
  #endif
74
- #if defined(UBRR2H)
55
+ #if NUM_SERIAL_PORTS >= 3
75
56
  extern HardwareSerial Serial2;
76
57
  #define HAVE_HWSERIAL2
77
58
  #endif
78
- #if defined(UBRR3H)
59
+ #if NUM_SERIAL_PORTS >= 4
79
60
  extern HardwareSerial Serial3;
80
61
  #define HAVE_HWSERIAL3
81
62
  #endif