Changes in / [70c85211:4570779] in mainline


Ignore:
Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/Makefile

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

    r70c85211 r4570779  
    2828#include <usb/usbdrv.h>
    2929#include <driver.h>
    30 #include <ipc/driver.h>
    3130#include <errno.h>
    32 #include <fibril.h>
    33 #include <usb/classes/hid.h>
    3431
    3532#define BUFFER_SIZE 32
    36 #define NAME "usbkbd"
    37 
    38 static const usb_endpoint_t CONTROL_EP = 0;
    39 
    40 static 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 }
    7033
    7134/* Call this periodically to check keyboard status changes. */
    72 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
     35static void poll_keyboard(device_t *dev)
    7336{
    7437        int rc;
     
    7639        char buffer[BUFFER_SIZE];
    7740        size_t actual_size;
    78         //usb_endpoint_t poll_endpoint = 1;
     41        usb_endpoint_t poll_endpoint = 1;
    7942
    80 //      usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
    81 //          dev);
    82 //      if (my_address < 0) {
    83 //              return;
    84 //      }
     43        usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
     44            dev);
     45        if (my_address < 0) {
     46                return;
     47        }
    8548
    8649        usb_target_t poll_target = {
    87                 .address = kbd_dev->address,
    88                 .endpoint = kbd_dev->default_ep
     50                .address = my_address,
     51                .endpoint = poll_endpoint
    8952        };
    9053
    91         rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    92             poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
    93 
     54        rc = usb_drv_async_interrupt_in(dev->parent_phone, poll_target,
     55            buffer, BUFFER_SIZE, &actual_size, &handle);
    9456        if (rc != EOK) {
    9557                return;
     
    11072
    11173        /*
    112          * TODO: Process pressed keys.
     74         * Process pressed keys.
    11375         */
    11476}
    11577
    116 static 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 
    135 static int usbkbd_add_device(device_t *dev)
     78static int add_kbd_device(device_t *dev)
    13679{
    13780        /* For now, fail immediately. */
     
    14083        /*
    14184         * When everything is okay, connect to "our" HC.
    142          *
    143          * Not supported yet, skip..
    14485         */
    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 //      }
     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        }
    15394
    154 //      dev->parent_phone = phone;
     95        dev->parent_phone = phone;
    15596
    15697        /*
    157          * Create new fibril for handling this keyboard
     98         * Just for fun ;-).
    15899         */
    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);
     100        poll_keyboard(dev);
    165101
    166102        /*
     
    171107
    172108static driver_ops_t kbd_driver_ops = {
    173         .add_device = usbkbd_add_device,
     109        .add_device = add_kbd_device,
    174110};
    175111
    176112static driver_t kbd_driver = {
    177         .name = NAME,
     113        .name = "usbkbd",
    178114        .driver_ops = &kbd_driver_ops
    179115};
  • uspace/lib/usb/include/usb/classes/hid.h

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