Talk to I2C devices via SysFS or C api

Hi, i’ve connected my i2c bus to a number of devices. i’ve run the following commands in an attempt to communicate with them.

$ ldto enable i2c-ao
$ i2cdetect -l
i2c-1   i2c             Meson I2C adapter                       I2C adapter
i2c-0   i2c             DesignWare HDMI                         I2C adapter
$ i2cdetect 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x08-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         08 -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --
$ echo realtime_clock 0x68 > /sys/bus/i2c/devices/i2c-1/new-device

However, i’m stuck on how to communicate with the device either through sysfs or some other api? Is there a C api or some other sysfs file im supposed to write to?

Thanks

You can use i2cget and i2cset to send sample read and write.

For C, use the kernel interface IOCTLs.

Can you give an example of how to use i2cset and i2cget?

I tried to use

i2cget 1  0x08 0x08
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-1, chip address 0x08, data address
0x08, using read word data.
Continue? [Y/n] y
Error: Read failed