diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pbdrv/drv/arduino/mod.cpp | 2 | ||||
-rw-r--r-- | lib/pbdrv/drv/rp2040/mod.c | 14 | ||||
-rw-r--r-- | lib/pbdrv/pb-mod.c | 11 | ||||
-rw-r--r-- | lib/pbdrv/pb-mod.h | 4 |
4 files changed, 18 insertions, 13 deletions
diff --git a/lib/pbdrv/drv/arduino/mod.cpp b/lib/pbdrv/drv/arduino/mod.cpp index c381077..581b80a 100644 --- a/lib/pbdrv/drv/arduino/mod.cpp +++ b/lib/pbdrv/drv/arduino/mod.cpp @@ -48,6 +48,8 @@ static void pb_setup() { * RP2040. */ __weak void pb_i2c_send(i2c_addr_t addr, const uint8_t * buf, size_t sz) { + if (pb_hook_i2c_send(addr, buf, sz)) return; + vTaskDelay(10 / portTICK_PERIOD_MS); // prevent bus collisions Wire.beginTransmission((int) addr); Wire.write(buf, sz); diff --git a/lib/pbdrv/drv/rp2040/mod.c b/lib/pbdrv/drv/rp2040/mod.c index bc20927..bca38d0 100644 --- a/lib/pbdrv/drv/rp2040/mod.c +++ b/lib/pbdrv/drv/rp2040/mod.c @@ -1,10 +1,8 @@ -#include "pb.h" - -#include "pb.h" -#include "pb-types.h" -#include "pb-mod.h" -#include "pb-send.h" -#include "pb-buf.h" +#include "../../pb.h" +#include "../../pb-types.h" +#include "../../pb-mod.h" +#include "../../pb-send.h" +#include "../../pb-buf.h" #include <hardware/i2c.h> #include <hardware/gpio.h> @@ -43,7 +41,7 @@ void pb_setup() { } __weak void pb_i2c_send(i2c_addr_t addr, const uint8_t * buf, size_t sz) { - pb_hook_i2c_send(addr, buf, sz); + if (pb_hook_i2c_send(addr, buf, sz)) return; // false to write stop condition to i2c bus i2c_write_timeout_us(PB_I2C_M, addr, buf, sz, false, PB_TIMEOUT_US); diff --git a/lib/pbdrv/pb-mod.c b/lib/pbdrv/pb-mod.c index 6b23b04..0342391 100644 --- a/lib/pbdrv/pb-mod.c +++ b/lib/pbdrv/pb-mod.c @@ -18,9 +18,8 @@ __weak void pb_hook_mod_state_write(pb_global_state_t state) { _global_state = state; } -__weak void pb_hook_i2c_recv(const uint8_t * data, size_t sz) { } __weak void pb_i2c_recv(const uint8_t * data, size_t sz) { - pb_hook_i2c_recv(data, sz); + if (pb_hook_i2c_recv(data, sz)) return; pb_buf_t buf = { .data = (char *) data, @@ -35,5 +34,11 @@ __weak void pb_i2c_recv(const uint8_t * data, size_t sz) { pb_msg_free(msg); } -__weak void pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data, size_t sz) { } +__weak bool pb_hook_i2c_recv(const uint8_t * data, size_t sz) { + return false; +} + +__weak bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data, size_t sz) { + return false; +} diff --git a/lib/pbdrv/pb-mod.h b/lib/pbdrv/pb-mod.h index e7b7832..7069b32 100644 --- a/lib/pbdrv/pb-mod.h +++ b/lib/pbdrv/pb-mod.h @@ -101,8 +101,8 @@ void pb_hook_mod_state_write(pb_global_state_t state); * \{ */ -void pb_hook_i2c_recv(const uint8_t * buf, size_t sz); -void pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz); +bool pb_hook_i2c_recv(const uint8_t * buf, size_t sz); +bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz); /// \} |