summaryrefslogtreecommitdiff
path: root/zephyr/include/emul
diff options
context:
space:
mode:
authorTomasz Michalec <tm@semihalf.com>2021-09-02 17:23:34 +0200
committerCommit Bot <commit-bot@chromium.org>2021-09-03 15:35:24 +0000
commit2766160a4bcec633694492915b2a8d0c3068851f (patch)
tree5e5062f28c043ba04835496940e3b888bd6a0e46 /zephyr/include/emul
parent7c543a2dc09f9302eaf4ae9a2f529a0fb9f88244 (diff)
downloadchrome-ec-2766160a4bcec633694492915b2a8d0c3068851f.tar.gz
zephyr: emul: Use common I2C code in emulators
Align following emulators to use common I2C code: - bb_retimer - bma255 - bmi (both 160 and 260) - smart_battery - tcs3400 BUG=none BRANCH=none TEST=make configure --test zephyr/test/drivers Signed-off-by: Tomasz Michalec <tm@semihalf.com> Change-Id: I7515407b867487574a29dcae3456d96920a24979 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3140202 Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/include/emul')
-rw-r--r--zephyr/include/emul/emul_bb_retimer.h103
-rw-r--r--zephyr/include/emul/emul_bma255.h118
-rw-r--r--zephyr/include/emul/emul_bmi.h138
-rw-r--r--zephyr/include/emul/emul_smart_battery.h80
-rw-r--r--zephyr/include/emul/emul_tcs3400.h103
5 files changed, 58 insertions, 484 deletions
diff --git a/zephyr/include/emul/emul_bb_retimer.h b/zephyr/include/emul/emul_bb_retimer.h
index 2820c59934..c63cc651c0 100644
--- a/zephyr/include/emul/emul_bb_retimer.h
+++ b/zephyr/include/emul/emul_bb_retimer.h
@@ -28,24 +28,15 @@
*
* - define a Device Tree overlay file to set default vendor ID and which
* inadvisable driver behaviour should be treated as errors
- * - call @ref bb_emul_set_read_func and @ref bb_emul_set_write_func to setup
- * custom handlers for I2C messages
* - call @ref bb_emul_set_reg and @ref bb_emul_get_reg to set and get value
* of BB retimers registers
* - call bb_emul_set_err_* to change emulator behaviour on inadvisable driver
* behaviour
- * - call @ref bb_emul_set_read_fail_reg and @ref bb_emul_set_write_fail_reg
- * to configure emulator to fail on given register read or write
+ * - call functions from emul_common_i2c.h to setup custom handlers for I2C
+ * messages
*/
/**
- * Special register values used in @ref bb_emul_set_read_fail_reg and
- * @ref bb_emul_set_write_fail_reg
- */
-#define BB_EMUL_FAIL_ALL_REG (-1)
-#define BB_EMUL_NO_FAIL_REG (-2)
-
-/**
* @brief Get pointer to BB retimer emulator using device tree order number.
*
* @param ord Device tree order number obtained from DT_DEP_ORD macro
@@ -55,78 +46,6 @@
struct i2c_emul *bb_emul_get(int ord);
/**
- * @brief Custom function type that is used as user-defined callback in read
- * I2C messages handling.
- *
- * @param emul Pointer to BB retimer emulator
- * @param reg Address which is now accessed by read command
- * @param data Pointer to custom user data
- *
- * @return 0 on success. Value of @p reg should be set by @ref bb_emul_set_reg
- * @return 1 continue with normal BB retimer emulator handler
- * @return negative on error
- */
-typedef int (*bb_emul_read_func)(struct i2c_emul *emul, int reg, void *data);
-
-/**
- * @brief Custom function type that is used as user-defined callback in write
- * I2C messages handling.
- *
- * @param emul Pointer to BB retimer emulator
- * @param reg Address which is now accessed by write command
- * @param val Value which is being written to @p reg
- * @param data Pointer to custom user data
- *
- * @return 0 on success
- * @return 1 continue with normal BB retimer emulator handler
- * @return negative on error
- */
-typedef int (*bb_emul_write_func)(struct i2c_emul *emul, int reg, uint32_t val,
- void *data);
-
-/**
- * @brief Lock access to BB retimer properties. After acquiring lock, user
- * may change emulator behaviour in multi-thread setup.
- *
- * @param emul Pointer to BB retimer emulator
- * @param timeout Timeout in getting lock
- *
- * @return k_mutex_lock return code
- */
-int bb_emul_lock_data(struct i2c_emul *emul, k_timeout_t timeout);
-
-/**
- * @brief Unlock access to BB retimer properties.
- *
- * @param emul Pointer to BB retimer emulator
- *
- * @return k_mutex_unlock return code
- */
-int bb_emul_unlock_data(struct i2c_emul *emul);
-
-/**
- * @brief Set write handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to BB retimer emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void bb_emul_set_write_func(struct i2c_emul *emul, bb_emul_write_func func,
- void *data);
-
-/**
- * @brief Set read handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to BB retimer emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void bb_emul_set_read_func(struct i2c_emul *emul, bb_emul_read_func func,
- void *data);
-
-/**
* @brief Set value of given register of BB retimer
*
* @param emul Pointer to BB retimer emulator
@@ -146,24 +65,6 @@ void bb_emul_set_reg(struct i2c_emul *emul, int reg, uint32_t val);
uint32_t bb_emul_get_reg(struct i2c_emul *emul, int reg);
/**
- * @brief Setup fail on read of given register of BB retimer
- *
- * @param emul Pointer to BB retimer emulator
- * @param reg Register address or one of special values (BB_EMUL_FAIL_ALL_REG,
- * BB_EMUL_NO_FAIL_REG)
- */
-void bb_emul_set_read_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
- * @brief Setup fail on write of given register of BB retimer
- *
- * @param emul Pointer to BB retimer emulator
- * @param reg Register address or one of special values (BB_EMUL_FAIL_ALL_REG,
- * BB_EMUL_NO_FAIL_REG)
- */
-void bb_emul_set_write_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
* @brief Set if error should be generated when read only register is being
* written
*
diff --git a/zephyr/include/emul/emul_bma255.h b/zephyr/include/emul/emul_bma255.h
index 1b40e06559..b2f71df88b 100644
--- a/zephyr/include/emul/emul_bma255.h
+++ b/zephyr/include/emul/emul_bma255.h
@@ -31,8 +31,6 @@
* - define a Device Tree overlay file to set default NVM content, default
* static accelerometer value and which inadvisable driver behaviour should
* be treated as errors
- * - call @ref bma_emul_set_read_func and @ref bma_emul_set_write_func to setup
- * custom handlers for I2C messages
* - call @ref bma_emul_set_reg and @ref bma_emul_get_reg to set and get value
* of BMA255 registers
* - call @ref bma_emul_set_off and @ref bma_emul_set_off to set and get
@@ -41,8 +39,8 @@
* accelerometer value
* - call bma_emul_set_err_* to change emulator behaviour on inadvisable driver
* behaviour
- * - call @ref bma_emul_set_read_fail_reg and @ref bma_emul_set_write_fail_reg
- * to configure emulator to fail on given register read or write
+ * - call functions from emul_common_i2c.h to setup custom handlers for I2C
+ * messages
*/
/**
@@ -61,13 +59,6 @@
#define BMA_EMUL_1G BIT(10)
/**
- * Special register values used in @ref bma_emul_set_read_fail_reg and
- * @ref bma_emul_set_write_fail_reg
- */
-#define BMA_EMUL_FAIL_ALL_REG (-1)
-#define BMA_EMUL_NO_FAIL_REG (-2)
-
-/**
* @brief Get pointer to BMA255 emulator using device tree order number.
*
* @param ord Device tree order number obtained from DT_DEP_ORD macro
@@ -77,78 +68,6 @@
struct i2c_emul *bma_emul_get(int ord);
/**
- * @brief Custom function type that is used as user-defined callback in read
- * I2C messages handling.
- *
- * @param emul Pointer to BMA255 emulator
- * @param reg Address which is now accessed by read command
- * @param data Pointer to custom user data
- *
- * @return 0 on success. Value of @p reg should be set by @ref bma_emul_set_reg
- * @return 1 continue with normal BMA255 emulator handler
- * @return negative on error
- */
-typedef int (*bma_emul_read_func)(struct i2c_emul *emul, int reg, void *data);
-
-/**
- * @brief Custom function type that is used as user-defined callback in write
- * I2C messages handling.
- *
- * @param emul Pointer to BMA255 emulator
- * @param reg Address which is now accessed by write command
- * @param val Value which is being written to @p reg
- * @param data Pointer to custom user data
- *
- * @return 0 on success
- * @return 1 continue with normal BMA255 emulator handler
- * @return negative on error
- */
-typedef int (*bma_emul_write_func)(struct i2c_emul *emul, int reg, uint8_t val,
- void *data);
-
-/**
- * @brief Lock access to BMA255 properties. After acquiring lock, user
- * may change emulator behaviour in multi-thread setup.
- *
- * @param emul Pointer to BMA255 emulator
- * @param timeout Timeout in getting lock
- *
- * @return k_mutex_lock return code
- */
-int bma_emul_lock_data(struct i2c_emul *emul, k_timeout_t timeout);
-
-/**
- * @brief Unlock access to BMA255 properties.
- *
- * @param emul Pointer to BMA255 emulator
- *
- * @return k_mutex_unlock return code
- */
-int bma_emul_unlock_data(struct i2c_emul *emul);
-
-/**
- * @brief Set write handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to BMA255 emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void bma_emul_set_write_func(struct i2c_emul *emul, bma_emul_write_func func,
- void *data);
-
-/**
- * @brief Set read handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to BMA255 emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void bma_emul_set_read_func(struct i2c_emul *emul, bma_emul_read_func func,
- void *data);
-
-/**
* @brief Set value of given register of BMA255
*
* @param emul Pointer to BMA255 emulator
@@ -168,24 +87,6 @@ void bma_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val);
uint8_t bma_emul_get_reg(struct i2c_emul *emul, int reg);
/**
- * @brief Setup fail on read of given register of BMA255
- *
- * @param emul Pointer to BMA255 emulator
- * @param reg Register address or one of special values (BMA_EMUL_FAIL_ALL_REG,
- * BMA_EMUL_NO_FAIL_REG)
- */
-void bma_emul_set_read_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
- * @brief Setup fail on write of given register of BMA255
- *
- * @param emul Pointer to BMA255 emulator
- * @param reg Register address or one of special values (BMA_EMUL_FAIL_ALL_REG,
- * BMA_EMUL_NO_FAIL_REG)
- */
-void bma_emul_set_write_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
* @brief Get internal value of offset for given axis
*
* @param emul Pointer to BMA255 emulator
@@ -269,6 +170,21 @@ void bma_emul_set_err_on_rsvd_write(struct i2c_emul *emul, bool set);
void bma_emul_set_err_on_msb_first(struct i2c_emul *emul, bool set);
/**
+ * @brief Function calculate register that should be accessed when I2C message
+ * started from @p reg register and now byte number @p bytes is handled.
+ * This function is used in I2C common emulator code and can be used in
+ * custom user functions.
+ *
+ * @param emul Pointer to BMA255 emulator
+ * @param reg Starting register
+ * @param bytes Number of bytes already processed in the I2C message handler
+ * @param read If current I2C message is read
+ *
+ * @retval Register address that should be accessed
+ */
+int bma_emul_access_reg(struct i2c_emul *emul, int reg, int bytes, bool read);
+
+/**
* @}
*/
diff --git a/zephyr/include/emul/emul_bmi.h b/zephyr/include/emul/emul_bmi.h
index d70b975195..9eac9c3f85 100644
--- a/zephyr/include/emul/emul_bmi.h
+++ b/zephyr/include/emul/emul_bmi.h
@@ -29,8 +29,6 @@
*
* - define a Device Tree overlay file to set which inadvisable driver behaviour
* should be treated as errors and which model is emulated
- * - call @ref bmi_emul_set_read_func and @ref bmi_emul_set_write_func to setup
- * custom handlers for I2C messages
* - call @ref bmi_emul_set_reg and @ref bmi_emul_get_reg to set and get value
* of BMI registers
* - call @ref bmi_emul_set_off and @ref bmi_emul_get_off to set and get
@@ -41,11 +39,11 @@
* behaviour
* - call @ref bmi_emul_simulate_cmd_exec_time to enable or disable simulation
* of command execution time
- * - call @ref bmi_emul_set_read_fail_reg and @ref bmi_emul_set_write_fail_reg
- * to configure emulator to fail on given register read or write
* - call @ref bmi_emul_append_frame to add frame to FIFO
* - call @reg bmi_emul_set_skipped_frames to generate skip frame on next access
* to FIFO
+ * - call functions from emul_common_i2c.h to setup custom handlers for I2C
+ * messages
*/
/**
@@ -106,13 +104,6 @@ enum bmi_emul_axis {
*/
#define BMI_EMUL_ACCESS_E 1
-/**
- * Special register values used in @ref bmi_emul_set_read_fail_reg and
- * @ref bmi_emul_set_write_fail_reg
- */
-#define BMI_EMUL_FAIL_ALL_REG (-1)
-#define BMI_EMUL_NO_FAIL_REG (-2)
-
/** Structure used to describe single FIFO frame */
struct bmi_emul_frame {
/** Type of frame */
@@ -145,14 +136,26 @@ struct bmi_emul_type_data {
bool sensortime_follow_config_frame;
/**
+ * @brief Compute register address that acctually will be accessed, when
+ * selected register is @p reg and there was @p byte handled in
+ * the current I2C message
+ *
+ * @param emul Pointer to BMI emulator
+ * @param reg Selected register
+ * @param byte Number of handled bytes in the current I2C message
+ * @param read If current I2C message is read
+ *
+ * @return Register address that will be accessed
+ */
+ int (*access_reg)(struct i2c_emul *emul, int reg, int byte, bool read);
+
+ /**
* @brief Model specific write function. It should modify state of
- * emulator if required. @p reg value should be updated to
- * register which is acctually accessed.
+ * emulator if required.
*
* @param regs Pointer to array of emulator's registers
* @param emul Pointer to BMI emulator
- * @param reg Pointer to accessed reg. If different reg is accessed,
- * this value should be modified.
+ * @param reg Selected register
* @param byte Number of handled bytes in this write command
* @param val Value that is being written
*
@@ -160,18 +163,15 @@ struct bmi_emul_type_data {
* @return BMI_EMUL_ACCESS_E on RO register access
* @return other on error
*/
- int (*handle_write)(uint8_t *regs, struct i2c_emul *emul, int *reg,
+ int (*handle_write)(uint8_t *regs, struct i2c_emul *emul, int reg,
int byte, uint8_t val);
/**
* @brief Model specific read function. It should modify state of
- * emulator if required. @p reg value should be updated to
- * register which is acctually accessed. @p buf should be
- * set to response value.
+ * emulator if required. @p buf should be set to response value.
*
* @param regs Pointer to array of emulator's registers
* @param emul Pointer to BMI emulator
- * @param reg Pointer to accessed reg. If different reg is accessed,
- * this value should be modified.
+ * @param reg Selected register
* @param byte Byte which is accessed during block read
* @param buf Pointer where read byte should be stored
*
@@ -179,7 +179,7 @@ struct bmi_emul_type_data {
* @return BMI_EMUL_ACCESS_E on WO register access
* @return other on error
*/
- int (*handle_read)(uint8_t *regs, struct i2c_emul *emul, int *reg,
+ int (*handle_read)(uint8_t *regs, struct i2c_emul *emul, int reg,
int byte, char *buf);
/**
* @brief Model specific reset function. It should modify state of
@@ -229,82 +229,6 @@ const struct bmi_emul_type_data *get_bmi260_emul_type_data(void);
struct i2c_emul *bmi_emul_get(int ord);
/**
- * @brief Custom function type that is used as user-defined callback in read
- * I2C messages handling.
- *
- * @param emul Pointer to BMI emulator
- * @param reg Address which is now accessed by read command
- * @param byte Byte which is accessed during block read
- * @param data Pointer to custom user data
- *
- * @return 0 on success. Value of @p reg should be set by @ref bmi_emul_set_reg
- * @return 1 continue with normal BMI emulator handler
- * @return negative on error
- */
-typedef int (*bmi_emul_read_func)(struct i2c_emul *emul, int reg, int byte,
- void *data);
-
-/**
- * @brief Custom function type that is used as user-defined callback in write
- * I2C messages handling.
- *
- * @param emul Pointer to BMA255 emulator
- * @param reg Address which is now accessed by write command
- * @param byte Number of handled bytes in this write command. It does include
- * first byte containing accessed register address.
- * @param val Value which is being written to @p reg
- * @param data Pointer to custom user data
- *
- * @return 0 on success
- * @return 1 continue with normal BMI emulator handler
- * @return negative on error
- */
-typedef int (*bmi_emul_write_func)(struct i2c_emul *emul, int reg, int byte,
- uint8_t val, void *data);
-
-/**
- * @brief Lock access to BMI properties. After acquiring lock, user
- * may change emulator behaviour in multi-thread setup.
- *
- * @param emul Pointer to BMI emulator
- * @param timeout Timeout in getting lock
- *
- * @return k_mutex_lock return code
- */
-int bmi_emul_lock_data(struct i2c_emul *emul, k_timeout_t timeout);
-
-/**
- * @brief Unlock access to BMI properties.
- *
- * @param emul Pointer to BMI emulator
- *
- * @return k_mutex_unlock return code
- */
-int bmi_emul_unlock_data(struct i2c_emul *emul);
-
-/**
- * @brief Set write handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to BMI emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void bmi_emul_set_write_func(struct i2c_emul *emul, bmi_emul_write_func func,
- void *data);
-
-/**
- * @brief Set read handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to BMI emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void bmi_emul_set_read_func(struct i2c_emul *emul, bmi_emul_read_func func,
- void *data);
-
-/**
* @brief Set value of given register of BMI
*
* @param emul Pointer to BMI emulator
@@ -324,24 +248,6 @@ void bmi_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val);
uint8_t bmi_emul_get_reg(struct i2c_emul *emul, int reg);
/**
- * @brief Setup fail on read of given register of BMI
- *
- * @param emul Pointer to BMI emulator
- * @param reg Register address or one of special values (BMI_EMUL_FAIL_ALL_REG,
- * BMI_EMUL_NO_FAIL_REG)
- */
-void bmi_emul_set_read_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
- * @brief Setup fail on write of given register of BMI
- *
- * @param emul Pointer to BMI emulator
- * @param reg Register address or one of special values (BMI_EMUL_FAIL_ALL_REG,
- * BMI_EMUL_NO_FAIL_REG)
- */
-void bmi_emul_set_write_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
* @brief Get internal value of offset for given axis and sensor
*
* @param emul Pointer to BMI emulator
diff --git a/zephyr/include/emul/emul_smart_battery.h b/zephyr/include/emul/emul_smart_battery.h
index be5e7e4b16..b48f836d66 100644
--- a/zephyr/include/emul/emul_smart_battery.h
+++ b/zephyr/include/emul/emul_smart_battery.h
@@ -28,13 +28,12 @@
* As-such, each application may
*
* - define a Device Tree overlay file to set the most of battery properties
- * - call @ref sbat_emul_set_custom_write_func and
- * @ref sbat_emul_set_custom_read_func to setup custom handlers for SMBus
- * messages.
* - get battery properties calling @ref sbat_emul_get_bat_data Battery
* properties can be changed through obtained pointer. In multithread
* environment access to battery can be guarded by calling
* @ref sbat_emul_lock_bat_data and @ref sbat_emul_unlock_bat_data
+ * - call functions from emul_common_i2c.h to setup custom handlers for SMBus
+ * messages
*/
/* Value used to indicate that no command is selected */
@@ -123,26 +122,6 @@ struct sbat_emul_bat_data {
struct i2c_emul *sbat_emul_get_ptr(int ord);
/**
- * @brief Custom function type that is used as user defined callbacks in read
- * and write SMBus messages handling.
- *
- * @param emul Pointer to smart battery emulator
- * @param buf Pointer to data from write command or to be filed by read command
- * @param len Pointer to number of bytes used for write command buffer. It may
- * exceed MSG_BUF_LEN, indicating that some bytes from write command
- * are not saved in @p buf. If read command is handled, than
- * function should set how many bytes are written to @p buf
- * @param cmd Command that was recognized
- * @param data Pointer to custom user data
- *
- * @return 0 on success
- * @return 1 continue with normal smart battery emulator handler
- * @return negative on error
- */
-typedef int (*sbat_emul_custom_func)(struct i2c_emul *emul, uint8_t *buf,
- int *len, int cmd, void *data);
-
-/**
* @brief Function which allows to get properties of emulated smart battery
*
* @param emul Pointer to smart battery emulator
@@ -152,48 +131,6 @@ typedef int (*sbat_emul_custom_func)(struct i2c_emul *emul, uint8_t *buf,
struct sbat_emul_bat_data *sbat_emul_get_bat_data(struct i2c_emul *emul);
/**
- * @brief Lock access to smart battery properties. After acquiring lock, user
- * may change emulator behaviour in multi-thread setup.
- *
- * @param emul Pointer to smart battery emulator
- * @param timeout Timeout in getting lock
- *
- * @return k_mutex_lock return code
- */
-int sbat_emul_lock_bat_data(struct i2c_emul *emul, k_timeout_t timeout);
-
-/**
- * @brief Unlock access to smart battery properties.
- *
- * @param emul Pointer to smart battery emulator
- *
- * @return k_mutex_unlock return code
- */
-int sbat_emul_unlock_bat_dat(struct i2c_emul *emul);
-
-/**
- * @brief Set custom write SMBus message handler. This function is called before
- * generic handler.
- *
- * @param emul Pointer to smart battery emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void sbat_emul_set_custom_write_func(struct i2c_emul *emul,
- sbat_emul_custom_func func, void *data);
-
-/**
- * @brief Set custom read SMBus message handler. This function is called before
- * generic handler.
- *
- * @param emul Pointer to smart battery emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void sbat_emul_set_custom_read_func(struct i2c_emul *emul,
- sbat_emul_custom_func func, void *data);
-
-/**
* @brief Convert date to format used by smart battery
*
* @param day Day
@@ -237,6 +174,19 @@ int sbat_emul_get_block_data(struct i2c_emul *emul, int cmd, uint8_t **blk,
int *len);
/**
+ * @brief Set next response of emulator. This function may be used in user
+ * custom read callback to setup response with calculated PEC.
+ *
+ * @param emul Pointer to smart battery emulator
+ * @param cmd Read command
+ * @param buf Buffer with the response
+ * @param len Length of the response
+ * @param fail If emulator should fail to send response
+ */
+void sbat_emul_set_response(struct i2c_emul *emul, int cmd, uint8_t *buf,
+ int len, bool fail);
+
+/**
* @}
*/
diff --git a/zephyr/include/emul/emul_tcs3400.h b/zephyr/include/emul/emul_tcs3400.h
index 41f3577658..49ec382a66 100644
--- a/zephyr/include/emul/emul_tcs3400.h
+++ b/zephyr/include/emul/emul_tcs3400.h
@@ -27,16 +27,14 @@
*
* - define a devicetree overlay file to set which inadvisable driver behaviour
* should be treated as error and emulated device ID and revision
- * - call @ref tcs_emul_set_read_func and @ref tcs_emul_set_write_func to setup
- * custom handlers for I2C messages
* - call @ref tcs_emul_set_reg and @ref tcs_emul_get_reg to set and get value
* of TCS3400 registers
* - call @ref tcs_emul_set_val and @ref tcs_emul_set_val to set and get
* light sensor value
* - call tcs_emul_set_err_* to change emulator behaviour on inadvisable driver
* behaviour
- * - call @ref tcs_emul_set_read_fail_reg and @ref tcs_emul_set_write_fail_reg
- * to configure emulator to fail on given register read or write
+ * - call functions from emul_common_i2c.h to setup custom handlers for I2C
+ * messages
*/
/**
@@ -77,13 +75,6 @@ enum tcs_emul_axis {
#define TCS_EMUL_REG_COUNT (TCS_EMUL_LAST_REG - TCS_EMUL_FIRST_REG + 1)
/**
- * Special register values used in @ref tcs_emul_set_read_fail_reg and
- * @ref tcs_emul_set_write_fail_reg
- */
-#define TCS_EMUL_FAIL_ALL_REG (-1)
-#define TCS_EMUL_NO_FAIL_REG (-2)
-
-/**
* @brief Get pointer to TCS3400 emulator using device tree order number.
*
* @param ord Device tree order number obtained from DT_DEP_ORD macro
@@ -93,78 +84,6 @@ enum tcs_emul_axis {
struct i2c_emul *tcs_emul_get(int ord);
/**
- * @brief Custom function type that is used as user-defined callback in read
- * I2C messages handling.
- *
- * @param emul Pointer to TCS3400 emulator
- * @param reg Address which is now accessed by read command
- * @param data Pointer to custom user data
- *
- * @return 0 on success. Value of @p reg should be set by @ref tcs_emul_set_reg
- * @return 1 continue with normal TCS3400 emulator handler
- * @return negative on error
- */
-typedef int (*tcs_emul_read_func)(struct i2c_emul *emul, int reg, void *data);
-
-/**
- * @brief Custom function type that is used as user-defined callback in write
- * I2C messages handling.
- *
- * @param emul Pointer to TCS3400 emulator
- * @param reg Address which is now accessed by write command
- * @param val Value which is being written to @p reg
- * @param data Pointer to custom user data
- *
- * @return 0 on success
- * @return 1 continue with normal TCS3400 emulator handler
- * @return negative on error
- */
-typedef int (*tcs_emul_write_func)(struct i2c_emul *emul, int reg, uint8_t val,
- void *data);
-
-/**
- * @brief Lock access to TCS3400 properties. After acquiring lock, user
- * may change emulator behaviour in multi-thread setup.
- *
- * @param emul Pointer to TCS3400 emulator
- * @param timeout Timeout in getting lock
- *
- * @return k_mutex_lock return code
- */
-int tcs_emul_lock_data(struct i2c_emul *emul, k_timeout_t timeout);
-
-/**
- * @brief Unlock access to TCS3400 properties.
- *
- * @param emul Pointer to TCS3400 emulator
- *
- * @return k_mutex_unlock return code
- */
-int tcs_emul_unlock_data(struct i2c_emul *emul);
-
-/**
- * @brief Set write handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to TCS3400 emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void tcs_emul_set_write_func(struct i2c_emul *emul, tcs_emul_write_func func,
- void *data);
-
-/**
- * @brief Set read handler for I2C messages. This function is called before
- * generic handler.
- *
- * @param emul Pointer to TCS3400 emulator
- * @param func Pointer to custom function
- * @param data User data passed on call of custom function
- */
-void tcs_emul_set_read_func(struct i2c_emul *emul, tcs_emul_read_func func,
- void *data);
-
-/**
* @brief Set value of given register of TCS3400
*
* @param emul Pointer to TCS3400 emulator
@@ -184,24 +103,6 @@ void tcs_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val);
uint8_t tcs_emul_get_reg(struct i2c_emul *emul, int reg);
/**
- * @brief Setup fail on read of given register of TCS3400
- *
- * @param emul Pointer to TCS3400 emulator
- * @param reg Register address or one of special values (TCS_EMUL_FAIL_ALL_REG,
- * TCS_EMUL_NO_FAIL_REG)
- */
-void tcs_emul_set_read_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
- * @brief Setup fail on write of given register of TCS3400
- *
- * @param emul Pointer to TCS3400 emulator
- * @param reg Register address or one of special values (TCS_EMUL_FAIL_ALL_REG,
- * TCS_EMUL_NO_FAIL_REG)
- */
-void tcs_emul_set_write_fail_reg(struct i2c_emul *emul, int reg);
-
-/**
* @brief Get internal value of light sensor for given axis
*
* @param emul Pointer to TCS3400 emulator