Welcome to mirror list, hosted at ThFree Co, Russian Federation.

furi-hal-irda.h « furi-hal-include « targets « firmware - github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00db4b34c17fb1603269b125ad6b07510a4a9789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
 * @file furi-hal-irda.h
 * IRDA HAL API
 */

#pragma once

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

#define IRDA_MAX_FREQUENCY      56000
#define IRDA_MIN_FREQUENCY      10000

typedef enum {
    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 */
} FuriHalIrdaTxGetDataState;

/** Callback type for providing data to IRDA DMA TX system. It is called every tim */
typedef FuriHalIrdaTxGetDataState (*FuriHalIrdaTxGetDataISRCallback) (void* context, uint32_t* duration, bool* level);

/** 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.
 */
typedef void (*FuriHalIrdaTxSignalSentISRCallback) (void* context);

/** Signature of callback function for receiving continuous IRDA rx signal.
 *
 * @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
 */
typedef void (*FuriHalIrdaRxCaptureCallback)(void* ctx, bool level, uint32_t duration);

/** Signature of callback function for reaching silence timeout on IRDA port.
 *
 * @param      ctx[in]  context to pass to callback
 */
typedef void (*FuriHalIrdaRxTimeoutCallback)(void* ctx);

/** Initialize IRDA RX timer to receive interrupts.
 *
 * It provides interrupts for every RX-signal edge changing with its duration.
 */
void furi_hal_irda_async_rx_start(void);

/** Deinitialize IRDA RX interrupt.
 */
void furi_hal_irda_async_rx_stop(void);

/** Setup hal for receiving silence timeout.
 *
 * Should be used with 'furi_hal_irda_timeout_irq_set_callback()'.
 *
 * @param[in]  timeout_us  time to wait for silence on IRDA port before
 *                         generating IRQ.
 */
void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us);

/** Setup callback for previously initialized IRDA RX interrupt.
 *
 * @param[in]  callback  callback to call when RX signal edge changing occurs
 * @param[in]  ctx       context for callback
 */
void furi_hal_irda_async_rx_set_capture_isr_callback(FuriHalIrdaRxCaptureCallback callback, void *ctx);

/** Setup callback for reaching silence timeout on IRDA port.
 *
 * Should setup hal with 'furi_hal_irda_setup_rx_timeout_irq()' first.
 *
 * @param[in]  callback  callback for silence timeout
 * @param[in]  ctx       context to pass to callback
 */
void furi_hal_irda_async_rx_set_timeout_isr_callback(FuriHalIrdaRxTimeoutCallback callback, void *ctx);

/** Check if IRDA is in use now.
 *
 * @return     true if IRDA is busy, false otherwise.
 */
bool furi_hal_irda_is_busy(void);

/** Set callback providing new data.
 *
 * This function has to be called before furi_hal_irda_async_tx_start().
 *
 * @param[in]  callback  function to provide new data
 * @param[in]  context   context for callback
 */
void furi_hal_irda_async_tx_set_data_isr_callback(FuriHalIrdaTxGetDataISRCallback callback, void* context);

/** 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.
 *
 * Any func (furi_hal_irda_async_tx_stop() or
 * furi_hal_irda_async_tx_wait_termination()) has to be called to wait end of
 * transmission and free resources.
 *
 * @param[in]  freq        frequency for PWM
 * @param[in]  duty_cycle  duty cycle for PWM
 */
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle);

/** Stop IR asynchronous transmission and free resources.
 *
 * Transmission will stop as soon as transmission reaches end of package
 * (FuriHalIrdaTxGetDataStateDone or FuriHalIrdaTxGetDataStateLastDone).
 */
void furi_hal_irda_async_tx_stop(void);

/** Wait for end of IR asynchronous transmission and free resources.
 *
 * Transmission will stop as soon as transmission reaches end of transmission
 * (FuriHalIrdaTxGetDataStateLastDone).
 */
void furi_hal_irda_async_tx_wait_termination(void);

/** Set callback for end of signal transmission
 *
 * @param[in]  callback  function to call when signal is sent
 * @param[in]  context   context for callback
 */
void furi_hal_irda_async_tx_set_signal_sent_isr_callback(FuriHalIrdaTxSignalSentISRCallback callback, void* context);

#ifdef __cplusplus
}
#endif