Changeset 35f0899 in mainline


Ignore:
Timestamp:
2011-03-06T09:21:46Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b330cb1f
Parents:
6bb456c
Message:

Added missing class-specific requests + fixed Set_Report request.

  • Added: Get_Report, Get_Protocol, Get_Idle
  • Fixed Set_Report: value is counted in the function

Not tested yet.

Location:
uspace/drv/usbhid
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/hidreq.c

    r6bb456c r35f0899  
    6969                return sess_rc;
    7070        }
     71       
     72        uint16_t value = 0;
     73        value |= (type << 8);
    7174
    7275        usb_log_debug("Sending Set_Report request to the device.\n");
     
    7477        rc = usb_control_request_set(&hid_dev->ctrl_pipe,
    7578            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    76             USB_HIDREQ_SET_REPORT, type, hid_dev->iface, buffer, buf_size);
     79            USB_HIDREQ_SET_REPORT, value, hid_dev->iface, buffer, buf_size);
    7780
    7881        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     
    187190                return sess_rc;
    188191        }
     192       
     193        return EOK;
     194}
     195
     196/*----------------------------------------------------------------------------*/
     197
     198int usbhid_req_get_report(usbhid_dev_t *hid_dev, usb_hid_report_type_t type,
     199    uint8_t *buffer, size_t buf_size, size_t *actual_size)
     200{
     201        if (hid_dev == NULL) {
     202                usb_log_error("usbhid_req_set_report(): no HID device structure"
     203                    " given.\n");
     204                return EINVAL;
     205        }
     206       
     207        /*
     208         * No need for checking other parameters, as they are checked in
     209         * the called function (usb_control_request_set()).
     210         */
     211       
     212        int rc, sess_rc;
     213       
     214        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     215        if (sess_rc != EOK) {
     216                usb_log_warning("Failed to start a session: %s.\n",
     217                    str_error(sess_rc));
     218                return sess_rc;
     219        }
     220
     221        uint16_t value = 0;
     222        value |= (type << 8);
     223       
     224        usb_log_debug("Sending Get_Report request to the device.\n");
     225       
     226        rc = usb_control_request_get(&hid_dev->ctrl_pipe,
     227            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     228            USB_HIDREQ_GET_REPORT, value, hid_dev->iface, buffer, buf_size,
     229            actual_size);
     230
     231        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     232
     233        if (rc != EOK) {
     234                usb_log_warning("Error sending output report to the keyboard: "
     235                    "%s.\n", str_error(rc));
     236                return rc;
     237        }
     238
     239        if (sess_rc != EOK) {
     240                usb_log_warning("Error closing session: %s.\n",
     241                    str_error(sess_rc));
     242                return sess_rc;
     243        }
     244       
     245        return EOK;
     246}
     247
     248int usbhid_req_get_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t *protocol)
     249{
     250        if (hid_dev == NULL) {
     251                usb_log_error("usbhid_req_set_protocol(): no HID device "
     252                    "structure given.\n");
     253                return EINVAL;
     254        }
     255       
     256        /*
     257         * No need for checking other parameters, as they are checked in
     258         * the called function (usb_control_request_set()).
     259         */
     260       
     261        int rc, sess_rc;
     262       
     263        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     264        if (sess_rc != EOK) {
     265                usb_log_warning("Failed to start a session: %s.\n",
     266                    str_error(sess_rc));
     267                return sess_rc;
     268        }
     269
     270        usb_log_debug("Sending Get_Protocol request to the device ("
     271            "protocol: %d, iface: %d).\n", protocol, hid_dev->iface);
     272       
     273        uint8_t buffer[1];
     274        size_t actual_size = 0;
     275       
     276        rc = usb_control_request_get(&hid_dev->ctrl_pipe,
     277            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     278            USB_HIDREQ_GET_PROTOCOL, 0, hid_dev->iface, buffer, 1, &actual_size);
     279
     280        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     281
     282        if (rc != EOK) {
     283                usb_log_warning("Error sending output report to the keyboard: "
     284                    "%s.\n", str_error(rc));
     285                return rc;
     286        }
     287
     288        if (sess_rc != EOK) {
     289                usb_log_warning("Error closing session: %s.\n",
     290                    str_error(sess_rc));
     291                return sess_rc;
     292        }
     293       
     294        if (actual_size != 1) {
     295                usb_log_warning("Wrong data size: %zu, expected: 1.\n",
     296                        actual_size);
     297                return ELIMIT;
     298        }
     299       
     300        *protocol = buffer[0];
     301       
     302        return EOK;
     303}
     304
     305int usbhid_req_get_idle(usbhid_dev_t *hid_dev, uint8_t *duration)
     306{
     307        if (hid_dev == NULL) {
     308                usb_log_error("usbhid_req_set_idle(): no HID device "
     309                    "structure given.\n");
     310                return EINVAL;
     311        }
     312       
     313        /*
     314         * No need for checking other parameters, as they are checked in
     315         * the called function (usb_control_request_set()).
     316         */
     317       
     318        int rc, sess_rc;
     319       
     320        sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     321        if (sess_rc != EOK) {
     322                usb_log_warning("Failed to start a session: %s.\n",
     323                    str_error(sess_rc));
     324                return sess_rc;
     325        }
     326
     327        usb_log_debug("Sending Get_Idle request to the device ("
     328            "duration: %u, iface: %d).\n", duration, hid_dev->iface);
     329       
     330        uint16_t value = 0;
     331        uint8_t buffer[1];
     332        size_t actual_size = 0;
     333       
     334        rc = usb_control_request_get(&hid_dev->ctrl_pipe,
     335            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     336            USB_HIDREQ_GET_IDLE, value, hid_dev->iface, buffer, 1,
     337            &actual_size);
     338
     339        sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     340
     341        if (rc != EOK) {
     342                usb_log_warning("Error sending output report to the keyboard: "
     343                    "%s.\n", str_error(rc));
     344                return rc;
     345        }
     346
     347        if (sess_rc != EOK) {
     348                usb_log_warning("Error closing session: %s.\n",
     349                    str_error(sess_rc));
     350                return sess_rc;
     351        }
     352       
     353        if (actual_size != 1) {
     354                usb_log_warning("Wrong data size: %zu, expected: 1.\n",
     355                        actual_size);
     356                return ELIMIT;
     357        }
     358       
     359        *duration = buffer[0];
    189360       
    190361        return EOK;
  • uspace/drv/usbhid/hidreq.h

    r6bb456c r35f0899  
    5252int usbhid_req_set_idle(usbhid_dev_t *hid_dev, uint8_t duration);
    5353
     54int usbhid_req_get_report(usbhid_dev_t *hid_dev, usb_hid_report_type_t type,
     55    uint8_t *buffer, size_t buf_size, size_t *actual_size);
     56
     57int usbhid_req_get_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t *protocol);
     58
     59int usbhid_req_get_idle(usbhid_dev_t *hid_dev, uint8_t *duration);
     60
    5461/*----------------------------------------------------------------------------*/
    5562
  • uspace/drv/usbhid/kbddev.c

    r6bb456c r35f0899  
    181181            usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0));
    182182       
    183         uint16_t value = 0;
    184         value |= (USB_HID_REPORT_TYPE_OUTPUT << 8);
    185 
    186183        assert(kbd_dev->hid_dev != NULL);
    187184        assert(kbd_dev->hid_dev->initialized);
    188         usbhid_req_set_report(kbd_dev->hid_dev, value, buffer,
    189             BOOTP_BUFFER_OUT_SIZE);
     185        usbhid_req_set_report(kbd_dev->hid_dev, USB_HID_REPORT_TYPE_OUTPUT,
     186            buffer, BOOTP_BUFFER_OUT_SIZE);
    190187}
    191188
Note: See TracChangeset for help on using the changeset viewer.