《USB Type-C and You.pdf》由會員分享,可在線閱讀,更多相關《USB Type-C and You.pdf(45頁珍藏版)》請在三個皮匠報告上搜索。
1、#EMBEDDEDOSSUMMITUSB Type-C and YouTurning your product concept into implementation necessitiesSam Hurst,GoogleGithub ID:sambhurstDiana Zigterman,GoogleGithub ID:DianaZigPort Role RecapSpecification RequirementsCreating a New Sink DeviceContents#EMBEDDEDOSSUMMITPort Role RecapFor more details,see la
2、st years USB-C Power Delivery OverviewPort Role RecapPower RoleData RoleVconn RoleSourceSupplies powerDFPActs as USB Host or Hub Downstream PortControls alternate mode entrySourceSupplies Vconn to the Electronically Marked CableCommunicates with the Electronically Marked CableSinkConsumes powerUFPAc
3、ts as USB DeviceOffMay not communicate with the cable#EMBEDDEDOSSUMMITSpecification RequirementsUSB Type-C Specificationhttps:/usb.org/document-library/usb-type-cr-cable-and-connector-specification-release-22 Goto spec for valid voltage ranges,connect and disconnect timings,TBT alternate mode specif
4、icsUSB Power Delivery Specificationhttps:/usb.org/document-library/usb-power-deliveryGoto spec for minimum PD requirements and features to exploreUSB Compliance specifications also available on usb.orgAccessing the SpecificationsWhat do you want to connect to?Think through all the things your custom
5、er might think they can plug inRoles:Which of these USB Type-C states apply to me?Accessory modes?Debug accessoryGenerally only useful if your product has a specific debug accessory you use with itAudio accessoryRarely used in industryTry states?Primarily useful if you or your partner doesnt support
6、 Power DeliveryDefinite“yes”if your port can function as both a host and deviceRoles:Am I“Dual Role Data”?Also required if you will be using PD DR_Swap messagesBecause youd like to use a non-default role combination(sink/DFP)Or because youre dual-role power with a preferred data roleNote for DR swap
7、s:the partner may reply with a RejectPower source ports can reference the USB Type-C SpecNot required if device sources=3A and have no USB 3 supportRequired Vconn power level ranges from 100 mW to 1.5 WRoles:Do I have to source Vconn?Sink ports primarily require Vconn sourcing if they need to probe
8、the cableCan I turn Vconn off?Yes,if:Cable e-marker reports it doesnt need VconnNo Ra is detectedCable e-marker doesnt reply to Discover Identity VDMsNote:your port is still considered“Vconn source”for purposes of Vconn swaps even if Vconn is turned offIf youre content with default USB Type-C roles
9、and have no need for more than 15 W sourcing or sinking,then possibly notDo I need Power Delivery support?But you do want PD if you need:More powerNon-default role combinationsAlternate modesPower button transmissionReference the“Message Applicability”section of the PD SpecificationWhich PD messages
10、 do I have to support?#EMBEDDEDOSSUMMITUSB Type-C Sink Device Application1.Create a Devicetree usb-c-connector node2.Create an application specific data structure3.Define a few policy callbacksThree Steps to create a USB Type-C Device#EMBEDDEDOSSUMMITUSB Type-C Devicetree nodeZephyrs USB Type-C Port
11、 perspectiveDevicetree USB Type-C Sink Port descriptionport1:usbc-port1 compatible=usb-c-connector;tcpc=;vbus=;power-role=sink;sink-pdos=;Devicetree USB Type-C Sink Port descriptionport1:usbc-port1 compatible=usb-c-connector;tcpc=;vbus=;power-role=sink;sink-pdos=;Type-C Port Controller(TCPC)Driver p
12、ort1:usbc-port1 compatible=usb-c-connector;tcpc=;vbus=;power-role=sink;sink-pdos=;VBUS Driverport1:usbc-port1 compatible=usb-c-connector;tcpc=;vbus=;power-role=sink;sink-pdos=;#EMBEDDEDOSSUMMITApplication specific data structureCheck if Power Role is supportedport1:usbc-port1 compatible=usb-c-connec
13、tor;reg=;tcpc=;vbus=;power-role=sink;sink-pdos=;#define PORT1_NODE DT_NODELABEL(port1)#define PORT1_POWER_ROLE DT_ENUM_IDX(DT_NODELABEL(port1),power_role)#if(PORT1_POWER_ROLE!=TC_ROLE_SINK)#error Unsupported board:Only Sink device supported#endifApplication Data Structure(Extract Sink PDOs)port1:usb
14、c-port1 compatible=usb-c-connector;reg=;tcpc=;vbus=;power-role=sink;sink-pdos=;static struct port1_data_t uint32_t snk_capsDT_PROP_LEN(DT_NODELABEL(port1),sink_pdos);int snk_cap_cnt;port1_data=.snk_caps=DT_FOREACH_PROP_ELEM(DT_NODELABEL(port1),sink_pdos,SINK_PDO),.snk_cap_cnt=DT_PROP_LEN(DT_NODELABE
15、L(port1),sink_pdos),;Application Data Structure(Additional members)static struct port1_data_t .uint32_t src_capsPDO_MAX_DATA_OBJECTS;int src_cap_cnt;atomic_t ps_ready;port1_data=.src_caps=0,.src_cap_cnt=0,.ps_ready=0;#EMBEDDEDOSSUMMITPolicy CallbacksMinimum Sink Policy Callbacksint(*policy_cb_get_sn
16、k_cap_t)(const struct device*dev,uint32_t*pdos,int*num_pdos);void(*policy_cb_set_src_cap_t)(const struct device*dev,const uint32_t*pdos,const int num_pdos);uint32_t(*policy_cb_get_rdo_t)(const struct device*dev);bool(*policy_cb_check_t)(const struct device*dev,const enum usbc_policy_check_t policy_c
17、heck);void(*policy_cb_notify_t)(const struct device*dev,const enum usbc_policy_notify_t policy_notify);Power Delivery Negotiation(Step 1)policy_cb_set_src_cap_tThe Zephyr USB Type-C PD Subsystem uses this callback to send the received Source capabilities to the application.For this application,the f
18、ollowing would be set:port1_data.src_capsport1_data.src_cap_cntstatic struct port1_data_t .uint32_t src_capsPDO_MAX_DATA_OBJECTS;int src_cap_cnt;atomic_t ps_ready;port1_data=.src_caps=0,.src_cap_cnt=0,.ps_ready=0;Sample Source Capabilities Could include:PDO1:5V(ALWAYS 5V)PDO2:12PDO3:20Power Delivery
19、 Negotiation(Step 2)policy_cb_get_rdo_tAfter the Source PDOs are stored,the application must select one of them and build an RDO to return to the stack.Zephyr uses this callback to get that RDO.union pd_rdo rdo;/*Maximum operating current 100mA*/rdo.fixed.min_or_max_operating_current=PD_CONVERT_MA_T
20、O_FIXED_PDO_CURRENT(100);/*Operating current 100mA*/rdo.fixed.operating_current=PD_CONVERT_MA_TO_FIXED_PDO_CURRENT(100);/*Object position 1(5V PDO)*/rdo.fixed.object_pos=1;return rdo.raw_value;Power Delivery Negotiation(Step 3)policy_cb_notify_tAs the Zephyr USB Type-C subsystem executes,it notifies
21、 the application certain changes occur.And thats what this callback is used for.In the following,the application is notified that an Accept message was received.case MSG_ACCEPT_RECEIVED:LOG_INF(Source accepted the request);break;case TRANSITION_PS:atomic_set_bit(&dpm_data-ps_ready,0);break;case NOT_
22、PD_CONNECTED:break;case POWER_CHANGE_0A0:LOG_INF(PWR 0A);break;case POWER_CHANGE_DEF:LOG_INF(PWR DEF);break;Power Delivery Negotiation(Step 4)policy_cb_notify_tAs the Zephyr USB Type-C subsytem executes,it notifies the application certain changes occur.And thats what this callback is used for.In the
23、 following,the application is notified that an PS_RDY message was received.case MSG_ACCEPT_RECEIVED:LOG_INF(Source accepted the request);break;case TRANSITION_PS:atomic_set_bit(&dpm_data-ps_ready,0);break;case NOT_PD_CONNECTED:break;case POWER_CHANGE_0A0:LOG_INF(PWR 0A);break;case POWER_CHANGE_DEF:L
24、OG_INF(PWR DEF);break;Get Sink Capabilitiespolicy_cb_get_snk_cap_tThe Zephyr USB Type-C PD Stack uses this callback to get the Sink PDOs and their count.For this application,the following is returned:port1_data.snk_capsport1_data.snk_cap_cntstatic struct port1_data_t uint32_t snk_capsDT_PROP_LEN(DT_
25、NODELABEL(port1),sink_pdos);int snk_cap_cnt;port1_data=.snk_caps=DT_FOREACH_PROP_ELEM(DT_NODELABEL(port1),sink_pdos,SINK_PDO),.snk_cap_cnt=DT_PROP_LEN(DT_NODELABEL(port1),sink_pdos),;Power Role Swap to Sourcepolicy_cb_check_tAs the Zephyr USB Type-C stack executes,it needs to check with application
26、before taken certain actions.And thats what this callback is used for.switch(policy_check)case CHECK_POWER_ROLE_SWAP:/*Reject power role swaps*/return false;case CHECK_DATA_ROLE_SWAP_TO_DFP:/*Reject data role swap to DFP*/return false;case CHECK_DATA_ROLE_SWAP_TO_UFP:/*Accept data role swap to UFP*/
27、return true;case CHECK_SNK_AT_DEFAULT_LEVEL:/*The device is at the default power level*/return true;default:/*Reject all other policy checks*/return false;Register the callbacks with the following APIusbc_set_policy_cb_set_src_capusbc_set_policy_cb_get_rdousbc_set_policy_cb_get_snk_capusbc_set_polic
28、y_cb_notifyusbc_set_policy_cb_checkRegister the Applications data structureusbc_set_dpm_dataAfter registration,the Applications data structure can be retrieved with the following:usbc_get_dpm_dataStart the Zephyr USB Type-C stackusbc_startZephyr USB Type-C SamplesSample Sink:zephyr/samples/subsys/sinkSample Source:zephyr/samples/subsys/sourceZephyr USB Type-C BoardsB-G747E-DPOW11(Sink ONLY)STM32G081B-EVAL(Source and Sink)See Zephyr Supported Boards For details:https:/docs.zephyrproject.org/latest/boards/index.html#EMBEDDEDOSSUMMITThank you!