Skip to content

Commit

Permalink
fix uart related plugins to disable expansion protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Jan 30, 2024
1 parent 7c8d72c commit 0875b3c
Show file tree
Hide file tree
Showing 25 changed files with 280 additions and 4 deletions.
13 changes: 13 additions & 0 deletions apps_source_code/airmon/airmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <core/thread.h>
#include <core/kernel.h>

#include <expansion/expansion.h>

#include "airmon_icons.h"
#include "airmon_pms.h"
#include "airmon_aqi.h"
Expand Down Expand Up @@ -236,9 +238,16 @@ static void airmon_context_free(AirmonContext* ctx) {
int32_t airmon_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

// Allocate all of the necessary structures
AirmonContext* ctx = airmon_context_alloc();
if(!ctx) {
// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);
return 255;
}

Expand All @@ -247,6 +256,10 @@ int32_t airmon_app(void* p) {

// Release all resources
airmon_context_free(ctx);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
11 changes: 11 additions & 0 deletions base_pack/camera_suite/camera_suite.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "camera_suite.h"
#include <stdlib.h>
#include <expansion/expansion.h>

bool camera_suite_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Expand Down Expand Up @@ -122,6 +123,11 @@ void camera_suite_app_free(CameraSuite* app) {
/** Main entry point for initialization. */
int32_t camera_suite_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

CameraSuite* app = camera_suite_app_alloc();
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
// Init with start scene.
Expand All @@ -131,5 +137,10 @@ int32_t camera_suite_app(void* p) {
camera_suite_save_settings(app);
furi_hal_power_suppress_charge_exit();
camera_suite_app_free(app);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
12 changes: 12 additions & 0 deletions base_pack/dap_link/dap_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <stm32wbxx_ll_usart.h>
#include <stm32wbxx_ll_lpuart.h>

#include <expansion/expansion.h>

#include "dap_link.h"
#include "dap_config.h"
#include "gui/dap_gui.h"
Expand Down Expand Up @@ -510,6 +512,9 @@ DapConfig* dap_app_get_config(DapApp* app) {

int32_t dap_link_app(void* p) {
UNUSED(p);
// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

if(furi_hal_usb_is_locked()) {
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
Expand All @@ -526,6 +531,9 @@ int32_t dap_link_app(void* p) {
dialog_message_show(dialogs, message);
dialog_message_free(message);
furi_record_close(RECORD_DIALOGS);
// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);
return -1;
}

Expand All @@ -551,5 +559,9 @@ int32_t dap_link_app(void* p) {
// free app
dap_app_free(app);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
12 changes: 12 additions & 0 deletions base_pack/esp8266_deauth/esp8266_deauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <gui/canvas_i.h>
#include <gui/gui.h>
#include <input/input.h>
#include <expansion/expansion.h>
//#include <math.h>
//#include <notification/notification.h>
//#include <notification/notification_messages.h>
Expand Down Expand Up @@ -315,6 +316,10 @@ static int32_t uart_worker(void* context) {
int32_t esp8266_deauth_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

DEAUTH_APP_LOG_I("Init");

// FuriTimer* timer = furi_timer_alloc(blink_test_update, FuriTimerTypePeriodic, event_queue);
Expand Down Expand Up @@ -363,6 +368,9 @@ int32_t esp8266_deauth_app(void* p) {
if(!app->mutex) {
DEAUTH_APP_LOG_E("cannot create mutex\r\n");
free(app);
// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);
return 255;
}

Expand Down Expand Up @@ -541,5 +549,9 @@ int32_t esp8266_deauth_app(void* p) {
}
#endif

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
12 changes: 12 additions & 0 deletions base_pack/gps_nmea_uart/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <furi.h>
#include <gui/gui.h>
#include <string.h>
#include <expansion/expansion.h>

typedef enum {
EventTypeTick,
Expand Down Expand Up @@ -131,6 +132,10 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
int32_t gps_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));

GpsUart* gps_uart = gps_uart_enable();
Expand All @@ -139,6 +144,9 @@ int32_t gps_app(void* p) {
if(!gps_uart->mutex) {
FURI_LOG_E("GPS", "cannot create mutex\r\n");
free(gps_uart);
// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);
return 255;
}

Expand Down Expand Up @@ -271,5 +279,9 @@ int32_t gps_app(void* p) {
furi_hal_power_disable_otg();
}

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
12 changes: 12 additions & 0 deletions base_pack/hc_sr04/hc_sr04.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <gui/elements.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <expansion/expansion.h>

typedef enum {
EventTypeTick,
Expand Down Expand Up @@ -176,6 +177,10 @@ static void hc_sr04_measure(PluginState* const plugin_state) {
}

int32_t hc_sr04_app() {
// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));

PluginState* plugin_state = malloc(sizeof(PluginState));
Expand All @@ -194,6 +199,9 @@ int32_t hc_sr04_app() {
furi_hal_power_suppress_charge_exit();
furi_message_queue_free(event_queue);
free(plugin_state);
// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);
return 255;
}

Expand Down Expand Up @@ -270,5 +278,9 @@ int32_t hc_sr04_app() {
furi_mutex_free(plugin_state->mutex);
free(plugin_state);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
12 changes: 12 additions & 0 deletions base_pack/sentry_safe/sentry_safe.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>

#include <furi_hal.h>
#include <expansion/expansion.h>

typedef struct {
uint8_t status;
Expand Down Expand Up @@ -83,6 +84,10 @@ void try_code(int a, int b, int c, int d, int e) {
int32_t sentry_safe_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(Event));

SentryState* sentry_state = malloc(sizeof(SentryState));
Expand All @@ -94,6 +99,9 @@ int32_t sentry_safe_app(void* p) {
FURI_LOG_E("SentrySafe", "cannot create mutex\r\n");
furi_message_queue_free(event_queue);
free(sentry_state);
// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);
return 255;
}

Expand Down Expand Up @@ -165,5 +173,9 @@ int32_t sentry_safe_app(void* p) {
furi_mutex_free(sentry_state->mutex);
free(sentry_state);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
9 changes: 9 additions & 0 deletions base_pack/uart_terminal/uart_terminal_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <furi.h>
#include <furi_hal.h>
#include <expansion/expansion.h>

static bool uart_terminal_app_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Expand Down Expand Up @@ -117,6 +118,10 @@ void uart_terminal_app_free(UART_TerminalApp* app) {

int32_t uart_terminal_app(void* p) {
UNUSED(p);
// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

UART_TerminalApp* uart_terminal_app = uart_terminal_app_alloc();

uart_terminal_app->uart = uart_terminal_uart_init(uart_terminal_app);
Expand All @@ -125,5 +130,9 @@ int32_t uart_terminal_app(void* p) {

uart_terminal_app_free(uart_terminal_app);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
8 changes: 8 additions & 0 deletions base_pack/wifi_marauder_companion/wifi_marauder_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <furi.h>
#include <furi_hal.h>
#include <expansion/expansion.h>

static bool wifi_marauder_app_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Expand Down Expand Up @@ -172,6 +173,9 @@ void wifi_marauder_app_free(WifiMarauderApp* app) {

int32_t wifi_marauder_app(void* p) {
UNUSED(p);
// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

uint8_t attempts = 0;
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
Expand All @@ -196,5 +200,9 @@ int32_t wifi_marauder_app(void* p) {
furi_hal_power_disable_otg();
}

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
12 changes: 12 additions & 0 deletions base_pack/wifi_scanner/wifi_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <stdlib.h>
#include <expansion/expansion.h>

#include "FlipperZeroWiFiModuleDefines.h"

Expand Down Expand Up @@ -838,6 +839,10 @@ void send_serial_command(SWiFiScannerApp* app, ESerialCommand command) {
int32_t wifi_scanner_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

WIFI_APP_LOG_I("Init");

// FuriTimer* timer = furi_timer_alloc(blink_test_update, FuriTimerTypePeriodic, event_queue);
Expand Down Expand Up @@ -874,6 +879,9 @@ int32_t wifi_scanner_app(void* p) {
if(!app->mutex) {
WIFI_APP_LOG_E("cannot create mutex\r\n");
free(app);
// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);
return 255;
}

Expand Down Expand Up @@ -1061,5 +1069,9 @@ int32_t wifi_scanner_app(void* p) {
}
#endif

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
10 changes: 10 additions & 0 deletions non_catalog_apps/LORA_term/uart_terminal_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <furi.h>
#include <furi_hal.h>
#include <expansion/expansion.h>

static bool uart_terminal_app_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Expand Down Expand Up @@ -92,6 +93,11 @@ void uart_terminal_app_free(UART_TerminalApp* app) {

int32_t uart_terminal_app(void* p) {
UNUSED(p);

// Disable expansion protocol to avoid interference with UART Handle
Expansion* expansion = furi_record_open(RECORD_EXPANSION);
expansion_disable(expansion);

UART_TerminalApp* uart_terminal_app = uart_terminal_app_alloc();

uart_terminal_app->uart = uart_terminal_uart_init(uart_terminal_app);
Expand All @@ -100,5 +106,9 @@ int32_t uart_terminal_app(void* p) {

uart_terminal_app_free(uart_terminal_app);

// Return previous state of expansion
expansion_enable(expansion);
furi_record_close(RECORD_EXPANSION);

return 0;
}
Loading

0 comments on commit 0875b3c

Please sign in to comment.