Changes in / [e7b9541:b82ec8d] in mainline
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
re7b9541 rb82ec8d 34 34 #include <usb/classes/hidparser.h> 35 35 #include <usb/devreq.h> 36 #include <usb/descriptor.h>37 36 38 37 #define BUFFER_SIZE 32 … … 53 52 * Kbd functions 54 53 */ 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; 54 static int usbkbd_get_descriptors() 55 { 56 // copy-pasted: 59 57 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 // } 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 }; 66 65 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 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 101 78 if (rc != EOK) { 102 79 return rc; 103 80 } 104 81 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; 82 // end of copy-paste 128 83 } 129 84 … … 156 111 // default endpoint 157 112 kbd_dev->default_ep = CONTROL_EP; 158 159 /*160 * will need all descriptors:161 * 1) choose one configuration from configuration descriptors162 * (set it to the device)163 * 2) set endpoints from endpoint descriptors164 */165 113 166 114 // TODO: get descriptors 167 usbkbd_get_descriptors( kbd_dev);115 usbkbd_get_descriptors(); 168 116 // TODO: parse descriptors and save endpoints 169 117 … … 184 132 callbacks->keyboard = usbkbd_process_keycodes; 185 133 186 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 187 NULL); 134 usb_hid_parse_report(kbd_dev->parser, buffer, callbacks, NULL); 188 135 } 189 136 -
uspace/lib/usb/include/usb/classes/hid.h
re7b9541 rb82ec8d 58 58 } usb_hid_protocol_t; 59 59 60 /** Part of standard USB HID descriptor specifying one class descriptor.61 *62 * (See HID Specification, p.22)63 */64 typedef struct {65 /** Type of class descriptor (Report or Physical). */66 uint8_t class_descriptor_type;67 /** Length of class descriptor. */68 uint16_t class_descriptor_length;69 } __attribute__ ((packed)) usb_standard_hid_descriptor_class_item_t;70 71 /** Standard USB HID descriptor.72 *73 * (See HID Specification, p.22)74 *75 * It is actually only the "header" of the descriptor, as it may have arbitrary76 * length if more than one class descritor is provided.77 */78 typedef struct {79 /** Size of this descriptor in bytes. */80 uint8_t length;81 /** Descriptor type (USB_DESCTYPE_HID). */82 uint8_t descriptor_type;83 /** HID Class Specification release. */84 uint16_t spec_release;85 /** Country code of localized hardware. */86 uint8_t country_code;87 /** Total number of class (i.e. Report and Physical) descriptors. */88 uint8_t class_count;89 /** First mandatory class descriptor info. */90 usb_standard_hid_descriptor_class_item_t class_descriptor;91 } __attribute__ ((packed)) usb_standard_hid_descriptor_t;92 93 94 60 /** 95 61 * @brief USB/HID keyboard device type. -
uspace/lib/usb/src/hidparser.c
re7b9541 rb82ec8d 75 75 76 76 callbacks->keyboard(keys, 6, arg); 77 78 return EOK;79 77 } 80 78
Note:
See TracChangeset
for help on using the changeset viewer.