1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-11 19:29:20 +08:00
2022-10-30 18:47:56 +01:00

1.8 KiB

sysfs

I2C

Byte order

All common libraries (smbus, digispark, firmata, i2cget) read and write I2C data in the order LSByte, MSByte.
Often the devices store its bytes in the reverse order and therefor needs to be swapped after reading.

Linux syscall implementation

In general there are different ioctl features for I2C

  • IOCTL I2C_RDWR, needs "I2C_FUNC_I2C"
  • IOCTL SMBUS, needs "I2C_FUNC_SMBUS.."
  • SYSFS I/O
  • call of "i2c_smbus_* methods"

The possible functions should be checked before by "I2C_FUNCS".

for further reading see:

Qotation from kernel.org: "If possible, use the provided i2c_smbus_* methods described below instead of issuing direct ioctls." We do not do this at the moment, instead we using the "IOCTL SMBUS".

Because the syscall needs uintptr in Go, there are some known pitfalls with that. Following documents could be helpful:

Basically by convert to an uintptr, which is than just a number to an object existing at the moment of creation without any other reference, the garbage collector will possible destroy the original object. Therefor uintptr should be avoided as long as possible.