From 7ad1970503a72692fcccb7dcea16ae1115f1f53b Mon Sep 17 00:00:00 2001 From: Matty Jorgensen Date: Sun, 7 Apr 2024 21:01:27 -0500 Subject: [PATCH] Use bit_lib from firmware --- infrared/apps/ir_decoder/helpers/bit_ops.c | 23 ---------------------- infrared/apps/ir_decoder/helpers/bit_ops.h | 5 ----- infrared/apps/ir_decoder/ir_decoder.c | 16 +++++++-------- infrared/apps/ir_decoder/ir_decoder.h | 3 +-- 4 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 infrared/apps/ir_decoder/helpers/bit_ops.c delete mode 100644 infrared/apps/ir_decoder/helpers/bit_ops.h diff --git a/infrared/apps/ir_decoder/helpers/bit_ops.c b/infrared/apps/ir_decoder/helpers/bit_ops.c deleted file mode 100644 index bf8e685..0000000 --- a/infrared/apps/ir_decoder/helpers/bit_ops.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "bit_ops.h" - -// https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c/746382#746382 -int bit_reversal(uint32_t input) { - int s = sizeof(input) * 2; - int i, x, y, p; - int rtn = 0; - - for(i = 0; i < (s / 2); i++) { - // extract bit on the left, from MSB - p = s - i - 1; - x = input & (1 << p); - x = x >> p; - - // extract bit on the right, from LSB - y = input & (1 << i); - y = y >> i; - - rtn = rtn | (x << i); - rtn = rtn | (y << p); - } - return rtn; -} \ No newline at end of file diff --git a/infrared/apps/ir_decoder/helpers/bit_ops.h b/infrared/apps/ir_decoder/helpers/bit_ops.h deleted file mode 100644 index ffa8835..0000000 --- a/infrared/apps/ir_decoder/helpers/bit_ops.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -int bit_reversal(uint32_t input); \ No newline at end of file diff --git a/infrared/apps/ir_decoder/ir_decoder.c b/infrared/apps/ir_decoder/ir_decoder.c index d7ed5e7..d740f2d 100644 --- a/infrared/apps/ir_decoder/ir_decoder.c +++ b/infrared/apps/ir_decoder/ir_decoder.c @@ -35,20 +35,20 @@ static void render_callback(Canvas* canvas, void* ctx) { furi_string_printf( temp_str, "0x%02X%02X%02X%02X", - bit_reversal(state->decoded_signal->address), - bit_reversal(~state->decoded_signal->address), - bit_reversal(state->decoded_signal->command), - bit_reversal(~state->decoded_signal->command)); + bit_lib_reverse_8_fast(state->decoded_signal->address), + bit_lib_reverse_8_fast(~state->decoded_signal->address), + bit_lib_reverse_8_fast(state->decoded_signal->command), + bit_lib_reverse_8_fast(~state->decoded_signal->command)); } else { // 4 bytes uint32_t mask = ((1 << (16 - 8 + 1)) - 1) << 8; furi_string_printf( temp_str, "0x%02X%02X%02X%02X", - bit_reversal(state->decoded_signal->address & 0xFF), - bit_reversal((state->decoded_signal->address & mask) >> 8), - bit_reversal(state->decoded_signal->command & 0xFF), - bit_reversal((state->decoded_signal->command & mask) >> 8)); + bit_lib_reverse_8_fast(state->decoded_signal->address & 0xFF), + bit_lib_reverse_8_fast((state->decoded_signal->address & mask) >> 8), + bit_lib_reverse_8_fast(state->decoded_signal->command & 0xFF), + bit_lib_reverse_8_fast((state->decoded_signal->command & mask) >> 8)); } canvas_draw_str(canvas, 2, 40, "LIRC HEX:"); canvas_draw_str(canvas, 50, 40, furi_string_get_cstr(temp_str)); diff --git a/infrared/apps/ir_decoder/ir_decoder.h b/infrared/apps/ir_decoder/ir_decoder.h index b30563e..fb86595 100644 --- a/infrared/apps/ir_decoder/ir_decoder.h +++ b/infrared/apps/ir_decoder/ir_decoder.h @@ -4,8 +4,7 @@ #include #include #include - -#include "helpers/bit_ops.h" +#include #define TAG "IR Decoder"