Changeset 2e15ac40 in mainline
- Timestamp:
- 2010-11-26T15:25:52Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bbc28be
- Parents:
- 03171de
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/Makefile
r03171de r2e15ac40 33 33 34 34 LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a 35 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIB_PREFIX) 35 EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIB_PREFIX) -I$(LIBDRV_PREFIX)/include 36 36 37 37 SOURCES = \ -
uspace/drv/usbkbd/main.c
r03171de r2e15ac40 28 28 #include <usb/usbdrv.h> 29 29 #include <driver.h> 30 #include <ipc/driver.h> 30 31 #include <errno.h> 32 #include <fibril.h> 33 #include <usb/classes/hid.h> 31 34 32 35 #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 endpoint 62 kbd_dev->default_ep = CONTROL_EP; 63 64 // TODO: get descriptors 65 66 // TODO: parse descriptors and save endpoints 67 68 return kbd_dev; 69 } 33 70 34 71 /* Call this periodically to check keyboard status changes. */ 35 static void poll_keyboard(device_t *dev)72 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 36 73 { 37 74 int rc; … … 39 76 char buffer[BUFFER_SIZE]; 40 77 size_t actual_size; 41 usb_endpoint_t poll_endpoint = 1;78 //usb_endpoint_t poll_endpoint = 1; 42 79 43 usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,44 dev);45 if (my_address < 0) {46 return;47 }80 // usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone, 81 // dev); 82 // if (my_address < 0) { 83 // return; 84 // } 48 85 49 86 usb_target_t poll_target = { 50 .address = my_address,51 .endpoint = poll_endpoint87 .address = kbd_dev->address, 88 .endpoint = kbd_dev->default_ep 52 89 }; 53 90 54 rc = usb_drv_async_interrupt_in(dev->parent_phone, poll_target, 55 buffer, BUFFER_SIZE, &actual_size, &handle); 91 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 92 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 93 56 94 if (rc != EOK) { 57 95 return; … … 72 110 73 111 /* 74 * Process pressed keys.112 * TODO: Process pressed keys. 75 113 */ 76 114 } 77 115 78 static int add_kbd_device(device_t *dev) 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) 79 136 { 80 137 /* For now, fail immediately. */ … … 83 140 /* 84 141 * When everything is okay, connect to "our" HC. 142 * 143 * Not supported yet, skip.. 85 144 */ 86 int phone = usb_drv_hc_connect(dev, 0);87 if (phone < 0) {88 /*89 * Connecting to HC failed, roll-back and announce90 * failure.91 */92 return phone;93 }145 // int phone = usb_drv_hc_connect(dev, 0); 146 // if (phone < 0) { 147 // /* 148 // * Connecting to HC failed, roll-back and announce 149 // * failure. 150 // */ 151 // return phone; 152 // } 94 153 95 dev->parent_phone = phone;154 // dev->parent_phone = phone; 96 155 97 156 /* 98 * Just for fun ;-).157 * Create new fibril for handling this keyboard 99 158 */ 100 poll_keyboard(dev); 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); 101 165 102 166 /* … … 107 171 108 172 static driver_ops_t kbd_driver_ops = { 109 .add_device = add_kbd_device,173 .add_device = usbkbd_add_device, 110 174 }; 111 175 112 176 static driver_t kbd_driver = { 113 .name = "usbkbd",177 .name = NAME, 114 178 .driver_ops = &kbd_driver_ops 115 179 }; -
uspace/lib/usb/include/usb/classes/hid.h
r03171de r2e15ac40 36 36 #define LIBUSB_HID_H_ 37 37 38 #include <usb/usb.h> 39 #include <driver.h> 40 38 41 /** USB/HID device requests. */ 39 42 typedef enum { … … 54 57 } usb_hid_protocol_t; 55 58 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 56 70 #endif 57 71 /**
Note:
See TracChangeset
for help on using the changeset viewer.