Changeset cd4ae1e in mainline for uspace/app
- Timestamp:
- 2011-04-28T13:14:14Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 54d71e1, a146aa33
- Parents:
- 74f00b6 (diff), c82135a8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 5 added
- 5 edited
- 4 moved
-
usbinfo/main.c (modified) (1 diff)
-
virtusbkbd/Makefile (modified) (1 diff)
-
virtusbkbd/stdreq.c (modified) (1 diff)
-
virtusbkbd/stdreq.h (modified) (1 diff)
-
virtusbkbd/virtusbkbd.c (modified) (9 diffs)
-
vuhid/Makefile (moved) (moved from uspace/app/virtusbhub/Makefile ) (1 diff)
-
vuhid/device.c (added)
-
vuhid/hids/bootkbd.c (added)
-
vuhid/ifaces.c (added)
-
vuhid/ifaces.h (moved) (moved from uspace/lib/usbvirt/src/debug.c ) (2 diffs)
-
vuhid/main.c (added)
-
vuhid/stdreq.c (added)
-
vuhid/stdreq.h (moved) (moved from uspace/drv/vhc/devices.h ) (2 diffs)
-
vuhid/virthid.h (moved) (moved from uspace/app/virtusbhub/main.c ) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/main.c
r74f00b6 rcd4ae1e 55 55 if (str_cmp(devpath, "qemu") == 0) { 56 56 devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1"; 57 } 58 59 /* Hack for virtual keyboard. */ 60 if (str_cmp(devpath, "virt") == 0) { 61 devpath = "/virt/usbhc/usb00_a1/usb00_a2"; 57 62 } 58 63 -
uspace/app/virtusbkbd/Makefile
r74f00b6 rcd4ae1e 32 32 BINARY = vuk 33 33 34 LIBS = $(LIBUSB _PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a34 LIBS = $(LIBUSBVIRT_PREFIX)/libusbvirt.a $(LIBUSB_PREFIX)/libusb.a 35 35 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIBUSBVIRT_PREFIX)/include -I$(LIBDRV_PREFIX)/include 36 36 -
uspace/app/virtusbkbd/stdreq.c
r74f00b6 rcd4ae1e 39 39 #include "kbdconfig.h" 40 40 41 int stdreq_on_get_descriptor(struct usbvirt_device *dev, 42 usb_device_request_setup_packet_t *request, uint8_t *data) 41 int req_get_descriptor(usbvirt_device_t *device, 42 const usb_device_request_setup_packet_t *setup_packet, 43 uint8_t *data, size_t *act_size) 43 44 { 44 if ( request->value_high == USB_DESCTYPE_HID_REPORT) {45 if (setup_packet->value_high == USB_DESCTYPE_HID_REPORT) { 45 46 /* 46 47 * For simplicity, always return the same 47 48 * report descriptor. 48 49 */ 49 int rc = dev->control_transfer_reply(dev, 0, 50 usbvirt_control_reply_helper(setup_packet, 51 data, act_size, 50 52 report_descriptor, report_descriptor_size); 51 52 return rc;53 54 return EOK; 53 55 } 54 56 -
uspace/app/virtusbkbd/stdreq.h
r74f00b6 rcd4ae1e 38 38 #include <usbvirt/device.h> 39 39 40 int stdreq_on_get_descriptor(usbvirt_device_t *, 41 usb_device_request_setup_packet_t *, uint8_t *); 40 int req_get_descriptor(usbvirt_device_t *device, 41 const usb_device_request_setup_packet_t *setup_packet, 42 uint8_t *data, size_t *act_size); 42 43 43 44 #endif -
uspace/app/virtusbkbd/virtusbkbd.c
r74f00b6 rcd4ae1e 48 48 #include <usb/descriptor.h> 49 49 #include <usb/classes/hid.h> 50 #include <usb/debug.h> 50 51 #include <usbvirt/device.h> 51 #include <usbvirt/hub.h>52 52 53 53 #include "kbdconfig.h" … … 67 67 68 68 kb_status_t status; 69 70 static int on_incoming_data(struct usbvirt_device *dev,71 usb_endpoint_t endpoint, void *buffer, size_t size)72 {73 printf("%s: ignoring incomming data to endpoint %d\n", NAME, endpoint);74 75 return EOK;76 }77 78 69 79 70 /** Compares current and last status of pressed keys. … … 100 91 } 101 92 102 static int on_request_for_data(struct usbvirt_device *dev, 103 usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size) 93 static int on_request_for_data(usbvirt_device_t *dev, 94 usb_endpoint_t endpoint, usb_transfer_type_t transfer_type, 95 void *buffer, size_t size, size_t *actual_size) 104 96 { 105 97 static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE]; … … 122 114 if (keypress_check_with_last_request(data, last_data, 123 115 2 + KB_MAX_KEYS_AT_ONCE)) { 124 *actual_size = 0; 125 return EOK; 116 return ENAK; 126 117 } 127 118 … … 131 122 } 132 123 133 static usbvirt_control_transfer_handler_t endpoint_zero_handlers[] = { 134 { 135 .request_type = USBVIRT_MAKE_CONTROL_REQUEST_TYPE( 136 USB_DIRECTION_IN, 137 USBVIRT_REQUEST_TYPE_STANDARD, 138 USBVIRT_REQUEST_RECIPIENT_DEVICE), 124 static usbvirt_control_request_handler_t endpoint_zero_handlers[] = { 125 { 126 .req_direction = USB_DIRECTION_IN, 127 .req_type = USB_REQUEST_TYPE_STANDARD, 128 .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE, 139 129 .request = USB_DEVREQ_GET_DESCRIPTOR, 140 130 .name = "GetDescriptor", 141 .callback = stdreq_on_get_descriptor131 .callback = req_get_descriptor 142 132 }, 143 133 { 144 .request_type = USBVIRT_MAKE_CONTROL_REQUEST_TYPE( 145 USB_DIRECTION_IN, 146 USBVIRT_REQUEST_TYPE_CLASS, 147 USBVIRT_REQUEST_RECIPIENT_DEVICE), 148 .request = USB_DEVREQ_GET_DESCRIPTOR, 149 .name = "GetDescriptor", 150 .callback = stdreq_on_get_descriptor 151 }, 152 USBVIRT_CONTROL_TRANSFER_HANDLER_LAST 134 .callback = NULL 135 } 153 136 }; 154 137 … … 157 140 */ 158 141 static usbvirt_device_ops_t keyboard_ops = { 159 .control_transfer_handlers = endpoint_zero_handlers, 160 .on_data = on_incoming_data, 161 .on_data_request = on_request_for_data 142 .control = endpoint_zero_handlers, 143 .data_in[1] = on_request_for_data 162 144 }; 163 145 … … 197 179 .ops = &keyboard_ops, 198 180 .descriptors = &descriptors, 199 .lib_debug_level = 3,200 .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL,201 181 .name = "keyboard" 202 182 }; … … 262 242 263 243 264 int rc = usbvirt_ connect(&keyboard_dev);244 int rc = usbvirt_device_plug(&keyboard_dev, "/virt/usbhc/hc"); 265 245 if (rc != EOK) { 266 246 printf("%s: Unable to start communication with VHCD (%s).\n", … … 278 258 printf("%s: Terminating...\n", NAME); 279 259 280 usbvirt_disconnect(&keyboard_dev);260 //usbvirt_disconnect(&keyboard_dev); 281 261 282 262 return 0; -
uspace/app/vuhid/Makefile
r74f00b6 rcd4ae1e 28 28 29 29 USPACE_PREFIX = ../.. 30 # acronym for virtual USB hu b30 # acronym for virtual USB human input device 31 31 # (it is really annoying to write long names) 32 32 BINARY = vuh 33 33 34 LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a 35 EXTRA_CFLAGS = -DSTANDALONE_HUB \ 36 -DHUB_PORT_COUNT=10 \ 37 -I$(LIBUSB_PREFIX)/include -I$(LIBUSBVIRT_PREFIX)/include -I$(LIBDRV_PREFIX)/include 34 LIBS = \ 35 $(LIBUSBVIRT_PREFIX)/libusbvirt.a \ 36 $(LIBUSB_PREFIX)/libusb.a 37 EXTRA_CFLAGS = \ 38 -I$(LIBUSB_PREFIX)/include \ 39 -I$(LIBUSBVIRT_PREFIX)/include \ 40 -I$(LIBDRV_PREFIX)/include 41 42 43 SOURCES_INTERFACES = \ 44 hids/bootkbd.c 38 45 39 46 SOURCES = \ 40 47 main.c \ 41 $(STOLEN_VHC_SOURCES) 42 43 STOLEN_VHC_SOURCES = \ 44 vhc_hub/hub.c \ 45 vhc_hub/virthub.c \ 46 vhc_hub/virthubops.c 47 STOLEN_VHC_HEADERS = \ 48 vhc_hub/hub.h \ 49 vhc_hub/virthub.h 50 51 PRE_DEPEND = $(STOLEN_VHC_SOURCES) $(STOLEN_VHC_HEADERS) 52 53 EXTRA_CLEAN = $(STOLEN_VHC_SOURCES) $(STOLEN_VHC_HEADERS) 54 55 HUB_IN_VHC = $(USPACE_PREFIX)/drv/vhc/hub 48 device.c \ 49 ifaces.c \ 50 stdreq.c \ 51 $(SOURCES_INTERFACES) 52 56 53 57 54 include $(USPACE_PREFIX)/Makefile.common 58 59 vhc_hub/%.h: $(HUB_IN_VHC)/%.h60 ln -sfn ../$(HUB_IN_VHC)/$*.h $@61 vhc_hub/%.c: $(HUB_IN_VHC)/%.c62 ln -sfn ../$(HUB_IN_VHC)/$*.c $@ -
uspace/app/vuhid/ifaces.h
r74f00b6 rcd4ae1e 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libusbvirt29 /** @addtogroup usbvirthid 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief Debugging support.33 * 34 34 */ 35 #i nclude <stdio.h>36 # include <bool.h>35 #ifndef VUHID_IFACES_H_ 36 #define VUHID_IFACES_H_ 37 37 38 #include " private.h"38 #include "virthid.h" 39 39 40 extern vuhid_interface_t *available_hid_interfaces[]; 40 41 41 static void debug_print(int level, uint8_t tag, 42 int current_level, uint8_t enabled_tags, 43 const char *format, va_list args) 44 { 45 if (level > current_level) { 46 return; 47 } 48 49 if ((tag & enabled_tags) == 0) { 50 return; 51 } 52 53 bool print_prefix = true; 54 55 if ((format[0] == '%') && (format[1] == 'M')) { 56 format += 2; 57 print_prefix = false; 58 } 59 60 if (print_prefix) { 61 printf("[vusb]: "); 62 while (--level > 0) { 63 printf(" "); 64 } 65 } 66 67 vprintf(format, args); 68 69 if (print_prefix) { 70 printf("\n"); 71 } 72 } 73 74 75 void user_debug(usbvirt_device_t *device, int level, uint8_t tag, 76 const char *format, ...) 77 { 78 va_list args; 79 va_start(args, format); 80 81 debug_print(level, tag, 82 device->debug_level, device->debug_enabled_tags, 83 format, args); 84 85 va_end(args); 86 } 87 88 void lib_debug(usbvirt_device_t *device, int level, uint8_t tag, 89 const char *format, ...) 90 { 91 va_list args; 92 va_start(args, format); 93 94 debug_print(level, tag, 95 device->lib_debug_level, device->lib_debug_enabled_tags, 96 format, args); 97 98 va_end(args); 99 } 100 42 #endif 101 43 /** 102 44 * @} -
uspace/app/vuhid/stdreq.h
r74f00b6 rcd4ae1e 1 1 /* 2 * Copyright (c) 201 0Vojtech Horky2 * Copyright (c) 2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup drvusbvhc29 /** @addtogroup usbvirthid 30 30 * @{ 31 */ 31 */ 32 32 /** @file 33 * @brief Virtual device management.33 * Device request handlers. 34 34 */ 35 #ifndef V HCD_DEVICES_H_36 #define V HCD_DEVICES_H_35 #ifndef VUHID_STDREQ_H_ 36 #define VUHID_STDREQ_H_ 37 37 38 #include <adt/list.h> 39 #include <usb/usb.h> 38 #include <usbvirt/device.h> 40 39 41 #include "hc.h" 40 int req_get_descriptor(usbvirt_device_t *device, 41 const usb_device_request_setup_packet_t *setup_packet, 42 uint8_t *data, size_t *act_size); 42 43 43 /** Connected virtual device. */ 44 typedef struct { 45 /** Phone used when sending data to device. */ 46 int phone; 47 /** Unique identification. */ 48 sysarg_t id; 49 /** Linked-list handle. */ 50 link_t link; 51 } virtdev_connection_t; 44 int req_set_protocol(usbvirt_device_t *device, 45 const usb_device_request_setup_packet_t *setup_packet, 46 uint8_t *data, size_t *act_size); 52 47 53 virtdev_connection_t *virtdev_add_device(int, sysarg_t); 54 virtdev_connection_t *virtdev_find(sysarg_t); 55 void virtdev_destroy_device(virtdev_connection_t *); 56 int virtdev_send_to_all(transaction_t *); 48 int req_set_report(usbvirt_device_t *device, 49 const usb_device_request_setup_packet_t *setup_packet, 50 uint8_t *data, size_t *act_size); 57 51 58 52 #endif -
uspace/app/vuhid/virthid.h
r74f00b6 rcd4ae1e 27 27 */ 28 28 29 /** @addtogroup usbvirth ub29 /** @addtogroup usbvirthid 30 30 * @{ 31 31 */ 32 /** 33 * @file 34 * @brief Virtual USB hub. 32 /** @file 33 * 35 34 */ 36 37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <errno.h> 40 #include <str_error.h> 41 #include <bool.h> 35 #ifndef VUHID_VIRTHID_H_ 36 #define VUHID_VIRTHID_H_ 42 37 43 38 #include <usb/usb.h> 44 #include <usb/descriptor.h>45 #include <usb/classes/hub.h>46 39 #include <usbvirt/device.h> 47 #include <usbvirt/hub.h>48 40 49 #include "vhc_hub/virthub.h" 41 #define VUHID_ENDPOINT_MAX USB11_ENDPOINT_MAX 42 #define VUHID_INTERFACE_MAX 8 50 43 51 #define NAME "vuh" 44 typedef struct vuhid_interface vuhid_interface_t; 52 45 53 static usbvirt_device_t hub_device; 46 struct vuhid_interface { 47 const char *name; 48 const char *id; 49 int usb_subclass; 50 int usb_protocol; 54 51 55 #define VERBOSE_SLEEP(sec, msg, ...) \ 56 do { \ 57 char _status[HUB_PORT_COUNT + 2]; \ 58 printf(NAME ": doing nothing for %zu seconds...\n", \ 59 (size_t) (sec)); \ 60 fibril_sleep((sec)); \ 61 virthub_get_status(&hub_device, _status, HUB_PORT_COUNT + 1); \ 62 printf(NAME ": " msg " [%s]\n" #__VA_ARGS__, _status); \ 63 } while (0) 52 uint8_t *report_descriptor; 53 size_t report_descriptor_size; 64 54 65 static void fibril_sleep(size_t sec) 66 { 67 while (sec-- > 0) { 68 async_usleep(1000*1000); 69 } 70 } 55 size_t in_data_size; 56 size_t out_data_size; 71 57 72 static int dev1 = 1; 58 int (*on_data_in)(vuhid_interface_t *, void *, size_t, size_t *); 59 int (*on_data_out)(vuhid_interface_t *, void *, size_t); 60 void (*live)(vuhid_interface_t *); 73 61 74 int main(int argc, char * argv[]) 75 { 76 int rc; 62 int set_protocol; 77 63 78 printf(NAME ": virtual USB hub.\n"); 64 void *interface_data; 65 }; 79 66 80 rc = virthub_init(&hub_device); 81 if (rc != EOK) { 82 printf(NAME ": Unable to start communication with VHCD (%s).\n", 83 str_error(rc)); 84 return rc; 85 } 86 87 while (true) { 88 VERBOSE_SLEEP(8, "will pretend device plug-in..."); 89 virthub_connect_device(&hub_device, &dev1); 67 typedef struct { 68 vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX]; 69 size_t in_endpoint_first_free; 70 vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX]; 71 size_t out_endpoint_first_free; 72 vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX]; 73 } vuhid_data_t; 90 74 91 VERBOSE_SLEEP(8, "will pretend device un-plug..."); 92 virthub_disconnect_device(&hub_device, &dev1); 93 } 75 typedef struct { 76 uint8_t length; 77 uint8_t type; 78 uint16_t hid_spec_release; 79 uint8_t country_code; 80 uint8_t descriptor_count; 81 uint8_t descriptor1_type; 82 uint16_t descriptor1_length; 83 } __attribute__ ((packed)) hid_descriptor_t; 94 84 95 usbvirt_disconnect(&hub_device); 96 97 return 0; 98 } 85 int add_interface_by_id(vuhid_interface_t **, const char *, usbvirt_device_t *); 99 86 100 101 /** @} 87 #endif 88 /** 89 * @} 102 90 */
Note:
See TracChangeset
for help on using the changeset viewer.
