mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
libqos: i2c: move address into QI2CDevice
This removes the hardcoded I2C address from the tests. The address is passed via QOSGraphEdgeOptions to i2c_device_create and stored in the QI2CDevice. The i2c_send and i2c_recv functions, along with their wrappers, therefore, can be changed to take a QI2CDevice rather than an adapter/address pair. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
8130dbcbcd
commit
06599472ec
5 changed files with 82 additions and 75 deletions
|
@ -31,13 +31,12 @@ static inline uint8_t bcd2bin(uint8_t x)
|
|||
static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
|
||||
{
|
||||
QI2CDevice *i2cdev = (QI2CDevice *)obj;
|
||||
I2CAdapter *i2c = i2cdev->bus;
|
||||
|
||||
uint8_t resp[7];
|
||||
time_t now = time(NULL);
|
||||
struct tm *tm_ptr = gmtime(&now);
|
||||
|
||||
i2c_read_block(i2c, DS1338_ADDR, 0, resp, sizeof(resp));
|
||||
i2c_read_block(i2cdev, 0, resp, sizeof(resp));
|
||||
|
||||
/* check retrieved time againt local time */
|
||||
g_assert_cmpuint(bcd2bin(resp[4]), == , tm_ptr->tm_mday);
|
||||
|
@ -50,6 +49,7 @@ static void ds1338_register_nodes(void)
|
|||
QOSGraphEdgeOptions opts = {
|
||||
.extra_device_opts = "address=0x68"
|
||||
};
|
||||
add_qi2c_address(&opts, &(QI2CAddress) { DS1338_ADDR });
|
||||
|
||||
qos_node_create_driver("ds1338", i2c_device_create);
|
||||
qos_node_consumes("ds1338", "i2c-bus", &opts);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue