Skip to content

Commit fd279ef

Browse files
committed
Fixing broken unit test due to recent USB flush fix
- Unit test was expecting changed flag to be unset to 0 by the Python interface
1 parent e29ad33 commit fd279ef

File tree

5 files changed

+96
-61
lines changed

5 files changed

+96
-61
lines changed

Diff for: Output/TestOut/host.py

+37-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Host-Side Python Commands for TestOut Output Module
33
'''
44

5-
# Copyright (C) 2016-2018 by Jacob Alexander
5+
# Copyright (C) 2016-2019 by Jacob Alexander
66
#
77
# This file is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
2424
import os
2525
import sys
2626

27-
from ctypes import POINTER, cast, c_char_p, c_uint8, c_uint16, Structure
27+
from ctypes import POINTER, cast, c_char_p, c_int8, c_int16, c_uint8, c_uint16, Structure
2828

2929
import kiilogger
3030

@@ -126,6 +126,33 @@ def __repr__( self ):
126126
return val
127127

128128

129+
class USBMouse( Structure ):
130+
'''
131+
USBMouse struct
132+
See Output/USB/output_usb.h
133+
'''
134+
135+
_fields_ = [
136+
( 'buttons', c_uint16 ),
137+
( 'relative_x', c_int16 ),
138+
( 'relative_y', c_int16 ),
139+
( 'vertwheel', c_int8 ),
140+
( 'horiwheel', c_int8 ),
141+
( 'changed', c_uint8 ),
142+
]
143+
144+
def __repr__( self ):
145+
val = "(buttons={}, relative_x={}, relative_y={}, vertwheel={}, horiwheel={}, changed={})".format(
146+
self.buttons,
147+
self.relative_x,
148+
self.relative_y,
149+
self.vertwheel,
150+
self.horiwheel,
151+
self.changed,
152+
)
153+
return val
154+
155+
129156

130157
### Classes ###
131158

@@ -306,10 +333,17 @@ def keyboard_send( self, args ):
306333

307334
def mouse_send( self, args ):
308335
'''
309-
TODO
336+
Callback received when Host-side KLL is ready to send USB mouse commands
337+
338+
TODO - Not fully implemented
310339
'''
340+
usb_mouse = cast( control.kiibohd.USBMouse_primary, POINTER( USBMouse ) )[0]
341+
311342
logger.warning("mouse_send not implemented")
312343

344+
# Indicate we are done with the buffer
345+
usb_mouse.changed = 0
346+
313347
def rawio_available( self, args ):
314348
'''
315349
Returns the size of rawio_outgoing_buffer

Diff for: Output/TestOut/output_testout.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ inline void TestOut_periodic()
100100
{
101101
#if enableMouse_define == 1
102102
// Process mouse actions
103-
while ( USBMouse_Changed )
103+
while ( USBMouse_primary.changed )
104104
{
105105
Output_callback( "mouse_send", "" );
106106
}

Diff for: Output/USB/arm/usb_mouse.c

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Teensyduino Core Library
22
* http://www.pjrc.com/teensy/
33
* Copyright (c) 2013 PJRC.COM, LLC.
4-
* Modified by Jacob Alexander (2015-2018)
4+
* Modified by Jacob Alexander (2015-2019)
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining
77
* a copy of this software and associated documentation files (the
@@ -96,12 +96,12 @@ void usb_mouse_send()
9696
warn_print("USB Transmit Timeout...");
9797

9898
// Clear status and state
99-
USBMouse_Buttons = 0;
100-
USBMouse_Relative_x = 0;
101-
USBMouse_Relative_y = 0;
102-
USBMouse_VertWheel = 0;
103-
USBMouse_HoriWheel = 0;
104-
USBMouse_Changed = 0;
99+
USBMouse_primary.buttons = 0;
100+
USBMouse_primary.relative_x = 0;
101+
USBMouse_primary.relative_y = 0;
102+
USBMouse_primary.vertwheel = 0;
103+
USBMouse_primary.horiwheel = 0;
104+
USBMouse_primary.changed = 0;
105105
return;
106106
}
107107
yield();
@@ -112,20 +112,20 @@ void usb_mouse_send()
112112
// Prepare USB Mouse Packet
113113
// TODO (HaaTa): Dynamically generate this code based on KLL requirements
114114
uint16_t *packet_data = (uint16_t*)(&tx_packet->buf[0]);
115-
packet_data[0] = USBMouse_Buttons;
116-
packet_data[1] = (uint16_t)USBMouse_Relative_x;
117-
packet_data[2] = (uint16_t)USBMouse_Relative_y;
118-
packet_data[3] = (uint16_t)(USBMouse_VertWheel | (USBMouse_HoriWheel << 8));
115+
packet_data[0] = USBMouse_primary.buttons;
116+
packet_data[1] = (uint16_t)USBMouse_primary.relative_x;
117+
packet_data[2] = (uint16_t)USBMouse_primary.relative_y;
118+
packet_data[3] = (uint16_t)(USBMouse_primary.vertwheel | (USBMouse_primary.horiwheel << 8));
119119
tx_packet->len = 8;
120120
usb_tx( MOUSE_ENDPOINT, tx_packet );
121121

122122
// Clear status and state
123-
USBMouse_Buttons = 0;
124-
USBMouse_Relative_x = 0;
125-
USBMouse_Relative_y = 0;
126-
USBMouse_VertWheel = 0;
127-
USBMouse_HoriWheel = 0;
128-
USBMouse_Changed = 0;
123+
USBMouse_primary.buttons = 0;
124+
USBMouse_primary.relative_x = 0;
125+
USBMouse_primary.relative_y = 0;
126+
USBMouse_primary.vertwheel = 0;
127+
USBMouse_primary.horiwheel = 0;
128+
USBMouse_primary.changed = 0;
129129
}
130130
#endif
131131

Diff for: Output/USB/output_usb.c

+21-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2011-2018 by Jacob Alexander
1+
/* Copyright (C) 2011-2019 by Jacob Alexander
22
*
33
* Permission is hereby granted, free of charge, to any person obtaining a copy
44
* of this software and associated documentation files (the "Software"), to deal
@@ -122,16 +122,8 @@ volatile uint8_t USBKeys_Sent;
122122
volatile uint8_t USBKeys_LEDs;
123123
volatile uint8_t USBKeys_LEDs_prev;
124124

125-
// Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed
126-
volatile uint16_t USBMouse_Buttons;
127-
128-
// Relative mouse axis movement, stores pending movement
129-
volatile int16_t USBMouse_Relative_x;
130-
volatile int16_t USBMouse_Relative_y;
131-
132-
// Mouse wheel pending action
133-
volatile int8_t USBMouse_VertWheel;
134-
volatile int8_t USBMouse_HoriWheel;
125+
// USBMouse Buffer
126+
volatile USBMouse USBMouse_primary; // Primary mouse send buffer
135127

136128
// Protocol setting from the host.
137129
// 0 - Boot Mode
@@ -140,9 +132,6 @@ volatile uint8_t USBKeys_Protocol = USBProtocol_define;
140132
volatile uint8_t USBKeys_Protocol_New = USBProtocol_define;
141133
volatile uint8_t USBKeys_Protocol_Change; // New value to set to USBKeys_Protocol if _Change is set
142134

143-
// Indicate if USB should send update
144-
USBMouseChangeState USBMouse_Changed;
145-
146135
// the idle configuration, how often we send the report to the
147136
// host (ms * 4) even when it hasn't changed
148137
// 0 - Disables
@@ -635,23 +624,23 @@ void Output_usbMouse_capability( TriggerMacro *trigger, uint8_t state, uint8_t s
635624
// Press/Hold
636625
if ( mouse_button )
637626
{
638-
USBMouse_Buttons |= (1 << mouse_button_shift);
627+
USBMouse_primary.buttons |= (1 << mouse_button_shift);
639628
}
640629

641630
if ( mouse_x )
642631
{
643-
USBMouse_Relative_x = mouse_x;
632+
USBMouse_primary.relative_x = mouse_x;
644633
}
645634
if ( mouse_y )
646635
{
647-
USBMouse_Relative_y = mouse_y;
636+
USBMouse_primary.relative_y = mouse_y;
648637
}
649638
break;
650639
case CapabilityState_Last:
651640
// Release
652641
if ( mouse_button )
653642
{
654-
USBMouse_Buttons &= ~(1 << mouse_button_shift);
643+
USBMouse_primary.buttons &= ~(1 << mouse_button_shift);
655644
}
656645
break;
657646
case CapabilityState_Debug:
@@ -665,12 +654,12 @@ void Output_usbMouse_capability( TriggerMacro *trigger, uint8_t state, uint8_t s
665654
// Trigger updates
666655
if ( mouse_button )
667656
{
668-
USBMouse_Changed |= USBMouseChangeState_Buttons;
657+
USBMouse_primary.changed |= USBMouseChangeState_Buttons;
669658
}
670659

671660
if ( mouse_x || mouse_y )
672661
{
673-
USBMouse_Changed |= USBMouseChangeState_Relative;
662+
USBMouse_primary.changed |= USBMouseChangeState_Relative;
674663
}
675664
}
676665

@@ -694,14 +683,14 @@ void Output_usbMouseWheel_capability( TriggerMacro *trigger, uint8_t state, uint
694683
// Press/Hold
695684
if ( wheel_vert )
696685
{
697-
USBMouse_VertWheel = wheel_vert;
698-
USBMouse_Changed |= USBMouseChangeState_WheelVert;
686+
USBMouse_primary.vertwheel = wheel_vert;
687+
USBMouse_primary.changed |= USBMouseChangeState_WheelVert;
699688
}
700689

701690
if ( wheel_hori )
702691
{
703-
USBMouse_HoriWheel = wheel_hori;
704-
USBMouse_Changed |= USBMouseChangeState_WheelHori;
692+
USBMouse_primary.horiwheel = wheel_hori;
693+
USBMouse_primary.changed |= USBMouseChangeState_WheelHori;
705694
}
706695
break;
707696
case CapabilityState_Debug:
@@ -733,17 +722,17 @@ void USB_flushBuffers()
733722
USBKeys_Sent = 0;
734723

735724
// Clear mouse state
736-
USBMouse_Buttons = 0;
737-
USBMouse_Relative_x = 0;
738-
USBMouse_Relative_y = 0;
739-
USBMouse_VertWheel = 0;
740-
USBMouse_HoriWheel = 0;
741-
USBMouse_Changed = 0;
725+
USBMouse_primary.buttons = 0;
726+
USBMouse_primary.relative_x = 0;
727+
USBMouse_primary.relative_y = 0;
728+
USBMouse_primary.vertwheel = 0;
729+
USBMouse_primary.horiwheel = 0;
730+
USBMouse_primary.changed = 0;
742731

743732
// Make sure everything actually flushes
744733
USBKeys_primary.changed = 1;
745734
USBKeys_idle.changed = 1;
746-
USBMouse_Changed = 1;
735+
USBMouse_primary.changed = 1;
747736
}
748737

749738

@@ -928,7 +917,7 @@ inline void USB_periodic()
928917

929918
#if enableMouse_define == 1
930919
// Process mouse actions
931-
while ( USBMouse_Changed )
920+
while ( USBMouse_primary.changed )
932921
{
933922
usb_mouse_send();
934923
}

Diff for: Output/USB/output_usb.h

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2013-2018 by Jacob Alexander
1+
/* Copyright (C) 2013-2019 by Jacob Alexander
22
*
33
* Permission is hereby granted, free of charge, to any person obtaining a copy
44
* of this software and associated documentation files (the "Software"), to deal
@@ -87,6 +87,24 @@ typedef struct USBKeys {
8787
USBKeyChangeState changed;
8888
} USBKeys;
8989

90+
// Buffer structure for USB HID mouse output
91+
typedef struct USBMouse {
92+
// Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed
93+
uint16_t buttons;
94+
95+
// Relative mouse axis movement, stores pending movement
96+
int16_t relative_x;
97+
int16_t relative_y;
98+
99+
// Mouse wheel pending action
100+
int8_t vertwheel;
101+
int8_t horiwheel;
102+
103+
// Indicate if USB should send update
104+
// OS only needs update if there has been a change in state
105+
USBMouseChangeState changed;
106+
} USBMouse;
107+
90108

91109

92110
// ----- Variables -----
@@ -104,19 +122,13 @@ extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode
104122
extern volatile uint8_t USBKeys_Protocol_New;
105123
extern volatile uint8_t USBKeys_Protocol_Change;
106124

107-
extern volatile uint16_t USBMouse_Buttons; // Bitmask for mouse buttons
108-
extern volatile int16_t USBMouse_Relative_x;
109-
extern volatile int16_t USBMouse_Relative_y;
110-
extern volatile int8_t USBMouse_VertWheel;
111-
extern volatile int8_t USBMouse_HoriWheel;
125+
extern volatile USBMouse USBMouse_primary;
112126

113127
// Keeps track of the idle timeout refresh (used on Mac OSX)
114128
extern volatile uint8_t USBKeys_Idle_Config;
115129
extern volatile uint32_t USBKeys_Idle_Expiry;
116130
extern volatile uint8_t USBKeys_Idle_Count; // AVR only
117131

118-
extern USBMouseChangeState USBMouse_Changed;
119-
120132
extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working
121133

122134
extern uint8_t Output_DebugMode; // 0 - Debug disabled, 1 - Debug enabled, 2 - Extra debug

0 commit comments

Comments
 (0)