Boboter
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <vector>
11#include <driver/gpio.h>
12#include <freertos/FreeRTOS.h>
13
17namespace HAL::GPIO {
18 using bitmask_t = uint64_t;
19
20 // TODO: Change to bitmask instead of pure gpio_num_t?
21 struct pin_config_t {
22 gpio_num_t gpio_pin;
23 gpio_mode_t mode;
24 gpio_pull_mode_t pull_mode;
25 gpio_int_type_t intr_type;
26 };
27
28 enum class level_t : uint8_t {
29 LOW = 0,
30 HIGH = 1
31 };
32
36 class Controller {
37 private:
38 static constexpr const char* TAG = "HAL::GPIO";
39
40 mutable SemaphoreHandle_t mutex;
41
42 struct saved_config_entry_t {
43 gpio_num_t gpio_pin;
44 gpio_mode_t mode;
45 };
46
47 std::vector<saved_config_entry_t> registered_entries;
48
49 private:
50 explicit Controller();
51 ~Controller();
52
53 public:
54 Controller(const Controller&) = delete;
55 Controller& operator=(const Controller&) = delete;
56
63 static Controller& get_instance() {
64 static Controller _instance;
65 return _instance;
66 }
67
71 void shutdown();
72
78 void add(const pin_config_t& entry);
79
86 void set_level(gpio_num_t gpio_pin, level_t level) const;
87
95 [[nodiscard]] level_t get_level(gpio_num_t gpio_pin) const;
96 };
97}
void set_level(gpio_num_t gpio_pin, level_t level) const
Sets the level of the given GPIO pin.
Definition gpio.cpp:91
void add(const pin_config_t &entry)
Configures a new GPIO pin using the given config.
Definition gpio.cpp:45
Controller & operator=(const Controller &)=delete
level_t get_level(gpio_num_t gpio_pin) const
Gets the level of the given GPIO pin.
Definition gpio.cpp:110
static Controller & get_instance()
Gets the controller instance.
Definition gpio.h:63
void shutdown()
Resets all pins and shuts down the controller.
Definition gpio.cpp:33
Controller(const Controller &)=delete
A namespace containing all components of the GPIO hardware abstraction layer.
Definition gpio.h:17
uint64_t bitmask_t
Definition gpio.h:18
level_t
Definition gpio.h:28
@ LOW
Definition gpio.h:29
@ HIGH
Definition gpio.h:30
Definition gpio.h:21
gpio_pull_mode_t pull_mode
Definition gpio.h:24
gpio_int_type_t intr_type
Definition gpio.h:25
gpio_mode_t mode
Definition gpio.h:23
gpio_num_t gpio_pin
Definition gpio.h:22