5 Replies Latest reply on Oct 3, 2017 7:46 PM by Alan.B

    How to configure two leds and an interrupt in gpio pins?

    Alan.B

      Hello friends!

       

      I started recently with the Intel Quark D2000 Dev Board, I'm doing tests with interrupt in GPIOS, I have configured two leds and a button. The idea is to detect the interruption and to switch the LEDs, but I can not make it work. Would they help me?

       

      This is my code ...

       

      #include "qm_interrupt.h"
      #include "qm_isr.h"
      #include "qm_gpio.h"
      #include "qm_pinmux.h"
      
      #define LED_0_OUT 9
      #define LED_1_OUT 10
      #define BTN_0_IN 12
      
      static void btn_isr();
      volatile int t_status = 0;
      
      int main(void) {
      
          static qm_gpio_port_config_t cfg;
      
          qm_pmux_select(LED_0_OUT, QM_PMUX_FN_0);
          qm_pmux_select(LED_1_OUT, QM_PMUX_FN_0);
          qm_pmux_select(BTN_0_IN, QM_PMUX_FN_0);
          qm_pmux_input_en(BTN_0_IN, true);
      
          cfg.direction = BIT(LED_0_OUT) | BIT(LED_1_OUT);
          cfg.int_en = BIT(BTN_0_IN);
          cfg.int_type = BIT(BTN_0_IN);
          cfg.int_polarity = BIT(BTN_0_IN);
          cfg.int_debounce = BIT(BTN_0_IN);
          cfg.int_bothedge = 0x0;
          cfg.callback = btn_isr;
      
          qm_irq_request(QM_IRQ_GPIO_0, qm_gpio_isr_0);
          qm_gpio_set_config(QM_GPIO_0, &cfg);
      
          while (1) {
         
          }
      
          return 0;
         
      }
      
      void btn_isr () {
      
          t_status = !t_status;
      
          if (t_status == 1) {
              qm_gpio_clear_pin(QM_GPIO_0, LED_1_OUT);
              qm_gpio_set_pin(QM_GPIO_0, LED_0_OUT);
          } else if (t_status == 0) {
              qm_gpio_clear_pin(QM_GPIO_0, LED_0_OUT);
              qm_gpio_set_pin(QM_GPIO_0, LED_1_OUT);
          }
      }
      

       

      Regards!