feat(hal): add util function to reverse a 8bit byte

This commit is contained in:
morris
2023-10-11 10:28:49 +08:00
parent 3de31924ac
commit e92a1515be
7 changed files with 45 additions and 23 deletions
+15
View File
@@ -85,6 +85,21 @@ uint32_t hal_utils_calc_clk_div_frac_accurate(const hal_utils_clk_info_t *clk_in
*/
uint32_t hal_utils_calc_clk_div_integer(const hal_utils_clk_info_t *clk_info, uint32_t *int_div);
/**
* @brief Reverse the bit order of an 8-bit unsigned integer
*
* @param n The 8-bit unsigned integer to be reversed
* @return The 8-bit unsigned integer after reversing
*/
__attribute__((always_inline))
static inline uint8_t hal_utils_bitwise_reverse8(uint8_t n)
{
n = ((n & 0xf0) >> 4) | ((n & 0x0f) << 4);
n = ((n & 0xcc) >> 2) | ((n & 0x33) << 2);
n = ((n & 0xaa) >> 1) | ((n & 0x55) << 1);
return n;
}
#ifdef __cplusplus
}
#endif