[FL-1800] IRDA: enc/decoder refactoring, Add NEC42 (#705)
* WIP: IRDA: multilen protocol refactoring, NEC42 * IRDA: Refactoring encoder/decoder Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "furi/check.h"
|
||||
#include "furi/common_defines.h"
|
||||
#include "irda.h"
|
||||
#include "irda_common_i.h"
|
||||
#include <stdbool.h>
|
||||
@@ -39,11 +40,12 @@ static bool irda_check_preamble(IrdaCommonDecoder* decoder) {
|
||||
bool result = false;
|
||||
bool start_level = (decoder->level + decoder->timings_cnt + 1) % 2;
|
||||
|
||||
if (decoder->timings_cnt == 0)
|
||||
return false;
|
||||
|
||||
// align to start at Mark timing
|
||||
if (!start_level) {
|
||||
if (decoder->timings_cnt > 0) {
|
||||
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
|
||||
}
|
||||
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
|
||||
}
|
||||
|
||||
if (decoder->protocol->timings.preamble_mark == 0) {
|
||||
@@ -66,45 +68,75 @@ static bool irda_check_preamble(IrdaCommonDecoder* decoder) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Pulse Distance Modulation */
|
||||
IrdaStatus irda_common_decode_pdm(IrdaCommonDecoder* decoder) {
|
||||
|
||||
/**
|
||||
* decoder->protocol->databit_len[0] contains biggest amount of bits, for this protocol.
|
||||
* decoder->protocol->databit_len[1...] contains lesser values, but which can be decoded
|
||||
* for some protocol modifications.
|
||||
*/
|
||||
static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
uint32_t* timings = decoder->timings;
|
||||
IrdaStatus status = IrdaStatusError;
|
||||
IrdaStatus status = IrdaStatusOk;
|
||||
const IrdaTimings* timings = &decoder->protocol->timings;
|
||||
|
||||
while (decoder->timings_cnt && (status == IrdaStatusOk)) {
|
||||
bool level = (decoder->level + decoder->timings_cnt + 1) % 2;
|
||||
uint32_t timing = decoder->timings[0];
|
||||
|
||||
/* check if short protocol version can be decoded */
|
||||
if (timings->min_split_time && !level && (timing > timings->min_split_time)) {
|
||||
for (int i = 1; decoder->protocol->databit_len[i] && (i < COUNT_OF(decoder->protocol->databit_len)); ++i) {
|
||||
if (decoder->protocol->databit_len[i] == decoder->databit_cnt) {
|
||||
return IrdaStatusReady;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status = decoder->protocol->decode(decoder, level, timing);
|
||||
furi_assert(status == IrdaStatusError || status == IrdaStatusOk);
|
||||
if (status == IrdaStatusError) {
|
||||
break;
|
||||
}
|
||||
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
|
||||
|
||||
/* check if largest protocol version can be decoded */
|
||||
if (level && (decoder->protocol->databit_len[0] == decoder->databit_cnt)) {
|
||||
status = IrdaStatusReady;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Pulse Distance-Width Modulation */
|
||||
IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder, bool level, uint32_t timing) {
|
||||
furi_assert(decoder);
|
||||
|
||||
IrdaStatus status = IrdaStatusOk;
|
||||
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
|
||||
uint16_t bit1_mark = decoder->protocol->timings.bit1_mark;
|
||||
uint16_t bit1_space = decoder->protocol->timings.bit1_space;
|
||||
uint16_t bit0_mark = decoder->protocol->timings.bit0_mark;
|
||||
uint16_t bit0_space = decoder->protocol->timings.bit0_space;
|
||||
|
||||
while (1) {
|
||||
// Stop bit
|
||||
if ((decoder->databit_cnt == decoder->protocol->databit_len) && (decoder->timings_cnt == 1)) {
|
||||
if (MATCH_TIMING(timings[0], bit1_mark, bit_tolerance)) {
|
||||
decoder->timings_cnt = 0;
|
||||
status = IrdaStatusReady;
|
||||
} else {
|
||||
status = IrdaStatusError;
|
||||
}
|
||||
break;
|
||||
}
|
||||
bool analyze_timing = level ^ (bit1_mark == bit0_mark);
|
||||
uint16_t bit1 = level ? bit1_mark : bit1_space;
|
||||
uint16_t bit0 = level ? bit0_mark : bit0_space;
|
||||
uint16_t no_info_timing = (bit1_mark == bit0_mark) ? bit1_mark : bit1_space;
|
||||
|
||||
if (decoder->timings_cnt >= 2) {
|
||||
if (MATCH_TIMING(timings[0], bit1_mark, bit_tolerance)
|
||||
&& MATCH_TIMING(timings[1], bit1_space, bit_tolerance)) {
|
||||
accumulate_lsb(decoder, 1);
|
||||
} else if (MATCH_TIMING(timings[0], bit0_mark, bit_tolerance)
|
||||
&& MATCH_TIMING(timings[1], bit0_space, bit_tolerance)) {
|
||||
accumulate_lsb(decoder, 0);
|
||||
} else {
|
||||
status = IrdaStatusError;
|
||||
break;
|
||||
}
|
||||
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 2);
|
||||
if (analyze_timing) {
|
||||
if (MATCH_TIMING(timing, bit1, bit_tolerance)) {
|
||||
accumulate_lsb(decoder, 1);
|
||||
} else if (MATCH_TIMING(timing, bit0, bit_tolerance)) {
|
||||
accumulate_lsb(decoder, 0);
|
||||
} else {
|
||||
status = IrdaStatusOk;
|
||||
break;
|
||||
status = IrdaStatusError;
|
||||
}
|
||||
} else {
|
||||
if (!MATCH_TIMING(timing, no_info_timing, bit_tolerance)) {
|
||||
status = IrdaStatusError;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,111 +144,59 @@ IrdaStatus irda_common_decode_pdm(IrdaCommonDecoder* decoder) {
|
||||
}
|
||||
|
||||
/* level switch detection goes in middle of time-quant */
|
||||
IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder) {
|
||||
IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing) {
|
||||
furi_assert(decoder);
|
||||
IrdaStatus status = IrdaStatusOk;
|
||||
uint16_t bit = decoder->protocol->timings.bit1_mark;
|
||||
uint16_t tolerance = decoder->protocol->timings.bit_tolerance;
|
||||
|
||||
while (decoder->timings_cnt) {
|
||||
uint32_t timing = decoder->timings[0];
|
||||
bool* switch_detect = &decoder->switch_detect;
|
||||
furi_assert((*switch_detect == true) || (*switch_detect == false));
|
||||
bool* switch_detect = &decoder->switch_detect;
|
||||
furi_assert((*switch_detect == true) || (*switch_detect == false));
|
||||
|
||||
bool single_timing = MATCH_TIMING(timing, bit, tolerance);
|
||||
bool double_timing = MATCH_TIMING(timing, 2*bit, tolerance);
|
||||
bool single_timing = MATCH_TIMING(timing, bit, tolerance);
|
||||
bool double_timing = MATCH_TIMING(timing, 2*bit, tolerance);
|
||||
|
||||
if(!single_timing && !double_timing) {
|
||||
status = IrdaStatusError;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((decoder->protocol->manchester_start_from_space) && (decoder->databit_cnt == 0)) {
|
||||
*switch_detect = 1; /* fake as we were previously in the middle of time-quant */
|
||||
decoder->data[0] = 0; /* first captured timing should be Mark */
|
||||
++decoder->databit_cnt;
|
||||
}
|
||||
|
||||
if (*switch_detect == 0) {
|
||||
if (double_timing) {
|
||||
status = IrdaStatusError;
|
||||
break;
|
||||
}
|
||||
/* only single timing - level switch required in the middle of time-quant */
|
||||
*switch_detect = 1;
|
||||
} else {
|
||||
/* double timing means we in the middle of time-quant again */
|
||||
if (single_timing)
|
||||
*switch_detect = 0;
|
||||
}
|
||||
|
||||
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
|
||||
status = IrdaStatusOk;
|
||||
bool level = (decoder->level + decoder->timings_cnt) % 2;
|
||||
|
||||
if (decoder->databit_cnt < decoder->protocol->databit_len) {
|
||||
if (*switch_detect) {
|
||||
accumulate_lsb(decoder, level);
|
||||
}
|
||||
if (decoder->databit_cnt == decoder->protocol->databit_len) {
|
||||
if (level) {
|
||||
status = IrdaStatusReady;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
furi_assert(level);
|
||||
/* cover case: sequence should be stopped after last bit was received */
|
||||
if (single_timing) {
|
||||
status = IrdaStatusReady;
|
||||
break;
|
||||
} else {
|
||||
status = IrdaStatusError;
|
||||
}
|
||||
}
|
||||
if(!single_timing && !double_timing) {
|
||||
return IrdaStatusError;
|
||||
}
|
||||
|
||||
return status;
|
||||
if (decoder->protocol->manchester_start_from_space && (decoder->databit_cnt == 0)) {
|
||||
*switch_detect = 1; /* fake as we were previously in the middle of time-quant */
|
||||
accumulate_lsb(decoder, 0);
|
||||
}
|
||||
|
||||
if (*switch_detect == 0) {
|
||||
if (double_timing) {
|
||||
return IrdaStatusError;
|
||||
}
|
||||
/* only single timing - level switch required in the middle of time-quant */
|
||||
*switch_detect = 1;
|
||||
} else {
|
||||
/* double timing means we're in the middle of time-quant again */
|
||||
if (single_timing)
|
||||
*switch_detect = 0;
|
||||
}
|
||||
|
||||
if (*switch_detect) {
|
||||
accumulate_lsb(decoder, level);
|
||||
}
|
||||
|
||||
return IrdaStatusOk;
|
||||
}
|
||||
|
||||
/* Pulse Width Modulation */
|
||||
IrdaStatus irda_common_decode_pwm(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
IrdaMessage* irda_common_decoder_check_ready(IrdaCommonDecoder* decoder) {
|
||||
IrdaMessage* message = NULL;
|
||||
|
||||
uint32_t* timings = decoder->timings;
|
||||
IrdaStatus status = IrdaStatusOk;
|
||||
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
|
||||
uint16_t bit1_mark = decoder->protocol->timings.bit1_mark;
|
||||
uint16_t bit1_space = decoder->protocol->timings.bit1_space;
|
||||
uint16_t bit0_mark = decoder->protocol->timings.bit0_mark;
|
||||
|
||||
while (decoder->timings_cnt) {
|
||||
bool level = (decoder->level + decoder->timings_cnt + 1) % 2;
|
||||
|
||||
if (level) {
|
||||
if (MATCH_TIMING(timings[0], bit1_mark, bit_tolerance)) {
|
||||
accumulate_lsb(decoder, 1);
|
||||
} else if (MATCH_TIMING(timings[0], bit0_mark, bit_tolerance)) {
|
||||
accumulate_lsb(decoder, 0);
|
||||
} else {
|
||||
status = IrdaStatusError;
|
||||
break;
|
||||
}
|
||||
if (decoder->protocol->interpret(decoder)) {
|
||||
decoder->databit_cnt = 0;
|
||||
message = &decoder->message;
|
||||
if (decoder->protocol->decode_repeat) {
|
||||
decoder->state = IrdaCommonDecoderStateProcessRepeat;
|
||||
} else {
|
||||
if (!MATCH_TIMING(timings[0], bit1_space, bit_tolerance)) {
|
||||
status = IrdaStatusError;
|
||||
break;
|
||||
}
|
||||
}
|
||||
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
|
||||
|
||||
if (decoder->databit_cnt == decoder->protocol->databit_len) {
|
||||
status = IrdaStatusReady;
|
||||
break;
|
||||
decoder->state = IrdaCommonDecoderStateWaitPreamble;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
return message;
|
||||
}
|
||||
|
||||
IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t duration) {
|
||||
@@ -245,12 +225,13 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t
|
||||
}
|
||||
break;
|
||||
case IrdaCommonDecoderStateDecode:
|
||||
status = decoder->protocol->decode(decoder);
|
||||
status = irda_common_decode_bits(decoder);
|
||||
if (status == IrdaStatusReady) {
|
||||
if (decoder->protocol->interpret(decoder)) {
|
||||
message = &decoder->message;
|
||||
decoder->state = IrdaCommonDecoderStateProcessRepeat;
|
||||
} else {
|
||||
message = irda_common_decoder_check_ready(decoder);
|
||||
if (message) {
|
||||
continue;
|
||||
} else if (decoder->protocol->databit_len[0] == decoder->databit_cnt) {
|
||||
/* error: can't decode largest protocol - begin decoding from start */
|
||||
decoder->state = IrdaCommonDecoderStateWaitPreamble;
|
||||
}
|
||||
} else if (status == IrdaStatusError) {
|
||||
@@ -259,10 +240,6 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t
|
||||
}
|
||||
break;
|
||||
case IrdaCommonDecoderStateProcessRepeat:
|
||||
if (!decoder->protocol->decode_repeat) {
|
||||
decoder->state = IrdaCommonDecoderStateWaitPreamble;
|
||||
continue;
|
||||
}
|
||||
status = decoder->protocol->decode_repeat(decoder);
|
||||
if (status == IrdaStatusError) {
|
||||
irda_common_decoder_reset_state(decoder);
|
||||
@@ -282,9 +259,14 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t
|
||||
void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec* protocol) {
|
||||
furi_assert(protocol);
|
||||
|
||||
/* protocol->databit_len[0] has to contain biggest value of bits that can be decoded */
|
||||
for (int i = 1; i < COUNT_OF(protocol->databit_len); ++i) {
|
||||
furi_assert(protocol->databit_len[i] <= protocol->databit_len[0]);
|
||||
}
|
||||
|
||||
uint32_t alloc_size = sizeof(IrdaCommonDecoder)
|
||||
+ protocol->databit_len / 8
|
||||
+ !!(protocol->databit_len % 8);
|
||||
+ protocol->databit_len[0] / 8
|
||||
+ !!(protocol->databit_len[0] % 8);
|
||||
IrdaCommonDecoder* decoder = furi_alloc(alloc_size);
|
||||
memset(decoder, 0, alloc_size);
|
||||
decoder->protocol = protocol;
|
||||
|
@@ -4,6 +4,19 @@
|
||||
#include <stdbool.h>
|
||||
#include <furi.h>
|
||||
#include "irda_i.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static IrdaStatus irda_common_encode_bits(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
IrdaStatus status = encoder->protocol->encode(encoder, duration, level);
|
||||
furi_assert(status == IrdaStatusOk);
|
||||
++encoder->timings_encoded;
|
||||
encoder->timings_sum += *duration;
|
||||
if ((encoder->bits_encoded == encoder->bits_to_encode) && *level) {
|
||||
status = IrdaStatusDone;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -32,14 +45,12 @@ IrdaStatus irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* d
|
||||
|
||||
*level = even_timing ^ logic_value;
|
||||
*duration = timings->bit1_mark;
|
||||
if (even_timing) /* start encoding from space */
|
||||
if (even_timing)
|
||||
++encoder->bits_encoded;
|
||||
++encoder->timings_encoded;
|
||||
encoder->timings_sum += *duration;
|
||||
else if (*level && (encoder->bits_encoded + 1 == encoder->bits_to_encode))
|
||||
++encoder->bits_encoded; /* don't encode last space */
|
||||
|
||||
bool finish = (encoder->bits_encoded == encoder->protocol->databit_len);
|
||||
finish |= (encoder->bits_encoded == (encoder->protocol->databit_len-1)) && *level && !even_timing;
|
||||
return finish ? IrdaStatusDone : IrdaStatusOk;
|
||||
return IrdaStatusOk;
|
||||
}
|
||||
|
||||
IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
@@ -47,39 +58,25 @@ IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duratio
|
||||
furi_assert(duration);
|
||||
furi_assert(level);
|
||||
|
||||
bool done = false;
|
||||
const IrdaTimings* timings = &encoder->protocol->timings;
|
||||
uint8_t index = encoder->bits_encoded / 8;
|
||||
uint8_t shift = encoder->bits_encoded % 8; // LSB first
|
||||
bool logic_value = !!(encoder->data[index] & (0x01 << shift));
|
||||
|
||||
// stop bit
|
||||
if (encoder->bits_encoded == encoder->protocol->databit_len) {
|
||||
furi_assert(!encoder->protocol->no_stop_bit);
|
||||
*duration = timings->bit1_mark;
|
||||
*level = true;
|
||||
++encoder->timings_encoded;
|
||||
encoder->timings_sum += *duration;
|
||||
return IrdaStatusDone;
|
||||
}
|
||||
bool pwm = timings->bit1_space == timings->bit0_space;
|
||||
|
||||
if (encoder->timings_encoded % 2) { /* start encoding from space */
|
||||
*duration = logic_value ? timings->bit1_mark : timings->bit0_mark;
|
||||
*level = true;
|
||||
if (pwm)
|
||||
++encoder->bits_encoded;
|
||||
} else {
|
||||
*duration = logic_value ? timings->bit1_space : timings->bit0_space;
|
||||
*level = false;
|
||||
++encoder->bits_encoded;
|
||||
if (!pwm)
|
||||
++encoder->bits_encoded;
|
||||
}
|
||||
|
||||
if ((encoder->bits_encoded == encoder->protocol->databit_len)
|
||||
&& encoder->protocol->no_stop_bit) {
|
||||
done = true;
|
||||
}
|
||||
|
||||
++encoder->timings_encoded;
|
||||
encoder->timings_sum += *duration;
|
||||
return done ? IrdaStatusDone : IrdaStatusOk;
|
||||
return IrdaStatusOk;
|
||||
}
|
||||
|
||||
IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
@@ -116,7 +113,7 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case IrdaCommonEncoderStateEncode:
|
||||
status = encoder->protocol->encode(encoder, duration, level);
|
||||
status = irda_common_encode_bits(encoder, duration, level);
|
||||
if (status == IrdaStatusDone) {
|
||||
if (encoder->protocol->encode_repeat) {
|
||||
encoder->state = IrdaCommonEncoderStateEncodeRepeat;
|
||||
@@ -138,10 +135,18 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
|
||||
|
||||
void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol) {
|
||||
furi_assert(protocol);
|
||||
if (protocol->decode == irda_common_decode_pdwm) {
|
||||
furi_assert((protocol->timings.bit1_mark == protocol->timings.bit0_mark) ^ (protocol->timings.bit1_space == protocol->timings.bit0_space));
|
||||
}
|
||||
|
||||
uint32_t alloc_size = sizeof(IrdaCommonEncoder)
|
||||
+ protocol->databit_len / 8
|
||||
+ !!(protocol->databit_len % 8);
|
||||
/* protocol->databit_len[0] has to contain biggest value of bits that can be decoded */
|
||||
for (int i = 1; i < COUNT_OF(protocol->databit_len); ++i) {
|
||||
furi_assert(protocol->databit_len[i] <= protocol->databit_len[0]);
|
||||
}
|
||||
|
||||
uint32_t alloc_size = sizeof(IrdaCommonDecoder)
|
||||
+ protocol->databit_len[0] / 8
|
||||
+ !!(protocol->databit_len[0] % 8);
|
||||
IrdaCommonEncoder* encoder = furi_alloc(alloc_size);
|
||||
memset(encoder, 0, alloc_size);
|
||||
encoder->protocol = protocol;
|
||||
@@ -162,8 +167,14 @@ void irda_common_encoder_reset(IrdaCommonEncoder* encoder) {
|
||||
encoder->state = IrdaCommonEncoderStateSilence;
|
||||
encoder->switch_detect = 0;
|
||||
|
||||
uint8_t bytes_to_clear = encoder->protocol->databit_len / 8
|
||||
+ !!(encoder->protocol->databit_len % 8);
|
||||
uint8_t max_databit_len = 0;
|
||||
|
||||
for (int i = 0; i < COUNT_OF(encoder->protocol->databit_len); ++i) {
|
||||
max_databit_len = MAX(max_databit_len, encoder->protocol->databit_len[i]);
|
||||
}
|
||||
|
||||
uint8_t bytes_to_clear = max_databit_len / 8
|
||||
+ !!(max_databit_len % 8);
|
||||
memset(encoder->data, 0, bytes_to_clear);
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,8 @@
|
||||
typedef struct IrdaCommonDecoder IrdaCommonDecoder;
|
||||
typedef struct IrdaCommonEncoder IrdaCommonEncoder;
|
||||
|
||||
typedef IrdaStatus (*IrdaCommonDecode)(IrdaCommonDecoder*);
|
||||
typedef IrdaStatus (*IrdaCommonDecode)(IrdaCommonDecoder*, bool, uint32_t);
|
||||
typedef IrdaStatus (*IrdaCommonDecodeRepeat)(IrdaCommonDecoder*);
|
||||
typedef bool (*IrdaCommonInterpret)(IrdaCommonDecoder*);
|
||||
typedef IrdaStatus (*IrdaCommonEncode)(IrdaCommonEncoder* encoder, uint32_t* out, bool* polarity);
|
||||
|
||||
@@ -19,9 +20,9 @@ typedef struct {
|
||||
IrdaTimings timings;
|
||||
bool manchester_start_from_space;
|
||||
bool no_stop_bit;
|
||||
uint32_t databit_len;
|
||||
uint8_t databit_len[4];
|
||||
IrdaCommonDecode decode;
|
||||
IrdaCommonDecode decode_repeat;
|
||||
IrdaCommonDecodeRepeat decode_repeat;
|
||||
IrdaCommonInterpret interpret;
|
||||
IrdaCommonEncode encode;
|
||||
IrdaCommonEncode encode_repeat;
|
||||
@@ -57,7 +58,8 @@ struct IrdaCommonEncoder {
|
||||
const IrdaCommonProtocolSpec* protocol;
|
||||
IrdaCommonStateEncoder state;
|
||||
bool switch_detect;
|
||||
uint32_t bits_encoded;
|
||||
uint8_t bits_to_encode;
|
||||
uint8_t bits_encoded;
|
||||
uint32_t timings_sum;
|
||||
uint32_t timings_encoded;
|
||||
void* context;
|
||||
@@ -65,12 +67,12 @@ struct IrdaCommonEncoder {
|
||||
};
|
||||
|
||||
IrdaMessage* irda_common_decode(IrdaCommonDecoder *decoder, bool level, uint32_t duration);
|
||||
IrdaStatus irda_common_decode_pdm(IrdaCommonDecoder* decoder);
|
||||
IrdaStatus irda_common_decode_pwm(IrdaCommonDecoder* decoder);
|
||||
IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder);
|
||||
IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder, bool level, uint32_t timing);
|
||||
IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing);
|
||||
void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec *protocol);
|
||||
void irda_common_decoder_free(IrdaCommonDecoder* decoder);
|
||||
void irda_common_decoder_reset(IrdaCommonDecoder* decoder);
|
||||
IrdaMessage* irda_common_decoder_check_ready(IrdaCommonDecoder* decoder);
|
||||
|
||||
IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
|
||||
IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
|
||||
|
@@ -12,10 +12,12 @@ const IrdaCommonProtocolSpec protocol_nec = {
|
||||
.preamble_tolerance = IRDA_NEC_PREAMBLE_TOLERANCE,
|
||||
.bit_tolerance = IRDA_NEC_BIT_TOLERANCE,
|
||||
.silence_time = IRDA_NEC_SILENCE,
|
||||
.min_split_time = IRDA_NEC_MIN_SPLIT_TIME,
|
||||
},
|
||||
.databit_len = 32,
|
||||
.databit_len[0] = 42,
|
||||
.databit_len[1] = 32,
|
||||
.no_stop_bit = false,
|
||||
.decode = irda_common_decode_pdm,
|
||||
.decode = irda_common_decode_pdwm,
|
||||
.encode = irda_common_encode_pdwm,
|
||||
.interpret = irda_decoder_nec_interpret,
|
||||
.decode_repeat = irda_decoder_nec_decode_repeat,
|
||||
@@ -34,9 +36,9 @@ const IrdaCommonProtocolSpec protocol_samsung32 = {
|
||||
.bit_tolerance = IRDA_SAMSUNG_BIT_TOLERANCE,
|
||||
.silence_time = IRDA_SAMSUNG_SILENCE,
|
||||
},
|
||||
.databit_len = 32,
|
||||
.databit_len[0] = 32,
|
||||
.no_stop_bit = false,
|
||||
.decode = irda_common_decode_pdm,
|
||||
.decode = irda_common_decode_pdwm,
|
||||
.encode = irda_common_encode_pdwm,
|
||||
.interpret = irda_decoder_samsung32_interpret,
|
||||
.decode_repeat = irda_decoder_samsung32_decode_repeat,
|
||||
@@ -52,7 +54,7 @@ const IrdaCommonProtocolSpec protocol_rc6 = {
|
||||
.bit_tolerance = IRDA_RC6_BIT_TOLERANCE,
|
||||
.silence_time = IRDA_RC6_SILENCE,
|
||||
},
|
||||
.databit_len = 1 + 3 + 1 + 8 + 8, // start_bit + 3 mode bits, + 1 toggle bit (x2 timing) + 8 address + 8 command
|
||||
.databit_len[0] = 1 + 3 + 1 + 8 + 8, // start_bit + 3 mode bits, + 1 toggle bit (x2 timing) + 8 address + 8 command
|
||||
.manchester_start_from_space = false,
|
||||
.decode = irda_decoder_rc6_decode_manchester,
|
||||
.encode = irda_encoder_rc6_encode_manchester,
|
||||
@@ -70,7 +72,7 @@ const IrdaCommonProtocolSpec protocol_rc5 = {
|
||||
.bit_tolerance = IRDA_RC5_BIT_TOLERANCE,
|
||||
.silence_time = IRDA_RC5_SILENCE,
|
||||
},
|
||||
.databit_len = 1 + 1 + 1 + 5 + 6, // start_bit + start_bit/command_bit + toggle_bit + 5 address + 6 command
|
||||
.databit_len[0] = 1 + 1 + 1 + 5 + 6, // start_bit + start_bit/command_bit + toggle_bit + 5 address + 6 command
|
||||
.manchester_start_from_space = true,
|
||||
.decode = irda_common_decode_manchester,
|
||||
.encode = irda_common_encode_manchester,
|
||||
@@ -90,10 +92,13 @@ const IrdaCommonProtocolSpec protocol_sirc = {
|
||||
.preamble_tolerance = IRDA_SIRC_PREAMBLE_TOLERANCE,
|
||||
.bit_tolerance = IRDA_SIRC_BIT_TOLERANCE,
|
||||
.silence_time = IRDA_SIRC_SILENCE,
|
||||
.min_split_time = IRDA_SIRC_MIN_SPLIT_TIME,
|
||||
},
|
||||
.databit_len = 20, /* 12/15/20 */
|
||||
.databit_len[0] = 20,
|
||||
.databit_len[1] = 15,
|
||||
.databit_len[2] = 12,
|
||||
.no_stop_bit = true,
|
||||
.decode = irda_common_decode_pwm,
|
||||
.decode = irda_common_decode_pdwm,
|
||||
.encode = irda_common_encode_pdwm,
|
||||
.interpret = irda_decoder_sirc_interpret,
|
||||
.decode_repeat = NULL,
|
||||
|
Reference in New Issue
Block a user