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

benpicco notifications at github.com
Mon Sep 16 21:00:27 CEST 2019


benpicco commented on this pull request.



> @@ -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;                                \

Yes - for the get I could get away with a macro to end up at a generic version, but I can't return from a macro so I was hoping `unsigned` will be enough.

If we can use C11 `_Generic` in RIOT, maybe this will be the solution here - I don't think any of our tool chains is *that* old that it would not support it.

I'll see what I can figure out - enjoy your hike!

-- 
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#discussion_r324834916
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190916/55d7904e/attachment.htm>


More information about the notifications mailing list