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

benpicco notifications at github.com
Sun Sep 15 22:14:03 CEST 2019


benpicco commented on this pull request.



> +    /* set masked bits to the given value  */
+    _set_reg_bit(&byte, mask, data);
+
+    /* write back new register value */
+    EXEC_RET(_write(dev, reg, &byte, 1));
+
+    return PCA9685_OK;
+}
+
+static void _set_reg_bit(uint8_t *byte, uint8_t mask, uint8_t bit)
+{
+    uint8_t shift = 0;
+    while (!((mask >> shift) & 0x01)) {
+        shift++;
+    }
+    *byte = ((*byte & ~mask) | ((bit << shift) & mask));

Turns out the compiler will [optimize this all away](https://godbolt.org/z/t38n6f) - neat!

-- 
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-288379864
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190915/41b0ef65/attachment.htm>


More information about the notifications mailing list