Browse Source

Pull out reverseBits into shared lib

Christopher Mullins 6 years ago
parent
commit
d20909db10
2 changed files with 26 additions and 0 deletions
  1. 18 0
      lib/Radio/RadioUtils.cpp
  2. 8 0
      lib/Radio/RadioUtils.h

+ 18 - 0
lib/Radio/RadioUtils.cpp

@@ -0,0 +1,18 @@
+#include <RadioUtils.h>
+
+#include <stdint.h>
+#include <stddef.h>
+#include <Arduino.h>
+
+uint8_t reverseBits(uint8_t byte) {
+  uint8_t result = byte;
+  uint8_t i = 7;
+
+  for (byte >>= 1; byte; byte >>= 1) {
+    result <<= 1;
+    result |= byte & 1;
+    --i;
+  }
+
+  return result << i;
+}

+ 8 - 0
lib/Radio/RadioUtils.h

@@ -0,0 +1,8 @@
+#pragma once
+
+#include <stdint.h>
+
+/**
+ * Reverse the bits of a given byte
+ */
+uint8_t reverseBits(uint8_t byte);