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 /** \ingroup Group_USB
38 * @defgroup Group_Device Device Management
40 * Functions, macros, variables, enums and types related to the management of a USB device when in Device mode.
45 #ifndef __USBDEVICE_H__
46 #define __USBDEVICE_H__
49 #include <avr/pgmspace.h>
50 #include <avr/eeprom.h>
52 #include "../../../Common/Common.h"
53 #include "../HighLevel/StdDescriptors.h"
56 /* Public Interface - May be used in end-application: */
58 #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__)
59 /** Mask for the Options parameter of the USB_Init() function. This indicates that the
60 * USB interface should be initialized in low speed (1.5Mb/s) mode.
62 * \note Low Speed mode is not available on all USB AVR models.
64 * \note Restrictions apply on the number, size and type of endpoints which can be used
65 * when running in low speed mode -- refer to the USB 2.0 standard.
67 #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
70 /** Mask for the Options parameter of the USB_Init() function. This indicates that the
71 * USB interface should be initialized in full speed (12Mb/s) mode.
73 #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
75 /* Psuedo-Function Macros: */
76 #if defined(__DOXYGEN__)
77 /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
78 * be taken out of suspended mode, and communications should resume.
80 * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
81 * host computer when the host has suspended all USB devices to enter a low power state.
83 * \note This macro should only be used if the device has indicated to the host that it
84 * supports the Remote Wakeup feature in the device descriptors, and should only be
85 * issued if the host is currently allowing remote wakeup events from the device (i.e.,
86 * the USB_RemoteWakeupEnabled flag is set, see DevChapter9.h documentation).
88 * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors.
90 static inline void USB_Device_SendRemoteWakeup(void);
92 /** Indicates if a Remote Wakeup request is being sent to the host. This returns true if a
93 * remote wakeup is currently being sent, false otherwise.
95 * This can be used in conjunction with the USB_Device_IsUSBSuspended() macro to determine if
96 * a sent RMWAKEUP request was accepted or rejected by the host.
98 * \note This macro should only be used if the device has indicated to the host that it
99 * supports the Remote Wakeup feature in the device descriptors.
101 * \see StdDescriptors.h for more information on the RMWAKEUP feature and device descriptors.
103 * \return Boolean true if no Remote Wakeup request is currently being sent, false otherwise
105 static inline bool USB_Device_IsRemoteWakeupSent(void);
107 /** Indicates if the device is currently suspended by the host. While suspended, the device is
108 * to enter a low power state until resumed by the host. While suspended no USB traffic to or
109 * from the device can occur (except for Remote Wakeup requests).
111 * \return Boolean true if the USB communications have been suspended by the host, false otherwise.
113 static inline bool USB_Device_IsUSBSuspended(void);
115 #define USB_Device_SendRemoteWakeup() MACROS{ UDCON |= (1 << RMWKUP); }MACROE
117 #define USB_Device_IsRemoteWakeupSent() ((UDCON & (1 << RMWKUP)) ? false : true)
119 #define USB_Device_IsUSBSuspended() ((UDINT & (1 << SUSPI)) ? true : false)
123 /** Enum for the ErrorCode parameter of the USB_DeviceError event.
125 * \see Events.h for more information on this event.
127 enum USB_Device_ErrorCodes_t
129 DEVICE_ERROR_GetDescriptorNotHooked
= 0, /**< Indicates that the GetDescriptor() method
130 * has not been hooked by the user application.
132 * \see StdDescriptors.h for more information on
133 * the GetDescriptor() method.
137 /* Private Interface - For use in library only: */
138 #if !defined(__DOXYGEN__)
140 #define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE
141 #define USB_Device_SetHighSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE