USB API
Overviewβ
The USB API provides functions for interacting with USB devices. The API includes functions for checking if a USB device is connected, sending and receiving data over USB CDC, and more.
The header file for this API is part of os/MatrixOS.h and the implementation is in os/system/USB/.
Namespace: USBβ
The USB namespace contains general USB functions.
MatrixOS::USB::Connectedβ
bool USB::Connected(void);
Checks if a USB device is connected.
Returns:
bool:trueif a USB device is connected;falseotherwise.
CDCβ
The USB::CDC namespace provides functions for communication over USB as a virtual serial port (CDC).
In the future this will likely migrate into a MatrixOS::Serial namespace with cross port support between USB, UART, BLE, etc.
MatrixOS::USB::CDC::Connectedβ
bool USB::CDC::Connected(void);
Checks if the USB CDC is connected.
Returns:
bool:trueif the USB CDC is connected;falseotherwise.
MatrixOS::USB::CDC::Availableβ
uint32_t USB::CDC::Available(void);
Returns the number of bytes available for reading.
Returns:
uint32_t: Number of bytes available.
MatrixOS::USB::CDC::Pollβ
void USB::CDC::Poll(void);
Processes incoming and outgoing USB CDC data. This function should be called periodically.
MatrixOS::USB::CDC::Printβ
void USB::CDC::Print(string str);
Sends a string over USB CDC without a newline.
Parameters:
str(string): The string to send.
MatrixOS::USB::CDC::Printlnβ
void USB::CDC::Println(string str);
Sends a string over USB CDC with a newline appended.
Parameters:
str(string): The string to send.
MatrixOS::USB::CDC::Printfβ
void USB::CDC::Printf(string format, ...);
Sends a formatted string over USB CDC.
Parameters:
format(string): The format string....: Additional arguments for formatting.
MatrixOS::USB::CDC::VPrintfβ
void USB::CDC::VPrintf(string format, va_list valst);
Sends a formatted string over USB CDC using a va_list.
Parameters:
format(string): The format string.valst(va_list): A list of arguments for formatting.
MatrixOS::USB::CDC::Flushβ
void USB::CDC::Flush(void);
Flushes the USB CDC output buffer.
MatrixOS::USB::CDC::Readβ
int8_t USB::CDC::Read(void);
Reads a single byte from the USB CDC input buffer.
Returns:
int8_t: The byte read, or a negative value if no data is available.
MatrixOS::USB::CDC::ReadBytesβ
uint32_t USB::CDC::ReadBytes(void* buffer, uint32_t length);
Reads multiple bytes from the USB CDC input buffer into the provided buffer.
Parameters:
buffer(void*): The buffer to store the read data.length(uint32_t): The maximum number of bytes to read.
Returns:
uint32_t: The number of bytes actually read.
MatrixOS::USB::CDC::ReadStringβ
string USB::CDC::ReadString(void);
Reads a string from the USB CDC input buffer.
Returns:
string: The string read from the buffer.
Comments