diff options
| author | Zixun LI <[email protected]> | 2025-11-27 12:01:33 +0100 |
|---|---|---|
| committer | Zixun LI <[email protected]> | 2025-11-27 12:01:33 +0100 |
| commit | 2e8d193c732bb211ebff8badff16a84775db42ff (patch) | |
| tree | 9a3410e65711df25559524b760447ff68fdd316a /src/common/tusb_common.h | |
| parent | b997ec725812d2f6a573610ba0dd817f271eddea (diff) | |
| parent | 5ef55bfa30d6f8cf175b3d327f621c76aae7b138 (diff) | |
Merge remote-tracking branch 'tinyusb/master' into hcd_fsdev
Signed-off-by: Zixun LI <[email protected]>
Diffstat (limited to 'src/common/tusb_common.h')
| -rw-r--r-- | src/common/tusb_common.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index f377d5272..b53fa5c02 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -329,6 +329,39 @@ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16(void *mem, uint16_ #endif +// scatter read 4 bytes from two buffers. Parameter are not checked +TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_scatter_read32(const uint8_t *buf1, uint8_t len1, const uint8_t *buf2, + uint8_t len2) { + uint32_t result = 0; + uint8_t shift = 0; + + for (uint8_t i = 0; i < len1; ++i) { + result |= ((uint32_t)buf1[i]) << shift; + shift += 8; + } + + for (uint8_t i = 0; i < len2; ++i) { + result |= ((uint32_t)buf2[i]) << shift; + shift += 8; + } + + return result; +} + +// scatter write 4 bytes to two buffers. Parameter are not checked +TU_ATTR_ALWAYS_INLINE static inline void tu_scatter_write32(uint32_t value, uint8_t *buf1, uint8_t len1, + uint8_t *buf2, uint8_t len2) { + for (uint8_t i = 0; i < len1; ++i) { + buf1[i] = (uint8_t)(value & 0xFF); + value >>= 8; + } + + for (uint8_t i = 0; i < len2; ++i) { + buf2[i] = (uint8_t)(value & 0xFF); + value >>= 8; + } +} + //--------------------------------------------------------------------+ // Descriptor helper //--------------------------------------------------------------------+ |
