ti.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Copyright (c) 2021 Project CHIP Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. from enum import Enum, auto
  16. from typing import Optional
  17. from .gn import GnBuilder
  18. class TIApp(Enum):
  19. LOCK = auto()
  20. PUMP = auto()
  21. PUMP_CONTROLLER = auto()
  22. ALL_CLUSTERS = auto()
  23. ALL_CLUSTERS_MINIMAL = auto()
  24. LIGHTING = auto()
  25. SHELL = auto()
  26. def ExampleName(self):
  27. if self == TIApp.LOCK:
  28. return 'lock-app'
  29. elif self == TIApp.PUMP:
  30. return 'pump-app'
  31. elif self == TIApp.PUMP_CONTROLLER:
  32. return 'pump-controller-app'
  33. elif self == TIApp.ALL_CLUSTERS:
  34. return 'all-clusters-app'
  35. elif self == TIApp.ALL_CLUSTERS_MINIMAL:
  36. return 'all-clusters-minimal-app'
  37. elif self == TIApp.LIGHTING:
  38. return 'lighting-app'
  39. elif self == TIApp.SHELL:
  40. return 'shell'
  41. else:
  42. raise Exception('Unknown app type: %r' % self)
  43. def AppNamePrefix(self, board):
  44. if self == TIApp.LOCK:
  45. return f'chip-{board.BoardName()}-lock-example'
  46. elif self == TIApp.PUMP:
  47. return f'chip-{board.BoardName()}-pump-example'
  48. elif self == TIApp.PUMP_CONTROLLER:
  49. return f'chip-{board.BoardName()}-pump-controller-example'
  50. elif self == TIApp.ALL_CLUSTERS:
  51. return f'chip-{board.BoardName()}-all-clusters-example'
  52. elif self == TIApp.ALL_CLUSTERS_MINIMAL:
  53. return f'chip-{board.BoardName()}-all-clusters-minimal-example'
  54. elif self == TIApp.LIGHTING:
  55. return f'chip-{board.BoardName()}-lighting-example'
  56. elif self == TIApp.SHELL:
  57. return f'chip-{board.BoardName()}-shell-example'
  58. else:
  59. raise Exception('Unknown app type: %r' % self)
  60. def BuildRoot(self, root, board):
  61. return os.path.join(root, 'examples', self.ExampleName(), board.FamilyName())
  62. class TIBoard(Enum):
  63. LP_CC2652R7 = auto()
  64. LP_EM_CC1354P10_6 = auto()
  65. def BoardName(self):
  66. if self == TIBoard.LP_CC2652R7:
  67. return 'LP_CC2652R7'
  68. elif self == TIBoard.LP_EM_CC1354P10_6:
  69. return 'LP_EM_CC1354P10_6'
  70. else:
  71. raise Exception('Unknown board type: %r' % self)
  72. def FamilyName(self):
  73. if self == TIBoard.LP_CC2652R7:
  74. return 'cc13x2x7_26x2x7'
  75. elif self == TIBoard.LP_EM_CC1354P10_6:
  76. return 'cc13x4_26x4'
  77. else:
  78. raise Exception('Unknown board type: %r' % self)
  79. class TIBuilder(GnBuilder):
  80. def __init__(self,
  81. root,
  82. runner,
  83. board=TIBoard.LP_CC2652R7,
  84. app: TIApp = TIApp.LOCK,
  85. openthread_ftd: Optional[bool] = None):
  86. super(TIBuilder, self).__init__(
  87. root=app.BuildRoot(root, board),
  88. runner=runner)
  89. self.code_root = root
  90. self.app = app
  91. self.board = board
  92. self.openthread_ftd = openthread_ftd
  93. def GnBuildArgs(self):
  94. args = [
  95. 'ti_sysconfig_root="%s"' % os.environ['TI_SYSCONFIG_ROOT'],
  96. 'ti_simplelink_board="%s"' % self.board.BoardName(),
  97. ]
  98. if self.openthread_ftd:
  99. args.append('chip_openthread_ftd=true')
  100. args.append('chip_progress_logging=false')
  101. elif self.openthread_ftd is not None:
  102. args.append('chip_openthread_ftd=false')
  103. return args
  104. def build_outputs(self):
  105. items = {}
  106. if (self.board == TIBoard.LP_CC2652R7):
  107. if (self.app == TIApp.LOCK
  108. or self.app == TIApp.PUMP
  109. or self.app == TIApp.PUMP_CONTROLLER):
  110. extensions = [".out", ".bin", ".out.map", "-bim.hex"]
  111. else:
  112. extensions = [".out", ".out.map"]
  113. else:
  114. extensions = [".out", ".out.map"]
  115. for extension in extensions:
  116. name = '%s%s' % (self.app.AppNamePrefix(self.board), extension)
  117. items[name] = os.path.join(self.output_dir, name)
  118. return items