/* This file has been prepared for Doxygen automatic documentation generation.*/ /*! \file ********************************************************************* * * \brief * This file contains the USB driver routines. * * \addtogroup usbstick * * \author * Atmel Corporation: http://www.atmel.com \n * Support email: avr@atmel.com * ******************************************************************************/ /* Copyright (c) 2008 ATMEL Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef USB_DRV_H_ #define USB_DRV_H_ #include "compiler.h" /** * \addtogroup usbdriver * @{ */ //_____ I N C L U D E S ____________________________________________________ typedef enum endpoint_parameter{ep_num, ep_type, ep_direction, ep_size, ep_bank, nyet_status} t_endpoint_parameter; //_____ M A C R O S ________________________________________________________ #define MAX_EP_NB 7 #define EP_CONTROL 0 #define EP_1 1 #define EP_2 2 #define EP_3 3 #define EP_4 4 #define EP_5 5 #define EP_6 6 #define EP_7 7 #define PIPE_CONTROL 0 #define PIPE_0 0 #define PIPE_1 1 #define PIPE_2 2 #define PIPE_3 3 #define PIPE_4 4 #define PIPE_5 5 #define PIPE_6 6 #define PIPE_7 7 // USB EndPoint #define MSK_EP_DIR 0x7F #define MSK_UADD 0x7F #define MSK_EPTYPE 0xC0 #define MSK_EPSIZE 0x70 #define MSK_EPBK 0x0C #define MSK_DTSEQ 0x0C #define MSK_NBUSYBK 0x03 #define MSK_CURRBK 0x03 #define MSK_DAT 0xFF // UEDATX #define MSK_BYCTH 0x07 // UEBCHX #define MSK_BYCTL 0xFF // UEBCLX #define MSK_EPINT 0x7F // UEINT #define MSK_HADDR 0xFF // UHADDR // USB Pipe #define MSK_PNUM 0x07 // UPNUM #define MSK_PRST 0x7F // UPRST #define MSK_PTYPE 0xC0 // UPCFG0X #define MSK_PTOKEN 0x30 #define MSK_PEPNUM 0x0F #define MSK_PSIZE 0x70 // UPCFG1X #define MSK_PBK 0x0C #define MSK_NBUSYBK 0x03 #define MSK_ERROR 0x1F #define MSK_PTYPE 0xC0 // UPCFG0X #define MSK_PTOKEN 0x30 #define MSK_TOKEN_SETUP 0x30 #define MSK_TOKEN_IN 0x10 #define MSK_TOKEN_OUT 0x20 #define MSK_PEPNUM 0x0F #define MSK_PSIZE 0x70 // UPCFG1X #define MSK_PBK 0x0C // Parameters for endpoint configuration // These define are the values used to enable and configure an endpoint. #define TYPE_CONTROL 0 #define TYPE_ISOCHRONOUS 1 #define TYPE_BULK 2 #define TYPE_INTERRUPT 3 //typedef enum ep_type {TYPE_CONTROL, TYPE_BULK, TYPE_ISOCHRONOUS, TYPE_INTERRUPT} e_ep_type; #define DIRECTION_OUT 0 #define DIRECTION_IN 1 //typedef enum ep_dir {DIRECTION_OUT, DIRECTION_IN} e_ep_dir; #define SIZE_8 0 #define SIZE_16 1 #define SIZE_32 2 #define SIZE_64 3 #define SIZE_128 4 #define SIZE_256 5 #define SIZE_512 6 #define SIZE_1024 7 //typedef enum ep_size {SIZE_8, SIZE_16, SIZE_32, SIZE_64, // SIZE_128, SIZE_256, SIZE_512, SIZE_1024} e_ep_size; #define ONE_BANK 0 #define TWO_BANKS 1 //typedef enum ep_bank {ONE_BANK, TWO_BANKS} e_ep_bank; #define NYET_ENABLED 0 #define NYET_DISABLED 1 //typedef enum ep_nyet {NYET_DISABLED, NYET_ENABLED} e_ep_nyet; #define TOKEN_SETUP 0 #define TOKEN_IN 1 #define TOKEN_OUT 2 #define Is_ep_addr_in(x) ( (x&0x80)? TRUE : FALSE) //! @ingroup usbdriver //! @defgroup Endpoints_configuration Configuration macros for endpoints //! List of the standard macro used to configure pipes and endpoints //! @{ #define Usb_build_ep_config0(type, dir, nyet) ((type<<6) /*| (nyet<<1)*/ | (dir)) #define Usb_build_ep_config1(size, bank ) ((size<<4) | (bank<<2) ) #define usb_configure_endpoint(num, type, dir, size, bank, nyet) \ ( Usb_select_endpoint(num), \ usb_config_ep(Usb_build_ep_config0(type, dir, nyet),\ Usb_build_ep_config1(size, bank) )) #define Host_build_pipe_config0(type, token, ep_num) ((type<<6) | (token<<4) | (ep_num)) #define Host_build_pipe_config1(size, bank ) ((size<<4) | (bank<<2) ) #define host_configure_pipe(num, type, token,ep_num, size, bank, freq) \ ( Host_select_pipe(num), \ Host_set_interrupt_frequency(freq), \ host_config_pipe(Host_build_pipe_config0(type, token, ep_num),\ Host_build_pipe_config1(size, bank) )) //! @} //! @ingroup usbdriver //! @defgroup USB_regulator USB Pads Regulator drivers //! Turns ON/OFF USB pads regulator //! @{ //! Enable internal USB pads regulator #define Usb_enable_regulator() (UHWCON |= (1<> 8), UDPADDL = (Uchar)addr) #define Usb_write_dpram_byte(val) (UEDATX=val) #define Usb_read_dpram_byte() (UEDATX) //! requests for VBus activation #define Usb_enable_vbus() (OTGCON |= (1<> 2) //! returns the number of busy banks #define Usb_nb_busy_bank() (UESTA0X & MSK_NBUSYBK) //! tests if at least one bank is busy #define Is_usb_one_bank_busy() ((UESTA0X & MSK_NBUSYBK) == 0 ? FALSE : TRUE) //! tests if current endpoint is configured #define Is_endpoint_configured() ((UESTA0X & (1<> 2) //! returns the number of the current bank #define Usb_current_bank() ( UESTA1X & MSK_CURRBK) //! clears FIFOCON bit #define Usb_ack_fifocon() (UEINTX &= ~(1<>4)) //! returns the type of the current pipe #define Host_get_pipe_type() (UPCFG0X>>6) //! tests if error occurs on pipe #define Host_error_status() (UPERRX & MSK_ERROR) //! acks all pipe error #define Host_ack_all_errors() (UPERRX = 0x00) //! Enable pipe end transmission interrupt #define Host_enable_transmit_interrupt() (UPIENX |= (1<>8)&0x00FF) \ | (((x)<<8)&0xFF00) \ ) //! Usb_write_word_enum_struc //! This macro help to fill the U16 fill in USB enumeration struct. //! Depending on the CPU architecture, the macro swap or not the nibbles //! //! @param x (U16) the 16 bit word to be written //! //! @return (U16) the 16 bit word written #if !defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) #error YOU MUST Define the Endian Type of target: LITTLE_ENDIAN or BIG_ENDIAN #endif #ifdef LITTLE_ENDIAN #define Usb_write_word_enum_struc(x) (x) #else //BIG_ENDIAN #define Usb_write_word_enum_struc(x) (wSWAP(x)) #endif //_____ D E C L A R A T I O N ______________________________________________ U8 usb_config_ep (U8, U8); U8 usb_select_enpoint_interrupt (void); U8 usb_send_packet (U8 , U8*, U8); U8 usb_read_packet (U8 , U8*, U8); void usb_halt_endpoint (U8); U8 usb_init_device (void); U8 host_config_pipe (U8, U8); U8 host_determine_pipe_size (U16); void host_disable_all_pipe (void); U8 usb_get_nb_pipe_interrupt (void); U8 usb_endpoint_wait_for_read_control_enabled(); U8 usb_endpoint_wait_for_write_enabled(); U8 usb_endpoint_wait_for_receive_out(); U8 usb_endpoint_wait_for_IN_ready(); #define usb_endpoint_wait_for_read_enabled usb_endpoint_wait_for_write_enabled #endif //USB_DRV_H_ /** @} */