Changeset 05920d23 in mainline for uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
- Timestamp:
- 2011-11-07T08:56:22Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5f047d0
- Parents:
- 07498c1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
r07498c1 r05920d23 67 67 /** IPC session to the console device (for sending key events). */ 68 68 async_sess_t *console_sess; 69 /** DDF function */70 ddf_fun_t *fun;71 69 } usb_multimedia_t; 72 70 73 71 74 72 /*----------------------------------------------------------------------------*/ 75 /** 73 /** 76 74 * Default handler for IPC methods not handled by DDF. 77 75 * … … 88 86 { 89 87 usb_log_debug(NAME " default_connection_handler()\n"); 90 91 usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data; 92 93 if (multim_dev == NULL) { 88 if (fun == NULL || fun->driver_data == NULL) { 94 89 async_answer_0(icallid, EINVAL); 95 90 return; 96 91 } 92 93 usb_multimedia_t *multim_dev = fun->driver_data; 97 94 98 95 async_sess_t *sess = … … 109 106 async_answer_0(icallid, EINVAL); 110 107 } 111 112 /*----------------------------------------------------------------------------*/ 113 108 /*----------------------------------------------------------------------------*/ 114 109 static ddf_dev_ops_t multimedia_ops = { 115 110 .default_handler = default_connection_handler 116 111 }; 117 118 112 /*----------------------------------------------------------------------------*/ 119 113 /** … … 134 128 * @param key Key code of the key according to HID Usage Tables. 135 129 */ 136 static void usb_multimedia_push_ev( usb_hid_dev_t *hid_dev,130 static void usb_multimedia_push_ev( 137 131 usb_multimedia_t *multim_dev, int type, unsigned int key) 138 132 { … … 154 148 155 149 async_exch_t *exch = async_exchange_begin(multim_dev->console_sess); 156 async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c); 157 async_exchange_end(exch); 158 } 159 160 /*----------------------------------------------------------------------------*/ 161 150 if (exch != NULL) { 151 async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c); 152 async_exchange_end(exch); 153 } else { 154 usb_log_warning("Failed to send multimedia key.\n"); 155 } 156 } 157 /*----------------------------------------------------------------------------*/ 162 158 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 163 159 { … … 186 182 187 183 multim_dev->console_sess = NULL; 188 multim_dev->fun = fun;189 184 190 185 //todo Autorepeat? … … 211 206 212 207 /* Save the KBD device structure into the HID device structure. */ 213 *data = multim_dev;208 *data = fun; 214 209 215 210 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); 216 211 return EOK; 217 212 } 218 219 /*----------------------------------------------------------------------------*/ 220 213 /*----------------------------------------------------------------------------*/ 221 214 void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data) 222 215 { 223 if (data != NULL) { 224 usb_multimedia_t *multim_dev = data; 216 ddf_fun_t *fun = data; 217 if (fun != NULL && fun->driver_data != NULL) { 218 usb_multimedia_t *multim_dev = fun->driver_data; 225 219 /* Hangup session to the console */ 226 220 if (multim_dev->console_sess) 227 221 async_hangup(multim_dev->console_sess); 228 const int ret = ddf_fun_unbind( multim_dev->fun);222 const int ret = ddf_fun_unbind(fun); 229 223 if (ret != EOK) { 230 224 usb_log_error("Failed to unbind %s function.\n", 231 multim_dev->fun->name);225 fun->name); 232 226 } else { 233 usb_log_debug2("%s unbound.\n", multim_dev->fun->name);227 usb_log_debug2("%s unbound.\n", fun->name); 234 228 /* This frees multim_dev too as it was stored in 235 229 * fun->data */ 236 ddf_fun_destroy( multim_dev->fun);230 ddf_fun_destroy(fun); 237 231 } 238 } 239 } 240 241 /*----------------------------------------------------------------------------*/ 242 232 } else { 233 usb_log_error( 234 "Failed to deinit multimedia subdriver, data missing.\n"); 235 } 236 } 237 /*----------------------------------------------------------------------------*/ 243 238 bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data) 244 239 { 245 240 // TODO: checks 246 if (hid_dev == NULL || data == NULL) { 241 ddf_fun_t *fun = data; 242 if (hid_dev == NULL || fun == NULL || fun->driver_data == NULL) { 247 243 return false; 248 244 } 249 245 250 usb_multimedia_t *multim_dev = data;246 usb_multimedia_t *multim_dev = fun->driver_data; 251 247 252 248 usb_hid_report_path_t *path = usb_hid_report_path(); 249 if (path == NULL) 250 return true; /* This might be a temporary failure. */ 251 253 252 int ret = 254 253 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); 255 if (ret != EOK) 254 if (ret != EOK) { 255 usb_hid_report_path_free(path); 256 256 return true; /* This might be a temporary failure. */ 257 } 257 258 258 259 usb_hid_report_path_set_report_id(path, hid_dev->report_id); … … 263 264 USB_HID_REPORT_TYPE_INPUT); 264 265 265 /*! @todo Is this iterating OK if done multiple times? 266 * @todo The parsing is not OK 267 */ 266 //FIXME Is this iterating OK if done multiple times? 267 //FIXME The parsing is not OK. (what's wrong?) 268 268 while (field != NULL) { 269 if (field->value != 0) {270 usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n", 269 if (field->value != 0) { 270 usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n", 271 271 field->value, field->usage); 272 272 const unsigned key = … … 275 275 usbhid_multimedia_usage_to_str(field->usage); 276 276 usb_log_info("Pressed key: %s\n", key_str); 277 usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS, 278 key); 277 usb_multimedia_push_ev(multim_dev, KEY_PRESS, key); 279 278 } 280 279 … … 289 288 return true; 290 289 } 291 292 290 /** 293 291 * @}
Note:
See TracChangeset
for help on using the changeset viewer.