aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pbdrv/drv/arduino/mod.cpp20
-rw-r--r--lib/pbdrv/pb.h22
-rw-r--r--puzzle/dummy/main.cpp28
3 files changed, 56 insertions, 14 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
diff --git a/puzzle/dummy/main.cpp b/puzzle/dummy/main.cpp
index 1c79441..688549f 100644
--- a/puzzle/dummy/main.cpp
+++ b/puzzle/dummy/main.cpp
@@ -3,12 +3,36 @@
#include "drv/arduino/mod.h"
+// #define THOMAS
+
+#ifdef THOMAS
+#define ADDR_RX 0x69
+#define ADDR_TX 0x20
+#define MSG "hoi"
+#define MSG_DELAY 10
+#else
+#define ADDR_TX 0x69
+#define ADDR_RX 0x20
+#define MSG "dag"
+#define MSG_DELAY 9
+#endif
+
const char * PBDRV_MOD_NAME = "dummy";
-const i2c_addr_t PBDRV_MOD_ADDR = 0x20;
+const i2c_addr_t PBDRV_MOD_ADDR = ADDR_RX;
void setup() {
pbdrv_setup();
+ Serial.begin(115200);
+ pinMode(4, OUTPUT);
+ digitalWrite(4, LOW);
}
-void loop() { }
+void loop() {
+ pbdrv_i2c_send(ADDR_TX, (uint8_t *) MSG, 4);
+ delay(MSG_DELAY);
+}
+
+void pbdrv_i2c_recv(const uint8_t * data, size_t size) {
+ Serial.println((char *) data);
+}