Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
5.9 KiB

  1. #!/usr/bin/env python
  2. # adapted boards.txt.py from esp8266/Arduino
  3. # - single board definition, ldscripts
  4. # - portable boards.local.txt for 2.3.0 and up
  5. import os
  6. import argparse
  7. import sys
  8. import collections
  9. # TODO: drop after platform.io supports python 3
  10. if sys.version < (3, 2):
  11. import string
  12. _format = string.Formatter().vformat
  13. def format_map(tmpl, f_map):
  14. return _format(tmpl, None, f_map)
  15. else:
  16. def format_map(tmpl, f_map):
  17. return tmpl.format_map(f_map)
  18. class VersionedSubstitution(collections.MutableMapping):
  19. def __init__(self, substitutions, targets, *args, **kwargs):
  20. self._targets = targets
  21. self._version = None
  22. self._store = substitutions.copy()
  23. self.update(dict(*args, **kwargs))
  24. def set_version(self, version):
  25. self._version = version
  26. def __getitem__(self, key):
  27. if self._version in self._targets:
  28. return self._store[key]
  29. return key
  30. def __setitem__(self, key, value):
  31. self._store[key] = value
  32. def __delitem__(self, key):
  33. del self._store[key]
  34. def __iter__(self):
  35. return iter(self._store)
  36. def __len__(self):
  37. return len(self._store)
  38. BOARDS_LOCAL = {
  39. "global": collections.OrderedDict(
  40. [("menu.float_support", "scanf and printf float support")]
  41. ),
  42. "flash_size": collections.OrderedDict(
  43. [
  44. (".menu.{eesz}.1M1S", "1M (1 EEPROM Sector, no SPIFFS)"),
  45. (".menu.{eesz}.1M1S.build.flash_size", "1M"),
  46. (".menu.{eesz}.1M1S.build.flash_size_bytes", "0x100000"),
  47. (".menu.{eesz}.1M1S.build.flash_ld", "eagle.flash.1m0m1s.ld"),
  48. (".menu.{eesz}.1M1S.build.spiffs_pagesize", "256"),
  49. (".menu.{eesz}.1M1S.upload.maximum_size", "1023984"),
  50. (".menu.{eesz}.1M1S.build.rfcal_addr", "0xFC000"),
  51. (".menu.{eesz}.2M4S", "2M (4 EEPROM Sectors, 1M SPIFFS)"),
  52. (".menu.{eesz}.2M4S.build.flash_size", "2M"),
  53. (".menu.{eesz}.2M4S.build.flash_size_bytes", "0x200000"),
  54. (".menu.{eesz}.2M4S.build.flash_ld", "eagle.flash.2m1m4s.ld"),
  55. (".menu.{eesz}.2M4S.build.spiffs_pagesize", "256"),
  56. (".menu.{eesz}.2M4S.upload.maximum_size", "1044464"),
  57. (".menu.{eesz}.2M4S.build.rfcal_addr", "0x1FC000"),
  58. (".menu.{eesz}.4M1M4S", "4M (4 EEPROM Sectors, 1M SPIFFS)"),
  59. (".menu.{eesz}.4M1M4S.build.flash_size", "4M"),
  60. (".menu.{eesz}.4M1M4S.build.flash_size_bytes", "0x400000"),
  61. (".menu.{eesz}.4M1M4S.build.flash_ld", "eagle.flash.4m1m4s.ld"),
  62. (".menu.{eesz}.4M1M4S.build.spiffs_pagesize", "256"),
  63. (".menu.{eesz}.4M1M4S.upload.maximum_size", "1044464"),
  64. (".menu.{eesz}.4M1M4S.build.rfcal_addr", "0x3FC000"),
  65. (".menu.{eesz}.4M3M4S", "4M (4 EEPROM Sectors, 3M SPIFFS)"),
  66. (".menu.{eesz}.4M3M4S.build.flash_size", "4M"),
  67. (".menu.{eesz}.4M3M4S.build.flash_size_bytes", "0x400000"),
  68. (".menu.{eesz}.4M3M4S.build.flash_ld", "eagle.flash.4m3m4s.ld"),
  69. (".menu.{eesz}.4M3M4S.build.spiffs_pagesize", "256"),
  70. (".menu.{eesz}.4M3M4S.upload.maximum_size", "1044464"),
  71. (".menu.{eesz}.4M3M4S.build.rfcal_addr", "0x3FC000"),
  72. ]
  73. ),
  74. "float_support": collections.OrderedDict(
  75. [
  76. (".menu.float_support.disabled", "Disabled (Recommended)"),
  77. (".menu.float_support.disabled.build.float", ""),
  78. (".menu.float_support.enabled", "Enabled"),
  79. (
  80. ".menu.float_support.enabled.build.float",
  81. "-u _printf_float -u _scanf_float",
  82. ),
  83. ]
  84. ),
  85. }
  86. BOARD = "generic"
  87. MENUS = ["flash_size", "float_support"]
  88. CORE_VERSIONS = ["2.3.0", "latest"]
  89. EXTRA_FLAGS = [
  90. (".compiler.cpp.extra_flags", "-DNO_GLOBAL_EEPROM -DMQTT_MAX_PACKET_SIZE=1024")
  91. ]
  92. SUBSTITUTIONS = VersionedSubstitution(
  93. dict(eesz="FlashSize", wipe="FlashErase", baud="UploadSpeed", vt="VTable"),
  94. ["2.3.0"],
  95. )
  96. def generate_boards_txt(args, sub=SUBSTITUTIONS):
  97. versions = args.versions
  98. if args.version:
  99. versions = [args.version]
  100. for version in versions:
  101. sub.set_version(version)
  102. result = ["#version={}\n\n".format(version)]
  103. result.extend("{}={}\n".format(k, v) for k, v in BOARDS_LOCAL["global"].items())
  104. result.append("\n")
  105. # print("{} unused:".format(version, set(BOARDS_LOCAL.keys()) - set(MENUS[version])))
  106. # continue
  107. for menu in MENUS:
  108. section = []
  109. for k, v in BOARDS_LOCAL[menu].items():
  110. k = format_map(k, sub)
  111. section.append(BOARD + "=".join([k, v]))
  112. result.append("\n".join(section))
  113. result.append("\n\n")
  114. if EXTRA_FLAGS:
  115. result.extend(("{}{}={}".format(BOARD, k, v)) for k, v in EXTRA_FLAGS)
  116. f_path = os.path.join(args.directory, version, "boards.local.txt")
  117. f_dir, _ = os.path.split(f_path)
  118. if not os.path.exists(f_dir):
  119. os.makedirs(f_dir)
  120. with open(f_path, "w") as f:
  121. for part in result:
  122. f.write(part)
  123. f.write("\n")
  124. def print_versions(args):
  125. for version in CORE_VERSIONS:
  126. print("- {}".format(version))
  127. if __name__ == "__main__":
  128. parser = argparse.ArgumentParser()
  129. parser.add_argument(
  130. "-d",
  131. "--directory",
  132. default=os.path.join(
  133. os.path.dirname(os.path.realpath(__file__)), "arduino_ide"
  134. ),
  135. )
  136. subparsers = parser.add_subparsers(title="commands")
  137. parser_versions = subparsers.add_parser("versions", help="list supported versions")
  138. parser_versions.set_defaults(command=print_versions)
  139. parser_generate = subparsers.add_parser("generate", help="")
  140. parser_generate.add_argument("version", nargs="?")
  141. parser_generate.set_defaults(command=generate_boards_txt, versions=CORE_VERSIONS)
  142. args = parser.parse_args()
  143. args.command(args)