mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-24 19:53:08 +00:00
3114a2d4b8
* 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>
72 lines
1.9 KiB
C
72 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);
|
|
|