Rework tlc5947 to remove AUTO_LOAD (#6503)

This commit is contained in:
Jesse Hills
2024-04-09 15:51:54 +12:00
committed by GitHub
parent c66b2c52c1
commit 12aa272234
13 changed files with 107 additions and 35 deletions
+3 -27
View File
@@ -2,18 +2,16 @@
// TLC5947 24-Channel, 12-Bit PWM LED Driver
// https://www.ti.com/lit/ds/symlink/tlc5947.pdf
#include <vector>
#include "esphome/components/output/float_output.h"
#include "esphome/core/component.h"
#include "esphome/core/hal.h"
#include "esphome/components/output/float_output.h"
#include <vector>
namespace esphome {
namespace tlc5947 {
class TLC5947 : public Component {
public:
class Channel;
const uint8_t N_CHANNELS_PER_CHIP = 24;
void set_data_pin(GPIOPin *data_pin) { data_pin_ = data_pin; }
@@ -31,31 +29,9 @@ class TLC5947 : public Component {
/// Send new values if they were updated.
void loop() override;
class Channel : public output::FloatOutput {
public:
void set_parent(TLC5947 *parent) { parent_ = parent; }
void set_channel(uint8_t channel) { channel_ = channel; }
protected:
void write_state(float state) override {
auto amount = static_cast<uint16_t>(state * 0xfff);
this->parent_->set_channel_value_(this->channel_, amount);
}
TLC5947 *parent_;
uint8_t channel_;
};
void set_channel_value(uint16_t channel, uint16_t value);
protected:
void set_channel_value_(uint16_t channel, uint16_t value) {
if (channel >= this->num_chips_ * N_CHANNELS_PER_CHIP)
return;
if (this->pwm_amounts_[channel] != value) {
this->update_ = true;
}
this->pwm_amounts_[channel] = value;
}
GPIOPin *data_pin_;
GPIOPin *clock_pin_;
GPIOPin *lat_pin_;