[FL-1505] Add RAW format (#576)
* Add RAW format * F5 stubs for build to pass * Fix saving decoded signal error * Irda: set ISR before starting timer, remove explicit NVIC configuration Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -9,11 +9,18 @@ extern "C" {
|
||||
/**
|
||||
* Signature of callback function for receiving continuous IRDA rx signal.
|
||||
*
|
||||
* @param level - level of input IRDA rx signal
|
||||
* @param duration - duration of continuous rx signal level in us
|
||||
* @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 (*TimerISRCallback)(void* ctx, bool level, uint32_t duration);
|
||||
typedef void (*ApiHalIrdaCaptureCallback)(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 (*ApiHalIrdaTimeoutCallback)(void* ctx);
|
||||
|
||||
/**
|
||||
* Initialize IRDA RX timer to receive interrupts.
|
||||
@@ -27,20 +34,37 @@ void api_hal_irda_rx_irq_init(void);
|
||||
*/
|
||||
void api_hal_irda_rx_irq_deinit(void);
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
void api_hal_irda_rx_timeout_irq_init(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* Setup callback for previously initialized IRDA RX interrupt.
|
||||
*
|
||||
* @param callback - callback to call when RX signal edge changing occurs
|
||||
* @param ctx - context for callback
|
||||
* @param[in] callback - callback to call when RX signal edge changing occurs
|
||||
* @param[in] ctx - context for callback
|
||||
*/
|
||||
void api_hal_irda_rx_irq_set_callback(TimerISRCallback callback, void *ctx);
|
||||
void api_hal_irda_rx_irq_set_callback(ApiHalIrdaCaptureCallback callback, void *ctx);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void api_hal_irda_rx_timeout_irq_set_callback(ApiHalIrdaTimeoutCallback callback, void *ctx);
|
||||
|
||||
/**
|
||||
* Start generating IRDA TX PWM. Provides PWM initialization on
|
||||
* defined frequency.
|
||||
*
|
||||
* @param duty_cycle - duty cycle
|
||||
* @param freq - PWM frequency to generate
|
||||
* @param[in] duty_cycle - duty cycle
|
||||
* @param[in] freq - PWM frequency to generate
|
||||
*/
|
||||
void api_hal_irda_pwm_set(float duty_cycle, float freq);
|
||||
|
||||
|
@@ -1,82 +1,58 @@
|
||||
#include "cmsis_os.h"
|
||||
#include "api-hal-tim_i.h"
|
||||
#include "api-hal-irda.h"
|
||||
#include <cmsis_os2.h>
|
||||
#include <api-hal-resources.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stm32wbxx_ll_tim.h>
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include "main.h"
|
||||
#include "api-hal-pwm.h"
|
||||
|
||||
#include <main.h>
|
||||
#include <api-hal-pwm.h>
|
||||
|
||||
static struct{
|
||||
TimerISRCallback callback;
|
||||
void *ctx;
|
||||
ApiHalIrdaCaptureCallback capture_callback;
|
||||
void *capture_context;
|
||||
ApiHalIrdaTimeoutCallback timeout_callback;
|
||||
void *timeout_context;
|
||||
} timer_irda;
|
||||
|
||||
typedef enum{
|
||||
TimerIRQSourceCCI1,
|
||||
TimerIRQSourceCCI2,
|
||||
} TimerIRQSource;
|
||||
|
||||
void api_hal_irda_tim_isr(TimerIRQSource source)
|
||||
{
|
||||
uint32_t duration = 0;
|
||||
bool level = 0;
|
||||
|
||||
switch (source) {
|
||||
case TimerIRQSourceCCI1:
|
||||
duration = LL_TIM_OC_GetCompareCH1(TIM2);
|
||||
LL_TIM_SetCounter(TIM2, 0);
|
||||
level = 1;
|
||||
break;
|
||||
case TimerIRQSourceCCI2:
|
||||
duration = LL_TIM_OC_GetCompareCH2(TIM2);
|
||||
LL_TIM_SetCounter(TIM2, 0);
|
||||
level = 0;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
}
|
||||
|
||||
if (timer_irda.callback)
|
||||
timer_irda.callback(timer_irda.ctx, level, duration);
|
||||
}
|
||||
|
||||
void api_hal_irda_rx_irq_init(void)
|
||||
{
|
||||
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* Peripheral clock enable */
|
||||
void api_hal_irda_rx_irq_init(void) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
|
||||
/**TIM2 GPIO Configuration
|
||||
PA0 ------> TIM2_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
hal_gpio_init_ex(&gpio_irda_rx, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
|
||||
|
||||
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
||||
TIM_InitStruct.Prescaler = 64 - 1;
|
||||
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||||
TIM_InitStruct.Autoreload = 0xFFFFFFFF;
|
||||
TIM_InitStruct.Autoreload = 0x7FFFFFFE;
|
||||
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
||||
LL_TIM_Init(TIM2, &TIM_InitStruct);
|
||||
|
||||
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_EnableARRPreload(TIM2);
|
||||
LL_TIM_DisableARRPreload(TIM2);
|
||||
LL_TIM_SetTriggerInput(TIM2, LL_TIM_TS_TI1FP1);
|
||||
LL_TIM_SetSlaveMode(TIM2, LL_TIM_SLAVEMODE_RESET);
|
||||
LL_TIM_CC_DisableChannel(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_FALLING);
|
||||
LL_TIM_DisableIT_TRIG(TIM2);
|
||||
LL_TIM_DisableDMAReq_TRIG(TIM2);
|
||||
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
|
||||
LL_TIM_DisableMasterSlaveMode(TIM2);
|
||||
LL_TIM_EnableMasterSlaveMode(TIM2);
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_DIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_FALLING);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_RISING);
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_INDIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);
|
||||
|
||||
LL_TIM_EnableIT_CC1(TIM2);
|
||||
LL_TIM_EnableIT_CC2(TIM2);
|
||||
@@ -90,22 +66,30 @@ void api_hal_irda_rx_irq_init(void)
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
}
|
||||
|
||||
/* Doesn't work. F5 deprecated. */
|
||||
void api_hal_irda_rx_irq_deinit(void) {
|
||||
LL_TIM_DisableIT_CC1(TIM2);
|
||||
LL_TIM_DisableIT_CC2(TIM2);
|
||||
LL_TIM_CC_DisableChannel(TIM2, LL_TIM_CHANNEL_CH1);
|
||||
LL_TIM_CC_DisableChannel(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
LL_TIM_DeInit(TIM2);
|
||||
}
|
||||
|
||||
void api_hal_irda_rx_timeout_irq_init(uint32_t timeout_ms) {
|
||||
LL_TIM_OC_SetCompareCH3(TIM2, timeout_ms * 1000);
|
||||
LL_TIM_OC_SetMode(TIM2, LL_TIM_CHANNEL_CH3, LL_TIM_OCMODE_ACTIVE);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH3);
|
||||
LL_TIM_EnableIT_CC3(TIM2);
|
||||
}
|
||||
|
||||
bool api_hal_irda_rx_irq_is_busy(void) {
|
||||
return (LL_TIM_IsEnabledIT_CC1(TIM2) || LL_TIM_IsEnabledIT_CC2(TIM2));
|
||||
}
|
||||
|
||||
void api_hal_irda_rx_irq_set_callback(TimerISRCallback callback, void *ctx) {
|
||||
furi_check(callback);
|
||||
void api_hal_irda_rx_irq_set_callback(ApiHalIrdaCaptureCallback callback, void *ctx) {
|
||||
timer_irda.capture_callback = callback;
|
||||
timer_irda.capture_context = ctx;
|
||||
}
|
||||
|
||||
timer_irda.callback = callback;
|
||||
timer_irda.ctx = ctx;
|
||||
void api_hal_irda_rx_timeout_irq_set_callback(ApiHalIrdaTimeoutCallback callback, void *ctx) {
|
||||
timer_irda.timeout_callback = callback;
|
||||
timer_irda.timeout_context = ctx;
|
||||
}
|
||||
|
||||
void api_hal_irda_pwm_set(float value, float freq) {
|
||||
@@ -115,4 +99,3 @@ void api_hal_irda_pwm_set(float value, float freq) {
|
||||
void api_hal_irda_pwm_stop() {
|
||||
hal_pwmn_stop(&IRDA_TX_TIM, IRDA_TX_CH);
|
||||
}
|
||||
|
||||
|
@@ -48,4 +48,8 @@ const GpioPin gpio_ext_pa7 = {.port = GPIOA, .pin = GPIO_PIN_7};
|
||||
|
||||
const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pin};
|
||||
const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin};
|
||||
const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin};
|
||||
const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin};
|
||||
|
||||
const GpioPin gpio_irda_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin};
|
||||
const GpioPin gpio_irda_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin};
|
||||
|
||||
|
@@ -87,6 +87,9 @@ extern const GpioPin gpio_rfid_pull;
|
||||
extern const GpioPin gpio_rfid_carrier_out;
|
||||
extern const GpioPin gpio_rfid_data_in;
|
||||
|
||||
extern const GpioPin gpio_irda_rx;
|
||||
extern const GpioPin gpio_irda_tx;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -14,7 +14,6 @@ void TIM2_IRQHandler(void)
|
||||
|
||||
if (READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC1S)) {
|
||||
// input capture
|
||||
api_hal_irda_tim_isr(TimerIRQSourceCCI1);
|
||||
consumed = true;
|
||||
}
|
||||
else {
|
||||
@@ -30,7 +29,6 @@ void TIM2_IRQHandler(void)
|
||||
|
||||
if (READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC2S)) {
|
||||
// input capture
|
||||
api_hal_irda_tim_isr(TimerIRQSourceCCI2);
|
||||
consumed = true;
|
||||
}
|
||||
else {
|
||||
|
@@ -1,17 +1,22 @@
|
||||
#include "api-hal-interrupt.h"
|
||||
#include "api-hal-irda.h"
|
||||
#include <cmsis_os2.h>
|
||||
#include <api-hal-interrupt.h>
|
||||
#include <api-hal-resources.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stm32wbxx_ll_tim.h>
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include "main.h"
|
||||
#include "api-hal-pwm.h"
|
||||
#include <main.h>
|
||||
#include <api-hal-pwm.h>
|
||||
|
||||
static struct{
|
||||
TimerISRCallback callback;
|
||||
void *ctx;
|
||||
ApiHalIrdaCaptureCallback capture_callback;
|
||||
void *capture_context;
|
||||
ApiHalIrdaTimeoutCallback timeout_callback;
|
||||
void *timeout_context;
|
||||
} timer_irda;
|
||||
|
||||
typedef enum{
|
||||
@@ -19,107 +24,105 @@ typedef enum{
|
||||
TimerIRQSourceCCI2,
|
||||
} TimerIRQSource;
|
||||
|
||||
static void api_hal_irda_handle_capture(TimerIRQSource source)
|
||||
{
|
||||
static void api_hal_irda_handle_timeout(void) {
|
||||
/* Timers CNT register starts to counting from 0 to ARR, but it is
|
||||
* reseted when Channel 1 catches interrupt. It is not reseted by
|
||||
* channel 2, though, so we have to distract it's values (see TimerIRQSourceCCI1 ISR).
|
||||
* This can cause false timeout: when time is over, but we started
|
||||
* receiving new signal few microseconds ago, because CNT register
|
||||
* is reseted once per period, not per sample. */
|
||||
if (LL_GPIO_IsInputPinSet(gpio_irda_rx.port, gpio_irda_rx.pin) == 0)
|
||||
return;
|
||||
|
||||
if (timer_irda.timeout_callback)
|
||||
timer_irda.timeout_callback(timer_irda.timeout_context);
|
||||
}
|
||||
|
||||
/* High pin level is a Space state of IRDA signal. Invert level for further processing. */
|
||||
static void api_hal_irda_handle_capture(TimerIRQSource source) {
|
||||
uint32_t duration = 0;
|
||||
bool level = 0;
|
||||
|
||||
switch (source) {
|
||||
case TimerIRQSourceCCI1:
|
||||
duration = LL_TIM_OC_GetCompareCH1(TIM2);
|
||||
LL_TIM_SetCounter(TIM2, 0);
|
||||
level = 0;
|
||||
duration = LL_TIM_IC_GetCaptureCH1(TIM2) - LL_TIM_IC_GetCaptureCH2(TIM2);
|
||||
level = 1;
|
||||
break;
|
||||
case TimerIRQSourceCCI2:
|
||||
duration = LL_TIM_OC_GetCompareCH2(TIM2);
|
||||
LL_TIM_SetCounter(TIM2, 0);
|
||||
level = 1;
|
||||
duration = LL_TIM_IC_GetCaptureCH2(TIM2);
|
||||
level = 0;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
}
|
||||
|
||||
if (timer_irda.callback)
|
||||
timer_irda.callback(timer_irda.ctx, level, duration);
|
||||
if (timer_irda.capture_callback)
|
||||
timer_irda.capture_callback(timer_irda.capture_context, level, duration);
|
||||
}
|
||||
|
||||
static void api_hal_irda_isr() {
|
||||
if(LL_TIM_IsActiveFlag_CC1(TIM2) == 1) {
|
||||
if(LL_TIM_IsActiveFlag_CC3(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC3(TIM2);
|
||||
api_hal_irda_handle_timeout();
|
||||
}
|
||||
if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC1(TIM2);
|
||||
|
||||
if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC1S)) {
|
||||
// input capture
|
||||
api_hal_irda_handle_capture(TimerIRQSourceCCI1);
|
||||
} else {
|
||||
// output compare
|
||||
// HAL_TIM_OC_DelayElapsedCallback(htim);
|
||||
// HAL_TIM_PWM_PulseFinishedCallback(htim);
|
||||
}
|
||||
}
|
||||
if(LL_TIM_IsActiveFlag_CC2(TIM2) == 1) {
|
||||
if(LL_TIM_IsActiveFlag_CC2(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC2(TIM2);
|
||||
|
||||
if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC2S)) {
|
||||
// input capture
|
||||
api_hal_irda_handle_capture(TimerIRQSourceCCI2);
|
||||
} else {
|
||||
// output compare
|
||||
// HAL_TIM_OC_DelayElapsedCallback(htim);
|
||||
// HAL_TIM_PWM_PulseFinishedCallback(htim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_irda_rx_irq_init(void)
|
||||
{
|
||||
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* Peripheral clock enable */
|
||||
void api_hal_irda_rx_irq_init(void) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
|
||||
/**TIM2 GPIO Configuration
|
||||
PA0 ------> TIM2_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
hal_gpio_init_ex(&gpio_irda_rx, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
|
||||
|
||||
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
||||
TIM_InitStruct.Prescaler = 64 - 1;
|
||||
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||||
TIM_InitStruct.Autoreload = 0xFFFFFFFF;
|
||||
TIM_InitStruct.Autoreload = 0x7FFFFFFE;
|
||||
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
||||
LL_TIM_Init(TIM2, &TIM_InitStruct);
|
||||
|
||||
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_EnableARRPreload(TIM2);
|
||||
LL_TIM_DisableARRPreload(TIM2);
|
||||
LL_TIM_SetTriggerInput(TIM2, LL_TIM_TS_TI1FP1);
|
||||
LL_TIM_SetSlaveMode(TIM2, LL_TIM_SLAVEMODE_RESET);
|
||||
LL_TIM_CC_DisableChannel(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_FALLING);
|
||||
LL_TIM_DisableIT_TRIG(TIM2);
|
||||
LL_TIM_DisableDMAReq_TRIG(TIM2);
|
||||
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
|
||||
LL_TIM_DisableMasterSlaveMode(TIM2);
|
||||
LL_TIM_EnableMasterSlaveMode(TIM2);
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_DIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_FALLING);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_RISING);
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_INDIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1);
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1);
|
||||
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);
|
||||
|
||||
LL_TIM_EnableIT_CC1(TIM2);
|
||||
LL_TIM_EnableIT_CC2(TIM2);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH1);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
|
||||
api_hal_interrupt_set_timer_isr(TIM2, api_hal_irda_isr);
|
||||
|
||||
LL_TIM_SetCounter(TIM2, 0);
|
||||
LL_TIM_EnableCounter(TIM2);
|
||||
|
||||
api_hal_interrupt_set_timer_isr(TIM2, api_hal_irda_isr);
|
||||
NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
}
|
||||
|
||||
void api_hal_irda_rx_irq_deinit(void) {
|
||||
@@ -127,15 +130,25 @@ void api_hal_irda_rx_irq_deinit(void) {
|
||||
api_hal_interrupt_set_timer_isr(TIM2, NULL);
|
||||
}
|
||||
|
||||
void api_hal_irda_rx_timeout_irq_init(uint32_t timeout_ms) {
|
||||
LL_TIM_OC_SetCompareCH3(TIM2, timeout_ms * 1000);
|
||||
LL_TIM_OC_SetMode(TIM2, LL_TIM_CHANNEL_CH3, LL_TIM_OCMODE_ACTIVE);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH3);
|
||||
LL_TIM_EnableIT_CC3(TIM2);
|
||||
}
|
||||
|
||||
bool api_hal_irda_rx_irq_is_busy(void) {
|
||||
return (LL_TIM_IsEnabledIT_CC1(TIM2) || LL_TIM_IsEnabledIT_CC2(TIM2));
|
||||
}
|
||||
|
||||
void api_hal_irda_rx_irq_set_callback(TimerISRCallback callback, void *ctx) {
|
||||
furi_check(callback);
|
||||
void api_hal_irda_rx_irq_set_callback(ApiHalIrdaCaptureCallback callback, void *ctx) {
|
||||
timer_irda.capture_callback = callback;
|
||||
timer_irda.capture_context = ctx;
|
||||
}
|
||||
|
||||
timer_irda.callback = callback;
|
||||
timer_irda.ctx = ctx;
|
||||
void api_hal_irda_rx_timeout_irq_set_callback(ApiHalIrdaTimeoutCallback callback, void *ctx) {
|
||||
timer_irda.timeout_callback = callback;
|
||||
timer_irda.timeout_context = ctx;
|
||||
}
|
||||
|
||||
void api_hal_irda_pwm_set(float value, float freq) {
|
||||
|
@@ -47,4 +47,8 @@ const GpioPin gpio_ext_pa7 = {.port = GPIOA, .pin = GPIO_PIN_7};
|
||||
|
||||
const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pin};
|
||||
const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin};
|
||||
const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin};
|
||||
const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin};
|
||||
|
||||
const GpioPin gpio_irda_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin};
|
||||
const GpioPin gpio_irda_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin};
|
||||
|
||||
|
@@ -86,6 +86,9 @@ extern const GpioPin gpio_rfid_pull;
|
||||
extern const GpioPin gpio_rfid_carrier_out;
|
||||
extern const GpioPin gpio_rfid_data_in;
|
||||
|
||||
extern const GpioPin gpio_irda_rx;
|
||||
extern const GpioPin gpio_irda_tx;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user