summaryrefslogtreecommitdiff
path: root/zephyr/include/emul/emul_smart_battery.h
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/include/emul/emul_smart_battery.h')
-rw-r--r--zephyr/include/emul/emul_smart_battery.h46
1 files changed, 29 insertions, 17 deletions
diff --git a/zephyr/include/emul/emul_smart_battery.h b/zephyr/include/emul/emul_smart_battery.h
index 034cb6915b..826e817992 100644
--- a/zephyr/include/emul/emul_smart_battery.h
+++ b/zephyr/include/emul/emul_smart_battery.h
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -17,6 +17,8 @@
#include <zephyr/drivers/i2c_emul.h>
#include <stdint.h>
+#include "emul/emul_common_i2c.h"
+
/**
* @brief Smart Battery emulator backend API
* @defgroup sbat_emul Smart Battery emulator
@@ -38,11 +40,11 @@
*/
/* Value used to indicate that no command is selected */
-#define SBAT_EMUL_NO_CMD -1
+#define SBAT_EMUL_NO_CMD -1
/* Maximum size of data that can be returned in SMBus block transaction */
-#define MAX_BLOCK_SIZE 32
+#define MAX_BLOCK_SIZE 32
/* Maximum length of command to send is maximum size of data + len byte + PEC */
-#define MSG_BUF_LEN (MAX_BLOCK_SIZE + 2)
+#define MSG_BUF_LEN (MAX_BLOCK_SIZE + 2)
/** @brief Emulated smart battery properties */
struct sbat_emul_bat_data {
@@ -65,6 +67,8 @@ struct sbat_emul_bat_data {
uint16_t error_code;
/** Design battery voltage in mV */
uint16_t design_mv;
+ /** Default Design battery voltage in mV */
+ const uint16_t default_design_mv;
/** Battery temperature at the moment in Kelvins */
uint16_t temp;
/** Battery voltage at the moment in mV */
@@ -77,8 +81,12 @@ struct sbat_emul_bat_data {
uint16_t max_error;
/** Capacity of the battery at the moment in mAh */
uint16_t cap;
+ /** Default capacity of the battery at the moment in mAh */
+ const uint16_t default_cap;
/** Full capacity of the battery in mAh */
uint16_t full_cap;
+ /** Default full capacity of the battery at the moment in mAh */
+ const uint16_t default_full_cap;
/** Design battery capacity in mAh */
uint16_t design_cap;
/** Charging current requested by battery */
@@ -111,25 +119,20 @@ struct sbat_emul_bat_data {
uint8_t mf_data[MAX_BLOCK_SIZE];
/** Manufacturer data length */
int mf_data_len;
+ /** Manufacture info */
+ uint8_t mf_info[MAX_BLOCK_SIZE];
+ /** Manufacture info length */
+ int mf_info_len;
};
/**
- * @brief Get pointer to smart battery emulator using device tree order number.
- *
- * @param ord Device tree order number obtained from DT_DEP_ORD macro
- *
- * @return Pointer to smart battery emulator
- */
-struct i2c_emul *sbat_emul_get_ptr(int ord);
-
-/**
* @brief Function which allows to get properties of emulated smart battery
*
* @param emul Pointer to smart battery emulator
*
* @return Pointer to smart battery properties
*/
-struct sbat_emul_bat_data *sbat_emul_get_bat_data(struct i2c_emul *emul);
+struct sbat_emul_bat_data *sbat_emul_get_bat_data(const struct emul *emul);
/**
* @brief Convert date to format used by smart battery
@@ -156,7 +159,7 @@ uint16_t sbat_emul_date_to_word(unsigned int day, unsigned int month,
* @return 1 if command is unknown or return type different then word
* @return negative on error while reading value
*/
-int sbat_emul_get_word_val(struct i2c_emul *emul, int cmd, uint16_t *val);
+int sbat_emul_get_word_val(const struct emul *emul, int cmd, uint16_t *val);
/**
* @brief Function which gets return value for read commands that returns block
@@ -171,7 +174,7 @@ int sbat_emul_get_word_val(struct i2c_emul *emul, int cmd, uint16_t *val);
* @return 1 if command is unknown or return type different then word
* @return negative on error while reading value
*/
-int sbat_emul_get_block_data(struct i2c_emul *emul, int cmd, uint8_t **blk,
+int sbat_emul_get_block_data(const struct emul *emul, int cmd, uint8_t **blk,
int *len);
/**
@@ -184,10 +187,19 @@ int sbat_emul_get_block_data(struct i2c_emul *emul, int cmd, uint8_t **blk,
* @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,
+void sbat_emul_set_response(const struct emul *emul, int cmd, uint8_t *buf,
int len, bool fail);
/**
+ * @brief Returns pointer to i2c_common_emul_data for argument emul
+ *
+ * @param emul Pointer to smart_battery emulator
+ * @return Pointer to i2c_common_emul_data from argument emul
+ */
+struct i2c_common_emul_data *
+emul_smart_battery_get_i2c_common_data(const struct emul *emul);
+
+/**
* @}
*/