unleashed-firmware/lib/irda/irda_common_decoder_i.h
Albert Kharisov 31c31db479
[FL-1250, FL-1252, FL-1323, FL-1324] New IRDA Application (part 1) (#497)
* Add new IrdaApp (half ready), add ButtonMenu

* Fix NEC's extension

* clang-format

* Fix leak

* Add submenu optional header

* IRDA: add Edit button

* clang-format

* IrdaApp: Fix scene flow

* Add IRDA NEC extended protocol

* IRDA: Add address/command length

Co-authored-by: SG <who.just.the.doctor@gmail.com>
2021-06-02 18:16:05 +03:00

73 lines
2 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);
void irda_common_decoder_reset(void* decoder);
DecodeStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder);