k32w.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 .gn import GnBuilder
  17. class K32WApp(Enum):
  18. LIGHT = auto()
  19. LOCK = auto()
  20. SHELL = auto()
  21. CONTACT = auto()
  22. def ExampleName(self):
  23. if self == K32WApp.LIGHT:
  24. return 'lighting-app'
  25. elif self == K32WApp.LOCK:
  26. return 'lock-app'
  27. elif self == K32WApp.SHELL:
  28. return 'shell'
  29. elif self == K32WApp.CONTACT:
  30. return "contact-sensor-app"
  31. else:
  32. raise Exception('Unknown app type: %r' % self)
  33. def AppNamePrefix(self):
  34. if self == K32WApp.LIGHT:
  35. return 'chip-k32w0x-light-example'
  36. elif self == K32WApp.LOCK:
  37. return 'chip-k32w0x-lock-example'
  38. elif self == K32WApp.SHELL:
  39. return 'chip-k32w0x-shell-example'
  40. elif self == K32WApp.CONTACT:
  41. return 'chip-k32w0x-contact-example'
  42. else:
  43. raise Exception('Unknown app type: %r' % self)
  44. def BuildRoot(self, root):
  45. return os.path.join(root, 'examples', self.ExampleName(), 'nxp', 'k32w', 'k32w0')
  46. class K32WBuilder(GnBuilder):
  47. def __init__(self,
  48. root,
  49. runner,
  50. app: K32WApp = K32WApp.LIGHT,
  51. release: bool = False,
  52. low_power: bool = False,
  53. tokenizer: bool = False,
  54. disable_ble: bool = False,
  55. disable_ota: bool = False,
  56. disable_logs: bool = False,
  57. se05x: bool = False,
  58. tinycrypt: bool = False,
  59. crypto_platform: bool = False):
  60. super(K32WBuilder, self).__init__(
  61. root=app.BuildRoot(root),
  62. runner=runner)
  63. self.code_root = root
  64. self.app = app
  65. self.low_power = low_power
  66. self.tokenizer = tokenizer
  67. self.release = release
  68. self.disable_ble = disable_ble
  69. self.disable_ota = disable_ota
  70. self.disable_logs = disable_logs
  71. self.se05x = se05x
  72. self.tinycrypt = tinycrypt
  73. self.crypto_platform = crypto_platform
  74. def GnBuildArgs(self):
  75. args = [
  76. 'k32w0_sdk_root="%s"' % os.environ['NXP_K32W0_SDK_ROOT'],
  77. ]
  78. if self.low_power:
  79. args.append('chip_with_low_power=1')
  80. else:
  81. args.append('chip_with_low_power=0')
  82. if self.tokenizer:
  83. args.append('chip_pw_tokenizer_logging=true')
  84. if self.release:
  85. args.append('is_debug=false')
  86. if self.disable_ble:
  87. args.append('chip_enable_ble=false')
  88. if self.disable_ota:
  89. args.append('chip_enable_ota_requestor=false')
  90. if self.disable_logs:
  91. args.append('chip_logging=false')
  92. if self.se05x:
  93. args.append('chip_with_se05x=true')
  94. if self.tinycrypt:
  95. args.append('chip_crypto=\"platform\" chip_crypto_flavor=\"tinycrypt\"')
  96. if self.crypto_platform:
  97. args.append('chip_crypto=\"platform\"')
  98. return args
  99. def generate(self):
  100. self._Execute([os.path.join(
  101. self.code_root, 'third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh')])
  102. super(K32WBuilder, self).generate()
  103. def build_outputs(self):
  104. items = {}
  105. for extension in ["", ".map", ".hex"]:
  106. name = '%s%s' % (self.app.AppNamePrefix(), extension)
  107. items[name] = os.path.join(self.output_dir, name)
  108. return items