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 "hid_task.h" 00046 #include "lib_mcu/usb/usb_drv.h" 00047 #include "usb_descriptors.h" 00048 #include "modules/usb/device_chap9/usb_standard_request.h" 00049 #include "usb_specific_request.h" 00050 #include "lib_mcu/util/start_boot.h" 00051 00052 00053 00054 //_____ M A C R O S ________________________________________________________ 00055 00056 00057 //_____ D E F I N I T I O N S ______________________________________________ 00058 00059 00060 //_____ D E C L A R A T I O N S ____________________________________________ 00061 00062 volatile U8 cpt_sof=0; 00063 extern U8 jump_bootloader; 00064 U8 g_last_joy =0; 00065 00066 00067 void hid_report_out (void); 00068 void hid_report_in (void); 00069 00072 void hid_task_init(void) 00073 { 00074 Leds_init(); 00075 Joy_init(); 00076 } 00077 00081 void hid_task(void) 00082 { 00083 if(!Is_device_enumerated()) // Check USB HID is enumerated 00084 return; 00085 00086 hid_report_out(); 00087 hid_report_in(); 00088 } 00089 00090 00093 void hid_report_out(void) 00094 { 00095 Usb_select_endpoint(EP_HID_OUT); 00096 if(Is_usb_receive_out()) 00097 { 00098 //* Read report from HID Generic Demo 00099 U8 led_state; 00100 U8 led_number; 00101 led_state = Usb_read_byte()&0x0F; // RepportOUT[0] is LEDS value 00102 led_number = Usb_read_byte()&0x0F; 00103 switch (led_number) 00104 { 00105 case 1: 00106 if(led_state) 00107 { Led0_on(); } 00108 else {Led0_off();} 00109 break; 00110 case 2: 00111 if(led_state) 00112 { Led1_on(); } 00113 else {Led1_off();} 00114 break; 00115 case 3: 00116 if(led_state) 00117 { Led2_on(); } 00118 else {Led2_off();} 00119 break; 00120 case 4: 00121 if(led_state) 00122 { Led3_on(); } 00123 else {Led3_off();} 00124 break; 00125 } 00126 Usb_ack_receive_out(); 00127 } 00128 00129 //** Check if we received DFU mode command from host 00130 if(jump_bootloader) 00131 { 00132 U32 volatile tempo; 00133 Leds_off(); 00134 Usb_detach(); // Detach actual generic HID application 00135 for(tempo=0;tempo<70000;tempo++); // Wait some time before 00136 start_boot(); // Jumping to booltoader 00137 } 00138 } 00139 00140 00143 void hid_report_in(void) 00144 { 00145 U8 joy =0; 00146 00147 Usb_select_endpoint(EP_HID_IN); 00148 if(!Is_usb_write_enabled()) 00149 return; // Not ready to send report 00150 00151 // Build the Joytick report 00152 if(Is_joy_up()|| Is_joy_down() || Is_joy_right() || Is_joy_left() ) 00153 { 00154 joy=0x01; 00155 } 00156 if(joy==g_last_joy) 00157 return; // Same report then no send report 00158 g_last_joy=joy; 00159 00160 // Send report 00161 Usb_write_byte(g_last_joy); // Joystick 00162 Usb_write_byte(GPIOR1); // Dummy (not used) 00163 Usb_write_byte(GPIOR1); // Dummy (not used) 00164 Usb_write_byte(GPIOR1); // Dummy (not used) 00165 Usb_write_byte(GPIOR1); // Dummy (not used) 00166 Usb_write_byte(GPIOR1); // Dummy (not used) 00167 Usb_write_byte(GPIOR1); // Dummy (not used) 00168 Usb_write_byte(GPIOR1); // Dummy (not used) 00169 Usb_ack_in_ready(); // Send data over the USB 00170 } 00171 00176 void sof_action() 00177 { 00178 cpt_sof++; 00179 }
1.5.3