Skip to content

Instantly share code, notes, and snippets.

@jboone
Last active December 19, 2015 02:19
Show Gist options
  • Save jboone/5881987 to your computer and use it in GitHub Desktop.
Save jboone/5881987 to your computer and use it in GitHub Desktop.
LPC43xx code for GPIO pin interrupts, ripped from the quadrature encoder code of my HackRF spectrum analyzer. (I should clean up that code and post it someday...)
// Pin configuration.
scu_pinmux(SCU_SD_CD, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
scu_pinmux(SCU_SD_DAT3, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
SCU_PINTSEL0 =
(1 << 13) | // GPIO1[6]
(6 << 8) |
(1 << 5) | // GPIO1[5]
(5 << 0)
;
// Interrupt configuration.
GPIO_PIN_INTERRUPT_ISEL =
(0 << 1) | // 1: edge-sensitive
(0 << 0) // 0: edge-sensitive
;
GPIO_PIN_INTERRUPT_IENR =
(1 << 1) | // 1: Enable rising-edge interrupt
(1 << 0) // 0: Enable rising-edge interrupt
;
GPIO_PIN_INTERRUPT_IENF =
(1 << 1) | // 1: Enable falling-edge interrupt
(1 << 0) // 0: Enable falling-edge interrupt
;
nvic_set_priority(NVIC_M4_PIN_INT0_IRQ, 255);
nvic_enable_irq(NVIC_M4_PIN_INT0_IRQ);
nvic_set_priority(NVIC_M4_PIN_INT1_IRQ, 255);
nvic_enable_irq(NVIC_M4_PIN_INT1_IRQ);
// Interrupt handlers.
void pin_int0_irqhandler() {
if( GPIO_PIN_INTERRUPT_IST & (1 << 0) ) {
encoder_update();
GPIO_PIN_INTERRUPT_IST = (1 << 0);
GPIO_PIN_INTERRUPT_RISE = (1 << 0);
GPIO_PIN_INTERRUPT_FALL = (1 << 0);
}
}
void pin_int1_irqhandler() {
if( GPIO_PIN_INTERRUPT_IST & (1 << 1) ) {
encoder_update();
GPIO_PIN_INTERRUPT_RISE = (1 << 1);
GPIO_PIN_INTERRUPT_FALL = (1 << 1);
GPIO_PIN_INTERRUPT_IST = (1 << 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment