Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
1,293 Views

MRAA scope of a GPIO context

Jump to solution

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

# include

 

# include

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;

 

}
0 Kudos
1 Solution
idata
Community Manager
49 Views

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

 

View solution in original post

1 Reply
idata
Community Manager
50 Views

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

 

View solution in original post

Reply