aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/drv/arduino
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-06 11:56:55 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-06 11:56:55 +0200
commitc7aa2916dce4cd3d82ac1be42c433d1ed66db69e (patch)
treed75f92b092005c9349ecd119367bdd5be197b638 /lib/pbdrv/drv/arduino
parent6f11bf1dd634e39a2f17fc63f156575f3b10358c (diff)
WIP debugging arduino puzzle module driver
Diffstat (limited to 'lib/pbdrv/drv/arduino')
-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);
}