Boboter
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <string>
11#include <vector>
12#include <driver/gpio.h>
13#include <freertos/FreeRTOS.h>
14#include "include/log_sources.h"
15
19namespace HAL::GPIO {
20 enum class level_t : uint8_t {
21 LOW = 0,
22 HIGH = 1
23 };
24
25 struct pin_config_t {
26 gpio_num_t gpio_pin;
27 gpio_mode_t mode;
28 gpio_pull_mode_t pull_mode;
29 gpio_int_type_t intr_type;
30 };
31
33 volatile uint32_t* set_register;
34 volatile uint32_t* clear_register;
35 uint32_t pin_mask;
36 };
37
41 class Controller {
42 private:
43 static constexpr const char* TAG = "HAL::GPIO";
44 static constexpr log_source LOG_SOURCE = LOG_SOURCE_HAL_GPIO;
45
46 mutable SemaphoreHandle_t mutex;
47
48 struct saved_config_entry_t {
49 gpio_num_t gpio_pin;
50 gpio_mode_t mode;
51 };
52
53 std::vector<saved_config_entry_t> registered_entries;
54
55 private:
56 explicit Controller();
57 ~Controller();
58
59 public:
60 Controller(const Controller&) = delete;
61 Controller& operator=(const Controller&) = delete;
62
69 static Controller& get_instance() {
70 static Controller _instance;
71 return _instance;
72 }
73
77 void enable_interrupts() const;
78
82 void shutdown();
83
89 void add(const pin_config_t& entry);
90
97 void set_level(gpio_num_t gpio_pin, level_t level) const;
98
106 [[nodiscard]] level_t get_level(gpio_num_t gpio_pin) const;
107
116 [[nodiscard]] fast_gpio_path_t get_fast_path_data(gpio_num_t gpio_pin) const;
117 };
118}
void enable_interrupts() const
Installs the ETS_GPIO_INTR_SOURCE ISR service to enable per-pin interrupts.
Definition gpio.cpp:40
void set_level(gpio_num_t gpio_pin, level_t level) const
Sets the level of the given GPIO pin.
Definition gpio.cpp:110
void add(const pin_config_t &entry)
Configures a new GPIO pin using the given config.
Definition gpio.cpp:57
fast_gpio_path_t get_fast_path_data(gpio_num_t gpio_pin) const
Gets data like the pin bit mask and necessary register addresses to address a pin directly for things...
Definition gpio.cpp:153
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:131
static Controller & get_instance()
Gets the controller instance.
Definition gpio.h:69
void shutdown()
Resets all pins and shuts down the controller.
Definition gpio.cpp:45
Controller(const Controller &)=delete
log_source
Definition log_sources.h:12
@ LOG_SOURCE_HAL_GPIO
Definition log_sources.h:15
A namespace containing all components of the GPIO hardware abstraction layer.
Definition gpio.h:19
level_t
Definition gpio.h:20
@ LOW
Definition gpio.h:21
@ HIGH
Definition gpio.h:22
Definition gpio.h:32
volatile uint32_t * set_register
Definition gpio.h:33
uint32_t pin_mask
Definition gpio.h:35
volatile uint32_t * clear_register
Definition gpio.h:34
Definition gpio.h:25
gpio_pull_mode_t pull_mode
Definition gpio.h:28
gpio_int_type_t intr_type
Definition gpio.h:29
gpio_mode_t mode
Definition gpio.h:27
gpio_num_t gpio_pin
Definition gpio.h:26