This module covers basic implementation of the USB Communications Device Class (CDC) Abstract Control Model (ACM). The class has been defined in the following specification documents:
- Universal Serial Bus Class Definitions for Communications Devices
- Universal Serial Bus Communications Class Subclass Specification for PSTN Devices
Abstract Control Model (ACM) is in fact a subclass of the Communications Device Class (CDC).
Interfaces
The ACM subclass describes the bidirectional communication flow popularly known as Virtual Serial Port. The class has two interfaces:
- COMM interface that contains one IN endpoint. The COMM interface is used to notify the host about serial state. Notifications can be sent by app_usbd_cdc_acm_serial_state_notify API call.
- DATA interface that contains one IN and one OUT bulk endpoint. The DATA interface allows to send or receive bulk data.
Sending and receiving data
Sending of data is performed by the app_usbd_cdc_acm_write function. When all data is sent, event APP_USBD_CDC_ACM_USER_EVT_TX_DONE is generated and a new chunk of data can be sent.
There are two ways to receive data. First one is the app_usbd_cdc_acm_read function. Class instance has internal receive buffer, to extract data from it the library client must provide number of bytes to read and a buffer to store them. Next action should be based on return value:
- NRF_SUCCESS Data was stored into user buffer. User can provide another buffer to be filled, or check bytes left in internal buffer using app_usbd_cdc_acm_bytes_stored
- NRF_ERROR_IO_PENDING There is not enough data in internal buffer to fill user buffer. When data is stored APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised. User can schedule up to two buffers.
- NRF_ERROR_BUSY There are already two buffers queued for transfers.
Second option to use for receiving is app_usbd_cdc_acm_read_any function. It is very similar to previous one but it returns data as quick as any data is available, even if the given buffer was not totally full. Return values and their meaning are the same, but this function cannot use double buffering. To check the number of bytes really read use app_usbd_cdc_acm_rx_size function