|
@@ -25,7 +25,6 @@
|
25
|
25
|
#if ENABLED(EXPERIMENTAL_I2CBUS)
|
26
|
26
|
|
27
|
27
|
#include "twibus.h"
|
28
|
|
-
|
29
|
28
|
#include <Wire.h>
|
30
|
29
|
|
31
|
30
|
TWIBus::TWIBus() {
|
|
@@ -121,18 +120,12 @@ bool TWIBus::request(const uint8_t bytes) {
|
121
|
120
|
#endif
|
122
|
121
|
|
123
|
122
|
// requestFrom() is a blocking function
|
124
|
|
- Wire.requestFrom(this->addr, bytes);
|
125
|
|
-
|
126
|
|
- // Wait for all bytes to arrive
|
127
|
|
- millis_t t = millis() + this->timeout;
|
128
|
|
- while (Wire.available() < bytes)
|
129
|
|
- if (ELAPSED(millis(), t)) {
|
130
|
|
- #if ENABLED(DEBUG_TWIBUS)
|
131
|
|
- SERIAL_ECHO_START;
|
132
|
|
- SERIAL_ECHOLNPGM("i2c timeout");
|
133
|
|
- #endif
|
134
|
|
- return false;
|
135
|
|
- }
|
|
123
|
+ if (Wire.requestFrom(this->addr, bytes) == 0) {
|
|
124
|
+ #if ENABLED(DEBUG_TWIBUS)
|
|
125
|
+ debug("request fail", this->addr);
|
|
126
|
+ #endif
|
|
127
|
+ return false;
|
|
128
|
+ }
|
136
|
129
|
|
137
|
130
|
return true;
|
138
|
131
|
}
|
|
@@ -151,6 +144,11 @@ uint8_t TWIBus::capture(char *dst, const uint8_t bytes) {
|
151
|
144
|
uint8_t count = 0;
|
152
|
145
|
while (count < bytes && Wire.available())
|
153
|
146
|
dst[count++] = Wire.read();
|
|
147
|
+
|
|
148
|
+ #if ENABLED(DEBUG_TWIBUS)
|
|
149
|
+ debug(PSTR("capture"), count);
|
|
150
|
+ #endif
|
|
151
|
+
|
154
|
152
|
return count;
|
155
|
153
|
}
|
156
|
154
|
|