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.
 
 
 
 
 
 

217 lines
4.5 KiB

  1. /**
  2. ******************************************************************************
  3. * @file usbd_ioreq.c
  4. * @author MCD Application Team
  5. * @brief This file provides the IO requests APIs for control endpoints.
  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. /* Includes ------------------------------------------------------------------*/
  20. #include "usbd_ioreq.h"
  21. /** @addtogroup STM32_USB_DEVICE_LIBRARY
  22. * @{
  23. */
  24. /** @defgroup USBD_IOREQ
  25. * @brief control I/O requests module
  26. * @{
  27. */
  28. /** @defgroup USBD_IOREQ_Private_TypesDefinitions
  29. * @{
  30. */
  31. /**
  32. * @}
  33. */
  34. /** @defgroup USBD_IOREQ_Private_Defines
  35. * @{
  36. */
  37. /**
  38. * @}
  39. */
  40. /** @defgroup USBD_IOREQ_Private_Macros
  41. * @{
  42. */
  43. /**
  44. * @}
  45. */
  46. /** @defgroup USBD_IOREQ_Private_Variables
  47. * @{
  48. */
  49. /**
  50. * @}
  51. */
  52. /** @defgroup USBD_IOREQ_Private_FunctionPrototypes
  53. * @{
  54. */
  55. /**
  56. * @}
  57. */
  58. /** @defgroup USBD_IOREQ_Private_Functions
  59. * @{
  60. */
  61. /**
  62. * @brief USBD_CtlSendData
  63. * send data on the ctl pipe
  64. * @param pdev: device instance
  65. * @param buff: pointer to data buffer
  66. * @param len: length of data to be sent
  67. * @retval status
  68. */
  69. USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
  70. uint16_t len)
  71. {
  72. /* Set EP0 State */
  73. pdev->ep0_state = USBD_EP0_DATA_IN;
  74. pdev->ep_in[0].total_length = len;
  75. pdev->ep_in[0].rem_length = len;
  76. /* Start the transfer */
  77. USBD_LL_Transmit (pdev, 0x00U, pbuf, len);
  78. return USBD_OK;
  79. }
  80. /**
  81. * @brief USBD_CtlContinueSendData
  82. * continue sending data on the ctl pipe
  83. * @param pdev: device instance
  84. * @param buff: pointer to data buffer
  85. * @param len: length of data to be sent
  86. * @retval status
  87. */
  88. USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
  89. uint8_t *pbuf, uint16_t len)
  90. {
  91. /* Start the next transfer */
  92. USBD_LL_Transmit (pdev, 0x00U, pbuf, len);
  93. return USBD_OK;
  94. }
  95. /**
  96. * @brief USBD_CtlPrepareRx
  97. * receive data on the ctl pipe
  98. * @param pdev: device instance
  99. * @param buff: pointer to data buffer
  100. * @param len: length of data to be received
  101. * @retval status
  102. */
  103. USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
  104. uint16_t len)
  105. {
  106. /* Set EP0 State */
  107. pdev->ep0_state = USBD_EP0_DATA_OUT;
  108. pdev->ep_out[0].total_length = len;
  109. pdev->ep_out[0].rem_length = len;
  110. /* Start the transfer */
  111. USBD_LL_PrepareReceive (pdev, 0U, pbuf, len);
  112. return USBD_OK;
  113. }
  114. /**
  115. * @brief USBD_CtlContinueRx
  116. * continue receive data on the ctl pipe
  117. * @param pdev: device instance
  118. * @param buff: pointer to data buffer
  119. * @param len: length of data to be received
  120. * @retval status
  121. */
  122. USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
  123. uint16_t len)
  124. {
  125. USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
  126. return USBD_OK;
  127. }
  128. /**
  129. * @brief USBD_CtlSendStatus
  130. * send zero lzngth packet on the ctl pipe
  131. * @param pdev: device instance
  132. * @retval status
  133. */
  134. USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev)
  135. {
  136. /* Set EP0 State */
  137. pdev->ep0_state = USBD_EP0_STATUS_IN;
  138. /* Start the transfer */
  139. USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
  140. return USBD_OK;
  141. }
  142. /**
  143. * @brief USBD_CtlReceiveStatus
  144. * receive zero lzngth packet on the ctl pipe
  145. * @param pdev: device instance
  146. * @retval status
  147. */
  148. USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev)
  149. {
  150. /* Set EP0 State */
  151. pdev->ep0_state = USBD_EP0_STATUS_OUT;
  152. /* Start the transfer */
  153. USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U);
  154. return USBD_OK;
  155. }
  156. /**
  157. * @brief USBD_GetRxCount
  158. * returns the received data length
  159. * @param pdev: device instance
  160. * @param ep_addr: endpoint address
  161. * @retval Rx Data blength
  162. */
  163. uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
  164. {
  165. return USBD_LL_GetRxDataSize(pdev, ep_addr);
  166. }
  167. /**
  168. * @}
  169. */
  170. /**
  171. * @}
  172. */
  173. /**
  174. * @}
  175. */
  176. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/