makeSip6.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python3
  2. """
  3. # TOP2049 Open Source programming suite
  4. #
  5. # Commandline utility
  6. #
  7. # Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. """
  23. import re
  24. import sys
  25. import os
  26. def substitute(input, oldSocket, newSocket):
  27. input = re.sub(r'(^\s*packages).*', lambda m:'{} = (("DIP10", ""), ),'.format(m.group(1)), input)
  28. input = re.sub(r'(^\s*chipPackage).*', lambda m:'{} = "DIP10",'.format(m.group(1)), input)
  29. input = re.sub(r'(^\s*chipPinVCC).*', lambda m:'{} = 9,'.format(m.group(1)), input)
  30. input = re.sub(r'(^\s*chipPinsVPP).*', lambda m:'{} = 10,'.format(m.group(1)), input)
  31. input = re.sub(r'(^\s*chipPinGND).*', lambda m:'{} = 8,'.format(m.group(1)), input)
  32. input = re.sub(r'(^\s*runtimeID).*', lambda m:'{} = (0xDE05, 0x01),'.format(m.group(1)), input)
  33. input = re.sub(r'(^\s*description).+"(.*)".*', lambda m:'{} = "{} - ICD",'.format(m.group(1), m.group(2)), input)
  34. input = re.sub(r'(^\s*bitfile).*', lambda m:'{} = "microchip01sip6",'.format(m.group(1)), input)
  35. input = re.sub("{}".format(oldSocket), "{}".format(newSocket), input)
  36. input = re.sub("{}".format(oldSocket.upper()), "{}".format(newSocket.upper()), input)
  37. return input
  38. def makeSip():
  39. inputFileName = '__init__.py'
  40. fin = open(inputFileName)
  41. dMCU = {}
  42. for line in fin:
  43. matchObj = re.match(r'.*(pic[0-9]+l?f\w+)(sip[0-9a]+).*', line)
  44. if matchObj:
  45. continue
  46. matchObj = re.match(r'.*(pic[0-9]+l?f\w+)(dip[0-9a]+).*', line)
  47. if not matchObj:
  48. print("{} did not match".format(line))
  49. continue
  50. # print('matched {} - {}'.format(matchObj.group(1), matchObj.group(2)))
  51. dMCU.setdefault(matchObj.group(1), matchObj.group(2))
  52. fin.close()
  53. for item in dMCU.items():
  54. fin = open("{}{}.py".format(item[0], item[1]))
  55. fout = open("{}sip6.py".format(item[0]), 'w')
  56. fout.write("#\n")
  57. fout.write("# THIS FILE WAS AUTOGENERATED BY makeSip6.py\n")
  58. fout.write("# Do not edit this file manually. All changes will be lost.\n")
  59. fout.write("#\n\n")
  60. for line in fin:
  61. fout.write(substitute(line, "{}".format(item[1]), "sip6"))
  62. fout.close()
  63. fin.close()
  64. def main(argv):
  65. makeSip()
  66. if __name__ == "__main__":
  67. exit(main(sys.argv))