Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbkbd/main.c

    r6336b6e rfbddf94  
    3838#include <usb/devreq.h>
    3939#include <usb/descriptor.h>
    40 #include <io/console.h>
    4140#include "descparser.h"
    4241#include "descdump.h"
    43 #include "conv.h"
    4442
    4543#define BUFFER_SIZE 32
     
    9088
    9189/*
    92  * TODO: Move somewhere else
    93  */
    94 /*
    95 #define BYTES_PER_LINE 12
    96 
    97 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
    98 {
    99         printf("%s\n", msg);
    100        
    101         size_t i;
    102         for (i = 0; i < length; i++) {
    103                 printf("  0x%02X", buffer[i]);
    104                 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
    105                     || (i + 1 == length)) {
    106                         printf("\n");
    107                 }
    108         }
    109 }
    110 */
    111 /*
    112  * Copy-paste from srv/hid/kbd/generic/kbd.c
    113  */
    114 
    115 /** Currently active modifiers.
    116  *
    117  * TODO: put to device?
    118  */
    119 static unsigned mods = KM_NUM_LOCK;
    120 
    121 /** Currently pressed lock keys. We track these to tackle autorepeat. 
    122  *
    123  * TODO: put to device?
    124  */
    125 static unsigned lock_keys;
    126 
    127 // TODO: put to device?
    128 //static int active_layout = 0;
    129 
    130 static void kbd_push_ev(int type, unsigned int key)
    131 {
    132         console_event_t ev;
    133         unsigned mod_mask;
    134 
    135         // TODO: replace by our own parsing?? or are the key codes identical??
    136         switch (key) {
    137         case KC_LCTRL: mod_mask = KM_LCTRL; break;
    138         case KC_RCTRL: mod_mask = KM_RCTRL; break;
    139         case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
    140         case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
    141         case KC_LALT: mod_mask = KM_LALT; break;
    142         case KC_RALT: mod_mask = KM_RALT; break;
    143         default: mod_mask = 0; break;
    144         }
    145 
    146         if (mod_mask != 0) {
    147                 if (type == KEY_PRESS)
    148                         mods = mods | mod_mask;
    149                 else
    150                         mods = mods & ~mod_mask;
    151         }
    152 
    153         switch (key) {
    154         case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
    155         case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
    156         case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
    157         default: mod_mask = 0; break;
    158         }
    159 
    160         if (mod_mask != 0) {
    161                 if (type == KEY_PRESS) {
    162                         /*
    163                          * Only change lock state on transition from released
    164                          * to pressed. This prevents autorepeat from messing
    165                          * up the lock state.
    166                          */
    167                         mods = mods ^ (mod_mask & ~lock_keys);
    168                         lock_keys = lock_keys | mod_mask;
    169 
    170                         /* Update keyboard lock indicator lights. */
    171                         // TODO
    172                         //kbd_ctl_set_ind(mods);
    173                 } else {
    174                         lock_keys = lock_keys & ~mod_mask;
    175                 }
    176         }
    177 /*
    178         printf("type: %d\n", type);
    179         printf("mods: 0x%x\n", mods);
    180         printf("keycode: %u\n", key);
    181 */
    182         /*
    183         if (type == KEY_PRESS && (mods & KM_LCTRL) &&
    184                 key == KC_F1) {
    185                 active_layout = 0;
    186                 layout[active_layout]->reset();
    187                 return;
    188         }
    189 
    190         if (type == KEY_PRESS && (mods & KM_LCTRL) &&
    191                 key == KC_F2) {
    192                 active_layout = 1;
    193                 layout[active_layout]->reset();
    194                 return;
    195         }
    196 
    197         if (type == KEY_PRESS && (mods & KM_LCTRL) &&
    198                 key == KC_F3) {
    199                 active_layout = 2;
    200                 layout[active_layout]->reset();
    201                 return;
    202         }
    203         */
    204         ev.type = type;
    205         ev.key = key;
    206         ev.mods = mods;
    207 
    208         //ev.c = layout[active_layout]->parse_ev(&ev);
    209 
    210         printf("Sending key %d to the console\n", ev.key);
    211         assert(console_callback_phone != -1);
    212         async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, 0);
    213 }
    214 /*
    215  * End of copy-paste
    216  */
    217 
    218         /*
    219          * TODO:
    220          * 1) key press / key release - how does the keyboard notify about release?
    221          * 2) layouts (use the already defined), not important now
    222          * 3)
    223          */
    224 
    225 /*
    22690 * Callbacks for parser
    22791 */
     
    23397        for (i = 0; i < count; ++i) {
    23498                printf("%d ", key_codes[i]);
    235                 // TODO: Key press / release
    236 
    237                 // TODO: NOT WORKING
    238                 unsigned int key = usbkbd_parse_scancode(key_codes[i]);
    239                 kbd_push_ev(KEY_PRESS, key);
    24099        }
    241100        printf("\n");
     
    405264        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    406265        //    NULL);
    407 //      printf("Calling usb_hid_boot_keyboard_input_report() with size %d\n",
    408 //          actual_size);
    409 //      dump_buffer("bufffer: ", buffer, actual_size);
    410         int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks,
    411             NULL);
    412         if (rc != EOK) {
    413                 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc);
    414         }
     266        printf("Calling usb_hid_boot_keyboard_input_report()...\n)");
     267        usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL);
    415268}
    416269
    417270static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    418271{
     272        return;
     273       
    419274        int rc;
    420275        usb_handle_t handle;
     
    434289        };
    435290
    436         printf("Polling keyboard...\n");
    437 
    438291        while (true) {
    439                 async_usleep(1000 * 1000 * 2);
     292                async_usleep(1000 * 1000);
    440293                rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    441294                    poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
    442295
    443296                if (rc != EOK) {
    444                         printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
    445297                        continue;
    446298                }
     
    448300                rc = usb_drv_async_wait_for(handle);
    449301                if (rc != EOK) {
    450                         printf("Error in usb_drv_async_wait_for(): %d\n", rc);
    451302                        continue;
    452303                }
     
    457308                 */
    458309                if (actual_size == 0) {
    459                         printf("Keyboar returned NAK\n");
    460310                        continue;
    461311                }
     
    464314                 * TODO: Process pressed keys.
    465315                 */
    466                 printf("Calling usbkbd_process_interrupt_in()\n");
    467                 // actual_size is not set, workaround...
    468                 usbkbd_process_interrupt_in(kbd_dev, buffer, /*actual_size*/8);
     316                usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
    469317        }
    470318
     
    486334        // initialize device (get and process descriptors, get address, etc.)
    487335        usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
    488         if (kbd_dev == NULL) {
    489                 printf("Error while initializing device.\n");
    490                 return -1;
    491         }
    492336
    493337        usbkbd_poll_keyboard(kbd_dev);
Note: See TracChangeset for help on using the changeset viewer.