Add automatic IR blaster detection

removed last_settings because it isnt needed anymore
This commit is contained in:
Sil333033
2024-01-27 20:33:10 +01:00
parent cb635ff2d2
commit 7c4f6de06f
8 changed files with 87 additions and 128 deletions

View File

@@ -2,6 +2,7 @@
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>
#include <furi_hal_bus.h>
#include <furi_hal_power.h>
#include <stm32wbxx_ll_tim.h>
#include <stm32wbxx_ll_dma.h>
@@ -79,6 +80,7 @@ static volatile InfraredState furi_hal_infrared_state = InfraredStateIdle;
static InfraredTimTx infrared_tim_tx;
static InfraredTimRx infrared_tim_rx;
static bool infrared_external_output;
static bool block_external;
static void furi_hal_infrared_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift);
static void furi_hal_infrared_async_tx_free_resources(void);
@@ -648,12 +650,29 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) {
furi_delay_us(5);
LL_TIM_GenerateEvent_UPDATE(INFRARED_DMA_TIMER); /* DMA -> TIMx_RCR */
furi_delay_us(5);
if(block_external) {
infrared_external_output = false;
} else {
infrared_external_output = furi_hal_infrared_is_external_connected();
}
if(infrared_external_output) {
if(!furi_hal_power_is_otg_enabled()) {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
furi_delay_ms(100);
}
LL_GPIO_ResetOutputPin(
gpio_ext_pa7.port, gpio_ext_pa7.pin); /* when disable it prevents false pulse */
furi_hal_gpio_init_ex(
&gpio_ext_pa7, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedHigh, GpioAltFn1TIM1);
} else {
furi_hal_power_disable_otg();
LL_GPIO_ResetOutputPin(
gpio_infrared_tx.port,
gpio_infrared_tx.pin); /* when disable it prevents false pulse */
@@ -708,3 +727,19 @@ void furi_hal_infrared_async_tx_set_signal_sent_isr_callback(
infrared_tim_tx.signal_sent_callback = callback;
infrared_tim_tx.signal_sent_context = context;
}
bool furi_hal_infrared_is_external_connected() {
furi_hal_gpio_init(&gpio_ext_pa7, GpioModeInput, GpioPullUp, GpioSpeedHigh);
furi_delay_ms(1);
bool is_external_connected = !furi_hal_gpio_read(&gpio_ext_pa7);
furi_hal_gpio_init(&gpio_ext_pa7, GpioModeAnalog, GpioPullDown, GpioSpeedLow);
return is_external_connected;
}
void furi_hal_infrared_block_external_output(bool block) {
block_external = block;
}
bool furi_hal_infrared_is_external_output_blocked(void) {
return block_external;
}