These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /*----------------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 2 * Name: DEMO.C
frank26080115 0:bf7b9fba3924 3 * Purpose: USB HID Demo
frank26080115 0:bf7b9fba3924 4 * Version: V1.10
frank26080115 0:bf7b9fba3924 5 *----------------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 6 * This software is supplied "AS IS" without any warranties, express,
frank26080115 0:bf7b9fba3924 7 * implied or statutory, including but not limited to the implied
frank26080115 0:bf7b9fba3924 8 * warranties of fitness for purpose, satisfactory quality and
frank26080115 0:bf7b9fba3924 9 * noninfringement. Keil extends you a royalty-free right to reproduce
frank26080115 0:bf7b9fba3924 10 * and distribute executable files created using this software for use
frank26080115 0:bf7b9fba3924 11 * on NXP Semiconductors LPC family microcontroller devices only. Nothing
frank26080115 0:bf7b9fba3924 12 * else gives you the right to use this software.
frank26080115 0:bf7b9fba3924 13 *
frank26080115 0:bf7b9fba3924 14 * Copyright (c) 2005-2009 Keil Software.
frank26080115 0:bf7b9fba3924 15 *---------------------------------------------------------------------------*/
frank26080115 0:bf7b9fba3924 16
frank26080115 0:bf7b9fba3924 17 #include "LPC17xx.h" /* LPC17xx definitions */
frank26080115 0:bf7b9fba3924 18
frank26080115 0:bf7b9fba3924 19 #include "lpc_types.h"
frank26080115 0:bf7b9fba3924 20
frank26080115 0:bf7b9fba3924 21 #include "usb.h"
frank26080115 0:bf7b9fba3924 22 #include "usbcfg.h"
frank26080115 0:bf7b9fba3924 23 #include "usbhw.h"
frank26080115 0:bf7b9fba3924 24
frank26080115 0:bf7b9fba3924 25 #include "demo.h"
frank26080115 0:bf7b9fba3924 26 #include "hid.h"
frank26080115 0:bf7b9fba3924 27
frank26080115 0:bf7b9fba3924 28 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 29 #include "lpc17xx_nvic.h"
frank26080115 0:bf7b9fba3924 30
frank26080115 0:bf7b9fba3924 31 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 32 /** @defgroup USBDEV_USBHID USBHID
frank26080115 0:bf7b9fba3924 33 * @ingroup USBDEV_Examples
frank26080115 0:bf7b9fba3924 34 * @{
frank26080115 0:bf7b9fba3924 35 */
frank26080115 0:bf7b9fba3924 36
frank26080115 0:bf7b9fba3924 37
frank26080115 0:bf7b9fba3924 38 uint8_t InReport; /* HID Input Report */
frank26080115 0:bf7b9fba3924 39 /* Bit0 : Buttons */
frank26080115 0:bf7b9fba3924 40 /* Bit1..7: Reserved */
frank26080115 0:bf7b9fba3924 41
frank26080115 0:bf7b9fba3924 42 uint8_t OutReport; /* HID Out Report */
frank26080115 0:bf7b9fba3924 43 /* Bit0..7: LEDs */
frank26080115 0:bf7b9fba3924 44
frank26080115 0:bf7b9fba3924 45
frank26080115 0:bf7b9fba3924 46 /*
frank26080115 0:bf7b9fba3924 47 * Get HID Input Report -> InReport
frank26080115 0:bf7b9fba3924 48 */
frank26080115 0:bf7b9fba3924 49
frank26080115 0:bf7b9fba3924 50 void GetInReport (void) {
frank26080115 0:bf7b9fba3924 51
frank26080115 0:bf7b9fba3924 52 if ((LPC_GPIO2 -> FIOPIN & PBINT) == 0) { /* Check if PBINT is pressed */
frank26080115 0:bf7b9fba3924 53 InReport = 0x01;
frank26080115 0:bf7b9fba3924 54 } else {
frank26080115 0:bf7b9fba3924 55 InReport = 0x00;
frank26080115 0:bf7b9fba3924 56 }
frank26080115 0:bf7b9fba3924 57 }
frank26080115 0:bf7b9fba3924 58
frank26080115 0:bf7b9fba3924 59
frank26080115 0:bf7b9fba3924 60 /*
frank26080115 0:bf7b9fba3924 61 * Set HID Output Report <- OutReport
frank26080115 0:bf7b9fba3924 62 */
frank26080115 0:bf7b9fba3924 63
frank26080115 0:bf7b9fba3924 64 void SetOutReport (void) {
frank26080115 0:bf7b9fba3924 65 //Because 8 LEDs are not ordered, so we have check each bit
frank26080115 0:bf7b9fba3924 66 //of OurReport to turn on/off LED correctly
frank26080115 0:bf7b9fba3924 67 uint8_t led_num;
frank26080115 0:bf7b9fba3924 68 LPC_GPIO2 -> FIOCLR = LEDMSK;
frank26080115 0:bf7b9fba3924 69 LPC_GPIO1 -> FIOCLR = 0xF0000000;
frank26080115 0:bf7b9fba3924 70 //LED0 (P2.6)
frank26080115 0:bf7b9fba3924 71 led_num = OutReport & (1<<0);
frank26080115 0:bf7b9fba3924 72 if(led_num == 0)
frank26080115 0:bf7b9fba3924 73 LPC_GPIO2 -> FIOCLR |= (1<<6);
frank26080115 0:bf7b9fba3924 74 else
frank26080115 0:bf7b9fba3924 75 LPC_GPIO2 -> FIOSET |= (1<<6);
frank26080115 0:bf7b9fba3924 76 //LED1 (P2.5)
frank26080115 0:bf7b9fba3924 77 led_num = OutReport & (1<<1);
frank26080115 0:bf7b9fba3924 78 if(led_num == 0)
frank26080115 0:bf7b9fba3924 79 LPC_GPIO2 -> FIOCLR |= (1<<5);
frank26080115 0:bf7b9fba3924 80 else
frank26080115 0:bf7b9fba3924 81 LPC_GPIO2 -> FIOSET |= (1<<5);
frank26080115 0:bf7b9fba3924 82 //LED2 (P2.4)
frank26080115 0:bf7b9fba3924 83 led_num = OutReport & (1<<2);
frank26080115 0:bf7b9fba3924 84 if(led_num == 0)
frank26080115 0:bf7b9fba3924 85 LPC_GPIO2 -> FIOCLR |= (1<<4);
frank26080115 0:bf7b9fba3924 86 else
frank26080115 0:bf7b9fba3924 87 LPC_GPIO2 -> FIOSET |= (1<<4);
frank26080115 0:bf7b9fba3924 88 //LED3 (P2.3)
frank26080115 0:bf7b9fba3924 89 led_num = OutReport & (1<<3);
frank26080115 0:bf7b9fba3924 90 if(led_num == 0)
frank26080115 0:bf7b9fba3924 91 LPC_GPIO2 -> FIOCLR |= (1<<3);
frank26080115 0:bf7b9fba3924 92 else
frank26080115 0:bf7b9fba3924 93 LPC_GPIO2 -> FIOSET |= (1<<3);
frank26080115 0:bf7b9fba3924 94 //LED4 (P2.2)
frank26080115 0:bf7b9fba3924 95 led_num = OutReport & (1<<4);
frank26080115 0:bf7b9fba3924 96 if(led_num == 0)
frank26080115 0:bf7b9fba3924 97 LPC_GPIO2 -> FIOCLR |= (1<<2);
frank26080115 0:bf7b9fba3924 98 else
frank26080115 0:bf7b9fba3924 99 LPC_GPIO2 -> FIOSET |= (1<<2);
frank26080115 0:bf7b9fba3924 100 //LED5 (P1.31)
frank26080115 0:bf7b9fba3924 101 led_num = OutReport & (1<<5);
frank26080115 0:bf7b9fba3924 102 if(led_num == 0)
frank26080115 0:bf7b9fba3924 103 LPC_GPIO1 -> FIOCLR |= (1<<31);
frank26080115 0:bf7b9fba3924 104 else
frank26080115 0:bf7b9fba3924 105 LPC_GPIO1 -> FIOSET |= (1<<31);
frank26080115 0:bf7b9fba3924 106 //LED6 (P1.29)
frank26080115 0:bf7b9fba3924 107 led_num = OutReport & (1<<6);
frank26080115 0:bf7b9fba3924 108 if(led_num == 0)
frank26080115 0:bf7b9fba3924 109 LPC_GPIO1 -> FIOCLR |= (1<<29);
frank26080115 0:bf7b9fba3924 110 else
frank26080115 0:bf7b9fba3924 111 LPC_GPIO1 -> FIOSET |= (1<<29);
frank26080115 0:bf7b9fba3924 112 //LED7 (P1.28)
frank26080115 0:bf7b9fba3924 113 led_num = OutReport & (1<<7);
frank26080115 0:bf7b9fba3924 114 if(led_num == 0)
frank26080115 0:bf7b9fba3924 115 LPC_GPIO1 -> FIOCLR |= (1<<28);
frank26080115 0:bf7b9fba3924 116 else
frank26080115 0:bf7b9fba3924 117 LPC_GPIO1 -> FIOSET |= (1<<28);
frank26080115 0:bf7b9fba3924 118 }
frank26080115 0:bf7b9fba3924 119
frank26080115 0:bf7b9fba3924 120
frank26080115 0:bf7b9fba3924 121 /* Main Program */
frank26080115 0:bf7b9fba3924 122
frank26080115 0:bf7b9fba3924 123 int main (void) {
frank26080115 0:bf7b9fba3924 124 LPC_GPIO2 -> FIODIR = LEDMSK; /* LEDs, port 2, bit 0~7 output only */
frank26080115 0:bf7b9fba3924 125 LPC_GPIO1 -> FIODIR = 0xF0000000; /* LEDs, port 1, bit 28-31 output */
frank26080115 0:bf7b9fba3924 126
frank26080115 0:bf7b9fba3924 127 USB_Init(); /* USB Initialization */
frank26080115 0:bf7b9fba3924 128 USB_Connect(TRUE); /* USB Connect */
frank26080115 0:bf7b9fba3924 129
frank26080115 0:bf7b9fba3924 130 while (1); /* Loop forever */
frank26080115 0:bf7b9fba3924 131 }
frank26080115 0:bf7b9fba3924 132
frank26080115 0:bf7b9fba3924 133 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 134 /*******************************************************************************
frank26080115 0:bf7b9fba3924 135 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 136 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 137 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 138 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 139 * @return None
frank26080115 0:bf7b9fba3924 140 *******************************************************************************/
frank26080115 0:bf7b9fba3924 141 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 142 {
frank26080115 0:bf7b9fba3924 143 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 144 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 145
frank26080115 0:bf7b9fba3924 146 /* Infinite loop */
frank26080115 0:bf7b9fba3924 147 while(1);
frank26080115 0:bf7b9fba3924 148 }
frank26080115 0:bf7b9fba3924 149 #endif
frank26080115 0:bf7b9fba3924 150
frank26080115 0:bf7b9fba3924 151 /*
frank26080115 0:bf7b9fba3924 152 * @}
frank26080115 0:bf7b9fba3924 153 */
frank26080115 0:bf7b9fba3924 154