00001 /*This file is prepared for Doxygen automatic documentation generation.*/ 00013 00014 /* Copyright (c) 2009 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 * 4. This software may only be redistributed and used in connection with an Atmel 00030 * AVR product. 00031 * 00032 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00033 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00034 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND 00035 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00036 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00037 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00038 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00039 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00040 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00041 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00042 */ 00043 00044 //_____ I N C L U D E S ___________________________________________________ 00045 00046 #include "config.h" 00047 #include "conf_usb.h" 00048 #include "host_mouse_task.h" 00049 #include "modules/usb/host_chap9/usb_host_task.h" 00050 #include "modules/usb/host_chap9/usb_host_enum.h" 00051 #include "lib_mcu/usb/usb_drv.h" 00052 00053 //_____ M A C R O S ________________________________________________________ 00054 00055 #ifndef LOG_STR_CODE 00056 #define LOG_STR_CODE(str) 00057 #else 00058 U8 code log_mouse_connect[]="Mouse Connected"; 00059 #endif 00060 00061 //_____ D E F I N I T I O N S ______________________________________________ 00062 00063 00064 //_____ D E C L A R A T I O N S ____________________________________________ 00065 00066 U8 mouse_connected=0; 00067 00068 U8 pipe_mouse_in; 00069 00076 void host_mouse_task_init(void) 00077 { 00078 Leds_init(); 00079 } 00080 00086 void host_mouse_task(void) 00087 { 00088 U8 i; 00089 S8 new_x,new_y; 00090 00091 //Test HID device connection 00092 if(Is_host_ready()) 00093 { 00094 if(Is_new_device_connection_event()) //Device connection 00095 { 00096 mouse_connected=0; 00097 for(i=0;i<Get_nb_supported_interface();i++) 00098 { 00099 if(Get_class(i)==HID_CLASS && Get_protocol(i)==HID_PROTOCOL_MOUSE) 00100 { 00101 mouse_connected=1; 00102 host_hid_set_idle(); 00103 host_get_hid_repport_descriptor(); 00104 LOG_STR_CODE(log_mouse_connect); 00105 PIPE_MOUSE_IN=host_get_hwd_pipe_nb(Get_ep_addr(i,0)); 00106 Host_select_pipe(PIPE_MOUSE_IN); 00107 Host_continuous_in_mode(); 00108 Host_unfreeze_pipe(); 00109 break; 00110 } 00111 } 00112 } 00113 if(mouse_connected) 00114 { 00115 Host_select_pipe(PIPE_MOUSE_IN); 00116 if(Is_host_in_received()) 00117 { 00118 if(Is_host_stall()==FALSE) 00119 { 00120 i=Host_read_byte(); 00121 new_x=(S8)Host_read_byte(); 00122 new_y=(S8)Host_read_byte(); 00123 00124 if(new_x==0) 00125 { Led0_off(); Led1_off();} 00126 else if(new_x>0) 00127 {Led0_on(); Led1_off();} 00128 else 00129 { Led0_off(); Led1_on();} 00130 00131 if(new_y==0) 00132 { Led2_off(); Led3_off();} 00133 else if(new_y>0) 00134 { Led2_on(); Led3_off();} 00135 else 00136 { Led2_off(); Led3_on();} 00137 } 00138 Host_ack_in_received(); Host_send_in(); 00139 } 00140 if(Is_host_nak_received()) 00141 { 00142 Host_ack_nak_received(); 00143 Led0_off(); Led1_off(); 00144 Led2_off(); Led3_off(); 00145 } 00146 } 00147 } 00148 //Device disconnection... 00149 if(Is_device_disconnection_event()) 00150 { 00151 Leds_off(); 00152 mouse_connected=0; 00153 } 00154 }
1.5.3