Changes in uspace/drv/usbkbd/main.c [38c5dfa:6986418] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
r38c5dfa r6986418 38 38 #include <usb/devreq.h> 39 39 #include <usb/descriptor.h> 40 #include "descparser.h" 40 41 41 42 #define BUFFER_SIZE 32 … … 78 79 } 79 80 80 #if 081 81 static void send_key(int key, int type, wchar_t c) { 82 82 async_msg_4(console_callback_phone, KBD_EVENT, type, key, 83 83 KM_NUM_LOCK, c); 84 84 } 85 #endif 85 86 static void send_alnum(int key, wchar_t c) { 87 printf(NAME ": sending key '%lc' to console\n", (wint_t) c); 88 send_key(key, KEY_PRESS, c); 89 send_key(key, KEY_RELEASE, c); 90 } 86 91 87 92 /* … … 91 96 void *arg) 92 97 { 93 98 printf("Got keys: "); 99 unsigned i; 100 for (i = 0; i < count; ++i) { 101 printf("%d ", key_codes[i]); 102 } 103 printf("\n"); 94 104 } 95 105 … … 97 107 * Kbd functions 98 108 */ 99 static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev, 100 const uint8_t *data, size_t size) 101 { 102 // const uint8_t *pos = data; 103 104 // // get the configuration descriptor (should be first) 105 // if (*pos != sizeof(usb_standard_configuration_descriptor_t) 106 // || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) { 107 // fprintf(stderr, "Wrong format of configuration descriptor"); 108 // return EINVAL; 109 // } 110 111 // usb_standard_configuration_descriptor_t config_descriptor; 112 // memcpy(&config_descriptor, pos, 113 // sizeof(usb_standard_configuration_descriptor_t)); 114 // pos += sizeof(usb_standard_configuration_descriptor_t); 115 116 // // parse other descriptors 117 // while (pos - data < size) { 118 // //uint8_t desc_size = *pos; 119 // uint8_t desc_type = *(pos + 1); 120 // switch (desc_type) { 121 // case USB_DESCTYPE_INTERFACE: 122 // break; 123 // case USB_DESCTYPE_ENDPOINT: 124 // break; 125 // case USB_DESCTYPE_HID: 126 // break; 127 // case USB_DESCTYPE_HID_REPORT: 128 // break; 129 // case USB_DESCTYPE_HID_PHYSICAL: 130 // break; 131 // } 132 // } 133 134 return EOK; 135 } 136 137 static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev) 138 { 139 // get the first configuration descriptor (TODO: or some other??) 109 static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev) 110 { 111 // iterate over all configurations and interfaces 112 // TODO: more configurations!! 113 unsigned i; 114 for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) { 115 uint8_t type = 116 kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.type; 117 // TODO: endianness 118 uint16_t length = 119 kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length; 120 121 // allocate space for the report descriptor 122 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length); 123 // get the descriptor from the device 124 125 } 126 } 127 128 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev) 129 { 130 // get the first configuration descriptor (TODO: parse also other!) 140 131 usb_standard_configuration_descriptor_t config_desc; 141 132 … … 166 157 } 167 158 168 rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred); 159 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 160 sizeof(usb_hid_configuration_t)); 161 if (kbd_dev->conf == NULL) { 162 free(descriptors); 163 return ENOMEM; 164 } 165 166 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 169 167 free(descriptors); 168 169 // get and report descriptors 170 rc = usbkbd_get_report_descriptor(kbd_dev); 171 172 usbkbd_print_config(kbd_dev->conf); 170 173 171 174 return rc; … … 174 177 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 175 178 { 176 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *) malloc(177 179 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 180 sizeof(usb_hid_dev_kbd_t)); 178 181 179 182 if (kbd_dev == NULL) { … … 208 211 */ 209 212 210 // TODO: get descriptors 211 usbkbd_get_descriptors(kbd_dev); 212 // TODO: parse descriptors and save endpoints 213 // TODO: get descriptors, parse descriptors and save endpoints 214 usbkbd_process_descriptors(kbd_dev); 213 215 214 216 return kbd_dev; … … 228 230 callbacks->keyboard = usbkbd_process_keycodes; 229 231 232 if (console_callback_phone != -1) { 233 static size_t counter = 0; 234 counter++; 235 if (counter > 3) { 236 counter = 0; 237 send_alnum(KC_A, L'a'); 238 } 239 } 240 230 241 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 231 242 NULL); … … 234 245 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 235 246 { 247 return; 248 236 249 int rc; 237 250 usb_handle_t handle;
Note:
See TracChangeset
for help on using the changeset viewer.