shiftreg_layout.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """
  2. # TOP2049 Open Source programming suite
  3. #
  4. # TOP2049 Shiftregister based layout definitions
  5. #
  6. # Copyright (c) 2010 Michael Buesch <m@bues.ch>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. """
  22. from libtoprammer.generic_layout import *
  23. class ShiftregLayout(GenericLayout):
  24. def __init__(self, nrZifPins, nrShiftRegs):
  25. GenericLayout.__init__(self, nrZifPins)
  26. self.nrShiftRegs = nrShiftRegs
  27. self.layouts = []
  28. for id in range(0, len(self.shiftreg_masks)):
  29. shreg_mask = self.shiftreg_masks[id]
  30. zif_mask = 0
  31. for bit in range(0, self.nrShiftRegs * 8):
  32. if (shreg_mask & (1 << bit)) == 0:
  33. continue
  34. regId = self.__bitnr2shregId(bit)
  35. zifPin = self.shreg2zif_map[regId]
  36. zif_mask |= (1 << (zifPin - 1))
  37. if id == 0 or zif_mask != 0:
  38. self.layouts.append( (id, zif_mask) )
  39. def __bitnr2shregId(self, bitNr):
  40. register = bitNr // 8
  41. pin = bitNr % 8
  42. return "%d.%d" % (register, pin)
  43. def supportedLayouts(self):
  44. return self.layouts