mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
hidpp-generic: implement various BE/LE functions
Not used here, but better having them written once. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user