mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
Add support for Pioneer SR IR remotes (#3308)
* add support for Pioneer SR IR remotes * fix minor issues * fix repeat * Fix protocol enumeration order * Add unit tests for Pioneer IR protocol * Clean up raw test data * Add encoder/decoder tests, modify parser * Remove dead code * Use loops where appropriate Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com> Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com>
This commit is contained in:
@@ -18,7 +18,6 @@ typedef InfraredStatus (
|
||||
typedef struct {
|
||||
InfraredTimings timings;
|
||||
bool manchester_start_from_space;
|
||||
bool no_stop_bit;
|
||||
uint8_t databit_len[4];
|
||||
InfraredCommonDecode decode;
|
||||
InfraredCommonDecodeRepeat decode_repeat;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "sirc/infrared_protocol_sirc.h"
|
||||
#include "kaseikyo/infrared_protocol_kaseikyo.h"
|
||||
#include "rca/infrared_protocol_rca.h"
|
||||
#include "pioneer/infrared_protocol_pioneer.h"
|
||||
|
||||
typedef struct {
|
||||
InfraredAlloc alloc;
|
||||
@@ -114,6 +115,20 @@ static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
.free = infrared_encoder_sirc_free},
|
||||
.get_protocol_variant = infrared_protocol_sirc_get_variant,
|
||||
},
|
||||
{
|
||||
.decoder =
|
||||
{.alloc = infrared_decoder_pioneer_alloc,
|
||||
.decode = infrared_decoder_pioneer_decode,
|
||||
.reset = infrared_decoder_pioneer_reset,
|
||||
.check_ready = infrared_decoder_pioneer_check_ready,
|
||||
.free = infrared_decoder_pioneer_free},
|
||||
.encoder =
|
||||
{.alloc = infrared_encoder_pioneer_alloc,
|
||||
.encode = infrared_encoder_pioneer_encode,
|
||||
.reset = infrared_encoder_pioneer_reset,
|
||||
.free = infrared_encoder_pioneer_free},
|
||||
.get_protocol_variant = infrared_protocol_pioneer_get_variant,
|
||||
},
|
||||
{
|
||||
.decoder =
|
||||
{.alloc = infrared_decoder_kaseikyo_alloc,
|
||||
|
||||
@@ -34,6 +34,8 @@ typedef enum {
|
||||
InfraredProtocolSIRC20,
|
||||
InfraredProtocolKaseikyo,
|
||||
InfraredProtocolRCA,
|
||||
InfraredProtocolPioneer,
|
||||
/* Add new protocols here */
|
||||
InfraredProtocolMAX,
|
||||
} InfraredProtocol;
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ const InfraredCommonProtocolSpec infrared_protocol_kaseikyo = {
|
||||
.min_split_time = INFRARED_KASEIKYO_MIN_SPLIT_TIME,
|
||||
},
|
||||
.databit_len[0] = 48,
|
||||
.no_stop_bit = false,
|
||||
.decode = infrared_common_decode_pdwm,
|
||||
.encode = infrared_common_encode_pdwm,
|
||||
.interpret = infrared_decoder_kaseikyo_interpret,
|
||||
|
||||
@@ -16,7 +16,6 @@ const InfraredCommonProtocolSpec infrared_protocol_nec = {
|
||||
},
|
||||
.databit_len[0] = 42,
|
||||
.databit_len[1] = 32,
|
||||
.no_stop_bit = false,
|
||||
.decode = infrared_common_decode_pdwm,
|
||||
.encode = infrared_common_encode_pdwm,
|
||||
.interpret = infrared_decoder_nec_interpret,
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "infrared_protocol_pioneer_i.h"
|
||||
#include <core/check.h>
|
||||
|
||||
InfraredMessage* infrared_decoder_pioneer_check_ready(void* ctx) {
|
||||
return infrared_common_decoder_check_ready(ctx);
|
||||
}
|
||||
|
||||
bool infrared_decoder_pioneer_interpret(InfraredCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
uint32_t* data = (void*)&decoder->data[0];
|
||||
uint8_t address = 0;
|
||||
uint8_t command = 0;
|
||||
InfraredProtocol protocol = InfraredProtocolUnknown;
|
||||
|
||||
if(decoder->databit_cnt == decoder->protocol->databit_len[0] ||
|
||||
decoder->databit_cnt == decoder->protocol->databit_len[1]) {
|
||||
address = *data & 0xFF;
|
||||
uint8_t real_address_checksum = ~address;
|
||||
uint8_t address_checksum = (*data >> 8) & 0xFF;
|
||||
command = (*data >> 16) & 0xFF;
|
||||
uint8_t real_command_checksum = ~command;
|
||||
uint8_t command_checksum = (*data >> 24) & 0xFF;
|
||||
if(address_checksum != real_address_checksum) {
|
||||
return false;
|
||||
}
|
||||
if(command_checksum != real_command_checksum) {
|
||||
return false;
|
||||
}
|
||||
protocol = InfraredProtocolPioneer;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
decoder->message.protocol = protocol;
|
||||
decoder->message.address = address;
|
||||
decoder->message.command = command;
|
||||
decoder->message.repeat = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void* infrared_decoder_pioneer_alloc(void) {
|
||||
return infrared_common_decoder_alloc(&infrared_protocol_pioneer);
|
||||
}
|
||||
|
||||
InfraredMessage* infrared_decoder_pioneer_decode(void* decoder, bool level, uint32_t duration) {
|
||||
return infrared_common_decode(decoder, level, duration);
|
||||
}
|
||||
|
||||
void infrared_decoder_pioneer_free(void* decoder) {
|
||||
infrared_common_decoder_free(decoder);
|
||||
}
|
||||
|
||||
void infrared_decoder_pioneer_reset(void* decoder) {
|
||||
infrared_common_decoder_reset(decoder);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "infrared_protocol_pioneer_i.h"
|
||||
#include <core/check.h>
|
||||
|
||||
void infrared_encoder_pioneer_reset(void* encoder_ptr, const InfraredMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
furi_assert(message);
|
||||
|
||||
InfraredCommonEncoder* encoder = encoder_ptr;
|
||||
infrared_common_encoder_reset(encoder);
|
||||
|
||||
uint8_t* data = encoder->data;
|
||||
|
||||
if(message->protocol == InfraredProtocolPioneer) {
|
||||
data[0] = message->address & 0xFF;
|
||||
data[1] = ~(message->address & 0xFF);
|
||||
data[2] = message->command & 0xFF;
|
||||
data[3] = ~(message->command & 0xFF);
|
||||
data[4] = 0;
|
||||
encoder->bits_to_encode = encoder->protocol->databit_len[0];
|
||||
} else {
|
||||
furi_crash();
|
||||
}
|
||||
}
|
||||
|
||||
void* infrared_encoder_pioneer_alloc(void) {
|
||||
return infrared_common_encoder_alloc(&infrared_protocol_pioneer);
|
||||
}
|
||||
|
||||
void infrared_encoder_pioneer_free(void* encoder_ptr) {
|
||||
infrared_common_encoder_free(encoder_ptr);
|
||||
}
|
||||
|
||||
InfraredStatus infrared_encoder_pioneer_encode_repeat(
|
||||
InfraredCommonEncoder* encoder,
|
||||
uint32_t* duration,
|
||||
bool* level) {
|
||||
furi_assert(encoder);
|
||||
|
||||
*duration = INFRARED_PIONEER_SILENCE;
|
||||
*level = false;
|
||||
|
||||
encoder->timings_sum = 0;
|
||||
encoder->timings_encoded = 1;
|
||||
encoder->bits_encoded = 0;
|
||||
encoder->state = InfraredCommonEncoderStatePreamble;
|
||||
|
||||
return InfraredStatusOk;
|
||||
}
|
||||
|
||||
InfraredStatus
|
||||
infrared_encoder_pioneer_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
||||
InfraredCommonEncoder* encoder = encoder_ptr;
|
||||
|
||||
InfraredStatus status = infrared_common_encode(encoder, duration, level);
|
||||
if((status == InfraredStatusOk) && (encoder->bits_encoded == encoder->bits_to_encode)) {
|
||||
furi_assert(!*level);
|
||||
status = InfraredStatusDone;
|
||||
encoder->state = InfraredCommonEncoderStateEncodeRepeat;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "infrared_protocol_pioneer_i.h"
|
||||
|
||||
const InfraredCommonProtocolSpec infrared_protocol_pioneer = {
|
||||
.timings =
|
||||
{
|
||||
.preamble_mark = INFRARED_PIONEER_PREAMBLE_MARK,
|
||||
.preamble_space = INFRARED_PIONEER_PREAMBLE_SPACE,
|
||||
.bit1_mark = INFRARED_PIONEER_BIT1_MARK,
|
||||
.bit1_space = INFRARED_PIONEER_BIT1_SPACE,
|
||||
.bit0_mark = INFRARED_PIONEER_BIT0_MARK,
|
||||
.bit0_space = INFRARED_PIONEER_BIT0_SPACE,
|
||||
.preamble_tolerance = INFRARED_PIONEER_PREAMBLE_TOLERANCE,
|
||||
.bit_tolerance = INFRARED_PIONEER_BIT_TOLERANCE,
|
||||
.silence_time = INFRARED_PIONEER_SILENCE,
|
||||
.min_split_time = INFRARED_PIONEER_MIN_SPLIT_TIME,
|
||||
},
|
||||
.databit_len[0] = 33,
|
||||
.databit_len[1] = 32,
|
||||
.decode = infrared_common_decode_pdwm,
|
||||
.encode = infrared_common_encode_pdwm,
|
||||
.interpret = infrared_decoder_pioneer_interpret,
|
||||
.decode_repeat = NULL,
|
||||
.encode_repeat = infrared_encoder_pioneer_encode_repeat,
|
||||
};
|
||||
|
||||
static const InfraredProtocolVariant infrared_protocol_variant_pioneer = {
|
||||
.name = "Pioneer",
|
||||
.address_length = 8,
|
||||
.command_length = 8,
|
||||
.frequency = INFRARED_PIONEER_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_PIONEER_DUTY_CYCLE,
|
||||
.repeat_count = INFRARED_PIONEER_REPEAT_COUNT_MIN,
|
||||
};
|
||||
|
||||
const InfraredProtocolVariant* infrared_protocol_pioneer_get_variant(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolPioneer)
|
||||
return &infrared_protocol_variant_pioneer;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "../infrared_i.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
* Pioneer SR protocol description
|
||||
* http://www.adrian-kingston.com/IRFormatPioneer.htm
|
||||
****************************************************************************************************
|
||||
* Preamble Preamble Pulse Width Modulation Pause Entirely repeat
|
||||
* mark space up to period message..
|
||||
*
|
||||
* 8500 4250 33 bits (500, 1500) ...26000 8500 4250
|
||||
* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ __________ _ _
|
||||
* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________ __________ _
|
||||
*
|
||||
* In 33 bits of data there is:
|
||||
* - 8 bits address
|
||||
* - 8 bits address inverse
|
||||
* - 8 bits command
|
||||
* - 8 bits command inverse
|
||||
* - 1 stop bit
|
||||
***************************************************************************************************/
|
||||
|
||||
void* infrared_decoder_pioneer_alloc(void);
|
||||
void infrared_decoder_pioneer_reset(void* decoder);
|
||||
InfraredMessage* infrared_decoder_pioneer_check_ready(void* decoder);
|
||||
void infrared_decoder_pioneer_free(void* decoder);
|
||||
InfraredMessage* infrared_decoder_pioneer_decode(void* decoder, bool level, uint32_t duration);
|
||||
|
||||
void* infrared_encoder_pioneer_alloc(void);
|
||||
void infrared_encoder_pioneer_reset(void* encoder_ptr, const InfraredMessage* message);
|
||||
void infrared_encoder_pioneer_free(void* decoder);
|
||||
InfraredStatus
|
||||
infrared_encoder_pioneer_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
|
||||
|
||||
const InfraredProtocolVariant* infrared_protocol_pioneer_get_variant(InfraredProtocol protocol);
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "../common/infrared_common_i.h"
|
||||
|
||||
#define INFRARED_PIONEER_CARRIER_FREQUENCY 40000
|
||||
#define INFRARED_PIONEER_DUTY_CYCLE 0.33
|
||||
#define INFRARED_PIONEER_PREAMBLE_MARK 8500
|
||||
#define INFRARED_PIONEER_PREAMBLE_SPACE 4225
|
||||
#define INFRARED_PIONEER_BIT1_MARK 500
|
||||
#define INFRARED_PIONEER_BIT1_SPACE 1500
|
||||
#define INFRARED_PIONEER_BIT0_MARK 500
|
||||
#define INFRARED_PIONEER_BIT0_SPACE 500
|
||||
#define INFRARED_PIONEER_PREAMBLE_TOLERANCE 200 // us
|
||||
#define INFRARED_PIONEER_BIT_TOLERANCE 120 // us
|
||||
#define INFRARED_PIONEER_SILENCE 26000
|
||||
#define INFRARED_PIONEER_MIN_SPLIT_TIME (INFRARED_PIONEER_SILENCE)
|
||||
#define INFRARED_PIONEER_REPEAT_COUNT_MIN 2
|
||||
|
||||
extern const InfraredCommonProtocolSpec infrared_protocol_pioneer;
|
||||
|
||||
bool infrared_decoder_pioneer_interpret(InfraredCommonDecoder* decoder);
|
||||
InfraredStatus infrared_encoder_pioneer_encode_repeat(
|
||||
InfraredCommonEncoder* encoder,
|
||||
uint32_t* duration,
|
||||
bool* level);
|
||||
@@ -15,7 +15,6 @@ const InfraredCommonProtocolSpec infrared_protocol_rca = {
|
||||
.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,
|
||||
|
||||
@@ -15,7 +15,6 @@ const InfraredCommonProtocolSpec infrared_protocol_samsung32 = {
|
||||
.min_split_time = INFRARED_SAMSUNG_MIN_SPLIT_TIME,
|
||||
},
|
||||
.databit_len[0] = 32,
|
||||
.no_stop_bit = false,
|
||||
.decode = infrared_common_decode_pdwm,
|
||||
.encode = infrared_common_encode_pdwm,
|
||||
.interpret = infrared_decoder_samsung32_interpret,
|
||||
|
||||
@@ -17,7 +17,6 @@ const InfraredCommonProtocolSpec infrared_protocol_sirc = {
|
||||
.databit_len[0] = 20,
|
||||
.databit_len[1] = 15,
|
||||
.databit_len[2] = 12,
|
||||
.no_stop_bit = true,
|
||||
.decode = infrared_common_decode_pdwm,
|
||||
.encode = infrared_common_encode_pdwm,
|
||||
.interpret = infrared_decoder_sirc_interpret,
|
||||
|
||||
Reference in New Issue
Block a user