Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 31cfee16 in mainline


Ignore:
Timestamp:
2011-05-03T09:16:39Z (11 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master
Children:
3facf63a
Parents:
30710035
Message:

Creating DDF functions in subdrivers + saving input report.

  • Keyboard function.
  • Mouse function.
  • Lgtch UltraX function - added to class keyboard.
  • Saving input report in hid dev structure.
Location:
uspace/drv/usbhid
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/kbd/kbddev.c

    r30710035 r31cfee16  
    766766
    767767/*----------------------------------------------------------------------------*/
     768
     769static int usb_kbd_create_function(usb_hid_dev_t *hid_dev)
     770{
     771        assert(hid_dev != NULL);
     772        assert(hid_dev->usb_dev != NULL);
     773       
     774        /* Create the function exposed under /dev/devices. */
     775        usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME);
     776        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     777            HID_KBD_FUN_NAME);
     778        if (fun == NULL) {
     779                usb_log_error("Could not create DDF function node.\n");
     780                return ENOMEM;
     781        }
     782       
     783        /*
     784         * Store the initialized HID device and HID ops
     785         * to the DDF function.
     786         */
     787        fun->ops = &hid_dev->ops;
     788        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
     789
     790        int rc = ddf_fun_bind(fun);
     791        if (rc != EOK) {
     792                usb_log_error("Could not bind DDF function: %s.\n",
     793                    str_error(rc));
     794                ddf_fun_destroy(fun);
     795                return rc;
     796        }
     797       
     798        usb_log_debug("Adding DDF function to class %s...\n",
     799            HID_KBD_CLASS_NAME);
     800        rc = ddf_fun_add_to_class(fun, HID_KBD_CLASS_NAME);
     801        if (rc != EOK) {
     802                usb_log_error(
     803                    "Could not add DDF function to class %s: %s.\n",
     804                    HID_KBD_CLASS_NAME, str_error(rc));
     805                ddf_fun_destroy(fun);
     806                return rc;
     807        }
     808       
     809        return EOK;
     810}
     811
     812/*----------------------------------------------------------------------------*/
    768813/* API functions                                                              */
    769814/*----------------------------------------------------------------------------*/
     
    930975        usb_log_debug("HID/KBD device structure initialized.\n");
    931976       
     977        usb_log_debug("Creating KBD function...\n");
     978        int rc = usb_kbd_create_function(hid_dev);
     979        if (rc != EOK) {
     980                usb_kbd_free(&kbd_dev);
     981                return rc;
     982        }
     983       
    932984        return EOK;
    933985}
  • uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c

    r30710035 r31cfee16  
    5858} usb_lgtch_flags;
    5959
     60/*----------------------------------------------------------------------------*/
     61/**
     62 * Logitech UltraX device type.
     63 */
     64typedef struct usb_lgtch_ultrax_t {
     65        /** Previously pressed keys (not translated to key codes). */
     66        int32_t *keys_old;
     67        /** Currently pressed keys (not translated to key codes). */
     68        int32_t *keys;
     69        /** Count of stored keys (i.e. number of keys in the report). */
     70        size_t key_count;
     71       
     72        /** IPC phone to the console device (for sending key events). */
     73        int console_phone;
     74
     75        /** Information for auto-repeat of keys. */
     76//      usb_kbd_repeat_t repeat;
     77       
     78        /** Mutex for accessing the information about auto-repeat. */
     79//      fibril_mutex_t *repeat_mtx;
     80
     81        /** State of the structure (for checking before use).
     82         *
     83         * 0 - not initialized
     84         * 1 - initialized
     85         * -1 - ready for destroying
     86         */
     87        int initialized;
     88} usb_lgtch_ultrax_t;
     89
    6090
    6191/*----------------------------------------------------------------------------*/
     
    208238/*----------------------------------------------------------------------------*/
    209239
    210 int usb_lgtch_init(struct usb_hid_dev *hid_dev)
    211 {
    212         if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
    213                 return EINVAL; /*! @todo Other return code? */
    214         }
    215        
    216         usb_log_debug(NAME " Initializing HID/lgtch_ultrax structure...\n");
    217        
    218         usb_lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)malloc(
    219             sizeof(usb_lgtch_ultrax_t));
    220         if (lgtch_dev == NULL) {
    221                 return ENOMEM;
    222         }
    223        
    224         lgtch_dev->console_phone = -1;
    225        
    226         usb_hid_report_path_t *path = usb_hid_report_path();
    227         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
    228        
    229         usb_hid_report_path_set_report_id(path, 1);
    230        
    231         lgtch_dev->key_count = usb_hid_report_input_length(
    232             hid_dev->report, path,
    233             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
    234         usb_hid_report_path_free(path);
    235        
    236         usb_log_debug(NAME " Size of the input report: %zu\n",
    237             lgtch_dev->key_count);
    238        
    239         lgtch_dev->keys = (int32_t *)calloc(lgtch_dev->key_count,
    240             sizeof(int32_t));
    241        
    242         if (lgtch_dev->keys == NULL) {
    243                 usb_log_fatal("No memory!\n");
    244                 free(lgtch_dev);
    245                 return ENOMEM;
    246         }
    247        
    248         lgtch_dev->keys_old =
    249                 (int32_t *)calloc(lgtch_dev->key_count, sizeof(int32_t));
    250        
    251         if (lgtch_dev->keys_old == NULL) {
    252                 usb_log_fatal("No memory!\n");
    253                 free(lgtch_dev->keys);
    254                 free(lgtch_dev);
    255                 return ENOMEM;
    256         }
    257        
    258         /*! @todo Autorepeat */
    259        
    260         // save the KBD device structure into the HID device structure
    261         hid_dev->data = lgtch_dev;
    262        
     240static int usb_lgtch_create_function(usb_hid_dev_t *hid_dev)
     241{
    263242        /* Create the function exposed under /dev/devices. */
    264243        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     
    269248        }
    270249       
    271         lgtch_dev->initialized = USB_LGTCH_STATUS_INITIALIZED;
    272         usb_log_debug(NAME " HID/lgtch_ultrax device structure initialized.\n");
    273        
    274250        /*
    275251         * Store the initialized HID device and HID ops
     
    279255        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
    280256       
    281         /*
    282          * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da
    283          *    do nej.
    284          * 2) do tych ops do .interfaces[DEV_IFACE_USBHID (asi)] priradi
    285          *    vyplnenu strukturu usbhid_iface_t.
    286          * 3) klientska aplikacia - musi si rucne vytvorit telefon
    287          *    (devman_device_connect() - cesta k zariadeniu (/hw/pci0/...) az
    288          *    k tej fcii.
    289          *    pouzit usb/classes/hid/iface.h - prvy int je telefon
    290          */
    291 
    292257        int rc = ddf_fun_bind(fun);
    293258        if (rc != EOK) {
     
    296261                // TODO: Can / should I destroy the DDF function?
    297262                ddf_fun_destroy(fun);
    298                 usb_lgtch_free(&lgtch_dev);
    299263                return rc;
    300264        }
     
    307271                // TODO: Can / should I destroy the DDF function?
    308272                ddf_fun_destroy(fun);
     273                return rc;
     274        }
     275       
     276        return EOK;
     277}
     278
     279/*----------------------------------------------------------------------------*/
     280
     281int usb_lgtch_init(struct usb_hid_dev *hid_dev)
     282{
     283        if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
     284                return EINVAL; /*! @todo Other return code? */
     285        }
     286       
     287        usb_log_debug(NAME " Initializing HID/lgtch_ultrax structure...\n");
     288       
     289        usb_lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)malloc(
     290            sizeof(usb_lgtch_ultrax_t));
     291        if (lgtch_dev == NULL) {
     292                return ENOMEM;
     293        }
     294       
     295        lgtch_dev->console_phone = -1;
     296       
     297        usb_hid_report_path_t *path = usb_hid_report_path();
     298        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     299       
     300        usb_hid_report_path_set_report_id(path, 1);
     301       
     302        lgtch_dev->key_count = usb_hid_report_input_length(
     303            hid_dev->report, path,
     304            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
     305        usb_hid_report_path_free(path);
     306       
     307        usb_log_debug(NAME " Size of the input report: %zu\n",
     308            lgtch_dev->key_count);
     309       
     310        lgtch_dev->keys = (int32_t *)calloc(lgtch_dev->key_count,
     311            sizeof(int32_t));
     312       
     313        if (lgtch_dev->keys == NULL) {
     314                usb_log_fatal("No memory!\n");
     315                free(lgtch_dev);
     316                return ENOMEM;
     317        }
     318       
     319        lgtch_dev->keys_old =
     320                (int32_t *)calloc(lgtch_dev->key_count, sizeof(int32_t));
     321       
     322        if (lgtch_dev->keys_old == NULL) {
     323                usb_log_fatal("No memory!\n");
     324                free(lgtch_dev->keys);
     325                free(lgtch_dev);
     326                return ENOMEM;
     327        }
     328       
     329        /*! @todo Autorepeat */
     330       
     331        // save the KBD device structure into the HID device structure
     332        hid_dev->data = lgtch_dev;
     333       
     334        lgtch_dev->initialized = USB_LGTCH_STATUS_INITIALIZED;
     335        usb_log_debug(NAME " HID/lgtch_ultrax device structure initialized.\n");
     336       
     337        int rc = usb_lgtch_create_function(hid_dev);
     338        if (rc != EOK) {
    309339                usb_lgtch_free(&lgtch_dev);
    310340                return rc;
  • uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.h

    r30710035 r31cfee16  
    4242
    4343/*----------------------------------------------------------------------------*/
    44 /**
    45  * USB/HID keyboard device type.
    46  *
    47  * Holds a reference to generic USB/HID device structure and keyboard-specific
    48  * data, such as currently pressed keys, modifiers and lock keys.
    49  *
    50  * Also holds a IPC phone to the console (since there is now no other way to
    51  * communicate with it).
    52  *
    53  * @note Storing active lock keys in this structure results in their setting
    54  *       being device-specific.
    55  */
    56 typedef struct usb_lgtch_ultrax_t {
    57         /** Previously pressed keys (not translated to key codes). */
    58         int32_t *keys_old;
    59         /** Currently pressed keys (not translated to key codes). */
    60         int32_t *keys;
    61         /** Count of stored keys (i.e. number of keys in the report). */
    62         size_t key_count;
    63        
    64         /** IPC phone to the console device (for sending key events). */
    65         int console_phone;
    66 
    67         /** Information for auto-repeat of keys. */
    68 //      usb_kbd_repeat_t repeat;
    69        
    70         /** Mutex for accessing the information about auto-repeat. */
    71 //      fibril_mutex_t *repeat_mtx;
    72 
    73         /** State of the structure (for checking before use).
    74          *
    75          * 0 - not initialized
    76          * 1 - initialized
    77          * -1 - ready for destroying
    78          */
    79         int initialized;
    80 } usb_lgtch_ultrax_t;
    81 
    82 /*----------------------------------------------------------------------------*/
    8344
    8445int usb_lgtch_init(struct usb_hid_dev *hid_dev);
  • uspace/drv/usbhid/main.c

    r30710035 r31cfee16  
    9999        usb_log_debug("USB/HID device structure initialized.\n");
    100100       
    101         /* Create the function exposed under /dev/devices. */
    102         ddf_fun_t *hid_fun = ddf_fun_create(dev->ddf_dev, fun_exposed,
    103             usb_hid_get_function_name(hid_dev));
    104         if (hid_fun == NULL) {
    105                 usb_log_error("Could not create DDF function node.\n");
    106                 usb_hid_free(&hid_dev);
    107                 return ENOMEM;
    108         }
    109        
    110         /*
    111          * Store the initialized HID device and HID ops
    112          * to the DDF function.
    113          */
    114         hid_fun->ops = &hid_dev->ops;
    115         hid_fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
    116        
    117101        /*
    118102         * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da
     
    125109         *    pouzit usb/classes/hid/iface.h - prvy int je telefon
    126110         */
    127 
    128         rc = ddf_fun_bind(hid_fun);
    129         if (rc != EOK) {
    130                 usb_log_error("Could not bind DDF function: %s.\n",
    131                     str_error(rc));
    132                 // TODO: Can / should I destroy the DDF function?
    133                 ddf_fun_destroy(hid_fun);
    134                 usb_hid_free(&hid_dev);
    135                 return rc;
    136         }
    137        
    138         rc = ddf_fun_add_to_class(hid_fun, usb_hid_get_class_name(hid_dev));
    139         if (rc != EOK) {
    140                 usb_log_error(
    141                     "Could not add DDF function to class 'hid': %s.\n",
    142                     str_error(rc));
    143                 // TODO: Can / should I destroy the DDF function?
    144                 ddf_fun_destroy(hid_fun);
    145                 usb_hid_free(&hid_dev);
    146                 return rc;
    147         }
    148111       
    149112        /* Start automated polling function.
  • uspace/drv/usbhid/mouse/mousedev.c

    r30710035 r31cfee16  
    300300/*----------------------------------------------------------------------------*/
    301301
     302static int usb_mouse_create_function(usb_hid_dev_t *hid_dev)
     303{
     304        /* Create the function exposed under /dev/devices. */
     305        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
     306        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     307            HID_MOUSE_FUN_NAME);
     308        if (fun == NULL) {
     309                usb_log_error("Could not create DDF function node.\n");
     310                return ENOMEM;
     311        }
     312       
     313        /*
     314         * Store the initialized HID device and HID ops
     315         * to the DDF function.
     316         */
     317        fun->ops = &hid_dev->ops;
     318        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
     319
     320        int rc = ddf_fun_bind(fun);
     321        if (rc != EOK) {
     322                usb_log_error("Could not bind DDF function: %s.\n",
     323                    str_error(rc));
     324                ddf_fun_destroy(fun);
     325                return rc;
     326        }
     327       
     328        usb_log_debug("Adding DDF function to class %s...\n",
     329            HID_MOUSE_CLASS_NAME);
     330        rc = ddf_fun_add_to_class(fun, HID_MOUSE_CLASS_NAME);
     331        if (rc != EOK) {
     332                usb_log_error(
     333                    "Could not add DDF function to class %s: %s.\n",
     334                    HID_MOUSE_CLASS_NAME, str_error(rc));
     335                ddf_fun_destroy(fun);
     336                return rc;
     337        }
     338       
     339        return EOK;
     340}
     341
     342/*----------------------------------------------------------------------------*/
     343
    302344int usb_mouse_init(usb_hid_dev_t *hid_dev)
    303345{
     
    317359        }
    318360       
    319 //      usb_hid_report_path_t *path = usb_hid_report_path();
    320 //      usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    321        
    322 //      usb_hid_report_path_set_report_id(path, 0);
    323        
    324 //      mouse_dev->button_count = usb_hid_report_input_length(
    325 //          hid_dev->report, path,
    326 //          USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
    327 //      usb_hid_report_path_free(path);
    328        
    329 //      usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    330        
    331361        mouse_dev->buttons = (int32_t *)calloc(USB_MOUSE_BUTTON_COUNT,
    332362            sizeof(int32_t));
     
    348378//          hid_dev->usb_dev->interface_no, IDLE_RATE);
    349379       
     380        int rc = usb_mouse_create_function(hid_dev);
     381        if (rc != EOK) {
     382                usb_mouse_free(&mouse_dev);
     383                return rc;
     384        }
     385       
    350386        return EOK;
    351387}
  • uspace/drv/usbhid/usbhid.c

    r30710035 r31cfee16  
    490490        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
    491491       
     492        int allocated = (hid_dev->input_report == NULL);
     493       
     494        if (!allocated
     495            || hid_dev->input_report_size < buffer_size) {
     496                uint8_t *input_old = hid_dev->input_report;
     497                uint8_t *input_new = (uint8_t *)malloc(buffer_size);
     498               
     499                if (input_new == NULL) {
     500                        usb_log_error("Failed to allocate space for input "
     501                            "buffer. This event may not be reported\n");
     502                        memset(hid_dev->input_report, 0,
     503                            hid_dev->input_report_size);
     504                } else {
     505                        memcpy(input_new, input_old,
     506                            hid_dev->input_report_size);
     507                        hid_dev->input_report = input_new;
     508                        if (allocated) {
     509                                free(input_old);
     510                        }
     511                }
     512        }
     513       
     514        /*! @todo This should probably be atomic. */
     515        memcpy(hid_dev->input_report, buffer, buffer_size);
     516        hid_dev->input_report_size = buffer_size;
     517       
    492518        bool cont = false;
    493519       
     
    528554/*----------------------------------------------------------------------------*/
    529555
    530 const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev)
    531 {
    532         switch (hid_dev->poll_pipe_index) {
    533         case USB_HID_KBD_POLL_EP_NO:
    534                 return HID_KBD_FUN_NAME;
    535                 break;
    536         case USB_HID_MOUSE_POLL_EP_NO:
    537                 return HID_MOUSE_FUN_NAME;
    538                 break;
    539         default:
    540                 return HID_GENERIC_FUN_NAME;
    541         }
    542 }
    543 
    544 /*----------------------------------------------------------------------------*/
    545 
    546 const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev)
    547 {
    548         // this means that only boot protocol keyboards will be connected
    549         // to the console; there is probably no better way to do this
    550        
    551         switch (hid_dev->poll_pipe_index) {
    552         case USB_HID_KBD_POLL_EP_NO:
    553                 return HID_KBD_CLASS_NAME;
    554                 break;
    555         case USB_HID_MOUSE_POLL_EP_NO:
    556                 return HID_MOUSE_CLASS_NAME;
    557                 break;
    558         default:
    559                 return HID_GENERIC_CLASS_NAME;
    560         }
    561 }
     556//const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev)
     557//{
     558//      switch (hid_dev->poll_pipe_index) {
     559//      case USB_HID_KBD_POLL_EP_NO:
     560//              return HID_KBD_FUN_NAME;
     561//              break;
     562//      case USB_HID_MOUSE_POLL_EP_NO:
     563//              return HID_MOUSE_FUN_NAME;
     564//              break;
     565//      default:
     566//              return HID_GENERIC_FUN_NAME;
     567//      }
     568//}
     569
     570/*----------------------------------------------------------------------------*/
     571
     572//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev)
     573//{
     574//      // this means that only boot protocol keyboards will be connected
     575//      // to the console; there is probably no better way to do this
     576       
     577//      switch (hid_dev->poll_pipe_index) {
     578//      case USB_HID_KBD_POLL_EP_NO:
     579//              return HID_KBD_CLASS_NAME;
     580//              break;
     581//      case USB_HID_MOUSE_POLL_EP_NO:
     582//              return HID_MOUSE_CLASS_NAME;
     583//              break;
     584//      default:
     585//              return HID_GENERIC_CLASS_NAME;
     586//      }
     587//}
    562588
    563589/*----------------------------------------------------------------------------*/
  • uspace/drv/usbhid/usbhid.h

    r30710035 r31cfee16  
    9393        usb_hid_report_t *report;
    9494       
     95        uint8_t *input_report;
     96       
     97        size_t input_report_size;
     98       
    9599        /** Arbitrary data (e.g. a special structure for handling keyboard). */
    96100        void *data;
     
    120124     void *arg);
    121125
    122 const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev);
     126//const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev);
    123127
    124 const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
     128//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
    125129
    126130void usb_hid_free(usb_hid_dev_t **hid_dev);
Note: See TracChangeset for help on using the changeset viewer.