mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
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>
This commit is contained in:
parent
7d8ada6e4d
commit
e8ecb706a8
5 changed files with 88 additions and 95 deletions
|
@ -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, ®, 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue