Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 1 | """Functions related to hardware topology. |
| 2 | |
| 3 | See proto definitions for descriptions of arguments. |
| 4 | """ |
C Shapiro | e4657e3 | 2020-01-24 13:32:11 -0600 | [diff] [blame] | 5 | |
Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 6 | # Needed to load from @proto. Add @unused to silence lint. |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 7 | load("//config/util/bindings/proto.star", "protos") |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 8 | load( |
| 9 | "@proto//chromiumos/config/api/topology.proto", |
| 10 | topo_pb = "chromiumos.config.api", |
| 11 | ) |
| 12 | load( |
| 13 | "@proto//chromiumos/config/api/hardware_topology.proto", |
| 14 | hw_topo_pb = "chromiumos.config.api", |
| 15 | ) |
| 16 | load( |
| 17 | "@proto//chromiumos/config/api/component.proto", |
| 18 | comp_pb = "chromiumos.config.api", |
| 19 | ) |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 20 | load("//config/util/hw_features.star", "hw_feat") |
David Burger | 32589c5 | 2020-04-08 07:11:06 -0600 | [diff] [blame] | 21 | |
Sean McAllister | 9eb2afe | 2020-10-19 15:18:23 +0000 | [diff] [blame] | 22 | _PRESENT = struct( |
| 23 | UNKNOWN = topo_pb.HardwareFeatures.PRESENT_UNKNOWN, |
| 24 | PRESENT = topo_pb.HardwareFeatures.PRESENT, |
| 25 | NOT_PRESENT = topo_pb.HardwareFeatures.NOT_PRESENT, |
| 26 | ) |
| 27 | |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 28 | _AUDIO_CODEC = struct( |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 29 | RT5682 = topo_pb.HardwareFeatures.Audio.RT5682, |
| 30 | ALC5682I = topo_pb.HardwareFeatures.Audio.ALC5682I, |
| 31 | ALC5682 = topo_pb.HardwareFeatures.Audio.ALC5682, |
YH Lin | 9e123f5 | 2021-04-13 19:52:18 -0700 | [diff] [blame] | 32 | DA7219 = topo_pb.HardwareFeatures.Audio.DA7219, |
| 33 | NAU88L25B = topo_pb.HardwareFeatures.Audio.NAU88L25B, |
| 34 | ) |
| 35 | |
| 36 | _AMPLIFIER = struct( |
Duncan Laurie | 6a174e4 | 2020-04-20 14:42:32 -0700 | [diff] [blame] | 37 | MAX98357 = topo_pb.HardwareFeatures.Audio.MAX98357, |
| 38 | MAX98373 = topo_pb.HardwareFeatures.Audio.MAX98373, |
| 39 | MAX98360 = topo_pb.HardwareFeatures.Audio.MAX98360, |
Yong Zhi | 35cd10d | 2020-07-16 20:56:50 -0500 | [diff] [blame] | 40 | RT1015 = topo_pb.HardwareFeatures.Audio.RT1015, |
rasheed.hsueh | ab30ef2 | 2020-10-28 11:47:34 +0800 | [diff] [blame] | 41 | ALC1011 = topo_pb.HardwareFeatures.Audio.ALC1011, |
YH Lin | 9e123f5 | 2021-04-13 19:52:18 -0700 | [diff] [blame] | 42 | RT1015P = topo_pb.HardwareFeatures.Audio.RT1015P, |
| 43 | ALC1019 = topo_pb.HardwareFeatures.Audio.ALC1019, |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
Jett Rink | 82da31e | 2020-03-13 11:46:26 -0600 | [diff] [blame] | 46 | _FP_LOC = struct( |
Jett Rink | e027f2f | 2020-04-14 12:11:23 -0600 | [diff] [blame] | 47 | NOT_PRESENT = topo_pb.HardwareFeatures.Fingerprint.NOT_PRESENT, |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 48 | POWER_BUTTON_TOP_LEFT = topo_pb.HardwareFeatures.Fingerprint.POWER_BUTTON_TOP_LEFT, |
| 49 | KEYBOARD_BOTTOM_LEFT = topo_pb.HardwareFeatures.Fingerprint.KEYBOARD_BOTTOM_LEFT, |
| 50 | KEYBOARD_BOTTOM_RIGHT = topo_pb.HardwareFeatures.Fingerprint.KEYBOARD_BOTTOM_RIGHT, |
| 51 | KEYBOARD_TOP_RIGHT = topo_pb.HardwareFeatures.Fingerprint.KEYBOARD_TOP_RIGHT, |
YH Lin | 1684b56 | 2021-04-01 17:46:52 -0700 | [diff] [blame] | 52 | RIGHT_SIDE = topo_pb.HardwareFeatures.Fingerprint.RIGHT_SIDE, |
| 53 | LEFT_SIDE = topo_pb.HardwareFeatures.Fingerprint.LEFT_SIDE, |
Jett Rink | 82da31e | 2020-03-13 11:46:26 -0600 | [diff] [blame] | 54 | ) |
| 55 | |
Jett Rink | e27c705 | 2020-03-19 11:42:05 -0600 | [diff] [blame] | 56 | _STORAGE = struct( |
Sean McAllister | a84b734 | 2020-06-23 18:08:48 -0600 | [diff] [blame] | 57 | EMMC = comp_pb.Component.Storage.EMMC, |
| 58 | NVME = comp_pb.Component.Storage.NVME, |
YH Lin | 1745dd2 | 2020-11-25 09:18:34 -0800 | [diff] [blame] | 59 | SATA = comp_pb.Component.Storage.SATA, |
Jett Rink | e27c705 | 2020-03-19 11:42:05 -0600 | [diff] [blame] | 60 | ) |
| 61 | |
Jett Rink | 0858d22 | 2020-03-19 11:27:54 -0600 | [diff] [blame] | 62 | _KB_TYPE = struct( |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 63 | NONE = topo_pb.HardwareFeatures.Keyboard.NONE, |
| 64 | INTERNAL = topo_pb.HardwareFeatures.Keyboard.INTERNAL, |
| 65 | DETACHABLE = topo_pb.HardwareFeatures.Keyboard.DETACHABLE, |
Jett Rink | 0858d22 | 2020-03-19 11:27:54 -0600 | [diff] [blame] | 66 | ) |
| 67 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 68 | _STYLUS = struct( |
| 69 | NONE = topo_pb.HardwareFeatures.Stylus.NONE, |
| 70 | INTERNAL = topo_pb.HardwareFeatures.Stylus.INTERNAL, |
| 71 | EXTERNAL = topo_pb.HardwareFeatures.Stylus.EXTERNAL, |
| 72 | ) |
| 73 | |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 74 | _REGION = struct( |
| 75 | SCREEN = topo_pb.HardwareFeatures.Button.SCREEN, |
| 76 | KEYBOARD = topo_pb.HardwareFeatures.Button.KEYBOARD, |
| 77 | ) |
| 78 | |
| 79 | _EDGE = struct( |
| 80 | LEFT = topo_pb.HardwareFeatures.Button.LEFT, |
| 81 | RIGHT = topo_pb.HardwareFeatures.Button.RIGHT, |
| 82 | TOP = topo_pb.HardwareFeatures.Button.TOP, |
| 83 | BOTTOM = topo_pb.HardwareFeatures.Button.BOTTOM, |
| 84 | ) |
| 85 | |
Ren-Pei Zeng | 0bf9635 | 2020-09-28 18:44:42 +0800 | [diff] [blame] | 86 | _CAMERA_FLAGS = struct( |
| 87 | SUPPORT_1080P = topo_pb.HardwareFeatures.Camera.FLAGS_SUPPORT_1080P, |
| 88 | SUPPORT_AUTOFOCUS = topo_pb.HardwareFeatures.Camera.FLAGS_SUPPORT_AUTOFOCUS, |
| 89 | ) |
| 90 | |
Sean McAllister | 17b4aa4 | 2020-10-15 19:54:24 +0000 | [diff] [blame] | 91 | _EC_TYPE = struct( |
| 92 | UNKNOWN = topo_pb.HardwareFeatures.EmbeddedController.EC_TYPE_UNKNOWN, |
| 93 | CHROME = topo_pb.HardwareFeatures.EmbeddedController.EC_CHROME, |
| 94 | WILCO = topo_pb.HardwareFeatures.EmbeddedController.EC_WILCO, |
| 95 | ) |
| 96 | |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 97 | _TPM_TYPE = struct( |
| 98 | UNKNOWN = topo_pb.HardwareFeatures.TrustedPlatformModule.TPM_TYPE_UNKNOWN, |
| 99 | THIRD_PARTY = topo_pb.HardwareFeatures.TrustedPlatformModule.THIRD_PARTY, |
YH Lin | bf6fce2 | 2021-04-21 13:43:53 -0700 | [diff] [blame] | 100 | GSC_H1B = topo_pb.HardwareFeatures.TrustedPlatformModule.GSC_H1B, |
| 101 | GSC_H1D = topo_pb.HardwareFeatures.TrustedPlatformModule.GSC_H1D, |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 102 | ) |
| 103 | |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 104 | # Starlark doesn't support converting enums to their names. Add helper fns. to |
| 105 | # do so. |
| 106 | def _button_region_to_str(region): |
| 107 | return { |
| 108 | _REGION.SCREEN: "SCREEN", |
| 109 | _REGION.KEYBOARD: "KEYBOARD", |
| 110 | }.get(region, "UNKNOWN") |
| 111 | |
| 112 | def _button_edge_to_str(edge): |
| 113 | return { |
| 114 | _EDGE.LEFT: "LEFT", |
| 115 | _EDGE.RIGHT: "RIGHT", |
| 116 | _EDGE.TOP: "TOP", |
| 117 | _EDGE.BOTTOM: "BOTTOM", |
| 118 | }.get(edge, "UNKNOWN") |
| 119 | |
Jett Rink | cb41fb4 | 2020-04-10 16:32:17 -0600 | [diff] [blame] | 120 | def _make_fw_config(mask, id): |
| 121 | """Builds a HardwareFeatures.FirmwareConfiguration proto. |
| 122 | |
| 123 | Takes a 32-bit mask for the field and an id. Shifts the id |
| 124 | into the mask region and checks that the value fits within the bit mask. |
| 125 | """ |
| 126 | lsb_bit_set = (~mask + 1) & mask |
| 127 | shifted_id = id * lsb_bit_set |
| 128 | if shifted_id & mask != shifted_id: |
| 129 | fail("Specified id %d out of range [0, %d]" % (id, mask // lsb_bit_set)) |
| 130 | |
| 131 | return topo_pb.HardwareFeatures.FirmwareConfiguration( |
| 132 | value = shifted_id, |
| 133 | mask = mask, |
| 134 | ) |
| 135 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 136 | def _accumulate_fw_config(existing_fw_config, new_fw_config): |
Josie Nordrum | 206be1b | 2020-06-04 12:20:16 -0600 | [diff] [blame] | 137 | """Adds fw config to existing fw config.""" |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 138 | if existing_fw_config.mask & new_fw_config.mask: |
| 139 | fail("FW_CONFIG masks cannot overlap! 0x%x and 0x%x" % |
Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 140 | (existing_fw_config.mask, new_fw_config.mask)) |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 141 | |
| 142 | existing_fw_config.value += new_fw_config.value |
| 143 | existing_fw_config.mask += new_fw_config.mask |
| 144 | |
| 145 | def _accumulate_fw_configs(result_hw_features, fw_configs): |
| 146 | for fw_config in fw_configs: |
| 147 | _accumulate_fw_config(result_hw_features.fw_config, fw_config) |
| 148 | |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 149 | def _create_design_features(form_factor = hw_feat.form_factor.CLAMSHELL): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 150 | """Builds a HardwareFeatures proto with form_factor.""" |
| 151 | return topo_pb.HardwareFeatures( |
| 152 | form_factor = topo_pb.HardwareFeatures.FormFactor( |
| 153 | form_factor = form_factor, |
| 154 | ), |
| 155 | ) |
C Shapiro | e4657e3 | 2020-01-24 13:32:11 -0600 | [diff] [blame] | 156 | |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 157 | _DEFAULT_FF = [hw_feat.form_factor.CLAMSHELL, hw_feat.form_factor.CONVERTIBLE] |
| 158 | |
| 159 | def _create_features(form_factors = _DEFAULT_FF): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 160 | """Builds a HardwareFeatures proto for each of form_factors.""" |
| 161 | return [_create_design_features(ff) for ff in form_factors] |
C Shapiro | e4657e3 | 2020-01-24 13:32:11 -0600 | [diff] [blame] | 162 | |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 163 | def _bool_to_present(value): |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 164 | """Returns correct value of present enum depending on value""" |
| 165 | if value == None: |
Sean McAllister | 9eb2afe | 2020-10-19 15:18:23 +0000 | [diff] [blame] | 166 | return _PRESENT.UNKNOWN |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 167 | elif value: |
Sean McAllister | 9eb2afe | 2020-10-19 15:18:23 +0000 | [diff] [blame] | 168 | return _PRESENT.PRESENT |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 169 | else: |
Sean McAllister | 9eb2afe | 2020-10-19 15:18:23 +0000 | [diff] [blame] | 170 | return _PRESENT.NOT_PRESENT |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 171 | |
C Shapiro | d236531 | 2020-05-18 14:46:48 -0500 | [diff] [blame] | 172 | def _create_screen( |
YH Lin | 1343298 | 2020-08-18 13:18:40 -0700 | [diff] [blame] | 173 | id = None, |
| 174 | description = None, |
Josie Nordrum | c83fdca | 2020-07-08 10:58:18 -0600 | [diff] [blame] | 175 | inches = 0, |
C Shapiro | d236531 | 2020-05-18 14:46:48 -0500 | [diff] [blame] | 176 | width_px = None, |
| 177 | height_px = None, |
| 178 | pixels_per_in = None, |
| 179 | touch = False, |
| 180 | fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 181 | """Builds a Topology proto for a screen.""" |
| 182 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 183 | |
C Shapiro | d236531 | 2020-05-18 14:46:48 -0500 | [diff] [blame] | 184 | hw_features.screen.panel_properties = comp_pb.Component.DisplayPanel.Properties( |
| 185 | diagonal_milliinch = inches * 1000, |
| 186 | width_px = width_px, |
| 187 | height_px = height_px, |
| 188 | pixels_per_in = pixels_per_in, |
| 189 | ) |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 190 | hw_features.screen.touch_support = _bool_to_present(touch) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 191 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 192 | _accumulate_fw_configs(hw_features, fw_configs) |
| 193 | |
YH Lin | 1343298 | 2020-08-18 13:18:40 -0700 | [diff] [blame] | 194 | if touch: |
| 195 | screen_id = id if id else "TOUCHSCREEN" |
| 196 | screen_desc = description if description else "Touchscreen" |
| 197 | else: |
| 198 | screen_id = id if id else "SCREEN" |
| 199 | screen_desc = description if description else "Default screen" |
| 200 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 201 | return topo_pb.Topology( |
YH Lin | 1343298 | 2020-08-18 13:18:40 -0700 | [diff] [blame] | 202 | id = screen_id, |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 203 | type = topo_pb.Topology.SCREEN, |
YH Lin | 1343298 | 2020-08-18 13:18:40 -0700 | [diff] [blame] | 204 | description = {"EN": screen_desc}, |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 205 | hardware_feature = hw_features, |
| 206 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 207 | |
Andrew Lamb | e7b9f48 | 2020-05-15 12:00:42 -0600 | [diff] [blame] | 208 | def _create_form_factor(form_factor, fw_configs = [], id = None, description = None): |
| 209 | """Builds a Topology proto for a form factor. |
| 210 | |
| 211 | Args: |
Andrew Lamb | 5636e40 | 2020-05-22 20:07:53 -0600 | [diff] [blame] | 212 | form_factor: A FormFactorType enum. Required. |
Andrew Lamb | e7b9f48 | 2020-05-15 12:00:42 -0600 | [diff] [blame] | 213 | fw_configs: A list of FirmwareConfiguration protos for the form factor. |
| 214 | id: A string identifier for the Topology. If not passed, a default is |
| 215 | provided based on form_factor. |
| 216 | description: An English description for the Topology. If not passed, a |
| 217 | default is provided based on form_factor. |
| 218 | """ |
| 219 | if not id: |
| 220 | id = { |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 221 | hw_feat.form_factor.CLAMSHELL: "CLAMSHELL", |
| 222 | hw_feat.form_factor.CONVERTIBLE: "CONVERTIBLE", |
Jeff Chase | 0039553 | 2021-05-05 15:41:43 -0400 | [diff] [blame] | 223 | hw_feat.form_factor.CHROMEBASE: "CHROMEBASE", |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 224 | hw_feat.form_factor.CHROMEBOX: "CHROMEBOX", |
Andrew Lamb | e7b9f48 | 2020-05-15 12:00:42 -0600 | [diff] [blame] | 225 | }[form_factor] |
| 226 | |
| 227 | if not description: |
| 228 | description = { |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 229 | hw_feat.form_factor.CLAMSHELL: "Device cannot rotate past 180 degrees", |
| 230 | hw_feat.form_factor.CONVERTIBLE: "Device can rotate 360 degrees", |
Jeff Chase | 0039553 | 2021-05-05 15:41:43 -0400 | [diff] [blame] | 231 | hw_feat.form_factor.CHROMEBASE: "Desktop chrome all-in-one.", |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 232 | hw_feat.form_factor.CHROMEBOX: "Desktop chrome device.", |
Andrew Lamb | e7b9f48 | 2020-05-15 12:00:42 -0600 | [diff] [blame] | 233 | }[form_factor] |
| 234 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 235 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 236 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 237 | hw_features.form_factor.form_factor = form_factor |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 238 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 239 | _accumulate_fw_configs(hw_features, fw_configs) |
| 240 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 241 | return topo_pb.Topology( |
| 242 | id = id, |
| 243 | type = topo_pb.Topology.FORM_FACTOR, |
| 244 | description = {"EN": description}, |
| 245 | hardware_feature = hw_features, |
| 246 | ) |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 247 | |
Duncan Laurie | 6a174e4 | 2020-04-20 14:42:32 -0700 | [diff] [blame] | 248 | def _create_audio(id, description, codec = None, speaker_amp = None, headphone_codec = None, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 249 | """Builds a Topology proto for audio.""" |
| 250 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 251 | |
Duncan Laurie | 6a174e4 | 2020-04-20 14:42:32 -0700 | [diff] [blame] | 252 | if codec: |
| 253 | hw_features.audio.audio_codec = codec |
| 254 | if speaker_amp: |
| 255 | hw_features.audio.speaker_amp = speaker_amp |
| 256 | if headphone_codec: |
| 257 | hw_features.audio.headphone_codec = headphone_codec |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 258 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 259 | _accumulate_fw_configs(hw_features, fw_configs) |
| 260 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 261 | return topo_pb.Topology( |
| 262 | id = id, |
| 263 | type = topo_pb.Topology.AUDIO, |
| 264 | description = {"EN": description}, |
| 265 | hardware_feature = hw_features, |
| 266 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 267 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 268 | def _create_stylus(id, description, stylus_type, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 269 | """Builds a Topology proto for a stylus.""" |
| 270 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 271 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 272 | hw_features.stylus.stylus = stylus_type |
| 273 | |
| 274 | _accumulate_fw_configs(hw_features, fw_configs) |
| 275 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 276 | return topo_pb.Topology( |
| 277 | id = id, |
| 278 | type = topo_pb.Topology.STYLUS, |
| 279 | description = {"EN": description}, |
| 280 | hardware_feature = hw_features, |
| 281 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 282 | |
YH Lin | 6b861e0 | 2021-03-01 18:23:16 -0800 | [diff] [blame] | 283 | def _create_keyboard(backlight, pwr_btn_present, kb_type, numpad_present = False, fw_configs = [], id = None, description = None): |
Andrew Lamb | 0cc271d | 2020-05-20 11:05:14 -0600 | [diff] [blame] | 284 | """Builds a Topology proto for a keyboard. |
| 285 | |
| 286 | Args: |
Andrew Lamb | 5636e40 | 2020-05-22 20:07:53 -0600 | [diff] [blame] | 287 | backlight: True if a backlight is present. Required. |
| 288 | pwr_btn_present: True if a power button is present. Required. |
| 289 | kb_type: A KeyboardType enum. Required. |
YH Lin | 6b861e0 | 2021-03-01 18:23:16 -0800 | [diff] [blame] | 290 | numpad_present: True if numeric pad is present. |
Andrew Lamb | 0cc271d | 2020-05-20 11:05:14 -0600 | [diff] [blame] | 291 | fw_configs: A list of FirmwareConfiguration protos for the form factor. |
| 292 | id: A string identifier for the Topology. If not passed, a default is |
| 293 | provided. |
| 294 | description: An English description for the Topology. If not passed, a |
| 295 | default is provided. |
| 296 | """ |
| 297 | |
| 298 | if not id: |
| 299 | id = "KB_{backlight}".format( |
| 300 | backlight = "BL" if backlight else "NO_BL", |
| 301 | ) |
| 302 | |
| 303 | if not description: |
| 304 | # Starlark doesn't seem to have a way to find the enum name with |
| 305 | # reflection. |
| 306 | if kb_type == topo_pb.HardwareFeatures.Keyboard.INTERNAL: |
| 307 | type_str = "Internal" |
| 308 | elif kb_type == topo_pb.HardwareFeatures.Keyboard.DETACHABLE: |
| 309 | type_str = "Detachable" |
| 310 | else: |
| 311 | type_str = "Unknown type" |
| 312 | |
| 313 | description = "{type} keyboard {backlight} backlight".format( |
| 314 | type = type_str, |
| 315 | backlight = "with" if backlight else "without", |
| 316 | ) |
| 317 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 318 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 319 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 320 | hw_features.keyboard.keyboard_type = kb_type |
| 321 | hw_features.keyboard.backlight = _bool_to_present(backlight) |
| 322 | hw_features.keyboard.power_button = _bool_to_present(pwr_btn_present) |
YH Lin | 6b861e0 | 2021-03-01 18:23:16 -0800 | [diff] [blame] | 323 | hw_features.keyboard.numeric_pad = _bool_to_present(numpad_present) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 324 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 325 | _accumulate_fw_configs(hw_features, fw_configs) |
| 326 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 327 | return topo_pb.Topology( |
| 328 | id = id, |
| 329 | type = topo_pb.Topology.KEYBOARD, |
| 330 | description = {"EN": description}, |
| 331 | hardware_feature = hw_features, |
| 332 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 333 | |
Jett Rink | ba590b5 | 2020-05-01 11:35:16 -0600 | [diff] [blame] | 334 | def _create_thermal(id, description, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 335 | """Builds a Topology proto for thermal.""" |
| 336 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 337 | |
Jett Rink | ba590b5 | 2020-05-01 11:35:16 -0600 | [diff] [blame] | 338 | _accumulate_fw_configs(hw_features, fw_configs) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 339 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 340 | return topo_pb.Topology( |
| 341 | id = id, |
| 342 | type = topo_pb.Topology.THERMAL, |
| 343 | description = {"EN": description}, |
| 344 | hardware_feature = hw_features, |
| 345 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 346 | |
Ricardo Ribalda | b9b17b3 | 2021-01-13 17:10:20 +0100 | [diff] [blame] | 347 | def _make_camera_device( |
| 348 | interface, |
| 349 | facing, |
| 350 | orientation, |
| 351 | flags, |
| 352 | ids, |
| 353 | privacy_switch_present = None): |
Ren-Pei Zeng | ce869dd | 2020-08-18 01:29:37 +0800 | [diff] [blame] | 354 | """Builds a HardwareFeatures.Camera.Device proto.""" |
| 355 | camera_pb = topo_pb.HardwareFeatures.Camera |
| 356 | device = camera_pb.Device() |
| 357 | |
Ren-Pei Zeng | ce869dd | 2020-08-18 01:29:37 +0800 | [diff] [blame] | 358 | device.interface = { |
| 359 | "usb": camera_pb.INTERFACE_USB, |
| 360 | "mipi": camera_pb.INTERFACE_MIPI, |
| 361 | }[interface] |
| 362 | device.facing = { |
| 363 | "back": camera_pb.FACING_BACK, |
| 364 | "front": camera_pb.FACING_FRONT, |
| 365 | }[facing] |
| 366 | device.orientation = { |
| 367 | 0: camera_pb.ORIENTATION_0, |
| 368 | 90: camera_pb.ORIENTATION_90, |
| 369 | 180: camera_pb.ORIENTATION_180, |
| 370 | 270: camera_pb.ORIENTATION_270, |
| 371 | }[orientation] |
Ren-Pei Zeng | 0bf9635 | 2020-09-28 18:44:42 +0800 | [diff] [blame] | 372 | device.flags = flags |
| 373 | device.ids = ids |
Ren-Pei Zeng | ce869dd | 2020-08-18 01:29:37 +0800 | [diff] [blame] | 374 | |
Ricardo Ribalda | b9b17b3 | 2021-01-13 17:10:20 +0100 | [diff] [blame] | 375 | if privacy_switch_present: |
| 376 | device.privacy_switch = _bool_to_present(privacy_switch_present) |
| 377 | |
Ren-Pei Zeng | ce869dd | 2020-08-18 01:29:37 +0800 | [diff] [blame] | 378 | return device |
| 379 | |
| 380 | def _create_camera( |
| 381 | id, |
| 382 | description, |
| 383 | fw_configs = [], |
Ren-Pei Zeng | ce869dd | 2020-08-18 01:29:37 +0800 | [diff] [blame] | 384 | camera_devices = []): |
| 385 | """Builds a Topology proto for cameras. |
| 386 | |
| 387 | Args: |
| 388 | id: A string identifier for the Topology. |
| 389 | description: An English description for the Topology. |
| 390 | fw_configs: A list of FirmwareConfiguration protos for the form factor. |
| 391 | camera_devices: A list of HardwareFeatures.Camera.Device protos. |
Ren-Pei Zeng | ce869dd | 2020-08-18 01:29:37 +0800 | [diff] [blame] | 392 | """ |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 393 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 394 | |
Ren-Pei Zeng | 9b5682d | 2020-10-14 17:37:30 +0800 | [diff] [blame] | 395 | camera = hw_features.camera |
| 396 | camera.devices = camera_devices |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 397 | |
| 398 | _accumulate_fw_configs(hw_features, fw_configs) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 399 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 400 | return topo_pb.Topology( |
| 401 | id = id, |
| 402 | type = topo_pb.Topology.CAMERA, |
| 403 | description = {"EN": description}, |
| 404 | hardware_feature = hw_features, |
| 405 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 406 | |
Andrew Lamb | 3501307 | 2020-05-04 11:05:48 -0600 | [diff] [blame] | 407 | def _create_sensor( |
| 408 | id, |
| 409 | description, |
| 410 | fw_configs = [], |
| 411 | lid_accel_present = None, |
Josie Nordrum | fd8bc5d | 2020-06-08 17:03:25 -0600 | [diff] [blame] | 412 | base_accel_present = None, |
| 413 | lid_gyro_present = None, |
| 414 | base_gyro_present = None, |
| 415 | lid_magno_present = None, |
Cheng Yueh | 8a682d4 | 2020-10-05 13:05:38 +0800 | [diff] [blame] | 416 | base_magno_present = None, |
| 417 | lid_light_present = None, |
| 418 | base_light_present = None): |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 419 | """Builds a Topology proto for accelerometer/gyroscrope/magnometer sensors.""" |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 420 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 421 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 422 | _accumulate_fw_configs(hw_features, fw_configs) |
| 423 | |
| 424 | if lid_accel_present: |
| 425 | hw_features.accelerometer.lid_accelerometer = _bool_to_present(lid_accel_present) |
| 426 | |
Josie Nordrum | fd8bc5d | 2020-06-08 17:03:25 -0600 | [diff] [blame] | 427 | if base_accel_present: |
| 428 | hw_features.accelerometer.base_accelerometer = _bool_to_present(base_accel_present) |
| 429 | |
| 430 | if lid_gyro_present: |
| 431 | hw_features.gyroscope.lid_gyroscope = _bool_to_present(lid_gyro_present) |
| 432 | |
Josie Nordrum | 20a8e60 | 2020-06-08 22:33:12 -0600 | [diff] [blame] | 433 | if base_gyro_present: |
| 434 | hw_features.gyroscope.base_gyroscope = _bool_to_present(base_gyro_present) |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 435 | |
Josie Nordrum | fd8bc5d | 2020-06-08 17:03:25 -0600 | [diff] [blame] | 436 | if lid_magno_present: |
| 437 | hw_features.magnetometer.lid_magnetometer = _bool_to_present(lid_magno_present) |
| 438 | |
| 439 | if base_magno_present: |
| 440 | hw_features.magnetometer.base_magnetometer = _bool_to_present(base_magno_present) |
| 441 | |
Cheng Yueh | 8a682d4 | 2020-10-05 13:05:38 +0800 | [diff] [blame] | 442 | if lid_light_present: |
| 443 | hw_features.light_sensor.lid_lightsensor = _bool_to_present(lid_light_present) |
| 444 | |
| 445 | if base_light_present: |
| 446 | hw_features.light_sensor.base_lightsensor = _bool_to_present(base_light_present) |
| 447 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 448 | return topo_pb.Topology( |
| 449 | id = id, |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 450 | type = topo_pb.Topology.ACCELEROMETER_GYROSCOPE_MAGNETOMETER, |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 451 | description = {"EN": description}, |
| 452 | hardware_feature = hw_features, |
| 453 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 454 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 455 | def _create_fingerprint(id, description, location, board = None, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 456 | """Builds a Topology proto for a fingerprint reader.""" |
| 457 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 458 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 459 | hw_features.fingerprint.location = location |
| 460 | if board: |
| 461 | hw_features.fingerprint.board = board |
Tom Hughes | dfc3540 | 2020-06-29 16:02:09 -0700 | [diff] [blame] | 462 | if board == "bloonchipper": |
Tom Hughes | 9a0d49e | 2020-10-30 16:44:35 -0700 | [diff] [blame] | 463 | hw_features.fingerprint.ro_version = "bloonchipper_v2.0.5938-197506c1" |
Jett Rink | 82da31e | 2020-03-13 11:46:26 -0600 | [diff] [blame] | 464 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 465 | _accumulate_fw_configs(hw_features, fw_configs) |
| 466 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 467 | return topo_pb.Topology( |
| 468 | id = id, |
| 469 | type = topo_pb.Topology.FINGERPRINT, |
| 470 | description = {"EN": description}, |
| 471 | hardware_feature = hw_features, |
| 472 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 473 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 474 | def _create_proximity_sensor(id, description, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 475 | """Builds a Topology proto for a proximity sensor.""" |
| 476 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 477 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 478 | _accumulate_fw_configs(hw_features, fw_configs) |
| 479 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 480 | return topo_pb.Topology( |
| 481 | id = id, |
| 482 | type = topo_pb.Topology.PROXIMITY_SENSOR, |
| 483 | description = {"EN": description}, |
| 484 | hardware_feature = hw_features, |
| 485 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 486 | |
Jett Rink | ba590b5 | 2020-05-01 11:35:16 -0600 | [diff] [blame] | 487 | def _create_daughter_board( |
| 488 | id, |
| 489 | description, |
| 490 | fw_configs = [], |
| 491 | usbc_count = 0, |
| 492 | usba_count = 0, |
| 493 | lte_support = False, |
Vincent Palatin | 0ebdfd3 | 2021-04-23 15:54:43 +0200 | [diff] [blame] | 494 | lte_model = None, |
Jett Rink | ba590b5 | 2020-05-01 11:35:16 -0600 | [diff] [blame] | 495 | hdmi_support = False): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 496 | """Builds a Topology proto for a daughter board.""" |
| 497 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 498 | |
Jett Rink | ba590b5 | 2020-05-01 11:35:16 -0600 | [diff] [blame] | 499 | _accumulate_fw_configs(hw_features, fw_configs) |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 500 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 501 | hw_features.usb_c.count.value = usbc_count |
| 502 | hw_features.usb_a.count.value = usba_count |
| 503 | hw_features.lte.present = _bool_to_present(lte_support) |
Vincent Palatin | 0ebdfd3 | 2021-04-23 15:54:43 +0200 | [diff] [blame] | 504 | hw_features.lte.model = lte_model |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 505 | hw_features.hdmi.present = _bool_to_present(hdmi_support) |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 506 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 507 | return topo_pb.Topology( |
| 508 | id = id, |
| 509 | type = topo_pb.Topology.DAUGHTER_BOARD, |
| 510 | description = {"EN": description}, |
| 511 | hardware_feature = hw_features, |
| 512 | ) |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 513 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 514 | def _create_non_volatile_storage(id, description, storage_type, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 515 | """Builds a Topology proto for non-volatile storage.""" |
| 516 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 517 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 518 | hw_features.storage.storage_type = storage_type |
Jett Rink | e27c705 | 2020-03-19 11:42:05 -0600 | [diff] [blame] | 519 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 520 | _accumulate_fw_configs(hw_features, fw_configs) |
| 521 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 522 | return topo_pb.Topology( |
| 523 | id = id, |
| 524 | type = topo_pb.Topology.NON_VOLATILE_STORAGE, |
| 525 | description = {"EN": description}, |
| 526 | hardware_feature = hw_features, |
| 527 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 528 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 529 | def _create_wifi(id, description, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 530 | """Builds a Topology proto for a WiFi chip.""" |
| 531 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 532 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 533 | _accumulate_fw_configs(hw_features, fw_configs) |
| 534 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 535 | return topo_pb.Topology( |
| 536 | id = id, |
| 537 | type = topo_pb.Topology.WIFI, |
| 538 | description = {"EN": description}, |
| 539 | hardware_feature = hw_features, |
| 540 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 541 | |
Vincent Palatin | 0ebdfd3 | 2021-04-23 15:54:43 +0200 | [diff] [blame] | 542 | def _create_lte_board(id, description, lte_present, fw_configs = [], model = None): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 543 | """Builds a Topology proto for a LTE board.""" |
| 544 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 545 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 546 | hw_features.lte.present = _bool_to_present(lte_present) |
Vincent Palatin | 0ebdfd3 | 2021-04-23 15:54:43 +0200 | [diff] [blame] | 547 | hw_features.lte.model = model |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 548 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 549 | _accumulate_fw_configs(hw_features, fw_configs) |
| 550 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 551 | return topo_pb.Topology( |
| 552 | id = id, |
| 553 | type = topo_pb.Topology.LTE_BOARD, |
| 554 | description = {"EN": description}, |
| 555 | hardware_feature = hw_features, |
| 556 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 557 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 558 | def _create_sd_reader(id, description, fw_configs = []): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 559 | """Builds a Topology proto for a SD reader.""" |
| 560 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 561 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 562 | _accumulate_fw_configs(hw_features, fw_configs) |
| 563 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 564 | return topo_pb.Topology( |
| 565 | id = id, |
| 566 | type = topo_pb.Topology.SD_READER, |
| 567 | description = {"EN": description}, |
| 568 | hardware_feature = hw_features, |
| 569 | ) |
Jett Rink | 937839f | 2020-03-26 12:09:49 -0600 | [diff] [blame] | 570 | |
Jett Rink | ba590b5 | 2020-05-01 11:35:16 -0600 | [diff] [blame] | 571 | def _create_motherboard_usb( |
| 572 | id, |
| 573 | description, |
| 574 | fw_configs = [], |
| 575 | usbc_count = 0, |
| 576 | usba_count = 0): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 577 | """Builds a Topology proto for a motherboard.""" |
| 578 | hw_features = topo_pb.HardwareFeatures() |
Jett Rink | 937839f | 2020-03-26 12:09:49 -0600 | [diff] [blame] | 579 | |
Jett Rink | ba590b5 | 2020-05-01 11:35:16 -0600 | [diff] [blame] | 580 | _accumulate_fw_configs(hw_features, fw_configs) |
Jett Rink | 937839f | 2020-03-26 12:09:49 -0600 | [diff] [blame] | 581 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 582 | hw_features.usb_c.count.value = usbc_count |
| 583 | hw_features.usb_a.count.value = usba_count |
Jett Rink | 937839f | 2020-03-26 12:09:49 -0600 | [diff] [blame] | 584 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 585 | return topo_pb.Topology( |
| 586 | id = id, |
| 587 | type = topo_pb.Topology.MOTHERBOARD_USB, |
| 588 | description = {"EN": description}, |
| 589 | hardware_feature = hw_features, |
| 590 | ) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 591 | |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 592 | def _create_bluetooth(id, description, bt_component, fw_configs = [], present = True): |
C Shapiro | a681fad | 2020-04-15 17:05:03 -0500 | [diff] [blame] | 593 | """Builds a Topology proto for bluetooth.""" |
| 594 | hw_features = topo_pb.HardwareFeatures() |
| 595 | |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 596 | hw_features.bluetooth.present = _bool_to_present(present) |
C Shapiro | a681fad | 2020-04-15 17:05:03 -0500 | [diff] [blame] | 597 | hw_features.bluetooth.component = bt_component |
| 598 | |
| 599 | _accumulate_fw_configs(hw_features, fw_configs) |
| 600 | |
| 601 | return topo_pb.Topology( |
| 602 | id = id, |
| 603 | type = topo_pb.Topology.BLUETOOTH, |
| 604 | description = {"EN": description}, |
| 605 | hardware_feature = hw_features, |
| 606 | ) |
| 607 | |
Josie Nordrum | 206be1b | 2020-06-04 12:20:16 -0600 | [diff] [blame] | 608 | def _create_barreljack(id, description, bj_present, fw_configs = []): |
| 609 | """Builds a Topology proto for barreljack.""" |
| 610 | hw_features = topo_pb.HardwareFeatures() |
| 611 | |
| 612 | hw_features.barreljack.present = _bool_to_present(bj_present) |
| 613 | |
| 614 | _accumulate_fw_configs(hw_features, fw_configs) |
| 615 | |
| 616 | return topo_pb.Topology( |
| 617 | id = id, |
| 618 | type = topo_pb.Topology.BARRELJACK, |
| 619 | description = {"EN": description}, |
| 620 | hardware_feature = hw_features, |
| 621 | ) |
| 622 | |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 623 | def _create_power_button(region, edge, position, id = None, description = None): |
| 624 | """Builds a Topology proto for a power button. |
| 625 | |
| 626 | Args: |
| 627 | region: A HardwareFeatures.Button.Region enum. Required. |
| 628 | edge: A HardwareFeatures.Button.Edge enum. Required. |
| 629 | position: The percentage for button center position to the display's |
| 630 | width/height in primary landscape screen orientation. If edge is |
| 631 | LEFT or RIGHT, specifies the button's center position as a fraction |
| 632 | of region's height relative to the top of region. For TOP and |
| 633 | BOTTOM, specifies the position as a fraction of region width |
| 634 | relative to the left side of region. Must be in the range |
| 635 | [0.0, 1.0]. Required. |
| 636 | id: A string identifier for the Topology. If not passed, a default is |
| 637 | provided. |
| 638 | description: An English description for the Topology. If not passed, a |
| 639 | default is provided. |
| 640 | """ |
| 641 | if not id: |
| 642 | id = "{region}_{edge}_POWER_BUTTON".format( |
| 643 | region = _button_region_to_str(region), |
| 644 | edge = _button_edge_to_str(edge), |
| 645 | ) |
| 646 | |
| 647 | if not description: |
| 648 | description = "Power button on the {edge} edge of the {region}".format( |
| 649 | region = _button_region_to_str(region).lower(), |
| 650 | edge = _button_edge_to_str(edge).lower(), |
| 651 | ) |
| 652 | return topo_pb.Topology( |
| 653 | id = id, |
| 654 | type = topo_pb.Topology.POWER_BUTTON, |
| 655 | description = {"EN": description}, |
| 656 | hardware_feature = topo_pb.HardwareFeatures( |
| 657 | power_button = topo_pb.HardwareFeatures.Button( |
| 658 | region = region, |
| 659 | edge = edge, |
| 660 | position = position, |
| 661 | ), |
| 662 | ), |
| 663 | ) |
| 664 | |
Andrew Lamb | 26e7202 | 2020-06-19 12:14:32 -0600 | [diff] [blame] | 665 | def _create_volume_button(region, edge, position, id = None, description = None): |
| 666 | """Builds a Topology proto for a volume button. |
| 667 | |
| 668 | Args: |
| 669 | region: A HardwareFeatures.Button.Region enum. Required. |
| 670 | edge: A HardwareFeatures.Button.Edge enum. Required. |
| 671 | position: The percentage for button center position to the display's |
| 672 | width/height in primary landscape screen orientation. If edge is |
| 673 | LEFT or RIGHT, specifies the button's center position as a fraction |
| 674 | of region's height relative to the top of region. For TOP and |
| 675 | BOTTOM, specifies the position as a fraction of region width |
| 676 | relative to the left side of region. Must be in the range |
| 677 | [0.0, 1.0]. Required. |
| 678 | id: A string identifier for the Topology. If not passed, a default is |
| 679 | provided. |
| 680 | description: An English description for the Topology. If not passed, a |
| 681 | default is provided. |
| 682 | """ |
| 683 | if not id: |
| 684 | id = "{region}_{edge}_VOLUME_BUTTON".format( |
| 685 | region = _button_region_to_str(region), |
| 686 | edge = _button_edge_to_str(edge), |
| 687 | ) |
| 688 | |
| 689 | if not description: |
| 690 | description = "Volume button on the {edge} edge of the {region}".format( |
| 691 | region = _button_region_to_str(region).lower(), |
| 692 | edge = _button_edge_to_str(edge).lower(), |
| 693 | ) |
| 694 | return topo_pb.Topology( |
| 695 | id = id, |
| 696 | type = topo_pb.Topology.POWER_BUTTON, |
| 697 | description = {"EN": description}, |
| 698 | hardware_feature = topo_pb.HardwareFeatures( |
| 699 | volume_button = topo_pb.HardwareFeatures.Button( |
| 700 | region = region, |
| 701 | edge = edge, |
| 702 | position = position, |
| 703 | ), |
| 704 | ), |
| 705 | ) |
| 706 | |
Sean McAllister | 4d7ecde | 2020-10-19 15:32:45 +0000 | [diff] [blame] | 707 | def _create_ec(present = True, ec_type = _EC_TYPE.CHROME, id = None): |
Sean McAllister | 17b4aa4 | 2020-10-15 19:54:24 +0000 | [diff] [blame] | 708 | """Builds a Topology proto for an embedded controller. |
| 709 | |
| 710 | Args: |
Sean McAllister | 4d7ecde | 2020-10-19 15:32:45 +0000 | [diff] [blame] | 711 | present: flag indicating whether the device has an EC at all |
| 712 | ec_type: An EmbeddedControllerType enum |
Sean McAllister | 17b4aa4 | 2020-10-15 19:54:24 +0000 | [diff] [blame] | 713 | id: A string identifier for the Topology. If not passed, a default is |
| 714 | provided. |
| 715 | """ |
| 716 | hw_features = topo_pb.HardwareFeatures() |
| 717 | hw_features.embedded_controller.ec_type = ec_type |
Sean McAllister | 4d7ecde | 2020-10-19 15:32:45 +0000 | [diff] [blame] | 718 | hw_features.embedded_controller.present = _bool_to_present(present) |
Sean McAllister | 17b4aa4 | 2020-10-15 19:54:24 +0000 | [diff] [blame] | 719 | |
| 720 | return topo_pb.Topology( |
| 721 | id = id or "ec", |
| 722 | type = topo_pb.Topology.EC, |
| 723 | hardware_feature = hw_features, |
| 724 | ) |
| 725 | |
Sean McAllister | 4d7ecde | 2020-10-19 15:32:45 +0000 | [diff] [blame] | 726 | # enumerate the common cases |
| 727 | _EC_NONE = _create_ec(present = False, ec_type = _EC_TYPE.UNKNOWN) |
| 728 | _EC_CHROME = _create_ec(ec_type = _EC_TYPE.CHROME) |
| 729 | _EC_WILCO = _create_ec(ec_type = _EC_TYPE.WILCO) |
| 730 | |
Zhuohao Lee | 8d9f1fb | 2021-02-01 21:35:07 +0800 | [diff] [blame] | 731 | def _create_touch(id, description, fw_configs = []): |
| 732 | """Builds a Topology proto for touch.""" |
| 733 | hw_features = topo_pb.HardwareFeatures() |
| 734 | |
| 735 | _accumulate_fw_configs(hw_features, fw_configs) |
| 736 | |
| 737 | return topo_pb.Topology( |
| 738 | id = id, |
| 739 | type = topo_pb.Topology.TOUCH, |
| 740 | description = {"EN": description}, |
| 741 | hardware_feature = hw_features, |
| 742 | ) |
| 743 | |
YH Lin | bf6fce2 | 2021-04-21 13:43:53 -0700 | [diff] [blame] | 744 | def _create_tpm(tpm_type = _TPM_TYPE.GSC_H1B, id = None, fw_configs = []): |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 745 | """Builds a Topology proto for a trusted platform module. |
| 746 | |
| 747 | Args: |
| 748 | tpm_type: A TrustedPlatformModuleType enum |
| 749 | id: A string identifier for the Topology. If not passed, a default is |
| 750 | provided. |
YH Lin | bf6fce2 | 2021-04-21 13:43:53 -0700 | [diff] [blame] | 751 | fw_configs: A list of FirmwareConfiguration protos for the tpm. |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 752 | """ |
| 753 | hw_features = topo_pb.HardwareFeatures() |
| 754 | hw_features.trusted_platform_module.tpm_type = tpm_type |
| 755 | |
YH Lin | bf6fce2 | 2021-04-21 13:43:53 -0700 | [diff] [blame] | 756 | _accumulate_fw_configs(hw_features, fw_configs) |
| 757 | |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 758 | return topo_pb.Topology( |
| 759 | id = id or "TPM", |
| 760 | type = topo_pb.Topology.TPM, |
| 761 | hardware_feature = hw_features, |
| 762 | ) |
| 763 | |
Toni Barzic | f802a70 | 2021-05-18 19:40:23 -0700 | [diff] [blame] | 764 | def _create_microphone_mute_switch(present = False): |
| 765 | """Builds a Topology proto for an microphone mute switch. |
| 766 | |
| 767 | Args: |
| 768 | present: flag indicating whether the device has an microphone mute |
| 769 | switch |
| 770 | """ |
| 771 | hw_features = topo_pb.HardwareFeatures() |
| 772 | hw_features.microphone_mute_switch.present = _bool_to_present(present) |
| 773 | |
| 774 | return topo_pb.Topology( |
| 775 | id = "Default", |
| 776 | type = topo_pb.Topology.MICROPHONE_MUTE_SWITCH, |
| 777 | hardware_feature = hw_features, |
| 778 | ) |
| 779 | |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 780 | # enumerate the common cases |
| 781 | _TPM_THIRD_PARTY = _create_tpm(tpm_type = _TPM_TYPE.THIRD_PARTY) |
YH Lin | bf6fce2 | 2021-04-21 13:43:53 -0700 | [diff] [blame] | 782 | _TPM_GSC_H1B = _create_tpm(tpm_type = _TPM_TYPE.GSC_H1B) |
| 783 | _TPM_GSC_H1D = _create_tpm(tpm_type = _TPM_TYPE.GSC_H1D) |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 784 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 785 | def _create_hardware_topology( |
| 786 | screen = None, |
| 787 | form_factor = None, |
| 788 | audio = None, |
| 789 | stylus = None, |
| 790 | keyboard = None, |
| 791 | thermal = None, |
| 792 | camera = None, |
| 793 | accelerometer_gyroscope_magnetometer = None, |
| 794 | fingerprint = None, |
| 795 | proximity_sensor = None, |
| 796 | daughter_board = None, |
| 797 | non_volatile_storage = None, |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 798 | wifi = None, |
| 799 | lte_board = None, |
| 800 | sd_reader = None, |
C Shapiro | a681fad | 2020-04-15 17:05:03 -0500 | [diff] [blame] | 801 | motherboard_usb = None, |
Josie Nordrum | 206be1b | 2020-06-04 12:20:16 -0600 | [diff] [blame] | 802 | bluetooth = None, |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 803 | barreljack = None, |
Andrew Lamb | 26e7202 | 2020-06-19 12:14:32 -0600 | [diff] [blame] | 804 | power_button = None, |
Sean McAllister | 17b4aa4 | 2020-10-15 19:54:24 +0000 | [diff] [blame] | 805 | volume_button = None, |
Zhuohao Lee | 8d9f1fb | 2021-02-01 21:35:07 +0800 | [diff] [blame] | 806 | ec = None, |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 807 | touch = None, |
Toni Barzic | f802a70 | 2021-05-18 19:40:23 -0700 | [diff] [blame] | 808 | tpm = None, |
| 809 | microphone_mute_switch = None): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 810 | """Builds a HardwareTopology proto from Topology protos.""" |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 811 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 812 | # Only allow form_factor topologies for form factors |
| 813 | if screen and screen.type != topo_pb.Topology.SCREEN: |
| 814 | fail("Invalid screen topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 815 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 816 | if form_factor and form_factor.type != topo_pb.Topology.FORM_FACTOR: |
| 817 | fail("Invalid form factor topology") |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 818 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 819 | if audio and audio.type != topo_pb.Topology.AUDIO: |
| 820 | fail("Invalid audio topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 821 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 822 | if stylus and stylus.type != topo_pb.Topology.STYLUS: |
| 823 | fail("Invalid stylus topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 824 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 825 | if keyboard and keyboard.type != topo_pb.Topology.KEYBOARD: |
| 826 | fail("Invalid keyboard topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 827 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 828 | if thermal and thermal.type != topo_pb.Topology.THERMAL: |
| 829 | fail("Invalid thermal topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 830 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 831 | if camera and camera.type != topo_pb.Topology.CAMERA: |
| 832 | fail("Invalid camera topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 833 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 834 | if accelerometer_gyroscope_magnetometer and accelerometer_gyroscope_magnetometer.type != topo_pb.Topology.ACCELEROMETER_GYROSCOPE_MAGNETOMETER: |
| 835 | fail("Invalid accelerometer/gyroscope/magnetometer topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 836 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 837 | if fingerprint and fingerprint.type != topo_pb.Topology.FINGERPRINT: |
| 838 | fail("Invalid fingerprint topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 839 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 840 | if proximity_sensor and proximity_sensor.type != topo_pb.Topology.PROXIMITY_SENSOR: |
| 841 | fail("Invalid proximity sensor topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 842 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 843 | if daughter_board and daughter_board.type != topo_pb.Topology.DAUGHTER_BOARD: |
| 844 | fail("Invalid daughter board topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 845 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 846 | if non_volatile_storage and non_volatile_storage.type != topo_pb.Topology.NON_VOLATILE_STORAGE: |
| 847 | fail("Invalid non-volatile storage topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 848 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 849 | if wifi and wifi.type != topo_pb.Topology.WIFI: |
| 850 | fail("Invalid wifi topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 851 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 852 | if lte_board and lte_board.type != topo_pb.Topology.LTE_BOARD: |
| 853 | fail("Invalid lte board topology") |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 854 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 855 | if sd_reader and sd_reader.type != topo_pb.Topology.SD_READER: |
| 856 | fail("Invalid lte board topology") |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 857 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 858 | if motherboard_usb and motherboard_usb.type != topo_pb.Topology.MOTHERBOARD_USB: |
| 859 | fail("Invalid motherboard usb board topology") |
Jett Rink | 937839f | 2020-03-26 12:09:49 -0600 | [diff] [blame] | 860 | |
C Shapiro | a681fad | 2020-04-15 17:05:03 -0500 | [diff] [blame] | 861 | if bluetooth and bluetooth.type != topo_pb.Topology.BLUETOOTH: |
| 862 | fail("Invalid bluetooth topology") |
| 863 | |
Josie Nordrum | 206be1b | 2020-06-04 12:20:16 -0600 | [diff] [blame] | 864 | if barreljack and barreljack.type != topo_pb.Topology.BARRELJACK: |
| 865 | fail("Invalid barreljack topology") |
| 866 | |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 867 | if power_button and power_button.type != topo_pb.Topology.POWER_BUTTON: |
| 868 | fail("Invalid power button topology") |
| 869 | |
Andrew Lamb | 26e7202 | 2020-06-19 12:14:32 -0600 | [diff] [blame] | 870 | if volume_button and volume_button.type != topo_pb.Topology.POWER_BUTTON: |
| 871 | fail("Invalid volume button topology") |
| 872 | |
Sean McAllister | 17b4aa4 | 2020-10-15 19:54:24 +0000 | [diff] [blame] | 873 | if ec and ec.type != topo_pb.Topology.EC: |
| 874 | fail("Invalid ec type") |
| 875 | |
Zhuohao Lee | 8d9f1fb | 2021-02-01 21:35:07 +0800 | [diff] [blame] | 876 | if touch and touch.type != topo_pb.Topology.TOUCH: |
| 877 | fail("Invalid touch topology") |
| 878 | |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 879 | if tpm and tpm.type != topo_pb.Topology.TPM: |
| 880 | fail("Invalid tpm type") |
| 881 | |
Toni Barzic | f802a70 | 2021-05-18 19:40:23 -0700 | [diff] [blame] | 882 | if microphone_mute_switch and microphone_mute_switch.type != topo_pb.Topology.MICROPHONE_MUTE_SWITCH: |
| 883 | fail("Invalid microphone mute switch type") |
| 884 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 885 | return hw_topo_pb.HardwareTopology( |
| 886 | screen = screen, |
| 887 | form_factor = form_factor, |
| 888 | audio = audio, |
| 889 | stylus = stylus, |
| 890 | keyboard = keyboard, |
| 891 | thermal = thermal, |
| 892 | camera = camera, |
| 893 | accelerometer_gyroscope_magnetometer = accelerometer_gyroscope_magnetometer, |
| 894 | fingerprint = fingerprint, |
| 895 | proximity_sensor = proximity_sensor, |
| 896 | daughter_board = daughter_board, |
| 897 | non_volatile_storage = non_volatile_storage, |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 898 | wifi = wifi, |
| 899 | lte_board = lte_board, |
| 900 | sd_reader = sd_reader, |
| 901 | motherboard_usb = motherboard_usb, |
C Shapiro | a681fad | 2020-04-15 17:05:03 -0500 | [diff] [blame] | 902 | bluetooth = bluetooth, |
Josie Nordrum | 206be1b | 2020-06-04 12:20:16 -0600 | [diff] [blame] | 903 | barreljack = barreljack, |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 904 | power_button = power_button, |
Andrew Lamb | 26e7202 | 2020-06-19 12:14:32 -0600 | [diff] [blame] | 905 | volume_button = volume_button, |
Sean McAllister | 17b4aa4 | 2020-10-15 19:54:24 +0000 | [diff] [blame] | 906 | ec = ec, |
Zhuohao Lee | 8d9f1fb | 2021-02-01 21:35:07 +0800 | [diff] [blame] | 907 | touch = touch, |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 908 | tpm = tpm, |
Toni Barzic | f802a70 | 2021-05-18 19:40:23 -0700 | [diff] [blame] | 909 | microphone_mute_switch = microphone_mute_switch, |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 910 | ) |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 911 | |
| 912 | def _accumulate_presence(existing_present, new_present): |
Sean McAllister | 9eb2afe | 2020-10-19 15:18:23 +0000 | [diff] [blame] | 913 | if existing_present == _PRESENT.PRESENT: |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 914 | return existing_present |
Sean McAllister | 9eb2afe | 2020-10-19 15:18:23 +0000 | [diff] [blame] | 915 | elif new_present != _PRESENT.UNKNOWN: |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 916 | return new_present |
| 917 | else: |
| 918 | return existing_present |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 919 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 920 | def _accumulate_usbc(existing_usbc, new_usbc): |
| 921 | existing_usbc.count.value += new_usbc.count.value |
| 922 | |
| 923 | def _accumulate_usba(existing_usba, new_usba): |
| 924 | existing_usba.count.value += new_usba.count.value |
| 925 | |
| 926 | def _accumulate_lte(existing_lte, new_lte): |
| 927 | existing_lte.present = _accumulate_presence(existing_lte.present, new_lte.present) |
Vincent Palatin | 0ebdfd3 | 2021-04-23 15:54:43 +0200 | [diff] [blame] | 928 | if new_lte.present == _PRESENT.PRESENT: |
| 929 | existing_lte.model = new_lte.model |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 930 | |
| 931 | def _accumulate_hdmi(existing_hdmi, new_hdmi): |
| 932 | existing_hdmi.present = _accumulate_presence(existing_hdmi.present, new_hdmi.present) |
| 933 | |
Andrew Lamb | a921d78 | 2020-08-31 14:47:35 -0600 | [diff] [blame] | 934 | def _convert_to_hw_features(hardware_topology): |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 935 | """Converts a HardwareTopology proto to a HardwareFeatures proto.""" |
| 936 | result = topo_pb.HardwareFeatures() |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 937 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 938 | # Need to make deep-copy otherwise we change the has_ message serialization |
| 939 | copy = proto.from_textpb(hw_topo_pb.HardwareTopology, proto.to_textpb(hardware_topology)) |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 940 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 941 | # Handle all possible screen hardware features attributes |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 942 | _accumulate_fw_config(result.fw_config, copy.screen.hardware_feature.fw_config) |
| 943 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 944 | if copy.screen.hardware_feature.screen != topo_pb.HardwareFeatures.Screen(): |
| 945 | result.screen = copy.screen.hardware_feature.screen |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 946 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 947 | # Handle all possible form factor hardware features attributes |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 948 | _accumulate_fw_config(result.fw_config, copy.form_factor.hardware_feature.fw_config) |
| 949 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 950 | if copy.form_factor.hardware_feature.form_factor != topo_pb.HardwareFeatures.FormFactor(): |
| 951 | result.form_factor = copy.form_factor.hardware_feature.form_factor |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 952 | |
Jett Rink | cb41fb4 | 2020-04-10 16:32:17 -0600 | [diff] [blame] | 953 | # Handle all possible audio features attributes |
| 954 | _accumulate_fw_config(result.fw_config, copy.audio.hardware_feature.fw_config) |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 955 | |
Jett Rink | cb41fb4 | 2020-04-10 16:32:17 -0600 | [diff] [blame] | 956 | if copy.audio.hardware_feature.audio != topo_pb.HardwareFeatures.Audio(): |
| 957 | result.audio = copy.audio.hardware_feature.audio |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 958 | |
| 959 | # Handle all possible stylus hardware features attributes |
| 960 | _accumulate_fw_config(result.fw_config, copy.stylus.hardware_feature.fw_config) |
| 961 | |
| 962 | if copy.stylus.hardware_feature.stylus != topo_pb.HardwareFeatures.Stylus(): |
| 963 | result.stylus = copy.stylus.hardware_feature.stylus |
| 964 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 965 | # Handle all possible keyboard hardware features attributes |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 966 | _accumulate_fw_config(result.fw_config, copy.keyboard.hardware_feature.fw_config) |
| 967 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 968 | if copy.keyboard.hardware_feature.keyboard != topo_pb.HardwareFeatures.Keyboard(): |
| 969 | result.keyboard = copy.keyboard.hardware_feature.keyboard |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 970 | |
Jett Rink | cb41fb4 | 2020-04-10 16:32:17 -0600 | [diff] [blame] | 971 | # Handle all possible thermal features attributes |
| 972 | _accumulate_fw_config(result.fw_config, copy.thermal.hardware_feature.fw_config) |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 973 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 974 | # Handle all possible camera features attributes |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 975 | _accumulate_fw_config(result.fw_config, copy.camera.hardware_feature.fw_config) |
| 976 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 977 | if copy.camera.hardware_feature.camera != topo_pb.HardwareFeatures.Camera(): |
| 978 | result.camera = copy.camera.hardware_feature.camera |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 979 | |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 980 | # Handle all possible sensor attributes |
| 981 | _accumulate_fw_config(result.fw_config, copy.accelerometer_gyroscope_magnetometer.hardware_feature.fw_config) |
| 982 | |
| 983 | if copy.accelerometer_gyroscope_magnetometer.hardware_feature.accelerometer != topo_pb.HardwareFeatures.Accelerometer(): |
| 984 | result.accelerometer = copy.accelerometer_gyroscope_magnetometer.hardware_feature.accelerometer |
| 985 | |
| 986 | if copy.accelerometer_gyroscope_magnetometer.hardware_feature.gyroscope != topo_pb.HardwareFeatures.Gyroscope(): |
| 987 | result.gyroscope = copy.accelerometer_gyroscope_magnetometer.hardware_feature.gyroscope |
| 988 | |
| 989 | if copy.accelerometer_gyroscope_magnetometer.hardware_feature.magnetometer != topo_pb.HardwareFeatures.Magnetometer(): |
| 990 | result.magnetometer = copy.accelerometer_gyroscope_magnetometer.hardware_feature.magnetometer |
| 991 | |
Jett Rink | 4a7cd45 | 2020-04-10 15:46:05 -0600 | [diff] [blame] | 992 | if copy.accelerometer_gyroscope_magnetometer.hardware_feature.light_sensor != topo_pb.HardwareFeatures.LightSensor(): |
| 993 | result.light_sensor = copy.accelerometer_gyroscope_magnetometer.hardware_feature.light_sensor |
| 994 | |
Jett Rink | cb41fb4 | 2020-04-10 16:32:17 -0600 | [diff] [blame] | 995 | # Handle all possible fingerprint hardware features attributes |
| 996 | _accumulate_fw_config(result.fw_config, copy.fingerprint.hardware_feature.fw_config) |
| 997 | |
| 998 | if copy.fingerprint.hardware_feature.fingerprint != topo_pb.HardwareFeatures.Fingerprint(): |
| 999 | result.fingerprint = copy.fingerprint.hardware_feature.fingerprint |
| 1000 | |
| 1001 | # Handle all possible proximity sensor hardware features attributes |
| 1002 | _accumulate_fw_config(result.fw_config, copy.proximity_sensor.hardware_feature.fw_config) |
| 1003 | |
| 1004 | # Handle all possible daughter board hardware features attributes |
| 1005 | _accumulate_fw_config(result.fw_config, copy.daughter_board.hardware_feature.fw_config) |
| 1006 | |
| 1007 | if copy.daughter_board.hardware_feature.usb_c != topo_pb.HardwareFeatures.UsbC(): |
| 1008 | _accumulate_usbc(result.usb_c, copy.daughter_board.hardware_feature.usb_c) |
| 1009 | |
| 1010 | if copy.daughter_board.hardware_feature.usb_a != topo_pb.HardwareFeatures.UsbA(): |
| 1011 | _accumulate_usba(result.usb_a, copy.daughter_board.hardware_feature.usb_a) |
| 1012 | |
| 1013 | if copy.daughter_board.hardware_feature.lte != topo_pb.HardwareFeatures.Lte(): |
| 1014 | _accumulate_lte(result.lte, copy.daughter_board.hardware_feature.lte) |
| 1015 | |
| 1016 | if copy.daughter_board.hardware_feature.hdmi != topo_pb.HardwareFeatures.Hdmi(): |
| 1017 | _accumulate_hdmi(result.hdmi, copy.daughter_board.hardware_feature.hdmi) |
| 1018 | |
| 1019 | # Handle all possible non volatile storage hardware features attributes |
| 1020 | _accumulate_fw_config(result.fw_config, copy.non_volatile_storage.hardware_feature.fw_config) |
| 1021 | |
| 1022 | if copy.non_volatile_storage.hardware_feature.storage != topo_pb.HardwareFeatures.Storage(): |
| 1023 | result.storage = copy.non_volatile_storage.hardware_feature.storage |
| 1024 | |
Jett Rink | cb41fb4 | 2020-04-10 16:32:17 -0600 | [diff] [blame] | 1025 | # Handle all possible wifi hardware features attributes |
| 1026 | _accumulate_fw_config(result.fw_config, copy.wifi.hardware_feature.fw_config) |
| 1027 | |
| 1028 | # Handle all possible lte board attributes |
| 1029 | _accumulate_fw_config(result.fw_config, copy.lte_board.hardware_feature.fw_config) |
| 1030 | |
| 1031 | if copy.lte_board.hardware_feature.lte != topo_pb.HardwareFeatures.Lte(): |
Vincent Palatin | 0ebdfd3 | 2021-04-23 15:54:43 +0200 | [diff] [blame] | 1032 | _accumulate_lte(result.lte, copy.lte_board.hardware_feature.lte) |
Jett Rink | cb41fb4 | 2020-04-10 16:32:17 -0600 | [diff] [blame] | 1033 | |
| 1034 | # Handle all possible sd reader hardware features attributes |
| 1035 | _accumulate_fw_config(result.fw_config, copy.sd_reader.hardware_feature.fw_config) |
| 1036 | |
| 1037 | # Handle all possible motherboard usb features attributes |
| 1038 | _accumulate_fw_config(result.fw_config, copy.motherboard_usb.hardware_feature.fw_config) |
| 1039 | |
| 1040 | if copy.motherboard_usb.hardware_feature.usb_c != topo_pb.HardwareFeatures.UsbC(): |
| 1041 | _accumulate_usbc(result.usb_c, copy.motherboard_usb.hardware_feature.usb_c) |
| 1042 | |
| 1043 | if copy.motherboard_usb.hardware_feature.usb_a != topo_pb.HardwareFeatures.UsbA(): |
| 1044 | _accumulate_usba(result.usb_a, copy.motherboard_usb.hardware_feature.usb_a) |
| 1045 | |
C Shapiro | a681fad | 2020-04-15 17:05:03 -0500 | [diff] [blame] | 1046 | # Handle all possible bluetooth features attributes |
| 1047 | _accumulate_fw_config(result.fw_config, copy.bluetooth.hardware_feature.fw_config) |
| 1048 | |
| 1049 | if copy.bluetooth.hardware_feature.bluetooth != topo_pb.HardwareFeatures.Bluetooth(): |
| 1050 | result.bluetooth = copy.bluetooth.hardware_feature.bluetooth |
| 1051 | |
Josie Nordrum | 206be1b | 2020-06-04 12:20:16 -0600 | [diff] [blame] | 1052 | # Handle all possible barreljack features |
| 1053 | _accumulate_fw_config(result.fw_config, copy.barreljack.hardware_feature.fw_config) |
| 1054 | |
| 1055 | if copy.barreljack.hardware_feature.barreljack != topo_pb.HardwareFeatures.BarrelJack(): |
| 1056 | result.barreljack = copy.barreljack.hardware_feature.barreljack |
Andrew Lamb | 90b168c | 2020-06-22 10:42:30 -0600 | [diff] [blame] | 1057 | |
| 1058 | if copy.power_button.hardware_feature.power_button != topo_pb.HardwareFeatures.Button(): |
| 1059 | result.power_button = copy.power_button.hardware_feature.power_button |
| 1060 | |
| 1061 | if copy.volume_button.hardware_feature.volume_button != topo_pb.HardwareFeatures.Button(): |
| 1062 | result.volume_button = copy.volume_button.hardware_feature.volume_button |
| 1063 | |
Toni Barzic | f802a70 | 2021-05-18 19:40:23 -0700 | [diff] [blame] | 1064 | if copy.microphone_mute_switch.hardware_feature.microphone_mute_switch != topo_pb.HardwareFeatures.MicrophoneMuteSwitch(): |
| 1065 | result.microphone_mute_switch = copy.microphone_mute_switch.hardware_feature.microphone_mute_switch |
| 1066 | |
Zhuohao Lee | 8d9f1fb | 2021-02-01 21:35:07 +0800 | [diff] [blame] | 1067 | # Handle all possible touch hardware features |
| 1068 | _accumulate_fw_config(result.fw_config, copy.touch.hardware_feature.fw_config) |
| 1069 | |
Andrew Lamb | e04a1ae | 2020-04-07 17:37:30 -0600 | [diff] [blame] | 1070 | return result |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 1071 | |
C Shapiro | e4657e3 | 2020-01-24 13:32:11 -0600 | [diff] [blame] | 1072 | hw_topo = struct( |
C Shapiro | 436f321 | 2020-01-25 07:56:31 -0600 | [diff] [blame] | 1073 | create_design_features = _create_design_features, |
C Shapiro | e4657e3 | 2020-01-24 13:32:11 -0600 | [diff] [blame] | 1074 | create_features = _create_features, |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 1075 | create_screen = _create_screen, |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 1076 | create_form_factor = _create_form_factor, |
Jett Rink | f30986f | 2020-02-18 13:28:41 -0700 | [diff] [blame] | 1077 | create_audio = _create_audio, |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 1078 | create_stylus = _create_stylus, |
| 1079 | create_keyboard = _create_keyboard, |
| 1080 | create_thermal = _create_thermal, |
| 1081 | create_camera = _create_camera, |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 1082 | create_sensor = _create_sensor, |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 1083 | create_fingerprint = _create_fingerprint, |
| 1084 | create_proximity_sensor = _create_proximity_sensor, |
| 1085 | create_daughter_board = _create_daughter_board, |
| 1086 | create_non_volatile_storage = _create_non_volatile_storage, |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 1087 | create_wifi = _create_wifi, |
| 1088 | create_lte_board = _create_lte_board, |
| 1089 | create_sd_reader = _create_sd_reader, |
Jett Rink | 937839f | 2020-03-26 12:09:49 -0600 | [diff] [blame] | 1090 | create_motherboard_usb = _create_motherboard_usb, |
C Shapiro | a681fad | 2020-04-15 17:05:03 -0500 | [diff] [blame] | 1091 | create_bluetooth = _create_bluetooth, |
Josie Nordrum | 206be1b | 2020-06-04 12:20:16 -0600 | [diff] [blame] | 1092 | create_barreljack = _create_barreljack, |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 1093 | create_hardware_topology = _create_hardware_topology, |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 1094 | create_power_button = _create_power_button, |
Andrew Lamb | 26e7202 | 2020-06-19 12:14:32 -0600 | [diff] [blame] | 1095 | create_volume_button = _create_volume_button, |
Zhuohao Lee | 8d9f1fb | 2021-02-01 21:35:07 +0800 | [diff] [blame] | 1096 | create_touch = _create_touch, |
Toni Barzic | f802a70 | 2021-05-18 19:40:23 -0700 | [diff] [blame] | 1097 | create_microphone_mute_switch = _create_microphone_mute_switch, |
Jett Rink | 3e3ef61 | 2020-01-28 11:59:17 -0700 | [diff] [blame] | 1098 | convert_to_hw_features = _convert_to_hw_features, |
Ren-Pei Zeng | ce869dd | 2020-08-18 01:29:37 +0800 | [diff] [blame] | 1099 | make_camera_device = _make_camera_device, |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 1100 | make_fw_config = _make_fw_config, |
Sean McAllister | 9473537 | 2021-04-22 16:06:33 -0600 | [diff] [blame] | 1101 | ff = hw_feat.form_factor, |
YH Lin | 9e123f5 | 2021-04-13 19:52:18 -0700 | [diff] [blame] | 1102 | amplifier = _AMPLIFIER, |
Jett Rink | 2812452 | 2020-02-05 16:26:37 -0700 | [diff] [blame] | 1103 | audio_codec = _AUDIO_CODEC, |
Jett Rink | 82da31e | 2020-03-13 11:46:26 -0600 | [diff] [blame] | 1104 | fp_loc = _FP_LOC, |
Jett Rink | e27c705 | 2020-03-19 11:42:05 -0600 | [diff] [blame] | 1105 | storage = _STORAGE, |
Jett Rink | 0858d22 | 2020-03-19 11:27:54 -0600 | [diff] [blame] | 1106 | kb_type = _KB_TYPE, |
Jett Rink | 67f6086 | 2020-04-09 13:20:42 -0600 | [diff] [blame] | 1107 | stylus = _STYLUS, |
Andrew Lamb | f723e84 | 2020-06-19 10:12:19 -0600 | [diff] [blame] | 1108 | region = _REGION, |
| 1109 | edge = _EDGE, |
Ren-Pei Zeng | 0bf9635 | 2020-09-28 18:44:42 +0800 | [diff] [blame] | 1110 | camera_flags = _CAMERA_FLAGS, |
Sean McAllister | 9eb2afe | 2020-10-19 15:18:23 +0000 | [diff] [blame] | 1111 | present = _PRESENT, |
Sean McAllister | 4d7ecde | 2020-10-19 15:32:45 +0000 | [diff] [blame] | 1112 | |
| 1113 | # embedded controller exports |
| 1114 | ec_type = _EC_TYPE, |
| 1115 | create_ec = _create_ec, |
| 1116 | EC_NONE = _EC_NONE, |
| 1117 | EC_CHROME = _EC_CHROME, |
| 1118 | EC_WILCO = _EC_WILCO, |
Kevin Shelton | a1788ee | 2021-02-18 22:13:13 +0000 | [diff] [blame] | 1119 | |
| 1120 | # trusted platform module exports |
| 1121 | tpm_type = _TPM_TYPE, |
| 1122 | create_tpm = _create_tpm, |
| 1123 | TPM_THIRD_PARTY = _TPM_THIRD_PARTY, |
YH Lin | bf6fce2 | 2021-04-21 13:43:53 -0700 | [diff] [blame] | 1124 | TPM_GSC_H1B = _TPM_GSC_H1B, |
| 1125 | TPM_GSC_H1D = _TPM_GSC_H1D, |
C Shapiro | 436f321 | 2020-01-25 07:56:31 -0600 | [diff] [blame] | 1126 | ) |