Changeset 7fc092a in mainline for uspace/drv/usbkbd/main.c
- Timestamp:
- 2011-01-27T22:09:29Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- db7ed07
- Parents:
- 9ee87f6 (diff), 6265a2b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
r9ee87f6 r7fc092a 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbhid 29 * @{ 30 */ 28 31 #include <usb/usbdrv.h> 29 32 #include <driver.h> … … 38 41 #include <usb/devreq.h> 39 42 #include <usb/descriptor.h> 43 #include "descparser.h" 44 #include "descdump.h" 40 45 41 46 #define BUFFER_SIZE 32 … … 88 93 * Callbacks for parser 89 94 */ 90 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count, 91 void *arg) 92 { 93 95 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 96 uint8_t modifiers, void *arg) 97 { 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 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 // TODO: endianness 116 uint16_t length = 117 kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length; 118 size_t actual_size = 0; 119 120 // allocate space for the report descriptor 121 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length); 122 123 // get the descriptor from the device 124 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone, 125 kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 126 0, i, kbd_dev->conf->interfaces[i].report_desc, length, 127 &actual_size); 128 129 if (rc != EOK) { 130 return rc; 131 } 132 133 assert(actual_size == length); 134 135 //dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT, 136 // kbd_dev->conf->interfaces[i].report_desc, length); 137 } 138 134 139 return EOK; 135 140 } 136 141 137 static int usbkbd_ get_descriptors(usb_hid_dev_kbd_t *kbd_dev)138 { 139 // get the first configuration descriptor (TODO: or some other??)142 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev) 143 { 144 // get the first configuration descriptor (TODO: parse also other!) 140 145 usb_standard_configuration_descriptor_t config_desc; 141 146 … … 166 171 } 167 172 168 rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred); 173 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 174 sizeof(usb_hid_configuration_t)); 175 if (kbd_dev->conf == NULL) { 176 free(descriptors); 177 return ENOMEM; 178 } 179 180 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 169 181 free(descriptors); 170 171 return rc; 182 if (rc != EOK) { 183 printf("Problem with parsing standard descriptors.\n"); 184 return rc; 185 } 186 187 // get and report descriptors 188 rc = usbkbd_get_report_descriptor(kbd_dev); 189 if (rc != EOK) { 190 printf("Problem with parsing HID REPORT descriptor.\n"); 191 return rc; 192 } 193 194 //usbkbd_print_config(kbd_dev->conf); 195 196 /* 197 * TODO: 198 * 1) select one configuration (lets say the first) 199 * 2) how many interfaces?? how to select one?? 200 * ("The default setting for an interface is always alternate setting zero.") 201 * 3) find endpoint which is IN and INTERRUPT (parse), save its number 202 * as the endpoint for polling 203 */ 204 205 return EOK; 172 206 } 173 207 174 208 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 175 209 { 176 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *) malloc(177 210 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 211 sizeof(usb_hid_dev_kbd_t)); 178 212 179 213 if (kbd_dev == NULL) { … … 186 220 // get phone to my HC and save it as my parent's phone 187 221 // TODO: maybe not a good idea if DDF will use parent_phone 188 kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 189 190 kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, 191 dev); 222 int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 223 if (rc < 0) { 224 printf("Problem setting phone to HC.\n"); 225 free(kbd_dev); 226 return NULL; 227 } 228 229 rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev); 230 if (rc < 0) { 231 printf("Problem getting address of the device.\n"); 232 free(kbd_dev); 233 return NULL; 234 } 192 235 193 236 // doesn't matter now that we have no address … … 208 251 */ 209 252 210 // TODO: get descriptors 211 usbkbd_get_descriptors(kbd_dev); 212 // TODO: parse descriptors and save endpoints 253 // TODO: get descriptors, parse descriptors and save endpoints 254 usbkbd_process_descriptors(kbd_dev); 213 255 214 256 return kbd_dev; … … 218 260 uint8_t *buffer, size_t actual_size) 219 261 { 220 /*221 * here, the parser will be called, probably with some callbacks222 * now only take last 6 bytes and process, i.e. send to kbd223 */224 225 262 usb_hid_report_in_callbacks_t *callbacks = 226 263 (usb_hid_report_in_callbacks_t *)malloc( … … 228 265 callbacks->keyboard = usbkbd_process_keycodes; 229 266 230 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 231 NULL); 267 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 268 // NULL); 269 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 270 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 232 271 } 233 272 234 273 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 235 274 { 275 return; 276 236 277 int rc; 237 278 usb_handle_t handle; … … 356 397 return driver_main(&kbd_driver); 357 398 } 399 400 /** 401 * @} 402 */
Note:
See TracChangeset
for help on using the changeset viewer.