Changeset 2c381250 in mainline
- Timestamp:
- 2010-10-13T06:49:48Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7da3219
- Parents:
- fd17ab5
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/kbdconfig.c
rfd17ab5 r2c381250 35 35 */ 36 36 #include "kbdconfig.h" 37 #include <usb/hcd.h> 38 #include <usb/hid.h> 37 39 #include <usb/hidut.h> 38 40 #include <usb/classes.h> 39 41 40 42 /** Standard device descriptor. */ 41 usb_standard_device_descriptor_t std_de scriptor = {43 usb_standard_device_descriptor_t std_device_descriptor = { 42 44 .length = sizeof(usb_standard_device_descriptor_t), 43 .descriptor_type = 1,45 .descriptor_type = USB_DESCTYPE_DEVICE, 44 46 .usb_spec_version = 0x110, 45 .device_class = USB_CLASS_ HID,47 .device_class = USB_CLASS_USE_INTERFACE, 46 48 .device_subclass = 0, 47 49 .device_protocol = 0, … … 49 51 .configuration_count = 1 50 52 }; 51 size_t std_descriptor_size = sizeof(std_descriptor); 53 54 /** Standard interface descriptor. */ 55 usb_standard_interface_descriptor_t std_interface_descriptor = { 56 .length = sizeof(usb_standard_interface_descriptor_t), 57 .descriptor_type = USB_DESCTYPE_INTERFACE, 58 .interface_number = 0, 59 .alternate_setting = 0, 60 .endpoint_count = 1, 61 .interface_class = USB_CLASS_HID, 62 .interface_subclass = 0, 63 .interface_protocol = USB_HID_PROTOCOL_KEYBOARD, 64 .str_interface = 0 65 }; 52 66 53 67 /** USB keyboard report descriptor. … … 105 119 .descriptor1_length = sizeof(report_descriptor) 106 120 }; 107 size_t hid_descriptor_size = sizeof(hid_descriptor); 121 122 /** Endpoint descriptor. */ 123 usb_standard_endpoint_descriptor_t endpoint_descriptor = { 124 .length = sizeof(usb_standard_endpoint_descriptor_t), 125 .descriptor_type = USB_DESCTYPE_ENDPOINT, 126 .endpoint_address = 1 | 128, 127 .attributes = USB_TRANSFER_INTERRUPT, 128 .max_packet_size = 8, 129 .poll_interval = 10 130 }; 131 132 /** Standard configuration descriptor. */ 133 usb_standard_configuration_descriptor_t std_configuration_descriptor = { 134 .length = sizeof(usb_standard_configuration_descriptor_t), 135 .descriptor_type = USB_DESCTYPE_CONFIGURATION, 136 .total_length = 137 sizeof(usb_standard_configuration_descriptor_t) 138 + sizeof(std_interface_descriptor) 139 + sizeof(hid_descriptor) 140 + sizeof(endpoint_descriptor) 141 , 142 .interface_count = 1, 143 .configuration_number = 1, 144 .str_configuration = 0, 145 .attributes = 128, /* denotes bus-powered device */ 146 .max_power = 50 147 }; 148 149 108 150 109 151 -
uspace/app/virtusbkbd/kbdconfig.h
rfd17ab5 r2c381250 40 40 #include "descriptor.h" 41 41 42 extern usb_standard_device_descriptor_t std_descriptor; 43 extern size_t std_descriptor_size; 42 extern usb_standard_device_descriptor_t std_device_descriptor; 43 44 extern usb_standard_configuration_descriptor_t std_configuration_descriptor; 45 46 extern usb_standard_interface_descriptor_t std_interface_descriptor; 47 48 extern usb_standard_endpoint_descriptor_t endpoint_descriptor; 49 50 44 51 extern hid_descriptor_t hid_descriptor; 45 extern size_t hid_descriptor_size; 52 46 53 extern report_descriptor_data_t report_descriptor; 47 54 extern size_t report_descriptor_size; -
uspace/app/virtusbkbd/virtusbkbd.c
rfd17ab5 r2c381250 89 89 }; 90 90 91 usbvirt_device_configuration_extras_t extra_descriptors[] = { 92 { 93 .data = (uint8_t *) &std_interface_descriptor, 94 .length = sizeof(std_interface_descriptor) 95 }, 96 { 97 .data = (uint8_t *) &hid_descriptor, 98 .length = sizeof(hid_descriptor) 99 }, 100 { 101 .data = (uint8_t *) &endpoint_descriptor, 102 .length = sizeof(endpoint_descriptor) 103 } 104 }; 105 106 /** Keyboard configuration. */ 107 usbvirt_device_configuration_t configuration = { 108 .descriptor = &std_configuration_descriptor, 109 .extra = extra_descriptors, 110 .extra_count = sizeof(extra_descriptors)/sizeof(extra_descriptors[0]) 111 }; 112 113 /** Keyboard standard descriptors. */ 114 usbvirt_descriptors_t descriptors = { 115 .device = &std_device_descriptor, 116 .configuration = &configuration, 117 .configuration_count = 1, 118 }; 119 91 120 /** Keyboard device. 92 121 * Rest of the items will be initialized later. … … 94 123 static usbvirt_device_t keyboard_dev = { 95 124 .ops = &keyboard_ops, 96 . standard_descriptor = &std_descriptor,125 .descriptors = &descriptors, 97 126 .device_id_ = USBVIRT_DEV_KEYBOARD_ID 98 127 }; -
uspace/lib/usbvirt/device.h
rfd17ab5 r2c381250 46 46 uint8_t *data); 47 47 48 /** Device operations. */ 48 49 typedef struct { 50 /** Callback for standard USB request. 51 * Called only when the request could not be handled by this 52 * framework. 53 */ 49 54 usbvirt_on_device_request_t on_devreq_std; 55 /** Callback for class-specific USB request. */ 50 56 usbvirt_on_device_request_t on_devreq_class; 57 /** Callback for all other incoming data. */ 51 58 int (*on_data)(struct usbvirt_device *dev, 52 59 usb_endpoint_t endpoint, void *buffer, size_t size); 53 60 } usbvirt_device_ops_t; 61 62 /** Extra configuration data for GET_CONFIGURATION request. */ 63 typedef struct { 64 /** Actual data. */ 65 uint8_t *data; 66 /** Data length. */ 67 size_t length; 68 } usbvirt_device_configuration_extras_t; 69 70 /** Single device configuration. */ 71 typedef struct { 72 /** Standard configuration descriptor. */ 73 usb_standard_configuration_descriptor_t *descriptor; 74 /** Array of extra data. */ 75 usbvirt_device_configuration_extras_t *extra; 76 /** Length of @c extra array. */ 77 size_t extra_count; 78 } usbvirt_device_configuration_t; 79 80 /** Standard USB descriptors. */ 81 typedef struct { 82 /** Standard device descriptor. 83 * There is always only one such descriptor for the device. 84 */ 85 usb_standard_device_descriptor_t *device; 86 87 /** Configurations. */ 88 usbvirt_device_configuration_t *configuration; 89 /** Number of configurations. */ 90 size_t configuration_count; 91 } usbvirt_descriptors_t; 92 54 93 55 94 typedef struct usbvirt_device { … … 69 108 /* Device attributes. */ 70 109 71 /** Standard device descriptor. 72 * If this descriptor is set (i.e. not NULL), the framework 73 * automatically handles call for its retrieval. 74 */ 75 usb_standard_device_descriptor_t *standard_descriptor; 110 /** Standard descriptors. */ 111 usbvirt_descriptors_t *descriptors; 76 112 77 113 -
uspace/lib/usbvirt/stdreq.c
rfd17ab5 r2c381250 34 34 */ 35 35 #include <errno.h> 36 #include <stdlib.h> 37 #include <mem.h> 36 38 #include <usb/devreq.h> 37 39 38 40 #include "private.h" 41 42 39 43 40 44 /* … … 52 56 */ 53 57 if ((type == USB_DESCTYPE_DEVICE) && (index == 0)) { 54 if (device-> standard_descriptor) {58 if (device->descriptors && device->descriptors->device) { 55 59 return device->send_data(device, 0, 56 device-> standard_descriptor,57 device-> standard_descriptor->length);60 device->descriptors->device, 61 device->descriptors->device->length); 58 62 } else { 59 63 return EFORWARD; 60 64 } 65 } 66 67 /* 68 * Configuration descriptor together with interface, endpoint and 69 * class-specific descriptors. 70 */ 71 if (type == USB_DESCTYPE_CONFIGURATION) { 72 if (!device->descriptors) { 73 return EFORWARD; 74 } 75 if (index >= device->descriptors->configuration_count) { 76 return EFORWARD; 77 } 78 /* Copy the data. */ 79 usbvirt_device_configuration_t *config = &device->descriptors 80 ->configuration[index]; 81 uint8_t *all_data = malloc(config->descriptor->total_length); 82 if (all_data == NULL) { 83 return ENOMEM; 84 } 85 86 uint8_t *ptr = all_data; 87 memcpy(ptr, config->descriptor, config->descriptor->length); 88 ptr += config->descriptor->length; 89 size_t i; 90 for (i = 0; i < config->extra_count; i++) { 91 usbvirt_device_configuration_extras_t *extra 92 = &config->extra[i]; 93 memcpy(ptr, extra->data, extra->length); 94 ptr += extra->length; 95 } 96 97 int rc = device->send_data(device, 0, all_data, 98 config->descriptor->total_length); 99 100 free(all_data); 101 102 return rc; 61 103 } 62 104
Note:
See TracChangeset
for help on using the changeset viewer.