53 #include <util/delay.h>
59 #if (USB_DEVICE_FEATURE==DISABLED && USB_HOST_FEATURE==DISABLED)
60 #error at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be unabled
63 #if (USB_DEVICE_FEATURE == ENABLED)
65 #define USB_ENDPOINT_WAIT_TIMEOUT 250
67 U8 usb_endpoint_wait_for_write_enabled() {
68 #if USB_ENDPOINT_WAIT_TIMEOUT
69 U16 timeout=USB_ENDPOINT_WAIT_TIMEOUT;
90 U8 usb_endpoint_wait_for_read_control_enabled() {
91 #if USB_ENDPOINT_WAIT_TIMEOUT
92 U16 timeout=USB_ENDPOINT_WAIT_TIMEOUT;
114 U8 usb_endpoint_wait_for_IN_ready() {
115 #if USB_ENDPOINT_WAIT_TIMEOUT
116 U16 timeout=USB_ENDPOINT_WAIT_TIMEOUT;
138 U8 usb_endpoint_wait_for_receive_out() {
139 #if USB_ENDPOINT_WAIT_TIMEOUT
140 U16 timeout=USB_ENDPOINT_WAIT_TIMEOUT;
174 UECFG1X = (UECFG1X & (1<<ALLOC)) | config1;
195 while(ep_num < MAX_EP_NB)
197 if (interrupt_flags & 1)
204 interrupt_flags = interrupt_flags >> 1;
234 remaining_length = data_length;
242 return remaining_length;
269 remaining_length = data_length;
278 return remaining_length;
308 if(Is_usb_id_device())
313 #if (USB_LOW_SPEED_DEVICE==DISABLE)
314 rv = usb_configure_endpoint(EP_CONTROL, \
321 rv = usb_configure_endpoint(EP_CONTROL, \
340 #if (USB_HOST_FEATURE == ENABLED)
350 U8 host_config_pipe(U8 config0, U8 config1)
373 U8 host_determine_pipe_size(U16 size)
375 if(size <= 8 ) {
return (SIZE_8 );}
376 else if(size <= 16 ) {
return (SIZE_16 );}
377 else if(size <= 32 ) {
return (SIZE_32 );}
378 else if(size <= 64 ) {
return (SIZE_64 );}
379 else if(size <= 128) {
return (SIZE_128 );}
380 else if(size <= 256) {
return (SIZE_256 );}
381 else if(size <= 512) {
return (SIZE_512 );}
382 else {
return (SIZE_1024);}
391 void host_disable_all_pipe(
void)
410 U8 usb_get_nb_pipe_interrupt(
void)
416 for(i=0;i< MAX_EP_NB;i++)
418 if (interrupt_flags & (1<<i))
428 #endif // USB_HOST_FEATURE == ENABLED
#define Is_usb_endpoint_enabled()
tests if the current endpoint is enabled
This file contains the possible external configuration of the USB.
#define Host_disable_pipe()
disables pipe
U8 usb_config_ep(U8 config0, U8 config1)
usb_configure_endpoint.
#define Host_enable_pipe()
enables pipe
#define Is_usb_detached()
test if the device is detached
#define Usb_read_byte()
returns FIFO byte for current endpoint
#define Usb_enable_endpoint()
enables the current endpoint
This file contains the USB driver routines.
#define Usb_write_byte(byte)
writes byte in FIFO for current endpoint
#define Is_usb_sof()
tests if Start Of Frame occurs
U8 usb_read_packet(U8 ep_num, U8 *rbuf, U8 data_length)
usb_read_packet.
U8 usb_init_device(void)
usb_init_device.
#define Is_usb_read_control_enabled()
tests if read allowed on control endpoint
#define Host_reset_pipe(p)
resets the pipe
#define Is_usb_endpoint_stall_requested()
tests if STALL handshake request is running
void usb_halt_endpoint(U8 ep_num)
usb_halt_endpoint.
U8 usb_send_packet(U8 ep_num, U8 *tbuf, U8 data_length)
usb_send_packet.
#define Host_allocate_memory()
allocates the current configuration in DPRAM memory
#define Is_endpoint_configured()
tests if current endpoint is configured
#define Host_get_pipe_interrupt()
returns pipe interrupt register
#define Usb_allocate_memory()
allocates the current configuration in DPRAM memory
#define Is_usb_write_enabled()
tests if endpoint write allowed
U8 usb_select_enpoint_interrupt(void)
usb_select_endpoint_interrupt.
#define Host_unallocate_memory()
un-allocates the current configuration in DPRAM memory
#define Is_usb_in_ready()
tests if IN ready
#define FALSE
An alias for zero, used for clarity.
#define Usb_interrupt_flags()
tests the general endpoint interrupt flags
#define Usb_select_endpoint(ep)
selects the endpoint number to interface with the CPU
#define Is_pipe_configured()
tests if current pipe is configured
#define Is_usb_receive_out()
tests if OUT received
#define Is_usb_read_enabled()
tests if endpoint read allowed
#define Usb_ack_sof()
acks Start Of Frame
#define Usb_enable_stall_handshake()
enables the STALL handshake for the next transaction
#define Host_select_pipe(p)
selects pipe for CPU interface