diff options
| author | tmk <nobody@nowhere> | 2013-11-02 03:10:49 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-11-02 04:30:08 +0900 |
| commit | 676d94d13791a99751cebf724fd5a56b150f344d (patch) | |
| tree | 5e931d0fbbf3c51272ba80703cd6c58e76c95993 /protocol | |
| parent | 1591764cfbc39e73c6f32e9b805d596379866ff0 (diff) | |
| download | qmk_firmware-676d94d13791a99751cebf724fd5a56b150f344d.tar.gz qmk_firmware-676d94d13791a99751cebf724fd5a56b150f344d.zip | |
Fix PS/2 mouse support
Diffstat (limited to 'protocol')
| -rw-r--r-- | protocol/pjrc.mk | 6 | ||||
| -rw-r--r-- | protocol/ps2_mouse.c | 122 |
2 files changed, 55 insertions, 73 deletions
diff --git a/protocol/pjrc.mk b/protocol/pjrc.mk index 27f908b1c..5a4461382 100644 --- a/protocol/pjrc.mk +++ b/protocol/pjrc.mk | |||
| @@ -7,7 +7,11 @@ SRC += $(PJRC_DIR)/main.c \ | |||
| 7 | $(PJRC_DIR)/usb.c | 7 | $(PJRC_DIR)/usb.c |
| 8 | 8 | ||
| 9 | # Option modules | 9 | # Option modules |
| 10 | ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) | 10 | ifdef MOUSEKEY_ENABLE |
| 11 | SRC += $(PJRC_DIR)/usb_mouse.c | ||
| 12 | endif | ||
| 13 | |||
| 14 | ifdef PS2_MOUSE_ENABLE | ||
| 11 | SRC += $(PJRC_DIR)/usb_mouse.c | 15 | SRC += $(PJRC_DIR)/usb_mouse.c |
| 12 | endif | 16 | endif |
| 13 | 17 | ||
diff --git a/protocol/ps2_mouse.c b/protocol/ps2_mouse.c index f796b2b4d..701d97213 100644 --- a/protocol/ps2_mouse.c +++ b/protocol/ps2_mouse.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | 2 | Copyright 2011,2013 Jun Wako <wakojun@gmail.com> |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
| @@ -32,27 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 32 | # define phex16(h) | 32 | # define phex16(h) |
| 33 | #endif | 33 | #endif |
| 34 | 34 | ||
| 35 | // disable when errors occur 255 times. | ||
| 36 | #define ERROR_RETURN() do { \ | ||
| 37 | if (ps2_error) { \ | ||
| 38 | if (ps2_mouse_error_count < 255) { \ | ||
| 39 | ps2_mouse_error_count++; \ | ||
| 40 | } else { \ | ||
| 41 | ps2_mouse_error_count = 0; \ | ||
| 42 | ps2_mouse_enable = false; \ | ||
| 43 | } \ | ||
| 44 | return ps2_error; \ | ||
| 45 | } \ | ||
| 46 | } while (0) | ||
| 47 | 35 | ||
| 48 | |||
| 49 | /* | ||
| 50 | TODO | ||
| 51 | ---- | ||
| 52 | - Stream mode | ||
| 53 | - Tracpoint command support: needed | ||
| 54 | - Middle button + move = Wheel traslation | ||
| 55 | */ | ||
| 56 | bool ps2_mouse_enable = true; | 36 | bool ps2_mouse_enable = true; |
| 57 | uint8_t ps2_mouse_x = 0; | 37 | uint8_t ps2_mouse_x = 0; |
| 58 | uint8_t ps2_mouse_y = 0; | 38 | uint8_t ps2_mouse_y = 0; |
| @@ -69,85 +49,50 @@ uint8_t ps2_mouse_init(void) { | |||
| 69 | 49 | ||
| 70 | ps2_host_init(); | 50 | ps2_host_init(); |
| 71 | 51 | ||
| 72 | // Reset | 52 | // Not reliable: sometime fail to initialize mouse |
| 73 | rcv = ps2_host_send(0xFF); | ||
| 74 | print("ps2_mouse_init: send 0xFF: "); | ||
| 75 | phex(ps2_error); print("\n"); | ||
| 76 | ERROR_RETURN(); | ||
| 77 | 53 | ||
| 78 | // ACK | 54 | // send Reset |
| 79 | rcv = ps2_host_recv(); | 55 | _delay_ms(1000); // wait for powering up |
| 80 | print("ps2_mouse_init: read ACK: "); | 56 | rcv = ps2_host_send(0xFF); |
| 57 | print("ps2_mouse_init: send Reset: "); | ||
| 81 | phex(rcv); phex(ps2_error); print("\n"); | 58 | phex(rcv); phex(ps2_error); print("\n"); |
| 82 | ERROR_RETURN(); | ||
| 83 | 59 | ||
| 84 | // BAT takes some time | 60 | // read completion code of BAT |
| 85 | _delay_ms(100); | 61 | //_delay_ms(1000); // wait for Basic Assurance Test |
| 86 | rcv = ps2_host_recv(); | 62 | rcv = ps2_host_recv(); |
| 87 | print("ps2_mouse_init: read BAT: "); | 63 | print("ps2_mouse_init: read BAT: "); |
| 88 | phex(rcv); phex(ps2_error); print("\n"); | 64 | phex(rcv); phex(ps2_error); print("\n"); |
| 89 | ERROR_RETURN(); | ||
| 90 | 65 | ||
| 91 | // Device ID | 66 | // read Device ID |
| 92 | rcv = ps2_host_recv(); | 67 | rcv = ps2_host_recv(); |
| 93 | print("ps2_mouse_init: read DevID: "); | 68 | print("ps2_mouse_init: read DevID: "); |
| 94 | phex(rcv); phex(ps2_error); print("\n"); | 69 | phex(rcv); phex(ps2_error); print("\n"); |
| 95 | ERROR_RETURN(); | ||
| 96 | 70 | ||
| 97 | // Enable data reporting | 71 | // send Enable Data Reporting |
| 98 | ps2_host_send(0xF4); | 72 | rcv = ps2_host_send(0xF4); |
| 99 | print("ps2_mouse_init: send 0xF4: "); | 73 | print("ps2_mouse_init: send 0xF4: "); |
| 100 | phex(ps2_error); print("\n"); | ||
| 101 | ERROR_RETURN(); | ||
| 102 | |||
| 103 | // ACK | ||
| 104 | rcv = ps2_host_recv(); | ||
| 105 | print("ps2_mouse_init: read ACK: "); | ||
| 106 | phex(rcv); phex(ps2_error); print("\n"); | 74 | phex(rcv); phex(ps2_error); print("\n"); |
| 107 | ERROR_RETURN(); | ||
| 108 | 75 | ||
| 109 | // Set Remote mode | 76 | // send Set Remote mode |
| 110 | ps2_host_send(0xF0); | 77 | rcv = ps2_host_send(0xF0); |
| 111 | print("ps2_mouse_init: send 0xF0: "); | 78 | print("ps2_mouse_init: send 0xF0: "); |
| 112 | phex(ps2_error); print("\n"); | ||
| 113 | ERROR_RETURN(); | ||
| 114 | |||
| 115 | // ACK | ||
| 116 | rcv = ps2_host_recv(); | ||
| 117 | print("ps2_mouse_init: read ACK: "); | ||
| 118 | phex(rcv); phex(ps2_error); print("\n"); | 79 | phex(rcv); phex(ps2_error); print("\n"); |
| 119 | ERROR_RETURN(); | ||
| 120 | 80 | ||
| 121 | return 0; | 81 | return 0; |
| 122 | } | 82 | } |
| 123 | 83 | ||
| 124 | /* | ||
| 125 | Data format: | ||
| 126 | bit: 7 6 5 4 3 2 1 0 | ||
| 127 | ----------------------------------------------------------------------- | ||
| 128 | 0 btn: Yovflw Xovflw Ysign Xsign 1 Middle Right Left | ||
| 129 | 1 x: X movement(0-255) | ||
| 130 | 2 y: Y movement(0-255) | ||
| 131 | */ | ||
| 132 | uint8_t ps2_mouse_read(void) | 84 | uint8_t ps2_mouse_read(void) |
| 133 | { | 85 | { |
| 134 | uint8_t rcv; | 86 | uint8_t rcv; |
| 135 | 87 | ||
| 136 | if (!ps2_mouse_enable) return 1; | 88 | if (!ps2_mouse_enable) return 1; |
| 137 | 89 | ||
| 138 | ps2_host_send(0xEB); | 90 | rcv = ps2_host_send(0xEB); |
| 139 | ERROR_RETURN(); | ||
| 140 | |||
| 141 | rcv=ps2_host_recv(); | ||
| 142 | ERROR_RETURN(); | ||
| 143 | 91 | ||
| 144 | if(rcv==0xFA) { | 92 | if(rcv==0xFA) { |
| 145 | ps2_mouse_btn = ps2_host_recv(); | 93 | ps2_mouse_btn = ps2_host_recv_response(); |
| 146 | ERROR_RETURN(); | 94 | ps2_mouse_x = ps2_host_recv_response(); |
| 147 | ps2_mouse_x = ps2_host_recv(); | 95 | ps2_mouse_y = ps2_host_recv_response(); |
| 148 | ERROR_RETURN(); | ||
| 149 | ps2_mouse_y = ps2_host_recv(); | ||
| 150 | ERROR_RETURN(); | ||
| 151 | } | 96 | } |
| 152 | return 0; | 97 | return 0; |
| 153 | } | 98 | } |
| @@ -216,3 +161,36 @@ void ps2_mouse_print(void) | |||
| 216 | phex(ps2_mouse_x); print(" "); | 161 | phex(ps2_mouse_x); print(" "); |
| 217 | phex(ps2_mouse_y); print("\n"); | 162 | phex(ps2_mouse_y); print("\n"); |
| 218 | } | 163 | } |
| 164 | |||
| 165 | |||
| 166 | /* PS/2 Mouse Synopsis | ||
| 167 | * http://www.computer-engineering.org/ps2mouse/ | ||
| 168 | * | ||
| 169 | * Command: | ||
| 170 | * 0xFF: Reset | ||
| 171 | * 0xF6: Set Defaults Sampling; rate=100, resolution=4cnt/mm, scaling=1:1, reporting=disabled | ||
| 172 | * 0xF5: Disable Data Reporting | ||
| 173 | * 0xF4: Enable Data Reporting | ||
| 174 | * 0xF3: Set Sample Rate | ||
| 175 | * 0xF2: Get Device ID | ||
| 176 | * 0xF0: Set Remote Mode | ||
| 177 | * 0xEB: Read Data | ||
| 178 | * 0xEA: Set Stream Mode | ||
| 179 | * 0xE9: Status Request | ||
| 180 | * 0xE8: Set Resolution | ||
| 181 | * 0xE7: Set Scaling 2:1 | ||
| 182 | * 0xE6: Set Scaling 1:1 | ||
| 183 | * | ||
| 184 | * Mode: | ||
| 185 | * Stream Mode: devices sends the data when it changs its state | ||
| 186 | * Remote Mode: host polls the data periodically | ||
| 187 | * | ||
| 188 | * This code uses Remote Mode and polls the data with Read Data(0xEB). | ||
| 189 | * | ||
| 190 | * Data format: | ||
| 191 | * byte|7 6 5 4 3 2 1 0 | ||
| 192 | * ----+-------------------------------------------------------------- | ||
| 193 | * 0|Yovflw Xovflw Ysign Xsign 1 Middle Right Left | ||
| 194 | * 1| X movement(0-255) | ||
| 195 | * 2| Y movement(0-255) | ||
| 196 | */ | ||
