Changes in uspace/drv/usbkbd/main.c [71ed4849:1f383dde] in mainline
- File:
-
- 1 edited
-
uspace/drv/usbkbd/main.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
r71ed4849 r1f383dde 29 29 #include <driver.h> 30 30 #include <ipc/driver.h> 31 #include <ipc/kbd.h>32 #include <io/keycode.h>33 #include <io/console.h>34 31 #include <errno.h> 35 32 #include <fibril.h> … … 38 35 #include <usb/devreq.h> 39 36 #include <usb/descriptor.h> 37 #include "descparser.h" 40 38 41 39 #define BUFFER_SIZE 32 … … 43 41 44 42 #define GUESSED_POLL_ENDPOINT 1 45 46 static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);47 static device_ops_t keyboard_ops = {48 .default_handler = default_connection_handler49 };50 51 static int console_callback_phone = -1;52 53 /** Default handler for IPC methods not handled by DDF.54 *55 * @param dev Device handling the call.56 * @param icallid Call id.57 * @param icall Call data.58 */59 void default_connection_handler(device_t *dev,60 ipc_callid_t icallid, ipc_call_t *icall)61 {62 sysarg_t method = IPC_GET_IMETHOD(*icall);63 64 if (method == IPC_M_CONNECT_TO_ME) {65 int callback = IPC_GET_ARG5(*icall);66 67 if (console_callback_phone != -1) {68 ipc_answer_0(icallid, ELIMIT);69 return;70 }71 72 console_callback_phone = callback;73 ipc_answer_0(icallid, EOK);74 return;75 }76 77 ipc_answer_0(icallid, EINVAL);78 }79 80 static void send_key(int key, int type, wchar_t c) {81 async_msg_4(console_callback_phone, KBD_EVENT, type, key,82 KM_NUM_LOCK, c);83 }84 85 static void send_alnum(int key, wchar_t c) {86 printf(NAME ": sending key '%lc' to console\n", (wint_t) c);87 send_key(key, KEY_PRESS, c);88 send_key(key, KEY_RELEASE, c);89 }90 43 91 44 /* … … 95 48 void *arg) 96 49 { 97 50 printf("Got keys: "); 51 unsigned i; 52 for (i = 0; i < count; ++i) { 53 printf("%d ", key_codes[i]); 54 } 55 printf("\n"); 98 56 } 99 57 … … 101 59 * Kbd functions 102 60 */ 103 static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev, 104 const uint8_t *data, size_t size) 105 { 106 // const uint8_t *pos = data; 107 108 // // get the configuration descriptor (should be first) 109 // if (*pos != sizeof(usb_standard_configuration_descriptor_t) 110 // || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) { 111 // fprintf(stderr, "Wrong format of configuration descriptor"); 112 // return EINVAL; 113 // } 114 115 // usb_standard_configuration_descriptor_t config_descriptor; 116 // memcpy(&config_descriptor, pos, 117 // sizeof(usb_standard_configuration_descriptor_t)); 118 // pos += sizeof(usb_standard_configuration_descriptor_t); 119 120 // // parse other descriptors 121 // while (pos - data < size) { 122 // //uint8_t desc_size = *pos; 123 // uint8_t desc_type = *(pos + 1); 124 // switch (desc_type) { 125 // case USB_DESCTYPE_INTERFACE: 126 // break; 127 // case USB_DESCTYPE_ENDPOINT: 128 // break; 129 // case USB_DESCTYPE_HID: 130 // break; 131 // case USB_DESCTYPE_HID_REPORT: 132 // break; 133 // case USB_DESCTYPE_HID_PHYSICAL: 134 // break; 135 // } 136 // } 137 138 return EOK; 139 } 140 141 static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev) 142 { 143 // get the first configuration descriptor (TODO: or some other??) 61 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev) 62 { 63 // get the first configuration descriptor (TODO: parse also other!) 144 64 usb_standard_configuration_descriptor_t config_desc; 145 65 … … 170 90 } 171 91 172 rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred); 92 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 93 sizeof(usb_hid_configuration_t)); 94 if (kbd_dev->conf == NULL) { 95 free(descriptors); 96 return ENOMEM; 97 } 98 99 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 173 100 free(descriptors); 174 101 102 //usbkbd_print_config(kbd_dev->conf); 103 175 104 return rc; 176 105 } … … 178 107 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 179 108 { 180 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *) malloc(181 sizeof(usb_hid_dev_kbd_t));109 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 110 sizeof(usb_hid_dev_kbd_t)); 182 111 183 112 if (kbd_dev == NULL) { … … 190 119 // get phone to my HC and save it as my parent's phone 191 120 // TODO: maybe not a good idea if DDF will use parent_phone 192 kbd_dev->device->parent_phone = usb_drv_hc_connect _auto(dev, 0);121 kbd_dev->device->parent_phone = usb_drv_hc_connect(dev, 0); 193 122 194 123 kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, … … 212 141 */ 213 142 214 // TODO: get descriptors 215 usbkbd_get_descriptors(kbd_dev); 216 // TODO: parse descriptors and save endpoints 143 // TODO: get descriptors, parse descriptors and save endpoints 144 usbkbd_process_descriptors(kbd_dev); 217 145 218 146 return kbd_dev; … … 231 159 sizeof(usb_hid_report_in_callbacks_t)); 232 160 callbacks->keyboard = usbkbd_process_keycodes; 233 234 if (console_callback_phone != -1) {235 static size_t counter = 0;236 counter++;237 if (counter > 3) {238 counter = 0;239 send_alnum(KC_A, L'a');240 }241 }242 161 243 162 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, … … 325 244 * Not supported yet, skip.. 326 245 */ 327 // int phone = usb_drv_hc_connect _auto(dev, 0);246 // int phone = usb_drv_hc_connect(dev, 0); 328 247 // if (phone < 0) { 329 248 // /* … … 346 265 fibril_add_ready(fid); 347 266 348 dev->ops = &keyboard_ops;349 350 add_device_to_class(dev, "keyboard");351 352 267 /* 353 268 * Hurrah, device is initialized.
Note:
See TracChangeset
for help on using the changeset viewer.
