00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 //_____ I N C L U D E S ___________________________________________________ 00018 00019 #include "config.h" 00020 #include "conf_usb.h" 00021 #include "hid_task.h" 00022 #include "lib_board/stk_525/stk_525.h" 00023 #include "lib_mcu\usb\usb_drv.h" 00024 #include "usb_descriptors.h" 00025 #include "modules\usb\device_chap9\usb_standard_request.h" 00026 #include "usb_specific_request.h" 00027 00028 00029 00030 //_____ M A C R O S ________________________________________________________ 00031 00032 00033 //_____ D E F I N I T I O N S ______________________________________________ 00034 00035 00036 00037 //_____ D E C L A R A T I O N S ____________________________________________ 00038 00039 extern bit usb_connected; 00040 extern U8 usb_configuration_nb; 00041 volatile U8 cpt_sof=0; 00042 extern U8 jump_bootloader; 00043 U8 last_joy=0; 00044 00046 void (*start_bootloader) (void)=(void (*)(void))0xf000; 00047 00048 00059 void hid_task_init(void) 00060 { 00061 Leds_init(); 00062 Joy_init(); 00063 } 00064 00065 00066 00067 00068 00078 void hid_task(void) 00079 { 00080 U8 joy; 00081 U32 volatile tempo; 00082 U8 led_state; 00083 U8 led_number; 00084 00085 if(Is_device_enumerated()) 00086 { 00087 Usb_select_endpoint(EP_HID_OUT); 00088 if(Is_usb_receive_out()) 00089 { 00090 led_state=Usb_read_byte()&0x0F; 00091 led_number=Usb_read_byte()&0x0F; 00092 switch (led_number) 00093 { 00094 case 1: 00095 if(led_state) 00096 { Led0_on(); } 00097 else {Led0_off();} 00098 break; 00099 case 2: 00100 if(led_state) 00101 { Led1_on(); } 00102 else {Led1_off();} 00103 break; 00104 case 3: 00105 if(led_state) 00106 { Led2_on(); } 00107 else {Led2_off();} 00108 break; 00109 case 4: 00110 if(led_state) 00111 { Led3_on(); } 00112 else {Led3_off();} 00113 break; 00114 } 00115 Usb_ack_receive_out(); 00116 } 00117 00118 if(jump_bootloader) 00119 { 00120 Leds_off(); 00121 Usb_detach(); 00122 for(tempo=0;tempo<70000;tempo++); 00123 (*start_bootloader)(); 00124 } 00125 00126 00127 joy=0; 00128 if(Is_joy_up()|| Is_joy_down() || Is_joy_right() || Is_joy_left() ) 00129 { 00130 joy=0x01; 00131 } 00132 Usb_select_endpoint(EP_HID_IN); 00133 if(Is_usb_write_enabled()) 00134 { 00135 if(joy!=last_joy) 00136 { 00137 Usb_write_byte(joy); 00138 Usb_write_byte(GPIOR1); 00139 Usb_write_byte(GPIOR1); 00140 Usb_write_byte(GPIOR1); 00141 Usb_write_byte(GPIOR1); 00142 Usb_write_byte(GPIOR1); 00143 Usb_write_byte(GPIOR1); 00144 Usb_write_byte(GPIOR1); 00145 Usb_ack_in_ready(); 00146 last_joy=joy; 00147 } 00148 } 00149 } 00150 00151 } 00152 00164 void sof_action() 00165 { 00166 cpt_sof++; 00167 }