mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Fix MY9231 flicker (#5765)
This commit is contained in:
parent
4ac49907ca
commit
255483de63
2 changed files with 22 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "my9231.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace my9231 {
|
||||
|
@ -51,7 +52,11 @@ void MY9231OutputComponent::setup() {
|
|||
MY9231_CMD_SCATTER_APDM | MY9231_CMD_FREQUENCY_DIVIDE_1 | MY9231_CMD_REACTION_FAST | MY9231_CMD_ONE_SHOT_DISABLE;
|
||||
ESP_LOGV(TAG, " Command: 0x%02X", command);
|
||||
|
||||
{
|
||||
InterruptLock lock;
|
||||
this->send_dcki_pulses_(32 * this->num_chips_);
|
||||
this->init_chips_(command);
|
||||
}
|
||||
ESP_LOGV(TAG, " Chips initialized.");
|
||||
}
|
||||
void MY9231OutputComponent::dump_config() {
|
||||
|
@ -66,11 +71,14 @@ void MY9231OutputComponent::loop() {
|
|||
if (!this->update_)
|
||||
return;
|
||||
|
||||
{
|
||||
InterruptLock lock;
|
||||
for (auto pwm_amount : this->pwm_amounts_) {
|
||||
this->write_word_(pwm_amount, this->bit_depth_);
|
||||
}
|
||||
// Send 8 DI pulses. After 8 falling edges, the duty data are store.
|
||||
this->send_di_pulses_(8);
|
||||
}
|
||||
this->update_ = false;
|
||||
}
|
||||
void MY9231OutputComponent::set_channel_value_(uint8_t channel, uint16_t value) {
|
||||
|
@ -92,6 +100,7 @@ void MY9231OutputComponent::init_chips_(uint8_t command) {
|
|||
// Send 16 DI pulse. After 14 falling edges, the command data are
|
||||
// stored and after 16 falling edges the duty mode is activated.
|
||||
this->send_di_pulses_(16);
|
||||
delayMicroseconds(12);
|
||||
}
|
||||
void MY9231OutputComponent::write_word_(uint16_t value, uint8_t bits) {
|
||||
for (uint8_t i = bits; i > 0; i--) {
|
||||
|
@ -106,6 +115,13 @@ void MY9231OutputComponent::send_di_pulses_(uint8_t count) {
|
|||
this->pin_di_->digital_write(false);
|
||||
}
|
||||
}
|
||||
void MY9231OutputComponent::send_dcki_pulses_(uint8_t count) {
|
||||
delayMicroseconds(12);
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
this->pin_dcki_->digital_write(true);
|
||||
this->pin_dcki_->digital_write(false);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace my9231
|
||||
} // namespace esphome
|
||||
|
|
|
@ -49,6 +49,7 @@ class MY9231OutputComponent : public Component {
|
|||
void init_chips_(uint8_t command);
|
||||
void write_word_(uint16_t value, uint8_t bits);
|
||||
void send_di_pulses_(uint8_t count);
|
||||
void send_dcki_pulses_(uint8_t count);
|
||||
|
||||
GPIOPin *pin_di_;
|
||||
GPIOPin *pin_dcki_;
|
||||
|
|
Loading…
Reference in a new issue