📄 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.8 at90usb162-hidgen-1_0_1 $Id: usb_drv.h,v 1.8 2006/11/30 14:08:28 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() (REGCR &= ~(1<<REGDIS))
//! Disable internal USB pads regulator
#define Usb_disable_regulator() (REGCR |= (1<<REGDIS))
//! Check regulator enable bit
#define Is_usb_regulator_enabled() ((REGCR & (1<<REGDIS)) ? FALSE : TRUE)
//! @}
//! @defgroup gen_usb USB common management drivers
//! These macros manage the USB controller
//! @{
//! Enable both USB interface
#define Usb_enable() (USBCON |= ((1<<USBE) ))
//! Disable both USB interface
#define Usb_disable() (USBCON &= ~((1<<USBE)))
#define Is_usb_enabled() ((USBCON & (1<<USBE)) ? TRUE : FALSE)
#define Usb_enable_device() (USBCON |= (1<<USBE))
#define Usb_disable_device() (USBCON &= ~(1<<USBE))
#define Usb_reset_macro_only() (UDCON &= ~(1<<RSTCPU))
#define Usb_reset_all_system() (UDCON |= (1<<RSTCPU))
#if (VBUS_SENSING_IO == ENABLED)
//! Init vbus sensing i/o
#define Usb_vbus_sense_init() (VBUS_SENSE_DDR &= ~(1<<VBUS_SENSE_IO), \
VBUS_SENSE_PORT &= ~(1<<VBUS_SENSE_IO))
//! test if vbus is present
#define Is_usb_vbus_on() (((VBUS_SENSE_PIN&(1<<VBUS_SENSE_IO)) != 0) ? TRUE : FALSE)
//! test if vbus is not present
#define Is_usb_vbus_off() (((VBUS_SENSE_PIN&(1<<VBUS_SENSE_IO)) == 0) ? TRUE : FALSE)
#endif
//! 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 Ps2_enable_device() (PS2CON |= (1<<PS2EN))
#define Ps2_disable_device() (PS2CON &= ~(1<<PS2EN))
#define Usb_direct_drive_usb_enable() (UPOE |= (1<<UPWE1), UPOE &= ~(1<<UPWE0))
#define Usb_direct_drive_ps2_enable() (UPOE |= ((1<<UPWE1) | (1<<UPWE0)))
#define Usb_direct_drive_disable() (UPOE &= ~((1<<UPWE1) | (1<<UPWE0)))
#define Usb_drive_dp_high() (UPOE |= (1<<UPDRV1))
#define Usb_drive_dp_low() (UPOE &= ~(1<<UPDRV1))
#define Usb_drive_dm_high() (UPOE |= (1<<UPDRV0))
#define Usb_drive_dm_low() (UPOE &= ~(1<<UPDRV0))
#define Ps2_drive_sck_high() (UPOE |= (1<<UPDRV1))
#define Ps2_drive_sck_low() (UPOE &= ~(1<<UPDRV1))
#define Ps2_drive_data_high() (UPOE |= (1<<UPDRV0))
#define Ps2_drive_data_low() (UPOE &= ~(1<<UPDRV0))
//! 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)))
//! @}
//! @defgroup USB_device_driver USB device controller drivers
//! These macros manage the USB Device controller.
//! @{
//! initiates a remote wake-up
#define Usb_initiate_remote_wake_up() (UDCON |= (1<<RMWKUP))
//! detaches from USB bus
#define Usb_detach() (UDCON |= (1<<DETACH))
//! attaches to USB bus
#define Usb_attach() (UDCON &= ~(1<<DETACH))
//! test if remote wake-up still running
#define Is_usb_pending_remote_wake_up() ((UDCON & (1<<RMWKUP)) ? TRUE : FALSE)
//! test if the device is detached
#define Is_usb_detached() ((UDCON & (1<<DETACH)) ? TRUE : FALSE)
//! returns the USB device interrupts (interrupt enabled)
#define Usb_get_device_interrupt() (UDINT & (1<<UDIEN))
//! acks the USB device interrupts (interrupt enabled)
#define Usb_ack_all_device_interrupt() (UDINT = ~(1<<UDIEN))
//! enables remote wake-up interrupt
#define Usb_enable_remote_wake_up_interrupt() (UDIEN |= (1<<UPRSME))
//! disables remote wake-up interrupt
#define Usb_disable_remote_wake_up_interrupt() (UDIEN &= ~(1<<UPRSME))
#define Is_remote_wake_up_interrupt_enabled() ((UDIEN & (1<<UPRSME)) ? TRUE : FALSE)
//! acks remote wake-up
#define Usb_ack_remote_wake_up_start() (UDINT = ~(1<<UPRSMI))
//! tests if remote wake-up still running
#define Is_usb_remote_wake_up_start() ((UDINT & (1<<UPRSMI)) ? TRUE : FALSE)
//! enables resume interrupt
#define Usb_enable_resume_interrupt() (UDIEN |= (1<<EORSME))
//! disables resume interrupt
#define Usb_disable_resume_interrupt() (UDIEN &= ~(1<<EORSME))
#define Is_resume_interrupt_enabled() ((UDIEN & (1<<EORSME)) ? TRUE : FALSE)
//! acks resume
#define Usb_ack_resume() (UDINT = ~(1<<EORSMI))
//! tests if resume occurs
#define Is_usb_resume() ((UDINT & (1<<EORSMI)) ? TRUE : FALSE)
//! enables wake-up interrupt
#define Usb_enable_wake_up_interrupt() (UDIEN |= (1<<WAKEUPE))
//! disables wake-up interrupt
#define Usb_disable_wake_up_interrupt() (UDIEN &= ~(1<<WAKEUPE))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -