2 * @brief USB Controller definitions for the LPC microcontrollers
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #define __INCLUDE_FROM_USB_DRIVER
\r
33 #define __INCLUDE_FROM_USB_CONTROLLER_C
\r
34 #include "USBController.h"
\r
36 volatile uint8_t USB_CurrentMode[MAX_USB_CORE];
\r
37 volatile bool Mem_IsInitialized = false;
\r
40 void USB_Init(uint8_t corenum, uint8_t mode)
\r
42 #if defined(USB_CAN_BE_HOST)
\r
43 if (mode == USB_MODE_Host && Mem_IsInitialized == false)
\r
45 USB_Memory_Init(USBRAM_BUFFER_SIZE);
\r
46 Mem_IsInitialized = true;
\r
49 USB_CurrentMode[corenum] = mode;
\r
50 HAL_USBInit(corenum);
\r
51 USB_ResetInterface(corenum, mode);
\r
52 USB_IsInitialized = true;
\r
55 void USB_Disable(uint8_t corenum, uint8_t mode)
\r
57 USB_IsInitialized = false;
\r
58 if (mode == USB_MODE_Device) {
\r
59 #if defined(USB_CAN_BE_DEVICE)
\r
60 HAL_USBConnect(corenum, 0);
\r
61 HAL_USBDeInit(corenum, mode);
\r
64 if (mode == USB_MODE_Host) {
\r
65 #if defined(USB_CAN_BE_HOST)
\r
67 #if defined(USB_MULTI_PORTS)
\r
69 for (i = 0; i < MAX_USB_CORE; i++) {
\r
71 HAL_USBDeInit(i, mode);
\r
74 HcdDeInitDriver(corenum);
\r
75 HAL_USBDeInit(corenum, mode);
\r
82 void USB_ResetInterface(uint8_t corenum, uint8_t mode)
\r
84 if (mode == USB_MODE_Device) {
\r
85 #if defined(USB_CAN_BE_DEVICE)
\r
86 USB_Init_Device(corenum);
\r
89 else if (mode == USB_MODE_Host) {
\r
90 #if defined(USB_CAN_BE_HOST)
\r
91 USB_Init_Host(corenum);
\r
96 #if defined(USB_CAN_BE_DEVICE)
\r
97 static void USB_Init_Device(uint8_t corenum)
\r
99 USB_DeviceState[corenum] = DEVICE_STATE_Unattached;
\r
100 USB_Device_ConfigurationNumber = 0;
\r
102 #if !defined(NO_DEVICE_REMOTE_WAKEUP)
\r
103 USB_Device_RemoteWakeupEnabled = false;
\r
106 #if !defined(NO_DEVICE_SELF_POWER)
\r
107 USB_Device_CurrentlySelfPowered = false;
\r
110 #if defined(USB_DEVICE_ROM_DRIVER)
\r
111 UsbdRom_Init(corenum);
\r
113 Endpoint_ConfigureEndpoint(corenum, ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
\r
114 ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
\r
115 ENDPOINT_BANK_SINGLE);
\r
117 HAL_EnableUSBInterrupt(corenum);
\r
118 HAL_USBConnect(corenum, 1);
\r
123 #if defined(USB_CAN_BE_HOST)
\r
124 static void USB_Init_Host(uint8_t corenum)
\r
128 // for(i=0;i<PIPE_TOTAL_PIPES;i++) PipeInfo[i].PipeHandle=0;
\r
130 pipeselected[corenum] = PIPE_CONTROLPIPE;
\r
132 USB_HostState[corenum] = HOST_STATE_Unattached;
\r
133 USB_Host_ControlPipeSize[corenum] = PIPE_CONTROLPIPE_DEFAULT_SIZE;
\r
135 if (HcdInitDriver(corenum) == HCD_STATUS_OK) {
\r
136 USB_IsInitialized = true;
\r
137 HAL_EnableUSBInterrupt(corenum);
\r
140 USB_IsInitialized = false;
\r
141 HcdDeInitDriver(corenum);
\r