Browse Source

Add build options of ps2_mouse

tags/v1.9
tmk 10 years ago
parent
commit
c6abcb6d89
3 changed files with 61 additions and 47 deletions
  1. 0
    1
      keyboard/onekey/config.h
  2. 40
    46
      protocol/ps2_mouse.c
  3. 21
    0
      protocol/ps2_mouse.h

+ 0
- 1
keyboard/onekey/config.h View File





/* 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

+ 40
- 46
protocol/ps2_mouse.c View File

#include "ps2_mouse.h" #include "ps2_mouse.h"
#include "report.h" #include "report.h"
#include "host.h" #include "host.h"

#define PS2_MOUSE_DEBUG
#ifdef PS2_MOUSE_DEBUG
# include "print.h"
# include "debug.h"
#else
# define print(s)
# define phex(h)
# define phex16(h)
#endif
#include "timer.h"
#include "print.h"
#include "debug.h"




static report_mouse_t mouse_report = {}; static report_mouse_t mouse_report = {};




static void ps2_mouse_print_raw_data(void);
static void ps2_mouse_print_usb_data(void);
static void print_usb_data(void);




/* supports only 3 button mouse at this time */ /* supports only 3 button mouse at this time */
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))
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;


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 (scroll_state == SCROLL_NONE) scroll_state = SCROLL_BTN;
#if PS2_MOUSE_SCROLL_BTN_MASK
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.h = mouse_report.x/2;
mouse_report.v = -mouse_report.y/(PS2_MOUSE_SCROLL_DIVISOR_V);
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);
}
}
else if ((mouse_report.buttons & (PS2_MOUSE_SCROLL_BTN_MASK)) == 0) {
#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
mouse_report.buttons |= (PS2_MOUSE_SCROLL_BTN_MASK);
host_mouse_send(&mouse_report); host_mouse_send(&mouse_report);
_delay_ms(100);
mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
} }
} else if (scroll_state == SCROLL_BTN &&
(mouse_report.buttons & PS2_MOUSE_SCROLL_BUTTON) == 0) {
#endif
scroll_state = SCROLL_NONE; scroll_state = SCROLL_NONE;
}
// doesn't send Scroll Button
mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
#endif


// send Scroll Button(down and up at once) when not scrolled
mouse_report.buttons |= PS2_MOUSE_SCROLL_BUTTON;
host_mouse_send(&mouse_report);
_delay_ms(100);
mouse_report.buttons &= ~PS2_MOUSE_SCROLL_BUTTON;
host_mouse_send(&mouse_report);
} else {
scroll_state = SCROLL_NONE;


host_mouse_send(&mouse_report);
}
ps2_mouse_print_usb_data();
host_mouse_send(&mouse_report);
print_usb_data();
} }
// clear report // clear report
mouse_report.x = 0; mouse_report.x = 0;
mouse_report.buttons = 0; mouse_report.buttons = 0;
} }


static void ps2_mouse_print_raw_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)
static void 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(" ");

+ 21
- 0
protocol/ps2_mouse.h View File

#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