Changeset 293de44 in mainline for uspace/drv/usbhid/multimedia/multimedia.c
- Timestamp:
- 2011-05-20T11:18:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c7c2443
- Parents:
- 160b75e (diff), 7941bd6 (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/usbhid/multimedia/multimedia.c
r160b75e r293de44 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 … … 108 87 sysarg_t method = IPC_GET_IMETHOD(*icall); 109 88 110 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 111 112 if (hid_dev == NULL || hid_dev->data == NULL) { 89 usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data; 90 //usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 91 92 if (multim_dev == NULL) { 113 93 async_answer_0(icallid, EINVAL); 114 94 return; 115 95 } 116 117 assert(hid_dev != NULL);118 assert(hid_dev->data != NULL);119 usb_lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)hid_dev->data;120 96 121 97 if (method == IPC_M_CONNECT_TO_ME) { 122 98 int callback = IPC_GET_ARG5(*icall); 123 99 124 if ( lgtch_dev->console_phone != -1) {100 if (multim_dev->console_phone != -1) { 125 101 async_answer_0(icallid, ELIMIT); 126 102 return; 127 103 } 128 104 129 lgtch_dev->console_phone = callback;105 multim_dev->console_phone = callback; 130 106 usb_log_debug(NAME " Saved phone to console: %d\n", callback); 131 107 async_answer_0(icallid, EOK); … … 138 114 /*----------------------------------------------------------------------------*/ 139 115 140 static ddf_dev_ops_t lgtch_ultrax_ops = {116 static ddf_dev_ops_t multimedia_ops = { 141 117 .default_handler = default_connection_handler 142 118 }; 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 119 164 120 /*----------------------------------------------------------------------------*/ … … 180 136 * @param key Key code of the key according to HID Usage Tables. 181 137 */ 182 static void usb_ lgtch_push_ev(usb_hid_dev_t *hid_dev, int type,183 u nsigned int key)138 static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev, 139 usb_multimedia_t *multim_dev, int type, unsigned int key) 184 140 { 185 141 assert(hid_dev != NULL); 186 assert( hid_dev->data!= NULL);187 188 usb_lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)hid_dev->data;142 assert(multim_dev != NULL); 143 144 // usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data; 189 145 190 146 console_event_t ev; … … 193 149 ev.key = key; 194 150 ev.mods = 0; 195 196 151 ev.c = 0; 197 152 198 153 usb_log_debug2(NAME " Sending key %d to the console\n", ev.key); 199 if ( lgtch_dev->console_phone < 0) {154 if (multim_dev->console_phone < 0) { 200 155 usb_log_warning( 201 156 "Connection to console not ready, key discarded.\n"); … … 203 158 } 204 159 205 async_msg_4( lgtch_dev->console_phone, KBD_EVENT, ev.type, ev.key,160 async_msg_4(multim_dev->console_phone, KBD_EVENT, ev.type, ev.key, 206 161 ev.mods, ev.c); 207 162 } … … 209 164 /*----------------------------------------------------------------------------*/ 210 165 211 static void usb_ lgtch_free(usb_lgtch_ultrax_t **lgtch_dev)212 { 213 if ( lgtch_dev == NULL || *lgtch_dev == NULL) {166 static void usb_multimedia_free(usb_multimedia_t **multim_dev) 167 { 168 if (multim_dev == NULL || *multim_dev == NULL) { 214 169 return; 215 170 } 216 171 217 172 // 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 // } 173 async_hangup((*multim_dev)->console_phone); 225 174 226 175 // 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) 176 if ((*multim_dev)->keys != NULL) { 177 free((*multim_dev)->keys); 178 } 179 if ((*multim_dev)->keys_old != NULL) { 180 free((*multim_dev)->keys_old); 181 } 182 183 free(*multim_dev); 184 *multim_dev = NULL; 185 } 186 187 /*----------------------------------------------------------------------------*/ 188 189 static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev, 190 usb_multimedia_t *multim_dev) 241 191 { 242 192 /* Create the function exposed under /dev/devices. */ … … 248 198 } 249 199 250 /* 251 * Store the initialized HID device and HID ops 252 * to the DDF function. 253 */ 254 fun->ops = &lgtch_ultrax_ops; 255 fun->driver_data = hid_dev; // TODO: maybe change to hid_dev->data 200 fun->ops = &multimedia_ops; 201 fun->driver_data = multim_dev; // TODO: maybe change to hid_dev->data 256 202 257 203 int rc = ddf_fun_bind(fun); … … 279 225 /*----------------------------------------------------------------------------*/ 280 226 281 int usb_ lgtch_init(struct usb_hid_dev *hid_dev)227 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 282 228 { 283 229 if (hid_dev == NULL || hid_dev->usb_dev == NULL) { … … 285 231 } 286 232 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) {233 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 234 235 usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc( 236 sizeof(usb_multimedia_t)); 237 if (multim_dev == NULL) { 292 238 return ENOMEM; 293 239 } 294 240 295 lgtch_dev->console_phone = -1;241 multim_dev->console_phone = -1; 296 242 297 243 usb_hid_report_path_t *path = usb_hid_report_path(); … … 300 246 usb_hid_report_path_set_report_id(path, 1); 301 247 302 lgtch_dev->key_count = usb_hid_report_input_length(303 hid_dev->report, path,304 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY); 248 multim_dev->key_count = usb_hid_report_size( 249 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 250 305 251 usb_hid_report_path_free(path); 306 252 307 253 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,254 multim_dev->key_count); 255 256 multim_dev->keys = (int32_t *)calloc(multim_dev->key_count, 311 257 sizeof(int32_t)); 312 258 313 if ( lgtch_dev->keys == NULL) {259 if (multim_dev->keys == NULL) { 314 260 usb_log_fatal("No memory!\n"); 315 free( lgtch_dev);261 free(multim_dev); 316 262 return ENOMEM; 317 263 } 318 264 319 lgtch_dev->keys_old =320 (int32_t *)calloc( lgtch_dev->key_count, sizeof(int32_t));321 322 if ( lgtch_dev->keys_old == NULL) {265 multim_dev->keys_old = 266 (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t)); 267 268 if (multim_dev->keys_old == NULL) { 323 269 usb_log_fatal("No memory!\n"); 324 free( lgtch_dev->keys);325 free( lgtch_dev);270 free(multim_dev->keys); 271 free(multim_dev); 326 272 return ENOMEM; 327 273 } … … 330 276 331 277 // 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); 278 *data = multim_dev; 279 280 usb_log_debug(NAME " HID/multimedia device structure initialized.\n"); 281 282 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 338 283 if (rc != EOK) { 339 usb_ lgtch_free(&lgtch_dev);284 usb_multimedia_free(&multim_dev); 340 285 return rc; 341 286 } 342 287 343 usb_log_debug(NAME " HID/ lgtch_ultraxstructure initialized.\n");288 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); 344 289 345 290 return EOK; … … 348 293 /*----------------------------------------------------------------------------*/ 349 294 350 void usb_ lgtch_deinit(struct usb_hid_dev *hid_dev)295 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data) 351 296 { 352 297 if (hid_dev == NULL) { … … 354 299 } 355 300 356 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, 301 if (data != NULL) { 302 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 303 usb_multimedia_free(&multim_dev); 304 } 305 } 306 307 /*----------------------------------------------------------------------------*/ 308 309 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data, 371 310 uint8_t *buffer, size_t buffer_size) 372 311 { … … 375 314 usb_log_debug(NAME " usb_lgtch_polling_callback(%p, %p, %zu)\n", 376 315 hid_dev, buffer, buffer_size); 316 317 if (data == NULL) { 318 return EINVAL; // TODO: other error code? 319 } 320 321 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 377 322 378 323 usb_log_debug(NAME " Calling usb_hid_parse_report() with " … … 380 325 381 326 usb_hid_report_path_t *path = usb_hid_report_path(); 382 usb_hid_report_path_append_item(path, 0xc, 0);327 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); 383 328 384 329 uint8_t report_id; … … 400 345 USB_HID_REPORT_TYPE_INPUT); 401 346 402 unsigned int key;347 // unsigned int key; 403 348 404 349 /*! @todo Is this iterating OK if done multiple times? … … 406 351 */ 407 352 while (field != NULL) { 408 usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n", field->value, 409 field->usage); 410 411 key = usb_lgtch_map_usage(field->usage); 412 usb_lgtch_push_ev(hid_dev, KEY_PRESS, key); 353 if(field->value != 0) { 354 usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n", 355 field->value, field->usage); 356 unsigned int key = 357 usb_multimedia_map_usage(field->usage); 358 const char *key_str = 359 usb_multimedia_usage_to_str(field->usage); 360 usb_log_info("Pressed key: %s\n", key_str); 361 usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS, 362 key); 363 } 413 364 414 365 field = usb_hid_report_get_sibling(
Note:
See TracChangeset
for help on using the changeset viewer.