Changes in / [243cb86:ebb98c5] in mainline


Ignore:
Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/Makefile

    r243cb86 rebb98c5  
    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

    r243cb86 rebb98c5  
    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>
    34 #include <usb/classes/hidparser.h>
    35 #include <usb/devreq.h>
    3631
    3732#define BUFFER_SIZE 32
    38 #define NAME "usbkbd"
    3933
    40 static const usb_endpoint_t CONTROL_EP = 0;
    41 
    42 /*
    43  * Callbacks for parser
    44  */
    45 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count,
    46                                     void *arg)
    47 {
    48 
    49 }
    50 
    51 /*
    52  * Kbd functions
    53  */
    54 static int usbkbd_get_descriptors()
    55 {
    56         // copy-pasted:
    57        
    58         /* Prepare the setup packet. */
    59         usb_device_request_setup_packet_t setup_packet = {
    60                 .request_type = 128,
    61                 .request = USB_DEVREQ_GET_DESCRIPTOR,
    62                 .index = 0,
    63                 .length = sizeof(usb_standard_device_descriptor_t)
    64         };
    65        
    66         setup_packet.value_high = USB_DESCTYPE_DEVICE;
    67         setup_packet.value_low = 0;
    68 
    69         /* Prepare local descriptor. */
    70         size_t actually_transferred = 0;
    71         usb_standard_device_descriptor_t descriptor_tmp;
    72 
    73         /* Perform the control read transaction. */
    74         int rc = usb_drv_psync_control_read(phone, target,
    75             &setup_packet, sizeof(setup_packet),
    76             &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred);
    77 
    78         if (rc != EOK) {
    79                 return rc;
    80         }
    81        
    82         // end of copy-paste
    83 }
    84 
    85 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    86 {
    87         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
    88                         sizeof(usb_hid_dev_kbd_t));
    89 
    90         if (kbd_dev == NULL) {
    91                 fprintf(stderr, NAME ": No memory!\n");
    92                 return NULL;
    93         }
    94 
    95         kbd_dev->device = dev;
    96 
    97         // get phone to my HC and save it as my parent's phone
    98         // TODO: maybe not a good idea if DDF will use parent_phone
    99         kbd_dev->device->parent_phone = usb_drv_hc_connect(dev, 0);
    100 
    101         kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
    102             dev);
    103 
    104         // doesn't matter now that we have no address
    105 //      if (kbd_dev->address < 0) {
    106 //              fprintf(stderr, NAME ": No device address!\n");
    107 //              free(kbd_dev);
    108 //              return NULL;
    109 //      }
    110 
    111         // default endpoint
    112         kbd_dev->default_ep = CONTROL_EP;
    113 
    114         // TODO: get descriptors
    115         usbkbd_get_descriptors();
    116         // TODO: parse descriptors and save endpoints
    117 
    118         return kbd_dev;
    119 }
    120 
    121 static void usbkbd_process_interrupt_in(usb_hid_dev_kbd_t *kbd_dev,
    122                                         uint8_t *buffer, size_t actual_size)
    123 {
    124         /*
    125          * here, the parser will be called, probably with some callbacks
    126          * now only take last 6 bytes and process, i.e. send to kbd
    127          */
    128 
    129         usb_hid_report_in_callbacks_t *callbacks =
    130             (usb_hid_report_in_callbacks_t *)malloc(
    131                 sizeof(usb_hid_report_in_callbacks_t));
    132         callbacks->keyboard = usbkbd_process_keycodes;
    133 
    134         usb_hid_parse_report(kbd_dev->parser, buffer, callbacks, NULL);
    135 }
    136 
    137 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
     34/* Call this periodically to check keyboard status changes. */
     35static void poll_keyboard(device_t *dev)
    13836{
    13937        int rc;
    14038        usb_handle_t handle;
    141         uint8_t buffer[BUFFER_SIZE];
     39        char buffer[BUFFER_SIZE];
    14240        size_t actual_size;
    143         //usb_endpoint_t poll_endpoint = 1;
     41        usb_endpoint_t poll_endpoint = 1;
    14442
    145 //      usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
    146 //          dev);
    147 //      if (my_address < 0) {
    148 //              return;
    149 //      }
     43        usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
     44            dev);
     45        if (my_address < 0) {
     46                return;
     47        }
    15048
    15149        usb_target_t poll_target = {
    152                 .address = kbd_dev->address,
    153                 .endpoint = kbd_dev->default_ep
     50                .address = my_address,
     51                .endpoint = poll_endpoint
    15452        };
    15553
    156         while (true) {
    157                 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    158                     poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
    159 
    160                 if (rc != EOK) {
    161                         continue;
    162                 }
    163 
    164                 rc = usb_drv_async_wait_for(handle);
    165                 if (rc != EOK) {
    166                         continue;
    167                 }
    168 
    169                 /*
    170                  * If the keyboard answered with NAK, it returned no data.
    171                  * This implies that no change happened since last query.
    172                  */
    173                 if (actual_size == 0) {
    174                         continue;
    175                 }
    176 
    177                 /*
    178                  * TODO: Process pressed keys.
    179                  */
    180                 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
     54        rc = usb_drv_async_interrupt_in(dev->parent_phone, poll_target,
     55            buffer, BUFFER_SIZE, &actual_size, &handle);
     56        if (rc != EOK) {
     57                return;
    18158        }
    18259
    183         // not reached
    184         assert(0);
     60        rc = usb_drv_async_wait_for(handle);
     61        if (rc != EOK) {
     62                return;
     63        }
     64
     65        /*
     66         * If the keyboard answered with NAK, it returned no data.
     67         * This implies that no change happened since last query.
     68         */
     69        if (actual_size == 0) {
     70                return;
     71        }
     72
     73        /*
     74         * Process pressed keys.
     75         */
    18576}
    18677
    187 static int usbkbd_fibril_device(void *arg)
    188 {
    189         printf("!!! USB device fibril\n");
    190 
    191         if (arg == NULL) {
    192                 printf("No device!\n");
    193                 return -1;
    194         }
    195 
    196         device_t *dev = (device_t *)arg;
    197 
    198         // initialize device (get and process descriptors, get address, etc.)
    199         usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
    200 
    201         usbkbd_poll_keyboard(kbd_dev);
    202 
    203         return EOK;
    204 }
    205 
    206 static int usbkbd_add_device(device_t *dev)
     78static int add_kbd_device(device_t *dev)
    20779{
    20880        /* For now, fail immediately. */
    209         //return ENOTSUP;
     81        return ENOTSUP;
    21082
    21183        /*
    21284         * When everything is okay, connect to "our" HC.
    213          *
    214          * Not supported yet, skip..
    21585         */
    216 //      int phone = usb_drv_hc_connect(dev, 0);
    217 //      if (phone < 0) {
    218 //              /*
    219 //               * Connecting to HC failed, roll-back and announce
    220 //               * failure.
    221 //               */
    222 //              return phone;
    223 //      }
     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        }
    22494
    225 //      dev->parent_phone = phone;
     95        dev->parent_phone = phone;
    22696
    22797        /*
    228          * Create new fibril for handling this keyboard
     98         * Just for fun ;-).
    22999         */
    230         fid_t fid = fibril_create(usbkbd_fibril_device, dev);
    231         if (fid == 0) {
    232                 printf("%s: failed to start fibril for HID device\n", NAME);
    233                 return ENOMEM;
    234         }
    235         fibril_add_ready(fid);
     100        poll_keyboard(dev);
    236101
    237102        /*
     
    242107
    243108static driver_ops_t kbd_driver_ops = {
    244         .add_device = usbkbd_add_device,
     109        .add_device = add_kbd_device,
    245110};
    246111
    247112static driver_t kbd_driver = {
    248         .name = NAME,
     113        .name = "usbkbd",
    249114        .driver_ops = &kbd_driver_ops
    250115};
  • uspace/lib/usb/include/usb/classes/hid.h

    r243cb86 rebb98c5  
    3636#define LIBUSB_HID_H_
    3737
    38 #include <usb/usb.h>
    39 #include <driver.h>
    40 #include <usb/classes/hidparser.h>
    41 
    4238/** USB/HID device requests. */
    4339typedef enum {
     
    5854} usb_hid_protocol_t;
    5955
    60 /**
    61  * @brief USB/HID keyboard device type.
    62  *
    63  * Quite dummy right now.
    64  */
    65 typedef struct {
    66         device_t *device;
    67         usb_address_t address;
    68         usb_endpoint_t default_ep;
    69         usb_hid_report_parser_t *parser;
    70 } usb_hid_dev_kbd_t;
    71 
    7256#endif
    7357/**
  • uspace/lib/usb/include/usb/classes/hidparser.h

    r243cb86 rebb98c5  
    5050         * @param arg Custom argument.
    5151         */
    52         void (*keyboard)(const uint16_t *key_codes, size_t count, void *arg);
     52        void (*keyboard)(const uint32_t *key_codes, size_t count, void *arg);
    5353} usb_hid_report_in_callbacks_t;
    5454
  • uspace/lib/usb/src/hidparser.c

    r243cb86 rebb98c5  
    6262    const usb_hid_report_in_callbacks_t *callbacks, void *arg)
    6363{
    64         int i;
    65        
    66         // TODO: parse report
    67        
    68         uint16_t keys[6];
    69        
    70         for (i = 0; i < 6; ++i) {
    71                 keys[i] = data[i];
    72         }
    73        
    74         callbacks->keyboard(keys, 6, arg);
     64        return ENOTSUP;
    7565}
    7666
Note: See TracChangeset for help on using the changeset viewer.