Changeset 76fbd9a in mainline for uspace/drv/bus/usb/usbhid
- Timestamp:
- 2012-02-24T19:07:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a76b01b4
- Parents:
- 5837c7a
- Location:
- uspace/drv/bus/usb/usbhid
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/generic/hiddev.c
r5837c7a r76fbd9a 46 46 #include "usbhid.h" 47 47 48 /*----------------------------------------------------------------------------*/ 48 49 49 50 50 const usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = { … … 60 60 const char *HID_GENERIC_CLASS_NAME = "hid"; 61 61 62 /*----------------------------------------------------------------------------*/ 62 63 63 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun); 64 64 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer, … … 68 68 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc, 69 69 size_t size, size_t *actual_size); 70 /*----------------------------------------------------------------------------*/ 70 71 71 static usbhid_iface_t usb_generic_iface = { 72 72 .get_event = usb_generic_hid_get_event, … … 75 75 .get_report_descriptor = usb_generic_get_report_descriptor 76 76 }; 77 /*----------------------------------------------------------------------------*/ 77 78 78 static ddf_dev_ops_t usb_generic_hid_ops = { 79 79 .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface, 80 80 .open = usb_generic_hid_client_connected 81 81 }; 82 /*----------------------------------------------------------------------------*/ 82 83 83 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun) 84 84 { … … 97 97 return hid_dev->max_input_report_size; 98 98 } 99 /*----------------------------------------------------------------------------*/ 99 100 100 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer, 101 101 size_t size, size_t *act_size, int *event_nr, unsigned int flags) … … 127 127 return EOK; 128 128 } 129 /*----------------------------------------------------------------------------*/ 129 130 130 static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun) 131 131 { … … 144 144 return hid_dev->report_desc_size; 145 145 } 146 /*----------------------------------------------------------------------------*/ 146 147 147 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc, 148 148 size_t size, size_t *actual_size) … … 166 166 return EOK; 167 167 } 168 /*----------------------------------------------------------------------------*/ 168 169 169 static int usb_generic_hid_client_connected(ddf_fun_t *fun) 170 170 { … … 172 172 return EOK; 173 173 } 174 /*----------------------------------------------------------------------------*/ 174 175 175 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data) 176 176 { … … 189 189 ddf_fun_destroy(fun); 190 190 } 191 /*----------------------------------------------------------------------------*/ 191 192 192 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 193 193 { … … 224 224 return EOK; 225 225 } 226 /*----------------------------------------------------------------------------*/ 226 227 227 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data) 228 228 { -
uspace/drv/bus/usb/usbhid/generic/hiddev.h
r5837c7a r76fbd9a 47 47 const char *HID_GENERIC_CLASS_NAME; 48 48 49 /*----------------------------------------------------------------------------*/ 49 50 50 51 51 int usb_generic_hid_init(struct usb_hid_dev *hid_dev, void **data); -
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r5837c7a r76fbd9a 73 73 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 74 74 static ddf_dev_ops_t kbdops = { .default_handler = default_connection_handler }; 75 /*----------------------------------------------------------------------------*/ 75 76 76 77 77 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; … … 88 88 static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000; 89 89 90 /*----------------------------------------------------------------------------*/ 90 91 91 /** Keyboard polling endpoint description for boot protocol class. */ 92 92 const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = { … … 103 103 104 104 static void usb_kbd_set_led(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev); 105 /*----------------------------------------------------------------------------*/ 105 106 106 static const uint8_t USB_KBD_BOOT_REPORT_DESCRIPTOR[] = { 107 107 0x05, 0x01, /* Usage Page (Generic Desktop), */ … … 138 138 0xC0 /* End Collection */ 139 139 }; 140 /*----------------------------------------------------------------------------*/ 140 141 141 typedef enum usb_kbd_flags { 142 142 USB_KBD_STATUS_UNINITIALIZED = 0, … … 144 144 USB_KBD_STATUS_TO_DESTROY = -1 145 145 } usb_kbd_flags; 146 /*----------------------------------------------------------------------------*/ 146 147 147 /* IPC method handler */ 148 /*----------------------------------------------------------------------------*/ 148 149 149 /** 150 150 * Default handler for IPC methods not handled by DDF. … … 208 208 209 209 } 210 /*----------------------------------------------------------------------------*/ 210 211 211 /* Key processing functions */ 212 /*----------------------------------------------------------------------------*/ 212 213 213 /** 214 214 * Handles turning of LED lights on and off. … … 283 283 } 284 284 } 285 /*----------------------------------------------------------------------------*/ 285 286 286 /** Send key event. 287 287 * … … 308 308 } 309 309 } 310 /*----------------------------------------------------------------------------*/ 310 311 311 static inline int usb_kbd_is_lock(unsigned int key_code) 312 312 { … … 315 315 || key_code == KC_CAPS_LOCK); 316 316 } 317 /*----------------------------------------------------------------------------*/ 317 318 318 static size_t find_in_array_int32(int32_t val, int32_t *arr, size_t arr_size) 319 319 { … … 326 326 return (size_t) -1; 327 327 } 328 /*----------------------------------------------------------------------------*/ 328 329 329 /** 330 330 * Checks if some keys were pressed or released and generates key events. … … 409 409 usb_log_debug2("Stored keys %s.\n", key_buffer); 410 410 } 411 /*----------------------------------------------------------------------------*/ 411 412 412 /* General kbd functions */ 413 /*----------------------------------------------------------------------------*/ 413 414 414 /** 415 415 * Processes data received from the device in form of report. … … 481 481 usb_kbd_check_key_changes(hid_dev, kbd_dev); 482 482 } 483 /*----------------------------------------------------------------------------*/ 483 484 484 /* HID/KBD structure manipulation */ 485 /*----------------------------------------------------------------------------*/ 485 486 486 static int usb_kbd_create_function(usb_kbd_t *kbd_dev) 487 487 { … … 537 537 return EOK; 538 538 } 539 /*----------------------------------------------------------------------------*/ 539 540 540 /* API functions */ 541 /*----------------------------------------------------------------------------*/ 541 542 542 /** 543 543 * Initialization of the USB/HID keyboard structure. … … 701 701 return EOK; 702 702 } 703 /*----------------------------------------------------------------------------*/ 703 704 704 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, void *data) 705 705 { … … 715 715 return true; 716 716 } 717 /*----------------------------------------------------------------------------*/ 717 718 718 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev) 719 719 { 720 720 return (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); 721 721 } 722 /*----------------------------------------------------------------------------*/ 722 723 723 int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev) 724 724 { 725 725 return (kbd_dev->initialized == USB_KBD_STATUS_TO_DESTROY); 726 726 } 727 /*----------------------------------------------------------------------------*/ 727 728 728 /** 729 729 * Properly destroys the USB/HID keyboard structure. … … 766 766 free(kbd_dev); 767 767 } 768 /*----------------------------------------------------------------------------*/ 768 769 769 void usb_kbd_deinit(usb_hid_dev_t *hid_dev, void *data) 770 770 { … … 779 779 } 780 780 } 781 /*----------------------------------------------------------------------------*/ 781 782 782 int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev) 783 783 { -
uspace/drv/bus/usb/usbhid/kbd/kbddev.h
r5837c7a r76fbd9a 50 50 struct usb_hid_dev; 51 51 52 /*----------------------------------------------------------------------------*/ 52 53 53 /** 54 54 * USB/HID keyboard device type. … … 113 113 } usb_kbd_t; 114 114 115 /*----------------------------------------------------------------------------*/ 115 116 116 117 117 extern const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description; … … 120 120 const char *HID_KBD_CLASS_NAME; 121 121 122 /*----------------------------------------------------------------------------*/ 122 123 123 124 124 int usb_kbd_init(struct usb_hid_dev *hid_dev, void **data); -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.c
r5837c7a r76fbd9a 105 105 } 106 106 } 107 /*----------------------------------------------------------------------------*/ 107 108 108 /** 109 109 * Main routine to be executed by a fibril for handling auto-repeat. … … 132 132 return EOK; 133 133 } 134 /*----------------------------------------------------------------------------*/ 134 135 135 /** 136 136 * Start repeating particular key. … … 149 149 fibril_mutex_unlock(&kbd->repeat_mtx); 150 150 } 151 /*----------------------------------------------------------------------------*/ 151 152 152 /** 153 153 * Stop repeating particular key. -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.h
r5837c7a r76fbd9a 42 42 struct usb_kbd_t; 43 43 44 /*----------------------------------------------------------------------------*/ 44 45 45 /** 46 46 * Structure for keeping information needed for auto-repeat of keys. … … 57 57 } usb_kbd_repeat_t; 58 58 59 /*----------------------------------------------------------------------------*/ 59 60 60 61 61 int usb_kbd_repeat_fibril(void *arg); -
uspace/drv/bus/usb/usbhid/main.c
r5837c7a r76fbd9a 113 113 return EOK; 114 114 } 115 /*----------------------------------------------------------------------------*/ 115 116 116 /** 117 117 * Callback for a device about to be removed from the driver. … … 126 126 return ENOTSUP; 127 127 } 128 /*----------------------------------------------------------------------------*/ 128 129 129 /** 130 130 * Callback for removing a device from the driver. … … 152 152 return EOK; 153 153 } 154 /*----------------------------------------------------------------------------*/ 154 155 155 /** USB generic driver callbacks */ 156 156 static const usb_driver_ops_t usb_hid_driver_ops = { … … 159 159 .device_gone = usb_hid_device_gone, 160 160 }; 161 /*----------------------------------------------------------------------------*/ 161 162 162 /** The driver itself. */ 163 163 static const usb_driver_t usb_hid_driver = { … … 166 166 .endpoints = usb_hid_endpoints 167 167 }; 168 /*----------------------------------------------------------------------------*/ 168 169 169 int main(int argc, char *argv[]) 170 170 { -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r5837c7a r76fbd9a 58 58 static ddf_dev_ops_t ops = { .default_handler = default_connection_handler }; 59 59 60 /*----------------------------------------------------------------------------*/ 60 61 61 const usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = { 62 62 .transfer_type = USB_TRANSFER_INTERRUPT, … … 74 74 static const uint8_t IDLE_RATE = 0; 75 75 76 /*----------------------------------------------------------------------------*/ 76 77 77 static const uint8_t USB_MOUSE_BOOT_REPORT_DESCRIPTOR[] = { 78 78 0x05, 0x01, // USAGE_PAGE (Generic Desktop) … … 104 104 }; 105 105 106 /*----------------------------------------------------------------------------*/ 106 107 107 108 108 /** Default handler for IPC methods not handled by DDF. … … 146 146 } 147 147 } 148 /*----------------------------------------------------------------------------*/ 148 149 149 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report, 150 150 int32_t usage) … … 245 245 return true; 246 246 } 247 /*----------------------------------------------------------------------------*/ 247 248 248 #define FUN_UNBIND_DESTROY(fun) \ 249 249 if (fun) { \ … … 256 256 } \ 257 257 } else (void)0 258 /*----------------------------------------------------------------------------*/ 258 259 259 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse) 260 260 { … … 337 337 return highest_button; 338 338 } 339 /*----------------------------------------------------------------------------*/ 339 340 340 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data) 341 341 { … … 387 387 return EOK; 388 388 } 389 /*----------------------------------------------------------------------------*/ 389 390 390 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data) 391 391 { … … 400 400 return usb_mouse_process_report(hid_dev, mouse_dev); 401 401 } 402 /*----------------------------------------------------------------------------*/ 402 403 403 void usb_mouse_deinit(usb_hid_dev_t *hid_dev, void *data) 404 404 { … … 421 421 free(mouse_dev); 422 422 } 423 /*----------------------------------------------------------------------------*/ 423 424 424 int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev) 425 425 { -
uspace/drv/bus/usb/usbhid/mouse/mousedev.h
r5837c7a r76fbd9a 42 42 struct usb_hid_dev; 43 43 44 /*----------------------------------------------------------------------------*/ 44 45 45 46 46 /** Container for USB mouse device. */ … … 57 57 } usb_mouse_t; 58 58 59 /*----------------------------------------------------------------------------*/ 59 60 60 61 61 extern const usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description; … … 64 64 const char *HID_MOUSE_CATEGORY; 65 65 66 /*----------------------------------------------------------------------------*/ 66 67 67 68 68 int usb_mouse_init(struct usb_hid_dev *hid_dev, void **data); … … 74 74 int usb_mouse_set_boot_protocol(struct usb_hid_dev *hid_dev); 75 75 76 /*----------------------------------------------------------------------------*/ 76 77 77 78 78 #endif // USB_HID_MOUSEDEV_H_ -
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
r5837c7a r76fbd9a 54 54 #define NAME "multimedia-keys" 55 55 56 /*----------------------------------------------------------------------------*/ 56 57 57 /** 58 58 * Logitech UltraX device type. … … 70 70 71 71 72 /*----------------------------------------------------------------------------*/ 72 73 73 /** 74 74 * Default handler for IPC methods not handled by DDF. … … 106 106 async_answer_0(icallid, EINVAL); 107 107 } 108 /*----------------------------------------------------------------------------*/ 108 109 109 static ddf_dev_ops_t multimedia_ops = { 110 110 .default_handler = default_connection_handler 111 111 }; 112 /*----------------------------------------------------------------------------*/ 112 113 113 /** 114 114 * Processes key events. … … 155 155 } 156 156 } 157 /*----------------------------------------------------------------------------*/ 157 158 158 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 159 159 { … … 216 216 return EOK; 217 217 } 218 /*----------------------------------------------------------------------------*/ 218 219 219 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data) 220 220 { … … 239 239 } 240 240 } 241 /*----------------------------------------------------------------------------*/ 241 242 242 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data) 243 243 { -
uspace/drv/bus/usb/usbhid/multimedia/multimedia.h
r5837c7a r76fbd9a 41 41 struct usb_hid_dev; 42 42 43 /*----------------------------------------------------------------------------*/ 43 44 44 45 45 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data); … … 49 49 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data); 50 50 51 /*----------------------------------------------------------------------------*/ 51 52 52 53 53 #endif // USB_HID_MULTIMEDIA_H_ -
uspace/drv/bus/usb/usbhid/subdrivers.h
r5837c7a r76fbd9a 40 40 #include "kbd/kbddev.h" 41 41 42 /*----------------------------------------------------------------------------*/ 42 43 43 44 44 typedef struct usb_hid_subdriver_usage { … … 47 47 } usb_hid_subdriver_usage_t; 48 48 49 /*----------------------------------------------------------------------------*/ 49 50 50 51 51 /** Structure representing the mapping between device requirements and the … … 81 81 } usb_hid_subdriver_mapping_t; 82 82 83 /*----------------------------------------------------------------------------*/ 83 84 84 85 85 extern const usb_hid_subdriver_mapping_t usb_hid_subdrivers[]; 86 86 extern const size_t USB_HID_MAX_SUBDRIVERS; 87 87 88 /*----------------------------------------------------------------------------*/ 88 89 89 90 90 #endif /* USB_HID_SUBDRIVERS_H_ */ -
uspace/drv/bus/usb/usbhid/usbhid.c
r5837c7a r76fbd9a 58 58 NULL 59 59 }; 60 /*----------------------------------------------------------------------------*/ 60 61 61 static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev) 62 62 { … … 74 74 return EOK; 75 75 } 76 /*----------------------------------------------------------------------------*/ 76 77 77 static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev) 78 78 { … … 90 90 return EOK; 91 91 } 92 /*----------------------------------------------------------------------------*/ 92 93 93 static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev) 94 94 { … … 110 110 return EOK; 111 111 } 112 /*----------------------------------------------------------------------------*/ 112 113 113 static bool usb_hid_ids_match(const usb_hid_dev_t *hid_dev, 114 114 const usb_hid_subdriver_mapping_t *mapping) … … 122 122 == mapping->product_id); 123 123 } 124 /*----------------------------------------------------------------------------*/ 124 125 125 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 126 126 const usb_hid_subdriver_mapping_t *mapping) … … 178 178 return matches; 179 179 } 180 /*----------------------------------------------------------------------------*/ 180 181 181 static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 182 182 const usb_hid_subdriver_t **subdrivers, unsigned count) … … 211 211 return EOK; 212 212 } 213 /*----------------------------------------------------------------------------*/ 213 214 214 static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev) 215 215 { … … 263 263 return usb_hid_save_subdrivers(hid_dev, subdrivers, count); 264 264 } 265 /*----------------------------------------------------------------------------*/ 265 266 266 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev) 267 267 { … … 290 290 return ENOTSUP; 291 291 } 292 /*----------------------------------------------------------------------------*/ 292 293 293 static int usb_hid_init_report(usb_hid_dev_t *hid_dev) 294 294 { … … 322 322 return EOK; 323 323 } 324 /*----------------------------------------------------------------------------*/ 324 325 325 /* 326 326 * This functions initializes required structures from the device's descriptors … … 458 458 return rc; 459 459 } 460 /*----------------------------------------------------------------------------*/ 460 461 461 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 462 462 size_t buffer_size, void *arg) … … 500 500 return cont; 501 501 } 502 /*----------------------------------------------------------------------------*/ 502 503 503 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg) 504 504 { … … 517 517 hid_dev->running = false; 518 518 } 519 /*----------------------------------------------------------------------------*/ 519 520 520 void usb_hid_new_report(usb_hid_dev_t *hid_dev) 521 521 { 522 522 ++hid_dev->report_nr; 523 523 } 524 /*----------------------------------------------------------------------------*/ 524 525 525 int usb_hid_report_number(const usb_hid_dev_t *hid_dev) 526 526 { 527 527 return hid_dev->report_nr; 528 528 } 529 /*----------------------------------------------------------------------------*/ 529 530 530 void usb_hid_deinit(usb_hid_dev_t *hid_dev) 531 531 { -
uspace/drv/bus/usb/usbhid/usbhid.h
r5837c7a r76fbd9a 95 95 }; 96 96 97 /*----------------------------------------------------------------------------*/ 97 98 98 /** 99 99 * Structure for holding general HID device data. … … 132 132 }; 133 133 134 /*----------------------------------------------------------------------------*/ 134 135 135 136 136 enum { … … 143 143 extern const usb_endpoint_description_t *usb_hid_endpoints[]; 144 144 145 /*----------------------------------------------------------------------------*/ 145 146 146 147 147 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
Note:
See TracChangeset
for help on using the changeset viewer.