Wixel SDK
|
#include <cc2511_types.h>
Go to the source code of this file.
Data Structures | |
union | USB_SETUP_PACKET |
struct | USB_DESCRIPTOR_DEVICE |
struct | USB_DESCRIPTOR_CONFIGURATION |
struct | USB_DESCRIPTOR_INTERFACE_ASSOCIATION |
struct | USB_DESCRIPTOR_INTERFACE |
struct | USB_DESCRIPTOR_ENDPOINT |
Macros | |
#define | USB_VENDOR_ID_POLOLU 0x1FFB |
#define | USB_EP0_PACKET_SIZE 32 |
#define | USB_REQUEST_GET_STATUS 0u |
#define | USB_REQUEST_CLEAR_FEATURE 1u |
#define | USB_REQUEST_SET_FEATURE 3u |
#define | USB_REQUEST_SET_ADDRESS 5u |
#define | USB_REQUEST_GET_DESCRIPTOR 6u |
#define | USB_REQUEST_SET_DESCRIPTOR 7u |
#define | USB_REQUEST_GET_CONFIGURATION 8u |
#define | USB_REQUEST_SET_CONFIGURATION 9u |
#define | USB_REQUEST_GET_INTERFACE 10u |
#define | USB_REQUEST_SET_INTERFACE 11u |
#define | USB_REQUEST_SYNCH_FRAME 12u |
#define | USB_REQUEST_TYPE_STANDARD 0u |
#define | USB_REQUEST_TYPE_CLASS 1u |
#define | USB_REQUEST_TYPE_VENDOR 2u |
#define | USB_RECIPIENT_DEVICE 0u |
#define | USB_RECIPIENT_INTERFACE 1u |
#define | USB_RECIPIENT_ENDPOINT 2u |
#define | USB_RECIPIENT_OTHER 3u |
#define | USB_DESCRIPTOR_TYPE_DEVICE 1u |
#define | USB_DESCRIPTOR_TYPE_CONFIGURATION 2u |
#define | USB_DESCRIPTOR_TYPE_STRING 3u |
#define | USB_DESCRIPTOR_TYPE_INTERFACE 4u |
#define | USB_DESCRIPTOR_TYPE_ENDPOINT 5u |
#define | USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 6u |
#define | USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 7u |
#define | USB_DESCRIPTOR_TYPE_INTERFACE_POWER 8u |
#define | USB_DESCRIPTOR_TYPE_ENDPOINT_CLASS_SPECIFIC 0x25u |
#define | USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION 0x0Bu |
#define | USB_FEATURE_DEVICE_REMOTE_WAKEUP 1u |
#define | USB_FEATURE_ENDPOINT_HALT 0u |
#define | USB_FEATURE_TEST_MODE 2u |
#define | USB_CONFIG_ATTR_DEFAULT (1<<7) |
#define | USB_CONFIG_ATTR_SELF_POWERED (1<<6) |
#define | USB_CONFIG_ATTR_REMOTE_WAKEUP (1<<5) |
#define | USB_OUT 0u |
#define | USB_IN 1u |
#define | USB_ENDPOINT_ADDRESS_IN 0x80 |
#define | USB_ENDPOINT_ADDRESS_OUT 0x00 |
#define | USB_TRANSFER_TYPE_CONTROL 0 |
#define | USB_TRANSFER_TYPE_ISOCHRONOUS 1 |
#define | USB_TRANSFER_TYPE_BULK 2 |
#define | USB_TRANSFER_TYPE_INTERRUPT 3 |
#define | USB_LANGUAGE_EN_US 0x0409 |
#define | USBCSOL_OUTPKT_RDY 0x01 |
#define | USBCSIL_INPKT_RDY 0x01 |
#define | USBCSIL_PKT_PRESENT 0x02 |
#define | DEFINE_STRING_DESCRIPTOR(name, char_count, ...) static uint16 CODE name[] = { (2*(char_count+1)) | (USB_DESCRIPTOR_TYPE_STRING<<8), __VA_ARGS__ }; |
Typedefs | |
typedef struct USB_DESCRIPTOR_DEVICE | USB_DESCRIPTOR_DEVICE |
typedef struct USB_DESCRIPTOR_CONFIGURATION | USB_DESCRIPTOR_CONFIGURATION |
typedef struct USB_DESCRIPTOR_INTERFACE_ASSOCIATION | USB_DESCRIPTOR_INTERFACE_ASSOCIATION |
typedef struct USB_DESCRIPTOR_INTERFACE | USB_DESCRIPTOR_INTERFACE |
typedef struct USB_DESCRIPTOR_ENDPOINT | USB_DESCRIPTOR_ENDPOINT |
Enumerations | |
enum | USB_DEVICE_STATES { USB_STATE_DETACHED = 0, USB_STATE_ATTACHED = 1, USB_STATE_POWERED = 2, USB_STATE_DEFAULT = 4, USB_STATE_ADDRESS = 8, USB_STATE_CONFIGURED = 16 } |
Functions | |
void | usbInit (void) |
void | usbPoll (void) |
void | usbControlRead (uint16 bytesCount, uint8 XDATA *source) |
void | usbControlWrite (uint16 bytesCount, uint8 XDATA *source) |
void | usbControlAcknowledge (void) |
void | usbControlStall (void) |
void | usbInitEndpointIn (uint8 endpointNumber, uint8 maxPacketSize) |
void | usbInitEndpointOut (uint8 endpointNumber, uint8 maxPacketSize) |
void | usbWriteFifo (uint8 endpointNumber, uint8 count, const uint8 XDATA *buffer) |
void | usbReadFifo (uint8 endpointNumber, uint8 count, uint8 XDATA *buffer) |
BIT | usbSuspended (void) |
void | usbSleep (void) |
void | usbShowStatusWithGreenLed (void) |
void | usbCallbackSetupHandler (void) |
void | usbCallbackClassDescriptorHandler (void) |
void | usbCallbackInitEndpoints (void) |
void | usbCallbackControlWriteHandler (void) |
Variables | |
enum USB_DEVICE_STATES XDATA | usbDeviceState |
USB_SETUP_PACKET XDATA | usbSetupPacket |
volatile BIT | usbSuspendMode |
volatile BIT | usbActivityFlag |
USB_DESCRIPTOR_DEVICE CODE | usbDeviceDescriptor |
uint8 CODE | usbStringDescriptorCount |
uint16 CODE *CODE | usbStringDescriptors [] |
The usb.lib
library takes care of setting up the USB module and responding to standard device requests. This is a general purpose library that can be used to implement many different kinds of USB device interfaces.
If you are looking for a simple way to send and receive bytes over USB, please see usb_com.h.
Many of the constants defined here come from the USB 2.0 Specification. In particular:
Definition in file usb.h.
#define DEFINE_STRING_DESCRIPTOR | ( | name, | |
char_count, | |||
... | |||
) | static uint16 CODE name[] = { (2*(char_count+1)) | (USB_DESCRIPTOR_TYPE_STRING<<8), __VA_ARGS__ }; |
Defines a new USB string descriptor.
name | The variable name to use for the string descriptor. |
char_count | The number of characters in the string. |
This macro evaluates to a line of C code that defines a static uint16 array in CODE space with the specified name.
See the usb_cdc_acm.c for an example use.
#define USB_EP0_PACKET_SIZE 32 |
#define USB_LANGUAGE_EN_US 0x0409 |
The USB language ID for English (US). It comes from http://www.usb.org/developers/docs/USB_LANGIDs.pdf
#define USB_VENDOR_ID_POLOLU 0x1FFB |
This is the Vendor ID assigned to Pololu Corporation by the USB Implementers Forum (USB-IF). For information on getting your own Vendor ID, see http://www.usb.org/developers/vendor/
typedef struct USB_DESCRIPTOR_CONFIGURATION USB_DESCRIPTOR_CONFIGURATION |
Standard Configuration Descriptor from USB Spec Table 9-10
typedef struct USB_DESCRIPTOR_DEVICE USB_DESCRIPTOR_DEVICE |
Standard Device Descriptor from USB Spec Table 9-8.
typedef struct USB_DESCRIPTOR_ENDPOINT USB_DESCRIPTOR_ENDPOINT |
Standard Endpoint Descriptor from USB Spec Table 9-13.
typedef struct USB_DESCRIPTOR_INTERFACE USB_DESCRIPTOR_INTERFACE |
Standard Interface Descriptor from USB Spec Table 9-12.
Interface Association Descriptor. This was defined in Engineering Change Notice (ECN) #7, Table 9-Z, not the USB specification.
enum USB_DEVICE_STATES |
void usbCallbackClassDescriptorHandler | ( | void | ) |
This is called by usbPoll() for certain Get Descriptor requests that are not supported by the USB library.
This callback is only called if bmRequest and bRequest indicate a standard Get Descriptor request, so there is no need to check those fields in this callback.
This function should read usbSetupPacket. If it recognizes the Get Descriptor request, it should call usbControlRead(). If it does not recognize the request, it should simply return. In this case, the USB library will respond to the host with a STALL packet.
This function must be defined by higher-level code. See usb_hid.c for an example.
Definition at line 271 of file usb_cdc_acm.c.
void usbCallbackControlWriteHandler | ( | void | ) |
This is called by usbPoll() when all the data for a Control Write request has been received.
This function should look at the data, perform any actions necessary, and decide whether the data was valid. If the data is invaild, this function can call usbControlStall() to reject the request.
Definition at line 281 of file usb_cdc_acm.c.
void usbCallbackInitEndpoints | ( | void | ) |
This is called by usbPoll() when the device enters the Configured state. This function should call usbInitEndpointIn() and usbInitEndpointOut() to initialize all the non-zero endpoints that it uses.
This function must be defined by higher-level code. See usb_cdc_acm.c for an example.
Definition at line 234 of file usb_cdc_acm.c.
void usbCallbackSetupHandler | ( | void | ) |
This is called by usbPoll() whenever a new request (SETUP packet) is received from the host that can not be handled by the USB library.
This function should read usbSetupPacket. If it recognizes the request from the host it should call usbControlRead(), usbControlWrite(), or usbControlAcknowledge(). If it does not recognize the request, it should simply return. In this case, the USB library will respond to the host with a STALL packet.
This function must be defined by higher-level code. See usb_cdc_acm.c for an example.
Definition at line 246 of file usb_cdc_acm.c.
void usbControlAcknowledge | ( | void | ) |
Tells the USB library to acknowledge the request. This is the right way to handle Control Write transfers with no data.
This should only be called from usbCallbackSetupHandler() or usbCallbackClassDescriptorHandler().
Tells the USB library to start a Control Read (Device-to-Host) transfer.
bytesCount | The number of bytes to send to the USB Host. |
source | A pointer to the first byte to send. |
This should only be called from usbCallbackSetupHandler() or usbCallbackClassDescriptorHandler().
void usbControlStall | ( | void | ) |
Tells the USB library that the request was invalid or failed, so it should respond to the host with STALL packet.
This should only be called from usbCallbackControlWriteHandler() in order to reject a Control Write transfer after the data has been received.
It can also be used in usbCallbackSetupHandler() or usbCallbackClassDescriptorHandler(), but it is not necessary in those callbacks because the default behavior of the library in that case is to stall.
Tells the USB library to start a Control Write (Host-to-Device) transfer.
bytesCount | The number of bytes to read from the host. |
source | A pointer to the location that the bytes will be written to. |
This should only be called from usbCallbackSetupHandler() or usbCallbackClassDescriptorHandler().
void usbInit | ( | void | ) |
Configures the specified endpoint to do double-buffered IN (device-to-host) transactions.
This should only be called from usbCallbackInitEndpoints().
Configures the specified endpoint to do double-buffered OUT (host-to-device) transactions.
This should only be called from usbCallbackInitEndpoints().
void usbPoll | ( | void | ) |
Reads data from a USB FIFO and writes to the specified memory buffer. This is equivalent to reading data from the FIFO register (e.g. USBF4) one byte at a time. Please refer to the CC2511 datasheet to understand when you can and can not read data from a USB FIFO.
void usbShowStatusWithGreenLed | ( | void | ) |
This function updates the green LED to reflect the current USB status. If you call this function frequently enough, then the green LED will exhibit these behaviors:
In order to make the flickering work properly, any library that directly reads or writes from USB FIFOs
Note: Calling this function will cause the USB library to have extra dependencies that it normally would not have, because this function accesses the system time and sets the green LED. You might get a linker error if those things are not available.
See usbActivityFlag for more information on the flickering.
Definition at line 13 of file green_led.c.
void usbSleep | ( | void | ) |
Sleeps until we receive USB resume signaling. Uses PM1.
Example usage:
BIT usbSuspended | ( | void | ) |
volatile BIT usbActivityFlag |
Libraries that directly access USB registers should set this bit to 1 whenever they read or write data from USB. This allows the USB led to flicker when there is USB activity. See usbShowStatusWithGreenLed() for more information.
Note: The USB HID library does not set this bit because that would result in constant flickering of the green LED in typical HID applications.
USB_DESCRIPTOR_DEVICE CODE usbDeviceDescriptor |
The device's Device Descriptor.
This must be defined by higher-level code. See usb_cdc_acm.c for an example.
Definition at line 109 of file usb_cdc_acm.c.
enum USB_DEVICE_STATES XDATA usbDeviceState |
The current USB Device State of this device.
Higher-level code should avoid reading or writing from non-zero USB endpoints if usbDeviceState is not USB_STATE_CONFIGURED because the non-zero endpoints are get initialized when the device enters the configured state.
USB_SETUP_PACKET XDATA usbSetupPacket |
The value of the last setup packet received from the host. It is useful to read this in usbCallbackSetupHandler(), usbCallbackControlWriteHandler(), and usbCallbackClassDescriptorHandler().
The number of string descriptors on this device.
This must be defined by higher-level code. See usb_cdc_acm.c for an example.
Definition at line 224 of file usb_cdc_acm.c.
An array of pointers to the string descriptors. The first entry corresponds to string descriptor 0 (the languages). The second entry corresponds to string descriptor 1, etc.
This must be defined by higher-level code. See usb_cdc_acm.c for an example.
Definition at line 228 of file usb_cdc_acm.c.
volatile BIT usbSuspendMode |
Direct access to this bit is provided for applications that need to use the P0 interrupt and want USB suspend mode to work. If you don't fall into that category, please don't use this bit directly: instead you should call usbSuspended() because that function is less likely to change in future versions. If you want to have a P0 interrupt AND USB Suspend, you should write your ISR like this:
If your P0 ISR does NOT clear usbSuspendMode, then your device will not be able to wake up out of suspend mode because when USB activity happens, your ISR will (if it's well-written) clear P0IFG so usbSleep won't be able to see that the P0IFG.USB_RESUME bit has been set, and it will keep on sleeping.