BeRTOS
Data Structures | Defines | Functions
usb.h File Reference

USB 2.0 standard descriptors. More...

#include <cpu/byteorder.h>

Go to the source code of this file.

Data Structures

struct  UsbCtrlRequest
 USB Control Request descriptor. More...
struct  UsbDescHeader
 USB common descriptor header. More...
struct  UsbDeviceDesc
 USB Device descriptor. More...
struct  UsbStringDesc
 USB string descriptor. More...
struct  UsbConfigDesc
 Device configuration descriptor. More...
struct  UsbInterfaceDesc
 Device interface descriptor. More...
struct  UsbEndpointDesc
 Endpoint descriptor. More...
struct  UsbDevice
 USB: generic device descriptor. More...

Defines

#define USB_STRING(...)   PP_CAT(USB_STRING_, PP_COUNT(__VA_ARGS__))(__VA_ARGS__)
 Pack a list with a variable number of elements into a UTF-16LE USB string.
#define DEFINE_USB_STRING(__name, __text)
 Define and initialize an USB string descriptor.

Functions

int usb_endpointNum (const UsbEndpointDesc *epd)
 Get the endpoint's address number of epd.
int usb_endpointType (const struct UsbEndpointDesc *epd)
 Get the transfer type of the endpoint epd.
int usb_endpointDirIn (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd has IN direction.
int usb_endpointDirOut (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd has OUT direction.
int usb_endpointXferBulk (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd has bulk transfer type.
int usb_endpointXferControl (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd has control transfer type.
int usb_endpointXferInt (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd has interrupt transfer type.
int usb_endpointXferIsoc (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd has isochronous transfer type.
int usb_endpointIsBulkIn (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd is bulk IN.
int usb_endpointIsBulkOut (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd is bulk OUT.
int usb_endpointIsIntIn (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd is interrupt IN.
int usb_endpointIsIntOut (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd is interrupt OUT.
int usb_endpointIsIsocIn (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd is isochronous IN.
int usb_endpointIsIsocOut (const struct UsbEndpointDesc *epd)
 Check if the endpoint epd is isochronous OUT.
ssize_t usb_endpointReadTimeout (int ep, void *buffer, ssize_t size, ticks_t timeout)
 Read up to size bytes from the USB endpoint identified by the address ep and store them in buffer.
ssize_t usb_endpointWriteTimeout (int ep, const void *buffer, ssize_t size, ticks_t timeout)
 Write up to size bytes from the buffer pointed buffer to the USB endpoint identified by the address ep.
int usb_deviceRegister (UsbDevice *dev)
 Register a generic USB device driver dev in the USB controller.

Detailed Description

USB 2.0 standard descriptors.

Author:
Andrea Righi <arighi@develer.com>

This file holds USB constants and structures that are needed for USB device APIs, as defined in the USB 2.0 specification.

Attention:
The API is work in progress and may change in future versions.

Definition in file usb.h.


Define Documentation

#define DEFINE_USB_STRING (   __name,
  __text 
)
Value:
struct {                            \
        UsbDescHeader __header;                 \
        uint8_t __body[sizeof(__text)];             \
    } PACKED __name = {                     \
        .__header = {                       \
            .bLength =                  \
                cpu_to_le16((uint16_t)sizeof(__name)),  \
            .bDescriptorType = USB_DT_STRING,       \
        },                          \
        .__body = {__text},                 \
    }

Define and initialize an USB string descriptor.

This macro is reuquired to properly declare and initialize a constant USB string in UTF-16LE format.

The structure must contain the standard common USB header (UsbDescHeader) and the UTF-16LE string all packed in a contiguous memory region.

Definition at line 234 of file usb.h.

#define USB_STRING (   ...)    PP_CAT(USB_STRING_, PP_COUNT(__VA_ARGS__))(__VA_ARGS__)

Pack a list with a variable number of elements into a UTF-16LE USB string.

Note:
The macro is recursively defined according the number of elements passed as argument. At the moment we support strings with up to 16 characters.

Definition at line 223 of file usb.h.


Function Documentation

ssize_t usb_endpointReadTimeout ( int  ep,
void *  buffer,
ssize_t  size,
ticks_t  timeout 
)

Read up to size bytes from the USB endpoint identified by the address ep and store them in buffer.

The timeout is an upper bound on the amount of time (in ticks) elapsed before returns. If timeout is zero, the the function returns immediatly and it basically works in non-blocking fashion. A negative value for timeout means that the function can block indefinitely.

Returns:
number of bytes actually read, or a negative value in case of errors.

Definition at line 1120 of file usb_stm32.c.

ssize_t usb_endpointWriteTimeout ( int  ep,
const void *  buffer,
ssize_t  size,
ticks_t  timeout 
)

Write up to size bytes from the buffer pointed buffer to the USB endpoint identified by the address ep.

The timeout is an upper bound on the amount of time (in ticks) elapsed before returns. If timeout is zero, the the function returns immediatly and it basically works in non-blocking fashion. A negative value for timeout means that the function can block indefinitely.

Returns:
number of bytes actually wrote, or a negative value in case of errors.

Definition at line 1179 of file usb_stm32.c.