Browse code

Add source code of the firmware for the IO Board

Pawel Jablonski authored on 05/06/2023 17:01:27
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,224 @@
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
+  * Copyright (c) 2015 STMicroelectronics.
10
+  * All rights reserved.
11
+  *
12
+  * This software is licensed under terms that can be found in the LICENSE file
13
+  * in the root directory of this software component.
14
+  * If no LICENSE file comes with this software, it is provided AS-IS.
15
+  *
16
+  ******************************************************************************
17
+  */
18
+
19
+/* Includes ------------------------------------------------------------------*/
20
+#include "usbd_ioreq.h"
21
+
22
+/** @addtogroup STM32_USB_DEVICE_LIBRARY
23
+  * @{
24
+  */
25
+
26
+
27
+/** @defgroup USBD_IOREQ
28
+  * @brief control I/O requests module
29
+  * @{
30
+  */
31
+
32
+/** @defgroup USBD_IOREQ_Private_TypesDefinitions
33
+  * @{
34
+  */
35
+/**
36
+  * @}
37
+  */
38
+
39
+
40
+/** @defgroup USBD_IOREQ_Private_Defines
41
+  * @{
42
+  */
43
+
44
+/**
45
+  * @}
46
+  */
47
+
48
+
49
+/** @defgroup USBD_IOREQ_Private_Macros
50
+  * @{
51
+  */
52
+/**
53
+  * @}
54
+  */
55
+
56
+
57
+/** @defgroup USBD_IOREQ_Private_Variables
58
+  * @{
59
+  */
60
+
61
+/**
62
+  * @}
63
+  */
64
+
65
+
66
+/** @defgroup USBD_IOREQ_Private_FunctionPrototypes
67
+  * @{
68
+  */
69
+/**
70
+  * @}
71
+  */
72
+
73
+
74
+/** @defgroup USBD_IOREQ_Private_Functions
75
+  * @{
76
+  */
77
+
78
+/**
79
+  * @brief  USBD_CtlSendData
80
+  *         send data on the ctl pipe
81
+  * @param  pdev: device instance
82
+  * @param  buff: pointer to data buffer
83
+  * @param  len: length of data to be sent
84
+  * @retval status
85
+  */
86
+USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
87
+                                    uint8_t *pbuf, uint32_t len)
88
+{
89
+  /* Set EP0 State */
90
+  pdev->ep0_state = USBD_EP0_DATA_IN;
91
+  pdev->ep_in[0].total_length = len;
92
+
93
+#ifdef USBD_AVOID_PACKET_SPLIT_MPS
94
+  pdev->ep_in[0].rem_length = 0U;
95
+#else
96
+  pdev->ep_in[0].rem_length = len;
97
+#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
98
+
99
+  /* Start the transfer */
100
+  (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
101
+
102
+  return USBD_OK;
103
+}
104
+
105
+/**
106
+  * @brief  USBD_CtlContinueSendData
107
+  *         continue sending data on the ctl pipe
108
+  * @param  pdev: device instance
109
+  * @param  buff: pointer to data buffer
110
+  * @param  len: length of data to be sent
111
+  * @retval status
112
+  */
113
+USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
114
+                                            uint8_t *pbuf, uint32_t len)
115
+{
116
+  /* Start the next transfer */
117
+  (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
118
+
119
+  return USBD_OK;
120
+}
121
+
122
+/**
123
+  * @brief  USBD_CtlPrepareRx
124
+  *         receive data on the ctl pipe
125
+  * @param  pdev: device instance
126
+  * @param  buff: pointer to data buffer
127
+  * @param  len: length of data to be received
128
+  * @retval status
129
+  */
130
+USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
131
+                                     uint8_t *pbuf, uint32_t len)
132
+{
133
+  /* Set EP0 State */
134
+  pdev->ep0_state = USBD_EP0_DATA_OUT;
135
+  pdev->ep_out[0].total_length = len;
136
+
137
+#ifdef USBD_AVOID_PACKET_SPLIT_MPS
138
+  pdev->ep_out[0].rem_length = 0U;
139
+#else
140
+  pdev->ep_out[0].rem_length = len;
141
+#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
142
+
143
+  /* Start the transfer */
144
+  (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
145
+
146
+  return USBD_OK;
147
+}
148
+
149
+/**
150
+  * @brief  USBD_CtlContinueRx
151
+  *         continue receive data on the ctl pipe
152
+  * @param  pdev: device instance
153
+  * @param  buff: pointer to data buffer
154
+  * @param  len: length of data to be received
155
+  * @retval status
156
+  */
157
+USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
158
+                                      uint8_t *pbuf, uint32_t len)
159
+{
160
+  (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
161
+
162
+  return USBD_OK;
163
+}
164
+
165
+/**
166
+  * @brief  USBD_CtlSendStatus
167
+  *         send zero lzngth packet on the ctl pipe
168
+  * @param  pdev: device instance
169
+  * @retval status
170
+  */
171
+USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
172
+{
173
+  /* Set EP0 State */
174
+  pdev->ep0_state = USBD_EP0_STATUS_IN;
175
+
176
+  /* Start the transfer */
177
+  (void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
178
+
179
+  return USBD_OK;
180
+}
181
+
182
+/**
183
+  * @brief  USBD_CtlReceiveStatus
184
+  *         receive zero lzngth packet on the ctl pipe
185
+  * @param  pdev: device instance
186
+  * @retval status
187
+  */
188
+USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
189
+{
190
+  /* Set EP0 State */
191
+  pdev->ep0_state = USBD_EP0_STATUS_OUT;
192
+
193
+  /* Start the transfer */
194
+  (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
195
+
196
+  return USBD_OK;
197
+}
198
+
199
+/**
200
+  * @brief  USBD_GetRxCount
201
+  *         returns the received data length
202
+  * @param  pdev: device instance
203
+  * @param  ep_addr: endpoint address
204
+  * @retval Rx Data blength
205
+  */
206
+uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
207
+{
208
+  return USBD_LL_GetRxDataSize(pdev, ep_addr);
209
+}
210
+
211
+/**
212
+  * @}
213
+  */
214
+
215
+
216
+/**
217
+  * @}
218
+  */
219
+
220
+
221
+/**
222
+  * @}
223
+  */
224
+