Changes in / [173922f:8c74d15] in mainline


Ignore:
Location:
uspace/drv/usbhid
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/generic/hiddev.c

    r173922f r8c74d15  
    126126        }
    127127       
    128         /*! @todo This should probably be somehow atomic. */
     128        /*! @todo This should probably be atomic. */
     129//      if (usb_hid_report_ready()) {
     130//              usb_log_debug2("Report ready, size: %zu\n",
     131//                  hid_dev->input_report_size);
     132               
     133//              usb_hid_report_received();
     134//      } else {
     135//              memset(buffer, 0, hid_dev->input_report_size);
     136//      }
    129137        memcpy(buffer, hid_dev->input_report,
    130138            hid_dev->input_report_size);
     
    132140        *event_nr = usb_hid_report_number(hid_dev);
    133141       
     142        // clear the buffer so that it will not be received twice
     143        //memset(hid_dev->input_report, 0, hid_dev->input_report_size);
     144       
     145        // note that we already received this report
     146//      report_received = true;
    134147        usb_log_debug2("OK\n");
    135148       
     
    171184       
    172185        if (hid_dev->report_desc_size > size) {
    173                 return EINVAL;
     186                return EINVAL;  // TODO: other error code
    174187        }
    175188       
  • uspace/drv/usbhid/kbd/kbddev.c

    r173922f r8c74d15  
    7272static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    7373
     74///** Boot protocol report size (key part). */
     75//static const size_t BOOTP_REPORT_SIZE = 6;
     76
     77///** Boot protocol total report size. */
     78//static const size_t BOOTP_BUFFER_SIZE = 8;
     79
     80///** Boot protocol output report size. */
     81//static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
     82
     83///** Boot protocol error key code. */
     84//static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
    7485static const uint8_t ERROR_ROLLOVER = 1;
    7586
     
    94105        .flags = 0
    95106};
     107
     108//static usb_endpoint_description_t hid_poll_endpoint_description = {
     109//      .transfer_type = USB_TRANSFER_INTERRUPT,
     110//      .direction = USB_DIRECTION_IN,
     111//      .interface_class = USB_CLASS_HID,
     112//      .flags = 0
     113//};
     114
     115///* Array of endpoints expected on the device, NULL terminated. */
     116//usb_endpoint_description_t
     117//    *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1] = {
     118//      &boot_poll_endpoint_description,
     119//      &hid_poll_endpoint_description,
     120//      NULL
     121//};
    96122
    97123const char *HID_KBD_FUN_NAME = "keyboard";
     
    150176
    151177/*----------------------------------------------------------------------------*/
     178
     179//static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
     180//    uint8_t report_id, void *arg);
     181
     182//static const usb_hid_report_in_callbacks_t usb_kbd_parser_callbacks = {
     183//      .keyboard = usb_kbd_process_keycodes
     184//};
     185
     186/*----------------------------------------------------------------------------*/
    152187/* Keyboard layouts                                                           */
    153188/*----------------------------------------------------------------------------*/
     
    165200
    166201/*----------------------------------------------------------------------------*/
     202/* Modifier constants                                                         */
     203/*----------------------------------------------------------------------------*/
     204/** Mapping of USB modifier key codes to generic modifier key codes. */
     205//static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
     206//      KC_LCTRL,         /* USB_HID_MOD_LCTRL */
     207//      KC_LSHIFT,        /* USB_HID_MOD_LSHIFT */
     208//      KC_LALT,          /* USB_HID_MOD_LALT */
     209//      0,                /* USB_HID_MOD_LGUI */
     210//      KC_RCTRL,         /* USB_HID_MOD_RCTRL */
     211//      KC_RSHIFT,        /* USB_HID_MOD_RSHIFT */
     212//      KC_RALT,          /* USB_HID_MOD_RALT */
     213//      0,                /* USB_HID_MOD_RGUI */
     214//};
     215
     216//typedef enum usbhid_lock_code {
     217//      USB_KBD_LOCK_NUM = 0x53,
     218//      USB_KBD_LOCK_CAPS = 0x39,
     219//      USB_KBD_LOCK_SCROLL = 0x47,
     220//      USB_KBD_LOCK_COUNT = 3
     221//} usbhid_lock_code;
     222
     223//static const usbhid_lock_code usbhid_lock_codes[USB_KBD_LOCK_COUNT] = {
     224//      USB_KBD_LOCK_NUM,
     225//      USB_KBD_LOCK_CAPS,
     226//      USB_KBD_LOCK_SCROLL
     227//};
     228
     229/*----------------------------------------------------------------------------*/
    167230/* IPC method handler                                                         */
    168231/*----------------------------------------------------------------------------*/
    169232
    170233static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
     234//ddf_dev_ops_t keyboard_ops = {
     235//      .default_handler = default_connection_handler
     236//};
    171237
    172238/**
     
    235301                return;
    236302        }
    237 
     303               
    238304        /* Reset the LED data. */
    239305        memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t));
     
    429495 */
    430496static void usb_kbd_check_key_changes(usb_hid_dev_t *hid_dev,
    431     usb_kbd_t *kbd_dev)
     497    usb_kbd_t *kbd_dev/*, const uint8_t *key_codes, size_t count*/)
    432498{
    433499        unsigned int key;
     
    501567        }
    502568       
     569//      usb_log_debug("Old keys: ");
     570//      for (i = 0; i < kbd_dev->key_count; ++i) {
     571//              usb_log_debug("%d ", kbd_dev->keys_old[i]);
     572//      }
     573//      usb_log_debug("\n");
     574       
     575       
     576//      usb_log_debug("New keys: ");
     577//      for (i = 0; i < kbd_dev->key_count; ++i) {
     578//              usb_log_debug("%d ", kbd_dev->keys[i]);
     579//      }
     580//      usb_log_debug("\n");
     581       
    503582        memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4);
    504583       
     
    511590
    512591/*----------------------------------------------------------------------------*/
     592/* Callbacks for parser                                                       */
     593/*----------------------------------------------------------------------------*/
     594/**
     595 * Callback function for the HID report parser.
     596 *
     597 * This function is called by the HID report parser with the parsed report.
     598 * The parsed report is used to check if any events occured (key was pressed or
     599 * released, modifier was pressed or released).
     600 *
     601 * @param key_codes Parsed keyboard report - codes of currently pressed keys
     602 *                  according to HID Usage Tables.
     603 * @param count Number of key codes in report (size of the report).
     604 * @param report_id
     605 * @param arg User-specified argument. Expects pointer to the keyboard device
     606 *            structure representing the keyboard.
     607 *
     608 * @sa usb_kbd_check_key_changes(), usb_kbd_check_modifier_changes()
     609 */
     610//static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
     611//    uint8_t report_id, void *arg)
     612//{
     613//      if (arg == NULL) {
     614//              usb_log_warning("Missing argument in callback "
     615//                  "usbhid_process_keycodes().\n");
     616//              return;
     617//      }
     618       
     619//      usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
     620       
     621//      if (hid_dev->data == NULL) {
     622//              usb_log_warning("Missing KBD device structure in callback.\n");
     623//              return;
     624//      }
     625       
     626//      usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data;
     627
     628//      usb_log_debug("Got keys from parser (report id: %u): %s\n",
     629//          report_id, usb_debug_str_buffer(key_codes, count, 0));
     630       
     631//      if (count != kbd_dev->key_count) {
     632//              usb_log_warning("Number of received keycodes (%zu) differs from"
     633//                  " expected (%zu).\n", count, kbd_dev->key_count);
     634//              return;
     635//      }
     636       
     637//      ///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count);
     638//      usb_kbd_check_key_changes(hid_dev, kbd_dev, key_codes, count);
     639//}
     640
     641/*----------------------------------------------------------------------------*/
    513642/* General kbd functions                                                      */
    514643/*----------------------------------------------------------------------------*/
     
    539668            "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0));
    540669       
     670//      int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
     671//          callbacks, kbd_dev);
    541672        usb_hid_report_path_t *path = usb_hid_report_path();
    542673        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
     674        //usb_hid_report_path_set_report_id(path, 0);
    543675
    544676        uint8_t report_id;
     
    566698               
    567699                assert(i < kbd_dev->key_count);
     700//              if (i == kbd_dev->key_count) {
     701//                      break;
     702//              }
    568703               
    569704                // save the key usage
     705                /* TODO: maybe it's not good to save value, nor usage
     706                 *       as the value may be e.g. 1 for LEDs and usage may be
     707                 *       value of the LED. On the other hand, in case of normal
     708                 *       keys, the usage is more important and we must check
     709                 *       that. One possible solution: distinguish between those
     710                 *       two parts of the Report somehow.
     711                 */
    570712                if (field->value != 0) {
    571713                        kbd_dev->keys[i] = field->usage;
     
    754896                usb_log_warning("Error creating output report buffer.\n");
    755897                free(kbd_dev->keys);
    756                 return ENOMEM;
     898                return ENOMEM;  /* TODO: other error code */
    757899        }
    758900       
     
    809951       
    810952        // save the KBD device structure into the HID device structure
     953        //hid_dev->data = kbd_dev;
    811954        *data = kbd_dev;
    812955       
     
    8951038       
    8961039        if ((*kbd_dev)->repeat_mtx != NULL) {
    897                 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
    898                 while (fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)) {}
     1040                /* TODO: replace by some check and wait */
     1041                assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
    8991042                free((*kbd_dev)->repeat_mtx);
    9001043        }
  • uspace/drv/usbhid/kbd/main.c

    r173922f r8c74d15  
    131131                    "Could not add DDF function to class 'keyboard': %s.\n",
    132132                    str_error(rc));
     133                // TODO: Can / should I destroy the DDF function?
    133134                ddf_fun_destroy(kbd_fun);
    134135                usb_kbd_free(&kbd_dev);
    135136                return rc;
    136137        }
     138       
     139        /*
     140         * Create new fibril for handling this keyboard
     141         */
     142        //fid_t fid = fibril_create(usb_kbd_fibril, kbd_dev);
    137143       
    138144        /* Start automated polling function.
     
    158164                return rc;
    159165        }
     166        //fibril_add_ready(fid);
    160167       
    161168        /*
  • uspace/drv/usbhid/mouse/mousedev.c

    r173922f r8c74d15  
    394394       
    395395        fun->ops = &mouse->ops;
    396         fun->driver_data = mouse;
     396        fun->driver_data = mouse;   // TODO: maybe change to hid_dev->data
    397397
    398398        int rc = ddf_fun_bind(fun);
     
    432432         */
    433433        fun->ops = &mouse->ops;
    434         fun->driver_data = mouse;
     434        fun->driver_data = mouse;   // TODO: maybe change to hid_dev->data
    435435
    436436        rc = ddf_fun_bind(fun);
     
    488488       
    489489        // set handler for incoming calls
     490        // TODO: must be one for each subdriver!!
    490491        mouse_dev->ops.default_handler = default_connection_handler;
    491492       
    492493        // TODO: how to know if the device supports the request???
    493         usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
    494             hid_dev->usb_dev->interface_no, IDLE_RATE);
     494//      usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
     495//          hid_dev->usb_dev->interface_no, IDLE_RATE);
    495496       
    496497        int rc = usb_mouse_create_function(hid_dev, mouse_dev);
  • uspace/drv/usbhid/mouse/mousedev.h

    r173922f r8c74d15  
    4545/** Container for USB mouse device. */
    4646typedef struct {
     47        ///** Polling interval in microseconds. */
     48        //suseconds_t poll_interval_us;
    4749        /** IPC phone to console (consumer). */
    4850        int mouse_phone;
  • uspace/drv/usbhid/multimedia/multimedia.c

    r173922f r8c74d15  
    143143        assert(multim_dev != NULL);
    144144       
     145//      usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data;
     146       
    145147        console_event_t ev;
    146148       
     
    171173        // hangup phone to the console
    172174        async_hangup((*multim_dev)->console_phone);
     175       
     176        // free all buffers
     177//      if ((*multim_dev)->keys != NULL) {
     178//              free((*multim_dev)->keys);
     179//      }
     180//      if ((*multim_dev)->keys_old != NULL) {
     181//              free((*multim_dev)->keys_old);
     182//      }
    173183
    174184        free(*multim_dev);
     
    235245        multim_dev->console_phone = -1;
    236246       
     247//      usb_hid_report_path_t *path = usb_hid_report_path();
     248//      usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     249       
     250//      usb_hid_report_path_set_report_id(path, 1);
     251       
     252//      multim_dev->key_count = usb_hid_report_size(
     253//          hid_dev->report, 1, USB_HID_REPORT_TYPE_INPUT);
     254
     255//      usb_hid_report_path_free(path);
     256       
     257//      usb_log_debug(NAME " Size of the input report: %zu\n",
     258//          multim_dev->key_count);
     259       
     260//      multim_dev->keys = (int32_t *)calloc(multim_dev->key_count,
     261//          sizeof(int32_t));
     262       
     263//      if (multim_dev->keys == NULL) {
     264//              usb_log_fatal("No memory!\n");
     265//              free(multim_dev);
     266//              return ENOMEM;
     267//      }
     268       
     269//      multim_dev->keys_old =
     270//              (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t));
     271       
     272//      if (multim_dev->keys_old == NULL) {
     273//              usb_log_fatal("No memory!\n");
     274//              free(multim_dev->keys);
     275//              free(multim_dev);
     276//              return ENOMEM;
     277//      }
     278       
    237279        /*! @todo Autorepeat */
    238280       
     
    273315{
    274316        // TODO: checks
    275         if (hid_dev == NULL || data == NULL || buffer == NULL) {
    276                 return false;
    277         }
    278317       
    279318        usb_log_debug(NAME " usb_lgtch_polling_callback(%p, %p, %zu)\n",
    280319            hid_dev, buffer, buffer_size);
     320       
     321        if (data == NULL) {
     322                return EINVAL;  // TODO: other error code?
     323        }
    281324       
    282325        usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
     
    305348            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    306349            USB_HID_REPORT_TYPE_INPUT);
    307 
     350       
     351//      unsigned int key;
     352       
    308353        /*! @todo Is this iterating OK if done multiple times?
    309354         *  @todo The parsing is not OK
  • uspace/drv/usbhid/subdrivers.c

    r173922f r8c74d15  
    5858};
    5959
     60//static usb_hid_subdriver_usage_t generic_hid_key_path[] = {
     61//      {0, 0}
     62//};
     63
    6064const usb_hid_subdriver_mapping_t usb_hid_subdrivers[] = {
    6165        {
     
    99103                }
    100104        },
     105//      {
     106//              generic_hid_key_path,
     107//              0,
     108//              USB_HID_PATH_COMPARE_ANYWHERE,
     109//              -1,
     110//              -1,
     111//              {
     112//                      .init = usb_generic_hid_init,
     113//                      .deinit = NULL,
     114//                      .poll = usb_generic_hid_polling_callback,
     115//                      .poll_end = NULL
     116//              }
     117//      },
    101118        {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL, NULL}}
    102119};
  • uspace/drv/usbhid/usbhid.c

    r173922f r8c74d15  
    6363static const int USB_HID_MAX_SUBDRIVERS = 10;
    6464
     65/** @todo What happens if this is not fibril local? */
     66//static fibril_local bool report_number;
     67
    6568/*----------------------------------------------------------------------------*/
    6669
     
    203206        }
    204207       
     208//      if (mapping->report_id >= 0) {
     209//              usb_hid_report_path_set_report_id(usage_path,
     210//                  mapping->report_id);
     211//      }
     212       
    205213        assert(hid_dev->report != NULL);
    206214       
    207215        usb_log_debug("Compare flags: %d\n", mapping->compare);
     216//      size_t size = usb_hid_report_size(hid_dev->report, 0,
     217//          USB_HID_REPORT_TYPE_INPUT);
     218//      size_t size = 0;
    208219       
    209220        bool matches = false;
     221
     222//      usb_hid_report_description_t *report_des =
     223//              usb_hid_report_find_description(hid_dev->report,
     224//              mapping->report_id, USB_HID_REPORT_TYPE_INPUT);
    210225        uint8_t report_id = mapping->report_id;
    211226
    212         do {
     227        /*while(report_des != NULL)*/do {
     228
     229//              if((mapping->report_id) == 0 && (report_des->report_id != 0)) {
     230//                      usb_hid_report_path_set_report_id(usage_path,
     231//                              report_des->report_id);
     232//              }
     233                                             
    213234                usb_log_debug("Trying report id %u\n", report_id);
    214235               
     
    226247
    227248                if (field != NULL) {
     249//                      size++;
     250//                      field = usb_hid_report_get_sibling(hid_dev->report,
     251//                          field, usage_path, mapping->compare,
     252//                          USB_HID_REPORT_TYPE_INPUT);
    228253                        matches = true;
    229254                        break;
     
    233258                    hid_dev->report, report_id,
    234259                    USB_HID_REPORT_TYPE_INPUT);
     260
     261//              if((mapping->report_id == 0) && (report_des->report_id != 0)) {
     262//                      uint8_t report_id = usb_hid_get_next_report_id(
     263//                              hid_dev->report, report_des->report_id,
     264//                              USB_HID_REPORT_TYPE_INPUT);
     265
     266//                      if(report_id == 0) {
     267//                              break;
     268//                      }
     269
     270//                      report_des = usb_hid_report_find_description(
     271//                              hid_dev->report, report_id,
     272//                              USB_HID_REPORT_TYPE_INPUT);
     273//              }
     274//              else {
     275//                      break;
     276//              }
    235277        } while (!matches && report_id != 0);
    236278       
     279//      usb_log_debug("Size of the input report: %zu\n", size);
    237280        usb_hid_report_path_free(usage_path);
    238281       
     
    380423       
    381424        uint8_t report_id = 0;
    382         size_t size;
     425        size_t size;/* = usb_hid_report_byte_size(hid_dev->report, report_id,
     426            USB_HID_REPORT_TYPE_INPUT);*/
    383427       
    384428        size_t max_size = 0;
     
    459503        rc = usb_hid_check_pipes(hid_dev, dev);
    460504        if (rc != EOK) {
     505                //usb_hid_free(&hid_dev);
    461506                return rc;
    462507        }
     
    506551                            == USB_HID_GENERIC_POLL_EP_NO);
    507552                       
     553                        /* TODO: this has no meaning if the report descriptor
     554                                 is not parsed */
    508555                        usb_log_info("Falling back to generic HID driver.\n");
    509556                        rc = usb_hid_set_generic_hid_subdriver(hid_dev);
     
    516563                usb_log_debug("Subdriver count: %d\n",
    517564                    hid_dev->subdriver_count);
     565                //usb_hid_free(&hid_dev);
    518566               
    519567        } else {
     
    571619        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
    572620       
     621//      int allocated = (hid_dev->input_report != NULL);
    573622        assert(hid_dev->input_report != NULL);
    574623        usb_log_debug("Max input report size: %zu, buffer size: %zu\n",
    575624            hid_dev->max_input_report_size, buffer_size);
    576 
     625        //assert(hid_dev->max_input_report_size >= buffer_size);
    577626        if (hid_dev->max_input_report_size >= buffer_size) {
    578627                /*! @todo This should probably be atomic. */
     
    621670/*----------------------------------------------------------------------------*/
    622671
     672//const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev)
     673//{
     674//      switch (hid_dev->poll_pipe_index) {
     675//      case USB_HID_KBD_POLL_EP_NO:
     676//              return HID_KBD_FUN_NAME;
     677//              break;
     678//      case USB_HID_MOUSE_POLL_EP_NO:
     679//              return HID_MOUSE_FUN_NAME;
     680//              break;
     681//      default:
     682//              return HID_GENERIC_FUN_NAME;
     683//      }
     684//}
     685
     686/*----------------------------------------------------------------------------*/
     687
     688//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev)
     689//{
     690//      // this means that only boot protocol keyboards will be connected
     691//      // to the console; there is probably no better way to do this
     692       
     693//      switch (hid_dev->poll_pipe_index) {
     694//      case USB_HID_KBD_POLL_EP_NO:
     695//              return HID_KBD_CLASS_NAME;
     696//              break;
     697//      case USB_HID_MOUSE_POLL_EP_NO:
     698//              return HID_MOUSE_CLASS_NAME;
     699//              break;
     700//      default:
     701//              return HID_GENERIC_CLASS_NAME;
     702//      }
     703//}
     704
     705/*----------------------------------------------------------------------------*/
     706
    623707void usb_hid_new_report(usb_hid_dev_t *hid_dev)
    624708{
     
    632716        return hid_dev->report_nr;
    633717}
     718
     719/*----------------------------------------------------------------------------*/
     720
     721//void usb_hid_report_received(void)
     722//{
     723//      ++report_number;
     724//}
     725
     726/*----------------------------------------------------------------------------*/
     727
     728//bool usb_hid_report_ready(void)
     729//{
     730//      return !report_received;
     731//}
    634732
    635733/*----------------------------------------------------------------------------*/
  • uspace/drv/usbhid/usbhid.h

    r173922f r8c74d15  
    5555                                         bool reason);
    5656
     57// TODO: add function and class name??
    5758typedef struct usb_hid_subdriver {     
    5859        /** Function to be called when initializing HID device. */
     
    125126     void *arg);
    126127
     128//const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev);
     129
     130//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
     131
    127132void usb_hid_new_report(usb_hid_dev_t *hid_dev);
    128133
    129134int usb_hid_report_number(usb_hid_dev_t *hid_dev);
     135
     136//void usb_hid_report_received(void);
     137
     138//bool usb_hid_report_ready(void);
    130139
    131140void usb_hid_free(usb_hid_dev_t **hid_dev);
Note: See TracChangeset for help on using the changeset viewer.