2021-07-08 18:20:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "irda.h"
|
|
|
|
#include "irda_i.h"
|
|
|
|
|
|
|
|
|
2021-09-09 21:37:32 +00:00
|
|
|
#define MATCH_TIMING(x, v, delta) ( ((x) < (v + delta)) \
|
|
|
|
&& ((x) > (v - delta)))
|
2021-07-08 18:20:13 +00:00
|
|
|
|
|
|
|
typedef struct IrdaCommonDecoder IrdaCommonDecoder;
|
|
|
|
typedef struct IrdaCommonEncoder IrdaCommonEncoder;
|
|
|
|
|
|
|
|
typedef IrdaStatus (*IrdaCommonDecode)(IrdaCommonDecoder*);
|
|
|
|
typedef bool (*IrdaCommonInterpret)(IrdaCommonDecoder*);
|
|
|
|
typedef IrdaStatus (*IrdaCommonEncode)(IrdaCommonEncoder* encoder, uint32_t* out, bool* polarity);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
IrdaTimings timings;
|
2021-08-20 20:51:15 +00:00
|
|
|
bool manchester_start_from_space;
|
2021-09-09 21:37:32 +00:00
|
|
|
bool no_stop_bit;
|
2021-07-08 18:20:13 +00:00
|
|
|
uint32_t databit_len;
|
|
|
|
IrdaCommonDecode decode;
|
|
|
|
IrdaCommonDecode decode_repeat;
|
|
|
|
IrdaCommonInterpret interpret;
|
|
|
|
IrdaCommonEncode encode;
|
|
|
|
IrdaCommonEncode encode_repeat;
|
|
|
|
} IrdaCommonProtocolSpec;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
IrdaCommonDecoderStateWaitPreamble,
|
|
|
|
IrdaCommonDecoderStateDecode,
|
|
|
|
IrdaCommonDecoderStateProcessRepeat,
|
|
|
|
} IrdaCommonStateDecoder;
|
|
|
|
|
|
|
|
typedef enum {
|
2021-09-09 21:37:32 +00:00
|
|
|
IrdaCommonEncoderStateSilence,
|
2021-07-08 18:20:13 +00:00
|
|
|
IrdaCommonEncoderStatePreamble,
|
|
|
|
IrdaCommonEncoderStateEncode,
|
|
|
|
IrdaCommonEncoderStateEncodeRepeat,
|
|
|
|
} IrdaCommonStateEncoder;
|
|
|
|
|
|
|
|
struct IrdaCommonDecoder {
|
|
|
|
const IrdaCommonProtocolSpec* protocol;
|
2021-09-09 21:37:32 +00:00
|
|
|
void* context;
|
2021-07-08 18:20:13 +00:00
|
|
|
uint32_t timings[6];
|
2021-09-09 21:37:32 +00:00
|
|
|
IrdaMessage message;
|
|
|
|
IrdaCommonStateDecoder state;
|
2021-07-08 18:20:13 +00:00
|
|
|
uint8_t timings_cnt;
|
|
|
|
bool switch_detect;
|
2021-09-09 21:37:32 +00:00
|
|
|
bool level;
|
2021-07-08 18:20:13 +00:00
|
|
|
uint16_t databit_cnt;
|
|
|
|
uint8_t data[];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IrdaCommonEncoder {
|
|
|
|
const IrdaCommonProtocolSpec* protocol;
|
|
|
|
IrdaCommonStateEncoder state;
|
|
|
|
bool switch_detect;
|
|
|
|
uint32_t bits_encoded;
|
2021-09-09 21:37:32 +00:00
|
|
|
uint32_t timings_sum;
|
2021-07-08 18:20:13 +00:00
|
|
|
uint32_t timings_encoded;
|
|
|
|
void* context;
|
|
|
|
uint8_t data[];
|
|
|
|
};
|
|
|
|
|
|
|
|
IrdaMessage* irda_common_decode(IrdaCommonDecoder *decoder, bool level, uint32_t duration);
|
2021-09-09 21:37:32 +00:00
|
|
|
IrdaStatus irda_common_decode_pdm(IrdaCommonDecoder* decoder);
|
|
|
|
IrdaStatus irda_common_decode_pwm(IrdaCommonDecoder* decoder);
|
2021-07-08 18:20:13 +00:00
|
|
|
IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder);
|
|
|
|
void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec *protocol);
|
2021-09-09 21:37:32 +00:00
|
|
|
void irda_common_decoder_free(IrdaCommonDecoder* decoder);
|
|
|
|
void irda_common_decoder_reset(IrdaCommonDecoder* decoder);
|
2021-07-08 18:20:13 +00:00
|
|
|
|
|
|
|
IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
|
|
|
|
IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
|
|
|
|
IrdaStatus irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
|
|
|
|
void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol);
|
|
|
|
void irda_common_encoder_free(IrdaCommonEncoder* encoder);
|
|
|
|
void irda_common_encoder_reset(IrdaCommonEncoder* encoder);
|
|
|
|
|