Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OTG_AVR8.h 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief USB OTG definitions for the AVR8 microcontrollers.
  28. * \copydetails Group_OTG_AVR8
  29. *
  30. * \note This file should not be included directly. It is automatically included as needed by the USB driver
  31. * dispatch header located in LUFA/Drivers/USB/USB.h.
  32. */
  33. /** \ingroup Group_OTG
  34. * \defgroup Group_OTG_AVR8 USB On The Go (OTG) Management (AVR8)
  35. * \brief USB OTG definitions for the AVR8 microcontrollers.
  36. *
  37. * Architecture specific USB OTG definitions for the Atmel 8-bit AVR microcontrollers.
  38. *
  39. * @{
  40. */
  41. #ifndef __USBOTG_AVR8_H__
  42. #define __USBOTG_AVR8_H__
  43. /* Includes: */
  44. #include "../../../../Common/Common.h"
  45. /* Enable C linkage for C++ Compilers: */
  46. #if defined(__cplusplus)
  47. extern "C" {
  48. #endif
  49. /* Preprocessor Checks: */
  50. #if !defined(__INCLUDE_FROM_USB_DRIVER)
  51. #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
  52. #endif
  53. /* Public Interface - May be used in end-application: */
  54. /* Macros: */
  55. /** Mask for the VBUS pulsing method of SRP, supported by some OTG devices.
  56. *
  57. * \see \ref USB_OTG_Device_InitiateSRP().
  58. */
  59. #define USB_OTG_SRP_VBUS (1 << SRPSEL)
  60. /** Mask for the Data + pulsing method of SRP, supported by some OTG devices.
  61. *
  62. * \see \ref USB_OTG_Device_InitiateSRP().
  63. */
  64. #define USB_OTG_STP_DATA 0
  65. /* Inline Functions: */
  66. /** Initiate a Host Negotiation Protocol request. This indicates to the other connected device
  67. * that the device wishes to change device/host roles.
  68. */
  69. static inline void USB_OTG_Device_RequestHNP(void) ATTR_ALWAYS_INLINE;
  70. static inline void USB_OTG_Device_RequestHNP(void)
  71. {
  72. OTGCON |= (1 << HNPREQ);
  73. }
  74. /** Cancel a Host Negotiation Protocol request. This stops a pending HNP request to the other
  75. * connected device.
  76. */
  77. static inline void USB_OTG_Device_CancelHNPRequest(void) ATTR_ALWAYS_INLINE;
  78. static inline void USB_OTG_Device_CancelHNPRequest(void)
  79. {
  80. OTGCON &= ~(1 << HNPREQ);
  81. }
  82. /** Determines if the device is currently sending a HNP to an attached host.
  83. *
  84. * \return Boolean \c true if currently sending a HNP to the other connected device, \c false otherwise
  85. */
  86. static inline bool USB_OTG_Device_IsSendingHNP(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
  87. static inline bool USB_OTG_Device_IsSendingHNP(void)
  88. {
  89. return ((OTGCON & (1 << HNPREQ)) ? true : false);
  90. }
  91. /** Initiates a Session Request Protocol request. Most OTG devices turn off VBUS when the USB
  92. * interface is not in use, to conserve power. Sending a SRP to a USB OTG device running in
  93. * host mode indicates that VBUS should be applied and a session started.
  94. *
  95. * There are two different methods of sending a SRP - either pulses on the VBUS line, or by
  96. * pulsing the Data + line via the internal pull-up resistor.
  97. *
  98. * \param[in] SRPTypeMask Mask indicating the type of SRP to use, either \ref USB_OTG_SRP_VBUS or
  99. * \ref USB_OTG_STP_DATA.
  100. */
  101. static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask) ATTR_ALWAYS_INLINE;
  102. static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask)
  103. {
  104. OTGCON = ((OTGCON & ~(1 << SRPSEL)) | (SRPTypeMask | (1 << SRPREQ)));
  105. }
  106. /** Accepts a HNP from a connected device, indicating that both devices should exchange
  107. * device/host roles.
  108. */
  109. static inline void USB_OTG_Host_AcceptHNP(void) ATTR_ALWAYS_INLINE;
  110. static inline void USB_OTG_Host_AcceptHNP(void)
  111. {
  112. OTGCON |= (1 << HNPREQ);
  113. }
  114. /** Rejects a HNP from a connected device, indicating that both devices should remain in their
  115. * current device/host roles.
  116. */
  117. static inline void USB_OTG_Host_RejectHNP(void) ATTR_ALWAYS_INLINE;
  118. static inline void USB_OTG_Host_RejectHNP(void)
  119. {
  120. OTGCON &= ~(1 << HNPREQ);
  121. }
  122. /** Indicates if the connected device is currently sending a HNP request.
  123. *
  124. * \return Boolean \c true if a HNP is currently being issued by the connected device, \c false otherwise.
  125. */
  126. static inline bool USB_OTG_Host_IsHNPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
  127. static inline bool USB_OTG_Host_IsHNPReceived(void)
  128. {
  129. return ((OTGCON & (1 << HNPREQ)) ? true : false);
  130. }
  131. /* Disable C linkage for C++ Compilers: */
  132. #if defined(__cplusplus)
  133. }
  134. #endif
  135. #endif
  136. /** @} */