pootle / tripipy

Simple python driver for Trinamic tmc5130 connected to Raspberry Pi
The Unlicense
36 stars 14 forks source link

triMixed register does not allow writeBytes #9

Open gautamjain opened 4 years ago

gautamjain commented 4 years ago

If you try to write to a triMixed field, a ValueError is thrown. For example:

self.writeInt('GCONF', 0)

causes:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/py_ws/tripipy/trinamicDriver.py", line 203, in writeInt
    creg.writeBytes(ba, value=regValue)
  File "/root/py_ws/tripipy/trinamicDriver.py", line 603, in writeBytes
    raise ValueError('register %s cannot accept new value in writeBytes' % self.name)
ValueError: register GCONF cannot accept new value in writeBytes

Can you help me understand why write_bytes() shouldn't accept a new value? It seems like this error will always be thrown:

class triMixed(triRegister):
...

    def writeBytes(self, ba, value=None):
        """
        fills the given 5 byte buffer with the bytes to write to the chip.
        """
        if not value is None:
            raise ValueError('register %s cannot accept new value in writeBytes' % self.name)
        self.packBytes(ba, self.curval)
pootle commented 4 years ago

A triMixed instance should have child triSubxxx fields, use set on the child fields to change the overall value of the total field, and then call writeBytes with value None on the triMixed field to transmit the current value to the chip.

gautamjain commented 4 years ago

Thanks. Makes sense.

However, some of the existing triMixed instances do not have any child triSubxxx fields. Should these be fixed?

E.g. GCONF, GSTAT, SWMODE, RAMPSTAT

pootle commented 4 years ago

eh? GSTAT uses GSTATflags which is defined in tmc5130regs.py, and similar for the others - when they're read only in particular (and they are all just flag bits) they just use a subclass of intflag so the various flags are named