Browse Source

Mouse extra buttons & horizontal scroll on Teensy 2.0

main
PaulStoffregen 8 years ago
parent
commit
102de8e359
6 changed files with 50 additions and 32 deletions
  1. +10
    -7
      usb_hid/usb.c
  2. +9
    -5
      usb_hid/usb_api.cpp
  3. +6
    -4
      usb_hid/usb_api.h
  4. +10
    -7
      usb_serial_hid/usb.c
  5. +9
    -5
      usb_serial_hid/usb_api.cpp
  6. +6
    -4
      usb_serial_hid/usb_api.h

+ 10
- 7
usb_hid/usb.c View File

@@ -138,24 +138,26 @@ static const uint8_t PROGMEM mouse_hid_report_desc[] = {
0xA1, 0x01, // Collection (Application)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button #1)
0x29, 0x03, // Usage Maximum (Button #3)
0x29, 0x08, // Usage Maximum (Button #8)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x95, 0x03, // Report Count (3)
0x95, 0x08, // Report Count (8)
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data, Variable, Absolute)
0x95, 0x01, // Report Count (1)
0x75, 0x05, // Report Size (5)
0x81, 0x03, // Input (Constant)
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x09, 0x38, // Usage (Wheel)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8),
0x95, 0x02, // Report Count (2),
0x95, 0x03, // Report Count (3),
0x81, 0x06, // Input (Data, Variable, Relative)
0x09, 0x38, // Usage (Wheel)
0x05, 0x0C, // Usage Page (Consumer)
0x0A, 0x38, 0x02, // Usage (AC Pan)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8),
0x95, 0x01, // Report Count (1),
0x81, 0x06, // Input (Data, Variable, Relative)
0xC0 // End Collection
@@ -862,6 +864,7 @@ ISR(USB_COM_vect)
UEDATX = 0;
UEDATX = 0;
UEDATX = 0;
UEDATX = 0;
usb_send_in();
return;
}

+ 9
- 5
usb_hid/usb_api.cpp View File

@@ -545,7 +545,7 @@ void usb_keyboard_class::keymedia_send(void)



void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel)
void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel, int8_t horiz)
{
uint8_t intr_state, timeout;

@@ -553,6 +553,7 @@ void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel)
if (x == -128) x = -127;
if (y == -128) y = -127;
if (wheel == -128) wheel = -127;
if (horiz == -128) horiz = -127;
intr_state = SREG;
cli();
UENUM = MOUSE_ENDPOINT;
@@ -574,30 +575,33 @@ void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel)
UEDATX = x;
UEDATX = y;
UEDATX = wheel;
UEDATX = horiz;
UEINTX = 0x3A;
SREG = intr_state;
}

void usb_mouse_class::click(uint8_t b)
{
mouse_buttons = (b & 7);
mouse_buttons = b;
move(0, 0);
mouse_buttons = 0;
move(0, 0);
}

void usb_mouse_class::scroll(int8_t wheel)
void usb_mouse_class::scroll(int8_t wheel, int8_t horiz)
{
move(0, 0, wheel);
move(0, 0, wheel, horiz);
}

void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right)
void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward)
{
uint8_t mask=0;

if (left) mask |= 1;
if (middle) mask |= 4;
if (right) mask |= 2;
if (back) mask |= 8;
if (forward) mask |= 16;
mouse_buttons = mask;
move(0, 0);
}

+ 6
- 4
usb_hid/usb_api.h View File

@@ -58,17 +58,19 @@ extern usb_keyboard_class Keyboard;
#define MOUSE_LEFT 1
#define MOUSE_MIDDLE 4
#define MOUSE_RIGHT 2
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
#define MOUSE_BACK 8
#define MOUSE_FORWARD 16
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_BACK | MOUSE_FORWARD)

class usb_mouse_class
{
public:
void begin(void) { }
void end(void) { }
void move(int8_t x, int8_t y, int8_t wheel=0);
void move(int8_t x, int8_t y, int8_t wheel=0, int8_t horiz=0);
void click(uint8_t b = MOUSE_LEFT);
void scroll(int8_t wheel);
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0);
void scroll(int8_t wheel, int8_t horiz=0);
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0);
void press(uint8_t b = MOUSE_LEFT);
void release(uint8_t b = MOUSE_LEFT);
bool isPressed(uint8_t b = MOUSE_ALL);

+ 10
- 7
usb_serial_hid/usb.c View File

@@ -126,24 +126,26 @@ static const uint8_t PROGMEM mouse_hid_report_desc[] = {
0xA1, 0x01, // Collection (Application)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button #1)
0x29, 0x03, // Usage Maximum (Button #3)
0x29, 0x08, // Usage Maximum (Button #8)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x95, 0x03, // Report Count (3)
0x95, 0x08, // Report Count (8)
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data, Variable, Absolute)
0x95, 0x01, // Report Count (1)
0x75, 0x05, // Report Size (5)
0x81, 0x03, // Input (Constant)
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x09, 0x38, // Usage (Wheel)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8),
0x95, 0x02, // Report Count (2),
0x95, 0x03, // Report Count (3),
0x81, 0x06, // Input (Data, Variable, Relative)
0x09, 0x38, // Usage (Wheel)
0x05, 0x0C, // Usage Page (Consumer)
0x0A, 0x38, 0x02, // Usage (AC Pan)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8),
0x95, 0x01, // Report Count (1),
0x81, 0x06, // Input (Data, Variable, Relative)
0xC0 // End Collection
@@ -884,6 +886,7 @@ ISR(USB_COM_vect)
UEDATX = 0;
UEDATX = 0;
UEDATX = 0;
UEDATX = 0;
usb_send_in();
return;
}

+ 9
- 5
usb_serial_hid/usb_api.cpp View File

@@ -784,7 +784,7 @@ void usb_keyboard_class::releaseAll(void)



void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel)
void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel, int8_t horiz)
{
uint8_t intr_state, timeout;

@@ -792,6 +792,7 @@ void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel)
if (x == -128) x = -127;
if (y == -128) y = -127;
if (wheel == -128) wheel = -127;
if (horiz == -128) horiz = -127;
intr_state = SREG;
cli();
UENUM = MOUSE_ENDPOINT;
@@ -813,30 +814,33 @@ void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel)
UEDATX = x;
UEDATX = y;
UEDATX = wheel;
UEDATX = horiz;
UEINTX = 0x3A;
SREG = intr_state;
}

void usb_mouse_class::click(uint8_t b)
{
mouse_buttons = (b & 7);
mouse_buttons = b;
move(0, 0);
mouse_buttons = 0;
move(0, 0);
}

void usb_mouse_class::scroll(int8_t wheel)
void usb_mouse_class::scroll(int8_t wheel, int8_t horiz)
{
move(0, 0, wheel);
move(0, 0, wheel, horiz);
}

void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right)
void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward)
{
uint8_t mask=0;

if (left) mask |= 1;
if (middle) mask |= 4;
if (right) mask |= 2;
if (back) mask |= 8;
if (forward) mask |= 16;
mouse_buttons = mask;
move(0, 0);
}

+ 6
- 4
usb_serial_hid/usb_api.h View File

@@ -87,17 +87,19 @@ extern usb_keyboard_class Keyboard;
#define MOUSE_LEFT 1
#define MOUSE_MIDDLE 4
#define MOUSE_RIGHT 2
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
#define MOUSE_BACK 8
#define MOUSE_FORWARD 16
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_BACK | MOUSE_FORWARD)

class usb_mouse_class
{
public:
void begin(void) { }
void end(void) { }
void move(int8_t x, int8_t y, int8_t wheel=0);
void move(int8_t x, int8_t y, int8_t wheel=0, int8_t horiz=0);
void click(uint8_t b = MOUSE_LEFT);
void scroll(int8_t wheel);
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0);
void scroll(int8_t wheel, int8_t horiz=0);
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0);
void press(uint8_t b = MOUSE_LEFT);
void release(uint8_t b = MOUSE_LEFT);
bool isPressed(uint8_t b = MOUSE_ALL);

Loading…
Cancel
Save