[FL-1505] Add RAW format (#576)
* Add RAW format * F5 stubs for build to pass * Fix saving decoded signal error * Irda: set ISR before starting timer, remove explicit NVIC configuration Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
88
lib/irda/encoder_decoder/nec/irda_decoder_nec.c
Normal file
88
lib/irda/encoder_decoder/nec/irda_decoder_nec.c
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "irda_protocol_defs_i.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <furi.h>
|
||||
#include "../irda_i.h"
|
||||
|
||||
|
||||
bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
uint8_t address = decoder->data[0];
|
||||
uint8_t address_inverse = decoder->data[1];
|
||||
uint8_t command = decoder->data[2];
|
||||
uint8_t command_inverse = decoder->data[3];
|
||||
|
||||
if ((command == (uint8_t) ~command_inverse) && (address == (uint8_t) ~address_inverse)) {
|
||||
decoder->message.command = command;
|
||||
decoder->message.address = address;
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Some NEC's extensions allow 16 bit address
|
||||
bool irda_decoder_necext_interpret(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
bool result = false;
|
||||
uint8_t command = decoder->data[2];
|
||||
uint8_t command_inverse = decoder->data[3];
|
||||
|
||||
if(command == (uint8_t)~command_inverse) {
|
||||
decoder->message.command = command;
|
||||
decoder->message.address = decoder->data[0] | (decoder->data[1] << 8);
|
||||
decoder->message.repeat = false;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// timings start from Space (delay between message and repeat)
|
||||
IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder) {
|
||||
furi_assert(decoder);
|
||||
|
||||
float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
|
||||
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
|
||||
IrdaStatus status = IrdaStatusError;
|
||||
|
||||
if(decoder->timings_cnt < 4) return IrdaStatusOk;
|
||||
|
||||
if((decoder->timings[0] > IRDA_NEC_REPEAT_PAUSE_MIN) &&
|
||||
(decoder->timings[0] < IRDA_NEC_REPEAT_PAUSE_MAX) &&
|
||||
MATCH_PREAMBLE_TIMING(decoder->timings[1], IRDA_NEC_REPEAT_MARK, preamble_tolerance) &&
|
||||
MATCH_PREAMBLE_TIMING(decoder->timings[2], IRDA_NEC_REPEAT_SPACE, preamble_tolerance) &&
|
||||
MATCH_BIT_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
|
||||
status = IrdaStatusReady;
|
||||
decoder->timings_cnt = 0;
|
||||
} else {
|
||||
status = IrdaStatusError;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void* irda_decoder_nec_alloc(void) {
|
||||
return irda_common_decoder_alloc(&protocol_nec);
|
||||
}
|
||||
|
||||
void* irda_decoder_necext_alloc(void) {
|
||||
return irda_common_decoder_alloc(&protocol_necext);
|
||||
}
|
||||
|
||||
IrdaMessage* irda_decoder_nec_decode(void* decoder, bool level, uint32_t duration) {
|
||||
return irda_common_decode(decoder, level, duration);
|
||||
}
|
||||
|
||||
void irda_decoder_nec_free(void* decoder) {
|
||||
irda_common_decoder_free(decoder);
|
||||
}
|
||||
|
||||
void irda_decoder_nec_reset(void* decoder) {
|
||||
irda_common_decoder_reset(decoder);
|
||||
}
|
||||
|
85
lib/irda/encoder_decoder/nec/irda_encoder_nec.c
Normal file
85
lib/irda/encoder_decoder/nec/irda_encoder_nec.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "furi/check.h"
|
||||
#include "irda_common_i.h"
|
||||
#include <stdint.h>
|
||||
#include "../irda_i.h"
|
||||
#include "irda_protocol_defs_i.h"
|
||||
#include <furi.h>
|
||||
|
||||
static const uint32_t repeat_timings[] = {
|
||||
IRDA_NEC_REPEAT_PAUSE2,
|
||||
IRDA_NEC_REPEAT_MARK,
|
||||
IRDA_NEC_REPEAT_SPACE,
|
||||
IRDA_NEC_BIT1_MARK,
|
||||
};
|
||||
|
||||
void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
IrdaCommonEncoder* encoder = encoder_ptr;
|
||||
irda_common_encoder_reset(encoder);
|
||||
|
||||
uint8_t address = message->address;
|
||||
uint8_t address_inverse = ~address;
|
||||
uint8_t command = message->command;
|
||||
uint8_t command_inverse = ~command;
|
||||
|
||||
uint32_t* data = (void*) encoder->data;
|
||||
*data |= address;
|
||||
*data |= address_inverse << 8;
|
||||
*data |= command << 16;
|
||||
*data |= command_inverse << 24;
|
||||
}
|
||||
|
||||
void irda_encoder_necext_reset(void* encoder_ptr, const IrdaMessage* message) {
|
||||
furi_assert(encoder_ptr);
|
||||
|
||||
IrdaCommonEncoder* encoder = encoder_ptr;
|
||||
irda_common_encoder_reset(encoder);
|
||||
|
||||
uint16_t address = message->address;
|
||||
uint8_t command = message->command;
|
||||
uint8_t command_inverse = ~command;
|
||||
|
||||
uint32_t* data = (void*) encoder->data;
|
||||
*data |= address;
|
||||
*data |= command << 16;
|
||||
*data |= command_inverse << 24;
|
||||
}
|
||||
|
||||
IrdaStatus irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
||||
furi_assert(encoder);
|
||||
|
||||
/* space + 2 timings preambule + payload + stop bit */
|
||||
uint32_t timings_encoded_up_to_repeat = 1 + 2 + encoder->protocol->databit_len * 2 + 1;
|
||||
uint32_t repeat_cnt = encoder->timings_encoded - timings_encoded_up_to_repeat;
|
||||
|
||||
furi_assert(encoder->timings_encoded >= timings_encoded_up_to_repeat);
|
||||
|
||||
if (repeat_cnt > 0)
|
||||
*duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)];
|
||||
else
|
||||
*duration = IRDA_NEC_REPEAT_PAUSE1;
|
||||
|
||||
*level = repeat_cnt % 2;
|
||||
++encoder->timings_encoded;
|
||||
bool done = (!((repeat_cnt + 1) % COUNT_OF(repeat_timings)));
|
||||
|
||||
return done ? IrdaStatusDone : IrdaStatusOk;
|
||||
}
|
||||
|
||||
void* irda_encoder_necext_alloc(void) {
|
||||
return irda_common_encoder_alloc(&protocol_necext);
|
||||
}
|
||||
|
||||
void* irda_encoder_nec_alloc(void) {
|
||||
return irda_common_encoder_alloc(&protocol_nec);
|
||||
}
|
||||
|
||||
void irda_encoder_nec_free(void* encoder_ptr) {
|
||||
irda_common_encoder_free(encoder_ptr);
|
||||
}
|
||||
|
||||
IrdaStatus irda_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
||||
return irda_common_encode(encoder_ptr, duration, level);
|
||||
}
|
||||
|
Reference in New Issue
Block a user