Update directions for CFW

This commit is contained in:
Derek Jamison 2024-01-23 12:27:11 -06:00
parent 6d812948f3
commit 50141c9e74
2 changed files with 64 additions and 3 deletions

View File

@ -2,9 +2,10 @@
## Overview
I created a YouTube video to explain how to modify official firmware to use an external IR Blaster. You can find the video [here](https://www.youtube.com/watch?v=o_Tz68ju4Dg)
[![Flipper Zero: IR Blaster on Official firmware](https://img.youtube.com/vi/o_Tz68ju4Dg/0.jpg)](https://youtu.be/o_Tz68ju4Dg)
In the comments Jeff-ss6qt posted a question about if we can detect the IR hardware and switch automatically. It turns out that we can! This tutorial will show you how!
In the comments **Jeff-ss6qt** posted a question about if we can detect the IR hardware and switch automatically. It turns out that we can! This tutorial will show you how!
## How to use this patch
You can apply this patch to your official firmware...
@ -12,7 +13,13 @@ You can apply this patch to your official firmware...
2. Instead of manually making the edits, 4:40-7:00.
- 2a. Copy this [ir-blaster.patch](./ir-blaster.patch) file into the root folder of your firmware (same folder as where the fbt file is).
- 2b. In VS Code, right click on `ir-blaster.patch` and choose `Open in Integrated Terminal`
- 2c. In the terminal window type: `git apply ir-blaster.patch`
- 2c. In the terminal window type: `git apply --verbose --whitespace=fix --ignore-space-change ir-blaster.patch`
- NOTE: For **Unleashed** or **Xtreme** firmware, you need to apply the `cfw-ir-blaster.patch` instead (since they already have variables defined for external infrared).
- In step 2b, copy the `cfw-ir-blaster.patch` file instead of the `ir-blaster.patch` file.
- In step 2c, type: `git apply --verbose --whitespace=fix --ignore-space-change cfw-ir-blaster.patch`
- NOTE: For **RogueMaster**, you need to apply the `cfw-ir-blaster.patch` instead with a custom directory parameter (since the target files are in a `firmware` subdirectory).
- In step 2b, copy the `cfw-ir-blaster.patch` file instead of the `ir-blaster.patch` file.
- In step 2c, type: `git apply --verbose --whitespace=fix --ignore-space-change --directory=firmware cfw-ir-blaster.patch`
3. 7:00-7:50 - In the source control pane, you should see a bunch of edits to `furi_hal_infrared.c`. You will not have any edits to `infrared_app.c`.
4. 7:50 - Ctrl+Shift+B then [Release] Flash (USB, with resources)
@ -23,7 +30,7 @@ When the IR Blaster is attached and use that instead of the built-in IR. When y
It automatically provides the +5 volts during the transmission, so no need to go into GPIO settings and change with that either (unless you want the status LED always on).
The detection is just based on "something" being present on pin A7, so other modules may also cause the Flipper Zero to no longer use the built-in IR port but typically you should be using your IR Blaster. We use an internal pull-up resistor on pin A7 and then read the value. If it is `high` we assume something nothing is connected. If it is `low` we assume the IR Blaster is connected (although all we really know is some module is pulling the pin toward ground.)
The detection is just based on "something" being present on pin A7, so other modules may also cause the Flipper Zero to no longer use the built-in IR port but typically you should be using your IR Blaster. We use an internal pull-up resistor on pin A7 and then read the value. If it is `high` we assume something nothing is connected. If it is `low` we assume the IR Blaster is connected (although all we really know is some module is pulling the pin toward ground.) The external CC1101 module, WiFi Dev Board and FlipBoard all return `high` when in the internal pull-up configuration; so there is a good chance other 3rd party modules are not detected as an IR Blaster.
This is really just for those times when you are needing to adjust your TV and don't have the accessory nearby -- simply unplug whatever is connected to your Flipper and do a quick IR transmit using the built-in LED. In general, I would always recommend using the IR Blaster module.

View File

@ -0,0 +1,54 @@
diff --git a/targets/f7/furi_hal/furi_hal_infrared.c b/targets/f7/furi_hal/furi_hal_infrared.c
index 9c0d84c55..b2592ee6d 100644
--- a/targets/f7/furi_hal/furi_hal_infrared.c
+++ b/targets/f7/furi_hal/furi_hal_infrared.c
@@ -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 was_otg_requested = false;
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);
@@ -585,6 +587,9 @@ static void furi_hal_infrared_async_tx_free_resources(void) {
} else {
furi_hal_gpio_init(&gpio_infrared_tx, GpioModeAnalog, GpioPullDown, GpioSpeedLow);
}
+ if(was_otg_requested) {
+ furi_hal_power_disable_otg();
+ }
furi_hal_interrupt_set_isr(INFRARED_DMA_CH1_IRQ, NULL, NULL);
furi_hal_interrupt_set_isr(INFRARED_DMA_CH2_IRQ, NULL, NULL);
@@ -645,6 +650,23 @@ 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);
+
+ // Detect if a module (like IR Blaster) is connected to PA7.
+ furi_hal_gpio_init(&gpio_ext_pa7, GpioModeInput, GpioPullUp, GpioSpeedHigh);
+ furi_delay_ms(1);
+ infrared_external_output = !furi_hal_gpio_read(&gpio_ext_pa7);
+ furi_hal_gpio_init(&gpio_ext_pa7, GpioModeAnalog, GpioPullDown, GpioSpeedLow);
+
+ if(infrared_external_output) {
+ was_otg_requested = !furi_hal_power_is_otg_enabled();
+ if(was_otg_requested) {
+ furi_hal_power_enable_otg();
+ furi_delay_ms(100);
+ }
+ } else {
+ was_otg_requested = false;
+ }
+
if(infrared_external_output) {
LL_GPIO_ResetOutputPin(
gpio_ext_pa7.port, gpio_ext_pa7.pin); /* when disable it prevents false pulse */