Changeset df6ded8 in mainline for uspace/lib/usbhid/src/hidreq.c


Ignore:
Timestamp:
2018-02-28T16:37:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b20da0
Parents:
f5e5f73 (diff), b2dca8de (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.
git-author:
Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
git-committer:
Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
Message:

Merge github.com:helenos-xhci-team/helenos

This commit merges support for USB 3 and generally refactors, fixes,
extends and cleans up the existing USB framework.

Notable additions and features:

  • new host controller driver has been implemented to control various xHC models (among others, NEC Renesas uPD720200)
  • isochronous data transfer mode
  • support for explicit USB device removal
  • USB tablet driver
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhid/src/hidreq.c

    rf5e5f73 rdf6ded8  
    6262{
    6363        if (ctrl_pipe == NULL) {
    64                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    65                 return EINVAL;
    66         }
    67        
    68         if (iface_no < 0) {
    69                 usb_log_warning("usbhid_req_set_report(): no interface given."
    70                     "\n");
    71                 return EINVAL;
    72         }
    73        
    74         /*
    75          * No need for checking other parameters, as they are checked in
    76          * the called function (usb_control_request_set()).
    77          */
    78        
    79         errno_t rc;
    80        
     64                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     65                return EINVAL;
     66        }
     67
     68        if (iface_no < 0) {
     69                usb_log_warning("usbhid_req_set_report(): no interface given."
     70                    "\n");
     71                return EINVAL;
     72        }
     73
     74        /*
     75         * No need for checking other parameters, as they are checked in
     76         * the called function (usb_control_request_set()).
     77         */
     78
     79        errno_t rc;
     80
    8181        uint16_t value = 0;
    8282        value |= (type << 8);
    8383
    84         usb_log_debug("Sending Set Report request to the device.\n");
    85        
     84        usb_log_debug("Sending Set Report request to the device.");
     85
    8686        rc = usb_control_request_set(ctrl_pipe,
    8787            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     
    9393                return rc;
    9494        }
    95        
     95
    9696        return EOK;
    9797}
     
    112112{
    113113        if (ctrl_pipe == NULL) {
    114                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    115                 return EINVAL;
    116         }
    117        
    118         if (iface_no < 0) {
    119                 usb_log_warning("usbhid_req_set_report(): no interface given."
    120                     "\n");
    121                 return EINVAL;
    122         }
    123        
    124         /*
    125          * No need for checking other parameters, as they are checked in
    126          * the called function (usb_control_request_set()).
    127          */
    128        
     114                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     115                return EINVAL;
     116        }
     117
     118        if (iface_no < 0) {
     119                usb_log_warning("usbhid_req_set_report(): no interface given."
     120                    "\n");
     121                return EINVAL;
     122        }
     123
     124        /*
     125         * No need for checking other parameters, as they are checked in
     126         * the called function (usb_control_request_set()).
     127         */
     128
    129129        errno_t rc;
    130130
    131131        usb_log_debug("Sending Set Protocol request to the device ("
    132132            "protocol: %d, iface: %d).\n", protocol, iface_no);
    133        
    134         rc = usb_control_request_set(ctrl_pipe, 
    135             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
     133
     134        rc = usb_control_request_set(ctrl_pipe,
     135            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    136136            USB_HIDREQ_SET_PROTOCOL, protocol, iface_no, NULL, 0);
    137137
     
    141141                return rc;
    142142        }
    143        
     143
    144144        return EOK;
    145145}
     
    160160{
    161161        if (ctrl_pipe == NULL) {
    162                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    163                 return EINVAL;
    164         }
    165        
    166         if (iface_no < 0) {
    167                 usb_log_warning("usbhid_req_set_report(): no interface given."
    168                     "\n");
    169                 return EINVAL;
    170         }
    171        
    172         /*
    173          * No need for checking other parameters, as they are checked in
    174          * the called function (usb_control_request_set()).
    175          */
    176        
     162                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     163                return EINVAL;
     164        }
     165
     166        if (iface_no < 0) {
     167                usb_log_warning("usbhid_req_set_report(): no interface given."
     168                    "\n");
     169                return EINVAL;
     170        }
     171
     172        /*
     173         * No need for checking other parameters, as they are checked in
     174         * the called function (usb_control_request_set()).
     175         */
     176
    177177        errno_t rc;
    178178
    179179        usb_log_debug("Sending Set Idle request to the device ("
    180180            "duration: %u, iface: %d).\n", duration, iface_no);
    181        
     181
    182182        uint16_t value = duration << 8;
    183        
     183
    184184        rc = usb_control_request_set(ctrl_pipe,
    185185            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     
    191191                return rc;
    192192        }
    193        
     193
    194194        return EOK;
    195195}
     
    203203 * @param[in][out] buffer Buffer for the report data.
    204204 * @param[in] buf_size Size of the buffer (in bytes).
    205  * @param[out] actual_size Actual size of report received from the device 
     205 * @param[out] actual_size Actual size of report received from the device
    206206 *                         (in bytes).
    207207 *
     
    210210 * @return Other value inherited from function usb_control_request_set().
    211211 */
    212 errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no, 
    213     usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size, 
     212errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no,
     213    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size,
    214214    size_t *actual_size)
    215215{
    216216        if (ctrl_pipe == NULL) {
    217                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    218                 return EINVAL;
    219         }
    220        
    221         if (iface_no < 0) {
    222                 usb_log_warning("usbhid_req_set_report(): no interface given."
    223                     "\n");
    224                 return EINVAL;
    225         }
    226        
    227         /*
    228          * No need for checking other parameters, as they are checked in
    229          * the called function (usb_control_request_set()).
    230          */
    231        
     217                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     218                return EINVAL;
     219        }
     220
     221        if (iface_no < 0) {
     222                usb_log_warning("usbhid_req_set_report(): no interface given."
     223                    "\n");
     224                return EINVAL;
     225        }
     226
     227        /*
     228         * No need for checking other parameters, as they are checked in
     229         * the called function (usb_control_request_set()).
     230         */
     231
    232232        errno_t rc;
    233233
    234234        uint16_t value = 0;
    235235        value |= (type << 8);
    236        
    237         usb_log_debug("Sending Get Report request to the device.\n");
    238        
    239         rc = usb_control_request_get(ctrl_pipe, 
    240             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
     236
     237        usb_log_debug("Sending Get Report request to the device.");
     238
     239        rc = usb_control_request_get(ctrl_pipe,
     240            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    241241            USB_HIDREQ_GET_REPORT, value, iface_no, buffer, buf_size,
    242242            actual_size);
     
    247247                return rc;
    248248        }
    249        
     249
    250250        return EOK;
    251251}
     
    262262 * @return Other value inherited from function usb_control_request_set().
    263263 */
    264 errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 
     264errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
    265265    usb_hid_protocol_t *protocol)
    266266{
    267267        if (ctrl_pipe == NULL) {
    268                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    269                 return EINVAL;
    270         }
    271        
    272         if (iface_no < 0) {
    273                 usb_log_warning("usbhid_req_set_report(): no interface given."
    274                     "\n");
    275                 return EINVAL;
    276         }
    277        
    278         /*
    279          * No need for checking other parameters, as they are checked in
    280          * the called function (usb_control_request_set()).
    281          */
    282        
    283         errno_t rc;     
     268                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     269                return EINVAL;
     270        }
     271
     272        if (iface_no < 0) {
     273                usb_log_warning("usbhid_req_set_report(): no interface given."
     274                    "\n");
     275                return EINVAL;
     276        }
     277
     278        /*
     279         * No need for checking other parameters, as they are checked in
     280         * the called function (usb_control_request_set()).
     281         */
     282
     283        errno_t rc;
    284284
    285285        usb_log_debug("Sending Get Protocol request to the device ("
    286286            "iface: %d).\n", iface_no);
    287        
     287
    288288        uint8_t buffer[1];
    289289        size_t actual_size = 0;
    290        
    291         rc = usb_control_request_get(ctrl_pipe, 
    292             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
     290
     291        rc = usb_control_request_get(ctrl_pipe,
     292            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    293293            USB_HIDREQ_GET_PROTOCOL, 0, iface_no, buffer, 1, &actual_size);
    294294
     
    298298                return rc;
    299299        }
    300        
     300
    301301        if (actual_size != 1) {
    302                 usb_log_warning("Wrong data size: %zu, expected: 1.\n",
    303                         actual_size);
     302                usb_log_warning("Wrong data size: %zu, expected: 1.",
     303                    actual_size);
    304304                return ELIMIT;
    305305        }
    306        
     306
    307307        *protocol = buffer[0];
    308        
     308
    309309        return EOK;
    310310}
     
    320320 * @retval EOK if successful.
    321321 * @retval EINVAL if no HID device is given.
    322  * @return Other value inherited from one of functions 
     322 * @return Other value inherited from one of functions
    323323 *         usb_pipe_start_session(), usb_pipe_end_session(),
    324324 *         usb_control_request_set().
    325325 */
    326 errno_t usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration)
    327 {
    328         if (ctrl_pipe == NULL) {
    329                 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
    330                 return EINVAL;
    331         }
    332        
    333         if (iface_no < 0) {
    334                 usb_log_warning("usbhid_req_set_report(): no interface given."
    335                     "\n");
    336                 return EINVAL;
    337         }
    338        
    339         /*
    340          * No need for checking other parameters, as they are checked in
    341          * the called function (usb_control_request_set()).
    342          */
    343        
     326errno_t usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no,
     327    uint8_t *duration)
     328{
     329        if (ctrl_pipe == NULL) {
     330                usb_log_warning("usbhid_req_set_report(): no pipe given.");
     331                return EINVAL;
     332        }
     333
     334        if (iface_no < 0) {
     335                usb_log_warning("usbhid_req_set_report(): no interface given."
     336                    "\n");
     337                return EINVAL;
     338        }
     339
     340        /*
     341         * No need for checking other parameters, as they are checked in
     342         * the called function (usb_control_request_set()).
     343         */
     344
    344345        errno_t rc;
    345346
    346347        usb_log_debug("Sending Get Idle request to the device ("
    347348            "iface: %d).\n", iface_no);
    348        
     349
    349350        uint16_t value = 0;
    350351        uint8_t buffer[1];
    351352        size_t actual_size = 0;
    352        
    353         rc = usb_control_request_get(ctrl_pipe, 
    354             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
    355             USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1, 
     353
     354        rc = usb_control_request_get(ctrl_pipe,
     355            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     356            USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1,
    356357            &actual_size);
    357358
     
    361362                return rc;
    362363        }
    363        
     364
    364365        if (actual_size != 1) {
    365                 usb_log_warning("Wrong data size: %zu, expected: 1.\n",
    366                         actual_size);
     366                usb_log_warning("Wrong data size: %zu, expected: 1.",
     367                    actual_size);
    367368                return ELIMIT;
    368369        }
    369        
     370
    370371        *duration = buffer[0];
    371        
     372
    372373        return EOK;
    373374}
Note: See TracChangeset for help on using the changeset viewer.