25 ESP_LOGV(TAG,
" Resetting devices");
26 if (!this->
write_bytes(PCA9685_REGISTER_SOFTWARE_RESET,
nullptr, 0)) {
31 if (!this->
write_byte(PCA9685_REGISTER_MODE1, PCA9685_MODE1_RESTART | PCA9685_MODE1_AUTOINC)) {
41 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)) {
53 mode1 = mode1 | PCA9685_MODE1_EXTCLK;
54 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
59 pre_scaler =
static_cast<int>((25000000 / (4096 * this->
frequency_)) - 1);
60 pre_scaler = clamp(pre_scaler, 3, 255);
62 ESP_LOGV(TAG,
" -> Prescaler: %d", pre_scaler);
64 if (!this->
write_byte(PCA9685_REGISTER_PRE_SCALE, pre_scaler)) {
69 mode1 = (mode1 & ~PCA9685_MODE1_SLEEP) | PCA9685_MODE1_RESTART;
70 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
102 const uint16_t phase_delta_begin = 4096 / num_channels;
103 for (uint8_t channel = this->min_channel_; channel <= this->
max_channel_; channel++) {
104 uint16_t phase_begin;
110 phase_begin = (channel - this->
min_channel_) * phase_delta_begin;
113 ESP_LOGE(TAG,
"Unknown phase balancer %d",
static_cast<int>(this->
balancer_));
120 }
else if (amount >= 4096) {
124 phase_end = phase_begin + amount;
125 if (phase_end >= 4096)
129 ESP_LOGVV(TAG,
"Channel %02u: amount=%04u phase_begin=%04u phase_end=%04u", channel, amount, phase_begin,
133 data[0] = phase_begin & 0xFF;
134 data[1] = (phase_begin >> 8) & 0xFF;
135 data[2] = phase_end & 0xFF;
136 data[3] = (phase_end >> 8) & 0xFF;
138 uint8_t
reg = PCA9685_REGISTER_LED0 + 4 * channel;