diff --git a/src/hidpp-generic.h b/src/hidpp-generic.h index 9efd0d91..3f16fb6e 100644 --- a/src/hidpp-generic.h +++ b/src/hidpp-generic.h @@ -150,12 +150,39 @@ hidpp_get_unaligned_be_u16(uint8_t *buf) return (buf[0] << 8) | buf[1]; } +static inline uint16_t +hidpp_be_u16_to_cpu(uint16_t data) +{ + return hidpp_get_unaligned_be_u16((uint8_t *)&data); +} + +static inline void +hidpp_set_unaligned_be_u16(uint8_t *buf, uint16_t value) +{ + buf[0] = value >> 8; + buf[1] = value & 0xFF; +} + +static inline uint16_t +hidpp_cpu_to_be_u16(uint16_t data) +{ + uint16_t result; + hidpp_set_unaligned_be_u16((uint8_t *)&result, data); + return result; +} + static inline uint16_t hidpp_get_unaligned_le_u16(uint8_t *buf) { return (buf[1] << 8) | buf[0]; } +static inline uint16_t +hidpp_le_u16_to_cpu(uint16_t data) +{ + return hidpp_get_unaligned_le_u16((uint8_t *)&data); +} + static inline void hidpp_set_unaligned_le_u16(uint8_t *buf, uint16_t value) { @@ -163,4 +190,12 @@ hidpp_set_unaligned_le_u16(uint8_t *buf, uint16_t value) buf[1] = value >> 8; } +static inline uint16_t +hidpp_cpu_to_le_u16(uint16_t data) +{ + uint16_t result; + hidpp_set_unaligned_le_u16((uint8_t *)&result, data); + return result; +} + #endif /* HIDPP_GENERIC_H */