View Single Post
Posts: 30 | Thanked: 42 times | Joined on Oct 2010 @ Russia
#247
Originally Posted by dirkvl View Post
The TCA8424 documentation says:
...
The example in the datasheet uses mixed R/W i2c transactions that are not available from userspace through i2c-dev interface. I still think that it should be possible to split a read transaction into two.

Here is a python code that may read values of the first registers, if it fails on the first write(), try changing address to 0x77.
Code:
#!/usr/bin/python

import fcntl
import os
import struct

class I2C(object):
    I2C_SLAVE = 0x0703

    def __init__(self, fname):
        self.fd = os.open(fname, os.O_RDWR)

    def __del__(self):
        os.close(self.fd)
    
    def select_device(self, devaddr):
        if fcntl.ioctl(self.fd, self.I2C_SLAVE, devaddr) < 0:
            return IOError('ioctl error')
    
    def write(self, data):
        os.write(self.fd, data)
   
    def read(self, count):
        data = ''
        while 1:
            d = os.read(self.fd, count - len(data))
            if len(d)==0:
                raise IOError("EOF while reading %d bytes" % count)

            data += d
            if len(data) == count:
                return data

if __name__ == '__main__':
    port = I2C('/dev/i2c-1')
    port.select_device(0x76) # or 0x77
    for i in range(10):
        port.write(struct.pack('<H', i))
        v = ord(p.read(1))
        print "reg=%02Xh val=%02Xh" % (i, v)
Copy it to a file and run "python filename.py" as root. My best guess is that it won't destroy your phone... I cannot test it on mine, since I have none, and won't have for a month at least. If the code works, I'll clean it up, and it should be easy to work with, as no compilation is required.

One more thing... It looks like this chip supports generic i2c HID interface and there is a module in mainline kernel for it. Try "modprobe i2c-hid" to see if the module is compiled and available... In any case it shouldn't work, as i2c lacks autoprobing and the proper way is to specify the device in the devicetree file...

Edit: Tried the code on n900 (and fixed it a bit), n900 is still alive )

Last edited by butler; 2014-01-04 at 22:06.