[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:
115
lib/infrared/encoder_decoder/rc6/infrared_decoder_rc6.c
Normal file
115
lib/infrared/encoder_decoder/rc6/infrared_decoder_rc6.c
Normal file
@@ -0,0 +1,115 @@
|
||||
#include "infrared.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <furi.h>
|
||||
#include "../infrared_i.h"
|
||||
#include "../infrared_protocol_defs_i.h"
|
||||
|
||||
typedef struct {
|
||||
InfraredCommonDecoder* common_decoder;
|
||||
bool toggle;
|
||||
} InfraredRc6Decoder;
|
||||
|
||||
InfraredMessage* infrared_decoder_rc6_check_ready(void* ctx) {
|
||||
InfraredRc6Decoder* decoder_rc6 = ctx;
|
||||
return infrared_common_decoder_check_ready(decoder_rc6->common_decoder);
|
||||
}
|
||||
|
||||
bool infrared_decoder_rc6_interpret(InfraredCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
uint32_t* data = (void*)&decoder->data[0];
|
||||
// MSB first
|
||||
uint8_t address = reverse((uint8_t)(*data >> 5));
|
||||
uint8_t command = reverse((uint8_t)(*data >> 13));
|
||||
bool start_bit = *data & 0x01;
|
||||
bool toggle = !!(*data & 0x10);
|
||||
uint8_t mode = (*data >> 1) & 0x7;
|
||||
|
||||
if((start_bit == 1) && (mode == 0)) {
|
||||
InfraredMessage* message = &decoder->message;
|
||||
InfraredRc6Decoder* rc6_decoder = decoder->context;
|
||||
bool* prev_toggle = &rc6_decoder->toggle;
|
||||
if((message->address == address) && (message->command == command) &&
|
||||
(message->protocol == InfraredProtocolRC6)) {
|
||||
message->repeat = (toggle == *prev_toggle);
|
||||
} else {
|
||||
message->repeat = false;
|
||||
}
|
||||
*prev_toggle = toggle;
|
||||
message->command = command;
|
||||
message->address = address;
|
||||
message->protocol = InfraredProtocolRC6;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* RC6 Uses manchester encoding, but it has twice longer
|
||||
* 4-th bit (toggle bit) time quant, so we need to decode
|
||||
* it separately and than pass decoding for other bits to
|
||||
* common manchester decode function.
|
||||
*/
|
||||
InfraredStatus infrared_decoder_rc6_decode_manchester(
|
||||
InfraredCommonDecoder* decoder,
|
||||
bool level,
|
||||
uint32_t timing) {
|
||||
// 4th bit lasts 2x times more
|
||||
InfraredStatus status = InfraredStatusError;
|
||||
uint16_t bit = decoder->protocol->timings.bit1_mark;
|
||||
uint16_t tolerance = decoder->protocol->timings.bit_tolerance;
|
||||
|
||||
bool single_timing = MATCH_TIMING(timing, bit, tolerance);
|
||||
bool double_timing = MATCH_TIMING(timing, 2 * bit, tolerance);
|
||||
bool triple_timing = MATCH_TIMING(timing, 3 * bit, tolerance);
|
||||
|
||||
if(decoder->databit_cnt == 4) {
|
||||
furi_assert(decoder->switch_detect == true);
|
||||
|
||||
if(single_timing ^ triple_timing) {
|
||||
++decoder->databit_cnt;
|
||||
decoder->data[0] |= (single_timing ? !level : level) << 4;
|
||||
status = InfraredStatusOk;
|
||||
}
|
||||
} else if(decoder->databit_cnt == 5) {
|
||||
if(single_timing || triple_timing) {
|
||||
if(triple_timing) timing = bit;
|
||||
decoder->switch_detect = false;
|
||||
status = infrared_common_decode_manchester(decoder, level, timing);
|
||||
} else if(double_timing) {
|
||||
status = InfraredStatusOk;
|
||||
}
|
||||
} else {
|
||||
status = infrared_common_decode_manchester(decoder, level, timing);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void* infrared_decoder_rc6_alloc(void) {
|
||||
InfraredRc6Decoder* decoder = malloc(sizeof(InfraredRc6Decoder));
|
||||
decoder->toggle = false;
|
||||
decoder->common_decoder = infrared_common_decoder_alloc(&protocol_rc6);
|
||||
decoder->common_decoder->context = decoder;
|
||||
return decoder;
|
||||
}
|
||||
|
||||
InfraredMessage* infrared_decoder_rc6_decode(void* decoder, bool level, uint32_t duration) {
|
||||
InfraredRc6Decoder* decoder_rc6 = decoder;
|
||||
return infrared_common_decode(decoder_rc6->common_decoder, level, duration);
|
||||
}
|
||||
|
||||
void infrared_decoder_rc6_free(void* decoder) {
|
||||
InfraredRc6Decoder* decoder_rc6 = decoder;
|
||||
infrared_common_decoder_free(decoder_rc6->common_decoder);
|
||||
free(decoder_rc6);
|
||||
}
|
||||
|
||||
void infrared_decoder_rc6_reset(void* decoder) {
|
||||
InfraredRc6Decoder* decoder_rc6 = decoder;
|
||||
infrared_common_decoder_reset(decoder_rc6->common_decoder);
|
||||
}
|
61
lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c
Normal file
61
lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "furi/memmgr.h"
|
||||
#include "infrared.h"
|
||||
#include "common/infrared_common_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
#include <stdint.h>
|
||||
#include "../infrared_i.h"
|
||||
|
||||
typedef struct InfraredEncoderRC6 {
|
||||
InfraredCommonEncoder* common_encoder;
|
||||
bool toggle_bit;
|
||||
} InfraredEncoderRC6;
|
||||
|
||||
void infrared_encoder_rc6_reset(void* encoder_ptr, const InfraredMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
InfraredEncoderRC6* encoder = encoder_ptr;
|
||||
InfraredCommonEncoder* common_encoder = encoder->common_encoder;
|
||||
infrared_common_encoder_reset(common_encoder);
|
||||
|
||||
uint32_t* data = (void*)common_encoder->data;
|
||||
*data |= 0x01; // start bit
|
||||
(void)*data; // 3 bits for mode == 0
|
||||
*data |= encoder->toggle_bit ? 0x10 : 0;
|
||||
*data |= reverse(message->address) << 5;
|
||||
*data |= reverse(message->command) << 13;
|
||||
|
||||
common_encoder->bits_to_encode = common_encoder->protocol->databit_len[0];
|
||||
encoder->toggle_bit ^= 1;
|
||||
}
|
||||
|
||||
InfraredStatus infrared_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
||||
InfraredEncoderRC6* encoder = encoder_ptr;
|
||||
return infrared_common_encode(encoder->common_encoder, duration, level);
|
||||
}
|
||||
|
||||
void* infrared_encoder_rc6_alloc(void) {
|
||||
InfraredEncoderRC6* encoder = malloc(sizeof(InfraredEncoderRC6));
|
||||
encoder->common_encoder = infrared_common_encoder_alloc(&protocol_rc6);
|
||||
encoder->toggle_bit = false;
|
||||
return encoder;
|
||||
}
|
||||
|
||||
void infrared_encoder_rc6_free(void* encoder_ptr) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
InfraredEncoderRC6* encoder = encoder_ptr;
|
||||
free(encoder->common_encoder);
|
||||
free(encoder);
|
||||
}
|
||||
|
||||
InfraredStatus infrared_encoder_rc6_encode_manchester(
|
||||
InfraredCommonEncoder* common_encoder,
|
||||
uint32_t* duration,
|
||||
bool* polarity) {
|
||||
InfraredStatus status = InfraredStatusError;
|
||||
|
||||
bool toggle_bit = (common_encoder->bits_encoded == 4);
|
||||
status = infrared_common_encode_manchester(common_encoder, duration, polarity);
|
||||
if(toggle_bit) *duration *= 2;
|
||||
return status;
|
||||
}
|
17
lib/infrared/encoder_decoder/rc6/infrared_rc6_spec.c
Normal file
17
lib/infrared/encoder_decoder/rc6/infrared_rc6_spec.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "../infrared_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
|
||||
static const InfraredProtocolSpecification infrared_rc6_protocol_specification = {
|
||||
.name = "RC6",
|
||||
.address_length = 8,
|
||||
.command_length = 8,
|
||||
.frequency = INFRARED_RC6_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_RC6_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
const InfraredProtocolSpecification* infrared_rc6_get_spec(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolRC6)
|
||||
return &infrared_rc6_protocol_specification;
|
||||
else
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user