Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
GpioEventManager.h
Go to the documentation of this file.
1
10#pragma once
11#include "pico/stdlib.h"
12#include <map>
13#include <vector>
14#include <functional>
15#include "EventManager.h"
16#include "GpioEvent.h"
17
22{
23public:
30
37 using GpioCallback = std::function<void(const GpioEvent &)>;
38
47 void enableInterrupt(uint pin, uint32_t edgeMask);
48
56 void disableInterrupt(uint pin);
57
66 void registerCallback(uint pin, GpioCallback cb);
67
76 void unregisterAll(uint pin);
77
78private:
79 GpioEventManager() = default;
80 bool handler_set = false;
81
82 static void gpio_event_handler(uint gpio, uint32_t events);
83
84 static inline std::map<uint, std::vector<GpioCallback>> listeners;
85};
Event pub/sub manager for embedded applications using FreeRTOS.
GpioEventManager registers interrupts and posts GpioChange events to multiple listeners per pin.
void registerCallback(uint pin, GpioCallback cb)
Register a callback for GPIO events on a specific pin.
GpioEventManager()=default
std::function< void(const GpioEvent &)> GpioCallback
Initialize the GPIO event manager.
static void gpio_event_handler(uint gpio, uint32_t events)
void unregisterAll(uint pin)
Unregister listeners for a GPIO pin.
void disableInterrupt(uint pin)
Disable GPIO interrupts for a specific pin.
static GpioEventManager & getInstance()
Get the singleton instance of GpioEventManager.
void enableInterrupt(uint pin, uint32_t edgeMask)
Enable GPIO interrupts for a specific pin and edge mask.
static std::map< uint, std::vector< GpioCallback > > listeners
Structure representing a GPIO event.
Definition GpioEvent.h:11