LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HAL_LPC11Uxx.c
Go to the documentation of this file.
1 /*
2  * @brief HAL USB functions for the LPC11Uxx microcontrollers
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #if defined(__LPC11UXX__) || defined(__LPC13UXX__)
33 
34 #include "../HAL_LPC.h"
35 #include "../../../USBTask.h"
36 
37 void HAL_USBInit(void)
38 {
39  /* Enable AHB clock to the USB block and USB RAM. */
40  LPC_SYSCON->SYSAHBCLKCTRL |= ((0x1 << 14) | (0x1 << 27));
41 
42  LPC_USB->EPBUFCFG = 0x3FC;
43 
44  /* configure usb_soft connect */
45  LPC_IOCON->PIO0_6 = 0x01;
46 
47 #if !defined(USB_DEVICE_ROM_DRIVER)
48  HAL_Reset();
49 #endif
50 }
51 
52 void HAL_USBDeInit(void)
53 {
54  NVIC_DisableIRQ(USB_IRQn); /* disable USB interrupt */
55  LPC_SYSCON->SYSAHBCLKCTRL &= ~((0x1 << 14) | (0x1 << 27)); /* disable USB clock */
56 }
57 
58 void HAL_EnableUSBInterrupt(void)
59 {
60  NVIC_EnableIRQ(USB_IRQn);
61 }
62 
63 void HAL_DisableUSBInterrupt(void)
64 {
65  NVIC_DisableIRQ(USB_IRQn);
66 }
67 
68 void HAL_SetDeviceAddress(uint8_t Address)
69 {
70 #ifdef USB_CAN_BE_DEVICE
71  LPC_USB->DEVCMDSTAT &= ~0x7F;
72  LPC_USB->DEVCMDSTAT |= (USB_EN | Address);
73 #endif
74 }
75 
76 void HAL_USBConnect(uint32_t con)
77 {
78 #ifdef USB_CAN_BE_DEVICE
79  if ( con ) {
80  LPC_USB->DEVCMDSTAT |= USB_DCON;
81  }
82  else {
83  LPC_USB->DEVCMDSTAT &= ~USB_DCON;
84  }
85 #endif
86 }
87 
88 #endif /*CHIP_LPC11UXX*/