[riot-notifications] [RIOT-OS/RIOT] core/bitarithm: introduce bitarithm_get/set_masked(), convert pca9685 (#12238)

Gunar Schorcht notifications at github.com
Mon Sep 16 19:40:57 CEST 2019


gschorcht commented on this pull request.



> @@ -274,21 +273,21 @@ static int _init(pca9685_t *dev)
 
     /* set Auto-Increment flag */
     uint8_t byte = 0;
-    _set_reg_bit(&byte, PCA9685_MODE2_INVERT, dev->params.inv);
-    _set_reg_bit(&byte, PCA9685_MODE2_OUTDRV, dev->params.out_drv);
-    _set_reg_bit(&byte, PCA9685_MODE2_OUTNE, dev->params.out_ne);
+    bitarithm_set_masked(&byte, PCA9685_MODE2_INVERT, dev->params.inv);

I would prefer to make these changes within a separate PR once this PR is merged.

> @@ -163,6 +163,47 @@ static inline unsigned bitarithm_lsb(unsigned v)
 }
 #endif
 
+/**
+ * @brief           Sets the masked bits in a word to the given value.
+ *
+ * @note            The mask should be compile-time constant so the compiler
+ *                  is able to optimize the entire loop away.
+ *
+ * @param       val The value to modify.
+ * @param[in]  mask The bitmask to apply.
+ * @param[in]  bits The new value of the masked bits.
+ *
+ */
+#define bitarithm_set_masked(val, mask, bits) do {                  \
+        const unsigned _mask = mask;                                \

I would prefere a furthere indent for the code with exception of the closing `} while (0)` to see the structure of the macro a bit better.

> @@ -163,6 +163,47 @@ static inline unsigned bitarithm_lsb(unsigned v)
 }
 #endif
 
+/**
+ * @brief           Sets the masked bits in a word to the given value.
+ *
+ * @note            The mask should be compile-time constant so the compiler
+ *                  is able to optimize the entire loop away.
+ *
+ * @param       val The value to modify.
+ * @param[in]  mask The bitmask to apply.
+ * @param[in]  bits The new value of the masked bits.
+ *
+ */
+#define bitarithm_set_masked(val, mask, bits) do {                  \
+        const unsigned _mask = mask;                                \

Might there be a problem for `uint32_t` parameters on platforms where `unsigned` is just 16 bit? 

-- 
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/12238#pullrequestreview-288785814
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190916/679fa616/attachment.htm>


More information about the notifications mailing list