2021-10-03 13:36:05 +03:00
|
|
|
/**
|
|
|
|
* @file furi-hal-irda.h
|
|
|
|
* IRDA HAL API
|
|
|
|
*/
|
|
|
|
|
2021-05-18 13:51:00 +03:00
|
|
|
#pragma once
|
2021-10-03 13:36:05 +03:00
|
|
|
|
2021-05-18 13:51:00 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2021-08-06 00:11:35 +03:00
|
|
|
#include <stddef.h>
|
2021-05-18 13:51:00 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-08-19 03:18:42 +03:00
|
|
|
#define IRDA_MAX_FREQUENCY 56000
|
|
|
|
#define IRDA_MIN_FREQUENCY 10000
|
|
|
|
|
2021-08-06 00:11:35 +03:00
|
|
|
typedef enum {
|
2021-10-03 13:36:05 +03:00
|
|
|
FuriHalIrdaTxGetDataStateOk, /**< New data obtained */
|
|
|
|
FuriHalIrdaTxGetDataStateDone, /**< New data obtained, and this is end of package */
|
|
|
|
FuriHalIrdaTxGetDataStateLastDone, /**< New data obtained, and this is end of package and no more data available */
|
2021-08-08 21:03:25 +03:00
|
|
|
} FuriHalIrdaTxGetDataState;
|
2021-08-06 00:11:35 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Callback type for providing data to IRDA DMA TX system. It is called every tim */
|
2021-08-11 20:51:06 +03:00
|
|
|
typedef FuriHalIrdaTxGetDataState (*FuriHalIrdaTxGetDataISRCallback) (void* context, uint32_t* duration, bool* level);
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Callback type called every time signal is sent by DMA to Timer.
|
|
|
|
*
|
|
|
|
* Actually, it means there are 2 timings left to send for this signal, which is
|
|
|
|
* almost end. Don't use this callback to stop transmission, as far as there are
|
|
|
|
* next signal is charged for transmission by DMA.
|
2021-08-11 20:51:06 +03:00
|
|
|
*/
|
|
|
|
typedef void (*FuriHalIrdaTxSignalSentISRCallback) (void* context);
|
2021-08-06 00:11:35 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Signature of callback function for receiving continuous IRDA rx signal.
|
2021-05-18 13:51:00 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param ctx[in] context to pass to callback
|
|
|
|
* @param level[in] level of input IRDA rx signal
|
|
|
|
* @param duration[in] duration of continuous rx signal level in us
|
2021-05-18 13:51:00 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
typedef void (*FuriHalIrdaRxCaptureCallback)(void* ctx, bool level, uint32_t duration);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Signature of callback function for reaching silence timeout on IRDA port.
|
2021-07-16 19:43:54 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param ctx[in] context to pass to callback
|
2021-07-16 19:43:54 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
typedef void (*FuriHalIrdaRxTimeoutCallback)(void* ctx);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Initialize IRDA RX timer to receive interrupts.
|
|
|
|
*
|
|
|
|
* It provides interrupts for every RX-signal edge changing with its duration.
|
2021-05-18 13:51:00 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_irda_async_rx_start(void);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Deinitialize IRDA RX interrupt.
|
2021-05-18 13:51:00 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_irda_async_rx_stop(void);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-08-11 20:51:06 +03:00
|
|
|
/** Setup hal for receiving silence timeout.
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
2021-08-08 21:03:25 +03:00
|
|
|
* Should be used with 'furi_hal_irda_timeout_irq_set_callback()'.
|
2021-07-16 19:43:54 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param[in] timeout_us time to wait for silence on IRDA port before
|
|
|
|
* generating IRQ.
|
2021-07-16 19:43:54 +03:00
|
|
|
*/
|
2021-08-11 20:51:06 +03:00
|
|
|
void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us);
|
2021-07-16 19:43:54 +03:00
|
|
|
|
2021-08-11 20:51:06 +03:00
|
|
|
/** Setup callback for previously initialized IRDA RX interrupt.
|
2021-05-18 13:51:00 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param[in] callback callback to call when RX signal edge changing occurs
|
|
|
|
* @param[in] ctx context for callback
|
2021-07-16 19:43:54 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_irda_async_rx_set_capture_isr_callback(FuriHalIrdaRxCaptureCallback callback, void *ctx);
|
2021-07-16 19:43:54 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Setup callback for reaching silence timeout on IRDA port.
|
|
|
|
*
|
2021-08-11 20:51:06 +03:00
|
|
|
* Should setup hal with 'furi_hal_irda_setup_rx_timeout_irq()' first.
|
2021-07-16 19:43:54 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param[in] callback callback for silence timeout
|
|
|
|
* @param[in] ctx context to pass to callback
|
2021-05-18 13:51:00 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_irda_async_rx_set_timeout_isr_callback(FuriHalIrdaRxTimeoutCallback callback, void *ctx);
|
2021-08-06 00:11:35 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Check if IRDA is in use now.
|
|
|
|
*
|
|
|
|
* @return true if IRDA is busy, false otherwise.
|
2021-08-06 00:11:35 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
bool furi_hal_irda_is_busy(void);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Set callback providing new data.
|
|
|
|
*
|
|
|
|
* This function has to be called before furi_hal_irda_async_tx_start().
|
2021-05-18 13:51:00 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param[in] callback function to provide new data
|
|
|
|
* @param[in] context context for callback
|
2021-05-18 13:51:00 +03:00
|
|
|
*/
|
2021-08-11 20:51:06 +03:00
|
|
|
void furi_hal_irda_async_tx_set_data_isr_callback(FuriHalIrdaTxGetDataISRCallback callback, void* context);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Start IR asynchronous transmission.
|
|
|
|
*
|
|
|
|
* It can be stopped by 2 reasons:
|
|
|
|
* 1. implicit call for furi_hal_irda_async_tx_stop()
|
|
|
|
* 2. callback can provide FuriHalIrdaTxGetDataStateLastDone response which
|
|
|
|
* means no more data available for transmission.
|
2021-08-06 00:11:35 +03:00
|
|
|
*
|
2021-08-08 21:03:25 +03:00
|
|
|
* Any func (furi_hal_irda_async_tx_stop() or
|
2021-10-03 13:36:05 +03:00
|
|
|
* furi_hal_irda_async_tx_wait_termination()) has to be called to wait end of
|
|
|
|
* transmission and free resources.
|
2021-08-06 00:11:35 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param[in] freq frequency for PWM
|
|
|
|
* @param[in] duty_cycle duty cycle for PWM
|
2021-05-18 13:51:00 +03:00
|
|
|
*/
|
2021-08-19 03:18:42 +03:00
|
|
|
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle);
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Stop IR asynchronous transmission and free resources.
|
|
|
|
*
|
|
|
|
* Transmission will stop as soon as transmission reaches end of package
|
|
|
|
* (FuriHalIrdaTxGetDataStateDone or FuriHalIrdaTxGetDataStateLastDone).
|
2021-08-06 00:11:35 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_irda_async_tx_stop(void);
|
2021-08-06 00:11:35 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Wait for end of IR asynchronous transmission and free resources.
|
|
|
|
*
|
|
|
|
* Transmission will stop as soon as transmission reaches end of transmission
|
|
|
|
* (FuriHalIrdaTxGetDataStateLastDone).
|
2021-06-09 16:04:49 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_irda_async_tx_wait_termination(void);
|
2021-06-09 16:04:49 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Set callback for end of signal transmission
|
2021-08-11 20:51:06 +03:00
|
|
|
*
|
2021-10-03 13:36:05 +03:00
|
|
|
* @param[in] callback function to call when signal is sent
|
|
|
|
* @param[in] context context for callback
|
2021-08-11 20:51:06 +03:00
|
|
|
*/
|
|
|
|
void furi_hal_irda_async_tx_set_signal_sent_isr_callback(FuriHalIrdaTxSignalSentISRCallback callback, void* context);
|
|
|
|
|
2021-05-18 13:51:00 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|