aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/config.def.h20
-rw-r--r--main/i2c.c10
-rw-r--r--main/mod.c3
3 files changed, 24 insertions, 9 deletions
diff --git a/main/config.def.h b/main/config.def.h
index 3d325fe..e9503ed 100644
--- a/main/config.def.h
+++ b/main/config.def.h
@@ -56,11 +56,10 @@
#endif
/** \} */
-#ifndef CFG_LED_PIN
-//! status LED pin
-#define CFG_LED_PIN CYW43_WL_GPIO_LED_PIN
-#endif
-
+/**
+ * \name I2C configuration
+ * \{
+ */
#ifndef CFG_SDA_PIN
//! I^2^C SDA pin
#define CFG_SDA_PIN 16
@@ -69,4 +68,15 @@
//! I^2^C SCL pin
#define CFG_SCL_PIN 17
#endif
+/** \} */
+
+#ifndef CFG_LED_PIN
+//! status LED pin
+#define CFG_LED_PIN CYW43_WL_GPIO_LED_PIN
+#endif
+
+#ifndef CFG_PB_MOD_MAX
+//! maximum number of simultaniously connected puzzle modules
+#define CFG_PB_MOD_MAX 8
+#endif
diff --git a/main/i2c.c b/main/i2c.c
index ccd6b46..612075b 100644
--- a/main/i2c.c
+++ b/main/i2c.c
@@ -9,15 +9,19 @@
#include "i2c.h"
#include "pb-mod.h"
#include "pbdrv.h"
+#include "config.h"
+
+i2c_addr_t modules[CFG_PB_MOD_MAX];
+size_t modules_size = 0;
void bus_task() {
- vTaskDelay(1000 / portTICK_PERIOD_MS);
-
bus_scan();
vTaskDelete(NULL);
}
void pb_route_cmd_magic_res(pb_msg_t * msg) {
- printf("got a magic response from 0x%02x!\n", msg->sender);
+ if (modules_size == CFG_PB_MOD_MAX) return;
+ modules[modules_size++] = msg->sender;
+ printf("i2c: registered puzzle module w/ address 0x%02x\n", msg->sender);
}
diff --git a/main/mod.c b/main/mod.c
index b234f97..11a1bb7 100644
--- a/main/mod.c
+++ b/main/mod.c
@@ -1,5 +1,6 @@
+#include "pb.h"
#include "pb-mod.h"
const char * PB_MOD_NAME = "main controller";
-const i2c_addr_t PB_MOD_ADDR = 0x20;
+const i2c_addr_t PB_MOD_ADDR = PB_ADDR_MOD_MAIN;