Changeset b8100da in mainline for uspace/app/virtusbkbd/virtusbkbd.c


Ignore:
Timestamp:
2010-10-10T17:01:40Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6c1315b
Parents:
b371844
Message:

Virtual USB device in separate library

The `usbvirt' library is intended to be a framework for creating
virtual USB devices.

So far, only the skeleton is ready.

File:
1 edited

Legend:

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

    rb371844 rb8100da  
    4646
    4747#include <usb/hcd.h>
    48 #include <usb/virtdev.h>
     48#include <usbvirt/device.h>
     49#include <usbvirt/hub.h>
     50#include <usbvirt/ids.h>
    4951
    5052#define LOOPS 5
     
    5961        (printf("%s: %s" fmt "\n", NAME, _QUOTEME(cmd), __VA_ARGS__), cmd(__VA_ARGS__))
    6062
     63static int on_incoming_data(struct usbvirt_device *dev,
     64    usb_endpoint_t endpoint, void *buffer, size_t size)
     65{
     66        printf("%s: ignoring incomming data to endpoint %d\n", NAME, endpoint);
     67       
     68        return EOK;
     69}
     70
     71/** Keyboard callbacks.
     72 * We abuse the fact that static variables are zero-filled.
     73 */
     74static usbvirt_device_ops_t keyboard_ops = {
     75        .on_data = on_incoming_data
     76};
     77
     78/** Keyboard device.
     79 * Rest of the items will be initialized later.
     80 */
     81static usbvirt_device_t keyboard_dev = {
     82        .ops = &keyboard_ops,
     83        .device_id_ = USBVIRT_DEV_KEYBOARD_ID
     84};
     85
     86
    6187static void fibril_sleep(size_t sec)
    6288{
     
    6692}
    6793
    68 static void on_data_from_host(usb_endpoint_t endpoint, void *buffer, size_t len)
    69 {
    70         printf("%s: ignoring incomming data to endpoint %d\n", NAME, endpoint);
    71 }
    7294
    7395int main(int argc, char * argv[])
    7496{
    75         int vhcd_phone = usb_virtdev_connect(DEV_HCD_NAME,
    76             USB_VIRTDEV_KEYBOARD_ID, on_data_from_host);
    77        
    78         if (vhcd_phone < 0) {
     97        int rc = usbvirt_connect(&keyboard_dev, DEV_HCD_NAME);
     98        if (rc != EOK) {
    7999                printf("%s: Unable to start comunication with VHCD at usb://%s (%s).\n",
    80                     NAME, DEV_HCD_NAME, str_error(vhcd_phone));
    81                 return vhcd_phone;
     100                    NAME, DEV_HCD_NAME, str_error(rc));
     101                return rc;
    82102        }
    83        
    84        
    85103       
    86104        size_t i;
     
    94112               
    95113                printf("%s: Will send data to VHCD...\n", NAME);
    96                 int rc = usb_virtdev_data_to_host(vhcd_phone, 0, data, size);
     114                int rc = keyboard_dev.send_data(&keyboard_dev, 0, data, size);
    97115                printf("%s:   ...data sent (%s).\n", NAME, str_error(rc));
    98116        }
     
    101119        printf("%s: Terminating...\n", NAME);
    102120       
    103         ipc_hangup(vhcd_phone);
     121        usbvirt_disconnect();
    104122       
    105123        return 0;
Note: See TracChangeset for help on using the changeset viewer.