GPIOINT - GPIO Interrupt#
GPIOINT General Purpose Input/Output Interrupt dispatcher.
The source files for the GPIO interrupt dispatcher library resides in the emdrv/gpiointerrupt folder, and are named gpiointerrupt.c and gpiointerrupt.h.
Introduction#
EFM32/EZR32/EFR32 has two GPIO interrupts lines, Odd and Even. If more than two interrupts are used then interrupt routine must dispatch from a callback register. This module provides small dispatcher for both GPIO interrupts enabling handling of up to 32 GPIO pin interrupts.
It is up to the user to configure and enable interrupt on given pin. This can be done using the GPIO library (emlib). This module handles the dispatch register and clearing of interrupt flags.
In order to use this dispatcher, it has to be initialized first by calling GPIOINT_Init(). Then each pin interrupt number must be configured by first registering the callback function for given interrupt number and then configure and enabling the interrupt number in the GPIO module.
The extended function GPIOINT_CallbackRegisterExt() may also be used to register a callback with context for a given pin number. The first available interrupt number will be returned.
The API#
This section contain brief descriptions of the functions in the API. You will find detailed information on parameters by clicking on the hyperlinked function names.
Your application code must include one header file: gpiointerrupt.h.
GPIOINT_Init()
This functions initializes the dispatcher register. Typically GPIOINT_Init() is called once in your startup code.
GPIOINT_CallbackRegister()
Register a callback function on a pin interrupt number.
GPIOINT_CallbackUnRegister()
Un-register a callback function on a pin interrupt number.
GPIOINT_CallbackRegisterExt()
Register a callback function with context on a pin number.
Example#
#include "gpiointerrupt.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_gpio.h"
// An array to track if given pin callback was called
volatile uint8_t pinInt[32];
// Gpio callbacks called when pin interrupt was triggered.
void gpioCallback1(uint8_t intNo)
{
pinInt[intNo]++;
}
void gpioCallback3(uint8_t intNo)
{
pinInt[intNo]++;
}
void gpioCallback8(uint8_t intNo)
{
pinInt[intNo]++;
}
int main(void)
{
CHIP_Init();
// Enable clock for GPIO module, initialize GPIOINT
CMU_ClockEnable(cmuClock_GPIO, true);
GPIOINT_Init();
// Register callback functions and enable interrupts
GPIOINT_CallbackRegister(1, gpioCallback1);
GPIOINT_CallbackRegister(3, gpioCallback3);
unsigned int intPin8 = GPIOINT_CallbackRegisterExt(8, gpioCallback8, (void *)callback8context);
GPIO_IntEnable(1<<1 | 1<<3 | 1<<intPin8);
while(true);
}
Typedefs#
GPIO interrupt callback function pointer.
Extended GPIO interrupt callback function pointer.
Functions#
Initialization of GPIOINT module.
Registers user callback for given pin interrupt number.
Registers user em4 wakeup callback for given port and pin interrupt number.
Registers user callback for given pin interrupt number.
Wrapper function to support porting gpiointerrupt.
Unregister user callback for a given pin interrupt number.
Macros#
A MACRO for Interrupt Un-available.
Typedef Documentation#
GPIOINT_IrqCallbackPtr_t#
typedef void(* GPIOINT_IrqCallbackPtr_t) (uint8_t intNo) )(uint8_t intNo)
GPIO interrupt callback function pointer.
Parameters:
intNo - The pin interrupt number the callback function is invoked for.
62
of file platform/emdrv/gpiointerrupt/inc/gpiointerrupt.h
GPIOINT_IrqCallbackPtrExt_t#
typedef void(* GPIOINT_IrqCallbackPtrExt_t) (uint8_t intNo, void *ctx) )(uint8_t intNo, void *ctx)
Extended GPIO interrupt callback function pointer.
Parameters:
intNo - The pin interrupt number the callback function is invoked for.
ctx - Pointer to callback context.
72
of file platform/emdrv/gpiointerrupt/inc/gpiointerrupt.h
Function Documentation#
GPIOINT_Init#
void GPIOINT_Init (void )
Initialization of GPIOINT module.
N/A |
84
of file platform/emdrv/gpiointerrupt/src/gpiointerrupt.c
GPIOINT_CallbackRegister#
void GPIOINT_CallbackRegister (uint8_t intNo, GPIOINT_IrqCallbackPtr_t callbackPtr)
Registers user callback for given pin interrupt number.
[in] | intNo | Pin interrupt number for the callback. |
[in] | callbackPtr | A pointer to callback function. |
Use this function to register a callback which shall be called upon interrupt generated for a given pin interrupt number. Interrupt itself must be configured externally. Function overwrites previously registered callback.
104
of file platform/emdrv/gpiointerrupt/src/gpiointerrupt.c
GPIOINT_EM4WUCallbackRegisterExt#
unsigned int GPIOINT_EM4WUCallbackRegisterExt (GPIO_Port_TypeDef port, uint8_t pin, GPIOINT_IrqCallbackPtrExt_t callbackPtr, void * callbackCtx)
Registers user em4 wakeup callback for given port and pin interrupt number.
[in] | port | GPIO Port for the callback. |
[in] | pin | Pin number for the callback. |
[in] | callbackPtr | A pointer to callback function. |
[in] | callbackCtx | A pointer to the callback context. |
Use this function to register an EM4 wakeup callback with context which shall be called upon interrupt generated for a given pin number. The function will return an interrupt number if one is available and pin is EM4WU compatible. Interrupt itself must be configured externally.
Returns
Interrupt number, or INTERRUPT_UNAVAILABLE if all are in use or pin doesn't support em4 wakeup.
146
of file platform/emdrv/gpiointerrupt/src/gpiointerrupt.c
GPIOINT_CallbackRegisterExt#
unsigned int GPIOINT_CallbackRegisterExt (uint8_t pin, GPIOINT_IrqCallbackPtrExt_t callbackPtr, void * callbackCtx)
Registers user callback for given pin interrupt number.
[in] | pin | Pin number for the callback. |
[in] | callbackPtr | A pointer to callback function. |
[in] | callbackCtx | A pointer to the callback context. |
Use this function to register a callback with context which shall be called upon interrupt generated for a given pin number. The function will return an interrupt number if one is available. Interrupt itself must be configured externally.
Returns
Interrupt number, or INTERRUPT_UNAVAILABLE if all are in use
225
of file platform/emdrv/gpiointerrupt/src/gpiointerrupt.c
gpioint_map_callback#
static void gpioint_map_callback (uint8_t int_no, void * context)
Wrapper function to support porting gpiointerrupt.
[in] | int_no | Interrupt number for callback |
[in] | context | A pointer to callback |
252
of file platform/emdrv/gpiointerrupt/src/gpiointerrupt.c
GPIOINT_CallbackUnRegister#
void GPIOINT_CallbackUnRegister (uint8_t intNo)
Unregister user callback for a given pin interrupt number.
[in] | intNo | Pin interrupt number for the callback. |
Use this function to unregister a callback.
100
of file platform/emdrv/gpiointerrupt/inc/gpiointerrupt.h
Macro Definition Documentation#
INTERRUPT_UNAVAILABLE
#define INTERRUPT_UNAVAILABLEValue:
(0xFF)
A MACRO for Interrupt Un-available.
49
of file platform/emdrv/gpiointerrupt/inc/gpiointerrupt.h