📄 lowlevel.h
字号:
/* LUFA Library Copyright (C) Dean Camera, 2009. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com*//* Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software.*//** \file * * Main low level USB driver. This module manages the low level initialization and shut down of the USB AVR's * USB interface in either device or (if supported) host mode. */#ifndef __USBLOWLEVEL_H__#define __USBLOWLEVEL_H__ /* Includes: */ #include <avr/io.h> #include <avr/interrupt.h> #include <stdbool.h> #include "USBMode.h" #include "../../../Common/Common.h" #include "../HighLevel/Events.h" #include "../HighLevel/USBTask.h" #include "../HighLevel/USBInterrupt.h" #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) #include "Host.h" #include "Pipe.h" #include "OTG.h" #endif #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) #include "Device.h" #include "Endpoint.h" #include "DevChapter9.h" #endif /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) extern "C" { #endif /* Preprocessor Checks and Defines: */ #if (F_CPU == 8000000) #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__)) #define USB_PLL_PSC 0 #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || \ defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || \ defined(__AVR_ATmega32U6__)) #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) #define USB_PLL_PSC 0 #endif #elif (F_CPU == 16000000) #if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__)) #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP1)) #elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)) #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP0)) #elif (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__)) #define USB_PLL_PSC (1 << PLLP0) #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) #define USB_PLL_PSC (1 << PINDIV) #endif #endif #if !defined(USB_PLL_PSC) #error No PLL prescale value available for chosen F_CPU value and AVR model. #endif /* Public Interface - May be used in end-application: */ /* Macros: */ /** Mode mask for the USB_CurrentMode global. This indicates that the USB interface is currently not * initialized into any mode. */ #define USB_MODE_NONE 0 /** Mode mask for the USB_CurrentMode global and the USB_Init() function. This indicates that the * USB interface is or should be initialized in the USB device mode. */ #define USB_MODE_DEVICE 1 /** Mode mask for the USB_CurrentMode global and the USB_Init() function. This indicates that the * USB interface is or should be initialized in the USB host mode. * * \note Not all USB AVRs support host mode. */ #define USB_MODE_HOST 2 /** Mode mask for the the USB_Init() function. This indicates that the USB interface should be * initialized into whatever mode the UID pin of the USB AVR indicates, and that the device * should swap over its mode when the level of the UID pin changes during operation. * * \note Not all USB AVRs support host mode, and thus UID mode. */ #define USB_MODE_UID 3 /** Regulator disable option mask for USB_Init(). This indicates that the internal 3.3V USB data pad * regulator should be enabled to regulate the data pin voltages to within the USB standard. * * \note See USB AVR data sheet for more information on the internal pad regulator. */ #define USB_OPT_REG_DISABLED (1 << 1) /** Regulator enable option mask for USB_Init(). This indicates that the internal 3.3V USB data pad * regulator should be disabled and the AVR's VCC level used for the data pads. * * \note See USB AVR data sheet for more information on the internal pad regulator. */ #define USB_OPT_REG_ENABLED (0 << 1) /** Manual PLL control option mask for USB_Init(). This indicates to the library that the user application * will take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. */ #define USB_OPT_MANUAL_PLL (1 << 2) /** Automatic PLL control option mask for USB_Init(). This indicates to the library that the library should * take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. */ #define USB_OPT_AUTO_PLL (0 << 2) /** Mask for a CONTROL type endpoint or pipe. * * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. */ #define EP_TYPE_CONTROL 0x00 /** Mask for an ISOCHRONOUS type endpoint or pipe. * * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. */ #define EP_TYPE_ISOCHRONOUS 0x01 /** Mask for a BULK type endpoint or pipe. * * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. */ #define EP_TYPE_BULK 0x02 /** Mask for an INTERRUPT type endpoint or pipe. * * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. */ #define EP_TYPE_INTERRUPT 0x03 /** Mask for determining the type of an endpoint or pipe. This should then be compared with the * EP_TYPE_* macros elsewhere in this module to determine the exact type of the endpoint or pipe. * * \note See Endpoint.h and Pipe.h headers for endpoint/pipe functions. */ #define EP_TYPE_MASK 0x03 /** Returns boolean true if the VBUS line is currently high (i.e. the USB host is supplying power), * otherwise returns false. */ #define USB_VBUS_GetStatus() ((USBSTA & (1 << VBUS)) ? true : false) /** Detaches the device from the USB bus. This has the effect of removing the device from any * host if, ceasing USB communications. If no host is present, this prevents any host from * enumerating the device once attached until USB_Attach() is called.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -