Changeset 0475e13 in mainline for uspace/drv/usbhid/main.c


Ignore:
Timestamp:
2011-02-25T10:40:14Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3a1aa20
Parents:
54e682f
Message:

Setting boot protocol for the keyboard, initialization in add_device().

  • Moved initialization of kbd to add_device() function. If it fails, it doesn't start to poll the keyboard.
  • Added setting of boot protocol to the keyboard in init_device().
  • Added constants for protocols to libusb/classes/hid (and renamed interface protocol enum).
File:
1 edited

Legend:

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

    r54e682f r0475e13  
    162162static int active_layout = 0;
    163163
    164 static void usbkbd_req_set_report(usb_hid_dev_kbd_t *kbd_dev, uint8_t *buffer,
    165     size_t buf_size)
     164static void usbkbd_req_set_report(usb_hid_dev_kbd_t *kbd_dev, uint16_t iface,
     165    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
    166166{
    167167        int rc, sess_rc;
     
    175175
    176176        usb_log_debug("Sending Set_Report request to the device.\n");
    177         // TODO: determine what interface to use!! (now set to 1)
     177       
    178178        rc = usb_control_request_set(&kbd_dev->ctrl_pipe,
    179179            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    180             USB_HIDREQ_SET_REPORT, USB_HID_REPORT_TYPE_OUTPUT,
    181             1, buffer, buf_size);
     180            USB_HIDREQ_SET_REPORT, type, iface, buffer, buf_size);
     181
     182        sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     183
     184        if (rc != EOK) {
     185                usb_log_warning("Error sending output report to the keyboard: "
     186                    "%s.\n", str_error(rc));
     187                return;
     188        }
     189
     190        if (sess_rc != EOK) {
     191                usb_log_warning("Error closing session: %s.\n",
     192                    str_error(sess_rc));
     193                return;
     194        }
     195}
     196
     197static void usbkbd_req_set_protocol(usb_hid_dev_kbd_t *kbd_dev, uint16_t iface,
     198    usb_hid_protocol_t protocol)
     199{
     200        int rc, sess_rc;
     201       
     202        sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
     203        if (sess_rc != EOK) {
     204                usb_log_warning("Failed to start a session: %s.\n",
     205                    str_error(sess_rc));
     206                return;
     207        }
     208
     209        usb_log_debug("Sending Set_Protocol request to the device.\n");
     210       
     211        rc = usb_control_request_set(&kbd_dev->ctrl_pipe,
     212            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     213            USB_HIDREQ_SET_PROTOCOL, protocol, iface, NULL, 0);
    182214
    183215        sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     
    225257        }
    226258       
    227         usbkbd_req_set_report(kbd_dev, buffer, BUFFER_SIZE);
     259        // TODO: determine what interface to use!! (now set to 1)
     260        usbkbd_req_set_report(kbd_dev, 1, USB_HID_REPORT_TYPE_OUTPUT, buffer,
     261            BUFFER_SIZE);
    228262}
    229263
     
    565599        }
    566600
    567 
    568 
    569 
    570601        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    571602            sizeof(usb_hid_configuration_t));
     
    671702        usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    672703       
     704        // set boot protocol
     705        usbkbd_req_set_protocol(kbd_dev, 1, USB_HID_PROTOCOL_BOOT);
     706       
    673707        return kbd_dev;
    674708
     
    760794                return -1;
    761795        }
    762 
    763         ddf_dev_t *dev = (ddf_dev_t *)arg;
    764 
    765         // initialize device (get and process descriptors, get address, etc.)
     796       
     797        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg;
     798
     799        usbkbd_poll_keyboard(kbd_dev);
     800
     801        return EOK;
     802}
     803
     804static int usbkbd_add_device(ddf_dev_t *dev)
     805{
     806        /*
     807         * Create default function.
     808         */
     809        // FIXME - check for errors
     810        ddf_fun_t *kbd_fun = ddf_fun_create(dev, fun_exposed, "keyboard");
     811        assert(kbd_fun != NULL);
     812        kbd_fun->ops = &keyboard_ops;
     813
     814        int rc = ddf_fun_bind(kbd_fun);
     815        assert(rc == EOK);
     816        rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
     817        assert(rc == EOK);
     818       
     819        /*
     820         * Initialize device (get and process descriptors, get address, etc.)
     821         */
    766822        usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
    767823        if (kbd_dev == NULL) {
     
    770826        }
    771827
    772         usbkbd_poll_keyboard(kbd_dev);
    773 
    774         return EOK;
    775 }
    776 
    777 static int usbkbd_add_device(ddf_dev_t *dev)
    778 {
    779         /* For now, fail immediately. */
    780         //return ENOTSUP;
    781 
    782         /*
    783          * When everything is okay, connect to "our" HC.
    784          *
    785          * Not supported yet, skip..
    786          */
    787 //      int phone = usb_drv_hc_connect_auto(dev, 0);
    788 //      if (phone < 0) {
    789 //              /*
    790 //               * Connecting to HC failed, roll-back and announce
    791 //               * failure.
    792 //               */
    793 //              return phone;
    794 //      }
    795 
    796 //      dev->parent_phone = phone;
    797 
    798         /*
    799          * Create default function.
    800          */
    801         // FIXME - check for errors
    802         ddf_fun_t *kbd_fun = ddf_fun_create(dev, fun_exposed, "keyboard");
    803         assert(kbd_fun != NULL);
    804         kbd_fun->ops = &keyboard_ops;
    805 
    806         int rc = ddf_fun_bind(kbd_fun);
    807         assert(rc == EOK);
    808         rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
    809         assert(rc == EOK);
    810 
    811828        /*
    812829         * Create new fibril for handling this keyboard
    813830         */
    814         fid_t fid = fibril_create(usbkbd_fibril_device, dev);
     831        fid_t fid = fibril_create(usbkbd_fibril_device, kbd_dev);
    815832        if (fid == 0) {
    816833                usb_log_error("Failed to start fibril for HID device\n");
Note: See TracChangeset for help on using the changeset viewer.