feat(hal): add util function to reverse a 8bit byte
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user