• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Functions related to components.
2
3See proto definitions for descriptions of arguments.
4"""
5
6# Needed to load from @proto. Add @unused to silence lint.
7load("//config/util/bindings/proto.star", "protos")
8load(
9    "@proto//chromiumos/config/api/component.proto",
10    comp_pb = "chromiumos.config.api",
11)
12load(
13    "@proto//chromiumos/config/api/component_id.proto",
14    comp_id_pb = "chromiumos.config.api",
15)
16
17def _create_usb(vendor_id, product_id, bcd_device):
18    """Builds a Interface.Usb proto."""
19    usb = comp_pb.Component.Interface.Usb(
20        vendor_id = vendor_id,
21        product_id = product_id,
22        bcd_device = bcd_device,
23    )
24    component_id = comp_id_pb.ComponentId(
25        value = ":".join([vendor_id, product_id, bcd_device]),
26    )
27    return component_id, usb
28
29def _create_pci(vendor_id, device_id, revision_id):
30    """Builds a Interface.Pci proto."""
31    pci = comp_pb.Component.Interface.Pci(
32        vendor_id = vendor_id,
33        device_id = device_id,
34        revision_id = revision_id,
35    )
36
37    component_id = comp_id_pb.ComponentId(
38        value = ":".join([vendor_id, device_id, revision_id]),
39    )
40    return component_id, pci
41
42def _create_display_panel(
43        display_vendor,
44        product_id,
45        product_name = None,
46        inches = None,
47        width_px = None,
48        height_px = None,
49        pixels_per_in = None):
50    """Builds a Component.DisplayPanel proto for touchscreen."""
51    vendor_code = display_vendor.display_panel_vendor.vendor_code
52    id = comp_id_pb.ComponentId(value = "_".join([vendor_code, product_id]))
53    return comp_pb.Component(
54        id = id,
55        name = product_name or product_id,
56        manufacturer_id = display_vendor.id,
57        display_panel = comp_pb.Component.DisplayPanel(
58            product_id = product_id,
59            properties = comp_pb.Component.DisplayPanel.Properties(
60                diagonal_milliinch = inches * 1000,
61                width_px = width_px,
62                height_px = height_px,
63                pixels_per_in = pixels_per_in,
64            ),
65        ),
66    )
67
68def _create_rounded_corners(
69        top_left,
70        top_right = None,
71        bottom_left = None,
72        bottom_right = None):
73    """Creates a Component.DisplayPanel.Properties.RoundedCorners."""
74    if top_right == None:
75        top_right = top_left
76    if bottom_left == None:
77        bottom_left = top_left
78    if bottom_right == None:
79        bottom_right = bottom_left
80    return comp_pb.Component.DisplayPanel.Properties.RoundedCorners(
81        top_left = comp_pb.Component.DisplayPanel.Properties.RoundedCorners.RoundedCorner(radius_px = top_left),
82        top_right = comp_pb.Component.DisplayPanel.Properties.RoundedCorners.RoundedCorner(radius_px = top_right),
83        bottom_left = comp_pb.Component.DisplayPanel.Properties.RoundedCorners.RoundedCorner(radius_px = bottom_left),
84        bottom_right = comp_pb.Component.DisplayPanel.Properties.RoundedCorners.RoundedCorner(radius_px = bottom_right),
85    )
86
87def _create_touch(
88        product_id,
89        fw_version,
90        product_series = None):
91    """Builds a Component.Touch proto."""
92    return comp_pb.Component.Touch(
93        product_id = product_id,
94        fw_version = fw_version,
95        product_series = product_series,
96    )
97
98def _create_touch_id(
99        touch_vendor,
100        product_id,
101        fw_version):
102    return comp_id_pb.ComponentId(
103        value = "_".join([touch_vendor.name, product_id, fw_version]),
104    )
105
106def _create_touchscreen(
107        touch_vendor,
108        product_id,
109        fw_version,
110        product_name = None,
111        product_series = None):
112    """Builds a Component.Touch proto for touchscreen."""
113    id = _create_touch_id(touch_vendor, product_id, fw_version)
114    touchscreen = _create_touch(
115        product_id,
116        fw_version,
117        product_series,
118    )
119    return comp_pb.Component(
120        id = id,
121        name = product_name,
122        manufacturer_id = touch_vendor.id,
123        touchscreen = touchscreen,
124    )
125
126def _create_touchpad(
127        touch_vendor,
128        product_id,
129        fw_version,
130        product_name = None,
131        product_series = None):
132    """Builds a Component.Touch proto for touchpad."""
133    id = _create_touch_id(touch_vendor, product_id, fw_version)
134    touchpad = _create_touch(
135        product_id,
136        fw_version,
137        product_series,
138    )
139    return comp_pb.Component(
140        id = id,
141        name = product_name,
142        manufacturer_id = touch_vendor.id,
143        touchpad = touchpad,
144    )
145
146def _create_soc_family(name, arch = comp_pb.Component.Soc.X86_64):
147    """Builds a Component.Soc.Family proto."""
148    return comp_pb.Component.Soc.Family(
149        arch = arch,
150        name = name,
151    )
152
153def _create_soc_model(family, model, cores, id):
154    """Builds a Component proto for an Soc."""
155    id_value = comp_id_pb.ComponentId(value = id)
156    soc = comp_pb.Component.Soc(
157        family = family,
158        model = model,
159        cores = cores,
160    )
161    return comp_pb.Component(id = id_value, soc = soc)
162
163def _create_bt(vendor_id, product_id, bcd_device):
164    """Builds a Component proto for Bluetooth."""
165    component_id, usb = _create_usb(
166        vendor_id = vendor_id,
167        product_id = product_id,
168        bcd_device = bcd_device,
169    )
170    return comp_pb.Component(
171        id = component_id,
172        bluetooth = comp_pb.Component.Bluetooth(usb = usb),
173    )
174
175def _create_cellular(vendor_id, product_id, bcd_device):
176    """Builds a Component proto for Cellular device."""
177    component_id, usb = _create_usb(
178        vendor_id = vendor_id,
179        product_id = product_id,
180        bcd_device = bcd_device,
181    )
182    return comp_pb.Component(
183        id = component_id,
184        cellular = comp_pb.Component.Cellular(usb = usb),
185    )
186
187def _create_wifi(vendor_id, device_id, revision_id):
188    """Builds a Component proto for Wifi."""
189    component_id, pci = _create_pci(
190        vendor_id = vendor_id,
191        device_id = device_id,
192        revision_id = revision_id,
193    )
194    return comp_pb.Component(
195        id = component_id,
196        wifi = comp_pb.Component.Wifi(pci = pci),
197    )
198
199_qual_status = struct(
200    REQUESTED = comp_pb.Component.Qualification.REQUESTED,
201    TECHNICALLY_QUALIFIED = comp_pb.Component.Qualification.TECHNICALLY_QUALIFIED,
202    QUALIFIED = comp_pb.Component.Qualification.QUALIFIED,
203)
204
205def _create_qual(component_id, status = _qual_status.REQUESTED):
206    """Builds a Component.Qualification proto."""
207    return comp_pb.Component.Qualification(
208        component_id = component_id,
209        status = status,
210    )
211
212def _create_quals(component_ids, status = _qual_status.REQUESTED):
213    """Builds a Component.Qualification proto for each of component_ids."""
214    return [_create_qual(id, status) for id in component_ids]
215
216def _create_amplifier(name):
217    """Builds a Component.Amplifier proto."""
218    return comp_pb.Component.Amplifier(
219        name = name,
220    )
221
222def _create_audio_codec(name):
223    """Builds a Component.AudioCodec proto."""
224    return comp_pb.Component.AudioCodec(
225        name = name,
226    )
227
228_BATTERY_TECHNOLOGY = struct(
229    TECH_UNKNOWN = comp_pb.Component.Battery.TECH_UNKNOWN,
230    LI_ION = comp_pb.Component.Battery.LI_ION,
231)
232
233def _create_battery(model, technology):
234    return comp_pb.Component(
235        battery = comp_pb.Component.Battery(
236            model = model,
237            technology = technology,
238        ),
239    )
240
241def _create_flash_chip(part_number):
242    """Build a Component.FlashChip proto."""
243    return comp_pb.Component.FlashChip(
244        part_number = part_number,
245    )
246
247def _create_embedded_controller(part_number):
248    """Build a Component.EmbeddedController proto."""
249    return comp_pb.Component.EmbeddedController(
250        part_number = part_number,
251    )
252
253def _create_storage_mmc(emmc5_fw_ver, manfid, name, oemid, prv, sectors):
254    """Build a Component.Storage proto for an MMC device."""
255    return comp_pb.Component.Storage(
256        emmc5_fw_ver = emmc5_fw_ver,
257        manfid = manfid,
258        name = name,
259        oemid = oemid,
260        prv = prv,
261        sectors = sectors,
262        type = comp_pb.Component.Storage.EMMC,
263    )
264
265def _create_tpm(manufacturer_info, version):
266    """Build a Component.Tpm proto."""
267    return comp_pb.Component.Tpm(
268        manufacturer_info = manufacturer_info,
269        version = version,
270    )
271
272def _append_display_panel(
273        component_list,
274        vendor_list,
275        display_vendor,
276        product_id,
277        product_name = None,
278        inches = None,
279        width_px = None,
280        height_px = None,
281        pixels_per_in = None):
282    if not display_vendor in vendor_list:
283        vendor_list.append(display_vendor)
284    component_list.append(
285        _create_display_panel(
286            display_vendor = display_vendor,
287            product_id = product_id,
288            product_name = product_name,
289            inches = inches,
290            width_px = width_px,
291            height_px = height_px,
292            pixels_per_in = pixels_per_in,
293        ),
294    )
295
296def _append_touchpad(
297        component_list,
298        vendor_list,
299        touch_vendor,
300        product_id,
301        fw_version,
302        product_name = None,
303        product_series = None):
304    if not touch_vendor in vendor_list:
305        vendor_list.append(touch_vendor)
306    component_list.append(
307        _create_touchpad(
308            touch_vendor = touch_vendor,
309            product_id = product_id,
310            fw_version = fw_version,
311            product_name = product_name,
312            product_series = product_series,
313        ),
314    )
315
316def _append_touchscreen(
317        component_list,
318        vendor_list,
319        touch_vendor,
320        product_id,
321        fw_version,
322        product_name = None,
323        product_series = None):
324    if not touch_vendor in vendor_list:
325        vendor_list.append(touch_vendor)
326    component_list.append(
327        _create_touchscreen(
328            touch_vendor = touch_vendor,
329            product_id = product_id,
330            fw_version = fw_version,
331            product_name = product_name,
332            product_series = product_series,
333        ),
334    )
335
336def _append_battery(
337        component_list,
338        vendor_list,
339        battery_vendor,
340        model,
341        technology = _BATTERY_TECHNOLOGY.LI_ION):
342    if not battery_vendor in vendor_list:
343        vendor_list.append(battery_vendor)
344    component_list.append(
345        _create_battery(
346            model = model,
347            technology = technology,
348        ),
349    )
350
351comp = struct(
352    create_soc_family = _create_soc_family,
353    create_soc_model = _create_soc_model,
354    create_bt = _create_bt,
355    create_cellular = _create_cellular,
356    create_display_panel = _create_display_panel,
357    create_rounded_corners = _create_rounded_corners,
358    create_touchscreen = _create_touchscreen,
359    create_touchpad = _create_touchpad,
360    create_wifi = _create_wifi,
361    create_qual = _create_qual,
362    create_quals = _create_quals,
363    create_amplifier = _create_amplifier,
364    create_audio_codec = _create_audio_codec,
365    create_battery = _create_battery,
366    create_ec_flash_chip = _create_flash_chip,
367    create_flash_chip = _create_flash_chip,
368    create_embedded_controller = _create_embedded_controller,
369    create_storage_mmc = _create_storage_mmc,
370    create_tpm = _create_tpm,
371    qual_status = _qual_status,
372    create_usb = _create_usb,
373    create_pci = _create_pci,
374    append_battery = _append_battery,
375    append_display_panel = _append_display_panel,
376    append_touchpad = _append_touchpad,
377    append_touchscreen = _append_touchscreen,
378    battery_technology = _BATTERY_TECHNOLOGY,
379)
380