Boboter
Loading...
Searching...
No Matches
ledc.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <vector>
11#include <soc/gpio_num.h>
12#include <driver/ledc.h>
13#include <freertos/FreeRTOS.h>
14
18namespace HAL::LEDC {
20 ledc_timer_t timer;
21 uint32_t frequency;
22 ledc_timer_bit_t resolution;
23 };
24
26 ledc_channel_t channel;
27 ledc_timer_t timer;
28 gpio_num_t gpio_pin;
29 uint32_t duty;
30 };
31
35 class Controller {
36 private:
37 static constexpr const char* TAG = "HAL::LEDC";
38
39 static constexpr ledc_mode_t SPEED_MODE = LEDC_LOW_SPEED_MODE;
40
41 mutable SemaphoreHandle_t mutex;
42
43 struct saved_channel_config_t {
44 ledc_channel_t channel;
45 gpio_num_t gpio_pin;
46 };
47
48 std::vector<ledc_timer_t> registered_timers;
49 std::vector<saved_channel_config_t> registered_channels;
50
51 private:
52 explicit Controller();
53 ~Controller();
54
55 public:
56 Controller(const Controller&) = delete;
57 Controller& operator=(const Controller&) = delete;
58
65 static Controller& get_instance() {
66 static Controller _instance;
67 return _instance;
68 }
69
73 void shutdown();
74
80 void add_timer(const timer_config_t& config);
81
87 void add_channel(const channel_config_t& config);
88
95 void set_frequency(ledc_timer_t ledc_timer, uint32_t frequency) const;
96
103 void set_duty(ledc_channel_t ledc_channel, uint32_t duty) const;
104 };
105}
void shutdown()
Resets all channels and shuts down the controller.
Definition ledc.cpp:32
void set_frequency(ledc_timer_t ledc_timer, uint32_t frequency) const
Sets the frequency of a specific LEDC timer.
Definition ledc.cpp:99
Controller(const Controller &)=delete
void add_channel(const channel_config_t &config)
Configures a new LEDC channel using the given config.
Definition ledc.cpp:73
Controller & operator=(const Controller &)=delete
void set_duty(ledc_channel_t ledc_channel, uint32_t duty) const
Sets the duty cycle of a specific LEDC channel.
Definition ledc.cpp:104
static Controller & get_instance()
Gets the controller instance.
Definition ledc.h:65
void add_timer(const timer_config_t &config)
Configures a new LEDC timer using the given config.
Definition ledc.cpp:57
A namespace containing all components of the LEDC hardware abstraction layer.
Definition ledc.h:18
Definition ledc.h:25
uint32_t duty
Definition ledc.h:29
ledc_timer_t timer
Definition ledc.h:27
gpio_num_t gpio_pin
Definition ledc.h:28
ledc_channel_t channel
Definition ledc.h:26
Definition ledc.h:19
ledc_timer_t timer
Definition ledc.h:20
uint32_t frequency
Definition ledc.h:21
ledc_timer_bit_t resolution
Definition ledc.h:22