[FL-2279] IR doxygen, rename irda -> infrared (#1010)
* IR: Doxygen docs, some rename * Rename irda -> infrared * Rollback collateral renames Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
100
lib/infrared/encoder_decoder/nec/infrared_decoder_nec.c
Normal file
100
lib/infrared/encoder_decoder/nec/infrared_decoder_nec.c
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "common/infrared_common_i.h"
|
||||
#include "infrared.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <furi.h>
|
||||
#include "../infrared_i.h"
|
||||
|
||||
InfraredMessage* infrared_decoder_nec_check_ready(void* ctx) {
|
||||
return infrared_common_decoder_check_ready(ctx);
|
||||
}
|
||||
|
||||
bool infrared_decoder_nec_interpret(InfraredCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
|
||||
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)) {
|
||||
decoder->message.protocol = InfraredProtocolNEC;
|
||||
decoder->message.address = address;
|
||||
decoder->message.command = command;
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
} else {
|
||||
decoder->message.protocol = InfraredProtocolNECext;
|
||||
decoder->message.address = decoder->data[0] | (decoder->data[1] << 8);
|
||||
decoder->message.command = decoder->data[2] | (decoder->data[3] << 8);
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
} 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))) {
|
||||
decoder->message.protocol = InfraredProtocolNEC42;
|
||||
decoder->message.address = address;
|
||||
decoder->message.command = command;
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
} else {
|
||||
decoder->message.protocol = InfraredProtocolNEC42ext;
|
||||
decoder->message.address = address | (address_inverse << 13);
|
||||
decoder->message.command = command | (command_inverse << 8);
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// timings start from Space (delay between message and repeat)
|
||||
InfraredStatus infrared_decoder_nec_decode_repeat(InfraredCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
|
||||
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
|
||||
InfraredStatus status = InfraredStatusError;
|
||||
|
||||
if(decoder->timings_cnt < 4) return InfraredStatusOk;
|
||||
|
||||
if((decoder->timings[0] > INFRARED_NEC_REPEAT_PAUSE_MIN) &&
|
||||
(decoder->timings[0] < INFRARED_NEC_REPEAT_PAUSE_MAX) &&
|
||||
MATCH_TIMING(decoder->timings[1], INFRARED_NEC_REPEAT_MARK, preamble_tolerance) &&
|
||||
MATCH_TIMING(decoder->timings[2], INFRARED_NEC_REPEAT_SPACE, preamble_tolerance) &&
|
||||
MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
|
||||
status = InfraredStatusReady;
|
||||
decoder->timings_cnt = 0;
|
||||
} else {
|
||||
status = InfraredStatusError;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void* infrared_decoder_nec_alloc(void) {
|
||||
return infrared_common_decoder_alloc(&protocol_nec);
|
||||
}
|
||||
|
||||
InfraredMessage* infrared_decoder_nec_decode(void* decoder, bool level, uint32_t duration) {
|
||||
return infrared_common_decode(decoder, level, duration);
|
||||
}
|
||||
|
||||
void infrared_decoder_nec_free(void* decoder) {
|
||||
infrared_common_decoder_free(decoder);
|
||||
}
|
||||
|
||||
void infrared_decoder_nec_reset(void* decoder) {
|
||||
infrared_common_decoder_reset(decoder);
|
||||
}
|
93
lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c
Normal file
93
lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "furi/check.h"
|
||||
#include "infrared.h"
|
||||
#include "common/infrared_common_i.h"
|
||||
#include <stdint.h>
|
||||
#include "../infrared_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
#include <furi.h>
|
||||
|
||||
static const uint32_t repeat_timings[] = {
|
||||
INFRARED_NEC_REPEAT_PERIOD - INFRARED_NEC_REPEAT_MARK - INFRARED_NEC_REPEAT_SPACE -
|
||||
INFRARED_NEC_BIT1_MARK,
|
||||
INFRARED_NEC_REPEAT_MARK,
|
||||
INFRARED_NEC_REPEAT_SPACE,
|
||||
INFRARED_NEC_BIT1_MARK,
|
||||
};
|
||||
|
||||
void infrared_encoder_nec_reset(void* encoder_ptr, const InfraredMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
furi_assert(message);
|
||||
|
||||
InfraredCommonEncoder* encoder = encoder_ptr;
|
||||
infrared_common_encoder_reset(encoder);
|
||||
|
||||
uint32_t* data1 = (void*)encoder->data;
|
||||
uint32_t* data2 = data1 + 1;
|
||||
if(message->protocol == InfraredProtocolNEC) {
|
||||
uint8_t address = message->address;
|
||||
uint8_t address_inverse = ~address;
|
||||
uint8_t command = message->command;
|
||||
uint8_t command_inverse = ~command;
|
||||
*data1 = address;
|
||||
*data1 |= address_inverse << 8;
|
||||
*data1 |= command << 16;
|
||||
*data1 |= command_inverse << 24;
|
||||
encoder->bits_to_encode = 32;
|
||||
} else if(message->protocol == InfraredProtocolNECext) {
|
||||
*data1 = (uint16_t)message->address;
|
||||
*data1 |= (message->command & 0xFFFF) << 16;
|
||||
encoder->bits_to_encode = 32;
|
||||
} else if(message->protocol == InfraredProtocolNEC42) {
|
||||
/* 13 address + 13 inverse address + 8 command + 8 inv command */
|
||||
*data1 = message->address & 0x1FFFUL;
|
||||
*data1 |= (~message->address & 0x1FFFUL) << 13;
|
||||
*data1 |= ((message->command & 0x3FUL) << 26);
|
||||
*data2 = (message->command & 0xC0UL) >> 6;
|
||||
*data2 |= (~message->command & 0xFFUL) << 2;
|
||||
encoder->bits_to_encode = 42;
|
||||
} else if(message->protocol == InfraredProtocolNEC42ext) {
|
||||
*data1 = message->address & 0x3FFFFFF;
|
||||
*data1 |= ((message->command & 0x3F) << 26);
|
||||
*data2 = (message->command & 0xFFC0) >> 6;
|
||||
encoder->bits_to_encode = 42;
|
||||
} else {
|
||||
furi_assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
InfraredStatus infrared_encoder_nec_encode_repeat(
|
||||
InfraredCommonEncoder* encoder,
|
||||
uint32_t* duration,
|
||||
bool* level) {
|
||||
furi_assert(encoder);
|
||||
|
||||
/* space + 2 timings preambule + payload + stop bit */
|
||||
uint32_t timings_encoded_up_to_repeat = 1 + 2 + encoder->bits_to_encode * 2 + 1;
|
||||
uint32_t repeat_cnt = encoder->timings_encoded - timings_encoded_up_to_repeat;
|
||||
|
||||
furi_assert(encoder->timings_encoded >= timings_encoded_up_to_repeat);
|
||||
|
||||
if(repeat_cnt > 0) {
|
||||
*duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)];
|
||||
} else {
|
||||
*duration = INFRARED_NEC_REPEAT_PERIOD - encoder->timings_sum;
|
||||
}
|
||||
|
||||
*level = repeat_cnt % 2;
|
||||
++encoder->timings_encoded;
|
||||
bool done = (!((repeat_cnt + 1) % COUNT_OF(repeat_timings)));
|
||||
|
||||
return done ? InfraredStatusDone : InfraredStatusOk;
|
||||
}
|
||||
|
||||
void* infrared_encoder_nec_alloc(void) {
|
||||
return infrared_common_encoder_alloc(&protocol_nec);
|
||||
}
|
||||
|
||||
void infrared_encoder_nec_free(void* encoder_ptr) {
|
||||
infrared_common_encoder_free(encoder_ptr);
|
||||
}
|
||||
|
||||
InfraredStatus infrared_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
||||
return infrared_common_encode(encoder_ptr, duration, level);
|
||||
}
|
47
lib/infrared/encoder_decoder/nec/infrared_nec_spec.c
Normal file
47
lib/infrared/encoder_decoder/nec/infrared_nec_spec.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "../infrared_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
|
||||
static const InfraredProtocolSpecification infrared_nec_protocol_specification = {
|
||||
.name = "NEC",
|
||||
.address_length = 8,
|
||||
.command_length = 8,
|
||||
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
static const InfraredProtocolSpecification infrared_necext_protocol_specification = {
|
||||
.name = "NECext",
|
||||
.address_length = 16,
|
||||
.command_length = 16,
|
||||
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
static const InfraredProtocolSpecification infrared_nec42_protocol_specification = {
|
||||
.name = "NEC42",
|
||||
.address_length = 13,
|
||||
.command_length = 8,
|
||||
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
static const InfraredProtocolSpecification infrared_nec42ext_protocol_specification = {
|
||||
.name = "NEC42ext",
|
||||
.address_length = 26,
|
||||
.command_length = 16,
|
||||
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
const InfraredProtocolSpecification* infrared_nec_get_spec(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolNEC)
|
||||
return &infrared_nec_protocol_specification;
|
||||
else if(protocol == InfraredProtocolNECext)
|
||||
return &infrared_necext_protocol_specification;
|
||||
else if(protocol == InfraredProtocolNEC42)
|
||||
return &infrared_nec42_protocol_specification;
|
||||
else if(protocol == InfraredProtocolNEC42ext)
|
||||
return &infrared_nec42ext_protocol_specification;
|
||||
else
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user