From a542e954cf79b51a427b4ceee14795ec47b11147 Mon Sep 17 00:00:00 2001 From: Vincent Dupont Date: Thu, 23 Aug 2018 13:59:48 +0200 Subject: [PATCH] fmt: add fmt_u16_hex() --- sys/fmt/fmt.c | 5 +++++ sys/include/fmt.h | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/sys/fmt/fmt.c b/sys/fmt/fmt.c index 58aa01483b..2bd4da0229 100644 --- a/sys/fmt/fmt.c +++ b/sys/fmt/fmt.c @@ -153,6 +153,11 @@ size_t fmt_hex_bytes(uint8_t *out, const char *hex) return final_len; } +size_t fmt_u16_hex(char *out, uint16_t val) +{ + return fmt_bytes_hex_reverse(out, (uint8_t*) &val, 2); +} + size_t fmt_u32_hex(char *out, uint32_t val) { return fmt_bytes_hex_reverse(out, (uint8_t*) &val, 4); diff --git a/sys/include/fmt.h b/sys/include/fmt.h index 7176494d30..3e3d3c8fb2 100644 --- a/sys/include/fmt.h +++ b/sys/include/fmt.h @@ -119,6 +119,20 @@ uint8_t fmt_hex_byte(const char *hex); */ size_t fmt_hex_bytes(uint8_t *out, const char *hex); +/** + * @brief Convert a uint16 value to hex string. + * + * Will write 4 bytes to @p out. + * If @p out is NULL, will only return the number of bytes that would have + * been written. + * + * @param[out] out Pointer to output buffer, or NULL + * @param[in] val Value to convert + * + * @return 4 + */ +size_t fmt_u16_hex(char *out, uint16_t val); + /** * @brief Convert a uint32 value to hex string. *