]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBHost/USBHostHID/USBHostMouse.cpp
1 /* mbed USBHost Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "USBHostMouse.h"
21 USBHostMouse :: USBHostMouse () {
22 host
= USBHost :: getHostInst ();
26 void USBHostMouse :: init () {
30 onButtonUpdate
= NULL
;
35 dev_connected
= false ;
36 mouse_device_found
= false ;
45 bool USBHostMouse :: connected () {
49 bool USBHostMouse :: connect () {
56 for ( uint8_t i
= 0 ; i
< MAX_DEVICE_CONNECTED
; i
++) {
57 if (( dev
= host
-> getDevice ( i
)) != NULL
) {
59 if ( host
-> enumerate ( dev
, this ))
62 if ( mouse_device_found
) {
64 int_in
= dev
-> getEndpoint ( mouse_intf
, INTERRUPT_ENDPOINT
, IN
);
68 USB_INFO ( "New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]" , dev
-> getVid (), dev
-> getPid (), dev
, mouse_intf
);
69 dev
-> setName ( "Mouse" , mouse_intf
);
70 host
-> registerDriver ( dev
, mouse_intf
, this , & USBHostMouse :: init
);
72 int_in
-> attach ( this , & USBHostMouse :: rxHandler
);
73 len_listen
= int_in
-> getSize ();
74 if ( len_listen
> sizeof ( report
)) {
75 len_listen
= sizeof ( report
);
77 host
-> interruptRead ( dev
, int_in
, report
, len_listen
, false );
88 void USBHostMouse :: rxHandler () {
89 int len_listen
= int_in
-> getSize ();
92 (* onUpdate
)( report
[ 0 ] & 0x07 , report
[ 1 ], report
[ 2 ], report
[ 3 ]);
95 if ( onButtonUpdate
&& ( buttons
!= ( report
[ 0 ] & 0x07 ))) {
96 (* onButtonUpdate
)( report
[ 0 ] & 0x07 );
99 if ( onXUpdate
&& ( x
!= report
[ 1 ])) {
100 (* onXUpdate
)( report
[ 1 ]);
103 if ( onYUpdate
&& ( y
!= report
[ 2 ])) {
104 (* onYUpdate
)( report
[ 2 ]);
107 if ( onZUpdate
&& ( z
!= report
[ 3 ])) {
108 (* onZUpdate
)( report
[ 3 ]);
111 // update mouse state
112 buttons
= report
[ 0 ] & 0x07 ;
117 if ( len_listen
> sizeof ( report
)) {
118 len_listen
= sizeof ( report
);
122 host
-> interruptRead ( dev
, int_in
, report
, len_listen
, false );
125 /*virtual*/ void USBHostMouse :: setVidPid ( uint16_t vid
, uint16_t pid
)
127 // we don't check VID/PID for mouse driver
130 /*virtual*/ bool USBHostMouse :: parseInterface ( uint8_t intf_nb
, uint8_t intf_class
, uint8_t intf_subclass
, uint8_t intf_protocol
) //Must return true if the interface should be parsed
132 if (( mouse_intf
== - 1 ) &&
133 ( intf_class
== HID_CLASS
) &&
134 ( intf_subclass
== 0x01 ) &&
135 ( intf_protocol
== 0x02 )) {
136 mouse_intf
= intf_nb
;
142 /*virtual*/ bool USBHostMouse :: useEndpoint ( uint8_t intf_nb
, ENDPOINT_TYPE type
, ENDPOINT_DIRECTION dir
) //Must return true if the endpoint will be used
144 if ( intf_nb
== mouse_intf
) {
145 if ( type
== INTERRUPT_ENDPOINT
&& dir
== IN
) {
146 mouse_device_found
= true ;