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

Changeset 2e15ac40 in mainline


Ignore:
Timestamp:
2010-11-26T15:25:52Z (11 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master
Children:
bbc28be
Parents:
03171de
Message:

Outlined some basic keyboard handling functions.

USB kbd driver now starts one fibril for each added device.
Initialization of kbd device outlined.
Added type usb_hid_dev_kbd_t.

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/Makefile

    r03171de r2e15ac40  
    3333
    3434LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a
    35 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIB_PREFIX)
     35EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIB_PREFIX) -I$(LIBDRV_PREFIX)/include
    3636
    3737SOURCES = \
  • uspace/drv/usbkbd/main.c

    r03171de r2e15ac40  
    2828#include <usb/usbdrv.h>
    2929#include <driver.h>
     30#include <ipc/driver.h>
    3031#include <errno.h>
     32#include <fibril.h>
     33#include <usb/classes/hid.h>
    3134
    3235#define BUFFER_SIZE 32
     36#define NAME "usbkbd"
     37
     38static const usb_endpoint_t CONTROL_EP = 0;
     39
     40static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
     41{
     42        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
     43                        sizeof(usb_hid_dev_kbd_t));
     44
     45        if (kbd_dev == NULL) {
     46                fprintf(stderr, NAME ": No memory!\n");
     47                return NULL;
     48        }
     49
     50        kbd_dev->device = dev;
     51
     52        kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
     53            dev);
     54
     55        if (kbd_dev->address < 0) {
     56                fprintf(stderr, NAME ": No device address!\n");
     57                free(kbd_dev);
     58                return NULL;
     59        }
     60
     61        // default endpoint
     62        kbd_dev->default_ep = CONTROL_EP;
     63
     64        // TODO: get descriptors
     65
     66        // TODO: parse descriptors and save endpoints
     67
     68        return kbd_dev;
     69}
    3370
    3471/* Call this periodically to check keyboard status changes. */
    35 static void poll_keyboard(device_t *dev)
     72static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    3673{
    3774        int rc;
     
    3976        char buffer[BUFFER_SIZE];
    4077        size_t actual_size;
    41         usb_endpoint_t poll_endpoint = 1;
     78        //usb_endpoint_t poll_endpoint = 1;
    4279
    43         usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
    44             dev);
    45         if (my_address < 0) {
    46                 return;
    47         }
     80//      usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
     81//          dev);
     82//      if (my_address < 0) {
     83//              return;
     84//      }
    4885
    4986        usb_target_t poll_target = {
    50                 .address = my_address,
    51                 .endpoint = poll_endpoint
     87                .address = kbd_dev->address,
     88                .endpoint = kbd_dev->default_ep
    5289        };
    5390
    54         rc = usb_drv_async_interrupt_in(dev->parent_phone, poll_target,
    55             buffer, BUFFER_SIZE, &actual_size, &handle);
     91        rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
     92            poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
     93
    5694        if (rc != EOK) {
    5795                return;
     
    72110
    73111        /*
    74          * Process pressed keys.
     112         * TODO: Process pressed keys.
    75113         */
    76114}
    77115
    78 static int add_kbd_device(device_t *dev)
     116static int usbkbd_fibril_device(void *arg)
     117{
     118        printf("!!! USB device fibril\n");
     119
     120        if (arg == NULL) {
     121                printf("No device!\n");
     122                return -1;
     123        }
     124
     125        device_t *dev = (device_t *)arg;
     126
     127        // initialize device (get and process descriptors, get address, etc.)
     128        usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
     129
     130        usbkbd_poll_keyboard(kbd_dev);
     131
     132        return EOK;
     133}
     134
     135static int usbkbd_add_device(device_t *dev)
    79136{
    80137        /* For now, fail immediately. */
     
    83140        /*
    84141         * When everything is okay, connect to "our" HC.
     142         *
     143         * Not supported yet, skip..
    85144         */
    86         int phone = usb_drv_hc_connect(dev, 0);
    87         if (phone < 0) {
    88                 /*
    89                  * Connecting to HC failed, roll-back and announce
    90                  * failure.
    91                  */
    92                 return phone;
    93         }
     145//      int phone = usb_drv_hc_connect(dev, 0);
     146//      if (phone < 0) {
     147//              /*
     148//               * Connecting to HC failed, roll-back and announce
     149//               * failure.
     150//               */
     151//              return phone;
     152//      }
    94153
    95         dev->parent_phone = phone;
     154//      dev->parent_phone = phone;
    96155
    97156        /*
    98          * Just for fun ;-).
     157         * Create new fibril for handling this keyboard
    99158         */
    100         poll_keyboard(dev);
     159        fid_t fid = fibril_create(usbkbd_fibril_device, dev);
     160        if (fid == 0) {
     161                printf("%s: failed to start fibril for HID device\n", NAME);
     162                return ENOMEM;
     163        }
     164        fibril_add_ready(fid);
    101165
    102166        /*
     
    107171
    108172static driver_ops_t kbd_driver_ops = {
    109         .add_device = add_kbd_device,
     173        .add_device = usbkbd_add_device,
    110174};
    111175
    112176static driver_t kbd_driver = {
    113         .name = "usbkbd",
     177        .name = NAME,
    114178        .driver_ops = &kbd_driver_ops
    115179};
  • uspace/lib/usb/include/usb/classes/hid.h

    r03171de r2e15ac40  
    3636#define LIBUSB_HID_H_
    3737
     38#include <usb/usb.h>
     39#include <driver.h>
     40
    3841/** USB/HID device requests. */
    3942typedef enum {
     
    5457} usb_hid_protocol_t;
    5558
     59/**
     60 * @brief USB/HID keyboard device type.
     61 *
     62 * Quite dummy right now.
     63 */
     64typedef struct {
     65        device_t *device;
     66        usb_address_t address;
     67        usb_endpoint_t default_ep;
     68} usb_hid_dev_kbd_t;
     69
    5670#endif
    5771/**
Note: See TracChangeset for help on using the changeset viewer.