00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.h"
00020 #include "conf_usb.h"
00021 #include "usb_drv.h"
00022
00023
00024
00025
00026
00027
00028
00039 U8 usb_config_ep(U8 config0, U8 config1)
00040 {
00041 Usb_enable_endpoint();
00042 UECFG0X = config0;
00043 UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
00044 Usb_allocate_memory();
00045 return (Is_endpoint_configured());
00046 }
00047
00059 U8 usb_select_enpoint_interrupt(void)
00060 {
00061 U8 interrupt_flags;
00062 U8 ep_num;
00063
00064 ep_num = 0;
00065 interrupt_flags = Usb_interrupt_flags();
00066
00067 while(ep_num < MAX_EP_NB)
00068 {
00069 if (interrupt_flags & 1)
00070 {
00071 return (ep_num);
00072 }
00073 else
00074 {
00075 ep_num++;
00076 interrupt_flags = interrupt_flags >> 1;
00077 }
00078 }
00079 return 0;
00080 }
00081
00102 U8 usb_send_packet(U8 ep_num, U8* tbuf, U8 data_length)
00103 {
00104 U8 remaining_length;
00105
00106 remaining_length = data_length;
00107 Usb_select_endpoint(ep_num);
00108 while(Is_usb_write_enabled() && (0 != remaining_length))
00109 {
00110 Usb_write_byte(*tbuf);
00111 remaining_length--;
00112 tbuf++;
00113 }
00114 return remaining_length;
00115 }
00116
00137 U8 usb_read_packet(U8 ep_num, U8* rbuf, U8 data_length)
00138 {
00139 U8 remaining_length;
00140
00141 remaining_length = data_length;
00142 Usb_select_endpoint(ep_num);
00143
00144 while(Is_usb_read_enabled() && (0 != remaining_length))
00145 {
00146 *rbuf = Usb_read_byte();
00147 remaining_length--;
00148 rbuf++;
00149 }
00150 return remaining_length;
00151 }
00152
00163 void usb_halt_endpoint (U8 ep_num)
00164 {
00165 Usb_select_endpoint(ep_num);
00166 Usb_enable_stall_handshake();
00167 }
00168
00179 U8 usb_init_device (void)
00180 {
00181 Usb_select_endpoint(EP_CONTROL);
00182 if(!Is_usb_endpoint_enabled())
00183 {
00184 return usb_configure_endpoint(EP_CONTROL, \
00185 TYPE_CONTROL, \
00186 DIRECTION_OUT, \
00187 SIZE_32, \
00188 ONE_BANK, \
00189 NYET_DISABLED);
00190 }
00191 return FALSE;
00192 }
00193
00194
00195