USB Component

Installation

The component requires ESP-IDF 5.3 and higher and is installed using IDF Component Manager.

Add this to the idf_component.yml in the project main directory or in the component directory:

dependencies:
  plasmapper/pl_usb: "^1.0.1"

Add this to the source code:

#include "pl_usb.h"

Add extern "C" to the app_main function:

extern "C" void app_main(void) {...}

Add this to the sdkconfig.defaults in the project directory or configure the values using Project Configuration:

CONFIG_COMPILER_CXX_RTTI=y
CONFIG_TINYUSB_CDC_ENABLED=y

Features

  1. PL::UsbDevice - a USB device class.

  2. PL::UsbDeviceCdc - a PL::HardwareInterface and PL::Stream implementation for the USB device CDC endpoint. PL::UsbDeviceCdc::Initialize() initializes the USB device and the USB device CDC endpoint. A number of Get And Set methods get and set USB device CDC parameters. A number of PL::UsbDeviceCdc::Read() and PL::UsbDeviceCdc::Write() functions read and write from/to the endpoint. Reading and writing to/from PL::Buffer object checks the data size and locks the object so these methods can be used in multithreaded applications.

  3. PL::StreamServer can be used with PL::UsbDeviceCdc to implement a stream server for the USB device CDC endpoint. The descendant class should override PL::StreamServer::HandleRequest() to handle the client request. PL::StreamServer::HandleRequest() is only called when there is incoming data in the internal buffer.

Thread safety

Class method thread safety is implemented by having the PL::Lockable as a base class and creating the class object lock guard at the beginning of the methods.

Examples

API reference