mirror of
https://github.com/esphome/esphome.git
synced 2024-12-26 07:24:54 +01:00
[BP1658CJ] Missing clock line delays and ack bit (#5448)
* fix: missing clock line delays and ack bit * chore: remove esphome namespace from delay methods * style: removed trailing whitespace
This commit is contained in:
parent
4d81153150
commit
2c94c3d96f
1 changed files with 20 additions and 4 deletions
|
@ -12,6 +12,8 @@ static const uint8_t BP1658CJ_ADDR_START_3CH = 0x10;
|
|||
static const uint8_t BP1658CJ_ADDR_START_2CH = 0x20;
|
||||
static const uint8_t BP1658CJ_ADDR_START_5CH = 0x30;
|
||||
|
||||
static const uint8_t BP1658CJ_DELAY = 2;
|
||||
|
||||
void BP1658CJ::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BP1658CJ Output Component...");
|
||||
this->data_pin_->setup();
|
||||
|
@ -81,27 +83,41 @@ void BP1658CJ::set_channel_value_(uint8_t channel, uint16_t value) {
|
|||
}
|
||||
this->pwm_amounts_[channel] = value;
|
||||
}
|
||||
|
||||
void BP1658CJ::write_bit_(bool value) {
|
||||
this->clock_pin_->digital_write(false);
|
||||
this->data_pin_->digital_write(value);
|
||||
this->clock_pin_->digital_write(true);
|
||||
|
||||
delayMicroseconds(BP1658CJ_DELAY);
|
||||
|
||||
this->clock_pin_->digital_write(false);
|
||||
}
|
||||
|
||||
void BP1658CJ::write_byte_(uint8_t data) {
|
||||
for (uint8_t mask = 0x80; mask; mask >>= 1) {
|
||||
this->write_bit_(data & mask);
|
||||
delayMicroseconds(BP1658CJ_DELAY);
|
||||
}
|
||||
this->clock_pin_->digital_write(false);
|
||||
this->data_pin_->digital_write(true);
|
||||
|
||||
// ack bit
|
||||
this->data_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||
this->clock_pin_->digital_write(true);
|
||||
|
||||
delayMicroseconds(BP1658CJ_DELAY);
|
||||
|
||||
this->clock_pin_->digital_write(false);
|
||||
this->data_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||
}
|
||||
|
||||
void BP1658CJ::write_buffer_(uint8_t *buffer, uint8_t size) {
|
||||
this->data_pin_->digital_write(false);
|
||||
this->clock_pin_->digital_write(false);
|
||||
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
this->write_byte_(buffer[i]);
|
||||
delayMicroseconds(BP1658CJ_DELAY);
|
||||
}
|
||||
this->clock_pin_->digital_write(false);
|
||||
|
||||
this->clock_pin_->digital_write(true);
|
||||
this->data_pin_->digital_write(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue