Changeset 4a4c8bcf in mainline
- Timestamp:
- 2011-06-08T20:37:07Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 15e54f5
- Parents:
- 8869f7b
- Location:
- uspace/drv/usbmouse
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbmouse/init.c
r8869f7b r4a4c8bcf 43 43 #include <errno.h> 44 44 45 // FIXME: remove this header46 #include <kernel/ipc/ipc_methods.h>47 48 45 /** Mouse polling endpoint description for boot protocol subclass. */ 49 46 usb_endpoint_description_t poll_endpoint_description = { … … 56 53 }; 57 54 58 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 55 /** Default handler for IPC methods not handled by DDF. 56 * 57 * @param fun Device function handling the call. 58 * @param icallid Call ID. 59 * @param icall Call data. 60 * 61 */ 62 static void default_connection_handler(ddf_fun_t *fun, ipc_callid_t icallid, 63 ipc_call_t *icall) 64 { 65 usb_mouse_t *mouse = (usb_mouse_t *) fun->driver_data; 66 assert(mouse != NULL); 67 68 async_sess_t *callback = 69 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 70 71 if (callback) { 72 if (mouse->console_sess == NULL) { 73 mouse->console_sess = callback; 74 async_answer_0(icallid, EOK); 75 } else 76 async_answer_0(icallid, ELIMIT); 77 } else 78 async_answer_0(icallid, EINVAL); 79 } 80 59 81 /** Device ops for USB mouse. */ 60 82 static ddf_dev_ops_t mouse_ops = { 61 83 .default_handler = default_connection_handler 62 84 }; 63 64 /** Default handler for IPC methods not handled by DDF.65 *66 * @param fun Device function handling the call.67 * @param icallid Call id.68 * @param icall Call data.69 */70 void default_connection_handler(ddf_fun_t *fun,71 ipc_callid_t icallid, ipc_call_t *icall)72 {73 sysarg_t method = IPC_GET_IMETHOD(*icall);74 75 usb_mouse_t *mouse = (usb_mouse_t *) fun->driver_data;76 assert(mouse != NULL);77 78 if (method == IPC_M_CONNECT_TO_ME) {79 int callback = IPC_GET_ARG5(*icall);80 81 if (mouse->console_phone != -1) {82 async_answer_0(icallid, ELIMIT);83 return;84 }85 86 mouse->console_phone = callback;87 async_answer_0(icallid, EOK);88 return;89 }90 91 async_answer_0(icallid, EINVAL);92 }93 85 94 86 /** Create USB mouse device. … … 102 94 { 103 95 usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t)); 104 if (mouse == NULL) {96 if (mouse == NULL) 105 97 return ENOMEM; 106 }98 107 99 mouse->dev = dev; 108 mouse->console_ phone = -1;109 100 mouse->console_sess = NULL; 101 110 102 int rc; 111 103 112 104 /* Create DDF function. */ 113 105 mouse->mouse_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "mouse"); … … 116 108 goto leave; 117 109 } 118 110 119 111 mouse->mouse_fun->ops = &mouse_ops; 120 112 121 113 rc = ddf_fun_bind(mouse->mouse_fun); 122 if (rc != EOK) {114 if (rc != EOK) 123 115 goto leave; 124 } 125 116 126 117 /* Add the function to mouse class. */ 127 118 rc = ddf_fun_add_to_class(mouse->mouse_fun, "mouse"); 128 if (rc != EOK) {119 if (rc != EOK) 129 120 goto leave; 130 }131 121 132 122 /* Set the boot protocol. */ 133 123 rc = usbhid_req_set_protocol(&dev->ctrl_pipe, dev->interface_no, 134 124 USB_HID_PROTOCOL_BOOT); 135 if (rc != EOK) {125 if (rc != EOK) 136 126 goto leave; 137 }138 127 139 /* Everything all 128 /* Everything allright. */ 140 129 dev->driver_data = mouse; 141 130 mouse->mouse_fun->driver_data = mouse; 142 131 143 132 return EOK; 144 133 145 134 leave: 146 135 free(mouse); 147 148 136 return rc; 149 137 } -
uspace/drv/usbmouse/main.c
r8869f7b r4a4c8bcf 34 34 * Main routines of USB boot protocol mouse driver. 35 35 */ 36 36 37 #include "mouse.h" 37 38 #include <usb/debug.h> … … 40 41 #include <str_error.h> 41 42 43 #define NAME "usbmouse" 44 42 45 /** Callback when new mouse device is attached and recognised by DDF. 43 46 * 44 47 * @param dev Representation of a generic DDF device. 48 * 45 49 * @return Error code. 50 * 46 51 */ 47 52 static int usbmouse_add_device(usb_device_t *dev) … … 53 58 return rc; 54 59 } 55 60 56 61 usb_log_debug("Polling pipe at endpoint %d.\n", 57 62 dev->pipes[0].pipe->endpoint_no); 58 59 rc = usb_device_auto_poll(dev, 0, 60 usb_mouse_polling_callback,dev->pipes[0].pipe->max_packet_size,63 64 rc = usb_device_auto_poll(dev, 0, usb_mouse_polling_callback, 65 dev->pipes[0].pipe->max_packet_size, 61 66 usb_mouse_polling_ended_callback, dev->driver_data); 62 67 63 68 if (rc != EOK) { 64 69 usb_log_error("Failed to start polling fibril: %s.\n", … … 66 71 return rc; 67 72 } 68 73 69 74 usb_log_info("controlling new mouse (handle %" PRIun ").\n", 70 75 dev->ddf_dev->handle); 71 76 72 77 return EOK; 73 78 } … … 93 98 { 94 99 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME); 95 96 100 return usb_driver_main(&mouse_driver); 97 101 } -
uspace/drv/usbmouse/mouse.c
r8869f7b r4a4c8bcf 40 40 #include <ipc/mouse.h> 41 41 #include <async.h> 42 #include <async_obsolete.h>43 42 #include "mouse.h" 44 43 45 44 /** Mouse polling callback. 46 45 * 47 * @param dev Device that is being polled.46 * @param dev Device that is being polled. 48 47 * @param buffer Data buffer. 49 * @param buffer_size Buffer size in bytes. 50 * @param arg Custom argument - points to usb_mouse_t. 48 * @param size Buffer size in bytes. 49 * @param arg Pointer to usb_mouse_t. 50 * 51 51 * @return Always true. 52 * 52 53 */ 53 bool usb_mouse_polling_callback(usb_device_t *dev, 54 uint8_t *buffer, size_t buffer_size, void *arg)54 bool usb_mouse_polling_callback(usb_device_t *dev, uint8_t *buffer, 55 size_t size, void *arg) 55 56 { 56 57 usb_mouse_t *mouse = (usb_mouse_t *) arg; 57 58 58 59 usb_log_debug2("got buffer: %s.\n", 59 usb_debug_str_buffer(buffer, buffer_size, 0));60 60 usb_debug_str_buffer(buffer, size, 0)); 61 61 62 uint8_t butt = buffer[0]; 62 63 char str_buttons[4] = { … … 66 67 0 67 68 }; 68 69 69 70 int shift_x = ((int) buffer[1]) - 127; 70 71 int shift_y = ((int) buffer[2]) - 127; 71 72 int wheel = ((int) buffer[3]) - 127; 72 73 if (buffer[1] == 0) {73 74 if (buffer[1] == 0) 74 75 shift_x = 0; 75 }76 if (buffer[2] == 0) {76 77 if (buffer[2] == 0) 77 78 shift_y = 0; 78 }79 if (buffer[3] == 0) {79 80 if (buffer[3] == 0) 80 81 wheel = 0; 81 } 82 83 if (mouse->console_phone >= 0) { 82 83 if (mouse->console_sess) { 84 84 if ((shift_x != 0) || (shift_y != 0)) { 85 /* FIXME: guessed for QEMU */ 86 async_obsolete_req_2_0(mouse->console_phone, 87 MEVENT_MOVE, 88 - shift_x / 10, - shift_y / 10); 85 // FIXME: guessed for QEMU 86 87 async_exch_t *exch = async_exchange_begin(mouse->console_sess); 88 async_req_2_0(exch, MEVENT_MOVE, -shift_x / 10, -shift_y / 10); 89 async_exchange_end(exch); 89 90 } 90 91 if (butt) { 91 /* FIXME: proper button clicking. */ 92 async_obsolete_req_2_0(mouse->console_phone, 93 MEVENT_BUTTON, 1, 1); 94 async_obsolete_req_2_0(mouse->console_phone, 95 MEVENT_BUTTON, 1, 0); 92 // FIXME: proper button clicking 93 94 async_exch_t *exch = async_exchange_begin(mouse->console_sess); 95 async_req_2_0(exch, MEVENT_BUTTON, 1, 1); 96 async_req_2_0(exch, MEVENT_BUTTON, 1, 0); 97 async_exchange_end(exch); 96 98 } 97 99 } 98 100 99 101 usb_log_debug("buttons=%s dX=%+3d dY=%+3d wheel=%+3d\n", 100 102 str_buttons, shift_x, shift_y, wheel); 101 103 102 104 /* Guess. */ 103 105 async_usleep(1000); 104 106 105 107 return true; 106 108 } … … 108 110 /** Callback when polling is terminated. 109 111 * 110 * @param dev Device where the polling terminated.112 * @param dev Device where the polling terminated. 111 113 * @param recurring_errors Whether the polling was terminated due to 112 * recurring errors. 113 * @param arg Custom argument - points to usb_mouse_t. 114 * recurring errors. 115 * @param arg Pointer to usb_mouse_t. 116 * 114 117 */ 115 void usb_mouse_polling_ended_callback(usb_device_t *dev, 116 bool recurring_errors,void *arg)118 void usb_mouse_polling_ended_callback(usb_device_t *dev, bool recurring_errors, 119 void *arg) 117 120 { 118 121 usb_mouse_t *mouse = (usb_mouse_t *) arg; 119 120 async_ obsolete_hangup(mouse->console_phone);121 mouse->console_ phone = -1;122 122 123 async_hangup(mouse->console_sess); 124 mouse->console_sess = NULL; 125 123 126 usb_device_destroy(dev); 124 127 } -
uspace/drv/usbmouse/mouse.h
r8869f7b r4a4c8bcf 34 34 * Common definitions for USB mouse driver. 35 35 */ 36 36 37 #ifndef USBMOUSE_MOUSE_H_ 37 38 #define USBMOUSE_MOUSE_H_ … … 40 41 #include <usb/dev/pipes.h> 41 42 #include <time.h> 43 #include <async.h> 42 44 43 #define NAME "usbmouse" 45 #define POLL_PIPE(dev) \ 46 ((dev)->pipes[0].pipe) 44 47 45 48 /** Container for USB mouse device. */ … … 47 50 /** Generic device container. */ 48 51 usb_device_t *dev; 52 49 53 /** Function representing the device. */ 50 54 ddf_fun_t *mouse_fun; 55 51 56 /** Polling interval in microseconds. */ 52 57 suseconds_t poll_interval_us; 53 /** IPC phone to console (consumer). */ 54 int console_phone; 58 59 /** Callback session to console (consumer). */ 60 async_sess_t *console_sess; 55 61 } usb_mouse_t; 56 57 #define POLL_PIPE(dev) ((dev)->pipes[0].pipe)58 62 59 63 extern usb_endpoint_description_t poll_endpoint_description; 60 64 61 int usb_mouse_create(usb_device_t *);62 63 bool usb_mouse_polling_callback(usb_device_t *, uint8_t *, size_t,void *);64 void usb_mouse_polling_ended_callback(usb_device_t *, bool, void *);65 extern int usb_mouse_create(usb_device_t *); 66 extern bool usb_mouse_polling_callback(usb_device_t *, uint8_t *, size_t, 67 void *); 68 extern void usb_mouse_polling_ended_callback(usb_device_t *, bool, void *); 65 69 66 70 #endif 71 67 72 /** 68 73 * @}
Note:
See TracChangeset
for help on using the changeset viewer.