diff options
-rw-r--r-- | lib/pbdrv/drv/rp2040/mod.c | 16 | ||||
-rw-r--r-- | main/i2c.c | 7 |
2 files changed, 17 insertions, 6 deletions
diff --git a/lib/pbdrv/drv/rp2040/mod.c b/lib/pbdrv/drv/rp2040/mod.c index b572c4e..6becdee 100644 --- a/lib/pbdrv/drv/rp2040/mod.c +++ b/lib/pbdrv/drv/rp2040/mod.c @@ -11,13 +11,22 @@ #define PBDRV_I2C i2c0 #define BUF_SIZE 256 +static volatile bool pbdrv_i2c_msg_avail = false; +static uint8_t data[BUF_SIZE]; +static size_t size = 0; + +// TODO: create event group instead of pbdrv_i2c_msg_avail +// TODO: create freertos task that monitors the pbdrv_i2c_msg_avail flag and +// calls pbdrv_i2c_recv when a message is received + + /** * \note this function is called from the I2C ISR, and should return as quickly * as possible. */ static void recv_event(i2c_inst_t *i2c, i2c_slave_event_t event) { - static uint8_t data[BUF_SIZE]; - static size_t size = 0; + // message needs to be handled first + if (pbdrv_i2c_msg_avail) return; switch (event) { case I2C_SLAVE_RECEIVE: { @@ -27,7 +36,8 @@ static void recv_event(i2c_inst_t *i2c, i2c_slave_event_t event) { } case I2C_SLAVE_FINISH: { // TODO: handle this w/ queue mechanism instead? - pbdrv_i2c_recv(data, size); + // pbdrv_i2c_recv(data, size); + pbdrv_i2c_msg_avail = true; size = 0; break; } @@ -30,6 +30,10 @@ // return array; // } +void pbdrv_i2c_recv(const uint8_t * a, size_t b) { + printf("%.*s", b, a); +} + void bus_task() { // scan bus for slaves // send updates at regular intervals @@ -42,9 +46,6 @@ void bus_task() { while (true) { vTaskDelay(10 / portTICK_PERIOD_MS); pbdrv_i2c_send(0x69, (uint8_t *) "bbbbbbbb", 9); - - // i2c_write_blocking(i2c0, 0x69, (uint8_t *) "bbbbbbbb", 9, false); - // pbdrv_i2c_recv(NULL, 0); } // while(1) { |