Ignore:
File:
1 edited

Legend:

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

    r48d2765 rd477734  
    196196        unsigned mod_mask;
    197197
    198         /*
    199          * These parts are copy-pasted from the AT keyboard driver.
    200          *
    201          * They definitely require some refactoring, but will keep it for later
    202          * when the console and keyboard system is changed in HelenOS.
    203          */
     198        // TODO: replace by our own parsing?? or are the key codes identical??
    204199        switch (key) {
    205200        case KC_LCTRL: mod_mask = KM_LCTRL; break;
     
    333328        i = 0;
    334329        // all fields should report Error Rollover
    335         while (i < kbd_dev->key_count &&
     330        while (i < kbd_dev->keycode_count &&
    336331            key_codes[i] == BOOTP_ERROR_ROLLOVER) {
    337332                ++i;
    338333        }
    339         if (i == kbd_dev->key_count) {
     334        if (i == kbd_dev->keycode_count) {
    340335                usb_log_debug("Phantom state occured.\n");
    341336                // phantom state, do nothing
     
    348343         * 1) Key releases
    349344         */
    350         for (j = 0; j < kbd_dev->key_count; ++j) {
     345        for (j = 0; j < kbd_dev->keycode_count; ++j) {
    351346                // try to find the old key in the new key list
    352347                i = 0;
    353                 while (i < kbd_dev->key_count
    354                     && key_codes[i] != kbd_dev->keys[j]) {
     348                while (i < kbd_dev->keycode_count
     349                    && key_codes[i] != kbd_dev->keycodes[j]) {
    355350                        ++i;
    356351                }
    357352               
    358                 if (i == kbd_dev->key_count) {
     353                if (i == kbd_dev->keycode_count) {
    359354                        // not found, i.e. the key was released
    360                         key = usbhid_parse_scancode(kbd_dev->keys[j]);
     355                        key = usbhid_parse_scancode(kbd_dev->keycodes[j]);
    361356                        usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key);
    362357                        usb_log_debug2("Key released: %d\n", key);
     
    369364         * 1) Key presses
    370365         */
    371         for (i = 0; i < kbd_dev->key_count; ++i) {
     366        for (i = 0; i < kbd_dev->keycode_count; ++i) {
    372367                // try to find the new key in the old key list
    373368                j = 0;
    374                 while (j < kbd_dev->key_count
    375                     && kbd_dev->keys[j] != key_codes[i]) {
     369                while (j < kbd_dev->keycode_count
     370                    && kbd_dev->keycodes[j] != key_codes[i]) {
    376371                        ++j;
    377372                }
    378373               
    379                 if (j == kbd_dev->key_count) {
     374                if (j == kbd_dev->keycode_count) {
    380375                        // not found, i.e. new key pressed
    381376                        key = usbhid_parse_scancode(key_codes[i]);
     
    397392//      }
    398393       
    399         memcpy(kbd_dev->keys, key_codes, kbd_dev->key_count);
     394        memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count);
    400395
    401396        usb_log_debug("New stored keycodes: %s\n",
    402             usb_debug_str_buffer(kbd_dev->keys, kbd_dev->key_count, 0));
     397            usb_debug_str_buffer(kbd_dev->keycodes, kbd_dev->keycode_count, 0));
    403398}
    404399
     
    420415
    421416        usb_log_debug("Got keys from parser: %s\n",
    422             usb_debug_str_buffer(key_codes, kbd_dev->key_count, 0));
    423        
    424         if (count != kbd_dev->key_count) {
     417            usb_debug_str_buffer(key_codes, kbd_dev->keycode_count, 0));
     418       
     419        if (count != kbd_dev->keycode_count) {
    425420                usb_log_warning("Number of received keycodes (%d) differs from"
    426                     " expected number (%d).\n", count, kbd_dev->key_count);
     421                    " expected number (%d).\n", count, kbd_dev->keycode_count);
    427422                return;
    428423        }
     
    435430/* General kbd functions                                                      */
    436431/*----------------------------------------------------------------------------*/
    437 /**
    438  * Processes data received from the device in form of report.
    439  *
    440  * This function uses the HID report parser to translate the data received from
    441  * the device into generic USB HID key codes and into generic modifiers bitmap.
    442  * The parser then calls the given callback (usbhid_kbd_process_keycodes()).
    443  *
    444  * @note Currently, only the boot protocol is supported.
    445  *
    446  * @param kbd_dev Keyboard device structure (must be initialized).
    447  * @param buffer Data from the keyboard (i.e. the report).
    448  * @param actual_size Size of the data from keyboard (report size) in bytes.
    449  *
    450  * @sa usbhid_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report().
    451  */
     432
    452433static void usbhid_kbd_process_data(usbhid_kbd_t *kbd_dev,
    453434                                    uint8_t *buffer, size_t actual_size)
     
    474455/* HID/KBD structure manipulation                                             */
    475456/*----------------------------------------------------------------------------*/
    476 /**
    477  * Creates a new USB/HID keyboard structure.
    478  *
    479  * The structure returned by this function is not initialized. Use
    480  * usbhid_kbd_init() to initialize it prior to polling.
    481  *
    482  * @return New uninitialized structure for representing a USB/HID keyboard or
    483  *         NULL if not successful (memory error).
    484  */
     457
    485458static usbhid_kbd_t *usbhid_kbd_new(void)
    486459{
     
    508481
    509482/*----------------------------------------------------------------------------*/
    510 /**
    511  * Properly destroys the USB/HID keyboard structure.
    512  *
    513  * @param kbd_dev Pointer to the structure to be destroyed.
    514  */
     483
    515484static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
    516485{
     
    532501
    533502/*----------------------------------------------------------------------------*/
    534 /**
    535  * Initialization of the USB/HID keyboard structure.
    536  *
    537  * This functions initializes required structures from the device's descriptors.
    538  *
    539  * During initialization, the keyboard is switched into boot protocol, the idle
    540  * rate is set to 0 (infinity), resulting in the keyboard only reporting event
    541  * when a key is pressed or released. Finally, the LED lights are turned on
    542  * according to the default setup of lock keys.
    543  *
    544  * @note By default, the keyboards is initialized with Num Lock turned on and
    545  *       other locks turned off.
    546  *
    547  * @param kbd_dev Keyboard device structure to be initialized.
    548  * @param dev DDF device structure of the keyboard.
    549  *
    550  * @retval EOK if successful.
    551  * @retval EINVAL if some parameter is not given.
    552  * @return Other value inherited from function usbhid_dev_init().
    553  */
     503
    554504static int usbhid_kbd_init(usbhid_kbd_t *kbd_dev, ddf_dev_t *dev)
    555505{
     
    586536       
    587537        // save the size of the report (boot protocol report by default)
    588         kbd_dev->key_count = BOOTP_REPORT_SIZE;
    589         kbd_dev->keys = (uint8_t *)calloc(
    590             kbd_dev->key_count, sizeof(uint8_t));
    591        
    592         if (kbd_dev->keys == NULL) {
     538        kbd_dev->keycode_count = BOOTP_REPORT_SIZE;
     539        kbd_dev->keycodes = (uint8_t *)calloc(
     540            kbd_dev->keycode_count, sizeof(uint8_t));
     541       
     542        if (kbd_dev->keycodes == NULL) {
    593543                usb_log_fatal("No memory!\n");
    594                 return ENOMEM;
     544                return rc;
    595545        }
    596546       
     
    621571/* HID/KBD polling                                                            */
    622572/*----------------------------------------------------------------------------*/
    623 /**
    624  * Main keyboard polling function.
    625  *
    626  * This function uses the Interrupt In pipe of the keyboard to poll for events.
    627  * The keyboard is initialized in a way that it reports only when a key is
    628  * pressed or released, so there is no actual need for any sleeping between
    629  * polls (see usbhid_kbd_try_add_device() or usbhid_kbd_init()).
    630  *
    631  * @param kbd_dev Initialized keyboard structure representing the device to
    632  *                poll.
    633  *
    634  * @sa usbhid_kbd_process_data()
    635  */
     573
    636574static void usbhid_kbd_poll(usbhid_kbd_t *kbd_dev)
    637575{
     
    701639
    702640/*----------------------------------------------------------------------------*/
    703 /**
    704  * Function executed by the main driver fibril.
    705  *
    706  * Just starts polling the keyboard for events.
    707  *
    708  * @param arg Initialized keyboard device structure (of type usbhid_kbd_t)
    709  *            representing the device.
    710  *
    711  * @retval EOK if the fibril finished polling the device.
    712  * @retval EINVAL if no device was given in the argument.
    713  *
    714  * @sa usbhid_kbd_poll()
    715  *
    716  * @todo Change return value - only case when the fibril finishes is in case
    717  *       of some error, so the error should probably be propagated from function
    718  *       usbhid_kbd_poll() to here and up.
    719  */
     641
    720642static int usbhid_kbd_fibril(void *arg)
    721643{
     
    739661/* API functions                                                              */
    740662/*----------------------------------------------------------------------------*/
    741 /**
    742  * Function for adding a new device of type USB/HID/keyboard.
    743  *
    744  * This functions initializes required structures from the device's descriptors
    745  * and starts a new fibril for polling the keyboard for events.
    746  *
    747  * During initialization, the keyboard is switched into boot protocol, the idle
    748  * rate is set to 0 (infinity), resulting in the keyboard only reporting event
    749  * when a key is pressed or released. Finally, the LED lights are turned on
    750  * according to the default setup of lock keys.
    751  *
    752  * @note By default, the keyboards is initialized with Num Lock turned on and
    753  *       other locks turned off.
    754  * @note Currently supports only boot-protocol keyboards.
    755  *
    756  * @param dev Device to add.
    757  *
    758  * @retval EOK if successful.
    759  * @retval ENOMEM if there
    760  * @return Other error code inherited from one of functions usbhid_kbd_init(),
    761  *         ddf_fun_bind() and ddf_fun_add_to_class().
    762  *
    763  * @sa usbhid_kbd_fibril()
    764  */
     663
    765664int usbhid_kbd_try_add_device(ddf_dev_t *dev)
    766665{
     
    784683                    "structure.\n");
    785684                ddf_fun_destroy(kbd_fun);
    786                 return ENOMEM;  // TODO: some other code??
     685                return EINVAL;  // TODO: some other code??
    787686        }
    788687       
Note: See TracChangeset for help on using the changeset viewer.