[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:
82
lib/infrared/encoder_decoder/rc5/infrared_decoder_rc5.c
Normal file
82
lib/infrared/encoder_decoder/rc5/infrared_decoder_rc5.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#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;
|
||||
} InfraredRc5Decoder;
|
||||
|
||||
InfraredMessage* infrared_decoder_rc5_check_ready(void* ctx) {
|
||||
InfraredRc5Decoder* decoder = ctx;
|
||||
return infrared_common_decoder_check_ready(decoder->common_decoder);
|
||||
}
|
||||
|
||||
bool infrared_decoder_rc5_interpret(InfraredCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
uint32_t* data = (void*)&decoder->data[0];
|
||||
/* Manchester (inverse):
|
||||
* 0->1 : 1
|
||||
* 1->0 : 0
|
||||
*/
|
||||
decoder->data[0] = ~decoder->data[0];
|
||||
decoder->data[1] = ~decoder->data[1];
|
||||
|
||||
// MSB first
|
||||
uint8_t address = reverse((uint8_t)decoder->data[0]) & 0x1F;
|
||||
uint8_t command = (reverse((uint8_t)decoder->data[1]) >> 2) & 0x3F;
|
||||
bool start_bit1 = *data & 0x01;
|
||||
bool start_bit2 = *data & 0x02;
|
||||
bool toggle = !!(*data & 0x04);
|
||||
|
||||
if(start_bit1 == 1) {
|
||||
InfraredProtocol protocol = start_bit2 ? InfraredProtocolRC5 : InfraredProtocolRC5X;
|
||||
InfraredMessage* message = &decoder->message;
|
||||
InfraredRc5Decoder* rc5_decoder = decoder->context;
|
||||
bool* prev_toggle = &rc5_decoder->toggle;
|
||||
if((message->address == address) && (message->command == command) &&
|
||||
(message->protocol == protocol)) {
|
||||
message->repeat = (toggle == *prev_toggle);
|
||||
} else {
|
||||
message->repeat = false;
|
||||
}
|
||||
*prev_toggle = toggle;
|
||||
message->command = command;
|
||||
message->address = address;
|
||||
message->protocol = protocol;
|
||||
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void* infrared_decoder_rc5_alloc(void) {
|
||||
InfraredRc5Decoder* decoder = malloc(sizeof(InfraredRc5Decoder));
|
||||
decoder->toggle = false;
|
||||
decoder->common_decoder = infrared_common_decoder_alloc(&protocol_rc5);
|
||||
decoder->common_decoder->context = decoder;
|
||||
return decoder;
|
||||
}
|
||||
|
||||
InfraredMessage* infrared_decoder_rc5_decode(void* decoder, bool level, uint32_t duration) {
|
||||
InfraredRc5Decoder* decoder_rc5 = decoder;
|
||||
return infrared_common_decode(decoder_rc5->common_decoder, level, duration);
|
||||
}
|
||||
|
||||
void infrared_decoder_rc5_free(void* decoder) {
|
||||
InfraredRc5Decoder* decoder_rc5 = decoder;
|
||||
infrared_common_decoder_free(decoder_rc5->common_decoder);
|
||||
free(decoder_rc5);
|
||||
}
|
||||
|
||||
void infrared_decoder_rc5_reset(void* decoder) {
|
||||
InfraredRc5Decoder* decoder_rc5 = decoder;
|
||||
infrared_common_decoder_reset(decoder_rc5->common_decoder);
|
||||
}
|
55
lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c
Normal file
55
lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#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 InfraredEncoderRC5 {
|
||||
InfraredCommonEncoder* common_encoder;
|
||||
bool toggle_bit;
|
||||
} InfraredEncoderRC5;
|
||||
|
||||
void infrared_encoder_rc5_reset(void* encoder_ptr, const InfraredMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
InfraredEncoderRC5* encoder = encoder_ptr;
|
||||
InfraredCommonEncoder* common_encoder = encoder->common_encoder;
|
||||
infrared_common_encoder_reset(common_encoder);
|
||||
|
||||
uint32_t* data = (void*)common_encoder->data;
|
||||
/* RC5 */
|
||||
*data |= 0x01; // start bit
|
||||
if(message->protocol == InfraredProtocolRC5) {
|
||||
*data |= 0x02; // start bit
|
||||
}
|
||||
*data |= encoder->toggle_bit ? 0x04 : 0;
|
||||
*data |= (reverse(message->address) >> 3) << 3; /* address 5 bit */
|
||||
*data |= (reverse(message->command) >> 2) << 8; /* command 6 bit */
|
||||
|
||||
common_encoder->data[0] = ~common_encoder->data[0];
|
||||
common_encoder->data[1] = ~common_encoder->data[1];
|
||||
|
||||
common_encoder->bits_to_encode = common_encoder->protocol->databit_len[0];
|
||||
encoder->toggle_bit ^= 1;
|
||||
}
|
||||
|
||||
InfraredStatus infrared_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
||||
InfraredEncoderRC5* encoder = encoder_ptr;
|
||||
return infrared_common_encode(encoder->common_encoder, duration, level);
|
||||
}
|
||||
|
||||
void* infrared_encoder_rc5_alloc(void) {
|
||||
InfraredEncoderRC5* encoder = malloc(sizeof(InfraredEncoderRC5));
|
||||
encoder->common_encoder = infrared_common_encoder_alloc(&protocol_rc5);
|
||||
encoder->toggle_bit = false;
|
||||
return encoder;
|
||||
}
|
||||
|
||||
void infrared_encoder_rc5_free(void* encoder_ptr) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
InfraredEncoderRC5* encoder = encoder_ptr;
|
||||
free(encoder->common_encoder);
|
||||
free(encoder);
|
||||
}
|
27
lib/infrared/encoder_decoder/rc5/infrared_rc5_spec.c
Normal file
27
lib/infrared/encoder_decoder/rc5/infrared_rc5_spec.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "../infrared_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
|
||||
static const InfraredProtocolSpecification infrared_rc5_protocol_specification = {
|
||||
.name = "RC5",
|
||||
.address_length = 5,
|
||||
.command_length = 6,
|
||||
.frequency = INFRARED_RC5_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_RC5_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
static const InfraredProtocolSpecification infrared_rc5x_protocol_specification = {
|
||||
.name = "RC5X",
|
||||
.address_length = 5,
|
||||
.command_length = 7,
|
||||
.frequency = INFRARED_RC5_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_RC5_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
const InfraredProtocolSpecification* infrared_rc5_get_spec(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolRC5)
|
||||
return &infrared_rc5_protocol_specification;
|
||||
else if(protocol == InfraredProtocolRC5X)
|
||||
return &infrared_rc5x_protocol_specification;
|
||||
else
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user