diff options
Diffstat (limited to 'protocol/ps2_mouse.c')
| -rw-r--r-- | protocol/ps2_mouse.c | 86 |
1 files changed, 40 insertions, 46 deletions
diff --git a/protocol/ps2_mouse.c b/protocol/ps2_mouse.c index ff730196c..ea629655f 100644 --- a/protocol/ps2_mouse.c +++ b/protocol/ps2_mouse.c | |||
| @@ -22,23 +22,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 22 | #include "ps2_mouse.h" | 22 | #include "ps2_mouse.h" |
| 23 | #include "report.h" | 23 | #include "report.h" |
| 24 | #include "host.h" | 24 | #include "host.h" |
| 25 | 25 | #include "timer.h" | |
| 26 | #define PS2_MOUSE_DEBUG | 26 | #include "print.h" |
| 27 | #ifdef PS2_MOUSE_DEBUG | 27 | #include "debug.h" |
| 28 | # include "print.h" | ||
| 29 | # include "debug.h" | ||
| 30 | #else | ||
| 31 | # define print(s) | ||
| 32 | # define phex(h) | ||
| 33 | # define phex16(h) | ||
| 34 | #endif | ||
| 35 | 28 | ||
| 36 | 29 | ||
| 37 | static report_mouse_t mouse_report = {}; | 30 | static report_mouse_t mouse_report = {}; |
| 38 | 31 | ||
| 39 | 32 | ||
| 40 | static void ps2_mouse_print_raw_data(void); | 33 | static void print_usb_data(void); |
| 41 | static void ps2_mouse_print_usb_data(void); | ||
| 42 | 34 | ||
| 43 | 35 | ||
| 44 | /* supports only 3 button mouse at this time */ | 36 | /* supports only 3 button mouse at this time */ |
| @@ -77,10 +69,6 @@ uint8_t ps2_mouse_init(void) { | |||
| 77 | return 0; | 69 | return 0; |
| 78 | } | 70 | } |
| 79 | 71 | ||
| 80 | /* scroll support | ||
| 81 | * TODO: should be build option | ||
| 82 | */ | ||
| 83 | #define PS2_MOUSE_SCROLL_BUTTON 0x04 | ||
| 84 | #define X_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_X_SIGN)) | 72 | #define X_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_X_SIGN)) |
| 85 | #define Y_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_Y_SIGN)) | 73 | #define Y_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_Y_SIGN)) |
| 86 | #define X_IS_OVF (mouse_report.buttons & (1<<PS2_MOUSE_X_OVFLW)) | 74 | #define X_IS_OVF (mouse_report.buttons & (1<<PS2_MOUSE_X_OVFLW)) |
| @@ -107,7 +95,12 @@ void ps2_mouse_task(void) | |||
| 107 | if (mouse_report.x || mouse_report.y || | 95 | if (mouse_report.x || mouse_report.y || |
| 108 | ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) { | 96 | ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) { |
| 109 | 97 | ||
| 110 | ps2_mouse_print_raw_data(); | 98 | #ifdef PS2_MOUSE_DEBUG |
| 99 | print("ps2_mouse raw: ["); | ||
| 100 | phex(mouse_report.buttons); print("|"); | ||
| 101 | print_hex8((uint8_t)mouse_report.x); print(" "); | ||
| 102 | print_hex8((uint8_t)mouse_report.y); print("]\n"); | ||
| 103 | #endif | ||
| 111 | 104 | ||
| 112 | buttons_prev = mouse_report.buttons; | 105 | buttons_prev = mouse_report.buttons; |
| 113 | 106 | ||
| @@ -132,37 +125,47 @@ void ps2_mouse_task(void) | |||
| 132 | mouse_report.y = -mouse_report.y; | 125 | mouse_report.y = -mouse_report.y; |
| 133 | 126 | ||
| 134 | 127 | ||
| 135 | if ((mouse_report.buttons & PS2_MOUSE_SCROLL_BUTTON) == PS2_MOUSE_SCROLL_BUTTON) { | 128 | #if PS2_MOUSE_SCROLL_BTN_MASK |
| 136 | if (scroll_state == SCROLL_NONE) scroll_state = SCROLL_BTN; | 129 | static uint16_t scroll_button_time = 0; |
| 130 | if ((mouse_report.buttons & (PS2_MOUSE_SCROLL_BTN_MASK)) == (PS2_MOUSE_SCROLL_BTN_MASK)) { | ||
| 131 | if (scroll_state == SCROLL_NONE) { | ||
| 132 | scroll_button_time = timer_read(); | ||
| 133 | scroll_state = SCROLL_BTN; | ||
| 134 | } | ||
| 137 | 135 | ||
| 138 | // doesn't send Scroll Button | 136 | // doesn't send Scroll Button |
| 139 | mouse_report.buttons &= ~PS2_MOUSE_SCROLL_BUTTON; | 137 | //mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK); |
| 140 | 138 | ||
| 141 | if (mouse_report.x || mouse_report.y) { | 139 | if (mouse_report.x || mouse_report.y) { |
| 142 | scroll_state = SCROLL_SENT; | 140 | scroll_state = SCROLL_SENT; |
| 143 | 141 | ||
| 144 | mouse_report.v = -mouse_report.y/2; | 142 | mouse_report.v = -mouse_report.y/(PS2_MOUSE_SCROLL_DIVISOR_V); |
| 145 | mouse_report.h = mouse_report.x/2; | 143 | mouse_report.h = mouse_report.x/(PS2_MOUSE_SCROLL_DIVISOR_H); |
| 146 | mouse_report.x = 0; | 144 | mouse_report.x = 0; |
| 147 | mouse_report.y = 0; | 145 | mouse_report.y = 0; |
| 146 | //host_mouse_send(&mouse_report); | ||
| 147 | } | ||
| 148 | } | ||
| 149 | else if ((mouse_report.buttons & (PS2_MOUSE_SCROLL_BTN_MASK)) == 0) { | ||
| 150 | #if PS2_MOUSE_SCROLL_BTN_SEND | ||
| 151 | if (scroll_state == SCROLL_BTN && | ||
| 152 | TIMER_DIFF_16(timer_read(), scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) { | ||
| 153 | // send Scroll Button(down and up at once) when not scrolled | ||
| 154 | mouse_report.buttons |= (PS2_MOUSE_SCROLL_BTN_MASK); | ||
| 148 | host_mouse_send(&mouse_report); | 155 | host_mouse_send(&mouse_report); |
| 156 | _delay_ms(100); | ||
| 157 | mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK); | ||
| 149 | } | 158 | } |
| 150 | } else if (scroll_state == SCROLL_BTN && | 159 | #endif |
| 151 | (mouse_report.buttons & PS2_MOUSE_SCROLL_BUTTON) == 0) { | ||
| 152 | scroll_state = SCROLL_NONE; | 160 | scroll_state = SCROLL_NONE; |
| 161 | } | ||
| 162 | // doesn't send Scroll Button | ||
| 163 | mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK); | ||
| 164 | #endif | ||
| 153 | 165 | ||
| 154 | // send Scroll Button(down and up at once) when not scrolled | ||
| 155 | mouse_report.buttons |= PS2_MOUSE_SCROLL_BUTTON; | ||
| 156 | host_mouse_send(&mouse_report); | ||
| 157 | _delay_ms(100); | ||
| 158 | mouse_report.buttons &= ~PS2_MOUSE_SCROLL_BUTTON; | ||
| 159 | host_mouse_send(&mouse_report); | ||
| 160 | } else { | ||
| 161 | scroll_state = SCROLL_NONE; | ||
| 162 | 166 | ||
| 163 | host_mouse_send(&mouse_report); | 167 | host_mouse_send(&mouse_report); |
| 164 | } | 168 | print_usb_data(); |
| 165 | ps2_mouse_print_usb_data(); | ||
| 166 | } | 169 | } |
| 167 | // clear report | 170 | // clear report |
| 168 | mouse_report.x = 0; | 171 | mouse_report.x = 0; |
| @@ -172,19 +175,10 @@ void ps2_mouse_task(void) | |||
| 172 | mouse_report.buttons = 0; | 175 | mouse_report.buttons = 0; |
| 173 | } | 176 | } |
| 174 | 177 | ||
| 175 | static void ps2_mouse_print_raw_data(void) | 178 | static void print_usb_data(void) |
| 176 | { | ||
| 177 | if (!debug_mouse) return; | ||
| 178 | print("ps2_mouse raw [btn|x y]: ["); | ||
| 179 | phex(mouse_report.buttons); print("|"); | ||
| 180 | print_hex8((uint8_t)mouse_report.x); print(" "); | ||
| 181 | print_hex8((uint8_t)mouse_report.y); print("]\n"); | ||
| 182 | } | ||
| 183 | |||
| 184 | static void ps2_mouse_print_usb_data(void) | ||
| 185 | { | 179 | { |
| 186 | if (!debug_mouse) return; | 180 | if (!debug_mouse) return; |
| 187 | print("ps2_mouse usb [btn|x y v h]: ["); | 181 | print("ps2_mouse usb: ["); |
| 188 | phex(mouse_report.buttons); print("|"); | 182 | phex(mouse_report.buttons); print("|"); |
| 189 | print_hex8((uint8_t)mouse_report.x); print(" "); | 183 | print_hex8((uint8_t)mouse_report.x); print(" "); |
| 190 | print_hex8((uint8_t)mouse_report.y); print(" "); | 184 | print_hex8((uint8_t)mouse_report.y); print(" "); |
