[FL-1696, FL-1685] IRDA: Add RC5, decoder refactoring (#663)
* [FL-1696] IRDA: Split decoders and protocols * IRDA: Restruct directories. * IRDA: fix long timings * [FL-1685] IRDA: Add RC5 Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "irda.h"
|
||||
#include "irda_protocol_defs_i.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
@@ -14,27 +15,15 @@ bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) {
|
||||
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) {
|
||||
if (address == (uint8_t) ~address_inverse) {
|
||||
decoder->message.protocol = IrdaProtocolNEC;
|
||||
decoder->message.address = address;
|
||||
} else {
|
||||
decoder->message.protocol = IrdaProtocolNECext;
|
||||
decoder->message.address = decoder->data[0] | (decoder->data[1] << 8);
|
||||
}
|
||||
decoder->message.command = command;
|
||||
decoder->message.address = address;
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Some NEC's extensions allow 16 bit address
|
||||
bool irda_decoder_necext_interpret(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
uint8_t command = decoder->data[2];
|
||||
uint8_t command_inverse = decoder->data[3];
|
||||
|
||||
if(command == (uint8_t)~command_inverse) {
|
||||
decoder->message.command = command;
|
||||
decoder->message.address = decoder->data[0] | (decoder->data[1] << 8);
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
@@ -70,10 +59,6 @@ void* irda_decoder_nec_alloc(void) {
|
||||
return irda_common_decoder_alloc(&protocol_nec);
|
||||
}
|
||||
|
||||
void* irda_decoder_necext_alloc(void) {
|
||||
return irda_common_decoder_alloc(&protocol_necext);
|
||||
}
|
||||
|
||||
IrdaMessage* irda_decoder_nec_decode(void* decoder, bool level, uint32_t duration) {
|
||||
return irda_common_decode(decoder, level, duration);
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "furi/check.h"
|
||||
#include "irda_common_i.h"
|
||||
#include "irda.h"
|
||||
#include "common/irda_common_i.h"
|
||||
#include <stdint.h>
|
||||
#include "../irda_i.h"
|
||||
#include "irda_protocol_defs_i.h"
|
||||
@@ -14,6 +15,7 @@ static const uint32_t repeat_timings[] = {
|
||||
|
||||
void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
furi_assert(message);
|
||||
|
||||
IrdaCommonEncoder* encoder = encoder_ptr;
|
||||
irda_common_encoder_reset(encoder);
|
||||
@@ -24,24 +26,11 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) {
|
||||
uint8_t command_inverse = ~command;
|
||||
|
||||
uint32_t* data = (void*) encoder->data;
|
||||
*data |= address;
|
||||
*data |= address_inverse << 8;
|
||||
*data |= command << 16;
|
||||
*data |= command_inverse << 24;
|
||||
}
|
||||
|
||||
void irda_encoder_necext_reset(void* encoder_ptr, const IrdaMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
IrdaCommonEncoder* encoder = encoder_ptr;
|
||||
irda_common_encoder_reset(encoder);
|
||||
|
||||
uint16_t address = message->address;
|
||||
uint8_t command = message->command;
|
||||
uint8_t command_inverse = ~command;
|
||||
|
||||
uint32_t* data = (void*) encoder->data;
|
||||
*data |= address;
|
||||
if (message->protocol == IrdaProtocolNEC) {
|
||||
*data = (address | (address_inverse << 8));
|
||||
} else if (message->protocol == IrdaProtocolNECext) {
|
||||
*data = (uint16_t) message->address;
|
||||
}
|
||||
*data |= command << 16;
|
||||
*data |= command_inverse << 24;
|
||||
}
|
||||
@@ -67,10 +56,6 @@ IrdaStatus irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t*
|
||||
return done ? IrdaStatusDone : IrdaStatusOk;
|
||||
}
|
||||
|
||||
void* irda_encoder_necext_alloc(void) {
|
||||
return irda_common_encoder_alloc(&protocol_necext);
|
||||
}
|
||||
|
||||
void* irda_encoder_nec_alloc(void) {
|
||||
return irda_common_encoder_alloc(&protocol_nec);
|
||||
}
|
||||
|
28
lib/irda/encoder_decoder/nec/irda_nec_spec.c
Normal file
28
lib/irda/encoder_decoder/nec/irda_nec_spec.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "../irda_i.h"
|
||||
#include "irda_protocol_defs_i.h"
|
||||
|
||||
static const IrdaProtocolSpecification irda_nec_protocol_specification = {
|
||||
.name = "NEC",
|
||||
.address_length = 2,
|
||||
.command_length = 2,
|
||||
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
static const IrdaProtocolSpecification irda_necext_protocol_specification = {
|
||||
.name = "NECext",
|
||||
.address_length = 4,
|
||||
.command_length = 2,
|
||||
.frequency = IRDA_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = IRDA_COMMON_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
const IrdaProtocolSpecification* irda_nec_get_spec(IrdaProtocol protocol) {
|
||||
if (protocol == IrdaProtocolNEC)
|
||||
return &irda_nec_protocol_specification;
|
||||
else if (protocol == IrdaProtocolNECext)
|
||||
return &irda_necext_protocol_specification;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user