Lines Matching +full:i2c +full:- +full:command

5  * SPDX-License-Identifier: Apache-2.0
18 #include <zephyr/drivers/i2c.h>
34 /** I2C address of emulator */
43 const struct bq27z746_emul_data *data = target->data; in emul_bq27z746_read_altmac()
48 return -EIO; in emul_bq27z746_read_altmac()
55 * 0..1: The command (for verification) in emul_bq27z746_read_altmac()
57 * 34: Checksum calculated as (uint8_t)(0xFF - (sum of all command and data bytes)) in emul_bq27z746_read_altmac()
58 * 35: Length including command, checksum and length (e.g. data length + 4) in emul_bq27z746_read_altmac()
61 /* Put the command in the first two byte */ in emul_bq27z746_read_altmac()
62 sys_put_le16(data->mac_cmd, buf); in emul_bq27z746_read_altmac()
64 /* Based on the command, put some data and the length into the buffer. */ in emul_bq27z746_read_altmac()
65 /* In all of the operations, don't consider the zero-terminator. */ in emul_bq27z746_read_altmac()
66 switch (data->mac_cmd) { in emul_bq27z746_read_altmac()
68 memcpy(&buf[2], manufacturer_name, sizeof(manufacturer_name) - 1); in emul_bq27z746_read_altmac()
69 buf[35] = sizeof(manufacturer_name) - 1 + BQ27Z746_MAC_OVERHEAD_LEN; in emul_bq27z746_read_altmac()
72 memcpy(&buf[2], device_name, sizeof(device_name) - 1); in emul_bq27z746_read_altmac()
73 buf[35] = sizeof(device_name) - 1 + BQ27Z746_MAC_OVERHEAD_LEN; in emul_bq27z746_read_altmac()
76 memcpy(&buf[2], device_chemistry, sizeof(device_chemistry) - 1); in emul_bq27z746_read_altmac()
77 buf[35] = sizeof(device_chemistry) - 1 + BQ27Z746_MAC_OVERHEAD_LEN; in emul_bq27z746_read_altmac()
80 LOG_ERR("ALTMAC command 0x%x is not supported", data->mac_cmd); in emul_bq27z746_read_altmac()
81 return -EIO; in emul_bq27z746_read_altmac()
87 for (int i = 0; i < BQ27Z746_MAC_COMPLETE_LEN - 2; i++) { in emul_bq27z746_read_altmac()
90 buf[34] = 0xFF - sum; in emul_bq27z746_read_altmac()
97 struct bq27z746_emul_data *data = target->data; in emul_bq27z746_write()
102 data->mac_cmd = sys_get_le16(&buf[1]); in emul_bq27z746_write()
106 return -EIO; in emul_bq27z746_write()
117 *val = -2; in emul_bq27z746_reg_read()
132 *val = -2; in emul_bq27z746_reg_read()
141 *val = -2; in emul_bq27z746_reg_read()
241 return -EIO; in emul_bq27z746_reg_read()
267 return -EIO; in emul_bq27z746_read()
282 i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); in bq27z746_emul_transfer_i2c()
285 if (msgs->flags & I2C_MSG_READ) { in bq27z746_emul_transfer_i2c()
287 return -EIO; in bq27z746_emul_transfer_i2c()
290 return emul_bq27z746_write(target, msgs->buf, msgs->len); in bq27z746_emul_transfer_i2c()
292 if (msgs->flags & I2C_MSG_READ) { in bq27z746_emul_transfer_i2c()
294 return -EIO; in bq27z746_emul_transfer_i2c()
296 if (msgs->len != 1) { in bq27z746_emul_transfer_i2c()
297 LOG_ERR("Unexpected msg0 length %d", msgs->len); in bq27z746_emul_transfer_i2c()
298 return -EIO; in bq27z746_emul_transfer_i2c()
300 reg = msgs->buf[0]; in bq27z746_emul_transfer_i2c()
304 if (msgs->flags & I2C_MSG_READ) { in bq27z746_emul_transfer_i2c()
305 rc = emul_bq27z746_read(target, reg, msgs->buf, msgs->len); in bq27z746_emul_transfer_i2c()
310 LOG_ERR("Second message must be an I2C write"); in bq27z746_emul_transfer_i2c()
311 return -EIO; in bq27z746_emul_transfer_i2c()
316 return -EIO; in bq27z746_emul_transfer_i2c()
327 * Set up a new emulator (I2C)