Changeset 1c6c4092 in mainline


Ignore:
Timestamp:
2011-03-01T16:39:31Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0f31e2b, 494eaf7
Parents:
27270db
Message:

Properly destroying HID and KBD device structures.

+ Do not send LOCK keys to console.

Location:
uspace/drv/usbhid
Files:
4 edited

Legend:

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

    r27270db r1c6c4092  
    270270/*----------------------------------------------------------------------------*/
    271271
     272void usbhid_dev_free(usbhid_dev_t **hid_dev)
     273{
     274        if (hid_dev == NULL || *hid_dev == NULL) {
     275                return;
     276        }
     277       
     278        // free the report descriptor
     279        if ((*hid_dev)->report_desc != NULL) {
     280                free((*hid_dev)->report_desc);
     281        }
     282        // destroy the parser
     283        if ((*hid_dev)->parser != NULL) {
     284                usb_hid_free_report_parser((*hid_dev)->parser);
     285        }
     286       
     287        // TODO: cleanup pipes
     288       
     289        free(*hid_dev);
     290        *hid_dev = NULL;
     291}
     292
     293/*----------------------------------------------------------------------------*/
     294
    272295int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev,
    273296    usb_endpoint_description_t *poll_ep_desc)
  • uspace/drv/usbhid/hiddev.h

    r27270db r1c6c4092  
    6969usbhid_dev_t *usbhid_dev_new(void);
    7070
     71void usbhid_dev_free(usbhid_dev_t **hid_dev);
     72
    7173int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev,
    7274    usb_endpoint_description_t *poll_ep_desc);
  • uspace/drv/usbhid/kbddev.c

    r27270db r1c6c4092  
    4141#include <io/keycode.h>
    4242#include <ipc/kbd.h>
     43#include <async.h>
    4344
    4445#include <usb/usb.h>
     
    253254        usb_log_debug2("\n\nmods after: 0x%x\n", kbd_dev->mods);
    254255        usb_log_debug2("\nLock keys after: 0x%x\n\n", kbd_dev->lock_keys);
     256       
     257        if (key = KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) {
     258                // do not send anything to the console, this is our business
     259                return;
     260        }
    255261       
    256262        if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F1) {
     
    453459/*----------------------------------------------------------------------------*/
    454460
    455 static usbhid_kbd_t *usbhid_kbd_new()
     461static usbhid_kbd_t *usbhid_kbd_new(void)
    456462{
    457463        usbhid_kbd_t *kbd_dev =
     
    475481       
    476482        return kbd_dev;
     483}
     484
     485/*----------------------------------------------------------------------------*/
     486
     487static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
     488{
     489        if (kbd_dev == NULL || *kbd_dev == NULL) {
     490                return;
     491        }
     492       
     493        // hangup phone to the console
     494        async_hangup((*kbd_dev)->console_phone);
     495       
     496        if ((*kbd_dev)->hid_dev != NULL) {
     497                usbhid_dev_free(&(*kbd_dev)->hid_dev);
     498                assert((*kbd_dev)->hid_dev == NULL);
     499        }
     500       
     501        free(*kbd_dev);
     502        *kbd_dev = NULL;
    477503}
    478504
     
    623649
    624650        usbhid_kbd_poll(kbd_dev);
     651       
     652        // at the end, properly destroy the KBD structure
     653        usbhid_kbd_free(&kbd_dev);
     654        assert(kbd_dev == NULL);
    625655
    626656        return EOK;
     
    645675         * Initialize device (get and process descriptors, get address, etc.)
    646676         */
    647         usb_log_info("Initializing USB HID/KBD device...\n");
     677        usb_log_info("Initializing USB/HID KBD device...\n");
    648678       
    649679        usbhid_kbd_t *kbd_dev = usbhid_kbd_new();
    650680        if (kbd_dev == NULL) {
    651                 usb_log_error("Error while creating USB HID/KBD device "
     681                usb_log_error("Error while creating USB/HID KBD device "
    652682                    "structure.\n");
    653683                ddf_fun_destroy(kbd_fun);
     
    658688       
    659689        if (rc != EOK) {
    660                 usb_log_error("Failed to initialize USB HID/KBD device.\n");
     690                usb_log_error("Failed to initialize USB/HID KBD device.\n");
    661691                ddf_fun_destroy(kbd_fun);
     692                usbhid_kbd_free(&kbd_dev);
    662693                return rc;
    663694        }       
    664695       
    665         usb_log_info("USB/KBD device structure initialized.\n");
     696        usb_log_info("USB/HID KBD device structure initialized.\n");
    666697       
    667698        /*
     
    675706        if (rc != EOK) {
    676707                usb_log_error("Could not bind DDF function.\n");
     708                // TODO: Can / should I destroy the DDF function?
     709                ddf_fun_destroy(kbd_fun);
     710                usbhid_kbd_free(&kbd_dev);
    677711                return rc;
    678712        }
     
    682716                usb_log_error("Could not add DDF function to class 'keyboard'"
    683717                    "\n");
     718                // TODO: Can / should I destroy the DDF function?
     719                ddf_fun_destroy(kbd_fun);
     720                usbhid_kbd_free(&kbd_dev);
    684721                return rc;
    685722        }
     
    690727        fid_t fid = fibril_create(usbhid_kbd_fibril, kbd_dev);
    691728        if (fid == 0) {
    692                 usb_log_error("Failed to start fibril for HID device\n");
     729                usb_log_error("Failed to start fibril for KBD device\n");
    693730                return ENOMEM;
    694731        }
  • uspace/drv/usbhid/main.c

    r27270db r1c6c4092  
    4040#include <errno.h>
    4141
    42 //#include <ipc/driver.h>
    43 //#include <ipc/kbd.h>
    44 //#include <io/keycode.h>
    45 //#include <io/console.h>
    46 //#include <str_error.h>
    47 
    48 //#include <usb/classes/classes.h>
    49 //#include <usb/classes/hid.h>
    50 //#include <usb/classes/hidparser.h>
    51 //#include <usb/request.h>
    52 //#include <usb/descriptor.h>
    53 //#include <io/console.h>
    54 //#include <stdint.h>
    55 //#include <usb/dp.h>
    56 
    5742#include "kbddev.h"
    5843
     
    6550static int usbhid_add_device(ddf_dev_t *dev)
    6651{
     52        usb_log_debug("usbhid_add_device()\n");
     53       
    6754        int rc = usbhid_kbd_try_add_device(dev);
    6855       
Note: See TracChangeset for help on using the changeset viewer.