def decodeRegisters(cls, MSLUT, MSLUTSEL, MSLUTSTART): obj = cls() obj._reg_MSLUT = MSLUT obj._reg_MSLUTSEL = MSLUTSEL obj._reg_MSLUTSTART = MSLUTSTART ranges = [ (TMC_helpers.field_get(MSLUTSEL, 0x0000FF00, 8), TMC_helpers.field_get(MSLUTSEL, 0x00000003, 0)), (TMC_helpers.field_get(MSLUTSEL, 0x00FF0000, 16), TMC_helpers.field_get(MSLUTSEL, 0x0000000C, 2)), (TMC_helpers.field_get(MSLUTSEL, 0xFF000000, 24), TMC_helpers.field_get(MSLUTSEL, 0x00000030, 4)), (255, TMC_helpers.field_get(MSLUTSEL, 0x000000C0, 6)), ] if not(ranges[0][0] <= ranges[1][0] <= ranges[2][0] <= ranges[3][0]): raise ValueError("Condition X1 <= X2 <= X3 <= X4 not satisfied") startSin = TMC_helpers.field_get(MSLUTSTART, 0x000000FF, 0) startCos = TMC_helpers.field_get(MSLUTSTART, 0x00FF0000, 16) # Generate the first quarter sine wave sineValues = [ (0, startSin) ] for i in range(1, 257): for j in range(0, 4): if i < ranges[j][0]: offset = ranges[j][1] - 1 break bitValue = ((MSLUT[math.floor((i)/32) & 7] >> ((i) % 32) ) & 1) deltaValue = bitValue + offset newValue = sineValues[i-1][1] + deltaValue sineValues += [(i, newValue)] # Generate the second quarter sine wave for i in range(257, 512): newValue = sineValues[511-i][1] sineValues += [(i, newValue)] # Generate the remaining sine wave offset = 2*sineValues[0][1] - 1 for i in range(512, 1024): newValue = -sineValues[i-512][1] + offset sineValues += [(i, newValue)] # Generate the cosine wave cosOffset = startCos - sineValues[256][1] obj._waveform = [] for i in range(0, 1024): tmp = sineValues[i] obj._waveform += [(tmp[0], tmp[1], sineValues[(i+256) % 1024][1] + cosOffset)] # The table is now initialized obj._initialized = True return obj
def readRegisterField(self, field): return TMC_helpers.field_get(self.readRegister(field[0]), field[1], field[2])
def get_gpio(self, idx): return TMC_helpers.field_get(self.get_gpios(), (1 << idx), idx)
def get_pullup(self, idx): return TMC_helpers.field_get(self.get_pullups(), (1 << idx), idx)
def get_direction(self, idx): return TMC_helpers.field_get(self.get_directions(), (1 << idx), idx)
def readRegisterField(self, registerAddress, mask, shift): return TMC_helpers.field_get(self.readRegister(registerAddress), mask, shift)