2021-05-18 10:51:00 +00:00
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2021-08-05 21:11:35 +00:00
|
|
|
#include <stddef.h>
|
2021-05-18 10:51:00 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-08-05 21:11:35 +00:00
|
|
|
typedef enum {
|
|
|
|
ApiHalIrdaTxGetDataStateError, /* An error occured during transmission */
|
|
|
|
ApiHalIrdaTxGetDataStateOk, /* New data obtained */
|
|
|
|
ApiHalIrdaTxGetDataStateDone, /* New data obtained, and this is end of package */
|
|
|
|
ApiHalIrdaTxGetDataStateLastDone, /* New data obtained, and this is end of package and no more data available */
|
|
|
|
} ApiHalIrdaTxGetDataState;
|
|
|
|
|
|
|
|
typedef ApiHalIrdaTxGetDataState (*ApiHalIrdaTxGetDataCallback) (void* context, uint32_t* duration, bool* level);
|
|
|
|
|
2021-05-18 10:51:00 +00:00
|
|
|
/**
|
|
|
|
* Signature of callback function for receiving continuous IRDA rx signal.
|
|
|
|
*
|
2021-07-16 16:43:54 +00: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 10:51:00 +00:00
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
typedef void (*ApiHalIrdaRxCaptureCallback)(void* ctx, bool level, uint32_t duration);
|
2021-05-18 10:51:00 +00:00
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
/**
|
|
|
|
* Signature of callback function for reaching silence timeout on IRDA port.
|
|
|
|
*
|
|
|
|
* @param ctx[in] - context to pass to callback
|
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
typedef void (*ApiHalIrdaRxTimeoutCallback)(void* ctx);
|
2021-05-18 10:51:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize IRDA RX timer to receive interrupts.
|
|
|
|
* It provides interrupts for every RX-signal edge changing
|
|
|
|
* with its duration.
|
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
void api_hal_irda_async_rx_start(void);
|
2021-05-18 10:51:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deinitialize IRDA RX interrupt.
|
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
void api_hal_irda_async_rx_stop(void);
|
2021-05-18 10:51:00 +00:00
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
/** Setup api hal for receiving silence timeout.
|
|
|
|
* Should be used with 'api_hal_irda_timeout_irq_set_callback()'.
|
|
|
|
*
|
|
|
|
* @param[in] timeout_ms - time to wait for silence on IRDA port
|
|
|
|
* before generating IRQ.
|
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
void api_hal_irda_async_rx_set_timeout(uint32_t timeout_ms);
|
2021-07-16 16:43:54 +00:00
|
|
|
|
2021-05-18 10:51:00 +00:00
|
|
|
/**
|
|
|
|
* Setup callback for previously initialized IRDA RX interrupt.
|
|
|
|
*
|
2021-07-16 16:43:54 +00:00
|
|
|
* @param[in] callback - callback to call when RX signal edge changing occurs
|
|
|
|
* @param[in] ctx - context for callback
|
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
void api_hal_irda_async_rx_set_capture_isr_callback(ApiHalIrdaRxCaptureCallback callback, void *ctx);
|
2021-07-16 16:43:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup callback for reaching silence timeout on IRDA port.
|
|
|
|
* Should setup api hal with 'api_hal_irda_setup_rx_timeout_irq()' first.
|
|
|
|
*
|
|
|
|
* @param[in] callback - callback for silence timeout
|
|
|
|
* @param[in] ctx - context to pass to callback
|
2021-05-18 10:51:00 +00:00
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
void api_hal_irda_async_rx_set_timeout_isr_callback(ApiHalIrdaRxTimeoutCallback callback, void *ctx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if IRDA is in use now.
|
|
|
|
* @return true - IRDA is busy, false otherwise.
|
|
|
|
*/
|
|
|
|
bool api_hal_irda_is_busy(void);
|
2021-05-18 10:51:00 +00:00
|
|
|
|
|
|
|
/**
|
2021-08-05 21:11:35 +00:00
|
|
|
* Set callback providing new data. This function has to be called
|
|
|
|
* before api_hal_irda_async_tx_start().
|
2021-05-18 10:51:00 +00:00
|
|
|
*
|
2021-08-05 21:11:35 +00:00
|
|
|
* @param[in] callback - function to provide new data
|
|
|
|
* @param[in] context - context for callback
|
2021-05-18 10:51:00 +00:00
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
void api_hal_irda_async_tx_set_data_isr_callback(ApiHalIrdaTxGetDataCallback callback, void* context);
|
2021-05-18 10:51:00 +00:00
|
|
|
|
|
|
|
/**
|
2021-08-05 21:11:35 +00:00
|
|
|
* Start IR asynchronous transmission. It can be stopped by 2 reasons:
|
|
|
|
* 1) implicit call for api_hal_irda_async_tx_stop()
|
|
|
|
* 2) callback can provide ApiHalIrdaTxGetDataStateLastDone response
|
|
|
|
* which means no more data available for transmission.
|
|
|
|
*
|
|
|
|
* Any func (api_hal_irda_async_tx_stop() or
|
|
|
|
* api_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
|
|
|
|
* @return true if transmission successfully started, false otherwise.
|
|
|
|
* If start failed no need to free resources.
|
2021-05-18 10:51:00 +00:00
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
bool api_hal_irda_async_tx_start(uint32_t freq, float duty_cycle);
|
2021-05-18 10:51:00 +00:00
|
|
|
|
2021-06-09 13:04:49 +00:00
|
|
|
/**
|
2021-08-05 21:11:35 +00:00
|
|
|
* Stop IR asynchronous transmission and free resources.
|
|
|
|
* Transmission will stop as soon as transmission reaches end of
|
|
|
|
* package (ApiHalIrdaTxGetDataStateDone or ApiHalIrdaTxGetDataStateLastDone).
|
|
|
|
*/
|
|
|
|
void api_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 (ApiHalIrdaTxGetDataStateLastDone).
|
2021-06-09 13:04:49 +00:00
|
|
|
*/
|
2021-08-05 21:11:35 +00:00
|
|
|
void api_hal_irda_async_tx_wait_termination(void);
|
2021-06-09 13:04:49 +00:00
|
|
|
|
2021-05-18 10:51:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|