?? usb_drv.h
字號:
//! @file usb_drv.h,v
//!
//! Copyright (c) 2006 Atmel.
//!
//! Use of this program is subject to Atmel's End User License Agreement.
//! Please read file license.txt for copyright notice.
//!
//! @brief This file contains the USB low level driver definition
//!
//! @version 1.34 at90usb128-demo-audio-1_0_2 $Id: usb_drv.h,v 1.34 2006/07/27 07:03:41 rletendu Exp $
//!
//! @todo
//! @bug
#ifndef _USB_DRV_H_
#define _USB_DRV_H_
//_____ 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;
//! @defgroup USB_low_level_drivers USB low level drivers module
//! USB low level drivers Module
//! @{
//_____ 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)
//! @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) ))
//! @}
//! @defgroup USB_regulator USB Pads Regulator drivers
//! Turns ON/OFF USB pads regulator
//! @{
//! Enable internal USB pads regulator
#define Usb_enable_regulator() (UHWCON |= (1<<UVREGE))
//! Disable internal USB pads regulator
#define Usb_disable_regulator() (UHWCON &= ~(1<<UVREGE))
//! Check regulator enable bit
#define Is_usb_regulator_enabled() ((UHWCON & (1<<UVREGE)) ? TRUE : FALSE)
//! @}
//! @defgroup gen_usb USB common management drivers
//! These macros manage the USB controller
//! @{
//! Enable external UID pin
#define Usb_enable_uid_pin() (UHWCON |= (1<<UIDE))
//! Disable external UID pin
#define Usb_disable_uid_pin() (UHWCON &= ~(1<<UIDE))
//! Disable external UID pin and force device mode
#define Usb_force_device_mode() (Usb_disable_uid_pin(), UHWCON |= (1<<UIMOD))
//! Disable external UID pin and force host mode
#define Usb_force_host_mode() (Usb_disable_uid_pin(), UHWCON &= ~(1<<UIMOD))
//! Enable external UVCON pin
#define Usb_enable_uvcon_pin() (UHWCON |= (1<<UVCONE))
//! Enable external UVCON pin
#define Usb_disable_uvcon_pin() (UHWCON &= ~(1<<UVCONE))
//! Use device full speed mode (default mode)
#define Usb_full_speed_mode() (UDCON &= ~(1<<LSM))
//! For device mode, force low speed mode
#define Usb_low_speed_mode() (UDCON |= (1<<LSM))
//! Enable both USB interface and Vbus pad
#define Usb_enable() (USBCON |= ((1<<USBE) | (1<<OTGPADE)))
//! Disable both USB interface and Vbus pad
#define Usb_disable() (USBCON &= ~((1<<USBE) | (1<<OTGPADE)))
#define Is_usb_enabled() ((USBCON & (1<<USBE)) ? TRUE : FALSE)
//! Enable VBUS pad
#define Usb_enable_vbus_pad() (USBCON |= (1<<OTGPADE))
//! Disable VBUS pad
#define Usb_disable_vbus_pad() (USBCON &= ~(1<<OTGPADE))
#define Usb_select_device() (USBCON &= ~(1<<HOST))
#define Usb_select_host() (USBCON |= (1<<HOST))
#define Is_usb_host_enabled() ((USBCON & (1<<HOST)) ? TRUE : FALSE)
//! Stop internal USB clock in interface (freeze the interface register)
#define Usb_freeze_clock() (USBCON |= (1<<FRZCLK))
#define Usb_unfreeze_clock() (USBCON &= ~(1<<FRZCLK))
#define Is_usb_clock_freezed() ((USBCON & (1<<FRZCLK)) ? TRUE : FALSE)
#define Usb_enable_id_interrupt() (USBCON |= (1<<IDTE))
#define Usb_disable_id_interrupt() (USBCON &= ~(1<<IDTE))
#define Is_usb_id_interrupt_enabled() ((USBCON & (1<<IDTE)) ? TRUE : FALSE)
#define Is_usb_id_device() ((USBSTA & (1<<ID)) ? TRUE : FALSE)
#define Usb_ack_id_transition() (USBINT = ~(1<<IDTI))
#define Is_usb_id_transition() ((USBINT & (1<<IDTI)) ? TRUE : FALSE)
#define Usb_enable_vbus_interrupt() (USBCON |= (1<<VBUSTE))
#define Usb_disable_vbus_interrupt() (USBCON &= ~(1<<VBUSTE))
#define Is_usb_vbus_interrupt_enabled() ((USBCON & (1<<VBUSTE)) ? TRUE : FALSE)
#define Is_usb_vbus_high() ((USBSTA & (1<<VBUS)) ? TRUE : FALSE)
#define Is_usb_vbus_low() ((USBSTA & (1<<VBUS)) ? FALSE : TRUE)
#define Usb_ack_vbus_transition() (USBINT = ~(1<<VBUSTI))
#define Is_usb_vbus_transition() ((USBINT & (1<<VBUSTI)) ? TRUE : FALSE)
//! returns the USB general interrupts (interrupt enabled)
#define Usb_get_general_interrupt() (USBINT & (USBCON & MSK_IDTE_VBUSTE))
//! acks the general interrupts (interrupt enabled)
#define Usb_ack_all_general_interrupt() (USBINT = ~(USBCON & MSK_IDTE_VBUSTE))
#define Usb_ack_cache_id_transition(x) ((x) &= ~(1<<IDTI))
#define Usb_ack_cache_vbus_transition(x) ((x) &= ~(1<<VBUSTI))
#define Is_usb_cache_id_transition(x) (((x) & (1<<IDTI)) )
#define Is_usb_cache_vbus_transition(x) (((x) & (1<<VBUSTI)))
//! returns the USB Pad interrupts (interrupt enabled)
#define Usb_get_otg_interrupt() (OTGINT & OTGIEN)
//! acks the USB Pad interrupts (interrupt enabled)
#define Usb_ack_all_otg_interrupt() (OTGINT = ~OTGIEN)
#define Is_otg_cache_bconnection_error(x) (((x) & MSK_BCERRI))
#define Usb_ack_cache_bconnection_error(x) ((x) &= ~MSK_BCERRI)
#define Usb_enter_dpram_mode() (UDPADDH = (1<<DPACC))
#define Usb_exit_dpram_mode() (UDPADDH = (U8)~(1<<DPACC))
#define Usb_set_dpram_address(addr) (UDPADDH = (1<<DPACC) + ((Uint16)addr >> 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<<VBUSREQ))
//! requests for VBus desactivation
#define Usb_disable_vbus() (OTGCON |= (1<<VBUSRQC))
//! Manually request VBUS without UVCON signal from USB interface
#define Usb_enable_manual_vbus() (PORTE|=0x80,DDRE|=0x80,Usb_disable_uvcon_pin())
//! initiates a Host Negociation Protocol
#define Usb_device_initiate_hnp() (OTGCON |= (1<<HNPREQ))
//! accepts a Host Negociation Protocol
#define Usb_host_accept_hnp() (OTGCON |= (1<<HNPREQ))
//! rejects a Host Negociation Protocol
#define Usb_host_reject_hnp() (OTGCON &= ~(1<<HNPREQ))
//! initiates a Session Request Protocol
#define Usb_device_initiate_srp() (OTGCON |= (1<<SRPREQ))
//! selects VBus as SRP method
#define Usb_select_vbus_srp_method() (OTGCON |= (1<<SRPSEL))
//! selects data line as SRP method
#define Usb_select_data_srp_method() (OTGCON &= ~(1<<SRPSEL))
//! enables hardware control on VBus
#define Usb_enable_vbus_hw_control() (OTGCON &= ~(1<<VBUSHWC))
//! disables hardware control on VBus
#define Usb_disable_vbus_hw_control() (OTGCON |= (1<<VBUSHWC))
//! tests if VBus has been requested
#define Is_usb_vbus_enabled() ((OTGCON & (1<<VBUSREQ)) ? TRUE : FALSE)
//! tests if a HNP occurs
#define Is_usb_hnp() ((OTGCON & (1<<HNPREQ)) ? TRUE : FALSE)
//! tests if a SRP from device occurs
#define Is_usb_device_srp() ((OTGCON & (1<<SRPREQ)) ? TRUE : FALSE)
//! enables suspend time out interrupt
#define Usb_enable_suspend_time_out_interrupt() (OTGIEN |= (1<<STOE))
//! disables suspend time out interrupt
#define Usb_disable_suspend_time_out_interrupt() (OTGIEN &= ~(1<<STOE))
#define Is_suspend_time_out_interrupt_enabled() ((OTGIEN & (1<<STOE)) ? TRUE : FALSE)
//! acks suspend time out interrupt
#define Usb_ack_suspend_time_out_interrupt() (OTGINT &= ~(1<<STOI))
//! tests if a suspend time out occurs
#define Is_usb_suspend_time_out_interrupt() ((OTGINT & (1<<STOI)) ? TRUE : FALSE)
//! enables HNP error interrupt
#define Usb_enable_hnp_error_interrupt() (OTGIEN |= (1<<HNPERRE))
//! disables HNP error interrupt
#define Usb_disable_hnp_error_interrupt() (OTGIEN &= ~(1<<HNPERRE))
#define Is_hnp_error_interrupt_enabled() ((OTGIEN & (1<<HNPERRE)) ? TRUE : FALSE)
//! acks HNP error interrupt
#define Usb_ack_hnp_error_interrupt() (OTGINT &= ~(1<<HNPERRI))
//! tests if a HNP error occurs
#define Is_usb_hnp_error_interrupt() ((OTGINT & (1<<HNPERRI)) ? TRUE : FALSE)
//! enables role exchange interrupt
#define Usb_enable_role_exchange_interrupt() (OTGIEN |= (1<<ROLEEXE))
//! disables role exchange interrupt
#define Usb_disable_role_exchange_interrupt() (OTGIEN &= ~(1<<ROLEEXE))
#define Is_role_exchange_interrupt_enabled() ((OTGIEN & (1<<ROLEEXE)) ? TRUE : FALSE)
//! acks role exchange interrupt
#define Usb_ack_role_exchange_interrupt() (OTGINT &= ~(1<<ROLEEXI))
//! tests if a role exchange occurs
#define Is_usb_role_exchange_interrupt() ((OTGINT & (1<<ROLEEXI)) ? TRUE : FALSE)
//! enables B device connection error interrupt
#define Usb_enable_bconnection_error_interrupt() (OTGIEN |= (1<<BCERRE))
//! disables B device connection error interrupt
#define Usb_disable_bconnection_error_interrupt() (OTGIEN &= ~(1<<BCERRE))
#define Is_bconnection_error_interrupt_enabled() ((OTGIEN & (1<<BCERRE)) ? TRUE : FALSE)
//! acks B device connection error interrupt
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -