Descriptors.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2018.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2018 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. *
  28. * Header file for Descriptors.c.
  29. */
  30. #ifndef _DESCRIPTORS_H_
  31. #define _DESCRIPTORS_H_
  32. /* Includes: */
  33. #include <LUFA/Drivers/USB/USB.h>
  34. #include "Config/AppConfig.h"
  35. /* Macros: */
  36. /** Descriptor type value for a DFU class functional descriptor. */
  37. #define DTYPE_DFUFunctional 0x21
  38. /** DFU attribute mask, indicating that the DFU device will detach and re-attach when a DFU_DETACH
  39. * command is issued, rather than the host issuing a USB Reset.
  40. */
  41. #define ATTR_WILL_DETATCH (1 << 3)
  42. /** DFU attribute mask, indicating that the DFU device can communicate during the manifestation phase
  43. * (memory programming phase).
  44. */
  45. #define ATTR_MANEFESTATION_TOLLERANT (1 << 2)
  46. /** DFU attribute mask, indicating that the DFU device can accept DFU_UPLOAD requests to send data from
  47. * the device to the host.
  48. */
  49. #define ATTR_CAN_UPLOAD (1 << 1)
  50. /** DFU attribute mask, indicating that the DFU device can accept DFU_DNLOAD requests to send data from
  51. * the host to the device.
  52. */
  53. #define ATTR_CAN_DOWNLOAD (1 << 0)
  54. #if defined(__AVR_AT90USB1287__)
  55. #define PRODUCT_ID_CODE 0x2FFB
  56. #define AVR_SIGNATURE_1 0x1E
  57. #define AVR_SIGNATURE_2 0x97
  58. #define AVR_SIGNATURE_3 0x82
  59. #elif defined(__AVR_AT90USB647__)
  60. #define PRODUCT_ID_CODE 0x2FF9
  61. #define AVR_SIGNATURE_1 0x1E
  62. #define AVR_SIGNATURE_2 0x96
  63. #define AVR_SIGNATURE_3 0x82
  64. #elif defined(__AVR_AT90USB1286__)
  65. #define PRODUCT_ID_CODE 0x2FFB
  66. #define AVR_SIGNATURE_1 0x1E
  67. #define AVR_SIGNATURE_2 0x97
  68. #define AVR_SIGNATURE_3 0x82
  69. #elif defined(__AVR_AT90USB646__)
  70. #define PRODUCT_ID_CODE 0x2FF9
  71. #define AVR_SIGNATURE_1 0x1E
  72. #define AVR_SIGNATURE_2 0x96
  73. #define AVR_SIGNATURE_3 0x82
  74. #elif defined(__AVR_ATmega32U4__)
  75. #define PRODUCT_ID_CODE 0x2FF4
  76. #define AVR_SIGNATURE_1 0x1E
  77. #define AVR_SIGNATURE_2 0x95
  78. #define AVR_SIGNATURE_3 0x87
  79. #elif defined(__AVR_ATmega16U4__)
  80. #define PRODUCT_ID_CODE 0x2FF3
  81. #define AVR_SIGNATURE_1 0x1E
  82. #define AVR_SIGNATURE_2 0x94
  83. #define AVR_SIGNATURE_3 0x88
  84. #elif defined(__AVR_ATmega32U2__)
  85. #define PRODUCT_ID_CODE 0x2FF0
  86. #define AVR_SIGNATURE_1 0x1E
  87. #define AVR_SIGNATURE_2 0x95
  88. #define AVR_SIGNATURE_3 0x8A
  89. #elif defined(__AVR_ATmega16U2__)
  90. #define PRODUCT_ID_CODE 0x2FEF
  91. #define AVR_SIGNATURE_1 0x1E
  92. #define AVR_SIGNATURE_2 0x94
  93. #define AVR_SIGNATURE_3 0x89
  94. #elif defined(__AVR_AT90USB162__)
  95. #define PRODUCT_ID_CODE 0x2FFA
  96. #define AVR_SIGNATURE_1 0x1E
  97. #define AVR_SIGNATURE_2 0x94
  98. #define AVR_SIGNATURE_3 0x82
  99. #elif defined(__AVR_ATmega8U2__)
  100. #define PRODUCT_ID_CODE 0x2FEE
  101. #define AVR_SIGNATURE_1 0x1E
  102. #define AVR_SIGNATURE_2 0x93
  103. #define AVR_SIGNATURE_3 0x89
  104. #elif defined(__AVR_AT90USB82__)
  105. #define PRODUCT_ID_CODE 0x2FF7
  106. #define AVR_SIGNATURE_1 0x1E
  107. #define AVR_SIGNATURE_2 0x93
  108. #define AVR_SIGNATURE_3 0x82
  109. #else
  110. #error The selected AVR part is not currently supported by this bootloader.
  111. #endif
  112. #if !defined(PRODUCT_ID_CODE)
  113. #error Current AVR model is not supported by this bootloader.
  114. #endif
  115. /* Type Defines: */
  116. /** Type define for a DFU class function descriptor. This descriptor gives DFU class information
  117. * to the host when read, indicating the DFU device's capabilities.
  118. */
  119. typedef struct
  120. {
  121. USB_Descriptor_Header_t Header; /**< Standard descriptor header structure */
  122. uint8_t Attributes; /**< DFU device attributes, a mask comprising of the
  123. * ATTR_* macros listed in this source file
  124. */
  125. uint16_t DetachTimeout; /**< Timeout in milliseconds between a USB_DETACH
  126. * command being issued and the device detaching
  127. * from the USB bus
  128. */
  129. uint16_t TransferSize; /**< Maximum number of bytes the DFU device can accept
  130. * from the host in a transaction
  131. */
  132. uint16_t DFUSpecification; /**< BCD packed DFU specification number this DFU
  133. * device complies with
  134. */
  135. } USB_Descriptor_DFU_Functional_t;
  136. /** Type define for the device configuration descriptor structure. This must be defined in the
  137. * application code, as the configuration descriptor contains several sub-descriptors which
  138. * vary between devices, and which describe the device's usage to the host.
  139. */
  140. typedef struct
  141. {
  142. USB_Descriptor_Configuration_Header_t Config;
  143. // DFU Interface
  144. USB_Descriptor_Interface_t DFU_Interface;
  145. USB_Descriptor_DFU_Functional_t DFU_Functional;
  146. } USB_Descriptor_Configuration_t;
  147. /** Enum for the device interface descriptor IDs within the device. Each interface descriptor
  148. * should have a unique ID index associated with it, which can be used to refer to the
  149. * interface from other descriptors.
  150. */
  151. enum InterfaceDescriptors_t
  152. {
  153. INTERFACE_ID_DFU = 0, /**< DFU interface descriptor ID */
  154. };
  155. /** Enum for the device string descriptor IDs within the device. Each string descriptor should
  156. * have a unique ID index associated with it, which can be used to refer to the string from
  157. * other descriptors.
  158. */
  159. enum StringDescriptors_t
  160. {
  161. STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */
  162. STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */
  163. STRING_ID_Product = 2, /**< Product string ID */
  164. };
  165. /* Function Prototypes: */
  166. uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
  167. const uint16_t wIndex,
  168. const void** const DescriptorAddress)
  169. ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
  170. #endif