diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-06 11:56:55 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-06 11:56:55 +0200 |
commit | c7aa2916dce4cd3d82ac1be42c433d1ed66db69e (patch) | |
tree | d75f92b092005c9349ecd119367bdd5be197b638 /lib | |
parent | 6f11bf1dd634e39a2f17fc63f156575f3b10358c (diff) |
WIP debugging arduino puzzle module driver
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pbdrv/drv/arduino/mod.cpp | 20 | ||||
-rw-r--r-- | lib/pbdrv/pb.h | 22 |
2 files changed, 30 insertions, 12 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); } diff --git a/lib/pbdrv/pb.h b/lib/pbdrv/pb.h index e37d785..b6efed0 100644 --- a/lib/pbdrv/pb.h +++ b/lib/pbdrv/pb.h @@ -1,18 +1,22 @@ #pragma once +#define PB_CLOCK_SPEED_HZ 100000 +#define PB_TIMEOUT_MS 10 +#define PB_TIMEOUT_US (1e3 * PB_TIMEOUT_MS) + // Adafruit NeoTrellis modules -#define BUSADDR_ADA_NEO_1 0x2E -#define BUSADDR_ADA_NEO_2 0x2F -#define BUSADDR_ADA_NEO_3 0x30 -#define BUSADDR_ADA_NEO_4 0x32 +#define PB_ADDR_ADA_NEO_1 0x2E +#define PB_ADDR_ADA_NEO_2 0x2F +#define PB_ADDR_ADA_NEO_3 0x30 +#define PB_ADDR_ADA_NEO_4 0x32 // TODO: ??? -#define BUSADDR_MOD_NEOTRELLIS 0 -#define BUSADDR_MOD_SOFTWARE 0 -#define BUSADDR_MOD_HARDWARE 0 -#define BUSADDR_MOD_VAULT 0 +#define PB_ADDR_MOD_NEOTRELLIS 0 +#define PB_ADDR_MOD_SOFTWARE 0 +#define PB_ADDR_MOD_HARDWARE 0 +#define PB_ADDR_MOD_VAULT 0 // #define BUSADDR_MOD_AUTOMATION 0 // main controller -#define BUSADDR_MOD_MAIN 0x00 +#define PB_ADDR_MOD_MAIN 0x00 |