/* QMSI GPIO app example * * PIN_OUT will be the output pin * PIN_IN will be the input pin with interrupts enabled * * https://communities.intel.com/thread/101009 */ #include "qm_gpio.h" #include "qm_interrupt.h" /* Connect LED to PIN_OUT (SSO 10)*/ #define PIN_OUT 0 /*Connect Button to PIN_INTR (A0)*/ #define PIN_IN 3 static void gpio_example_callback(uint32_t); int main(void) { qm_gpio_port_config_t cfg; /* Request IRQ and write GPIO port config */ cfg.direction = BIT(PIN_OUT); /* Output Pin */ cfg.int_en = BIT(PIN_IN); /* Interrupt enabled for input pin */ cfg.int_type = BIT(PIN_IN); /* Edge sensitive interrupt */ cfg.int_polarity = BIT(PIN_IN); /* Rising edge */ cfg.int_debounce = BIT(PIN_IN); /* Debounce enabled */ cfg.int_bothedge = 0x0; /* Both edge disabled */ cfg.callback = gpio_example_callback; /* When rising edge on PIN_IN occurs, gpio_example_callback is called */ qm_irq_request(QM_IRQ_GPIO_0, qm_gpio_isr_0); qm_gpio_set_config(QM_GPIO_0, &cfg); /* Turn off the LED to start */ qm_gpio_clear_pin(QM_GPIO_0, PIN_OUT); while(1) { /* Your code goes here */ /* Run infinitely */ } return 0; } /* Function called when interrupt occurs (input pin goes from LOW to HIGH) */ void gpio_example_callback(uint32_t status) { /* toggle LED state - ON/OFF */ /* If LED is off, turn it on */ if(false == qm_gpio_read_pin(QM_GPIO_0, PIN_OUT)) { qm_gpio_set_pin(QM_GPIO_0, PIN_OUT); } else{ /* If LED was on, turn it off */ qm_gpio_clear_pin(QM_GPIO_0, PIN_OUT); } }