rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
usbconfig.cpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2013-2016, Cypress Semiconductor Corporation or a *
3* subsidiary of Cypress Semiconductor Corporation. All rights reserved. *
4* *
5* This software, including source code, documentation and related *
6* materials ("Software"), is owned by Cypress Semiconductor Corporation or *
7* one of its subsidiaries ("Cypress") and is protected by and subject to *
8* worldwide patent protection (United States and foreign), United States *
9* copyright laws and international treaty provisions. Therefore, you may use *
10* this Software only as provided in the license agreement accompanying the *
11* software package from which you obtained this Software ("EULA"). *
12* *
13* If no EULA applies, Cypress hereby grants you a personal, non-exclusive, *
14* non-transferable license to copy, modify, and compile the *
15* Software source code solely for use in connection with Cypress's *
16* integrated circuit products. Any reproduction, modification, translation, *
17* compilation, or representation of this Software except as specified *
18* above is prohibited without the express written permission of Cypress. *
19* *
20* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO *
21* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING, *
22* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED *
23* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
24* PARTICULAR PURPOSE. Cypress reserves the right to make *
25* changes to the Software without notice. Cypress does not assume any *
26* liability arising out of the application or use of the Software or any *
27* product or circuit described in the Software. Cypress does not *
28* authorize its products for use in any products where a malfunction or *
29* failure of the Cypress product may reasonably be expected to result in *
30* significant property damage, injury or death ("High Risk Product"). By *
31* including Cypress's product in a High Risk Product, the manufacturer *
32* of such system or application assumes all risk of such use and in doing *
33* so agrees to indemnify Cypress against all liability. *
34*******************************************************************************/
35/************************************************************************/
36/** \file usbconfig.c
37 **
38 ** Part of USB Driver Module
39 **
40 ** A detailed description is available at
41 ** @link UsbConfigGroup USB Device Cdc Com Module description @endlink
42 **
43 ** History:
44 ** - 2012-08-24 2.0 MSc New Version for use with M3 L3 USB driver
45 ** - 2012-10-02 2.1 MSc use of external interrupts without L3 implemented
46 ** - 2012-11-22 2.2 MSc minor bug fixes
47 ** - 2015-05-05 2.3 MSCH updated to latest version, changed
48 ** !USB_DISBALE_..._FUNCTIONALITY to FM_PERIPHERAL_USB_..._ENABLED
49 *****************************************************************************/
50
51/******************************************************************************/
52/* Include files */
53/******************************************************************************/
54
55#include "pdl_header.h"
56#include "usb.h"
57
58/**
59 ******************************************************************************
60 ** \defgroup UsbConfigGroup USB Config
61 **
62 ** Provided functions of USB module:
63 **
64 ** - UsbConfig_UsbInit()
65 ** - UsbConfig_SwitchMode()
66 ** - UsbConfig_Device0Vbus()
67 ** - UsbConfig_Device1Vbus()
68 ** - UsbConfig_Host0Overcurrent()
69 ** - UsbConfig_Host1Overcurrent()
70 ** - UsbConfig_Host0Vbus()
71 ** - UsbConfig_Host1Vbus()
72 ** - UsbConfig_Host0PulldownHostEnable()
73 ** - UsbConfig_Host1PulldownHostEnable()
74 ** - UsbDevice_Usb0ExintCallback()
75 ** - UsbDevice_Usb1ExintCallback()
76 **
77 ** Used to initialize and configure the USB HAL. It gives an example how to initialize
78 ** all USB parts. UsbConfig_UsbInit() is used to setup USB host and device mode for USB0 and USB1.
79 ** UsbConfig_SwitchMode() is used to detect the Device VBUS and to do the Host / Device switching.
80 ** UsbConfig_Device<n>Vbus() <n = 0,1> is used to do GPIO read or write for the Device VBUS detection pin.
81 ** UsbConfig_Device<n>Vbus() is defined as callback for the USB stack.
82 ** UsbConfig_Host<n>Overcurrent() <n = 0,1> is used to do GPIO read or write for the Host overcurrent detection.
83 ** UsbConfig_Host<n>Overcurrent() is defined as callback for the USB stack.
84 ** UsbConfig_Host<n>Vbus() <n = 0,1> is used to do GPIO read or write for the Host VBUS enable.
85 ** UsbConfig_Host<n>Vbus() is defined as callback for the USB stack.
86 ** UsbConfig_Host<n>PulldownHostEnable() <n = 0,1> is used to do GPIO read or write to enable the Host 15K pulldowns (externally).
87 ** UsbConfig_Host<n>PulldownHostEnable() is defined as callback for the USB stack.
88 ** UsbDevice_Usb<n>ExintCallback() <n = 0,1> is used if the Device VBUS detection is done by IRQ.
89 ** UsbDevice_Usb<n>ExintCallback() is called from an external IRQ pin.
90 **
91 ******************************************************************************/
92//@{
93
94/**
95 ******************************************************************************
96 ** \page usbconfig_module_includes Required includes in main application
97 ** \brief Following includes are required
98 ** @code
99 ** #include "usb.h"
100 ** @endcode
101 **
102 ******************************************************************************/
103
104/**
105 ******************************************************************************
106 ** \page usbconfig_module_init Example: Initialization
107 ** \brief Following initialization is required
108 **
109 ** @code
110 ** UsbConfig_UsbInit();
111 ** @endcode
112 **
113 ******************************************************************************/
114
115/**
116 ******************************************************************************
117 ** \page usbconfig_example_main Example: Whole example
118 ** @code
119 ** #include "usb.h"
120 **
121 **
122 ** int main()
123 ** {
124 **
125 ** // other initializations
126 **
127 ** UsbConfig_UsbInit();
128 **
129 ** // other initializations
130 **
131 ** for(;;)
132 ** {
133 ** UsbConfig_SwitchMode(); //must be called periodically to do VBUS detection
134 ** //or Host / Device switching
135 **
136 ** // application code
137 ** }
138 ** }
139 ** @endcode
140 **
141 ******************************************************************************/
142
143#if ((FM_PERIPHERAL_USB_DEVICE_ENABLED == ON) || (FM_PERIPHERAL_USB_HOST_ENABLED == ON))
144
145#if (FM_PERIPHERAL_USB_DEVICE_ENABLED == ON)
146 #include "usbdevice.h"
147 #if ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))
148 #include "usbdevicehw.h"
149 #endif
150 #if ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1))
151 #include "usbdescriptors.h"
152 #endif
153#endif
154#if (FM_PERIPHERAL_USB_HOST_ENABLED == ON)
155 #include "usbhost.h"
156 #if ((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))
157 #include "usbhosthw.h"
158 #endif
159#endif
160
161#if (USBDEVICECDCCOM_ENABLED == ON)
162 #include "UsbDeviceCdcCom.h"
163#endif
164#if (USBDEVICEHIDCOM_ENABLED == ON)
165 #include "UsbDeviceHidCom.h"
166#endif
167#if (USBDEVICEHIDJOYSTICK_ENABLED == ON)
168 #include "UsbDeviceHidJoystick.h"
169#endif
170#if (USBDEVICEHIDKEYBOARD_ENABLED == ON)
171 #include "UsbDeviceHidKeyboard.h"
172#endif
173#if (USBDEVICEHIDMOUSE_ENABLED == ON)
174 #include "UsbDeviceHidMouse.h"
175#endif
176#if (USBDEVICELIBUSB_ENABLED == ON)
177 #include "UsbDeviceLibUsb.h"
178#endif
179#if (USBDEVICEPRINTER_ENABLED == ON)
180 #include "UsbDevicePrinter.h"
181#endif
182#if USBHOSTHIDMOUSE_ENABLED == ON
183 #include "UsbHostHidMouse.h"
184#endif
185#if USBHOSTHIDKEYBOARD_ENABLED == ON
186 #include "UsbHostHidKeyboard.h"
187#endif
188#if (USBDEVICEMASSSTORAGE_ENABLED == ON)
189 #include "UsbDeviceMassStorage.h"
190#endif
191/******************************************************************************/
192/* Local pre-processor symbols/macros ('#define') */
193/******************************************************************************/
194
195/******************************************************************************/
196/* Global variable definitions (declared in header file with 'extern') */
197/******************************************************************************/
198
199/******************************************************************************/
200/* Local function prototypes ('static') */
201/******************************************************************************/
202
203#if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
204static void UsbConfig_UsbDeviceClassesInitCallback0(stc_usbn_t* pstcUSB);
205#endif
206
207#if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
208static void UsbConfig_UsbDeviceClassesInitCallback1(stc_usbn_t* pstcUSB);
209#endif
210
211#ifdef __USBDEVICEHW_H__
212 #if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))))
213 static boolean_t UsbConfig_Device0Vbus(en_usb_extint_param_t enType);
214 #endif
215 #if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))))
216 static boolean_t UsbConfig_Device1Vbus(en_usb_extint_param_t enType);
217 #endif
218#endif
219#ifdef __USBHOSTHW_H__
220 #if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
221 boolean_t UsbConfig_Host0Overcurrent(en_usb_extint_param_t enType);
222 boolean_t UsbConfig_Host0Vbus(en_usb_gpio_param_t enType);
223 boolean_t UsbConfig_Host0PulldownHostEnable(en_usb_gpio_param_t enType);
224 #endif
225 #if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
226 boolean_t UsbConfig_Host1Overcurrent(en_usb_extint_param_t enType);
227 boolean_t UsbConfig_Host1Vbus(en_usb_gpio_param_t enType);
228 boolean_t UsbConfig_Host1PulldownHostEnable(en_usb_gpio_param_t enType);
229 #endif
230#endif
231
232#if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
233static void UsbConfig_UsbDeviceClassesInitCallback0(stc_usbn_t* pstcUSB)
234{
235 #if (USBDEVICECDCCOM_ENABLED == ON)
236 UsbDeviceCdcCom_Init((stc_usbn_t*)&USB0);
237 #endif
238 #if (USBDEVICEHIDCOM_ENABLED == ON)
239 UsbDeviceHidCom_Init((stc_usbn_t*)&USB0);
240 #endif
241 #if (USBDEVICEHIDJOYSTICK_ENABLED == ON)
242 UsbDeviceHidJoystick_Init((stc_usbn_t*)&USB0);
243 #endif
244 #if (USBDEVICEHIDKEYBOARD_ENABLED == ON)
245 UsbDeviceHidKeyboard_Init((stc_usbn_t*)&USB0);
246 #endif
247 #if (USBDEVICEHIDMOUSE_ENABLED == ON)
248 UsbDeviceHidMouse_Init((stc_usbn_t*)&USB0);
249 #endif
250 #if (USBDEVICELIBUSB_ENABLED == ON)
251 UsbDeviceLibUsb_Init((stc_usbn_t*)&USB0);
252 #endif
253 #if (USBDEVICEPRINTER_ENABLED == ON)
254 UsbDevicePrinter_Init((stc_usbn_t*)&USB0);
255 #endif
256 #if (USBDEVICEMASSSTORAGE_ENABLED == ON)
257 UsbDeviceMassStorage_Init((stc_usbn_t*)&USB0);
258 #endif
259 /* USB0 WIZARD DEVICECLASSINIT */
260}
261#endif
262
263#if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
264static void UsbConfig_UsbDeviceClassesInitCallback1(stc_usbn_t* pstcUSB)
265{
266 #if (USBDEVICECDCCOM_ENABLED == ON)
267 UsbDeviceCdcCom_Init((stc_usbn_t*)&USB1);
268 #endif
269 #if (USBDEVICEHIDCOM_ENABLED == ON)
270 UsbDeviceHidCom_Init((stc_usbn_t*)&USB1);
271 #endif
272 #if (USBDEVICEHIDJOYSTICK_ENABLED == ON)
273 UsbDeviceHidJoystick_Init((stc_usbn_t*)&USB1);
274 #endif
275 #if (USBDEVICEHIDKEYBOARD_ENABLED == ON)
276 UsbDeviceHidKeyboard_Init((stc_usbn_t*)&USB1);
277 #endif
278 #if (USBDEVICEHIDMOUSE_ENABLED == ON)
279 UsbDeviceHidMouse_Init((stc_usbn_t*)&USB1);
280 #endif
281 #if (USBDEVICELIBUSB_ENABLED == ON)
282 UsbDeviceLibUsb_Init((stc_usbn_t*)&USB1);
283 #endif
284 #if (USBDEVICEPRINTER_ENABLED == ON)
285 UsbDevicePrinter_Init((stc_usbn_t*)&USB1);
286 #endif
287 #if (USBDEVICEMASSSTORAGE_ENABLED == ON)
288 UsbDeviceMassStorage_Init((stc_usbn_t*)&USB1);
289 #endif
290 /* USB1 WIZARD DEVICECLASSINIT */
291}
292#endif
293
294/******************************************************************************/
295/* Global variable definitions (declared in header file with 'extern') */
296/******************************************************************************/
297
298
299
300
301
302
303
304
305/**
306 ******************************************************************************
307 ** \brief Initialize USB
308 **
309 ******************************************************************************/
311{
312 stc_usb_config_t stcUsbConfig;
313 #if (!defined(USB_DISBALE_DEVICE_FUNCTIONALITY))
314 stc_usbdevice_config_t stcUsbDeviceConfig;
315 #endif
316
317 Usb_Init();
318
319
320 /* Setup USB 0 */
321 USB_ZERO_STRUCT(stcUsbConfig);
322
323 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
324 USB_ZERO_STRUCT(stcUsbDeviceConfig);
325 #endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
326
327 #if ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
328 stcUsbConfig.enMode = UsbHostDeviceEnabled;
329 #elif ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == OFF))
330 stcUsbConfig.enMode = UsbHostEnabled;
331 #elif ((FM_PERIPHERAL_ENABLE_USB0_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
332 stcUsbConfig.enMode = UsbDeviceEnabled;
333 #endif
334
335 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
336 #if ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1))
337 stcUsbDeviceConfig.pu8DeviceDescriptor = (uint8_t*)au8DeviceDescriptor;
338 stcUsbDeviceConfig.pu8ConfigDescriptor = (uint8_t*)au8ConfigDescriptor;
339 stcUsbDeviceConfig.astcReportDescriptors = (stc_usbdevice_reportdescriptor_t*)astcReportDescriptors;
340 stcUsbDeviceConfig.pstcStringDescriptors = (stc_usbdevice_stringdescriptor_t*)pstcStringDescriptors;
341 stcUsbDeviceConfig.u8StringDescriptorCount = USBDESCRIPTORS_STRINGDESCRIPTOR_COUNT;
342 #endif /* ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1)) */
343 #endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
344
345 stcUsbConfig.bUseInterrupts = TRUE;
346
347 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
348 #if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1)))
349 stcUsbConfig.pfnDeviceVbus = UsbConfig_Device0Vbus;
350 #endif
351 #endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
352
353 #if ((FM_PERIPHERAL_USB_HOST_ENABLED))
354 #if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && ((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1)))
355 stcUsbConfig.pfnHostVbus = UsbConfig_Host0Vbus;
356 stcUsbConfig.pfnHostPullDownHostEnable = UsbConfig_Host0PulldownHostEnable;
357 stcUsbConfig.pfnHostOvercurrent = UsbConfig_Host0Overcurrent;
358 #endif
359 #endif /* ((FM_PERIPHERAL_USB_HOST_ENABLED)) */
360
361 #if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
362 stcUsbDeviceConfig.pfnInitClassesCallback = UsbConfig_UsbDeviceClassesInitCallback0;
363 #endif
364
365 #if FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
366 UsbDevice_Init((stc_usbn_t*)&USB0,&stcUsbConfig,&stcUsbDeviceConfig);
367 #endif
368
369 #if FM_PERIPHERAL_ENABLE_USB0 == ON
370 #if FM_PERIPHERAL_ENABLE_USB0_HOST == ON
371 UsbHost_Init((stc_usbn_t*)&USB0,&stcUsbConfig);
372 #endif
373 Usb_Configure((stc_usbn_t*)&USB0,&stcUsbConfig);
374 #endif
375
376
377
378
379 /* Setup USB 1 */
380 USB_ZERO_STRUCT(stcUsbConfig);
381
382 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
383 USB_ZERO_STRUCT(stcUsbDeviceConfig);
384 #endif
385
386 #if ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
387 stcUsbConfig.enMode = UsbHostDeviceEnabled;
388 #elif ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == OFF))
389 stcUsbConfig.enMode = UsbHostEnabled;
390 #elif ((FM_PERIPHERAL_ENABLE_USB1_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
391 stcUsbConfig.enMode = UsbDeviceEnabled;
392 #endif
393
394 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
395 #if ((USE_USBDESCRIPTORS_H == 1) || (USB_USE_PDL == 1))
396 stcUsbDeviceConfig.pu8DeviceDescriptor = (uint8_t*)au8DeviceDescriptor;
397 stcUsbDeviceConfig.pu8ConfigDescriptor = (uint8_t*)au8ConfigDescriptor;
398 stcUsbDeviceConfig.astcReportDescriptors = (stc_usbdevice_reportdescriptor_t*)astcReportDescriptors;
399 stcUsbDeviceConfig.pstcStringDescriptors = (stc_usbdevice_stringdescriptor_t*)pstcStringDescriptors;
400 stcUsbDeviceConfig.u8StringDescriptorCount = USBDESCRIPTORS_STRINGDESCRIPTOR_COUNT;
401 #endif
402 #endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
403
404 stcUsbConfig.bUseInterrupts = TRUE;
405
406 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED)
407 #if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1)))
408 stcUsbConfig.pfnDeviceVbus = UsbConfig_Device1Vbus;
409 #endif
410 #endif /* (FM_PERIPHERAL_USB_DEVICE_ENABLED) */
411
412 #if (FM_PERIPHERAL_USB_HOST_ENABLED)
413 #if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && ((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1)))
414 stcUsbConfig.pfnHostVbus = UsbConfig_Host1Vbus;
415 stcUsbConfig.pfnHostPullDownHostEnable = UsbConfig_Host1PulldownHostEnable;
416 stcUsbConfig.pfnHostOvercurrent = UsbConfig_Host1Overcurrent;
417 #endif
418 #endif /* (FM_PERIPHERAL_USB_HOST_ENABLED) */
419
420 #if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
421 stcUsbDeviceConfig.pfnInitClassesCallback = UsbConfig_UsbDeviceClassesInitCallback1;
422 #endif
423
424 #if FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
425 UsbDevice_Init((stc_usbn_t*)&USB1,&stcUsbConfig,&stcUsbDeviceConfig);
426 #endif
427
428 #if FM_PERIPHERAL_ENABLE_USB1 == ON
429 #if FM_PERIPHERAL_ENABLE_USB1_HOST == ON
430 UsbHost_Init((stc_usbn_t*)&USB1,&stcUsbConfig);
431 #endif
432 Usb_Configure((stc_usbn_t*)&USB1,&stcUsbConfig);
433 #endif
434}
435
436#ifdef __USBDEVICEHW_H__
437
438#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1))))
439/**
440 ******************************************************************************
441 ** \brief Device 0 VBUS GPIO / external interrupt callback
442 **
443 ** \param enType
444 **
445 ** \return Depending on enType
446 **
447 ******************************************************************************/
448static boolean_t UsbConfig_Device0Vbus(en_usb_extint_param_t enType)
449{
450 switch(enType)
451 {
452 case UsbExtIntDeinit:
453 DEVICE0VBUS_DEINIT;
454 break;
455 case UsbExtIntInit:
456 DEVICE0VBUS_INIT;
457 break;
458 case UsbExtIntDisableIsr:
459 DEVICE0VBUS_DISABLEISR;
460 break;
461 case UsbExtIntEnableIsr:
462 DEVICE0VBUS_ENABLEISR;
463 break;
464 case UsbExtIntClearIsrFlag:
465 DEVICE0VBUS_CLEARISRFLAG;
466 break;
467 case UsbExtIntIsSetIsrFlag:
468 return DEVICE0VBUS_ISRISSET;
469 case UsbExtIntSetLowDetect:
470 DEVICE0VBUS_SETLOWDETECT;
471 break;
472 case UsbExtIntSetHighDetect:
473 DEVICE0VBUS_SETHIGHDETECT;
474 break;
475 case UsbExtIntGetLevel:
476 return DEVICE0VBUS_HIGHDETECT;
477 }
478 return FALSE;
479}
480#endif
481
482#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && ((USE_USBDEVICEHW_H == 1) || (USB_USE_PDL == 1)))
483/**
484 ******************************************************************************
485 ** \brief Device 1 VBUS GPIO / external interrupt callback
486 **
487 ** \param enType
488 **
489 ** \return Depending on enType
490 **
491 ******************************************************************************/
492static boolean_t UsbConfig_Device1Vbus(en_usb_extint_param_t enType)
493{
494 switch(enType)
495 {
496 case UsbExtIntDeinit:
497 DEVICE1VBUS_DEINIT;
498 break;
499 case UsbExtIntInit:
500 DEVICE1VBUS_INIT;
501 break;
502 case UsbExtIntDisableIsr:
503 DEVICE1VBUS_DISABLEISR;
504 break;
505 case UsbExtIntEnableIsr:
506 DEVICE1VBUS_ENABLEISR;
507 break;
508 case UsbExtIntClearIsrFlag:
509 DEVICE1VBUS_CLEARISRFLAG;
510 break;
511 case UsbExtIntIsSetIsrFlag:
512 return DEVICE1VBUS_ISRISSET;
513 break;
514 case UsbExtIntSetLowDetect:
515 DEVICE1VBUS_SETLOWDETECT;
516 break;
517 case UsbExtIntSetHighDetect:
518 DEVICE1VBUS_SETHIGHDETECT;
519 break;
520 case UsbExtIntGetLevel:
521 return DEVICE1VBUS_HIGHDETECT;
522 break;
523 }
524 return FALSE;
525}
526#endif
527
528#endif
529
530#ifdef __USBHOSTHW_H__
531
532#if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
533/**
534 ******************************************************************************
535 ** \brief Host 0 Overcurrent GPIO / external interrupt callback
536 **
537 ** \param enType
538 **
539 ** \return Depending on enType
540 **
541 ******************************************************************************/
542boolean_t UsbConfig_Host0Overcurrent(en_usb_extint_param_t enType)
543{
544 switch(enType)
545 {
546 case UsbExtIntDeinit:
547 HOST0OVERCURRENT_DEINIT;
548 break;
549 case UsbExtIntInit:
550 HOST0OVERCURRENT_INIT;
551 break;
552 case UsbExtIntDisableIsr:
553 HOST0OVERCURRENT_DISABLEISR;
554 break;
555 case UsbExtIntEnableIsr:
556 HOST0OVERCURRENT_ENABLEISR;
557 break;
558 case UsbExtIntClearIsrFlag:
559 HOST0OVERCURRENT_CLEARISRFLAG;
560 break;
561 case UsbExtIntIsSetIsrFlag:
562 return HOST0OVERCURRENT_ISRISSET;
563 case UsbExtIntSetLowDetect:
564 HOST0OVERCURRENT_SETLOWDETECT;
565 break;
566 case UsbExtIntSetHighDetect:
567 HOST0OVERCURRENT_SETHIGHDETECT;
568 break;
569 case UsbExtIntGetLevel:
570 return HOST0OVERCURRENT_HIGHDETECT;
571 default:
572 return FALSE;
573 }
574 return TRUE;
575}
576
577/**
578 ******************************************************************************
579 ** \brief Host 0 VBUS GPIO / external interrupt callback
580 **
581 ** \param enType
582 **
583 ** \return Depending on enType
584 **
585 ******************************************************************************/
586boolean_t UsbConfig_Host0Vbus(en_usb_gpio_param_t enType)
587{
588 switch(enType)
589 {
590 case UsbGpioDeinit:
591 HOST0VBUS_DEINIT;
592 break;
593 case UsbGpioInit:
594 HOST0VBUS_INIT;
595 break;
596 case UsbGpioSet:
597 HOST0VBUS_SET;
598 break;
599 case UsbGpioClear:
600 HOST0VBUS_CLEAR;
601 break;
602 default:
603 return FALSE;
604 }
605 return TRUE;
606}
607
608/**
609 ******************************************************************************
610 ** \brief Host 0 pull-down GPIO / external interrupt callback
611 **
612 ** \param enType
613 **
614 ** \return Depending on enType
615 **
616 ******************************************************************************/
617boolean_t UsbConfig_Host0PulldownHostEnable(en_usb_gpio_param_t enType)
618{
619 switch(enType)
620 {
621 case UsbGpioDeinit:
622 HOST0OTGPULLDOWN_DEINIT;
623 break;
624 case UsbGpioInit:
625 HOST0OTGPULLDOWN_INIT;
626 break;
627 case UsbGpioSet:
628 HOST0OTGPULLDOWN_SET;
629 break;
630 case UsbGpioClear:
631 HOST0OTGPULLDOWN_CLEAR;
632 break;
633 default:
634 return FALSE;
635 }
636 return TRUE;
637}
638#endif
639
640#if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (((USE_USBHOSTHW_H == 1) || (USB_USE_PDL == 1))))
641/**
642 ******************************************************************************
643 ** \brief Host 1 Overcurrent GPIO / external interrupt callback
644 **
645 ** \param enType
646 **
647 ** \return Depending on enType
648 **
649 ******************************************************************************/
650boolean_t UsbConfig_Host1Overcurrent(en_usb_extint_param_t enType)
651{
652 switch(enType)
653 {
654 case UsbExtIntDeinit:
655 HOST1OVERCURRENT_DEINIT;
656 break;
657 case UsbExtIntInit:
658 HOST1OVERCURRENT_INIT;
659 break;
660 case UsbExtIntDisableIsr:
661 HOST1OVERCURRENT_DISABLEISR;
662 break;
663 case UsbExtIntEnableIsr:
664 HOST1OVERCURRENT_ENABLEISR;
665 break;
666 case UsbExtIntClearIsrFlag:
667 HOST1OVERCURRENT_CLEARISRFLAG;
668 break;
669 case UsbExtIntIsSetIsrFlag:
670 return HOST1OVERCURRENT_ISRISSET;
671 case UsbExtIntSetLowDetect:
672 HOST1OVERCURRENT_SETLOWDETECT;
673 break;
674 case UsbExtIntSetHighDetect:
675 HOST1OVERCURRENT_SETHIGHDETECT;
676 break;
677 case UsbExtIntGetLevel:
678 return HOST1OVERCURRENT_HIGHDETECT;
679 default:
680 return FALSE;
681 }
682 return TRUE;
683}
684
685/**
686 ******************************************************************************
687 ** \brief Host 1 VBUS GPIO / external interrupt callback
688 **
689 ** \param enType
690 **
691 ** \return Depending on enType
692 **
693 ******************************************************************************/
694boolean_t UsbConfig_Host1Vbus(en_usb_gpio_param_t enType)
695{
696 switch(enType)
697 {
698 case UsbGpioDeinit:
699 HOST1VBUS_DEINIT;
700 break;
701 case UsbGpioInit:
702 HOST1VBUS_INIT;
703 break;
704 case UsbGpioSet:
705 HOST1VBUS_SET;
706 break;
707 case UsbGpioClear:
708 HOST1VBUS_CLEAR;
709 break;
710 default:
711 return FALSE;
712 }
713 return TRUE;
714}
715
716/**
717 ******************************************************************************
718 ** \brief Host 1 pull-down GPIO / external interrupt callback
719 **
720 ** \param enType
721 **
722 ** \return Depending on enType
723 **
724 ******************************************************************************/
725boolean_t UsbConfig_Host1PulldownHostEnable(en_usb_gpio_param_t enType)
726{
727 switch(enType)
728 {
729 case UsbGpioDeinit:
730 HOST1OTGPULLDOWN_DEINIT;
731 break;
732 case UsbGpioInit:
733 HOST1OTGPULLDOWN_INIT;
734 break;
735 case UsbGpioSet:
736 HOST1OTGPULLDOWN_SET;
737 break;
738 case UsbGpioClear:
739 HOST1OTGPULLDOWN_CLEAR;
740 break;
741 default:
742 return FALSE;
743 }
744 return TRUE;
745}
746#endif
747
748#endif
749
751{
752 #if FM_PERIPHERAL_ENABLE_USB0 == ON
753 #if ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == OFF))
754 Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchToHost,0);
755 #endif
756 #if ((FM_PERIPHERAL_ENABLE_USB0_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
757 Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchDependingDeviceVbus,0);
758 #endif
759 #if ((FM_PERIPHERAL_ENABLE_USB0_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
760 Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchDependingDeviceVbus,0);
761 #endif
762 #endif
763
764 #if FM_PERIPHERAL_ENABLE_USB1 == ON
765 #if ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == OFF))
766
767 Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchToHost,0);
768 #endif
769 #if ((FM_PERIPHERAL_ENABLE_USB1_HOST == OFF) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
770 Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchDependingDeviceVbus,0);
771 #endif
772 #if ((FM_PERIPHERAL_ENABLE_USB1_HOST == ON) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
773 Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchDependingDeviceVbus,0);
774 #endif
775 #endif
776}
777
778
779#if (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON)
781{
782 if (Usb_SwitchUsb((stc_usbn_t*)&USB0,UsbSwitchDependingDeviceVbus,0) == Ok)
783 {
784 if (DEVICE0VBUS_HIGHDETECT)
785 {
786 DEVICE0VBUS_SETLOWDETECT;
787 }
788 else
789 {
790 DEVICE0VBUS_SETHIGHDETECT;
791 }
792 }
793
794}
795#endif
796
797#if (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON)
799{
800 if (Usb_SwitchUsb((stc_usbn_t*)&USB1,UsbSwitchDependingDeviceVbus,0) == Ok)
801 {
802 if (DEVICE1VBUS_HIGHDETECT)
803 {
804 DEVICE1VBUS_SETLOWDETECT;
805 }
806 else
807 {
808 DEVICE1VBUS_SETHIGHDETECT;
809 }
810 }
811}
812#endif
813
814
815
816#if (USB_USE_L3 == 0)
817#if ((USB_USE_L3 == 0) && (USB_USE_EXT_INT == 1))
818#if (!defined(USB_DISBALE_DEVICE_FUNCTIONALITY))
820{
821 #if FM_PERIPHERAL_ENABLE_USB0 == ON
822 if (DEVICE0VBUS_ISRISSET)
823 {
824 DEVICE0VBUS_CLEARISRFLAG;
826 }
827 #endif
828 #if FM_PERIPHERAL_ENABLE_USB1 == ON
829 if (DEVICE1VBUS_ISRISSET)
830 {
831 DEVICE1VBUS_CLEARISRFLAG;
833 }
834 #endif
835}
836
838{
839 #if FM_PERIPHERAL_ENABLE_USB0 == ON
840 if (DEVICE0VBUS_ISRISSET)
841 {
842 DEVICE0VBUS_CLEARISRFLAG;
844 }
845 #endif
846 #if FM_PERIPHERAL_ENABLE_USB1 == ON
847 if (DEVICE1VBUS_ISRISSET)
848 {
849 DEVICE1VBUS_CLEARISRFLAG;
851 }
852 #endif
853}
854
855void INT0_7_Handler (void)
856{
857 #if FM_PERIPHERAL_ENABLE_USB0 == ON
858 if (DEVICE0VBUS_ISRISSET)
859 {
860 DEVICE0VBUS_CLEARISRFLAG;
862 }
863 #endif
864 #if FM_PERIPHERAL_ENABLE_USB1 == ON
865 if (DEVICE1VBUS_ISRISSET)
866 {
867 DEVICE1VBUS_CLEARISRFLAG;
869 }
870 #endif
871}
872#endif
873#endif
874#endif
875#else
876
877/**
878 ******************************************************************************
879 ** \brief Initialize USB (dummy if USB is disabled)
880 **
881 ******************************************************************************/
882void UsbConfig_UsbInit(void)
883{
884}
885
886/**
887 ******************************************************************************
888 ** \brief Switch USB mode (dummy if USB is disabled)
889 **
890 ******************************************************************************/
891void UsbConfig_SwitchMode(void)
892{
893}
894#endif /* ((!defined(USB_DISBALE_DEVICE_FUNCTIONALITY)) || (!defined(USB_DISBALE_HOST_FUNCTIONALITY))) */
895//@} // UsbConfigGroup
static void UsbConfig_UsbDeviceClassesInitCallback0(stc_usbn_t *pstcUSB)
boolean_t UsbConfig_Host1PulldownHostEnable(en_usb_gpio_param_t enType)
Host 1 pull-down GPIO / external interrupt callback.
void INT8_31_Handler(void)
void INT8_15_Handler(void)
void UsbDevice_Usb0ExintCallback(void)
static void UsbConfig_UsbDeviceClassesInitCallback1(stc_usbn_t *pstcUSB)
boolean_t UsbConfig_Host0Overcurrent(en_usb_extint_param_t enType)
Host 0 Overcurrent GPIO / external interrupt callback.
void UsbConfig_UsbInit(void)
Initialize USB.
void INT0_7_Handler(void)
boolean_t UsbConfig_Host1Overcurrent(en_usb_extint_param_t enType)
Host 1 Overcurrent GPIO / external interrupt callback.
void UsbConfig_SwitchMode(void)
Switch USB mode (dummy if USB is disabled)
boolean_t UsbConfig_Host0PulldownHostEnable(en_usb_gpio_param_t enType)
Host 0 pull-down GPIO / external interrupt callback.
void UsbDevice_Usb1ExintCallback(void)
static boolean_t UsbConfig_Device1Vbus(en_usb_extint_param_t enType)
Device 1 VBUS GPIO / external interrupt callback.
boolean_t UsbConfig_Host1Vbus(en_usb_gpio_param_t enType)
Host 1 VBUS GPIO / external interrupt callback.
boolean_t UsbConfig_Host0Vbus(en_usb_gpio_param_t enType)
Host 0 VBUS GPIO / external interrupt callback.
static boolean_t UsbConfig_Device0Vbus(en_usb_extint_param_t enType)
Device 0 VBUS GPIO / external interrupt callback.
const uint8_t au8ConfigDescriptor[53]
const stc_usbdevice_stringdescriptor_t pstcStringDescriptors[]
const stc_usbdevice_reportdescriptor_t astcReportDescriptors[3]
const uint8_t au8DeviceDescriptor[18]