colinoflynn / pyjtagbs

Python JTAG Boundary Scan tool
GNU Lesser General Public License v2.1
70 stars 14 forks source link

SPI & I2C #5

Open jerome60 opened 1 year ago

jerome60 commented 1 year ago

Hello, it's great work. is there any progress on spi and i2c support? I might be able to contribute on the subject.

floriangmeiner commented 6 months ago

Hey @jerome60, have you made and progress or tried anything? I'm also curious and would love to be help.

jerome60 commented 5 months ago

Hi @floriangmeiner , I worked a little on the subject which I put aside for the moment. I added SPI and I2C functions to interface with the DLL which already has these functions for the moment it did not work. I can use this code for you to move forward on it if you want?

jerome60 commented 5 months ago

` def set_i2c_sda_pin(self, device_number, pinid):

    rv = self.lib.jtagcore_i2c_set_sda_pin(self._jtag, device_number, pinid);
    self._check_return(rv)

    return rv

def set_i2c_scl_pin(self, device_number, pinid):

    rv = self.lib.jtagcore_i2c_set_scl_pin(self._jtag, device_number, pinid);
    self._check_return(rv)

    return rv

def i2c_set_write_read(self, device_number, i2cadr, data):

    if isinstance(data, str):
        tmp_buffer2 = data.encode("utf-8")    

    rv = self.lib.jtagcore_i2c_write_read(self._jtag, i2cadr, 0, 16, tmp_buffer2, 0, 0);
    if rv < 0:
        print ("JTAG chain error !")
    elif rv == 0:
        print ("Warning : Device Ack not detected!")`
jerome60 commented 5 months ago

in JTAGCORE.py

jerome60 commented 5 months ago

and jtagbs.py ` def i2c_set_sda_pin(self, pins):

    if isinstance(pins, str) or isinstance(pins, int):
        pins = [pins]

    for i in range(0, len(pins)):

        pin = pins[i]

        if isinstance(pin, str):
            pin = self.lookup_pinid(pin)

        self.jtag.interface.set_i2c_sda_pin(self.deviceid, pin);

    if self.autoscan:
        self.jtag.scan()

        # self._check_return(rv)

    # return rv

def i2c_set_scl_pin(self, pins):

    if isinstance(pins, str) or isinstance(pins, int):
        pins = [pins]

    for i in range(0, len(pins)):

        pin = pins[i]

        if isinstance(pin, str):
            pin = self.lookup_pinid(pin)

        self.jtag.interface.set_i2c_scl_pin(self.deviceid, pin);

    if self.autoscan:
        self.jtag.scan()
        # self._check_return(rv)

    # return rv

def set_i2c_write_read(self, i2cadr, data):

    self.jtag.interface.i2c_set_write_read(self.deviceid, i2cadr, data)`
jerome60 commented 5 months ago

and in main.py `#lattice.i2c_set_sda_pin("IOI12")

lattice.i2c_set_scl_pin("IOI10")

I2C_RET = lattice.set_i2c_write_read("5C","10")

print ('retour I2C',I2C_RET)`