Embedded SDK
Embedded SDK
usbd_conf.c
Go to the documentation of this file.
1 
33 #include "os_io_seproxyhal.h"
34 #include "os_helpers.h"
35 /* Includes ------------------------------------------------------------------*/
36 #include "usbd_def.h"
37 #include "usbd_core.h"
38 
39 
40 /*******************************************************************************
41  LL Driver Interface (USB Device Library --> PCD)
42 *******************************************************************************/
43 unsigned int ep_in_stall;
44 unsigned int ep_out_stall;
50 USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
51 {
52  UNUSED(pdev);
53  ep_in_stall = 0;
54  ep_out_stall = 0;
55  return USBD_OK;
56 }
57 
63 USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev)
64 {
65  uint8_t buffer[4];
66  UNUSED(pdev);
67 
68  // usb off
69  buffer[0] = SEPROXYHAL_TAG_USB_CONFIG;
70  buffer[1] = 0;
71  buffer[2] = 1;
72  buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_DISCONNECT;
73  io_seproxyhal_spi_send(buffer, 4);
74 
75  return USBD_OK;
76 }
77 
83 USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
84 {
85  uint8_t buffer[5];
86  UNUSED(pdev);
87 
88  // reset address
89  buffer[0] = SEPROXYHAL_TAG_USB_CONFIG;
90  buffer[1] = 0;
91  buffer[2] = 2;
92  buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ADDR;
93  buffer[4] = 0;
94  io_seproxyhal_spi_send(buffer, 5);
95 
96  // start usb operation
97  buffer[0] = SEPROXYHAL_TAG_USB_CONFIG;
98  buffer[1] = 0;
99  buffer[2] = 1;
100  buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_CONNECT;
101  io_seproxyhal_spi_send(buffer, 4);
102  return USBD_OK;
103 }
104 
110 USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev)
111 {
112  UNUSED(pdev);
113  uint8_t buffer[4];
114  buffer[0] = SEPROXYHAL_TAG_USB_CONFIG;
115  buffer[1] = 0;
116  buffer[2] = 1;
117  buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_DISCONNECT;
118  io_seproxyhal_spi_send(buffer, 4);
119  return USBD_OK;
120 }
121 
130 USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev,
131  uint8_t ep_addr,
132  uint8_t ep_type,
133  uint16_t ep_mps)
134 {
135  uint8_t buffer[8];
136  UNUSED(pdev);
137 
138  ep_in_stall = 0;
139  ep_out_stall = 0;
140 
141  buffer[0] = SEPROXYHAL_TAG_USB_CONFIG;
142  buffer[1] = 0;
143  buffer[2] = 5;
144  buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ENDPOINTS;
145  buffer[4] = 1;
146  buffer[5] = ep_addr;
147  buffer[6] = 0;
148  switch(ep_type) {
149  case USBD_EP_TYPE_CTRL:
150  buffer[6] = SEPROXYHAL_TAG_USB_CONFIG_TYPE_CONTROL;
151  break;
152  case USBD_EP_TYPE_ISOC:
153  buffer[6] = SEPROXYHAL_TAG_USB_CONFIG_TYPE_ISOCHRONOUS;
154  break;
155  case USBD_EP_TYPE_BULK:
156  buffer[6] = SEPROXYHAL_TAG_USB_CONFIG_TYPE_BULK;
157  break;
158  case USBD_EP_TYPE_INTR:
159  buffer[6] = SEPROXYHAL_TAG_USB_CONFIG_TYPE_INTERRUPT;
160  break;
161  }
162  buffer[7] = ep_mps;
163  io_seproxyhal_spi_send(buffer, 8);
164  return USBD_OK;
165 }
166 
173 USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
174 {
175  UNUSED(pdev);
176  uint8_t buffer[8];
177  buffer[0] = SEPROXYHAL_TAG_USB_CONFIG;
178  buffer[1] = 0;
179  buffer[2] = 5;
180  buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ENDPOINTS;
181  buffer[4] = 1;
182  buffer[5] = ep_addr;
183  buffer[6] = SEPROXYHAL_TAG_USB_CONFIG_TYPE_DISABLED;
184  buffer[7] = 0;
185  io_seproxyhal_spi_send(buffer, 8);
186  return USBD_OK;
187 }
188 
195 USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
196 {
197  UNUSED(pdev);
198  UNUSED(ep_addr);
199  //HAL_PCD_EP_Flush(pdev->pData, ep_addr);
200  return USBD_OK;
201 }
202 
209 USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
210 {
211  UNUSED(pdev);
212  uint8_t buffer[6];
213  buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE;
214  buffer[1] = 0;
215  buffer[2] = 3;
216  buffer[3] = ep_addr;
217  buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_STALL;
218  buffer[5] = 0;
219  io_seproxyhal_spi_send(buffer, 6);
220  if (ep_addr & 0x80) {
221  ep_in_stall |= (1<<(ep_addr&0x7F));
222  }
223  else {
224  ep_out_stall |= (1<<(ep_addr&0x7F));
225  }
226  return USBD_OK;
227 }
228 
235 USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
236 {
237  UNUSED(pdev);
238  uint8_t buffer[6];
239  buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE;
240  buffer[1] = 0;
241  buffer[2] = 3;
242  buffer[3] = ep_addr;
243  buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_UNSTALL;
244  buffer[5] = 0;
245  io_seproxyhal_spi_send(buffer, 6);
246  if (ep_addr & 0x80) {
247  ep_in_stall &= ~(1<<(ep_addr&0x7F));
248  }
249  else {
250  ep_out_stall &= ~(1<<(ep_addr&0x7F));
251  }
252  return USBD_OK;
253 }
254 
261 uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
262 {
263  UNUSED(pdev);
264  if((ep_addr & 0x80) == 0x80)
265  {
266  return ep_in_stall & (1<<(ep_addr&0x7F));
267  }
268  else
269  {
270  return ep_out_stall & (1<<(ep_addr&0x7F));
271  }
272 }
279 USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr)
280 {
281  UNUSED(pdev);
282  uint8_t buffer[5];
283  buffer[0] = SEPROXYHAL_TAG_USB_CONFIG;
284  buffer[1] = 0;
285  buffer[2] = 2;
286  buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ADDR;
287  buffer[4] = dev_addr;
288  io_seproxyhal_spi_send(buffer, 5);
289  return USBD_OK;
290 }
291 
300 USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev,
301  uint8_t ep_addr,
302  uint8_t *pbuf,
303  uint16_t size)
304 {
305  UNUSED(pdev);
306  uint8_t buffer[6];
307  buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE;
308  buffer[1] = (3+size)>>8;
309  buffer[2] = (3+size);
310  buffer[3] = ep_addr;
311  buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_IN;
312  buffer[5] = size;
313  io_seproxyhal_spi_send(buffer, 6);
314  io_seproxyhal_spi_send(pbuf, size);
315  return USBD_OK;
316 }
317 
326 USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
327  uint8_t ep_addr,
328  uint16_t size)
329 {
330  UNUSED(pdev);
331  uint8_t buffer[6];
332  buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE;
333  buffer[1] = (3/*+size*/)>>8;
334  buffer[2] = (3/*+size*/);
335  buffer[3] = ep_addr;
336  buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_OUT;
337  buffer[5] = size; // expected size, not transmitted here !
338  io_seproxyhal_spi_send(buffer, 6);
339  return USBD_OK;
340 }
341 
342 
343 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Flushes an endpoint of the Low Level Driver.
Definition: usbd_conf.c:195
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
Initializes the Low Level portion of the Device driver.
Definition: usbd_conf.c:50
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Returns Stall condition.
Definition: usbd_conf.c:261
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
Starts the Low Level portion of the Device driver.
Definition: usbd_conf.c:83
unsigned int ep_out_stall
Definition: usbd_conf.c:44
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
De-Initializes the Low Level portion of the Device driver.
Definition: usbd_conf.c:63
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
Transmits data over an endpoint.
Definition: usbd_conf.c:300
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Sets a Stall condition on an endpoint of the Low Level Driver.
Definition: usbd_conf.c:209
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
Stops the Low Level portion of the Device driver.
Definition: usbd_conf.c:110
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
Assigns a USB address to the device.
Definition: usbd_conf.c:279
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Clears a Stall condition on an endpoint of the Low Level Driver.
Definition: usbd_conf.c:235
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
Opens an endpoint of the Low Level Driver.
Definition: usbd_conf.c:130
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Closes an endpoint of the Low Level Driver.
Definition: usbd_conf.c:173
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint16_t size)
Prepares an endpoint for reception.
Definition: usbd_conf.c:326
unsigned int ep_in_stall
Definition: usbd_conf.c:43
unsigned short uint16_t
Definition: usbd_conf.h:54
unsigned char uint8_t
Definition: usbd_conf.h:53