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#include "include/log_sources.h"
15
19namespace HAL::LEDC {
21 ledc_timer_t timer;
22 uint32_t frequency;
23 ledc_timer_bit_t resolution;
24 };
25
27 ledc_channel_t channel;
28 ledc_timer_t timer;
29 gpio_num_t gpio_pin;
30 uint32_t duty;
31 };
32
36 class Controller {
37 private:
38 static constexpr const char* TAG = "HAL::LEDC";
39 static constexpr log_source LOG_SOURCE = LOG_SOURCE_HAL_LEDC;
40
41 static constexpr ledc_mode_t SPEED_MODE = LEDC_LOW_SPEED_MODE;
42
43 mutable SemaphoreHandle_t mutex;
44
45 struct saved_channel_config_t {
46 ledc_channel_t channel;
47 gpio_num_t gpio_pin;
48 };
49
50 std::vector<ledc_timer_t> registered_timers;
51 std::vector<saved_channel_config_t> registered_channels;
52
53 private:
54 explicit Controller();
55 ~Controller();
56
57 public:
58 Controller(const Controller&) = delete;
59 Controller& operator=(const Controller&) = delete;
60
67 static Controller& get_instance() {
68 static Controller _instance;
69 return _instance;
70 }
71
75 void shutdown();
76
82 void add_timer(const timer_config_t& config);
83
89 void add_channel(const channel_config_t& config);
90
97 void set_frequency(ledc_timer_t ledc_timer, uint32_t frequency) const;
98
105 void set_duty(ledc_channel_t ledc_channel, uint32_t duty) const;
106 };
107}
void shutdown()
Resets all channels and shuts down the controller.
Definition ledc.cpp:38
void set_frequency(ledc_timer_t ledc_timer, uint32_t frequency) const
Sets the frequency of a specific LEDC timer.
Definition ledc.cpp:111
Controller(const Controller &)=delete
void add_channel(const channel_config_t &config)
Configures a new LEDC channel using the given config.
Definition ledc.cpp:81
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:118
static Controller & get_instance()
Gets the controller instance.
Definition ledc.h:67
void add_timer(const timer_config_t &config)
Configures a new LEDC timer using the given config.
Definition ledc.cpp:63
log_source
Definition log_sources.h:12
@ LOG_SOURCE_HAL_LEDC
Definition log_sources.h:16
A namespace containing all components of the LEDC hardware abstraction layer.
Definition ledc.h:19
Definition ledc.h:26
uint32_t duty
Definition ledc.h:30
ledc_timer_t timer
Definition ledc.h:28
gpio_num_t gpio_pin
Definition ledc.h:29
ledc_channel_t channel
Definition ledc.h:27
Definition ledc.h:20
ledc_timer_t timer
Definition ledc.h:21
uint32_t frequency
Definition ledc.h:22
ledc_timer_bit_t resolution
Definition ledc.h:23