aboutsummaryrefslogtreecommitdiff
path: root/main/i2c.c
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-22 18:32:06 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-22 18:32:06 +0200
commitccdcf5001c47820c41e9b962d8498602870289b5 (patch)
tree92c5fc878931e0a792975340f06a12bb6d4585a9 /main/i2c.c
parentd6440954806d381dae5b3df65b43192f897018c6 (diff)
WIP RP2040 I2C workaround code
Diffstat (limited to 'main/i2c.c')
-rw-r--r--main/i2c.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/main/i2c.c b/main/i2c.c
index 2503560..0f23a13 100644
--- a/main/i2c.c
+++ b/main/i2c.c
@@ -16,6 +16,18 @@
i2c_addr_t modules[CFG_PB_MOD_MAX];
size_t modules_size = 0;
+static void bus_scan() {
+ pb_buf_t buf = pb_send_magic_req();
+
+ // check for all 7-bit addresses
+ uint16_t addr_max = 1 << 7;
+ for (uint16_t addr = 0x00; addr < addr_max; addr++) {
+ pb_i2c_send(addr, (uint8_t *) buf.data, buf.size);
+ }
+
+ pb_buf_free(&buf);
+}
+
static void state_exchange() {
for (size_t i = 0; i < modules_size; i++) {
pb_buf_t buf = pb_send_state_req();
@@ -28,10 +40,6 @@ void bus_task() {
// do a scan of the bus
bus_scan();
- // FIXME: this should be removed (see handover: RP2040 I2C limitations)
- // wait for 5 seconds until all handshake responses are received
- pb_mod_blocking_delay_ms(5e3);
-
while(1) {
// send my state to all puzzle modules
state_exchange();