Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

347 lines
11 KiB

  1. /**
  2. ******************************************************************************
  3. * @file usbd_def.h
  4. * @author MCD Application Team
  5. * @brief General defines for the usb device library
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * http://www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __USBD_DEF_H
  21. #define __USBD_DEF_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "usbd_conf.h"
  27. /** @addtogroup STM32_USBD_DEVICE_LIBRARY
  28. * @{
  29. */
  30. /** @defgroup USB_DEF
  31. * @brief general defines for the usb device library file
  32. * @{
  33. */
  34. /** @defgroup USB_DEF_Exported_Defines
  35. * @{
  36. */
  37. #ifndef NULL
  38. #define NULL 0U
  39. #endif /* NULL */
  40. #ifndef USBD_MAX_NUM_INTERFACES
  41. #define USBD_MAX_NUM_INTERFACES 1U
  42. #endif /* USBD_MAX_NUM_CONFIGURATION */
  43. #ifndef USBD_MAX_NUM_CONFIGURATION
  44. #define USBD_MAX_NUM_CONFIGURATION 1U
  45. #endif /* USBD_MAX_NUM_CONFIGURATION */
  46. #ifndef USBD_LPM_ENABLED
  47. #define USBD_LPM_ENABLED 0U
  48. #endif /* USBD_LPM_ENABLED */
  49. #ifndef USBD_SELF_POWERED
  50. #define USBD_SELF_POWERED 1U
  51. #endif /*USBD_SELF_POWERED */
  52. #ifndef USBD_SUPPORT_USER_STRING
  53. #define USBD_SUPPORT_USER_STRING 0U
  54. #endif /* USBD_SUPPORT_USER_STRING */
  55. #define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
  56. #define USB_LEN_DEV_DESC 0x12U
  57. #define USB_LEN_CFG_DESC 0x09U
  58. #define USB_LEN_IF_DESC 0x09U
  59. #define USB_LEN_EP_DESC 0x07U
  60. #define USB_LEN_OTG_DESC 0x03U
  61. #define USB_LEN_LANGID_STR_DESC 0x04U
  62. #define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U
  63. #define USBD_IDX_LANGID_STR 0x00U
  64. #define USBD_IDX_MFC_STR 0x01U
  65. #define USBD_IDX_PRODUCT_STR 0x02U
  66. #define USBD_IDX_SERIAL_STR 0x03U
  67. #define USBD_IDX_CONFIG_STR 0x04U
  68. #define USBD_IDX_INTERFACE_STR 0x05U
  69. #define USB_REQ_TYPE_STANDARD 0x00U
  70. #define USB_REQ_TYPE_CLASS 0x20U
  71. #define USB_REQ_TYPE_VENDOR 0x40U
  72. #define USB_REQ_TYPE_MASK 0x60U
  73. #define USB_REQ_RECIPIENT_DEVICE 0x00U
  74. #define USB_REQ_RECIPIENT_INTERFACE 0x01U
  75. #define USB_REQ_RECIPIENT_ENDPOINT 0x02U
  76. #define USB_REQ_RECIPIENT_MASK 0x03U
  77. #define USB_REQ_GET_STATUS 0x00U
  78. #define USB_REQ_CLEAR_FEATURE 0x01U
  79. #define USB_REQ_SET_FEATURE 0x03U
  80. #define USB_REQ_SET_ADDRESS 0x05U
  81. #define USB_REQ_GET_DESCRIPTOR 0x06U
  82. #define USB_REQ_SET_DESCRIPTOR 0x07U
  83. #define USB_REQ_GET_CONFIGURATION 0x08U
  84. #define USB_REQ_SET_CONFIGURATION 0x09U
  85. #define USB_REQ_GET_INTERFACE 0x0AU
  86. #define USB_REQ_SET_INTERFACE 0x0BU
  87. #define USB_REQ_SYNCH_FRAME 0x0CU
  88. #define USB_DESC_TYPE_DEVICE 0x01U
  89. #define USB_DESC_TYPE_CONFIGURATION 0x02U
  90. #define USB_DESC_TYPE_STRING 0x03U
  91. #define USB_DESC_TYPE_INTERFACE 0x04U
  92. #define USB_DESC_TYPE_ENDPOINT 0x05U
  93. #define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
  94. #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
  95. #define USB_DESC_TYPE_BOS 0x0FU
  96. #define USB_CONFIG_REMOTE_WAKEUP 0x02U
  97. #define USB_CONFIG_SELF_POWERED 0x01U
  98. #define USB_FEATURE_EP_HALT 0x00U
  99. #define USB_FEATURE_REMOTE_WAKEUP 0x01U
  100. #define USB_FEATURE_TEST_MODE 0x02U
  101. #define USB_DEVICE_CAPABITY_TYPE 0x10U
  102. #define USB_HS_MAX_PACKET_SIZE 512U
  103. #define USB_FS_MAX_PACKET_SIZE 64U
  104. #define USB_MAX_EP0_SIZE 64U
  105. /* Device Status */
  106. #define USBD_STATE_DEFAULT 0x01U
  107. #define USBD_STATE_ADDRESSED 0x02U
  108. #define USBD_STATE_CONFIGURED 0x03U
  109. #define USBD_STATE_SUSPENDED 0x04U
  110. /* EP0 State */
  111. #define USBD_EP0_IDLE 0x00U
  112. #define USBD_EP0_SETUP 0x01U
  113. #define USBD_EP0_DATA_IN 0x02U
  114. #define USBD_EP0_DATA_OUT 0x03U
  115. #define USBD_EP0_STATUS_IN 0x04U
  116. #define USBD_EP0_STATUS_OUT 0x05U
  117. #define USBD_EP0_STALL 0x06U
  118. #define USBD_EP_TYPE_CTRL 0x00U
  119. #define USBD_EP_TYPE_ISOC 0x01U
  120. #define USBD_EP_TYPE_BULK 0x02U
  121. #define USBD_EP_TYPE_INTR 0x03U
  122. /**
  123. * @}
  124. */
  125. /** @defgroup USBD_DEF_Exported_TypesDefinitions
  126. * @{
  127. */
  128. typedef struct usb_setup_req
  129. {
  130. uint8_t bmRequest;
  131. uint8_t bRequest;
  132. uint16_t wValue;
  133. uint16_t wIndex;
  134. uint16_t wLength;
  135. }USBD_SetupReqTypedef;
  136. struct _USBD_HandleTypeDef;
  137. typedef struct _Device_cb
  138. {
  139. uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
  140. uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
  141. /* Control Endpoints*/
  142. uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
  143. uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev );
  144. uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev );
  145. /* Class Specific Endpoints*/
  146. uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
  147. uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
  148. uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev);
  149. uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
  150. uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
  151. uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
  152. uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
  153. uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
  154. uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
  155. #if (USBD_SUPPORT_USER_STRING == 1U)
  156. uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length);
  157. #endif
  158. } USBD_ClassTypeDef;
  159. /* Following USB Device Speed */
  160. typedef enum
  161. {
  162. USBD_SPEED_HIGH = 0U,
  163. USBD_SPEED_FULL = 1U,
  164. USBD_SPEED_LOW = 2U,
  165. }USBD_SpeedTypeDef;
  166. /* Following USB Device status */
  167. typedef enum {
  168. USBD_OK = 0U,
  169. USBD_BUSY,
  170. USBD_FAIL,
  171. }USBD_StatusTypeDef;
  172. /* USB Device descriptors structure */
  173. typedef struct
  174. {
  175. uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  176. uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  177. uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  178. uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  179. uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  180. uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  181. uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  182. #if (USBD_LPM_ENABLED == 1U)
  183. uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
  184. #endif
  185. } USBD_DescriptorsTypeDef;
  186. /* USB Device handle structure */
  187. typedef struct
  188. {
  189. uint32_t status;
  190. uint32_t is_used;
  191. uint32_t total_length;
  192. uint32_t rem_length;
  193. uint32_t maxpacket;
  194. } USBD_EndpointTypeDef;
  195. /* USB Device handle structure */
  196. typedef struct _USBD_HandleTypeDef
  197. {
  198. uint8_t id;
  199. uint32_t dev_config;
  200. uint32_t dev_default_config;
  201. uint32_t dev_config_status;
  202. USBD_SpeedTypeDef dev_speed;
  203. USBD_EndpointTypeDef ep_in[15];
  204. USBD_EndpointTypeDef ep_out[15];
  205. uint32_t ep0_state;
  206. uint32_t ep0_data_len;
  207. uint8_t dev_state;
  208. uint8_t dev_old_state;
  209. uint8_t dev_address;
  210. uint8_t dev_connection_status;
  211. uint8_t dev_test_mode;
  212. uint32_t dev_remote_wakeup;
  213. USBD_SetupReqTypedef request;
  214. USBD_DescriptorsTypeDef *pDesc;
  215. USBD_ClassTypeDef *pClass;
  216. void *pClassData;
  217. void *pUserData;
  218. void *pData;
  219. } USBD_HandleTypeDef;
  220. /**
  221. * @}
  222. */
  223. /** @defgroup USBD_DEF_Exported_Macros
  224. * @{
  225. */
  226. #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
  227. (((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
  228. #define LOBYTE(x) ((uint8_t)(x & 0x00FFU))
  229. #define HIBYTE(x) ((uint8_t)((x & 0xFF00U) >> 8U))
  230. #ifndef MIN
  231. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  232. #endif
  233. #ifndef MAX
  234. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  235. #endif
  236. #if defined ( __GNUC__ )
  237. #ifndef __weak
  238. #define __weak __attribute__((weak))
  239. #endif /* __weak */
  240. #ifndef __packed
  241. #define __packed __attribute__((__packed__))
  242. #endif /* __packed */
  243. #endif /* __GNUC__ */
  244. /* In HS mode and when the DMA is used, all variables and data structures dealing
  245. with the DMA during the transaction process should be 4-bytes aligned */
  246. #if defined (__GNUC__) /* GNU Compiler */
  247. #define __ALIGN_END __attribute__ ((aligned (4)))
  248. #define __ALIGN_BEGIN
  249. #else
  250. #define __ALIGN_END
  251. #if defined (__CC_ARM) /* ARM Compiler */
  252. #define __ALIGN_BEGIN __align(4)
  253. #elif defined (__ICCARM__) /* IAR Compiler */
  254. #define __ALIGN_BEGIN
  255. #elif defined (__TASKING__) /* TASKING Compiler */
  256. #define __ALIGN_BEGIN __align(4)
  257. #endif /* __CC_ARM */
  258. #endif /* __GNUC__ */
  259. /**
  260. * @}
  261. */
  262. /** @defgroup USBD_DEF_Exported_Variables
  263. * @{
  264. */
  265. /**
  266. * @}
  267. */
  268. /** @defgroup USBD_DEF_Exported_FunctionsPrototype
  269. * @{
  270. */
  271. /**
  272. * @}
  273. */
  274. #ifdef __cplusplus
  275. }
  276. #endif
  277. #endif /* __USBD_DEF_H */
  278. /**
  279. * @}
  280. */
  281. /**
  282. * @}
  283. */
  284. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/