Add util functions to write in little-endian
This will be helpful for writing HID values.
This commit is contained in:
parent
6366438a69
commit
2680a714b4
@ -13,6 +13,12 @@ sc_write16be(uint8_t *buf, uint16_t value) {
|
|||||||
buf[1] = value;
|
buf[1] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
sc_write16le(uint8_t *buf, uint16_t value) {
|
||||||
|
buf[0] = value;
|
||||||
|
buf[1] = value >> 8;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
sc_write32be(uint8_t *buf, uint32_t value) {
|
sc_write32be(uint8_t *buf, uint32_t value) {
|
||||||
buf[0] = value >> 24;
|
buf[0] = value >> 24;
|
||||||
@ -21,12 +27,26 @@ sc_write32be(uint8_t *buf, uint32_t value) {
|
|||||||
buf[3] = value;
|
buf[3] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
sc_write32le(uint8_t *buf, uint32_t value) {
|
||||||
|
buf[0] = value;
|
||||||
|
buf[1] = value >> 8;
|
||||||
|
buf[2] = value >> 16;
|
||||||
|
buf[3] = value >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
sc_write64be(uint8_t *buf, uint64_t value) {
|
sc_write64be(uint8_t *buf, uint64_t value) {
|
||||||
sc_write32be(buf, value >> 32);
|
sc_write32be(buf, value >> 32);
|
||||||
sc_write32be(&buf[4], (uint32_t) value);
|
sc_write32be(&buf[4], (uint32_t) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
sc_write64le(uint8_t *buf, uint64_t value) {
|
||||||
|
sc_write32le(buf, (uint32_t) value);
|
||||||
|
sc_write32le(buf, value >> 32);
|
||||||
|
}
|
||||||
|
|
||||||
static inline uint16_t
|
static inline uint16_t
|
||||||
sc_read16be(const uint8_t *buf) {
|
sc_read16be(const uint8_t *buf) {
|
||||||
return (buf[0] << 8) | buf[1];
|
return (buf[0] << 8) | buf[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user