3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 * USB Device mode related macros and enums. This module contains macros and enums which are used when
34 * the USB controller is initialized in device mode.
37 #ifndef __USBDEVICE_H__
38 #define __USBDEVICE_H__
41 #include <avr/pgmspace.h>
42 #include <avr/eeprom.h>
44 #include "../../../Common/Common.h"
45 #include "../HighLevel/StdDescriptors.h"
48 /* Public Interface - May be used in end-application: */
50 #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__)
51 /** Mask for the Options parameter of the USB_Init() function. This indicates that the
52 * USB interface should be initialized in low speed (1.5Mb/s) mode.
54 * \note Low Speed mode is not available on all USB AVR models.
56 * \note Restrictions apply on the number, size and type of endpoints which can be used
57 * when running in low speed mode -- refer to the USB 2.0 standard.
59 #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
62 /** Mask for the Options parameter of the USB_Init() function. This indicates that the
63 * USB interface should be initialized in full speed (12Mb/s) mode.
65 #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
67 /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
68 * be taken out of suspended mode, and communications should resume.
70 * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
71 * host computer when the host has suspended all USB devices to enter a low power state.
73 * \note This macro should only be used if the device has indicated to the host that it
74 * supports the Remote Wakeup feature in the device descriptors, and should only be
75 * issued if the host is currently allowing remote wakeup events from the device (i.e.,
76 * the USB_RemoteWakeupEnabled flag is set, see DevChapter9.h documentation).
78 * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors.
80 #define USB_Device_SendRemoteWakeup() MACROS{ UDCON |= (1 << RMWKUP); }MACROE
82 /** Indicates if a Remote Wakeup request is being sent to the host. This returns true if a
83 * remote wakeup is currently being sent, false otherwise.
85 * This can be used in conjunction with the USB_Device_IsUSBSuspended() macro to determine if
86 * a sent RMWAKEUP request was accepted or rejected by the host.
88 * \note This macro should only be used if the device has indicated to the host that it
89 * supports the Remote Wakeup feature in the device descriptors.
91 * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors.
93 #define USB_Device_IsRemoteWakeupSent() ((UDCON & (1 << RMWKUP)) ? false : true)
95 /** Indicates if the device is currently suspended by the host. While suspended, the device is
96 * to enter a low power state until resumed by the host. While suspended no USB traffic to or
97 * from the device can ocurr (except for Remote Wakeup requests).
99 * This macro returns true if the USB communications have been suspended by the host, false
102 #define USB_Device_IsUSBSuspended() ((UDINT & (1 << SUSPI)) ? true : false)
105 /** Enum for the ErrorCode parameter of the USB_DeviceError event.
107 * \see Events.h for more information on this event.
109 enum USB_Device_ErrorCodes_t
111 DEVICE_ERROR_GetDescriptorNotHooked
= 0, /**< Indicates that the GetDescriptor() method
112 * has not been hooked by the user application.
114 * \see StdDescriptors.h for more information on
115 * the GetDescriptor() method.
119 /* Private Interface - For use in library only: */
120 #if !defined(__DOXYGEN__)
122 #define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE
123 #define USB_Device_SetHighSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE