aboutsummaryrefslogtreecommitdiff
path: root/tests/pca9552-test.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2019-03-18 15:09:51 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2019-06-03 14:03:01 +0200
commite8ecb706a8a3a75ea45387a3561b6debed9cacc3 (patch)
treee0074f37da7f4dce193e64c8d11192762429e366 /tests/pca9552-test.c
parent7d8ada6e4d20b47dcf42d22fc62599a9799eac7a (diff)
libqos: move common i2c code to libqos
The functions to read/write 8-bit or 16-bit registers are the same in tmp105 and pca9552 tests, and in fact they are a special case of "read block"/"write block" functionality; read block in turn is used in ds1338-test. Move everything inside libqos-test, removing the duplication. Account for the small differences by adding to tmp105-test.c the "read register after writing" behavior that is specific to it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/pca9552-test.c')
-rw-r--r--tests/pca9552-test.c37
1 files changed, 8 insertions, 29 deletions
diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c
index 5466a67ed7..06359b7435 100644
--- a/tests/pca9552-test.c
+++ b/tests/pca9552-test.c
@@ -18,27 +18,6 @@
static I2CAdapter *i2c;
-static uint8_t pca9552_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg)
-{
- uint8_t resp[1];
- i2c_send(i2c, addr, &reg, 1);
- i2c_recv(i2c, addr, resp, 1);
- return resp[0];
-}
-
-static void pca9552_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
- uint8_t value)
-{
- uint8_t cmd[2];
- uint8_t resp[1];
-
- cmd[0] = reg;
- cmd[1] = value;
- i2c_send(i2c, addr, cmd, 2);
- i2c_recv(i2c, addr, resp, 1);
- g_assert_cmphex(resp[0], ==, cmd[1]);
-}
-
static void receive_autoinc(void)
{
uint8_t resp;
@@ -67,26 +46,26 @@ static void send_and_receive(void)
{
uint8_t value;
- value = pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
+ value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
g_assert_cmphex(value, ==, 0x55);
- value = pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
+ value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
g_assert_cmphex(value, ==, 0x0);
/* Switch on LED 0 */
- pca9552_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
- value = pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
+ i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54);
+ value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0);
g_assert_cmphex(value, ==, 0x54);
- value = pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
+ value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0);
g_assert_cmphex(value, ==, 0x01);
/* Switch on LED 12 */
- pca9552_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54);
- value = pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3);
+ i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54);
+ value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3);
g_assert_cmphex(value, ==, 0x54);
- value = pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT1);
+ value = i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT1);
g_assert_cmphex(value, ==, 0x10);
}