mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-23 21:34:35 +03:00
4d6b170769
* Fixing compiler warnings with -Wextra * More warnings suppression, WIP * Even more warning fixes * Added new lines at end of text files. * Padding fix * Additional fixes to warnings on different build configurations; added -Wextra to default build pipeline * Fixes for Secplus v1 * -additional warnings * +-Wredundant-decls fixes * FuriHal: print stack overflow task name in console * FuriHal: add missing include Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
#include "manchester_encoder.h"
|
|
#include <stdio.h>
|
|
|
|
void manchester_encoder_reset(ManchesterEncoderState* state) {
|
|
state->step = 0;
|
|
}
|
|
|
|
bool manchester_encoder_advance(
|
|
ManchesterEncoderState* state,
|
|
const bool curr_bit,
|
|
ManchesterEncoderResult* result) {
|
|
bool advance = false;
|
|
switch(state->step) {
|
|
case 0:
|
|
state->prev_bit = curr_bit;
|
|
if(state->prev_bit) {
|
|
*result = ManchesterEncoderResultShortLow;
|
|
} else {
|
|
*result = ManchesterEncoderResultShortHigh;
|
|
}
|
|
state->step = 1;
|
|
advance = true;
|
|
break;
|
|
case 1:
|
|
*result = (state->prev_bit << 1) + curr_bit;
|
|
if(curr_bit == state->prev_bit) {
|
|
state->step = 2;
|
|
} else {
|
|
state->prev_bit = curr_bit;
|
|
advance = true;
|
|
}
|
|
break;
|
|
case 2:
|
|
if(curr_bit) {
|
|
*result = ManchesterEncoderResultShortLow;
|
|
} else {
|
|
*result = ManchesterEncoderResultShortHigh;
|
|
}
|
|
state->prev_bit = curr_bit;
|
|
state->step = 1;
|
|
advance = true;
|
|
break;
|
|
default:
|
|
printf("DO CRASH HERE\r\n");
|
|
// furi_crash
|
|
break;
|
|
}
|
|
return advance;
|
|
}
|
|
|
|
ManchesterEncoderResult manchester_encoder_finish(ManchesterEncoderState* state) {
|
|
state->step = 0;
|
|
return (state->prev_bit << 1) + state->prev_bit;
|
|
}
|