Changes in uspace/drv/bus/usb/usbhid/multimedia/multimedia.c [ce2a1c2:5da7199] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
rce2a1c2 r5da7199 64 64 //int32_t *keys; 65 65 /** Count of stored keys (i.e. number of keys in the report). */ 66 //size_t key_count; 66 //size_t key_count; 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 … … 88 86 { 89 87 usb_log_debug(NAME " default_connection_handler()\n"); 90 88 91 89 usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data; 92 90 93 91 if (multim_dev == NULL) { 94 92 async_answer_0(icallid, EINVAL); 95 93 return; 96 94 } 97 95 98 96 async_sess_t *sess = 99 97 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); … … 139 137 assert(hid_dev != NULL); 140 138 assert(multim_dev != NULL); 141 139 142 140 kbd_event_t ev; 143 141 144 142 ev.type = type; 145 143 ev.key = key; … … 153 151 return; 154 152 } 155 153 156 154 async_exch_t *exch = async_exchange_begin(multim_dev->console_sess); 157 155 async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c); … … 161 159 /*----------------------------------------------------------------------------*/ 162 160 163 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 164 { 165 if (hid_dev == NULL || hid_dev->usb_dev == NULL) { 166 return EINVAL; /*! @todo Other return code? */ 167 } 168 169 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 170 161 static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev, 162 usb_multimedia_t *multim_dev) 163 { 171 164 /* Create the exposed function. */ 172 ddf_fun_t *fun = ddf_fun_create( 173 hid_dev->usb_dev->ddf_dev, fun_exposed,NAME);165 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 166 NAME); 174 167 if (fun == NULL) { 175 168 usb_log_error("Could not create DDF function node.\n"); 176 169 return ENOMEM; 177 170 } 178 171 179 172 fun->ops = &multimedia_ops; 180 181 usb_multimedia_t *multim_dev = 182 ddf_fun_data_alloc(fun, sizeof(usb_multimedia_t)); 183 if (multim_dev == NULL) { 184 ddf_fun_destroy(fun); 185 return ENOMEM; 186 } 187 188 multim_dev->console_sess = NULL; 189 multim_dev->fun = fun; 190 191 //todo Autorepeat? 192 173 fun->driver_data = multim_dev; // TODO: maybe change to hid_dev->data 174 193 175 int rc = ddf_fun_bind(fun); 194 176 if (rc != EOK) { 195 177 usb_log_error("Could not bind DDF function: %s.\n", 196 178 str_error(rc)); 179 // TODO: Can / should I destroy the DDF function? 197 180 ddf_fun_destroy(fun); 198 181 return rc; 199 182 } 200 183 201 184 usb_log_debug("%s function created (handle: %" PRIun ").\n", 202 185 NAME, fun->handle); 203 186 204 187 rc = ddf_fun_add_to_category(fun, "keyboard"); 205 188 if (rc != EOK) { … … 207 190 "Could not add DDF function to category 'keyboard': %s.\n", 208 191 str_error(rc)); 192 // TODO: Can / should I destroy the DDF function? 209 193 ddf_fun_destroy(fun); 210 194 return rc; 211 195 } 212 213 /* Save the KBD device structure into the HID device structure. */ 196 197 return EOK; 198 } 199 200 /*----------------------------------------------------------------------------*/ 201 202 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 203 { 204 if (hid_dev == NULL || hid_dev->usb_dev == NULL) { 205 return EINVAL; /*! @todo Other return code? */ 206 } 207 208 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 209 210 usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc( 211 sizeof(usb_multimedia_t)); 212 if (multim_dev == NULL) { 213 return ENOMEM; 214 } 215 216 multim_dev->console_sess = NULL; 217 218 /*! @todo Autorepeat */ 219 220 // save the KBD device structure into the HID device structure 214 221 *data = multim_dev; 215 222 223 usb_log_debug(NAME " HID/multimedia device structure initialized.\n"); 224 225 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 226 if (rc != EOK) 227 return rc; 228 216 229 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); 230 217 231 return EOK; 218 232 } … … 225 239 return; 226 240 } 227 241 228 242 if (data != NULL) { 229 243 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 230 244 // hangup session to the console 231 245 async_hangup(multim_dev->console_sess); 232 const int ret = ddf_fun_unbind(multim_dev->fun);233 if (ret != EOK) {234 usb_log_error("Failed to unbind multim function.\n");235 } else {236 usb_log_debug2("%s unbound.\n", multim_dev->fun->name);237 ddf_fun_destroy(multim_dev->fun);238 }239 246 } 240 247 } … … 250 257 251 258 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 252 259 253 260 usb_hid_report_path_t *path = usb_hid_report_path(); 254 261 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0); … … 257 264 258 265 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 259 &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END260 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 266 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 267 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 261 268 USB_HID_REPORT_TYPE_INPUT); 262 269 … … 276 283 key); 277 284 } 278 285 279 286 field = usb_hid_report_get_sibling( 280 &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END287 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 281 288 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 282 289 USB_HID_REPORT_TYPE_INPUT); 283 } 290 } 284 291 285 292 usb_hid_report_path_free(path); 286 293 287 294 return true; 288 295 }
Note:
See TracChangeset
for help on using the changeset viewer.