Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | /* SPDX-License-Identifier: GPL-2.0+ */ /* * Mouse/trackpad/touchscreen input uclass * * Copyright 2020 Google LLC */ #ifndef _MOUSE_H #define _MOUSE_H #include <stdbool.h> #include <video_defs.h> struct udevice; enum mouse_ev_t { MOUSE_EV_NULL, MOUSE_EV_MOTION, MOUSE_EV_BUTTON, }; enum mouse_state_t { BUTTON_LEFT = 1 << 0, BUTTON_MIDDLE = 1 << 1, BUTTON_RIGHT = 1 << 2, BUTTON_SCROLL_PLUS = 1 << 3, BUTTON_SCROLL_MINUS = 1 << 4, }; /** * struct mouse_uc_priv - pre-device private data for mouse uclass * * @left_pressed: True if left button is currently pressed * @click_pending: True if a click has occurred but not yet retrieved * @click_pos: Position where the click occurred * @last_pos: Last position received from mouse * @video_dev: Video device for coordinate scaling * @video_width: Width of video display * @video_height: Height of video display */ struct mouse_uc_priv { bool left_pressed; bool click_pending; struct vid_pos click_pos; struct vid_pos last_pos; struct udevice *video_dev; int video_width; int video_height; }; /** * struct mouse_event - information about a mouse event * * @type: Mouse event ype */ struct mouse_event { enum mouse_ev_t type; union { /** * @state: Mouse state (enum mouse_state_t bitmask) * @x: X position of mouse * @y: Y position of mouse * @xrel: Relative motion in X direction * @yrel: Relative motion in Y direction */ struct mouse_motion { unsigned char state; unsigned short x; unsigned short y; short xrel; short yrel; } motion; /** * @button: Button number that was pressed/released (BUTTON_...) * @pressed: True if button was pressed, false if released * @clicks: number of clicks (normally 1; 2 = double-click) * @x: X position of mouse * @y: Y position of mouse */ struct mouse_button { unsigned char button; bool pressed; unsigned char clicks; unsigned short x; unsigned short y; } button; }; }; struct mouse_ops { /** * mouse_get_event() - Get a mouse event * * Gets the next available mouse event from the device. This can be a * motion event (mouse movement) or a button event (button press or * release). * * @dev: Mouse device * @event: Returns the mouse event * Returns: 0 if OK, -EAGAIN if no event available, -ENOSYS if not * supported */ int (*get_event)(struct udevice *dev, struct mouse_event *event); /** * set_ptr_visible() - Show or hide the system mouse pointer * * This is used to hide the system pointer when expo is rendering its * own custom mouse pointer. * * @dev: Mouse device * @visible: true to show the pointer, false to hide it * Returns: 0 if OK, -ENOSYS if not supported */ int (*set_ptr_visible)(struct udevice *dev, bool visible); }; #define mouse_get_ops(dev) ((struct mouse_ops *)(dev)->driver->ops) /** * mouse_get_event() - Get a mouse event * * Gets the next available mouse event from the device. This can be a * motion event (mouse movement) or a button event (button press or * release). * * @dev: Mouse device * @event: Returns the mouse event * Returns: 0 if OK, -EAGAIN if no event available, -ENOSYS if not * supported */ int mouse_get_event(struct udevice *dev, struct mouse_event *event); /** * mouse_get_click() - Check if a left mouse button click has occurred * * @dev: Mouse device * @pos: Returns position of click * Returns: 0 if a click has occurred, -EAGAIN if no click pending */ int mouse_get_click(struct udevice *dev, struct vid_pos *pos); /** * mouse_get_pos() - Get the current mouse position * * @dev: Mouse device * @pos: Returns last position * Returns: 0 if position is available, -ve on error */ int mouse_get_pos(struct udevice *dev, struct vid_pos *pos); /** * mouse_set_ptr_visible() - Show or hide the system mouse pointer * * This is used to hide the system pointer when rendering a custom mouse * pointer (e.g., in expo mode). * * @dev: Mouse device * @visible: true to show the pointer, false to hide it * Returns: 0 if OK, -ENOSYS if not supported */ int mouse_set_ptr_visible(struct udevice *dev, bool visible); /** * mouse_set_video() - Set the video device for coordinate scaling * * Sets up the video device in the mouse uclass private data so mouse drivers * can scale coordinates to match the display resolution. * * This also places the mouse in the middle of the display * * @dev: Mouse device * @video_dev: Video device * Returns: 0 if OK, -ve on error */ int mouse_set_video(struct udevice *dev, struct udevice *video_dev); /** * mouse_queue_click_for_test() - Queue a click event for testing * * This is a back-door function for tests to simulate a mouse click at a * specific position. The click will be returned by the next call to * mouse_get_click(). * * @dev: Mouse device * @x: X coordinate of click * @y: Y coordinate of click * Returns: 0 if OK, -ve on error */ int mouse_queue_click_for_test(struct udevice *dev, int x, int y); #endif |