Skip to content

Commit e395e04

Browse files
chrysngdoffe
authored andcommitted
tests/periph/i2c: Demonstrate mock hooking
1 parent dab11d7 commit e395e04

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/periph/i2c/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@
4545
/* i2c_buf is global to reduce stack memory consumption */
4646
static uint8_t i2c_buf[BUFSIZE];
4747

48+
#if IS_USED(MODULE_PERIPH_I2C_MOCK)
49+
/* The write function of periph_i2c_mock is usually a complete no-op. This
50+
* function illustrates how the mock functions are customized. */
51+
int i2c_write_bytes(i2c_t dev, uint16_t addr, const void *data, size_t len,
52+
uint8_t flags)
53+
{
54+
(void)dev;
55+
(void)addr;
56+
(void)data;
57+
(void)flags;
58+
printf("Mock write intercepted; this write of %"PRIu32" byte(s) is still ignored.\n", (uint32_t)len);
59+
return 0;
60+
}
61+
#endif
62+
4863
static inline void _print_i2c_read(i2c_t dev, uint16_t *reg, uint8_t *buf,
4964
int len)
5065
{

0 commit comments

Comments
 (0)