Merge branch 'master' into ICPad

Integrating upstream changes into PixelMap modifications
This commit is contained in:
Jacob Alexander 2016-04-19 15:02:01 -07:00
commit 8ed4daa2c6
20 changed files with 531 additions and 178 deletions

View file

@ -309,37 +309,33 @@ static uint8_t sys_ctrl_report_desc[] = {
static uint8_t mouse_report_desc[] = {
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x02, // Usage (Mouse)
0xa1, 0x01, // Collection (Application)
0xA1, 0x01, // Collection (Application)
0x09, 0x02, // Usage (Mouse)
0xa1, 0x02, // Collection (Logical)
0xA1, 0x02, // Collection (Logical)
0x09, 0x01, // Usage (Pointer)
// Buttons (5 bits)
0xa1, 0x00, // Collection (Physical) - Buttons
// Buttons (16 bits)
0xA1, 0x00, // Collection (Physical) - Buttons
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button 1)
0x29, 0x05, // Usage Maximum (Button 5)
0x29, 0x10, // Usage Maximum (Button 16)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1)
0x95, 0x05, // Report Count (5)
0x95, 0x10, // Report Count (16)
0x81, 0x02, // Input (Data,Var,Abs)
// Padding (3 bits)
0x75, 0x03, // Report Size (3)
0x95, 0x01, // Report Count (1)
0x81, 0x03, // Input (Cnst,Var,Abs)
// Pointer (16 bits)
// Pointer (32 bits)
0x05, 0x01, // Usage PAGE (Generic Desktop)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7f, // Logical Maximum (127)
0x75, 0x08, // Report Size (8)
0x16, 0x01, 0x80, // Logical Minimum (-32 767)
0x26, 0xFF, 0x7F, // Logical Maximum (32 767)
0x75, 0x10, // Report Size (16)
0x95, 0x02, // Report Count (2)
0x81, 0x06, // Input (Data,Var,Rel)
/*
// Vertical Wheel
// - Multiplier (2 bits)
0xa1, 0x02, // Collection (Logical)
@ -382,6 +378,7 @@ static uint8_t mouse_report_desc[] = {
0x81, 0x06, // Input (Data,Var,Rel)
0xc0, // End Collection - Horizontal Wheel
*/
0xc0, // End Collection - Buttons
0xc0, // End Collection - Mouse Logical
0xc0 // End Collection - Mouse Application

View file

@ -1,7 +1,7 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
* Modified by Jacob Alexander (2015)
* Modified by Jacob Alexander (2015-2016)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -115,38 +115,78 @@
// ----- Variables -----
// which buttons are currently pressed
uint8_t usb_mouse_buttons_state=0;
static uint8_t transmit_previous_timeout = 0;
static uint16_t usb_mouse_resolution_x=DEFAULT_XRES;
static uint16_t usb_mouse_resolution_y=DEFAULT_YRES;
static uint16_t usb_mouse_position_x=DEFAULT_XRES/2;
static uint16_t usb_mouse_position_y=DEFAULT_YRES/2;
static uint32_t usb_mouse_scale_x=DEFAULT_XSCALE;
static uint32_t usb_mouse_scale_y=DEFAULT_YSCALE;
static uint32_t usb_mouse_offset_x=DEFAULT_XSCALE/2-1;
static uint32_t usb_mouse_offset_y=DEFAULT_YSCALE/2-1;
// which buttons are currently pressed
uint8_t usb_mouse_buttons_state = 0;
static uint16_t usb_mouse_resolution_x = DEFAULT_XRES;
static uint16_t usb_mouse_resolution_y = DEFAULT_YRES;
static uint16_t usb_mouse_position_x = DEFAULT_XRES / 2;
static uint16_t usb_mouse_position_y = DEFAULT_YRES / 2;
static uint32_t usb_mouse_scale_x = DEFAULT_XSCALE;
static uint32_t usb_mouse_scale_y = DEFAULT_YSCALE;
static uint32_t usb_mouse_offset_x = DEFAULT_XSCALE / 2 - 1;
static uint32_t usb_mouse_offset_y = DEFAULT_YSCALE / 2 - 1;
// ----- Functions -----
// Set the mouse buttons. To create a "click", 2 calls are needed,
// one to push the button down and the second to release it
int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right)
// Process pending mouse commands
// XXX Missing mouse movement and wheels
// Proper support will require KLL generation of the USB descriptors
// Similar support will be required for joystick control
void usb_mouse_send()
{
uint8_t mask=0;
uint32_t wait_count = 0;
usb_packet_t *tx_packet;
if (left) mask |= 1;
if (middle) mask |= 4;
if (right) mask |= 2;
usb_mouse_buttons_state = mask;
return usb_mouse_move(0, 0, 0);
// Wait till ready
while ( 1 )
{
if ( !usb_configuration )
{
erro_print("USB not configured...");
return;
}
// Attempt to acquire a USB packet for the mouse endpoint
if ( usb_tx_packet_count( MOUSE_ENDPOINT ) < TX_PACKET_LIMIT )
{
tx_packet = usb_malloc();
if ( tx_packet )
break;
}
if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout )
{
transmit_previous_timeout = 1;
warn_print("USB Transmit Timeout...");
return;
}
yield();
}
transmit_previous_timeout = 0;
// Prepare USB Mouse Packet
// TODO Dynamically generate this code based on KLL requirements
uint16_t *packet_data = (uint16_t*)(&tx_packet->buf[0]);
packet_data[0] = USBMouse_Buttons;
packet_data[1] = USBMouse_Relative_x;
packet_data[2] = USBMouse_Relative_y;
tx_packet->len = 6;
usb_tx( MOUSE_ENDPOINT, tx_packet );
// Clear status and state
USBMouse_Buttons = 0;
USBMouse_Relative_x = 0;
USBMouse_Relative_y = 0;
USBMouse_Changed = 0;
}
static uint8_t transmit_previous_timeout=0;
// Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement.
int usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
{

View file

@ -1,7 +1,7 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
* Modified by Jacob Alexander (2015)
* Modified by Jacob Alexander (2015-2016)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -43,16 +43,11 @@
// ----- Functions -----
// Proces pending mouse commands
void usb_mouse_send();
// TODO - More generic
int usb_mouse_buttons( uint8_t left, uint8_t middle, uint8_t right );
int usb_mouse_move( int8_t x, int8_t y, int8_t wheel );
int usb_mouse_position( uint16_t x, uint16_t y );
void usb_mouse_screen_size( uint16_t width, uint16_t height, uint8_t mac );
extern uint8_t usb_mouse_buttons_state;
// TODO - Move
#define MOUSE_LEFT 1
#define MOUSE_MIDDLE 4
#define MOUSE_RIGHT 2
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)

View file

@ -1,10 +1,10 @@
Name = pjrcUSBCapabilities;
Version = 0.6;
Author = "HaaTa (Jacob Alexander) 2014-2015";
KLL = 0.3c;
Version = 0.8;
Author = "HaaTa (Jacob Alexander) 2014-2016";
KLL = 0.3d;
# Modified Date
Date = 2015-08-21;
Date = 2016-03-21;
# Output capabilities
@ -12,6 +12,7 @@ consCtrlOut => Output_consCtrlSend_capability( consCode : 2 );
noneOut => Output_noneSend_capability();
sysCtrlOut => Output_sysCtrlSend_capability( sysCode : 1 );
usbKeyOut => Output_usbCodeSend_capability( usbCode : 1 );
mouseOut => Output_usbMouse_capability( mouseCode : 2, relative_x : 2, relative_y : 2 );
# Configuration capabilities
kbdProtocolBoot => Output_kbdProtocolBoot_capability();
@ -21,6 +22,12 @@ kbdProtocolNKRO => Output_kbdProtocolNKRO_capability();
keyboardLocale => KeyboardLocale_define;
keyboardLocale = 0;
# Default KRO Mode
# Set to 0 for Boot Mode (6KRO)
# Set to 1 for NKRO Mode (default)
usbProtocol => USBProtocol_define;
usbProtocol = 1;
# Bootloader Mode capability
# XXX
# By default this is disabled on purpose

View file

@ -37,8 +37,12 @@
#include "arm/usb_dev.h"
#include "arm/usb_keyboard.h"
#include "arm/usb_serial.h"
#include "arm/usb_mouse.h"
#endif
// KLL
#include <kll_defs.h>
// Local Includes
#include "output_com.h"
@ -47,14 +51,15 @@
// ----- Macros -----
// Used to build a bitmap lookup table from a byte addressable array
#define byteLookup( byte ) case (( byte ) * ( 8 )): bytePosition = byte; byteShift = 0; break; \
case (( byte ) * ( 8 ) + ( 1 )): bytePosition = byte; byteShift = 1; break; \
case (( byte ) * ( 8 ) + ( 2 )): bytePosition = byte; byteShift = 2; break; \
case (( byte ) * ( 8 ) + ( 3 )): bytePosition = byte; byteShift = 3; break; \
case (( byte ) * ( 8 ) + ( 4 )): bytePosition = byte; byteShift = 4; break; \
case (( byte ) * ( 8 ) + ( 5 )): bytePosition = byte; byteShift = 5; break; \
case (( byte ) * ( 8 ) + ( 6 )): bytePosition = byte; byteShift = 6; break; \
case (( byte ) * ( 8 ) + ( 7 )): bytePosition = byte; byteShift = 7; break
#define byteLookup( byte ) \
case (( byte ) * ( 8 )): bytePosition = byte; byteShift = 0; break; \
case (( byte ) * ( 8 ) + ( 1 )): bytePosition = byte; byteShift = 1; break; \
case (( byte ) * ( 8 ) + ( 2 )): bytePosition = byte; byteShift = 2; break; \
case (( byte ) * ( 8 ) + ( 3 )): bytePosition = byte; byteShift = 3; break; \
case (( byte ) * ( 8 ) + ( 4 )): bytePosition = byte; byteShift = 4; break; \
case (( byte ) * ( 8 ) + ( 5 )): bytePosition = byte; byteShift = 5; break; \
case (( byte ) * ( 8 ) + ( 6 )): bytePosition = byte; byteShift = 6; break; \
case (( byte ) * ( 8 ) + ( 7 )): bytePosition = byte; byteShift = 7; break
@ -111,15 +116,25 @@ uint8_t USBKeys_SentCLI = 0;
// 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
volatile uint8_t USBKeys_LEDs = 0;
// Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed
volatile uint16_t USBMouse_Buttons = 0;
// Relative mouse axis movement, stores pending movement
volatile uint16_t USBMouse_Relative_x = 0;
volatile uint16_t USBMouse_Relative_y = 0;
// Protocol setting from the host.
// 0 - Boot Mode
// 1 - NKRO Mode (Default, unless set by a BIOS or boot interface)
volatile uint8_t USBKeys_Protocol = 1;
volatile uint8_t USBKeys_Protocol = USBProtocol_define;
// Indicate if USB should send update
// OS only needs update if there has been a change in state
USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None;
// Indicate if USB should send update
USBMouseChangeState USBMouse_Changed = 0;
// the idle configuration, how often we send the report to the
// host (ms * 4) even when it hasn't changed
uint8_t USBKeys_Idle_Config = 125;
@ -505,6 +520,63 @@ void Output_flashMode_capability( uint8_t state, uint8_t stateType, uint8_t *arg
Output_firmwareReload();
}
// Sends a mouse command over the USB Output buffer
// XXX This function *will* be changing in the future
// If you use it, be prepared that your .kll files will break in the future (post KLL 0.5)
// Argument #1: USB Mouse Button (16 bit)
// Argument #2: USB X Axis (16 bit) relative
// Argument #3: USB Y Axis (16 bit) relative
void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args )
{
// Display capability name
if ( stateType == 0xFF && state == 0xFF )
{
print("Output_usbMouse(mouseButton,relX,relY)");
return;
}
// Determine which mouse button was sent
// The USB spec defines up to a max of 0xFFFF buttons
// The usual are:
// 1 - Button 1 - (Primary)
// 2 - Button 2 - (Secondary)
// 3 - Button 3 - (Tertiary)
uint16_t mouse_button = *(uint16_t*)(&args[0]);
// X/Y Relative Axis
uint16_t mouse_x = *(uint16_t*)(&args[2]);
uint16_t mouse_y = *(uint16_t*)(&args[4]);
// Adjust for bit shift
uint16_t mouse_button_shift = mouse_button - 1;
// Only send mouse button if in press or hold state
if ( stateType == 0x00 && state == 0x03 ) // Release state
{
// Release
if ( mouse_button )
USBMouse_Buttons &= ~(1 << mouse_button_shift);
}
else
{
// Press or hold
if ( mouse_button )
USBMouse_Buttons |= (1 << mouse_button_shift);
if ( mouse_x )
USBMouse_Relative_x = mouse_x;
if ( mouse_y )
USBMouse_Relative_y = mouse_y;
}
// Trigger updates
if ( mouse_button )
USBMouse_Changed |= USBMouseChangeState_Buttons;
if ( mouse_x || mouse_y )
USBMouse_Changed |= USBMouseChangeState_Relative;
}
// ----- Functions -----
@ -552,6 +624,10 @@ inline void Output_send()
for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ )
USBKeys_Keys[c] = 0;
// Process mouse actions
while ( USBMouse_Changed )
usb_mouse_send();
// Send keypresses while there are pending changes
while ( USBKeys_Changed )
usb_keyboard_send();

View file

@ -56,6 +56,14 @@ typedef enum USBKeyChangeState {
USBKeyChangeState_All = 0x7F,
} USBKeyChangeState;
// Allows for selective USB descriptor pushes
// However, in most cases everything is updated for each packet push
typedef enum USBMouseChangeState {
USBMouseChangeState_None = 0x00,
USBMouseChangeState_Buttons = 0x01,
USBMouseChangeState_Relative = 0x02,
} USBMouseChangeState;
// ----- Variables -----
@ -72,11 +80,16 @@ extern uint16_t USBKeys_ConsCtrl; // 1KRO container for Consumer Contro
extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode
extern volatile uint16_t USBMouse_Buttons; // Bitmask for mouse buttons
extern volatile uint16_t USBMouse_Relative_x;
extern volatile uint16_t USBMouse_Relative_y;
// Misc variables (XXX Some are only properly utilized using AVR)
extern uint8_t USBKeys_Idle_Config;
extern uint8_t USBKeys_Idle_Count;
extern USBKeyChangeState USBKeys_Changed;
extern USBKeyChangeState USBKeys_Changed;
extern USBMouseChangeState USBMouse_Changed;
extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working