Skip to content

Commit

Permalink
tests/periph/i2c: Demonstrate mock hooking
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn authored and gdoffe committed Feb 28, 2024
1 parent 65063c4 commit bf9daa6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/periph/i2c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@
/* i2c_buf is global to reduce stack memory consumption */
static uint8_t i2c_buf[BUFSIZE];

#if IS_USED(MODULE_PERIPH_I2C_MOCK)
/* The write function of periph_i2c_mock is usually a complete no-op. This
* function illustrates how the mock functions are customized. */
int i2c_write_bytes(i2c_t dev, uint16_t addr, const void *data, size_t len,
uint8_t flags)
{
(void)dev;
(void)addr;
(void)data;
(void)flags;
printf("Mock write intercepted; this write of %d byte(s) is still ignored.\n", len);
return 0;
}
#endif

static inline void _print_i2c_read(i2c_t dev, uint16_t *reg, uint8_t *buf,
int len)
{
Expand Down

0 comments on commit bf9daa6

Please sign in to comment.