mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 20:49:49 +04:00
Infrared RCA Protocol + Update docs
Thanks to anonymous contributor for protocol implementation and testing
This commit is contained in:
45
lib/infrared/encoder_decoder/rca/infrared_decoder_rca.c
Normal file
45
lib/infrared/encoder_decoder/rca/infrared_decoder_rca.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "infrared_protocol_rca_i.h"
|
||||
#include <core/check.h>
|
||||
|
||||
InfraredMessage* infrared_decoder_rca_check_ready(void* ctx) {
|
||||
return infrared_common_decoder_check_ready(ctx);
|
||||
}
|
||||
|
||||
bool infrared_decoder_rca_interpret(InfraredCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
uint32_t* data = (void*)&decoder->data;
|
||||
|
||||
uint8_t address = (*data & 0xF);
|
||||
uint8_t command = (*data >> 4) & 0xFF;
|
||||
uint8_t address_inverse = (*data >> 12) & 0xF;
|
||||
uint8_t command_inverse = (*data >> 16) & 0xFF;
|
||||
uint8_t inverse_address_inverse = (uint8_t)~address_inverse & 0xF;
|
||||
uint8_t inverse_command_inverse = (uint8_t)~command_inverse;
|
||||
|
||||
if((command == inverse_command_inverse) && (address == inverse_address_inverse)) {
|
||||
decoder->message.protocol = InfraredProtocolRCA;
|
||||
decoder->message.address = address;
|
||||
decoder->message.command = command;
|
||||
decoder->message.repeat = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void* infrared_decoder_rca_alloc(void) {
|
||||
return infrared_common_decoder_alloc(&infrared_protocol_rca);
|
||||
}
|
||||
|
||||
InfraredMessage* infrared_decoder_rca_decode(void* decoder, bool level, uint32_t duration) {
|
||||
return infrared_common_decode(decoder, level, duration);
|
||||
}
|
||||
|
||||
void infrared_decoder_rca_free(void* decoder) {
|
||||
infrared_common_decoder_free(decoder);
|
||||
}
|
||||
|
||||
void infrared_decoder_rca_reset(void* decoder) {
|
||||
infrared_common_decoder_reset(decoder);
|
||||
}
|
||||
37
lib/infrared/encoder_decoder/rca/infrared_encoder_rca.c
Normal file
37
lib/infrared/encoder_decoder/rca/infrared_encoder_rca.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "infrared_protocol_rca_i.h"
|
||||
|
||||
#include <core/check.h>
|
||||
|
||||
void infrared_encoder_rca_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* data = (void*)encoder->data;
|
||||
|
||||
uint8_t address = message->address;
|
||||
uint8_t address_inverse = ~address;
|
||||
uint8_t command = message->command;
|
||||
uint8_t command_inverse = ~command;
|
||||
|
||||
*data = address & 0xF;
|
||||
*data |= command << 4;
|
||||
*data |= (address_inverse & 0xF) << 12;
|
||||
*data |= command_inverse << 16;
|
||||
|
||||
encoder->bits_to_encode = encoder->protocol->databit_len[0];
|
||||
}
|
||||
|
||||
void* infrared_encoder_rca_alloc(void) {
|
||||
return infrared_common_encoder_alloc(&infrared_protocol_rca);
|
||||
}
|
||||
|
||||
void infrared_encoder_rca_free(void* encoder_ptr) {
|
||||
infrared_common_encoder_free(encoder_ptr);
|
||||
}
|
||||
|
||||
InfraredStatus infrared_encoder_rca_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
||||
return infrared_common_encode(encoder_ptr, duration, level);
|
||||
}
|
||||
40
lib/infrared/encoder_decoder/rca/infrared_protocol_rca.c
Normal file
40
lib/infrared/encoder_decoder/rca/infrared_protocol_rca.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "infrared_protocol_rca_i.h"
|
||||
|
||||
const InfraredCommonProtocolSpec infrared_protocol_rca = {
|
||||
.timings =
|
||||
{
|
||||
.preamble_mark = INFRARED_RCA_PREAMBLE_MARK,
|
||||
.preamble_space = INFRARED_RCA_PREAMBLE_SPACE,
|
||||
.bit1_mark = INFRARED_RCA_BIT1_MARK,
|
||||
.bit1_space = INFRARED_RCA_BIT1_SPACE,
|
||||
.bit0_mark = INFRARED_RCA_BIT0_MARK,
|
||||
.bit0_space = INFRARED_RCA_BIT0_SPACE,
|
||||
.preamble_tolerance = INFRARED_RCA_PREAMBLE_TOLERANCE,
|
||||
.bit_tolerance = INFRARED_RCA_BIT_TOLERANCE,
|
||||
.silence_time = INFRARED_RCA_SILENCE,
|
||||
.min_split_time = INFRARED_RCA_MIN_SPLIT_TIME,
|
||||
},
|
||||
.databit_len[0] = 24,
|
||||
.no_stop_bit = false,
|
||||
.decode = infrared_common_decode_pdwm,
|
||||
.encode = infrared_common_encode_pdwm,
|
||||
.interpret = infrared_decoder_rca_interpret,
|
||||
.decode_repeat = NULL,
|
||||
.encode_repeat = NULL,
|
||||
};
|
||||
|
||||
static const InfraredProtocolVariant infrared_protocol_variant_rca = {
|
||||
.name = "RCA",
|
||||
.address_length = 4,
|
||||
.command_length = 8,
|
||||
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
|
||||
.repeat_count = INFRARED_RCA_REPEAT_COUNT_MIN,
|
||||
};
|
||||
|
||||
const InfraredProtocolVariant* infrared_protocol_rca_get_variant(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolRCA)
|
||||
return &infrared_protocol_variant_rca;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
30
lib/infrared/encoder_decoder/rca/infrared_protocol_rca.h
Normal file
30
lib/infrared/encoder_decoder/rca/infrared_protocol_rca.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "../infrared_i.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
* RCA protocol description
|
||||
* https://www.sbprojects.net/knowledge/ir/rca.php
|
||||
****************************************************************************************************
|
||||
* Preamble Preamble Pulse Distance/Width Pause Preamble Preamble
|
||||
* mark space Modulation up to period repeat repeat
|
||||
* mark space
|
||||
*
|
||||
* 4000 4000 24 bit ...8000 4000 4000
|
||||
* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________
|
||||
* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________ ___________
|
||||
*
|
||||
***************************************************************************************************/
|
||||
|
||||
void* infrared_decoder_rca_alloc(void);
|
||||
void infrared_decoder_rca_reset(void* decoder);
|
||||
void infrared_decoder_rca_free(void* decoder);
|
||||
InfraredMessage* infrared_decoder_rca_check_ready(void* decoder);
|
||||
InfraredMessage* infrared_decoder_rca_decode(void* decoder, bool level, uint32_t duration);
|
||||
|
||||
void* infrared_encoder_rca_alloc(void);
|
||||
InfraredStatus infrared_encoder_rca_encode(void* encoder_ptr, uint32_t* duration, bool* level);
|
||||
void infrared_encoder_rca_reset(void* encoder_ptr, const InfraredMessage* message);
|
||||
void infrared_encoder_rca_free(void* encoder_ptr);
|
||||
|
||||
const InfraredProtocolVariant* infrared_protocol_rca_get_variant(InfraredProtocol protocol);
|
||||
30
lib/infrared/encoder_decoder/rca/infrared_protocol_rca_i.h
Normal file
30
lib/infrared/encoder_decoder/rca/infrared_protocol_rca_i.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "../common/infrared_common_i.h"
|
||||
|
||||
#define INFRARED_RCA_PREAMBLE_MARK 4000
|
||||
#define INFRARED_RCA_PREAMBLE_SPACE 4000
|
||||
#define INFRARED_RCA_BIT1_MARK 500
|
||||
#define INFRARED_RCA_BIT1_SPACE 2000
|
||||
#define INFRARED_RCA_BIT0_MARK 500
|
||||
#define INFRARED_RCA_BIT0_SPACE 1000
|
||||
#define INFRARED_RCA_REPEAT_PERIOD 8000
|
||||
#define INFRARED_RCA_SILENCE INFRARED_RCA_REPEAT_PERIOD
|
||||
|
||||
#define INFRARED_RCA_MIN_SPLIT_TIME INFRARED_RCA_REPEAT_PAUSE_MIN
|
||||
#define INFRARED_RCA_REPEAT_PAUSE_MIN 4000
|
||||
#define INFRARED_RCA_REPEAT_PAUSE_MAX 150000
|
||||
#define INFRARED_RCA_REPEAT_COUNT_MIN 1
|
||||
#define INFRARED_RCA_REPEAT_MARK INFRARED_RCA_PREAMBLE_MARK
|
||||
#define INFRARED_RCA_REPEAT_SPACE INFRARED_RCA_PREAMBLE_SPACE
|
||||
#define INFRARED_RCA_PREAMBLE_TOLERANCE 200 // us
|
||||
#define INFRARED_RCA_BIT_TOLERANCE 120 // us
|
||||
|
||||
extern const InfraredCommonProtocolSpec infrared_protocol_rca;
|
||||
|
||||
bool infrared_decoder_rca_interpret(InfraredCommonDecoder* decoder);
|
||||
InfraredStatus infrared_decoder_rca_decode_repeat(InfraredCommonDecoder* decoder);
|
||||
InfraredStatus infrared_encoder_rca_encode_repeat(
|
||||
InfraredCommonEncoder* encoder,
|
||||
uint32_t* duration,
|
||||
bool* level);
|
||||
Reference in New Issue
Block a user