BP1658CJ - Fix timing for all platforms, now consistent with other drivers (#5799)

This commit is contained in:
Cossid 2023-12-12 18:04:17 -06:00 committed by GitHub
parent d0bcba3b3f
commit a72725f4b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,40 +90,41 @@ void BP1658CJ::set_channel_value_(uint8_t channel, uint16_t value) {
void BP1658CJ::write_bit_(bool value) {
this->data_pin_->digital_write(value);
this->clock_pin_->digital_write(true);
delayMicroseconds(BP1658CJ_DELAY);
this->clock_pin_->digital_write(true);
delayMicroseconds(BP1658CJ_DELAY);
this->clock_pin_->digital_write(false);
delayMicroseconds(BP1658CJ_DELAY);
}
void BP1658CJ::write_byte_(uint8_t data) {
for (uint8_t mask = 0x80; mask; mask >>= 1) {
this->write_bit_(data & mask);
delayMicroseconds(BP1658CJ_DELAY);
}
// 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);
delayMicroseconds(BP1658CJ_DELAY);
this->data_pin_->pin_mode(gpio::FLAG_OUTPUT);
}
void BP1658CJ::write_buffer_(uint8_t *buffer, uint8_t size) {
this->data_pin_->digital_write(false);
delayMicroseconds(BP1658CJ_DELAY);
this->clock_pin_->digital_write(false);
delayMicroseconds(BP1658CJ_DELAY);
for (uint32_t i = 0; i < size; i++) {
this->write_byte_(buffer[i]);
delayMicroseconds(BP1658CJ_DELAY);
}
this->clock_pin_->digital_write(true);
delayMicroseconds(BP1658CJ_DELAY);
this->data_pin_->digital_write(true);
delayMicroseconds(BP1658CJ_DELAY);
}
} // namespace bp1658cj