aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/drv
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pbdrv/drv')
-rw-r--r--lib/pbdrv/drv/arduino/mod.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/pbdrv/drv/arduino/mod.cpp b/lib/pbdrv/drv/arduino/mod.cpp
index c7bbe45..2113ba2 100644
--- a/lib/pbdrv/drv/arduino/mod.cpp
+++ b/lib/pbdrv/drv/arduino/mod.cpp
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <stdint.h>
+#include "../../pb.h"
#include "mod.h"
static void recv_event(int bytes) {
@@ -22,12 +23,25 @@ static void recv_event(int bytes) {
void pbdrv_setup() {
Wire.begin((int) PBDRV_MOD_ADDR);
+ Wire.setWireTimeout(PB_TIMEOUT_US, true);
+ Wire.setClock(PB_CLOCK_SPEED_HZ);
Wire.onReceive(recv_event);
}
__weak void pbdrv_i2c_send(i2c_addr_t addr, const uint8_t * buf, size_t sz) {
- Wire.beginTransmission((int) addr);
- Wire.write(buf, sz);
- Wire.endTransmission();
+ uint8_t error;
+ uint8_t retry = 4;
+ do {
+ error = 0;
+ Wire.beginTransmission((int) addr);
+ size_t written = Wire.write(buf, sz);
+ if (written != sz)
+ error++;
+ error += Wire.endTransmission(true);
+ Wire.setWireTimeout(PB_TIMEOUT_US, true);
+
+ if(retry == 0) break;
+ retry--;
+ } while (error);
}