mirror of
https://github.com/esphome/esphome.git
synced 2025-09-16 10:12:21 +01:00
Support for LibreTiny platform (RTL8710, BK7231 & other modules) (#3509)
Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl> Co-authored-by: Sam Neirinck <git@samneirinck.com> Co-authored-by: David Buezas <dbuezas@users.noreply.github.com> Co-authored-by: Stroe Andrei Catalin <catalin2402@gmail.com> Co-authored-by: Sam Neirinck <github@samneirinck.be> Co-authored-by: Péter Sárközi <xmisterhu@gmail.com> Co-authored-by: Hajo Noerenberg <hn@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
22c0b0abaa
commit
a9630ac847
55
esphome/components/libretiny_pwm/libretiny_pwm.h
Normal file
55
esphome/components/libretiny_pwm/libretiny_pwm.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
|
||||
#ifdef USE_LIBRETINY
|
||||
|
||||
namespace esphome {
|
||||
namespace libretiny_pwm {
|
||||
|
||||
class LibreTinyPWM : public output::FloatOutput, public Component {
|
||||
public:
|
||||
explicit LibreTinyPWM(InternalGPIOPin *pin) : pin_(pin) {}
|
||||
|
||||
void set_frequency(float frequency) { this->frequency_ = frequency; }
|
||||
/// Dynamically change frequency at runtime
|
||||
void update_frequency(float frequency) override;
|
||||
|
||||
/// Setup LibreTinyPWM.
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
/// HARDWARE setup priority
|
||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
||||
|
||||
/// Override FloatOutput's write_state.
|
||||
void write_state(float state) override;
|
||||
|
||||
protected:
|
||||
InternalGPIOPin *pin_;
|
||||
uint8_t bit_depth_{10};
|
||||
float frequency_{};
|
||||
float duty_{0.0f};
|
||||
bool initialized_ = false;
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
|
||||
public:
|
||||
SetFrequencyAction(LibreTinyPWM *parent) : parent_(parent) {}
|
||||
TEMPLATABLE_VALUE(float, frequency);
|
||||
|
||||
void play(Ts... x) {
|
||||
float freq = this->frequency_.value(x...);
|
||||
this->parent_->update_frequency(freq);
|
||||
}
|
||||
|
||||
protected:
|
||||
LibreTinyPWM *parent_;
|
||||
};
|
||||
|
||||
} // namespace libretiny_pwm
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user