Skip to content

Commit

Permalink
add 5V auto-enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
GLinnik21 committed Aug 27, 2023
1 parent 1d35856 commit 7e494a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mh_z19_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct MhZ19App {
FuriMutex* mutex;
FuriThread* worker_thread;
uint32_t ppm;
bool otg_was_previously_enabled;
bool is_5V_enabled;
};

typedef enum MhZ19WorkerEventFlags {
Expand Down
17 changes: 17 additions & 0 deletions mh_z19_uart.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
#include "mh_z19_uart.h"
#include <furi_hal_console.h>
#include <furi_hal_power.h>

#include "mh_z19_app_i.h"
#include "mh_z19_uart_tools.h"

static void mh_z19_app_uart_enable_5V(MhZ19App* app) {
app->otg_was_previously_enabled = furi_hal_power_is_otg_enabled();
furi_hal_power_enable_otg();
app->is_5V_enabled = furi_hal_power_is_otg_enabled() || furi_hal_power_is_charging();
}

static void mh_z19_app_uart_restore_5V_state(MhZ19App* app) {
if(app->is_5V_enabled && !app->otg_was_previously_enabled) {
furi_hal_power_disable_otg();
}
}

void mh_z19_app_uart_init(MhZ19App* app) {
app->uart_state = MhZ19UartStateWaitStart;
furi_hal_console_disable();

mh_z19_app_uart_enable_5V(app);

furi_hal_uart_deinit((app->uart_channel = FuriHalUartIdUSART1));
furi_hal_uart_init(app->uart_channel, MH_Z19_BAUDRATE);
furi_hal_uart_set_irq_cb(app->uart_channel, mh_z19_app_uart_callback, app);
}

void mh_z19_app_uart_deinit(MhZ19App* app) {
mh_z19_app_uart_restore_5V_state(app);
furi_hal_console_enable();
furi_hal_uart_deinit(app->uart_channel);
}
Expand Down

0 comments on commit 7e494a4

Please sign in to comment.