Replace uint8_t with u8 et al, fix whitespace.

This commit is contained in:
Uwe Hermann 2010-12-29 17:28:06 +01:00
parent 6a16711bee
commit c39eb69e4d
14 changed files with 253 additions and 257 deletions

View File

@ -66,8 +66,8 @@ static const u8 hid_report_descriptor[] = {
static const struct { static const struct {
struct usb_hid_descriptor hid_descriptor; struct usb_hid_descriptor hid_descriptor;
struct { struct {
uint8_t bReportDescriptorType; u8 bReportDescriptorType;
uint16_t wDescriptorLength; u16 wDescriptorLength;
} __attribute__((packed)) hid_report; } __attribute__((packed)) hid_report;
} __attribute__((packed)) hid_function = { } __attribute__((packed)) hid_function = {
.hid_descriptor = { .hid_descriptor = {
@ -281,7 +281,7 @@ void sys_tick_handler(void)
{ {
static int x = 0; static int x = 0;
static int dir = 1; static int dir = 1;
uint8_t buf[4] = {0, 0, 0, 0}; u8 buf[4] = {0, 0, 0, 0};
buf[1] = dir; buf[1] = dir;
x += dir; x += dir;

View File

@ -124,7 +124,7 @@ static const u16 gamma_table_1_3[] = {
#endif #endif
#ifdef GAMMA_2_2 #ifdef GAMMA_2_2
static const uint16_t gamma_table_2_2[] = { static const u16 gamma_table_2_2[] = {
0, 0, 2, 4, 7, 11, 17, 24, 0, 0, 2, 4, 7, 11, 17, 24,
32, 42, 53, 65, 79, 94, 111, 129, 32, 42, 53, 65, 79, 94, 111, 129,
148, 169, 192, 216, 242, 270, 299, 330, 148, 169, 192, 216, 242, 270, 299, 330,

View File

@ -66,8 +66,8 @@ static const u8 hid_report_descriptor[] = {
static const struct { static const struct {
struct usb_hid_descriptor hid_descriptor; struct usb_hid_descriptor hid_descriptor;
struct { struct {
uint8_t bReportDescriptorType; u8 bReportDescriptorType;
uint16_t wDescriptorLength; u16 wDescriptorLength;
} __attribute__((packed)) hid_report; } __attribute__((packed)) hid_report;
} __attribute__((packed)) hid_function = { } __attribute__((packed)) hid_function = {
.hid_descriptor = { .hid_descriptor = {
@ -262,7 +262,7 @@ void sys_tick_handler(void)
{ {
static int x = 0; static int x = 0;
static int dir = 1; static int dir = 1;
uint8_t buf[4] = {0, 0, 0, 0}; u8 buf[4] = {0, 0, 0, 0};
buf[1] = dir; buf[1] = dir;
x += dir; x += dir;

View File

@ -66,8 +66,8 @@ static const u8 hid_report_descriptor[] = {
static const struct { static const struct {
struct usb_hid_descriptor hid_descriptor; struct usb_hid_descriptor hid_descriptor;
struct { struct {
uint8_t bReportDescriptorType; u8 bReportDescriptorType;
uint16_t wDescriptorLength; u16 wDescriptorLength;
} __attribute__((packed)) hid_report; } __attribute__((packed)) hid_report;
} __attribute__((packed)) hid_function = { } __attribute__((packed)) hid_function = {
.hid_descriptor = { .hid_descriptor = {
@ -262,7 +262,7 @@ void sys_tick_handler(void)
{ {
static int x = 0; static int x = 0;
static int dir = 1; static int dir = 1;
uint8_t buf[4] = {0, 0, 0, 0}; u8 buf[4] = {0, 0, 0, 0};
buf[1] = dir; buf[1] = dir;
x += dir; x += dir;

View File

@ -21,54 +21,54 @@
#define __CDC_H #define __CDC_H
/* Definitions of Communications Device Class from /* Definitions of Communications Device Class from
* "Universal Serial Bus Class Definitions for Communications Devices * "Universal Serial Bus Class Definitions for Communications Devices
* Revision 1.2" * Revision 1.2"
*/ */
/* Table 2: Communications Device Class Code */ /* Table 2: Communications Device Class Code */
#define USB_CLASS_CDC 0x02 #define USB_CLASS_CDC 0x02
/* Table 4: Class Subclass Code */ /* Table 4: Class Subclass Code */
#define USB_CDC_SUBCLASS_DLCM 0x01 #define USB_CDC_SUBCLASS_DLCM 0x01
#define USB_CDC_SUBCLASS_ACM 0x02 #define USB_CDC_SUBCLASS_ACM 0x02
/* ... */ /* ... */
/* Table 5 Communications Interface Class Control Protocol Codes */ /* Table 5 Communications Interface Class Control Protocol Codes */
#define USB_CDC_PROTOCOL_NONE 0x00 #define USB_CDC_PROTOCOL_NONE 0x00
#define USB_CDC_PROTOCOL_AT 0x01 #define USB_CDC_PROTOCOL_AT 0x01
/* ... */ /* ... */
/* Table 6: Data Interface Class Code */ /* Table 6: Data Interface Class Code */
#define USB_CLASS_DATA 0x0A #define USB_CLASS_DATA 0x0A
/* Table 12: Type Values for the bDescriptorType Field */ /* Table 12: Type Values for the bDescriptorType Field */
#define CS_INTERFACE 0x24 #define CS_INTERFACE 0x24
#define CS_ENDPOINT 0x25 #define CS_ENDPOINT 0x25
/* Table 13: bDescriptor SubType in Communications Class Functional /* Table 13: bDescriptor SubType in Communications Class Functional
* Descriptors */ * Descriptors */
#define USB_CDC_TYPE_HEADER 0x00 #define USB_CDC_TYPE_HEADER 0x00
#define USB_CDC_TYPE_CALL_MANAGEMENT 0x01 #define USB_CDC_TYPE_CALL_MANAGEMENT 0x01
#define USB_CDC_TYPE_ACM 0x02 #define USB_CDC_TYPE_ACM 0x02
/* ... */ /* ... */
#define USB_CDC_TYPE_UNION 0x06 #define USB_CDC_TYPE_UNION 0x06
/* ... */ /* ... */
/* Table 15: Class-Specific Descriptor Header Format */ /* Table 15: Class-Specific Descriptor Header Format */
struct usb_cdc_header_descriptor { struct usb_cdc_header_descriptor {
uint8_t bFunctionLength; u8 bFunctionLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint8_t bDescriptorSubtype; u8 bDescriptorSubtype;
uint16_t bcdCDC; u16 bcdCDC;
} __attribute__((packed)); } __attribute__((packed));
/* Table 16: Union Interface Functional Descriptor */ /* Table 16: Union Interface Functional Descriptor */
struct usb_cdc_union_descriptor { struct usb_cdc_union_descriptor {
uint8_t bFunctionLength; u8 bFunctionLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint8_t bDescriptorSubtype; u8 bDescriptorSubtype;
uint8_t bControlInterface; u8 bControlInterface;
uint8_t bSubordinateInterface0; u8 bSubordinateInterface0;
/* ... */ /* ... */
} __attribute__((packed)); } __attribute__((packed));
@ -80,19 +80,19 @@ struct usb_cdc_union_descriptor {
/* Table 3: Call Management Functional Descriptor */ /* Table 3: Call Management Functional Descriptor */
struct usb_cdc_call_management_descriptor { struct usb_cdc_call_management_descriptor {
uint8_t bFunctionLength; u8 bFunctionLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint8_t bDescriptorSubtype; u8 bDescriptorSubtype;
uint8_t bmCapabilities; u8 bmCapabilities;
uint8_t bDataInterface; u8 bDataInterface;
} __attribute__((packed)); } __attribute__((packed));
/* Table 4: Abstract Control Management Functional Descriptor */ /* Table 4: Abstract Control Management Functional Descriptor */
struct usb_cdc_acm_descriptor { struct usb_cdc_acm_descriptor {
uint8_t bFunctionLength; u8 bFunctionLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint8_t bDescriptorSubtype; u8 bDescriptorSubtype;
uint8_t bmCapabilities; u8 bmCapabilities;
} __attribute__((packed)); } __attribute__((packed));
/* Table 13: Class-Specific Request Codes for PSTN subclasses */ /* Table 13: Class-Specific Request Codes for PSTN subclasses */
@ -104,10 +104,10 @@ struct usb_cdc_acm_descriptor {
/* Table 17: Line Coding Structure */ /* Table 17: Line Coding Structure */
struct usb_cdc_line_coding { struct usb_cdc_line_coding {
uint32_t dwDTERate; u32 dwDTERate;
uint8_t bCharFormat; u8 bCharFormat;
uint8_t bParityType; u8 bParityType;
uint8_t bDataBits; u8 bDataBits;
} __attribute__((packed)); } __attribute__((packed));
/* Table 30: Class-Specific Notification Codes for PSTN subclasses */ /* Table 30: Class-Specific Notification Codes for PSTN subclasses */
@ -115,14 +115,13 @@ struct usb_cdc_line_coding {
#define USB_CDC_NOTIFY_SERIAL_STATE 0x28 #define USB_CDC_NOTIFY_SERIAL_STATE 0x28
/* ... */ /* ... */
/* Notification Structure */ /* Notification Structure */
struct usb_cdc_notification { struct usb_cdc_notification {
uint8_t bmRequestType; u8 bmRequestType;
uint8_t bNotification; u8 bNotification;
uint16_t wValue; u16 wValue;
uint16_t wIndex; u16 wIndex;
uint16_t wLength; u16 wLength;
} __attribute__((packed)); } __attribute__((packed));
#endif #endif

View File

@ -27,7 +27,7 @@ enum dfu_req {
DFU_GETSTATUS, DFU_GETSTATUS,
DFU_CLRSTATUS, DFU_CLRSTATUS,
DFU_GETSTATE, DFU_GETSTATE,
DFU_ABORT DFU_ABORT,
}; };
enum dfu_status { enum dfu_status {
@ -65,17 +65,17 @@ enum dfu_state {
#define DFU_FUNCTIONAL 0x21 #define DFU_FUNCTIONAL 0x21
struct usb_dfu_descriptor { struct usb_dfu_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint8_t bmAttributes; u8 bmAttributes;
#define USB_DFU_CAN_DOWNLOAD 0x01 #define USB_DFU_CAN_DOWNLOAD 0x01
#define USB_DFU_CAN_UPLOAD 0x02 #define USB_DFU_CAN_UPLOAD 0x02
#define USB_DFU_MANIFEST_TOLERANT 0x04 #define USB_DFU_MANIFEST_TOLERANT 0x04
#define USB_DFU_WILL_DETACH 0x08 #define USB_DFU_WILL_DETACH 0x08
uint16_t wDetachTimeout; u16 wDetachTimeout;
uint16_t wTransferSize; u16 wTransferSize;
uint16_t bcdDFUVersion; u16 bcdDFUVersion;
} __attribute__((packed)); } __attribute__((packed));
#endif #endif

View File

@ -28,11 +28,11 @@
#define USB_DT_REPORT 0x22 #define USB_DT_REPORT 0x22
struct usb_hid_descriptor { struct usb_hid_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint16_t bcdHID; u16 bcdHID;
uint8_t bCountryCode; u8 bCountryCode;
uint8_t bNumDescriptors; u8 bNumDescriptors;
} __attribute__((packed)); } __attribute__((packed));
#endif #endif

View File

@ -25,47 +25,42 @@
/* Static buffer for control transactions: /* Static buffer for control transactions:
* This is defined as weak in the library, applicaiton * This is defined as weak in the library, applicaiton
* may provide if a larger buffer is requred. */ * may provide if a larger buffer is requred. */
extern uint8_t usbd_control_buffer[]; extern u8 usbd_control_buffer[];
/* <usb.c> */ /* <usb.c> */
extern int usbd_init(const struct usb_device_descriptor *dev, extern int usbd_init(const struct usb_device_descriptor *dev,
const struct usb_config_descriptor *conf, const struct usb_config_descriptor *conf,
const char **strings); const char **strings);
extern void usbd_set_control_buffer_size(uint16_t size); extern void usbd_set_control_buffer_size(u16 size);
extern void usbd_register_reset_callback(void (*callback)(void)); extern void usbd_register_reset_callback(void (*callback)(void));
extern void usbd_register_suspend_callback(void (*callback)(void)); extern void usbd_register_suspend_callback(void (*callback)(void));
extern void usbd_register_resume_callback(void (*callback)(void)); extern void usbd_register_resume_callback(void (*callback)(void));
typedef int (*usbd_control_callback)(struct usb_setup_data *req, typedef int (*usbd_control_callback)(struct usb_setup_data *req, u8 **buf,
uint8_t **buf, uint16_t *len, u16 *len, void (**complete)(struct usb_setup_data *req));
void (**complete)(struct usb_setup_data *req));
/* <usb_control.c> */ /* <usb_control.c> */
extern int usbd_register_control_callback(uint8_t type, uint8_t type_mask, extern int usbd_register_control_callback(u8 type, u8 type_mask,
usbd_control_callback callback); usbd_control_callback callback);
/* <usb_standard.c> */ /* <usb_standard.c> */
extern void extern void usbd_register_set_config_callback(void (*callback)(u16 wValue));
usbd_register_set_config_callback(void (*callback)(uint16_t wValue));
/* Functions to be provided by the hardware abstraction layer */ /* Functions to be provided by the hardware abstraction layer */
extern void usbd_poll(void); extern void usbd_poll(void);
extern void usbd_ep_setup(uint8_t addr, uint8_t type, uint16_t max_size, extern void usbd_ep_setup(u8 addr, u8 type, u16 max_size,
void (*callback)(uint8_t ep)); void (*callback)(u8 ep));
extern uint16_t extern u16 usbd_ep_write_packet(u8 addr, const void *buf, u16 len);
usbd_ep_write_packet(uint8_t addr, const void *buf, uint16_t len);
extern uint16_t extern u16 usbd_ep_read_packet(u8 addr, void *buf, u16 len);
usbd_ep_read_packet(uint8_t addr, void *buf, uint16_t len);
extern void usbd_ep_stall_set(uint8_t addr, uint8_t stall); extern void usbd_ep_stall_set(u8 addr, u8 stall);
extern uint8_t usbd_ep_stall_get(uint8_t addr); extern u8 usbd_ep_stall_get(u8 addr);
/* Optional */ /* Optional */
extern void usbd_cable_connect(uint8_t on); extern void usbd_cable_connect(u8 on);
#endif #endif

View File

@ -20,183 +20,185 @@
#ifndef __USBSTD_H #ifndef __USBSTD_H
#define __USBSTD_H #define __USBSTD_H
/* #include <stdint.h>
#include <libopenstm32/common.h> /* TODO: Move elsewhere? */
/*
* This file contains structure definitions for the USB control structures * This file contains structure definitions for the USB control structures
* defined in chapter 9 of the "Univeral Serial Bus Specification Revision 2.0" * defined in chapter 9 of the "Univeral Serial Bus Specification Revision 2.0"
* Available from the USB Implementers Forum - http://www.usb.org/ * Available from the USB Implementers Forum - http://www.usb.org/
*/ */
#include <stdint.h>
/* USB Setup Data structure - Table 9-2 */ /* USB Setup Data structure - Table 9-2 */
struct usb_setup_data { struct usb_setup_data {
uint8_t bmRequestType; u8 bmRequestType;
uint8_t bRequest; u8 bRequest;
uint16_t wValue; u16 wValue;
uint16_t wIndex; u16 wIndex;
uint16_t wLength; u16 wLength;
} __attribute__((packed)); } __attribute__((packed));
/* bmRequestType bit definitions */ /* bmRequestType bit definitions */
#define USB_REQ_TYPE_IN 0x80 #define USB_REQ_TYPE_IN 0x80
#define USB_REQ_TYPE_STANDARD 0x00 #define USB_REQ_TYPE_STANDARD 0x00
#define USB_REQ_TYPE_CLASS 0x20 #define USB_REQ_TYPE_CLASS 0x20
#define USB_REQ_TYPE_VENDOR 0x40 #define USB_REQ_TYPE_VENDOR 0x40
#define USB_REQ_TYPE_DEVICE 0x00 #define USB_REQ_TYPE_DEVICE 0x00
#define USB_REQ_TYPE_INTERFACE 0x01 #define USB_REQ_TYPE_INTERFACE 0x01
#define USB_REQ_TYPE_ENDPOINT 0x02 #define USB_REQ_TYPE_ENDPOINT 0x02
#define USB_REQ_TYPE_DIRECTION 0x80 #define USB_REQ_TYPE_DIRECTION 0x80
#define USB_REQ_TYPE_TYPE 0x60 #define USB_REQ_TYPE_TYPE 0x60
#define USB_REQ_TYPE_RECIPIENT 0x1F #define USB_REQ_TYPE_RECIPIENT 0x1F
/* USB Standard Request Codes - Table 9-4 */ /* USB Standard Request Codes - Table 9-4 */
#define USB_REQ_GET_STATUS 0 #define USB_REQ_GET_STATUS 0
#define USB_REQ_CLEAR_FEATURE 1 #define USB_REQ_CLEAR_FEATURE 1
/* Reserved for future use: 2 */ /* Reserved for future use: 2 */
#define USB_REQ_SET_FEATURE 3 #define USB_REQ_SET_FEATURE 3
/* Reserved for future use: 3 */ /* Reserved for future use: 3 */
#define USB_REQ_SET_ADDRESS 5 #define USB_REQ_SET_ADDRESS 5
#define USB_REQ_GET_DESCRIPTOR 6 #define USB_REQ_GET_DESCRIPTOR 6
#define USB_REQ_SET_DESCRIPTOR 7 #define USB_REQ_SET_DESCRIPTOR 7
#define USB_REQ_GET_CONFIGURATION 8 #define USB_REQ_GET_CONFIGURATION 8
#define USB_REQ_SET_CONFIGURATION 9 #define USB_REQ_SET_CONFIGURATION 9
#define USB_REQ_GET_INTERFACE 10 #define USB_REQ_GET_INTERFACE 10
#define USB_REQ_SET_INTERFACE 11 #define USB_REQ_SET_INTERFACE 11
#define USB_REQ_SET_SYNCH_FRAME 12 #define USB_REQ_SET_SYNCH_FRAME 12
/* USB Descriptor Types - Table 9-5 */ /* USB Descriptor Types - Table 9-5 */
#define USB_DT_DEVICE 1 #define USB_DT_DEVICE 1
#define USB_DT_CONFIGURATION 2 #define USB_DT_CONFIGURATION 2
#define USB_DT_STRING 3 #define USB_DT_STRING 3
#define USB_DT_INTERFACE 4 #define USB_DT_INTERFACE 4
#define USB_DT_ENDPOINT 5 #define USB_DT_ENDPOINT 5
#define USB_DT_DEVICE_QUALIFIER 6 #define USB_DT_DEVICE_QUALIFIER 6
#define USB_DT_OTHER_SPEED_CONFIGURATION 7 #define USB_DT_OTHER_SPEED_CONFIGURATION 7
#define USB_DT_INTERFACE_POWER 8 #define USB_DT_INTERFACE_POWER 8
/* USB Standard Feature Selectors - Table 9-6 */ /* USB Standard Feature Selectors - Table 9-6 */
#define USB_FEAT_ENDPOINT_HALT 0 #define USB_FEAT_ENDPOINT_HALT 0
#define USB_FEAT_DEVICE_REMOTE_WAKEUP 1 #define USB_FEAT_DEVICE_REMOTE_WAKEUP 1
#define USB_FEAT_TEST_MODE 2 #define USB_FEAT_TEST_MODE 2
/* Information Returned by a GetStatus() Request to a Device - Figure 9-4 */ /* Information Returned by a GetStatus() Request to a Device - Figure 9-4 */
#define USB_DEV_STATUS_SELF_POWERED 0x01 #define USB_DEV_STATUS_SELF_POWERED 0x01
#define USB_DEV_STATUS_REMOTE_WAKEUP 0x02 #define USB_DEV_STATUS_REMOTE_WAKEUP 0x02
/* USB Standard Device Descriptor - Table 9-8 */ /* USB Standard Device Descriptor - Table 9-8 */
struct usb_device_descriptor { struct usb_device_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint16_t bcdUSB; u16 bcdUSB;
uint8_t bDeviceClass; u8 bDeviceClass;
uint8_t bDeviceSubClass; u8 bDeviceSubClass;
uint8_t bDeviceProtocol; u8 bDeviceProtocol;
uint8_t bMaxPacketSize0; u8 bMaxPacketSize0;
uint16_t idVendor; u16 idVendor;
uint16_t idProduct; u16 idProduct;
uint16_t bcdDevice; u16 bcdDevice;
uint8_t iManufacturer; u8 iManufacturer;
uint8_t iProduct; u8 iProduct;
uint8_t iSerialNumber; u8 iSerialNumber;
uint8_t bNumConfigurations; u8 bNumConfigurations;
} __attribute__((packed)); } __attribute__((packed));
#define USB_DT_DEVICE_SIZE sizeof(struct usb_device_descriptor)
/* USB Device_Qualifier Descriptor - Table 9-9 #define USB_DT_DEVICE_SIZE sizeof(struct usb_device_descriptor)
* Not used in this implementation.
/* USB Device_Qualifier Descriptor - Table 9-9
* Not used in this implementation.
*/ */
struct usb_device_qualifier_descriptor { struct usb_device_qualifier_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint16_t bcdUSB; u16 bcdUSB;
uint8_t bDeviceClass; u8 bDeviceClass;
uint8_t bDeviceSubClass; u8 bDeviceSubClass;
uint8_t bDeviceProtocol; u8 bDeviceProtocol;
uint8_t bMaxPacketSize0; u8 bMaxPacketSize0;
uint8_t bNumConfigurations; u8 bNumConfigurations;
uint8_t bReserved; u8 bReserved;
} __attribute__((packed)); } __attribute__((packed));
/* USB Standard Configuration Descriptor - Table 9-10 */ /* USB Standard Configuration Descriptor - Table 9-10 */
struct usb_config_descriptor { struct usb_config_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint16_t wTotalLength; u16 wTotalLength;
uint8_t bNumInterfaces; u8 bNumInterfaces;
uint8_t bConfigurationValue; u8 bConfigurationValue;
uint8_t iConfiguration; u8 iConfiguration;
uint8_t bmAttributes; u8 bmAttributes;
uint8_t bMaxPower; u8 bMaxPower;
/* Descriptor ends here. The following are used internally: */ /* Descriptor ends here. The following are used internally: */
const struct usb_interface { const struct usb_interface {
int num_altsetting; int num_altsetting;
const struct usb_interface_descriptor *altsetting; const struct usb_interface_descriptor *altsetting;
} *interface; } *interface;
} __attribute__((packed)); } __attribute__((packed));
#define USB_DT_CONFIGURATION_SIZE 9 #define USB_DT_CONFIGURATION_SIZE 9
/* USB Configuration Descriptor bmAttributes bit definitions */ /* USB Configuration Descriptor bmAttributes bit definitions */
#define USB_CONFIG_ATTR_SELF_POWERED 0x40 #define USB_CONFIG_ATTR_SELF_POWERED 0x40
#define USB_CONFIG_ATTR_REMOTE_WAKEUP 0x20 #define USB_CONFIG_ATTR_REMOTE_WAKEUP 0x20
/* Other Speed Configuration is the same as Configuration Descriptor. /* Other Speed Configuration is the same as Configuration Descriptor.
* - Table 9-11 * - Table 9-11
*/ */
/* USB Standard Interface Descriptor - Table 9-12 */ /* USB Standard Interface Descriptor - Table 9-12 */
struct usb_interface_descriptor { struct usb_interface_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint8_t bInterfaceNumber; u8 bInterfaceNumber;
uint8_t bAlternateSetting; u8 bAlternateSetting;
uint8_t bNumEndpoints; u8 bNumEndpoints;
uint8_t bInterfaceClass; u8 bInterfaceClass;
uint8_t bInterfaceSubClass; u8 bInterfaceSubClass;
uint8_t bInterfaceProtocol; u8 bInterfaceProtocol;
uint8_t iInterface; u8 iInterface;
/* Descriptor ends here. The following are used internally: */ /* Descriptor ends here. The following are used internally: */
const struct usb_endpoint_descriptor *endpoint; const struct usb_endpoint_descriptor *endpoint;
const void *extra; const void *extra;
int extralen; int extralen;
} __attribute__((packed)); } __attribute__((packed));
#define USB_DT_INTERFACE_SIZE 9 #define USB_DT_INTERFACE_SIZE 9
/* USB Standard Endpoint Descriptor - Table 9-13 */ /* USB Standard Endpoint Descriptor - Table 9-13 */
struct usb_endpoint_descriptor { struct usb_endpoint_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint8_t bEndpointAddress; u8 bEndpointAddress;
uint8_t bmAttributes; u8 bmAttributes;
uint16_t wMaxPacketSize; u16 wMaxPacketSize;
uint8_t bInterval; u8 bInterval;
} __attribute__((packed)); } __attribute__((packed));
#define USB_DT_ENDPOINT_SIZE sizeof(struct usb_endpoint_descriptor) #define USB_DT_ENDPOINT_SIZE sizeof(struct usb_endpoint_descriptor)
/* USB Endpoint Descriptor bmAttributes bit definitions */ /* USB Endpoint Descriptor bmAttributes bit definitions */
#define USB_ENDPOINT_ATTR_CONTROL 0x00 #define USB_ENDPOINT_ATTR_CONTROL 0x00
#define USB_ENDPOINT_ATTR_ISOCHRONOUS 0x01 #define USB_ENDPOINT_ATTR_ISOCHRONOUS 0x01
#define USB_ENDPOINT_ATTR_BULK 0x02 #define USB_ENDPOINT_ATTR_BULK 0x02
#define USB_ENDPOINT_ATTR_INTERRUPT 0x03 #define USB_ENDPOINT_ATTR_INTERRUPT 0x03
#define USB_ENDPOINT_ATTR_NOSYNC 0x00 #define USB_ENDPOINT_ATTR_NOSYNC 0x00
#define USB_ENDPOINT_ATTR_ASYNC 0x04 #define USB_ENDPOINT_ATTR_ASYNC 0x04
#define USB_ENDPOINT_ATTR_ADAPTIVE 0x08 #define USB_ENDPOINT_ATTR_ADAPTIVE 0x08
#define USB_ENDPOINT_ATTR_SYNC 0x0C #define USB_ENDPOINT_ATTR_SYNC 0x0C
#define USB_ENDPOINT_ATTR_DATA 0x00 #define USB_ENDPOINT_ATTR_DATA 0x00
#define USB_ENDPOINT_ATTR_FEEDBACK 0x10 #define USB_ENDPOINT_ATTR_FEEDBACK 0x10
#define USB_ENDPOINT_ATTR_IMPLICIT_FEEDBACK_DATA 0x20 #define USB_ENDPOINT_ATTR_IMPLICIT_FEEDBACK_DATA 0x20
/* Table 9-15 specifies String Descriptor Zero. /* Table 9-15 specifies String Descriptor Zero.
* Table 9-16 specified UNICODE String Descriptor. * Table 9-16 specified UNICODE String Descriptor.
*/ */
struct usb_string_descriptor { struct usb_string_descriptor {
uint8_t bLength; u8 bLength;
uint8_t bDescriptorType; u8 bDescriptorType;
uint16_t wData[]; u16 wData[];
} __attribute__((packed)); } __attribute__((packed));
#endif #endif

View File

@ -23,7 +23,7 @@
struct _usbd_device _usbd_device; struct _usbd_device _usbd_device;
uint8_t usbd_control_buffer[128] __attribute__((weak)); u8 usbd_control_buffer[128] __attribute__((weak));
/** Main initialization entry point. /** Main initialization entry point.
* *
@ -77,7 +77,7 @@ void usbd_register_resume_callback(void (*callback)(void))
_usbd_device.user_callback_resume = callback; _usbd_device.user_callback_resume = callback;
} }
void usbd_set_control_buffer_size(uint16_t size) void usbd_set_control_buffer_size(u16 size)
{ {
_usbd_device.ctrl_buf_len = size; _usbd_device.ctrl_buf_len = size;
} }

View File

@ -29,15 +29,15 @@ static struct usb_control_state {
struct usb_setup_data req; struct usb_setup_data req;
uint8_t *ctrl_buf; u8 *ctrl_buf;
uint16_t ctrl_len; u16 ctrl_len;
void (*complete)(struct usb_setup_data *req); void (*complete)(struct usb_setup_data *req);
} control_state; } control_state;
/** Register application callback function for handling of usb control /** Register application callback function for handling of usb control
* request. */ * request. */
int usbd_register_control_callback(uint8_t type, uint8_t type_mask, int usbd_register_control_callback(u8 type, u8 type_mask,
usbd_control_callback callback) usbd_control_callback callback)
{ {
int i; int i;
@ -76,10 +76,10 @@ static void usb_control_send_chunk(void)
static int usb_control_recv_chunk(void) static int usb_control_recv_chunk(void)
{ {
uint16_t packetsize = MIN(_usbd_device.desc->bMaxPacketSize0, u16 packetsize = MIN(_usbd_device.desc->bMaxPacketSize0,
control_state.req.wLength - control_state.req.wLength -
control_state.ctrl_len); control_state.ctrl_len);
uint16_t size = usbd_ep_read_packet(0, u16 size = usbd_ep_read_packet(0,
control_state.ctrl_buf + control_state.ctrl_len, control_state.ctrl_buf + control_state.ctrl_len,
packetsize); packetsize);
@ -156,7 +156,7 @@ static void usb_control_setup_write(struct usb_setup_data *req)
else control_state.state = LAST_DATA_OUT; else control_state.state = LAST_DATA_OUT;
} }
void _usbd_control_setup(uint8_t ea) void _usbd_control_setup(u8 ea)
{ {
struct usb_setup_data *req = &control_state.req; struct usb_setup_data *req = &control_state.req;
(void)ea; (void)ea;
@ -177,7 +177,7 @@ void _usbd_control_setup(uint8_t ea)
} }
} }
void _usbd_control_out(uint8_t ea) void _usbd_control_out(u8 ea)
{ {
(void)ea; (void)ea;
@ -221,7 +221,7 @@ void _usbd_control_out(uint8_t ea)
} }
} }
void _usbd_control_in(uint8_t ea) void _usbd_control_in(u8 ea)
{ {
(void)ea; (void)ea;
switch(control_state.state) { switch(control_state.state) {

View File

@ -153,10 +153,10 @@ u8 usbd_ep_stall_get(u8 addr)
* @param len Number of bytes to copy. * @param len Number of bytes to copy.
*/ */
static inline void static inline void
usb_copy_to_pm(volatile void *vPM, const void *buf, uint16_t len) usb_copy_to_pm(volatile void *vPM, const void *buf, u16 len)
{ {
const uint16_t *lbuf = buf; const u16 *lbuf = buf;
volatile uint16_t *PM = vPM; volatile u16 *PM = vPM;
for(len = (len + 1) >> 1; len; PM += 2, lbuf++, len--) for(len = (len + 1) >> 1; len; PM += 2, lbuf++, len--)
*PM = *lbuf; *PM = *lbuf;
@ -182,16 +182,16 @@ u16 usbd_ep_write_packet(u8 addr, const void *buf, u16 len)
* @param len Number of bytes to copy. * @param len Number of bytes to copy.
*/ */
static inline void static inline void
usb_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len) usb_copy_from_pm(void *buf, const volatile void *vPM, u16 len)
{ {
uint16_t *lbuf = buf; u16 *lbuf = buf;
const volatile uint16_t *PM = vPM; const volatile u16 *PM = vPM;
uint8_t odd = len & 1; u8 odd = len & 1;
for(len >>= 1; len; PM += 2, lbuf++, len--) for(len >>= 1; len; PM += 2, lbuf++, len--)
*lbuf = *PM; *lbuf = *PM;
if(odd) *(uint8_t*)lbuf = *(uint8_t*)PM; if(odd) *(u8*)lbuf = *(u8*)PM;
} }
u16 usbd_ep_read_packet(u8 addr, void *buf, u16 len) u16 usbd_ep_read_packet(u8 addr, void *buf, u16 len)

View File

@ -30,13 +30,13 @@ extern struct _usbd_device {
const struct usb_config_descriptor *config; const struct usb_config_descriptor *config;
const char **strings; const char **strings;
uint8_t *ctrl_buf; /**< Internal buffer used for control transfers */ u8 *ctrl_buf; /**< Internal buffer used for control transfers */
uint16_t ctrl_buf_len; u16 ctrl_buf_len;
uint8_t current_address; u8 current_address;
uint8_t current_config; u8 current_config;
uint16_t pm_top; /**< Top of allocated endpoint buffer memory */ u16 pm_top; /**< Top of allocated endpoint buffer memory */
/* User callback functions for various USB events */ /* User callback functions for various USB events */
void (*user_callback_reset)(void); void (*user_callback_reset)(void);
@ -45,14 +45,14 @@ extern struct _usbd_device {
struct user_control_callback { struct user_control_callback {
usbd_control_callback cb; usbd_control_callback cb;
uint8_t type; u8 type;
uint8_t type_mask; u8 type_mask;
} user_control_callback[MAX_USER_CONTROL_CALLBACK]; } user_control_callback[MAX_USER_CONTROL_CALLBACK];
void (*user_callback_ctr[8][3])(uint8_t ea); void (*user_callback_ctr[8][3])(u8 ea);
/* User callback function for some standard USB function hooks */ /* User callback function for some standard USB function hooks */
void (*user_callback_set_config)(uint16_t wValue); void (*user_callback_set_config)(u16 wValue);
} _usbd_device; } _usbd_device;
enum _usbd_transaction { enum _usbd_transaction {
@ -61,18 +61,18 @@ enum _usbd_transaction {
USB_TRANSACTION_SETUP, USB_TRANSACTION_SETUP,
}; };
void _usbd_control_in(uint8_t ea); void _usbd_control_in(u8 ea);
void _usbd_control_out(uint8_t ea); void _usbd_control_out(u8 ea);
void _usbd_control_setup(uint8_t ea); void _usbd_control_setup(u8 ea);
int _usbd_standard_request(struct usb_setup_data *req, int _usbd_standard_request(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len); u8 **buf, u16 *len);
void _usbd_reset(void); void _usbd_reset(void);
/* Functions provided by the hardware abstraction */ /* Functions provided by the hardware abstraction */
void _usbd_hw_init(void); void _usbd_hw_init(void);
void _usbd_hw_set_address(uint8_t addr); void _usbd_hw_set_address(u8 addr);
void _usbd_hw_endpoints_reset(void); void _usbd_hw_endpoints_reset(void);
#endif #endif

View File

@ -21,18 +21,18 @@
#include <usb/usbd.h> #include <usb/usbd.h>
#include "usb_private.h" #include "usb_private.h"
void usbd_register_set_config_callback(void (*callback)(uint16_t wValue)) void usbd_register_set_config_callback(void (*callback)(u16 wValue))
{ {
_usbd_device.user_callback_set_config = callback; _usbd_device.user_callback_set_config = callback;
} }
static uint16_t static u16
build_config_descriptor(uint8_t index, uint8_t *buf, uint16_t len) build_config_descriptor(u8 index, u8 *buf, u16 len)
{ {
uint8_t *tmpbuf = buf; u8 *tmpbuf = buf;
const struct usb_config_descriptor *cfg = &_usbd_device.config[index]; const struct usb_config_descriptor *cfg = &_usbd_device.config[index];
uint16_t count, total = 0, totallen = 0; u16 count, total = 0, totallen = 0;
uint16_t i, j, k; u16 i, j, k;
memcpy(buf, cfg, count = MIN(len, cfg->bLength)); memcpy(buf, cfg, count = MIN(len, cfg->bLength));
buf += count; len -= count; total += count; totallen += cfg->bLength; buf += count; len -= count; total += count; totallen += cfg->bLength;
@ -64,19 +64,19 @@ build_config_descriptor(uint8_t index, uint8_t *buf, uint16_t len)
} }
/* Fill in wTotalLength */ /* Fill in wTotalLength */
*(uint16_t*)(tmpbuf+2) = totallen; *(u16*)(tmpbuf+2) = totallen;
return total; return total;
} }
static int usb_standard_get_descriptor(struct usb_setup_data *req, static int usb_standard_get_descriptor(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
int i; int i;
switch(req->wValue >> 8) { switch(req->wValue >> 8) {
case USB_DT_DEVICE: case USB_DT_DEVICE:
*buf = (uint8_t *)_usbd_device.desc; *buf = (u8 *)_usbd_device.desc;
*len = MIN(*len, _usbd_device.desc->bLength); *len = MIN(*len, _usbd_device.desc->bLength);
return 1; return 1;
@ -97,7 +97,7 @@ static int usb_standard_get_descriptor(struct usb_setup_data *req,
* 2 + 2; * 2 + 2;
sd->bDescriptorType = USB_DT_STRING; sd->bDescriptorType = USB_DT_STRING;
*buf = (uint8_t *)sd; *buf = (u8 *)sd;
*len = MIN(*len, sd->bLength); *len = MIN(*len, sd->bLength);
for(i = 0; i < (*len / 2) - 1; i++) for(i = 0; i < (*len / 2) - 1; i++)
@ -115,7 +115,7 @@ static int usb_standard_get_descriptor(struct usb_setup_data *req,
} }
static int usb_standard_set_address(struct usb_setup_data *req, static int usb_standard_set_address(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
(void)buf; (void)buf;
@ -130,7 +130,7 @@ static int usb_standard_set_address(struct usb_setup_data *req,
} }
static int usb_standard_set_configuration(struct usb_setup_data *req, static int usb_standard_set_configuration(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
(void)buf; (void)buf;
@ -151,7 +151,7 @@ static int usb_standard_set_configuration(struct usb_setup_data *req,
} }
static int usb_standard_get_configuration(struct usb_setup_data *req, static int usb_standard_get_configuration(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
@ -162,7 +162,7 @@ static int usb_standard_get_configuration(struct usb_setup_data *req,
} }
static int usb_standard_set_interface(struct usb_setup_data *req, static int usb_standard_set_interface(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
(void)buf; (void)buf;
@ -175,7 +175,7 @@ static int usb_standard_set_interface(struct usb_setup_data *req,
} }
static int usb_standard_get_interface(struct usb_setup_data *req, static int usb_standard_get_interface(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
(void)buf; (void)buf;
@ -188,7 +188,7 @@ static int usb_standard_get_interface(struct usb_setup_data *req,
} }
static int usb_standard_device_get_status(struct usb_setup_data *req, static int usb_standard_device_get_status(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
/* bit 0: self powered */ /* bit 0: self powered */
@ -201,7 +201,7 @@ static int usb_standard_device_get_status(struct usb_setup_data *req,
} }
static int usb_standard_interface_get_status(struct usb_setup_data *req, static int usb_standard_interface_get_status(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
/* not defined */ /* not defined */
@ -214,7 +214,7 @@ static int usb_standard_interface_get_status(struct usb_setup_data *req,
} }
static int usb_standard_endpoint_get_status(struct usb_setup_data *req, static int usb_standard_endpoint_get_status(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)req; (void)req;
@ -226,7 +226,7 @@ static int usb_standard_endpoint_get_status(struct usb_setup_data *req,
} }
static int usb_standard_endpoint_stall(struct usb_setup_data *req, static int usb_standard_endpoint_stall(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)buf; (void)buf;
(void)len; (void)len;
@ -237,7 +237,7 @@ static int usb_standard_endpoint_stall(struct usb_setup_data *req,
} }
static int usb_standard_endpoint_unstall(struct usb_setup_data *req, static int usb_standard_endpoint_unstall(struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) u8 **buf, u16 *len)
{ {
(void)buf; (void)buf;
(void)len; (void)len;
@ -247,11 +247,11 @@ static int usb_standard_endpoint_unstall(struct usb_setup_data *req,
return 1; return 1;
} }
int _usbd_standard_request_device(struct usb_setup_data *req, uint8_t **buf, int _usbd_standard_request_device(struct usb_setup_data *req, u8 **buf,
uint16_t *len) u16 *len)
{ {
int (*command)(struct usb_setup_data *req, uint8_t **buf, int (*command)(struct usb_setup_data *req, u8 **buf,
uint16_t *len) = NULL; u16 *len) = NULL;
switch(req->bRequest) { switch(req->bRequest) {
case USB_REQ_CLEAR_FEATURE: case USB_REQ_CLEAR_FEATURE:
@ -292,11 +292,11 @@ int _usbd_standard_request_device(struct usb_setup_data *req, uint8_t **buf,
return command(req, buf, len); return command(req, buf, len);
} }
int _usbd_standard_request_interface(struct usb_setup_data *req, uint8_t **buf, int _usbd_standard_request_interface(struct usb_setup_data *req, u8 **buf,
uint16_t *len) u16 *len)
{ {
int (*command)(struct usb_setup_data *req, uint8_t **buf, int (*command)(struct usb_setup_data *req, u8 **buf,
uint16_t *len) = NULL; u16 *len) = NULL;
switch(req->bRequest) { switch(req->bRequest) {
case USB_REQ_CLEAR_FEATURE: case USB_REQ_CLEAR_FEATURE:
@ -319,11 +319,11 @@ int _usbd_standard_request_interface(struct usb_setup_data *req, uint8_t **buf,
return command(req, buf, len); return command(req, buf, len);
} }
int _usbd_standard_request_endpoint(struct usb_setup_data *req, uint8_t **buf, int _usbd_standard_request_endpoint(struct usb_setup_data *req, u8 **buf,
uint16_t *len) u16 *len)
{ {
int (*command)(struct usb_setup_data *req, uint8_t **buf, int (*command)(struct usb_setup_data *req, u8 **buf,
uint16_t *len) = NULL; u16 *len) = NULL;
switch(req->bRequest) { switch(req->bRequest) {
case USB_REQ_CLEAR_FEATURE: case USB_REQ_CLEAR_FEATURE:
@ -351,8 +351,8 @@ int _usbd_standard_request_endpoint(struct usb_setup_data *req, uint8_t **buf,
return command(req, buf, len); return command(req, buf, len);
} }
int _usbd_standard_request(struct usb_setup_data *req, uint8_t **buf, int _usbd_standard_request(struct usb_setup_data *req, u8 **buf,
uint16_t *len) u16 *len)
{ {
/* FIXME: have class/vendor requests as well */ /* FIXME: have class/vendor requests as well */
if((req->bmRequestType & USB_REQ_TYPE_TYPE) != USB_REQ_TYPE_STANDARD) if((req->bmRequestType & USB_REQ_TYPE_TYPE) != USB_REQ_TYPE_STANDARD)