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
31 /** \ingroup Group_USB
32 * @defgroup Group_Device Device Management
34 * USB Device mode related macros and enums. This module contains macros and enums which are used when
35 * the USB controller is initialized in device mode.
40 #ifndef __USBDEVICE_H__
41 #define __USBDEVICE_H__
44 #include <avr/pgmspace.h>
45 #include <avr/eeprom.h>
47 #include "../../../Common/Common.h"
48 #include "../HighLevel/StdDescriptors.h"
51 /* Public Interface - May be used in end-application: */
53 #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__)
54 /** Mask for the Options parameter of the USB_Init() function. This indicates that the
55 * USB interface should be initialized in low speed (1.5Mb/s) mode.
57 * \note Low Speed mode is not available on all USB AVR models.
59 * \note Restrictions apply on the number, size and type of endpoints which can be used
60 * when running in low speed mode -- refer to the USB 2.0 standard.
62 #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
65 /** Mask for the Options parameter of the USB_Init() function. This indicates that the
66 * USB interface should be initialized in full speed (12Mb/s) mode.
68 #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
70 /* Pseudo-Function Macros: */
71 #if defined(__DOXYGEN__)
72 /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
73 * be taken out of suspended mode, and communications should resume.
75 * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
76 * host computer when the host has suspended all USB devices to enter a low power state.
78 * \note This macro should only be used if the device has indicated to the host that it
79 * supports the Remote Wakeup feature in the device descriptors, and should only be
80 * issued if the host is currently allowing remote wakeup events from the device (i.e.,
81 * the USB_RemoteWakeupEnabled flag is set, see DevChapter9.h documentation).
83 * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors.
85 static inline void USB_Device_SendRemoteWakeup(void);
87 /** Indicates if a Remote Wakeup request is being sent to the host. This returns true if a
88 * remote wakeup is currently being sent, false otherwise.
90 * This can be used in conjunction with the USB_Device_IsUSBSuspended() macro to determine if
91 * a sent RMWAKEUP request was accepted or rejected by the host.
93 * \note This macro should only be used if the device has indicated to the host that it
94 * supports the Remote Wakeup feature in the device descriptors.
96 * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors.
98 * \return Boolean true if no Remote Wakeup request is currently being sent, false otherwise
100 static inline bool USB_Device_IsRemoteWakeupSent(void);
102 /** Indicates if the device is currently suspended by the host. While suspended, the device is
103 * to enter a low power state until resumed by the host. While suspended no USB traffic to or
104 * from the device can occur (except for Remote Wakeup requests).
106 * \return Boolean true if the USB communications have been suspended by the host, false otherwise.
108 static inline bool USB_Device_IsUSBSuspended(void);
110 #define USB_Device_SendRemoteWakeup() MACROS{ UDCON |= (1 << RMWKUP); }MACROE
112 #define USB_Device_IsRemoteWakeupSent() ((UDCON & (1 << RMWKUP)) ? false : true)
114 #define USB_Device_IsUSBSuspended() ((UDINT & (1 << SUSPI)) ? true : false)
118 /** Enum for the ErrorCode parameter of the USB_DeviceError event.
120 * \see Events.h for more information on this event.
122 enum USB_Device_ErrorCodes_t
124 DEVICE_ERROR_GetDescriptorNotHooked
= 0, /**< Indicates that the GetDescriptor() method
125 * has not been hooked by the user application.
127 * \see StdDescriptors.h for more information on
128 * the GetDescriptor() method.
132 /* Private Interface - For use in library only: */
133 #if !defined(__DOXYGEN__)
135 #define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE
136 #define USB_Device_SetHighSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE