00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "config.h"
00049 #include "conf_usb.h"
00050 #include "usb_drv.h"
00051
00052
00053
00054
00055
00056
00057
00068 U8 usb_config_ep(U8 config0, U8 config1)
00069 {
00070 Usb_enable_endpoint();
00071 UECFG0X = config0;
00072 UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
00073 Usb_allocate_memory();
00074 return (Is_endpoint_configured());
00075 }
00076
00088 U8 usb_select_enpoint_interrupt(void)
00089 {
00090 U8 interrupt_flags;
00091 U8 ep_num;
00092
00093 ep_num = 0;
00094 interrupt_flags = Usb_interrupt_flags();
00095
00096 while(ep_num < MAX_EP_NB)
00097 {
00098 if (interrupt_flags & 1)
00099 {
00100 return (ep_num);
00101 }
00102 else
00103 {
00104 ep_num++;
00105 interrupt_flags = interrupt_flags >> 1;
00106 }
00107 }
00108 return 0;
00109 }
00110
00131 U8 usb_send_packet(U8 ep_num, U8* tbuf, U8 data_length)
00132 {
00133 U8 remaining_length;
00134
00135 remaining_length = data_length;
00136 Usb_select_endpoint(ep_num);
00137 while(Is_usb_write_enabled() && (0 != remaining_length))
00138 {
00139 Usb_write_byte(*tbuf);
00140 remaining_length--;
00141 tbuf++;
00142 }
00143 return remaining_length;
00144 }
00145
00166 U8 usb_read_packet(U8 ep_num, U8* rbuf, U8 data_length)
00167 {
00168 U8 remaining_length;
00169
00170 remaining_length = data_length;
00171 Usb_select_endpoint(ep_num);
00172
00173 while(Is_usb_read_enabled() && (0 != remaining_length))
00174 {
00175 *rbuf = Usb_read_byte();
00176 remaining_length--;
00177 rbuf++;
00178 }
00179 return remaining_length;
00180 }
00181
00192 void usb_halt_endpoint (U8 ep_num)
00193 {
00194 Usb_select_endpoint(ep_num);
00195 Usb_enable_stall_handshake();
00196 }
00197
00208 U8 usb_init_device (void)
00209 {
00210 Usb_select_endpoint(EP_CONTROL);
00211 if(!Is_usb_endpoint_enabled())
00212 {
00213 return usb_configure_endpoint(EP_CONTROL, \
00214 TYPE_CONTROL, \
00215 DIRECTION_OUT, \
00216 SIZE_32, \
00217 ONE_BANK, \
00218 NYET_DISABLED);
00219 }
00220 return FALSE;
00221 }
00222
00223
00224