// 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 }
/* Setup a timer for a periodic (repeat mode) rate */ static void setupMRT(uint8_t ch, MRT_MODE_T mode, uint32_t rate) { LPC_MRT_CH_T *pMRT; /* Get pointer to timer selected by ch */ pMRT = Chip_MRT_GetRegPtr(ch); /* Setup timer with rate based on MRT clock */ Chip_MRT_SetInterval(pMRT, (Chip_Clock_GetSystemClockRate() / rate) | MRT_INTVAL_LOAD); /* Timer mode */ Chip_MRT_SetMode(pMRT, mode); /* Clear pending interrupt and enable timer */ Chip_MRT_IntClear(pMRT); Chip_MRT_SetEnabled(pMRT); }