aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pbdrv')
-rw-r--r--lib/pbdrv/drv/rp2040/mod.c2
-rw-r--r--lib/pbdrv/pb-mod.c5
-rw-r--r--lib/pbdrv/pb-mod.h16
3 files changed, 20 insertions, 3 deletions
diff --git a/lib/pbdrv/drv/rp2040/mod.c b/lib/pbdrv/drv/rp2040/mod.c
index 1535da9..bc20927 100644
--- a/lib/pbdrv/drv/rp2040/mod.c
+++ b/lib/pbdrv/drv/rp2040/mod.c
@@ -43,6 +43,8 @@ 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);
+
// 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 c27194e..6b23b04 100644
--- a/lib/pbdrv/pb-mod.c
+++ b/lib/pbdrv/pb-mod.c
@@ -18,7 +18,10 @@ __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);
+
pb_buf_t buf = {
.data = (char *) data,
.size = sz,
@@ -32,3 +35,5 @@ __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) { }
+
diff --git a/lib/pbdrv/pb-mod.h b/lib/pbdrv/pb-mod.h
index 91e1d1f..e7b7832 100644
--- a/lib/pbdrv/pb-mod.h
+++ b/lib/pbdrv/pb-mod.h
@@ -62,10 +62,8 @@ void pb_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz);
/// \}
-/// \ingroup pb_hook
-/// \{
-
/**
+ * \ingroup pb_hook
* \defgroup pb_hook_mod_state State
* \brief Provide your own global state variable
*
@@ -94,6 +92,18 @@ pb_global_state_t pb_hook_mod_state_read();
void pb_hook_mod_state_write(pb_global_state_t state);
/// \}
+
+/**
+ * \ingroup pb_hook
+ * \defgroup pb_hook_i2c I2C
+ * \brief Intercept incoming/outgoing I2C messages
+ *
+ * \{
+ */
+
+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);
+
/// \}
#ifdef __cplusplus