diff options
-rw-r--r-- | common/mock_smart_battery.c | 41 | ||||
-rw-r--r-- | common/smart_battery.c | 4 |
2 files changed, 19 insertions, 26 deletions
diff --git a/common/mock_smart_battery.c b/common/mock_smart_battery.c index 98112c3ec0..0620de6e39 100644 --- a/common/mock_smart_battery.c +++ b/common/mock_smart_battery.c @@ -10,42 +10,40 @@ #include "console.h" #include "smart_battery.h" #include "smart_battery_stub.h" +#include "test_util.h" #include "uart.h" #include "util.h" static uint16_t mock_smart_battery[SB_MANUFACTURER_DATA + 1]; -int sb_read(int cmd, int *param) +int sb_i2c_read16(int port, int slave_addr, int offset, int *data) { - if (cmd >= ARRAY_SIZE(mock_smart_battery)) + if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR) + return EC_ERROR_INVAL; + if (offset >= ARRAY_SIZE(mock_smart_battery)) return EC_ERROR_UNIMPLEMENTED; - if (cmd < 0 || param == NULL) + if (offset < 0 || data == NULL) return EC_ERROR_INVAL; - *param = mock_smart_battery[cmd]; + *data = mock_smart_battery[offset]; return EC_SUCCESS; } +DECLARE_TEST_I2C_READ16(sb_i2c_read16); -int sb_write(int cmd, int param) +int sb_i2c_write16(int port, int slave_addr, int offset, int data) { - if (cmd >= ARRAY_SIZE(mock_smart_battery)) + if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR) + return EC_ERROR_INVAL; + if (offset >= ARRAY_SIZE(mock_smart_battery)) return EC_ERROR_UNIMPLEMENTED; - if (cmd < 0) + if (offset < 0) return EC_ERROR_INVAL; - mock_smart_battery[cmd] = param; - return EC_SUCCESS; -} - -int battery_manufacturer_name(char *manufacturer_name, int buf_size) -{ - return EC_SUCCESS; -} - -int battery_device_name(char *device_name, int buf_size) -{ + mock_smart_battery[offset] = data; return EC_SUCCESS; } +DECLARE_TEST_I2C_WRITE16(sb_i2c_write16); -int battery_device_chemistry(char *device_chemistry, int buf_size) +int sb_i2c_read_string(int port, int slave_addr, int offset, uint8_t *data, + int len) { return EC_SUCCESS; } @@ -55,11 +53,6 @@ int battery_time_at_rate(int rate, int *minutes) return EC_SUCCESS; } -int battery_manufacturer_date(int *year, int *month, int *day) -{ - return EC_SUCCESS; -} - /* Fake battery */ const struct battery_temperature_ranges bat_temp_ranges = { /* diff --git a/common/smart_battery.c b/common/smart_battery.c index ef9136ee00..84ae7d15b0 100644 --- a/common/smart_battery.c +++ b/common/smart_battery.c @@ -21,12 +21,12 @@ test_mockable int sbc_write(int cmd, int param) return i2c_write16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param); } -test_mockable int sb_read(int cmd, int *param) +int sb_read(int cmd, int *param) { return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); } -test_mockable int sb_write(int cmd, int param) +int sb_write(int cmd, int param) { return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); } |