📄 usbs-enum.html
字号:
<TTCLASS="STRUCTFIELD"><I>type</I></TT> fields are determined by the standard.The <TTCLASS="STRUCTFIELD"><I>total_length</I></TT> field depends on thenumber of interfaces and endpoints used by this configuration, andconvenience macros are provided to calculate this: the first argumentto the macros specify the number of interfaces, the second the numberof endpoints. The <TTCLASS="STRUCTFIELD"><I>number_interfaces</I></TT> fieldis self-explanatory. If the peripheral involves multipleconfigurations then each one must have a unique id, and this will beused in the set-configuration control message. The id<TTCLASS="LITERAL">0</TT> is reserved, and a set-configuration controlmessage that uses this id indicates that the peripheral should beinactive. Configurations can have a string description if required.The <TTCLASS="STRUCTFIELD"><I>attributes</I></TT> field must have the<TTCLASS="LITERAL">REQUIRED</TT> bit set; the<TTCLASS="LITERAL">SELF_POWERED</TT> bit informs the host that theperipheral has its own power supply and will not draw any power overthe bus, leaving more bus power available to other peripherals; the<TTCLASS="LITERAL">REMOTE_WAKEUP</TT> bit is used if the peripheral caninterrupt the host when the latter is in power-saving mode. Forperipherals that are not self-powered, the<TTCLASS="STRUCTFIELD"><I>max_power</I></TT> field specifies the powerrequirements in units of 2mA.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16164"></A><H3><SPANCLASS="STRUCTNAME">usb_interface_descriptor</SPAN></H3><P>A USB configuration involves one or more interfaces, typicallycorresponding to different streams of data. For example, one interfacemight involve video data while another interface is for audio.Multiple interfaces in a single configuration will be active at thesame time.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">const usb_interface_descriptor usb_interface = { length: USB_INTERFACE_DESCRIPTOR_LENGTH, type: USB_INTERFACE_DESCRIPTOR_TYPE, interface_id: 0, alternate_setting: 0, number_endpoints: 2, interface_class: USB_INTERFACE_DESCRIPTOR_CLASS_VENDOR, interface_subclass: USB_INTERFACE_DESCRIPTOR_SUBCLASS_VENDOR, interface_protocol: USB_INTERFACE_DESCRIPTOR_PROTOCOL_VENDOR, interface_str: 0};const usbs_enumeration_data usb_enum_data = { … total_number_interfaces: 1, interfaces: &usb_interface, …};</PRE></TD></TR></TABLE><P>Again, the <TTCLASS="STRUCTFIELD"><I>length</I></TT> and<TTCLASS="STRUCTFIELD"><I>type</I></TT> fields are specified by the standard.Each interface within a configuration requires its own id. However, agiven interface may have several alternate settings, in other wordsentries in the interfaces array with the same id but different<TTCLASS="STRUCTFIELD"><I>alternate_setting</I></TT> fields. For example,there might be one setting which requires a bandwidth of 100K/s andanother setting that only needs 50K/s. The host can use the standardset-interface control message to choose the most appropriate setting.The handling of this request is the responsibility of higher-levelcode, so the application may have to <AHREF="usbs-control.html#AEN16582">install</A> its own handler.</P><P>The number of endpoints used by an interface is specified in the<TTCLASS="STRUCTFIELD"><I>number_endpoints</I></TT> field. Exact details ofwhich endpoints are used is held in a separate array of endpointdescriptors. The class, subclass and protocol fields are used byhost-side code to determine which host-side device driver shouldhandle this specific interface. Usually this is determined on aper-peripheral basis in the<SPANCLASS="STRUCTNAME">usb_device_descriptor</SPAN> structure, but that candefer the details to individual interfaces. A per-interface stringis allowed as well.</P><P>For USB peripherals involving multiple configurations, the array of<SPANCLASS="STRUCTNAME">usb_interface_descriptor</SPAN> structures shouldfirst contain all the interfaces for the first configuration, then allthe interfaces for the second configuration, and so on.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16179"></A><H3><SPANCLASS="STRUCTNAME">usb_endpoint_descriptor</SPAN></H3><P>The host also needs information about which endpoint should be usedfor what. This involves an array of endpoint descriptors:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">const usb_endpoint_descriptor usb_endpoints[] = { { length: USB_ENDPOINT_DESCRIPTOR_LENGTH, type: USB_ENDPOINT_DESCRIPTOR_TYPE, endpoint: USB_ENDPOINT_DESCRIPTOR_ENDPOINT_OUT | 1, attributes: USB_ENDPOINT_DESCRIPTOR_ATTR_BULK, max_packet_lo: 64, max_packet_hi: 0, interval: 0 }, { length: USB_ENDPOINT_DESCRIPTOR_LENGTH, type: USB_ENDPOINT_DESCRIPTOR_TYPE, endpoint: USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN | 2, attributes: USB_ENDPOINT_DESCRIPTOR_ATTR_BULK, max_packet_lo: 64, max_packet_hi: 0, interval: 0 }};const usbs_enumeration_data usb_enum_data = { … total_number_endpoints: 2, endpoints: usb_endpoints, …};</PRE></TD></TR></TABLE><P>As usual the values for the <TTCLASS="STRUCTFIELD"><I>length</I></TT> and<TTCLASS="STRUCTFIELD"><I>type</I></TT> fields are specified by the standard.The <TTCLASS="STRUCTFIELD"><I>endpoint</I></TT> field gives both the endpointnumber and the direction, so in the above example endpoint 1 is usedfor OUT (host to peripheral) transfers and endpoint 2 is used for IN(peripheral to host) transfers. The<TTCLASS="STRUCTFIELD"><I>attributes</I></TT> field indicates the USB protocolthat should be used on this endpoint: <TTCLASS="LITERAL">CONTROL</TT>,<TTCLASS="LITERAL">ISOCHRONOUS</TT>, <TTCLASS="LITERAL">BULK</TT> or<TTCLASS="LITERAL">INTERRUPT</TT>. The<TTCLASS="STRUCTFIELD"><I>max_packet</I></TT> field specifies the maximum sizeof a single USB packet. For bulk transfers this will typically be 64bytes. For isochronous transfers this can be up to 1023 bytes. Forinterrupt transfers it can be up to 64 bytes, although usually asmaller value will be used. The <TTCLASS="STRUCTFIELD"><I>interval</I></TT>field is ignored for control and bulk transfers. For isochronoustransfers it should be set to 1. For interrupt transfers it can be avalue between 1 and 255, and indicates the number of millisecondsbetween successive polling operations.</P><P>For USB peripherals involving multiple configurations or interfacesthe array of endpoint descriptors should be organized sequentially:first the endpoints corresponding to the first interface of the firstconfiguration, then the second interface in that configuration, and soon; then all the endpoints for all the interfaces in the secondconfiguration; etc.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16196"></A><H3>Strings</H3><P>The enumeration data can contain a number of strings with additionalinformation. Unicode encoding is used for the strings, and it ispossible for a peripheral to supply a given string in multiplelanguages using the appropriate characters. The first two bytes ofeach string give a length and type field. The first string is special;after the two bytes header it consists of an array of 2-byte languageid codes, indicating the supported languages. The language code0x0409 corresponds to English (United States). </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">const unsigned char* usb_strings[] = { "\004\003\011\004", "\020\003R\000e\000d\000 \000H\000a\000t\000"};const usbs_enumeration_data usb_enum_data = { … total_number_strings: 2, strings: usb_strings, …};</PRE></TD></TR></TABLE><P>The default handler for standard control messages assumes that theperipheral only uses a single language. If this is not the case thenhigher-level code will have to handle the standard get-descriptorcontrol messages when a string descriptor is requested.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16201"></A><H3><SPANCLASS="STRUCTNAME">usbs_enumeration_data</SPAN></H3><P>The <SPANCLASS="STRUCTNAME">usbs_enumeration_data</SPAN> data structurecollects together all the various descriptors that make up theenumeration data. It is the responsibility of application code tosupply a suitable data structure and install it in the controlendpoints's <TTCLASS="STRUCTFIELD"><I>enumeration_data</I></TT> field beforethe USB device is started.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="usbs-intro.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="usbs-start.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Introduction</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-usb-slave.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Starting up a USB Device</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -