Naming and coding style convention, new linter tool. (#945)

* Makefile, Scripts: new linter
* About: remove ID from IC
* Firmware: remove double define for DIVC/DIVR
* Scripts: check folder names too. Docker: replace syntax check with make lint.
* Reformat Sources and Migrate to new file naming convention
* Docker: symlink clang-format-12 to clang-format
* Add coding style guide
This commit is contained in:
あく
2022-01-05 19:10:18 +03:00
committed by GitHub
parent c98e54da10
commit 389ff92cc1
899 changed files with 379245 additions and 373421 deletions

View File

@@ -12,23 +12,21 @@ static void irda_common_decoder_reset_state(IrdaCommonDecoder* decoder);
static inline size_t consume_samples(uint32_t* array, size_t len, size_t shift) {
furi_assert(len >= shift);
len -= shift;
for (int i = 0; i < len; ++i)
array[i] = array[i + shift];
for(int i = 0; i < len; ++i) array[i] = array[i + shift];
return len;
}
static inline void accumulate_lsb(IrdaCommonDecoder* decoder, bool bit) {
uint16_t index = decoder->databit_cnt / 8;
uint8_t shift = decoder->databit_cnt % 8; // LSB first
uint8_t shift = decoder->databit_cnt % 8; // LSB first
if (!shift)
decoder->data[index] = 0;
if(!shift) decoder->data[index] = 0;
if (bit) {
decoder->data[index] |= (0x1 << shift); // add 1
if(bit) {
decoder->data[index] |= (0x1 << shift); // add 1
} else {
(void) decoder->data[index]; // add 0
(void)decoder->data[index]; // add 0
}
++decoder->databit_cnt;
@@ -40,25 +38,24 @@ 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;
if(decoder->timings_cnt == 0) return false;
// align to start at Mark timing
if (!start_level) {
if(!start_level) {
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
}
if (decoder->protocol->timings.preamble_mark == 0) {
if(decoder->protocol->timings.preamble_mark == 0) {
return true;
}
while ((!result) && (decoder->timings_cnt >= 2)) {
while((!result) && (decoder->timings_cnt >= 2)) {
float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
uint16_t preamble_mark = decoder->protocol->timings.preamble_mark;
uint16_t preamble_space = decoder->protocol->timings.preamble_space;
if ((MATCH_TIMING(decoder->timings[0], preamble_mark, preamble_tolerance))
&& (MATCH_TIMING(decoder->timings[1], preamble_space, preamble_tolerance))) {
if((MATCH_TIMING(decoder->timings[0], preamble_mark, preamble_tolerance)) &&
(MATCH_TIMING(decoder->timings[1], preamble_space, preamble_tolerance))) {
result = true;
}
@@ -68,7 +65,6 @@ static bool irda_check_preamble(IrdaCommonDecoder* decoder) {
return result;
}
/**
* 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
@@ -80,19 +76,21 @@ static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) {
IrdaStatus status = IrdaStatusOk;
const IrdaTimings* timings = &decoder->protocol->timings;
while (decoder->timings_cnt && (status == IrdaStatusOk)) {
while(decoder->timings_cnt && (status == IrdaStatusOk)) {
bool level = (decoder->level + decoder->timings_cnt + 1) % 2;
uint32_t timing = decoder->timings[0];
if (timings->min_split_time && !level) {
if (timing > timings->min_split_time) {
if(timings->min_split_time && !level) {
if(timing > timings->min_split_time) {
/* long low timing - check if we're ready for any of protocol modification */
for (int i = 0; decoder->protocol->databit_len[i] && (i < COUNT_OF(decoder->protocol->databit_len)); ++i) {
if (decoder->protocol->databit_len[i] == decoder->databit_cnt) {
for(int i = 0; decoder->protocol->databit_len[i] &&
(i < COUNT_OF(decoder->protocol->databit_len));
++i) {
if(decoder->protocol->databit_len[i] == decoder->databit_cnt) {
return IrdaStatusReady;
}
}
} else if (decoder->protocol->databit_len[0] == decoder->databit_cnt) {
} else if(decoder->protocol->databit_len[0] == decoder->databit_cnt) {
/* short low timing for longest protocol - this is signal is longer than we expected */
return IrdaStatusError;
}
@@ -101,13 +99,14 @@ static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) {
status = decoder->protocol->decode(decoder, level, timing);
furi_check(decoder->databit_cnt <= decoder->protocol->databit_len[0]);
furi_assert(status == IrdaStatusError || status == IrdaStatusOk);
if (status == IrdaStatusError) {
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) && !timings->min_split_time) {
if(level && (decoder->protocol->databit_len[0] == decoder->databit_cnt) &&
!timings->min_split_time) {
status = IrdaStatusReady;
break;
}
@@ -132,16 +131,16 @@ IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder, bool level, uint3
uint16_t bit0 = level ? bit0_mark : bit0_space;
uint16_t no_info_timing = (bit1_mark == bit0_mark) ? bit1_mark : bit1_space;
if (analyze_timing) {
if (MATCH_TIMING(timing, bit1, bit_tolerance)) {
if(analyze_timing) {
if(MATCH_TIMING(timing, bit1, bit_tolerance)) {
accumulate_lsb(decoder, 1);
} else if (MATCH_TIMING(timing, bit0, bit_tolerance)) {
} else if(MATCH_TIMING(timing, bit0, bit_tolerance)) {
accumulate_lsb(decoder, 0);
} else {
status = IrdaStatusError;
}
} else {
if (!MATCH_TIMING(timing, no_info_timing, bit_tolerance)) {
if(!MATCH_TIMING(timing, no_info_timing, bit_tolerance)) {
status = IrdaStatusError;
}
}
@@ -159,31 +158,30 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level,
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 double_timing = MATCH_TIMING(timing, 2 * bit, tolerance);
if(!single_timing && !double_timing) {
return IrdaStatusError;
}
if (decoder->protocol->manchester_start_from_space && (decoder->databit_cnt == 0)) {
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) {
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(single_timing) *switch_detect = 0;
}
if (*switch_detect) {
if (decoder->protocol->databit_len[0] == decoder->databit_cnt) {
if(*switch_detect) {
if(decoder->protocol->databit_len[0] == decoder->databit_cnt) {
return IrdaStatusError;
}
accumulate_lsb(decoder, level);
@@ -196,17 +194,19 @@ IrdaMessage* irda_common_decoder_check_ready(IrdaCommonDecoder* decoder) {
IrdaMessage* message = NULL;
bool found_length = false;
for (int i = 0; decoder->protocol->databit_len[i] && (i < COUNT_OF(decoder->protocol->databit_len)); ++i) {
if (decoder->protocol->databit_len[i] == decoder->databit_cnt) {
for(int i = 0;
decoder->protocol->databit_len[i] && (i < COUNT_OF(decoder->protocol->databit_len));
++i) {
if(decoder->protocol->databit_len[i] == decoder->databit_cnt) {
found_length = true;
break;
}
}
if (found_length && decoder->protocol->interpret(decoder)) {
if(found_length && decoder->protocol->interpret(decoder)) {
decoder->databit_cnt = 0;
message = &decoder->message;
if (decoder->protocol->decode_repeat) {
if(decoder->protocol->decode_repeat) {
decoder->state = IrdaCommonDecoderStateProcessRepeat;
} else {
decoder->state = IrdaCommonDecoderStateWaitPreamble;
@@ -222,19 +222,19 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t
IrdaMessage* message = 0;
IrdaStatus status = IrdaStatusError;
if (decoder->level == level) {
if(decoder->level == level) {
irda_common_decoder_reset(decoder);
}
decoder->level = level; // start with low level (Space timing)
decoder->level = level; // start with low level (Space timing)
decoder->timings[decoder->timings_cnt] = duration;
decoder->timings_cnt++;
furi_check(decoder->timings_cnt <= sizeof(decoder->timings));
while(1) {
switch (decoder->state) {
switch(decoder->state) {
case IrdaCommonDecoderStateWaitPreamble:
if (irda_check_preamble(decoder)) {
if(irda_check_preamble(decoder)) {
decoder->state = IrdaCommonDecoderStateDecode;
decoder->databit_cnt = 0;
decoder->switch_detect = false;
@@ -243,25 +243,25 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t
break;
case IrdaCommonDecoderStateDecode:
status = irda_common_decode_bits(decoder);
if (status == IrdaStatusReady) {
if(status == IrdaStatusReady) {
message = irda_common_decoder_check_ready(decoder);
if (message) {
if(message) {
continue;
} else if (decoder->protocol->databit_len[0] == decoder->databit_cnt) {
} 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) {
} else if(status == IrdaStatusError) {
irda_common_decoder_reset_state(decoder);
continue;
}
break;
case IrdaCommonDecoderStateProcessRepeat:
status = decoder->protocol->decode_repeat(decoder);
if (status == IrdaStatusError) {
if(status == IrdaStatusError) {
irda_common_decoder_reset_state(decoder);
continue;
} else if (status == IrdaStatusReady) {
} else if(status == IrdaStatusReady) {
decoder->message.repeat = true;
message = &decoder->message;
}
@@ -277,13 +277,12 @@ 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) {
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);
uint32_t alloc_size = sizeof(IrdaCommonDecoder) + protocol->databit_len[0] / 8 +
!!(protocol->databit_len[0] % 8);
IrdaCommonDecoder* decoder = furi_alloc(alloc_size);
decoder->protocol = protocol;
decoder->level = true;
@@ -300,8 +299,8 @@ void irda_common_decoder_reset_state(IrdaCommonDecoder* decoder) {
decoder->databit_cnt = 0;
decoder->switch_detect = false;
decoder->message.protocol = IrdaProtocolUnknown;
if (decoder->protocol->timings.preamble_mark == 0) {
if (decoder->timings_cnt > 0) {
if(decoder->protocol->timings.preamble_mark == 0) {
if(decoder->timings_cnt > 0) {
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
}
}
@@ -313,4 +312,3 @@ void irda_common_decoder_reset(IrdaCommonDecoder* decoder) {
irda_common_decoder_reset_state(decoder);
decoder->timings_cnt = 0;
}

View File

@@ -6,12 +6,13 @@
#include "irda_i.h"
#include <stdint.h>
static IrdaStatus irda_common_encode_bits(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
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) {
if((encoder->bits_encoded == encoder->bits_to_encode) && *level) {
status = IrdaStatusDone;
}
@@ -32,23 +33,24 @@ static IrdaStatus irda_common_encode_bits(IrdaCommonEncoder* encoder, uint32_t*
* 0 1 2 | 3 4 |
* _____-------_____---___
*/
IrdaStatus irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
IrdaStatus
irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
furi_assert(encoder);
furi_assert(duration);
furi_assert(level);
const IrdaTimings* timings = &encoder->protocol->timings;
uint8_t index = encoder->bits_encoded / 8;
uint8_t shift = encoder->bits_encoded % 8; // LSB first
uint8_t shift = encoder->bits_encoded % 8; // LSB first
bool logic_value = !!(encoder->data[index] & (0x01 << shift));
bool even_timing = !(encoder->timings_encoded % 2);
*level = even_timing ^ logic_value;
*duration = timings->bit1_mark;
if (even_timing)
if(even_timing)
++encoder->bits_encoded;
else if (*level && (encoder->bits_encoded + 1 == encoder->bits_to_encode))
++encoder->bits_encoded; /* don't encode last space */
else if(*level && (encoder->bits_encoded + 1 == encoder->bits_to_encode))
++encoder->bits_encoded; /* don't encode last space */
return IrdaStatusOk;
}
@@ -60,20 +62,18 @@ IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duratio
const IrdaTimings* timings = &encoder->protocol->timings;
uint8_t index = encoder->bits_encoded / 8;
uint8_t shift = encoder->bits_encoded % 8; // LSB first
uint8_t shift = encoder->bits_encoded % 8; // LSB first
bool logic_value = !!(encoder->data[index] & (0x01 << shift));
bool pwm = timings->bit1_space == timings->bit0_space;
if (encoder->timings_encoded % 2) { /* start encoding from 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;
if(pwm) ++encoder->bits_encoded;
} else {
*duration = logic_value ? timings->bit1_space : timings->bit0_space;
*level = false;
if (!pwm)
++encoder->bits_encoded;
if(!pwm) ++encoder->bits_encoded;
}
return IrdaStatusOk;
@@ -86,7 +86,7 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
IrdaStatus status = IrdaStatusOk;
const IrdaTimings* timings = &encoder->protocol->timings;
switch (encoder->state) {
switch(encoder->state) {
case IrdaCommonEncoderStateSilence:
*duration = encoder->protocol->timings.silence_time;
*level = false;
@@ -96,8 +96,8 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
encoder->timings_sum = 0;
break;
case IrdaCommonEncoderStatePreamble:
if (timings->preamble_mark) {
if (encoder->timings_encoded == 1) {
if(timings->preamble_mark) {
if(encoder->timings_encoded == 1) {
*duration = timings->preamble_mark;
*level = true;
} else {
@@ -114,8 +114,8 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
/* FALLTHROUGH */
case IrdaCommonEncoderStateEncode:
status = irda_common_encode_bits(encoder, duration, level);
if (status == IrdaStatusDone) {
if (encoder->protocol->encode_repeat) {
if(status == IrdaStatusDone) {
if(encoder->protocol->encode_repeat) {
encoder->state = IrdaCommonEncoderStateEncodeRepeat;
} else {
encoder->timings_encoded = 0;
@@ -135,18 +135,19 @@ 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));
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));
}
/* 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) {
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);
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;
@@ -169,12 +170,10 @@ void irda_common_encoder_reset(IrdaCommonEncoder* encoder) {
uint8_t max_databit_len = 0;
for (int i = 0; i < COUNT_OF(encoder->protocol->databit_len); ++i) {
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);
uint8_t bytes_to_clear = max_databit_len / 8 + !!(max_databit_len % 8);
memset(encoder->data, 0, bytes_to_clear);
}

View File

@@ -4,9 +4,7 @@
#include "irda.h"
#include "irda_i.h"
#define MATCH_TIMING(x, v, delta) ( ((x) < (v + delta)) \
&& ((x) > (v - delta)))
#define MATCH_TIMING(x, v, delta) (((x) < (v + delta)) && ((x) > (v - delta)))
typedef struct IrdaCommonDecoder IrdaCommonDecoder;
typedef struct IrdaCommonEncoder IrdaCommonEncoder;
@@ -18,9 +16,9 @@ typedef IrdaStatus (*IrdaCommonEncode)(IrdaCommonEncoder* encoder, uint32_t* out
typedef struct {
IrdaTimings timings;
bool manchester_start_from_space;
bool no_stop_bit;
uint8_t databit_len[4];
bool manchester_start_from_space;
bool no_stop_bit;
uint8_t databit_len[4];
IrdaCommonDecode decode;
IrdaCommonDecodeRepeat decode_repeat;
IrdaCommonInterpret interpret;
@@ -66,18 +64,18 @@ struct IrdaCommonEncoder {
uint8_t data[];
};
IrdaMessage* irda_common_decode(IrdaCommonDecoder *decoder, bool level, uint32_t duration);
IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t duration);
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_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);
IrdaStatus irda_common_encode_manchester(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);

View File

@@ -2,18 +2,19 @@
#include "irda_protocol_defs_i.h"
const IrdaCommonProtocolSpec protocol_nec = {
.timings = {
.preamble_mark = IRDA_NEC_PREAMBLE_MARK,
.preamble_space = IRDA_NEC_PREAMBLE_SPACE,
.bit1_mark = IRDA_NEC_BIT1_MARK,
.bit1_space = IRDA_NEC_BIT1_SPACE,
.bit0_mark = IRDA_NEC_BIT0_MARK,
.bit0_space = IRDA_NEC_BIT0_SPACE,
.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,
},
.timings =
{
.preamble_mark = IRDA_NEC_PREAMBLE_MARK,
.preamble_space = IRDA_NEC_PREAMBLE_SPACE,
.bit1_mark = IRDA_NEC_BIT1_MARK,
.bit1_space = IRDA_NEC_BIT1_SPACE,
.bit0_mark = IRDA_NEC_BIT0_MARK,
.bit0_space = IRDA_NEC_BIT0_SPACE,
.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[0] = 42,
.databit_len[1] = 32,
.no_stop_bit = false,
@@ -25,18 +26,19 @@ const IrdaCommonProtocolSpec protocol_nec = {
};
const IrdaCommonProtocolSpec protocol_samsung32 = {
.timings = {
.preamble_mark = IRDA_SAMSUNG_PREAMBLE_MARK,
.preamble_space = IRDA_SAMSUNG_PREAMBLE_SPACE,
.bit1_mark = IRDA_SAMSUNG_BIT1_MARK,
.bit1_space = IRDA_SAMSUNG_BIT1_SPACE,
.bit0_mark = IRDA_SAMSUNG_BIT0_MARK,
.bit0_space = IRDA_SAMSUNG_BIT0_SPACE,
.preamble_tolerance = IRDA_SAMSUNG_PREAMBLE_TOLERANCE,
.bit_tolerance = IRDA_SAMSUNG_BIT_TOLERANCE,
.silence_time = IRDA_SAMSUNG_SILENCE,
.min_split_time = IRDA_SAMSUNG_MIN_SPLIT_TIME,
},
.timings =
{
.preamble_mark = IRDA_SAMSUNG_PREAMBLE_MARK,
.preamble_space = IRDA_SAMSUNG_PREAMBLE_SPACE,
.bit1_mark = IRDA_SAMSUNG_BIT1_MARK,
.bit1_space = IRDA_SAMSUNG_BIT1_SPACE,
.bit0_mark = IRDA_SAMSUNG_BIT0_MARK,
.bit0_space = IRDA_SAMSUNG_BIT0_SPACE,
.preamble_tolerance = IRDA_SAMSUNG_PREAMBLE_TOLERANCE,
.bit_tolerance = IRDA_SAMSUNG_BIT_TOLERANCE,
.silence_time = IRDA_SAMSUNG_SILENCE,
.min_split_time = IRDA_SAMSUNG_MIN_SPLIT_TIME,
},
.databit_len[0] = 32,
.no_stop_bit = false,
.decode = irda_common_decode_pdwm,
@@ -47,16 +49,19 @@ const IrdaCommonProtocolSpec protocol_samsung32 = {
};
const IrdaCommonProtocolSpec protocol_rc6 = {
.timings = {
.preamble_mark = IRDA_RC6_PREAMBLE_MARK,
.preamble_space = IRDA_RC6_PREAMBLE_SPACE,
.bit1_mark = IRDA_RC6_BIT,
.preamble_tolerance = IRDA_RC6_PREAMBLE_TOLERANCE,
.bit_tolerance = IRDA_RC6_BIT_TOLERANCE,
.silence_time = IRDA_RC6_SILENCE,
.min_split_time = IRDA_RC6_MIN_SPLIT_TIME,
},
.databit_len[0] = 1 + 3 + 1 + 8 + 8, // start_bit + 3 mode bits, + 1 toggle bit (x2 timing) + 8 address + 8 command
.timings =
{
.preamble_mark = IRDA_RC6_PREAMBLE_MARK,
.preamble_space = IRDA_RC6_PREAMBLE_SPACE,
.bit1_mark = IRDA_RC6_BIT,
.preamble_tolerance = IRDA_RC6_PREAMBLE_TOLERANCE,
.bit_tolerance = IRDA_RC6_BIT_TOLERANCE,
.silence_time = IRDA_RC6_SILENCE,
.min_split_time = IRDA_RC6_MIN_SPLIT_TIME,
},
.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,
@@ -66,16 +71,18 @@ const IrdaCommonProtocolSpec protocol_rc6 = {
};
const IrdaCommonProtocolSpec protocol_rc5 = {
.timings = {
.preamble_mark = 0,
.preamble_space = 0,
.bit1_mark = IRDA_RC5_BIT,
.preamble_tolerance = 0,
.bit_tolerance = IRDA_RC5_BIT_TOLERANCE,
.silence_time = IRDA_RC5_SILENCE,
.min_split_time = IRDA_RC5_MIN_SPLIT_TIME,
},
.databit_len[0] = 1 + 1 + 1 + 5 + 6, // start_bit + start_bit/command_bit + toggle_bit + 5 address + 6 command
.timings =
{
.preamble_mark = 0,
.preamble_space = 0,
.bit1_mark = IRDA_RC5_BIT,
.preamble_tolerance = 0,
.bit_tolerance = IRDA_RC5_BIT_TOLERANCE,
.silence_time = IRDA_RC5_SILENCE,
.min_split_time = IRDA_RC5_MIN_SPLIT_TIME,
},
.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,
@@ -85,18 +92,19 @@ const IrdaCommonProtocolSpec protocol_rc5 = {
};
const IrdaCommonProtocolSpec protocol_sirc = {
.timings = {
.preamble_mark = IRDA_SIRC_PREAMBLE_MARK,
.preamble_space = IRDA_SIRC_PREAMBLE_SPACE,
.bit1_mark = IRDA_SIRC_BIT1_MARK,
.bit1_space = IRDA_SIRC_BIT1_SPACE,
.bit0_mark = IRDA_SIRC_BIT0_MARK,
.bit0_space = IRDA_SIRC_BIT0_SPACE,
.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,
},
.timings =
{
.preamble_mark = IRDA_SIRC_PREAMBLE_MARK,
.preamble_space = IRDA_SIRC_PREAMBLE_SPACE,
.bit1_mark = IRDA_SIRC_BIT1_MARK,
.bit1_space = IRDA_SIRC_BIT1_SPACE,
.bit0_mark = IRDA_SIRC_BIT0_MARK,
.bit0_space = IRDA_SIRC_BIT0_SPACE,
.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[0] = 20,
.databit_len[1] = 15,
.databit_len[2] = 12,
@@ -107,4 +115,3 @@ const IrdaCommonProtocolSpec protocol_sirc = {
.decode_repeat = NULL,
.encode_repeat = irda_encoder_sirc_encode_repeat,
};

View File

@@ -7,7 +7,7 @@
#include <stdlib.h>
#include <furi.h>
#include "irda_i.h"
#include <furi-hal-irda.h>
#include <furi_hal_irda.h>
typedef struct {
IrdaAlloc alloc;
@@ -41,78 +41,77 @@ typedef struct {
static const IrdaEncoderDecoder irda_encoder_decoder[] = {
{
.decoder = {
.alloc = irda_decoder_nec_alloc,
.decode = irda_decoder_nec_decode,
.reset = irda_decoder_nec_reset,
.check_ready = irda_decoder_nec_check_ready,
.free = irda_decoder_nec_free},
.encoder = {
.alloc = irda_encoder_nec_alloc,
.encode = irda_encoder_nec_encode,
.reset = irda_encoder_nec_reset,
.free = irda_encoder_nec_free},
.get_protocol_spec = irda_nec_get_spec,
.decoder =
{.alloc = irda_decoder_nec_alloc,
.decode = irda_decoder_nec_decode,
.reset = irda_decoder_nec_reset,
.check_ready = irda_decoder_nec_check_ready,
.free = irda_decoder_nec_free},
.encoder =
{.alloc = irda_encoder_nec_alloc,
.encode = irda_encoder_nec_encode,
.reset = irda_encoder_nec_reset,
.free = irda_encoder_nec_free},
.get_protocol_spec = irda_nec_get_spec,
},
{
.decoder = {
.alloc = irda_decoder_samsung32_alloc,
.decode = irda_decoder_samsung32_decode,
.reset = irda_decoder_samsung32_reset,
.check_ready = irda_decoder_samsung32_check_ready,
.free = irda_decoder_samsung32_free},
.encoder = {
.alloc = irda_encoder_samsung32_alloc,
.encode = irda_encoder_samsung32_encode,
.reset = irda_encoder_samsung32_reset,
.free = irda_encoder_samsung32_free},
.get_protocol_spec = irda_samsung32_get_spec,
.decoder =
{.alloc = irda_decoder_samsung32_alloc,
.decode = irda_decoder_samsung32_decode,
.reset = irda_decoder_samsung32_reset,
.check_ready = irda_decoder_samsung32_check_ready,
.free = irda_decoder_samsung32_free},
.encoder =
{.alloc = irda_encoder_samsung32_alloc,
.encode = irda_encoder_samsung32_encode,
.reset = irda_encoder_samsung32_reset,
.free = irda_encoder_samsung32_free},
.get_protocol_spec = irda_samsung32_get_spec,
},
{
.decoder = {
.alloc = irda_decoder_rc5_alloc,
.decode = irda_decoder_rc5_decode,
.reset = irda_decoder_rc5_reset,
.check_ready = irda_decoder_rc5_check_ready,
.free = irda_decoder_rc5_free},
.encoder = {
.alloc = irda_encoder_rc5_alloc,
.encode = irda_encoder_rc5_encode,
.reset = irda_encoder_rc5_reset,
.free = irda_encoder_rc5_free},
.get_protocol_spec = irda_rc5_get_spec,
.decoder =
{.alloc = irda_decoder_rc5_alloc,
.decode = irda_decoder_rc5_decode,
.reset = irda_decoder_rc5_reset,
.check_ready = irda_decoder_rc5_check_ready,
.free = irda_decoder_rc5_free},
.encoder =
{.alloc = irda_encoder_rc5_alloc,
.encode = irda_encoder_rc5_encode,
.reset = irda_encoder_rc5_reset,
.free = irda_encoder_rc5_free},
.get_protocol_spec = irda_rc5_get_spec,
},
{
.decoder = {
.alloc = irda_decoder_rc6_alloc,
.decode = irda_decoder_rc6_decode,
.reset = irda_decoder_rc6_reset,
.check_ready = irda_decoder_rc6_check_ready,
.free = irda_decoder_rc6_free},
.encoder = {
.alloc = irda_encoder_rc6_alloc,
.encode = irda_encoder_rc6_encode,
.reset = irda_encoder_rc6_reset,
.free = irda_encoder_rc6_free},
.get_protocol_spec = irda_rc6_get_spec,
.decoder =
{.alloc = irda_decoder_rc6_alloc,
.decode = irda_decoder_rc6_decode,
.reset = irda_decoder_rc6_reset,
.check_ready = irda_decoder_rc6_check_ready,
.free = irda_decoder_rc6_free},
.encoder =
{.alloc = irda_encoder_rc6_alloc,
.encode = irda_encoder_rc6_encode,
.reset = irda_encoder_rc6_reset,
.free = irda_encoder_rc6_free},
.get_protocol_spec = irda_rc6_get_spec,
},
{
.decoder = {
.alloc = irda_decoder_sirc_alloc,
.decode = irda_decoder_sirc_decode,
.reset = irda_decoder_sirc_reset,
.check_ready = irda_decoder_sirc_check_ready,
.free = irda_decoder_sirc_free},
.encoder = {
.alloc = irda_encoder_sirc_alloc,
.encode = irda_encoder_sirc_encode,
.reset = irda_encoder_sirc_reset,
.free = irda_encoder_sirc_free},
.get_protocol_spec = irda_sirc_get_spec,
.decoder =
{.alloc = irda_decoder_sirc_alloc,
.decode = irda_decoder_sirc_decode,
.reset = irda_decoder_sirc_reset,
.check_ready = irda_decoder_sirc_check_ready,
.free = irda_decoder_sirc_free},
.encoder =
{.alloc = irda_encoder_sirc_alloc,
.encode = irda_encoder_sirc_encode,
.reset = irda_encoder_sirc_reset,
.free = irda_encoder_sirc_free},
.get_protocol_spec = irda_sirc_get_spec,
},
};
static int irda_find_index_by_protocol(IrdaProtocol protocol);
static const IrdaProtocolSpecification* irda_get_spec_by_protocol(IrdaProtocol protocol);
@@ -122,10 +121,10 @@ const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t
IrdaMessage* message = NULL;
IrdaMessage* result = NULL;
for (int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if (irda_encoder_decoder[i].decoder.decode) {
for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if(irda_encoder_decoder[i].decoder.decode) {
message = irda_encoder_decoder[i].decoder.decode(handler->ctx[i], level, duration);
if (!result && message) {
if(!result && message) {
result = message;
}
}
@@ -138,9 +137,9 @@ IrdaDecoderHandler* irda_alloc_decoder(void) {
IrdaDecoderHandler* handler = furi_alloc(sizeof(IrdaDecoderHandler));
handler->ctx = furi_alloc(sizeof(void*) * COUNT_OF(irda_encoder_decoder));
for (int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
handler->ctx[i] = 0;
if (irda_encoder_decoder[i].decoder.alloc)
if(irda_encoder_decoder[i].decoder.alloc)
handler->ctx[i] = irda_encoder_decoder[i].decoder.alloc();
}
@@ -152,8 +151,8 @@ void irda_free_decoder(IrdaDecoderHandler* handler) {
furi_assert(handler);
furi_assert(handler->ctx);
for (int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if (irda_encoder_decoder[i].decoder.free)
for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if(irda_encoder_decoder[i].decoder.free)
irda_encoder_decoder[i].decoder.free(handler->ctx[i]);
}
@@ -162,8 +161,8 @@ void irda_free_decoder(IrdaDecoderHandler* handler) {
}
void irda_reset_decoder(IrdaDecoderHandler* handler) {
for (int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if (irda_encoder_decoder[i].decoder.reset)
for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if(irda_encoder_decoder[i].decoder.reset)
irda_encoder_decoder[i].decoder.reset(handler->ctx[i]);
}
}
@@ -174,10 +173,10 @@ const IrdaMessage* irda_check_decoder_ready(IrdaDecoderHandler* handler) {
IrdaMessage* message = NULL;
IrdaMessage* result = NULL;
for (int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if (irda_encoder_decoder[i].decoder.check_ready) {
for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if(irda_encoder_decoder[i].decoder.check_ready) {
message = irda_encoder_decoder[i].decoder.check_ready(handler->ctx[i]);
if (!result && message) {
if(!result && message) {
result = message;
}
}
@@ -186,7 +185,6 @@ const IrdaMessage* irda_check_decoder_ready(IrdaDecoderHandler* handler) {
return result;
}
IrdaEncoderHandler* irda_alloc_encoder(void) {
IrdaEncoderHandler* handler = furi_alloc(sizeof(IrdaEncoderHandler));
handler->handler = NULL;
@@ -198,7 +196,7 @@ void irda_free_encoder(IrdaEncoderHandler* handler) {
furi_assert(handler);
const IrdaEncoders* encoder = handler->encoder;
if (encoder || handler->handler) {
if(encoder || handler->handler) {
furi_assert(encoder);
furi_assert(handler->handler);
furi_assert(encoder->free);
@@ -209,8 +207,8 @@ void irda_free_encoder(IrdaEncoderHandler* handler) {
}
static int irda_find_index_by_protocol(IrdaProtocol protocol) {
for (int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if (irda_encoder_decoder[i].get_protocol_spec(protocol)) {
for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
if(irda_encoder_decoder[i].get_protocol_spec(protocol)) {
return i;
}
}
@@ -230,8 +228,8 @@ void irda_reset_encoder(IrdaEncoderHandler* handler, const IrdaMessage* message)
furi_assert(required_encoder->alloc);
/* Realloc encoder if different protocol set */
if (required_encoder != handler->encoder) {
if (handler->handler != NULL) {
if(required_encoder != handler->encoder) {
if(handler->handler != NULL) {
furi_assert(handler->encoder->free);
handler->encoder->free(handler->handler);
}
@@ -261,10 +259,9 @@ bool irda_is_protocol_valid(IrdaProtocol protocol) {
}
IrdaProtocol irda_get_protocol_by_name(const char* protocol_name) {
for (IrdaProtocol protocol = 0; protocol < IrdaProtocolMAX; ++protocol) {
for(IrdaProtocol protocol = 0; protocol < IrdaProtocolMAX; ++protocol) {
const char* name = irda_get_protocol_name(protocol);
if (!strcmp(name, protocol_name))
return protocol;
if(!strcmp(name, protocol_name)) return protocol;
}
return IrdaProtocolUnknown;
}
@@ -272,7 +269,8 @@ IrdaProtocol irda_get_protocol_by_name(const char* protocol_name) {
static const IrdaProtocolSpecification* irda_get_spec_by_protocol(IrdaProtocol protocol) {
int index = irda_find_index_by_protocol(protocol);
furi_check(index >= 0);
const IrdaProtocolSpecification* spec = irda_encoder_decoder[index].get_protocol_spec(protocol);
const IrdaProtocolSpecification* spec =
irda_encoder_decoder[index].get_protocol_spec(protocol);
furi_assert(spec);
return spec;
}
@@ -296,4 +294,3 @@ uint32_t irda_get_protocol_frequency(IrdaProtocol protocol) {
float irda_get_protocol_duty_cycle(IrdaProtocol protocol) {
return irda_get_spec_by_protocol(protocol)->duty_cycle;
}

View File

@@ -7,13 +7,13 @@
extern "C" {
#endif
#define IRDA_COMMON_CARRIER_FREQUENCY 38000
#define IRDA_COMMON_DUTY_CYCLE 0.33
#define IRDA_COMMON_CARRIER_FREQUENCY 38000
#define IRDA_COMMON_DUTY_CYCLE 0.33
/* if we want to see splitted raw signals during brutforce,
* we have to have RX raw timing delay less than TX */
#define IRDA_RAW_RX_TIMING_DELAY_US 150000
#define IRDA_RAW_TX_TIMING_DELAY_US 180000
#define IRDA_RAW_RX_TIMING_DELAY_US 150000
#define IRDA_RAW_TX_TIMING_DELAY_US 180000
typedef struct IrdaDecoderHandler IrdaDecoderHandler;
typedef struct IrdaEncoderHandler IrdaEncoderHandler;
@@ -202,4 +202,3 @@ float irda_get_protocol_duty_cycle(IrdaProtocol protocol);
#ifdef __cplusplus
}
#endif

View File

@@ -24,24 +24,23 @@ typedef struct {
float duty_cycle;
} IrdaProtocolSpecification;
typedef const IrdaProtocolSpecification* (*IrdaGetProtocolSpec) (IrdaProtocol protocol);
typedef const IrdaProtocolSpecification* (*IrdaGetProtocolSpec)(IrdaProtocol protocol);
typedef void* (*IrdaAlloc) (void);
typedef void (*IrdaFree) (void*);
typedef void* (*IrdaAlloc)(void);
typedef void (*IrdaFree)(void*);
typedef void (*IrdaDecoderReset) (void*);
typedef IrdaMessage* (*IrdaDecode) (void* ctx, bool level, uint32_t duration);
typedef IrdaMessage* (*IrdaDecoderCheckReady) (void*);
typedef void (*IrdaDecoderReset)(void*);
typedef IrdaMessage* (*IrdaDecode)(void* ctx, bool level, uint32_t duration);
typedef IrdaMessage* (*IrdaDecoderCheckReady)(void*);
typedef void (*IrdaEncoderReset)(void* encoder, const IrdaMessage* message);
typedef IrdaStatus (*IrdaEncode)(void* encoder, uint32_t* out, bool* polarity);
static inline uint8_t reverse(uint8_t value) {
uint8_t reverse_value = 0;
for (int i = 0; i < 8; ++i) {
for(int i = 0; i < 8; ++i) {
reverse_value |= (value & (0x01 << i)) ? 1 << (7 - i) : 0;
}
return reverse_value;
}

View File

@@ -20,21 +20,21 @@
*
***************************************************************************************************/
#define IRDA_NEC_PREAMBLE_MARK 9000
#define IRDA_NEC_PREAMBLE_SPACE 4500
#define IRDA_NEC_BIT1_MARK 560
#define IRDA_NEC_BIT1_SPACE 1690
#define IRDA_NEC_BIT0_MARK 560
#define IRDA_NEC_BIT0_SPACE 560
#define IRDA_NEC_REPEAT_PERIOD 110000
#define IRDA_NEC_SILENCE IRDA_NEC_REPEAT_PERIOD
#define IRDA_NEC_MIN_SPLIT_TIME IRDA_NEC_REPEAT_PAUSE_MIN
#define IRDA_NEC_REPEAT_PAUSE_MIN 4000
#define IRDA_NEC_REPEAT_PAUSE_MAX 150000
#define IRDA_NEC_REPEAT_MARK 9000
#define IRDA_NEC_REPEAT_SPACE 2250
#define IRDA_NEC_PREAMBLE_TOLERANCE 200 // us
#define IRDA_NEC_BIT_TOLERANCE 120 // us
#define IRDA_NEC_PREAMBLE_MARK 9000
#define IRDA_NEC_PREAMBLE_SPACE 4500
#define IRDA_NEC_BIT1_MARK 560
#define IRDA_NEC_BIT1_SPACE 1690
#define IRDA_NEC_BIT0_MARK 560
#define IRDA_NEC_BIT0_SPACE 560
#define IRDA_NEC_REPEAT_PERIOD 110000
#define IRDA_NEC_SILENCE IRDA_NEC_REPEAT_PERIOD
#define IRDA_NEC_MIN_SPLIT_TIME IRDA_NEC_REPEAT_PAUSE_MIN
#define IRDA_NEC_REPEAT_PAUSE_MIN 4000
#define IRDA_NEC_REPEAT_PAUSE_MAX 150000
#define IRDA_NEC_REPEAT_MARK 9000
#define IRDA_NEC_REPEAT_SPACE 2250
#define IRDA_NEC_PREAMBLE_TOLERANCE 200 // us
#define IRDA_NEC_BIT_TOLERANCE 120 // us
void* irda_decoder_nec_alloc(void);
void irda_decoder_nec_reset(void* decoder);
@@ -47,12 +47,12 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message);
void irda_encoder_nec_free(void* encoder_ptr);
bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder);
IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder);
IrdaStatus irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
IrdaStatus
irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
const IrdaProtocolSpecification* irda_nec_get_spec(IrdaProtocol protocol);
extern const IrdaCommonProtocolSpec protocol_nec;
/***************************************************************************************************
* SAMSUNG32 protocol description
* https://www.mikrocontroller.net/articles/IRMP_-_english#SAMSUNG
@@ -67,27 +67,27 @@ extern const IrdaCommonProtocolSpec protocol_nec;
*
***************************************************************************************************/
#define IRDA_SAMSUNG_PREAMBLE_MARK 4500
#define IRDA_SAMSUNG_PREAMBLE_SPACE 4500
#define IRDA_SAMSUNG_BIT1_MARK 550
#define IRDA_SAMSUNG_BIT1_SPACE 1650
#define IRDA_SAMSUNG_BIT0_MARK 550
#define IRDA_SAMSUNG_BIT0_SPACE 550
#define IRDA_SAMSUNG_REPEAT_PAUSE_MIN 30000
#define IRDA_SAMSUNG_REPEAT_PAUSE1 46000
#define IRDA_SAMSUNG_REPEAT_PAUSE2 97000
#define IRDA_SAMSUNG_PREAMBLE_MARK 4500
#define IRDA_SAMSUNG_PREAMBLE_SPACE 4500
#define IRDA_SAMSUNG_BIT1_MARK 550
#define IRDA_SAMSUNG_BIT1_SPACE 1650
#define IRDA_SAMSUNG_BIT0_MARK 550
#define IRDA_SAMSUNG_BIT0_SPACE 550
#define IRDA_SAMSUNG_REPEAT_PAUSE_MIN 30000
#define IRDA_SAMSUNG_REPEAT_PAUSE1 46000
#define IRDA_SAMSUNG_REPEAT_PAUSE2 97000
/* Samsung silence have to be greater than REPEAT MAX
* otherwise there can be problems during unit tests parsing
* of some data. Real tolerances we don't know, but in real life
* silence time should be greater than max repeat time. This is
* because of similar preambule timings for repeat and first messages. */
#define IRDA_SAMSUNG_MIN_SPLIT_TIME 5000
#define IRDA_SAMSUNG_SILENCE 145000
#define IRDA_SAMSUNG_REPEAT_PAUSE_MAX 140000
#define IRDA_SAMSUNG_REPEAT_MARK 4500
#define IRDA_SAMSUNG_REPEAT_SPACE 4500
#define IRDA_SAMSUNG_PREAMBLE_TOLERANCE 200 // us
#define IRDA_SAMSUNG_BIT_TOLERANCE 120 // us
#define IRDA_SAMSUNG_MIN_SPLIT_TIME 5000
#define IRDA_SAMSUNG_SILENCE 145000
#define IRDA_SAMSUNG_REPEAT_PAUSE_MAX 140000
#define IRDA_SAMSUNG_REPEAT_MARK 4500
#define IRDA_SAMSUNG_REPEAT_SPACE 4500
#define IRDA_SAMSUNG_PREAMBLE_TOLERANCE 200 // us
#define IRDA_SAMSUNG_BIT_TOLERANCE 120 // us
void* irda_decoder_samsung32_alloc(void);
void irda_decoder_samsung32_reset(void* decoder);
@@ -100,12 +100,14 @@ void* irda_encoder_samsung32_alloc(void);
void irda_encoder_samsung32_free(void* encoder_ptr);
bool irda_decoder_samsung32_interpret(IrdaCommonDecoder* decoder);
IrdaStatus irda_decoder_samsung32_decode_repeat(IrdaCommonDecoder* decoder);
IrdaStatus irda_encoder_samsung32_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
IrdaStatus irda_encoder_samsung32_encode_repeat(
IrdaCommonEncoder* encoder,
uint32_t* duration,
bool* level);
const IrdaProtocolSpecification* irda_samsung32_get_spec(IrdaProtocol protocol);
extern const IrdaCommonProtocolSpec protocol_samsung32;
/***************************************************************************************************
* RC6 protocol description
* https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A
@@ -127,17 +129,17 @@ extern const IrdaCommonProtocolSpec protocol_samsung32;
* command - 8 bit
***************************************************************************************************/
#define IRDA_RC6_CARRIER_FREQUENCY 36000
#define IRDA_RC6_DUTY_CYCLE 0.33
#define IRDA_RC6_CARRIER_FREQUENCY 36000
#define IRDA_RC6_DUTY_CYCLE 0.33
#define IRDA_RC6_PREAMBLE_MARK 2666
#define IRDA_RC6_PREAMBLE_SPACE 889
#define IRDA_RC6_BIT 444 // half of time-quant for 1 bit
#define IRDA_RC6_PREAMBLE_TOLERANCE 200 // us
#define IRDA_RC6_BIT_TOLERANCE 120 // us
#define IRDA_RC6_PREAMBLE_MARK 2666
#define IRDA_RC6_PREAMBLE_SPACE 889
#define IRDA_RC6_BIT 444 // half of time-quant for 1 bit
#define IRDA_RC6_PREAMBLE_TOLERANCE 200 // us
#define IRDA_RC6_BIT_TOLERANCE 120 // us
/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
#define IRDA_RC6_SILENCE (2700 * 10)
#define IRDA_RC6_MIN_SPLIT_TIME 2700
#define IRDA_RC6_SILENCE (2700 * 10)
#define IRDA_RC6_MIN_SPLIT_TIME 2700
void* irda_decoder_rc6_alloc(void);
void irda_decoder_rc6_reset(void* decoder);
@@ -149,13 +151,16 @@ void irda_encoder_rc6_reset(void* encoder_ptr, const IrdaMessage* message);
void irda_encoder_rc6_free(void* decoder);
IrdaStatus irda_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder);
IrdaStatus irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing);
IrdaStatus irda_encoder_rc6_encode_manchester(IrdaCommonEncoder* encoder_ptr, uint32_t* duration, bool* polarity);
IrdaStatus
irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing);
IrdaStatus irda_encoder_rc6_encode_manchester(
IrdaCommonEncoder* encoder_ptr,
uint32_t* duration,
bool* polarity);
const IrdaProtocolSpecification* irda_rc6_get_spec(IrdaProtocol protocol);
extern const IrdaCommonProtocolSpec protocol_rc6;
/***************************************************************************************************
* RC5 protocol description
* https://www.mikrocontroller.net/articles/IRMP_-_english#RC5_.2B_RC5X
@@ -178,17 +183,17 @@ extern const IrdaCommonProtocolSpec protocol_rc6;
* command - 6/7 bit
***************************************************************************************************/
#define IRDA_RC5_CARRIER_FREQUENCY 36000
#define IRDA_RC5_DUTY_CYCLE 0.33
#define IRDA_RC5_CARRIER_FREQUENCY 36000
#define IRDA_RC5_DUTY_CYCLE 0.33
#define IRDA_RC5_PREAMBLE_MARK 0
#define IRDA_RC5_PREAMBLE_SPACE 0
#define IRDA_RC5_BIT 888 // half of time-quant for 1 bit
#define IRDA_RC5_PREAMBLE_TOLERANCE 200 // us
#define IRDA_RC5_BIT_TOLERANCE 120 // us
#define IRDA_RC5_PREAMBLE_MARK 0
#define IRDA_RC5_PREAMBLE_SPACE 0
#define IRDA_RC5_BIT 888 // half of time-quant for 1 bit
#define IRDA_RC5_PREAMBLE_TOLERANCE 200 // us
#define IRDA_RC5_BIT_TOLERANCE 120 // us
/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
#define IRDA_RC5_SILENCE (2700 * 10)
#define IRDA_RC5_MIN_SPLIT_TIME 2700
#define IRDA_RC5_SILENCE (2700 * 10)
#define IRDA_RC5_MIN_SPLIT_TIME 2700
void* irda_decoder_rc5_alloc(void);
void irda_decoder_rc5_reset(void* decoder);
@@ -204,7 +209,6 @@ const IrdaProtocolSpecification* irda_rc5_get_spec(IrdaProtocol protocol);
extern const IrdaCommonProtocolSpec protocol_rc5;
/***************************************************************************************************
* Sony SIRC protocol description
* https://www.sbprojects.net/knowledge/ir/sirc.php
@@ -226,20 +230,19 @@ extern const IrdaCommonProtocolSpec protocol_rc5;
* Assume 8 last extended bits for SIRC20 are address bits.
***************************************************************************************************/
#define IRDA_SIRC_CARRIER_FREQUENCY 40000
#define IRDA_SIRC_DUTY_CYCLE 0.33
#define IRDA_SIRC_PREAMBLE_MARK 2400
#define IRDA_SIRC_PREAMBLE_SPACE 600
#define IRDA_SIRC_BIT1_MARK 1200
#define IRDA_SIRC_BIT1_SPACE 600
#define IRDA_SIRC_BIT0_MARK 600
#define IRDA_SIRC_BIT0_SPACE 600
#define IRDA_SIRC_PREAMBLE_TOLERANCE 200 // us
#define IRDA_SIRC_BIT_TOLERANCE 120 // us
#define IRDA_SIRC_SILENCE 10000
#define IRDA_SIRC_MIN_SPLIT_TIME (IRDA_SIRC_SILENCE - 1000)
#define IRDA_SIRC_REPEAT_PERIOD 45000
#define IRDA_SIRC_CARRIER_FREQUENCY 40000
#define IRDA_SIRC_DUTY_CYCLE 0.33
#define IRDA_SIRC_PREAMBLE_MARK 2400
#define IRDA_SIRC_PREAMBLE_SPACE 600
#define IRDA_SIRC_BIT1_MARK 1200
#define IRDA_SIRC_BIT1_SPACE 600
#define IRDA_SIRC_BIT0_MARK 600
#define IRDA_SIRC_BIT0_SPACE 600
#define IRDA_SIRC_PREAMBLE_TOLERANCE 200 // us
#define IRDA_SIRC_BIT_TOLERANCE 120 // us
#define IRDA_SIRC_SILENCE 10000
#define IRDA_SIRC_MIN_SPLIT_TIME (IRDA_SIRC_SILENCE - 1000)
#define IRDA_SIRC_REPEAT_PERIOD 45000
void* irda_decoder_sirc_alloc(void);
void irda_decoder_sirc_reset(void* decoder);
@@ -253,7 +256,7 @@ void irda_encoder_sirc_free(void* decoder);
IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
bool irda_decoder_sirc_interpret(IrdaCommonDecoder* decoder);
const IrdaProtocolSpecification* irda_sirc_get_spec(IrdaProtocol protocol);
IrdaStatus irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
IrdaStatus
irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
extern const IrdaCommonProtocolSpec protocol_sirc;

View File

@@ -6,7 +6,6 @@
#include <furi.h>
#include "../irda_i.h"
IrdaMessage* irda_decoder_nec_check_ready(void* ctx) {
return irda_common_decoder_check_ready(ctx);
}
@@ -16,12 +15,12 @@ bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) {
bool result = false;
if (decoder->databit_cnt == 32) {
if(decoder->databit_cnt == 32) {
uint8_t address = decoder->data[0];
uint8_t address_inverse = decoder->data[1];
uint8_t command = decoder->data[2];
uint8_t command_inverse = decoder->data[3];
if ((command == (uint8_t) ~command_inverse) && (address == (uint8_t) ~address_inverse)) {
if((command == (uint8_t)~command_inverse) && (address == (uint8_t)~address_inverse)) {
decoder->message.protocol = IrdaProtocolNEC;
decoder->message.address = address;
decoder->message.command = command;
@@ -34,16 +33,15 @@ bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) {
decoder->message.repeat = false;
result = true;
}
} else if (decoder->databit_cnt == 42) {
uint32_t* data1 = (void*) decoder->data;
uint16_t* data2 = (void*) (data1 + 1);
} else if(decoder->databit_cnt == 42) {
uint32_t* data1 = (void*)decoder->data;
uint16_t* data2 = (void*)(data1 + 1);
uint16_t address = *data1 & 0x1FFF;
uint16_t address_inverse = (*data1 >> 13) & 0x1FFF;
uint16_t command = ((*data1 >> 26) & 0x3F) | ((*data2 & 0x3) << 6);
uint16_t command_inverse = (*data2 >> 2) & 0xFF;
if ((address == (~address_inverse & 0x1FFF))
&& (command == (~command_inverse & 0xFF))) {
if((address == (~address_inverse & 0x1FFF)) && (command == (~command_inverse & 0xFF))) {
decoder->message.protocol = IrdaProtocolNEC42;
decoder->message.address = address;
decoder->message.command = command;
@@ -100,4 +98,3 @@ void irda_decoder_nec_free(void* decoder) {
void irda_decoder_nec_reset(void* decoder) {
irda_common_decoder_reset(decoder);
}

View File

@@ -20,9 +20,9 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) {
IrdaCommonEncoder* encoder = encoder_ptr;
irda_common_encoder_reset(encoder);
uint32_t* data1 = (void*) encoder->data;
uint32_t* data1 = (void*)encoder->data;
uint32_t* data2 = data1 + 1;
if (message->protocol == IrdaProtocolNEC) {
if(message->protocol == IrdaProtocolNEC) {
uint8_t address = message->address;
uint8_t address_inverse = ~address;
uint8_t command = message->command;
@@ -32,11 +32,11 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) {
*data1 |= command << 16;
*data1 |= command_inverse << 24;
encoder->bits_to_encode = 32;
} else if (message->protocol == IrdaProtocolNECext) {
*data1 = (uint16_t) message->address;
} else if(message->protocol == IrdaProtocolNECext) {
*data1 = (uint16_t)message->address;
*data1 |= (message->command & 0xFFFF) << 16;
encoder->bits_to_encode = 32;
} else if (message->protocol == IrdaProtocolNEC42) {
} else if(message->protocol == IrdaProtocolNEC42) {
/* 13 address + 13 inverse address + 8 command + 8 inv command */
*data1 = message->address & 0x1FFFUL;
*data1 |= (~message->address & 0x1FFFUL) << 13;
@@ -44,7 +44,7 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) {
*data2 = (message->command & 0xC0UL) >> 6;
*data2 |= (~message->command & 0xFFUL) << 2;
encoder->bits_to_encode = 42;
} else if (message->protocol == IrdaProtocolNEC42ext) {
} else if(message->protocol == IrdaProtocolNEC42ext) {
*data1 = message->address & 0x3FFFFFF;
*data1 |= ((message->command & 0x3F) << 26);
*data2 = (message->command & 0xFFC0) >> 6;
@@ -54,7 +54,8 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) {
}
}
IrdaStatus irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
IrdaStatus
irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
furi_assert(encoder);
/* space + 2 timings preambule + payload + stop bit */
@@ -63,7 +64,7 @@ IrdaStatus irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t*
furi_assert(encoder->timings_encoded >= timings_encoded_up_to_repeat);
if (repeat_cnt > 0) {
if(repeat_cnt > 0) {
*duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)];
} else {
*duration = IRDA_NEC_REPEAT_PERIOD - encoder->timings_sum;
@@ -87,4 +88,3 @@ void irda_encoder_nec_free(void* encoder_ptr) {
IrdaStatus irda_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
return irda_common_encode(encoder_ptr, duration, level);
}

View File

@@ -2,47 +2,46 @@
#include "irda_protocol_defs_i.h"
static const IrdaProtocolSpecification irda_nec_protocol_specification = {
.name = "NEC",
.address_length = 8,
.command_length = 8,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
.name = "NEC",
.address_length = 8,
.command_length = 8,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
};
static const IrdaProtocolSpecification irda_necext_protocol_specification = {
.name = "NECext",
.address_length = 16,
.command_length = 16,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
.name = "NECext",
.address_length = 16,
.command_length = 16,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
};
static const IrdaProtocolSpecification irda_nec42_protocol_specification = {
.name = "NEC42",
.address_length = 13,
.command_length = 8,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
.name = "NEC42",
.address_length = 13,
.command_length = 8,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
};
static const IrdaProtocolSpecification irda_nec42ext_protocol_specification = {
.name = "NEC42ext",
.address_length = 26,
.command_length = 16,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
.name = "NEC42ext",
.address_length = 26,
.command_length = 16,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
};
const IrdaProtocolSpecification* irda_nec_get_spec(IrdaProtocol protocol) {
if (protocol == IrdaProtocolNEC)
if(protocol == IrdaProtocolNEC)
return &irda_nec_protocol_specification;
else if (protocol == IrdaProtocolNECext)
else if(protocol == IrdaProtocolNECext)
return &irda_necext_protocol_specification;
else if (protocol == IrdaProtocolNEC42)
else if(protocol == IrdaProtocolNEC42)
return &irda_nec42_protocol_specification;
else if (protocol == IrdaProtocolNEC42ext)
else if(protocol == IrdaProtocolNEC42ext)
return &irda_nec42ext_protocol_specification;
else
return NULL;
}

View File

@@ -20,7 +20,7 @@ bool irda_decoder_rc5_interpret(IrdaCommonDecoder* decoder) {
furi_assert(decoder);
bool result = false;
uint32_t* data = (void*) &decoder->data[0];
uint32_t* data = (void*)&decoder->data[0];
/* Manchester (inverse):
* 0->1 : 1
* 1->0 : 0
@@ -29,20 +29,19 @@ bool irda_decoder_rc5_interpret(IrdaCommonDecoder* decoder) {
decoder->data[1] = ~decoder->data[1];
// MSB first
uint8_t address = reverse((uint8_t) decoder->data[0]) & 0x1F;
uint8_t command = (reverse((uint8_t) decoder->data[1]) >> 2) & 0x3F;
uint8_t address = reverse((uint8_t)decoder->data[0]) & 0x1F;
uint8_t command = (reverse((uint8_t)decoder->data[1]) >> 2) & 0x3F;
bool start_bit1 = *data & 0x01;
bool start_bit2 = *data & 0x02;
bool toggle = !!(*data & 0x04);
if (start_bit1 == 1) {
if(start_bit1 == 1) {
IrdaProtocol protocol = start_bit2 ? IrdaProtocolRC5 : IrdaProtocolRC5X;
IrdaMessage* message = &decoder->message;
IrdaRc5Decoder *rc5_decoder = decoder->context;
bool *prev_toggle = &rc5_decoder->toggle;
if ((message->address == address)
&& (message->command == command)
&& (message->protocol == protocol)) {
IrdaRc5Decoder* rc5_decoder = decoder->context;
bool* prev_toggle = &rc5_decoder->toggle;
if((message->address == address) && (message->command == command) &&
(message->protocol == protocol)) {
message->repeat = (toggle == *prev_toggle);
} else {
message->repeat = false;
@@ -81,4 +80,3 @@ void irda_decoder_rc5_reset(void* decoder) {
IrdaRc5Decoder* decoder_rc5 = decoder;
irda_common_decoder_reset(decoder_rc5->common_decoder);
}

View File

@@ -17,11 +17,11 @@ void irda_encoder_rc5_reset(void* encoder_ptr, const IrdaMessage* message) {
IrdaCommonEncoder* common_encoder = encoder->common_encoder;
irda_common_encoder_reset(common_encoder);
uint32_t* data = (void*) common_encoder->data;
uint32_t* data = (void*)common_encoder->data;
/* RC5 */
*data |= 0x01; // start bit
if (message->protocol == IrdaProtocolRC5) {
*data |= 0x02; // start bit
*data |= 0x01; // start bit
if(message->protocol == IrdaProtocolRC5) {
*data |= 0x02; // start bit
}
*data |= encoder->toggle_bit ? 0x04 : 0;
*data |= (reverse(message->address) >> 3) << 3; /* address 5 bit */
@@ -53,4 +53,3 @@ void irda_encoder_rc5_free(void* encoder_ptr) {
free(encoder->common_encoder);
free(encoder);
}

View File

@@ -2,27 +2,26 @@
#include "irda_protocol_defs_i.h"
static const IrdaProtocolSpecification irda_rc5_protocol_specification = {
.name = "RC5",
.address_length = 5,
.command_length = 6,
.frequency = IRDA_RC5_CARRIER_FREQUENCY,
.duty_cycle = IRDA_RC5_DUTY_CYCLE,
.name = "RC5",
.address_length = 5,
.command_length = 6,
.frequency = IRDA_RC5_CARRIER_FREQUENCY,
.duty_cycle = IRDA_RC5_DUTY_CYCLE,
};
static const IrdaProtocolSpecification irda_rc5x_protocol_specification = {
.name = "RC5X",
.address_length = 5,
.command_length = 7,
.frequency = IRDA_RC5_CARRIER_FREQUENCY,
.duty_cycle = IRDA_RC5_DUTY_CYCLE,
.name = "RC5X",
.address_length = 5,
.command_length = 7,
.frequency = IRDA_RC5_CARRIER_FREQUENCY,
.duty_cycle = IRDA_RC5_DUTY_CYCLE,
};
const IrdaProtocolSpecification* irda_rc5_get_spec(IrdaProtocol protocol) {
if (protocol == IrdaProtocolRC5)
if(protocol == IrdaProtocolRC5)
return &irda_rc5_protocol_specification;
else if (protocol == IrdaProtocolRC5X)
else if(protocol == IrdaProtocolRC5X)
return &irda_rc5x_protocol_specification;
else
return NULL;
}

View File

@@ -20,21 +20,20 @@ bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder) {
furi_assert(decoder);
bool result = false;
uint32_t* data = (void*) &decoder->data[0];
uint32_t* data = (void*)&decoder->data[0];
// MSB first
uint8_t address = reverse((uint8_t) (*data >> 5));
uint8_t command = reverse((uint8_t) (*data >> 13));
uint8_t address = reverse((uint8_t)(*data >> 5));
uint8_t command = reverse((uint8_t)(*data >> 13));
bool start_bit = *data & 0x01;
bool toggle = !!(*data & 0x10);
uint8_t mode = (*data >> 1) & 0x7;
if ((start_bit == 1) && (mode == 0)) {
if((start_bit == 1) && (mode == 0)) {
IrdaMessage* message = &decoder->message;
IrdaRc6Decoder *rc6_decoder = decoder->context;
bool *prev_toggle = &rc6_decoder->toggle;
if ((message->address == address)
&& (message->command == command)
&& (message->protocol == IrdaProtocolRC6)) {
IrdaRc6Decoder* rc6_decoder = decoder->context;
bool* prev_toggle = &rc6_decoder->toggle;
if((message->address == address) && (message->command == command) &&
(message->protocol == IrdaProtocolRC6)) {
message->repeat = (toggle == *prev_toggle);
} else {
message->repeat = false;
@@ -55,31 +54,31 @@ bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder) {
* it separately and than pass decoding for other bits to
* common manchester decode function.
*/
IrdaStatus irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing) {
IrdaStatus
irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing) {
// 4th bit lasts 2x times more
IrdaStatus status = IrdaStatusError;
uint16_t bit = decoder->protocol->timings.bit1_mark;
uint16_t tolerance = decoder->protocol->timings.bit_tolerance;
bool single_timing = MATCH_TIMING(timing, bit, tolerance);
bool double_timing = MATCH_TIMING(timing, 2*bit, tolerance);
bool triple_timing = MATCH_TIMING(timing, 3*bit, tolerance);
bool double_timing = MATCH_TIMING(timing, 2 * bit, tolerance);
bool triple_timing = MATCH_TIMING(timing, 3 * bit, tolerance);
if (decoder->databit_cnt == 4) {
if(decoder->databit_cnt == 4) {
furi_assert(decoder->switch_detect == true);
if (single_timing ^ triple_timing) {
if(single_timing ^ triple_timing) {
++decoder->databit_cnt;
decoder->data[0] |= (single_timing ? !level : level) << 4;
status = IrdaStatusOk;
}
} else if (decoder->databit_cnt == 5) {
if (single_timing || triple_timing) {
if (triple_timing)
timing = bit;
} else if(decoder->databit_cnt == 5) {
if(single_timing || triple_timing) {
if(triple_timing) timing = bit;
decoder->switch_detect = false;
status = irda_common_decode_manchester(decoder, level, timing);
} else if (double_timing) {
} else if(double_timing) {
status = IrdaStatusOk;
}
} else {
@@ -112,4 +111,3 @@ void irda_decoder_rc6_reset(void* decoder) {
IrdaRc6Decoder* decoder_rc6 = decoder;
irda_common_decoder_reset(decoder_rc6->common_decoder);
}

View File

@@ -17,9 +17,9 @@ void irda_encoder_rc6_reset(void* encoder_ptr, const IrdaMessage* message) {
IrdaCommonEncoder* common_encoder = encoder->common_encoder;
irda_common_encoder_reset(common_encoder);
uint32_t* data = (void*) common_encoder->data;
*data |= 0x01; // start bit
(void) *data; // 3 bits for mode == 0
uint32_t* data = (void*)common_encoder->data;
*data |= 0x01; // start bit
(void)*data; // 3 bits for mode == 0
*data |= encoder->toggle_bit ? 0x10 : 0;
*data |= reverse(message->address) << 5;
*data |= reverse(message->command) << 13;
@@ -48,13 +48,14 @@ void irda_encoder_rc6_free(void* encoder_ptr) {
free(encoder);
}
IrdaStatus irda_encoder_rc6_encode_manchester(IrdaCommonEncoder* common_encoder, uint32_t* duration, bool* polarity) {
IrdaStatus irda_encoder_rc6_encode_manchester(
IrdaCommonEncoder* common_encoder,
uint32_t* duration,
bool* polarity) {
IrdaStatus status = IrdaStatusError;
bool toggle_bit = (common_encoder->bits_encoded == 4);
status = irda_common_encode_manchester(common_encoder, duration, polarity);
if (toggle_bit)
*duration *= 2;
if(toggle_bit) *duration *= 2;
return status;
}

View File

@@ -2,17 +2,16 @@
#include "irda_protocol_defs_i.h"
static const IrdaProtocolSpecification irda_rc6_protocol_specification = {
.name = "RC6",
.address_length = 8,
.command_length = 8,
.frequency = IRDA_RC6_CARRIER_FREQUENCY,
.duty_cycle = IRDA_RC6_DUTY_CYCLE,
.name = "RC6",
.address_length = 8,
.command_length = 8,
.frequency = IRDA_RC6_CARRIER_FREQUENCY,
.duty_cycle = IRDA_RC6_DUTY_CYCLE,
};
const IrdaProtocolSpecification* irda_rc6_get_spec(IrdaProtocol protocol) {
if (protocol == IrdaProtocolRC6)
if(protocol == IrdaProtocolRC6)
return &irda_rc6_protocol_specification;
else
return NULL;
}

View File

@@ -5,7 +5,6 @@
#include <furi.h>
#include "../irda_i.h"
IrdaMessage* irda_decoder_samsung32_check_ready(void* ctx) {
return irda_common_decoder_check_ready(ctx);
}
@@ -19,7 +18,7 @@ bool irda_decoder_samsung32_interpret(IrdaCommonDecoder* decoder) {
uint8_t command = decoder->data[2];
uint8_t command_inverse = decoder->data[3];
if ((address1 == address2) && (command == (uint8_t) ~command_inverse)) {
if((address1 == address2) && (command == (uint8_t)~command_inverse)) {
decoder->message.command = command;
decoder->message.address = address1;
decoder->message.protocol = IrdaProtocolSamsung32;
@@ -38,17 +37,15 @@ IrdaStatus irda_decoder_samsung32_decode_repeat(IrdaCommonDecoder* decoder) {
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
IrdaStatus status = IrdaStatusError;
if (decoder->timings_cnt < 6)
return IrdaStatusOk;
if(decoder->timings_cnt < 6) return IrdaStatusOk;
if ((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN)
&& (decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX)
&& MATCH_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance)
&& MATCH_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance)
&& MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)
&& MATCH_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance)
&& MATCH_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)
) {
if((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN) &&
(decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX) &&
MATCH_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance) &&
MATCH_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance) &&
MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance) &&
MATCH_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance) &&
MATCH_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
status = IrdaStatusReady;
decoder->timings_cnt = 0;
} else {
@@ -73,4 +70,3 @@ void irda_decoder_samsung32_free(void* decoder) {
void irda_decoder_samsung32_reset(void* decoder) {
irda_common_decoder_reset(decoder);
}

View File

@@ -24,7 +24,7 @@ void irda_encoder_samsung32_reset(void* encoder_ptr, const IrdaMessage* message)
uint8_t command = message->command;
uint8_t command_inverse = ~command;
uint32_t* data = (void*) encoder->data;
uint32_t* data = (void*)encoder->data;
*data |= address;
*data |= address << 8;
*data |= command << 16;
@@ -33,7 +33,10 @@ void irda_encoder_samsung32_reset(void* encoder_ptr, const IrdaMessage* message)
encoder->bits_to_encode = encoder->protocol->databit_len[0];
}
IrdaStatus irda_encoder_samsung32_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
IrdaStatus irda_encoder_samsung32_encode_repeat(
IrdaCommonEncoder* encoder,
uint32_t* duration,
bool* level) {
furi_assert(encoder);
/* space + 2 timings preambule + payload + stop bit */
@@ -42,7 +45,7 @@ IrdaStatus irda_encoder_samsung32_encode_repeat(IrdaCommonEncoder* encoder, uint
furi_assert(encoder->timings_encoded >= timings_encoded_up_to_repeat);
if (repeat_cnt > 0)
if(repeat_cnt > 0)
*duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)];
else
*duration = IRDA_SAMSUNG_REPEAT_PAUSE1;
@@ -65,5 +68,3 @@ void irda_encoder_samsung32_free(void* encoder_ptr) {
IrdaStatus irda_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
return irda_common_encode(encoder_ptr, duration, level);
}

View File

@@ -2,17 +2,16 @@
#include "irda_protocol_defs_i.h"
static const IrdaProtocolSpecification irda_samsung32_protocol_specification = {
.name = "Samsung32",
.address_length = 8,
.command_length = 8,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
.name = "Samsung32",
.address_length = 8,
.command_length = 8,
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
};
const IrdaProtocolSpecification* irda_samsung32_get_spec(IrdaProtocol protocol) {
if (protocol == IrdaProtocolSamsung32)
if(protocol == IrdaProtocolSamsung32)
return &irda_samsung32_protocol_specification;
else
return NULL;
}

View File

@@ -6,7 +6,6 @@
#include <furi.h>
#include "../irda_i.h"
IrdaMessage* irda_decoder_sirc_check_ready(void* ctx) {
return irda_common_decoder_check_ready(ctx);
}
@@ -14,21 +13,21 @@ IrdaMessage* irda_decoder_sirc_check_ready(void* ctx) {
bool irda_decoder_sirc_interpret(IrdaCommonDecoder* decoder) {
furi_assert(decoder);
uint32_t* data = (void*) &decoder->data[0];
uint32_t* data = (void*)&decoder->data[0];
uint16_t address = 0;
uint8_t command = 0;
IrdaProtocol protocol = IrdaProtocolUnknown;
if (decoder->databit_cnt == 12) {
address = (*data >> 7) & 0x1F;
if(decoder->databit_cnt == 12) {
address = (*data >> 7) & 0x1F;
command = *data & 0x7F;
protocol = IrdaProtocolSIRC;
} else if (decoder->databit_cnt == 15) {
address = (*data >> 7) & 0xFF;
} else if(decoder->databit_cnt == 15) {
address = (*data >> 7) & 0xFF;
command = *data & 0x7F;
protocol = IrdaProtocolSIRC15;
} else if (decoder->databit_cnt == 20) {
address = (*data >> 7) & 0x1FFF;
} else if(decoder->databit_cnt == 20) {
address = (*data >> 7) & 0x1FFF;
command = *data & 0x7F;
protocol = IrdaProtocolSIRC20;
} else {
@@ -59,4 +58,3 @@ void irda_decoder_sirc_free(void* decoder) {
void irda_decoder_sirc_reset(void* decoder) {
irda_common_decoder_reset(decoder);
}

View File

@@ -6,7 +6,6 @@
#include "irda_protocol_defs_i.h"
#include <furi.h>
void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message) {
furi_assert(encoder_ptr);
furi_assert(message);
@@ -14,17 +13,17 @@ void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message) {
IrdaCommonEncoder* encoder = encoder_ptr;
irda_common_encoder_reset(encoder);
uint32_t* data = (void*) encoder->data;
uint32_t* data = (void*)encoder->data;
if (message->protocol == IrdaProtocolSIRC) {
if(message->protocol == IrdaProtocolSIRC) {
*data = (message->command & 0x7F);
*data |= (message->address & 0x1F) << 7;
encoder->bits_to_encode = 12;
} else if (message->protocol == IrdaProtocolSIRC15) {
} else if(message->protocol == IrdaProtocolSIRC15) {
*data = (message->command & 0x7F);
*data |= (message->address & 0xFF) << 7;
encoder->bits_to_encode = 15;
} else if (message->protocol == IrdaProtocolSIRC20) {
} else if(message->protocol == IrdaProtocolSIRC20) {
*data = (message->command & 0x7F);
*data |= (message->address & 0x1FFF) << 7;
encoder->bits_to_encode = 20;
@@ -33,7 +32,8 @@ void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message) {
}
}
IrdaStatus irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
IrdaStatus
irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
furi_assert(encoder);
furi_assert(encoder->timings_encoded == (1 + 2 + encoder->bits_to_encode * 2 - 1));
@@ -62,11 +62,10 @@ IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool*
IrdaCommonEncoder* encoder = encoder_ptr;
IrdaStatus status = irda_common_encode(encoder, duration, level);
if ((status == IrdaStatusOk) && (encoder->bits_encoded == encoder->bits_to_encode)) {
if((status == IrdaStatusOk) && (encoder->bits_encoded == encoder->bits_to_encode)) {
furi_assert(!*level);
status = IrdaStatusDone;
encoder->state = IrdaCommonEncoderStateEncodeRepeat;
}
return status;
}

View File

@@ -2,37 +2,36 @@
#include "irda_protocol_defs_i.h"
static const IrdaProtocolSpecification irda_sirc_protocol_specification = {
.name = "SIRC",
.address_length = 5,
.command_length = 7,
.frequency = IRDA_SIRC_CARRIER_FREQUENCY,
.duty_cycle = IRDA_SIRC_DUTY_CYCLE,
.name = "SIRC",
.address_length = 5,
.command_length = 7,
.frequency = IRDA_SIRC_CARRIER_FREQUENCY,
.duty_cycle = IRDA_SIRC_DUTY_CYCLE,
};
static const IrdaProtocolSpecification irda_sirc15_protocol_specification = {
.name = "SIRC15",
.address_length = 8,
.command_length = 7,
.frequency = IRDA_SIRC_CARRIER_FREQUENCY,
.duty_cycle = IRDA_SIRC_DUTY_CYCLE,
.name = "SIRC15",
.address_length = 8,
.command_length = 7,
.frequency = IRDA_SIRC_CARRIER_FREQUENCY,
.duty_cycle = IRDA_SIRC_DUTY_CYCLE,
};
static const IrdaProtocolSpecification irda_sirc20_protocol_specification = {
.name = "SIRC20",
.address_length = 13,
.command_length = 7,
.frequency = IRDA_SIRC_CARRIER_FREQUENCY,
.duty_cycle = IRDA_SIRC_DUTY_CYCLE,
.name = "SIRC20",
.address_length = 13,
.command_length = 7,
.frequency = IRDA_SIRC_CARRIER_FREQUENCY,
.duty_cycle = IRDA_SIRC_DUTY_CYCLE,
};
const IrdaProtocolSpecification* irda_sirc_get_spec(IrdaProtocol protocol) {
if (protocol == IrdaProtocolSIRC)
if(protocol == IrdaProtocolSIRC)
return &irda_sirc_protocol_specification;
else if (protocol == IrdaProtocolSIRC15)
else if(protocol == IrdaProtocolSIRC15)
return &irda_sirc15_protocol_specification;
else if (protocol == IrdaProtocolSIRC20)
else if(protocol == IrdaProtocolSIRC20)
return &irda_sirc20_protocol_specification;
else
return NULL;
}