LatticeMico32 Microprocessor Software Support
20
LatticeMico GPIO
Functions
Since the GPIO is a general-purpose device and does not fit a well-defined
usage scenario, there are no predefined functions. However, there are
numerous macros provided in the MicoGPIO.h file that allow easy access to
the various GPIO registers using the GPIO context structure. These macros
are listed here, and their usage is illustrated in “Software Usage Examples” on
page 21.
Figure 15: Macros for Accessing GPIO Registers
/*
* MACROS FOR ACCESSING GPIO REGISTERS
*
* NOTE: For the macros, the following rules apply:
* X is a pointer to a valid MicoGPIOCtx_t structure.
* Y is an unsigned int variable.
*/
/* reads data register */
#define MICO_GPIO_READ_DATA(X,Y) \
(Y)=((volatile MicoGPIO_t *)((X)->base))->data
/* writes data-register */
#define MICO_GPIO_WRITE_DATA(X,Y) \
((volatile MicoGPIO_t *)((X)->base))->data=(Y)
/* reads tristate register */
#define MICO_GPIO_READ_TRISTATE(X,Y) \
(Y) = ((volatile MicoGPIO_t *)((X)->base))->tristate
/* writes tristate register */
#define MICO_GPIO_WRITE_TRISTATE(X,Y) \
((volatile MicoGPIO_t *)((X)->base))->tristate = (Y)
/* reads irq-mask register */
#define MICO_GPIO_READ_IRQ_MASK(X,Y) \
(Y) = ((volatile MicoGPIO_t *)((X)->base))->irqMask
/* writes irq-mask register */
#define MICO_GPIO_WRITE_IRQ_MASK(X,Y) \
((volatile MicoGPIO_t *)((X)->base))->irqMask = (Y)
/* reads edge-capture register */
#define MICO_GPIO_READ_EDGE_CAPTURE(X,Y) \
(Y) = ((volatile MicoGPIO_t *)((X)->base))->edgeCapture
/* writes to the edge-capture register */
#define MICO_GPIO_WRITE_EDGE_CAPTURE(X,Y) \
((volatile MicoGPIO_t *)((X)->base))->edgeCapture = (Y)