Skip to content

Commit

Permalink
usb-c: Generate USB-C connector VIF policies XML file
Browse files Browse the repository at this point in the history
Generates XML file containing VIF policies by reading the device tree
using EDT.pickle generated during build
This script writes a subset of general and sink-pdo VIF policies in
output file
This script gets invoked during build if enabled through kconfig
The generated XML containing USB-C VIF policies could be used by
USB PD/Type-C analysers/testers to understand USB-C properties and
perform tests accordingly

Signed-off-by: Madhurima Paruchuri <[email protected]>
  • Loading branch information
madhurimaparuchuri authored and MaureenHelm committed Dec 2, 2022
1 parent bc31bad commit fa738b0
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,11 @@ if(CONFIG_BOOTLOADER_MCUBOOT)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/mcuboot.cmake)
endif()

# Generate USB-C VIF policies in XML format
if (CONFIG_BUILD_OUTPUT_VIF)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/vif.cmake)
endif()

get_property(extra_post_build_commands
GLOBAL PROPERTY
extra_post_build_commands
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ scripts/build/gen_image_info.py @tejlmand
/scripts/list_boards.py @mbolivar-nordic
/scripts/build/process_gperf.py @dcpleung @nashif
/scripts/build/gen_relocate_app.py @dcpleung
/scripts/generate_usb_vif/ @madhurimaparuchuri
/scripts/requirements*.txt @mbolivar-nordic @galak @nashif
/scripts/tests/twister/ @aasthagr
/scripts/tests/build/test_subfolder_list.py @rmstoi
Expand Down
22 changes: 22 additions & 0 deletions cmake/vif.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0

# Generates USB-C VIF policies in XML format from device tree.
set(gen_vif_script ${ZEPHYR_BASE}/scripts/generate_usb_vif/generate_vif.py)
set(dts_compatible usb-c-connector)
set(vif_xml ${PROJECT_BINARY_DIR}/vif.xml)
set(cmd_gen_vif ${PYTHON_EXECUTABLE} ${gen_vif_script}
--edt-pickle ${EDT_PICKLE}
--compatible ${dts_compatible}
--vif-out ${vif_xml}
--board ${BOARD}
)

add_custom_command(
OUTPUT ${vif_xml}
DEPENDS ${EDT_PICKLE}
COMMENT "Generating XML file at zephyr/vif.xml"
COMMAND ${cmd_gen_vif}
)

add_custom_target(gen_vif ALL DEPENDS ${vif_xml})
5 changes: 3 additions & 2 deletions samples/subsys/usb_c/sink/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Basic USB-C SINK
Overview
********

This example demonstrates how to create a USB-C Power Delivery application
using the USB-C subsystem. The application implements a USB-C Sink device.
This example demonstrates how to create a USB-C Power Delivery application and
how to generate USB VIF policies in XML format using the USB-C subsystem. The
application implements a USB-C Sink device.

After the USB-C Sink device is plugged into a Power Delivery charger, it
negotiates with the charger to provide 5V@100mA and displays all
Expand Down
1 change: 1 addition & 0 deletions samples/subsys/usb_c/sink/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ CONFIG_USBC_STACK=y
CONFIG_USBC_THREAD_PRIORITY=10
CONFIG_ADC=y
CONFIG_LOG=y
CONFIG_BUILD_OUTPUT_VIF=y
97 changes: 97 additions & 0 deletions scripts/generate_usb_vif/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python3

# Copyright (c) 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0

"""This file contains all constants defined to be used by all other scripts
in this folder i.e, generate_usb_vif"""

XML_ENCODING = "utf-8"
XML_ELEMENT_NAME_PREFIX = "vif"
XML_ROOT_ELEMENT_NAME = "VIF"
XML_NAMESPACE_ATTRIBUTES = {
"xmlns:opt": "http://compliance.usb.org/cv/VendorInfoFile/Schemas/Current/VendorInfoFileOptionalContent.xsd",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema",
"xmlns:vif": "http://compliance.usb.org/cv/VendorInfoFile/Schemas/Current/VendorInfoFile.xsd",
}

NAME = "name"
VALUE = "value"
TEXT = "text"
ATTRIBUTES = "attributes"
CHILD = "child"
COMPONENT = "Component"
TRUE = "true"
FALSE = "false"

SINK_PDOS = "sink-pdos"
SINK_PDO = "SnkPDO"
SINK_PDO_SUPPLY_TYPE = "Snk_PDO_Supply_Type"
SINK_PDO_VOLTAGE = "Snk_PDO_Voltage"
SINK_PDO_OP_CURRENT = "Snk_PDO_Op_Current"
SINK_PDO_MIN_VOLTAGE = "Snk_PDO_Min_Voltage"
SINK_PDO_MAX_VOLTAGE = "Snk_PDO_Max_Voltage"
SINK_PDO_OP_POWER = "Snk_PDO_Op_Power"
PD_POWER_AS_SINK = "PD_Power_As_Sink"
NUM_SINK_PDOS = "Num_Snk_PDOs"
MODEL_PART_NUMBER = "Model_Part_Number"
EPR_SUPPORTED_AS_SINK = "EPR_Supported_As_Snk"
NO_USB_SUSPEND_MAY_BE_SET = "No_USB_Suspend_May_Be_Set"
HIGHER_CAPABILITY_SET = "Higher_Capability_Set"
FR_SWAP_REQD_TYPE_C_CURRENT_AS_INITIAL_SOURCE = "FR_Swap_Reqd_Type_C_Current_As_Initial_Source"

VIF_SPEC_ELEMENTS = {
"VIF_Specification": {
TEXT: "3.19",
},
"VIF_App": {
CHILD: {
"Vendor": {
TEXT: "USB-IF",
},
"Name": {
TEXT: "VIF Editor",
},
"Version": {
TEXT: "3.2.4.0",
}
}
},
"VIF_Product_Type": {
TEXT: "Port Product",
ATTRIBUTES: {
"value": "0",
},
},
"Certification_Type": {
TEXT: "End Product",
ATTRIBUTES: {
"value": "0",
},
}
}

VIF_ELEMENTS = ["VIF_Specification", "VIF_App", "Vendor", "Name", "Version",
"Vendor_Name", "VIF_Product_Type", "Certification_Type",
MODEL_PART_NUMBER, COMPONENT, SINK_PDOS, SINK_PDO,
SINK_PDO_SUPPLY_TYPE, SINK_PDO_VOLTAGE, SINK_PDO_OP_CURRENT,
SINK_PDO_MIN_VOLTAGE, SINK_PDO_MAX_VOLTAGE, SINK_PDO_OP_POWER,
PD_POWER_AS_SINK, PD_POWER_AS_SINK, NUM_SINK_PDOS,
EPR_SUPPORTED_AS_SINK, NO_USB_SUSPEND_MAY_BE_SET,
HIGHER_CAPABILITY_SET, ]

DT_VIF_ELEMENTS = {
SINK_PDOS: "SnkPdoList",
}

PDO_TYPE_FIXED = 0
PDO_TYPE_BATTERY = 1
PDO_TYPE_VARIABLE = 2
PDO_TYPE_AUGUMENTED = 3

PDO_TYPES = {
PDO_TYPE_FIXED: "Fixed",
PDO_TYPE_BATTERY: "Battery",
PDO_TYPE_VARIABLE: "Variable",
PDO_TYPE_AUGUMENTED: "Augmented",
}
Loading

0 comments on commit fa738b0

Please sign in to comment.