00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00013 00014 /* Copyright (c) 2007, Atmel Corporation All rights reserved. 00015 * 00016 * Redistribution and use in source and binary forms, with or without 00017 * modification, are permitted provided that the following conditions are met: 00018 * 00019 * 1. Redistributions of source code must retain the above copyright notice, 00020 * this list of conditions and the following disclaimer. 00021 * 00022 * 2. Redistributions in binary form must reproduce the above copyright notice, 00023 * this list of conditions and the following disclaimer in the documentation 00024 * and/or other materials provided with the distribution. 00025 * 00026 * 3. The name of ATMEL may not be used to endorse or promote products derived 00027 * from this software without specific prior written permission. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED 00030 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00031 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND 00032 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00033 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00034 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00035 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00036 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00037 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00038 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 */ 00040 00041 //_____ I N C L U D E S ___________________________________________________ 00042 00043 #include "config.h" 00044 #include "conf_usb.h" 00045 #include "host_mouse_task.h" 00046 #include "modules/usb/host_chap9/usb_host_task.h" 00047 #include "modules/usb/host_chap9/usb_host_enum.h" 00048 #include "lib_mcu/usb/usb_drv.h" 00049 00050 //_____ M A C R O S ________________________________________________________ 00051 00052 #ifndef LOG_STR_CODE 00053 #define LOG_STR_CODE(str) 00054 #else 00055 U8 code log_mouse_connect[]="Mouse Connected"; 00056 #endif 00057 00058 //_____ D E F I N I T I O N S ______________________________________________ 00059 00060 00061 //_____ D E C L A R A T I O N S ____________________________________________ 00062 00063 U8 mouse_connected=0; 00064 00065 U8 pipe_mouse_in; 00066 00073 void host_mouse_task_init(void) 00074 { 00075 Leds_init(); 00076 } 00077 00083 void host_mouse_task(void) 00084 { 00085 U8 i; 00086 S8 new_x,new_y; 00087 00088 //Test HID device connection 00089 if(Is_host_ready()) 00090 { 00091 if(Is_new_device_connection_event()) //Device connection 00092 { 00093 mouse_connected=0; 00094 for(i=0;i<Get_nb_supported_interface();i++) 00095 { 00096 if(Get_class(i)==HID_CLASS && Get_protocol(i)==HID_PROTOCOL_MOUSE) 00097 { 00098 mouse_connected=1; 00099 host_hid_set_idle(); 00100 host_get_hid_repport_descriptor(); 00101 LOG_STR_CODE(log_mouse_connect); 00102 PIPE_MOUSE_IN=host_get_hwd_pipe_nb(Get_ep_addr(i,0)); 00103 Host_select_pipe(PIPE_MOUSE_IN); 00104 Host_continuous_in_mode(); 00105 Host_unfreeze_pipe(); 00106 break; 00107 } 00108 } 00109 } 00110 if(mouse_connected) 00111 { 00112 Host_select_pipe(PIPE_MOUSE_IN); 00113 if(Is_host_in_received()) 00114 { 00115 if(Is_host_stall()==FALSE) 00116 { 00117 i=Host_read_byte(); 00118 new_x=(S8)Host_read_byte(); 00119 new_y=(S8)Host_read_byte(); 00120 00121 if(new_x==0) 00122 { Led0_off(); Led1_off();} 00123 else if(new_x>0) 00124 {Led0_on(); Led1_off();} 00125 else 00126 { Led0_off(); Led1_on();} 00127 00128 if(new_y==0) 00129 { Led2_off(); Led3_off();} 00130 else if(new_y>0) 00131 { Led2_on(); Led3_off();} 00132 else 00133 { Led2_off(); Led3_on();} 00134 } 00135 Host_ack_in_received(); Host_send_in(); 00136 } 00137 if(Is_host_nak_received()) 00138 { 00139 Host_ack_nak_received(); 00140 Led0_off(); Led1_off(); 00141 Led2_off(); Led3_off(); 00142 } 00143 00144 } 00145 } 00146 //Device disconnection... 00147 if(Is_device_disconnection_event()) 00148 { 00149 Leds_off(); 00150 mouse_connected=0; 00151 } 00152 }
1.5.3