hid_task.c

Go to the documentation of this file.
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 #include "lib_mcu\adc\adc_drv.h"
00028 
00029 
00030 
00031 //_____ M A C R O S ________________________________________________________
00032 
00033 
00034 //_____ D E F I N I T I O N S ______________________________________________
00035 
00036 
00037 
00038 //_____ D E C L A R A T I O N S ____________________________________________
00039 
00040 extern bit   usb_connected;
00041 extern  U8   usb_configuration_nb;
00042 volatile U8 cpt_sof=0;
00043 
00045 void (*start_bootloader) (void)=(void (*)(void))0xf000;
00046 
00047 
00058 void hid_task_init(void)
00059 {
00060    init_adc();
00061    Leds_init();
00062    Joy_init();
00063 }
00064 
00065 
00066 
00067 
00068 
00078 void hid_task(void)
00079 {
00080    U8 dummy;
00081    U8 dummy2;
00082    U8 volatile pot;
00083    U8 volatile tempe;
00084    U8 joy;
00085    U32 volatile tempo;
00086 
00087     if(Is_device_enumerated())                     
00088     {
00089       Usb_select_endpoint(EP_HID_OUT);    
00090       if(Is_usb_receive_out())
00091       {
00092          Leds_set_val(Usb_read_byte());   
00093          GPIOR1=Usb_read_byte();          
00094          GPIOR1=Usb_read_byte();          
00095          dummy=Usb_read_byte();           
00096          dummy2=Usb_read_byte();          
00097          Usb_ack_receive_out();
00098       }
00099 
00100       if(dummy==0x55 && dummy2==0xAA)     
00101       {
00102          Usb_detach();                    
00103          for(tempo=0;tempo<70000;tempo++);
00104          (*start_bootloader)();           
00105       }
00106       tempe=(S8)Read_temperature();       
00107       tempe=(S8)Read_temperature();
00108       tempe=(S8)Read_temperature();
00109 
00110       pot= Get_adc_pot_val()>>2;          
00111       pot= Get_adc_pot_val()>>2;          
00112       pot= Get_adc_pot_val()>>2;          
00113 
00114       joy=0;                              
00115       if(Is_joy_up())                     
00116       {
00117         joy+=0x01;
00118       }
00119       if(Is_joy_down())                   
00120       {
00121         joy+=0x02;
00122       }
00123       if(Is_joy_right())                  
00124       {
00125         joy+=0x04;
00126       }
00127       if(Is_joy_left())                   
00128       {
00129         joy+=0x08;
00130       }
00131       Usb_select_endpoint(EP_HID_IN);     
00132       if(Is_usb_in_ready())
00133       {
00134          Usb_write_byte(Leds_get_val());           
00135          Usb_write_byte(joy);             
00136          Usb_write_byte(pot);             
00137          Usb_write_byte(tempe);           
00138          Usb_write_byte(GPIOR1);          
00139          Usb_write_byte(~PINE);           
00140          Usb_write_byte(~PINE);           
00141          Usb_write_byte(~PINE);           
00142          Usb_ack_fifocon();               
00143       }
00144     }
00145 
00146 }
00147 
00159 void sof_action()
00160 {
00161    cpt_sof++;
00162 }

Generated on Fri Mar 17 16:02:03 2006 for Atmel by  doxygen 1.4.6-NO