unleashed-firmware/lib/toolbox/manchester_decoder.c
あく 389ff92cc1
Naming and coding style convention, new linter tool. ()
* Makefile, Scripts: new linter
* About: remove ID from IC
* Firmware: remove double define for DIVC/DIVR
* Scripts: check folder names too. Docker: replace syntax check with make lint.
* Reformat Sources and Migrate to new file naming convention
* Docker: symlink clang-format-12 to clang-format
* Add coding style guide
2022-01-05 19:10:18 +03:00

35 lines
984 B
C

#include "manchester_decoder.h"
#include <stdint.h>
static const uint8_t transitions[] = {0b00000001, 0b10010001, 0b10011011, 0b11111011};
static const ManchesterState manchester_reset_state = ManchesterStateMid1;
bool manchester_advance(
ManchesterState state,
ManchesterEvent event,
ManchesterState* next_state,
bool* data) {
bool result = false;
ManchesterState new_state;
if(event == ManchesterEventReset) {
new_state = manchester_reset_state;
} else {
new_state = transitions[state] >> event & 0x3;
if(new_state == state) {
new_state = manchester_reset_state;
} else {
if(new_state == ManchesterStateMid0) {
if(data) *data = false;
result = true;
} else if(new_state == ManchesterStateMid1) {
if(data) *data = true;
result = true;
}
}
}
*next_state = new_state;
return result;
}