00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036 #include "mouse.h"
00037 #include <usb/debug.h>
00038 #include <usb/classes/classes.h>
00039 #include <usb/hid/hid.h>
00040 #include <usb/dev/request.h>
00041 #include <usb/hid/request.h>
00042 #include <errno.h>
00043
00045 usb_endpoint_description_t poll_endpoint_description = {
00046 .transfer_type = USB_TRANSFER_INTERRUPT,
00047 .direction = USB_DIRECTION_IN,
00048 .interface_class = USB_CLASS_HID,
00049 .interface_subclass = USB_HID_SUBCLASS_BOOT,
00050 .interface_protocol = USB_HID_PROTOCOL_MOUSE,
00051 .flags = 0
00052 };
00053
00054 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
00056 static ddf_dev_ops_t mouse_ops = {
00057 .default_handler = default_connection_handler
00058 };
00059
00066 void default_connection_handler(ddf_fun_t *fun,
00067 ipc_callid_t icallid, ipc_call_t *icall)
00068 {
00069 sysarg_t method = IPC_GET_IMETHOD(*icall);
00070
00071 usb_mouse_t *mouse = (usb_mouse_t *) fun->driver_data;
00072 assert(mouse != NULL);
00073
00074 if (method == IPC_M_CONNECT_TO_ME) {
00075 int callback = IPC_GET_ARG5(*icall);
00076
00077 if (mouse->console_phone != -1) {
00078 async_answer_0(icallid, ELIMIT);
00079 return;
00080 }
00081
00082 mouse->console_phone = callback;
00083 async_answer_0(icallid, EOK);
00084 return;
00085 }
00086
00087 async_answer_0(icallid, EINVAL);
00088 }
00089
00097 int usb_mouse_create(usb_device_t *dev)
00098 {
00099 usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t));
00100 if (mouse == NULL) {
00101 return ENOMEM;
00102 }
00103 mouse->dev = dev;
00104 mouse->console_phone = -1;
00105
00106 int rc;
00107
00108
00109 mouse->mouse_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "mouse");
00110 if (mouse->mouse_fun == NULL) {
00111 rc = ENOMEM;
00112 goto leave;
00113 }
00114
00115 mouse->mouse_fun->ops = &mouse_ops;
00116
00117 rc = ddf_fun_bind(mouse->mouse_fun);
00118 if (rc != EOK) {
00119 goto leave;
00120 }
00121
00122
00123 rc = ddf_fun_add_to_class(mouse->mouse_fun, "mouse");
00124 if (rc != EOK) {
00125 goto leave;
00126 }
00127
00128
00129 rc = usbhid_req_set_protocol(&dev->ctrl_pipe, dev->interface_no,
00130 USB_HID_PROTOCOL_BOOT);
00131 if (rc != EOK) {
00132 goto leave;
00133 }
00134
00135
00136 dev->driver_data = mouse;
00137 mouse->mouse_fun->driver_data = mouse;
00138
00139 return EOK;
00140
00141 leave:
00142 free(mouse);
00143
00144 return rc;
00145 }
00146