Add build options of ps2_mouse

example_keyboards
tmk 11 years ago
parent d7f663a1ea
commit c6abcb6d89

@ -69,7 +69,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* PS/2 mouse */ /* PS/2 mouse */
#define PS2_MOUSE_DEBUG
#ifdef PS2_USE_BUSYWAIT #ifdef PS2_USE_BUSYWAIT
# define PS2_CLOCK_PORT PORTD # define PS2_CLOCK_PORT PORTD
# define PS2_CLOCK_PIN PIND # define PS2_CLOCK_PIN PIND

@ -22,23 +22,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ps2_mouse.h" #include "ps2_mouse.h"
#include "report.h" #include "report.h"
#include "host.h" #include "host.h"
#include "timer.h"
#define PS2_MOUSE_DEBUG #include "print.h"
#ifdef PS2_MOUSE_DEBUG #include "debug.h"
# include "print.h"
# include "debug.h"
#else
# define print(s)
# define phex(h)
# define phex16(h)
#endif
static report_mouse_t mouse_report = {}; static report_mouse_t mouse_report = {};
static void ps2_mouse_print_raw_data(void); static void print_usb_data(void);
static void ps2_mouse_print_usb_data(void);
/* supports only 3 button mouse at this time */ /* supports only 3 button mouse at this time */
@ -77,10 +69,6 @@ uint8_t ps2_mouse_init(void) {
return 0; return 0;
} }
/* scroll support
* TODO: should be build option
*/
#define PS2_MOUSE_SCROLL_BUTTON 0x04
#define X_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_X_SIGN)) #define X_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_X_SIGN))
#define Y_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_Y_SIGN)) #define Y_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_Y_SIGN))
#define X_IS_OVF (mouse_report.buttons & (1<<PS2_MOUSE_X_OVFLW)) #define X_IS_OVF (mouse_report.buttons & (1<<PS2_MOUSE_X_OVFLW))
@ -107,7 +95,12 @@ void ps2_mouse_task(void)
if (mouse_report.x || mouse_report.y || if (mouse_report.x || mouse_report.y ||
((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) { ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) {
ps2_mouse_print_raw_data(); #ifdef PS2_MOUSE_DEBUG
print("ps2_mouse raw: [");
phex(mouse_report.buttons); print("|");
print_hex8((uint8_t)mouse_report.x); print(" ");
print_hex8((uint8_t)mouse_report.y); print("]\n");
#endif
buttons_prev = mouse_report.buttons; buttons_prev = mouse_report.buttons;
@ -132,37 +125,47 @@ void ps2_mouse_task(void)
mouse_report.y = -mouse_report.y; mouse_report.y = -mouse_report.y;
if ((mouse_report.buttons & PS2_MOUSE_SCROLL_BUTTON) == PS2_MOUSE_SCROLL_BUTTON) { #if PS2_MOUSE_SCROLL_BTN_MASK
if (scroll_state == SCROLL_NONE) scroll_state = SCROLL_BTN; static uint16_t scroll_button_time = 0;
if ((mouse_report.buttons & (PS2_MOUSE_SCROLL_BTN_MASK)) == (PS2_MOUSE_SCROLL_BTN_MASK)) {
if (scroll_state == SCROLL_NONE) {
scroll_button_time = timer_read();
scroll_state = SCROLL_BTN;
}
// doesn't send Scroll Button // doesn't send Scroll Button
mouse_report.buttons &= ~PS2_MOUSE_SCROLL_BUTTON; //mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
if (mouse_report.x || mouse_report.y) { if (mouse_report.x || mouse_report.y) {
scroll_state = SCROLL_SENT; scroll_state = SCROLL_SENT;
mouse_report.v = -mouse_report.y/2; mouse_report.v = -mouse_report.y/(PS2_MOUSE_SCROLL_DIVISOR_V);
mouse_report.h = mouse_report.x/2; mouse_report.h = mouse_report.x/(PS2_MOUSE_SCROLL_DIVISOR_H);
mouse_report.x = 0; mouse_report.x = 0;
mouse_report.y = 0; mouse_report.y = 0;
host_mouse_send(&mouse_report); //host_mouse_send(&mouse_report);
} }
} else if (scroll_state == SCROLL_BTN && }
(mouse_report.buttons & PS2_MOUSE_SCROLL_BUTTON) == 0) { else if ((mouse_report.buttons & (PS2_MOUSE_SCROLL_BTN_MASK)) == 0) {
scroll_state = SCROLL_NONE; #if PS2_MOUSE_SCROLL_BTN_SEND
if (scroll_state == SCROLL_BTN &&
TIMER_DIFF_16(timer_read(), scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) {
// send Scroll Button(down and up at once) when not scrolled // send Scroll Button(down and up at once) when not scrolled
mouse_report.buttons |= PS2_MOUSE_SCROLL_BUTTON; mouse_report.buttons |= (PS2_MOUSE_SCROLL_BTN_MASK);
host_mouse_send(&mouse_report); host_mouse_send(&mouse_report);
_delay_ms(100); _delay_ms(100);
mouse_report.buttons &= ~PS2_MOUSE_SCROLL_BUTTON; mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
host_mouse_send(&mouse_report); }
} else { #endif
scroll_state = SCROLL_NONE; scroll_state = SCROLL_NONE;
}
// doesn't send Scroll Button
mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
#endif
host_mouse_send(&mouse_report); host_mouse_send(&mouse_report);
} print_usb_data();
ps2_mouse_print_usb_data();
} }
// clear report // clear report
mouse_report.x = 0; mouse_report.x = 0;
@ -172,19 +175,10 @@ void ps2_mouse_task(void)
mouse_report.buttons = 0; mouse_report.buttons = 0;
} }
static void ps2_mouse_print_raw_data(void) static void print_usb_data(void)
{
if (!debug_mouse) return;
print("ps2_mouse raw [btn|x y]: [");
phex(mouse_report.buttons); print("|");
print_hex8((uint8_t)mouse_report.x); print(" ");
print_hex8((uint8_t)mouse_report.y); print("]\n");
}
static void ps2_mouse_print_usb_data(void)
{ {
if (!debug_mouse) return; if (!debug_mouse) return;
print("ps2_mouse usb [btn|x y v h]: ["); print("ps2_mouse usb: [");
phex(mouse_report.buttons); print("|"); phex(mouse_report.buttons); print("|");
print_hex8((uint8_t)mouse_report.x); print(" "); print_hex8((uint8_t)mouse_report.x); print(" ");
print_hex8((uint8_t)mouse_report.y); print(" "); print_hex8((uint8_t)mouse_report.y); print(" ");

@ -39,6 +39,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PS2_MOUSE_X_OVFLW 6 #define PS2_MOUSE_X_OVFLW 6
#define PS2_MOUSE_Y_OVFLW 7 #define PS2_MOUSE_Y_OVFLW 7
/*
* Scroll by mouse move with pressing button
*/
/* mouse button to start scrolling; set 0 to disable scroll */
#ifndef PS2_MOUSE_SCROLL_BTN_MASK
#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE)
#endif
/* send button event when button is released within this value(ms); set 0 to disable */
#ifndef PS2_MOUSE_SCROLL_BTN_SEND
#define PS2_MOUSE_SCROLL_BTN_SEND 300
#endif
/* divide virtical and horizontal mouse move by this to convert to scroll move */
#ifndef PS2_MOUSE_SCROLL_DIVISOR_V
#define PS2_MOUSE_SCROLL_DIVISOR_V 2
#endif
#ifndef PS2_MOUSE_SCROLL_DIVISOR_H
#define PS2_MOUSE_SCROLL_DIVISOR_H 2
#endif
uint8_t ps2_mouse_init(void); uint8_t ps2_mouse_init(void);
void ps2_mouse_task(void); void ps2_mouse_task(void);

Loading…
Cancel
Save