diff --git a/infrared/apps/ir_decoder/helpers/bit_ops.c b/infrared/apps/ir_decoder/helpers/bit_ops.c new file mode 100644 index 0000000..bf8e685 --- /dev/null +++ b/infrared/apps/ir_decoder/helpers/bit_ops.c @@ -0,0 +1,23 @@ +#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 new file mode 100644 index 0000000..ffa8835 --- /dev/null +++ b/infrared/apps/ir_decoder/helpers/bit_ops.h @@ -0,0 +1,5 @@ +#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 a8e37a0..d7ed5e7 100644 --- a/infrared/apps/ir_decoder/ir_decoder.c +++ b/infrared/apps/ir_decoder/ir_decoder.c @@ -1,39 +1,4 @@ -#include -#include -#include -#include -#include -#include - -#define TAG "IR Decoder" - -typedef struct { - InfraredMessage* decoded_signal; - FuriMutex* mutex; - ViewPort* view_port; -} IRDecoderState; - -// https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c/746382#746382 -static 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; -} +#include "ir_decoder.h" static void render_callback(Canvas* canvas, void* ctx) { FURI_LOG_T(TAG, "Render callback"); diff --git a/infrared/apps/ir_decoder/ir_decoder.h b/infrared/apps/ir_decoder/ir_decoder.h new file mode 100644 index 0000000..b30563e --- /dev/null +++ b/infrared/apps/ir_decoder/ir_decoder.h @@ -0,0 +1,16 @@ +#include +#include +#include +#include +#include +#include + +#include "helpers/bit_ops.h" + +#define TAG "IR Decoder" + +typedef struct { + InfraredMessage* decoded_signal; + FuriMutex* mutex; + ViewPort* view_port; +} IRDecoderState;