class FakeI2c
Defined at line 38 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
This class fakes an I2c device by implementing the I2cProtocol. When a tester wants to
have a fake I2c device, they should create a class that inherents FakeI2c and implements
the |Transact| function. The |Transact| function is where the Fake driver can view the I2C
Write data and return Read data.
The FakeI2c class is helpful because it serializes the Read and Write data, making it easier
for a tester to write a fake.
Here's an example:
class FakeLightSensor : public FakeI2c {
virtual zx_status_t Transact(const uint8_t* write_buffer, size_t write_buffer_size,
uint8_t* read_buffer, size_t* read_buffer_size, size_t
expected_read_size) {
if (CompareWrite(write_buffer, write_buffer_size, kReadLightRegisterCommand,
sizeof(kReadLightRegisterCommand)) {
SetRead(light_sensor_data_, expected_read_size, read_buffer,
sizeof(read_buffer_size);
return ZX_OK;
}
return ZX_ERR_NOT_SUPPORTED;
}
}
Protected Members
interrupt irq_
ServerBindingGroup bindings_
Public Methods
zx_status_t I2cGetInterrupt (uint32_t flags, zx::interrupt * out_irq)
Defined at line 40 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
void SetInterrupt (zx::interrupt irq)
Defined at line 44 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
void Transfer (TransferRequestView request, TransferCompleter::Sync & completer)
This function takes |request| and serialies the write data so it is easier to use
in a fake. This will call |Transact| with the serialzed data.
Defined at line 48 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
void GetName (GetNameCompleter::Sync & completer)
Defined at line 96 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
fuchsia_hardware_i2c::Service::InstanceHandler CreateInstanceHandler (async_dispatcher_t * dispatcher)
Defined at line 104 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
void set_name (std::optional<std::string> name)
Defined at line 114 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
Protected Methods
zx_status_t Transact (const uint8_t * write_buffer, size_t write_buffer_size, uint8_t * read_buffer, size_t * read_buffer_size, size_t expected_read_size)
The main function to be overriden for a specific fake. This is called on each
I2cTransact, but with serialized write and read information so it is easier to
use.
bool CompareWrite (const uint8_t * write_buffer, size_t write_buffer_size, const uint8_t * command_buffer, size_t command_buffer_size)
Helper functions for specific fakes to use inside of |Transact|.
Defined at line 125 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h
void SetRead (const void * return_buffer, size_t return_buffer_size, uint8_t * read_buffer, size_t * read_buffer_size)
Defined at line 131 of file ../../src/devices/i2c/testing/fake-i2c/include/lib/fake-i2c/fake-i2c.h