AnsweredAssumed Answered

Using LWGPIO_STRUCT  in lwgpio

Question asked by mike65535 on Oct 31, 2012
Latest reply on Nov 1, 2012 by Bryan Hunt

I'm trying to understand how to properly use the lwgpio functionality.

 

I scanned the forums and spotted this snippet:

 

void _bsp_io_defaults(void)
{
    LWGPIO_STRUCT pin_struct;

    lwgpio_init(&pin_struct, BSP_SPI_FLASH_WP_N,    LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);
    lwgpio_init(&pin_struct, BSP_SPI_FLASH_HOLD_N,  LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);

    lwgpio_init(&pin_struct, BSP_ANALOG_PULLUP_1,   LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);
    lwgpio_init(&pin_struct, BSP_ANALOG_PULLUP_2,   LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);
    lwgpio_init(&pin_struct, BSP_ANALOG_PULLUP_3,   LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);

 

/*etc until all pins have the correct defaults set */

}

 

In that snippet, and some other mqx code examples,  the various LWGPIO_STRUCT instances are NOT global. If so, I guess I don't understand how one accesses a pin (say BSP_SPI_FLASH_WP_N) from elsewhere in the code.  In other words, the struct(s) used above are gone once _bsp_io_defaults() returns , so if I want to change a pin's value from time to time, to what struct do I talk (e.g., using lwgpio_set_value)?

 

Can/should I, when I need it, just declare another local struct, initialize it to the pin I want to control using lwgpio_init, and then call lwgpio_set_value ?

 

Or do I instead declare a struct for each applicable IO pin globally and talk to that struct when I need to?

 

Hope that's clear.

 

Outcomes