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.
For I2C hardware manual of HiFive1 Rev B board, you can read i2c_specs.pdf. The I2C hardware is implemented base on it.
I have created an I2C test with an Arduino UNO board. Because I use old BSP version that do not support I2C driver, so my programmed driver control directly I2C register without using vtables. (See drv_i2c0.c)