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

Changeset d97d209 in mainline


Ignore:
Timestamp:
2010-10-10T22:01:32Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
2c970ee
Parents:
0e41957
Message:

API change in virtual USB device

Instead of passing individual items of device request, the whole
structure is passed-in.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/virtusbkbd.c

    r0e41957 rd97d209  
    4747#include <usb/hcd.h>
    4848#include <usb/device.h>
     49#include <usb/hid.h>
    4950#include <usbvirt/device.h>
    5051#include <usbvirt/hub.h>
     
    7071}
    7172
     73static int on_class_request(struct usbvirt_device *dev,
     74    usb_device_request_setup_packet_t *request, uint8_t *data)
     75{
     76        printf("%s: class request (%d)\n", NAME, (int) request->request);
     77       
     78        return EOK;
     79}
     80
    7281static usb_standard_device_descriptor_t std_descriptor = {
    7382        .length = sizeof(usb_standard_device_descriptor_t),
     
    8594 */
    8695static usbvirt_device_ops_t keyboard_ops = {
     96        .on_devreq_class = on_class_request,
    8797        .on_data = on_incoming_data
    8898};
  • uspace/lib/usbvirt/ctrlpipe.c

    r0e41957 rd97d209  
    4545        ((value & GET_MIDBITS_MASK(size, shift)) >> shift)
    4646
    47 static usb_direction_t request_get_direction(uint8_t request_type)
    48 {
    49         int bit7 = GET_MIDBITS(request_type, 1, 7);
    50         return bit7 ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
    51 }
    52 
    5347static int request_get_type(uint8_t request_type)
    5448{
     
    5650}
    5751
    58 static int request_get_recipient(uint8_t request_type)
    59 {
    60         return GET_MIDBITS(request_type, 5, 0);
    61 }
    6252
    63 
    64 typedef struct {
    65         uint8_t request_type;
    66         uint8_t request;
    67         uint16_t value;
    68         uint16_t index;
    69         uint16_t length;
    70 } __attribute__ ((packed)) devreq_setup_packet_t;
    7153
    7254int control_pipe(void *buffer, size_t size)
    7355{
    74         if (size < sizeof(devreq_setup_packet_t)) {
     56        if (size < sizeof(usb_device_request_setup_packet_t)) {
    7557                return ENOMEM;
    7658        }
    7759       
    78         devreq_setup_packet_t *request = (devreq_setup_packet_t *) buffer;
    79         uint8_t *remaining_data = ((uint8_t *) request) + sizeof(devreq_setup_packet_t);
     60        usb_device_request_setup_packet_t *request = (usb_device_request_setup_packet_t *) buffer;
     61        uint8_t *remaining_data = ((uint8_t *) request) + sizeof(usb_device_request_setup_packet_t);
    8062       
    81         usb_direction_t direction = request_get_direction(request->request_type);
    8263        int type = request_get_type(request->request_type);
    83         int recipient = request_get_recipient(request->request_type);
    84        
    8564       
    8665        switch (type) {
    8766                case REQUEST_TYPE_STANDARD:
    88                         return handle_std_request(direction, recipient,
    89                             request->request, request->value,
    90                             request->index, request->length,
    91                             remaining_data);
     67                        return handle_std_request(request, remaining_data);
    9268                        break;
    9369                case REQUEST_TYPE_CLASS:
    9470                        if (DEVICE_HAS_OP(device, on_devreq_class)) {
    9571                                return device->ops->on_devreq_class(device,
    96                                     direction, recipient,
    97                                     request->request, request->value,
    98                                     request->index, request->length,
    99                                     remaining_data);
     72                                    request, remaining_data);
    10073                        }
    10174                        break;
  • uspace/lib/usbvirt/device.h

    r0e41957 rd97d209  
    4242struct usbvirt_device;
    4343
    44 typedef int (*usbvirt_on_devreq_t)(struct usbvirt_device *dev,
    45     usb_direction_t, int recipient,
    46     uint8_t request, uint16_t value, uint16_t index, uint16_t length,
    47     uint8_t *remaining_data);
     44typedef int (*usbvirt_on_device_request_t)(struct usbvirt_device *dev,
     45        usb_device_request_setup_packet_t *request,
     46        uint8_t *data);
    4847
    4948typedef struct {
    50         usbvirt_on_devreq_t on_devreq_std;
    51         usbvirt_on_devreq_t on_devreq_class;
     49        usbvirt_on_device_request_t on_devreq_std;
     50        usbvirt_on_device_request_t on_devreq_class;
    5251        int (*on_data)(struct usbvirt_device *dev,
    5352            usb_endpoint_t endpoint, void *buffer, size_t size);
  • uspace/lib/usbvirt/private.h

    r0e41957 rd97d209  
    5555int control_pipe(void *buffer, size_t size);
    5656
    57 int handle_std_request(usb_direction_t direction, int recipient,
    58     uint16_t request, uint16_t value, uint16_t index, uint16_t length,
    59     uint8_t *remaining_data);
     57int handle_std_request(usb_device_request_setup_packet_t *request, uint8_t *data);
    6058
    6159#endif
  • uspace/lib/usbvirt/stdreq.c

    r0e41957 rd97d209  
    8181}
    8282
    83 int handle_std_request(usb_direction_t direction, int recipient,
    84     uint16_t request, uint16_t value, uint16_t index, uint16_t length,
    85     uint8_t *remaining_data)
     83int handle_std_request(usb_device_request_setup_packet_t *request, uint8_t *data)
    8684{
    8785        int rc;
    8886       
    89         switch (request) {
     87        switch (request->request) {
    9088                case USB_DEVREQ_GET_DESCRIPTOR:
    91                         rc = handle_get_descriptor(value >> 8, (uint8_t) value,
    92                             index, length);
     89                        rc = handle_get_descriptor(
     90                            request->value_low, request->value_high,
     91                            request->index, request->length);
    9392                        break;
    9493               
    9594                case USB_DEVREQ_SET_ADDRESS:
    96                         rc = handle_set_address(value, index, length);
     95                        rc = handle_set_address(request->value,
     96                            request->index, request->length);
    9797                        break;
    9898               
     
    108108        if (rc == EFORWARD) {
    109109                if (DEVICE_HAS_OP(device, on_devreq_std)) {
    110                         return device->ops->on_devreq_std(device, direction,
    111                             recipient,
    112                             request, value, index,
    113                             length, remaining_data);
     110                        return device->ops->on_devreq_std(device,
     111                            request, data);
    114112                }
    115113        }
Note: See TracChangeset for help on using the changeset viewer.