24 ESP_LOGV(TAG,
" Resetting devices");
25 if (!this->
write_bytes(PCA9685_REGISTER_SOFTWARE_RESET,
nullptr, 0)) {
30 if (!this->
write_byte(PCA9685_REGISTER_MODE1, PCA9685_MODE1_RESTART | PCA9685_MODE1_AUTOINC)) {
40 if (!this->
read_byte(PCA9685_REGISTER_MODE1, &mode1)) {
44 mode1 = (mode1 & ~PCA9685_MODE1_RESTART) | PCA9685_MODE1_SLEEP;
45 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
52 mode1 = mode1 | PCA9685_MODE1_EXTCLK;
53 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
58 pre_scaler =
static_cast<int>((25000000 / (4096 * this->
frequency_)) - 1);
59 pre_scaler = clamp(pre_scaler, 3, 255);
61 ESP_LOGV(TAG,
" -> Prescaler: %d", pre_scaler);
63 if (!this->
write_byte(PCA9685_REGISTER_PRE_SCALE, pre_scaler)) {
68 mode1 = (mode1 & ~PCA9685_MODE1_SLEEP) | PCA9685_MODE1_RESTART;
69 if (!this->
write_byte(PCA9685_REGISTER_MODE1, mode1)) {
101 const uint16_t phase_delta_begin = 4096 / num_channels;
102 for (uint8_t channel = this->min_channel_; channel <= this->
max_channel_; channel++) {
103 uint16_t phase_begin;
109 phase_begin = (channel - this->
min_channel_) * phase_delta_begin;
112 ESP_LOGE(TAG,
"Unknown phase balancer %d",
static_cast<int>(this->
balancer_));
119 }
else if (amount >= 4096) {
123 phase_end = phase_begin + amount;
124 if (phase_end >= 4096)
128 ESP_LOGVV(TAG,
"Channel %02u: amount=%04u phase_begin=%04u phase_end=%04u", channel, amount, phase_begin,
132 data[0] = phase_begin & 0xFF;
133 data[1] = (phase_begin >> 8) & 0xFF;
134 data[2] = phase_end & 0xFF;
135 data[3] = (phase_end >> 8) & 0xFF;
137 uint8_t
reg = PCA9685_REGISTER_LED0 + 4 * channel;