
SILICON LABS Programming USB Device Module
![]()
ข้อมูลจำเพาะ
- Product: USB Device Module
- Function: USB device programming
- ผู้ผลิต: ซิลิคอนแล็บส์
คำแนะนำการใช้ผลิตภัณฑ์
การเริ่มต้นโมดูลอุปกรณ์ USB
Begin by initializing the USB device module core using the function sl_usbd_core_init(). Check for any errors using the returned status.
การเริ่มต้นคลาส
After initializing the USB device core, initialize each class you intend to use. Refer to the Programming Guide of your specific class for more information.
การสร้างอุปกรณ์ USB ของคุณ
การเพิ่มการกำหนดค่า
Start by adding a configuration to your device. Use sl_usbd_core_add_configuration() to add a configuration with necessary parameters like speed, power consumption, etc.
Example – การเพิ่มการกำหนดค่าลงในอุปกรณ์ของคุณ
- sl_status_t status; uint8_t config_nbr_fs; status = sl_usbd_core_add_configuration(0, 100u, SL_USBD_DEVICE_SPEED_FULL, “Config Add Example Full-Speed config”, &config_nbr_fs); if (status != SL_STATUS_OK) { // Error handling }
การเพิ่มฟังก์ชั่น USB
Once you have added a configuration, you can add interfaces and endpoints to your device. Each USB class has specific requirements for interfaces and endpoints.
Example – การเพิ่มอินสแตนซ์คลาสให้กับอุปกรณ์ของคุณ
- sl_status_t status; uint8_t class_nbr; status = sl_usbd__create_instance(&class_nbr); if (status != SL_STATUS_OK) { // Error handling }
ส่วนนี้จะอธิบายคลาส Communications Device Class (CDC) และคลาสย่อย CDC ที่เกี่ยวข้องซึ่งได้รับการสนับสนุนโดยสแต็ก USB Device ของ Silicon Labs ปัจจุบัน USB-Device ของ Silicon Labs รองรับคลาสย่อย Abstract Control Model (ACM) ซึ่งมักใช้สำหรับการจำลองแบบอนุกรม
CDC ประกอบด้วยอุปกรณ์โทรคมนาคมและเครือข่ายหลากหลายชนิด อุปกรณ์โทรคมนาคมประกอบด้วยโมเด็มอนาล็อก โทรศัพท์อนาล็อกและดิจิทัล อะแดปเตอร์เทอร์มินัล ISDN เป็นต้นampอุปกรณ์เครือข่ายประกอบด้วยโมเด็ม ADSL และเคเบิลโมเด็ม อะแดปเตอร์อีเทอร์เน็ต และฮับ CDC กำหนดกรอบการทำงานเพื่อรวมมาตรฐานบริการสื่อสารที่มีอยู่ เช่น V.250 (สำหรับโมเด็มบนเครือข่ายโทรศัพท์) และอีเทอร์เน็ต (สำหรับอุปกรณ์เครือข่ายท้องถิ่น) โดยใช้ลิงก์ USB อุปกรณ์สื่อสารมีหน้าที่จัดการอุปกรณ์ จัดการการโทรเมื่อจำเป็น และส่งข้อมูล
CDC กำหนดกลุ่มอุปกรณ์หลัก 7 กลุ่ม แต่ละกลุ่มจะอยู่ในโมเดลการสื่อสารหนึ่งๆ ซึ่งอาจประกอบด้วยหลายคลาสย่อย แต่ละกลุ่มอุปกรณ์มีเอกสารข้อมูลจำเพาะของตนเองนอกเหนือจากคลาสพื้นฐานของ CDC ซึ่งประกอบด้วย 7 กลุ่มหลักดังนี้:
- Public Switched Telephone Network (PSTN), devices including voiceband modems, telephones, and serial emulation devices.
- Integrated Services Digital Network (ISDN) devices, including terminal adaptors and telephones.
- Ethernet Control Model (ECM) devices, including devices supporting the IEEE 802 family (ex.: cable and ADSL modems, WiFi adapters).
- Asynchronous Transfer Mode (ATM) devices, including ADSL modems and other devices connected to ATM networks (workstations, routers, LAN switches).
- Wireless Mobile Communications (WMC) devices, including multi-function communications handset devices used to manage voice and data communications.
- Ethernet Emulation Model (EEM) devices which exchange Ethernet-framed data.
- Network Control Model (NCM) devices, including high-speed network devices (High Speed Packet Access modems, Line Terminal Equipment)
CDC และการใช้งานคลาสย่อยที่เกี่ยวข้องเป็นไปตามข้อกำหนดต่อไปนี้:
- Universal Serial Bus, Class Definitions for Communications Devices, Revision 1.2, November 3 2010.
- Universal Serial Bus, Communications, Subclass for PSTN Devices, Revision 1.2, February 9 2007.
อุปกรณ์ USB CDC คลาสฐานเหนือview
อุปกรณ์ CDC ประกอบด้วยอินเทอร์เฟซต่อไปนี้เพื่อใช้ในการสื่อสาร:
- Communications Class Interface (CCI) is responsible for the device management and optionally the call management. The device management enables the general configuration and control of the device and the notification of events to the host. The call management enables calls establishment and termination. Call management might be multiplexed through a DCI. A CCI is mandatory for all CDC devices. It identifies the CDC function by specifying the communication model supported by the CDC device. The interface(s) following the CCI can be any defined USB class interface, such as Audio or a vendor-specific interface. The vendor-specific interface is represented specifically by a DCI.
- Data Class Interface (DCI) is responsible for data transmission. Data transmitted and/or received do not follow a specific format. Data could be raw data from a communication line, data following a proprietary format, etc. All the DCIs following the CCI can be seen as subordinate interfaces.
A CDC device must have at least one CCI and zero or more DCIs. One CCI and any subordinate DCI together provide a feature to the host. This capability is also referred to as a function. In a CDC composite device, you could have several functions. Therefore, the device would be composed of several sets of CCI and DCI(s) as shown in Figure – CDC Composite Device.
รูปภาพ – อุปกรณ์คอมโพสิต CDC
![]()
อุปกรณ์ CDC มีแนวโน้มที่จะใช้การรวมกันของจุดสิ้นสุดต่อไปนี้:
- A pair of control IN and OUT endpoints called the default endpoint.
- An optional bulk or interrupt IN endpoint.
- A pair of bulk or isochronous IN and OUT endpoints. Note that Silicon Labs USB device stack does not currently support isochronous endpoints.
ตารางด้านล่างแสดงการใช้งานจุดสิ้นสุดที่แตกต่างกันและอินเทอร์เฟซของ CDC ที่ใช้
ตาราง – การใช้งานจุดสิ้นสุดของ CDC
| จุดสิ้นสุด | ทิศทาง | อินเทอร์เฟซ | การใช้งาน |
|---|---|---|---|
| ควบคุมใน | Device-to-host | ซีซีไอ | Standard requests for enumeration, class-specific requests, device management, and optionally call management. |
| ควบคุมออก | Host-to-device | ซีซีไอ | Standard requests for enumeration, class-specific requests, device management, and optionally call management. |
| Interrupt or bulk IN | Device-to-host | ซีซีไอ | การแจ้งเตือนเหตุการณ์ เช่น การตรวจจับเสียงเรียกเข้า สถานะสายซีเรียล สถานะเครือข่าย |
| Bulk or isochronous IN | Device-to-host | ดีซีไอ | การสื่อสารข้อมูลแบบดิบหรือแบบฟอร์แมต |
| Bulk or isochronous OUT | Host-to-device | ดีซีไอ | การสื่อสารข้อมูลแบบดิบหรือแบบฟอร์แมต |
- อุปกรณ์สื่อสารส่วนใหญ่ใช้จุดสิ้นสุดแบบขัดจังหวะเพื่อแจ้งเตือนโฮสต์เกี่ยวกับเหตุการณ์ต่างๆ จุดสิ้นสุดแบบไอโซโครนัสไม่ควรใช้สำหรับการส่งข้อมูลเมื่อโปรโตคอลเฉพาะต้องอาศัยการส่งข้อมูลซ้ำในกรณีที่โปรโตคอล USB ผิดพลาด การสื่อสารแบบไอโซโครนัสอาจสูญเสียข้อมูลโดยธรรมชาติ เนื่องจากไม่มีกลไกการลองใหม่
- โมเดลการสื่อสารหลักทั้งเจ็ดแบบครอบคลุมหลายคลาสย่อย คลาสย่อยอธิบายถึงวิธีที่อุปกรณ์ควรใช้ CCI เพื่อจัดการการจัดการอุปกรณ์และการจัดการการโทร ตารางด้านล่างแสดงคลาสย่อยที่เป็นไปได้ทั้งหมดและโมเดลการสื่อสารที่คลาสย่อยเหล่านั้นอยู่
ตาราง – คลาสย่อย CDC
| ซับคลาส | รูปแบบการสื่อสาร | Example ของอุปกรณ์ที่ใช้คลาสย่อยนี้ |
|---|---|---|
| Direct Line Control Model | PSTN | อุปกรณ์โมเด็มควบคุมโดยตรงจากโฮสต์ USB |
| แบบจำลองการควบคุมนามธรรม | PSTN | อุปกรณ์จำลองแบบอนุกรม อุปกรณ์โมเด็มที่ควบคุมผ่านชุดคำสั่งแบบอนุกรม |
| รุ่นควบคุมโทรศัพท์ | PSTN | อุปกรณ์โทรศัพท์ด้วยเสียง |
| Multi-Channel Control Model | ISDN | อะแดปเตอร์เทอร์มินัลอัตราพื้นฐาน อะแดปเตอร์เทอร์มินัลอัตราหลัก โทรศัพท์ |
| CAPI Control Model | ISDN | อะแดปเตอร์เทอร์มินัลอัตราพื้นฐาน อะแดปเตอร์เทอร์มินัลอัตราหลัก โทรศัพท์ |
| Ethernet Networking Control Model | อีซีเอ็ม | DOC-SIS cable modems, ADSL modems that support PPPoE emulation, Wi-Fi adaptors (IEEE 802.11-family), IEEE 802.3 adaptors |
| ATM Networking Control Model | ATM | ADSL modems |
| รุ่นควบคุมโทรศัพท์มือถือไร้สาย | ดับเบิลยูเอ็มซี | อุปกรณ์ปลายทางเคลื่อนที่ที่เชื่อมต่อกับอุปกรณ์ไร้สาย |
| การจัดการอุปกรณ์ | ดับเบิลยูเอ็มซี | อุปกรณ์ปลายทางเคลื่อนที่ที่เชื่อมต่อกับอุปกรณ์ไร้สาย |
| แบบจำลองสายตรงเคลื่อนที่ | ดับเบิลยูเอ็มซี | อุปกรณ์ปลายทางเคลื่อนที่ที่เชื่อมต่อกับอุปกรณ์ไร้สาย |
| โอเบ็กซ์ | ดับเบิลยูเอ็มซี | อุปกรณ์ปลายทางเคลื่อนที่ที่เชื่อมต่อกับอุปกรณ์ไร้สาย |
| Ethernet Emulation Model | EEM | Devices using Ethernet frames as the next layer of transport. Not intended for routing and Internet connectivity devices |
| โมเดลการควบคุมเครือข่าย | NCM | IEEE 802.3 adaptors carrying high-speed data bandwidth on network |
ความต้องการทรัพยากรคลาส ACM CDC ของอุปกรณ์ USB จากแกนหลัก
Each time you add a CDC ACM class instance to a USB configuration via a call to the function sl_usbd_cdc_acm_add_to_configuration(), the following resources will be allocated from the core.
| ทรัพยากร | ปริมาณ |
|---|---|
| อินเทอร์เฟซ | 2 |
| Alternate interfaces | 2 |
| ปลายทาง | 3 |
| Interface groups | 1 |
- Note that those numbers are per configuration. When setting up your
SL_USBD_INTERFACE_QUANTITY,SL_USBD_ALT_INTERFACE_QUANTITY,SL_USBD_INTERFACE_GROUP_QUANTITYและSL_USBD_DESCRIPTOR_QUANTITYconfiguration values, don’t forget to take into account on how many configurations the class will be added. For theSL_USBD_OPEN_ENDPOINTS_QUANTITYconfiguration value, since endpoints are opened only when a configuration is set by the host, you just need to take into account the number of needed endpoints for a class instance.
อุปกรณ์ USB CDC ACM ซับคลาสเหนือview
- The CDC base class is composed of a Communications Class Interface (CCI) and Data Class Interface (DCI), which is discussed in detail in USB Device CDC Base Class Overview หัวข้อนี้จะกล่าวถึง CCI ประเภท ACM ซึ่งประกอบด้วยจุดสิ้นสุดเริ่มต้นสำหรับองค์ประกอบการจัดการ และจุดสิ้นสุดการขัดจังหวะสำหรับองค์ประกอบการแจ้งเตือน จุดสิ้นสุดจำนวนมากสองจุดจะถูกใช้เพื่อส่งข้อมูลที่ไม่ได้ระบุผ่าน DCI
ACM subclass ถูกใช้โดยอุปกรณ์สื่อสารสองประเภท:
- Devices supporting AT commands (for instance, voiceband modems).
- Serial emulation devices which are also called Virtual COM port devices.
There are several subclass-specific requests for the ACM subclass. They allow you to control and configure the device. The complete list and description of all ACM requests can be found in the specification “Universal Serial Bus, Communications, Subclass for PSTN Devices, revision 1.2, February 9, 2007”, section 6.2.2.
From this list, Silicon Labs’ ACM subclass supports the following:
ตาราง – คำขอ ACM ที่ได้รับการสนับสนุนโดย Silicon Labs
| Subclass Request | คำอธิบาย |
|---|---|
| SetCommFeature | โฮสต์จะส่งคำขอนี้เพื่อควบคุมการตั้งค่าสำหรับฟีเจอร์การสื่อสารที่กำหนด ไม่ได้ใช้สำหรับการจำลองแบบอนุกรม |
| GetCommFeature | โฮสต์จะส่งคำขอนี้เพื่อรับการตั้งค่าปัจจุบันสำหรับฟีเจอร์การสื่อสารที่กำหนด ไม่ได้ใช้สำหรับการจำลองแบบอนุกรม |
| ClearCommFeature | โฮสต์จะส่งคำขอนี้เพื่อล้างการตั้งค่าสำหรับฟีเจอร์การสื่อสารที่กำหนด ไม่ได้ใช้สำหรับการจำลองแบบอนุกรม |
| การเข้ารหัส SetLine | โฮสต์จะส่งคำขอนี้เพื่อกำหนดค่าการตั้งค่าอุปกรณ์ ACM ได้แก่ อัตราบอด จำนวนบิตหยุด ประเภทพาริตี และจำนวนบิตข้อมูล สำหรับการจำลองแบบอนุกรม คำขอนี้จะถูกส่งโดยอัตโนมัติจากเทอร์มินัลอนุกรมทุกครั้งที่คุณกำหนดค่าการตั้งค่าอนุกรมสำหรับพอร์ต COM เสมือนแบบเปิด |
| รับการเข้ารหัสไลน์ | โฮสต์จะส่งคำขอนี้เพื่อรับการตั้งค่า ACM ปัจจุบัน (บอดเรต, สต็อปบิต, พาริตี้, บิตข้อมูล) สำหรับการจำลองแบบอนุกรม เทอร์มินัลอนุกรมจะส่งคำขอนี้โดยอัตโนมัติในระหว่างการเปิดพอร์ต COM เสมือน |
| SetControlLineState | The host sends this request to control the carrier for half-duplex modems and indicate that Data Terminal Equipment (DTE) is ready or not. In the serial emulation case, the DTE is a serial terminal. For a serial emulation, certain serial terminals allow you to send this request with the controls set. |
| เซ็ตเบรก | โฮสต์จะส่งคำขอนี้เพื่อสร้างเบรกแบบ RS-232 สำหรับการจำลองแบบอนุกรม เทอร์มินัลอนุกรมบางรุ่นอนุญาตให้คุณส่งคำขอนี้ได้ |
Silicon Labs’ ACM subclass uses the interrupt IN endpoint to notify the host about the current serial line state. The serial line state is a bitmap informing the host about:
- Data discarded because of overrun
- ข้อผิดพลาดของพาริตี
- ข้อผิดพลาดในการจัดเฟรม
- State of the ring signal detection
- State of break detection mechanism
- State of transmission carrier
- State of receiver carrier detection
Silicon Labs’ ACM subclass implementation complies with the following specification:
- Universal Serial Bus, การสื่อสาร, ซับคลาสสำหรับอุปกรณ์ PSTN, การแก้ไขครั้งที่ 1.2, 9 กุมภาพันธ์ 2007
การกำหนดค่าคลาส ACM CDC ของอุปกรณ์ USB
หัวข้อนี้จะอธิบายวิธีการกำหนดค่าคลาส CDC ACM (คลาสอุปกรณ์สื่อสาร, โมเดลการควบคุมเชิงนามธรรม) โดยมีพารามิเตอร์การกำหนดค่าสองกลุ่ม:
- การกำหนดค่าเฉพาะแอปพลิเคชันคลาส ACM CDC ของอุปกรณ์ USB
- การกำหนดค่าอินสแตนซ์คลาส ACM CDC ของอุปกรณ์ USB
การกำหนดค่าเฉพาะแอปพลิเคชันคลาส ACM CDC ของอุปกรณ์ USB
- คลาสฐาน CDC
- ซับคลาส ACM
คลาสฐาน CDC
- ก่อนอื่น หากต้องการใช้โมดูลคลาส CDC ของอุปกรณ์ USB ของ Silicon Labs คุณจะต้องปรับค่าคอนฟิกูเรชันเวลาคอมไพล์ CDC #define-s ตามความต้องการของแอปพลิเคชันของคุณ ซึ่งจะถูกจัดกลุ่มใหม่ภายในส่วนหัว sl_usbd_core_config.h file ภายใต้ส่วน CDC วัตถุประสงค์คือเพื่อแจ้งให้โมดูลอุปกรณ์ USB ทราบจำนวนอ็อบเจ็กต์ USB CDC ที่จะจัดสรร
- ตารางด้านล่างนี้จะอธิบายฟิลด์การกำหนดค่าแต่ละฟิลด์ที่มีอยู่ในโครงสร้างการกำหนดค่านี้
ตาราง – การกำหนดค่า CDC ของอุปกรณ์ USB กำหนด
| ชื่อการกำหนดค่า | คำอธิบาย | ค่าเริ่มต้น |
|---|---|---|
SL_USBD_CDC_CLASS_INSTANCE_QUANTITY |
จำนวนอินสแตนซ์คลาสที่คุณจะจัดสรรผ่านการเรียกใช้ฟังก์ชัน sl_usbd_cdc_acm_create_instance(). |
2 |
SL_USBD_CDC_CONFIGURATION_QUANTITY |
Number of configurations. ACM class instances can be added to one or more configurations via a call to the sl_usbd_cdc_acm_add_to_configuration(). |
1 |
SL_USBD_CDC_DATA_INTERFACE_QUANTITY |
Total number of data interfaces (DCI) for all the CDC functions. Each CDC ACM function added via a call to the function sl_usbd_cdc_acm_create_instance() will add a data interface. |
2 |
ซับคลาส ACM
ซับคลาส ACM มีการกำหนดค่าเวลาคอมไพล์หนึ่งรายการดังแสดงในตารางด้านล่าง
ตาราง – การกำหนดค่า ACM CDC ของอุปกรณ์ USB
| ชื่อการกำหนดค่า | คำอธิบาย | ค่าเริ่มต้น |
|---|---|---|
SL_USBD_CDC_ACM_SUBCLASS_INSTANCE_QUANTITY |
Configures the number of subclass instances you will allocate via a call to the function sl_usbd_cdc_acm_create_instance(). |
2 |
การกำหนดค่าอินสแตนซ์คลาส ACM CDC ของอุปกรณ์ USB
This section defines the configurations related to the CDC ACM serial class instances.
- การสร้างอินสแตนซ์คลาส
- line state interval
- call mgmt capabilities
- การเรียกกลับ p_acm
การสร้างอินสแตนซ์คลาส
To create a CDC ACM serial class instance, call the function sl_usbd_cdc_acm_create_instance(). This function takes three configuration arguments, as described here.
line_state_interval
This is the interval (in milliseconds) that your CDC ACM serial class instance will report the line state notifications to the host. This value must be a power of two (1, 2, 4, 8, 16, etc).
call_mgmt_capabilities
บิตแมปความสามารถในการจัดการการโทร ค่าที่เป็นไปได้ของบิตแมปมีดังนี้:
| ค่า (บิต) | คำอธิบาย |
|---|---|
SL_USBD_ACM_SERIAL_CALL_MGMT_DEV |
Device handles call management itself. |
SL_USBD_ACM_SERIAL_CALL_MGMT_DATA_CCI_DCI |
Device can send/receive call management information over a Data Class interface. |
p_acm_callbacks
p_acm_callbacksis a pointer to a structure of typesl_usbd_cdc_acm_callbacks_t. Its purpose is to give the CDC ACM Class a set of callback functions to be called when a CDC ACM event occurs.- Not all callbacks are mandatory and a null pointer (
NULL) can be passed in the callbacks structure variable when the callback is not needed. - ตารางด้านล่างนี้จะอธิบายฟิลด์การกำหนดค่าแต่ละฟิลด์ที่มีอยู่ในโครงสร้างการกำหนดค่านี้
Table – sl_usbd_cdc_acm_callbacks_t Configuration Structure
| ทุ่งนา | คำอธิบาย | ลายเซ็นฟังก์ชัน |
|---|---|---|
| .เปิดใช้งาน | เรียกเมื่อเปิดใช้งานอินสแตนซ์คลาส USB สำเร็จ | void app_usbd_cdc_acm_enable(uint8_t subclass_nbr); |
| .ปิดการใช้งาน | เรียกเมื่ออินสแตนซ์คลาส USB ถูกปิดใช้งาน | void app_usbd_cdc_acm_disable(uint8_t subclass_nbr); |
| .line_control_changed | Called when a line control change is received. | void app_usbd_cdc_acm_line_control_changed(uint8_t subclass_nbr, uint8_t event, uint8_t event_chngd); |
| line_coding_changed | Called when a line coding change is received. | bool app_usbd_cdc_acm_line_coding_changed(uint8_t subclass_nbr, subclass_nbr, sl_usbd_cdc_acm_line_coding_t *p_line_coding |
See section Registering Event Notification Callbacks for callback functions exampเล.
คู่มือการเขียนโปรแกรมคลาส ACM CDC ของอุปกรณ์ USB
This section explains how to use the CDC Abstract Control Model class.
- การเริ่มต้นคลาส CDC ACM ของอุปกรณ์ USB
- การเพิ่มอินสแตนซ์คลาส CDC ACM ของอุปกรณ์ USB ลงในอุปกรณ์ของคุณ
- การสื่อสารโดยใช้คลาส CDC ACM
การเริ่มต้นคลาส CDC ACM ของอุปกรณ์ USB
- To add CDC ACM class functionality to your device, you must first initialize the CDC base class and the ACM subclass by calling the functions
sl_usbd_cdc_init()และsl_usbd_cdc_acm_init(). - อดีตample below shows how to call
sl_usbd_cdc_init()และsl_usbd_cdc_acm_init()using default arguments.
Example – การเริ่มต้นคลาส CDC ACM
![]()
การเพิ่มอินสแตนซ์คลาส CDC ACM ของอุปกรณ์ USB ลงในอุปกรณ์ของคุณ
หากต้องการเพิ่มฟังก์ชันคลาส CDC ACM ให้กับอุปกรณ์ของคุณ คุณต้องสร้างอินสแตนซ์ จากนั้นจึงเพิ่มลงในการกำหนดค่าของอุปกรณ์
- การสร้างอินสแตนซ์คลาส CDC ACM
- การเพิ่มอินสแตนซ์คลาส CDC ACM ลงในการกำหนดค่าอุปกรณ์ของคุณ
- การลงทะเบียนการโทรกลับแจ้งเตือนเหตุการณ์
การสร้างอินสแตนซ์คลาส CDC ACM
- Create a CDC ACM class instance by calling the function
sl_usbd_cdc_acm_create_instance(). - อดีตample below shows how to create a CDC ACM class instance via
sl_usbd_cdc_acm_create_instance().
Exampเลอ – Creating a CDC ACM Function via sl_usbd_cdc_acm_create_instance()
![]()
การเพิ่มอินสแตนซ์คลาส CDC ACM ลงในการกำหนดค่าอุปกรณ์ของคุณ
- หลังจากที่คุณสร้างอินสแตนซ์คลาส CDC ACM แล้ว คุณสามารถเพิ่มลงในการกำหนดค่าได้โดยการเรียกใช้ฟังก์ชัน
sl_usbd_cdc_acm_add_to_configuration(). - อดีตample below shows how to call
sl_usbd_cdc_acm_add_to_configuration().
Example – Call to USBD ACM sl_usbd_cdc_acm_add_to_configuration()
![]()
- Class number to add to the configuration returned by
sl_usbd_cdc_acm_create_instance(). - Configuration number (here adding it to a Full-Speed configuration).
การลงทะเบียนการโทรกลับแจ้งเตือนเหตุการณ์
The CDC ACM Serial class can notify your application of any changes in line control or coding via notification callback functions. A callback functions structure can be passed as argument during the ACM instance creation. Note that those callbacks are optional. Example – CDC ACM Callbacks Registration illustrates the use of the callback registration functions. Example – CDC ACM Callbacks Implementation shows an exampแนวทางการใช้งานฟังก์ชันการโทรกลับ
Example – การลงทะเบียนการโทรกลับของ CDC ACM![]()
Example – การใช้งาน CDC ACM Callbacks
![]()
- It is important to return false to this function if the line coding applying failed. Otherwise, return true.
การสื่อสารโดยใช้คลาส CDC ACM
- สถานะซีเรียล
- การเข้ารหัสบรรทัด
- การควบคุมสาย
- สถานะของเส้น
- การสื่อสารแบบอินสแตนซ์คลาสย่อย
สถานะซีเรียล
การเข้ารหัสบรรทัด
- The USB host controls the line coding (baud rate, parity, etc) of the CDC ACM device. When necessary, the application is responsible for setting the line coding.
- There are two functions provided to retrieve and set the current line coding, as described in the table below.
ตาราง – ฟังก์ชันการเข้ารหัสสาย ACM ของ CDC
| การทำงาน | คำอธิบาย |
|---|---|
sl_usbd_cdc_acm_get_line_coding() |
Your application can get the current line coding settings set either from the host with SetLineCoding requests or with the function sl_usbd_cdc_acm_set_line_coding(). |
sl_usbd_cdc_acm_set_line_coding() |
แอปพลิเคชันของคุณสามารถตั้งค่าการเข้ารหัสบรรทัดได้ โฮสต์สามารถดึงการตั้งค่าด้วยคำขอ GetLineCoding |
การควบคุมสาย
- The USB host controls the line control (RTS and DTR pins, break signal, and so on) of the CDC ACM device. When necessary, your application is responsible for applying the line controls.
- A function is provided to retrieve and set the current line controls, as are described in the table below.
ตาราง – ฟังก์ชันการควบคุมสาย ACM ของ CDC
| การทำงาน | |
|---|---|
sl_usbd_cdc_acm_get_line_control_state() |
แอปพลิเคชันของคุณสามารถรับสถานะเส้นควบคุมปัจจุบันที่ตั้งค่าโดยโฮสต์ด้วยคำขอ SetControlLineState |
สถานะของเส้น
- The USB host retrieves the line state at a regular interval. Your application must update the line state each time it changes. When necessary, your application is responsible for setting the line state.
- Two functions are provided to retrieve and set the current line controls, as described in the table below.
Table – CDC ACM Line State Functions
| การทำงาน | |
|---|---|
sl_usbd_cdc_acm_set_line_state_event() |
แอปพลิเคชันของคุณสามารถตั้งค่าเหตุการณ์สถานะสายใดๆ ก็ได้ ขณะตั้งค่าสถานะสาย การถ่ายโอนสัญญาณขัดจังหวะจะถูกส่งไปยังโฮสต์เพื่อแจ้งการเปลี่ยนแปลงสถานะสายอนุกรม |
sl_usbd_cdc_acm_clear_line_state_event() |
แอปพลิเคชันสามารถล้างเหตุการณ์สถานะสายได้สองเหตุการณ์ ได้แก่ การตรวจจับพาหะของสายส่งและพาหะของสายรับ เหตุการณ์อื่นๆ ทั้งหมดจะถูกล้างโดยอัตโนมัติโดยซับคลาสการจำลองแบบอนุกรมของ ACM |
การสื่อสารแบบอินสแตนซ์คลาสย่อย
Silicon Labs’ ACM subclass offers the following functions to communicate with the host. For more details about the functions’ parameters, see the CDC ACM Subclass Functions reference.
| ชื่อฟังก์ชั่น | การดำเนินการ |
|---|---|
sl_usbd_cdc_acm_read() |
Receives data from host through a bulk OUT endpoint. This function is blocking. |
sl_usbd_cdc_acm_write() |
Sends data to host through a bulk IN endpoint. This function is blocking. |
Table – CDC ACM Communication API Summary
sl_usbd_cdc_acm_read()และsl_usbd_cdc_acm_write()provide synchronous communication, which means that the transfer is blocking. In other words, upon calling the function, the application blocks until the transfer is complete with or without an error. A timeout can be specified to avoid waiting forever. The example ด้านล่างแสดงการอ่านและการเขียนampไฟล์ที่รับข้อมูลจากโฮสต์โดยใช้จุดสิ้นสุด OUT จำนวนมากและส่งข้อมูลไปยังโฮสต์โดยใช้จุดสิ้นสุด IN จำนวนมาก
รายการ – การอ่านและเขียนแบบอนุกรมample
![]()
- The class instance number created with
sl_usbd_cdc_acm_create_instance()provides an internal reference to the ACM subclass to route the transfer to the proper bulk OUT or IN endpoint. - Your application must ensure that the buffer provided to the function is large enough to accommodate all the data. Otherwise, synchronization issues might happen.
- To avoid an infinite blocking situation, specify a timeout expressed in milliseconds. A value of ‘0’ makes the application task wait forever.
- The application provides the initialized transmit buffer.
คำถามที่พบบ่อย
Q: How do I troubleshoot if my USB device is not recognized by the system?
Q: Can I use multiple USB classes simultaneously on the same device?
เอกสาร / แหล่งข้อมูล
![]() | Programming USB Device Module |
อ้างอิง
- คู่มือการใช้งานmanual.tools
