[FL-1156, FL-1249] Add IRDA encoder/decoder library (#451)
* Add cscope db generation * Add api-hal-irda, TIM2: HAL->LL * Add libirda: pwm decoding * Universal state machine * Add irda decoder library * Move IRDA capture to standalone tool * Add encoder/decoder samsung32, NEC, fix bugs * Port current App to new Irda lib * Fix clang format for test data * Port IRDA api-hal to f6 Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
87
lib/irda/samsung/irda_decoder_samsung.c
Normal file
87
lib/irda/samsung/irda_decoder_samsung.c
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <furi.h>
|
||||
#include "../irda_i.h"
|
||||
|
||||
|
||||
static bool interpret_samsung32(IrdaCommonDecoder* decoder);
|
||||
static DecodeStatus decode_repeat_samsung32(IrdaCommonDecoder* decoder);
|
||||
|
||||
|
||||
static const IrdaCommonProtocolSpec protocol_samsung32 = {
|
||||
{
|
||||
IRDA_SAMSUNG_PREAMBULE_MARK,
|
||||
IRDA_SAMSUNG_PREAMBULE_SPACE,
|
||||
IRDA_SAMSUNG_BIT1_MARK,
|
||||
IRDA_SAMSUNG_BIT1_SPACE,
|
||||
IRDA_SAMSUNG_BIT0_MARK,
|
||||
IRDA_SAMSUNG_BIT0_SPACE,
|
||||
IRDA_SAMSUNG_PREAMBLE_TOLERANCE,
|
||||
IRDA_SAMSUNG_BIT_TOLERANCE,
|
||||
},
|
||||
32,
|
||||
irda_common_decode_pdwm,
|
||||
interpret_samsung32,
|
||||
decode_repeat_samsung32,
|
||||
};
|
||||
|
||||
|
||||
static bool interpret_samsung32(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
uint8_t address1 = decoder->data[0];
|
||||
uint8_t address2 = decoder->data[1];
|
||||
uint8_t command = decoder->data[2];
|
||||
uint8_t command_inverse = decoder->data[3];
|
||||
|
||||
if ((address1 == address2) && (command == (uint8_t) ~command_inverse)) {
|
||||
decoder->message.command = command;
|
||||
decoder->message.address = address1;
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// timings start from Space (delay between message and repeat)
|
||||
static DecodeStatus decode_repeat_samsung32(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
|
||||
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
|
||||
DecodeStatus status = DecodeStatusError;
|
||||
|
||||
if (decoder->timings_cnt < 6)
|
||||
return DecodeStatusOk;
|
||||
|
||||
if ((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN)
|
||||
&& (decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX)
|
||||
&& MATCH_PREAMBLE_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance)
|
||||
&& MATCH_PREAMBLE_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance)
|
||||
&& MATCH_BIT_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)
|
||||
&& MATCH_BIT_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance)
|
||||
&& MATCH_BIT_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)
|
||||
) {
|
||||
status = DecodeStatusReady;
|
||||
decoder->timings_cnt = 0;
|
||||
} else {
|
||||
status = DecodeStatusError;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void* irda_decoder_samsung32_alloc(void) {
|
||||
return irda_common_decoder_alloc(&protocol_samsung32);
|
||||
}
|
||||
|
||||
IrdaMessage* irda_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration) {
|
||||
return irda_common_decode(decoder, level, duration);
|
||||
}
|
||||
|
||||
void irda_decoder_samsung32_free(void* decoder) {
|
||||
irda_common_decoder_free(decoder);
|
||||
}
|
||||
|
44
lib/irda/samsung/irda_encoder_samsung.c
Normal file
44
lib/irda/samsung/irda_encoder_samsung.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdint.h>
|
||||
#include "../irda_i.h"
|
||||
|
||||
|
||||
static const IrdaEncoderTimings encoder_timings = {
|
||||
.bit1_mark = IRDA_SAMSUNG_BIT1_MARK,
|
||||
.bit1_space = IRDA_SAMSUNG_BIT1_SPACE,
|
||||
.bit0_mark =IRDA_SAMSUNG_BIT0_MARK,
|
||||
.bit0_space = IRDA_SAMSUNG_BIT0_SPACE,
|
||||
.duty_cycle = IRDA_SAMSUNG_DUTY_CYCLE,
|
||||
.carrier_frequency = IRDA_SAMSUNG_CARRIER_FREQUENCY,
|
||||
};
|
||||
|
||||
|
||||
static void irda_encode_samsung32_preamble(void) {
|
||||
irda_encode_mark(&encoder_timings, IRDA_SAMSUNG_PREAMBULE_MARK);
|
||||
irda_encode_space(&encoder_timings, IRDA_SAMSUNG_PREAMBULE_SPACE);
|
||||
}
|
||||
|
||||
static void irda_encode_samsung32_repeat(void) {
|
||||
irda_encode_space(&encoder_timings, IRDA_SAMSUNG_REPEAT_PAUSE);
|
||||
irda_encode_mark(&encoder_timings, IRDA_SAMSUNG_REPEAT_MARK);
|
||||
irda_encode_space(&encoder_timings, IRDA_SAMSUNG_REPEAT_SPACE);
|
||||
irda_encode_bit(&encoder_timings, 1);
|
||||
irda_encode_bit(&encoder_timings, 1);
|
||||
}
|
||||
|
||||
void irda_encoder_samsung32_encode(uint32_t addr, uint32_t cmd, bool repeat) {
|
||||
uint8_t address = addr & 0xFF;
|
||||
uint8_t command = cmd & 0xFF;
|
||||
uint8_t command_inverse = (uint8_t) ~command;
|
||||
|
||||
if (!repeat) {
|
||||
irda_encode_samsung32_preamble();
|
||||
irda_encode_byte(&encoder_timings, address);
|
||||
irda_encode_byte(&encoder_timings, address);
|
||||
irda_encode_byte(&encoder_timings, command);
|
||||
irda_encode_byte(&encoder_timings, command_inverse);
|
||||
irda_encode_bit(&encoder_timings, 1);
|
||||
} else {
|
||||
irda_encode_samsung32_repeat();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user