diff --git a/Output/TestOut/host.py b/Output/TestOut/host.py index 5a1d385bb..c933a6212 100644 --- a/Output/TestOut/host.py +++ b/Output/TestOut/host.py @@ -2,7 +2,7 @@ Host-Side Python Commands for TestOut Output Module ''' -# Copyright (C) 2016-2018 by Jacob Alexander +# Copyright (C) 2016-2019 by Jacob Alexander # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ import os import sys -from ctypes import POINTER, cast, c_char_p, c_uint8, c_uint16, Structure +from ctypes import POINTER, cast, c_char_p, c_int8, c_int16, c_uint8, c_uint16, Structure import kiilogger @@ -126,6 +126,33 @@ def __repr__( self ): return val +class USBMouse( Structure ): + ''' + USBMouse struct + See Output/USB/output_usb.h + ''' + + _fields_ = [ + ( 'buttons', c_uint16 ), + ( 'relative_x', c_int16 ), + ( 'relative_y', c_int16 ), + ( 'vertwheel', c_int8 ), + ( 'horiwheel', c_int8 ), + ( 'changed', c_uint8 ), + ] + + def __repr__( self ): + val = "(buttons={}, relative_x={}, relative_y={}, vertwheel={}, horiwheel={}, changed={})".format( + self.buttons, + self.relative_x, + self.relative_y, + self.vertwheel, + self.horiwheel, + self.changed, + ) + return val + + ### Classes ### @@ -306,10 +333,17 @@ def keyboard_send( self, args ): def mouse_send( self, args ): ''' - TODO + Callback received when Host-side KLL is ready to send USB mouse commands + + TODO - Not fully implemented ''' + usb_mouse = cast( control.kiibohd.USBMouse_primary, POINTER( USBMouse ) )[0] + logger.warning("mouse_send not implemented") + # Indicate we are done with the buffer + usb_mouse.changed = 0 + def rawio_available( self, args ): ''' Returns the size of rawio_outgoing_buffer diff --git a/Output/TestOut/output_testout.c b/Output/TestOut/output_testout.c index 0ab19c0f2..3f030a6d6 100644 --- a/Output/TestOut/output_testout.c +++ b/Output/TestOut/output_testout.c @@ -100,7 +100,7 @@ inline void TestOut_periodic() { #if enableMouse_define == 1 // Process mouse actions - while ( USBMouse_Changed ) + while ( USBMouse_primary.changed ) { Output_callback( "mouse_send", "" ); } diff --git a/Output/USB/arm/usb_mouse.c b/Output/USB/arm/usb_mouse.c index 0373fe105..4587ac4ed 100644 --- a/Output/USB/arm/usb_mouse.c +++ b/Output/USB/arm/usb_mouse.c @@ -1,7 +1,7 @@ /* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2013 PJRC.COM, LLC. - * Modified by Jacob Alexander (2015-2018) + * Modified by Jacob Alexander (2015-2019) * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -96,12 +96,12 @@ void usb_mouse_send() warn_print("USB Transmit Timeout..."); // Clear status and state - USBMouse_Buttons = 0; - USBMouse_Relative_x = 0; - USBMouse_Relative_y = 0; - USBMouse_VertWheel = 0; - USBMouse_HoriWheel = 0; - USBMouse_Changed = 0; + USBMouse_primary.buttons = 0; + USBMouse_primary.relative_x = 0; + USBMouse_primary.relative_y = 0; + USBMouse_primary.vertwheel = 0; + USBMouse_primary.horiwheel = 0; + USBMouse_primary.changed = 0; return; } yield(); @@ -112,20 +112,20 @@ void usb_mouse_send() // Prepare USB Mouse Packet // TODO (HaaTa): 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] = (uint16_t)USBMouse_Relative_x; - packet_data[2] = (uint16_t)USBMouse_Relative_y; - packet_data[3] = (uint16_t)(USBMouse_VertWheel | (USBMouse_HoriWheel << 8)); + packet_data[0] = USBMouse_primary.buttons; + packet_data[1] = (uint16_t)USBMouse_primary.relative_x; + packet_data[2] = (uint16_t)USBMouse_primary.relative_y; + packet_data[3] = (uint16_t)(USBMouse_primary.vertwheel | (USBMouse_primary.horiwheel << 8)); tx_packet->len = 8; usb_tx( MOUSE_ENDPOINT, tx_packet ); // Clear status and state - USBMouse_Buttons = 0; - USBMouse_Relative_x = 0; - USBMouse_Relative_y = 0; - USBMouse_VertWheel = 0; - USBMouse_HoriWheel = 0; - USBMouse_Changed = 0; + USBMouse_primary.buttons = 0; + USBMouse_primary.relative_x = 0; + USBMouse_primary.relative_y = 0; + USBMouse_primary.vertwheel = 0; + USBMouse_primary.horiwheel = 0; + USBMouse_primary.changed = 0; } #endif diff --git a/Output/USB/output_usb.c b/Output/USB/output_usb.c index 17b5b6de2..06a2da1a9 100644 --- a/Output/USB/output_usb.c +++ b/Output/USB/output_usb.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2018 by Jacob Alexander +/* Copyright (C) 2011-2019 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -122,16 +122,8 @@ volatile uint8_t USBKeys_Sent; volatile uint8_t USBKeys_LEDs; volatile uint8_t USBKeys_LEDs_prev; -// Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed -volatile uint16_t USBMouse_Buttons; - -// Relative mouse axis movement, stores pending movement -volatile int16_t USBMouse_Relative_x; -volatile int16_t USBMouse_Relative_y; - -// Mouse wheel pending action -volatile int8_t USBMouse_VertWheel; -volatile int8_t USBMouse_HoriWheel; +// USBMouse Buffer +volatile USBMouse USBMouse_primary; // Primary mouse send buffer // Protocol setting from the host. // 0 - Boot Mode @@ -140,9 +132,6 @@ volatile uint8_t USBKeys_Protocol = USBProtocol_define; volatile uint8_t USBKeys_Protocol_New = USBProtocol_define; volatile uint8_t USBKeys_Protocol_Change; // New value to set to USBKeys_Protocol if _Change is set -// Indicate if USB should send update -USBMouseChangeState USBMouse_Changed; - // the idle configuration, how often we send the report to the // host (ms * 4) even when it hasn't changed // 0 - Disables @@ -635,23 +624,23 @@ void Output_usbMouse_capability( TriggerMacro *trigger, uint8_t state, uint8_t s // Press/Hold if ( mouse_button ) { - USBMouse_Buttons |= (1 << mouse_button_shift); + USBMouse_primary.buttons |= (1 << mouse_button_shift); } if ( mouse_x ) { - USBMouse_Relative_x = mouse_x; + USBMouse_primary.relative_x = mouse_x; } if ( mouse_y ) { - USBMouse_Relative_y = mouse_y; + USBMouse_primary.relative_y = mouse_y; } break; case CapabilityState_Last: // Release if ( mouse_button ) { - USBMouse_Buttons &= ~(1 << mouse_button_shift); + USBMouse_primary.buttons &= ~(1 << mouse_button_shift); } break; case CapabilityState_Debug: @@ -665,12 +654,12 @@ void Output_usbMouse_capability( TriggerMacro *trigger, uint8_t state, uint8_t s // Trigger updates if ( mouse_button ) { - USBMouse_Changed |= USBMouseChangeState_Buttons; + USBMouse_primary.changed |= USBMouseChangeState_Buttons; } if ( mouse_x || mouse_y ) { - USBMouse_Changed |= USBMouseChangeState_Relative; + USBMouse_primary.changed |= USBMouseChangeState_Relative; } } @@ -694,14 +683,14 @@ void Output_usbMouseWheel_capability( TriggerMacro *trigger, uint8_t state, uint // Press/Hold if ( wheel_vert ) { - USBMouse_VertWheel = wheel_vert; - USBMouse_Changed |= USBMouseChangeState_WheelVert; + USBMouse_primary.vertwheel = wheel_vert; + USBMouse_primary.changed |= USBMouseChangeState_WheelVert; } if ( wheel_hori ) { - USBMouse_HoriWheel = wheel_hori; - USBMouse_Changed |= USBMouseChangeState_WheelHori; + USBMouse_primary.horiwheel = wheel_hori; + USBMouse_primary.changed |= USBMouseChangeState_WheelHori; } break; case CapabilityState_Debug: @@ -733,17 +722,17 @@ void USB_flushBuffers() USBKeys_Sent = 0; // Clear mouse state - USBMouse_Buttons = 0; - USBMouse_Relative_x = 0; - USBMouse_Relative_y = 0; - USBMouse_VertWheel = 0; - USBMouse_HoriWheel = 0; - USBMouse_Changed = 0; + USBMouse_primary.buttons = 0; + USBMouse_primary.relative_x = 0; + USBMouse_primary.relative_y = 0; + USBMouse_primary.vertwheel = 0; + USBMouse_primary.horiwheel = 0; + USBMouse_primary.changed = 0; // Make sure everything actually flushes USBKeys_primary.changed = 1; USBKeys_idle.changed = 1; - USBMouse_Changed = 1; + USBMouse_primary.changed = 1; } @@ -928,7 +917,7 @@ inline void USB_periodic() #if enableMouse_define == 1 // Process mouse actions - while ( USBMouse_Changed ) + while ( USBMouse_primary.changed ) { usb_mouse_send(); } diff --git a/Output/USB/output_usb.h b/Output/USB/output_usb.h index c94218512..ff6d7a113 100644 --- a/Output/USB/output_usb.h +++ b/Output/USB/output_usb.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013-2018 by Jacob Alexander +/* Copyright (C) 2013-2019 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -87,6 +87,24 @@ typedef struct USBKeys { USBKeyChangeState changed; } USBKeys; +// Buffer structure for USB HID mouse output +typedef struct USBMouse { + // Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed + uint16_t buttons; + + // Relative mouse axis movement, stores pending movement + int16_t relative_x; + int16_t relative_y; + + // Mouse wheel pending action + int8_t vertwheel; + int8_t horiwheel; + + // Indicate if USB should send update + // OS only needs update if there has been a change in state + USBMouseChangeState changed; +} USBMouse; + // ----- Variables ----- @@ -104,19 +122,13 @@ extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode extern volatile uint8_t USBKeys_Protocol_New; extern volatile uint8_t USBKeys_Protocol_Change; -extern volatile uint16_t USBMouse_Buttons; // Bitmask for mouse buttons -extern volatile int16_t USBMouse_Relative_x; -extern volatile int16_t USBMouse_Relative_y; -extern volatile int8_t USBMouse_VertWheel; -extern volatile int8_t USBMouse_HoriWheel; +extern volatile USBMouse USBMouse_primary; // Keeps track of the idle timeout refresh (used on Mac OSX) extern volatile uint8_t USBKeys_Idle_Config; extern volatile uint32_t USBKeys_Idle_Expiry; extern volatile uint8_t USBKeys_Idle_Count; // AVR only -extern USBMouseChangeState USBMouse_Changed; - extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working extern uint8_t Output_DebugMode; // 0 - Debug disabled, 1 - Debug enabled, 2 - Extra debug