Difference between device.write and lib.i2c_write

Hi ,

From base/microblaze/microblaze_python_libraries.ipynb, we can see that:

device.write(0x50, buf, 1), buf, 2)

‘device’ is defined by device = lib.i2c_open(lib.PMOD_G4_B, lib.PMOD_G4_A).
If dir(device), we can see the available functions:
image .

However, these are slightly different from the definition as the screenshot below, as well as in PYNQ/i2c.c at master · Xilinx/PYNQ · GitHub.
They start with i2c. For example the code above “device.write(0x50, buf, 1)” should be “lib.i2c_write(0x50, buf, 1)”.

The same is true for gpio and spi.

So questions are:

  1. are they equivalent, e.g. device.write vs lib.i2c_write ? the testing result is. Just want to confirm.
  2. any more specific documentation about it? would be good to read some references.
    any input will be much appreciated.


device.write is a wrapper around lib.i2c_write with the first argument passed implicitly. This is a common pattern across across all of the Microblaze drivers and is done automatically by the C->Python communication layer. The rule is that a any function of the form T {type}_func({type}, ...) becomes a method on {type} with the signature T instance.func(...).

This is documented in general terms in the Microblaze programming notebook under the “Class-like objects” section.


Thank you Peter. Appreciate it.