Changes in / [e69f10b:7351dc3] in mainline
- Location:
- uspace/drv
- Files:
-
- 2 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/utils/device_keeper.c
re69f10b r7351dc3 35 35 #include <assert.h> 36 36 #include <errno.h> 37 #include <usb/debug.h>38 37 39 38 #include "device_keeper.h" … … 121 120 case 0x9: /* set configuration */ 122 121 case 0x11: /* set interface */ 123 /* target must be device */ 124 if ((data[0] & 0xf) == 0) { 125 instance->devices[target.address].toggle_status = 0; 126 } 122 instance->devices[target.address].toggle_status = 0; 127 123 break; 128 124 } -
uspace/drv/usbhid/Makefile
re69f10b r7351dc3 42 42 hidreq.c \ 43 43 kbddev.c \ 44 kbdrepeat.c \45 44 hiddev.c \ 46 45 $(STOLEN_LAYOUT_SOURCES) -
uspace/drv/usbhid/conv.c
re69f10b r7351dc3 40 40 #include "conv.h" 41 41 42 /**43 * Mapping between USB HID key codes (from HID Usage Tables) and corresponding44 * HelenOS key codes.45 */46 42 static int scanmap_simple[255] = { 47 43 … … 167 163 }; 168 164 169 /**170 * Translate USB HID key codes (from HID Usage Tables) to generic key codes171 * recognized by HelenOS.172 *173 * @param scancode USB HID key code (from HID Usage Tables).174 *175 * @retval HelenOS key code corresponding to the given USB HID key code.176 */177 165 unsigned int usbhid_parse_scancode(int scancode) 178 166 { -
uspace/drv/usbhid/descdump.c
re69f10b r7351dc3 44 44 #define BYTES_PER_LINE 12 45 45 46 /**47 * Dumps the given buffer in hexadecimal format to standard output.48 *49 * @param msg Message to print before the buffer.50 * @param buffer Buffer to print.51 * @param length Size of the buffer in bytes.52 */53 46 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 54 47 { … … 69 62 #define INDENT " " 70 63 71 /**72 * Print standard configuration descriptor to standard output.73 *74 * @param index Index of the descriptor.75 * @param d Standard configuration descriptor to print.76 */77 64 void dump_standard_configuration_descriptor( 78 65 int index, const usb_standard_configuration_descriptor_t *d) … … 97 84 } 98 85 99 /**100 * Print standard interface descriptor to standard output.101 *102 * @param d Standard interface descriptor to print.103 */104 86 void dump_standard_interface_descriptor( 105 87 const usb_standard_interface_descriptor_t *d) … … 117 99 } 118 100 119 /**120 * Print standard endpoint descriptor to standard output.121 *122 * @param d Standard endpoint descriptor to print.123 */124 101 void dump_standard_endpoint_descriptor( 125 102 const usb_standard_endpoint_descriptor_t *d) … … 149 126 } 150 127 151 /**152 * Print standard HID descriptor to standard output.153 *154 * @param d Standard HID descriptor to print.155 */156 128 void dump_standard_hid_descriptor_header( 157 129 const usb_standard_hid_descriptor_t *d) … … 167 139 } 168 140 169 /**170 * Print HID class-specific descriptor header (type and length) to standard171 * output.172 *173 * @param d HID class-specific descriptor header to print.174 */175 141 void dump_standard_hid_class_descriptor_info( 176 142 const usb_standard_hid_class_descriptor_info_t *d) … … 180 146 } 181 147 182 /**183 * Print HID class-specific descriptor (without the header) to standard output.184 *185 * @param index Index of the descriptor.186 * @param type Type of the HID class-specific descriptor (Report or Physical).187 * @param d HID class descriptor to print.188 * @param size Size of the descriptor in bytes.189 */190 148 void dump_hid_class_descriptor(int index, uint8_t type, 191 149 const uint8_t *d, size_t size ) -
uspace/drv/usbhid/hiddev.c
re69f10b r7351dc3 53 53 /* Non-API functions */ 54 54 /*----------------------------------------------------------------------------*/ 55 /** 56 * Retreives HID Report descriptor from the device. 57 * 58 * This function first parses the HID descriptor from the Interface descriptor 59 * to get the size of the Report descriptor and then requests the Report 60 * descriptor from the device. 61 * 62 * @param hid_dev HID device structure. 63 * @param config_desc Full configuration descriptor (including all nested 64 * descriptors). 65 * @param config_desc_size Size of the full configuration descriptor (in bytes). 66 * @param iface_desc Pointer to the interface descriptor inside the full 67 * configuration descriptor (@a config_desc) for the interface 68 * assigned with this device (@a hid_dev). 69 * 70 * @retval EOK if successful. 71 * @retval ENOENT if no HID descriptor could be found. 72 * @retval EINVAL if the HID descriptor or HID report descriptor have different 73 * size than expected. 74 * @retval ENOMEM if some allocation failed. 75 * @return Other value inherited from function usb_request_get_descriptor(). 76 * 77 * @sa usb_request_get_descriptor() 78 */ 55 79 56 static int usbhid_dev_get_report_descriptor(usbhid_dev_t *hid_dev, 80 57 uint8_t *config_desc, size_t config_desc_size, uint8_t *iface_desc) … … 166 143 167 144 /*----------------------------------------------------------------------------*/ 168 /** 169 * Retreives descriptors from the device, initializes pipes and stores 170 * important information from descriptors. 171 * 172 * Initializes the polling pipe described by the given endpoint description 173 * (@a poll_ep_desc). 174 * 175 * Information retreived from descriptors and stored in the HID device structure: 176 * - Assigned interface number (the interface controlled by this instance of 177 * the driver) 178 * - Polling interval (from the interface descriptor) 179 * - Report descriptor 180 * 181 * @param hid_dev HID device structure to be initialized. 182 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint 183 * that has to be present in the device in order to 184 * successfuly initialize the structure. 185 * 186 * @sa usb_endpoint_pipe_initialize_from_configuration(), 187 * usbhid_dev_get_report_descriptor() 188 */ 145 189 146 static int usbhid_dev_process_descriptors(usbhid_dev_t *hid_dev, 190 147 usb_endpoint_description_t *poll_ep_desc) … … 285 242 /* API functions */ 286 243 /*----------------------------------------------------------------------------*/ 287 /** 288 * Creates new uninitialized HID device structure. 289 * 290 * @return Pointer to the new HID device structure, or NULL if an error occured. 291 */ 244 292 245 usbhid_dev_t *usbhid_dev_new(void) 293 246 { … … 316 269 317 270 /*----------------------------------------------------------------------------*/ 318 /** 319 * Properly destroys the HID device structure. 320 * 321 * @note Currently does not clean-up the used pipes, as there are no functions 322 * offering such functionality. 323 * 324 * @param hid_dev Pointer to the structure to be destroyed. 325 */ 271 326 272 void usbhid_dev_free(usbhid_dev_t **hid_dev) 327 273 { … … 346 292 347 293 /*----------------------------------------------------------------------------*/ 348 /** 349 * Initializes HID device structure. 350 * 351 * @param hid_dev HID device structure to be initialized. 352 * @param dev DDF device representing the HID device. 353 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint 354 * that has to be present in the device in order to 355 * successfuly initialize the structure. 356 * 357 * @retval EOK if successful. 358 * @retval EINVAL if some argument is missing. 359 * @return Other value inherited from one of functions 360 * usb_device_connection_initialize_from_device(), 361 * usb_endpoint_pipe_initialize_default_control(), 362 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 363 * usbhid_dev_process_descriptors(). 364 * 365 * @sa usbhid_dev_process_descriptors() 366 */ 294 367 295 int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev, 368 296 usb_endpoint_description_t *poll_ep_desc) … … 424 352 * Get descriptors, parse descriptors and save endpoints. 425 353 */ 426 rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 427 if (rc != EOK) { 428 usb_log_error("Failed to start session on the control pipe: %s" 429 ".\n", str_error(rc)); 430 return rc; 431 } 354 usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 432 355 433 356 rc = usbhid_dev_process_descriptors(hid_dev, poll_ep_desc); 434 if (rc != EOK) { 435 /* TODO: end session?? */ 357 358 usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 359 if (rc != EOK) { 436 360 usb_log_error("Failed to process descriptors: %s.\n", 437 361 str_error(rc)); 438 return rc;439 }440 441 rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);442 if (rc != EOK) {443 usb_log_warning("Failed to start session on the control pipe: "444 "%s.\n", str_error(rc));445 362 return rc; 446 363 } -
uspace/drv/usbhid/hiddev.h
re69f10b r7351dc3 48 48 49 49 /** 50 * USB/HID device type. 51 * 52 * Holds a reference to DDF device structure, and HID-specific data, such 53 * as information about used pipes (one Control pipe and one Interrupt In pipe), 54 * polling interval, assigned interface number, Report descriptor and a 55 * reference to the Report parser used to parse incoming reports and composing 56 * outgoing reports. 50 * @brief USB/HID device type. 57 51 */ 58 52 typedef struct { 59 /** DDF device representing the controlled HID device. */60 53 ddf_dev_t *device; 61 54 62 /** Physical connection to the device. */63 55 usb_device_connection_t wire; 64 /** USB pipe corresponding to the default Control endpoint. */65 56 usb_endpoint_pipe_t ctrl_pipe; 66 /** USB pipe corresponding to the Interrupt In (polling) pipe. */67 57 usb_endpoint_pipe_t poll_pipe; 68 58 69 /** Polling interval retreived from the Interface descriptor. */70 59 short poll_interval; 71 60 72 /** Interface number assigned to this device. */73 61 uint16_t iface; 74 62 75 /** Report descriptor. */76 63 uint8_t *report_desc; 77 78 64 size_t report_desc_size; 79 80 /** HID Report parser. */81 65 usb_hid_report_parser_t *parser; 82 66 83 /** State of the structure (for checking before use). */84 67 int initialized; 85 68 } usbhid_dev_t; -
uspace/drv/usbhid/hidreq.c
re69f10b r7351dc3 46 46 47 47 /*----------------------------------------------------------------------------*/ 48 /** 49 * Send Set Report request to the HID device. 50 * 51 * @param hid_dev HID device to send the request to. 52 * @param type Type of the report. 53 * @param buffer Report data. 54 * @param buf_size Report data size (in bytes). 55 * 56 * @retval EOK if successful. 57 * @retval EINVAL if no HID device is given. 58 * @return Other value inherited from one of functions 59 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 60 * usb_control_request_set(). 61 */ 48 62 49 int usbhid_req_set_report(usbhid_dev_t *hid_dev, 63 50 usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size) … … 110 97 111 98 /*----------------------------------------------------------------------------*/ 112 /** 113 * Send Set Protocol request to the HID device. 114 * 115 * @param hid_dev HID device to send the request to. 116 * @param protocol Protocol to set. 117 * 118 * @retval EOK if successful. 119 * @retval EINVAL if no HID device is given. 120 * @return Other value inherited from one of functions 121 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 122 * usb_control_request_set(). 123 */ 99 124 100 int usbhid_req_set_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t protocol) 125 101 { … … 169 145 170 146 /*----------------------------------------------------------------------------*/ 171 /** 172 * Send Set Idle request to the HID device. 173 * 174 * @param hid_dev HID device to send the request to. 175 * @param duration Duration value (is multiplicated by 4 by the device to 176 * get real duration in miliseconds). 177 * 178 * @retval EOK if successful. 179 * @retval EINVAL if no HID device is given. 180 * @return Other value inherited from one of functions 181 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 182 * usb_control_request_set(). 183 */ 147 184 148 int usbhid_req_set_idle(usbhid_dev_t *hid_dev, uint8_t duration) 185 149 { … … 231 195 232 196 /*----------------------------------------------------------------------------*/ 233 /** 234 * Send Get Report request to the HID device. 235 * 236 * @param[in] hid_dev HID device to send the request to. 237 * @param[in] type Type of the report. 238 * @param[in][out] buffer Buffer for the report data. 239 * @param[in] buf_size Size of the buffer (in bytes). 240 * @param[out] actual_size Actual size of report received from the device 241 * (in bytes). 242 * 243 * @retval EOK if successful. 244 * @retval EINVAL if no HID device is given. 245 * @return Other value inherited from one of functions 246 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 247 * usb_control_request_set(). 248 */ 197 249 198 int usbhid_req_get_report(usbhid_dev_t *hid_dev, usb_hid_report_type_t type, 250 199 uint8_t *buffer, size_t buf_size, size_t *actual_size) … … 297 246 } 298 247 299 /*----------------------------------------------------------------------------*/300 /**301 * Send Get Protocol request to the HID device.302 *303 * @param[in] hid_dev HID device to send the request to.304 * @param[out] protocol Current protocol of the device.305 *306 * @retval EOK if successful.307 * @retval EINVAL if no HID device is given.308 * @return Other value inherited from one of functions309 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),310 * usb_control_request_set().311 */312 248 int usbhid_req_get_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t *protocol) 313 249 { … … 367 303 } 368 304 369 /*----------------------------------------------------------------------------*/370 /**371 * Send Get Idle request to the HID device.372 *373 * @param[in] hid_dev HID device to send the request to.374 * @param[out] duration Duration value (multiplicate by 4 to get real duration375 * in miliseconds).376 *377 * @retval EOK if successful.378 * @retval EINVAL if no HID device is given.379 * @return Other value inherited from one of functions380 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),381 * usb_control_request_set().382 */383 305 int usbhid_req_get_idle(usbhid_dev_t *hid_dev, uint8_t *duration) 384 306 { -
uspace/drv/usbhid/kbddev.c
re69f10b r7351dc3 37 37 #include <errno.h> 38 38 #include <str_error.h> 39 #include <fibril.h> 39 40 #include <stdio.h> 40 41 … … 42 43 #include <ipc/kbd.h> 43 44 #include <async.h> 44 #include <fibril.h>45 #include <fibril_synch.h>46 45 47 46 #include <usb/usb.h> … … 57 56 #include "layout.h" 58 57 #include "conv.h" 59 #include "kbdrepeat.h" 60 61 /*----------------------------------------------------------------------------*/ 62 /** Default modifiers when the keyboard is initialized. */ 58 59 /*----------------------------------------------------------------------------*/ 60 63 61 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 64 65 /** Boot protocol report size (key part). */66 62 static const size_t BOOTP_REPORT_SIZE = 6; 67 68 /** Boot protocol total report size. */69 63 static const size_t BOOTP_BUFFER_SIZE = 8; 70 71 /** Boot protocol output report size. */72 64 static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 73 74 /** Boot protocol error key code. */75 65 static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 76 77 /** Default idle rate for keyboards. */78 66 static const uint8_t IDLE_RATE = 0; 79 80 /** Delay before a pressed key starts auto-repeating. */81 static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;82 83 /** Delay between two repeats of a pressed key when auto-repeating. */84 static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;85 67 86 68 /** Keyboard polling endpoint description for boot protocol class. */ … … 100 82 #define NUM_LAYOUTS 3 101 83 102 /** Keyboard layout map. */103 84 static layout_op_t *layout[NUM_LAYOUTS] = { 104 85 &us_qwerty_op, … … 112 93 /* Modifier constants */ 113 94 /*----------------------------------------------------------------------------*/ 114 /** Mapping of USB modifier key codes to generic modifier key codes. */ 95 115 96 static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = { 116 97 KC_LCTRL, /* USB_HID_MOD_LCTRL */ … … 133 114 }; 134 115 135 /** 136 * Default handler for IPC methods not handled by DDF. 116 /** Default handler for IPC methods not handled by DDF. 137 117 * 138 * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it 139 * assumes the caller is the console and thus it stores IPC phone to it for 140 * later use by the driver to notify about key events. 141 * 142 * @param fun Device function handling the call. 118 * @param dev Device handling the call. 143 119 * @param icallid Call id. 144 120 * @param icall Call data. … … 171 147 /* Key processing functions */ 172 148 /*----------------------------------------------------------------------------*/ 173 /** 174 * Handles turning of LED lights on and off. 175 * 176 * In case of USB keyboards, the LEDs are handled in the driver, not in the 177 * device. When there should be a change (lock key was pressed), the driver 178 * uses a Set_Report request sent to the device to set the state of the LEDs. 179 * 180 * This functions sets the LED lights according to current settings of modifiers 181 * kept in the keyboard device structure. 182 * 183 * @param kbd_dev Keyboard device structure. 184 */ 149 185 150 static void usbhid_kbd_set_led(usbhid_kbd_t *kbd_dev) 186 151 { … … 224 189 225 190 /*----------------------------------------------------------------------------*/ 226 /** 227 * Processes key events. 228 * 229 * @note This function was copied from AT keyboard driver and modified to suit 230 * USB keyboard. 231 * 232 * @note Lock keys are not sent to the console, as they are completely handled 233 * in the driver. It may, however, be required later that the driver 234 * sends also these keys to application (otherwise it cannot use those 235 * keys at all). 236 * 237 * @param kbd_dev Keyboard device structure. 238 * @param type Type of the event (press / release). Recognized values: 239 * KEY_PRESS, KEY_RELEASE 240 * @param key Key code of the key according to HID Usage Tables. 241 */ 242 void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key) 191 192 static void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, 193 unsigned int key) 243 194 { 244 195 console_event_t ev; 245 196 unsigned mod_mask; 246 197 247 /* 248 * These parts are copy-pasted from the AT keyboard driver. 249 * 250 * They definitely require some refactoring, but will keep it for later 251 * when the console and keyboard system is changed in HelenOS. 252 */ 198 // TODO: replace by our own parsing?? or are the key codes identical?? 253 199 switch (key) { 254 200 case KC_LCTRL: mod_mask = KM_LCTRL; break; … … 282 228 * up the lock state. 283 229 */ 284 unsigned int locks_old = kbd_dev->lock_keys;285 286 230 kbd_dev->mods = 287 231 kbd_dev->mods ^ (mod_mask & ~kbd_dev->lock_keys); … … 289 233 290 234 /* Update keyboard lock indicator lights. */ 291 if (kbd_dev->lock_keys != locks_old) { 292 usbhid_kbd_set_led(kbd_dev); 293 } 235 usbhid_kbd_set_led(kbd_dev); 294 236 } else { 295 237 kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask; … … 338 280 339 281 /*----------------------------------------------------------------------------*/ 340 /** 341 * Checks if modifiers were pressed or released and generates key events. 342 * 343 * @param kbd_dev Keyboard device structure. 344 * @param modifiers Bitmap of modifiers. 345 * 346 * @sa usbhid_kbd_push_ev() 347 */ 282 348 283 static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev, 349 284 uint8_t modifiers) … … 381 316 382 317 /*----------------------------------------------------------------------------*/ 383 /** 384 * Checks if some keys were pressed or released and generates key events. 385 * 386 * An event is created only when key is pressed or released. Besides handling 387 * the events (usbhid_kbd_push_ev()), the auto-repeat fibril is notified about 388 * key presses and releases (see usbhid_kbd_repeat_start() and 389 * usbhid_kbd_repeat_stop()). 390 * 391 * @param kbd_dev Keyboard device structure. 392 * @param key_codes Parsed keyboard report - codes of currently pressed keys 393 * according to HID Usage Tables. 394 * @param count Number of key codes in report (size of the report). 395 * 396 * @sa usbhid_kbd_push_ev(), usbhid_kbd_repeat_start(), usbhid_kbd_repeat_stop() 397 */ 318 398 319 static void usbhid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev, 399 const uint8_t *key_codes , size_t count)320 const uint8_t *key_codes) 400 321 { 401 322 unsigned int key; … … 407 328 i = 0; 408 329 // all fields should report Error Rollover 409 while (i < count &&330 while (i < kbd_dev->keycode_count && 410 331 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 411 332 ++i; 412 333 } 413 if (i == count) {334 if (i == kbd_dev->keycode_count) { 414 335 usb_log_debug("Phantom state occured.\n"); 415 336 // phantom state, do nothing … … 417 338 } 418 339 419 /* TODO: quite dummy right now, think of better implementation */ 420 assert(count == kbd_dev->key_count); 340 // TODO: quite dummy right now, think of better implementation 421 341 422 342 /* 423 343 * 1) Key releases 424 344 */ 425 for (j = 0; j < count; ++j) {345 for (j = 0; j < kbd_dev->keycode_count; ++j) { 426 346 // try to find the old key in the new key list 427 347 i = 0; 428 while (i < kbd_dev->key _count429 && key_codes[i] != kbd_dev->key s[j]) {348 while (i < kbd_dev->keycode_count 349 && key_codes[i] != kbd_dev->keycodes[j]) { 430 350 ++i; 431 351 } 432 352 433 if (i == count) {353 if (i == kbd_dev->keycode_count) { 434 354 // not found, i.e. the key was released 435 key = usbhid_parse_scancode(kbd_dev->keys[j]); 436 usbhid_kbd_repeat_stop(kbd_dev, key); 355 key = usbhid_parse_scancode(kbd_dev->keycodes[j]); 437 356 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key); 438 357 usb_log_debug2("Key released: %d\n", key); … … 445 364 * 1) Key presses 446 365 */ 447 for (i = 0; i < kbd_dev->key _count; ++i) {366 for (i = 0; i < kbd_dev->keycode_count; ++i) { 448 367 // try to find the new key in the old key list 449 368 j = 0; 450 while (j < count && kbd_dev->keys[j] != key_codes[i]) { 369 while (j < kbd_dev->keycode_count 370 && kbd_dev->keycodes[j] != key_codes[i]) { 451 371 ++j; 452 372 } 453 373 454 if (j == count) {374 if (j == kbd_dev->keycode_count) { 455 375 // not found, i.e. new key pressed 456 376 key = usbhid_parse_scancode(key_codes[i]); … … 458 378 key_codes[i]); 459 379 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); 460 usbhid_kbd_repeat_start(kbd_dev, key); 461 } else {size_t 380 } else { 462 381 // found, nothing happens 463 382 } 464 383 } 465 466 memcpy(kbd_dev->keys, key_codes, count); 384 // // report all currently pressed keys 385 // for (i = 0; i < kbd_dev->keycode_count; ++i) { 386 // if (key_codes[i] != 0) { 387 // key = usbhid_parse_scancode(key_codes[i]); 388 // usb_log_debug2("Key pressed: %d (keycode: %d)\n", key, 389 // key_codes[i]); 390 // usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); 391 // } 392 // } 393 394 memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count); 467 395 468 396 usb_log_debug("New stored keycodes: %s\n", 469 usb_debug_str_buffer(kbd_dev->key s, kbd_dev->key_count, 0));397 usb_debug_str_buffer(kbd_dev->keycodes, kbd_dev->keycode_count, 0)); 470 398 } 471 399 … … 473 401 /* Callbacks for parser */ 474 402 /*----------------------------------------------------------------------------*/ 475 /** 476 * Callback function for the HID report parser. 477 * 478 * This function is called by the HID report parser with the parsed report. 479 * The parsed report is used to check if any events occured (key was pressed or 480 * released, modifier was pressed or released). 481 * 482 * @param key_codes Parsed keyboard report - codes of currently pressed keys 483 * according to HID Usage Tables. 484 * @param count Number of key codes in report (size of the report). 485 * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI). 486 * @param arg User-specified argument. Expects pointer to the keyboard device 487 * structure representing the keyboard. 488 * 489 * @sa usbhid_kbd_check_key_changes(), usbhid_kbd_check_modifier_changes() 490 */ 403 491 404 static void usbhid_kbd_process_keycodes(const uint8_t *key_codes, size_t count, 492 405 uint8_t modifiers, void *arg) … … 502 415 503 416 usb_log_debug("Got keys from parser: %s\n", 504 usb_debug_str_buffer(key_codes, kbd_dev->key _count, 0));505 506 if (count != kbd_dev->key _count) {417 usb_debug_str_buffer(key_codes, kbd_dev->keycode_count, 0)); 418 419 if (count != kbd_dev->keycode_count) { 507 420 usb_log_warning("Number of received keycodes (%d) differs from" 508 " expected number (%d).\n", count, kbd_dev->key _count);421 " expected number (%d).\n", count, kbd_dev->keycode_count); 509 422 return; 510 423 } 511 424 512 425 usbhid_kbd_check_modifier_changes(kbd_dev, modifiers); 513 usbhid_kbd_check_key_changes(kbd_dev, key_codes , count);426 usbhid_kbd_check_key_changes(kbd_dev, key_codes); 514 427 } 515 428 … … 517 430 /* General kbd functions */ 518 431 /*----------------------------------------------------------------------------*/ 519 /** 520 * Processes data received from the device in form of report. 521 * 522 * This function uses the HID report parser to translate the data received from 523 * the device into generic USB HID key codes and into generic modifiers bitmap. 524 * The parser then calls the given callback (usbhid_kbd_process_keycodes()). 525 * 526 * @note Currently, only the boot protocol is supported. 527 * 528 * @param kbd_dev Keyboard device structure (must be initialized). 529 * @param buffer Data from the keyboard (i.e. the report). 530 * @param actual_size Size of the data from keyboard (report size) in bytes. 531 * 532 * @sa usbhid_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report(). 533 */ 432 534 433 static void usbhid_kbd_process_data(usbhid_kbd_t *kbd_dev, 535 434 uint8_t *buffer, size_t actual_size) … … 558 457 /* HID/KBD structure manipulation */ 559 458 /*----------------------------------------------------------------------------*/ 560 /** 561 * Creates a new USB/HID keyboard structure. 562 * 563 * The structure returned by this function is not initialized. Use 564 * usbhid_kbd_init() to initialize it prior to polling. 565 * 566 * @return New uninitialized structure for representing a USB/HID keyboard or 567 * NULL if not successful (memory error). 568 */ 459 569 460 static usbhid_kbd_t *usbhid_kbd_new(void) 570 461 { … … 592 483 593 484 /*----------------------------------------------------------------------------*/ 594 /** 595 * Properly destroys the USB/HID keyboard structure. 596 * 597 * @param kbd_dev Pointer to the structure to be destroyed. 598 */ 485 599 486 static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev) 600 487 { … … 611 498 } 612 499 613 if ((*kbd_dev)->repeat_mtx != NULL) {614 /* TODO: replace by some check and wait */615 assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));616 free((*kbd_dev)->repeat_mtx);617 }618 619 500 usb_hid_free_report_parser((*kbd_dev)->parser); 620 501 … … 624 505 625 506 /*----------------------------------------------------------------------------*/ 626 /** 627 * Initialization of the USB/HID keyboard structure. 628 * 629 * This functions initializes required structures from the device's descriptors. 630 * 631 * During initialization, the keyboard is switched into boot protocol, the idle 632 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 633 * when a key is pressed or released. Finally, the LED lights are turned on 634 * according to the default setup of lock keys. 635 * 636 * @note By default, the keyboards is initialized with Num Lock turned on and 637 * other locks turned off. 638 * 639 * @param kbd_dev Keyboard device structure to be initialized. 640 * @param dev DDF device structure of the keyboard. 641 * 642 * @retval EOK if successful. 643 * @retval EINVAL if some parameter is not given. 644 * @return Other value inherited from function usbhid_dev_init(). 645 */ 507 646 508 static int usbhid_kbd_init(usbhid_kbd_t *kbd_dev, ddf_dev_t *dev) 647 509 { … … 678 540 679 541 // save the size of the report (boot protocol report by default) 680 kbd_dev->key _count = BOOTP_REPORT_SIZE;681 kbd_dev->key s = (uint8_t *)calloc(682 kbd_dev->key _count, sizeof(uint8_t));683 684 if (kbd_dev->key s == NULL) {542 kbd_dev->keycode_count = BOOTP_REPORT_SIZE; 543 kbd_dev->keycodes = (uint8_t *)calloc( 544 kbd_dev->keycode_count, sizeof(uint8_t)); 545 546 if (kbd_dev->keycodes == NULL) { 685 547 usb_log_fatal("No memory!\n"); 686 return ENOMEM;548 return rc; 687 549 } 688 550 … … 691 553 kbd_dev->lock_keys = 0; 692 554 693 kbd_dev->repeat.key_new = 0;694 kbd_dev->repeat.key_repeated = 0;695 kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;696 kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;697 698 kbd_dev->repeat_mtx = (fibril_mutex_t *)(699 malloc(sizeof(fibril_mutex_t)));700 if (kbd_dev->repeat_mtx == NULL) {701 usb_log_fatal("No memory!\n");702 free(kbd_dev->keys);703 return ENOMEM;704 }705 706 fibril_mutex_initialize(kbd_dev->repeat_mtx);707 708 555 /* 709 556 * Set boot protocol. … … 728 575 /* HID/KBD polling */ 729 576 /*----------------------------------------------------------------------------*/ 730 /** 731 * Main keyboard polling function. 732 * 733 * This function uses the Interrupt In pipe of the keyboard to poll for events. 734 * The keyboard is initialized in a way that it reports only when a key is 735 * pressed or released, so there is no actual need for any sleeping between 736 * polls (see usbhid_kbd_try_add_device() or usbhid_kbd_init()). 737 * 738 * @param kbd_dev Initialized keyboard structure representing the device to 739 * poll. 740 * 741 * @sa usbhid_kbd_process_data() 742 */ 577 743 578 static void usbhid_kbd_poll(usbhid_kbd_t *kbd_dev) 744 579 { … … 763 598 usb_log_warning("Failed to start a session: %s.\n", 764 599 str_error(sess_rc)); 765 break;600 continue; 766 601 } 767 602 … … 775 610 usb_log_warning("Error polling the keyboard: %s.\n", 776 611 str_error(rc)); 777 break;612 continue; 778 613 } 779 614 … … 781 616 usb_log_warning("Error closing session: %s.\n", 782 617 str_error(sess_rc)); 783 break;618 continue; 784 619 } 785 620 … … 802 637 //async_usleep(kbd_dev->hid_dev->poll_interval); 803 638 } 804 } 805 806 /*----------------------------------------------------------------------------*/ 807 /** 808 * Function executed by the main driver fibril. 809 * 810 * Just starts polling the keyboard for events. 811 * 812 * @param arg Initialized keyboard device structure (of type usbhid_kbd_t) 813 * representing the device. 814 * 815 * @retval EOK if the fibril finished polling the device. 816 * @retval EINVAL if no device was given in the argument. 817 * 818 * @sa usbhid_kbd_poll() 819 * 820 * @todo Change return value - only case when the fibril finishes is in case 821 * of some error, so the error should probably be propagated from function 822 * usbhid_kbd_poll() to here and up. 823 */ 639 640 // not reached 641 assert(0); 642 } 643 644 /*----------------------------------------------------------------------------*/ 645 824 646 static int usbhid_kbd_fibril(void *arg) 825 647 { … … 843 665 /* API functions */ 844 666 /*----------------------------------------------------------------------------*/ 845 /** 846 * Function for adding a new device of type USB/HID/keyboard. 847 * 848 * This functions initializes required structures from the device's descriptors 849 * and starts new fibril for polling the keyboard for events and another one for 850 * handling auto-repeat of keys. 851 * 852 * During initialization, the keyboard is switched into boot protocol, the idle 853 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 854 * when a key is pressed or released. Finally, the LED lights are turned on 855 * according to the default setup of lock keys. 856 * 857 * @note By default, the keyboards is initialized with Num Lock turned on and 858 * other locks turned off. 859 * @note Currently supports only boot-protocol keyboards. 860 * 861 * @param dev Device to add. 862 * 863 * @retval EOK if successful. 864 * @retval ENOMEM if there 865 * @return Other error code inherited from one of functions usbhid_kbd_init(), 866 * ddf_fun_bind() and ddf_fun_add_to_class(). 867 * 868 * @sa usbhid_kbd_fibril(), usbhid_kbd_repeat_fibril() 869 */ 667 870 668 int usbhid_kbd_try_add_device(ddf_dev_t *dev) 871 669 { … … 889 687 "structure.\n"); 890 688 ddf_fun_destroy(kbd_fun); 891 return E NOMEM; // TODO: some other code??689 return EINVAL; // TODO: some other code?? 892 690 } 893 691 … … 938 736 } 939 737 fibril_add_ready(fid); 940 941 /*942 * Create new fibril for auto-repeat943 */944 fid = fibril_create(usbhid_kbd_repeat_fibril, kbd_dev);945 if (fid == 0) {946 usb_log_error("Failed to start fibril for KBD auto-repeat");947 return ENOMEM;948 }949 fibril_add_ready(fid);950 738 951 739 (void)keyboard_ops; -
uspace/drv/usbhid/kbddev.h
re69f10b r7351dc3 39 39 #include <stdint.h> 40 40 41 #include <fibril_synch.h>42 43 41 #include <usb/classes/hid.h> 44 42 #include <usb/classes/hidparser.h> … … 49 47 50 48 /*----------------------------------------------------------------------------*/ 49 51 50 /** 52 * Structure for keeping information needed for auto-repeat of keys.51 * @brief USB/HID keyboard device type. 53 52 */ 54 53 typedef struct { 55 /** Last pressed key. */56 unsigned int key_new;57 /** Key to be repeated. */58 unsigned int key_repeated;59 /** Delay before first repeat in microseconds. */60 unsigned int delay_before;61 /** Delay between repeats in microseconds. */62 unsigned int delay_between;63 } usbhid_kbd_repeat_t;64 65 /**66 * USB/HID keyboard device type.67 *68 * Holds a reference to generic USB/HID device structure and keyboard-specific69 * data, such as currently pressed keys, modifiers and lock keys.70 *71 * Also holds a IPC phone to the console (since there is now no other way to72 * communicate with it).73 *74 * @note Storing active lock keys in this structure results in their setting75 * being device-specific.76 */77 typedef struct {78 /** Structure holding generic USB/HID device information. */79 54 usbhid_dev_t *hid_dev; 80 55 81 /** Currently pressed keys (not translated to key codes). */ 82 uint8_t *keys; 83 /** Count of stored keys (i.e. number of keys in the report). */ 84 size_t key_count; 85 /** Currently pressed modifiers (bitmap). */ 56 uint8_t *keycodes; 57 size_t keycode_count; 86 58 uint8_t modifiers; 87 59 88 /** Currently active modifiers including locks. Sent to the console. */89 60 unsigned mods; 90 91 /** Currently active lock keys. */92 61 unsigned lock_keys; 93 62 94 /** IPC phone to the console device (for sending key events). */95 63 int console_phone; 96 64 97 /** Information for auto-repeat of keys. */98 usbhid_kbd_repeat_t repeat;99 100 /** Mutex for accessing the information about auto-repeat. */101 fibril_mutex_t *repeat_mtx;102 103 65 usb_hid_report_parser_t *parser; 104 66 105 /** State of the structure (for checking before use). */106 67 int initialized; 107 68 } usbhid_kbd_t; … … 111 72 int usbhid_kbd_try_add_device(ddf_dev_t *dev); 112 73 113 void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key);114 115 74 #endif /* USBHID_KBDDEV_H_ */ 116 75 -
uspace/drv/usbhid/main.c
re69f10b r7351dc3 47 47 48 48 /*----------------------------------------------------------------------------*/ 49 /** 50 * Callback for passing a new device to the driver. 51 * 52 * @note Currently, only boot-protocol keyboards are supported by this driver. 53 * 54 * @param dev Structure representing the new device. 55 * 56 * @retval EOK if successful. 57 * @retval EREFUSED if the device is not supported. 58 */ 49 59 50 static int usbhid_add_device(ddf_dev_t *dev) 60 51 {
Note:
See TracChangeset
for help on using the changeset viewer.