GpioEventManager registers interrupts and posts GpioChange events to multiple listeners per pin. More...
#include <GpioEventManager.h>
Public Types | |
using | GpioCallback = std::function< void(const GpioEvent &)> |
Initialize the GPIO event manager. | |
Public Member Functions | |
void | enableInterrupt (uint pin, uint32_t edgeMask) |
Enable GPIO interrupts for a specific pin and edge mask. | |
void | disableInterrupt (uint pin) |
Disable GPIO interrupts for a specific pin. | |
void | registerCallback (uint pin, GpioCallback cb) |
Register a callback for GPIO events on a specific pin. | |
void | unregisterAll (uint pin) |
Unregister listeners for a GPIO pin. | |
Static Public Member Functions | |
static GpioEventManager & | getInstance () |
Get the singleton instance of GpioEventManager. | |
Private Member Functions | |
GpioEventManager ()=default | |
Static Private Member Functions | |
static void | gpio_event_handler (uint gpio, uint32_t events) |
Private Attributes | |
bool | handler_set = false |
Static Private Attributes | |
static std::map< uint, std::vector< GpioCallback > > | listeners |
Definition at line 21 of file GpioEventManager.h.
using GpioEventManager::GpioCallback = std::function<void(const GpioEvent &)> |
This declares the callback used by the pico sdk when an interrupt occurs.
Definition at line 37 of file GpioEventManager.h.
|
privatedefault |
void GpioEventManager::disableInterrupt | ( | uint | pin | ) |
This unregisters the pin from the pico SDK and stops listening for events.
pin | The GPIO pin number to disable interrupts for. |
Definition at line 23 of file GpioEventManager.cpp.
References listeners.
void GpioEventManager::enableInterrupt | ( | uint | pin, |
uint32_t | edgeMask | ||
) |
This registers the pin with the pico SDK and sets up the interrupt handler.
pin | The GPIO pin number to enable interrupts for. |
edgeMask | Bitmask of edges to listen for (GPIO_IRQ_EDGE_RISE, GPIO_IRQ_EDGE_FALL). |
Definition at line 15 of file GpioEventManager.cpp.
References gpio_event_handler(), and handler_set.
Referenced by App::onStart().
|
static |
This is a thread-safe singleton implementation.
Definition at line 10 of file GpioEventManager.cpp.
Referenced by AppContext::initFrameworkServices().
|
staticprivate |
Definition at line 36 of file GpioEventManager.cpp.
References AppContext::getTypeKey(), GpioChange, and listeners.
Referenced by enableInterrupt().
void GpioEventManager::registerCallback | ( | uint | pin, |
GpioCallback | cb | ||
) |
This allows multiple listeners to be registered for the same pin.
pin | The GPIO pin number to register the callback for. |
cb | The callback function to call when an event occurs. |
Definition at line 28 of file GpioEventManager.cpp.
References listeners.
void GpioEventManager::unregisterAll | ( | uint | pin | ) |
This removes the the list of listeners for the specified pin.
pin | The GPIO pin number to unregister the callback from. |
cb | The callback function to remove. |
Definition at line 32 of file GpioEventManager.cpp.
References listeners.
|
private |
Definition at line 80 of file GpioEventManager.h.
Referenced by enableInterrupt().
|
inlinestaticprivate |
Definition at line 84 of file GpioEventManager.h.
Referenced by disableInterrupt(), gpio_event_handler(), registerCallback(), and unregisterAll().