All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 1/2] shared/util: Add convertion function for 24 bits
Date: Mon, 13 Sep 2021 11:05:51 -0700	[thread overview]
Message-ID: <20210913180552.3468107-1-luiz.dentz@gmail.com> (raw)

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds get/put 24 bits variants.
---
 src/shared/util.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index 60908371d..ac70117ca 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -131,6 +131,20 @@ static inline uint16_t get_be16(const void *ptr)
 	return be16_to_cpu(get_unaligned((const uint16_t *) ptr));
 }
 
+static inline uint32_t get_le24(const void *ptr)
+{
+	const uint8_t *src = ptr;
+
+	return ((uint32_t)src[2] << 16) | get_le16(ptr);
+}
+
+static inline uint32_t get_be24(const void *ptr)
+{
+	const uint8_t *src = ptr;
+
+	return ((uint32_t)src[0] << 16) | get_be16(&src[1]);
+}
+
 static inline uint32_t get_le32(const void *ptr)
 {
 	return le32_to_cpu(get_unaligned((const uint32_t *) ptr));
@@ -161,6 +175,18 @@ static inline void put_be16(uint16_t val, const void *ptr)
 	put_unaligned(cpu_to_be16(val), (uint16_t *) ptr);
 }
 
+static inline void put_le24(uint32_t val, void *ptr)
+{
+	put_le16(val, ptr);
+	put_unaligned(val >> 16, (uint8_t *) ptr + 2);
+}
+
+static inline void put_be24(uint32_t val, void *ptr)
+{
+	put_unaligned(val >> 16, (uint8_t *) ptr + 2);
+	put_be16(val, ptr + 1);
+}
+
 static inline void put_le32(uint32_t val, void *dst)
 {
 	put_unaligned(cpu_to_le32(val), (uint32_t *) dst);
-- 
2.31.1


             reply	other threads:[~2021-09-13 18:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 18:05 Luiz Augusto von Dentz [this message]
2021-09-13 18:05 ` [PATCH BlueZ 2/2] shared/util: Update UUID database with LE Audio services Luiz Augusto von Dentz
2021-09-13 18:42 ` [BlueZ,1/2] shared/util: Add convertion function for 24 bits bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210913180552.3468107-1-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.