69 lines
1.3 KiB
C
69 lines
1.3 KiB
C
#pragma once
|
|
|
|
#include <string.h>
|
|
|
|
typedef int (*usb_cb_setup_request_t)(int endpoint,usb_device_request_t *request);
|
|
|
|
|
|
typedef struct {
|
|
uint8_t bLength;
|
|
uint8_t bDescriptorType;
|
|
wchar_t characters[];
|
|
} usbstring_t;
|
|
|
|
#define USBSTRING_INIT(text) { bLength: sizeof(text), bDescriptorType: DT_STRING, characters: text }
|
|
|
|
static inline void usbstring_set(usbstring_t *dst,char *src){
|
|
int i,
|
|
n = strlen(src);
|
|
|
|
for (i=0;i<n;i++){
|
|
dst->characters[i] = (wchar_t)src[i];
|
|
}
|
|
dst->bDescriptorType = DT_STRING;
|
|
dst->bLength = (n*2) + 2;
|
|
};
|
|
|
|
|
|
typedef struct {
|
|
uint8_t size;
|
|
struct usb_standard_configuration_descriptor
|
|
*descriptor;
|
|
|
|
usb_cb_setup_request_t
|
|
setup_handler[ 7 ];
|
|
|
|
} device_configuration_t;
|
|
|
|
|
|
typedef struct {
|
|
struct usb_standard_device_descriptor
|
|
descriptor;
|
|
|
|
device_configuration_t
|
|
**configurations;
|
|
|
|
usbstring_t
|
|
**strings;
|
|
} usb_device_setup_t;
|
|
|
|
|
|
typedef union {
|
|
uint8_t value;
|
|
struct {
|
|
uint8_t HWEnabled:1; // USB Device Hardware is enabled
|
|
/* Device states USB Spec. 2.0 Chapter 9 */
|
|
uint8_t Attached:1;
|
|
uint8_t Powered:1;
|
|
uint8_t Default:1;
|
|
uint8_t Address:1;
|
|
uint8_t Configured:1;
|
|
uint8_t Suspended:1;
|
|
|
|
uint8_t Debugged:1; // 1-Bit Flag reserved for debugging, must be ignored
|
|
};
|
|
} usb_device_state_t;
|
|
|
|
|
|
|