arduino_ci 0.3.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +125 -69
- data/REFERENCE.md +711 -0
- data/cpp/arduino/Arduino.h +1 -7
- data/cpp/arduino/ArduinoDefines.h +3 -0
- data/cpp/arduino/AvrMath.h +117 -17
- data/cpp/arduino/Client.h +27 -0
- data/cpp/arduino/EEPROM.h +64 -0
- data/cpp/arduino/Godmode.cpp +7 -0
- data/cpp/arduino/Godmode.h +121 -15
- data/cpp/arduino/HardwareSerial.h +4 -4
- data/cpp/arduino/IPAddress.h +59 -0
- data/cpp/arduino/Print.h +9 -12
- data/cpp/arduino/Printable.h +8 -0
- data/cpp/arduino/SPI.h +11 -3
- data/cpp/arduino/Server.h +5 -0
- data/cpp/arduino/Udp.h +27 -0
- data/cpp/arduino/Wire.h +197 -77
- data/cpp/arduino/avr/io.h +10 -1
- data/cpp/arduino/avr/pgmspace.h +76 -46
- data/cpp/unittest/ArduinoUnitTests.h +32 -0
- data/cpp/unittest/Assertion.h +54 -26
- data/cpp/unittest/Compare.h +58 -51
- data/cpp/unittest/OstreamHelpers.h +4 -0
- data/exe/arduino_ci.rb +538 -0
- data/exe/arduino_ci_remote.rb +2 -393
- data/exe/arduino_library_location.rb +2 -2
- data/exe/ensure_arduino_installation.rb +7 -1
- data/lib/arduino_ci.rb +1 -0
- data/lib/arduino_ci/arduino_backend.rb +238 -0
- data/lib/arduino_ci/arduino_downloader.rb +43 -73
- data/lib/arduino_ci/arduino_downloader_linux.rb +17 -55
- data/lib/arduino_ci/arduino_downloader_osx.rb +21 -33
- data/lib/arduino_ci/arduino_downloader_windows.rb +11 -53
- data/lib/arduino_ci/arduino_installation.rb +18 -80
- data/lib/arduino_ci/ci_config.rb +8 -11
- data/lib/arduino_ci/cpp_library.rb +250 -59
- data/lib/arduino_ci/host.rb +59 -4
- data/lib/arduino_ci/library_properties.rb +101 -0
- data/lib/arduino_ci/version.rb +1 -1
- data/misc/default.yml +57 -6
- metadata +19 -87
- data/cpp/arduino/Arduino.h.orig +0 -143
- data/exe/libasan.rb +0 -29
- data/lib/arduino_ci/arduino_cmd.rb +0 -332
- data/lib/arduino_ci/arduino_cmd_linux.rb +0 -17
- data/lib/arduino_ci/arduino_cmd_linux_builder.rb +0 -19
- data/lib/arduino_ci/arduino_cmd_osx.rb +0 -17
- data/lib/arduino_ci/arduino_cmd_windows.rb +0 -17
@@ -44,19 +44,19 @@ class HardwareSerial : public StreamTape
|
|
44
44
|
operator bool() { return true; }
|
45
45
|
};
|
46
46
|
|
47
|
-
#if
|
47
|
+
#if NUM_SERIAL_PORTS >= 1
|
48
48
|
extern HardwareSerial Serial;
|
49
49
|
#define HAVE_HWSERIAL0
|
50
50
|
#endif
|
51
|
-
#if
|
51
|
+
#if NUM_SERIAL_PORTS >= 2
|
52
52
|
extern HardwareSerial Serial1;
|
53
53
|
#define HAVE_HWSERIAL1
|
54
54
|
#endif
|
55
|
-
#if
|
55
|
+
#if NUM_SERIAL_PORTS >= 3
|
56
56
|
extern HardwareSerial Serial2;
|
57
57
|
#define HAVE_HWSERIAL2
|
58
58
|
#endif
|
59
|
-
#if
|
59
|
+
#if NUM_SERIAL_PORTS >= 4
|
60
60
|
extern HardwareSerial Serial3;
|
61
61
|
#define HAVE_HWSERIAL3
|
62
62
|
#endif
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <stdint.h>
|
4
|
+
|
5
|
+
class IPAddress {
|
6
|
+
private:
|
7
|
+
union {
|
8
|
+
uint8_t bytes[4];
|
9
|
+
uint32_t dword;
|
10
|
+
operator uint8_t *() const { return (uint8_t *)bytes; }
|
11
|
+
} _address;
|
12
|
+
|
13
|
+
public:
|
14
|
+
// Constructors
|
15
|
+
IPAddress() : IPAddress(0, 0, 0, 0) {}
|
16
|
+
IPAddress(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4) {
|
17
|
+
_address.bytes[0] = octet1;
|
18
|
+
_address.bytes[1] = octet2;
|
19
|
+
_address.bytes[2] = octet3;
|
20
|
+
_address.bytes[3] = octet4;
|
21
|
+
}
|
22
|
+
IPAddress(uint32_t dword) { _address.dword = dword; }
|
23
|
+
IPAddress(const uint8_t bytes[]) {
|
24
|
+
_address.bytes[0] = bytes[0];
|
25
|
+
_address.bytes[1] = bytes[1];
|
26
|
+
_address.bytes[2] = bytes[2];
|
27
|
+
_address.bytes[3] = bytes[3];
|
28
|
+
}
|
29
|
+
IPAddress(unsigned long dword) { _address.dword = (uint32_t)dword; }
|
30
|
+
|
31
|
+
// Accessors
|
32
|
+
uint32_t asWord() const { return _address.dword; }
|
33
|
+
uint8_t *raw_address() { return _address.bytes; }
|
34
|
+
|
35
|
+
// Comparisons
|
36
|
+
bool operator==(const IPAddress &rhs) const {
|
37
|
+
return _address.dword == rhs.asWord();
|
38
|
+
}
|
39
|
+
|
40
|
+
bool operator!=(const IPAddress &rhs) const {
|
41
|
+
return _address.dword != rhs.asWord();
|
42
|
+
}
|
43
|
+
|
44
|
+
// Indexing
|
45
|
+
uint8_t operator[](int index) const { return _address.bytes[index]; }
|
46
|
+
uint8_t &operator[](int index) { return _address.bytes[index]; }
|
47
|
+
|
48
|
+
// Conversions
|
49
|
+
operator uint32_t() const { return _address.dword; };
|
50
|
+
|
51
|
+
friend class EthernetClass;
|
52
|
+
friend class UDP;
|
53
|
+
friend class Client;
|
54
|
+
friend class Server;
|
55
|
+
friend class DhcpClass;
|
56
|
+
friend class DNSClient;
|
57
|
+
};
|
58
|
+
|
59
|
+
const IPAddress INADDR_NONE(0, 0, 0, 0);
|
data/cpp/arduino/Print.h
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
#include <stdio.h>
|
4
4
|
#include <avr/pgmspace.h>
|
5
|
+
|
6
|
+
#include "Printable.h"
|
5
7
|
#include "WString.h"
|
6
8
|
|
7
9
|
#define DEC 10
|
@@ -12,22 +14,17 @@
|
|
12
14
|
#endif
|
13
15
|
#define BIN 2
|
14
16
|
|
15
|
-
class Print;
|
16
|
-
|
17
|
-
class Printable
|
18
|
-
{
|
19
|
-
public:
|
20
|
-
virtual size_t printTo(Print& p) const = 0;
|
21
|
-
};
|
22
|
-
|
23
17
|
class Print
|
24
18
|
{
|
19
|
+
private:
|
20
|
+
int write_error;
|
21
|
+
protected:
|
22
|
+
void setWriteError(int err = 1) { write_error = err; }
|
25
23
|
public:
|
26
|
-
Print() {}
|
24
|
+
Print() : write_error(0) {}
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
void clearWriteError() { }
|
26
|
+
int getWriteError() { return write_error; }
|
27
|
+
void clearWriteError() { setWriteError(0); }
|
31
28
|
virtual int availableForWrite() { return 0; }
|
32
29
|
|
33
30
|
virtual size_t write(uint8_t) = 0;
|
data/cpp/arduino/SPI.h
CHANGED
@@ -40,7 +40,11 @@
|
|
40
40
|
|
41
41
|
class SPISettings {
|
42
42
|
public:
|
43
|
-
|
43
|
+
uint8_t bitOrder;
|
44
|
+
|
45
|
+
SPISettings(uint32_t clock, uint8_t bitOrder = MSBFIRST, uint8_t dataMode = SPI_MODE0) {
|
46
|
+
this->bitOrder = bitOrder;
|
47
|
+
};
|
44
48
|
SPISettings(){};
|
45
49
|
};
|
46
50
|
|
@@ -68,6 +72,7 @@ public:
|
|
68
72
|
// and configure the correct settings.
|
69
73
|
void beginTransaction(SPISettings settings)
|
70
74
|
{
|
75
|
+
this->bitOrder = settings.bitOrder;
|
71
76
|
#ifdef SPI_TRANSACTION_MISMATCH_LED
|
72
77
|
if (inTransactionFlag) {
|
73
78
|
pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT);
|
@@ -94,10 +99,12 @@ public:
|
|
94
99
|
uint16_t transfer16(uint16_t data) {
|
95
100
|
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out;
|
96
101
|
in.val = data;
|
97
|
-
if (
|
102
|
+
if (bitOrder == MSBFIRST) {
|
98
103
|
out.msb = transfer(in.msb);
|
99
104
|
out.lsb = transfer(in.lsb);
|
100
|
-
}
|
105
|
+
}
|
106
|
+
else
|
107
|
+
{
|
101
108
|
out.lsb = transfer(in.lsb);
|
102
109
|
out.msb = transfer(in.msb);
|
103
110
|
}
|
@@ -143,6 +150,7 @@ private:
|
|
143
150
|
#endif
|
144
151
|
|
145
152
|
bool isStarted = false;
|
153
|
+
uint8_t bitOrder;
|
146
154
|
String* dataIn;
|
147
155
|
String* dataOut;
|
148
156
|
};
|
data/cpp/arduino/Udp.h
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <IPAddress.h>
|
4
|
+
#include <Stream.h>
|
5
|
+
|
6
|
+
class UDP : public Stream {
|
7
|
+
protected:
|
8
|
+
uint8_t *rawIPAddress(IPAddress &addr) { return addr.raw_address(); };
|
9
|
+
|
10
|
+
public:
|
11
|
+
UDP() {
|
12
|
+
// The Stream mock defines a String buffer but never puts anyting in it!
|
13
|
+
if (!mGodmodeDataIn) {
|
14
|
+
mGodmodeDataIn = new String;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
~UDP() {
|
18
|
+
if (mGodmodeDataIn) {
|
19
|
+
delete mGodmodeDataIn;
|
20
|
+
mGodmodeDataIn = nullptr;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
virtual size_t write(uint8_t value) {
|
24
|
+
mGodmodeDataIn->concat(value);
|
25
|
+
return 1;
|
26
|
+
}
|
27
|
+
};
|
data/cpp/arduino/Wire.h
CHANGED
@@ -1,138 +1,258 @@
|
|
1
|
+
/*
|
2
|
+
* The Wire Library (https://www.arduino.cc/en/Reference/Wire)
|
3
|
+
* allows you to communicate with I2C/TWI devices. The general
|
4
|
+
* TWI protocol supports one "master" device and many "slave"
|
5
|
+
* devices that share the same two wires (SDA and SCL for data
|
6
|
+
* and clock respectively).
|
7
|
+
*
|
8
|
+
* You initialize the library by calling begin() as a master or
|
9
|
+
* begin(myAddress) as a slave (with an int from 8-127). In the
|
10
|
+
* initial mock implementation we support only the master role.
|
11
|
+
*
|
12
|
+
* To send bytes from a master to a slave, start with
|
13
|
+
* beginTransmission(slaveAddress), then use write(byte) to
|
14
|
+
* enqueue data, and finish with endTransmission().
|
15
|
+
*
|
16
|
+
* When a master wants to read, it starts with a call to
|
17
|
+
* requestFrom(slaveAddress, quantity) which blocks until the
|
18
|
+
* request finishes. The return value is either 0 (if the slave
|
19
|
+
* does not respond) or the number of bytes requested (which
|
20
|
+
* might be more than the number sent since reading is simply
|
21
|
+
* looking at a pin value at each clock tick).
|
22
|
+
*
|
23
|
+
* A master can write to or read from two or more slaves in
|
24
|
+
* quick succession (say, during one loop() function), so our
|
25
|
+
* mock needs to support preloading data to be read from multiple
|
26
|
+
* slaves and archive data sent to multiple slaves.
|
27
|
+
*
|
28
|
+
* In the mock, this is handled by having an array of wireData_t
|
29
|
+
* structures, each of which contains a deque for input and a
|
30
|
+
* deque for output. You can preload data to be read and you can
|
31
|
+
* look at a log of data that has been written.
|
32
|
+
*/
|
1
33
|
|
2
34
|
#pragma once
|
3
35
|
|
4
36
|
#include <inttypes.h>
|
5
37
|
#include "Stream.h"
|
38
|
+
#include <cassert>
|
39
|
+
#include <deque>
|
40
|
+
using std::deque;
|
41
|
+
|
42
|
+
const size_t SLAVE_COUNT = 128;
|
43
|
+
const size_t BUFFER_LENGTH = 32;
|
44
|
+
|
45
|
+
struct wireData_t {
|
46
|
+
uint8_t misoSize; // bytes remaining for this read
|
47
|
+
uint8_t mosiSize; // bytes included in this write
|
48
|
+
deque<uint8_t> misoBuffer; // master in, slave out
|
49
|
+
deque<uint8_t> mosiBuffer; // master out, slave in
|
50
|
+
};
|
51
|
+
|
52
|
+
// Some inspiration taken from
|
53
|
+
// https://github.com/arduino/ArduinoCore-megaavr/blob/d2a81093ba66d22dbda14c30d146c231c5910734/libraries/Wire/src/Wire.cpp
|
54
|
+
class TwoWire : public ObservableDataStream {
|
55
|
+
private:
|
56
|
+
bool _didBegin = false;
|
57
|
+
wireData_t* in = nullptr; // pointer to current slave for writing
|
58
|
+
wireData_t* out = nullptr; // pointer to current slave for reading
|
59
|
+
wireData_t slaves[SLAVE_COUNT];
|
6
60
|
|
7
|
-
class TwoWire : public ObservableDataStream
|
8
|
-
{
|
9
61
|
public:
|
10
|
-
|
62
|
+
|
63
|
+
//////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
+
// testing methods
|
65
|
+
//////////////////////////////////////////////////////////////////////////////////////////////
|
66
|
+
|
67
|
+
// initialize all the mocks
|
68
|
+
void resetMocks() {
|
69
|
+
_didBegin = false;
|
70
|
+
in = nullptr; // pointer to current slave for writing
|
71
|
+
out = nullptr; // pointer to current slave for reading
|
72
|
+
for (int i = 0; i < SLAVE_COUNT; ++i) {
|
73
|
+
slaves[i].misoSize = 0;
|
74
|
+
slaves[i].mosiSize = 0;
|
75
|
+
slaves[i].misoBuffer.clear();
|
76
|
+
slaves[i].mosiBuffer.clear();
|
77
|
+
}
|
11
78
|
}
|
12
79
|
|
13
|
-
//
|
14
|
-
|
15
|
-
|
16
|
-
|
80
|
+
// to verify that Wire.begin() was called at some point
|
81
|
+
bool didBegin() { return _didBegin; }
|
82
|
+
|
83
|
+
// to access the MISO buffer, which allows you to mock what the master will read in a request
|
84
|
+
deque<uint8_t>* getMiso(uint8_t address) {
|
85
|
+
return &slaves[address].misoBuffer;
|
17
86
|
}
|
18
|
-
|
19
|
-
|
20
|
-
|
87
|
+
|
88
|
+
// to access the MOSI buffer, which records what the master sends during a write
|
89
|
+
deque<uint8_t>* getMosi(uint8_t address) {
|
90
|
+
return &slaves[address].mosiBuffer;
|
21
91
|
}
|
22
|
-
|
23
|
-
|
92
|
+
|
93
|
+
|
94
|
+
//////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
+
// mock implementation
|
96
|
+
//////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
+
|
98
|
+
// constructor initializes internal data
|
99
|
+
TwoWire() {
|
100
|
+
resetMocks();
|
24
101
|
}
|
25
|
-
|
26
|
-
|
102
|
+
|
103
|
+
// https://www.arduino.cc/en/Reference/WireBegin
|
104
|
+
// Initiate the Wire library and join the I2C bus as a master or slave. This
|
105
|
+
// should normally be called only once.
|
106
|
+
void begin() { begin(0); }
|
107
|
+
void begin(uint8_t address) {
|
108
|
+
assert(address == 0);
|
109
|
+
_didBegin = true;
|
27
110
|
}
|
111
|
+
void begin(int address) { begin((uint8_t)address); }
|
112
|
+
// NOTE: end() is not part of the published API so we ignore it
|
113
|
+
void end() {}
|
28
114
|
|
29
115
|
// https://www.arduino.cc/en/Reference/WireSetClock
|
30
|
-
// This function modifies the clock frequency for I2C communication. I2C slave
|
31
|
-
// clock frequency, however 100KHz is usually
|
32
|
-
|
33
|
-
|
34
|
-
}
|
116
|
+
// This function modifies the clock frequency for I2C communication. I2C slave
|
117
|
+
// devices have no minimum working clock frequency, however 100KHz is usually
|
118
|
+
// the baseline.
|
119
|
+
// Since the mock does not actually write pins we ignore this.
|
120
|
+
void setClock(uint32_t clock) {}
|
35
121
|
|
36
122
|
// https://www.arduino.cc/en/Reference/WireBeginTransmission
|
37
|
-
// Begin a transmission to the I2C slave device with the given address.
|
38
|
-
// transmission with the write() function and
|
39
|
-
|
40
|
-
|
41
|
-
}
|
123
|
+
// Begin a transmission to the I2C slave device with the given address.
|
124
|
+
// Subsequently, queue bytes for transmission with the write() function and
|
125
|
+
// transmit them by calling endTransmission().
|
126
|
+
// For the mock we update our output to the proper destination.
|
42
127
|
void beginTransmission(uint8_t address) {
|
43
|
-
|
128
|
+
assert(_didBegin);
|
129
|
+
assert(address > 0 && address < SLAVE_COUNT);
|
130
|
+
assert(out == nullptr);
|
131
|
+
out = &slaves[address];
|
132
|
+
out->mosiSize = 0;
|
44
133
|
}
|
134
|
+
void beginTransmission(int address) { beginTransmission((uint8_t)address); }
|
45
135
|
|
46
136
|
// https://www.arduino.cc/en/Reference/WireEndTransmission
|
47
|
-
// Ends a transmission to a slave device that was begun by beginTransmission()
|
48
|
-
// queued by write().
|
49
|
-
|
50
|
-
|
137
|
+
// Ends a transmission to a slave device that was begun by beginTransmission()
|
138
|
+
// and transmits the bytes that were queued by write().
|
139
|
+
// In the mock we just leave the bytes there in the buffer
|
140
|
+
// to be read by the testing API and we ignore the sendStop.
|
141
|
+
uint8_t endTransmission(bool sendStop) {
|
142
|
+
assert(_didBegin);
|
143
|
+
assert(out);
|
144
|
+
out = nullptr;
|
51
145
|
return 0; // success
|
52
146
|
}
|
53
|
-
uint8_t endTransmission(void) {
|
54
|
-
return endTransmission((uint8_t)true);
|
55
|
-
}
|
147
|
+
uint8_t endTransmission(void) { return endTransmission(true); }
|
56
148
|
|
57
149
|
// https://www.arduino.cc/en/Reference/WireRequestFrom
|
58
|
-
// Used by the master to request bytes from a slave device. The bytes may then
|
59
|
-
// available() and read() functions.
|
60
|
-
uint8_t requestFrom(
|
61
|
-
|
62
|
-
|
150
|
+
// Used by the master to request bytes from a slave device. The bytes may then
|
151
|
+
// be retrieved with the available() and read() functions.
|
152
|
+
uint8_t requestFrom(uint8_t address, uint8_t quantity, uint32_t _iaddress, uint8_t _isize, uint8_t stop) {
|
153
|
+
assert(_didBegin);
|
154
|
+
assert(address > 0 && address < SLAVE_COUNT);
|
155
|
+
assert(quantity <= BUFFER_LENGTH);
|
156
|
+
in = &slaves[address];
|
157
|
+
// do we have enough data in the input buffer
|
158
|
+
if (quantity <= (in->misoBuffer).size()) { // enough data
|
159
|
+
in->misoSize = quantity;
|
160
|
+
return quantity;
|
161
|
+
} else { // not enough data
|
162
|
+
in->misoSize = 0;
|
163
|
+
in = nullptr;
|
164
|
+
return 0;
|
165
|
+
}
|
63
166
|
}
|
64
|
-
|
65
|
-
|
66
|
-
return requestFrom(address, quantity, stop);
|
167
|
+
|
168
|
+
uint8_t requestFrom(uint8_t address, uint8_t quantity, uint8_t stop) {
|
169
|
+
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint32_t)0, (uint8_t)0, (uint8_t)stop);
|
67
170
|
}
|
171
|
+
|
68
172
|
uint8_t requestFrom(uint8_t address, uint8_t quantity) {
|
69
|
-
return requestFrom((
|
173
|
+
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
|
70
174
|
}
|
71
|
-
|
72
|
-
|
175
|
+
|
176
|
+
uint8_t requestFrom(int address, int quantity) {
|
177
|
+
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
|
73
178
|
}
|
74
|
-
uint8_t requestFrom(
|
75
|
-
|
76
|
-
return 0;
|
179
|
+
uint8_t requestFrom(int address, int quantity, int stop) {
|
180
|
+
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)stop);
|
77
181
|
}
|
78
182
|
|
79
183
|
// https://www.arduino.cc/en/Reference/WireWrite
|
80
|
-
// Writes data from a slave device in response to a request from a master, or
|
81
|
-
// master to slave device (in-between
|
184
|
+
// Writes data from a slave device in response to a request from a master, or
|
185
|
+
// queues bytes for transmission from a master to slave device (in-between
|
186
|
+
// calls to beginTransmission() and endTransmission()).
|
82
187
|
size_t write(uint8_t value) {
|
83
|
-
|
84
|
-
|
188
|
+
assert(out);
|
189
|
+
assert(++(out->mosiSize) <= BUFFER_LENGTH);
|
190
|
+
(out->mosiBuffer).push_back(value);
|
191
|
+
return 1; // number of bytes written
|
192
|
+
}
|
193
|
+
size_t write(const char *str) {
|
194
|
+
return str == NULL ? 0 : write((const uint8_t *)str, String(str).length());
|
85
195
|
}
|
86
|
-
size_t write(const char *str) { return str == NULL ? 0 : write((const uint8_t *)str, String(str).length()); }
|
87
196
|
size_t write(const uint8_t *buffer, size_t size) {
|
88
197
|
size_t n;
|
89
|
-
for (n = 0; size && write(*buffer++) && ++n; --size)
|
198
|
+
for (n = 0; size && write(*buffer++) && ++n; --size)
|
199
|
+
;
|
90
200
|
return n;
|
91
201
|
}
|
92
|
-
size_t write(const char *buffer, size_t size) {
|
202
|
+
size_t write(const char *buffer, size_t size) {
|
203
|
+
return write((const uint8_t *)buffer, size);
|
204
|
+
}
|
93
205
|
size_t write(unsigned long n) { return write((uint8_t)n); }
|
94
206
|
size_t write(long n) { return write((uint8_t)n); }
|
95
207
|
size_t write(unsigned int n) { return write((uint8_t)n); }
|
96
208
|
size_t write(int n) { return write((uint8_t)n); }
|
97
209
|
|
98
210
|
// https://www.arduino.cc/en/Reference/WireAvailable
|
99
|
-
// Returns the number of bytes available for retrieval with read(). This
|
100
|
-
// call to requestFrom() or on a
|
211
|
+
// Returns the number of bytes available for retrieval with read(). This
|
212
|
+
// should be called on a master device after a call to requestFrom() or on a
|
213
|
+
// slave inside the onReceive() handler.
|
101
214
|
int available(void) {
|
102
|
-
|
103
|
-
return
|
215
|
+
assert(in);
|
216
|
+
return in->misoSize;
|
104
217
|
}
|
105
218
|
|
106
219
|
// https://www.arduino.cc/en/Reference/WireRead
|
107
|
-
// Reads a byte that was transmitted from a slave device to a master after a
|
108
|
-
// from a master to a slave. read()
|
109
|
-
|
110
|
-
|
111
|
-
|
220
|
+
// Reads a byte that was transmitted from a slave device to a master after a
|
221
|
+
// call to requestFrom() or was transmitted from a master to a slave. read()
|
222
|
+
// inherits from the Stream utility class.
|
223
|
+
// In the mock we simply return the next byte from the input buffer.
|
224
|
+
uint8_t read(void) {
|
225
|
+
uint8_t value = peek();
|
226
|
+
--in->misoSize;
|
227
|
+
in->misoBuffer.pop_front();
|
228
|
+
return value; // The next byte received
|
112
229
|
}
|
113
|
-
|
114
|
-
|
115
|
-
|
230
|
+
|
231
|
+
// part of the Stream API
|
232
|
+
uint8_t peek(void) {
|
233
|
+
assert(in);
|
234
|
+
assert(0 < in->misoSize);
|
235
|
+
return in->misoBuffer.front(); // The next byte received
|
116
236
|
}
|
237
|
+
|
238
|
+
// part of the Stream API
|
117
239
|
void flush(void) {
|
118
|
-
//
|
240
|
+
// NOTE: commented out in the megaavr repository
|
241
|
+
// data already at the (mock) destination
|
119
242
|
}
|
120
243
|
|
121
244
|
// https://www.arduino.cc/en/Reference/WireOnReceive
|
122
|
-
// Registers a function to be called when a slave device receives a
|
123
|
-
|
124
|
-
|
125
|
-
}
|
245
|
+
// Registers a function to be called when a slave device receives a
|
246
|
+
// transmission from a master.
|
247
|
+
// We don't (yet) support the slave role in the mock
|
248
|
+
void onReceive(void (*callback)(int)) { assert(false); }
|
126
249
|
|
127
250
|
// https://www.arduino.cc/en/Reference/WireOnRequest
|
128
|
-
// Register a function to be called when a master requests data from this
|
129
|
-
|
130
|
-
|
131
|
-
}
|
251
|
+
// Register a function to be called when a master requests data from this
|
252
|
+
// slave device.
|
253
|
+
// We don't (yet) support the slave role in the mock
|
254
|
+
void onRequest(void (*callback)(void)) { assert(false); }
|
132
255
|
|
133
|
-
private:
|
134
|
-
int i2cAddress;
|
135
|
-
bool isMaster = false;
|
136
256
|
};
|
137
257
|
|
138
258
|
extern TwoWire Wire;
|