Metal library I²C data, registers, addresses

i’m trying to “talk” with my HiFive1-rev-b to a sensor via I²C. the sensor’s documentation mentions writing a byte to a register (also a byte) at an address (also a byte) to instruct the sensor to send data.
metal/i2c.h’s metal_i2c_read (and metal_i2c_write) only accept address (addr) and payload (*buf) arguments.
what am i missing?

and: where are those functions defined? metal/i2c.c seems to only contain declarations and metal/i2c.h surprisingly holds definitions, which are only redirections to functions within the struct `metal_i2c_vtable’…?

I also found it hard to get to the other side of those vtables. One way is to use something like notepad++ with its “Find in files” and search all the *.c *.h files in the project for some string. Make sure the current directory is the top of the project so notepad++ will search every directory from there down. A good string to use is the address of the instance for the device as shown in the “SiFive FE310-G002 Manual”. e.g. the I2c is at 0x10016000 but search with text 10016000. If you keep searching up the chain of references you will eventually find: …\freedom-metal\src\drivers\sifive_i2c0.c. This has all the code to control the device so you can see how it works. Also at the very bottom is how the mystery vtable is filled in.

1 Like