[riot-notifications] [RIOT-OS/RIOT] drivers: support for NXP PCA9685 I2C 16-channel, 12-bit PWM controller (#10556)

benpicco notifications at github.com
Fri Sep 6 16:43:27 CEST 2019


benpicco commented on this pull request.



> +
+    DEBUG_DEV("mode=%u freq=%"PRIu32" res=%u", dev, mode, freq, res);
+
+    dev->params.mode = mode;
+    dev->params.freq = freq;
+    dev->params.res = res;
+
+    /* prescale can only be set while in sleep mode (powered off) */
+    if (dev->powered_on) {
+        pca9685_pwm_poweroff(dev);
+    }
+
+    /* prescale = round(clk / (PCA9685_RESOLUTION * freq)) - 1; */
+    float clk = (float)(dev->params.ext_freq ? dev->params.ext_freq
+                                             : PCA9685_OSC_FREQ);
+    float prescale = clk / PCA9685_RESOLUTION / freq;

Do you really need `float` here?
```C
uint32_t div = PCA9685_RESOLUTION * freq;
uint8_t byte = (clk + div/2) / div - 1;
```

Should achieve the same result (untested)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10556#pullrequestreview-284909725
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190906/d7015421/attachment.htm>


More information about the notifications mailing list