infrared: add Kaseikyo IR protocol (#1965)
* infrared: add Kaseikyo IR protocol Add Kaseikyo IR protocol support. This protocol is also called the Panasonic protocol and is used by a number of manufacturers including Denon. The protocol includes a vendor field and a number of fields that are vendor specific. To support the format of address+command used by flipper the vendor+genre1+genre2+id fields are encoded into the address while the data is used for the command. There are older versions of the protocol that used a reverse bit order that are not supported. Protocol information: - https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_Kaseikyo.hpp - http://www.hifi-remote.com/johnsfine/DecodeIR.html#Kaseikyo - https://www.denon.com/-/media/files/documentmaster/denonna/avr-x3700h_avc-x3700h_ir_code_v01_04062020.doc * Format and add unit test to Kaseikyo IR codec. Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#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_kaseikyo_check_ready(void* ctx) {
|
||||
return infrared_common_decoder_check_ready(ctx);
|
||||
}
|
||||
|
||||
bool infrared_decoder_kaseikyo_interpret(InfraredCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
uint16_t vendor_id = ((uint16_t)(decoder->data[1]) << 8) | (uint16_t)decoder->data[0];
|
||||
uint8_t vendor_parity = decoder->data[2] & 0x0f;
|
||||
uint8_t genre1 = decoder->data[2] >> 4;
|
||||
uint8_t genre2 = decoder->data[3] & 0x0f;
|
||||
uint16_t data = (uint16_t)(decoder->data[3] >> 4) | ((uint16_t)(decoder->data[4] & 0x3f) << 4);
|
||||
uint8_t id = decoder->data[4] >> 6;
|
||||
uint8_t parity = decoder->data[5];
|
||||
|
||||
uint8_t vendor_parity_check = decoder->data[0] ^ decoder->data[1];
|
||||
vendor_parity_check = (vendor_parity_check & 0xf) ^ (vendor_parity_check >> 4);
|
||||
uint8_t parity_check = decoder->data[2] ^ decoder->data[3] ^ decoder->data[4];
|
||||
|
||||
if(vendor_parity == vendor_parity_check && parity == parity_check) {
|
||||
decoder->message.command = (uint32_t)data;
|
||||
decoder->message.address = ((uint32_t)id << 24) | ((uint32_t)vendor_id << 8) |
|
||||
((uint32_t)genre1 << 4) | (uint32_t)genre2;
|
||||
decoder->message.protocol = InfraredProtocolKaseikyo;
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void* infrared_decoder_kaseikyo_alloc(void) {
|
||||
return infrared_common_decoder_alloc(&protocol_kaseikyo);
|
||||
}
|
||||
|
||||
InfraredMessage* infrared_decoder_kaseikyo_decode(void* decoder, bool level, uint32_t duration) {
|
||||
return infrared_common_decode(decoder, level, duration);
|
||||
}
|
||||
|
||||
void infrared_decoder_kaseikyo_free(void* decoder) {
|
||||
infrared_common_decoder_free(decoder);
|
||||
}
|
||||
|
||||
void infrared_decoder_kaseikyo_reset(void* decoder) {
|
||||
infrared_common_decoder_reset(decoder);
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
#include <core/check.h>
|
||||
#include "common/infrared_common_i.h"
|
||||
#include <stdint.h>
|
||||
#include "../infrared_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
#include <furi.h>
|
||||
|
||||
void infrared_encoder_kaseikyo_reset(void* encoder_ptr, const InfraredMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
InfraredCommonEncoder* encoder = encoder_ptr;
|
||||
infrared_common_encoder_reset(encoder);
|
||||
|
||||
uint32_t address = message->address;
|
||||
uint16_t command = message->command;
|
||||
|
||||
uint8_t id = (address >> 24) & 3;
|
||||
uint16_t vendor_id = (address >> 8) & 0xffff;
|
||||
uint8_t genre1 = (address >> 4) & 0xf;
|
||||
uint8_t genre2 = address & 0xf;
|
||||
|
||||
encoder->data[0] = (uint8_t)(vendor_id & 0xff);
|
||||
encoder->data[1] = (uint8_t)(vendor_id >> 8);
|
||||
uint8_t vendor_parity = encoder->data[0] ^ encoder->data[1];
|
||||
vendor_parity = (vendor_parity & 0xf) ^ (vendor_parity >> 4);
|
||||
encoder->data[2] = (vendor_parity & 0xf) | (genre1 << 4);
|
||||
encoder->data[3] = (genre2 & 0xf) | ((uint8_t)(command & 0xf) << 4);
|
||||
encoder->data[4] = (id << 6) | (uint8_t)(command >> 4);
|
||||
encoder->data[5] = encoder->data[2] ^ encoder->data[3] ^ encoder->data[4];
|
||||
|
||||
encoder->bits_to_encode = encoder->protocol->databit_len[0];
|
||||
}
|
||||
|
||||
void* infrared_encoder_kaseikyo_alloc(void) {
|
||||
return infrared_common_encoder_alloc(&protocol_kaseikyo);
|
||||
}
|
||||
|
||||
void infrared_encoder_kaseikyo_free(void* encoder_ptr) {
|
||||
infrared_common_encoder_free(encoder_ptr);
|
||||
}
|
||||
|
||||
InfraredStatus
|
||||
infrared_encoder_kaseikyo_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
||||
return infrared_common_encode(encoder_ptr, duration, level);
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
#include "../infrared_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
|
||||
static const InfraredProtocolSpecification infrared_kaseikyo_protocol_specification = {
|
||||
.name = "Kaseikyo",
|
||||
.address_length = 26,
|
||||
.command_length = 10,
|
||||
.frequency = INFRARED_COMMON_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_COMMON_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
const InfraredProtocolSpecification* infrared_kaseikyo_get_spec(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolKaseikyo)
|
||||
return &infrared_kaseikyo_protocol_specification;
|
||||
else
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user