00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 //_____ I N C L U D E S ___________________________________________________ 00023 00024 #include "config.h" 00025 #include "conf_usb.h" 00026 #include "usb_device_task.h" 00027 #include "modules\usb\usb_task.h" 00028 00029 #include "lib_mcu\usb\usb_drv.h" 00030 #include "usb_descriptors.h" 00031 #include "modules\usb\device_chap9\usb_standard_request.h" 00032 #include "lib_mcu\pll\pll_drv.h" 00033 00034 00035 00036 00037 //_____ M A C R O S ________________________________________________________ 00038 00039 //_____ D E F I N I T I O N S ______________________________________________ 00040 00046 bit usb_connected; 00047 00048 00055 extern U8 usb_configuration_nb; 00056 00057 00058 00059 //_____ D E C L A R A T I O N S ____________________________________________ 00060 00073 void usb_device_task_init(void) 00074 { 00075 Enable_interrupt(); 00076 Usb_disable(); 00077 Usb_enable(); 00078 Usb_select_device(); 00079 Usb_enable_vbus_interrupt(); 00080 Enable_interrupt(); 00081 00082 } 00083 00097 void usb_start_device (void) 00098 { 00099 Pll_start_auto(); 00100 Wait_pll_ready(); 00101 Usb_unfreeze_clock(); 00102 Usb_enable_suspend_interrupt(); 00103 Usb_enable_reset_interrupt(); 00104 usb_init_device(); // configure the USB controller EP0 00105 Usb_attach(); 00106 usb_connected = FALSE; 00107 } 00108 00119 void usb_device_task(void) 00120 { 00121 if (Is_usb_vbus_high()&& usb_connected==FALSE) 00122 { 00123 usb_connected = TRUE; 00124 Usb_vbus_on_action(); 00125 Usb_send_event(EVT_USB_POWERED); 00126 Usb_enable_reset_interrupt(); 00127 Usb_attach(); 00128 } 00129 00130 if(Is_usb_event(EVT_USB_RESET)) 00131 { 00132 Usb_ack_event(EVT_USB_RESET); 00133 Usb_reset_endpoint(0); 00134 usb_configuration_nb=0; 00135 } 00136 00137 // Here connection to the device enumeration process 00138 Usb_select_endpoint(EP_CONTROL); 00139 if (Is_usb_receive_setup()) 00140 { 00141 usb_process_request(); 00142 } 00143 }