LatticeMico32 Microprocessor Software Support
LatticeMico GPIO
21
Services
The GPIO device driver registers GPIO instances with the LatticeMico32
lookup service, using their instance names for device names and
“GPIODevice” as the device type.
For more information about using the lookup service, refer to the
LatticeMico32 Software Developer User Guide
.
Software Usage Examples
This section provides two code examples that demonstrate how to access the
GPIO registers.
Using the GPIO Register Structure
The code example shown in Figure 16 shows how to locate a GPIO device,
with 32 programmable I/Os, that is instantiated in the platform and how to
directly access the registers using the GPIO register structure.
Using Provided Macros
The code example shown in Figure 17 shows how to locate a GPIO device
that is instantiated in the platform and how to directly access the data register
using the macros provided in MicoGPIO.h header file.
Figure 16: Locating a GPIO and Accessing Its Registers
/* Fetch GPIO instance named "LED" */
volatile MicoGPIO_t *pGPIO;
MicoGPIOCtx_t *leds = (MicoGPIOCtx_t *)MicoGetDevice("led");
if(leds == 0) {
/* failed to find a component named "leds" */
return(-1);
}
/* get access to the GPIO registers */
pGPIO = (volatile MicoGPIO_t *)(leds->base);
/* write 0x80 to programmable I/O pins 7 through 0 via the data
register. */
pGPIO->data = 0x80000000;
Figure 17: Locating a GPIO and Accessing Its Data Register
/* Fetch GPIO instance named "LED" */
unsigned int iValue;
MicoGPIOCtx_t *leds = (MicoGPIOCtx_t *)MicoGetDevice("led");
if (leds == 0) {
/* failed to find a component named "leds" */
return(-1);
}