Changeset d972534 in mainline


Ignore:
Timestamp:
2011-02-24T23:32:04Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54e682f
Parents:
f2ba5d9f
Message:

LED setting

  • LEDs are determined from remembered modifiers (not good, as that doesn't work well).
  • Added function for sending a Set_Report(Output) request (specific, have to make it generic later).
  • Added a lot of debug output.
  • Added HID Report Type constants to libusb (hid.h).
  • Added constants for LEDs (hidparser.h).
  • Modified function for composing output reports in hidparser.
Location:
uspace
Files:
5 edited

Legend:

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

    rf2ba5d9f rd972534  
    3636#include <io/keycode.h>
    3737#include <stdint.h>
     38#include <stdio.h>
     39#include <usb/debug.h>
    3840#include "conv.h"
    3941
     
    207209
    208210        key = map[scancode];
     211       
     212        if (scancode == 0x53) {
     213                usb_log_debug("\n\nWe have a NUM LOCK!, sending key %u\n\n", key);
     214        }
     215       
     216        if (scancode == 0x47) {
     217                usb_log_debug("\n\nWe have a SCROLL LOCK!, sending key %u\n\n", key);
     218        }
     219       
     220        if (scancode == 0x39) {
     221                usb_log_debug("\n\nWe have a CAPS LOCK!, sending key %u\n\n", key);
     222        }
     223       
    209224//      if (key != 0)
    210225//              kbd_push_ev(type, key);
  • uspace/drv/usbhid/main.c

    rf2ba5d9f rd972534  
    5959
    6060#define BUFFER_SIZE 8
     61#define BUFFER_OUT_SIZE 1
    6162#define NAME "usbhid"
    6263
     
    122123
    123124static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
    124 {
     125{uint8_t buffer[BUFFER_SIZE];
    125126        printf("%s\n", msg);
    126127       
     
    161162static int active_layout = 0;
    162163
    163 static void kbd_push_ev(int type, unsigned int key)
     164static void usbkbd_req_set_report(usb_hid_dev_kbd_t *kbd_dev, uint8_t *buffer,
     165    size_t buf_size)
     166{
     167        int rc, sess_rc;
     168       
     169        sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
     170        if (sess_rc != EOK) {
     171                usb_log_warning("Failed to start a session: %s.\n",
     172                    str_error(sess_rc));
     173                return;
     174        }
     175
     176        usb_log_debug("Sending Set_Report request to the device.\n");
     177        // TODO: determine what interface to use!! (now set to 1)
     178        rc = usb_control_request_set(&kbd_dev->ctrl_pipe,
     179            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
     180            USB_HIDREQ_SET_REPORT, USB_HID_REPORT_TYPE_OUTPUT,
     181            1, buffer, buf_size);
     182
     183        sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
     184
     185        if (rc != EOK) {
     186                usb_log_warning("Error sending output report to the keyboard: "
     187                    "%s.\n", str_error(rc));
     188                return;
     189        }
     190
     191        if (sess_rc != EOK) {
     192                usb_log_warning("Error closing session: %s.\n",
     193                    str_error(sess_rc));
     194                return;
     195        }
     196}
     197
     198static void usbkbd_set_led(unsigned mods, usb_hid_dev_kbd_t *kbd_dev)
     199{
     200        uint8_t buffer[BUFFER_SIZE];
     201        int rc= 0;
     202       
     203        uint8_t leds = 0;
     204
     205        if (mods & KM_NUM_LOCK) {
     206                leds |= USB_HID_LED_NUM_LOCK;
     207        }
     208       
     209        if (mods & KM_CAPS_LOCK) {
     210                leds |= USB_HID_LED_CAPS_LOCK;
     211        }
     212       
     213        if (mods & KM_SCROLL_LOCK) {
     214                leds |= USB_HID_LED_SCROLL_LOCK;
     215        }
     216
     217        // TODO: COMPOSE and KANA
     218       
     219        usb_log_debug("Creating output report.\n");
     220        if ((rc = usb_hid_boot_keyboard_output_report(
     221            leds, buffer, BUFFER_SIZE)) != EOK) {
     222                usb_log_warning("Error composing output report to the keyboard:"
     223                    "%s.\n", str_error(rc));
     224                return;
     225        }
     226       
     227        usbkbd_req_set_report(kbd_dev, buffer, BUFFER_SIZE);
     228}
     229
     230static void kbd_push_ev(int type, unsigned int key, usb_hid_dev_kbd_t *kbd_dev)
    164231{
    165232        console_event_t ev;
     
    185252
    186253        switch (key) {
    187         case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
    188         case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
    189         case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
     254        case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; usb_log_debug("\n\nPushing CAPS LOCK! (mask: %u)\n\n", mod_mask); break;
     255        case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; usb_log_debug("\n\nPushing NUM LOCK! (mask: %u)\n\n", mod_mask); break;
     256        case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; usb_log_debug("\n\nPushing SCROLL LOCK! (mask: %u)\n\n", mod_mask); break;
    190257        default: mod_mask = 0; break;
    191258        }
    192259
    193260        if (mod_mask != 0) {
     261                usb_log_debug("\n\nChanging mods and lock keys\n\n");
     262                usb_log_debug("\n\nmods before: 0x%x\n\n", mods);
     263                usb_log_debug("\n\nLock keys before:0x%x\n\n", lock_keys);
     264               
    194265                if (type == KEY_PRESS) {
    195266                        /*
     
    202273
    203274                        /* Update keyboard lock indicator lights. */
    204                         // TODO
    205                         //kbd_ctl_set_ind(mods);
     275                        usbkbd_set_led(mods, kbd_dev);
    206276                } else {
    207277                        lock_keys = lock_keys & ~mod_mask;
     
    213283        usb_log_debug2("keycode: %u\n", key);
    214284*/
     285        usb_log_debug("\n\nmods after: 0x%x\n\n", mods);
     286        usb_log_debug("\n\nLock keys after: 0x%x\n\n", lock_keys);
    215287       
    216288        if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     
    238310        ev.key = key;
    239311        ev.mods = mods;
     312       
     313        if (ev.mods & KM_NUM_LOCK) {
     314                usb_log_debug("\n\nNum Lock turned on.\n\n");
     315        }
    240316
    241317        ev.c = layout[active_layout]->parse_ev(&ev);
     
    288364                        if (usb_hid_modifiers_keycodes[i] != 0) {
    289365                                kbd_push_ev(KEY_PRESS,
    290                                     usb_hid_modifiers_keycodes[i]);
     366                                    usb_hid_modifiers_keycodes[i], kbd_dev);
    291367                        }
    292368                } else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
     
    295371                        if (usb_hid_modifiers_keycodes[i] != 0) {
    296372                                kbd_push_ev(KEY_RELEASE,
    297                                     usb_hid_modifiers_keycodes[i]);
     373                                    usb_hid_modifiers_keycodes[i], kbd_dev);
    298374                        }
    299375                }       // no change
     
    323399                        // not found, i.e. the key was released
    324400                        key = usbkbd_parse_scancode(kbd_dev->keycodes[j]);
    325                         kbd_push_ev(KEY_RELEASE, key);
     401                        kbd_push_ev(KEY_RELEASE, key, kbd_dev);
    326402                } else {
    327403                        // found, nothing happens
     
    343419                        // not found, i.e. new key pressed
    344420                        key = usbkbd_parse_scancode(key_codes[i]);
    345                         kbd_push_ev(KEY_PRESS, key);
     421                        kbd_push_ev(KEY_PRESS, key, kbd_dev);
    346422                } else {
    347423                        // found, nothing happens
     
    621697
    622698        while (true) {
    623                 async_usleep(1000 * 10);
     699                async_usleep(1000 * 1000);
    624700
    625701                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
  • uspace/lib/usb/include/usb/classes/hid.h

    rf2ba5d9f rd972534  
    5050        USB_HIDREQ_SET_PROTOCOL = 11
    5151} usb_hid_request_t;
     52
     53typedef enum {
     54        USB_HID_REPORT_TYPE_INPUT = 1,
     55        USB_HID_REPORT_TYPE_OUTPUT = 2,
     56        USB_HID_REPORT_TYPE_FEATURE = 3
     57} usb_hid_report_type_t;
    5258
    5359/** USB/HID subclass constants. */
  • uspace/lib/usb/include/usb/classes/hidparser.h

    rf2ba5d9f rd972534  
    8383} usb_hid_modifiers_t;
    8484
     85typedef enum {
     86        USB_HID_LED_NUM_LOCK = 0x1,
     87        USB_HID_LED_CAPS_LOCK = 0x2,
     88        USB_HID_LED_SCROLL_LOCK = 0x4,
     89        USB_HID_LED_COMPOSE = 0x8,
     90        USB_HID_LED_KANA = 0x10,
     91        USB_HID_LED_COUNT = 5
     92} usb_hid_led_t;
     93
    8594static const usb_hid_modifiers_t
    8695    usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
     
    94103        USB_HID_MOD_RGUI
    95104};
     105
     106//static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = {
     107//      USB_HID_LED_NUM_LOCK,
     108//      USB_HID_LED_CAPS_LOCK,
     109//      USB_HID_LED_SCROLL_LOCK,
     110//      USB_HID_LED_COMPOSE,
     111//      USB_HID_LED_KANA
     112//};
    96113
    97114//#define USB_HID_BOOT_KEYBOARD_NUM_LOCK                0x01
  • uspace/lib/usb/src/hidparser.c

    rf2ba5d9f rd972534  
    144144int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size)
    145145{
    146         if(size != 1){
     146        if(size < 2){
    147147                return -1;
    148148        }
    149149
    150         /* used only first five bits, others are only padding*/
    151         *data = leds;
     150        data[1] = leds;
    152151        return EOK;
    153152}
Note: See TracChangeset for help on using the changeset viewer.