Changeset d3b6d5e in mainline
- Timestamp:
- 2011-05-12T08:33:24Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 373bc2d
- Parents:
- cecb1a97
- Location:
- uspace/drv/usbhid
- Files:
-
- 1 added
- 1 deleted
- 2 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/Makefile
rcecb1a97 rd3b6d5e 46 46 generic/hiddev.c \ 47 47 mouse/mousedev.c \ 48 lgtch-ultrax/lgtch-ultrax.c \49 lgtch-ultrax/keymap.c \48 multimedia/multimedia.c \ 49 multimedia/keymap.c \ 50 50 $(STOLEN_LAYOUT_SOURCES) 51 51 -
uspace/drv/usbhid/multimedia/keymap.h
rcecb1a97 rd3b6d5e 34 34 */ 35 35 36 #ifndef USB_HID_ LGTCH_ULTRAX_KEYMAP_H_37 #define USB_HID_ LGTCH_ULTRAX_KEYMAP_H_36 #ifndef USB_HID_MULTIMEDIA_KEYMAP_H_ 37 #define USB_HID_MULTIMEDIA_KEYMAP_H_ 38 38 39 unsigned int usb_ lgtch_map_usage(int usage);39 unsigned int usb_multimedia_map_usage(int usage); 40 40 41 #endif /* USB_HID_LGTCH_ULTRAX_KEYMAP_H_ */ 41 const char *usb_multimedia_usage_to_str(int usage); 42 43 #endif /* USB_HID_MULTIMEDIA_KEYMAP_H_ */ 42 44 43 45 /** -
uspace/drv/usbhid/multimedia/multimedia.c
rcecb1a97 rd3b6d5e 32 32 /** 33 33 * @file 34 * USB Logitech UltraX Keyboard sampledriver.35 */ 36 37 38 #include " lgtch-ultrax.h"34 * USB Keyboard multimedia keys subdriver. 35 */ 36 37 38 #include "multimedia.h" 39 39 #include "../usbhid.h" 40 40 #include "keymap.h" … … 50 50 #include <io/console.h> 51 51 52 #define NAME "lgtch-ultrax" 53 54 typedef enum usb_lgtch_flags { 55 USB_LGTCH_STATUS_UNINITIALIZED = 0, 56 USB_LGTCH_STATUS_INITIALIZED = 1, 57 USB_LGTCH_STATUS_TO_DESTROY = -1 58 } usb_lgtch_flags; 52 #define NAME "multimedia-keys" 59 53 60 54 /*----------------------------------------------------------------------------*/ … … 62 56 * Logitech UltraX device type. 63 57 */ 64 typedef struct usb_ lgtch_ultrax_t {58 typedef struct usb_multimedia_t { 65 59 /** Previously pressed keys (not translated to key codes). */ 66 60 int32_t *keys_old; … … 68 62 int32_t *keys; 69 63 /** Count of stored keys (i.e. number of keys in the report). */ 70 size_t key_count; 71 64 size_t key_count; 72 65 /** IPC phone to the console device (for sending key events). */ 73 66 int console_phone; 74 75 /** Information for auto-repeat of keys. */ 76 // usb_kbd_repeat_t repeat; 77 78 /** Mutex for accessing the information about auto-repeat. */ 79 // fibril_mutex_t *repeat_mtx; 80 81 /** State of the structure (for checking before use). 82 * 83 * 0 - not initialized 84 * 1 - initialized 85 * -1 - ready for destroying 86 */ 87 int initialized; 88 } usb_lgtch_ultrax_t; 67 } usb_multimedia_t; 89 68 90 69 … … 117 96 assert(hid_dev != NULL); 118 97 assert(hid_dev->data != NULL); 119 usb_ lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)hid_dev->data;98 usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data; 120 99 121 100 if (method == IPC_M_CONNECT_TO_ME) { 122 101 int callback = IPC_GET_ARG5(*icall); 123 102 124 if ( lgtch_dev->console_phone != -1) {103 if (multim_dev->console_phone != -1) { 125 104 async_answer_0(icallid, ELIMIT); 126 105 return; 127 106 } 128 107 129 lgtch_dev->console_phone = callback;108 multim_dev->console_phone = callback; 130 109 usb_log_debug(NAME " Saved phone to console: %d\n", callback); 131 110 async_answer_0(icallid, EOK); … … 138 117 /*----------------------------------------------------------------------------*/ 139 118 140 static ddf_dev_ops_t lgtch_ultrax_ops = {119 static ddf_dev_ops_t multimedia_ops = { 141 120 .default_handler = default_connection_handler 142 121 }; 143 144 /*----------------------------------------------------------------------------*/145 146 //static void usb_lgtch_process_keycodes(const uint8_t *key_codes, size_t count,147 // uint8_t report_id, void *arg);148 149 //static const usb_hid_report_in_callbacks_t usb_lgtch_parser_callbacks = {150 // .keyboard = usb_lgtch_process_keycodes151 //};152 153 ///*----------------------------------------------------------------------------*/154 155 //static void usb_lgtch_process_keycodes(const uint8_t *key_codes, size_t count,156 // uint8_t report_id, void *arg)157 //{158 // // TODO: checks159 160 // usb_log_debug(NAME " Got keys from parser (report id: %u): %s\n",161 // report_id, usb_debug_str_buffer(key_codes, count, 0));162 //}163 122 164 123 /*----------------------------------------------------------------------------*/ … … 180 139 * @param key Key code of the key according to HID Usage Tables. 181 140 */ 182 static void usb_ lgtch_push_ev(usb_hid_dev_t *hid_dev, int type,141 static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev, int type, 183 142 unsigned int key) 184 143 { … … 186 145 assert(hid_dev->data != NULL); 187 146 188 usb_ lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)hid_dev->data;147 usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data; 189 148 190 149 console_event_t ev; … … 193 152 ev.key = key; 194 153 ev.mods = 0; 195 196 154 ev.c = 0; 197 155 198 156 usb_log_debug2(NAME " Sending key %d to the console\n", ev.key); 199 if ( lgtch_dev->console_phone < 0) {157 if (multim_dev->console_phone < 0) { 200 158 usb_log_warning( 201 159 "Connection to console not ready, key discarded.\n"); … … 203 161 } 204 162 205 async_msg_4( lgtch_dev->console_phone, KBD_EVENT, ev.type, ev.key,163 async_msg_4(multim_dev->console_phone, KBD_EVENT, ev.type, ev.key, 206 164 ev.mods, ev.c); 207 165 } … … 209 167 /*----------------------------------------------------------------------------*/ 210 168 211 static void usb_ lgtch_free(usb_lgtch_ultrax_t **lgtch_dev)212 { 213 if ( lgtch_dev == NULL || *lgtch_dev == NULL) {169 static void usb_multimedia_free(usb_multimedia_t **multim_dev) 170 { 171 if (multim_dev == NULL || *multim_dev == NULL) { 214 172 return; 215 173 } 216 174 217 175 // hangup phone to the console 218 async_hangup((*lgtch_dev)->console_phone); 219 220 // if ((*lgtch_dev)->repeat_mtx != NULL) { 221 // /* TODO: replace by some check and wait */ 222 // assert(!fibril_mutex_is_locked((*lgtch_dev)->repeat_mtx)); 223 // free((*lgtch_dev)->repeat_mtx); 224 // } 176 async_hangup((*multim_dev)->console_phone); 225 177 226 178 // free all buffers 227 if ((* lgtch_dev)->keys != NULL) {228 free((* lgtch_dev)->keys);229 } 230 if ((* lgtch_dev)->keys_old != NULL) {231 free((* lgtch_dev)->keys_old);232 } 233 234 free(* lgtch_dev);235 * lgtch_dev = NULL;236 } 237 238 /*----------------------------------------------------------------------------*/ 239 240 static int usb_ lgtch_create_function(usb_hid_dev_t *hid_dev)179 if ((*multim_dev)->keys != NULL) { 180 free((*multim_dev)->keys); 181 } 182 if ((*multim_dev)->keys_old != NULL) { 183 free((*multim_dev)->keys_old); 184 } 185 186 free(*multim_dev); 187 *multim_dev = NULL; 188 } 189 190 /*----------------------------------------------------------------------------*/ 191 192 static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev) 241 193 { 242 194 /* Create the function exposed under /dev/devices. */ … … 252 204 * to the DDF function. 253 205 */ 254 fun->ops = & lgtch_ultrax_ops;206 fun->ops = &multimedia_ops; 255 207 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 256 208 … … 279 231 /*----------------------------------------------------------------------------*/ 280 232 281 int usb_ lgtch_init(struct usb_hid_dev *hid_dev)233 int usb_multimedia_init(struct usb_hid_dev *hid_dev) 282 234 { 283 235 if (hid_dev == NULL || hid_dev->usb_dev == NULL) { … … 285 237 } 286 238 287 usb_log_debug(NAME " Initializing HID/ lgtch_ultraxstructure...\n");288 289 usb_ lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)malloc(290 sizeof(usb_ lgtch_ultrax_t));291 if ( lgtch_dev == NULL) {239 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 240 241 usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc( 242 sizeof(usb_multimedia_t)); 243 if (multim_dev == NULL) { 292 244 return ENOMEM; 293 245 } 294 246 295 lgtch_dev->console_phone = -1;247 multim_dev->console_phone = -1; 296 248 297 249 usb_hid_report_path_t *path = usb_hid_report_path(); … … 300 252 usb_hid_report_path_set_report_id(path, 1); 301 253 302 lgtch_dev->key_count = usb_hid_report_input_length(254 multim_dev->key_count = usb_hid_report_input_length( 303 255 hid_dev->report, path, 304 256 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); … … 306 258 307 259 usb_log_debug(NAME " Size of the input report: %zu\n", 308 lgtch_dev->key_count);309 310 lgtch_dev->keys = (int32_t *)calloc(lgtch_dev->key_count,260 multim_dev->key_count); 261 262 multim_dev->keys = (int32_t *)calloc(multim_dev->key_count, 311 263 sizeof(int32_t)); 312 264 313 if ( lgtch_dev->keys == NULL) {265 if (multim_dev->keys == NULL) { 314 266 usb_log_fatal("No memory!\n"); 315 free( lgtch_dev);267 free(multim_dev); 316 268 return ENOMEM; 317 269 } 318 270 319 lgtch_dev->keys_old =320 (int32_t *)calloc( lgtch_dev->key_count, sizeof(int32_t));321 322 if ( lgtch_dev->keys_old == NULL) {271 multim_dev->keys_old = 272 (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t)); 273 274 if (multim_dev->keys_old == NULL) { 323 275 usb_log_fatal("No memory!\n"); 324 free( lgtch_dev->keys);325 free( lgtch_dev);276 free(multim_dev->keys); 277 free(multim_dev); 326 278 return ENOMEM; 327 279 } … … 330 282 331 283 // save the KBD device structure into the HID device structure 332 hid_dev->data = lgtch_dev; 333 334 lgtch_dev->initialized = USB_LGTCH_STATUS_INITIALIZED; 335 usb_log_debug(NAME " HID/lgtch_ultrax device structure initialized.\n"); 336 337 int rc = usb_lgtch_create_function(hid_dev); 284 hid_dev->data = multim_dev; 285 286 usb_log_debug(NAME " HID/multimedia device structure initialized.\n"); 287 288 int rc = usb_multimedia_create_function(hid_dev); 338 289 if (rc != EOK) { 339 usb_ lgtch_free(&lgtch_dev);290 usb_multimedia_free(&multim_dev); 340 291 return rc; 341 292 } 342 293 343 usb_log_debug(NAME " HID/ lgtch_ultraxstructure initialized.\n");294 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); 344 295 345 296 return EOK; … … 348 299 /*----------------------------------------------------------------------------*/ 349 300 350 void usb_ lgtch_deinit(struct usb_hid_dev *hid_dev)301 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev) 351 302 { 352 303 if (hid_dev == NULL) { … … 355 306 356 307 if (hid_dev->data != NULL) { 357 usb_lgtch_ultrax_t *lgtch_dev = 358 (usb_lgtch_ultrax_t *)hid_dev->data; 359 // if (usb_kbd_is_initialized(kbd_dev)) { 360 // usb_kbd_mark_unusable(kbd_dev); 361 // } else { 362 usb_lgtch_free(&lgtch_dev); 363 hid_dev->data = NULL; 364 // } 365 } 366 } 367 368 /*----------------------------------------------------------------------------*/ 369 370 bool usb_lgtch_polling_callback(struct usb_hid_dev *hid_dev, 308 usb_multimedia_t *multim_dev = 309 (usb_multimedia_t *)hid_dev->data; 310 usb_multimedia_free(&multim_dev); 311 hid_dev->data = NULL; 312 } 313 } 314 315 /*----------------------------------------------------------------------------*/ 316 317 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, 371 318 uint8_t *buffer, size_t buffer_size) 372 319 { … … 380 327 381 328 usb_hid_report_path_t *path = usb_hid_report_path(); 382 usb_hid_report_path_append_item(path, 0xc, 0);329 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); 383 330 384 331 uint8_t report_id; … … 409 356 field->usage); 410 357 411 key = usb_lgtch_map_usage(field->usage); 412 usb_lgtch_push_ev(hid_dev, KEY_PRESS, key); 358 key = usb_multimedia_map_usage(field->usage); 359 const char *key_str = usb_multimedia_usage_to_str(field->usage); 360 usb_log_info("Pressed key: %s\n", key_str); 361 usb_multimedia_push_ev(hid_dev, KEY_PRESS, key); 413 362 414 363 field = usb_hid_report_get_sibling( -
uspace/drv/usbhid/multimedia/multimedia.h
rcecb1a97 rd3b6d5e 31 31 */ 32 32 /** @file 33 * USB Logitech UltraX Keyboard sampledriver.33 * USB Keyboard multimedia keys subdriver. 34 34 */ 35 35 36 #ifndef USB_HID_ LGTCH_ULTRAX_H_37 #define USB_HID_ LGTCH_ULTRAX_H_36 #ifndef USB_HID_MULTIMEDIA_H_ 37 #define USB_HID_MULTIMEDIA_H_ 38 38 39 39 #include <usb/devdrv.h> … … 43 43 /*----------------------------------------------------------------------------*/ 44 44 45 int usb_ lgtch_init(struct usb_hid_dev *hid_dev);45 int usb_multimedia_init(struct usb_hid_dev *hid_dev); 46 46 47 void usb_ lgtch_deinit(struct usb_hid_dev *hid_dev);47 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev); 48 48 49 bool usb_ lgtch_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer,50 size_t buffer_size);49 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, 50 uint8_t *buffer, size_t buffer_size); 51 51 52 52 /*----------------------------------------------------------------------------*/ 53 53 54 #endif // USB_HID_ LGTCH_ULTRAX_H_54 #endif // USB_HID_MULTIMEDIA_H_ 55 55 56 56 /** -
uspace/drv/usbhid/subdrivers.c
rcecb1a97 rd3b6d5e 38 38 #include "usb/classes/hidpath.h" 39 39 40 #include "lgtch-ultrax/lgtch-ultrax.h" 40 //#include "lgtch-ultrax/lgtch-ultrax.h" 41 #include "multimedia/multimedia.h" 41 42 #include "mouse/mousedev.h" 42 43 … … 79 80 -1, 80 81 { 81 .init = usb_ lgtch_init,82 .deinit = usb_ lgtch_deinit,83 .poll = usb_ lgtch_polling_callback,82 .init = usb_multimedia_init, 83 .deinit = usb_multimedia_deinit, 84 .poll = usb_multimedia_polling_callback, 84 85 .poll_end = NULL 85 86 }
Note:
See TracChangeset
for help on using the changeset viewer.