Changes in / [ff8ed06:c9d5577] in mainline
- Location:
- uspace
- Files:
-
- 4 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/virtusbkbd.c
rff8ed06 rc9d5577 271 271 printf("%s: Simulating keyboard events...\n", NAME); 272 272 fibril_sleep(10); 273 //while (1) {273 while (1) { 274 274 kb_process_events(&status, keyboard_events, keyboard_events_count, 275 275 on_keyboard_change); 276 //}276 } 277 277 278 278 printf("%s: Terminating...\n", NAME); -
uspace/drv/usbhub/main.c
rff8ed06 rc9d5577 52 52 while(true){ 53 53 usb_hub_check_hub_changes(); 54 async_usleep(1000 * 1000 );/// \TODO proper number once54 async_usleep(1000 * 1000); 55 55 } 56 56 return 0; -
uspace/drv/usbhub/usbhub.c
rff8ed06 rc9d5577 46 46 #include "usbhub_private.h" 47 47 #include "port_status.h" 48 #include "usb/usb.h"49 48 50 49 static usb_iface_t hub_usb_iface = { … … 86 85 87 86 // get hub descriptor 87 usb_target_t target; 88 target.address = addr; 89 target.endpoint = 0; 90 usb_device_request_setup_packet_t request; 91 //printf("[usb_hub] creating descriptor request\n"); 92 usb_hub_set_descriptor_request(&request); 88 93 89 94 //printf("[usb_hub] creating serialized descriptor\n"); … … 93 98 int opResult; 94 99 //printf("[usb_hub] starting control transaction\n"); 95 96 opResult = usb_drv_req_get_descriptor(hc, addr, 97 USB_REQUEST_TYPE_CLASS, 98 USB_DESCTYPE_HUB, 0, 0, serialized_descriptor, 100 opResult = usb_drv_sync_control_read( 101 hc, target, &request, serialized_descriptor, 99 102 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 100 101 103 if (opResult != EOK) { 102 104 dprintf(1,"[usb_hub] failed when receiving hub descriptor, badcode = %d",opResult); … … 153 155 int port; 154 156 int opResult; 157 usb_device_request_setup_packet_t request; 155 158 usb_target_t target; 156 159 target.address = hub_info->usb_device->address; … … 170 173 if(std_descriptor.configuration_count<1){ 171 174 dprintf(1,"[usb_hub] THERE ARE NO CONFIGURATIONS AVAILABLE"); 172 //shouldn`t I return?173 175 } 174 176 /// \TODO check other configurations … … 182 184 } 183 185 //set configuration 184 opResult = usb_drv_req_set_configuration(hc, target.address, 185 config_descriptor.configuration_number); 186 186 request.request_type = 0; 187 request.request = USB_DEVREQ_SET_CONFIGURATION; 188 request.index=0; 189 request.length=0; 190 request.value_high=0; 191 request.value_low = config_descriptor.configuration_number; 192 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0); 187 193 if (opResult != EOK) { 188 194 dprintf(1,"[usb_hub]something went wrong when setting hub`s configuration, %d", opResult); 189 195 } 190 196 191 usb_device_request_setup_packet_t request;192 197 for (port = 1; port < hub_info->port_count+1; ++port) { 193 198 usb_hub_set_power_port_request(&request, port); … … 224 229 225 230 231 226 232 //********************************************* 227 233 // … … 231 237 232 238 /** 233 * Convenience function for releasing default address and writing debug info234 * (these few lines are used too often to be written again and again) .239 * convenience function for releasing default address and writing debug info 240 * (these few lines are used too often to be written again and again) 235 241 * @param hc 236 242 * @return … … 247 253 248 254 /** 249 * Reset the port with new device and reserve the default address.255 * reset the port with new device and reserve the default address 250 256 * @param hc 251 257 * @param port … … 276 282 277 283 /** 278 * Finalize adding new device after port reset284 * finalize adding new device after port reset 279 285 * @param hc 280 286 * @param port … … 339 345 340 346 /** 341 * Unregister device address in hc347 * unregister device address in hc 342 348 * @param hc 343 349 * @param port … … 349 355 int opResult; 350 356 351 /** \TODO remove device from device manager - not yet implemented in 352 * devide manager 353 */ 357 /// \TODO remove device 354 358 355 359 hub->attached_devs[port].devman_handle=0; … … 372 376 373 377 /** 374 * Process interrupts on given hub port378 * process interrupts on given hub port 375 379 * @param hc 376 380 * @param port … … 430 434 usb_port_set_reset_completed(&status, false); 431 435 usb_port_set_dev_connected(&status, false); 432 if (status>>16) { 433 dprintf(1,"[usb_hub]there was some unsupported change on port %d: %X",port,status); 434 436 if (status) { 437 dprintf(1,"[usb_hub]there was some unsupported change on port %d",port); 435 438 } 436 439 /// \TODO handle other changes … … 439 442 } 440 443 441 /** 442 * Check changes on all known hubs. 444 /* Check changes on all known hubs. 443 445 */ 444 446 void usb_hub_check_hub_changes(void) { … … 460 462 target.address = hub_info->usb_device->address; 461 463 target.endpoint = 1;/// \TODO get from endpoint descriptor 462 /*dprintf(1,"[usb_hub] checking changes for hub at addr %d",463 target.address); */464 dprintf(1,"[usb_hub] checking changes for hub at addr %d", 465 target.address); 464 466 465 467 size_t port_count = hub_info->port_count; -
uspace/drv/usbhub/usbhub_private.h
rff8ed06 rc9d5577 31 31 */ 32 32 /** @file 33 * @brief Hub driver private definitions33 * @brief Hub driver. 34 34 */ 35 35 … … 68 68 69 69 /** 70 * Create hub structure instance70 * create hub structure instance 71 71 * 72 72 * Set the address and port count information most importantly. … … 78 78 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc); 79 79 80 /** List of hubs maanged by this driver */80 /** list of hubs maanged by this driver */ 81 81 extern usb_general_list_t usb_hub_list; 82 82 83 /** Lock for hub list*/83 /** lock for hub list*/ 84 84 extern futex_t usb_hub_list_lock; 85 85 86 86 87 87 /** 88 * Perform complete control read transaction88 * perform complete control read transaction 89 89 * 90 * Manages all three steps of transaction: setup, read and finalize90 * manages all three steps of transaction: setup, read and finalize 91 91 * @param phone 92 92 * @param target 93 * @param request Request packet94 * @param rcvd_buffer Received data93 * @param request request for data 94 * @param rcvd_buffer received data 95 95 * @param rcvd_size 96 * @param actual_size Actual size of received data96 * @param actual_size actual size of received data 97 97 * @return error code 98 98 */ … … 104 104 105 105 /** 106 * Perform complete control write transaction106 * perform complete control write transaction 107 107 * 108 * Manages all three steps of transaction: setup, write and finalize108 * manages all three steps of transaction: setup, write and finalize 109 109 * @param phone 110 110 * @param target 111 * @param request Request packet to send data111 * @param request request to send data 112 112 * @param sent_buffer 113 113 * @param sent_size … … 121 121 122 122 /** 123 * Set the device request to be a get hub descriptor request.123 * set the device request to be a get hub descriptor request. 124 124 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE 125 125 * @param request … … 137 137 } 138 138 139 /**140 * Clear feature on hub port.141 *142 * @param hc Host controller telephone143 * @param address Hub address144 * @param port_index Port145 * @param feature Feature selector146 * @return Operation result147 */148 139 static inline int usb_hub_clear_port_feature(int hc, usb_address_t address, 149 140 int port_index, -
uspace/drv/usbkbd/Makefile
rff8ed06 rc9d5577 33 33 34 34 SOURCES = \ 35 main.c \ 36 descparser.c \ 37 descdump.c 35 main.c 38 36 39 37 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/usbkbd/main.c
rff8ed06 rc9d5577 38 38 #include <usb/devreq.h> 39 39 #include <usb/descriptor.h> 40 #include "descparser.h"41 #include "descdump.h"42 40 43 41 #define BUFFER_SIZE 32 … … 90 88 * Callbacks for parser 91 89 */ 92 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 93 uint8_t modifiers, void *arg) 94 { 95 printf("Got keys: "); 96 unsigned i; 97 for (i = 0; i < count; ++i) { 98 printf("%d ", key_codes[i]); 99 } 100 printf("\n"); 90 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count, 91 void *arg) 92 { 93 101 94 } 102 95 … … 104 97 * Kbd functions 105 98 */ 106 static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev) 107 { 108 // iterate over all configurations and interfaces 109 // TODO: more configurations!! 110 unsigned i; 111 for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) { 112 // TODO: endianness 113 uint16_t length = 114 kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length; 115 size_t actual_size = 0; 116 117 // allocate space for the report descriptor 118 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length); 119 120 // get the descriptor from the device 121 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone, 122 kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 123 0, i, kbd_dev->conf->interfaces[i].report_desc, length, 124 &actual_size); 125 126 if (rc != EOK) { 127 return rc; 128 } 129 130 assert(actual_size == length); 131 132 //dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT, 133 // kbd_dev->conf->interfaces[i].report_desc, length); 134 } 135 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 136 134 return EOK; 137 135 } 138 136 139 static int usbkbd_ process_descriptors(usb_hid_dev_kbd_t *kbd_dev)140 { 141 // get the first configuration descriptor (TODO: parse also other!)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 140 usb_standard_configuration_descriptor_t config_desc; 143 141 … … 168 166 } 169 167 170 kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 171 sizeof(usb_hid_configuration_t)); 172 if (kbd_dev->conf == NULL) { 173 free(descriptors); 174 return ENOMEM; 175 } 176 177 rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf); 168 rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred); 178 169 free(descriptors); 179 if (rc != EOK) { 180 printf("Problem with parsing standard descriptors.\n"); 181 return rc; 182 } 183 184 // get and report descriptors 185 rc = usbkbd_get_report_descriptor(kbd_dev); 186 if (rc != EOK) { 187 printf("Problem with parsing HID REPORT descriptor.\n"); 188 return rc; 189 } 190 191 //usbkbd_print_config(kbd_dev->conf); 192 193 /* 194 * TODO: 195 * 1) select one configuration (lets say the first) 196 * 2) how many interfaces?? how to select one?? 197 * ("The default setting for an interface is always alternate setting zero.") 198 * 3) find endpoint which is IN and INTERRUPT (parse), save its number 199 * as the endpoint for polling 200 */ 201 202 return EOK; 170 171 return rc; 203 172 } 204 173 205 174 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) 206 175 { 207 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *) calloc(1,208 176 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc( 177 sizeof(usb_hid_dev_kbd_t)); 209 178 210 179 if (kbd_dev == NULL) { … … 217 186 // get phone to my HC and save it as my parent's phone 218 187 // TODO: maybe not a good idea if DDF will use parent_phone 219 int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0); 220 if (rc < 0) { 221 printf("Problem setting phone to HC.\n"); 222 free(kbd_dev); 223 return NULL; 224 } 225 226 rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev); 227 if (rc < 0) { 228 printf("Problem getting address of the device.\n"); 229 free(kbd_dev); 230 return NULL; 231 } 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); 232 192 233 193 // doesn't matter now that we have no address … … 248 208 */ 249 209 250 // TODO: get descriptors, parse descriptors and save endpoints 251 usbkbd_process_descriptors(kbd_dev); 210 // TODO: get descriptors 211 usbkbd_get_descriptors(kbd_dev); 212 // TODO: parse descriptors and save endpoints 252 213 253 214 return kbd_dev; … … 257 218 uint8_t *buffer, size_t actual_size) 258 219 { 220 /* 221 * here, the parser will be called, probably with some callbacks 222 * now only take last 6 bytes and process, i.e. send to kbd 223 */ 224 259 225 usb_hid_report_in_callbacks_t *callbacks = 260 226 (usb_hid_report_in_callbacks_t *)malloc( … … 262 228 callbacks->keyboard = usbkbd_process_keycodes; 263 229 264 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 265 // NULL); 266 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 267 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 230 usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 231 NULL); 268 232 } 269 233 270 234 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 271 235 { 272 return;273 274 236 int rc; 275 237 usb_handle_t handle; -
uspace/drv/vhc/hcd.c
rff8ed06 rc9d5577 116 116 sleep(5); 117 117 118 usb_dprintf_enable(NAME, -1);118 usb_dprintf_enable(NAME, 0); 119 119 120 120 printf(NAME ": virtual USB host controller driver.\n"); -
uspace/lib/usb/include/usb/classes/hid.h
rff8ed06 rc9d5577 39 39 #include <driver.h> 40 40 #include <usb/classes/hidparser.h> 41 #include <usb/descriptor.h>42 41 43 42 /** USB/HID device requests. */ … … 64 63 */ 65 64 typedef struct { 66 /** Type of class -specificdescriptor (Report or Physical). */67 uint8_t type;68 /** Length of class -specific descriptor in bytes. */69 uint16_t length;70 } __attribute__ ((packed)) usb_standard_hid_ class_descriptor_info_t;65 /** Type of class descriptor (Report or Physical). */ 66 uint8_t class_descriptor_type; 67 /** Length of class descriptor. */ 68 uint16_t class_descriptor_length; 69 } __attribute__ ((packed)) usb_standard_hid_descriptor_class_item_t; 71 70 72 71 /** Standard USB HID descriptor. … … 74 73 * (See HID Specification, p.22) 75 74 * 76 * It is actually only the "header" of the descriptor, it does not contain 77 * the last two mandatory fields (type and length of the first class-specific 78 * descriptor). 75 * It is actually only the "header" of the descriptor, as it may have arbitrary 76 * length if more than one class descritor is provided. 79 77 */ 80 78 typedef struct { 81 /** Total size of this descriptor in bytes. 82 * 83 * This includes all class-specific descriptor info - type + length 84 * for each descriptor. 85 */ 79 /** Size of this descriptor in bytes. */ 86 80 uint8_t length; 87 81 /** Descriptor type (USB_DESCTYPE_HID). */ … … 91 85 /** Country code of localized hardware. */ 92 86 uint8_t country_code; 93 /** Total number of class-specific (i.e. Report and Physical) 94 * descriptors. 95 * 96 * @note There is always only one Report descriptor. 97 */ 98 uint8_t class_desc_count; 99 /** First mandatory class descriptor (Report) info. */ 100 usb_standard_hid_class_descriptor_info_t report_desc_info; 87 /** Total number of class (i.e. Report and Physical) descriptors. */ 88 uint8_t class_count; 89 /** First mandatory class descriptor info. */ 90 usb_standard_hid_descriptor_class_item_t class_descriptor; 101 91 } __attribute__ ((packed)) usb_standard_hid_descriptor_t; 102 92 103 /**104 *105 */106 typedef struct {107 usb_standard_interface_descriptor_t iface_desc;108 usb_standard_endpoint_descriptor_t *endpoints;109 usb_standard_hid_descriptor_t hid_desc;110 uint8_t *report_desc;111 //usb_standard_hid_class_descriptor_info_t *class_desc_info;112 //uint8_t **class_descs;113 } usb_hid_iface_t;114 115 /**116 *117 */118 typedef struct {119 usb_standard_configuration_descriptor_t config_descriptor;120 usb_hid_iface_t *interfaces;121 } usb_hid_configuration_t;122 93 123 94 /** … … 128 99 typedef struct { 129 100 device_t *device; 130 usb_hid_configuration_t *conf;131 101 usb_address_t address; 132 102 usb_endpoint_t poll_endpoint; … … 134 104 } usb_hid_dev_kbd_t; 135 105 136 // TODO: more configurations!137 138 106 #endif 139 107 /** -
uspace/lib/usb/include/usb/classes/hidparser.h
rff8ed06 rc9d5577 38 38 #include <stdint.h> 39 39 40 /**41 * Description of report items42 */43 typedef struct {44 45 uint8_t usage_min;46 uint8_t usage_max;47 uint8_t logical_min;48 uint8_t logical_max;49 uint8_t size;50 uint8_t count;51 uint8_t offset;52 53 } usb_hid_report_item_t;54 55 56 40 /** HID report parser structure. */ 57 41 typedef struct { 58 42 } usb_hid_report_parser_t; 59 60 43 61 44 /** HID parser callbacks for IN items. */ … … 67 50 * @param arg Custom argument. 68 51 */ 69 void (*keyboard)(const uint 8_t *key_codes, size_t count, const uint8_t modifiers, void *arg);52 void (*keyboard)(const uint16_t *key_codes, size_t count, void *arg); 70 53 } usb_hid_report_in_callbacks_t; 71 72 #define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x0173 #define USB_HID_BOOT_KEYBOARD_CAPS_LOCK 0x0274 #define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK 0x0475 #define USB_HID_BOOT_KEYBOARD_COMPOSE 0x0876 #define USB_HID_BOOT_KEYBOARD_KANA 0x1077 78 /*79 * modifiers definitions80 */81 82 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,83 const usb_hid_report_in_callbacks_t *callbacks, void *arg);84 85 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);86 54 87 55 int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser, … … 92 60 const usb_hid_report_in_callbacks_t *callbacks, void *arg); 93 61 94 95 int usb_hid_free_report_parser(usb_hid_report_parser_t *parser);96 97 62 #endif 98 63 /** -
uspace/lib/usb/src/hidparser.c
rff8ed06 rc9d5577 40 40 * @param parser Opaque HID report parser structure. 41 41 * @param data Data describing the report. 42 * @param size Size of the descriptor in bytes. 42 43 * @return Error code. 43 44 */ … … 54 55 * @param parser Opaque HID report parser structure. 55 56 * @param data Data for the report. 57 * @param size Size of the data in bytes. 56 58 * @param callbacks Callbacks for report actions. 57 59 * @param arg Custom argument (passed through to the callbacks). … … 64 66 int i; 65 67 66 /* main parsing loop */ 67 while(0){ 68 } 68 // TODO: parse report 69 69 70 71 uint8_t keys[6]; 70 uint16_t keys[6]; 72 71 73 72 for (i = 0; i < 6; ++i) { … … 75 74 } 76 75 77 callbacks->keyboard(keys, 6, 0, arg); 78 79 return EOK; 80 } 81 82 /** Free the HID report parser structure 83 * 84 * @param parser Opaque HID report parser structure 85 * @return Error code 86 */ 87 int usb_hid_free_report_parser(usb_hid_report_parser_t *parser) 88 { 89 76 callbacks->keyboard(keys, 6, arg); 77 90 78 return EOK; 91 79 } … … 93 81 94 82 /** 95 * Parse input report.96 *97 * @param data Data for report98 * @param size Size of report99 * @param callbacks Callbacks for report actions100 * @param arg Custom arguments101 *102 * @return Error code103 */104 int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,105 const usb_hid_report_in_callbacks_t *callbacks, void *arg)106 {107 int i;108 usb_hid_report_item_t item;109 110 /* fill item due to the boot protocol report descriptor */111 // modifier keys are in the first byte112 uint8_t modifiers = data[0];113 114 item.offset = 2; /* second byte is reserved */115 item.size = 8;116 item.count = 6;117 item.usage_min = 0;118 item.usage_max = 255;119 item.logical_min = 0;120 item.logical_max = 255;121 122 if(size != 8){123 return -1;124 }125 126 uint8_t keys[6];127 for(i=item.offset; i<item.count; i++) {128 keys[i-2] = data[i];129 }130 131 callbacks->keyboard(keys, 6, modifiers, arg);132 return EOK;133 }134 135 /**136 * Makes output report for keyboard boot protocol137 *138 * @param leds139 * @param output Output report data buffer140 * @param size Size of the output buffer141 * @return Error code142 */143 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size)144 {145 if(size != 1){146 return -1;147 }148 149 /* used only first five bits, others are only padding*/150 *data = leds;151 return EOK;152 }153 154 /**155 83 * @} 156 84 */ -
uspace/srv/devman/main.c
rff8ed06 rc9d5577 479 479 } 480 480 481 //printf(NAME ": devman_forward: forward connection to device %s to "482 //"driver %s.\n", dev->pathname, driver->name);481 printf(NAME ": devman_forward: forward connection to device %s to " 482 "driver %s.\n", dev->pathname, driver->name); 483 483 ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE); 484 484 }
Note:
See TracChangeset
for help on using the changeset viewer.