From 558fa5670bb624c63c03f76f9f434dc7189f2aa9 Mon Sep 17 00:00:00 2001 From: Anna Prosvetova Date: Fri, 12 Nov 2021 16:04:35 +0300 Subject: [PATCH] RPC: Add Virtual Display & Unify log tags (#814) * RPC: Update protobuf sources * RPC: Add Virtual Display * Unify log tags * RPC: Virtual Display placeholder * Rpc: clear frame buffer callback before confirm. * Firmware: full assert for hal, move fatfs initialization to furi hal. * FuriHal: VCP optimizations, thread safe console. Rpc: adjust buffer sizes. Co-authored-by: Aleksandr Kutuzov --- applications/applications.mk | 4 + applications/archive/helpers/archive_files.c | 6 +- applications/bt/bt_service/bt.c | 18 +-- applications/bt/bt_settings.c | 12 +- applications/debug_tools/bad_usb.c | 15 +- .../debug_tools/display_test/display_test.c | 4 +- applications/debug_tools/keypad_test.c | 6 +- .../desktop/helpers/desktop_animation.c | 10 +- applications/dialogs/view_holder.c | 4 +- applications/dolphin/dolphin.c | 2 +- applications/dolphin/helpers/dolphin_state.c | 8 +- applications/gui/gui.c | 8 +- applications/gui/view_dispatcher.c | 6 +- applications/irda/irda-app-file-parser.cpp | 25 ++-- applications/loader/loader.c | 30 ++-- applications/loader/loader_i.h | 2 - applications/nfc/nfc_worker.c | 141 ++++++++---------- applications/notification/notification-app.c | 19 ++- applications/rpc/rpc.c | 39 ++--- applications/rpc/rpc.h | 1 + applications/rpc/rpc_cli.c | 7 +- applications/rpc/rpc_gui.c | 122 ++++++++++++++- applications/storage/storage-test-app.c | 2 +- applications/storage/storages/storage-ext.c | 2 +- applications/storage/storages/storage-int.c | 2 +- applications/subghz/subghz_i.c | 29 ++-- .../subghz/views/subghz_test_static.c | 6 +- applications/tests/rpc/rpc_test.c | 4 +- applications/tests/test_index.c | 14 +- assets/compiled/flipper.pb.h | 31 ++-- assets/compiled/gui.pb.c | 12 +- assets/compiled/gui.pb.h | 54 +++++-- assets/protobuf | 2 +- core/flipper.c | 12 +- firmware/targets/f6/Inc/stm32_assert.h | 40 +++++ firmware/targets/f6/Inc/stm32wbxx_hal_conf.h | 15 +- firmware/targets/f6/Src/main.c | 15 +- .../targets/f6/ble-glue/battery_service.c | 14 +- firmware/targets/f6/ble-glue/ble_app.c | 6 +- firmware/targets/f6/ble-glue/ble_glue.c | 12 +- .../targets/f6/ble-glue/dev_info_service.c | 30 ++-- firmware/targets/f6/ble-glue/gap.c | 52 +++---- firmware/targets/f6/ble-glue/serial_service.c | 32 ++-- firmware/targets/f6/{Src => }/fatfs/fatfs.c | 0 firmware/targets/f6/{Src => }/fatfs/fatfs.h | 0 firmware/targets/f6/{Src => }/fatfs/ffconf.h | 0 .../targets/f6/{Src => }/fatfs/spi_sd_hal.c | 0 .../f6/{Src => }/fatfs/stm32_adafruit_sd.c | 0 .../f6/{Src => }/fatfs/stm32_adafruit_sd.h | 0 firmware/targets/f6/{Src => }/fatfs/syscall.c | 0 .../targets/f6/{Src => }/fatfs/user_diskio.c | 0 .../targets/f6/{Src => }/fatfs/user_diskio.h | 0 .../targets/f6/furi-hal/furi-hal-bootloader.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-clock.c | 4 +- .../targets/f6/furi-hal/furi-hal-compress.c | 4 +- .../targets/f6/furi-hal/furi-hal-console.c | 10 +- .../targets/f6/furi-hal/furi-hal-crypto.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-delay.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-i2c.c | 4 +- .../targets/f6/furi-hal/furi-hal-interrupt.c | 10 +- firmware/targets/f6/furi-hal/furi-hal-light.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-nfc.c | 10 +- firmware/targets/f6/furi-hal/furi-hal-os.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-power.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-rfid.c | 21 +-- firmware/targets/f6/furi-hal/furi-hal-spi.c | 4 +- .../targets/f6/furi-hal/furi-hal-subghz.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-usb.c | 10 +- firmware/targets/f6/furi-hal/furi-hal-vcp.c | 95 +++++++----- .../targets/f6/furi-hal/furi-hal-version.c | 4 +- firmware/targets/f6/furi-hal/furi-hal-vibro.c | 4 +- firmware/targets/f6/furi-hal/furi-hal.c | 22 ++- firmware/targets/f6/target.mk | 9 +- firmware/targets/f7/Inc/stm32_assert.h | 40 +++++ firmware/targets/f7/Inc/stm32wbxx_hal_conf.h | 15 +- firmware/targets/f7/Src/main.c | 15 +- .../targets/f7/ble-glue/battery_service.c | 14 +- firmware/targets/f7/ble-glue/ble_app.c | 6 +- firmware/targets/f7/ble-glue/ble_glue.c | 12 +- .../targets/f7/ble-glue/dev_info_service.c | 30 ++-- firmware/targets/f7/ble-glue/gap.c | 52 +++---- firmware/targets/f7/ble-glue/serial_service.c | 32 ++-- firmware/targets/f7/{Src => }/fatfs/fatfs.c | 0 firmware/targets/f7/{Src => }/fatfs/fatfs.h | 0 firmware/targets/f7/{Src => }/fatfs/ffconf.h | 0 .../targets/f7/{Src => }/fatfs/spi_sd_hal.c | 0 .../f7/{Src => }/fatfs/stm32_adafruit_sd.c | 0 .../f7/{Src => }/fatfs/stm32_adafruit_sd.h | 0 firmware/targets/f7/{Src => }/fatfs/syscall.c | 0 .../targets/f7/{Src => }/fatfs/user_diskio.c | 0 .../targets/f7/{Src => }/fatfs/user_diskio.h | 0 .../targets/f7/furi-hal/furi-hal-bootloader.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-clock.c | 4 +- .../targets/f7/furi-hal/furi-hal-compress.c | 4 +- .../targets/f7/furi-hal/furi-hal-console.c | 10 +- .../targets/f7/furi-hal/furi-hal-crypto.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-delay.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-i2c.c | 4 +- .../targets/f7/furi-hal/furi-hal-interrupt.c | 10 +- firmware/targets/f7/furi-hal/furi-hal-light.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-nfc.c | 10 +- firmware/targets/f7/furi-hal/furi-hal-os.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-power.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-rfid.c | 21 +-- firmware/targets/f7/furi-hal/furi-hal-spi.c | 4 +- .../targets/f7/furi-hal/furi-hal-subghz.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-usb.c | 10 +- firmware/targets/f7/furi-hal/furi-hal-vcp.c | 95 +++++++----- .../targets/f7/furi-hal/furi-hal-version.c | 4 +- firmware/targets/f7/furi-hal/furi-hal-vibro.c | 4 +- firmware/targets/f7/furi-hal/furi-hal.c | 22 ++- firmware/targets/f7/target.mk | 9 +- lib/drivers/bq27220.c | 12 +- .../protocols/subghz_protocol_came_atomo.c | 4 +- lib/subghz/protocols/subghz_protocol_common.c | 10 +- lib/subghz/protocols/subghz_protocol_common.h | 3 +- .../protocols/subghz_protocol_nice_flor_s.c | 4 +- .../protocols/subghz_protocol_princeton.c | 8 +- lib/subghz/protocols/subghz_protocol_raw.c | 14 +- lib/subghz/subghz_file_encoder_worker.c | 18 ++- lib/subghz/subghz_keystore.c | 80 +++++----- lib/subghz/subghz_worker.c | 4 +- lib/toolbox/saved_struct.c | 18 +-- 123 files changed, 1050 insertions(+), 694 deletions(-) mode change 100755 => 100644 applications/nfc/nfc_worker.c mode change 100755 => 100644 applications/rpc/rpc.c create mode 100644 firmware/targets/f6/Inc/stm32_assert.h rename firmware/targets/f6/{Src => }/fatfs/fatfs.c (100%) rename firmware/targets/f6/{Src => }/fatfs/fatfs.h (100%) rename firmware/targets/f6/{Src => }/fatfs/ffconf.h (100%) rename firmware/targets/f6/{Src => }/fatfs/spi_sd_hal.c (100%) rename firmware/targets/f6/{Src => }/fatfs/stm32_adafruit_sd.c (100%) rename firmware/targets/f6/{Src => }/fatfs/stm32_adafruit_sd.h (100%) rename firmware/targets/f6/{Src => }/fatfs/syscall.c (100%) rename firmware/targets/f6/{Src => }/fatfs/user_diskio.c (100%) rename firmware/targets/f6/{Src => }/fatfs/user_diskio.h (100%) create mode 100644 firmware/targets/f7/Inc/stm32_assert.h rename firmware/targets/f7/{Src => }/fatfs/fatfs.c (100%) rename firmware/targets/f7/{Src => }/fatfs/fatfs.h (100%) rename firmware/targets/f7/{Src => }/fatfs/ffconf.h (100%) rename firmware/targets/f7/{Src => }/fatfs/spi_sd_hal.c (100%) rename firmware/targets/f7/{Src => }/fatfs/stm32_adafruit_sd.c (100%) rename firmware/targets/f7/{Src => }/fatfs/stm32_adafruit_sd.h (100%) rename firmware/targets/f7/{Src => }/fatfs/syscall.c (100%) rename firmware/targets/f7/{Src => }/fatfs/user_diskio.c (100%) rename firmware/targets/f7/{Src => }/fatfs/user_diskio.h (100%) diff --git a/applications/applications.mk b/applications/applications.mk index 1168ee82..4f0a5a67 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -231,6 +231,10 @@ endif SRV_RPC ?= 0 ifeq ($(SRV_RPC), 1) CFLAGS += -DSRV_RPC +ifeq ($(SRV_RPC_DEBUG), 1) +CFLAGS += -DSRV_RPC_DEBUG +endif +SRV_CLI = 1 endif SRV_LOADER ?= 0 diff --git a/applications/archive/helpers/archive_files.c b/applications/archive/helpers/archive_files.c index fc3508e8..83b67a5b 100644 --- a/applications/archive/helpers/archive_files.c +++ b/applications/archive/helpers/archive_files.c @@ -1,6 +1,8 @@ #include "archive_files.h" #include "archive_browser.h" +#define TAG "Archive" + bool filter_by_extension(FileInfo* file_info, const char* tab_ext, const char* name) { furi_assert(file_info); furi_assert(tab_ext); @@ -147,11 +149,11 @@ void archive_file_append(const char* path, const char* format, ...) { FileWorker* file_worker = file_worker_alloc(false); if(!file_worker_open(file_worker, path, FSAM_WRITE, FSOM_OPEN_APPEND)) { - FURI_LOG_E("Archive", "Append open error"); + FURI_LOG_E(TAG, "Append open error"); } if(!file_worker_write(file_worker, string_get_cstr(string), string_size(string))) { - FURI_LOG_E("Archive", "Append write error"); + FURI_LOG_E(TAG, "Append write error"); } file_worker_close(file_worker); diff --git a/applications/bt/bt_service/bt.c b/applications/bt/bt_service/bt.c index 3336ab9f..64966570 100755 --- a/applications/bt/bt_service/bt.c +++ b/applications/bt/bt_service/bt.c @@ -2,7 +2,7 @@ #include "battery_service.h" #include "bt_keys_storage.h" -#define BT_SERVICE_TAG "BT" +#define TAG "BtSrv" static void bt_draw_statusbar_callback(Canvas* canvas, void* context) { furi_assert(context); @@ -87,7 +87,7 @@ static uint16_t bt_on_data_received_callback(uint8_t* data, uint16_t size, void* size_t bytes_processed = rpc_session_feed(bt->rpc_session, data, size, 1000); if(bytes_processed != size) { - FURI_LOG_E(BT_SERVICE_TAG, "Only %d of %d bytes processed by RPC", bytes_processed, size); + FURI_LOG_E(TAG, "Only %d of %d bytes processed by RPC", bytes_processed, size); } return rpc_session_get_available_size(bt->rpc_session); } @@ -135,7 +135,7 @@ static void bt_on_gap_event_callback(BleEvent event, void* context) { BtMessage message = {.type = BtMessageTypeUpdateStatusbar}; furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); // Open RPC session - FURI_LOG_I(BT_SERVICE_TAG, "Open RPC connection"); + FURI_LOG_I(TAG, "Open RPC connection"); bt->rpc_session = rpc_session_open(bt->rpc); rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback); rpc_session_set_buffer_is_empty_callback(bt->rpc_session, bt_rpc_buffer_is_empty_callback); @@ -149,7 +149,7 @@ static void bt_on_gap_event_callback(BleEvent event, void* context) { message.data.battery_level = info.charge; furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); } else if(event.type == BleEventTypeDisconnected) { - FURI_LOG_I(BT_SERVICE_TAG, "Close RPC connection"); + FURI_LOG_I(TAG, "Close RPC connection"); if(bt->rpc_session) { rpc_session_close(bt->rpc_session); bt->rpc_session = NULL; @@ -172,7 +172,7 @@ static void bt_on_gap_event_callback(BleEvent event, void* context) { static void bt_on_key_storage_change_callback(uint8_t* addr, uint16_t size, void* context) { furi_assert(context); Bt* bt = context; - FURI_LOG_I(BT_SERVICE_TAG, "Changed addr start: %08lX, size changed: %d", addr, size); + FURI_LOG_I(TAG, "Changed addr start: %08lX, size changed: %d", addr, size); BtMessage message = {.type = BtMessageTypeKeysStorageUpdated}; furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK); } @@ -195,20 +195,20 @@ int32_t bt_srv() { // Read keys if(!bt_load_key_storage(bt)) { - FURI_LOG_W(BT_SERVICE_TAG, "Failed to load saved bonding keys"); + FURI_LOG_W(TAG, "Failed to load saved bonding keys"); } // Start 2nd core if(!furi_hal_bt_start_core2()) { - FURI_LOG_E(BT_SERVICE_TAG, "Core2 startup failed"); + FURI_LOG_E(TAG, "Core2 startup failed"); } else { view_port_enabled_set(bt->statusbar_view_port, true); if(furi_hal_bt_init_app(bt_on_gap_event_callback, bt)) { - FURI_LOG_I(BT_SERVICE_TAG, "BLE stack started"); + FURI_LOG_I(TAG, "BLE stack started"); if(bt->bt_settings.enabled) { furi_hal_bt_start_advertising(); } } else { - FURI_LOG_E(BT_SERVICE_TAG, "BT App start failed"); + FURI_LOG_E(TAG, "BT App start failed"); } } furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt); diff --git a/applications/bt/bt_settings.c b/applications/bt/bt_settings.c index bd6399a9..9c154c47 100644 --- a/applications/bt/bt_settings.c +++ b/applications/bt/bt_settings.c @@ -2,7 +2,7 @@ #include #include -#define BT_SETTINGS_TAG "bt settings" +#define TAG "BtSettings" #define BT_SETTINGS_PATH "/int/bt.settings" bool bt_settings_load(BtSettings* bt_settings) { @@ -10,7 +10,7 @@ bool bt_settings_load(BtSettings* bt_settings) { bool file_loaded = false; BtSettings settings = {}; - FURI_LOG_I(BT_SETTINGS_TAG, "Loading settings from \"%s\"", BT_SETTINGS_PATH); + FURI_LOG_I(TAG, "Loading settings from \"%s\"", BT_SETTINGS_PATH); FileWorker* file_worker = file_worker_alloc(true); if(file_worker_open(file_worker, BT_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) { if(file_worker_read(file_worker, &settings, sizeof(settings))) { @@ -20,16 +20,16 @@ bool bt_settings_load(BtSettings* bt_settings) { file_worker_free(file_worker); if(file_loaded) { - FURI_LOG_I(BT_SETTINGS_TAG, "Settings load success"); + FURI_LOG_I(TAG, "Settings load success"); if(settings.version != BT_SETTINGS_VERSION) { - FURI_LOG_E(BT_SETTINGS_TAG, "Settings version mismatch"); + FURI_LOG_E(TAG, "Settings version mismatch"); } else { osKernelLock(); *bt_settings = settings; osKernelUnlock(); } } else { - FURI_LOG_E(BT_SETTINGS_TAG, "Settings load failed"); + FURI_LOG_E(TAG, "Settings load failed"); } return file_loaded; } @@ -41,7 +41,7 @@ bool bt_settings_save(BtSettings* bt_settings) { FileWorker* file_worker = file_worker_alloc(true); if(file_worker_open(file_worker, BT_SETTINGS_PATH, FSAM_WRITE, FSOM_OPEN_ALWAYS)) { if(file_worker_write(file_worker, bt_settings, sizeof(BtSettings))) { - FURI_LOG_I(BT_SETTINGS_TAG, "Settings saved to \"%s\"", BT_SETTINGS_PATH); + FURI_LOG_I(TAG, "Settings saved to \"%s\"", BT_SETTINGS_PATH); result = true; } } diff --git a/applications/debug_tools/bad_usb.c b/applications/debug_tools/bad_usb.c index ad20e26e..c5fc0f24 100644 --- a/applications/debug_tools/bad_usb.c +++ b/applications/debug_tools/bad_usb.c @@ -6,6 +6,9 @@ #include #include +#define TAG "BadUsb" +#define WORKER_TAG TAG "Worker" + typedef enum { EventTypeInput, EventTypeWorkerState, @@ -191,7 +194,7 @@ static bool ducky_parse_line(string_t line, BadUsbParams* app) { static void badusb_worker(void* context) { BadUsbParams* app = context; - FURI_LOG_I("BadUSB worker", "Init"); + FURI_LOG_I(WORKER_TAG, "Init"); File* script_file = storage_file_alloc(furi_record_open("storage")); BadUsbEvent evt; string_t line; @@ -203,7 +206,7 @@ static void badusb_worker(void* context) { uint32_t flags = osThreadFlagsWait(WorkerCmdStart | WorkerCmdStop, osFlagsWaitAny, osWaitForever); if(flags & WorkerCmdStart) { - FURI_LOG_I("BadUSB worker", "Start"); + FURI_LOG_I(WORKER_TAG, "Start"); do { ret = storage_file_read(script_file, buffer, 16); for(uint16_t i = 0; i < ret; i++) { @@ -211,7 +214,7 @@ static void badusb_worker(void* context) { line_cnt++; if(ducky_parse_line(line, app) == false) { ret = 0; - FURI_LOG_E("BadUSB worker", "Unknown command at line %lu", line_cnt); + FURI_LOG_E(WORKER_TAG, "Unknown command at line %lu", line_cnt); evt.type = EventTypeWorkerState; evt.worker.state = WorkerStateScriptError; evt.worker.line = line_cnt; @@ -231,7 +234,7 @@ static void badusb_worker(void* context) { } while(ret > 0); } } else { - FURI_LOG_E("BadUSB worker", "Script file open error"); + FURI_LOG_E(WORKER_TAG, "Script file open error"); evt.type = EventTypeWorkerState; evt.worker.state = WorkerStateNoFile; osMessageQueuePut(app->event_queue, &evt, 0, osWaitForever); @@ -243,7 +246,7 @@ static void badusb_worker(void* context) { storage_file_close(script_file); storage_file_free(script_file); - FURI_LOG_I("BadUSB worker", "End"); + FURI_LOG_I(WORKER_TAG, "End"); evt.type = EventTypeWorkerState; evt.worker.state = WorkerStateDone; osMessageQueuePut(app->event_queue, &evt, 0, osWaitForever); @@ -324,7 +327,7 @@ int32_t bad_usb_app(void* p) { } } } else if(event.type == EventTypeWorkerState) { - FURI_LOG_I("BadUSB app", "ev: %d", event.worker.state); + FURI_LOG_I(TAG, "ev: %d", event.worker.state); if(event.worker.state == WorkerStateDone) { worker_running = false; if(app_state == AppStateExit) diff --git a/applications/debug_tools/display_test/display_test.c b/applications/debug_tools/display_test/display_test.c index f2685a82..5a53562d 100644 --- a/applications/debug_tools/display_test/display_test.c +++ b/applications/debug_tools/display_test/display_test.c @@ -14,6 +14,8 @@ #include "view_display_test.h" +#define TAG "DisplayTest" + typedef struct { Gui* gui; ViewDispatcher* view_dispatcher; @@ -77,7 +79,7 @@ static uint32_t display_test_exit_callback(void* context) { static void display_test_reload_config(DisplayTest* instance) { FURI_LOG_I( - "DisplayTest", + TAG, "contrast: %d, regulation_ratio: %d, bias: %d", instance->config_contrast, instance->config_regulation_ratio, diff --git a/applications/debug_tools/keypad_test.c b/applications/debug_tools/keypad_test.c index e390ccd5..20f259aa 100644 --- a/applications/debug_tools/keypad_test.c +++ b/applications/debug_tools/keypad_test.c @@ -2,6 +2,8 @@ #include #include +#define TAG "KeypadTest" + typedef struct { bool press[5]; uint16_t up; @@ -80,7 +82,7 @@ int32_t keypad_test_app(void* p) { ValueMutex state_mutex; if(!init_mutex(&state_mutex, &_state, sizeof(KeypadTestState))) { - FURI_LOG_E("KeypadTest", "cannot create mutex"); + FURI_LOG_E(TAG, "cannot create mutex"); return 0; } @@ -101,7 +103,7 @@ int32_t keypad_test_app(void* p) { if(event_status == osOK) { if(event.type == EventTypeInput) { FURI_LOG_I( - "KeypadTest", + TAG, "key: %s type: %s", input_get_key_name(event.input.key), input_get_type_name(event.input.type)); diff --git a/applications/desktop/helpers/desktop_animation.c b/applications/desktop/helpers/desktop_animation.c index 07eaf631..f570b171 100644 --- a/applications/desktop/helpers/desktop_animation.c +++ b/applications/desktop/helpers/desktop_animation.c @@ -1,5 +1,7 @@ #include "desktop_animation.h" +#define TAG "DesktopAnimation" + static const Icon* idle_scenes[] = {&A_Wink_128x64, &A_WatchingTV_128x64}; const Icon* desktop_get_icon() { @@ -12,10 +14,10 @@ const Icon* desktop_get_icon() { DolphinStats stats = dolphin_stats(dolphin); float timediff = fabs(difftime(stats.timestamp, dolphin_state_timestamp())); - FURI_LOG_I("desktop-animation", "background change"); - FURI_LOG_I("desktop-animation", "icounter: %d", stats.icounter); - FURI_LOG_I("desktop-animation", "butthurt: %d", stats.butthurt); - FURI_LOG_I("desktop-animation", "time since deeed: %.0f", timediff); + FURI_LOG_I(TAG, "background change"); + FURI_LOG_I(TAG, "icounter: %d", stats.icounter); + FURI_LOG_I(TAG, "butthurt: %d", stats.butthurt); + FURI_LOG_I(TAG, "time since deeed: %.0f", timediff); #endif if((random() % 100) > 50) { // temp rnd selection diff --git a/applications/dialogs/view_holder.c b/applications/dialogs/view_holder.c index 2307bcd8..56d88001 100644 --- a/applications/dialogs/view_holder.c +++ b/applications/dialogs/view_holder.c @@ -1,6 +1,8 @@ #include "view-holder.h" #include +#define TAG "ViewHolder" + struct ViewHolder { View* view; ViewPort* view_port; @@ -125,7 +127,7 @@ static void view_holder_input_callback(InputEvent* event, void* context) { view_holder->ongoing_input &= ~key_bit; } else if(!(view_holder->ongoing_input & key_bit)) { FURI_LOG_W( - "ViewHolder", + TAG, "non-complementary input, discarding key: %s, type: %s", input_get_key_name(event->key), input_get_type_name(event->type)); diff --git a/applications/dolphin/dolphin.c b/applications/dolphin/dolphin.c index 1415f435..09bdb982 100644 --- a/applications/dolphin/dolphin.c +++ b/applications/dolphin/dolphin.c @@ -82,7 +82,7 @@ static void dolphin_check_butthurt(DolphinState* state) { float diff_time = difftime(dolphin_state_get_timestamp(state), dolphin_state_timestamp()); if((fabs(diff_time)) > DOLPHIN_TIMEGATE) { - FURI_LOG_I("dolphin-state", "Increasing butthurt"); + FURI_LOG_I("DolphinState", "Increasing butthurt"); dolphin_state_butthurted(state); } } diff --git a/applications/dolphin/helpers/dolphin_state.c b/applications/dolphin/helpers/dolphin_state.c index 379908c9..31066534 100644 --- a/applications/dolphin/helpers/dolphin_state.c +++ b/applications/dolphin/helpers/dolphin_state.c @@ -4,7 +4,7 @@ #include #include -#define DOLPHIN_STATE_TAG "DolphinState" +#define TAG "DolphinState" #define DOLPHIN_STATE_PATH "/int/dolphin.state" #define DOLPHIN_STATE_HEADER_MAGIC 0xD0 #define DOLPHIN_STATE_HEADER_VERSION 0x01 @@ -48,10 +48,10 @@ bool dolphin_state_save(DolphinState* dolphin_state) { DOLPHIN_STATE_HEADER_VERSION); if(result) { - FURI_LOG_I(DOLPHIN_STATE_TAG, "State saved"); + FURI_LOG_I(TAG, "State saved"); dolphin_state->dirty = false; } else { - FURI_LOG_E(DOLPHIN_STATE_TAG, "Failed to save state"); + FURI_LOG_E(TAG, "Failed to save state"); } return result; @@ -66,7 +66,7 @@ bool dolphin_state_load(DolphinState* dolphin_state) { DOLPHIN_STATE_HEADER_VERSION); if(!loaded) { - FURI_LOG_W(DOLPHIN_STATE_TAG, "Reset dolphin-state"); + FURI_LOG_W(TAG, "Reset dolphin-state"); memset(dolphin_state, 0, sizeof(*dolphin_state)); dolphin_state->dirty = true; } diff --git a/applications/gui/gui.c b/applications/gui/gui.c index 46a515a0..ff872ab4 100644 --- a/applications/gui/gui.c +++ b/applications/gui/gui.c @@ -1,5 +1,7 @@ #include "gui_i.h" +#define TAG "GuiSrv" + ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) { // Iterating backward ViewPortArray_it_t it; @@ -190,7 +192,7 @@ void gui_input(Gui* gui, InputEvent* input_event) { gui->ongoing_input |= key_bit; } else if(!(gui->ongoing_input & key_bit)) { FURI_LOG_D( - "Gui", + TAG, "non-complementary input, discarding key: %s type: %s, sequence: %p", input_get_key_name(input_event->key), input_get_type_name(input_event->type), @@ -212,7 +214,7 @@ void gui_input(Gui* gui, InputEvent* input_event) { view_port_input(view_port, input_event); } else if(gui->ongoing_input_view_port && input_event->type == InputTypeRelease) { FURI_LOG_D( - "Gui", + TAG, "ViewPort changed while key press %p -> %p. Sending key: %s, type: %s, sequence: %p to previous view port", gui->ongoing_input_view_port, view_port, @@ -222,7 +224,7 @@ void gui_input(Gui* gui, InputEvent* input_event) { view_port_input(gui->ongoing_input_view_port, input_event); } else { FURI_LOG_D( - "Gui", + TAG, "ViewPort changed while key press %p -> %p. Discarding key: %s, type: %s, sequence: %p", gui->ongoing_input_view_port, view_port, diff --git a/applications/gui/view_dispatcher.c b/applications/gui/view_dispatcher.c index e50c1809..f12cfe8b 100644 --- a/applications/gui/view_dispatcher.c +++ b/applications/gui/view_dispatcher.c @@ -1,5 +1,7 @@ #include "view_dispatcher_i.h" +#define TAG "ViewDispatcher" + ViewDispatcher* view_dispatcher_alloc() { ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher)); @@ -237,7 +239,7 @@ void view_dispatcher_handle_input(ViewDispatcher* view_dispatcher, InputEvent* e view_dispatcher->ongoing_input &= ~key_bit; } else if(!(view_dispatcher->ongoing_input & key_bit)) { FURI_LOG_D( - "ViewDispatcher", + TAG, "non-complementary input, discarding key: %s, type: %s, sequence: %p", input_get_key_name(event->key), input_get_type_name(event->type), @@ -276,7 +278,7 @@ void view_dispatcher_handle_input(ViewDispatcher* view_dispatcher, InputEvent* e } } else if(view_dispatcher->ongoing_input_view && event->type == InputTypeRelease) { FURI_LOG_D( - "ViewDispatcher", + TAG, "View changed while key press %p -> %p. Sending key: %s, type: %s, sequence: %p to previous view port", view_dispatcher->ongoing_input_view, view_dispatcher->current_view, diff --git a/applications/irda/irda-app-file-parser.cpp b/applications/irda/irda-app-file-parser.cpp index 3ab14fc0..b556fb6c 100644 --- a/applications/irda/irda-app-file-parser.cpp +++ b/applications/irda/irda-app-file-parser.cpp @@ -11,6 +11,8 @@ #include #include +#define TAG "IrdaFileParser" + bool IrdaAppFileParser::open_irda_file_read(const char* name) { std::string full_filename; if(name[0] != '/') @@ -154,11 +156,7 @@ std::unique_ptr if(!irda_is_protocol_valid((IrdaProtocol)protocol)) { size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30); FURI_LOG_E( - "IrdaFileParser", - "Unknown protocol(\'%.*s...\'): \'%s\'", - end_of_str, - str.c_str(), - protocol_name); + TAG, "Unknown protocol(\'%.*s...\'): \'%s\'", end_of_str, str.c_str(), protocol_name); return nullptr; } @@ -167,7 +165,7 @@ std::unique_ptr if(address != (address & address_mask)) { size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30); FURI_LOG_E( - "IrdaFileParser", + TAG, "Signal(\'%.*s...\'): address is too long (mask for this protocol is 0x%08X): 0x%X", end_of_str, str.c_str(), @@ -181,7 +179,7 @@ std::unique_ptr if(command != (command & command_mask)) { size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30); FURI_LOG_E( - "IrdaFileParser", + TAG, "Signal(\'%.*s...\'): command is too long (mask for this protocol is 0x%08X): 0x%X", end_of_str, str.c_str(), @@ -256,7 +254,7 @@ std::unique_ptr if((frequency < IRDA_MIN_FREQUENCY) || (frequency > IRDA_MAX_FREQUENCY)) { size_t end_of_str = MIN(string.find_last_not_of(" \t\r\n") + 1, (size_t)30); FURI_LOG_E( - "IrdaFileParser", + TAG, "RAW signal(\'%.*s...\'): frequency is out of bounds (%ld-%ld): %ld", end_of_str, string.c_str(), @@ -269,7 +267,7 @@ std::unique_ptr if((duty_cycle == 0) || (duty_cycle > 100)) { size_t end_of_str = MIN(string.find_last_not_of(" \t\r\n") + 1, (size_t)30); FURI_LOG_E( - "IrdaFileParser", + TAG, "RAW signal(\'%.*s...\'): duty cycle is out of bounds (0-100): %ld", end_of_str, string.c_str(), @@ -283,8 +281,7 @@ std::unique_ptr if(last_valid_ch != std::string_view::npos) { str.remove_suffix(str.size() - last_valid_ch - 1); } else { - FURI_LOG_E( - "IrdaFileParser", "RAW signal(\'%.*s\'): no timings", header_len, string.c_str()); + FURI_LOG_E(TAG, "RAW signal(\'%.*s\'): no timings", header_len, string.c_str()); return nullptr; } @@ -303,7 +300,7 @@ std::unique_ptr parsed = std::sscanf(str.data(), "%9s", buf); if(parsed != 1) { FURI_LOG_E( - "IrdaFileParser", + TAG, "RAW signal(\'%.*s...\'): failed on timing[%ld] \'%*s\'", header_len, string.c_str(), @@ -318,7 +315,7 @@ std::unique_ptr int value = atoi(buf); if(value <= 0) { FURI_LOG_E( - "IrdaFileParser", + TAG, "RAW signal(\'%.*s...\'): failed on timing[%ld] \'%s\'", header_len, string.c_str(), @@ -330,7 +327,7 @@ std::unique_ptr if(raw_signal.timings_cnt >= max_raw_timings_in_signal) { FURI_LOG_E( - "IrdaFileParser", + TAG, "RAW signal(\'%.*s...\'): too much timings (max %ld)", header_len, string.c_str(), diff --git a/applications/loader/loader.c b/applications/loader/loader.c index 574db256..98ce42b1 100644 --- a/applications/loader/loader.c +++ b/applications/loader/loader.c @@ -1,6 +1,8 @@ #include "loader/loader.h" #include "loader_i.h" +#define TAG "LoaderSrv" + #define LOADER_THREAD_FLAG_SHOW_MENU (1 << 0) #define LOADER_THREAD_FLAG_ALL (LOADER_THREAD_FLAG_SHOW_MENU) @@ -15,15 +17,13 @@ static void loader_menu_callback(void* _ctx, uint32_t index) { if(!loader_lock(loader_instance)) return; if(furi_thread_get_state(loader_instance->thread) != FuriThreadStateStopped) { - FURI_LOG_E( - LOADER_LOG_TAG, "Can't start app. %s is running", loader_instance->current_app->name); + FURI_LOG_E(TAG, "Can't start app. %s is running", loader_instance->current_app->name); return; } furi_hal_power_insomnia_enter(); loader_instance->current_app = flipper_app; - FURI_LOG_I( - LOADER_LOG_TAG, "Starting furi application: %s", loader_instance->current_app->name); + FURI_LOG_I(TAG, "Starting furi application: %s", loader_instance->current_app->name); furi_thread_set_name(loader_instance->thread, flipper_app->name); furi_thread_set_stack_size(loader_instance->thread, flipper_app->stack_size); furi_thread_set_context(loader_instance->thread, NULL); @@ -79,14 +79,14 @@ LoaderStatus loader_start(Loader* instance, const char* name, const char* args) } if(!flipper_app) { - FURI_LOG_E(LOADER_LOG_TAG, "Can't find application with name %s", name); + FURI_LOG_E(TAG, "Can't find application with name %s", name); return LoaderStatusErrorUnknownApp; } bool locked = loader_lock(instance); if(!locked || (furi_thread_get_state(instance->thread) != FuriThreadStateStopped)) { - FURI_LOG_E(LOADER_LOG_TAG, "Can't start app. %s is running", instance->current_app->name); + FURI_LOG_E(TAG, "Can't start app. %s is running", instance->current_app->name); /* no need to call loader_unlock() - it is called as soon as application stops */ return LoaderStatusErrorAppStarted; } @@ -97,10 +97,10 @@ LoaderStatus loader_start(Loader* instance, const char* name, const char* args) string_set_str(instance->args, args); string_strim(instance->args); thread_args = (void*)string_get_cstr(instance->args); - FURI_LOG_I(LOADER_LOG_TAG, "Start %s app with args: %s", name, args); + FURI_LOG_I(TAG, "Start %s app with args: %s", name, args); } else { string_clean(instance->args); - FURI_LOG_I(LOADER_LOG_TAG, "Start %s app with no args", name); + FURI_LOG_I(TAG, "Start %s app with no args", name); } furi_thread_set_name(instance->thread, flipper_app->name); @@ -155,7 +155,7 @@ static void loader_thread_state_callback(FuriThreadState thread_state, void* con delay(20); int heap_diff = instance->free_heap_size - memmgr_get_free_heap(); FURI_LOG_I( - LOADER_LOG_TAG, + TAG, "Application thread stopped. Heap allocation balance: %d. Thread allocation balance: %d.", heap_diff, furi_thread_get_heap_size(instance->thread)); @@ -266,7 +266,7 @@ static void loader_add_cli_command(FlipperApplication* app) { } static void loader_build_menu() { - FURI_LOG_I(LOADER_LOG_TAG, "Building main menu"); + FURI_LOG_I(TAG, "Building main menu"); size_t i; for(i = 0; i < FLIPPER_APPS_COUNT; i++) { loader_add_cli_command((FlipperApplication*)&FLIPPER_APPS[i]); @@ -300,7 +300,7 @@ static void loader_build_menu() { loader_submenu_callback, (void*)LoaderMenuViewSettings); - FURI_LOG_I(LOADER_LOG_TAG, "Building plugins menu"); + FURI_LOG_I(TAG, "Building plugins menu"); for(i = 0; i < FLIPPER_PLUGINS_COUNT; i++) { loader_add_cli_command((FlipperApplication*)&FLIPPER_PLUGINS[i]); submenu_add_item( @@ -311,7 +311,7 @@ static void loader_build_menu() { (void*)&FLIPPER_PLUGINS[i]); } - FURI_LOG_I(LOADER_LOG_TAG, "Building debug menu"); + FURI_LOG_I(TAG, "Building debug menu"); for(i = 0; i < FLIPPER_DEBUG_APPS_COUNT; i++) { loader_add_cli_command((FlipperApplication*)&FLIPPER_DEBUG_APPS[i]); submenu_add_item( @@ -322,7 +322,7 @@ static void loader_build_menu() { (void*)&FLIPPER_DEBUG_APPS[i]); } - FURI_LOG_I(LOADER_LOG_TAG, "Building settings menu"); + FURI_LOG_I(TAG, "Building settings menu"); for(i = 0; i < FLIPPER_SETTINGS_APPS_COUNT; i++) { submenu_add_item( loader_instance->settings_menu, @@ -339,7 +339,7 @@ void loader_show_menu() { } int32_t loader_srv(void* p) { - FURI_LOG_I(LOADER_LOG_TAG, "Starting"); + FURI_LOG_I(TAG, "Starting"); loader_instance = loader_alloc(); @@ -350,7 +350,7 @@ int32_t loader_srv(void* p) { FLIPPER_ON_SYSTEM_START[i](); } - FURI_LOG_I(LOADER_LOG_TAG, "Started"); + FURI_LOG_I(TAG, "Started"); furi_record_create("loader", loader_instance); diff --git a/applications/loader/loader_i.h b/applications/loader/loader_i.h index 8d44911f..08c9ac09 100644 --- a/applications/loader/loader_i.h +++ b/applications/loader/loader_i.h @@ -12,8 +12,6 @@ #include #include -#define LOADER_LOG_TAG "loader" - struct Loader { osThreadId_t loader_thread; FuriThread* thread; diff --git a/applications/nfc/nfc_worker.c b/applications/nfc/nfc_worker.c old mode 100755 new mode 100644 index cbd7fe35..3f7f87e4 --- a/applications/nfc/nfc_worker.c +++ b/applications/nfc/nfc_worker.c @@ -3,7 +3,7 @@ #include "nfc_protocols/emv_decoder.h" #include "nfc_protocols/mifare_ultralight.h" -#define NFC_WORKER_TAG "nfc worker" +#define TAG "NfcWorker" /***************************** NFC Worker API *******************************/ @@ -144,7 +144,7 @@ void nfc_worker_emulate(NfcWorker* nfc_worker) { NfcDeviceCommonData* data = &nfc_worker->dev_data->nfc_data; while(nfc_worker->state == NfcWorkerStateEmulate) { if(furi_hal_nfc_listen(data->uid, data->uid_len, data->atqa, data->sak, false, 100)) { - FURI_LOG_I(NFC_WORKER_TAG, "Reader detected"); + FURI_LOG_I(TAG, "Reader detected"); } osDelay(10); } @@ -174,18 +174,17 @@ void nfc_worker_read_emv_app(NfcWorker* nfc_worker) { result->nfc_data.uid, dev_list[0].dev.nfca.nfcId1, result->nfc_data.uid_len); result->nfc_data.protocol = NfcDeviceProtocolEMV; - FURI_LOG_I(NFC_WORKER_TAG, "Send select PPSE command"); + FURI_LOG_I(TAG, "Send select PPSE command"); tx_len = emv_prepare_select_ppse(tx_buff); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err != ERR_NONE) { - FURI_LOG_E(NFC_WORKER_TAG, "Error during selection PPSE request: %d", err); + FURI_LOG_E(TAG, "Error during selection PPSE request: %d", err); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I( - NFC_WORKER_TAG, "Select PPSE response received. Start parsing response"); + FURI_LOG_I(TAG, "Select PPSE response received. Start parsing response"); if(emv_decode_ppse_response(rx_buff, *rx_len, &emv_app)) { - FURI_LOG_I(NFC_WORKER_TAG, "Select PPSE responce parced"); + FURI_LOG_I(TAG, "Select PPSE responce parced"); // Notify caller and exit result->emv_data.aid_len = emv_app.aid_len; memcpy(result->emv_data.aid, emv_app.aid, emv_app.aid_len); @@ -194,18 +193,18 @@ void nfc_worker_read_emv_app(NfcWorker* nfc_worker) { } break; } else { - FURI_LOG_E(NFC_WORKER_TAG, "Can't find pay application"); + FURI_LOG_E(TAG, "Can't find pay application"); furi_hal_nfc_deactivate(); continue; } } else { // Can't find EMV card - FURI_LOG_W(NFC_WORKER_TAG, "Card doesn't support EMV"); + FURI_LOG_W(TAG, "Card doesn't support EMV"); furi_hal_nfc_deactivate(); } } else { // Can't find EMV card - FURI_LOG_W(NFC_WORKER_TAG, "Can't find any cards"); + FURI_LOG_W(TAG, "Can't find any cards"); furi_hal_nfc_deactivate(); } osDelay(20); @@ -236,58 +235,53 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) { result->nfc_data.uid, dev_list[0].dev.nfca.nfcId1, result->nfc_data.uid_len); result->nfc_data.protocol = NfcDeviceProtocolEMV; - FURI_LOG_I(NFC_WORKER_TAG, "Send select PPSE command"); + FURI_LOG_I(TAG, "Send select PPSE command"); tx_len = emv_prepare_select_ppse(tx_buff); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err != ERR_NONE) { - FURI_LOG_E(NFC_WORKER_TAG, "Error during selection PPSE request: %d", err); + FURI_LOG_E(TAG, "Error during selection PPSE request: %d", err); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I( - NFC_WORKER_TAG, "Select PPSE response received. Start parsing response"); + FURI_LOG_I(TAG, "Select PPSE response received. Start parsing response"); if(emv_decode_ppse_response(rx_buff, *rx_len, &emv_app)) { - FURI_LOG_I(NFC_WORKER_TAG, "Select PPSE responce parced"); + FURI_LOG_I(TAG, "Select PPSE responce parced"); result->emv_data.aid_len = emv_app.aid_len; memcpy(result->emv_data.aid, emv_app.aid, emv_app.aid_len); } else { - FURI_LOG_E(NFC_WORKER_TAG, "Can't find pay application"); + FURI_LOG_E(TAG, "Can't find pay application"); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I(NFC_WORKER_TAG, "Starting application ..."); + FURI_LOG_I(TAG, "Starting application ..."); tx_len = emv_prepare_select_app(tx_buff, &emv_app); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err != ERR_NONE) { - FURI_LOG_E( - NFC_WORKER_TAG, "Error during application selection request: %d", err); + FURI_LOG_E(TAG, "Error during application selection request: %d", err); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I( - NFC_WORKER_TAG, - "Select application response received. Start parsing response"); + FURI_LOG_I(TAG, "Select application response received. Start parsing response"); if(emv_decode_select_app_response(rx_buff, *rx_len, &emv_app)) { - FURI_LOG_I(NFC_WORKER_TAG, "Card name: %s", emv_app.name); + FURI_LOG_I(TAG, "Card name: %s", emv_app.name); memcpy(result->emv_data.name, emv_app.name, sizeof(emv_app.name)); } else if(emv_app.pdol.size > 0) { - FURI_LOG_W(NFC_WORKER_TAG, "Can't find card name, but PDOL is present."); + FURI_LOG_W(TAG, "Can't find card name, but PDOL is present."); } else { - FURI_LOG_E(NFC_WORKER_TAG, "Can't find card name or PDOL"); + FURI_LOG_E(TAG, "Can't find card name or PDOL"); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I(NFC_WORKER_TAG, "Starting Get Processing Options command ..."); + FURI_LOG_I(TAG, "Starting Get Processing Options command ..."); tx_len = emv_prepare_get_proc_opt(tx_buff, &emv_app); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err != ERR_NONE) { - FURI_LOG_E( - NFC_WORKER_TAG, "Error during Get Processing Options command: %d", err); + FURI_LOG_E(TAG, "Error during Get Processing Options command: %d", err); furi_hal_nfc_deactivate(); continue; } if(emv_decode_get_proc_opt(rx_buff, *rx_len, &emv_app)) { - FURI_LOG_I(NFC_WORKER_TAG, "Card number parsed"); + FURI_LOG_I(TAG, "Card number parsed"); result->emv_data.number_len = emv_app.card_number_len; memcpy(result->emv_data.number, emv_app.card_number, emv_app.card_number_len); // Notify caller and exit @@ -311,7 +305,7 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) { tx_buff, tx_len, &rx_buff, &rx_len, false); if(err != ERR_NONE) { FURI_LOG_E( - NFC_WORKER_TAG, + TAG, "Error reading application sfi %d, record %d", sfi, record); @@ -323,7 +317,7 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) { } } if(pan_found) { - FURI_LOG_I(NFC_WORKER_TAG, "Card PAN found"); + FURI_LOG_I(TAG, "Card PAN found"); result->emv_data.number_len = emv_app.card_number_len; memcpy( result->emv_data.number, @@ -345,18 +339,18 @@ void nfc_worker_read_emv(NfcWorker* nfc_worker) { } break; } else { - FURI_LOG_E(NFC_WORKER_TAG, "Can't read card number"); + FURI_LOG_E(TAG, "Can't read card number"); } furi_hal_nfc_deactivate(); } } else { // Can't find EMV card - FURI_LOG_W(NFC_WORKER_TAG, "Card doesn't support EMV"); + FURI_LOG_W(TAG, "Card doesn't support EMV"); furi_hal_nfc_deactivate(); } } else { // Can't find EMV card - FURI_LOG_W(NFC_WORKER_TAG, "Can't find any cards"); + FURI_LOG_W(TAG, "Can't find any cards"); furi_hal_nfc_deactivate(); } osDelay(20); @@ -418,63 +412,63 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { while(nfc_worker->state == NfcWorkerStateEmulateApdu) { if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 300)) { - FURI_LOG_I(NFC_WORKER_TAG, "POS terminal detected"); + FURI_LOG_I(TAG, "POS terminal detected"); // Read data from POS terminal err = furi_hal_nfc_data_exchange(NULL, 0, &rx_buff, &rx_len, false); if(err == ERR_NONE) { - FURI_LOG_I(NFC_WORKER_TAG, "Received Select PPSE"); + FURI_LOG_I(TAG, "Received Select PPSE"); } else { - FURI_LOG_E(NFC_WORKER_TAG, "Error in 1st data exchange: select PPSE"); + FURI_LOG_E(TAG, "Error in 1st data exchange: select PPSE"); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I(NFC_WORKER_TAG, "Transive SELECT PPSE ANS"); + FURI_LOG_I(TAG, "Transive SELECT PPSE ANS"); tx_len = emv_select_ppse_ans(tx_buff); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err == ERR_NONE) { - FURI_LOG_I(NFC_WORKER_TAG, "Received Select APP"); + FURI_LOG_I(TAG, "Received Select APP"); } else { - FURI_LOG_E(NFC_WORKER_TAG, "Error in 2nd data exchange: select APP"); + FURI_LOG_E(TAG, "Error in 2nd data exchange: select APP"); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I(NFC_WORKER_TAG, "Transive SELECT APP ANS"); + FURI_LOG_I(TAG, "Transive SELECT APP ANS"); tx_len = emv_select_app_ans(tx_buff); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err == ERR_NONE) { - FURI_LOG_I(NFC_WORKER_TAG, "Received PDOL"); + FURI_LOG_I(TAG, "Received PDOL"); } else { - FURI_LOG_E(NFC_WORKER_TAG, "Error in 3rd data exchange: receive PDOL"); + FURI_LOG_E(TAG, "Error in 3rd data exchange: receive PDOL"); furi_hal_nfc_deactivate(); continue; } - FURI_LOG_I(NFC_WORKER_TAG, "Transive PDOL ANS"); + FURI_LOG_I(TAG, "Transive PDOL ANS"); tx_len = emv_get_proc_opt_ans(tx_buff); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err == ERR_NONE) { - FURI_LOG_I(NFC_WORKER_TAG, "Transive PDOL ANS"); + FURI_LOG_I(TAG, "Transive PDOL ANS"); } else { - FURI_LOG_E(NFC_WORKER_TAG, "Error in 4rd data exchange: Transive PDOL ANS"); + FURI_LOG_E(TAG, "Error in 4rd data exchange: Transive PDOL ANS"); furi_hal_nfc_deactivate(); continue; } if(*rx_len != sizeof(debug_rx) || memcmp(rx_buff, debug_rx, sizeof(debug_rx))) { - FURI_LOG_E(NFC_WORKER_TAG, "Failed long message test"); + FURI_LOG_E(TAG, "Failed long message test"); } else { - FURI_LOG_I(NFC_WORKER_TAG, "Correct debug message received"); + FURI_LOG_I(TAG, "Correct debug message received"); tx_len = sizeof(debug_tx); err = furi_hal_nfc_data_exchange( (uint8_t*)debug_tx, tx_len, &rx_buff, &rx_len, false); if(err == ERR_NONE) { - FURI_LOG_I(NFC_WORKER_TAG, "Transive Debug message"); + FURI_LOG_I(TAG, "Transive Debug message"); } } furi_hal_nfc_deactivate(); } else { - FURI_LOG_W(NFC_WORKER_TAG, "Can't find reader"); + FURI_LOG_W(TAG, "Can't find reader"); } osDelay(20); } @@ -501,71 +495,69 @@ void nfc_worker_read_mifare_ul(NfcWorker* nfc_worker) { dev_list[0].dev.nfca.sensRes.platformInfo, dev_list[0].dev.nfca.selRes.sak)) { // Get Mifare Ultralight version - FURI_LOG_I(NFC_WORKER_TAG, "Found Mifare Ultralight tag. Reading tag version"); + FURI_LOG_I(TAG, "Found Mifare Ultralight tag. Reading tag version"); tx_len = mf_ul_prepare_get_version(tx_buff); err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); if(err == ERR_NONE) { mf_ul_parse_get_version_response(rx_buff, &mf_ul_read); FURI_LOG_I( - NFC_WORKER_TAG, + TAG, "Mifare Ultralight Type: %d, Pages: %d", mf_ul_read.type, mf_ul_read.pages_to_read); - FURI_LOG_I(NFC_WORKER_TAG, "Reading signature ..."); + FURI_LOG_I(TAG, "Reading signature ..."); tx_len = mf_ul_prepare_read_signature(tx_buff); if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) { - FURI_LOG_W(NFC_WORKER_TAG, "Failed reading signature"); + FURI_LOG_W(TAG, "Failed reading signature"); memset(mf_ul_read.data.signature, 0, sizeof(mf_ul_read.data.signature)); } else { mf_ul_parse_read_signature_response(rx_buff, &mf_ul_read); } } else if(err == ERR_TIMEOUT) { FURI_LOG_W( - NFC_WORKER_TAG, + TAG, "Card doesn't respond to GET VERSION command. Setting default read parameters"); err = ERR_NONE; mf_ul_set_default_version(&mf_ul_read); // Reinit device furi_hal_nfc_deactivate(); if(!furi_hal_nfc_detect(&dev_list, &dev_cnt, 300, false)) { - FURI_LOG_E(NFC_WORKER_TAG, "Lost connection. Restarting search"); + FURI_LOG_E(TAG, "Lost connection. Restarting search"); continue; } } else { FURI_LOG_E( - NFC_WORKER_TAG, - "Error getting Mifare Ultralight version. Error code: %d", - err); + TAG, "Error getting Mifare Ultralight version. Error code: %d", err); continue; } if(mf_ul_read.support_fast_read) { - FURI_LOG_I(NFC_WORKER_TAG, "Reading pages ..."); + FURI_LOG_I(TAG, "Reading pages ..."); tx_len = mf_ul_prepare_fast_read(tx_buff, 0x00, mf_ul_read.pages_to_read - 1); if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) { - FURI_LOG_E(NFC_WORKER_TAG, "Failed reading pages"); + FURI_LOG_E(TAG, "Failed reading pages"); continue; } else { mf_ul_parse_fast_read_response( rx_buff, 0x00, mf_ul_read.pages_to_read - 1, &mf_ul_read); } - FURI_LOG_I(NFC_WORKER_TAG, "Reading 3 counters ..."); + FURI_LOG_I(TAG, "Reading 3 counters ..."); for(uint8_t i = 0; i < 3; i++) { tx_len = mf_ul_prepare_read_cnt(tx_buff, i); if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) { - FURI_LOG_W(NFC_WORKER_TAG, "Failed reading Counter %d", i); + FURI_LOG_W(TAG, "Failed reading Counter %d", i); mf_ul_read.data.counter[i] = 0; } else { mf_ul_parse_read_cnt_response(rx_buff, i, &mf_ul_read); } } - FURI_LOG_I(NFC_WORKER_TAG, "Checking tearing flags ..."); + FURI_LOG_I(TAG, "Checking tearing flags ..."); for(uint8_t i = 0; i < 3; i++) { tx_len = mf_ul_prepare_check_tearing(tx_buff, i); if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) { - FURI_LOG_E(NFC_WORKER_TAG, "Error checking tearing flag %d", i); + FURI_LOG_E(TAG, "Error checking tearing flag %d", i); mf_ul_read.data.tearing[i] = MF_UL_TEARING_FLAG_DEFAULT; } else { mf_ul_parse_check_tearing_response(rx_buff, i, &mf_ul_read); @@ -574,11 +566,10 @@ void nfc_worker_read_mifare_ul(NfcWorker* nfc_worker) { } else { // READ card with READ command (4 pages at a time) for(uint8_t page = 0; page < mf_ul_read.pages_to_read; page += 4) { - FURI_LOG_I(NFC_WORKER_TAG, "Reading pages %d - %d ...", page, page + 3); + FURI_LOG_I(TAG, "Reading pages %d - %d ...", page, page + 3); tx_len = mf_ul_prepare_read(tx_buff, page); if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) { - FURI_LOG_E( - NFC_WORKER_TAG, "Read pages %d - %d failed", page, page + 3); + FURI_LOG_E(TAG, "Read pages %d - %d failed", page, page + 3); continue; } else { mf_ul_parse_read_response(rx_buff, page, &mf_ul_read); @@ -602,10 +593,10 @@ void nfc_worker_read_mifare_ul(NfcWorker* nfc_worker) { } break; } else { - FURI_LOG_W(NFC_WORKER_TAG, "Tag does not support Mifare Ultralight"); + FURI_LOG_W(TAG, "Tag does not support Mifare Ultralight"); } } else { - FURI_LOG_W(NFC_WORKER_TAG, "Can't find any tags"); + FURI_LOG_W(TAG, "Can't find any tags"); } osDelay(100); } @@ -629,7 +620,7 @@ void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) { data->nfc_data.sak, true, 200)) { - FURI_LOG_D(NFC_WORKER_TAG, "Anticollision passed"); + FURI_LOG_D(TAG, "Anticollision passed"); if(furi_hal_nfc_get_first_frame(&rx_buff, &rx_len)) { // Data exchange loop while(nfc_worker->state == NfcWorkerStateEmulateMifareUl) { @@ -641,17 +632,17 @@ void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) { if(err == ERR_NONE) { continue; } else { - FURI_LOG_E(NFC_WORKER_TAG, "Communication error: %d", err); + FURI_LOG_E(TAG, "Communication error: %d", err); break; } } else { - FURI_LOG_W(NFC_WORKER_TAG, "Not valid command: %02X", rx_buff[0]); + FURI_LOG_W(TAG, "Not valid command: %02X", rx_buff[0]); furi_hal_nfc_deactivate(); break; } } } else { - FURI_LOG_W(NFC_WORKER_TAG, "Error in 1st data exchange"); + FURI_LOG_W(TAG, "Error in 1st data exchange"); furi_hal_nfc_deactivate(); } } @@ -662,7 +653,7 @@ void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) { nfc_worker->callback(nfc_worker->context); } } - FURI_LOG_W(NFC_WORKER_TAG, "Can't find reader"); + FURI_LOG_W(TAG, "Can't find reader"); osThreadYield(); } } diff --git a/applications/notification/notification-app.c b/applications/notification/notification-app.c index 3912cf62..62a58ff6 100644 --- a/applications/notification/notification-app.c +++ b/applications/notification/notification-app.c @@ -5,6 +5,8 @@ #include "notification-messages.h" #include "notification-app.h" +#define TAG "NotificationSrv" + static const uint8_t minimal_delay = 100; static const uint8_t led_off_values[NOTIFICATION_LED_COUNT] = {0x00, 0x00, 0x00}; @@ -314,7 +316,7 @@ static bool notification_load_settings(NotificationApp* app) { File* file = storage_file_alloc(furi_record_open("storage")); const size_t settings_size = sizeof(NotificationSettings); - FURI_LOG_I("notification", "loading settings from \"%s\"", NOTIFICATION_SETTINGS_PATH); + FURI_LOG_I(TAG, "loading settings from \"%s\"", NOTIFICATION_SETTINGS_PATH); bool fs_result = storage_file_open(file, NOTIFICATION_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING); @@ -327,21 +329,18 @@ static bool notification_load_settings(NotificationApp* app) { } if(fs_result) { - FURI_LOG_I("notification", "load success"); + FURI_LOG_I(TAG, "load success"); if(settings.version != NOTIFICATION_SETTINGS_VERSION) { FURI_LOG_E( - "notification", - "version(%d != %d) mismatch", - settings.version, - NOTIFICATION_SETTINGS_VERSION); + TAG, "version(%d != %d) mismatch", settings.version, NOTIFICATION_SETTINGS_VERSION); } else { osKernelLock(); memcpy(&app->settings, &settings, settings_size); osKernelUnlock(); } } else { - FURI_LOG_E("notification", "load failed, %s", storage_file_get_error_desc(file)); + FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file)); } storage_file_close(file); @@ -356,7 +355,7 @@ static bool notification_save_settings(NotificationApp* app) { File* file = storage_file_alloc(furi_record_open("storage")); const size_t settings_size = sizeof(NotificationSettings); - FURI_LOG_I("notification", "saving settings to \"%s\"", NOTIFICATION_SETTINGS_PATH); + FURI_LOG_I(TAG, "saving settings to \"%s\"", NOTIFICATION_SETTINGS_PATH); osKernelLock(); memcpy(&settings, &app->settings, settings_size); @@ -374,9 +373,9 @@ static bool notification_save_settings(NotificationApp* app) { } if(fs_result) { - FURI_LOG_I("notification", "save success"); + FURI_LOG_I(TAG, "save success"); } else { - FURI_LOG_E("notification", "save failed, %s", storage_file_get_error_desc(file)); + FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file)); } storage_file_close(file); diff --git a/applications/rpc/rpc.c b/applications/rpc/rpc.c old mode 100755 new mode 100644 index 3d4243c0..123f1faa --- a/applications/rpc/rpc.c +++ b/applications/rpc/rpc.c @@ -9,6 +9,7 @@ #include #include #include + #include #include #include @@ -16,14 +17,12 @@ #include #include -#define RPC_TAG "RPC" +#define TAG "RpcSrv" #define RPC_EVENT_NEW_DATA (1 << 0) #define RPC_EVENT_DISCONNECT (1 << 1) #define RPC_EVENTS_ALL (RPC_EVENT_DISCONNECT | RPC_EVENT_NEW_DATA) -#define DEBUG_PRINT 0 - DICT_DEF2(RpcHandlerDict, pb_size_t, M_DEFAULT_OPLIST, RpcHandler, M_POD_OPLIST) typedef struct { @@ -264,6 +263,7 @@ void rpc_print_message(const PB_Main* message) { size_t msg_file_count = message->content.storage_list_response.file_count; string_cat_printf(str, "\tlist_response {\r\n"); rpc_sprintf_msg_file(str, "\t\t", msg_file, msg_file_count); + break; } case PB_Main_gui_start_screen_stream_request_tag: string_cat_printf(str, "\tstart_screen_stream {\r\n"); @@ -271,8 +271,8 @@ void rpc_print_message(const PB_Main* message) { case PB_Main_gui_stop_screen_stream_request_tag: string_cat_printf(str, "\tstop_screen_stream {\r\n"); break; - case PB_Main_gui_screen_stream_frame_tag: - string_cat_printf(str, "\tscreen_stream_frame {\r\n"); + case PB_Main_gui_screen_frame_tag: + string_cat_printf(str, "\tscreen_frame {\r\n"); break; case PB_Main_gui_send_input_event_request_tag: string_cat_printf(str, "\tsend_input_event {\r\n"); @@ -281,6 +281,12 @@ void rpc_print_message(const PB_Main* message) { string_cat_printf( str, "\t\type: %d\r\n", message->content.gui_send_input_event_request.type); break; + case PB_Main_gui_start_virtual_display_request_tag: + string_cat_printf(str, "\tstart_virtual_display {\r\n"); + break; + case PB_Main_gui_stop_virtual_display_request_tag: + string_cat_printf(str, "\tstop_virtual_display {\r\n"); + break; } string_cat_printf(str, "\t}\r\n}\r\n"); printf("%s", string_get_cstr(str)); @@ -335,7 +341,7 @@ RpcSession* rpc_session_open(Rpc* rpc) { }; rpc_add_handler(rpc, PB_Main_stop_session_tag, &rpc_handler); - FURI_LOG_D(RPC_TAG, "Session started\r\n"); + FURI_LOG_D(TAG, "Session started\r\n"); } return result ? &rpc->session : NULL; /* support 1 open session for now */ @@ -468,7 +474,7 @@ bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) { } } -#if DEBUG_PRINT +#if SRV_RPC_DEBUG rpc_print_data("INPUT", buf, bytes_received); #endif @@ -481,8 +487,8 @@ void rpc_send_and_release(Rpc* rpc, PB_Main* message) { RpcSession* session = &rpc->session; pb_ostream_t ostream = PB_OSTREAM_SIZING; -#if DEBUG_PRINT - FURI_LOG_I(RPC_TAG, "OUTPUT:"); +#if SRV_RPC_DEBUG + FURI_LOG_I(TAG, "OUTPUT:"); rpc_print_message(message); #endif @@ -494,7 +500,7 @@ void rpc_send_and_release(Rpc* rpc, PB_Main* message) { pb_encode_ex(&ostream, &PB_Main_msg, message, PB_ENCODE_DELIMITED); -#if DEBUG_PRINT +#if SRV_RPC_DEBUG rpc_print_data("OUTPUT", buffer, ostream.bytes_written); #endif @@ -535,12 +541,12 @@ int32_t rpc_srv(void* p) { .callback = rpc_pb_stream_read, .state = rpc, .errmsg = NULL, - .bytes_left = 1024, /* max incoming message size */ + .bytes_left = RPC_MAX_MESSAGE_SIZE, /* max incoming message size */ }; if(pb_decode_ex(&istream, &PB_Main_msg, rpc->decoded_message, PB_DECODE_DELIMITED)) { -#if DEBUG_PRINT - FURI_LOG_I(RPC_TAG, "INPUT:"); +#if SRV_RPC_DEBUG + FURI_LOG_I(TAG, "INPUT:"); rpc_print_message(rpc->decoded_message); #endif RpcHandler* handler = @@ -549,20 +555,19 @@ int32_t rpc_srv(void* p) { if(handler && handler->message_handler) { handler->message_handler(rpc->decoded_message, handler->context); } else if(!handler && !rpc->session.terminate) { - FURI_LOG_E( - RPC_TAG, "Unhandled message, tag: %d", rpc->decoded_message->which_content); + FURI_LOG_E(TAG, "Unhandled message, tag: %d", rpc->decoded_message->which_content); } } else { xStreamBufferReset(rpc->stream); if(!rpc->session.terminate) { - FURI_LOG_E(RPC_TAG, "Decode failed, error: \'%.128s\'", PB_GET_ERROR(&istream)); + FURI_LOG_E(TAG, "Decode failed, error: \'%.128s\'", PB_GET_ERROR(&istream)); } } pb_release(&PB_Main_msg, rpc->decoded_message); if(rpc->session.terminate) { - FURI_LOG_D(RPC_TAG, "Session terminated"); + FURI_LOG_D(TAG, "Session terminated"); osEventFlagsClear(rpc->events, RPC_EVENTS_ALL); rpc_free_session(&rpc->session); rpc->busy = false; diff --git a/applications/rpc/rpc.h b/applications/rpc/rpc.h index 3e58a885..61e315ba 100755 --- a/applications/rpc/rpc.h +++ b/applications/rpc/rpc.h @@ -5,6 +5,7 @@ #include "cmsis_os.h" #define RPC_BUFFER_SIZE (1024) +#define RPC_MAX_MESSAGE_SIZE (1536) /** Rpc interface. Used for opening session only. */ typedef struct Rpc Rpc; diff --git a/applications/rpc/rpc_cli.c b/applications/rpc/rpc_cli.c index 853e9dd3..373217b9 100644 --- a/applications/rpc/rpc_cli.c +++ b/applications/rpc/rpc_cli.c @@ -1,14 +1,14 @@ #include #include #include -#include +#include typedef struct { Cli* cli; bool session_close_request; } CliRpc; -#define CLI_READ_BUFFER_SIZE 100 +#define CLI_READ_BUFFER_SIZE 64 static void rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t bytes_len) { furi_assert(context); @@ -50,7 +50,8 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) { } if(size_received) { - rpc_session_feed(rpc_session, buffer, size_received, 3000); + furi_assert( + rpc_session_feed(rpc_session, buffer, size_received, 3000) == size_received); } } diff --git a/applications/rpc/rpc_gui.c b/applications/rpc/rpc_gui.c index 10a0afd9..6e9cfb08 100644 --- a/applications/rpc/rpc_gui.c +++ b/applications/rpc/rpc_gui.c @@ -3,12 +3,17 @@ #include "gui.pb.h" #include +#define TAG "RpcGui" + typedef struct { Rpc* rpc; Gui* gui; + ViewPort* virtual_display_view_port; + uint8_t* virtual_display_buffer; + bool virtual_display_not_empty; } RpcGuiSystem; -void rpc_system_gui_screen_frame_callback(uint8_t* data, size_t size, void* context) { +void rpc_system_gui_screen_stream_frame_callback(uint8_t* data, size_t size, void* context) { furi_assert(data); furi_assert(size == 1024); furi_assert(context); @@ -17,11 +22,11 @@ void rpc_system_gui_screen_frame_callback(uint8_t* data, size_t size, void* cont PB_Main* frame = furi_alloc(sizeof(PB_Main)); - frame->which_content = PB_Main_gui_screen_stream_frame_tag; + frame->which_content = PB_Main_gui_screen_frame_tag; frame->command_status = PB_CommandStatus_OK; - frame->content.gui_screen_stream_frame.data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(size)); - uint8_t* buffer = frame->content.gui_screen_stream_frame.data->bytes; - uint16_t* frame_size_msg = &frame->content.gui_screen_stream_frame.data->size; + frame->content.gui_screen_frame.data = furi_alloc(PB_BYTES_ARRAY_T_ALLOCSIZE(size)); + uint8_t* buffer = frame->content.gui_screen_frame.data->bytes; + uint16_t* frame_size_msg = &frame->content.gui_screen_frame.data->size; *frame_size_msg = size; memcpy(buffer, data, size); @@ -37,7 +42,8 @@ void rpc_system_gui_start_screen_stream_process(const PB_Main* request, void* co rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK); - gui_set_framebuffer_callback(rpc_gui->gui, rpc_system_gui_screen_frame_callback, context); + gui_set_framebuffer_callback( + rpc_gui->gui, rpc_system_gui_screen_stream_frame_callback, context); } void rpc_system_gui_stop_screen_stream_process(const PB_Main* request, void* context) { @@ -45,9 +51,9 @@ void rpc_system_gui_stop_screen_stream_process(const PB_Main* request, void* con furi_assert(context); RpcGuiSystem* rpc_gui = context; - rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK); - gui_set_framebuffer_callback(rpc_gui->gui, NULL, NULL); + + rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK); } void rpc_system_gui_send_input_event_request_process(const PB_Main* request, void* context) { @@ -120,6 +126,88 @@ void rpc_system_gui_send_input_event_request_process(const PB_Main* request, voi rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK); } +static void rpc_system_gui_virtual_display_render_callback(Canvas* canvas, void* context) { + furi_assert(canvas); + furi_assert(context); + RpcGuiSystem* rpc_gui = context; + + if(!rpc_gui->virtual_display_not_empty) { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignCenter, "Virtual Display"); + canvas_draw_str_aligned(canvas, 64, 36, AlignCenter, AlignCenter, "Waiting for frames..."); + return; + } + + canvas_draw_xbm(canvas, 0, 0, canvas->width, canvas->height, rpc_gui->virtual_display_buffer); +} + +void rpc_system_gui_start_virtual_display_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(context); + RpcGuiSystem* rpc_gui = context; + + if(rpc_gui->virtual_display_view_port) { + rpc_send_and_release_empty( + rpc_gui->rpc, + request->command_id, + PB_CommandStatus_ERROR_VIRTUAL_DISPLAY_ALREADY_STARTED); + return; + } + + // TODO: consider refactoring + // Using display framebuffer size as an XBM buffer size is like comparing apples and oranges + // Glad they both are 1024 for now + size_t buffer_size = canvas_get_buffer_size(rpc_gui->gui->canvas); + rpc_gui->virtual_display_buffer = furi_alloc(buffer_size); + rpc_gui->virtual_display_view_port = view_port_alloc(); + view_port_draw_callback_set( + rpc_gui->virtual_display_view_port, + rpc_system_gui_virtual_display_render_callback, + rpc_gui); + gui_add_view_port(rpc_gui->gui, rpc_gui->virtual_display_view_port, GuiLayerFullscreen); + + rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK); +} + +void rpc_system_gui_stop_virtual_display_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(context); + RpcGuiSystem* rpc_gui = context; + + if(!rpc_gui->virtual_display_view_port) { + rpc_send_and_release_empty( + rpc_gui->rpc, request->command_id, PB_CommandStatus_ERROR_VIRTUAL_DISPLAY_NOT_STARTED); + return; + } + + gui_remove_view_port(rpc_gui->gui, rpc_gui->virtual_display_view_port); + view_port_free(rpc_gui->virtual_display_view_port); + free(rpc_gui->virtual_display_buffer); + rpc_gui->virtual_display_view_port = NULL; + rpc_gui->virtual_display_not_empty = false; + + rpc_send_and_release_empty(rpc_gui->rpc, request->command_id, PB_CommandStatus_OK); +} + +void rpc_system_gui_virtual_display_frame_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(context); + RpcGuiSystem* rpc_gui = context; + + if(!rpc_gui->virtual_display_view_port) { + FURI_LOG_W(TAG, "Virtual display is not started, ignoring incoming frame packet"); + return; + } + + size_t buffer_size = canvas_get_buffer_size(rpc_gui->gui->canvas); + memcpy( + rpc_gui->virtual_display_buffer, + request->content.gui_screen_frame.data->bytes, + buffer_size); + rpc_gui->virtual_display_not_empty = true; + view_port_update(rpc_gui->virtual_display_view_port); +} + void* rpc_system_gui_alloc(Rpc* rpc) { furi_assert(rpc); @@ -142,6 +230,15 @@ void* rpc_system_gui_alloc(Rpc* rpc) { rpc_handler.message_handler = rpc_system_gui_send_input_event_request_process; rpc_add_handler(rpc, PB_Main_gui_send_input_event_request_tag, &rpc_handler); + rpc_handler.message_handler = rpc_system_gui_start_virtual_display_process; + rpc_add_handler(rpc, PB_Main_gui_start_virtual_display_request_tag, &rpc_handler); + + rpc_handler.message_handler = rpc_system_gui_stop_virtual_display_process; + rpc_add_handler(rpc, PB_Main_gui_stop_virtual_display_request_tag, &rpc_handler); + + rpc_handler.message_handler = rpc_system_gui_virtual_display_frame_process; + rpc_add_handler(rpc, PB_Main_gui_screen_frame_tag, &rpc_handler); + return rpc_gui; } @@ -149,6 +246,15 @@ void rpc_system_gui_free(void* ctx) { furi_assert(ctx); RpcGuiSystem* rpc_gui = ctx; furi_assert(rpc_gui->gui); + + if(rpc_gui->virtual_display_view_port) { + gui_remove_view_port(rpc_gui->gui, rpc_gui->virtual_display_view_port); + view_port_free(rpc_gui->virtual_display_view_port); + free(rpc_gui->virtual_display_buffer); + rpc_gui->virtual_display_view_port = NULL; + rpc_gui->virtual_display_not_empty = false; + } + gui_set_framebuffer_callback(rpc_gui->gui, NULL, NULL); furi_record_close("gui"); free(rpc_gui); diff --git a/applications/storage/storage-test-app.c b/applications/storage/storage-test-app.c index 022181a5..1c4e1915 100644 --- a/applications/storage/storage-test-app.c +++ b/applications/storage/storage-test-app.c @@ -2,7 +2,7 @@ #include #include -#define TAG "storage-test" +#define TAG "StorageTest" #define BYTES_COUNT 16 #define TEST_STRING "TestDataStringProvidedByDiceRoll" #define SEEK_OFFSET_FROM_START 10 diff --git a/applications/storage/storages/storage-ext.c b/applications/storage/storages/storage-ext.c index a434c2d8..51de7612 100644 --- a/applications/storage/storages/storage-ext.c +++ b/applications/storage/storages/storage-ext.c @@ -10,7 +10,7 @@ typedef DIR SDDir; typedef FILINFO SDFileInfo; typedef FRESULT SDError; -#define TAG "storage-ext" +#define TAG "StorageExt" #define STORAGE_PATH "/ext" /********************* Definitions ********************/ diff --git a/applications/storage/storages/storage-int.c b/applications/storage/storages/storage-int.c index 3eabdec7..69ffe15e 100644 --- a/applications/storage/storages/storage-int.c +++ b/applications/storage/storages/storage-int.c @@ -2,7 +2,7 @@ #include #include -#define TAG "storage-int" +#define TAG "StorageInt" #define STORAGE_PATH "/int" typedef struct { diff --git a/applications/subghz/subghz_i.c b/applications/subghz/subghz_i.c index 26472901..ce693991 100644 --- a/applications/subghz/subghz_i.c +++ b/applications/subghz/subghz_i.c @@ -20,7 +20,7 @@ bool subghz_set_pteset(SubGhz* subghz, const char* preset) { } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) { subghz->txrx->preset = FuriHalSubGhzPreset2FSKDev476Async; } else { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unknown preset"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unknown preset"); return false; } return true; @@ -41,7 +41,7 @@ bool subghz_get_preset_name(SubGhz* subghz, string_t preset) { case FuriHalSubGhzPreset2FSKDev476Async: preset_name = "FuriHalSubGhzPreset2FSKDev476Async"; break; - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unknown preset"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unknown preset"); default: return false; break; @@ -210,11 +210,12 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) { do { if(!flipper_file_open_existing(flipper_file, string_get_cstr(path))) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to open file for read: %s", string_get_cstr(path)); + FURI_LOG_E( + SUBGHZ_PARSER_TAG, "Unable to open file for read: %s", string_get_cstr(path)); break; } if(!flipper_file_read_header(flipper_file, temp_str, &version)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing or incorrect header"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing or incorrect header"); break; } @@ -222,18 +223,18 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) { (!strcmp(string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) && version == SUBGHZ_KEY_FILE_VERSION) { } else { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Type or version mismatch"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Type or version mismatch"); break; } if(!flipper_file_read_uint32( flipper_file, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Frequency"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Frequency"); break; } if(!flipper_file_read_string(flipper_file, "Preset", temp_str)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Preset"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Preset"); break; } if(!subghz_set_pteset(subghz, string_get_cstr(temp_str))) { @@ -241,14 +242,14 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) { } if(!flipper_file_read_string(flipper_file, "Protocol", temp_str)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Protocol"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Protocol"); break; } subghz->txrx->protocol_result = subghz_parser_get_by_name(subghz->txrx->parser, string_get_cstr(temp_str)); if(subghz->txrx->protocol_result == NULL) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "This type of protocol was not found"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "This type of protocol was not found"); break; } if(!subghz->txrx->protocol_result->to_load_protocol_from_file( @@ -310,7 +311,7 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) { do { // Checking that this type of people can be saved if(subghz->txrx->protocol_result->to_save_file == NULL) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "No saving of this type of keys"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "No saving of this type of keys"); break; } // Create subghz folder directory if necessary @@ -334,19 +335,19 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) { // Open file if(!flipper_file_open_always(flipper_file, string_get_cstr(dev_file_name))) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to open file for write: %s", dev_file_name); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to open file for write: %s", dev_file_name); break; } if(!flipper_file_write_header_cstr( flipper_file, SUBGHZ_KEY_FILE_TYPE, SUBGHZ_KEY_FILE_VERSION)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add header"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add header"); break; } if(!flipper_file_write_uint32( flipper_file, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Frequency"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Frequency"); break; } @@ -354,7 +355,7 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) { break; } if(!flipper_file_write_string_cstr(flipper_file, "Preset", string_get_cstr(temp_str))) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Preset"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Preset"); break; } diff --git a/applications/subghz/views/subghz_test_static.c b/applications/subghz/views/subghz_test_static.c index aa701464..bc672406 100644 --- a/applications/subghz/views/subghz_test_static.c +++ b/applications/subghz/views/subghz_test_static.c @@ -8,6 +8,8 @@ #include #include +#define TAG "SubGhzTestStatic" + typedef enum { SubghzTestStaticStatusIDLE, SubghzTestStaticStatusTX, @@ -99,7 +101,7 @@ bool subghz_test_static_input(InputEvent* event, void* context) { } else { notification_message_block(notification, &sequence_set_red_255); - FURI_LOG_I("SubghzTestStatic", "TX Start"); + FURI_LOG_I(TAG, "TX Start"); subghz_encoder_princeton_set( instance->encoder, subghz_test_static_keys[model->button], 10000); @@ -110,7 +112,7 @@ bool subghz_test_static_input(InputEvent* event, void* context) { } } else if(event->type == InputTypeRelease) { if(instance->satus_tx == SubghzTestStaticStatusTX) { - FURI_LOG_I("SubghzTestStatic", "TX Stop"); + FURI_LOG_I(TAG, "TX Stop"); subghz_encoder_princeton_print_log(instance->encoder); furi_hal_subghz_stop_async_tx(); notification_message(notification, &sequence_reset_red); diff --git a/applications/tests/rpc/rpc_test.c b/applications/tests/rpc/rpc_test.c index 51ed30cf..af99be4a 100644 --- a/applications/tests/rpc/rpc_test.c +++ b/applications/tests/rpc/rpc_test.c @@ -29,7 +29,7 @@ static RpcSession* session = NULL; static StreamBufferHandle_t output_stream = NULL; static uint32_t command_id = 0; -#define TEST_RPC_TAG "TEST_RPC" +#define TAG "UnitTestsRpc" #define MAX_RECEIVE_OUTPUT_TIMEOUT 3000 #define MAX_NAME_LENGTH 255 #define MAX_DATA_SIZE 512 // have to be exact as in rpc_storage.c @@ -1334,7 +1334,7 @@ int run_minunit_test_rpc() { Storage* storage = furi_record_open("storage"); furi_record_close("storage"); if(storage_sd_status(storage) != FSE_OK) { - FURI_LOG_E("UNIT_TESTS", "SD card not mounted - skip storage tests"); + FURI_LOG_E(TAG, "SD card not mounted - skip storage tests"); } else { MU_RUN_SUITE(test_rpc_storage); } diff --git a/applications/tests/test_index.c b/applications/tests/test_index.c index f436c0ef..f5607566 100644 --- a/applications/tests/test_index.c +++ b/applications/tests/test_index.c @@ -8,7 +8,7 @@ #include #include -#define TESTS_TAG "UNIT_TESTS" +#define TAG "UnitTests" int run_minunit(); int run_minunit_test_irda_decoder_encoder(); @@ -42,7 +42,7 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) { // TODO: lock device while test running if(loader_is_locked(loader)) { - FURI_LOG_E(TESTS_TAG, "RPC: stop all applications to run tests"); + FURI_LOG_E(TAG, "RPC: stop all applications to run tests"); notification_message(notification, &sequence_blink_magenta_100); } else { notification_message_block(notification, &sequence_set_only_blue_255); @@ -56,21 +56,21 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) { test_result |= run_minunit_test_flipper_file(); cycle_counter = (DWT->CYCCNT - cycle_counter); - FURI_LOG_I(TESTS_TAG, "Consumed: %0.2fs", (float)cycle_counter / (SystemCoreClock)); + FURI_LOG_I(TAG, "Consumed: %0.2fs", (float)cycle_counter / (SystemCoreClock)); if(test_result == 0) { delay(200); /* wait for tested services and apps to deallocate */ uint32_t heap_after = memmgr_get_free_heap(); notification_message(notification, &sequence_success); if(heap_after != heap_before) { - FURI_LOG_E(TESTS_TAG, "Leaked: %d", heap_before - heap_after); + FURI_LOG_E(TAG, "Leaked: %d", heap_before - heap_after); } else { - FURI_LOG_I(TESTS_TAG, "No leaks"); + FURI_LOG_I(TAG, "No leaks"); } - FURI_LOG_I(TESTS_TAG, "PASSED"); + FURI_LOG_I(TAG, "PASSED"); } else { notification_message(notification, &sequence_error); - FURI_LOG_E(TESTS_TAG, "FAILED"); + FURI_LOG_E(TAG, "FAILED"); } } diff --git a/assets/compiled/flipper.pb.h b/assets/compiled/flipper.pb.h index 161b969d..49b5fdee 100644 --- a/assets/compiled/flipper.pb.h +++ b/assets/compiled/flipper.pb.h @@ -36,7 +36,10 @@ typedef enum _PB_CommandStatus { PB_CommandStatus_ERROR_STORAGE_DIR_NOT_EMPTY = 18, /* *< Directory, you're going to remove is not empty */ /* *< Application Errors */ PB_CommandStatus_ERROR_APP_CANT_START = 16, /* *< Can't start app - internal error */ - PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED = 17 /* *< Another app is running */ + PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED = 17, /* *< Another app is running */ + /* *< Virtual Display Errors */ + PB_CommandStatus_ERROR_VIRTUAL_DISPLAY_ALREADY_STARTED = 19, /* *< Virtual Display session can't be started twice */ + PB_CommandStatus_ERROR_VIRTUAL_DISPLAY_NOT_STARTED = 20 /* *< Virtual Display session can't be stopped when it's not started */ } PB_CommandStatus; /* Struct definitions */ @@ -76,18 +79,20 @@ typedef struct _PB_Main { PB_StopSession stop_session; PB_Gui_StartScreenStreamRequest gui_start_screen_stream_request; PB_Gui_StopScreenStreamRequest gui_stop_screen_stream_request; - PB_Gui_ScreenStreamFrame gui_screen_stream_frame; + PB_Gui_ScreenFrame gui_screen_frame; PB_Gui_SendInputEventRequest gui_send_input_event_request; PB_Storage_StatRequest storage_stat_request; PB_Storage_StatResponse storage_stat_response; + PB_Gui_StartVirtualDisplayRequest gui_start_virtual_display_request; + PB_Gui_StopVirtualDisplayRequest gui_stop_virtual_display_request; } content; } PB_Main; /* Helper constants for enums */ #define _PB_CommandStatus_MIN PB_CommandStatus_OK -#define _PB_CommandStatus_MAX PB_CommandStatus_ERROR_STORAGE_DIR_NOT_EMPTY -#define _PB_CommandStatus_ARRAYSIZE ((PB_CommandStatus)(PB_CommandStatus_ERROR_STORAGE_DIR_NOT_EMPTY+1)) +#define _PB_CommandStatus_MAX PB_CommandStatus_ERROR_VIRTUAL_DISPLAY_NOT_STARTED +#define _PB_CommandStatus_ARRAYSIZE ((PB_CommandStatus)(PB_CommandStatus_ERROR_VIRTUAL_DISPLAY_NOT_STARTED+1)) #ifdef __cplusplus @@ -124,10 +129,12 @@ extern "C" { #define PB_Main_stop_session_tag 19 #define PB_Main_gui_start_screen_stream_request_tag 20 #define PB_Main_gui_stop_screen_stream_request_tag 21 -#define PB_Main_gui_screen_stream_frame_tag 22 +#define PB_Main_gui_screen_frame_tag 22 #define PB_Main_gui_send_input_event_request_tag 23 #define PB_Main_storage_stat_request_tag 24 #define PB_Main_storage_stat_response_tag 25 +#define PB_Main_gui_start_virtual_display_request_tag 26 +#define PB_Main_gui_stop_virtual_display_request_tag 27 /* Struct field encoding specification for nanopb */ #define PB_Empty_FIELDLIST(X, a) \ @@ -162,10 +169,12 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,app_lock_status_response,content.app X(a, STATIC, ONEOF, MSG_W_CB, (content,stop_session,content.stop_session), 19) \ X(a, STATIC, ONEOF, MSG_W_CB, (content,gui_start_screen_stream_request,content.gui_start_screen_stream_request), 20) \ X(a, STATIC, ONEOF, MSG_W_CB, (content,gui_stop_screen_stream_request,content.gui_stop_screen_stream_request), 21) \ -X(a, STATIC, ONEOF, MSG_W_CB, (content,gui_screen_stream_frame,content.gui_screen_stream_frame), 22) \ +X(a, STATIC, ONEOF, MSG_W_CB, (content,gui_screen_frame,content.gui_screen_frame), 22) \ X(a, STATIC, ONEOF, MSG_W_CB, (content,gui_send_input_event_request,content.gui_send_input_event_request), 23) \ X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_stat_request,content.storage_stat_request), 24) \ -X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_stat_response,content.storage_stat_response), 25) +X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_stat_response,content.storage_stat_response), 25) \ +X(a, STATIC, ONEOF, MSG_W_CB, (content,gui_start_virtual_display_request,content.gui_start_virtual_display_request), 26) \ +X(a, STATIC, ONEOF, MSG_W_CB, (content,gui_stop_virtual_display_request,content.gui_stop_virtual_display_request), 27) #define PB_Main_CALLBACK NULL #define PB_Main_DEFAULT NULL #define PB_Main_content_empty_MSGTYPE PB_Empty @@ -186,10 +195,12 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_stat_response,content.storag #define PB_Main_content_stop_session_MSGTYPE PB_StopSession #define PB_Main_content_gui_start_screen_stream_request_MSGTYPE PB_Gui_StartScreenStreamRequest #define PB_Main_content_gui_stop_screen_stream_request_MSGTYPE PB_Gui_StopScreenStreamRequest -#define PB_Main_content_gui_screen_stream_frame_MSGTYPE PB_Gui_ScreenStreamFrame +#define PB_Main_content_gui_screen_frame_MSGTYPE PB_Gui_ScreenFrame #define PB_Main_content_gui_send_input_event_request_MSGTYPE PB_Gui_SendInputEventRequest #define PB_Main_content_storage_stat_request_MSGTYPE PB_Storage_StatRequest #define PB_Main_content_storage_stat_response_MSGTYPE PB_Storage_StatResponse +#define PB_Main_content_gui_start_virtual_display_request_MSGTYPE PB_Gui_StartVirtualDisplayRequest +#define PB_Main_content_gui_stop_virtual_display_request_MSGTYPE PB_Gui_StopVirtualDisplayRequest extern const pb_msgdesc_t PB_Empty_msg; extern const pb_msgdesc_t PB_StopSession_msg; @@ -203,9 +214,9 @@ extern const pb_msgdesc_t PB_Main_msg; /* Maximum encoded size of messages (where known) */ #define PB_Empty_size 0 #define PB_StopSession_size 0 -#if defined(PB_Storage_ListRequest_size) && defined(PB_Storage_ListResponse_size) && defined(PB_Storage_ReadRequest_size) && defined(PB_Storage_ReadResponse_size) && defined(PB_Storage_WriteRequest_size) && defined(PB_Storage_DeleteRequest_size) && defined(PB_Storage_MkdirRequest_size) && defined(PB_Storage_Md5sumRequest_size) && defined(PB_App_StartRequest_size) && defined(PB_Gui_ScreenStreamFrame_size) && defined(PB_Storage_StatRequest_size) && defined(PB_Storage_StatResponse_size) +#if defined(PB_Storage_ListRequest_size) && defined(PB_Storage_ListResponse_size) && defined(PB_Storage_ReadRequest_size) && defined(PB_Storage_ReadResponse_size) && defined(PB_Storage_WriteRequest_size) && defined(PB_Storage_DeleteRequest_size) && defined(PB_Storage_MkdirRequest_size) && defined(PB_Storage_Md5sumRequest_size) && defined(PB_App_StartRequest_size) && defined(PB_Gui_ScreenFrame_size) && defined(PB_Storage_StatRequest_size) && defined(PB_Storage_StatResponse_size) #define PB_Main_size (10 + sizeof(union PB_Main_content_size_union)) -union PB_Main_content_size_union {char f7[(6 + PB_Storage_ListRequest_size)]; char f8[(6 + PB_Storage_ListResponse_size)]; char f9[(6 + PB_Storage_ReadRequest_size)]; char f10[(6 + PB_Storage_ReadResponse_size)]; char f11[(6 + PB_Storage_WriteRequest_size)]; char f12[(6 + PB_Storage_DeleteRequest_size)]; char f13[(6 + PB_Storage_MkdirRequest_size)]; char f14[(6 + PB_Storage_Md5sumRequest_size)]; char f16[(7 + PB_App_StartRequest_size)]; char f22[(7 + PB_Gui_ScreenStreamFrame_size)]; char f24[(7 + PB_Storage_StatRequest_size)]; char f25[(7 + PB_Storage_StatResponse_size)]; char f0[36];}; +union PB_Main_content_size_union {char f7[(6 + PB_Storage_ListRequest_size)]; char f8[(6 + PB_Storage_ListResponse_size)]; char f9[(6 + PB_Storage_ReadRequest_size)]; char f10[(6 + PB_Storage_ReadResponse_size)]; char f11[(6 + PB_Storage_WriteRequest_size)]; char f12[(6 + PB_Storage_DeleteRequest_size)]; char f13[(6 + PB_Storage_MkdirRequest_size)]; char f14[(6 + PB_Storage_Md5sumRequest_size)]; char f16[(7 + PB_App_StartRequest_size)]; char f22[(7 + PB_Gui_ScreenFrame_size)]; char f24[(7 + PB_Storage_StatRequest_size)]; char f25[(7 + PB_Storage_StatResponse_size)]; char f0[36];}; #endif #ifdef __cplusplus diff --git a/assets/compiled/gui.pb.c b/assets/compiled/gui.pb.c index ecc8a647..2c1d8490 100644 --- a/assets/compiled/gui.pb.c +++ b/assets/compiled/gui.pb.c @@ -6,18 +6,24 @@ #error Regenerate this file with the current version of nanopb generator. #endif +PB_BIND(PB_Gui_ScreenFrame, PB_Gui_ScreenFrame, AUTO) + + PB_BIND(PB_Gui_StartScreenStreamRequest, PB_Gui_StartScreenStreamRequest, AUTO) PB_BIND(PB_Gui_StopScreenStreamRequest, PB_Gui_StopScreenStreamRequest, AUTO) -PB_BIND(PB_Gui_ScreenStreamFrame, PB_Gui_ScreenStreamFrame, AUTO) - - PB_BIND(PB_Gui_SendInputEventRequest, PB_Gui_SendInputEventRequest, AUTO) +PB_BIND(PB_Gui_StartVirtualDisplayRequest, PB_Gui_StartVirtualDisplayRequest, AUTO) + + +PB_BIND(PB_Gui_StopVirtualDisplayRequest, PB_Gui_StopVirtualDisplayRequest, AUTO) + + diff --git a/assets/compiled/gui.pb.h b/assets/compiled/gui.pb.h index abb702fb..84cf1d57 100644 --- a/assets/compiled/gui.pb.h +++ b/assets/compiled/gui.pb.h @@ -28,18 +28,26 @@ typedef enum _PB_Gui_InputType { } PB_Gui_InputType; /* Struct definitions */ -typedef struct _PB_Gui_ScreenStreamFrame { +typedef struct _PB_Gui_ScreenFrame { pb_bytes_array_t *data; -} PB_Gui_ScreenStreamFrame; +} PB_Gui_ScreenFrame; typedef struct _PB_Gui_StartScreenStreamRequest { char dummy_field; } PB_Gui_StartScreenStreamRequest; +typedef struct _PB_Gui_StartVirtualDisplayRequest { + char dummy_field; +} PB_Gui_StartVirtualDisplayRequest; + typedef struct _PB_Gui_StopScreenStreamRequest { char dummy_field; } PB_Gui_StopScreenStreamRequest; +typedef struct _PB_Gui_StopVirtualDisplayRequest { + char dummy_field; +} PB_Gui_StopVirtualDisplayRequest; + typedef struct _PB_Gui_SendInputEventRequest { PB_Gui_InputKey key; PB_Gui_InputType type; @@ -61,21 +69,30 @@ extern "C" { #endif /* Initializer values for message structs */ +#define PB_Gui_ScreenFrame_init_default {NULL} #define PB_Gui_StartScreenStreamRequest_init_default {0} #define PB_Gui_StopScreenStreamRequest_init_default {0} -#define PB_Gui_ScreenStreamFrame_init_default {NULL} #define PB_Gui_SendInputEventRequest_init_default {_PB_Gui_InputKey_MIN, _PB_Gui_InputType_MIN} +#define PB_Gui_StartVirtualDisplayRequest_init_default {0} +#define PB_Gui_StopVirtualDisplayRequest_init_default {0} +#define PB_Gui_ScreenFrame_init_zero {NULL} #define PB_Gui_StartScreenStreamRequest_init_zero {0} #define PB_Gui_StopScreenStreamRequest_init_zero {0} -#define PB_Gui_ScreenStreamFrame_init_zero {NULL} #define PB_Gui_SendInputEventRequest_init_zero {_PB_Gui_InputKey_MIN, _PB_Gui_InputType_MIN} +#define PB_Gui_StartVirtualDisplayRequest_init_zero {0} +#define PB_Gui_StopVirtualDisplayRequest_init_zero {0} /* Field tags (for use in manual encoding/decoding) */ -#define PB_Gui_ScreenStreamFrame_data_tag 1 +#define PB_Gui_ScreenFrame_data_tag 1 #define PB_Gui_SendInputEventRequest_key_tag 1 #define PB_Gui_SendInputEventRequest_type_tag 2 /* Struct field encoding specification for nanopb */ +#define PB_Gui_ScreenFrame_FIELDLIST(X, a) \ +X(a, POINTER, SINGULAR, BYTES, data, 1) +#define PB_Gui_ScreenFrame_CALLBACK NULL +#define PB_Gui_ScreenFrame_DEFAULT NULL + #define PB_Gui_StartScreenStreamRequest_FIELDLIST(X, a) \ #define PB_Gui_StartScreenStreamRequest_CALLBACK NULL @@ -86,33 +103,44 @@ extern "C" { #define PB_Gui_StopScreenStreamRequest_CALLBACK NULL #define PB_Gui_StopScreenStreamRequest_DEFAULT NULL -#define PB_Gui_ScreenStreamFrame_FIELDLIST(X, a) \ -X(a, POINTER, SINGULAR, BYTES, data, 1) -#define PB_Gui_ScreenStreamFrame_CALLBACK NULL -#define PB_Gui_ScreenStreamFrame_DEFAULT NULL - #define PB_Gui_SendInputEventRequest_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, UENUM, key, 1) \ X(a, STATIC, SINGULAR, UENUM, type, 2) #define PB_Gui_SendInputEventRequest_CALLBACK NULL #define PB_Gui_SendInputEventRequest_DEFAULT NULL +#define PB_Gui_StartVirtualDisplayRequest_FIELDLIST(X, a) \ + +#define PB_Gui_StartVirtualDisplayRequest_CALLBACK NULL +#define PB_Gui_StartVirtualDisplayRequest_DEFAULT NULL + +#define PB_Gui_StopVirtualDisplayRequest_FIELDLIST(X, a) \ + +#define PB_Gui_StopVirtualDisplayRequest_CALLBACK NULL +#define PB_Gui_StopVirtualDisplayRequest_DEFAULT NULL + +extern const pb_msgdesc_t PB_Gui_ScreenFrame_msg; extern const pb_msgdesc_t PB_Gui_StartScreenStreamRequest_msg; extern const pb_msgdesc_t PB_Gui_StopScreenStreamRequest_msg; -extern const pb_msgdesc_t PB_Gui_ScreenStreamFrame_msg; extern const pb_msgdesc_t PB_Gui_SendInputEventRequest_msg; +extern const pb_msgdesc_t PB_Gui_StartVirtualDisplayRequest_msg; +extern const pb_msgdesc_t PB_Gui_StopVirtualDisplayRequest_msg; /* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define PB_Gui_ScreenFrame_fields &PB_Gui_ScreenFrame_msg #define PB_Gui_StartScreenStreamRequest_fields &PB_Gui_StartScreenStreamRequest_msg #define PB_Gui_StopScreenStreamRequest_fields &PB_Gui_StopScreenStreamRequest_msg -#define PB_Gui_ScreenStreamFrame_fields &PB_Gui_ScreenStreamFrame_msg #define PB_Gui_SendInputEventRequest_fields &PB_Gui_SendInputEventRequest_msg +#define PB_Gui_StartVirtualDisplayRequest_fields &PB_Gui_StartVirtualDisplayRequest_msg +#define PB_Gui_StopVirtualDisplayRequest_fields &PB_Gui_StopVirtualDisplayRequest_msg /* Maximum encoded size of messages (where known) */ -/* PB_Gui_ScreenStreamFrame_size depends on runtime parameters */ +/* PB_Gui_ScreenFrame_size depends on runtime parameters */ #define PB_Gui_SendInputEventRequest_size 4 #define PB_Gui_StartScreenStreamRequest_size 0 +#define PB_Gui_StartVirtualDisplayRequest_size 0 #define PB_Gui_StopScreenStreamRequest_size 0 +#define PB_Gui_StopVirtualDisplayRequest_size 0 #ifdef __cplusplus } /* extern "C" */ diff --git a/assets/protobuf b/assets/protobuf index 0e6d374a..6be7def6 160000 --- a/assets/protobuf +++ b/assets/protobuf @@ -1 +1 @@ -Subproject commit 0e6d374ab1a12f95a3cd04444376a261e7252db4 +Subproject commit 6be7def6087c4d277386381ff2792fa622933668 diff --git a/core/flipper.c b/core/flipper.c index c8d12068..59c1823a 100755 --- a/core/flipper.c +++ b/core/flipper.c @@ -3,10 +3,12 @@ #include #include +#define TAG "Flipper" + static void flipper_print_version(const char* target, const Version* version) { if(version) { FURI_LOG_I( - "FLIPPER", + TAG, "\r\n\t%s version:\t%s\r\n" "\tBuild date:\t\t%s\r\n" "\tGit Commit:\t\t%s (%s)\r\n" @@ -18,7 +20,7 @@ static void flipper_print_version(const char* target, const Version* version) { version_get_gitbranchnum(version), version_get_gitbranch(version)); } else { - FURI_LOG_I("FLIPPER", "No build info for %s", target); + FURI_LOG_I(TAG, "No build info for %s", target); } } @@ -31,10 +33,10 @@ void flipper_init() { version = (const Version*)furi_hal_version_get_firmware_version(); flipper_print_version("Firmware", version); - FURI_LOG_I("FLIPPER", "starting services"); + FURI_LOG_I(TAG, "starting services"); for(size_t i = 0; i < FLIPPER_SERVICES_COUNT; i++) { - FURI_LOG_I("FLIPPER", "starting service %s", FLIPPER_SERVICES[i].name); + FURI_LOG_I(TAG, "starting service %s", FLIPPER_SERVICES[i].name); FuriThread* thread = furi_thread_alloc(); @@ -45,5 +47,5 @@ void flipper_init() { furi_thread_start(thread); } - FURI_LOG_I("FLIPPER", "services startup complete"); + FURI_LOG_I(TAG, "services startup complete"); } diff --git a/firmware/targets/f6/Inc/stm32_assert.h b/firmware/targets/f6/Inc/stm32_assert.h new file mode 100644 index 00000000..9f6261ff --- /dev/null +++ b/firmware/targets/f6/Inc/stm32_assert.h @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * @file stm32_assert.h + * @brief STM32 assert file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_ASSERT_H +#define __STM32_ASSERT_H + +#ifdef __cplusplus + extern "C" { +#endif + +#ifdef USE_FULL_ASSERT + #define assert_param(expr) ((expr) ? (void)0U : assert_failed()) + void assert_failed(); +#else + #define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32_ASSERT_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f6/Inc/stm32wbxx_hal_conf.h b/firmware/targets/f6/Inc/stm32wbxx_hal_conf.h index ab7b2953..4d5ad791 100644 --- a/firmware/targets/f6/Inc/stm32wbxx_hal_conf.h +++ b/firmware/targets/f6/Inc/stm32wbxx_hal_conf.h @@ -184,7 +184,7 @@ * @brief Uncomment the line below to expanse the "assert_param" macro in the * HAL drivers code */ -/* #define USE_FULL_ASSERT 1U */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -329,17 +329,8 @@ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ - #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ - void assert_failed(uint8_t* file, uint32_t line); + #define assert_param(expr) ((expr) ? (void)0U : assert_failed()) + void assert_failed(); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ diff --git a/firmware/targets/f6/Src/main.c b/firmware/targets/f6/Src/main.c index ea6d8943..a546086f 100644 --- a/firmware/targets/f6/Src/main.c +++ b/firmware/targets/f6/Src/main.c @@ -1,11 +1,11 @@ #include "main.h" -#include "fatfs/fatfs.h" - #include #include #include +#define TAG "Main" + int main(void) { // Initialize FURI layer furi_init(); @@ -16,13 +16,9 @@ int main(void) { // Flipper FURI HAL furi_hal_init(); - // 3rd party - MX_FATFS_Init(); - FURI_LOG_I("HAL", "FATFS OK"); - // CMSIS initialization osKernelInitialize(); - FURI_LOG_I("HAL", "KERNEL OK"); + FURI_LOG_I(TAG, "KERNEL OK"); // Init flipper flipper_init(); @@ -47,9 +43,6 @@ void Error_Handler(void) { * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ + furi_crash("HAL assert failed"); } #endif /* USE_FULL_ASSERT */ diff --git a/firmware/targets/f6/ble-glue/battery_service.c b/firmware/targets/f6/ble-glue/battery_service.c index 1dd8c5a0..2a5dad5e 100644 --- a/firmware/targets/f6/ble-glue/battery_service.c +++ b/firmware/targets/f6/ble-glue/battery_service.c @@ -4,7 +4,7 @@ #include -#define BATTERY_SERVICE_TAG "battery service" +#define TAG "BtBatterySvc" typedef struct { uint16_t svc_handle; @@ -23,7 +23,7 @@ void battery_svc_start() { // Add Battery service status = aci_gatt_add_service(UUID_TYPE_16, (Service_UUID_t*)&service_uuid, PRIMARY_SERVICE, 4, &battery_svc->svc_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to add Battery service: %d", status); + FURI_LOG_E(TAG, "Failed to add Battery service: %d", status); } // Add Battery level characteristic status = aci_gatt_add_char(battery_svc->svc_handle, @@ -37,7 +37,7 @@ void battery_svc_start() { CHAR_VALUE_LEN_CONSTANT, &battery_svc->char_level_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to add Battery level characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add Battery level characteristic: %d", status); } } @@ -47,12 +47,12 @@ void battery_svc_stop() { // Delete Battery level characteristic status = aci_gatt_del_char(battery_svc->svc_handle, battery_svc->char_level_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to delete Battery level characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete Battery level characteristic: %d", status); } // Delete Battery service status = aci_gatt_del_service(battery_svc->svc_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to delete Battery service: %d", status); + FURI_LOG_E(TAG, "Failed to delete Battery service: %d", status); } free(battery_svc); battery_svc = NULL; @@ -65,14 +65,14 @@ bool battery_svc_update_level(uint8_t battery_charge) { return false; } // Update battery level characteristic - FURI_LOG_I(BATTERY_SERVICE_TAG, "Updating battery level characteristic"); + FURI_LOG_I(TAG, "Updating battery level characteristic"); tBleStatus result = aci_gatt_update_char_value(battery_svc->svc_handle, battery_svc->char_level_handle, 0, 1, &battery_charge); if(result) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed updating RX characteristic: %d", result); + FURI_LOG_E(TAG, "Failed updating RX characteristic: %d", result); } return result != BLE_STATUS_SUCCESS; } diff --git a/firmware/targets/f6/ble-glue/ble_app.c b/firmware/targets/f6/ble-glue/ble_app.c index 92fddfc4..40b34679 100644 --- a/firmware/targets/f6/ble-glue/ble_app.c +++ b/firmware/targets/f6/ble-glue/ble_app.c @@ -8,7 +8,7 @@ #include -#define BLE_APP_TAG "ble app" +#define TAG "Bt" PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t ble_app_cmd_buffer; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint32_t ble_app_nvm[BLE_NVM_SRAM_SIZE]; @@ -53,7 +53,7 @@ bool ble_app_init() { }; status = SHCI_C2_Config(&config_param); if(status) { - FURI_LOG_E(BLE_APP_TAG, "Failed to configure 2nd core: %d", status); + FURI_LOG_E(TAG, "Failed to configure 2nd core: %d", status); } // Start ble stack on 2nd core @@ -82,7 +82,7 @@ bool ble_app_init() { }; status = SHCI_C2_BLE_Init(&ble_init_cmd_packet); if(status) { - FURI_LOG_E(BLE_APP_TAG, "Failed to start ble stack: %d", status); + FURI_LOG_E(TAG, "Failed to start ble stack: %d", status); } return status == SHCI_Success; } diff --git a/firmware/targets/f6/ble-glue/ble_glue.c b/firmware/targets/f6/ble-glue/ble_glue.c index 45277366..35c16223 100644 --- a/firmware/targets/f6/ble-glue/ble_glue.c +++ b/firmware/targets/f6/ble-glue/ble_glue.c @@ -10,6 +10,8 @@ #include "app_debug.h" #include +#define TAG "Core2" + #define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH*4U*DIVC(( sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE ), 4U)) PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ble_glue_event_pool[POOL_SIZE]; @@ -125,20 +127,20 @@ static void ble_glue_sys_user_event_callback( void * pPayload ) { if(p_sys_event->subevtcode == SHCI_SUB_EVT_CODE_READY) { if(ble_app_init()) { - FURI_LOG_I("Core2", "BLE stack started"); + FURI_LOG_I(TAG, "BLE stack started"); ble_glue->status = BleGlueStatusStarted; if(SHCI_C2_SetFlashActivityControl(FLASH_ACTIVITY_CONTROL_SEM7) == SHCI_Success) { - FURI_LOG_I("Core2", "Flash activity control switched to SEM7"); + FURI_LOG_I(TAG, "Flash activity control switched to SEM7"); } else { - FURI_LOG_E("Core2", "Failed to switch flash activity control to SEM7"); + FURI_LOG_E(TAG, "Failed to switch flash activity control to SEM7"); } } else { - FURI_LOG_E("Core2", "BLE stack startup failed"); + FURI_LOG_E(TAG, "BLE stack startup failed"); ble_glue->status = BleGlueStatusBleStackMissing; } furi_hal_power_insomnia_exit(); } else if(p_sys_event->subevtcode == SHCI_SUB_EVT_ERROR_NOTIF) { - FURI_LOG_E("Core2", "Error during initialization"); + FURI_LOG_E(TAG, "Error during initialization"); furi_hal_power_insomnia_exit(); } else if(p_sys_event->subevtcode == SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE) { SHCI_C2_BleNvmRamUpdate_Evt_t* p_sys_ble_nvm_ram_update_event = (SHCI_C2_BleNvmRamUpdate_Evt_t*)p_sys_event->payload; diff --git a/firmware/targets/f6/ble-glue/dev_info_service.c b/firmware/targets/f6/ble-glue/dev_info_service.c index 7ce2647c..64ff0509 100644 --- a/firmware/targets/f6/ble-glue/dev_info_service.c +++ b/firmware/targets/f6/ble-glue/dev_info_service.c @@ -4,7 +4,7 @@ #include -#define DEV_INFO_SVC_TAG "dev info service" +#define TAG "BtDevInfoSvc" typedef struct { uint16_t service_handle; @@ -29,7 +29,7 @@ void dev_info_svc_start() { uint16_t uuid = DEVICE_INFORMATION_SERVICE_UUID; status = aci_gatt_add_service(UUID_TYPE_16, (Service_UUID_t*)&uuid, PRIMARY_SERVICE, 9, &dev_info_svc->service_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add Device Information Service: %d", status); + FURI_LOG_E(TAG, "Failed to add Device Information Service: %d", status); } // Add characteristics @@ -45,7 +45,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->man_name_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add manufacturer name char: %d", status); + FURI_LOG_E(TAG, "Failed to add manufacturer name char: %d", status); } uuid = SERIAL_NUMBER_UUID; status = aci_gatt_add_char(dev_info_svc->service_handle, @@ -59,7 +59,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->serial_num_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add serial number char: %d", status); + FURI_LOG_E(TAG, "Failed to add serial number char: %d", status); } uuid = FIRMWARE_REVISION_UUID; status = aci_gatt_add_char(dev_info_svc->service_handle, @@ -73,7 +73,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->firmware_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add firmware revision char: %d", status); + FURI_LOG_E(TAG, "Failed to add firmware revision char: %d", status); } uuid = SOFTWARE_REVISION_UUID; status = aci_gatt_add_char(dev_info_svc->service_handle, @@ -87,7 +87,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->software_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add software revision char: %d", status); + FURI_LOG_E(TAG, "Failed to add software revision char: %d", status); } // Update characteristics @@ -97,7 +97,7 @@ void dev_info_svc_start() { strlen(dev_info_man_name), (uint8_t*)dev_info_man_name); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update manufacturer name char: %d", status); + FURI_LOG_E(TAG, "Failed to update manufacturer name char: %d", status); } status = aci_gatt_update_char_value(dev_info_svc->service_handle, dev_info_svc->serial_num_char_handle, @@ -105,7 +105,7 @@ void dev_info_svc_start() { strlen(dev_info_serial_num), (uint8_t*)dev_info_serial_num); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update serial number char: %d", status); + FURI_LOG_E(TAG, "Failed to update serial number char: %d", status); } status = aci_gatt_update_char_value(dev_info_svc->service_handle, dev_info_svc->firmware_rev_char_handle, @@ -113,7 +113,7 @@ void dev_info_svc_start() { strlen(dev_info_firmware_rev_num), (uint8_t*)dev_info_firmware_rev_num); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update firmware revision char: %d", status); + FURI_LOG_E(TAG, "Failed to update firmware revision char: %d", status); } status = aci_gatt_update_char_value(dev_info_svc->service_handle, dev_info_svc->software_rev_char_handle, @@ -121,7 +121,7 @@ void dev_info_svc_start() { strlen(dev_info_software_rev_num), (uint8_t*)dev_info_software_rev_num); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update software revision char: %d", status); + FURI_LOG_E(TAG, "Failed to update software revision char: %d", status); } } @@ -131,24 +131,24 @@ void dev_info_svc_stop() { // Delete service characteristics status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->man_name_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete manufacturer name char: %d", status); + FURI_LOG_E(TAG, "Failed to delete manufacturer name char: %d", status); } status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->serial_num_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete serial number char: %d", status); + FURI_LOG_E(TAG, "Failed to delete serial number char: %d", status); } status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->firmware_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete firmware revision char: %d", status); + FURI_LOG_E(TAG, "Failed to delete firmware revision char: %d", status); } status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->software_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete software revision char: %d", status); + FURI_LOG_E(TAG, "Failed to delete software revision char: %d", status); } // Delete service status = aci_gatt_del_service(dev_info_svc->service_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete device info service: %d", status); + FURI_LOG_E(TAG, "Failed to delete device info service: %d", status); } free(dev_info_svc); dev_info_svc = NULL; diff --git a/firmware/targets/f6/ble-glue/gap.c b/firmware/targets/f6/ble-glue/gap.c index 39c9c405..7c7041cb 100644 --- a/firmware/targets/f6/ble-glue/gap.c +++ b/firmware/targets/f6/ble-glue/gap.c @@ -10,7 +10,7 @@ #include -#define GAP_TAG "BLE" +#define TAG "BtGap" #define FAST_ADV_TIMEOUT 30000 #define INITIAL_ADV_TIMEOUT 60000 @@ -80,7 +80,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) if (disconnection_complete_event->Connection_Handle == gap->gap_svc.connection_handle) { gap->gap_svc.connection_handle = 0; gap->state = GapStateIdle; - FURI_LOG_I(GAP_TAG, "Disconnect from client. Reason: %d", disconnection_complete_event->Reason); + FURI_LOG_I(TAG, "Disconnect from client. Reason: %d", disconnection_complete_event->Reason); } if(gap->enable_adv) { // Restart advertising @@ -96,28 +96,28 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) meta_evt = (evt_le_meta_event*) event_pckt->data; switch (meta_evt->subevent) { case EVT_LE_CONN_UPDATE_COMPLETE: - FURI_LOG_D(GAP_TAG, "Connection update event"); + FURI_LOG_D(TAG, "Connection update event"); break; case EVT_LE_PHY_UPDATE_COMPLETE: evt_le_phy_update_complete = (hci_le_phy_update_complete_event_rp0*)meta_evt->data; if(evt_le_phy_update_complete->Status) { - FURI_LOG_E(GAP_TAG, "Update PHY failed, status %d", evt_le_phy_update_complete->Status); + FURI_LOG_E(TAG, "Update PHY failed, status %d", evt_le_phy_update_complete->Status); } else { - FURI_LOG_I(GAP_TAG, "Update PHY succeed"); + FURI_LOG_I(TAG, "Update PHY succeed"); } ret = hci_le_read_phy(gap->gap_svc.connection_handle,&tx_phy,&rx_phy); if(ret) { - FURI_LOG_E(GAP_TAG, "Read PHY failed, status: %d", ret); + FURI_LOG_E(TAG, "Read PHY failed, status: %d", ret); } else { - FURI_LOG_I(GAP_TAG, "PHY Params TX = %d, RX = %d ", tx_phy, rx_phy); + FURI_LOG_I(TAG, "PHY Params TX = %d, RX = %d ", tx_phy, rx_phy); } break; case EVT_LE_CONN_COMPLETE: furi_hal_power_insomnia_enter(); hci_le_connection_complete_event_rp0* connection_complete_event = (hci_le_connection_complete_event_rp0 *) meta_evt->data; - FURI_LOG_I(GAP_TAG, "Connection complete for connection handle 0x%x", connection_complete_event->Connection_Handle); + FURI_LOG_I(TAG, "Connection complete for connection handle 0x%x", connection_complete_event->Connection_Handle); // Stop advertising as connection completed osTimerStop(gap->advertise_timer); @@ -141,7 +141,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) aci_gap_pairing_complete_event_rp0 *pairing_complete; case EVT_BLUE_GAP_LIMITED_DISCOVERABLE: - FURI_LOG_I(GAP_TAG, "Limited discoverable event"); + FURI_LOG_I(TAG, "Limited discoverable event"); break; case EVT_BLUE_GAP_PASS_KEY_REQUEST: @@ -149,39 +149,39 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) // Generate random PIN code uint32_t pin = rand() % 999999; aci_gap_pass_key_resp(gap->gap_svc.connection_handle, pin); - FURI_LOG_I(GAP_TAG, "Pass key request event. Pin: %d", pin); + FURI_LOG_I(TAG, "Pass key request event. Pin: %d", pin); BleEvent event = {.type = BleEventTypePinCodeShow, .data.pin_code = pin}; gap->on_event_cb(event, gap->context); } break; case EVT_BLUE_GAP_AUTHORIZATION_REQUEST: - FURI_LOG_I(GAP_TAG, "Authorization request event"); + FURI_LOG_I(TAG, "Authorization request event"); break; case EVT_BLUE_GAP_SLAVE_SECURITY_INITIATED: - FURI_LOG_I(GAP_TAG, "Slave security initiated"); + FURI_LOG_I(TAG, "Slave security initiated"); break; case EVT_BLUE_GAP_BOND_LOST: - FURI_LOG_I(GAP_TAG, "Bond lost event. Start rebonding"); + FURI_LOG_I(TAG, "Bond lost event. Start rebonding"); aci_gap_allow_rebond(gap->gap_svc.connection_handle); break; case EVT_BLUE_GAP_DEVICE_FOUND: - FURI_LOG_I(GAP_TAG, "Device found event"); + FURI_LOG_I(TAG, "Device found event"); break; case EVT_BLUE_GAP_ADDR_NOT_RESOLVED: - FURI_LOG_I(GAP_TAG, "Address not resolved event"); + FURI_LOG_I(TAG, "Address not resolved event"); break; case EVT_BLUE_GAP_KEYPRESS_NOTIFICATION: - FURI_LOG_I(GAP_TAG, "Key press notification event"); + FURI_LOG_I(TAG, "Key press notification event"); break; case EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE: - FURI_LOG_I(GAP_TAG, "Hex_value = %lx", + FURI_LOG_I(TAG, "Hex_value = %lx", ((aci_gap_numeric_comparison_value_event_rp0 *)(blue_evt->data))->Numeric_Value); aci_gap_numeric_comparison_value_confirm_yesno(gap->gap_svc.connection_handle, 1); break; @@ -189,17 +189,17 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) case EVT_BLUE_GAP_PAIRING_CMPLT: pairing_complete = (aci_gap_pairing_complete_event_rp0*)blue_evt->data; if (pairing_complete->Status) { - FURI_LOG_E(GAP_TAG, "Pairing failed with status: %d. Terminating connection", pairing_complete->Status); + FURI_LOG_E(TAG, "Pairing failed with status: %d. Terminating connection", pairing_complete->Status); aci_gap_terminate(gap->gap_svc.connection_handle, 5); } else { - FURI_LOG_I(GAP_TAG, "Pairing complete"); + FURI_LOG_I(TAG, "Pairing complete"); BleEvent event = {.type = BleEventTypeConnected}; gap->on_event_cb(event, gap->context); } break; case EVT_BLUE_GAP_PROCEDURE_COMPLETE: - FURI_LOG_I(GAP_TAG, "Procedure complete event"); + FURI_LOG_I(TAG, "Procedure complete event"); break; } default: @@ -286,11 +286,11 @@ static void gap_init_svc(Gap* gap) { // Set GAP characteristics status = aci_gatt_update_char_value(gap->gap_svc.gap_svc_handle, gap->gap_svc.dev_name_char_handle, 0, strlen(name), (uint8_t *) name); if (status) { - FURI_LOG_E(GAP_TAG, "Failed updating name characteristic: %d", status); + FURI_LOG_E(TAG, "Failed updating name characteristic: %d", status); } status = aci_gatt_update_char_value(gap->gap_svc.gap_svc_handle, gap->gap_svc.appearance_char_handle, 0, 2, gap_appearence_char_uuid); if(status) { - FURI_LOG_E(GAP_TAG, "Failed updating appearence characteristic: %d", status); + FURI_LOG_E(TAG, "Failed updating appearence characteristic: %d", status); } // Set default PHY hci_le_set_default_phy(ALL_PHYS_PREFERENCE, TX_2M_PREFERRED, RX_2M_PREFERRED); @@ -322,7 +322,7 @@ static void gap_advertise_start(GapState new_state) // Stop advertising status = aci_gap_set_non_discoverable(); if (status) { - FURI_LOG_E(GAP_TAG, "Stop Advertising Failed, result: %d", status); + FURI_LOG_E(TAG, "Stop Advertising Failed, result: %d", status); } } // Configure advertising @@ -331,7 +331,7 @@ static void gap_advertise_start(GapState new_state) strlen(name), (uint8_t*)name, gap->gap_svc.adv_svc_uuid_len, gap->gap_svc.adv_svc_uuid, 0, 0); if(status) { - FURI_LOG_E(GAP_TAG, "Set discoverable err: %d", status); + FURI_LOG_E(TAG, "Set discoverable err: %d", status); } gap->state = new_state; BleEvent event = {.type = BleEventTypeStartAdvertising}; @@ -355,14 +355,14 @@ static void gap_advertise_stop() { } void gap_start_advertising() { - FURI_LOG_I(GAP_TAG, "Start advertising"); + FURI_LOG_I(TAG, "Start advertising"); gap->enable_adv = true; GapCommand command = GapCommandAdvFast; furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK); } void gap_stop_advertising() { - FURI_LOG_I(GAP_TAG, "Stop advertising"); + FURI_LOG_I(TAG, "Stop advertising"); gap->enable_adv = false; GapCommand command = GapCommandAdvStop; furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK); diff --git a/firmware/targets/f6/ble-glue/serial_service.c b/firmware/targets/f6/ble-glue/serial_service.c index 43b07718..c7ea6db2 100644 --- a/firmware/targets/f6/ble-glue/serial_service.c +++ b/firmware/targets/f6/ble-glue/serial_service.c @@ -4,7 +4,7 @@ #include -#define SERIAL_SERVICE_TAG "serial service" +#define TAG "BtSerialSvc" typedef struct { uint16_t svc_handle; @@ -37,26 +37,26 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void *event) { if(attribute_modified->Attr_Handle == serial_svc->rx_char_handle + 2) { // Descriptor handle ret = SVCCTL_EvtAckFlowEnable; - FURI_LOG_D(SERIAL_SERVICE_TAG, "RX descriptor event"); + FURI_LOG_D(TAG, "RX descriptor event"); } else if(attribute_modified->Attr_Handle == serial_svc->rx_char_handle + 1) { - FURI_LOG_D(SERIAL_SERVICE_TAG, "Received %d bytes", attribute_modified->Attr_Data_Length); + FURI_LOG_D(TAG, "Received %d bytes", attribute_modified->Attr_Data_Length); if(serial_svc->on_received_cb) { furi_check(osMutexAcquire(serial_svc->buff_size_mtx, osWaitForever) == osOK); if(attribute_modified->Attr_Data_Length > serial_svc->bytes_ready_to_receive) { FURI_LOG_W( - SERIAL_SERVICE_TAG, "Received %d, while was ready to receive %d bytes. Can lead to buffer overflow!", + TAG, "Received %d, while was ready to receive %d bytes. Can lead to buffer overflow!", attribute_modified->Attr_Data_Length, serial_svc->bytes_ready_to_receive); } serial_svc->bytes_ready_to_receive -= MIN(serial_svc->bytes_ready_to_receive, attribute_modified->Attr_Data_Length); uint32_t buff_free_size = serial_svc->on_received_cb(attribute_modified->Attr_Data, attribute_modified->Attr_Data_Length, serial_svc->context); - FURI_LOG_D(SERIAL_SERVICE_TAG, "Available buff size: %d", buff_free_size); + FURI_LOG_D(TAG, "Available buff size: %d", buff_free_size); furi_check(osMutexRelease(serial_svc->buff_size_mtx) == osOK); } ret = SVCCTL_EvtAckFlowEnable; } } else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) { - FURI_LOG_D(SERIAL_SERVICE_TAG, "Ack received", blecore_evt->ecode); + FURI_LOG_D(TAG, "Ack received", blecore_evt->ecode); if(serial_svc->on_sent_cb) { serial_svc->on_sent_cb(serial_svc->context); } @@ -75,7 +75,7 @@ void serial_svc_start() { // Add service status = aci_gatt_add_service(UUID_TYPE_128, (Service_UUID_t *)service_uuid, PRIMARY_SERVICE, 10, &serial_svc->svc_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add Serial service: %d", status); + FURI_LOG_E(TAG, "Failed to add Serial service: %d", status); } // Add RX characteristics @@ -88,7 +88,7 @@ void serial_svc_start() { CHAR_VALUE_LEN_VARIABLE, &serial_svc->rx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add RX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add RX characteristic: %d", status); } // Add TX characteristic @@ -101,7 +101,7 @@ void serial_svc_start() { CHAR_VALUE_LEN_VARIABLE, &serial_svc->tx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add TX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add TX characteristic: %d", status); } // Add Flow Control characteristic status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)flow_ctrl_uuid, @@ -113,7 +113,7 @@ void serial_svc_start() { CHAR_VALUE_LEN_CONSTANT, &serial_svc->flow_ctrl_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add Flow Control characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add Flow Control characteristic: %d", status); } // Allocate buffer size mutex serial_svc->buff_size_mtx = osMutexNew(NULL); @@ -136,7 +136,7 @@ void serial_svc_notify_buffer_is_empty() { furi_check(osMutexAcquire(serial_svc->buff_size_mtx, osWaitForever) == osOK); if(serial_svc->bytes_ready_to_receive == 0) { - FURI_LOG_D(SERIAL_SERVICE_TAG, "Buffer is empty. Notifying client"); + FURI_LOG_D(TAG, "Buffer is empty. Notifying client"); serial_svc->bytes_ready_to_receive = serial_svc->buff_size; uint32_t buff_size_reversed = REVERSE_BYTES_U32(serial_svc->buff_size); aci_gatt_update_char_value(serial_svc->svc_handle, serial_svc->flow_ctrl_char_handle, 0, sizeof(uint32_t), (uint8_t*)&buff_size_reversed); @@ -150,20 +150,20 @@ void serial_svc_stop() { // Delete characteristics status = aci_gatt_del_char(serial_svc->svc_handle, serial_svc->tx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete TX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete TX characteristic: %d", status); } status = aci_gatt_del_char(serial_svc->svc_handle, serial_svc->rx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete RX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete RX characteristic: %d", status); } status = aci_gatt_del_char(serial_svc->svc_handle, serial_svc->flow_ctrl_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete Flow Control characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete Flow Control characteristic: %d", status); } // Delete service status = aci_gatt_del_service(serial_svc->svc_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete Serial service: %d", status); + FURI_LOG_E(TAG, "Failed to delete Serial service: %d", status); } // Delete buffer size mutex osMutexDelete(serial_svc->buff_size_mtx); @@ -182,7 +182,7 @@ bool serial_svc_update_tx(uint8_t* data, uint8_t data_len) { data_len, data); if(result) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed updating TX characteristic: %d", result); + FURI_LOG_E(TAG, "Failed updating TX characteristic: %d", result); } return result != BLE_STATUS_SUCCESS; } diff --git a/firmware/targets/f6/Src/fatfs/fatfs.c b/firmware/targets/f6/fatfs/fatfs.c similarity index 100% rename from firmware/targets/f6/Src/fatfs/fatfs.c rename to firmware/targets/f6/fatfs/fatfs.c diff --git a/firmware/targets/f6/Src/fatfs/fatfs.h b/firmware/targets/f6/fatfs/fatfs.h similarity index 100% rename from firmware/targets/f6/Src/fatfs/fatfs.h rename to firmware/targets/f6/fatfs/fatfs.h diff --git a/firmware/targets/f6/Src/fatfs/ffconf.h b/firmware/targets/f6/fatfs/ffconf.h similarity index 100% rename from firmware/targets/f6/Src/fatfs/ffconf.h rename to firmware/targets/f6/fatfs/ffconf.h diff --git a/firmware/targets/f6/Src/fatfs/spi_sd_hal.c b/firmware/targets/f6/fatfs/spi_sd_hal.c similarity index 100% rename from firmware/targets/f6/Src/fatfs/spi_sd_hal.c rename to firmware/targets/f6/fatfs/spi_sd_hal.c diff --git a/firmware/targets/f6/Src/fatfs/stm32_adafruit_sd.c b/firmware/targets/f6/fatfs/stm32_adafruit_sd.c similarity index 100% rename from firmware/targets/f6/Src/fatfs/stm32_adafruit_sd.c rename to firmware/targets/f6/fatfs/stm32_adafruit_sd.c diff --git a/firmware/targets/f6/Src/fatfs/stm32_adafruit_sd.h b/firmware/targets/f6/fatfs/stm32_adafruit_sd.h similarity index 100% rename from firmware/targets/f6/Src/fatfs/stm32_adafruit_sd.h rename to firmware/targets/f6/fatfs/stm32_adafruit_sd.h diff --git a/firmware/targets/f6/Src/fatfs/syscall.c b/firmware/targets/f6/fatfs/syscall.c similarity index 100% rename from firmware/targets/f6/Src/fatfs/syscall.c rename to firmware/targets/f6/fatfs/syscall.c diff --git a/firmware/targets/f6/Src/fatfs/user_diskio.c b/firmware/targets/f6/fatfs/user_diskio.c similarity index 100% rename from firmware/targets/f6/Src/fatfs/user_diskio.c rename to firmware/targets/f6/fatfs/user_diskio.c diff --git a/firmware/targets/f6/Src/fatfs/user_diskio.h b/firmware/targets/f6/fatfs/user_diskio.h similarity index 100% rename from firmware/targets/f6/Src/fatfs/user_diskio.h rename to firmware/targets/f6/fatfs/user_diskio.h diff --git a/firmware/targets/f6/furi-hal/furi-hal-bootloader.c b/firmware/targets/f6/furi-hal/furi-hal-bootloader.c index 2962877e..e8ea913e 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-bootloader.c +++ b/firmware/targets/f6/furi-hal/furi-hal-bootloader.c @@ -2,6 +2,8 @@ #include #include +#define TAG "FuriHalBoot" + // Boot request enum #define BOOT_REQUEST_TAINTED 0x00000000 #define BOOT_REQUEST_CLEAN 0xDADEDADE @@ -11,7 +13,7 @@ void furi_hal_bootloader_init() { #ifndef DEBUG LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED); #endif - FURI_LOG_I("FuriHalBoot", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-clock.c b/firmware/targets/f6/furi-hal/furi-hal-clock.c index fd4899d4..7a124049 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-clock.c +++ b/firmware/targets/f6/furi-hal/furi-hal-clock.c @@ -5,6 +5,8 @@ #include #include +#define TAG "FuriHalClock" + #define HS_CLOCK_IS_READY() (LL_RCC_HSE_IsReady() && LL_RCC_HSI_IsReady()) #define LS_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) @@ -123,7 +125,7 @@ void furi_hal_clock_init() { // APB2 LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - FURI_LOG_I("FuriHalClock", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_clock_switch_to_hsi() { diff --git a/firmware/targets/f6/furi-hal/furi-hal-compress.c b/firmware/targets/f6/furi-hal/furi-hal-compress.c index 9b7678f5..eb6e9d51 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-compress.c +++ b/firmware/targets/f6/furi-hal/furi-hal-compress.c @@ -4,6 +4,8 @@ #include #include +#define TAG "FuriHalCompress" + #define FURI_HAL_COMPRESS_ICON_ENCODED_BUFF_SIZE (512) #define FURI_HAL_COMPRESS_ICON_DECODED_BUFF_SIZE (1024) @@ -46,7 +48,7 @@ void furi_hal_compress_icon_init() { FURI_HAL_COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG); heatshrink_decoder_reset(icon_decoder->decoder); memset(icon_decoder->decoded_buff, 0, sizeof(icon_decoder->decoded_buff)); - FURI_LOG_I("FuriHalCompress", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_compress_icon_decode(const uint8_t* icon_data, uint8_t** decoded_buff) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-console.c b/firmware/targets/f6/furi-hal/furi-hal-console.c index ffe340b9..993b498e 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-console.c +++ b/firmware/targets/f6/furi-hal/furi-hal-console.c @@ -6,8 +6,12 @@ #include #include +#include + #include +#define TAG "FuriHalConsole" + #define CONSOLE_BAUDRATE 230400 volatile bool furi_hal_console_alive = false; @@ -16,7 +20,7 @@ void furi_hal_console_init() { furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE); furi_hal_console_alive = true; - FURI_LOG_I("FuriHalConsole", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_console_enable() { @@ -35,22 +39,26 @@ void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) { if (!furi_hal_console_alive) return; + UTILS_ENTER_CRITICAL_SECTION(); // Transmit data furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size); // Wait for TC flag to be raised for last char while (!LL_USART_IsActiveFlag_TC(USART1)); + UTILS_EXIT_CRITICAL_SECTION(); } void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) { if (!furi_hal_console_alive) return; + UTILS_ENTER_CRITICAL_SECTION(); // Transmit data furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size); // Transmit new line symbols furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)"\r\n", 2); // Wait for TC flag to be raised for last char while (!LL_USART_IsActiveFlag_TC(USART1)); + UTILS_EXIT_CRITICAL_SECTION(); } void furi_hal_console_printf(const char format[], ...) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-crypto.c b/firmware/targets/f6/furi-hal/furi-hal-crypto.c index 648f3f18..91875d23 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-crypto.c +++ b/firmware/targets/f6/furi-hal/furi-hal-crypto.c @@ -3,10 +3,12 @@ #include #include +#define TAG "FuriHalCrypto" + CRYP_HandleTypeDef crypt; void furi_hal_crypto_init() { - FURI_LOG_I("FuriHalCrypto", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-delay.c b/firmware/targets/f6/furi-hal/furi-hal-delay.c index 52de8715..b5f3c334 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-delay.c +++ b/firmware/targets/f6/furi-hal/furi-hal-delay.c @@ -3,6 +3,8 @@ #include #include +#define TAG "FuriHalDelay" + static uint32_t clk_per_microsecond; void furi_hal_delay_init(void) { @@ -10,7 +12,7 @@ void furi_hal_delay_init(void) { DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; DWT->CYCCNT = 0U; clk_per_microsecond = SystemCoreClock / 1000000.0f; - FURI_LOG_I("FuriHalDelay", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void delay_us(float microseconds) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-i2c.c b/firmware/targets/f6/furi-hal/furi-hal-i2c.c index 196a2a7b..b1ec4711 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-i2c.c +++ b/firmware/targets/f6/furi-hal/furi-hal-i2c.c @@ -6,6 +6,8 @@ #include #include +#define TAG "FuriHalI2C" + osMutexId_t furi_hal_i2c_mutex = NULL; void furi_hal_i2c_init() { @@ -42,7 +44,7 @@ void furi_hal_i2c_init() { LL_I2C_DisableOwnAddress2(POWER_I2C); LL_I2C_DisableGeneralCall(POWER_I2C); LL_I2C_EnableClockStretching(POWER_I2C); - FURI_LOG_I("FuriHalI2C", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } bool furi_hal_i2c_tx( diff --git a/firmware/targets/f6/furi-hal/furi-hal-interrupt.c b/firmware/targets/f6/furi-hal/furi-hal-interrupt.c index 47e99c9f..2685edab 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-interrupt.c +++ b/firmware/targets/f6/furi-hal/furi-hal-interrupt.c @@ -4,6 +4,8 @@ #include #include +#define TAG "FuriHalInterrupt" + volatile FuriHalInterruptISR furi_hal_tim_tim2_isr = NULL; volatile FuriHalInterruptISR furi_hal_tim_tim1_isr = NULL; @@ -22,7 +24,7 @@ void furi_hal_interrupt_init() { NVIC_SetPriority(DMA1_Channel1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0)); NVIC_EnableIRQ(DMA1_Channel1_IRQn); - FURI_LOG_I("FuriHalInterrupt", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR isr) { @@ -161,10 +163,10 @@ void TAMP_STAMP_LSECSS_IRQHandler(void) { if (LL_RCC_IsActiveFlag_LSECSS()) { LL_RCC_ClearFlag_LSECSS(); if (!LL_RCC_LSE_IsReady()) { - FURI_LOG_E("FuriHalInterrupt", "LSE CSS fired: resetting system"); + FURI_LOG_E(TAG, "LSE CSS fired: resetting system"); NVIC_SystemReset(); } else { - FURI_LOG_E("FuriHalInterrupt", "LSE CSS fired: but LSE is alive"); + FURI_LOG_E(TAG, "LSE CSS fired: but LSE is alive"); } } } @@ -176,7 +178,7 @@ void RCC_IRQHandler(void) { void NMI_Handler(void) { if (LL_RCC_IsActiveFlag_HSECSS()) { LL_RCC_ClearFlag_HSECSS(); - FURI_LOG_E("FuriHalInterrupt", "HSE CSS fired: resetting system"); + FURI_LOG_E(TAG, "HSE CSS fired: resetting system"); NVIC_SystemReset(); } } diff --git a/firmware/targets/f6/furi-hal/furi-hal-light.c b/firmware/targets/f6/furi-hal/furi-hal-light.c index fba1bec4..ecf0d4f2 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-light.c +++ b/firmware/targets/f6/furi-hal/furi-hal-light.c @@ -1,6 +1,8 @@ #include #include +#define TAG "FuriHalLight" + #define LED_CURRENT_RED 50 #define LED_CURRENT_GREEN 50 #define LED_CURRENT_BLUE 50 @@ -21,7 +23,7 @@ void furi_hal_light_init() { lp5562_enable(); lp5562_configure(); - FURI_LOG_I("FuriHalLight", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_light_set(Light light, uint8_t value) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-nfc.c b/firmware/targets/f6/furi-hal/furi-hal-nfc.c index d92e2cad..4bca12a9 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-nfc.c +++ b/firmware/targets/f6/furi-hal/furi-hal-nfc.c @@ -1,15 +1,17 @@ #include "furi-hal-nfc.h" #include +#define TAG "FuriHalNfc" + static const uint32_t clocks_in_ms = 64 * 1000; void furi_hal_nfc_init() { ReturnCode ret = rfalNfcInitialize(); if(ret == ERR_NONE) { furi_hal_nfc_start_sleep(); - FURI_LOG_I("FuriHalNfc", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } else { - FURI_LOG_W("FuriHalNfc", "Initialization failed, RFAL returned: %d", ret); + FURI_LOG_W(TAG, "Initialization failed, RFAL returned: %d", ret); } } @@ -63,7 +65,7 @@ bool furi_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t ti while(state != RFAL_NFC_STATE_ACTIVATED) { rfalNfcWorker(); state = rfalNfcGetState(); - FURI_LOG_D("HAL NFC", "Current state %d", state); + FURI_LOG_D(TAG, "Current state %d", state); if(state == RFAL_NFC_STATE_POLL_ACTIVATION) { start = DWT->CYCCNT; continue; @@ -73,7 +75,7 @@ bool furi_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t ti } if(DWT->CYCCNT - start > timeout * clocks_in_ms) { rfalNfcDeactivate(true); - FURI_LOG_D("HAL NFC", "Timeout"); + FURI_LOG_D(TAG, "Timeout"); return false; } osThreadYield(); diff --git a/firmware/targets/f6/furi-hal/furi-hal-os.c b/firmware/targets/f6/furi-hal/furi-hal-os.c index eb1811b6..aac1b10e 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-os.c +++ b/firmware/targets/f6/furi-hal/furi-hal-os.c @@ -5,6 +5,8 @@ #include +#define TAG "FuriHalOs" + #define FURI_HAL_OS_CLK_FREQUENCY 32768 #define FURI_HAL_OS_TICK_PER_SECOND 1024 #define FURI_HAL_OS_CLK_PER_TICK (FURI_HAL_OS_CLK_FREQUENCY / FURI_HAL_OS_TICK_PER_SECOND) @@ -44,7 +46,7 @@ void furi_hal_os_init() { osTimerStart(second_timer, 1024); #endif - FURI_LOG_I("FuriHalOs", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void LPTIM2_IRQHandler(void) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-power.c b/firmware/targets/f6/furi-hal/furi-hal-power.c index 47ce5f4d..870cbda6 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-power.c +++ b/firmware/targets/f6/furi-hal/furi-hal-power.c @@ -15,6 +15,8 @@ #include +#define TAG "FuriHalPower" + typedef struct { volatile uint8_t insomnia; volatile uint8_t deep_insomnia; @@ -74,7 +76,7 @@ void furi_hal_power_init() { LL_PWR_SMPS_SetMode(LL_PWR_SMPS_STEP_DOWN); bq27220_init(&cedv); bq25896_init(); - FURI_LOG_I("FuriHalPower", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } uint16_t furi_hal_power_insomnia_level() { diff --git a/firmware/targets/f6/furi-hal/furi-hal-rfid.c b/firmware/targets/f6/furi-hal/furi-hal-rfid.c index a9bbc32c..d7092f88 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-rfid.c +++ b/firmware/targets/f6/furi-hal/furi-hal-rfid.c @@ -104,7 +104,7 @@ void furi_hal_rfid_tim_read(float freq, float duty_cycle) { sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; - if(HAL_TIM_OC_ConfigChannel(&LFRFID_READ_TIM, &sConfigOC, LFRFID_READ_CHANNEL) != HAL_OK) { + if(HAL_TIM_PWM_ConfigChannel(&LFRFID_READ_TIM, &sConfigOC, LFRFID_READ_CHANNEL) != HAL_OK) { Error_Handler(); } @@ -142,7 +142,6 @@ void furi_hal_rfid_tim_emulate(float freq) { TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; // basic PWM setup with needed freq and internal clock LFRFID_EMULATE_TIM.Init.Prescaler = prescaler; @@ -182,24 +181,6 @@ void furi_hal_rfid_tim_emulate(float freq) { HAL_OK) { Error_Handler(); } - - // no deadtime - sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; - sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; - sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; - sBreakDeadTimeConfig.DeadTime = 0; - sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; - sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; - sBreakDeadTimeConfig.BreakFilter = 0; - sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE; - sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH; - sBreakDeadTimeConfig.Break2Filter = 0; - sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; - if(HAL_TIMEx_ConfigBreakDeadTime(&LFRFID_EMULATE_TIM, &sBreakDeadTimeConfig) != HAL_OK) { - Error_Handler(); - } } void furi_hal_rfid_tim_emulate_start() { diff --git a/firmware/targets/f6/furi-hal/furi-hal-spi.c b/firmware/targets/f6/furi-hal/furi-hal-spi.c index 805b8dfb..da7c63df 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-spi.c +++ b/firmware/targets/f6/furi-hal/furi-hal-spi.c @@ -9,6 +9,8 @@ #include #include +#define TAG "FuriHalSpi" + void furi_hal_spi_init() { // Spi structure is const, but mutex is not // Need some hell-ish casting to make it work @@ -33,7 +35,7 @@ void furi_hal_spi_init() { hal_gpio_init_ex(&gpio_spi_d_mosi, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedVeryHigh, GpioAltFn5SPI2); hal_gpio_init_ex(&gpio_spi_d_sck, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedVeryHigh, GpioAltFn5SPI2); - FURI_LOG_I("FuriHalSpi", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_spi_bus_lock(const FuriHalSpiBus* bus) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-subghz.c b/firmware/targets/f6/furi-hal/furi-hal-subghz.c index cd610cb2..276482ee 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-subghz.c +++ b/firmware/targets/f6/furi-hal/furi-hal-subghz.c @@ -10,6 +10,8 @@ #include #include +#define TAG "FuriHalSubGhz" + static volatile SubGhzState furi_hal_subghz_state = SubGhzStateInit; static volatile SubGhzRegulation furi_hal_subghz_regulation = SubGhzRegulationTxRx; @@ -303,7 +305,7 @@ void furi_hal_subghz_init() { cc1101_shutdown(device); furi_hal_spi_device_return(device); - FURI_LOG_I("FuriHalSubGhz", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_subghz_sleep() { diff --git a/firmware/targets/f6/furi-hal/furi-hal-usb.c b/firmware/targets/f6/furi-hal/furi-hal-usb.c index 8c78eb8b..45a6177e 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-usb.c +++ b/firmware/targets/f6/furi-hal/furi-hal-usb.c @@ -5,6 +5,8 @@ #include "usb.h" +#define TAG "FuriHalUsb" + #define USB_RECONNECT_DELAY 500 extern struct UsbInterface usb_cdc_single; @@ -64,7 +66,7 @@ void furi_hal_usb_init(void) { HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0); NVIC_EnableIRQ(USB_LP_IRQn); - FURI_LOG_I("FuriHalUsb", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_usb_set_config(UsbMode new_mode) { @@ -81,7 +83,7 @@ void furi_hal_usb_set_config(UsbMode new_mode) { usb_if_modes[usb_config.mode_cur]->deinit(&udev); if (usb_if_modes[new_mode] != NULL) { usb_if_modes[new_mode]->init(&udev, usb_if_modes[new_mode]); - FURI_LOG_I("FuriHalUsb", "USB mode change %u -> %u", usb_config.mode_cur, new_mode); + FURI_LOG_I(TAG, "USB mode change %u -> %u", usb_config.mode_cur, new_mode); usb_config.enabled = true; usb_config.mode_cur = new_mode; } @@ -98,7 +100,7 @@ void furi_hal_usb_disable() { susp_evt(&udev, 0, 0); usbd_connect(&udev, false); usb_config.enabled = false; - FURI_LOG_I("FuriHalUsb", "USB Disable"); + FURI_LOG_I(TAG, "USB Disable"); } } @@ -106,7 +108,7 @@ void furi_hal_usb_enable() { if ((!usb_config.enabled) && (usb_if_modes[usb_config.mode_cur] != NULL)) { usbd_connect(&udev, true); usb_config.enabled = true; - FURI_LOG_I("FuriHalUsb", "USB Enable"); + FURI_LOG_I(TAG, "USB Enable"); } } diff --git a/firmware/targets/f6/furi-hal/furi-hal-vcp.c b/firmware/targets/f6/furi-hal/furi-hal-vcp.c index 93da91d8..039481f1 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-vcp.c +++ b/firmware/targets/f6/furi-hal/furi-hal-vcp.c @@ -1,8 +1,10 @@ #include - +#include #include #include +#define TAG "FuriHalVcp" + #define USB_CDC_PKT_LEN CDC_DATA_SZ #define VCP_RX_BUF_SIZE (USB_CDC_PKT_LEN * 3) #define VCP_TX_BUF_SIZE (USB_CDC_PKT_LEN * 3) @@ -17,11 +19,11 @@ typedef enum { VcpEvtDisable = (1 << 4), VcpEvtRx = (1 << 5), VcpEvtTx = (1 << 6), - VcpEvtRxDone = (1 << 7), - VcpEvtTxDone = (1 << 8), + VcpEvtStreamRx = (1 << 7), + VcpEvtStreamTx = (1 << 8), } WorkerEvtFlags; -#define VCP_THREAD_FLAG_ALL (VcpEvtConnect | VcpEvtDisconnect | VcpEvtEnable | VcpEvtDisable | VcpEvtRx | VcpEvtTx | VcpEvtRxDone | VcpEvtTxDone) +#define VCP_THREAD_FLAG_ALL (VcpEvtConnect | VcpEvtDisconnect | VcpEvtEnable | VcpEvtDisable | VcpEvtRx | VcpEvtTx | VcpEvtStreamRx | VcpEvtStreamTx) typedef struct { FuriThread* thread; @@ -62,61 +64,69 @@ void furi_hal_vcp_init() { vcp->thread = furi_thread_alloc(); furi_thread_set_name(vcp->thread, "VcpWorker"); - furi_thread_set_stack_size(vcp->thread, 512); + furi_thread_set_stack_size(vcp->thread, 1024); furi_thread_set_callback(vcp->thread, vcp_worker); furi_thread_start(vcp->thread); - FURI_LOG_I("FuriHalVcp", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } static int32_t vcp_worker(void* context) { bool enabled = true; bool tx_idle = false; - bool rx_pending = false; + size_t missed_rx = 0; furi_hal_cdc_set_callbacks(VCP_IF_NUM, &cdc_cb); - + while (1) { uint32_t flags = osThreadFlagsWait(VCP_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever); furi_assert((flags & osFlagsError) == 0); // New data received - if((flags & VcpEvtRxDone) && enabled) { + if((flags & VcpEvtStreamRx) && enabled && missed_rx > 0) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP StreamRx\r\n"); +#endif if (xStreamBufferSpacesAvailable(vcp->rx_stream) >= USB_CDC_PKT_LEN) { - size_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); - if (len > 0) - xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever); - else - rx_pending = false; - } else - rx_pending = true; // Buffer is full, retry later + flags |= VcpEvtRx; + missed_rx--; + } } // Rx buffer was read, maybe there is enough space for new data? - if((flags & VcpEvtRx) && rx_pending) { + if((flags & VcpEvtRx)) { if (xStreamBufferSpacesAvailable(vcp->rx_stream) >= USB_CDC_PKT_LEN) { - size_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); - if (len > 0) - xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever); - else - rx_pending = false; + int32_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_printf("VCP Rx %d\r\n", len); +#endif + if (len > 0) { + furi_check(xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever) == len); + } + } else { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Rx missed\r\n"); +#endif + missed_rx++; } } // New data in Tx buffer - if((flags & VcpEvtTx) && enabled) { + if((flags & VcpEvtStreamTx) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP StreamTx\r\n"); +#endif if (tx_idle) { - size_t len = xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0); - if (len > 0) { - tx_idle = false; - furi_hal_cdc_send(VCP_IF_NUM, vcp->data_buffer, len); - } + flags |= VcpEvtTx; } } // CDC write transfer done - if((flags & VcpEvtTxDone) && enabled) { + if((flags & VcpEvtTx) && enabled) { size_t len = xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0); +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_printf("VCP Tx %d\r\n", len); +#endif if (len > 0) { // Some data left in Tx buffer. Sending it now tx_idle = false; furi_hal_cdc_send(VCP_IF_NUM, vcp->data_buffer, len); @@ -127,6 +137,9 @@ static int32_t vcp_worker(void* context) { // VCP session opened if((flags & VcpEvtConnect) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Connect\r\n"); +#endif if (vcp->connected == false) { vcp->connected = true; xStreamBufferSend(vcp->rx_stream, &ascii_soh, 1, osWaitForever); @@ -135,6 +148,9 @@ static int32_t vcp_worker(void* context) { // VCP session closed if((flags & VcpEvtDisconnect) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Disconnect\r\n"); +#endif if (vcp->connected == true) { vcp->connected = false; xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever); @@ -143,6 +159,9 @@ static int32_t vcp_worker(void* context) { // VCP enabled if((flags & VcpEvtEnable) && !enabled){ +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Enable\r\n"); +#endif furi_hal_cdc_set_callbacks(VCP_IF_NUM, &cdc_cb); enabled = true; furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); // flush Rx buffer @@ -154,6 +173,9 @@ static int32_t vcp_worker(void* context) { // VCP disabled if((flags & VcpEvtDisable) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Disable\r\n"); +#endif enabled = false; vcp->connected = false; xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever); @@ -182,9 +204,9 @@ size_t furi_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeo batch_size = VCP_RX_BUF_SIZE; size_t len = xStreamBufferReceive(vcp->rx_stream, buffer, batch_size, timeout); - osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRx); if (len == 0) break; + osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamRx); size -= len; buffer += len; rx_cnt += len; @@ -207,7 +229,7 @@ void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) { batch_size = VCP_TX_BUF_SIZE; xStreamBufferSend(vcp->tx_stream, buffer, batch_size, osWaitForever); - osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTx); + osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamTx); size -= batch_size; buffer += batch_size; @@ -215,6 +237,9 @@ void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) { } static void vcp_state_callback(uint8_t state) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP State\r\n"); +#endif if (state == 0) { osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtDisconnect); } @@ -223,7 +248,9 @@ static void vcp_state_callback(uint8_t state) { static void vcp_on_cdc_control_line(uint8_t state) { // bit 0: DTR state, bit 1: RTS state bool dtr = state & (1 << 0); - +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP CtrlLine\r\n"); +#endif if (dtr == true) { osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtConnect); } else { @@ -232,12 +259,12 @@ static void vcp_on_cdc_control_line(uint8_t state) { } static void vcp_on_cdc_rx() { - uint32_t ret = osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRxDone); + uint32_t ret = osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRx); furi_assert((ret & osFlagsError) == 0); } static void vcp_on_cdc_tx_complete() { - osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTxDone); + osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTx); } bool furi_hal_vcp_is_connected(void) { diff --git a/firmware/targets/f6/furi-hal/furi-hal-version.c b/firmware/targets/f6/furi-hal/furi-hal-version.c index 5b412315..8f5f26d9 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-version.c +++ b/firmware/targets/f6/furi-hal/furi-hal-version.c @@ -7,6 +7,8 @@ #include #include "ble.h" +#define TAG "FuriHalVersion" + #define FURI_HAL_VERSION_OTP_HEADER_MAGIC 0xBABE #define FURI_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE @@ -191,7 +193,7 @@ void furi_hal_version_init() { break; default: furi_crash(NULL); } - FURI_LOG_I("FuriHalVersion", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } bool furi_hal_version_do_i_belong_here() { diff --git a/firmware/targets/f6/furi-hal/furi-hal-vibro.c b/firmware/targets/f6/furi-hal/furi-hal-vibro.c index 7dfddd42..7de8ad84 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-vibro.c +++ b/firmware/targets/f6/furi-hal/furi-hal-vibro.c @@ -1,10 +1,12 @@ #include #include +#define TAG "FuriHalVibro" + void furi_hal_vibro_init() { hal_gpio_init(&vibro_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); hal_gpio_write(&vibro_gpio, false); - FURI_LOG_I("FuriHalVibro", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } diff --git a/firmware/targets/f6/furi-hal/furi-hal.c b/firmware/targets/f6/furi-hal/furi-hal.c index f332d187..d435c5f2 100644 --- a/firmware/targets/f6/furi-hal/furi-hal.c +++ b/firmware/targets/f6/furi-hal/furi-hal.c @@ -7,6 +7,10 @@ #include +#include + +#define TAG "FuriHal" + void furi_hal_init() { furi_hal_clock_init(); furi_hal_console_init(); @@ -14,23 +18,23 @@ void furi_hal_init() { furi_hal_delay_init(); MX_GPIO_Init(); - FURI_LOG_I("HAL", "GPIO OK"); + FURI_LOG_I(TAG, "GPIO OK"); MX_RTC_Init(); - FURI_LOG_I("HAL", "RTC OK"); + FURI_LOG_I(TAG, "RTC OK"); furi_hal_bootloader_init(); furi_hal_version_init(); furi_hal_spi_init(); MX_TIM1_Init(); - FURI_LOG_I("HAL", "TIM1 OK"); + FURI_LOG_I(TAG, "TIM1 OK"); MX_TIM2_Init(); - FURI_LOG_I("HAL", "TIM2 OK"); + FURI_LOG_I(TAG, "TIM2 OK"); MX_TIM16_Init(); - FURI_LOG_I("HAL", "TIM16 OK"); + FURI_LOG_I(TAG, "TIM16 OK"); MX_COMP1_Init(); - FURI_LOG_I("HAL", "COMP1 OK"); + FURI_LOG_I(TAG, "COMP1 OK"); furi_hal_crypto_init(); @@ -38,7 +42,7 @@ void furi_hal_init() { furi_hal_usb_init(); furi_hal_usb_set_config(UsbModeVcpSingle); furi_hal_vcp_init(); - FURI_LOG_I("HAL", "USB OK"); + FURI_LOG_I(TAG, "USB OK"); furi_hal_i2c_init(); @@ -55,6 +59,10 @@ void furi_hal_init() { // FreeRTOS glue furi_hal_os_init(); + // FatFS driver initialization + MX_FATFS_Init(); + FURI_LOG_I(TAG, "FATFS OK"); + // Partial null pointer dereference protection LL_MPU_Disable(); LL_MPU_ConfigRegion( diff --git a/firmware/targets/f6/target.mk b/firmware/targets/f6/target.mk index 879d6272..85669e8d 100644 --- a/firmware/targets/f6/target.mk +++ b/firmware/targets/f6/target.mk @@ -128,6 +128,11 @@ ifeq ($(FURI_HAL_OS_DEBUG), 1) CFLAGS += -DFURI_HAL_OS_DEBUG endif +FURI_HAL_USB_VCP_DEBUG ?= 0 +ifeq ($(FURI_HAL_USB_VCP_DEBUG), 1) +CFLAGS += -DFURI_HAL_USB_VCP_DEBUG +endif + FURI_HAL_SUBGHZ_TX_GPIO ?= 0 ifneq ($(FURI_HAL_SUBGHZ_TX_GPIO), 0) CFLAGS += -DFURI_HAL_SUBGHZ_TX_GPIO=$(FURI_HAL_SUBGHZ_TX_GPIO) @@ -144,10 +149,10 @@ C_SOURCES += $(wildcard $(FURI_HAL_DIR)/*.c) # Other CFLAGS += \ -I$(MXPROJECT_DIR)/Inc \ - -I$(MXPROJECT_DIR)/Src/fatfs + -I$(MXPROJECT_DIR)/fatfs C_SOURCES += \ $(wildcard $(MXPROJECT_DIR)/Src/*.c) \ - $(wildcard $(MXPROJECT_DIR)/Src/fatfs/*.c) + $(wildcard $(MXPROJECT_DIR)/fatfs/*.c) # Linker options ifeq ($(NO_BOOTLOADER), 1) diff --git a/firmware/targets/f7/Inc/stm32_assert.h b/firmware/targets/f7/Inc/stm32_assert.h new file mode 100644 index 00000000..9f6261ff --- /dev/null +++ b/firmware/targets/f7/Inc/stm32_assert.h @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * @file stm32_assert.h + * @brief STM32 assert file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_ASSERT_H +#define __STM32_ASSERT_H + +#ifdef __cplusplus + extern "C" { +#endif + +#ifdef USE_FULL_ASSERT + #define assert_param(expr) ((expr) ? (void)0U : assert_failed()) + void assert_failed(); +#else + #define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32_ASSERT_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/Inc/stm32wbxx_hal_conf.h b/firmware/targets/f7/Inc/stm32wbxx_hal_conf.h index ab7b2953..4d5ad791 100644 --- a/firmware/targets/f7/Inc/stm32wbxx_hal_conf.h +++ b/firmware/targets/f7/Inc/stm32wbxx_hal_conf.h @@ -184,7 +184,7 @@ * @brief Uncomment the line below to expanse the "assert_param" macro in the * HAL drivers code */ -/* #define USE_FULL_ASSERT 1U */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -329,17 +329,8 @@ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ - #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ - void assert_failed(uint8_t* file, uint32_t line); + #define assert_param(expr) ((expr) ? (void)0U : assert_failed()) + void assert_failed(); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ diff --git a/firmware/targets/f7/Src/main.c b/firmware/targets/f7/Src/main.c index ea6d8943..a546086f 100644 --- a/firmware/targets/f7/Src/main.c +++ b/firmware/targets/f7/Src/main.c @@ -1,11 +1,11 @@ #include "main.h" -#include "fatfs/fatfs.h" - #include #include #include +#define TAG "Main" + int main(void) { // Initialize FURI layer furi_init(); @@ -16,13 +16,9 @@ int main(void) { // Flipper FURI HAL furi_hal_init(); - // 3rd party - MX_FATFS_Init(); - FURI_LOG_I("HAL", "FATFS OK"); - // CMSIS initialization osKernelInitialize(); - FURI_LOG_I("HAL", "KERNEL OK"); + FURI_LOG_I(TAG, "KERNEL OK"); // Init flipper flipper_init(); @@ -47,9 +43,6 @@ void Error_Handler(void) { * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ + furi_crash("HAL assert failed"); } #endif /* USE_FULL_ASSERT */ diff --git a/firmware/targets/f7/ble-glue/battery_service.c b/firmware/targets/f7/ble-glue/battery_service.c index 1dd8c5a0..2a5dad5e 100644 --- a/firmware/targets/f7/ble-glue/battery_service.c +++ b/firmware/targets/f7/ble-glue/battery_service.c @@ -4,7 +4,7 @@ #include -#define BATTERY_SERVICE_TAG "battery service" +#define TAG "BtBatterySvc" typedef struct { uint16_t svc_handle; @@ -23,7 +23,7 @@ void battery_svc_start() { // Add Battery service status = aci_gatt_add_service(UUID_TYPE_16, (Service_UUID_t*)&service_uuid, PRIMARY_SERVICE, 4, &battery_svc->svc_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to add Battery service: %d", status); + FURI_LOG_E(TAG, "Failed to add Battery service: %d", status); } // Add Battery level characteristic status = aci_gatt_add_char(battery_svc->svc_handle, @@ -37,7 +37,7 @@ void battery_svc_start() { CHAR_VALUE_LEN_CONSTANT, &battery_svc->char_level_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to add Battery level characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add Battery level characteristic: %d", status); } } @@ -47,12 +47,12 @@ void battery_svc_stop() { // Delete Battery level characteristic status = aci_gatt_del_char(battery_svc->svc_handle, battery_svc->char_level_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to delete Battery level characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete Battery level characteristic: %d", status); } // Delete Battery service status = aci_gatt_del_service(battery_svc->svc_handle); if(status) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed to delete Battery service: %d", status); + FURI_LOG_E(TAG, "Failed to delete Battery service: %d", status); } free(battery_svc); battery_svc = NULL; @@ -65,14 +65,14 @@ bool battery_svc_update_level(uint8_t battery_charge) { return false; } // Update battery level characteristic - FURI_LOG_I(BATTERY_SERVICE_TAG, "Updating battery level characteristic"); + FURI_LOG_I(TAG, "Updating battery level characteristic"); tBleStatus result = aci_gatt_update_char_value(battery_svc->svc_handle, battery_svc->char_level_handle, 0, 1, &battery_charge); if(result) { - FURI_LOG_E(BATTERY_SERVICE_TAG, "Failed updating RX characteristic: %d", result); + FURI_LOG_E(TAG, "Failed updating RX characteristic: %d", result); } return result != BLE_STATUS_SUCCESS; } diff --git a/firmware/targets/f7/ble-glue/ble_app.c b/firmware/targets/f7/ble-glue/ble_app.c index 92fddfc4..40b34679 100644 --- a/firmware/targets/f7/ble-glue/ble_app.c +++ b/firmware/targets/f7/ble-glue/ble_app.c @@ -8,7 +8,7 @@ #include -#define BLE_APP_TAG "ble app" +#define TAG "Bt" PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t ble_app_cmd_buffer; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint32_t ble_app_nvm[BLE_NVM_SRAM_SIZE]; @@ -53,7 +53,7 @@ bool ble_app_init() { }; status = SHCI_C2_Config(&config_param); if(status) { - FURI_LOG_E(BLE_APP_TAG, "Failed to configure 2nd core: %d", status); + FURI_LOG_E(TAG, "Failed to configure 2nd core: %d", status); } // Start ble stack on 2nd core @@ -82,7 +82,7 @@ bool ble_app_init() { }; status = SHCI_C2_BLE_Init(&ble_init_cmd_packet); if(status) { - FURI_LOG_E(BLE_APP_TAG, "Failed to start ble stack: %d", status); + FURI_LOG_E(TAG, "Failed to start ble stack: %d", status); } return status == SHCI_Success; } diff --git a/firmware/targets/f7/ble-glue/ble_glue.c b/firmware/targets/f7/ble-glue/ble_glue.c index 45277366..35c16223 100644 --- a/firmware/targets/f7/ble-glue/ble_glue.c +++ b/firmware/targets/f7/ble-glue/ble_glue.c @@ -10,6 +10,8 @@ #include "app_debug.h" #include +#define TAG "Core2" + #define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH*4U*DIVC(( sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE ), 4U)) PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ble_glue_event_pool[POOL_SIZE]; @@ -125,20 +127,20 @@ static void ble_glue_sys_user_event_callback( void * pPayload ) { if(p_sys_event->subevtcode == SHCI_SUB_EVT_CODE_READY) { if(ble_app_init()) { - FURI_LOG_I("Core2", "BLE stack started"); + FURI_LOG_I(TAG, "BLE stack started"); ble_glue->status = BleGlueStatusStarted; if(SHCI_C2_SetFlashActivityControl(FLASH_ACTIVITY_CONTROL_SEM7) == SHCI_Success) { - FURI_LOG_I("Core2", "Flash activity control switched to SEM7"); + FURI_LOG_I(TAG, "Flash activity control switched to SEM7"); } else { - FURI_LOG_E("Core2", "Failed to switch flash activity control to SEM7"); + FURI_LOG_E(TAG, "Failed to switch flash activity control to SEM7"); } } else { - FURI_LOG_E("Core2", "BLE stack startup failed"); + FURI_LOG_E(TAG, "BLE stack startup failed"); ble_glue->status = BleGlueStatusBleStackMissing; } furi_hal_power_insomnia_exit(); } else if(p_sys_event->subevtcode == SHCI_SUB_EVT_ERROR_NOTIF) { - FURI_LOG_E("Core2", "Error during initialization"); + FURI_LOG_E(TAG, "Error during initialization"); furi_hal_power_insomnia_exit(); } else if(p_sys_event->subevtcode == SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE) { SHCI_C2_BleNvmRamUpdate_Evt_t* p_sys_ble_nvm_ram_update_event = (SHCI_C2_BleNvmRamUpdate_Evt_t*)p_sys_event->payload; diff --git a/firmware/targets/f7/ble-glue/dev_info_service.c b/firmware/targets/f7/ble-glue/dev_info_service.c index 7ce2647c..64ff0509 100644 --- a/firmware/targets/f7/ble-glue/dev_info_service.c +++ b/firmware/targets/f7/ble-glue/dev_info_service.c @@ -4,7 +4,7 @@ #include -#define DEV_INFO_SVC_TAG "dev info service" +#define TAG "BtDevInfoSvc" typedef struct { uint16_t service_handle; @@ -29,7 +29,7 @@ void dev_info_svc_start() { uint16_t uuid = DEVICE_INFORMATION_SERVICE_UUID; status = aci_gatt_add_service(UUID_TYPE_16, (Service_UUID_t*)&uuid, PRIMARY_SERVICE, 9, &dev_info_svc->service_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add Device Information Service: %d", status); + FURI_LOG_E(TAG, "Failed to add Device Information Service: %d", status); } // Add characteristics @@ -45,7 +45,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->man_name_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add manufacturer name char: %d", status); + FURI_LOG_E(TAG, "Failed to add manufacturer name char: %d", status); } uuid = SERIAL_NUMBER_UUID; status = aci_gatt_add_char(dev_info_svc->service_handle, @@ -59,7 +59,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->serial_num_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add serial number char: %d", status); + FURI_LOG_E(TAG, "Failed to add serial number char: %d", status); } uuid = FIRMWARE_REVISION_UUID; status = aci_gatt_add_char(dev_info_svc->service_handle, @@ -73,7 +73,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->firmware_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add firmware revision char: %d", status); + FURI_LOG_E(TAG, "Failed to add firmware revision char: %d", status); } uuid = SOFTWARE_REVISION_UUID; status = aci_gatt_add_char(dev_info_svc->service_handle, @@ -87,7 +87,7 @@ void dev_info_svc_start() { CHAR_VALUE_LEN_CONSTANT, &dev_info_svc->software_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to add software revision char: %d", status); + FURI_LOG_E(TAG, "Failed to add software revision char: %d", status); } // Update characteristics @@ -97,7 +97,7 @@ void dev_info_svc_start() { strlen(dev_info_man_name), (uint8_t*)dev_info_man_name); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update manufacturer name char: %d", status); + FURI_LOG_E(TAG, "Failed to update manufacturer name char: %d", status); } status = aci_gatt_update_char_value(dev_info_svc->service_handle, dev_info_svc->serial_num_char_handle, @@ -105,7 +105,7 @@ void dev_info_svc_start() { strlen(dev_info_serial_num), (uint8_t*)dev_info_serial_num); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update serial number char: %d", status); + FURI_LOG_E(TAG, "Failed to update serial number char: %d", status); } status = aci_gatt_update_char_value(dev_info_svc->service_handle, dev_info_svc->firmware_rev_char_handle, @@ -113,7 +113,7 @@ void dev_info_svc_start() { strlen(dev_info_firmware_rev_num), (uint8_t*)dev_info_firmware_rev_num); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update firmware revision char: %d", status); + FURI_LOG_E(TAG, "Failed to update firmware revision char: %d", status); } status = aci_gatt_update_char_value(dev_info_svc->service_handle, dev_info_svc->software_rev_char_handle, @@ -121,7 +121,7 @@ void dev_info_svc_start() { strlen(dev_info_software_rev_num), (uint8_t*)dev_info_software_rev_num); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to update software revision char: %d", status); + FURI_LOG_E(TAG, "Failed to update software revision char: %d", status); } } @@ -131,24 +131,24 @@ void dev_info_svc_stop() { // Delete service characteristics status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->man_name_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete manufacturer name char: %d", status); + FURI_LOG_E(TAG, "Failed to delete manufacturer name char: %d", status); } status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->serial_num_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete serial number char: %d", status); + FURI_LOG_E(TAG, "Failed to delete serial number char: %d", status); } status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->firmware_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete firmware revision char: %d", status); + FURI_LOG_E(TAG, "Failed to delete firmware revision char: %d", status); } status = aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->software_rev_char_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete software revision char: %d", status); + FURI_LOG_E(TAG, "Failed to delete software revision char: %d", status); } // Delete service status = aci_gatt_del_service(dev_info_svc->service_handle); if(status) { - FURI_LOG_E(DEV_INFO_SVC_TAG, "Failed to delete device info service: %d", status); + FURI_LOG_E(TAG, "Failed to delete device info service: %d", status); } free(dev_info_svc); dev_info_svc = NULL; diff --git a/firmware/targets/f7/ble-glue/gap.c b/firmware/targets/f7/ble-glue/gap.c index 39c9c405..7c7041cb 100644 --- a/firmware/targets/f7/ble-glue/gap.c +++ b/firmware/targets/f7/ble-glue/gap.c @@ -10,7 +10,7 @@ #include -#define GAP_TAG "BLE" +#define TAG "BtGap" #define FAST_ADV_TIMEOUT 30000 #define INITIAL_ADV_TIMEOUT 60000 @@ -80,7 +80,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) if (disconnection_complete_event->Connection_Handle == gap->gap_svc.connection_handle) { gap->gap_svc.connection_handle = 0; gap->state = GapStateIdle; - FURI_LOG_I(GAP_TAG, "Disconnect from client. Reason: %d", disconnection_complete_event->Reason); + FURI_LOG_I(TAG, "Disconnect from client. Reason: %d", disconnection_complete_event->Reason); } if(gap->enable_adv) { // Restart advertising @@ -96,28 +96,28 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) meta_evt = (evt_le_meta_event*) event_pckt->data; switch (meta_evt->subevent) { case EVT_LE_CONN_UPDATE_COMPLETE: - FURI_LOG_D(GAP_TAG, "Connection update event"); + FURI_LOG_D(TAG, "Connection update event"); break; case EVT_LE_PHY_UPDATE_COMPLETE: evt_le_phy_update_complete = (hci_le_phy_update_complete_event_rp0*)meta_evt->data; if(evt_le_phy_update_complete->Status) { - FURI_LOG_E(GAP_TAG, "Update PHY failed, status %d", evt_le_phy_update_complete->Status); + FURI_LOG_E(TAG, "Update PHY failed, status %d", evt_le_phy_update_complete->Status); } else { - FURI_LOG_I(GAP_TAG, "Update PHY succeed"); + FURI_LOG_I(TAG, "Update PHY succeed"); } ret = hci_le_read_phy(gap->gap_svc.connection_handle,&tx_phy,&rx_phy); if(ret) { - FURI_LOG_E(GAP_TAG, "Read PHY failed, status: %d", ret); + FURI_LOG_E(TAG, "Read PHY failed, status: %d", ret); } else { - FURI_LOG_I(GAP_TAG, "PHY Params TX = %d, RX = %d ", tx_phy, rx_phy); + FURI_LOG_I(TAG, "PHY Params TX = %d, RX = %d ", tx_phy, rx_phy); } break; case EVT_LE_CONN_COMPLETE: furi_hal_power_insomnia_enter(); hci_le_connection_complete_event_rp0* connection_complete_event = (hci_le_connection_complete_event_rp0 *) meta_evt->data; - FURI_LOG_I(GAP_TAG, "Connection complete for connection handle 0x%x", connection_complete_event->Connection_Handle); + FURI_LOG_I(TAG, "Connection complete for connection handle 0x%x", connection_complete_event->Connection_Handle); // Stop advertising as connection completed osTimerStop(gap->advertise_timer); @@ -141,7 +141,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) aci_gap_pairing_complete_event_rp0 *pairing_complete; case EVT_BLUE_GAP_LIMITED_DISCOVERABLE: - FURI_LOG_I(GAP_TAG, "Limited discoverable event"); + FURI_LOG_I(TAG, "Limited discoverable event"); break; case EVT_BLUE_GAP_PASS_KEY_REQUEST: @@ -149,39 +149,39 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) // Generate random PIN code uint32_t pin = rand() % 999999; aci_gap_pass_key_resp(gap->gap_svc.connection_handle, pin); - FURI_LOG_I(GAP_TAG, "Pass key request event. Pin: %d", pin); + FURI_LOG_I(TAG, "Pass key request event. Pin: %d", pin); BleEvent event = {.type = BleEventTypePinCodeShow, .data.pin_code = pin}; gap->on_event_cb(event, gap->context); } break; case EVT_BLUE_GAP_AUTHORIZATION_REQUEST: - FURI_LOG_I(GAP_TAG, "Authorization request event"); + FURI_LOG_I(TAG, "Authorization request event"); break; case EVT_BLUE_GAP_SLAVE_SECURITY_INITIATED: - FURI_LOG_I(GAP_TAG, "Slave security initiated"); + FURI_LOG_I(TAG, "Slave security initiated"); break; case EVT_BLUE_GAP_BOND_LOST: - FURI_LOG_I(GAP_TAG, "Bond lost event. Start rebonding"); + FURI_LOG_I(TAG, "Bond lost event. Start rebonding"); aci_gap_allow_rebond(gap->gap_svc.connection_handle); break; case EVT_BLUE_GAP_DEVICE_FOUND: - FURI_LOG_I(GAP_TAG, "Device found event"); + FURI_LOG_I(TAG, "Device found event"); break; case EVT_BLUE_GAP_ADDR_NOT_RESOLVED: - FURI_LOG_I(GAP_TAG, "Address not resolved event"); + FURI_LOG_I(TAG, "Address not resolved event"); break; case EVT_BLUE_GAP_KEYPRESS_NOTIFICATION: - FURI_LOG_I(GAP_TAG, "Key press notification event"); + FURI_LOG_I(TAG, "Key press notification event"); break; case EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE: - FURI_LOG_I(GAP_TAG, "Hex_value = %lx", + FURI_LOG_I(TAG, "Hex_value = %lx", ((aci_gap_numeric_comparison_value_event_rp0 *)(blue_evt->data))->Numeric_Value); aci_gap_numeric_comparison_value_confirm_yesno(gap->gap_svc.connection_handle, 1); break; @@ -189,17 +189,17 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) case EVT_BLUE_GAP_PAIRING_CMPLT: pairing_complete = (aci_gap_pairing_complete_event_rp0*)blue_evt->data; if (pairing_complete->Status) { - FURI_LOG_E(GAP_TAG, "Pairing failed with status: %d. Terminating connection", pairing_complete->Status); + FURI_LOG_E(TAG, "Pairing failed with status: %d. Terminating connection", pairing_complete->Status); aci_gap_terminate(gap->gap_svc.connection_handle, 5); } else { - FURI_LOG_I(GAP_TAG, "Pairing complete"); + FURI_LOG_I(TAG, "Pairing complete"); BleEvent event = {.type = BleEventTypeConnected}; gap->on_event_cb(event, gap->context); } break; case EVT_BLUE_GAP_PROCEDURE_COMPLETE: - FURI_LOG_I(GAP_TAG, "Procedure complete event"); + FURI_LOG_I(TAG, "Procedure complete event"); break; } default: @@ -286,11 +286,11 @@ static void gap_init_svc(Gap* gap) { // Set GAP characteristics status = aci_gatt_update_char_value(gap->gap_svc.gap_svc_handle, gap->gap_svc.dev_name_char_handle, 0, strlen(name), (uint8_t *) name); if (status) { - FURI_LOG_E(GAP_TAG, "Failed updating name characteristic: %d", status); + FURI_LOG_E(TAG, "Failed updating name characteristic: %d", status); } status = aci_gatt_update_char_value(gap->gap_svc.gap_svc_handle, gap->gap_svc.appearance_char_handle, 0, 2, gap_appearence_char_uuid); if(status) { - FURI_LOG_E(GAP_TAG, "Failed updating appearence characteristic: %d", status); + FURI_LOG_E(TAG, "Failed updating appearence characteristic: %d", status); } // Set default PHY hci_le_set_default_phy(ALL_PHYS_PREFERENCE, TX_2M_PREFERRED, RX_2M_PREFERRED); @@ -322,7 +322,7 @@ static void gap_advertise_start(GapState new_state) // Stop advertising status = aci_gap_set_non_discoverable(); if (status) { - FURI_LOG_E(GAP_TAG, "Stop Advertising Failed, result: %d", status); + FURI_LOG_E(TAG, "Stop Advertising Failed, result: %d", status); } } // Configure advertising @@ -331,7 +331,7 @@ static void gap_advertise_start(GapState new_state) strlen(name), (uint8_t*)name, gap->gap_svc.adv_svc_uuid_len, gap->gap_svc.adv_svc_uuid, 0, 0); if(status) { - FURI_LOG_E(GAP_TAG, "Set discoverable err: %d", status); + FURI_LOG_E(TAG, "Set discoverable err: %d", status); } gap->state = new_state; BleEvent event = {.type = BleEventTypeStartAdvertising}; @@ -355,14 +355,14 @@ static void gap_advertise_stop() { } void gap_start_advertising() { - FURI_LOG_I(GAP_TAG, "Start advertising"); + FURI_LOG_I(TAG, "Start advertising"); gap->enable_adv = true; GapCommand command = GapCommandAdvFast; furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK); } void gap_stop_advertising() { - FURI_LOG_I(GAP_TAG, "Stop advertising"); + FURI_LOG_I(TAG, "Stop advertising"); gap->enable_adv = false; GapCommand command = GapCommandAdvStop; furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK); diff --git a/firmware/targets/f7/ble-glue/serial_service.c b/firmware/targets/f7/ble-glue/serial_service.c index 43b07718..c7ea6db2 100644 --- a/firmware/targets/f7/ble-glue/serial_service.c +++ b/firmware/targets/f7/ble-glue/serial_service.c @@ -4,7 +4,7 @@ #include -#define SERIAL_SERVICE_TAG "serial service" +#define TAG "BtSerialSvc" typedef struct { uint16_t svc_handle; @@ -37,26 +37,26 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void *event) { if(attribute_modified->Attr_Handle == serial_svc->rx_char_handle + 2) { // Descriptor handle ret = SVCCTL_EvtAckFlowEnable; - FURI_LOG_D(SERIAL_SERVICE_TAG, "RX descriptor event"); + FURI_LOG_D(TAG, "RX descriptor event"); } else if(attribute_modified->Attr_Handle == serial_svc->rx_char_handle + 1) { - FURI_LOG_D(SERIAL_SERVICE_TAG, "Received %d bytes", attribute_modified->Attr_Data_Length); + FURI_LOG_D(TAG, "Received %d bytes", attribute_modified->Attr_Data_Length); if(serial_svc->on_received_cb) { furi_check(osMutexAcquire(serial_svc->buff_size_mtx, osWaitForever) == osOK); if(attribute_modified->Attr_Data_Length > serial_svc->bytes_ready_to_receive) { FURI_LOG_W( - SERIAL_SERVICE_TAG, "Received %d, while was ready to receive %d bytes. Can lead to buffer overflow!", + TAG, "Received %d, while was ready to receive %d bytes. Can lead to buffer overflow!", attribute_modified->Attr_Data_Length, serial_svc->bytes_ready_to_receive); } serial_svc->bytes_ready_to_receive -= MIN(serial_svc->bytes_ready_to_receive, attribute_modified->Attr_Data_Length); uint32_t buff_free_size = serial_svc->on_received_cb(attribute_modified->Attr_Data, attribute_modified->Attr_Data_Length, serial_svc->context); - FURI_LOG_D(SERIAL_SERVICE_TAG, "Available buff size: %d", buff_free_size); + FURI_LOG_D(TAG, "Available buff size: %d", buff_free_size); furi_check(osMutexRelease(serial_svc->buff_size_mtx) == osOK); } ret = SVCCTL_EvtAckFlowEnable; } } else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) { - FURI_LOG_D(SERIAL_SERVICE_TAG, "Ack received", blecore_evt->ecode); + FURI_LOG_D(TAG, "Ack received", blecore_evt->ecode); if(serial_svc->on_sent_cb) { serial_svc->on_sent_cb(serial_svc->context); } @@ -75,7 +75,7 @@ void serial_svc_start() { // Add service status = aci_gatt_add_service(UUID_TYPE_128, (Service_UUID_t *)service_uuid, PRIMARY_SERVICE, 10, &serial_svc->svc_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add Serial service: %d", status); + FURI_LOG_E(TAG, "Failed to add Serial service: %d", status); } // Add RX characteristics @@ -88,7 +88,7 @@ void serial_svc_start() { CHAR_VALUE_LEN_VARIABLE, &serial_svc->rx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add RX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add RX characteristic: %d", status); } // Add TX characteristic @@ -101,7 +101,7 @@ void serial_svc_start() { CHAR_VALUE_LEN_VARIABLE, &serial_svc->tx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add TX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add TX characteristic: %d", status); } // Add Flow Control characteristic status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)flow_ctrl_uuid, @@ -113,7 +113,7 @@ void serial_svc_start() { CHAR_VALUE_LEN_CONSTANT, &serial_svc->flow_ctrl_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to add Flow Control characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to add Flow Control characteristic: %d", status); } // Allocate buffer size mutex serial_svc->buff_size_mtx = osMutexNew(NULL); @@ -136,7 +136,7 @@ void serial_svc_notify_buffer_is_empty() { furi_check(osMutexAcquire(serial_svc->buff_size_mtx, osWaitForever) == osOK); if(serial_svc->bytes_ready_to_receive == 0) { - FURI_LOG_D(SERIAL_SERVICE_TAG, "Buffer is empty. Notifying client"); + FURI_LOG_D(TAG, "Buffer is empty. Notifying client"); serial_svc->bytes_ready_to_receive = serial_svc->buff_size; uint32_t buff_size_reversed = REVERSE_BYTES_U32(serial_svc->buff_size); aci_gatt_update_char_value(serial_svc->svc_handle, serial_svc->flow_ctrl_char_handle, 0, sizeof(uint32_t), (uint8_t*)&buff_size_reversed); @@ -150,20 +150,20 @@ void serial_svc_stop() { // Delete characteristics status = aci_gatt_del_char(serial_svc->svc_handle, serial_svc->tx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete TX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete TX characteristic: %d", status); } status = aci_gatt_del_char(serial_svc->svc_handle, serial_svc->rx_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete RX characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete RX characteristic: %d", status); } status = aci_gatt_del_char(serial_svc->svc_handle, serial_svc->flow_ctrl_char_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete Flow Control characteristic: %d", status); + FURI_LOG_E(TAG, "Failed to delete Flow Control characteristic: %d", status); } // Delete service status = aci_gatt_del_service(serial_svc->svc_handle); if(status) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed to delete Serial service: %d", status); + FURI_LOG_E(TAG, "Failed to delete Serial service: %d", status); } // Delete buffer size mutex osMutexDelete(serial_svc->buff_size_mtx); @@ -182,7 +182,7 @@ bool serial_svc_update_tx(uint8_t* data, uint8_t data_len) { data_len, data); if(result) { - FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed updating TX characteristic: %d", result); + FURI_LOG_E(TAG, "Failed updating TX characteristic: %d", result); } return result != BLE_STATUS_SUCCESS; } diff --git a/firmware/targets/f7/Src/fatfs/fatfs.c b/firmware/targets/f7/fatfs/fatfs.c similarity index 100% rename from firmware/targets/f7/Src/fatfs/fatfs.c rename to firmware/targets/f7/fatfs/fatfs.c diff --git a/firmware/targets/f7/Src/fatfs/fatfs.h b/firmware/targets/f7/fatfs/fatfs.h similarity index 100% rename from firmware/targets/f7/Src/fatfs/fatfs.h rename to firmware/targets/f7/fatfs/fatfs.h diff --git a/firmware/targets/f7/Src/fatfs/ffconf.h b/firmware/targets/f7/fatfs/ffconf.h similarity index 100% rename from firmware/targets/f7/Src/fatfs/ffconf.h rename to firmware/targets/f7/fatfs/ffconf.h diff --git a/firmware/targets/f7/Src/fatfs/spi_sd_hal.c b/firmware/targets/f7/fatfs/spi_sd_hal.c similarity index 100% rename from firmware/targets/f7/Src/fatfs/spi_sd_hal.c rename to firmware/targets/f7/fatfs/spi_sd_hal.c diff --git a/firmware/targets/f7/Src/fatfs/stm32_adafruit_sd.c b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c similarity index 100% rename from firmware/targets/f7/Src/fatfs/stm32_adafruit_sd.c rename to firmware/targets/f7/fatfs/stm32_adafruit_sd.c diff --git a/firmware/targets/f7/Src/fatfs/stm32_adafruit_sd.h b/firmware/targets/f7/fatfs/stm32_adafruit_sd.h similarity index 100% rename from firmware/targets/f7/Src/fatfs/stm32_adafruit_sd.h rename to firmware/targets/f7/fatfs/stm32_adafruit_sd.h diff --git a/firmware/targets/f7/Src/fatfs/syscall.c b/firmware/targets/f7/fatfs/syscall.c similarity index 100% rename from firmware/targets/f7/Src/fatfs/syscall.c rename to firmware/targets/f7/fatfs/syscall.c diff --git a/firmware/targets/f7/Src/fatfs/user_diskio.c b/firmware/targets/f7/fatfs/user_diskio.c similarity index 100% rename from firmware/targets/f7/Src/fatfs/user_diskio.c rename to firmware/targets/f7/fatfs/user_diskio.c diff --git a/firmware/targets/f7/Src/fatfs/user_diskio.h b/firmware/targets/f7/fatfs/user_diskio.h similarity index 100% rename from firmware/targets/f7/Src/fatfs/user_diskio.h rename to firmware/targets/f7/fatfs/user_diskio.h diff --git a/firmware/targets/f7/furi-hal/furi-hal-bootloader.c b/firmware/targets/f7/furi-hal/furi-hal-bootloader.c index 2962877e..e8ea913e 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-bootloader.c +++ b/firmware/targets/f7/furi-hal/furi-hal-bootloader.c @@ -2,6 +2,8 @@ #include #include +#define TAG "FuriHalBoot" + // Boot request enum #define BOOT_REQUEST_TAINTED 0x00000000 #define BOOT_REQUEST_CLEAN 0xDADEDADE @@ -11,7 +13,7 @@ void furi_hal_bootloader_init() { #ifndef DEBUG LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED); #endif - FURI_LOG_I("FuriHalBoot", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-clock.c b/firmware/targets/f7/furi-hal/furi-hal-clock.c index fd4899d4..7a124049 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-clock.c +++ b/firmware/targets/f7/furi-hal/furi-hal-clock.c @@ -5,6 +5,8 @@ #include #include +#define TAG "FuriHalClock" + #define HS_CLOCK_IS_READY() (LL_RCC_HSE_IsReady() && LL_RCC_HSI_IsReady()) #define LS_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) @@ -123,7 +125,7 @@ void furi_hal_clock_init() { // APB2 LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - FURI_LOG_I("FuriHalClock", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_clock_switch_to_hsi() { diff --git a/firmware/targets/f7/furi-hal/furi-hal-compress.c b/firmware/targets/f7/furi-hal/furi-hal-compress.c index 9b7678f5..eb6e9d51 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-compress.c +++ b/firmware/targets/f7/furi-hal/furi-hal-compress.c @@ -4,6 +4,8 @@ #include #include +#define TAG "FuriHalCompress" + #define FURI_HAL_COMPRESS_ICON_ENCODED_BUFF_SIZE (512) #define FURI_HAL_COMPRESS_ICON_DECODED_BUFF_SIZE (1024) @@ -46,7 +48,7 @@ void furi_hal_compress_icon_init() { FURI_HAL_COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG); heatshrink_decoder_reset(icon_decoder->decoder); memset(icon_decoder->decoded_buff, 0, sizeof(icon_decoder->decoded_buff)); - FURI_LOG_I("FuriHalCompress", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_compress_icon_decode(const uint8_t* icon_data, uint8_t** decoded_buff) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-console.c b/firmware/targets/f7/furi-hal/furi-hal-console.c index ffe340b9..993b498e 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-console.c +++ b/firmware/targets/f7/furi-hal/furi-hal-console.c @@ -6,8 +6,12 @@ #include #include +#include + #include +#define TAG "FuriHalConsole" + #define CONSOLE_BAUDRATE 230400 volatile bool furi_hal_console_alive = false; @@ -16,7 +20,7 @@ void furi_hal_console_init() { furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE); furi_hal_console_alive = true; - FURI_LOG_I("FuriHalConsole", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_console_enable() { @@ -35,22 +39,26 @@ void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) { if (!furi_hal_console_alive) return; + UTILS_ENTER_CRITICAL_SECTION(); // Transmit data furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size); // Wait for TC flag to be raised for last char while (!LL_USART_IsActiveFlag_TC(USART1)); + UTILS_EXIT_CRITICAL_SECTION(); } void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) { if (!furi_hal_console_alive) return; + UTILS_ENTER_CRITICAL_SECTION(); // Transmit data furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size); // Transmit new line symbols furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)"\r\n", 2); // Wait for TC flag to be raised for last char while (!LL_USART_IsActiveFlag_TC(USART1)); + UTILS_EXIT_CRITICAL_SECTION(); } void furi_hal_console_printf(const char format[], ...) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-crypto.c b/firmware/targets/f7/furi-hal/furi-hal-crypto.c index 648f3f18..91875d23 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-crypto.c +++ b/firmware/targets/f7/furi-hal/furi-hal-crypto.c @@ -3,10 +3,12 @@ #include #include +#define TAG "FuriHalCrypto" + CRYP_HandleTypeDef crypt; void furi_hal_crypto_init() { - FURI_LOG_I("FuriHalCrypto", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-delay.c b/firmware/targets/f7/furi-hal/furi-hal-delay.c index 52de8715..b5f3c334 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-delay.c +++ b/firmware/targets/f7/furi-hal/furi-hal-delay.c @@ -3,6 +3,8 @@ #include #include +#define TAG "FuriHalDelay" + static uint32_t clk_per_microsecond; void furi_hal_delay_init(void) { @@ -10,7 +12,7 @@ void furi_hal_delay_init(void) { DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; DWT->CYCCNT = 0U; clk_per_microsecond = SystemCoreClock / 1000000.0f; - FURI_LOG_I("FuriHalDelay", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void delay_us(float microseconds) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-i2c.c b/firmware/targets/f7/furi-hal/furi-hal-i2c.c index 196a2a7b..b1ec4711 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-i2c.c +++ b/firmware/targets/f7/furi-hal/furi-hal-i2c.c @@ -6,6 +6,8 @@ #include #include +#define TAG "FuriHalI2C" + osMutexId_t furi_hal_i2c_mutex = NULL; void furi_hal_i2c_init() { @@ -42,7 +44,7 @@ void furi_hal_i2c_init() { LL_I2C_DisableOwnAddress2(POWER_I2C); LL_I2C_DisableGeneralCall(POWER_I2C); LL_I2C_EnableClockStretching(POWER_I2C); - FURI_LOG_I("FuriHalI2C", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } bool furi_hal_i2c_tx( diff --git a/firmware/targets/f7/furi-hal/furi-hal-interrupt.c b/firmware/targets/f7/furi-hal/furi-hal-interrupt.c index 47e99c9f..2685edab 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-interrupt.c +++ b/firmware/targets/f7/furi-hal/furi-hal-interrupt.c @@ -4,6 +4,8 @@ #include #include +#define TAG "FuriHalInterrupt" + volatile FuriHalInterruptISR furi_hal_tim_tim2_isr = NULL; volatile FuriHalInterruptISR furi_hal_tim_tim1_isr = NULL; @@ -22,7 +24,7 @@ void furi_hal_interrupt_init() { NVIC_SetPriority(DMA1_Channel1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0)); NVIC_EnableIRQ(DMA1_Channel1_IRQn); - FURI_LOG_I("FuriHalInterrupt", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR isr) { @@ -161,10 +163,10 @@ void TAMP_STAMP_LSECSS_IRQHandler(void) { if (LL_RCC_IsActiveFlag_LSECSS()) { LL_RCC_ClearFlag_LSECSS(); if (!LL_RCC_LSE_IsReady()) { - FURI_LOG_E("FuriHalInterrupt", "LSE CSS fired: resetting system"); + FURI_LOG_E(TAG, "LSE CSS fired: resetting system"); NVIC_SystemReset(); } else { - FURI_LOG_E("FuriHalInterrupt", "LSE CSS fired: but LSE is alive"); + FURI_LOG_E(TAG, "LSE CSS fired: but LSE is alive"); } } } @@ -176,7 +178,7 @@ void RCC_IRQHandler(void) { void NMI_Handler(void) { if (LL_RCC_IsActiveFlag_HSECSS()) { LL_RCC_ClearFlag_HSECSS(); - FURI_LOG_E("FuriHalInterrupt", "HSE CSS fired: resetting system"); + FURI_LOG_E(TAG, "HSE CSS fired: resetting system"); NVIC_SystemReset(); } } diff --git a/firmware/targets/f7/furi-hal/furi-hal-light.c b/firmware/targets/f7/furi-hal/furi-hal-light.c index fba1bec4..ecf0d4f2 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-light.c +++ b/firmware/targets/f7/furi-hal/furi-hal-light.c @@ -1,6 +1,8 @@ #include #include +#define TAG "FuriHalLight" + #define LED_CURRENT_RED 50 #define LED_CURRENT_GREEN 50 #define LED_CURRENT_BLUE 50 @@ -21,7 +23,7 @@ void furi_hal_light_init() { lp5562_enable(); lp5562_configure(); - FURI_LOG_I("FuriHalLight", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_light_set(Light light, uint8_t value) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-nfc.c b/firmware/targets/f7/furi-hal/furi-hal-nfc.c index d92e2cad..4bca12a9 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-nfc.c +++ b/firmware/targets/f7/furi-hal/furi-hal-nfc.c @@ -1,15 +1,17 @@ #include "furi-hal-nfc.h" #include +#define TAG "FuriHalNfc" + static const uint32_t clocks_in_ms = 64 * 1000; void furi_hal_nfc_init() { ReturnCode ret = rfalNfcInitialize(); if(ret == ERR_NONE) { furi_hal_nfc_start_sleep(); - FURI_LOG_I("FuriHalNfc", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } else { - FURI_LOG_W("FuriHalNfc", "Initialization failed, RFAL returned: %d", ret); + FURI_LOG_W(TAG, "Initialization failed, RFAL returned: %d", ret); } } @@ -63,7 +65,7 @@ bool furi_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t ti while(state != RFAL_NFC_STATE_ACTIVATED) { rfalNfcWorker(); state = rfalNfcGetState(); - FURI_LOG_D("HAL NFC", "Current state %d", state); + FURI_LOG_D(TAG, "Current state %d", state); if(state == RFAL_NFC_STATE_POLL_ACTIVATION) { start = DWT->CYCCNT; continue; @@ -73,7 +75,7 @@ bool furi_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t ti } if(DWT->CYCCNT - start > timeout * clocks_in_ms) { rfalNfcDeactivate(true); - FURI_LOG_D("HAL NFC", "Timeout"); + FURI_LOG_D(TAG, "Timeout"); return false; } osThreadYield(); diff --git a/firmware/targets/f7/furi-hal/furi-hal-os.c b/firmware/targets/f7/furi-hal/furi-hal-os.c index eb1811b6..aac1b10e 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-os.c +++ b/firmware/targets/f7/furi-hal/furi-hal-os.c @@ -5,6 +5,8 @@ #include +#define TAG "FuriHalOs" + #define FURI_HAL_OS_CLK_FREQUENCY 32768 #define FURI_HAL_OS_TICK_PER_SECOND 1024 #define FURI_HAL_OS_CLK_PER_TICK (FURI_HAL_OS_CLK_FREQUENCY / FURI_HAL_OS_TICK_PER_SECOND) @@ -44,7 +46,7 @@ void furi_hal_os_init() { osTimerStart(second_timer, 1024); #endif - FURI_LOG_I("FuriHalOs", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void LPTIM2_IRQHandler(void) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-power.c b/firmware/targets/f7/furi-hal/furi-hal-power.c index 47ce5f4d..870cbda6 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-power.c +++ b/firmware/targets/f7/furi-hal/furi-hal-power.c @@ -15,6 +15,8 @@ #include +#define TAG "FuriHalPower" + typedef struct { volatile uint8_t insomnia; volatile uint8_t deep_insomnia; @@ -74,7 +76,7 @@ void furi_hal_power_init() { LL_PWR_SMPS_SetMode(LL_PWR_SMPS_STEP_DOWN); bq27220_init(&cedv); bq25896_init(); - FURI_LOG_I("FuriHalPower", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } uint16_t furi_hal_power_insomnia_level() { diff --git a/firmware/targets/f7/furi-hal/furi-hal-rfid.c b/firmware/targets/f7/furi-hal/furi-hal-rfid.c index 59d24333..02a82bd1 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-rfid.c +++ b/firmware/targets/f7/furi-hal/furi-hal-rfid.c @@ -109,7 +109,7 @@ void furi_hal_rfid_tim_read(float freq, float duty_cycle) { sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; - if(HAL_TIM_OC_ConfigChannel(&LFRFID_READ_TIM, &sConfigOC, LFRFID_READ_CHANNEL) != HAL_OK) { + if(HAL_TIM_PWM_ConfigChannel(&LFRFID_READ_TIM, &sConfigOC, LFRFID_READ_CHANNEL) != HAL_OK) { Error_Handler(); } @@ -147,7 +147,6 @@ void furi_hal_rfid_tim_emulate(float freq) { TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; // basic PWM setup with needed freq and internal clock LFRFID_EMULATE_TIM.Init.Prescaler = 0; @@ -191,24 +190,6 @@ void furi_hal_rfid_tim_emulate(float freq) { HAL_OK) { Error_Handler(); } - - // no deadtime - sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; - sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; - sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; - sBreakDeadTimeConfig.DeadTime = 0; - sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; - sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; - sBreakDeadTimeConfig.BreakFilter = 0; - sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE; - sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH; - sBreakDeadTimeConfig.Break2Filter = 0; - sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; - if(HAL_TIMEx_ConfigBreakDeadTime(&LFRFID_EMULATE_TIM, &sBreakDeadTimeConfig) != HAL_OK) { - Error_Handler(); - } } void furi_hal_rfid_tim_emulate_start() { diff --git a/firmware/targets/f7/furi-hal/furi-hal-spi.c b/firmware/targets/f7/furi-hal/furi-hal-spi.c index 805b8dfb..da7c63df 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-spi.c +++ b/firmware/targets/f7/furi-hal/furi-hal-spi.c @@ -9,6 +9,8 @@ #include #include +#define TAG "FuriHalSpi" + void furi_hal_spi_init() { // Spi structure is const, but mutex is not // Need some hell-ish casting to make it work @@ -33,7 +35,7 @@ void furi_hal_spi_init() { hal_gpio_init_ex(&gpio_spi_d_mosi, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedVeryHigh, GpioAltFn5SPI2); hal_gpio_init_ex(&gpio_spi_d_sck, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedVeryHigh, GpioAltFn5SPI2); - FURI_LOG_I("FuriHalSpi", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_spi_bus_lock(const FuriHalSpiBus* bus) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-subghz.c b/firmware/targets/f7/furi-hal/furi-hal-subghz.c index cd610cb2..276482ee 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-subghz.c +++ b/firmware/targets/f7/furi-hal/furi-hal-subghz.c @@ -10,6 +10,8 @@ #include #include +#define TAG "FuriHalSubGhz" + static volatile SubGhzState furi_hal_subghz_state = SubGhzStateInit; static volatile SubGhzRegulation furi_hal_subghz_regulation = SubGhzRegulationTxRx; @@ -303,7 +305,7 @@ void furi_hal_subghz_init() { cc1101_shutdown(device); furi_hal_spi_device_return(device); - FURI_LOG_I("FuriHalSubGhz", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_subghz_sleep() { diff --git a/firmware/targets/f7/furi-hal/furi-hal-usb.c b/firmware/targets/f7/furi-hal/furi-hal-usb.c index 8c78eb8b..45a6177e 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-usb.c +++ b/firmware/targets/f7/furi-hal/furi-hal-usb.c @@ -5,6 +5,8 @@ #include "usb.h" +#define TAG "FuriHalUsb" + #define USB_RECONNECT_DELAY 500 extern struct UsbInterface usb_cdc_single; @@ -64,7 +66,7 @@ void furi_hal_usb_init(void) { HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0); NVIC_EnableIRQ(USB_LP_IRQn); - FURI_LOG_I("FuriHalUsb", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } void furi_hal_usb_set_config(UsbMode new_mode) { @@ -81,7 +83,7 @@ void furi_hal_usb_set_config(UsbMode new_mode) { usb_if_modes[usb_config.mode_cur]->deinit(&udev); if (usb_if_modes[new_mode] != NULL) { usb_if_modes[new_mode]->init(&udev, usb_if_modes[new_mode]); - FURI_LOG_I("FuriHalUsb", "USB mode change %u -> %u", usb_config.mode_cur, new_mode); + FURI_LOG_I(TAG, "USB mode change %u -> %u", usb_config.mode_cur, new_mode); usb_config.enabled = true; usb_config.mode_cur = new_mode; } @@ -98,7 +100,7 @@ void furi_hal_usb_disable() { susp_evt(&udev, 0, 0); usbd_connect(&udev, false); usb_config.enabled = false; - FURI_LOG_I("FuriHalUsb", "USB Disable"); + FURI_LOG_I(TAG, "USB Disable"); } } @@ -106,7 +108,7 @@ void furi_hal_usb_enable() { if ((!usb_config.enabled) && (usb_if_modes[usb_config.mode_cur] != NULL)) { usbd_connect(&udev, true); usb_config.enabled = true; - FURI_LOG_I("FuriHalUsb", "USB Enable"); + FURI_LOG_I(TAG, "USB Enable"); } } diff --git a/firmware/targets/f7/furi-hal/furi-hal-vcp.c b/firmware/targets/f7/furi-hal/furi-hal-vcp.c index 93da91d8..039481f1 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-vcp.c +++ b/firmware/targets/f7/furi-hal/furi-hal-vcp.c @@ -1,8 +1,10 @@ #include - +#include #include #include +#define TAG "FuriHalVcp" + #define USB_CDC_PKT_LEN CDC_DATA_SZ #define VCP_RX_BUF_SIZE (USB_CDC_PKT_LEN * 3) #define VCP_TX_BUF_SIZE (USB_CDC_PKT_LEN * 3) @@ -17,11 +19,11 @@ typedef enum { VcpEvtDisable = (1 << 4), VcpEvtRx = (1 << 5), VcpEvtTx = (1 << 6), - VcpEvtRxDone = (1 << 7), - VcpEvtTxDone = (1 << 8), + VcpEvtStreamRx = (1 << 7), + VcpEvtStreamTx = (1 << 8), } WorkerEvtFlags; -#define VCP_THREAD_FLAG_ALL (VcpEvtConnect | VcpEvtDisconnect | VcpEvtEnable | VcpEvtDisable | VcpEvtRx | VcpEvtTx | VcpEvtRxDone | VcpEvtTxDone) +#define VCP_THREAD_FLAG_ALL (VcpEvtConnect | VcpEvtDisconnect | VcpEvtEnable | VcpEvtDisable | VcpEvtRx | VcpEvtTx | VcpEvtStreamRx | VcpEvtStreamTx) typedef struct { FuriThread* thread; @@ -62,61 +64,69 @@ void furi_hal_vcp_init() { vcp->thread = furi_thread_alloc(); furi_thread_set_name(vcp->thread, "VcpWorker"); - furi_thread_set_stack_size(vcp->thread, 512); + furi_thread_set_stack_size(vcp->thread, 1024); furi_thread_set_callback(vcp->thread, vcp_worker); furi_thread_start(vcp->thread); - FURI_LOG_I("FuriHalVcp", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } static int32_t vcp_worker(void* context) { bool enabled = true; bool tx_idle = false; - bool rx_pending = false; + size_t missed_rx = 0; furi_hal_cdc_set_callbacks(VCP_IF_NUM, &cdc_cb); - + while (1) { uint32_t flags = osThreadFlagsWait(VCP_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever); furi_assert((flags & osFlagsError) == 0); // New data received - if((flags & VcpEvtRxDone) && enabled) { + if((flags & VcpEvtStreamRx) && enabled && missed_rx > 0) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP StreamRx\r\n"); +#endif if (xStreamBufferSpacesAvailable(vcp->rx_stream) >= USB_CDC_PKT_LEN) { - size_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); - if (len > 0) - xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever); - else - rx_pending = false; - } else - rx_pending = true; // Buffer is full, retry later + flags |= VcpEvtRx; + missed_rx--; + } } // Rx buffer was read, maybe there is enough space for new data? - if((flags & VcpEvtRx) && rx_pending) { + if((flags & VcpEvtRx)) { if (xStreamBufferSpacesAvailable(vcp->rx_stream) >= USB_CDC_PKT_LEN) { - size_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); - if (len > 0) - xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever); - else - rx_pending = false; + int32_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_printf("VCP Rx %d\r\n", len); +#endif + if (len > 0) { + furi_check(xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever) == len); + } + } else { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Rx missed\r\n"); +#endif + missed_rx++; } } // New data in Tx buffer - if((flags & VcpEvtTx) && enabled) { + if((flags & VcpEvtStreamTx) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP StreamTx\r\n"); +#endif if (tx_idle) { - size_t len = xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0); - if (len > 0) { - tx_idle = false; - furi_hal_cdc_send(VCP_IF_NUM, vcp->data_buffer, len); - } + flags |= VcpEvtTx; } } // CDC write transfer done - if((flags & VcpEvtTxDone) && enabled) { + if((flags & VcpEvtTx) && enabled) { size_t len = xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0); +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_printf("VCP Tx %d\r\n", len); +#endif if (len > 0) { // Some data left in Tx buffer. Sending it now tx_idle = false; furi_hal_cdc_send(VCP_IF_NUM, vcp->data_buffer, len); @@ -127,6 +137,9 @@ static int32_t vcp_worker(void* context) { // VCP session opened if((flags & VcpEvtConnect) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Connect\r\n"); +#endif if (vcp->connected == false) { vcp->connected = true; xStreamBufferSend(vcp->rx_stream, &ascii_soh, 1, osWaitForever); @@ -135,6 +148,9 @@ static int32_t vcp_worker(void* context) { // VCP session closed if((flags & VcpEvtDisconnect) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Disconnect\r\n"); +#endif if (vcp->connected == true) { vcp->connected = false; xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever); @@ -143,6 +159,9 @@ static int32_t vcp_worker(void* context) { // VCP enabled if((flags & VcpEvtEnable) && !enabled){ +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Enable\r\n"); +#endif furi_hal_cdc_set_callbacks(VCP_IF_NUM, &cdc_cb); enabled = true; furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); // flush Rx buffer @@ -154,6 +173,9 @@ static int32_t vcp_worker(void* context) { // VCP disabled if((flags & VcpEvtDisable) && enabled) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP Disable\r\n"); +#endif enabled = false; vcp->connected = false; xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever); @@ -182,9 +204,9 @@ size_t furi_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeo batch_size = VCP_RX_BUF_SIZE; size_t len = xStreamBufferReceive(vcp->rx_stream, buffer, batch_size, timeout); - osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRx); if (len == 0) break; + osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamRx); size -= len; buffer += len; rx_cnt += len; @@ -207,7 +229,7 @@ void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) { batch_size = VCP_TX_BUF_SIZE; xStreamBufferSend(vcp->tx_stream, buffer, batch_size, osWaitForever); - osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTx); + osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamTx); size -= batch_size; buffer += batch_size; @@ -215,6 +237,9 @@ void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) { } static void vcp_state_callback(uint8_t state) { +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP State\r\n"); +#endif if (state == 0) { osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtDisconnect); } @@ -223,7 +248,9 @@ static void vcp_state_callback(uint8_t state) { static void vcp_on_cdc_control_line(uint8_t state) { // bit 0: DTR state, bit 1: RTS state bool dtr = state & (1 << 0); - +#ifdef FURI_HAL_USB_VCP_DEBUG + furi_hal_console_puts("VCP CtrlLine\r\n"); +#endif if (dtr == true) { osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtConnect); } else { @@ -232,12 +259,12 @@ static void vcp_on_cdc_control_line(uint8_t state) { } static void vcp_on_cdc_rx() { - uint32_t ret = osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRxDone); + uint32_t ret = osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRx); furi_assert((ret & osFlagsError) == 0); } static void vcp_on_cdc_tx_complete() { - osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTxDone); + osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTx); } bool furi_hal_vcp_is_connected(void) { diff --git a/firmware/targets/f7/furi-hal/furi-hal-version.c b/firmware/targets/f7/furi-hal/furi-hal-version.c index e4adebc0..f38e6cdc 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-version.c +++ b/firmware/targets/f7/furi-hal/furi-hal-version.c @@ -7,6 +7,8 @@ #include #include "ble.h" +#define TAG "FuriHalVersion" + #define FURI_HAL_VERSION_OTP_HEADER_MAGIC 0xBABE #define FURI_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE @@ -191,7 +193,7 @@ void furi_hal_version_init() { break; default: furi_crash(NULL); } - FURI_LOG_I("FuriHalVersion", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } bool furi_hal_version_do_i_belong_here() { diff --git a/firmware/targets/f7/furi-hal/furi-hal-vibro.c b/firmware/targets/f7/furi-hal/furi-hal-vibro.c index 7dfddd42..7de8ad84 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-vibro.c +++ b/firmware/targets/f7/furi-hal/furi-hal-vibro.c @@ -1,10 +1,12 @@ #include #include +#define TAG "FuriHalVibro" + void furi_hal_vibro_init() { hal_gpio_init(&vibro_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); hal_gpio_write(&vibro_gpio, false); - FURI_LOG_I("FuriHalVibro", "Init OK"); + FURI_LOG_I(TAG, "Init OK"); } diff --git a/firmware/targets/f7/furi-hal/furi-hal.c b/firmware/targets/f7/furi-hal/furi-hal.c index f332d187..d435c5f2 100644 --- a/firmware/targets/f7/furi-hal/furi-hal.c +++ b/firmware/targets/f7/furi-hal/furi-hal.c @@ -7,6 +7,10 @@ #include +#include + +#define TAG "FuriHal" + void furi_hal_init() { furi_hal_clock_init(); furi_hal_console_init(); @@ -14,23 +18,23 @@ void furi_hal_init() { furi_hal_delay_init(); MX_GPIO_Init(); - FURI_LOG_I("HAL", "GPIO OK"); + FURI_LOG_I(TAG, "GPIO OK"); MX_RTC_Init(); - FURI_LOG_I("HAL", "RTC OK"); + FURI_LOG_I(TAG, "RTC OK"); furi_hal_bootloader_init(); furi_hal_version_init(); furi_hal_spi_init(); MX_TIM1_Init(); - FURI_LOG_I("HAL", "TIM1 OK"); + FURI_LOG_I(TAG, "TIM1 OK"); MX_TIM2_Init(); - FURI_LOG_I("HAL", "TIM2 OK"); + FURI_LOG_I(TAG, "TIM2 OK"); MX_TIM16_Init(); - FURI_LOG_I("HAL", "TIM16 OK"); + FURI_LOG_I(TAG, "TIM16 OK"); MX_COMP1_Init(); - FURI_LOG_I("HAL", "COMP1 OK"); + FURI_LOG_I(TAG, "COMP1 OK"); furi_hal_crypto_init(); @@ -38,7 +42,7 @@ void furi_hal_init() { furi_hal_usb_init(); furi_hal_usb_set_config(UsbModeVcpSingle); furi_hal_vcp_init(); - FURI_LOG_I("HAL", "USB OK"); + FURI_LOG_I(TAG, "USB OK"); furi_hal_i2c_init(); @@ -55,6 +59,10 @@ void furi_hal_init() { // FreeRTOS glue furi_hal_os_init(); + // FatFS driver initialization + MX_FATFS_Init(); + FURI_LOG_I(TAG, "FATFS OK"); + // Partial null pointer dereference protection LL_MPU_Disable(); LL_MPU_ConfigRegion( diff --git a/firmware/targets/f7/target.mk b/firmware/targets/f7/target.mk index 761621d7..d6b8cbfa 100644 --- a/firmware/targets/f7/target.mk +++ b/firmware/targets/f7/target.mk @@ -128,6 +128,11 @@ ifeq ($(FURI_HAL_OS_DEBUG), 1) CFLAGS += -DFURI_HAL_OS_DEBUG endif +FURI_HAL_USB_VCP_DEBUG ?= 0 +ifeq ($(FURI_HAL_USB_VCP_DEBUG), 1) +CFLAGS += -DFURI_HAL_USB_VCP_DEBUG +endif + FURI_HAL_SUBGHZ_TX_GPIO ?= 0 ifneq ($(FURI_HAL_SUBGHZ_TX_GPIO), 0) CFLAGS += -DFURI_HAL_SUBGHZ_TX_GPIO=$(FURI_HAL_SUBGHZ_TX_GPIO) @@ -144,10 +149,10 @@ C_SOURCES += $(wildcard $(FURI_HAL_DIR)/*.c) # Other CFLAGS += \ -I$(MXPROJECT_DIR)/Inc \ - -I$(MXPROJECT_DIR)/Src/fatfs + -I$(MXPROJECT_DIR)/fatfs C_SOURCES += \ $(wildcard $(MXPROJECT_DIR)/Src/*.c) \ - $(wildcard $(MXPROJECT_DIR)/Src/fatfs/*.c) + $(wildcard $(MXPROJECT_DIR)/fatfs/*.c) # Linker options ifeq ($(NO_BOOTLOADER), 1) diff --git a/lib/drivers/bq27220.c b/lib/drivers/bq27220.c index d83cae05..578e3849 100644 --- a/lib/drivers/bq27220.c +++ b/lib/drivers/bq27220.c @@ -5,6 +5,8 @@ #include #include +#define TAG "Gauge" + uint16_t bq27220_read_word(uint8_t address) { uint8_t buffer[2] = {address}; uint16_t ret; @@ -70,13 +72,13 @@ bool bq27220_init(const ParamCEDV* cedv) { uint32_t timeout = 100; uint16_t design_cap = bq27220_get_design_capacity(); if(cedv->design_cap == design_cap) { - FURI_LOG_I("gauge", "Skip battery profile update"); + FURI_LOG_I(TAG, "Skip battery profile update"); return true; } - FURI_LOG_I("gauge", "Start updating battery profile"); + FURI_LOG_I(TAG, "Start updating battery profile"); OperationStatus status = {}; if(!bq27220_control(Control_ENTER_CFG_UPDATE)) { - FURI_LOG_E("gauge", "Can't configure update"); + FURI_LOG_E(TAG, "Can't configure update"); return false; }; @@ -111,10 +113,10 @@ bool bq27220_init(const ParamCEDV* cedv) { delay_us(10000); design_cap = bq27220_get_design_capacity(); if(cedv->design_cap == design_cap) { - FURI_LOG_I("gauge", "Battery profile update success"); + FURI_LOG_I(TAG, "Battery profile update success"); return true; } else { - FURI_LOG_E("gauge", "Battery profile update failed"); + FURI_LOG_E(TAG, "Battery profile update failed"); return false; } } diff --git a/lib/subghz/protocols/subghz_protocol_came_atomo.c b/lib/subghz/protocols/subghz_protocol_came_atomo.c index d28aae56..fbf9ca38 100644 --- a/lib/subghz/protocols/subghz_protocol_came_atomo.c +++ b/lib/subghz/protocols/subghz_protocol_came_atomo.c @@ -3,6 +3,8 @@ #include #include "../subghz_keystore.h" +#define TAG "SubGhzCameAtomo" + #define SUBGHZ_NO_CAME_ATOMO_RAINBOW_TABLE 0xFFFFFFFFFFFFFFFF struct SubGhzProtocolCameAtomo { @@ -39,7 +41,7 @@ void subghz_protocol_came_atomo_free(SubGhzProtocolCameAtomo* instance) { void subghz_protocol_came_atomo_name_file(SubGhzProtocolCameAtomo* instance, const char* name) { instance->rainbow_table_file_name = name; - printf("Loading CAME Atomo rainbow table %s\r\n", name); + FURI_LOG_I(TAG, "Loading rainbow table from %s", name); } /** Read bytes from rainbow table diff --git a/lib/subghz/protocols/subghz_protocol_common.c b/lib/subghz/protocols/subghz_protocol_common.c index be74fb2a..95ca876f 100644 --- a/lib/subghz/protocols/subghz_protocol_common.c +++ b/lib/subghz/protocols/subghz_protocol_common.c @@ -175,12 +175,12 @@ bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, Flipper bool res = false; do { if(!flipper_file_write_string_cstr(flipper_file, "Protocol", instance->name)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Protocol"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Protocol"); break; } if(!flipper_file_write_uint32( flipper_file, "Bit", (uint32_t*)&instance->code_last_count_bit, 1)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Bit"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Bit"); break; } @@ -190,7 +190,7 @@ bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, Flipper } if(!flipper_file_write_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Key"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Key"); break; } res = true; @@ -211,14 +211,14 @@ bool subghz_protocol_common_to_load_protocol_from_file( do { if(!flipper_file_read_uint32(flipper_file, "Bit", (uint32_t*)&temp_data, 1)) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Bit"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Bit"); break; } instance->code_last_count_bit = (uint8_t)temp_data; uint8_t key_data[sizeof(uint64_t)] = {0}; if(!flipper_file_read_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) { - FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Key"); + FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Key"); break; } for(uint8_t i = 0; i < sizeof(uint64_t); i++) { diff --git a/lib/subghz/protocols/subghz_protocol_common.h b/lib/subghz/protocols/subghz_protocol_common.h index 0795c9e6..6064f895 100644 --- a/lib/subghz/protocols/subghz_protocol_common.h +++ b/lib/subghz/protocols/subghz_protocol_common.h @@ -21,11 +21,10 @@ #define SUBGHZ_APP_EXTENSION ".sub" #define SUBGHZ_ENCODER_UPLOAD_MAX_SIZE 2048 -#define SUBGHZ_KEY_TAG "SubGhzParser" +#define SUBGHZ_PARSER_TAG "SubGhzParser" #define SUBGHZ_KEY_FILE_VERSION 1 #define SUBGHZ_KEY_FILE_TYPE "Flipper SubGhz Key File" -#define SUBGHZ_RAW_TAG "SubGhzRAW" #define SUBGHZ_RAW_FILE_VERSION 1 #define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File" diff --git a/lib/subghz/protocols/subghz_protocol_nice_flor_s.c b/lib/subghz/protocols/subghz_protocol_nice_flor_s.c index dd288a01..b1b8e4ac 100644 --- a/lib/subghz/protocols/subghz_protocol_nice_flor_s.c +++ b/lib/subghz/protocols/subghz_protocol_nice_flor_s.c @@ -9,6 +9,8 @@ * https://vrtp.ru/index.php?showtopic=27867 */ +#define TAG "SubGhzNiceFlorS" + struct SubGhzProtocolNiceFlorS { SubGhzProtocolCommon common; const char* rainbow_table_file_name; @@ -45,7 +47,7 @@ void subghz_protocol_nice_flor_s_free(SubGhzProtocolNiceFlorS* instance) { void subghz_protocol_nice_flor_s_name_file(SubGhzProtocolNiceFlorS* instance, const char* name) { instance->rainbow_table_file_name = name; - printf("Loading Nice FloR S rainbow table %s\r\n", name); + FURI_LOG_I(TAG, "Loading rainbow table from %s", name); } /** Send bit diff --git a/lib/subghz/protocols/subghz_protocol_princeton.c b/lib/subghz/protocols/subghz_protocol_princeton.c index a9b78795..238770e7 100644 --- a/lib/subghz/protocols/subghz_protocol_princeton.c +++ b/lib/subghz/protocols/subghz_protocol_princeton.c @@ -11,6 +11,8 @@ #define SUBGHZ_PT_COUNT_KEY 5 #define SUBGHZ_PT_TIMEOUT 320 +#define TAG "SubghzPrinceton" + struct SubGhzEncoderPrinceton { uint32_t key; uint16_t te; @@ -67,7 +69,7 @@ void subghz_encoder_princeton_print_log(void* context) { float duty_cycle = ((float)instance->time_high / (instance->time_high + instance->time_low)) * 100; FURI_LOG_I( - "EncoderPrinceton", + TAG "Encoder", "Radio ON=%dus, OFF=%dus, DutyCycle=%d,%d%%", instance->time_high, instance->time_low, @@ -297,7 +299,7 @@ bool subghz_decoder_princeton_to_save_file( bool res = subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); if(res) { res = flipper_file_write_uint32(flipper_file, "TE", (uint32_t*)&instance->te, 1); - if(!res) FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Te"); + if(!res) FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Te"); } return res; } @@ -310,7 +312,7 @@ bool subghz_decoder_princeton_to_load_protocol_from_file( (SubGhzProtocolCommon*)instance, flipper_file); if(loaded) { loaded = flipper_file_read_uint32(flipper_file, "TE", (uint32_t*)&instance->te, 1); - if(!loaded) FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing TE"); + if(!loaded) FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing TE"); } return loaded; } diff --git a/lib/subghz/protocols/subghz_protocol_raw.c b/lib/subghz/protocols/subghz_protocol_raw.c index f8d9be49..49ce87ed 100644 --- a/lib/subghz/protocols/subghz_protocol_raw.c +++ b/lib/subghz/protocols/subghz_protocol_raw.c @@ -1,6 +1,8 @@ #include "subghz_protocol_raw.h" #include "../subghz_file_encoder_worker.h" +#define TAG "SubGhzRaw" + #define SUBGHZ_DOWNLOAD_MAX_SIZE 512 struct SubGhzProtocolRAW { @@ -165,28 +167,28 @@ bool subghz_protocol_raw_save_to_file_init( // Open file if(!flipper_file_open_always(instance->flipper_file, string_get_cstr(dev_file_name))) { - FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to open file for write: %s", dev_file_name); + FURI_LOG_E(TAG, "Unable to open file for write: %s", dev_file_name); break; } if(!flipper_file_write_header_cstr( instance->flipper_file, SUBGHZ_RAW_FILE_TYPE, SUBGHZ_RAW_FILE_VERSION)) { - FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add header"); + FURI_LOG_E(TAG, "Unable to add header"); break; } if(!flipper_file_write_uint32(instance->flipper_file, "Frequency", (uint32_t*)&frequency, 1)) { - FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add Frequency"); + FURI_LOG_E(TAG, "Unable to add Frequency"); break; } if(!flipper_file_write_string_cstr(instance->flipper_file, "Preset", preset)) { - FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add Preset"); + FURI_LOG_E(TAG, "Unable to add Preset"); break; } if(!flipper_file_write_string_cstr(instance->flipper_file, "Protocol", instance->common.name)) { - FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add Protocol"); + FURI_LOG_E(TAG, "Unable to add Protocol"); break; } @@ -222,7 +224,7 @@ bool subghz_protocol_raw_save_to_file_write(SubGhzProtocolRAW* instance) { if(instance->file_is_open == RAWFileIsOpenWrite) { if(!flipper_file_write_int32( instance->flipper_file, "RAW_Data", instance->upload_raw, instance->ind_write)) { - FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add RAW_Data"); + FURI_LOG_E(TAG, "Unable to add RAW_Data"); } else { instance->sample_write += instance->ind_write; instance->ind_write = 0; diff --git a/lib/subghz/subghz_file_encoder_worker.c b/lib/subghz/subghz_file_encoder_worker.c index d8e5132d..7bde91fa 100644 --- a/lib/subghz/subghz_file_encoder_worker.c +++ b/lib/subghz/subghz_file_encoder_worker.c @@ -4,6 +4,8 @@ #include #include +#define TAG "SubGhzFileEncoderWorker" + #define SUBGHZ_FILE_ENCODER_LOAD 512 struct SubGhzFileEncoderWorker { @@ -86,11 +88,11 @@ LevelDuration subghz_file_encoder_worker_get_level_duration(void* context) { level_duration = level_duration_make(true, duration); } else if(duration == 0) { level_duration = level_duration_reset(); - FURI_LOG_I("SubGhzFileEncoderWorker", "Stop transmission"); + FURI_LOG_I(TAG, "Stop transmission"); } return level_duration; } else { - FURI_LOG_E("SubGhzFileEncoderWorker", "Slow flash read"); + FURI_LOG_E(TAG, "Slow flash read"); return level_duration_wait(); } } @@ -102,27 +104,27 @@ LevelDuration subghz_file_encoder_worker_get_level_duration(void* context) { */ static int32_t subghz_file_encoder_worker_thread(void* context) { SubGhzFileEncoderWorker* instance = context; - FURI_LOG_I("SubGhzFileEncoderWorker", "Worker start"); + FURI_LOG_I(TAG, "Worker start"); bool res = false; File* file = flipper_file_get_file(instance->flipper_file); do { if(!flipper_file_open_existing( instance->flipper_file, string_get_cstr(instance->file_path))) { FURI_LOG_E( - "SubGhzFileEncoderWorker", + TAG, "Unable to open file for read: %s", string_get_cstr(instance->file_path)); break; } if(!flipper_file_read_string(instance->flipper_file, "Protocol", instance->str_data)) { - FURI_LOG_E("SubGhzFileEncoderWorker", "Missing Protocol"); + FURI_LOG_E(TAG, "Missing Protocol"); break; } //skip the end of the previous line "\n" storage_file_seek(file, 1, false); res = true; - FURI_LOG_I("SubGhzFileEncoderWorker", "Start transmission"); + FURI_LOG_I(TAG, "Start transmission"); } while(0); while(res && instance->worker_running) { @@ -149,13 +151,13 @@ static int32_t subghz_file_encoder_worker_thread(void* context) { } } //waiting for the end of the transfer - FURI_LOG_I("SubGhzFileEncoderWorker", "End read file"); + FURI_LOG_I(TAG, "End read file"); while(instance->worker_running) { osDelay(50); } flipper_file_close(instance->flipper_file); - FURI_LOG_I("SubGhzFileEncoderWorker", "Worker stop"); + FURI_LOG_I(TAG, "Worker stop"); return 0; } diff --git a/lib/subghz/subghz_keystore.c b/lib/subghz/subghz_keystore.c index 3b55b700..04fb80ea 100644 --- a/lib/subghz/subghz_keystore.c +++ b/lib/subghz/subghz_keystore.c @@ -7,7 +7,7 @@ #include #include -#define SUBGHZ_KEYSTORE_TAG "SubGhzParser" +#define TAG "SubGhzKeystore" #define FILE_BUFFER_SIZE 64 @@ -71,7 +71,7 @@ static bool subghz_keystore_process_line(SubGhzKeystore* instance, char* line) { subghz_keystore_add_key(instance, name, key, type); return true; } else { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Failed to load line: %s\r\n", line); + FURI_LOG_E(TAG, "Failed to load line: %s\r\n", line); return false; } } @@ -133,13 +133,13 @@ static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint (uint8_t*)encrypted_line, (uint8_t*)decrypted_line, len)) { subghz_keystore_process_line(instance, decrypted_line); } else { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Decryption failed"); + FURI_LOG_E(TAG, "Decryption failed"); result = false; break; } } else { FURI_LOG_E( - SUBGHZ_KEYSTORE_TAG, "Invalid encrypted data: %s", encrypted_line); + TAG, "Invalid encrypted data: %s", encrypted_line); } } else { subghz_keystore_process_line(instance, encrypted_line); @@ -155,7 +155,7 @@ static bool subghz_keystore_read_file(SubGhzKeystore* instance, File* file, uint encrypted_line[encrypted_line_cursor] = buffer[i]; encrypted_line_cursor++; } else { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Malformed file"); + FURI_LOG_E(TAG, "Malformed file"); result = false; break; } @@ -186,21 +186,21 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) { FlipperFile* flipper_file = flipper_file_alloc(storage); do { if(!flipper_file_open_existing(flipper_file, file_name)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for read: %s", file_name); + FURI_LOG_E(TAG, "Unable to open file for read: %s", file_name); break; } if(!flipper_file_read_header(flipper_file, filetype, &version)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing or incorrect header"); + FURI_LOG_E(TAG, "Missing or incorrect header"); break; } if(!flipper_file_read_uint32(flipper_file, "Encryption", (uint32_t*)&encryption, 1)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing encryption type"); + FURI_LOG_E(TAG, "Missing encryption type"); break; } if(strcmp(string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_TYPE) != 0 || version != SUBGHZ_KEYSTORE_FILE_VERSION) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Type or version mismatch"); + FURI_LOG_E(TAG, "Type or version mismatch"); break; } @@ -209,13 +209,13 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) { result = subghz_keystore_read_file(instance, file, NULL); } else if(encryption == SubGhzKeystoreEncryptionAES256) { if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing IV"); + FURI_LOG_E(TAG, "Missing IV"); break; } subghz_keystore_mess_with_iv(iv); result = subghz_keystore_read_file(instance, file, iv); } else { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unknown encryption"); + FURI_LOG_E(TAG, "Unknown encryption"); break; } } while(0); @@ -240,28 +240,28 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8 FlipperFile* flipper_file = flipper_file_alloc(storage); do { if(!flipper_file_open_always(flipper_file, file_name)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for write: %s", file_name); + FURI_LOG_E(TAG, "Unable to open file for write: %s", file_name); break; } if(!flipper_file_write_header_cstr( flipper_file, SUBGHZ_KEYSTORE_FILE_TYPE, SUBGHZ_KEYSTORE_FILE_VERSION)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add header"); + FURI_LOG_E(TAG, "Unable to add header"); break; } SubGhzKeystoreEncryption encryption = SubGhzKeystoreEncryptionAES256; if(!flipper_file_write_uint32(flipper_file, "Encryption", (uint32_t*)&encryption, 1)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add Encryption"); + FURI_LOG_E(TAG, "Unable to add Encryption"); break; } if(!flipper_file_write_hex(flipper_file, "IV", iv, 16)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add IV"); + FURI_LOG_E(TAG, "Unable to add IV"); break; } subghz_keystore_mess_with_iv(iv); if(!furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to load encryption key"); + FURI_LOG_E(TAG, "Unable to load encryption key"); break; } @@ -291,7 +291,7 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8 // Form encrypted line if(!furi_hal_crypto_encrypt( (uint8_t*)decrypted_line, (uint8_t*)encrypted_line, len)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Encryption failed"); + FURI_LOG_E(TAG, "Encryption failed"); break; } // HEX Encode encrypted line @@ -307,7 +307,7 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8 encrypted_line_count++; FURI_LOG_I( - SUBGHZ_KEYSTORE_TAG, "Encrypted: `%s` -> `%s`", decrypted_line, encrypted_line); + TAG, "Encrypted: `%s` -> `%s`", decrypted_line, encrypted_line); } furi_hal_crypto_store_unload_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT); result = encrypted_line_count == SubGhzKeyArray_size(instance->data); @@ -344,26 +344,26 @@ bool subghz_keystore_raw_encrypted_save( FlipperFile* input_flipper_file = flipper_file_alloc(storage); do { if(!flipper_file_open_existing(input_flipper_file, input_file_name)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for read: %s", input_file_name); + FURI_LOG_E(TAG, "Unable to open file for read: %s", input_file_name); break; } if(!flipper_file_read_header(input_flipper_file, filetype, &version)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing or incorrect header"); + FURI_LOG_E(TAG, "Missing or incorrect header"); break; } if(!flipper_file_read_uint32(input_flipper_file, "Encryption", (uint32_t*)&encryption, 1)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing encryption type"); + FURI_LOG_E(TAG, "Missing encryption type"); break; } if(strcmp(string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_RAW_TYPE) != 0 || version != SUBGHZ_KEYSTORE_FILE_VERSION) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Type or version mismatch"); + FURI_LOG_E(TAG, "Type or version mismatch"); break; } if(encryption != SubGhzKeystoreEncryptionNone) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Already encryption"); + FURI_LOG_E(TAG, "Already encryption"); break; } File* input_file = flipper_file_get_file(input_flipper_file); @@ -371,34 +371,34 @@ bool subghz_keystore_raw_encrypted_save( FlipperFile* output_flipper_file = flipper_file_alloc(storage); if(!flipper_file_open_always(output_flipper_file, output_file_name)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for write: %s", output_file_name); + FURI_LOG_E(TAG, "Unable to open file for write: %s", output_file_name); break; } if(!flipper_file_write_header_cstr( output_flipper_file, string_get_cstr(filetype), SUBGHZ_KEYSTORE_FILE_VERSION)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add header"); + FURI_LOG_E(TAG, "Unable to add header"); break; } SubGhzKeystoreEncryption tmp_encryption = SubGhzKeystoreEncryptionAES256; if(!flipper_file_write_uint32( output_flipper_file, "Encryption", (uint32_t*)&tmp_encryption, 1)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add Encryption"); + FURI_LOG_E(TAG, "Unable to add Encryption"); break; } if(!flipper_file_write_hex(output_flipper_file, "IV", iv, 16)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add IV"); + FURI_LOG_E(TAG, "Unable to add IV"); break; } if(!flipper_file_write_string_cstr(output_flipper_file, "Encrypt_data", "RAW")) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to add Encrypt_data"); + FURI_LOG_E(TAG, "Unable to add Encrypt_data"); break; } subghz_keystore_mess_with_iv(iv); if(!furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to load encryption key"); + FURI_LOG_E(TAG, "Unable to load encryption key"); break; } @@ -431,7 +431,7 @@ bool subghz_keystore_raw_encrypted_save( // Form encrypted line if(!furi_hal_crypto_encrypt( (uint8_t*)buffer, (uint8_t*)encrypted_line, FILE_BUFFER_SIZE / 2)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Encryption failed"); + FURI_LOG_E(TAG, "Encryption failed"); result = false; break; } @@ -483,40 +483,40 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* FlipperFile* flipper_file = flipper_file_alloc(storage); do { if(!flipper_file_open_existing(flipper_file, file_name)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to open file for read: %s", file_name); + FURI_LOG_E(TAG, "Unable to open file for read: %s", file_name); break; } if(!flipper_file_read_header(flipper_file, str_temp, &version)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing or incorrect header"); + FURI_LOG_E(TAG, "Missing or incorrect header"); break; } if(!flipper_file_read_uint32(flipper_file, "Encryption", (uint32_t*)&encryption, 1)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing encryption type"); + FURI_LOG_E(TAG, "Missing encryption type"); break; } if(strcmp(string_get_cstr(str_temp), SUBGHZ_KEYSTORE_FILE_RAW_TYPE) != 0 || version != SUBGHZ_KEYSTORE_FILE_VERSION) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Type or version mismatch"); + FURI_LOG_E(TAG, "Type or version mismatch"); break; } File* file = flipper_file_get_file(flipper_file); if(encryption != SubGhzKeystoreEncryptionAES256) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unknown encryption"); + FURI_LOG_E(TAG, "Unknown encryption"); break; } if(offset < 16) { if(!flipper_file_read_hex(flipper_file, "IV", iv, 16)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing IV"); + FURI_LOG_E(TAG, "Missing IV"); break; } subghz_keystore_mess_with_iv(iv); } if(!flipper_file_read_string(flipper_file, "Encrypt_data", str_temp)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Missing Encrypt_data"); + FURI_LOG_E(TAG, "Missing Encrypt_data"); break; } @@ -537,7 +537,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* size_t size = storage_file_size(file); size -= storage_file_tell(file); if(size < (offset * 2 + len * 2)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Seek position exceeds file size"); + FURI_LOG_E(TAG, "Seek position exceeds file size"); break; } @@ -555,7 +555,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* } if(!furi_hal_crypto_store_load_key(SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT, iv)) { - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Unable to load encryption key"); + FURI_LOG_E(TAG, "Unable to load encryption key"); break; } @@ -576,7 +576,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* if(!furi_hal_crypto_decrypt( (uint8_t*)buffer, (uint8_t*)decrypted_line, bufer_size / 2)) { decrypted = false; - FURI_LOG_E(SUBGHZ_KEYSTORE_TAG, "Decryption failed"); + FURI_LOG_E(TAG, "Decryption failed"); break; } memcpy(data, (uint8_t*)decrypted_line + (offset - (offset / 16) * 16), len); diff --git a/lib/subghz/subghz_worker.c b/lib/subghz/subghz_worker.c index 8fd5d4bc..f1f05f43 100644 --- a/lib/subghz/subghz_worker.c +++ b/lib/subghz/subghz_worker.c @@ -3,6 +3,8 @@ #include #include +#define TAG "SubGhzWorker" + struct SubGhzWorker { FuriThread* thread; StreamBufferHandle_t stream; @@ -54,7 +56,7 @@ static int32_t subghz_worker_thread_callback(void* context) { xStreamBufferReceive(instance->stream, &level_duration, sizeof(LevelDuration), 10); if(ret == sizeof(LevelDuration)) { if(level_duration_is_reset(level_duration)) { - FURI_LOG_E("SubGhzWorker", "Overrun buffer");; + FURI_LOG_E(TAG, "Overrun buffer");; if(instance->overrun_callback) instance->overrun_callback(instance->context); } else { bool level = level_duration_get_level(level_duration); diff --git a/lib/toolbox/saved_struct.c b/lib/toolbox/saved_struct.c index 61b5bdc6..653e51c8 100644 --- a/lib/toolbox/saved_struct.c +++ b/lib/toolbox/saved_struct.c @@ -3,7 +3,7 @@ #include #include -#define SAVED_STRUCT_TAG "SAVED_STRUCT" +#define TAG "SavedStruct" typedef struct { uint8_t magic; @@ -23,7 +23,7 @@ bool saved_struct_save(const char* path, furi_assert(size); SavedStructHeader header; - FURI_LOG_I(SAVED_STRUCT_TAG, "Saving \"%s\"", path); + FURI_LOG_I(TAG, "Saving \"%s\"", path); // Store Storage* storage = furi_record_open("storage"); @@ -32,7 +32,7 @@ bool saved_struct_save(const char* path, bool saved = storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS); if(!saved) { FURI_LOG_E( - SAVED_STRUCT_TAG, + TAG, "Open failed \"%s\". Error: \'%s\'", path, storage_file_get_error_desc(file)); @@ -58,7 +58,7 @@ bool saved_struct_save(const char* path, if(bytes_count != (size + sizeof(header))) { FURI_LOG_E( - SAVED_STRUCT_TAG, + TAG, "Write failed \"%s\". Error: \'%s\'", path, storage_file_get_error_desc(file)); @@ -77,7 +77,7 @@ bool saved_struct_load(const char* path, size_t size, uint8_t magic, uint8_t version) { - FURI_LOG_I(SAVED_STRUCT_TAG, "Loading \"%s\"", path); + FURI_LOG_I(TAG, "Loading \"%s\"", path); SavedStructHeader header; @@ -88,7 +88,7 @@ bool saved_struct_load(const char* path, bool loaded = storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING); if (!loaded) { FURI_LOG_E( - SAVED_STRUCT_TAG, + TAG, "Failed to read \"%s\". Error: %s", path, storage_file_get_error_desc(file)); @@ -100,14 +100,14 @@ bool saved_struct_load(const char* path, bytes_count += storage_file_read(file, data_read, size); if(bytes_count != (sizeof(SavedStructHeader) + size)) { - FURI_LOG_E(SAVED_STRUCT_TAG, "Size mismatch of file \"%s\"", path); + FURI_LOG_E(TAG, "Size mismatch of file \"%s\"", path); result = false; } } if(result && (header.magic != magic || header.version != version)) { FURI_LOG_E( - SAVED_STRUCT_TAG, + TAG, "Magic(%d != %d) or Version(%d != %d) mismatch of file \"%s\"", header.magic, magic, @@ -126,7 +126,7 @@ bool saved_struct_load(const char* path, if(header.checksum != checksum) { FURI_LOG_E( - SAVED_STRUCT_TAG, + TAG, "Checksum(%d != %d) mismatch of file \"%s\"", header.checksum, checksum,