Changes in uspace/drv/usbhid/hidreq.c [2391aaf:2b12f06] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/hidreq.c
r2391aaf r2b12f06 46 46 47 47 /*----------------------------------------------------------------------------*/ 48 48 /** 49 * Send Set Report request to the HID device. 50 * 51 * @param hid_dev HID device to send the request to. 52 * @param type Type of the report. 53 * @param buffer Report data. 54 * @param buf_size Report data size (in bytes). 55 * 56 * @retval EOK if successful. 57 * @retval EINVAL if no HID device is given. 58 * @return Other value inherited from one of functions 59 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 60 * usb_control_request_set(). 61 */ 49 62 int usbhid_req_set_report(usbhid_dev_t *hid_dev, 50 63 usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size) … … 69 82 return sess_rc; 70 83 } 84 85 uint16_t value = 0; 86 value |= (type << 8); 71 87 72 88 usb_log_debug("Sending Set_Report request to the device.\n"); … … 74 90 rc = usb_control_request_set(&hid_dev->ctrl_pipe, 75 91 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 76 USB_HIDREQ_SET_REPORT, type, hid_dev->iface, buffer, buf_size); 77 78 sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 79 80 if (rc != EOK) { 81 usb_log_warning("Error sending output report to the keyboard: " 82 "%s.\n", str_error(rc)); 83 return rc; 84 } 85 86 if (sess_rc != EOK) { 87 usb_log_warning("Error closing session: %s.\n", 88 str_error(sess_rc)); 89 return sess_rc; 90 } 91 92 return EOK; 93 } 94 95 /*----------------------------------------------------------------------------*/ 96 92 USB_HIDREQ_SET_REPORT, value, hid_dev->iface, buffer, buf_size); 93 94 sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 95 96 if (rc != EOK) { 97 usb_log_warning("Error sending output report to the keyboard: " 98 "%s.\n", str_error(rc)); 99 return rc; 100 } 101 102 if (sess_rc != EOK) { 103 usb_log_warning("Error closing session: %s.\n", 104 str_error(sess_rc)); 105 return sess_rc; 106 } 107 108 return EOK; 109 } 110 111 /*----------------------------------------------------------------------------*/ 112 /** 113 * Send Set Protocol request to the HID device. 114 * 115 * @param hid_dev HID device to send the request to. 116 * @param protocol Protocol to set. 117 * 118 * @retval EOK if successful. 119 * @retval EINVAL if no HID device is given. 120 * @return Other value inherited from one of functions 121 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 122 * usb_control_request_set(). 123 */ 97 124 int usbhid_req_set_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t protocol) 98 125 { … … 142 169 143 170 /*----------------------------------------------------------------------------*/ 171 /** 172 * Send Set Idle request to the HID device. 173 * 174 * @param hid_dev HID device to send the request to. 175 * @param duration Duration value (is multiplicated by 4 by the device to 176 * get real duration in miliseconds). 177 * 178 * @retval EOK if successful. 179 * @retval EINVAL if no HID device is given. 180 * @return Other value inherited from one of functions 181 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 182 * usb_control_request_set(). 183 */ 184 int usbhid_req_set_idle(usbhid_dev_t *hid_dev, uint8_t duration) 185 { 186 if (hid_dev == NULL) { 187 usb_log_error("usbhid_req_set_idle(): no HID device " 188 "structure given.\n"); 189 return EINVAL; 190 } 191 192 /* 193 * No need for checking other parameters, as they are checked in 194 * the called function (usb_control_request_set()). 195 */ 196 197 int rc, sess_rc; 198 199 sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 200 if (sess_rc != EOK) { 201 usb_log_warning("Failed to start a session: %s.\n", 202 str_error(sess_rc)); 203 return sess_rc; 204 } 205 206 usb_log_debug("Sending Set_Idle request to the device (" 207 "duration: %u, iface: %d).\n", duration, hid_dev->iface); 208 209 uint16_t value = duration << 8; 210 211 rc = usb_control_request_set(&hid_dev->ctrl_pipe, 212 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 213 USB_HIDREQ_SET_IDLE, value, hid_dev->iface, NULL, 0); 214 215 sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 216 217 if (rc != EOK) { 218 usb_log_warning("Error sending output report to the keyboard: " 219 "%s.\n", str_error(rc)); 220 return rc; 221 } 222 223 if (sess_rc != EOK) { 224 usb_log_warning("Error closing session: %s.\n", 225 str_error(sess_rc)); 226 return sess_rc; 227 } 228 229 return EOK; 230 } 231 232 /*----------------------------------------------------------------------------*/ 233 /** 234 * Send Get Report request to the HID device. 235 * 236 * @param[in] hid_dev HID device to send the request to. 237 * @param[in] type Type of the report. 238 * @param[in][out] buffer Buffer for the report data. 239 * @param[in] buf_size Size of the buffer (in bytes). 240 * @param[out] actual_size Actual size of report received from the device 241 * (in bytes). 242 * 243 * @retval EOK if successful. 244 * @retval EINVAL if no HID device is given. 245 * @return Other value inherited from one of functions 246 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 247 * usb_control_request_set(). 248 */ 249 int usbhid_req_get_report(usbhid_dev_t *hid_dev, usb_hid_report_type_t type, 250 uint8_t *buffer, size_t buf_size, size_t *actual_size) 251 { 252 if (hid_dev == NULL) { 253 usb_log_error("usbhid_req_set_report(): no HID device structure" 254 " given.\n"); 255 return EINVAL; 256 } 257 258 /* 259 * No need for checking other parameters, as they are checked in 260 * the called function (usb_control_request_set()). 261 */ 262 263 int rc, sess_rc; 264 265 sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 266 if (sess_rc != EOK) { 267 usb_log_warning("Failed to start a session: %s.\n", 268 str_error(sess_rc)); 269 return sess_rc; 270 } 271 272 uint16_t value = 0; 273 value |= (type << 8); 274 275 usb_log_debug("Sending Get_Report request to the device.\n"); 276 277 rc = usb_control_request_get(&hid_dev->ctrl_pipe, 278 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 279 USB_HIDREQ_GET_REPORT, value, hid_dev->iface, buffer, buf_size, 280 actual_size); 281 282 sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 283 284 if (rc != EOK) { 285 usb_log_warning("Error sending output report to the keyboard: " 286 "%s.\n", str_error(rc)); 287 return rc; 288 } 289 290 if (sess_rc != EOK) { 291 usb_log_warning("Error closing session: %s.\n", 292 str_error(sess_rc)); 293 return sess_rc; 294 } 295 296 return EOK; 297 } 298 299 /*----------------------------------------------------------------------------*/ 300 /** 301 * Send Get Protocol request to the HID device. 302 * 303 * @param[in] hid_dev HID device to send the request to. 304 * @param[out] protocol Current protocol of the device. 305 * 306 * @retval EOK if successful. 307 * @retval EINVAL if no HID device is given. 308 * @return Other value inherited from one of functions 309 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 310 * usb_control_request_set(). 311 */ 312 int usbhid_req_get_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t *protocol) 313 { 314 if (hid_dev == NULL) { 315 usb_log_error("usbhid_req_set_protocol(): no HID device " 316 "structure given.\n"); 317 return EINVAL; 318 } 319 320 /* 321 * No need for checking other parameters, as they are checked in 322 * the called function (usb_control_request_set()). 323 */ 324 325 int rc, sess_rc; 326 327 sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 328 if (sess_rc != EOK) { 329 usb_log_warning("Failed to start a session: %s.\n", 330 str_error(sess_rc)); 331 return sess_rc; 332 } 333 334 usb_log_debug("Sending Get_Protocol request to the device (" 335 "iface: %d).\n", hid_dev->iface); 336 337 uint8_t buffer[1]; 338 size_t actual_size = 0; 339 340 rc = usb_control_request_get(&hid_dev->ctrl_pipe, 341 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 342 USB_HIDREQ_GET_PROTOCOL, 0, hid_dev->iface, buffer, 1, &actual_size); 343 344 sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 345 346 if (rc != EOK) { 347 usb_log_warning("Error sending output report to the keyboard: " 348 "%s.\n", str_error(rc)); 349 return rc; 350 } 351 352 if (sess_rc != EOK) { 353 usb_log_warning("Error closing session: %s.\n", 354 str_error(sess_rc)); 355 return sess_rc; 356 } 357 358 if (actual_size != 1) { 359 usb_log_warning("Wrong data size: %zu, expected: 1.\n", 360 actual_size); 361 return ELIMIT; 362 } 363 364 *protocol = buffer[0]; 365 366 return EOK; 367 } 368 369 /*----------------------------------------------------------------------------*/ 370 /** 371 * Send Get Idle request to the HID device. 372 * 373 * @param[in] hid_dev HID device to send the request to. 374 * @param[out] duration Duration value (multiplicate by 4 to get real duration 375 * in miliseconds). 376 * 377 * @retval EOK if successful. 378 * @retval EINVAL if no HID device is given. 379 * @return Other value inherited from one of functions 380 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 381 * usb_control_request_set(). 382 */ 383 int usbhid_req_get_idle(usbhid_dev_t *hid_dev, uint8_t *duration) 384 { 385 if (hid_dev == NULL) { 386 usb_log_error("usbhid_req_set_idle(): no HID device " 387 "structure given.\n"); 388 return EINVAL; 389 } 390 391 /* 392 * No need for checking other parameters, as they are checked in 393 * the called function (usb_control_request_set()). 394 */ 395 396 int rc, sess_rc; 397 398 sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 399 if (sess_rc != EOK) { 400 usb_log_warning("Failed to start a session: %s.\n", 401 str_error(sess_rc)); 402 return sess_rc; 403 } 404 405 usb_log_debug("Sending Get_Idle request to the device (" 406 "iface: %d).\n", hid_dev->iface); 407 408 uint16_t value = 0; 409 uint8_t buffer[1]; 410 size_t actual_size = 0; 411 412 rc = usb_control_request_get(&hid_dev->ctrl_pipe, 413 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 414 USB_HIDREQ_GET_IDLE, value, hid_dev->iface, buffer, 1, 415 &actual_size); 416 417 sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 418 419 if (rc != EOK) { 420 usb_log_warning("Error sending output report to the keyboard: " 421 "%s.\n", str_error(rc)); 422 return rc; 423 } 424 425 if (sess_rc != EOK) { 426 usb_log_warning("Error closing session: %s.\n", 427 str_error(sess_rc)); 428 return sess_rc; 429 } 430 431 if (actual_size != 1) { 432 usb_log_warning("Wrong data size: %zu, expected: 1.\n", 433 actual_size); 434 return ELIMIT; 435 } 436 437 *duration = buffer[0]; 438 439 return EOK; 440 } 441 442 /*----------------------------------------------------------------------------*/ 144 443 145 444 /**
Note:
See TracChangeset
for help on using the changeset viewer.