[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 17:43:09 CEST 2019


benpicco commented on this pull request.



> +}
+
+static int _update(const pca9685_t *dev, uint8_t reg, uint8_t mask, uint8_t data)
+{
+    uint8_t byte;
+    uint8_t shift = 0;
+
+    while (!((mask >> shift) & 0x01)) {
+        shift++;
+    }
+
+    /* read current register value */
+    EXEC_RET(_read(dev, reg, &byte, 1));
+
+    /* set masked bits to the given value  */
+    byte = (byte & ~mask) | ((data << shift) & mask);

Looks like `data` is always either `0` or `1`/ mask has only one bit set.
Then you could simply do
```C
*byte = bit ? (*byte | mask) : (*byte & ~mask);
```

The same is almost true for `_set_reg_bit()` too - `PCA9685_MODE2_OUTNE` is the odd one out where you actually set two bits instead of one.

-- 
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-284946289
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190906/220d6cfd/attachment.htm>


More information about the notifications mailing list