Changeset 8ff0bd2 in mainline for uspace/drv/bus/usb/usbhid/mouse/mousedev.c
- Timestamp:
- 2011-09-04T11:30:58Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 03bc76a
- Parents:
- d2c67e7 (diff), deac215e (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
rd2c67e7 r8ff0bd2 44 44 #include <async_obsolete.h> 45 45 #include <str_error.h> 46 #include <ipc/mouse .h>46 #include <ipc/mouseev.h> 47 47 #include <io/console.h> 48 48 49 #include <ipc/kbd .h>49 #include <ipc/kbdev.h> 50 50 #include <io/keycode.h> 51 51 … … 53 53 #include "../usbhid.h" 54 54 55 /** Number of simulated arrow-key presses for singel wheel step. */ 56 #define ARROWS_PER_SINGLE_WHEEL 3 57 55 58 // FIXME: remove this header 56 #include < kernel/ipc/ipc_methods.h>59 #include <abi/ipc/methods.h> 57 60 58 61 #define NAME "mouse" … … 71 74 const char *HID_MOUSE_FUN_NAME = "mouse"; 72 75 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel"; 73 const char *HID_MOUSE_C LASS_NAME= "mouse";74 const char *HID_MOUSE_WHEEL_C LASS_NAME= "keyboard";76 const char *HID_MOUSE_CATEGORY = "mouse"; 77 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard"; 75 78 76 79 /** Default idle rate for mouses. */ … … 180 183 /*----------------------------------------------------------------------------*/ 181 184 182 static void usb_mouse_ free(usb_mouse_t **mouse_dev)183 { 184 assert(mouse_dev != NULL && *mouse_dev != NULL);185 static void usb_mouse_destroy(usb_mouse_t *mouse_dev) 186 { 187 assert(mouse_dev != NULL); 185 188 186 189 // hangup phone to the console 187 if ((*mouse_dev)->mouse_phone >= 0) { 188 async_obsolete_hangup((*mouse_dev)->mouse_phone); 189 } 190 191 if ((*mouse_dev)->wheel_phone >= 0) { 192 async_obsolete_hangup((*mouse_dev)->wheel_phone); 193 } 194 195 free(*mouse_dev); 196 *mouse_dev = NULL; 190 if (mouse_dev->mouse_phone >= 0) { 191 async_obsolete_hangup(mouse_dev->mouse_phone); 192 } 193 194 if (mouse_dev->wheel_phone >= 0) { 195 async_obsolete_hangup(mouse_dev->wheel_phone); 196 } 197 197 } 198 198 … … 201 201 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel) 202 202 { 203 kbd_event_t ev; 204 205 ev.type = KEY_PRESS; 206 ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0; 207 ev.mods = 0; 208 ev.c = 0; 203 unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN; 209 204 210 205 if (mouse_dev->wheel_phone < 0) { 211 206 usb_log_warning( 212 "Connection to console not ready, keydiscarded.\n");207 "Connection to console not ready, wheel roll discarded.\n"); 213 208 return; 214 209 } 215 210 216 int count = ( wheel < 0) ? -wheel : wheel;211 int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 217 212 int i; 218 213 219 for (i = 0; i < count * 3; ++i) { 220 usb_log_debug2("Sending key %d to the console\n", ev.key); 221 async_obsolete_msg_4(mouse_dev->wheel_phone, KBD_EVENT, ev.type, 222 ev.key, ev.mods, ev.c); 223 // send key release right away 224 async_obsolete_msg_4(mouse_dev->wheel_phone, KBD_EVENT, KEY_RELEASE, 225 ev.key, ev.mods, ev.c); 226 } 227 } 228 229 /*----------------------------------------------------------------------------*/ 230 231 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 232 usb_mouse_t *mouse_dev, uint8_t *buffer, 233 size_t buffer_size) 214 for (i = 0; i < count; i++) { 215 /* Send arrow press and release. */ 216 usb_log_debug2("Sending key %d to the console\n", key); 217 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, 218 KEY_PRESS, key, 0, 0); 219 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, 220 KEY_RELEASE, key, 0, 0); 221 } 222 } 223 224 /*----------------------------------------------------------------------------*/ 225 226 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report, 227 int32_t usage) 228 { 229 int result = 0; 230 231 usb_hid_report_path_t *path = usb_hid_report_path(); 232 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 233 usage); 234 235 usb_hid_report_path_set_report_id(path, rid); 236 237 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 238 report, NULL, path, USB_HID_PATH_COMPARE_END, 239 USB_HID_REPORT_TYPE_INPUT); 240 241 if (field != NULL) { 242 result = field->value; 243 } 244 245 usb_hid_report_path_free(path); 246 247 return result; 248 } 249 250 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 251 usb_mouse_t *mouse_dev) 234 252 { 235 253 assert(mouse_dev != NULL); 236 237 usb_log_debug2("got buffer: %s.\n",238 usb_debug_str_buffer(buffer, buffer_size, 0));239 254 240 255 if (mouse_dev->mouse_phone < 0) { … … 243 258 } 244 259 245 /* 246 * parse the input report 247 */ 248 249 usb_log_debug(NAME " Calling usb_hid_parse_report() with " 250 "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0)); 251 252 uint8_t report_id; 253 254 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 255 &report_id); 256 257 if (rc != EOK) { 258 usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n", 259 str_error(rc)); 260 return true; 261 } 262 263 /* 264 * X 265 */ 266 int shift_x = 0; 267 268 usb_hid_report_path_t *path = usb_hid_report_path(); 269 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 270 USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 271 272 usb_hid_report_path_set_report_id(path, report_id); 273 274 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 275 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 276 USB_HID_REPORT_TYPE_INPUT); 277 278 if (field != NULL) { 279 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 280 field->usage); 281 shift_x = field->value; 282 } 283 284 usb_hid_report_path_free(path); 285 286 /* 287 * Y 288 */ 289 int shift_y = 0; 290 291 path = usb_hid_report_path(); 292 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 293 USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 294 295 usb_hid_report_path_set_report_id(path, report_id); 296 297 field = usb_hid_report_get_sibling( 298 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 299 USB_HID_REPORT_TYPE_INPUT); 300 301 if (field != NULL) { 302 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 303 field->usage); 304 shift_y = field->value; 305 } 306 307 usb_hid_report_path_free(path); 308 260 int shift_x = get_mouse_axis_move_value(hid_dev->report_id, 261 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 262 int shift_y = get_mouse_axis_move_value(hid_dev->report_id, 263 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 264 int wheel = get_mouse_axis_move_value(hid_dev->report_id, 265 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 266 309 267 if ((shift_x != 0) || (shift_y != 0)) { 310 268 async_obsolete_req_2_0(mouse_dev->mouse_phone, 311 MEVENT_MOVE, shift_x, shift_y); 312 } 313 314 /* 315 * Wheel 316 */ 317 int wheel = 0; 318 319 path = usb_hid_report_path(); 320 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 321 USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 322 323 usb_hid_report_path_set_report_id(path, report_id); 324 325 field = usb_hid_report_get_sibling( 326 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 327 USB_HID_REPORT_TYPE_INPUT); 328 329 if (field != NULL) { 330 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 331 field->usage); 332 wheel = field->value; 333 } 334 335 usb_hid_report_path_free(path); 336 337 // send arrow up for positive direction and arrow down for negative 338 // direction; three arrows for difference of 1 339 usb_mouse_send_wheel(mouse_dev, wheel); 340 269 MOUSEEV_MOVE_EVENT, shift_x, shift_y); 270 } 271 272 if (wheel != 0) { 273 usb_mouse_send_wheel(mouse_dev, wheel); 274 } 341 275 342 276 /* 343 277 * Buttons 344 278 */ 345 path = usb_hid_report_path();279 usb_hid_report_path_t *path = usb_hid_report_path(); 346 280 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 347 usb_hid_report_path_set_report_id(path, report_id);348 349 field = usb_hid_report_get_sibling(281 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 282 283 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 350 284 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 351 285 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, … … 353 287 354 288 while (field != NULL) { 355 usb_log_debug (NAME " VALUE(%X) USAGE(%X)\n", field->value,289 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value, 356 290 field->usage); 357 291 … … 359 293 && field->value != 0) { 360 294 async_obsolete_req_2_0(mouse_dev->mouse_phone, 361 M EVENT_BUTTON, field->usage, 1);295 MOUSEEV_BUTTON_EVENT, field->usage, 1); 362 296 mouse_dev->buttons[field->usage - field->usage_minimum] 363 297 = field->value; 364 } else if ( 365 mouse_dev->buttons[field->usage - field->usage_minimum] != 0 298 } else if (mouse_dev->buttons[field->usage - field->usage_minimum] != 0 366 299 && field->value == 0) { 367 368 M EVENT_BUTTON, field->usage, 0);369 mouse_dev->buttons[field->usage - field->usage_minimum]370 =field->value;371 300 async_obsolete_req_2_0(mouse_dev->mouse_phone, 301 MOUSEEV_BUTTON_EVENT, field->usage, 0); 302 mouse_dev->buttons[field->usage - field->usage_minimum] = 303 field->value; 304 } 372 305 373 306 field = usb_hid_report_get_sibling( … … 389 322 assert(mouse != NULL); 390 323 391 /* Create the function exposed under /dev/devices. */324 /* Create the exposed function. */ 392 325 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); 393 326 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, … … 409 342 } 410 343 411 usb_log_debug("Adding DDF function to c lass%s...\n",412 HID_MOUSE_C LASS_NAME);413 rc = ddf_fun_add_to_c lass(fun, HID_MOUSE_CLASS_NAME);344 usb_log_debug("Adding DDF function to category %s...\n", 345 HID_MOUSE_CATEGORY); 346 rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY); 414 347 if (rc != EOK) { 415 348 usb_log_error( 416 "Could not add DDF function to c lass%s: %s.\n",417 HID_MOUSE_C LASS_NAME, str_error(rc));349 "Could not add DDF function to category %s: %s.\n", 350 HID_MOUSE_CATEGORY, str_error(rc)); 418 351 ddf_fun_destroy(fun); 419 352 return rc; … … 447 380 } 448 381 449 usb_log_debug("Adding DDF function to c lass%s...\n",450 HID_MOUSE_WHEEL_C LASS_NAME);451 rc = ddf_fun_add_to_c lass(fun, HID_MOUSE_WHEEL_CLASS_NAME);382 usb_log_debug("Adding DDF function to category %s...\n", 383 HID_MOUSE_WHEEL_CATEGORY); 384 rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY); 452 385 if (rc != EOK) { 453 386 usb_log_error( 454 "Could not add DDF function to c lass%s: %s.\n",455 HID_MOUSE_WHEEL_C LASS_NAME, str_error(rc));387 "Could not add DDF function to category %s: %s.\n", 388 HID_MOUSE_WHEEL_CATEGORY, str_error(rc)); 456 389 ddf_fun_destroy(fun); 457 390 return rc; … … 501 434 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 502 435 if (rc != EOK) { 503 usb_mouse_ free(&mouse_dev);436 usb_mouse_destroy(mouse_dev); 504 437 return rc; 505 438 } … … 510 443 /*----------------------------------------------------------------------------*/ 511 444 512 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data, 513 uint8_t *buffer, size_t buffer_size) 514 { 515 usb_log_debug("usb_mouse_polling_callback()\n"); 516 usb_debug_str_buffer(buffer, buffer_size, 0); 517 445 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data) 446 { 518 447 if (hid_dev == NULL || data == NULL) { 519 448 usb_log_error("Missing argument to the mouse polling callback." … … 524 453 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 525 454 526 return usb_mouse_process_report(hid_dev, mouse_dev, buffer, 527 buffer_size); 455 return usb_mouse_process_report(hid_dev, mouse_dev); 528 456 } 529 457 … … 533 461 { 534 462 if (data != NULL) { 535 usb_mouse_ free((usb_mouse_t **)&data);463 usb_mouse_destroy((usb_mouse_t *)data); 536 464 } 537 465 }
Note:
See TracChangeset
for help on using the changeset viewer.