[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
This commit is contained in:
67
lib/one_wire/pulse_protocols/pulse_protocol.c
Normal file
67
lib/one_wire/pulse_protocols/pulse_protocol.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "pulse_protocol.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct PulseProtocol {
|
||||
void* context;
|
||||
PulseProtocolPulseCallback pulse_cb;
|
||||
PulseProtocolResetCallback reset_cb;
|
||||
PulseProtocolGetDataCallback get_data_cb;
|
||||
PulseProtocolDecodedCallback decoded_cb;
|
||||
};
|
||||
|
||||
PulseProtocol* pulse_protocol_alloc() {
|
||||
PulseProtocol* protocol = malloc(sizeof(PulseProtocol));
|
||||
memset(protocol, 0, sizeof(PulseProtocol));
|
||||
return protocol;
|
||||
}
|
||||
|
||||
void pulse_protocol_set_context(PulseProtocol* protocol, void* context) {
|
||||
protocol->context = context;
|
||||
}
|
||||
|
||||
void pulse_protocol_set_pulse_cb(PulseProtocol* protocol, PulseProtocolPulseCallback callback) {
|
||||
protocol->pulse_cb = callback;
|
||||
}
|
||||
|
||||
void pulse_protocol_set_reset_cb(PulseProtocol* protocol, PulseProtocolResetCallback callback) {
|
||||
protocol->reset_cb = callback;
|
||||
}
|
||||
|
||||
void pulse_protocol_set_get_data_cb(PulseProtocol* protocol, PulseProtocolGetDataCallback callback) {
|
||||
protocol->get_data_cb = callback;
|
||||
}
|
||||
|
||||
void pulse_protocol_set_decoded_cb(PulseProtocol* protocol, PulseProtocolDecodedCallback callback) {
|
||||
protocol->decoded_cb = callback;
|
||||
}
|
||||
|
||||
void pulse_protocol_free(PulseProtocol* protocol) {
|
||||
free(protocol);
|
||||
}
|
||||
|
||||
void pulse_protocol_process_pulse(PulseProtocol* protocol, bool polarity, uint32_t length) {
|
||||
if(protocol->pulse_cb != NULL) {
|
||||
protocol->pulse_cb(protocol->context, polarity, length);
|
||||
}
|
||||
}
|
||||
|
||||
void pulse_protocol_reset(PulseProtocol* protocol) {
|
||||
if(protocol->reset_cb != NULL) {
|
||||
protocol->reset_cb(protocol->context);
|
||||
}
|
||||
}
|
||||
|
||||
bool pulse_protocol_decoded(PulseProtocol* protocol) {
|
||||
bool result = false;
|
||||
if(protocol->decoded_cb != NULL) {
|
||||
result = protocol->decoded_cb(protocol->context);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void pulse_protocol_get_data(PulseProtocol* protocol, uint8_t* data, size_t length) {
|
||||
if(protocol->get_data_cb != NULL) {
|
||||
protocol->get_data_cb(protocol->context, data, length);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user