Changes in uspace/drv/usbkbd/main.c [1f383dde:71ed4849] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
r1f383dde r71ed4849 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> 31 34 #include <errno.h> 32 35 #include <fibril.h> … … 35 38 #include <usb/devreq.h> 36 39 #include <usb/descriptor.h> 37 #include "descparser.h"38 40 39 41 #define BUFFER_SIZE 32 … … 41 43 42 44 #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_handler 49 }; 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 } 43 90 44 91 /* … … 48 95 void *arg) 49 96 { 50 printf("Got keys: "); 51 unsigned i; 52 for (i = 0; i < count; ++i) { 53 printf("%d ", key_codes[i]); 54 } 55 printf("\n"); 97 56 98 } 57 99 … … 59 101 * Kbd functions 60 102 */ 61 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev) 62 { 63 // get the first configuration descriptor (TODO: parse also other!) 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??) 64 144 usb_standard_configuration_descriptor_t config_desc; 65 145 … … 90 170 } 91 171 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); 172 rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred); 100 173 free(descriptors); 101 174 102 //usbkbd_print_config(kbd_dev->conf);103 104 175 return rc; 105 176 } … … 107 178 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 108 179 { 109 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *) calloc(1,110 180 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc( 181 sizeof(usb_hid_dev_kbd_t)); 111 182 112 183 if (kbd_dev == NULL) { … … 119 190 // get phone to my HC and save it as my parent's phone 120 191 // TODO: maybe not a good idea if DDF will use parent_phone 121 kbd_dev->device->parent_phone = usb_drv_hc_connect (dev, 0);192 kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 122 193 123 194 kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, … … 141 212 */ 142 213 143 // TODO: get descriptors, parse descriptors and save endpoints 144 usbkbd_process_descriptors(kbd_dev); 214 // TODO: get descriptors 215 usbkbd_get_descriptors(kbd_dev); 216 // TODO: parse descriptors and save endpoints 145 217 146 218 return kbd_dev; … … 159 231 sizeof(usb_hid_report_in_callbacks_t)); 160 232 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 } 161 242 162 243 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, … … 244 325 * Not supported yet, skip.. 245 326 */ 246 // int phone = usb_drv_hc_connect (dev, 0);327 // int phone = usb_drv_hc_connect_auto(dev, 0); 247 328 // if (phone < 0) { 248 329 // /* … … 265 346 fibril_add_ready(fid); 266 347 348 dev->ops = &keyboard_ops; 349 350 add_device_to_class(dev, "keyboard"); 351 267 352 /* 268 353 * Hurrah, device is initialized.
Note:
See TracChangeset
for help on using the changeset viewer.