5 Replies Latest reply on Oct 7, 2016 2:24 PM by LeonardoR_Intel

    More than one GPIO interrupt (configuration structure)

    mark_kram

      Hi I have simple question about GPIO configuration structure:

      Question:

      If I want to use single GPIO interrupt my conf. structure looks as below (for example)

       

      #define PIN_OUT 5

      #define PIN_INTR 2

       

      gpio_cfg.int_en = BIT(PIN_INTR);                       /* Interrupt enabled */

      gpio_cfg.int_type = BIT(PIN_INTR);                    /* Edge sensitive interrupt */

      gpio_cfg.int_polarity = BIT(PIN_INTR);               /* Rising edge */

      gpio_cfg.int_debounce = BIT(PIN_INTR);           /* Debounce enabled */

      gpio_cfg.int_bothedge = 0x0;                              /* Both edge disabled */

      gpio_cfg.callback = gpio_example_callback;      /* callback function*/

       

      my question is how it should looks like if I want to use for example two or three GPIO interrupts (buttons) and call different functions for each of them (call_back_****1, call_back_****2, call_back_****3 ) ?

       

      Reagards,

      Frank.

        • 1. Re: More than one GPIO interrupt (configuration structure)
          LeonardoR_Intel

          Hi Frank,

           

          Yes it is possible to use different GPIOs with different function calls, you have to define a different interruption pin, and another cfg (any name). I'm going to take your example to explain it to you:

           

          #define PIN_OUT 5

          #define PIN_INTR 2

          #define PIN_INTS 3

           

          gpio_cfg.int_en = BIT(PIN_INTR);                       /* Interrupt enabled */

          gpio_cfg.int_type = BIT(PIN_INTR);                    /* Edge sensitive interrupt */

          gpio_cfg.int_polarity = BIT(PIN_INTR);               /* Rising edge */

          gpio_cfg.int_debounce = BIT(PIN_INTR);           /* Debounce enabled */

          gpio_cfg.int_bothedge = 0x0;                              /* Both edge disabled */

          gpio_cfg.callback = gpio_example_callback;      /* callback function*/

           

          gpio_cfg2.int_en = BIT(PIN_INTS);                       /* Interrupt enabled */

          gpio_cfg2.int_type = BIT(PIN_INTS);                    /* Edge sensitive interrupt */

          gpio_cfg2.int_polarity = BIT(PIN_INTS);               /* Rising edge */

          gpio_cfg2.int_debounce = BIT(PIN_INTS);           /* Debounce enabled */

          gpio_cfg2.int_bothedge = 0x0;                              /* Both edge disabled */

          gpio_cfg2.callback = gpio_example_callback2;      /* callback function*/

           

          I hope you find this useful, let me know if you have issues.

           

          Regards,

          -Leonardo

          1 of 1 people found this helpful
          • 2. Re: More than one GPIO interrupt (configuration structure)
            mark_kram

            Hi Leonardo :-),

             

               thanks for your time and the fast answer. Till yesterday I was using one configuration structure and one call back function (checking inside the call back function which "button" was pressed, I think it wasn't a good idea because there was one interrupt function [inside which there was implemented button checking] which should heve possibly less operation). Please tell me which way is better one cfg configuration for all gpio interrupt or maybe each cfg struct to each gpio interrupt?

             

            Frank.

            • 3. Re: More than one GPIO interrupt (configuration structure)
              LeonardoR_Intel

              Hi Frank,

               

              That's a good question. Personally I think that the best way to do this is using different cfg structures for each GPIO interrupt, in that way you can call different interrupt functions or the same in an easier way. And in this way your code remains more organized and easy to understand.

               

              I hope you find this information helpful. 

               

              Have a nice day.

               

              Regards,

              -Leonardo

              1 of 1 people found this helpful
              • 4. Re: More than one GPIO interrupt (configuration structure)
                mark_kram

                Hi Leonardo,

                   thank you very much for your time and information :-) this is what I wanted to know. Have a nice day!

                 

                Best regards,

                Frank.

                • 5. Re: More than one GPIO interrupt (configuration structure)
                  LeonardoR_Intel

                  Hi Frank,

                   

                  That's great, it was a pleasure to help you.

                   

                  Remember that we are here to help you with your issues.

                   

                  Regards,

                  -Leonardo