flipperzero-firmware/lib/one_wire/pulse_protocols/pulse_decoder.c
SG bdba15b366
[FL-2393][FL-2381] iButton, OneWire: move to plain C (#1068)
* iButton: getting started on the worker concept
* Hal delay: added global instructions_per_us variable
* iButton: one wire slave
* iButton: ibutton key setter
* iButton: one wire host, use ibutton_hal
* iButton\RFID: common pulse decoder concept
* iButton: cyfral decoder
* iButton: worker thread concept
* iButton: metakom decoder
* iButton: write key through worker
* iButton: worker mode holder
* iButton: worker improvements
* iButton: Cyfral encoder
* iButton: Metakom encoder
* lib: pulse protocol helpers
* iButton: Metakom decoder
* iButton: Cyfral decoder
* iButton worker: separate modes
* iButton: libs documentation
* HAL: iButton gpio modes
* iButton worker: rename modes file
* iButton worker, hal: move to LL
* iButton CLI: worker for reading and emulation commands
* iButton HAL: correct init and emulation sequence
* iButton cli: moved to plain C
* iButton: move to worker, small step to plain C
* Libs, one wire: move to plain C
* Libs: added forgotten files to compilation
* iButton writer: get rid of manual disable/enable irq
2022-03-29 16:01:56 +03:00

67 lines
1.9 KiB
C

#include <stdlib.h>
#include "pulse_decoder.h"
#include <string.h>
#include <furi/check.h>
#define MAX_PROTOCOL 5
struct PulseDecoder {
PulseProtocol* protocols[MAX_PROTOCOL];
};
PulseDecoder* pulse_decoder_alloc() {
PulseDecoder* decoder = malloc(sizeof(PulseDecoder));
memset(decoder, 0, sizeof(PulseDecoder));
return decoder;
}
void pulse_decoder_free(PulseDecoder* reader) {
furi_assert(reader);
free(reader);
}
void pulse_decoder_add_protocol(PulseDecoder* reader, PulseProtocol* protocol, int32_t index) {
furi_check(index < MAX_PROTOCOL);
furi_check(reader->protocols[index] == NULL);
reader->protocols[index] = protocol;
}
void pulse_decoder_process_pulse(PulseDecoder* reader, bool polarity, uint32_t length) {
furi_assert(reader);
for(size_t index = 0; index < MAX_PROTOCOL; index++) {
if(reader->protocols[index] != NULL) {
pulse_protocol_process_pulse(reader->protocols[index], polarity, length);
}
}
}
int32_t pulse_decoder_get_decoded_index(PulseDecoder* reader) {
furi_assert(reader);
int32_t decoded = -1;
for(size_t index = 0; index < MAX_PROTOCOL; index++) {
if(reader->protocols[index] != NULL) {
if(pulse_protocol_decoded(reader->protocols[index])) {
decoded = index;
break;
}
}
}
return decoded;
}
void pulse_decoder_reset(PulseDecoder* reader) {
furi_assert(reader);
for(size_t index = 0; index < MAX_PROTOCOL; index++) {
if(reader->protocols[index] != NULL) {
pulse_protocol_reset(reader->protocols[index]);
}
}
}
void pulse_decoder_get_data(PulseDecoder* reader, int32_t index, uint8_t* data, size_t length) {
furi_assert(reader);
furi_check(reader->protocols[index] != NULL);
pulse_protocol_get_data(reader->protocols[index], data, length);
}