2021-09-09 21:37:32 +00:00
|
|
|
#include "furi/check.h"
|
|
|
|
#include "irda.h"
|
|
|
|
#include "common/irda_common_i.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "../irda_i.h"
|
|
|
|
#include "irda_protocol_defs_i.h"
|
|
|
|
#include <furi.h>
|
|
|
|
|
|
|
|
void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message) {
|
|
|
|
furi_assert(encoder_ptr);
|
|
|
|
furi_assert(message);
|
|
|
|
|
|
|
|
IrdaCommonEncoder* encoder = encoder_ptr;
|
|
|
|
irda_common_encoder_reset(encoder);
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
uint32_t* data = (void*)encoder->data;
|
2021-09-09 21:37:32 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
if(message->protocol == IrdaProtocolSIRC) {
|
2021-09-09 21:37:32 +00:00
|
|
|
*data = (message->command & 0x7F);
|
|
|
|
*data |= (message->address & 0x1F) << 7;
|
2021-09-15 17:22:58 +00:00
|
|
|
encoder->bits_to_encode = 12;
|
2022-01-05 16:10:18 +00:00
|
|
|
} else if(message->protocol == IrdaProtocolSIRC15) {
|
2021-09-09 21:37:32 +00:00
|
|
|
*data = (message->command & 0x7F);
|
|
|
|
*data |= (message->address & 0xFF) << 7;
|
2021-09-15 17:22:58 +00:00
|
|
|
encoder->bits_to_encode = 15;
|
2022-01-05 16:10:18 +00:00
|
|
|
} else if(message->protocol == IrdaProtocolSIRC20) {
|
2021-09-09 21:37:32 +00:00
|
|
|
*data = (message->command & 0x7F);
|
|
|
|
*data |= (message->address & 0x1FFF) << 7;
|
2021-09-15 17:22:58 +00:00
|
|
|
encoder->bits_to_encode = 20;
|
2021-09-09 21:37:32 +00:00
|
|
|
} else {
|
|
|
|
furi_assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
IrdaStatus
|
|
|
|
irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
|
2021-09-09 21:37:32 +00:00
|
|
|
furi_assert(encoder);
|
|
|
|
|
2021-09-24 11:56:27 +00:00
|
|
|
furi_assert(encoder->timings_encoded == (1 + 2 + encoder->bits_to_encode * 2 - 1));
|
2021-09-09 21:37:32 +00:00
|
|
|
|
|
|
|
furi_assert(encoder->timings_sum < IRDA_SIRC_REPEAT_PERIOD);
|
|
|
|
*duration = IRDA_SIRC_REPEAT_PERIOD - encoder->timings_sum;
|
|
|
|
*level = false;
|
|
|
|
|
|
|
|
encoder->timings_sum = 0;
|
|
|
|
encoder->timings_encoded = 1;
|
|
|
|
encoder->bits_encoded = 0;
|
|
|
|
encoder->state = IrdaCommonEncoderStatePreamble;
|
|
|
|
|
|
|
|
return IrdaStatusOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* irda_encoder_sirc_alloc(void) {
|
2021-09-15 17:22:58 +00:00
|
|
|
return irda_common_encoder_alloc(&protocol_sirc);
|
2021-09-09 21:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void irda_encoder_sirc_free(void* encoder_ptr) {
|
2021-09-15 17:22:58 +00:00
|
|
|
irda_common_encoder_free(encoder_ptr);
|
2021-09-09 21:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
|
2021-09-15 17:22:58 +00:00
|
|
|
IrdaCommonEncoder* encoder = encoder_ptr;
|
2021-09-09 21:37:32 +00:00
|
|
|
|
2021-09-15 17:22:58 +00:00
|
|
|
IrdaStatus status = irda_common_encode(encoder, duration, level);
|
2022-01-05 16:10:18 +00:00
|
|
|
if((status == IrdaStatusOk) && (encoder->bits_encoded == encoder->bits_to_encode)) {
|
2021-09-09 21:37:32 +00:00
|
|
|
furi_assert(!*level);
|
|
|
|
status = IrdaStatusDone;
|
2021-09-15 17:22:58 +00:00
|
|
|
encoder->state = IrdaCommonEncoderStateEncodeRepeat;
|
2021-09-09 21:37:32 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|