nRF5 SDK v17.1.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions

nRF52840 only: Module with types, definitions and API used by CDC ACM class. More...

Modules

 USB CDC ACM internals
 nRF52840 only: Internals of the USB ACM class implementation.
 
 USB CDC ACM class configuration
 
 CDC class descriptors
 nRF52840 only: Descriptors used in the USB CDC class implementation.A group of macros used to initialize CDC descriptors
 
 CDC class types
 nRF52840 only: Variable types used by the CDC class implementation.
 

Data Structures

struct  app_usbd_cdc_acm_t
 CDC ACM class instance type. More...
 

Macros

#define APP_USBD_CDC_ACM_DEFAULT_DESC(comm_interface,comm_epin,data_interface,data_epin,data_epout)
 Default CDC ACM descriptors. More...
 
#define APP_USBD_CDC_ACM_GLOBAL_DEF(instance_name,user_ev_handler,comm_ifc,data_ifc,comm_ein,data_ein,data_eout,cdc_protocol)
 Global definition of app_usbd_cdc_acm_t class instance. More...
 

Typedefs

typedef enum
app_usbd_cdc_acm_user_event_e 
app_usbd_cdc_acm_user_event_t
 Events passed to user event handler. More...
 

Enumerations

enum  app_usbd_cdc_acm_user_event_e {
  APP_USBD_CDC_ACM_USER_EVT_RX_DONE,
  APP_USBD_CDC_ACM_USER_EVT_TX_DONE,
  APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN,
  APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE
}
 Events passed to user event handler. More...
 
enum  app_usbd_cdc_acm_serial_state_t {
  APP_USBD_CDC_ACM_SERIAL_STATE_DCD = (1u << 0),
  APP_USBD_CDC_ACM_SERIAL_STATE_DSR = (1u << 1),
  APP_USBD_CDC_ACM_SERIAL_STATE_BREAK = (1u << 2),
  APP_USBD_CDC_ACM_SERIAL_STATE_RING = (1u << 3),
  APP_USBD_CDC_ACM_SERIAL_STATE_FRAMING = (1u << 4),
  APP_USBD_CDC_ACM_SERIAL_STATE_PARITY = (1u << 5),
  APP_USBD_CDC_ACM_SERIAL_STATE_OVERRUN = (1u << 6)
}
 Serial state notifications. More...
 
enum  app_usbd_cdc_acm_line_state_t {
  APP_USBD_CDC_ACM_LINE_STATE_DTR = (1u << 0),
  APP_USBD_CDC_ACM_LINE_STATE_RTS = (1u << 1)
}
 Serial line state. More...
 

Functions

static app_usbd_class_inst_t
const * 
app_usbd_cdc_acm_class_inst_get (app_usbd_cdc_acm_t const *p_cdc_acm)
 Helper function to get class instance from CDC ACM class. More...
 
static app_usbd_cdc_acm_req_tapp_usbd_cdc_acm_class_request_get (app_usbd_cdc_acm_t const *p_cdc_acm)
 Helper function to get cdc_acm specific request from cdc_acm class. More...
 
static app_usbd_cdc_acm_t const * app_usbd_cdc_acm_class_get (app_usbd_class_inst_t const *p_inst)
 Helper function to get cdc_acm from base class instance. More...
 
ret_code_t app_usbd_cdc_acm_write (app_usbd_cdc_acm_t const *p_cdc_acm, const void *p_buf, size_t length)
 Writes data to CDC ACM serial port. More...
 
size_t app_usbd_cdc_acm_rx_size (app_usbd_cdc_acm_t const *p_cdc_acm)
 Returns the amount of data that was read. More...
 
size_t app_usbd_cdc_acm_bytes_stored (app_usbd_cdc_acm_t const *p_cdc_acm)
 Returns the amount of data that was stored into internal buffer. More...
 
ret_code_t app_usbd_cdc_acm_read (app_usbd_cdc_acm_t const *p_cdc_acm, void *p_buf, size_t length)
 Reads data from CDC ACM serial port. More...
 
ret_code_t app_usbd_cdc_acm_read_any (app_usbd_cdc_acm_t const *p_cdc_acm, void *p_buf, size_t length)
 Read any data from CDC ACM port up to given buffer size. More...
 
ret_code_t app_usbd_cdc_acm_serial_state_notify (app_usbd_cdc_acm_t const *p_cdc_acm, app_usbd_cdc_acm_serial_state_t serial_state, bool value)
 Serial state notification via IN interrupt endpoint. More...
 
ret_code_t app_usbd_cdc_acm_line_state_get (app_usbd_cdc_acm_t const *p_cdc_acm, app_usbd_cdc_acm_line_state_t line_state, uint32_t *value)
 Control line value get. More...
 

Detailed Description

nRF52840 only: Module with types, definitions and API used by CDC ACM class.

References:

Macro Definition Documentation

#define APP_USBD_CDC_ACM_DEFAULT_DESC (   comm_interface,
  comm_epin,
  data_interface,
  data_epin,
  data_epout 
)
Value:
APP_USBD_CDC_IAD_DSC(comm_interface, \
APP_USBD_CDC_COMM_INTERFACE_DSC(comm_interface, \
APP_USBD_CDC_HEADER_DSC(0x0110) \
APP_USBD_CDC_CALL_MGMT_DSC(0x03, data_interface) \
APP_USBD_CDC_ACM_DSC(0x02) \
APP_USBD_CDC_UNION_DSC(comm_interface, data_interface) \
APP_USBD_CDC_COM_EP_DSC(comm_epin, NRF_DRV_USBD_EPSIZE) \
APP_USBD_CDC_DATA_INTERFACE_DSC(data_interface, 0, 0) \
APP_USBD_CDC_DATA_EP_DSC(data_epin, data_epout, NRF_DRV_USBD_EPSIZE)

Default CDC ACM descriptors.

Parameters
comm_interfaceCOMM interface number.
comm_epinCOMM interface IN endpoint.
data_interfaceDATA interface number.
data_epinDATA interface IN endpoint.
data_epoutDATA interface OUT endpoint.
#define APP_USBD_CDC_ACM_GLOBAL_DEF (   instance_name,
  user_ev_handler,
  comm_ifc,
  data_ifc,
  comm_ein,
  data_ein,
  data_eout,
  cdc_protocol 
)
Value:
user_ev_handler, \
comm_ifc, \
data_ifc, \
comm_ein, \
data_ein, \
data_eout, \
cdc_protocol) \

Global definition of app_usbd_cdc_acm_t class instance.

Parameters
instance_nameName of global instance.
user_ev_handlerUser event handler (optional).
comm_ifcInterface number of cdc_acm control.
data_ifcInterface number of cdc_acm DATA.
comm_einCOMM subclass IN endpoint.
data_einDATA subclass IN endpoint.
data_eoutDATA subclass OUT endpoint.
cdc_protocolCDC protocol app_usbd_cdc_comm_protocol_t
Note
This macro is just simplified version of APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL.

Typedef Documentation

Events passed to user event handler.

Note
Example prototype of user event handler:
void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,

Enumeration Type Documentation

Serial line state.

Enumerator
APP_USBD_CDC_ACM_LINE_STATE_DTR 

Line state bit DTR.

APP_USBD_CDC_ACM_LINE_STATE_RTS 

Line state bit RTS.

Serial state notifications.

Enumerator
APP_USBD_CDC_ACM_SERIAL_STATE_DCD 

Notification bit DCD.

APP_USBD_CDC_ACM_SERIAL_STATE_DSR 

Notification bit DSR.

APP_USBD_CDC_ACM_SERIAL_STATE_BREAK 

Notification bit BREAK.

APP_USBD_CDC_ACM_SERIAL_STATE_RING 

Notification bit RING.

APP_USBD_CDC_ACM_SERIAL_STATE_FRAMING 

Notification bit FRAMING.

APP_USBD_CDC_ACM_SERIAL_STATE_PARITY 

Notification bit PARITY.

APP_USBD_CDC_ACM_SERIAL_STATE_OVERRUN 

Notification bit OVERRUN.

Events passed to user event handler.

Note
Example prototype of user event handler:
void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
Enumerator
APP_USBD_CDC_ACM_USER_EVT_RX_DONE 

User event RX_DONE.

APP_USBD_CDC_ACM_USER_EVT_TX_DONE 

User event TX_DONE.

APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN 

User event PORT_OPEN.

APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE 

User event PORT_CLOSE.

Function Documentation

size_t app_usbd_cdc_acm_bytes_stored ( app_usbd_cdc_acm_t const *  p_cdc_acm)

Returns the amount of data that was stored into internal buffer.

This function should be used on APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get information how many bytes are waiting in internal buffer.

Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
Returns
Amount of data waiting.
static app_usbd_cdc_acm_t const* app_usbd_cdc_acm_class_get ( app_usbd_class_inst_t const *  p_inst)
inlinestatic

Helper function to get cdc_acm from base class instance.

Parameters
[in]p_instBase class instance.
Returns
CDC ACM class handle.
static app_usbd_class_inst_t const* app_usbd_cdc_acm_class_inst_get ( app_usbd_cdc_acm_t const *  p_cdc_acm)
inlinestatic

Helper function to get class instance from CDC ACM class.

Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
Returns
Base class instance.
static app_usbd_cdc_acm_req_t* app_usbd_cdc_acm_class_request_get ( app_usbd_cdc_acm_t const *  p_cdc_acm)
inlinestatic

Helper function to get cdc_acm specific request from cdc_acm class.

Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
Returns
CDC ACM class specific request.
ret_code_t app_usbd_cdc_acm_line_state_get ( app_usbd_cdc_acm_t const *  p_cdc_acm,
app_usbd_cdc_acm_line_state_t  line_state,
uint32_t *  value 
)

Control line value get.

Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
[in]line_stateLine control value type.
[out]valueLine control value.
Returns
Standard error code.
ret_code_t app_usbd_cdc_acm_read ( app_usbd_cdc_acm_t const *  p_cdc_acm,
void *  p_buf,
size_t  length 
)

Reads data from CDC ACM serial port.

This function uses internal buffer and double buffering for continuous transmission.

If there is enough data in internal buffer to fill user buffer, NRF_SUCCESS is returned and data is immediately available in the user buffer.

If not, up to two user buffers can be scheduled, function returns NRF_ERROR_IO_PENDING when first buffer is filled and APP_USBD_CDC_ACM_USER_EVT_RX_DONE event is generated.

See Also
app_usbd_cdc_acm_read_any
app_usbd_cdc_acm_rx_size
Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
[out]p_bufOutput buffer.
[in]lengthNumber of bytes to read.
Return values
NRF_SUCCESSData is stored into user buffer.
NRF_ERROR_IO_PENDINGAwaiting transmission, when data is stored into user buffer, APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
NRF_ERROR_BUSYThere are already 2 buffers queued for transfers.
otherStandard error code.
ret_code_t app_usbd_cdc_acm_read_any ( app_usbd_cdc_acm_t const *  p_cdc_acm,
void *  p_buf,
size_t  length 
)

Read any data from CDC ACM port up to given buffer size.

This function is very similar to the app_usbd_cdc_acm_read but it returns data as quick as any data is available, even if the given buffer was not totally full.

Note
This function cannot use double buffering.
To check the number of bytes really read use app_usbd_cdc_acm_rx_size function.
See Also
app_usbd_cdc_acm_read
app_usbd_cdc_acm_rx_size
Parameters
p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
[out]p_bufOutput buffer.
[in]lengthMaximum number of bytes to read.
Return values
NRF_SUCCESSData is stored into user buffer.
NRF_ERROR_IO_PENDINGAwaiting transmission, when data is stored into user buffer, APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
NRF_ERROR_BUSYThere is already buffer set for a transfer.
otherStandard error code.
size_t app_usbd_cdc_acm_rx_size ( app_usbd_cdc_acm_t const *  p_cdc_acm)

Returns the amount of data that was read.

This function should be used on APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get information how many bytes have been transfered into user buffer.

Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
Returns
Amount of data transfered.
ret_code_t app_usbd_cdc_acm_serial_state_notify ( app_usbd_cdc_acm_t const *  p_cdc_acm,
app_usbd_cdc_acm_serial_state_t  serial_state,
bool  value 
)

Serial state notification via IN interrupt endpoint.

Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
[in]serial_stateSerial state notification type.
[in]valueSerial state value.
Returns
Standard error code.
ret_code_t app_usbd_cdc_acm_write ( app_usbd_cdc_acm_t const *  p_cdc_acm,
const void *  p_buf,
size_t  length 
)

Writes data to CDC ACM serial port.

This is asynchronous call. User should wait for APP_USBD_CDC_ACM_USER_EVT_TX_DONE event to be sure that all data has been sent and input buffer could be accessed again.

Parameters
[in]p_cdc_acmCDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF).
[in]p_bufInput buffer.
[in]lengthInput buffer length.
Returns
Standard error code.

Documentation feedback | Developer Zone | Subscribe | Updated