1 Reply Latest reply on Jan 19, 2017 5:11 PM by Intel Corporation

    MRAA scope of a GPIO context

    conor100

      Hi,

       

      How come the scope of a GPIO context does not extend outside a function? I want to do all my GPIO initialization in a function but it gives an error saying that d_pin is not declared.

       

      Thanks

       

       

      #include <stdio.h>
       #include <unistd.h>
       #include <mraa.h>
      
       void gpio_init(void) {
      
       mraa_gpio_context d_pin = NULL;
       d_pin = mraa_gpio_init(100);
       mraa_gpio_dir(d_pin, MRAA_GPIO_OUT);
       }
      
      
       int main()
       {
       // select onboard LED pin based on the platform type
       // create a GPIO object from MRAA using it
      
       gpio_init();
      
       // loop forever toggling the on board LED every second
       for (;;) {
       mraa_gpio_write(d_pin, 0);
       sleep(1);
       mraa_gpio_write(d_pin, 1);
       sleep(1);
       }
      
       return MRAA_SUCCESS;
       }
      
        • 1. Re: MRAA scope of a GPIO context
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi Conor,
           
          Thanks for your interest in the Intel Joule Platform.
           
          I appreciate all the information provided, looking at the code you have posted the declaration of the d_pin context is performed inside the function gpio_init(), and you are getting the error message because that context is only accessible in that function, think of it like a local variable.
           
          Hope this information helps, however, if you have any other question, please let me know.
           
          Regards,
          -Yermi
           

          1 of 1 people found this helpful