flipperzero-firmware/lib/irda/irda_common_decoder_i.h
Albert Kharisov 3114a2d4b8
[FL-1156, FL-1249] Add IRDA encoder/decoder library (#451)
* Add cscope db generation
* Add api-hal-irda, TIM2: HAL->LL
* Add libirda: pwm decoding
* Universal state machine
* Add irda decoder library
* Move IRDA capture to standalone tool
* Add encoder/decoder samsung32, NEC, fix bugs
* Port current App to new Irda lib
* Fix clang format for test data
* Port IRDA api-hal to f6

Co-authored-by: あく <alleteam@gmail.com>
2021-05-18 13:51:00 +03:00

73 lines
1.9 KiB
C

#pragma once
#include <stdint.h>
#include "irda.h"
#define MATCH_BIT_TIMING(x, v, delta) ( ((x) < (v + delta)) \
&& ((x) > (v - delta)))
#define MATCH_PREAMBLE_TIMING(x, v, delta) ( ((x) < ((v) * (1 + (delta)))) \
&& ((x) > ((v) * (1 - (delta)))))
typedef enum {
DecodeStatusError,
DecodeStatusOk,
DecodeStatusReady,
} DecodeStatus;
typedef struct IrdaCommonDecoder IrdaCommonDecoder;
typedef DecodeStatus (*IrdaCommonDecode)(IrdaCommonDecoder*);
typedef bool (*IrdaCommonInterpret)(IrdaCommonDecoder*);
typedef DecodeStatus (*IrdaCommonDecodeRepeat)(IrdaCommonDecoder*);
typedef enum IrdaCommonState {
IrdaCommonStateWaitPreamble,
IrdaCommonStateDecode,
IrdaCommonStateProcessRepeat,
} IrdaCommonState;
typedef struct {
uint16_t preamble_mark;
uint16_t preamble_space;
uint16_t bit1_mark;
uint16_t bit1_space;
uint16_t bit0_mark;
uint16_t bit0_space;
float preamble_tolerance;
uint32_t bit_tolerance;
} IrdaCommonDecoderTimings;
typedef struct {
IrdaCommonDecoderTimings timings;
uint32_t databit_len;
IrdaCommonDecode decode;
IrdaCommonInterpret interpret;
IrdaCommonDecodeRepeat decode_repeat;
} IrdaCommonProtocolSpec;
struct IrdaCommonDecoder {
const IrdaCommonProtocolSpec* protocol;
IrdaCommonState state;
IrdaMessage message;
uint32_t timings[6];
uint8_t timings_cnt;
uint32_t level;
uint16_t databit_cnt;
uint8_t data[];
};
static inline void shift_left_array(uint32_t *array, uint32_t len, uint32_t shift) {
for (int i = 0; i < len; ++i)
array[i] = array[i + shift];
}
IrdaMessage* irda_common_decode(IrdaCommonDecoder *decoder, bool level, uint32_t duration);
void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec *protocol);
void irda_common_decoder_free(void* decoder);
DecodeStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder);