29 ESP_LOGV(TAG,
" Resetting devices");
30 if (!this->
write_bytes(PCA9685_REGISTER_SOFTWARE_RESET,
nullptr, 0)) {
34 if (!this->
write_byte(PCA9685_REGISTER_MODE1, PCA9685_MODE1_RESTART | PCA9685_MODE1_AUTOINC)) {
42 if (!this->
read_byte(PCA9685_REGISTER_MODE1, &mode1)) {
45 mode1 = (mode1 & ~PCA9685_MODE1_RESTART) | PCA9685_MODE1_SLEEP;
46 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
52 mode1 = mode1 | PCA9685_MODE1_EXTCLK;
53 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
57 pre_scaler =
static_cast<int>((25000000 / (4096 * this->
frequency_)) - 1);
58 pre_scaler = clamp(pre_scaler, 3, 255);
60 ESP_LOGV(TAG,
" -> Prescaler: %d", pre_scaler);
62 if (!this->
write_byte(PCA9685_REGISTER_PRE_SCALE, pre_scaler)) {
66 mode1 = (mode1 & ~PCA9685_MODE1_SLEEP) | PCA9685_MODE1_RESTART;
67 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
96 const uint16_t phase_delta_begin = 4096 / num_channels;
97 for (uint8_t channel = this->min_channel_; channel <= this->
max_channel_; channel++) {
104 phase_begin = (channel - this->
min_channel_) * phase_delta_begin;
107 ESP_LOGE(TAG,
"Unknown phase balancer %d",
static_cast<int>(this->
balancer_));
114 }
else if (amount >= 4096) {
118 phase_end = phase_begin + amount;
119 if (phase_end >= 4096)
123 ESP_LOGVV(TAG,
"Channel %02u: amount=%04u phase_begin=%04u phase_end=%04u", channel, amount, phase_begin,
127 data[0] = phase_begin & 0xFF;
128 data[1] = (phase_begin >> 8) & 0xFF;
129 data[2] = phase_end & 0xFF;
130 data[3] = (phase_end >> 8) & 0xFF;
132 uint8_t
reg = PCA9685_REGISTER_LED0 + 4 * channel;