mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-20 01:33:18 +00:00
31c31db479
* 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>
73 lines
2 KiB
C
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);
|
|
|