[FL-1398] IRDA: Implement timings encoder, add RC-6 (#570)

* Add RC-6 protocol
* Implement timings Encoder
* Remove Unit-tests from build
This commit is contained in:
Albert Kharisov
2021-07-08 21:20:13 +03:00
committed by GitHub
parent 4ce41a3e6f
commit 9f6e14d005
32 changed files with 1563 additions and 489 deletions

View File

@@ -7,14 +7,19 @@
extern "C" {
#endif
typedef struct IrdaHandler IrdaHandler;
#define IRDA_COMMON_CARRIER_FREQUENCY 38000
#define IRDA_COMMON_DUTY_CYCLE 0.33
typedef struct IrdaDecoderHandler IrdaDecoderHandler;
typedef struct IrdaEncoderHandler IrdaEncoderHandler;
// Do not change protocol order, as it can be saved into memory and fw update can be performed!
typedef enum {
IrdaProtocolUnknown = -1,
IrdaProtocolSamsung32 = 0,
IrdaProtocolNEC = 1,
IrdaProtocolNECext = 2,
IrdaProtocolNEC = 0,
IrdaProtocolNECext = 1,
IrdaProtocolSamsung32 = 2,
IrdaProtocolRC6 = 3,
} IrdaProtocol;
typedef struct {
@@ -24,40 +29,45 @@ typedef struct {
bool repeat;
} IrdaMessage;
typedef enum {
IrdaStatusError,
IrdaStatusOk,
IrdaStatusDone,
IrdaStatusReady,
} IrdaStatus;
/**
* Initialize decoder.
*
* \return returns pointer to IRDA decoder handler if success, otherwise - error.
*/
IrdaHandler* irda_alloc_decoder(void);
IrdaDecoderHandler* irda_alloc_decoder(void);
/**
* Provide to decoder next timing. If message is ready, it returns decoded message,
* otherwise NULL.
* Provide to decoder next timing.
*
* \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
* \param[in] handler - handler to IRDA decoders. Should be aquired with \c irda_alloc_decoder().
* \param[in] level - high(true) or low(false) level of input signal to analyze.
* it should alternate every call, otherwise it is an error case,
* and decoder resets its state and start decoding from the start.
* \param[in] duration - duration of steady high/low input signal.
* \return if message is ready, returns pointer to decoded message, returns NULL.
*/
const IrdaMessage* irda_decode(IrdaHandler* handler, bool level, uint32_t duration);
const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t duration);
/**
* Deinitialize decoder and free allocated memory.
*
* \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
* \param[in] handler - handler to IRDA decoders. Should be aquired with \c irda_alloc_decoder().
*/
void irda_free_decoder(IrdaHandler* handler);
void irda_free_decoder(IrdaDecoderHandler* handler);
/**
* Reset IRDA decoder.
*
* \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
* \param[in] handler - handler to IRDA decoders. Should be aquired with \c irda_alloc_decoder().
*/
void irda_reset_decoder(IrdaHandler* handler);
void irda_reset_decoder(IrdaDecoderHandler* handler);
/**
* Send message over IRDA.
@@ -107,6 +117,60 @@ uint8_t irda_get_protocol_command_length(IrdaProtocol protocol);
*/
bool irda_is_protocol_valid(IrdaProtocol protocol);
/**
* Send raw data through infrared port.
*
* \param[in] protocol - use IRDA settings (duty cycle, frequency) from
* this protocol. If provided IrdaProtocolUnknown - use
* default settings.
* \param[in] timings - array of timings to send.
* \param[in] timings_cnt - timings array size.
* \param[in] start_from_mark - true if timings starts from mark,
* otherwise from space
*/
void irda_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool start_from_mark);
/**
* Allocate IRDA encoder.
*
* \return encoder handler.
*/
IrdaEncoderHandler* irda_alloc_encoder(void);
/**
* Free encoder handler previously allocated with \c irda_alloc_encoder().
*
* \param[in] handler - handler to IRDA encoder. Should be aquired with \c irda_alloc_encoder().
*/
void irda_free_encoder(IrdaEncoderHandler* handler);
/**
* Encode previously set IRDA message.
* Usage:
* 1) alloc with \c irda_alloc_encoder()
* 2) set message to encode with \c irda_reset_encoder()
* 3) call for \c irda_encode() to continuously get one at a time timings.
* 4) when \c irda_encode() returns IrdaStatusDone, it means new message is fully encoded.
* 5) to encode additional timings, just continue calling \c irda_encode().
*
* \param[in] handler - handler to IRDA encoder. Should be aquired with \c irda_alloc_encoder().
* \param[out] duration - encoded timing.
* \param[out] level - encoded level.
*
* \return status of encode operation.
*/
IrdaStatus irda_encode(IrdaEncoderHandler* handler, uint32_t* duration, bool* level);
/**
* Reset IRDA encoder and set new message to encode. If it's not called after receiveing
* IrdaStatusDone in \c irda_encode(), encoder will encode repeat messages
* till the end of time.
*
* \param[in] handler - handler to IRDA encoder. Should be aquired with \c irda_alloc_encoder().
* \param[in] message - message to encode.
*/
void irda_reset_encoder(IrdaEncoderHandler* handler, const IrdaMessage* message);
#ifdef __cplusplus
}
#endif