void IrTherm_Init(void){ /* Enable clocks to SWM and IOCON to save power */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); Chip_SWM_MovablePinAssign(SWM_I2C_SDA_IO, 11); Chip_SWM_MovablePinAssign(SWM_I2C_SCL_IO, 10); #if (I2C_BITRATE > 400000) /* Enable Fast Mode Plus for I2C pins */ Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO10, PIN_I2CMODE_FASTPLUS); Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO11, PIN_I2CMODE_FASTPLUS); #else Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO10, PIN_I2CMODE_STDFAST); Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO11, PIN_I2CMODE_STDFAST); #endif /* Enable I2C clock and reset I2C peripheral - the boot ROM does not do this */ Chip_I2C_Init(); /* Setup the I2C handle */ i2cHandleMaster = LPC_I2CD_API->i2c_setup(LPC_I2C_BASE, i2cMasterHandleMEM); /* Set I2C bitrate */ LPC_I2CD_API->i2c_set_bitrate(i2cHandleMaster, Chip_Clock_GetSystemClockRate(), I2C_BITRATE); /* Disable the interrupt for the I2C */ NVIC_DisableIRQ(I2C_IRQn); /* Disable clocks to SWM and IOCON to save power */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON); }
/* Board UART Initialisation function */ void Board_UART_Init(LPC_USART_T *pUART) { /* Enable the clock to the Switch Matrix */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); Chip_Clock_SetUARTClockDiv(1); /* divided by 1 */ if (pUART == LPC_USART0) { /*connect the U0_TXD_O and U0_RXD_I signals to port pins(P0.4, P0.0) */ Chip_SWM_FixedPinEnable(ACMP_I1, DISABLE); Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, PIO4); Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, PIO0); /* Enable USART0 clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_UART0); // FIXME UART clocking and reset need to be part of CHIP driver /* Peripheral reset control to USART0, a "1" bring it out of reset. */ Chip_SYSCTL_PeriphReset(RESET_USART0); } else if (pUART == LPC_USART1) { /*connect the U1_TXD_O and U1_RXD_I signals to port pins(P0.13, P0.14) */ Chip_SWM_MovablePinAssign(SWM_U1_TXD_O, PIO13); Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, PIO14); /* Enable USART1 clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_UART1); // FIXME UART clocking and reset need to be part of CHIP driver /* Peripheral reset control to USART1, a "1" bring it out of reset. */ Chip_SYSCTL_PeriphReset(RESET_USART1); } else { /*connect the U2_TXD_O and U2_RXD_I signals to port pins(P0.13, P0.14) */ Chip_SWM_MovablePinAssign(SWM_U2_TXD_O, PIO13); Chip_SWM_MovablePinAssign(SWM_U2_RXD_I, PIO14); /* Enable USART2 clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_UART2); // FIXME UART clocking and reset need to be part of CHIP driver /* Peripheral reset control to USART2, a "1" bring it out of reset. */ Chip_SYSCTL_PeriphReset(RESET_USART2); } }
/* Initialize pin and clocks for USB0/USB1 port */ static void usb_pin_clk_init(void) { /* enable USB main clock */ Chip_Clock_SetUSBClockSource(SYSCTL_USBCLKSRC_PLLOUT, 1); /* Enable AHB clock to the USB block and USB RAM. */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USB); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USBRAM); /* power UP USB Phy */ Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPAD_PD); }
/* Initialize GPIO block */ void Chip_GPIO_Init(LPC_GPIO_T *pGPIO) { Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO0); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO1); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO2); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_MUX); Chip_SYSCTL_PeriphReset(RESET_MUX); }
/* Initializes pin muxing for SPI1 interface - note that SystemInit() may already setup your pin muxing at system startup */ static void Init_SPI_PinMux(void) { #if (defined(BOARD_NXP_LPCXPRESSO_812) || defined(BOARD_LPC812MAX)) /* Enable the clock to the Switch Matrix */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); /* * Initialize SSP0 pins connect * SCK1: PINASSIGN4[31:24]: Select P0.12 * MOSI1: PINASSIGN5[7:0]: Select P0.14 * MISO1: PINASSIGN5[15:8] : Select P0.6 * SSEL1: PINASSIGN5[23:16]: Select P0.13 */ Chip_SWM_DisableFixedPin(SWM_FIXED_VDDCMP); Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO, 12); Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, 7); Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO, 14); Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, 9); #if defined(BOARD_LPC812MAX) Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 15); Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 0); #else Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 6); Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 1); #endif Chip_SWM_DisableFixedPin(SWM_FIXED_ACMP_I1); Chip_SWM_MovablePinAssign(SWM_SPI0_SSEL_IO, 13); Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL_IO, 10); /* Disable the clock to the Switch Matrix to save power */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); #elif defined(BOARD_NXP_LPCXPRESSO_824) /* Enable the clock to the Switch Matrix */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); /* Master Pins for SPI0 */ Chip_SWM_MovablePinAssign(SWM_SPI0_SSEL0_IO, 15); Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO, 24); Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 25); Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO, 26); /* Slave Pins for SPI1 */ Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL0_IO, 17); Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, 18); Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 28); Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, 16); /* Disable the clock to the Switch Matrix to save power */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); #else /* Configure your own SPI pin muxing here if needed */ #warning "No SPI pin muxing defined" #endif }
/* Set up and initialize hardware prior to call to main */ void Board_SystemInit(void) { /* System clock to the GPIO & the SWM & the IOCON need to be enabled or most of the I/O related peripherals won't work. */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); /* Setup system clocking and muxing */ SystemSetupMuxing(); }
/* Set up and initialize all required blocks and functions related to the board hardware */ void Board_Init(void) { /* INMUX and IOCON are used by many apps, enable both INMUX and IOCON clock bits here. */ Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_INPUTMUX); Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_IOCON); /* Sets up DEBUG UART */ DEBUGINIT(); /* Initialize GPIO */ Chip_GPIO_Init(LPC_GPIO); /* Initialize the LEDs. Be careful with below routine, once it's called some of the I/O will be set to output. */ Board_LED_Init(); }
/* Initializes pin muxing for SPI interface - note that SystemInit() may already setup your pin muxing at system startup */ static void Init_SPI_PinMux(void) { #if (defined(BOARD_NXP_LPCXPRESSO_1549)) /* Enable the clock to the Switch Matrix */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); /* * Initialize SPI0 pins connect * SCK0: PINASSIGN3[15:8]: Select P0.0 * MOSI0: PINASSIGN3[23:16]: Select P0.16 * MISO0: PINASSIGN3[31:24] : Select P0.10 * SSEL0: PINASSIGN4[7:0]: Select P0.9 */ Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 0, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)); Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 16, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)); Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 10, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)); Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)); Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO, 0); /* P0.0 */ Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO, 16);/* P0.16 */ Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 10);/* P0.10 */ Chip_SWM_MovablePinAssign(SWM_SPI0_SSELSN_0_IO, 9); /* P0.9 */ /* Disable the clock to the Switch Matrix to save power */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); #else /* Configure your own SPI pin muxing here if needed */ #warning "No SPI pin muxing defined" #endif }
static void usb_pin_clk_init(void) { /* enable USB main clock */ Chip_Clock_SetUSBClockSource(SYSCTL_USBCLKSRC_PLLOUT, 1); /* Enable AHB clock to the USB block and USB RAM. */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USB); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USBRAM); /* power UP USB Phy */ Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPAD_PD); /* Enable IOCON clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 3, (IOCON_FUNC1 | IOCON_MODE_INACT)); /* PIO0_3 used for USB_VBUS */ Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC1 | IOCON_MODE_INACT)); /* PIO0_6 used for USB_CONNECT */ }
/* Initialize the SPI */ void Chip_SPI_Init(LPC_SPI_T *pSPI, SPI_CONFIG_T *pConfig) { uint32_t EnStat = pSPI->CFG & SPI_CFG_SPI_EN; Chip_Clock_EnablePeriphClock((pSPI == LPC_SPI1) ? SYSCTL_CLOCK_SPI1 : SYSCTL_CLOCK_SPI0); Chip_SYSCTL_PeriphReset((pSPI == LPC_SPI1) ? RESET_SPI1 : RESET_SPI0); /* Disable before update CFG register */ if (EnStat) { Chip_SPI_Disable(pSPI); } /* SPI Configurate */ pSPI->CFG = ((uint32_t) pConfig->ClockMode) | ((uint32_t) pConfig->DataOrder) | ((uint32_t) pConfig->Mode) | ((uint32_t) pConfig->SSELPol); /* Rate Divider setting */ pSPI->DIV = SPI_DIV_VAL(pConfig->ClkDiv); /* Clear status flag*/ Chip_SPI_ClearStatus(pSPI, SPI_STAT_CLR_RXOV | SPI_STAT_CLR_TXUR | SPI_STAT_CLR_SSA | SPI_STAT_CLR_SSD); /* Return the previous state */ if (EnStat) { Chip_SPI_Enable(pSPI); } }
void Chip_USB_Init(void) { /* Set USB PLL input to main oscillator */ Chip_Clock_SetUSBPLLSource(SYSCTL_PLLCLKSRC_MAINOSC); /* Setup USB PLL (FCLKIN = 12MHz) * 4 = 48MHz MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2) FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */ Chip_Clock_SetupUSBPLL(3, 1); /* Powerup USB PLL */ Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPLL_PD); /* Wait for PLL to lock */ while (!Chip_Clock_IsUSBPLLLocked()) {} /* enable USB main clock */ Chip_Clock_SetUSBClockSource(SYSCTL_USBCLKSRC_PLLOUT, 1); /* Enable AHB clock to the USB block. */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USB); /* power UP USB Phy */ Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPHY_PD); /* Reset USB block */ Chip_SYSCTL_PeriphReset(RESET_USB); }
void CAN_baudrate_calculate(uint32_t baud_rate, uint32_t *can_api_timing_cfg) { uint32_t pClk, div, quanta, segs, seg1, seg2, clk_per_bit, can_sjw; Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_CAN); pClk = Chip_Clock_GetMainClockRate(); clk_per_bit = pClk / baud_rate; for (div = 0; div <= 15; div++) { for (quanta = 1; quanta <= 32; quanta++) { for (segs = 3; segs <= 17; segs++) { if (clk_per_bit == (segs * quanta * (div + 1))) { segs -= 3; seg1 = segs / 2; seg2 = segs - seg1; can_sjw = seg1 > 3 ? 3 : seg1; can_api_timing_cfg[0] = div; can_api_timing_cfg[1] = ((quanta - 1) & 0x3F) | (can_sjw & 0x03) << 6 | (seg1 & 0x0F) << 8 | (seg2 & 0x07) << 12; return; } } } } }
/* Initialize I2C Interface */ void Chip_I2C_Init(void) { /* Enable I2C clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_I2C); /* Peripheral reset control to I2C */ Chip_SYSCTL_PeriphReset(RESET_I2C); }
// Initialize the push button void pb_init(void){ // Set initial values pbState = READY; pbTenths = 0; pbLongPress = false; pbShortPress = false; // Set up timer interrupt Chip_MRT_IntClear(LPC_MRT_CH(0)); Chip_MRT_SetEnabled(LPC_MRT_CH(0)); // Set up pin interrupt Chip_PININT_Init(LPC_GPIO_PIN_INT); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_PININT); Chip_SYSCTL_PeriphReset(RESET_PININT); Chip_INMUX_PinIntSel(0, 0, PWR_PB_SENSE); Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, 1 << 0); Chip_PININT_SetPinModeLevel(LPC_GPIO_PIN_INT, 1 << 0); PININT_EnableLevelInt(LPC_GPIO_PIN_INT, 1 << 0); PININT_LowActive(LPC_GPIO_PIN_INT, 1 << 0); // Enable low first so that initial press is not detected NVIC_ClearPendingIRQ(PIN_INT0_IRQn); NVIC_EnableIRQ(PIN_INT0_IRQn); NVIC_SetPriority(PIN_INT0_IRQn, 0x02); // Set higher than systick, but lower than sampling }
/* Initialize the ADC peripheral and the ADC setup structure to default value */ void Chip_ADC_Init(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup) { uint8_t div; uint32_t cr = 0; uint32_t clk; Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC); #if defined(ADC_TRIM_SUPPORT) pADC->ADTRM = 0xF00; #endif pADC->INTEN = 0; /* Disable all interrupts */ cr |= ADC_CR_PDN; ADCSetup->adcRate = ADC_MAX_SAMPLE_RATE; ADCSetup->bitsAccuracy = 0; /* LPC17xx/40xx doesn't support this setting */ clk = 0; ADCSetup->burstMode = false; div = getClkDiv(pADC, false, ADCSetup->adcRate, clk); cr |= ADC_CR_CLKDIV(div); #if !defined(ADC_ACC_12BITS) cr |= ADC_CR_BITACC(ADCSetup->bitsAccuracy); #endif /*defined(ADC_ACC_12BITS)*/ pADC->CR = cr; }
/* Initializes the LPC_I2C peripheral with specified parameter */ void Chip_I2C_Init(I2C_ID_T id) { /* Enable I2C Clocking */ Chip_Clock_EnablePeriphClock(i2c[id].clk); IP_I2C_Init(i2c[id].ip); }
/* Initializes the SDC card controller */ void Chip_SDC_Init(LPC_SDC_T *pSDC) { uint32_t i = 0; Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SDC); Chip_SYSCTL_PeriphReset(SYSCTL_RESET_PCSDC); /* Initialize GPDMA controller */ Chip_GPDMA_Init(LPC_GPDMA); /* Initialize SDC peripheral */ SDC_Init(pSDC); /* Power-up SDC Peripheral */ Chip_SDC_PowerControl(pSDC, SDC_POWER_UP, 0); /* delays for the supply output is stable*/ for ( i = 0; i < 0x80000; i++ ) {} Chip_SDC_SetClock(pSDC, SDC_IDENT_CLOCK_RATE); Chip_SDC_ClockControl(pSDC, SDC_CLOCK_ENABLE, ENABLE); /* Power-on SDC Interface */ Chip_SDC_PowerControl(pSDC, SDC_POWER_ON, 0); }
/** * This brings up enough clocks to allow the processor to run quickly while initialising memory. * Other platform specific clock init can be done in init_platform() or init_architecture() */ WEAK void init_clocks( void ){ /** This brings up enough clocks to allow the processor to run quickly while initialising memory. * Other platform specific clock init can be done in init_platform() or init_architecture() */ //LPC54xx clock initialized in SystemInit(). #ifdef BOOTLOADER LPC_SYSCTL->SYSAHBCLKCTRL[0] |= 0x00000018; // Magicoe #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1 fpuInit(); #endif #if defined(NO_BOARD_LIB) /* Chip specific SystemInit */ Chip_SystemInit(); #else /* Enable RAM 2 clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SRAM2); /* Board specific SystemInit */ Board_SystemInit(); //init pin muxing and clock. #endif LPC_SYSCTL->SYSAHBCLKCTRL[0] |= 0x00000018; // Magicoe Chip_SYSCTL_PowerUp(PDRUNCFG_PD_IRC_OSC_EN|PDRUNCFG_PD_IRC_EN); /* Configure PIN0.21 as CLKOUT with pull-up, monitor the MAINCLK on scope */ Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 21, IOCON_MODE_PULLUP | IOCON_FUNC1 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF); Chip_Clock_SetCLKOUTSource(SYSCTL_CLKOUTSRC_RTC, 1); Chip_Clock_EnableRTCOsc(); Chip_RTC_Init(LPC_RTC); Chip_RTC_Enable1KHZ(LPC_RTC); Chip_RTC_Enable(LPC_RTC); #endif }
/* Sets up system pin muxing */ void Board_SetupMuxing(void) { /* Enable IOCON clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); }
/* Board Debug UART Initialisation function */ STATIC void Board_UART_Init(void) { /* Enable the clock to the Switch Matrix */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); /* Connect the U0_TXD_O and U0_RXD_I signals to port pins(P0.07, P0.18) */ Chip_SWM_DisableFixedPin(SWM_FIXED_ADC0); Chip_SWM_DisableFixedPin(SWM_FIXED_ADC8); /* Enable UART Divider clock, divided by 1 */ Chip_Clock_SetUARTClockDiv(1); /* Divided by 1 */ if (DEBUG_UART == LPC_USART0) { Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, 7); Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, 18); } else if (DEBUG_UART == LPC_USART1) { Chip_SWM_MovablePinAssign(SWM_U1_TXD_O, 7); Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, 18); } else { Chip_SWM_MovablePinAssign(SWM_U2_TXD_O, 7); Chip_SWM_MovablePinAssign(SWM_U2_RXD_I, 18); } /* Disable the clock to the Switch Matrix to save power */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); }
static void pwm_2_init(void) { uint8_t i = 0; /* Setup Board specific output pin */ /* Enable SWM clock before altering SWM */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); /* Connect SCT outputs. */ for(i = 2; i < 4; i++) { Chip_SWM_MovablePortPinAssign(pwm_config[i].pin_mov, pwm_config[i].port, pwm_config[i].pin); } /* Disable SWM clock after altering SWM */ Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); Chip_SCTPWM_Init(LPC_SCT2); Chip_SCTPWM_SetRate(LPC_SCT2, PWM_2_RATE); for(i = 2; i < 4; i++) { /* Use SCT2_OUTx pin. */ Chip_SCTPWM_SetOutPin(pwm_config[i].sct, pwm_config[i].index, i - 2); /* Start with 0% duty cycle */ Chip_SCTPWM_SetDutyCycle(pwm_config[i].sct, pwm_config[i].index, 0); } Chip_SCTPWM_Start(LPC_SCT2); return; }
void App_Button_Init(void) { ButtonWaiting = 0; //Initialize the timer for the debouncing, but don't start it Chip_TIMER_Init(DEBOUNCE_TIMER); Chip_TIMER_Reset(DEBOUNCE_TIMER); DEBOUNCE_TIMER->PR = 100; DEBOUNCE_TIMER->MCR = (1<<1)|(1<<0); //Enable MR0 match interrupt, Reset TC on MR0 match DEBOUNCE_TIMER->MR[0]= 0xFFFF; //MR0 match value //Enable the IRQ for the timer NVIC_EnableIRQ(DEBOUNCE_TIMER_NVIC_NAME); //Set all button pins to GPIO input with pullup Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_1_PORT, BUTTON_1_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP)); Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_2_PORT, BUTTON_2_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP)); Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_3_PORT, BUTTON_3_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP)); Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_4_PORT, BUTTON_4_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP)); Chip_IOCON_PinMuxSet(LPC_IOCON, BUTTON_5_PORT, BUTTON_5_PIN, (IOCON_FUNC0 | IOCON_MODE_PULLUP)); Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_1_PORT, BUTTON_1_PIN); Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_2_PORT, BUTTON_2_PIN); Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_3_PORT, BUTTON_3_PIN); Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_4_PORT, BUTTON_4_PIN); Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_5_PORT, BUTTON_5_PIN); //TODO: Probably put this in the main initalization... Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_PINT); //Setup GPIO interrupts for each button /* Configure interrupt channel for the GPIO pin in SysCon block */ Chip_SYSCTL_SetPinInterrupt(BUTTON_1_PININT_INDEX, BUTTON_1_PORT, BUTTON_1_PIN); Chip_SYSCTL_SetPinInterrupt(BUTTON_2_PININT_INDEX, BUTTON_2_PORT, BUTTON_2_PIN); Chip_SYSCTL_SetPinInterrupt(BUTTON_3_PININT_INDEX, BUTTON_3_PORT, BUTTON_3_PIN); Chip_SYSCTL_SetPinInterrupt(BUTTON_4_PININT_INDEX, BUTTON_4_PORT, BUTTON_4_PIN); Chip_SYSCTL_SetPinInterrupt(BUTTON_5_PININT_INDEX, BUTTON_5_PORT, BUTTON_5_PIN); /* Configure channel interrupt as edge sensitive and falling edge interrupt */ Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_1_PININT_INDEX)); Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_2_PININT_INDEX)); Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_3_PININT_INDEX)); Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_4_PININT_INDEX)); Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(BUTTON_5_PININT_INDEX)); Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_1_PININT_INDEX)); Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_2_PININT_INDEX)); Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_3_PININT_INDEX)); Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_4_PININT_INDEX)); Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(BUTTON_5_PININT_INDEX)); Chip_PININT_ClearIntStatus(LPC_PININT, ((1 << BUTTON_1_PININT_INDEX)|(1<<BUTTON_2_PININT_INDEX)|(1<<BUTTON_3_PININT_INDEX)|(1<<BUTTON_4_PININT_INDEX)|(1<<BUTTON_5_PININT_INDEX)) ); App_EnableButtons(); return; }
/* Initializes the LPC_I2C peripheral */ void Chip_I2C_Init(LPC_I2C_T *pI2C) { int clkIndex = returnClkIdx(pI2C); /* Enable clock to I2C peripheral and reset */ Chip_Clock_EnablePeriphClock((CHIP_SYSCON_CLOCK_T) ClockIdx[clkIndex]); Chip_SYSCON_PeriphReset((CHIP_SYSCON_PERIPH_RESET_T) resetIdx[clkIndex]); }
/* Initialize the Watchdog timer */ void Chip_WWDT_Init(LPC_WWDT_T *pWWDT) { /* Enables clock for WDT */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_WWDT); /* Disable watchdog */ IP_WWDT_Init(pWWDT); }
/* Set up and initialize hardware prior to call to main */ void Board_SystemInit(void) { /* Setup system clocking and muxing */ SystemSetupClocking(); SystemSetupMuxing(); /* Enable I/OH SRAM (SRAM1) */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_RAM1); }
/* Sets up system pin muxing */ void Board_SetupMuxing(void) { /* Enable IOCON clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); /* IOCON clock left on, this is needed if CLKIN is used. */ }
/* Initializes the pUART peripheral */ void Chip_UART_Init(LPC_USART_T *pUART) { IP_UART_ID_T UARTPort = Chip_UART_Get_UARTNum(pUART); /* Enable UART clocking. UART base clock(s) must already be enabled */ Chip_Clock_EnablePeriphClock(Chip_UART_DetermineClk(pUART)); IP_UART_Init(pUART, UARTPort); }
/* Initialize the Watchdog timer */ void Chip_WWDT_Init(LPC_WWDT_T *pWWDT) { Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_WDT); /* Disable watchdog */ pWWDT->MOD = 0; pWWDT->TC = 0xFF; pWWDT->WARNINT = 0x3FF; pWWDT->WINDOW = 0xFFFFFF; }
/* Initializes the ACMP */ void Chip_ACMP_Init(LPC_CMP_T *pACMP) { /* Enable the power to the analog comparator */ Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_ACMP_PD); /* Enable the clock to the register interface */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ACOMP); IP_ACMP_Init(pACMP); }
/* Initializes the ACMP */ void Chip_ACMP_Init(LPC_CMP_T *pACMP) { /* Enable the power to the analog comparator */ Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_ACOMP_PD); /* Enable ACMP clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ACOMP); IP_ACMP_Init(pACMP); }