|
NetBurner 3.5.7
PDF Version |
USB CDC Abstract Control Model Device Class. More...
#include <usbd_cdc_acm.h>
Inherits nbrtos::USB::Device.
Public Member Functions | |
| dCDC_ACM (nbrtos::USB::Ctlr *parent, const usb_dev_t *desc, const usb_cfg_t *cfg, const nbrtos::USB::StrDescTbl *strTbl) | |
| Construct a CDC ACM device instance. | |
| virtual void | Event_BusReset () |
| Handle USB bus reset event. | |
| virtual void | Event_Suspend () |
| Handle USB suspend event. | |
| virtual void | Event_Resume () |
| Handle USB resume event. | |
| virtual int | Event_ControlMsg (nbrtos::USB::bufPtr_t ctlMsg, uint8_t bufLen) |
| Handle USB control message. | |
| virtual int | SetConfiguration (uint16_t wValue) |
| Set the active USB configuration. | |
| virtual int | SetAltSetting (uint16_t wIndex, uint16_t wValue) |
| Set alternate interface setting. | |
| virtual int | ProcessBuffer (uint8_t ep, PoolPtr pp, uint16_t bufLen) |
| Process a received data buffer. | |
| virtual uint16_t | GetStatus (eReqTarget_t target, uint16_t wIndex, int *err) |
| Get device or endpoint status. | |
| virtual uint8_t | GetActiveConfig (int *err) |
| Get currently active configuration. | |
| virtual uint8_t | GetAltSetting (uint8_t intfNum, int *err) |
| Get current alternate setting for an interface. | |
| virtual uint16_t | GetMaxPktSize (uint8_t epnum, eDir_t dir) |
| Get maximum packet size for an endpoint. | |
| nbrtos::USB::eBusState_t | GetUSBState () |
| Get current USB bus state. | |
| void | SetUSBState (nbrtos::USB::eBusState_t newState) |
| Set USB bus state. | |
| int | ReadData (uint8_t *pData, int rdLen) |
| Read data from the CDC device (non-blocking) | |
| int | ReadWTimeout (uint8_t *pData, int rdLen, TickTimeout timeout) |
| Read data from the CDC device with timeout. | |
| int | WriteData (uint8_t *pData, int wrLen) |
| Write data to the CDC device (non-blocking) | |
| int | WriteWTimeout (uint8_t *pData, int wrLen, TickTimeout timeout) |
| Write data to the CDC device with timeout. | |
| int | Open () |
| Open the CDC device for use. | |
| int | Peek (uint8_t *buf) |
| Peek at the next byte without removing it. | |
| virtual int | ProcessSetupPkt (uint8_t epnum, usb_setup_pkt_t msg) |
| Process USB setup packet. | |
Static Public Member Functions | |
| static int | sProcessBuffer (Device *dev, uint8_t ep, PoolPtr pp, uint16_t bufLen) |
| Static callback wrapper for ProcessBuffer. | |
USB CDC Abstract Control Model Device Class.
This class implements a USB CDC ACM device that provides virtual serial port functionality. When connected to a host computer, the device enumerates as a standard COM port, enabling serial communication over USB.
The class inherits from nbrtos::USB::Device and implements all required virtual functions for USB device operation, plus CDC-specific functionality for line coding and control signal management.
Key features:
Expand for Example Usage
| dCDC_ACM::dCDC_ACM | ( | nbrtos::USB::Ctlr * | parent, |
| const usb_dev_t * | desc, | ||
| const usb_cfg_t * | cfg, | ||
| const nbrtos::USB::StrDescTbl * | strTbl ) |
Construct a CDC ACM device instance.
Creates a new CDC ACM device attached to the specified USB controller. The device will not be active until Open() is called.
| parent | Pointer to the USB controller this device is attached to |
| desc | Pointer to the USB device descriptor |
| cfg | Pointer to the USB configuration descriptor (includes CDC interface and endpoint descriptors) |
| strTbl | Pointer to the string descriptor table for device identification strings |
|
virtual |
Handle USB bus reset event.
Called by the USB stack when a bus reset is detected. Resets the device state machine and clears any pending transfers.
|
virtual |
Handle USB control message.
Processes control endpoint messages, including CDC-specific class requests such as GET_LINE_CODING, SET_LINE_CODING, and SET_CONTROL_LINE_STATE.
| ctlMsg | Pointer to the control message buffer |
| bufLen | Length of the control message |
|
virtual |
Handle USB resume event.
Called by the USB stack when the bus resumes from suspend state. Normal operation can continue after this event.
|
virtual |
Handle USB suspend event.
Called by the USB stack when the bus enters suspend state. The device should reduce power consumption when suspended.
|
virtual |
Get currently active configuration.
Returns the current configuration value for GET_CONFIGURATION requests.
| [out] | err | Pointer to receive error code |
|
virtual |
Get current alternate setting for an interface.
Returns the alternate setting for GET_INTERFACE requests.
| intfNum | Interface number | |
| [out] | err | Pointer to receive error code |
|
virtual |
Get maximum packet size for an endpoint.
Returns the maximum packet size configured for the specified endpoint.
| epnum | Endpoint number |
| dir | Endpoint direction (IN or OUT) |
|
virtual |
Get device or endpoint status.
Returns the status for GET_STATUS requests.
| target | Request target (device, interface, or endpoint) | |
| wIndex | Index value from the request (interface or endpoint number) | |
| [out] | err | Pointer to receive error code |
| nbrtos::USB::eBusState_t dCDC_ACM::GetUSBState | ( | ) |
Get current USB bus state.
Returns the current state of the USB connection.
| int dCDC_ACM::Open | ( | ) |
Open the CDC device for use.
Initializes the CDC device, sets up the file descriptor interface, and prepares the device for data transfer. Must be called before using ReadData(), WriteData(), or the file descriptor.
Expand for Example Usage
| int dCDC_ACM::Peek | ( | uint8_t * | buf | ) |
Peek at the next byte without removing it.
Returns the next byte in the receive buffer without removing it. Useful for protocols that need to look ahead in the data stream.
| buf | Pointer to receive the peeked byte |
|
virtual |
Process a received data buffer.
Called by the USB stack when data is received on an endpoint. Copies received data to the receive FIFO and signals waiting readers.
| ep | Endpoint number that received data |
| pp | Pool pointer to the received buffer |
| bufLen | Number of bytes received |
|
virtual |
Process USB setup packet.
Handles USB setup packets received on the control endpoint, including standard device requests and CDC class-specific requests.
| epnum | Endpoint number (typically 0 for control endpoint) |
| msg | USB setup packet to process |
| int dCDC_ACM::ReadData | ( | uint8_t * | pData, |
| int | rdLen ) |
Read data from the CDC device (non-blocking)
Reads available data from the receive buffer. Returns immediately with whatever data is available, up to the requested length.
| pData | Pointer to buffer to receive data |
| rdLen | Maximum number of bytes to read |
| int dCDC_ACM::ReadWTimeout | ( | uint8_t * | pData, |
| int | rdLen, | ||
| TickTimeout | timeout ) |
Read data from the CDC device with timeout.
Reads data from the receive buffer, waiting up to the specified timeout for data to become available.
| pData | Pointer to buffer to receive data |
| rdLen | Maximum number of bytes to read |
| timeout | Maximum time to wait for data (in system ticks) |
Expand for Example Usage
|
virtual |
Set alternate interface setting.
Called by the USB stack when the host selects an alternate setting for an interface.
| wIndex | Interface number |
| wValue | Alternate setting value |
|
virtual |
Set the active USB configuration.
Called by the USB stack when the host selects a configuration. Initializes endpoints and prepares the device for data transfer.
| wValue | Configuration value from SET_CONFIGURATION request |
| void dCDC_ACM::SetUSBState | ( | nbrtos::USB::eBusState_t | newState | ) |
Set USB bus state.
Updates the internal USB state. Typically called by event handlers.
| newState | New USB bus state to set |
|
static |
Static callback wrapper for ProcessBuffer.
Static member function that dispatches to the instance ProcessBuffer method. Used for registering with the USB stack callback system.
| dev | Pointer to the device instance |
| ep | Endpoint number |
| pp | Pool pointer to the buffer |
| bufLen | Buffer length |
| int dCDC_ACM::WriteData | ( | uint8_t * | pData, |
| int | wrLen ) |
Write data to the CDC device (non-blocking)
Writes data to the transmit buffer. Returns immediately after copying data to the buffer. The actual USB transmission occurs asynchronously.
| pData | Pointer to data to write |
| wrLen | Number of bytes to write |
| int dCDC_ACM::WriteWTimeout | ( | uint8_t * | pData, |
| int | wrLen, | ||
| TickTimeout | timeout ) |
Write data to the CDC device with timeout.
Writes data to the transmit buffer, waiting up to the specified timeout for buffer space to become available.
| pData | Pointer to data to write |
| wrLen | Number of bytes to write |
| timeout | Maximum time to wait for buffer space (in system ticks) |