This example project demonstrates how to use interrupts to detect button presses. The example is written for BGM111 development kit in C language with Bluetooth SDK v2.0.1. The BGScript version of this project can be found at:
The example differentiates 3 kind of button presses:
The button presses generate external stack events (gecko_evt_system_external_signal), which can be handled by the user on demand. In the example log messages are sent to UART using UARTDRV.
Since UARTDRV uses interrupts as well, an interrupt dispatcher is used instead of writing interrupt handlers. This is implemented in gpiointerrupt.c
The interrupts are enabled for both rising and falling edges by:
And the callback functions are set by
Note, that the dispatcher uses pin numbers, no interrupt handler numbers, so in this case the 3rd parameter of GPIO_ExtIntConfig(...) is practically not used.
The rising/falling edge can be differentiated by reading the state of the GPIO pins in the interrupt handler.
One issue with this approach is that you lose any timestamp of when the interrupt happened inside the handling of the external_signal. If you instead configure the interrupts with gecko_config and use bgapi_hardware_init, you can get the interrupts with timestamp into the hardware_interrupt event.
@klangdon79 the event evt_hardware_interrupt is deprecated starting from SDK v2.3.0. Most of the HW related BGAPI calls are marked deprecated (ADC, GPIO, interrupts). It is better to handle the HW peripherals directly using emlib or emdrv.