Changeset 73301a0 in mainline


Ignore:
Timestamp:
2010-10-15T12:57:35Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
47e3a8e
Parents:
cbc00a4d
Message:

Virtual USB keyboard sends its report

Also, the virtual USB framework now handles the standard requests
differently. First, all requests has standalone callbacks and the
user callbacks are always called first. If they return EFORWARD,
the framework will try to satisfy the request by itself.

Location:
uspace
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/Makefile

    rcbc00a4d r73301a0  
    3838        kbdconfig.c \
    3939        keys.c \
     40        stdreq.c \
    4041        virtusbkbd.c
    4142
  • uspace/app/virtusbkbd/virtusbkbd.c

    rcbc00a4d r73301a0  
    5454#include "kbdconfig.h"
    5555#include "keys.h"
     56#include "stdreq.h"
    5657
    5758#define LOOPS 5
     
    7677static int on_class_request(struct usbvirt_device *dev,
    7778    usb_device_request_setup_packet_t *request, uint8_t *data)
    78 {
     79{       
    7980        printf("%s: class request (%d)\n", NAME, (int) request->request);
    8081       
     
    8687 */
    8788static usbvirt_device_ops_t keyboard_ops = {
    88         .on_devreq_class = on_class_request,
     89        .standard_request_ops = &standard_request_ops,
     90        .on_class_device_request = on_class_request,
    8991        .on_data = on_incoming_data
    9092};
  • uspace/lib/usb/descriptor.h

    rcbc00a4d r73301a0  
    4545        USB_DESCTYPE_STRING = 3,
    4646        USB_DESCTYPE_INTERFACE = 4,
    47         USB_DESCTYPE_ENDPOINT = 5
     47        USB_DESCTYPE_ENDPOINT = 5,
     48        USB_DESCTYPE_HID = 0x21,
     49        USB_DESCTYPE_HID_REPORT = 0x22,
     50        USB_DESCTYPE_HID_PHYSICAL = 0x23,
     51        /* USB_DESCTYPE_ = */
    4852} usb_descriptor_type_t;
    4953
  • uspace/lib/usbvirt/ctrlpipe.c

    rcbc00a4d r73301a0  
    6868                        break;
    6969                case REQUEST_TYPE_CLASS:
    70                         if (DEVICE_HAS_OP(device, on_devreq_class)) {
    71                                 return device->ops->on_devreq_class(device,
     70                        if (DEVICE_HAS_OP(device, on_class_device_request)) {
     71                                return device->ops->on_class_device_request(device,
    7272                                    request, remaining_data);
    7373                        }
  • uspace/lib/usbvirt/device.h

    rcbc00a4d r73301a0  
    4646        uint8_t *data);
    4747
     48/** Callbacks for standard device requests.
     49 * When these functions are NULL or return EFORWARD, this
     50 * framework will try to satisfy the request by itself.
     51 */
     52typedef struct {
     53        usbvirt_on_device_request_t on_get_status;
     54        usbvirt_on_device_request_t on_clear_feature;
     55        usbvirt_on_device_request_t on_set_feature;
     56        usbvirt_on_device_request_t on_set_address;
     57        usbvirt_on_device_request_t on_get_descriptor;
     58        usbvirt_on_device_request_t on_set_descriptor;
     59        usbvirt_on_device_request_t on_get_configuration;
     60        usbvirt_on_device_request_t on_set_configuration;
     61        usbvirt_on_device_request_t on_get_interface;
     62        usbvirt_on_device_request_t on_set_interface;
     63        usbvirt_on_device_request_t on_synch_frame;
     64} usbvirt_standard_device_request_ops_t;
     65
    4866/** Device operations. */
    4967typedef struct {
    50         /** Callback for standard USB request.
    51          * Called only when the request could not be handled by this
    52          * framework.
    53          */
    54         usbvirt_on_device_request_t on_devreq_std;
     68        /** Callbacks for standard deivce requests. */
     69        usbvirt_standard_device_request_ops_t *standard_request_ops;
    5570        /** Callback for class-specific USB request. */
    56         usbvirt_on_device_request_t on_devreq_class;
     71        usbvirt_on_device_request_t on_class_device_request;
    5772        /** Callback for all other incoming data. */
    5873        int (*on_data)(struct usbvirt_device *dev,
  • uspace/lib/usbvirt/stdreq.c

    rcbc00a4d r73301a0  
    123123}
    124124
     125#define HANDLE_REQUEST(request, data, type, dev, user_callback, default_handler) \
     126        do { \
     127                if ((request)->request == (type)) { \
     128                        int _rc = EFORWARD; \
     129                        if (((dev)->ops) && ((dev)->ops->standard_request_ops) \
     130                            && ((dev)->ops->standard_request_ops->user_callback)) { \
     131                                _rc = (dev)->ops->standard_request_ops->\
     132                                    user_callback(dev, request, data); \
     133                        } \
     134                        if (_rc == EFORWARD) { \
     135                                default_handler; \
     136                        } \
     137                        return _rc; \
     138                } \
     139        } while (false)
     140
     141
    125142int handle_std_request(usb_device_request_setup_packet_t *request, uint8_t *data)
    126143{
    127         int rc;
     144        HANDLE_REQUEST(request, data, USB_DEVREQ_GET_DESCRIPTOR,
     145            device, on_get_descriptor,
     146            handle_get_descriptor(request->value_low, request->value_high,
     147                request->index, request->length));
    128148       
    129         switch (request->request) {
    130                 case USB_DEVREQ_GET_DESCRIPTOR:
    131                         rc = handle_get_descriptor(
    132                             request->value_low, request->value_high,
    133                             request->index, request->length);
    134                         break;
    135                
    136                 case USB_DEVREQ_SET_ADDRESS:
    137                         rc = handle_set_address(request->value,
    138                             request->index, request->length);
    139                         break;
    140                
    141                 default:
    142                         rc = EFORWARD;
    143                         break;
    144         }
     149        HANDLE_REQUEST(request, data, USB_DEVREQ_SET_ADDRESS,
     150            device, on_set_address,
     151            handle_set_address(request->value,
     152                request->index, request->length));
    145153       
    146         /*
    147          * We preprocessed all we could.
    148          * If it was not enough, pass the request to the actual driver.
    149          */
    150         if (rc == EFORWARD) {
    151                 if (DEVICE_HAS_OP(device, on_devreq_std)) {
    152                         return device->ops->on_devreq_std(device,
    153                             request, data);
    154                 }
    155         }
    156        
    157         return EOK;
     154        return ENOTSUP;
    158155}
    159156
Note: See TracChangeset for help on using the changeset viewer.