Changes in uspace/drv/usbkbd/main.c [101ef25c:dafab9e0] in mainline
- File:
-
- 1 edited
-
uspace/drv/usbkbd/main.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
r101ef25c rdafab9e0 32 32 #include <fibril.h> 33 33 #include <usb/classes/hid.h> 34 #include <usb/classes/hidparser.h> 35 #include <usb/devreq.h> 36 #include <usb/descriptor.h> 34 37 35 38 #define BUFFER_SIZE 32 … … 37 40 38 41 static const usb_endpoint_t CONTROL_EP = 0; 42 43 /* 44 * Callbacks for parser 45 */ 46 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count, 47 void *arg) 48 { 49 50 } 51 52 /* 53 * Kbd functions 54 */ 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 101 if (rc != EOK) { 102 return rc; 103 } 104 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; 128 } 39 129 40 130 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) … … 66 156 // default endpoint 67 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 */ 68 165 69 166 // TODO: get descriptors 70 167 usbkbd_get_descriptors(kbd_dev); 71 168 // TODO: parse descriptors and save endpoints 72 169 … … 75 172 76 173 static void usbkbd_process_interrupt_in(usb_hid_dev_kbd_t *kbd_dev, 77 char*buffer, size_t actual_size)174 uint8_t *buffer, size_t actual_size) 78 175 { 79 176 /* … … 81 178 * now only take last 6 bytes and process, i.e. send to kbd 82 179 */ 180 181 usb_hid_report_in_callbacks_t *callbacks = 182 (usb_hid_report_in_callbacks_t *)malloc( 183 sizeof(usb_hid_report_in_callbacks_t)); 184 callbacks->keyboard = usbkbd_process_keycodes; 185 186 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 187 NULL); 83 188 } 84 189 … … 87 192 int rc; 88 193 usb_handle_t handle; 89 charbuffer[BUFFER_SIZE];194 uint8_t buffer[BUFFER_SIZE]; 90 195 size_t actual_size; 91 196 //usb_endpoint_t poll_endpoint = 1;
Note:
See TracChangeset
for help on using the changeset viewer.
