Changes in / [70c85211:4570779] in mainline
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/Makefile
r70c85211 r4570779 33 33 34 34 LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a 35 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIB_PREFIX) -I$(LIBDRV_PREFIX)/include35 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIB_PREFIX) 36 36 37 37 SOURCES = \ -
uspace/drv/usbkbd/main.c
r70c85211 r4570779 28 28 #include <usb/usbdrv.h> 29 29 #include <driver.h> 30 #include <ipc/driver.h>31 30 #include <errno.h> 32 #include <fibril.h>33 #include <usb/classes/hid.h>34 31 35 32 #define BUFFER_SIZE 32 36 #define NAME "usbkbd"37 38 static const usb_endpoint_t CONTROL_EP = 0;39 40 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)41 {42 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(43 sizeof(usb_hid_dev_kbd_t));44 45 if (kbd_dev == NULL) {46 fprintf(stderr, NAME ": No memory!\n");47 return NULL;48 }49 50 kbd_dev->device = dev;51 52 kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,53 dev);54 55 if (kbd_dev->address < 0) {56 fprintf(stderr, NAME ": No device address!\n");57 free(kbd_dev);58 return NULL;59 }60 61 // default endpoint62 kbd_dev->default_ep = CONTROL_EP;63 64 // TODO: get descriptors65 66 // TODO: parse descriptors and save endpoints67 68 return kbd_dev;69 }70 33 71 34 /* Call this periodically to check keyboard status changes. */ 72 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)35 static void poll_keyboard(device_t *dev) 73 36 { 74 37 int rc; … … 76 39 char buffer[BUFFER_SIZE]; 77 40 size_t actual_size; 78 //usb_endpoint_t poll_endpoint = 1;41 usb_endpoint_t poll_endpoint = 1; 79 42 80 //usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,81 //dev);82 //if (my_address < 0) {83 //return;84 //}43 usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone, 44 dev); 45 if (my_address < 0) { 46 return; 47 } 85 48 86 49 usb_target_t poll_target = { 87 .address = kbd_dev->address,88 .endpoint = kbd_dev->default_ep50 .address = my_address, 51 .endpoint = poll_endpoint 89 52 }; 90 53 91 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 92 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 93 54 rc = usb_drv_async_interrupt_in(dev->parent_phone, poll_target, 55 buffer, BUFFER_SIZE, &actual_size, &handle); 94 56 if (rc != EOK) { 95 57 return; … … 110 72 111 73 /* 112 * TODO:Process pressed keys.74 * Process pressed keys. 113 75 */ 114 76 } 115 77 116 static int usbkbd_fibril_device(void *arg) 117 { 118 printf("!!! USB device fibril\n"); 119 120 if (arg == NULL) { 121 printf("No device!\n"); 122 return -1; 123 } 124 125 device_t *dev = (device_t *)arg; 126 127 // initialize device (get and process descriptors, get address, etc.) 128 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 129 130 usbkbd_poll_keyboard(kbd_dev); 131 132 return EOK; 133 } 134 135 static int usbkbd_add_device(device_t *dev) 78 static int add_kbd_device(device_t *dev) 136 79 { 137 80 /* For now, fail immediately. */ … … 140 83 /* 141 84 * When everything is okay, connect to "our" HC. 142 *143 * Not supported yet, skip..144 85 */ 145 //int phone = usb_drv_hc_connect(dev, 0);146 //if (phone < 0) {147 ///*148 //* Connecting to HC failed, roll-back and announce149 //* failure.150 //*/151 //return phone;152 //}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 } 153 94 154 //dev->parent_phone = phone;95 dev->parent_phone = phone; 155 96 156 97 /* 157 * Create new fibril for handling this keyboard98 * Just for fun ;-). 158 99 */ 159 fid_t fid = fibril_create(usbkbd_fibril_device, dev); 160 if (fid == 0) { 161 printf("%s: failed to start fibril for HID device\n", NAME); 162 return ENOMEM; 163 } 164 fibril_add_ready(fid); 100 poll_keyboard(dev); 165 101 166 102 /* … … 171 107 172 108 static driver_ops_t kbd_driver_ops = { 173 .add_device = usbkbd_add_device,109 .add_device = add_kbd_device, 174 110 }; 175 111 176 112 static driver_t kbd_driver = { 177 .name = NAME,113 .name = "usbkbd", 178 114 .driver_ops = &kbd_driver_ops 179 115 }; -
uspace/lib/usb/include/usb/classes/hid.h
r70c85211 r4570779 36 36 #define LIBUSB_HID_H_ 37 37 38 #include <usb/usb.h>39 #include <driver.h>40 41 38 /** USB/HID device requests. */ 42 39 typedef enum { … … 57 54 } usb_hid_protocol_t; 58 55 59 /**60 * @brief USB/HID keyboard device type.61 *62 * Quite dummy right now.63 */64 typedef struct {65 device_t *device;66 usb_address_t address;67 usb_endpoint_t default_ep;68 } usb_hid_dev_kbd_t;69 70 56 #endif 71 57 /**
Note:
See TracChangeset
for help on using the changeset viewer.