Changeset e7b9541 in mainline for uspace/drv/usbkbd/main.c
- Timestamp:
- 2010-12-12T13:40:16Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0c05496
- Parents:
- b82ec8d (diff), a3b1107 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
rb82ec8d re7b9541 34 34 #include <usb/classes/hidparser.h> 35 35 #include <usb/devreq.h> 36 #include <usb/descriptor.h> 36 37 37 38 #define BUFFER_SIZE 32 … … 52 53 * Kbd functions 53 54 */ 54 static int usbkbd_get_descriptors() 55 { 56 // copy-pasted: 57 58 /* Prepare the setup packet. */ 59 usb_device_request_setup_packet_t setup_packet = { 60 .request_type = 128, 61 .request = USB_DEVREQ_GET_DESCRIPTOR, 62 .index = 0, 63 .length = sizeof(usb_standard_device_descriptor_t) 64 }; 65 66 setup_packet.value_high = USB_DESCTYPE_DEVICE; 67 setup_packet.value_low = 0; 68 69 /* Prepare local descriptor. */ 70 size_t actually_transferred = 0; 71 usb_standard_device_descriptor_t descriptor_tmp; 72 73 /* Perform the control read transaction. */ 74 int rc = usb_drv_psync_control_read(phone, target, 75 &setup_packet, sizeof(setup_packet), 76 &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred); 77 55 static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev, 56 const uint8_t *data, size_t size) 57 { 58 // const uint8_t *pos = data; 59 60 // // get the configuration descriptor (should be first) 61 // if (*pos != sizeof(usb_standard_configuration_descriptor_t) 62 // || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) { 63 // fprintf(stderr, "Wrong format of configuration descriptor"); 64 // return EINVAL; 65 // } 66 67 // usb_standard_configuration_descriptor_t config_descriptor; 68 // memcpy(&config_descriptor, pos, 69 // sizeof(usb_standard_configuration_descriptor_t)); 70 // pos += sizeof(usb_standard_configuration_descriptor_t); 71 72 // // parse other descriptors 73 // while (pos - data < size) { 74 // //uint8_t desc_size = *pos; 75 // uint8_t desc_type = *(pos + 1); 76 // switch (desc_type) { 77 // case USB_DESCTYPE_INTERFACE: 78 // break; 79 // case USB_DESCTYPE_ENDPOINT: 80 // break; 81 // case USB_DESCTYPE_HID: 82 // break; 83 // case USB_DESCTYPE_HID_REPORT: 84 // break; 85 // case USB_DESCTYPE_HID_PHYSICAL: 86 // break; 87 // } 88 // } 89 90 return EOK; 91 } 92 93 static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev) 94 { 95 // get the first configuration descriptor (TODO: or some other??) 96 usb_standard_configuration_descriptor_t config_desc; 97 98 int rc = usb_drv_req_get_bare_configuration_descriptor( 99 kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc); 100 78 101 if (rc != EOK) { 79 102 return rc; 80 103 } 81 104 82 // end of copy-paste 105 // prepare space for all underlying descriptors 106 uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length); 107 if (descriptors == NULL) { 108 return ENOMEM; 109 } 110 111 size_t transferred = 0; 112 // get full configuration descriptor 113 rc = usb_drv_req_get_full_configuration_descriptor( 114 kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors, 115 config_desc.total_length, &transferred); 116 117 if (rc != EOK) { 118 return rc; 119 } 120 if (transferred != config_desc.total_length) { 121 return ELIMIT; 122 } 123 124 rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred); 125 free(descriptors); 126 127 return rc; 83 128 } 84 129 … … 111 156 // default endpoint 112 157 kbd_dev->default_ep = CONTROL_EP; 158 159 /* 160 * will need all descriptors: 161 * 1) choose one configuration from configuration descriptors 162 * (set it to the device) 163 * 2) set endpoints from endpoint descriptors 164 */ 113 165 114 166 // TODO: get descriptors 115 usbkbd_get_descriptors( );167 usbkbd_get_descriptors(kbd_dev); 116 168 // TODO: parse descriptors and save endpoints 117 169 … … 132 184 callbacks->keyboard = usbkbd_process_keycodes; 133 185 134 usb_hid_parse_report(kbd_dev->parser, buffer, callbacks, NULL); 186 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 187 NULL); 135 188 } 136 189
Note:
See TracChangeset
for help on using the changeset viewer.