Merge branch 'dev' into release-candidate
This commit is contained in:
		
						commit
						dc622321b9
					
				@ -39,6 +39,7 @@ extern int32_t music_player_app(void* p);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// On system start hooks declaration
 | 
					// On system start hooks declaration
 | 
				
			||||||
extern void bt_cli_init();
 | 
					extern void bt_cli_init();
 | 
				
			||||||
 | 
					extern void crypto_cli_init();
 | 
				
			||||||
extern void ibutton_cli_init();
 | 
					extern void ibutton_cli_init();
 | 
				
			||||||
extern void irda_cli_init();
 | 
					extern void irda_cli_init();
 | 
				
			||||||
extern void lfrfid_cli_init();
 | 
					extern void lfrfid_cli_init();
 | 
				
			||||||
@ -171,6 +172,9 @@ const size_t FLIPPER_APPS_COUNT = sizeof(FLIPPER_APPS) / sizeof(FlipperApplicati
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// On system start hooks
 | 
					// On system start hooks
 | 
				
			||||||
const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[] = {
 | 
					const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[] = {
 | 
				
			||||||
 | 
					#ifdef SRV_CLI
 | 
				
			||||||
 | 
					    crypto_cli_init,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    irda_cli_init,
 | 
					    irda_cli_init,
 | 
				
			||||||
#ifdef APP_NFC
 | 
					#ifdef APP_NFC
 | 
				
			||||||
    nfc_cli_init,
 | 
					    nfc_cli_init,
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
#include "bt_debug_app.h"
 | 
					#include "bt_debug_app.h"
 | 
				
			||||||
 | 
					#include <furi-hal-bt.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum BtDebugSubmenuIndex {
 | 
					enum BtDebugSubmenuIndex {
 | 
				
			||||||
    BtDebugSubmenuIndexCarrierTest,
 | 
					    BtDebugSubmenuIndexCarrierTest,
 | 
				
			||||||
@ -25,6 +26,10 @@ uint32_t bt_debug_start_view(void* context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
BtDebugApp* bt_debug_app_alloc() {
 | 
					BtDebugApp* bt_debug_app_alloc() {
 | 
				
			||||||
    BtDebugApp* app = furi_alloc(sizeof(BtDebugApp));
 | 
					    BtDebugApp* app = furi_alloc(sizeof(BtDebugApp));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Load settings
 | 
				
			||||||
 | 
					    bt_settings_load(&app->settings);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Gui
 | 
					    // Gui
 | 
				
			||||||
    app->gui = furi_record_open("gui");
 | 
					    app->gui = furi_record_open("gui");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -88,7 +93,15 @@ void bt_debug_app_free(BtDebugApp* app) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int32_t bt_debug_app(void* p) {
 | 
					int32_t bt_debug_app(void* p) {
 | 
				
			||||||
    BtDebugApp* app = bt_debug_app_alloc();
 | 
					    BtDebugApp* app = bt_debug_app_alloc();
 | 
				
			||||||
 | 
					    // Stop advertising
 | 
				
			||||||
 | 
					    furi_hal_bt_stop_advertising();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_run(app->view_dispatcher);
 | 
					    view_dispatcher_run(app->view_dispatcher);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Restart advertising
 | 
				
			||||||
 | 
					    if(app->settings.enabled) {
 | 
				
			||||||
 | 
					        furi_hal_bt_start_advertising();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    bt_debug_app_free(app);
 | 
					    bt_debug_app_free(app);
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -3,13 +3,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define BT_SERVICE_TAG "BT"
 | 
					#define BT_SERVICE_TAG "BT"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// static void bt_update_statusbar(void* arg) {
 | 
					 | 
				
			||||||
//     furi_assert(arg);
 | 
					 | 
				
			||||||
//     Bt* bt = arg;
 | 
					 | 
				
			||||||
//     BtMessage m = {.type = BtMessageTypeUpdateStatusbar};
 | 
					 | 
				
			||||||
//     furi_check(osMessageQueuePut(bt->message_queue, &m, 0, osWaitForever) == osOK);
 | 
					 | 
				
			||||||
// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void bt_draw_statusbar_callback(Canvas* canvas, void* context) {
 | 
					static void bt_draw_statusbar_callback(Canvas* canvas, void* context) {
 | 
				
			||||||
    canvas_draw_icon(canvas, 0, 0, &I_Bluetooth_5x8);
 | 
					    canvas_draw_icon(canvas, 0, 0, &I_Bluetooth_5x8);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -42,10 +35,6 @@ Bt* bt_alloc() {
 | 
				
			|||||||
    // Alloc queue
 | 
					    // Alloc queue
 | 
				
			||||||
    bt->message_queue = osMessageQueueNew(8, sizeof(BtMessage), NULL);
 | 
					    bt->message_queue = osMessageQueueNew(8, sizeof(BtMessage), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // doesn't make sense if we waiting for transition on service start
 | 
					 | 
				
			||||||
    // bt->update_status_timer = osTimerNew(bt_update_statusbar, osTimerPeriodic, bt, NULL);
 | 
					 | 
				
			||||||
    // osTimerStart(bt->update_status_timer, 4000);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Setup statusbar view port
 | 
					    // Setup statusbar view port
 | 
				
			||||||
    bt->statusbar_view_port = bt_statusbar_view_port_alloc();
 | 
					    bt->statusbar_view_port = bt_statusbar_view_port_alloc();
 | 
				
			||||||
    // Gui
 | 
					    // Gui
 | 
				
			||||||
@ -67,15 +56,18 @@ int32_t bt_srv() {
 | 
				
			|||||||
        FURI_LOG_E(BT_SERVICE_TAG, "Core2 startup failed");
 | 
					        FURI_LOG_E(BT_SERVICE_TAG, "Core2 startup failed");
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        view_port_enabled_set(bt->statusbar_view_port, true);
 | 
					        view_port_enabled_set(bt->statusbar_view_port, true);
 | 
				
			||||||
        if(bt->bt_settings.enabled) {
 | 
					        if(furi_hal_bt_init_app()) {
 | 
				
			||||||
            bool bt_app_started = furi_hal_bt_start_app();
 | 
					            FURI_LOG_I(BT_SERVICE_TAG, "BLE stack started");
 | 
				
			||||||
            if(!bt_app_started) {
 | 
					            if(bt->bt_settings.enabled) {
 | 
				
			||||||
                FURI_LOG_E(BT_SERVICE_TAG, "BT App start failed");
 | 
					                furi_hal_bt_start_advertising();
 | 
				
			||||||
            } else {
 | 
					                FURI_LOG_I(BT_SERVICE_TAG, "Start advertising");
 | 
				
			||||||
                FURI_LOG_I(BT_SERVICE_TAG, "BT App started");
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            FURI_LOG_E(BT_SERVICE_TAG, "BT App start failed");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    // Update statusbar
 | 
				
			||||||
 | 
					    view_port_enabled_set(bt->statusbar_view_port, furi_hal_bt_is_alive());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    BtMessage message;
 | 
					    BtMessage message;
 | 
				
			||||||
    while(1) {
 | 
					    while(1) {
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,8 @@ extern "C" {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
typedef struct Bt Bt;
 | 
					typedef struct Bt Bt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bt_update_statusbar(Bt* bt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bt_update_battery_level(Bt* bt, uint8_t battery_level);
 | 
					void bt_update_battery_level(Bt* bt, uint8_t battery_level);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool bt_pin_code_show(Bt* bt, uint32_t pin_code);
 | 
					bool bt_pin_code_show(Bt* bt, uint32_t pin_code);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,12 @@
 | 
				
			|||||||
#include "bt.h"
 | 
					#include "bt.h"
 | 
				
			||||||
#include "bt_i.h"
 | 
					#include "bt_i.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bt_update_statusbar(Bt* bt) {
 | 
				
			||||||
 | 
					    furi_assert(bt);
 | 
				
			||||||
 | 
					    BtMessage message = {.type = BtMessageTypeUpdateStatusbar};
 | 
				
			||||||
 | 
					    furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bt_update_battery_level(Bt* bt, uint8_t battery_level) {
 | 
					void bt_update_battery_level(Bt* bt, uint8_t battery_level) {
 | 
				
			||||||
    furi_assert(bt);
 | 
					    furi_assert(bt);
 | 
				
			||||||
    BtMessage message = {
 | 
					    BtMessage message = {
 | 
				
			||||||
 | 
				
			|||||||
@ -32,7 +32,6 @@ typedef struct {
 | 
				
			|||||||
struct Bt {
 | 
					struct Bt {
 | 
				
			||||||
    BtSettings bt_settings;
 | 
					    BtSettings bt_settings;
 | 
				
			||||||
    osMessageQueueId_t message_queue;
 | 
					    osMessageQueueId_t message_queue;
 | 
				
			||||||
    osTimerId_t update_status_timer;
 | 
					 | 
				
			||||||
    Gui* gui;
 | 
					    Gui* gui;
 | 
				
			||||||
    ViewPort* statusbar_view_port;
 | 
					    ViewPort* statusbar_view_port;
 | 
				
			||||||
    DialogsApp* dialogs;
 | 
					    DialogsApp* dialogs;
 | 
				
			||||||
 | 
				
			|||||||
@ -31,12 +31,11 @@ BtSettingsApp* bt_settings_app_alloc() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
 | 
					    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    app->submenu = submenu_alloc();
 | 
					    app->var_item_list = variable_item_list_alloc();
 | 
				
			||||||
    view_dispatcher_add_view(
 | 
					    view_dispatcher_add_view(
 | 
				
			||||||
        app->view_dispatcher, BtSettingsAppViewSubmenu, submenu_get_view(app->submenu));
 | 
					        app->view_dispatcher,
 | 
				
			||||||
    app->dialog_ex = dialog_ex_alloc();
 | 
					        BtSettingsAppViewVarItemList,
 | 
				
			||||||
    view_dispatcher_add_view(
 | 
					        variable_item_list_get_view(app->var_item_list));
 | 
				
			||||||
        app->view_dispatcher, BtSettingsAppViewDialogEx, dialog_ex_get_view(app->dialog_ex));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneStart);
 | 
					    scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneStart);
 | 
				
			||||||
    return app;
 | 
					    return app;
 | 
				
			||||||
@ -44,12 +43,9 @@ BtSettingsApp* bt_settings_app_alloc() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void bt_settings_app_free(BtSettingsApp* app) {
 | 
					void bt_settings_app_free(BtSettingsApp* app) {
 | 
				
			||||||
    furi_assert(app);
 | 
					    furi_assert(app);
 | 
				
			||||||
    // Submenu
 | 
					    // Variable item list
 | 
				
			||||||
    view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewSubmenu);
 | 
					    view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewVarItemList);
 | 
				
			||||||
    submenu_free(app->submenu);
 | 
					    variable_item_list_free(app->var_item_list);
 | 
				
			||||||
    // Dialog
 | 
					 | 
				
			||||||
    view_dispatcher_remove_view(app->view_dispatcher, BtSettingsAppViewDialogEx);
 | 
					 | 
				
			||||||
    dialog_ex_free(app->dialog_ex);
 | 
					 | 
				
			||||||
    // View dispatcher
 | 
					    // View dispatcher
 | 
				
			||||||
    view_dispatcher_free(app->view_dispatcher);
 | 
					    view_dispatcher_free(app->view_dispatcher);
 | 
				
			||||||
    scene_manager_free(app->scene_manager);
 | 
					    scene_manager_free(app->scene_manager);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										11
									
								
								applications/bt/bt_settings_app/bt_settings_app.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										11
									
								
								applications/bt/bt_settings_app/bt_settings_app.h
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -6,8 +6,7 @@
 | 
				
			|||||||
#include <gui/view_dispatcher.h>
 | 
					#include <gui/view_dispatcher.h>
 | 
				
			||||||
#include <gui/scene_manager.h>
 | 
					#include <gui/scene_manager.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <gui/modules/submenu.h>
 | 
					#include <gui/modules/variable-item-list.h>
 | 
				
			||||||
#include <gui/modules/dialog_ex.h>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../bt_settings.h"
 | 
					#include "../bt_settings.h"
 | 
				
			||||||
#include "scenes/bt_settings_scene.h"
 | 
					#include "scenes/bt_settings_scene.h"
 | 
				
			||||||
@ -17,11 +16,7 @@ typedef struct {
 | 
				
			|||||||
    Gui* gui;
 | 
					    Gui* gui;
 | 
				
			||||||
    SceneManager* scene_manager;
 | 
					    SceneManager* scene_manager;
 | 
				
			||||||
    ViewDispatcher* view_dispatcher;
 | 
					    ViewDispatcher* view_dispatcher;
 | 
				
			||||||
    Submenu* submenu;
 | 
					    VariableItemList* var_item_list;
 | 
				
			||||||
    DialogEx* dialog_ex;
 | 
					 | 
				
			||||||
} BtSettingsApp;
 | 
					} BtSettingsApp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef enum {
 | 
					typedef enum { BtSettingsAppViewVarItemList } BtSettingsAppView;
 | 
				
			||||||
    BtSettingsAppViewSubmenu,
 | 
					 | 
				
			||||||
    BtSettingsAppViewDialogEx,
 | 
					 | 
				
			||||||
} BtSettingsAppView;
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -1,2 +1 @@
 | 
				
			|||||||
ADD_SCENE(bt_settings, start, Start)
 | 
					ADD_SCENE(bt_settings, start, Start)
 | 
				
			||||||
ADD_SCENE(bt_settings, disable_dialog, DisableDialog)
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -1,44 +0,0 @@
 | 
				
			|||||||
#include "../bt_settings_app.h"
 | 
					 | 
				
			||||||
#include <furi-hal-boot.h>
 | 
					 | 
				
			||||||
#include <furi-hal-power.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void bt_setting_disable_dialog_callback(DialogExResult result, void* context) {
 | 
					 | 
				
			||||||
    BtSettingsApp* app = context;
 | 
					 | 
				
			||||||
    view_dispatcher_send_custom_event(app->view_dispatcher, result);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void bt_settings_scene_disable_dialog_on_enter(void* context) {
 | 
					 | 
				
			||||||
    BtSettingsApp* app = context;
 | 
					 | 
				
			||||||
    DialogEx* dialog_ex = app->dialog_ex;
 | 
					 | 
				
			||||||
    dialog_ex_set_text(
 | 
					 | 
				
			||||||
        dialog_ex, "Reboot device\nto disable Bluetooth", 64, 32, AlignCenter, AlignCenter);
 | 
					 | 
				
			||||||
    dialog_ex_set_left_button_text(dialog_ex, "Back");
 | 
					 | 
				
			||||||
    dialog_ex_set_right_button_text(dialog_ex, "Reboot");
 | 
					 | 
				
			||||||
    dialog_ex_set_result_callback(dialog_ex, bt_setting_disable_dialog_callback);
 | 
					 | 
				
			||||||
    dialog_ex_set_context(dialog_ex, app);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewDialogEx);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool bt_settings_scene_disable_dialog_on_event(void* context, SceneManagerEvent event) {
 | 
					 | 
				
			||||||
    BtSettingsApp* app = context;
 | 
					 | 
				
			||||||
    bool consumed = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(event.type == SceneManagerEventTypeCustom) {
 | 
					 | 
				
			||||||
        if(event.event == DialogExResultLeft) {
 | 
					 | 
				
			||||||
            scene_manager_previous_scene(app->scene_manager);
 | 
					 | 
				
			||||||
            consumed = true;
 | 
					 | 
				
			||||||
        } else if(event.event == DialogExResultRight) {
 | 
					 | 
				
			||||||
            app->settings.enabled = false;
 | 
					 | 
				
			||||||
            bt_settings_save(&app->settings);
 | 
					 | 
				
			||||||
            furi_hal_boot_set_mode(FuriHalBootModeNormal);
 | 
					 | 
				
			||||||
            furi_hal_power_reset();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return consumed;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void bt_settings_scene_disable_dialog_on_exit(void* context) {
 | 
					 | 
				
			||||||
    BtSettingsApp* app = context;
 | 
					 | 
				
			||||||
    dialog_ex_clean(app->dialog_ex);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,28 +1,45 @@
 | 
				
			|||||||
#include "../bt_settings_app.h"
 | 
					#include "../bt_settings_app.h"
 | 
				
			||||||
#include "furi-hal-bt.h"
 | 
					#include "furi-hal-bt.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum BtSettingsAppStartSubmenuIndex {
 | 
					enum BtSetting {
 | 
				
			||||||
    BtSettingsAppStartSubmenuIndexEnable,
 | 
					    BtSettingOff,
 | 
				
			||||||
 | 
					    BtSettingOn,
 | 
				
			||||||
 | 
					    BtSettingNum,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void bt_settings_scene_start_submenu_callback(void* context, uint32_t index) {
 | 
					const char* const bt_settings_text[BtSettingNum] = {
 | 
				
			||||||
    BtSettingsApp* app = context;
 | 
					    "Off",
 | 
				
			||||||
 | 
					    "On",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void bt_settings_scene_start_var_list_change_callback(VariableItem* item) {
 | 
				
			||||||
 | 
					    BtSettingsApp* app = variable_item_get_context(item);
 | 
				
			||||||
 | 
					    uint8_t index = variable_item_get_current_value_index(item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    variable_item_set_current_value_text(item, bt_settings_text[index]);
 | 
				
			||||||
    view_dispatcher_send_custom_event(app->view_dispatcher, index);
 | 
					    view_dispatcher_send_custom_event(app->view_dispatcher, index);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bt_settings_scene_start_on_enter(void* context) {
 | 
					void bt_settings_scene_start_on_enter(void* context) {
 | 
				
			||||||
    BtSettingsApp* app = context;
 | 
					    BtSettingsApp* app = context;
 | 
				
			||||||
    Submenu* submenu = app->submenu;
 | 
					    VariableItemList* var_item_list = app->var_item_list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const char* submenu_label = app->settings.enabled ? "Disable" : "Enable";
 | 
					    VariableItem* item;
 | 
				
			||||||
    submenu_add_item(
 | 
					    item = variable_item_list_add(
 | 
				
			||||||
        submenu,
 | 
					        var_item_list,
 | 
				
			||||||
        submenu_label,
 | 
					        "Bluetooth",
 | 
				
			||||||
        BtSettingsAppStartSubmenuIndexEnable,
 | 
					        BtSettingNum,
 | 
				
			||||||
        bt_settings_scene_start_submenu_callback,
 | 
					        bt_settings_scene_start_var_list_change_callback,
 | 
				
			||||||
        app);
 | 
					        app);
 | 
				
			||||||
 | 
					    if(app->settings.enabled) {
 | 
				
			||||||
 | 
					        variable_item_set_current_value_index(item, BtSettingOn);
 | 
				
			||||||
 | 
					        variable_item_set_current_value_text(item, bt_settings_text[BtSettingOn]);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        variable_item_set_current_value_index(item, BtSettingOff);
 | 
				
			||||||
 | 
					        variable_item_set_current_value_text(item, bt_settings_text[BtSettingOff]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewSubmenu);
 | 
					    view_dispatcher_switch_to_view(app->view_dispatcher, BtSettingsAppViewVarItemList);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
 | 
					bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
 | 
				
			||||||
@ -30,27 +47,19 @@ bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
 | 
				
			|||||||
    bool consumed = false;
 | 
					    bool consumed = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(event.type == SceneManagerEventTypeCustom) {
 | 
					    if(event.type == SceneManagerEventTypeCustom) {
 | 
				
			||||||
        if(event.event == BtSettingsAppStartSubmenuIndexEnable) {
 | 
					        if(event.event == BtSettingOn) {
 | 
				
			||||||
            if(!app->settings.enabled) {
 | 
					            furi_hal_bt_start_advertising();
 | 
				
			||||||
                app->settings.enabled = true;
 | 
					            app->settings.enabled = true;
 | 
				
			||||||
                furi_hal_bt_start_app();
 | 
					        } else if(event.event == BtSettingOff) {
 | 
				
			||||||
                submenu_clean(app->submenu);
 | 
					            app->settings.enabled = false;
 | 
				
			||||||
                submenu_add_item(
 | 
					            furi_hal_bt_stop_advertising();
 | 
				
			||||||
                    app->submenu,
 | 
					 | 
				
			||||||
                    "Disable",
 | 
					 | 
				
			||||||
                    BtSettingsAppStartSubmenuIndexEnable,
 | 
					 | 
				
			||||||
                    bt_settings_scene_start_submenu_callback,
 | 
					 | 
				
			||||||
                    app);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneDisableDialog);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            consumed = true;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        consumed = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return consumed;
 | 
					    return consumed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bt_settings_scene_start_on_exit(void* context) {
 | 
					void bt_settings_scene_start_on_exit(void* context) {
 | 
				
			||||||
    BtSettingsApp* app = context;
 | 
					    BtSettingsApp* app = context;
 | 
				
			||||||
    submenu_clean(app->submenu);
 | 
					    variable_item_list_clean(app->var_item_list);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,15 @@
 | 
				
			|||||||
#include <notification/notification-messages.h>
 | 
					#include <notification/notification-messages.h>
 | 
				
			||||||
#include <shci.h>
 | 
					#include <shci.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ENCLAVE_SIGNATURE_KEY_SLOT 1
 | 
				
			||||||
 | 
					#define ENCLAVE_SIGNATURE_SIZE 16
 | 
				
			||||||
 | 
					static const uint8_t enclave_signature_iv[16] =
 | 
				
			||||||
 | 
					    {0x32, 0xe6, 0xa7, 0x85, 0x20, 0xae, 0x0b, 0xf0, 0x00, 0xb6, 0x30, 0x9b, 0xd5, 0x42, 0x9e, 0xa6};
 | 
				
			||||||
 | 
					static const uint8_t enclave_signature_input[ENCLAVE_SIGNATURE_SIZE] =
 | 
				
			||||||
 | 
					    {0xdc, 0x76, 0x15, 0x1e, 0x69, 0xe8, 0xdc, 0xd3, 0x4a, 0x71, 0x0b, 0x42, 0x71, 0xe0, 0xa9, 0x78};
 | 
				
			||||||
 | 
					static const uint8_t enclave_signature_expected[ENCLAVE_SIGNATURE_SIZE] =
 | 
				
			||||||
 | 
					    {0x6b, 0x31, 0xc, 0xac, 0x3f, 0x68, 0x79, 0x76, 0x43, 0xc4, 0xfe, 0xe0, 0x25, 0x53, 0x64, 0xc7};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 
 | 
					/* 
 | 
				
			||||||
 * Device Info Command
 | 
					 * Device Info Command
 | 
				
			||||||
 * This command is intended to be used by humans and machines
 | 
					 * This command is intended to be used by humans and machines
 | 
				
			||||||
@ -85,6 +94,18 @@ void cli_command_device_info(Cli* cli, string_t args, void* context) {
 | 
				
			|||||||
            printf("%02X", ble_mac[i]);
 | 
					            printf("%02X", ble_mac[i]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        printf("\r\n");
 | 
					        printf("\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Signature verification
 | 
				
			||||||
 | 
					        uint8_t buffer[ENCLAVE_SIGNATURE_SIZE];
 | 
				
			||||||
 | 
					        bool enclave_valid = false;
 | 
				
			||||||
 | 
					        if(furi_hal_crypto_store_load_key(ENCLAVE_SIGNATURE_KEY_SLOT, enclave_signature_iv)) {
 | 
				
			||||||
 | 
					            if(furi_hal_crypto_encrypt(enclave_signature_input, buffer, ENCLAVE_SIGNATURE_SIZE)) {
 | 
				
			||||||
 | 
					                enclave_valid =
 | 
				
			||||||
 | 
					                    memcmp(buffer, enclave_signature_expected, ENCLAVE_SIGNATURE_SIZE) == 0;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            furi_hal_crypto_store_unload_key(ENCLAVE_SIGNATURE_KEY_SLOT);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        printf("enclave_valid       : %s\r\n", enclave_valid ? "true" : "false");
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        printf("radio_alive         : false\r\n");
 | 
					        printf("radio_alive         : false\r\n");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										284
									
								
								applications/crypto/crypto_cli.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										284
									
								
								applications/crypto/crypto_cli.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,284 @@
 | 
				
			|||||||
 | 
					#include <furi-hal.h>
 | 
				
			||||||
 | 
					#include <furi.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <lib/toolbox/args.h>
 | 
				
			||||||
 | 
					#include <cli/cli.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_cli_print_usage() {
 | 
				
			||||||
 | 
					    printf("Usage:\r\n");
 | 
				
			||||||
 | 
					    printf("crypto <cmd> <args>\r\n");
 | 
				
			||||||
 | 
					    printf("Cmd list:\r\n");
 | 
				
			||||||
 | 
					    printf(
 | 
				
			||||||
 | 
					        "\tencrypt <key_slot:int> <iv:hex>\t - Using key from secure enclave and IV encrypt plain text with AES256CBC and encode to hex\r\n");
 | 
				
			||||||
 | 
					    printf(
 | 
				
			||||||
 | 
					        "\tdecrypt <key_slot:int> <iv:hex>\t - Using key from secure enclave and IV decrypt hex encoded encrypted with AES256CBC data to plain text\r\n");
 | 
				
			||||||
 | 
					    printf("\thas_key <key_slot:int>\t - Check if secure enclave has key in slot\r\n");
 | 
				
			||||||
 | 
					    printf(
 | 
				
			||||||
 | 
					        "\tstore_key <key_type:str> <key_size:int> <key_data:hex>\t - Store key in secure enclave, returns allocated slot number !!! NON-REVERSABLE OPERATION - READ MANUAL FIRST !!!\r\n");
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_cli_encrypt(Cli* cli, string_t args) {
 | 
				
			||||||
 | 
					    int key_slot = 0;
 | 
				
			||||||
 | 
					    bool key_loaded = false;
 | 
				
			||||||
 | 
					    uint8_t iv[16];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        if(!args_read_int_and_trim(args, &key_slot) || !(key_slot > 0 && key_slot <= 100)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing slot, expected int 1-100");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!args_read_hex_bytes(args, iv, 16)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing IV, expected 16 bytes in hex");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
 | 
				
			||||||
 | 
					            printf("Unable to load key from slot %d", key_slot);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        key_loaded = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        printf("Enter plain text and press Ctrl+C to complete encryption:\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        string_t input;
 | 
				
			||||||
 | 
					        string_init(input);
 | 
				
			||||||
 | 
					        char c;
 | 
				
			||||||
 | 
					        while(cli_read(cli, (uint8_t*)&c, 1) == 1) {
 | 
				
			||||||
 | 
					            if(c == CliSymbolAsciiETX) {
 | 
				
			||||||
 | 
					                printf("\r\n");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            } else if(c >= 0x20 && c < 0x7F) {
 | 
				
			||||||
 | 
					                putc(c, stdout);
 | 
				
			||||||
 | 
					                fflush(stdout);
 | 
				
			||||||
 | 
					                string_push_back(input, c);
 | 
				
			||||||
 | 
					            } else if(c == CliSymbolAsciiCR) {
 | 
				
			||||||
 | 
					                printf("\r\n");
 | 
				
			||||||
 | 
					                string_push_back(input, '\n');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        size_t size = string_size(input);
 | 
				
			||||||
 | 
					        if(size > 0) {
 | 
				
			||||||
 | 
					            // C-string null termination and block alignments
 | 
				
			||||||
 | 
					            size++;
 | 
				
			||||||
 | 
					            size_t remain = size % 16;
 | 
				
			||||||
 | 
					            if(remain) {
 | 
				
			||||||
 | 
					                size = size - remain + 16;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            string_reserve(input, size);
 | 
				
			||||||
 | 
					            uint8_t* output = furi_alloc(size);
 | 
				
			||||||
 | 
					            if(!furi_hal_crypto_encrypt((const uint8_t*)string_get_cstr(input), output, size)) {
 | 
				
			||||||
 | 
					                printf("Failed to encrypt input");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                printf("Hex-encoded encrypted data:\r\n");
 | 
				
			||||||
 | 
					                for(size_t i = 0; i < size; i++) {
 | 
				
			||||||
 | 
					                    printf("%02x", output[i]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                printf("\r\n");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            free(output);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            printf("No input");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        string_clear(input);
 | 
				
			||||||
 | 
					    } while(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(key_loaded) {
 | 
				
			||||||
 | 
					        furi_hal_crypto_store_unload_key(key_slot);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_cli_decrypt(Cli* cli, string_t args) {
 | 
				
			||||||
 | 
					    int key_slot = 0;
 | 
				
			||||||
 | 
					    bool key_loaded = false;
 | 
				
			||||||
 | 
					    uint8_t iv[16];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        if(!args_read_int_and_trim(args, &key_slot) || !(key_slot > 0 && key_slot <= 100)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing slot, expected int 1-100");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!args_read_hex_bytes(args, iv, 16)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing IV, expected 16 bytes in hex");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
 | 
				
			||||||
 | 
					            printf("Unable to load key from slot %d", key_slot);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        key_loaded = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        printf("Enter Hex-encoded data and press Ctrl+C to complete decryption:\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        string_t hex_input;
 | 
				
			||||||
 | 
					        string_init(hex_input);
 | 
				
			||||||
 | 
					        char c;
 | 
				
			||||||
 | 
					        while(cli_read(cli, (uint8_t*)&c, 1) == 1) {
 | 
				
			||||||
 | 
					            if(c == CliSymbolAsciiETX) {
 | 
				
			||||||
 | 
					                printf("\r\n");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            } else if(c >= 0x20 && c < 0x7F) {
 | 
				
			||||||
 | 
					                putc(c, stdout);
 | 
				
			||||||
 | 
					                fflush(stdout);
 | 
				
			||||||
 | 
					                string_push_back(hex_input, c);
 | 
				
			||||||
 | 
					            } else if(c == CliSymbolAsciiCR) {
 | 
				
			||||||
 | 
					                printf("\r\n");
 | 
				
			||||||
 | 
					                string_push_back(hex_input, '\n');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        string_strim(hex_input);
 | 
				
			||||||
 | 
					        size_t hex_size = string_size(hex_input);
 | 
				
			||||||
 | 
					        if(hex_size > 0 && hex_size % 2 == 0) {
 | 
				
			||||||
 | 
					            size_t size = hex_size / 2;
 | 
				
			||||||
 | 
					            uint8_t* input = furi_alloc(size);
 | 
				
			||||||
 | 
					            uint8_t* output = furi_alloc(size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(args_read_hex_bytes(hex_input, input, size) &&
 | 
				
			||||||
 | 
					               furi_hal_crypto_decrypt(input, output, size)) {
 | 
				
			||||||
 | 
					                printf("Decrypted data:\r\n");
 | 
				
			||||||
 | 
					                printf("%s\r\n", output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                printf("Failed to decrypt input");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            free(input);
 | 
				
			||||||
 | 
					            free(output);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            printf("Invalid or empty input");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        string_clear(hex_input);
 | 
				
			||||||
 | 
					    } while(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(key_loaded) {
 | 
				
			||||||
 | 
					        furi_hal_crypto_store_unload_key(key_slot);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_cli_has_key(Cli* cli, string_t args) {
 | 
				
			||||||
 | 
					    int key_slot = 0;
 | 
				
			||||||
 | 
					    uint8_t iv[16];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        if(!args_read_int_and_trim(args, &key_slot) || !(key_slot > 0 && key_slot <= 100)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing slot, expected int 1-100");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
 | 
				
			||||||
 | 
					            printf("Unable to load key from slot %d", key_slot);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        printf("Successfully loaded key from slot %d", key_slot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        furi_hal_crypto_store_unload_key(key_slot);
 | 
				
			||||||
 | 
					    } while(0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_cli_store_key(Cli* cli, string_t args) {
 | 
				
			||||||
 | 
					    int key_size = 0;
 | 
				
			||||||
 | 
					    string_t key_type;
 | 
				
			||||||
 | 
					    string_init(key_type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uint8_t data[32 + 12] = {};
 | 
				
			||||||
 | 
					    FuriHalCryptoKey key;
 | 
				
			||||||
 | 
					    key.data = data;
 | 
				
			||||||
 | 
					    size_t data_size = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        if(!args_read_string_and_trim(args, key_type)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing key type, expected master, simple or encrypted");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(string_cmp_str(key_type, "master") == 0) {
 | 
				
			||||||
 | 
					            key.type = FuriHalCryptoKeyTypeMaster;
 | 
				
			||||||
 | 
					        } else if(string_cmp_str(key_type, "simple") == 0) {
 | 
				
			||||||
 | 
					            key.type = FuriHalCryptoKeyTypeSimple;
 | 
				
			||||||
 | 
					        } else if(string_cmp_str(key_type, "encrypted") == 0) {
 | 
				
			||||||
 | 
					            key.type = FuriHalCryptoKeyTypeEncrypted;
 | 
				
			||||||
 | 
					            data_size += 12;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing key type, expected master, simple or encrypted");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!args_read_int_and_trim(args, &key_size)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing key size, expected 128 or 256");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(key_size == 128) {
 | 
				
			||||||
 | 
					            key.size = FuriHalCryptoKeySize128;
 | 
				
			||||||
 | 
					            data_size += 16;
 | 
				
			||||||
 | 
					        } else if(key_size == 256) {
 | 
				
			||||||
 | 
					            key.size = FuriHalCryptoKeySize256;
 | 
				
			||||||
 | 
					            data_size += 32;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing key size, expected 128 or 256");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(!args_read_hex_bytes(args, data, data_size)) {
 | 
				
			||||||
 | 
					            printf("Incorrect or missing key data, expected hex encoded key with or without IV.");
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        uint8_t slot;
 | 
				
			||||||
 | 
					        if(furi_hal_crypto_store_add_key(&key, &slot)) {
 | 
				
			||||||
 | 
					            printf("Success. Stored to slot: %d", slot);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            printf("Failure");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } while(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    string_clear(key_type);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_cli(Cli* cli, string_t args, void* context) {
 | 
				
			||||||
 | 
					    string_t cmd;
 | 
				
			||||||
 | 
					    string_init(cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        if(!args_read_string_and_trim(args, cmd)) {
 | 
				
			||||||
 | 
					            crypto_cli_print_usage();
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(string_cmp_str(cmd, "encrypt") == 0) {
 | 
				
			||||||
 | 
					            crypto_cli_encrypt(cli, args);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(string_cmp_str(cmd, "decrypt") == 0) {
 | 
				
			||||||
 | 
					            crypto_cli_decrypt(cli, args);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(string_cmp_str(cmd, "has_key") == 0) {
 | 
				
			||||||
 | 
					            crypto_cli_has_key(cli, args);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(string_cmp_str(cmd, "store_key") == 0) {
 | 
				
			||||||
 | 
					            crypto_cli_store_key(cli, args);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        crypto_cli_print_usage();
 | 
				
			||||||
 | 
					    } while(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    string_clear(cmd);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_cli_init() {
 | 
				
			||||||
 | 
					    Cli* cli = furi_record_open("cli");
 | 
				
			||||||
 | 
					    cli_add_command(cli, "crypto", CliCommandFlagDefault, crypto_cli, NULL);
 | 
				
			||||||
 | 
					    furi_record_close("cli");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -116,7 +116,7 @@ void canvas_set_font(Canvas* canvas, Font font) {
 | 
				
			|||||||
    } else if(font == FontKeyboard) {
 | 
					    } else if(font == FontKeyboard) {
 | 
				
			||||||
        u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mf);
 | 
					        u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mf);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -150,7 +150,7 @@ void canvas_draw_str_aligned(
 | 
				
			|||||||
        x -= (u8g2_GetStrWidth(&canvas->fb, str) / 2);
 | 
					        x -= (u8g2_GetStrWidth(&canvas->fb, str) / 2);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -164,7 +164,7 @@ void canvas_draw_str_aligned(
 | 
				
			|||||||
        y += (u8g2_GetAscent(&canvas->fb) / 2);
 | 
					        y += (u8g2_GetAscent(&canvas->fb) / 2);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -118,7 +118,7 @@ static void widget_add_element(Widget* widget, WidgetElement* element) {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void widget_add_string_multi_element(
 | 
					void widget_add_string_multiline_element(
 | 
				
			||||||
    Widget* widget,
 | 
					    Widget* widget,
 | 
				
			||||||
    uint8_t x,
 | 
					    uint8_t x,
 | 
				
			||||||
    uint8_t y,
 | 
					    uint8_t y,
 | 
				
			||||||
@ -127,9 +127,9 @@ void widget_add_string_multi_element(
 | 
				
			|||||||
    Font font,
 | 
					    Font font,
 | 
				
			||||||
    const char* text) {
 | 
					    const char* text) {
 | 
				
			||||||
    furi_assert(widget);
 | 
					    furi_assert(widget);
 | 
				
			||||||
    WidgetElement* string_multi_element =
 | 
					    WidgetElement* string_multiline_element =
 | 
				
			||||||
        widget_element_string_multi_create(x, y, horizontal, vertical, font, text);
 | 
					        widget_element_string_multiline_create(x, y, horizontal, vertical, font, text);
 | 
				
			||||||
    widget_add_element(widget, string_multi_element);
 | 
					    widget_add_element(widget, string_multiline_element);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void widget_add_string_element(
 | 
					void widget_add_string_element(
 | 
				
			||||||
 | 
				
			|||||||
@ -34,7 +34,7 @@ View* widget_get_view(Widget* widget);
 | 
				
			|||||||
 * @param vertical - Align instance
 | 
					 * @param vertical - Align instance
 | 
				
			||||||
 * @param font Font instance
 | 
					 * @param font Font instance
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void widget_add_string_multi_element(
 | 
					void widget_add_string_multiline_element(
 | 
				
			||||||
    Widget* widget,
 | 
					    Widget* widget,
 | 
				
			||||||
    uint8_t x,
 | 
					    uint8_t x,
 | 
				
			||||||
    uint8_t y,
 | 
					    uint8_t y,
 | 
				
			||||||
 | 
				
			|||||||
@ -32,26 +32,15 @@ static bool gui_button_input(InputEvent* event, WidgetElement* element) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if(model->callback == NULL) return consumed;
 | 
					    if(model->callback == NULL) return consumed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(event->key == InputKeyOk && event->type == InputTypePress &&
 | 
					    if((model->button_type == GuiButtonTypeLeft) && (event->key == InputKeyLeft)) {
 | 
				
			||||||
       model->button_type == GuiButtonTypeCenter) {
 | 
					        model->callback(model->button_type, event->type, model->context);
 | 
				
			||||||
        model->callback(GuiButtonTypeCenterPress, model->context);
 | 
					 | 
				
			||||||
        consumed = true;
 | 
					        consumed = true;
 | 
				
			||||||
    } else if(
 | 
					    } else if((model->button_type == GuiButtonTypeRight) && (event->key == InputKeyRight)) {
 | 
				
			||||||
        event->key == InputKeyOk && event->type == InputTypeRelease &&
 | 
					        model->callback(model->button_type, event->type, model->context);
 | 
				
			||||||
        model->button_type == GuiButtonTypeCenter) {
 | 
					        consumed = true;
 | 
				
			||||||
        model->callback(GuiButtonTypeCenterRelease, model->context);
 | 
					    } else if((model->button_type == GuiButtonTypeCenter) && (event->key == InputKeyOk)) {
 | 
				
			||||||
 | 
					        model->callback(model->button_type, event->type, model->context);
 | 
				
			||||||
        consumed = true;
 | 
					        consumed = true;
 | 
				
			||||||
    } else if(event->type == InputTypeShort) {
 | 
					 | 
				
			||||||
        if((model->button_type == GuiButtonTypeLeft) && (event->key == InputKeyLeft)) {
 | 
					 | 
				
			||||||
            model->callback(model->button_type, model->context);
 | 
					 | 
				
			||||||
            consumed = true;
 | 
					 | 
				
			||||||
        } else if((model->button_type == GuiButtonTypeRight) && (event->key == InputKeyRight)) {
 | 
					 | 
				
			||||||
            model->callback(model->button_type, model->context);
 | 
					 | 
				
			||||||
            consumed = true;
 | 
					 | 
				
			||||||
        } else if((model->button_type == GuiButtonTypeCenter) && (event->key == InputKeyOk)) {
 | 
					 | 
				
			||||||
            model->callback(model->button_type, model->context);
 | 
					 | 
				
			||||||
            consumed = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return consumed;
 | 
					    return consumed;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,16 +1,15 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include <furi.h>
 | 
					#include <furi.h>
 | 
				
			||||||
#include <gui/view.h>
 | 
					#include <gui/view.h>
 | 
				
			||||||
 | 
					#include <input/input.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef enum {
 | 
					typedef enum {
 | 
				
			||||||
    GuiButtonTypeLeft,
 | 
					    GuiButtonTypeLeft,
 | 
				
			||||||
    GuiButtonTypeCenter,
 | 
					    GuiButtonTypeCenter,
 | 
				
			||||||
    GuiButtonTypeRight,
 | 
					    GuiButtonTypeRight,
 | 
				
			||||||
    GuiButtonTypeCenterPress,
 | 
					 | 
				
			||||||
    GuiButtonTypeCenterRelease,
 | 
					 | 
				
			||||||
} GuiButtonType;
 | 
					} GuiButtonType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef void (*ButtonCallback)(GuiButtonType result, void* context);
 | 
					typedef void (*ButtonCallback)(GuiButtonType result, InputType type, void* context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct WidgetElement WidgetElement;
 | 
					typedef struct WidgetElement WidgetElement;
 | 
				
			||||||
typedef struct Widget Widget;
 | 
					typedef struct Widget Widget;
 | 
				
			||||||
@ -31,7 +30,7 @@ struct WidgetElement {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Create multi string element */
 | 
					/* Create multi string element */
 | 
				
			||||||
WidgetElement* widget_element_string_multi_create(
 | 
					WidgetElement* widget_element_string_multiline_create(
 | 
				
			||||||
    uint8_t x,
 | 
					    uint8_t x,
 | 
				
			||||||
    uint8_t y,
 | 
					    uint8_t y,
 | 
				
			||||||
    Align horizontal,
 | 
					    Align horizontal,
 | 
				
			||||||
 | 
				
			|||||||
@ -9,12 +9,12 @@ typedef struct {
 | 
				
			|||||||
    Align vertical;
 | 
					    Align vertical;
 | 
				
			||||||
    Font font;
 | 
					    Font font;
 | 
				
			||||||
    string_t text;
 | 
					    string_t text;
 | 
				
			||||||
} GuiStringMultiModel;
 | 
					} GuiStringMultiLineModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gui_string_multi_draw(Canvas* canvas, WidgetElement* element) {
 | 
					static void gui_string_multiline_draw(Canvas* canvas, WidgetElement* element) {
 | 
				
			||||||
    furi_assert(canvas);
 | 
					    furi_assert(canvas);
 | 
				
			||||||
    furi_assert(element);
 | 
					    furi_assert(element);
 | 
				
			||||||
    GuiStringMultiModel* model = element->model;
 | 
					    GuiStringMultiLineModel* model = element->model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(string_size(model->text)) {
 | 
					    if(string_size(model->text)) {
 | 
				
			||||||
        canvas_set_font(canvas, model->font);
 | 
					        canvas_set_font(canvas, model->font);
 | 
				
			||||||
@ -28,16 +28,16 @@ static void gui_string_multi_draw(Canvas* canvas, WidgetElement* element) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gui_string_multi_free(WidgetElement* gui_string) {
 | 
					static void gui_string_multiline_free(WidgetElement* gui_string) {
 | 
				
			||||||
    furi_assert(gui_string);
 | 
					    furi_assert(gui_string);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GuiStringMultiModel* model = gui_string->model;
 | 
					    GuiStringMultiLineModel* model = gui_string->model;
 | 
				
			||||||
    string_clear(model->text);
 | 
					    string_clear(model->text);
 | 
				
			||||||
    free(gui_string->model);
 | 
					    free(gui_string->model);
 | 
				
			||||||
    free(gui_string);
 | 
					    free(gui_string);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WidgetElement* widget_element_string_multi_create(
 | 
					WidgetElement* widget_element_string_multiline_create(
 | 
				
			||||||
    uint8_t x,
 | 
					    uint8_t x,
 | 
				
			||||||
    uint8_t y,
 | 
					    uint8_t y,
 | 
				
			||||||
    Align horizontal,
 | 
					    Align horizontal,
 | 
				
			||||||
@ -47,7 +47,7 @@ WidgetElement* widget_element_string_multi_create(
 | 
				
			|||||||
    furi_assert(text);
 | 
					    furi_assert(text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Allocate and init model
 | 
					    // Allocate and init model
 | 
				
			||||||
    GuiStringMultiModel* model = furi_alloc(sizeof(GuiStringMultiModel));
 | 
					    GuiStringMultiLineModel* model = furi_alloc(sizeof(GuiStringMultiLineModel));
 | 
				
			||||||
    model->x = x;
 | 
					    model->x = x;
 | 
				
			||||||
    model->y = y;
 | 
					    model->y = y;
 | 
				
			||||||
    model->horizontal = horizontal;
 | 
					    model->horizontal = horizontal;
 | 
				
			||||||
@ -59,8 +59,8 @@ WidgetElement* widget_element_string_multi_create(
 | 
				
			|||||||
    WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
 | 
					    WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
 | 
				
			||||||
    gui_string->parent = NULL;
 | 
					    gui_string->parent = NULL;
 | 
				
			||||||
    gui_string->input = NULL;
 | 
					    gui_string->input = NULL;
 | 
				
			||||||
    gui_string->draw = gui_string_multi_draw;
 | 
					    gui_string->draw = gui_string_multiline_draw;
 | 
				
			||||||
    gui_string->free = gui_string_multi_free;
 | 
					    gui_string->free = gui_string_multiline_free;
 | 
				
			||||||
    gui_string->model = model;
 | 
					    gui_string->model = model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return gui_string;
 | 
					    return gui_string;
 | 
				
			||||||
@ -35,7 +35,7 @@ ValueMutex* menu_init() {
 | 
				
			|||||||
    ValueMutex* menu_mutex = furi_alloc(sizeof(ValueMutex));
 | 
					    ValueMutex* menu_mutex = furi_alloc(sizeof(ValueMutex));
 | 
				
			||||||
    if(menu_mutex == NULL || !init_mutex(menu_mutex, menu, sizeof(Menu))) {
 | 
					    if(menu_mutex == NULL || !init_mutex(menu_mutex, menu, sizeof(Menu))) {
 | 
				
			||||||
        printf("[menu_task] cannot create menu mutex\r\n");
 | 
					        printf("[menu_task] cannot create menu mutex\r\n");
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // OpenGui record
 | 
					    // OpenGui record
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,10 @@
 | 
				
			|||||||
#include "../nfc_i.h"
 | 
					#include "../nfc_i.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_delete_widget_callback(GuiButtonType result, void* context) {
 | 
					void nfc_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
 | 
				
			||||||
    Nfc* nfc = (Nfc*)context;
 | 
					    Nfc* nfc = (Nfc*)context;
 | 
				
			||||||
 | 
					    if(type == InputTypeShort) {
 | 
				
			||||||
    view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
 | 
					        view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_delete_on_enter(void* context) {
 | 
					void nfc_scene_delete_on_enter(void* context) {
 | 
				
			||||||
 | 
				
			|||||||
@ -7,9 +7,11 @@ enum {
 | 
				
			|||||||
    NfcSceneDeviceInfoData,
 | 
					    NfcSceneDeviceInfoData,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_device_info_widget_callback(GuiButtonType result, void* context) {
 | 
					void nfc_scene_device_info_widget_callback(GuiButtonType result, InputType type, void* context) {
 | 
				
			||||||
    Nfc* nfc = context;
 | 
					    Nfc* nfc = context;
 | 
				
			||||||
    view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
 | 
					    if(type == InputTypeShort) {
 | 
				
			||||||
 | 
					        view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_device_info_dialog_callback(DialogExResult result, void* context) {
 | 
					void nfc_scene_device_info_dialog_callback(DialogExResult result, void* context) {
 | 
				
			||||||
@ -22,9 +24,11 @@ void nfc_scene_device_info_text_box_callback(void* context) {
 | 
				
			|||||||
    view_dispatcher_send_custom_event(nfc->view_dispatcher, NFC_SCENE_DEVICE_INFO_BACK_EVENT);
 | 
					    view_dispatcher_send_custom_event(nfc->view_dispatcher, NFC_SCENE_DEVICE_INFO_BACK_EVENT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_device_info_bank_card_callback(GuiButtonType result, void* context) {
 | 
					void nfc_scene_device_info_bank_card_callback(GuiButtonType result, InputType type, void* context) {
 | 
				
			||||||
    Nfc* nfc = context;
 | 
					    Nfc* nfc = context;
 | 
				
			||||||
    view_dispatcher_send_custom_event(nfc->view_dispatcher, NFC_SCENE_DEVICE_INFO_BACK_EVENT);
 | 
					    if(type == InputTypeShort) {
 | 
				
			||||||
 | 
					        view_dispatcher_send_custom_event(nfc->view_dispatcher, NFC_SCENE_DEVICE_INFO_BACK_EVENT);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_device_info_on_enter(void* context) {
 | 
					void nfc_scene_device_info_on_enter(void* context) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,14 @@
 | 
				
			|||||||
#include "../nfc_i.h"
 | 
					#include "../nfc_i.h"
 | 
				
			||||||
#include "../helpers/nfc_emv_parser.h"
 | 
					#include "../helpers/nfc_emv_parser.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_read_emv_data_success_widget_callback(GuiButtonType result, void* context) {
 | 
					void nfc_scene_read_emv_data_success_widget_callback(
 | 
				
			||||||
 | 
					    GuiButtonType result,
 | 
				
			||||||
 | 
					    InputType type,
 | 
				
			||||||
 | 
					    void* context) {
 | 
				
			||||||
    Nfc* nfc = (Nfc*)context;
 | 
					    Nfc* nfc = (Nfc*)context;
 | 
				
			||||||
 | 
					    if(type == InputTypeShort) {
 | 
				
			||||||
    view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
 | 
					        view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void nfc_scene_read_emv_data_success_on_enter(void* context) {
 | 
					void nfc_scene_read_emv_data_success_on_enter(void* context) {
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
 | 
				
			|||||||
        } else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
					        } else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
				
			||||||
            snprintf(preset_str, sizeof(preset_str), "FM");
 | 
					            snprintf(preset_str, sizeof(preset_str), "FM");
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            furi_check(0);
 | 
					            furi_crash(NULL);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        subghz_receiver_add_data_statusbar(
 | 
					        subghz_receiver_add_data_statusbar(
 | 
				
			||||||
            subghz->subghz_receiver, frequency_str, preset_str, string_get_cstr(history_stat_str));
 | 
					            subghz->subghz_receiver, frequency_str, preset_str, string_get_cstr(history_stat_str));
 | 
				
			||||||
@ -46,7 +46,7 @@ void subghz_scene_add_to_history_callback(SubGhzProtocolCommon* parser, void* co
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if(subghz_history_add_to_history(
 | 
					    if(subghz_history_add_to_history(
 | 
				
			||||||
           subghz->txrx->history, parser, subghz->txrx->frequency, subghz->txrx->preset)) {
 | 
					           subghz->txrx->history, parser, subghz->txrx->frequency, subghz->txrx->preset)) {
 | 
				
			||||||
        subghz_protocol_reset(subghz->txrx->protocol);
 | 
					        subghz_parser_reset(subghz->txrx->parser);
 | 
				
			||||||
        string_clean(str_buff);
 | 
					        string_clean(str_buff);
 | 
				
			||||||
        subghz_history_get_text_item_menu(
 | 
					        subghz_history_get_text_item_menu(
 | 
				
			||||||
            subghz->txrx->history, str_buff, subghz_history_get_item(subghz->txrx->history) - 1);
 | 
					            subghz->txrx->history, str_buff, subghz_history_get_item(subghz->txrx->history) - 1);
 | 
				
			||||||
@ -79,23 +79,18 @@ const void subghz_scene_receiver_on_enter(void* context) {
 | 
				
			|||||||
    string_clear(str_buff);
 | 
					    string_clear(str_buff);
 | 
				
			||||||
    subghz_scene_receiver_update_statusbar(subghz);
 | 
					    subghz_scene_receiver_update_statusbar(subghz);
 | 
				
			||||||
    subghz_receiver_set_callback(subghz->subghz_receiver, subghz_scene_receiver_callback, subghz);
 | 
					    subghz_receiver_set_callback(subghz->subghz_receiver, subghz_scene_receiver_callback, subghz);
 | 
				
			||||||
    subghz_protocol_enable_dump(
 | 
					    subghz_parser_enable_dump(subghz->txrx->parser, subghz_scene_add_to_history_callback, subghz);
 | 
				
			||||||
        subghz->txrx->protocol, subghz_scene_add_to_history_callback, subghz);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subghz->state_notifications = NOTIFICATION_RX_STATE;
 | 
					    subghz->state_notifications = NOTIFICATION_RX_STATE;
 | 
				
			||||||
    if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
					    if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
				
			||||||
        subghz_rx_end(subghz->txrx->worker);
 | 
					        subghz_rx_end(subghz);
 | 
				
			||||||
        //subghz_sleep();
 | 
					 | 
				
			||||||
        subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
					    if((subghz->txrx->txrx_state == SubGhzTxRxStateIdle) ||
 | 
				
			||||||
        subghz_begin(subghz->txrx->preset);
 | 
					       (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
 | 
				
			||||||
        subghz_rx(subghz->txrx->worker, subghz->txrx->frequency);
 | 
					        subghz_begin(subghz, subghz->txrx->preset);
 | 
				
			||||||
        subghz->txrx->txrx_state = SubGhzTxRxStateRx;
 | 
					        subghz_rx(subghz, subghz->txrx->frequency);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if(subghz->txrx->idx_menu_chosen != 0) {
 | 
					 | 
				
			||||||
        subghz_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    subghz_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewReceiver);
 | 
					    view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewReceiver);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -108,16 +103,15 @@ const bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event
 | 
				
			|||||||
        case SubghzReceverEventBack:
 | 
					        case SubghzReceverEventBack:
 | 
				
			||||||
            // Stop CC1101 Rx
 | 
					            // Stop CC1101 Rx
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
				
			||||||
                subghz_rx_end(subghz->txrx->worker);
 | 
					                subghz_rx_end(subghz);
 | 
				
			||||||
                subghz_sleep();
 | 
					                subghz_sleep(subghz);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            subghz_history_clean(subghz->txrx->history);
 | 
					            subghz_history_clean(subghz->txrx->history);
 | 
				
			||||||
            subghz->txrx->hopper_state = SubGhzHopperStateOFF;
 | 
					            subghz->txrx->hopper_state = SubGhzHopperStateOFF;
 | 
				
			||||||
            subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
 | 
					            subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
 | 
				
			||||||
            subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
 | 
					            subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
 | 
				
			||||||
            subghz->txrx->idx_menu_chosen = 0;
 | 
					            subghz->txrx->idx_menu_chosen = 0;
 | 
				
			||||||
            subghz_protocol_enable_dump(subghz->txrx->protocol, NULL, subghz);
 | 
					            subghz_parser_enable_dump(subghz->txrx->parser, NULL, subghz);
 | 
				
			||||||
            scene_manager_search_and_switch_to_previous_scene(
 | 
					            scene_manager_search_and_switch_to_previous_scene(
 | 
				
			||||||
                subghz->scene_manager, SubGhzSceneStart);
 | 
					                subghz->scene_manager, SubGhzSceneStart);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
@ -129,6 +123,7 @@ const bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case SubghzReceverEventConfig:
 | 
					        case SubghzReceverEventConfig:
 | 
				
			||||||
            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
					            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
				
			||||||
 | 
					            subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver);
 | 
				
			||||||
            scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
 | 
					            scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
@ -137,7 +132,7 @@ const bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    } else if(event.type == SceneManagerEventTypeTick) {
 | 
					    } else if(event.type == SceneManagerEventTypeTick) {
 | 
				
			||||||
        if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
					        if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
				
			||||||
            subghz_hopper_update(subghz->txrx);
 | 
					            subghz_hopper_update(subghz);
 | 
				
			||||||
            subghz_scene_receiver_update_statusbar(subghz);
 | 
					            subghz_scene_receiver_update_statusbar(subghz);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,15 +1,31 @@
 | 
				
			|||||||
#include "../subghz_i.h"
 | 
					#include "../subghz_i.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_scene_receiver_info_callback(GuiButtonType result, void* context) {
 | 
					typedef enum {
 | 
				
			||||||
 | 
					    SubGhzSceneReceiverInfoCustomEventTxStart,
 | 
				
			||||||
 | 
					    SubGhzSceneReceiverInfoCustomEventTxStop,
 | 
				
			||||||
 | 
					    SubGhzSceneReceiverInfoCustomEventSave,
 | 
				
			||||||
 | 
					} SubGhzSceneReceiverInfoCustomEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(context);
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					    SubGhz* subghz = context;
 | 
				
			||||||
    view_dispatcher_send_custom_event(subghz->view_dispatcher, result);
 | 
					
 | 
				
			||||||
 | 
					    if((result == GuiButtonTypeCenter) && (type == InputTypePress)) {
 | 
				
			||||||
 | 
					        view_dispatcher_send_custom_event(
 | 
				
			||||||
 | 
					            subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventTxStart);
 | 
				
			||||||
 | 
					    } else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
 | 
				
			||||||
 | 
					        view_dispatcher_send_custom_event(
 | 
				
			||||||
 | 
					            subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventTxStop);
 | 
				
			||||||
 | 
					    } else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
 | 
				
			||||||
 | 
					        view_dispatcher_send_custom_event(
 | 
				
			||||||
 | 
					            subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventSave);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool subghz_scene_receiver_info_update_parser(void* context) {
 | 
					static bool subghz_scene_receiver_info_update_parser(void* context) {
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					    SubGhz* subghz = context;
 | 
				
			||||||
    subghz->txrx->protocol_result = subghz_protocol_get_by_name(
 | 
					    subghz->txrx->protocol_result = subghz_parser_get_by_name(
 | 
				
			||||||
        subghz->txrx->protocol,
 | 
					        subghz->txrx->parser,
 | 
				
			||||||
        subghz_history_get_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
 | 
					        subghz_history_get_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(subghz->txrx->protocol_result->to_load_protocol != NULL) {
 | 
					    if(subghz->txrx->protocol_result->to_load_protocol != NULL) {
 | 
				
			||||||
@ -44,14 +60,14 @@ const void subghz_scene_receiver_info_on_enter(void* context) {
 | 
				
			|||||||
        } else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
					        } else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
				
			||||||
            snprintf(buffer_str, sizeof(buffer_str), "FM");
 | 
					            snprintf(buffer_str, sizeof(buffer_str), "FM");
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            furi_check(0);
 | 
					            furi_crash(NULL);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        widget_add_string_element(
 | 
					        widget_add_string_element(
 | 
				
			||||||
            subghz->widget, 113, 0, AlignLeft, AlignTop, FontSecondary, buffer_str);
 | 
					            subghz->widget, 113, 0, AlignLeft, AlignTop, FontSecondary, buffer_str);
 | 
				
			||||||
        string_t text;
 | 
					        string_t text;
 | 
				
			||||||
        string_init(text);
 | 
					        string_init(text);
 | 
				
			||||||
        subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, text);
 | 
					        subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, text);
 | 
				
			||||||
        widget_add_string_multi_element(
 | 
					        widget_add_string_multiline_element(
 | 
				
			||||||
            subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text));
 | 
					            subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text));
 | 
				
			||||||
        string_clear(text);
 | 
					        string_clear(text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -83,52 +99,46 @@ const void subghz_scene_receiver_info_on_enter(void* context) {
 | 
				
			|||||||
const bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
 | 
					const bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					    SubGhz* subghz = context;
 | 
				
			||||||
    if(event.type == SceneManagerEventTypeCustom) {
 | 
					    if(event.type == SceneManagerEventTypeCustom) {
 | 
				
			||||||
        if(event.event == GuiButtonTypeCenterPress) {
 | 
					        if(event.event == SubGhzSceneReceiverInfoCustomEventTxStart) {
 | 
				
			||||||
            //CC1101 Stop RX -> Start TX
 | 
					            //CC1101 Stop RX -> Start TX
 | 
				
			||||||
            subghz->state_notifications = NOTIFICATION_TX_STATE;
 | 
					            subghz->state_notifications = NOTIFICATION_TX_STATE;
 | 
				
			||||||
            if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
					            if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
				
			||||||
                subghz->txrx->hopper_state = SubGhzHopperStatePause;
 | 
					                subghz->txrx->hopper_state = SubGhzHopperStatePause;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
				
			||||||
                subghz_rx_end(subghz->txrx->worker);
 | 
					                subghz_rx_end(subghz);
 | 
				
			||||||
                //subghz_sleep();
 | 
					 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(!subghz_scene_receiver_info_update_parser(subghz)) {
 | 
					            if(!subghz_scene_receiver_info_update_parser(subghz)) {
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
				
			||||||
                subghz_tx_start(subghz);
 | 
					                subghz_tx_start(subghz);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateTx;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        } else if(event.event == GuiButtonTypeCenterRelease) {
 | 
					        } else if(event.event == SubGhzSceneReceiverInfoCustomEventTxStop) {
 | 
				
			||||||
            //CC1101 Stop Tx -> Start RX
 | 
					            //CC1101 Stop Tx -> Start RX
 | 
				
			||||||
            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
					            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
 | 
				
			||||||
                subghz_tx_stop(subghz);
 | 
					                subghz_tx_stop(subghz);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
				
			||||||
                subghz_begin(subghz->txrx->preset);
 | 
					                subghz_begin(subghz, subghz->txrx->preset);
 | 
				
			||||||
                subghz_rx(subghz->txrx->worker, subghz->txrx->frequency);
 | 
					                subghz_rx(subghz, subghz->txrx->frequency);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateRx;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
 | 
					            if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
 | 
				
			||||||
                subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
 | 
					                subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            subghz->state_notifications = NOTIFICATION_RX_STATE;
 | 
					            subghz->state_notifications = NOTIFICATION_RX_STATE;
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        } else if(event.event == GuiButtonTypeRight) {
 | 
					        } else if(event.event == SubGhzSceneReceiverInfoCustomEventSave) {
 | 
				
			||||||
            //CC1101 Stop RX -> Save
 | 
					            //CC1101 Stop RX -> Save
 | 
				
			||||||
            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
					            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
				
			||||||
            if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
					            if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
				
			||||||
                subghz->txrx->hopper_state = SubGhzHopperStateOFF;
 | 
					                subghz->txrx->hopper_state = SubGhzHopperStateOFF;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
				
			||||||
                subghz_rx_end(subghz->txrx->worker);
 | 
					                subghz_rx_end(subghz);
 | 
				
			||||||
                subghz_sleep();
 | 
					                subghz_sleep(subghz);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(!subghz_scene_receiver_info_update_parser(subghz)) {
 | 
					            if(!subghz_scene_receiver_info_update_parser(subghz)) {
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
@ -141,7 +151,7 @@ const bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    } else if(event.type == SceneManagerEventTypeTick) {
 | 
					    } else if(event.type == SceneManagerEventTypeTick) {
 | 
				
			||||||
        if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
					        if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
 | 
				
			||||||
            subghz_hopper_update(subghz->txrx);
 | 
					            subghz_hopper_update(subghz);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        switch(subghz->state_notifications) {
 | 
					        switch(subghz->state_notifications) {
 | 
				
			||||||
        case NOTIFICATION_TX_STATE:
 | 
					        case NOTIFICATION_TX_STATE:
 | 
				
			||||||
 | 
				
			|||||||
@ -15,8 +15,7 @@ enum SubmenuIndex {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool subghz_scene_set_type_submenu_to_find_protocol(void* context, const char* protocol_name) {
 | 
					bool subghz_scene_set_type_submenu_to_find_protocol(void* context, const char* protocol_name) {
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					    SubGhz* subghz = context;
 | 
				
			||||||
    subghz->txrx->protocol_result =
 | 
					    subghz->txrx->protocol_result = subghz_parser_get_by_name(subghz->txrx->parser, protocol_name);
 | 
				
			||||||
        subghz_protocol_get_by_name(subghz->txrx->protocol, protocol_name);
 | 
					 | 
				
			||||||
    if(subghz->txrx->protocol_result == NULL) {
 | 
					    if(subghz->txrx->protocol_result == NULL) {
 | 
				
			||||||
        string_set(subghz->error_str, "Protocol not found");
 | 
					        string_set(subghz->error_str, "Protocol not found");
 | 
				
			||||||
        scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
 | 
					        scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
 | 
				
			||||||
@ -142,7 +141,7 @@ const bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event
 | 
				
			|||||||
        case SubmenuIndexGateTX:
 | 
					        case SubmenuIndexGateTX:
 | 
				
			||||||
            if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "GateTX")) {
 | 
					            if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "GateTX")) {
 | 
				
			||||||
                subghz->txrx->protocol_result->code_last_count_bit = 24;
 | 
					                subghz->txrx->protocol_result->code_last_count_bit = 24;
 | 
				
			||||||
                key = (key & 0x00F0FFFF) | 0xF << 16; //btn 0xF, 0xC, 0xA, 0x6
 | 
					                key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?)
 | 
				
			||||||
                subghz->txrx->protocol_result->code_last_found =
 | 
					                subghz->txrx->protocol_result->code_last_found =
 | 
				
			||||||
                    subghz_protocol_common_reverse_key(
 | 
					                    subghz_protocol_common_reverse_key(
 | 
				
			||||||
                        key, subghz->txrx->protocol_result->code_last_count_bit);
 | 
					                        key, subghz->txrx->protocol_result->code_last_count_bit);
 | 
				
			||||||
 | 
				
			|||||||
@ -39,7 +39,7 @@ static void subghz_scene_transmitter_update_data_show(void* context) {
 | 
				
			|||||||
        } else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
					        } else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
				
			||||||
            snprintf(preset_str, sizeof(preset_str), "FM");
 | 
					            snprintf(preset_str, sizeof(preset_str), "FM");
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            furi_check(0);
 | 
					            furi_crash(NULL);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        subghz_transmitter_add_data_to_show(
 | 
					        subghz_transmitter_add_data_to_show(
 | 
				
			||||||
@ -70,21 +70,19 @@ const bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent ev
 | 
				
			|||||||
        if(event.event == SubghzTransmitterEventSendStart) {
 | 
					        if(event.event == SubghzTransmitterEventSendStart) {
 | 
				
			||||||
            subghz->state_notifications = NOTIFICATION_TX_STATE;
 | 
					            subghz->state_notifications = NOTIFICATION_TX_STATE;
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
				
			||||||
                subghz_rx_end(subghz->txrx->worker);
 | 
					                subghz_rx_end(subghz);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
					            if((subghz->txrx->txrx_state == SubGhzTxRxStateIdle) ||
 | 
				
			||||||
 | 
					               (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
 | 
				
			||||||
                subghz_tx_start(subghz);
 | 
					                subghz_tx_start(subghz);
 | 
				
			||||||
                subghz_scene_transmitter_update_data_show(subghz);
 | 
					                subghz_scene_transmitter_update_data_show(subghz);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateTx;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        } else if(event.event == SubghzTransmitterEventSendStop) {
 | 
					        } else if(event.event == SubghzTransmitterEventSendStop) {
 | 
				
			||||||
            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
					            subghz->state_notifications = NOTIFICATION_IDLE_STATE;
 | 
				
			||||||
            if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
 | 
					            if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
 | 
				
			||||||
                subghz_tx_stop(subghz);
 | 
					                subghz_tx_stop(subghz);
 | 
				
			||||||
                subghz_sleep();
 | 
					                subghz_sleep(subghz);
 | 
				
			||||||
                subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        } else if(event.event == SubghzTransmitterEventBack) {
 | 
					        } else if(event.event == SubghzTransmitterEventBack) {
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ const char* const subghz_frequencies_text[] = {
 | 
				
			|||||||
    "387.00",
 | 
					    "387.00",
 | 
				
			||||||
    "433.08",
 | 
					    "433.08",
 | 
				
			||||||
    "433.92",
 | 
					    "433.92",
 | 
				
			||||||
 | 
					    "434.42",
 | 
				
			||||||
    "434.78",
 | 
					    "434.78",
 | 
				
			||||||
    "438.90",
 | 
					    "438.90",
 | 
				
			||||||
    "464.00",
 | 
					    "464.00",
 | 
				
			||||||
@ -26,6 +27,7 @@ const uint32_t subghz_frequencies[] = {
 | 
				
			|||||||
    387000000,
 | 
					    387000000,
 | 
				
			||||||
    433075000, /* LPD433 first */
 | 
					    433075000, /* LPD433 first */
 | 
				
			||||||
    433920000, /* LPD433 mid */
 | 
					    433920000, /* LPD433 mid */
 | 
				
			||||||
 | 
					    434420000,
 | 
				
			||||||
    434775000, /* LPD433 last channels */
 | 
					    434775000, /* LPD433 last channels */
 | 
				
			||||||
    438900000,
 | 
					    438900000,
 | 
				
			||||||
    464000000,
 | 
					    464000000,
 | 
				
			||||||
@ -156,24 +158,24 @@ SubGhz* subghz_alloc() {
 | 
				
			|||||||
    subghz->txrx = furi_alloc(sizeof(SubGhzTxRx));
 | 
					    subghz->txrx = furi_alloc(sizeof(SubGhzTxRx));
 | 
				
			||||||
    subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
 | 
					    subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
 | 
				
			||||||
    subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
 | 
					    subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
 | 
				
			||||||
    subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					    subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
 | 
				
			||||||
    subghz->txrx->hopper_state = SubGhzHopperStateOFF;
 | 
					    subghz->txrx->hopper_state = SubGhzHopperStateOFF;
 | 
				
			||||||
    subghz->txrx->history = subghz_history_alloc();
 | 
					    subghz->txrx->history = subghz_history_alloc();
 | 
				
			||||||
    subghz->txrx->worker = subghz_worker_alloc();
 | 
					    subghz->txrx->worker = subghz_worker_alloc();
 | 
				
			||||||
    subghz->txrx->protocol = subghz_protocol_alloc();
 | 
					    subghz->txrx->parser = subghz_parser_alloc();
 | 
				
			||||||
    subghz_worker_set_overrun_callback(
 | 
					    subghz_worker_set_overrun_callback(
 | 
				
			||||||
        subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_protocol_reset);
 | 
					        subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_parser_reset);
 | 
				
			||||||
    subghz_worker_set_pair_callback(
 | 
					    subghz_worker_set_pair_callback(
 | 
				
			||||||
        subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_protocol_parse);
 | 
					        subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_parse);
 | 
				
			||||||
    subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->protocol);
 | 
					    subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->parser);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Init Error_str
 | 
					    //Init Error_str
 | 
				
			||||||
    string_init(subghz->error_str);
 | 
					    string_init(subghz->error_str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subghz_protocol_load_keeloq_file(subghz->txrx->protocol, "/ext/subghz/keeloq_mfcodes");
 | 
					    subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/keeloq_mfcodes");
 | 
				
			||||||
    subghz_protocol_load_nice_flor_s_file(subghz->txrx->protocol, "/ext/subghz/nice_floor_s_rx");
 | 
					    subghz_parser_load_nice_flor_s_file(subghz->txrx->parser, "/ext/subghz/nice_floor_s_rx");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //subghz_protocol_enable_dump_text(subghz->protocol, subghz_text_callback, subghz);
 | 
					    //subghz_parser_enable_dump_text(subghz->protocol, subghz_text_callback, subghz);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return subghz;
 | 
					    return subghz;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -232,7 +234,7 @@ void subghz_free(SubGhz* subghz) {
 | 
				
			|||||||
    subghz->gui = NULL;
 | 
					    subghz->gui = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Worker & Protocol & History
 | 
					    //Worker & Protocol & History
 | 
				
			||||||
    subghz_protocol_free(subghz->txrx->protocol);
 | 
					    subghz_parser_free(subghz->txrx->parser);
 | 
				
			||||||
    subghz_worker_free(subghz->txrx->worker);
 | 
					    subghz_worker_free(subghz->txrx->worker);
 | 
				
			||||||
    subghz_history_free(subghz->txrx->history);
 | 
					    subghz_history_free(subghz->txrx->history);
 | 
				
			||||||
    free(subghz->txrx);
 | 
					    free(subghz->txrx);
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
#include <furi.h>
 | 
					#include <furi.h>
 | 
				
			||||||
#include <furi-hal.h>
 | 
					#include <furi-hal.h>
 | 
				
			||||||
#include <stream_buffer.h>
 | 
					#include <stream_buffer.h>
 | 
				
			||||||
#include <lib/subghz/protocols/subghz_protocol.h>
 | 
					#include <lib/subghz/subghz_parser.h>
 | 
				
			||||||
#include <lib/subghz/protocols/subghz_protocol_common.h>
 | 
					#include <lib/subghz/protocols/subghz_protocol_common.h>
 | 
				
			||||||
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
 | 
					#include <lib/subghz/protocols/subghz_protocol_princeton.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -205,10 +205,10 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
 | 
				
			|||||||
    instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
 | 
					    instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
 | 
				
			||||||
    furi_check(instance->stream);
 | 
					    furi_check(instance->stream);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SubGhzProtocol* protocol = subghz_protocol_alloc();
 | 
					    SubGhzParser* parser = subghz_parser_alloc();
 | 
				
			||||||
    subghz_protocol_load_keeloq_file(protocol, "/ext/subghz/keeloq_mfcodes");
 | 
					    subghz_parser_load_keeloq_file(parser, "/ext/subghz/keeloq_mfcodes");
 | 
				
			||||||
    subghz_protocol_load_nice_flor_s_file(protocol, "/ext/subghz/nice_floor_s_rx");
 | 
					    subghz_parser_load_nice_flor_s_file(parser, "/ext/subghz/nice_floor_s_rx");
 | 
				
			||||||
    subghz_protocol_enable_dump_text(protocol, subghz_cli_command_rx_text_callback, instance);
 | 
					    subghz_parser_enable_dump_text(parser, subghz_cli_command_rx_text_callback, instance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Configure radio
 | 
					    // Configure radio
 | 
				
			||||||
    furi_hal_subghz_reset();
 | 
					    furi_hal_subghz_reset();
 | 
				
			||||||
@ -228,11 +228,11 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
 | 
				
			|||||||
        if(ret == sizeof(LevelDuration)) {
 | 
					        if(ret == sizeof(LevelDuration)) {
 | 
				
			||||||
            if(level_duration_is_reset(level_duration)) {
 | 
					            if(level_duration_is_reset(level_duration)) {
 | 
				
			||||||
                printf(".");
 | 
					                printf(".");
 | 
				
			||||||
                subghz_protocol_reset(protocol);
 | 
					                subghz_parser_reset(parser);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                bool level = level_duration_get_level(level_duration);
 | 
					                bool level = level_duration_get_level(level_duration);
 | 
				
			||||||
                uint32_t duration = level_duration_get_duration(level_duration);
 | 
					                uint32_t duration = level_duration_get_duration(level_duration);
 | 
				
			||||||
                subghz_protocol_parse(protocol, level, duration);
 | 
					                subghz_parser_parse(parser, level, duration);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -244,7 +244,7 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
 | 
				
			|||||||
    printf("\r\nPackets recieved %u\r\n", instance->packet_count);
 | 
					    printf("\r\nPackets recieved %u\r\n", instance->packet_count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Cleanup
 | 
					    // Cleanup
 | 
				
			||||||
    subghz_protocol_free(protocol);
 | 
					    subghz_parser_free(parser);
 | 
				
			||||||
    vStreamBufferDelete(instance->stream);
 | 
					    vStreamBufferDelete(instance->stream);
 | 
				
			||||||
    free(instance);
 | 
					    free(instance);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -112,5 +112,3 @@ bool subghz_history_add_to_history(
 | 
				
			|||||||
 * @return SubGhzProtocolCommonLoad*
 | 
					 * @return SubGhzProtocolCommonLoad*
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
SubGhzProtocolCommonLoad* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx);
 | 
					SubGhzProtocolCommonLoad* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx);
 | 
				
			||||||
 | 
					 | 
				
			||||||
void subghz_hopper_update(void* context);
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -10,19 +10,23 @@
 | 
				
			|||||||
#include "../notification/notification.h"
 | 
					#include "../notification/notification.h"
 | 
				
			||||||
#include "views/subghz_receiver.h"
 | 
					#include "views/subghz_receiver.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_begin(FuriHalSubGhzPreset preset) {
 | 
					void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset) {
 | 
				
			||||||
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    furi_hal_subghz_reset();
 | 
					    furi_hal_subghz_reset();
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    furi_hal_subghz_idle();
 | 
				
			||||||
    furi_hal_subghz_load_preset(preset);
 | 
					    furi_hal_subghz_load_preset(preset);
 | 
				
			||||||
    hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
 | 
					    hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
 | 
				
			||||||
 | 
					    subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t subghz_rx(void* context, uint32_t frequency) {
 | 
					uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    if(!furi_hal_subghz_is_frequency_valid(frequency)) {
 | 
					    if(!furi_hal_subghz_is_frequency_valid(frequency)) {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    SubGhzWorker* worker = context;
 | 
					    furi_assert(
 | 
				
			||||||
 | 
					        subghz->txrx->txrx_state != SubGhzTxRxStateRx &&
 | 
				
			||||||
 | 
					        subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    furi_hal_subghz_idle();
 | 
				
			||||||
    uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
 | 
					    uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
 | 
				
			||||||
@ -30,45 +34,54 @@ uint32_t subghz_rx(void* context, uint32_t frequency) {
 | 
				
			|||||||
    furi_hal_subghz_flush_rx();
 | 
					    furi_hal_subghz_flush_rx();
 | 
				
			||||||
    furi_hal_subghz_rx();
 | 
					    furi_hal_subghz_rx();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, worker);
 | 
					    furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, subghz->txrx->worker);
 | 
				
			||||||
    subghz_worker_start(worker);
 | 
					    subghz_worker_start(subghz->txrx->worker);
 | 
				
			||||||
 | 
					    subghz->txrx->txrx_state = SubGhzTxRxStateRx;
 | 
				
			||||||
    return value;
 | 
					    return value;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t subghz_tx(uint32_t frequency) {
 | 
					uint32_t subghz_tx(SubGhz* subghz, uint32_t frequency) {
 | 
				
			||||||
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    if(!furi_hal_subghz_is_frequency_valid(frequency)) {
 | 
					    if(!furi_hal_subghz_is_frequency_valid(frequency)) {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    furi_hal_subghz_idle();
 | 
				
			||||||
    uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
 | 
					    uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
 | 
				
			||||||
    hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
 | 
					    hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
 | 
				
			||||||
    hal_gpio_write(&gpio_cc1101_g0, true);
 | 
					    hal_gpio_write(&gpio_cc1101_g0, true);
 | 
				
			||||||
    furi_hal_subghz_tx();
 | 
					    furi_hal_subghz_tx();
 | 
				
			||||||
 | 
					    subghz->txrx->txrx_state = SubGhzTxRxStateTx;
 | 
				
			||||||
    return value;
 | 
					    return value;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_idle(void) {
 | 
					void subghz_idle(SubGhz* subghz) {
 | 
				
			||||||
 | 
					    furi_assert(subghz);
 | 
				
			||||||
 | 
					    furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    furi_hal_subghz_idle();
 | 
				
			||||||
 | 
					    subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_rx_end(void* context) {
 | 
					void subghz_rx_end(SubGhz* subghz) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    SubGhzWorker* worker = context;
 | 
					    furi_assert(subghz->txrx->txrx_state == SubGhzTxRxStateRx);
 | 
				
			||||||
 | 
					    if(subghz_worker_is_running(subghz->txrx->worker)) {
 | 
				
			||||||
    if(subghz_worker_is_running(worker)) {
 | 
					        subghz_worker_stop(subghz->txrx->worker);
 | 
				
			||||||
        subghz_worker_stop(worker);
 | 
					 | 
				
			||||||
        furi_hal_subghz_stop_async_rx();
 | 
					        furi_hal_subghz_stop_async_rx();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    furi_hal_subghz_idle();
 | 
				
			||||||
 | 
					    subghz->txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_sleep(void) {
 | 
					void subghz_sleep(SubGhz* subghz) {
 | 
				
			||||||
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    furi_hal_subghz_sleep();
 | 
					    furi_hal_subghz_sleep();
 | 
				
			||||||
 | 
					    subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_frequency_preset_to_str(void* context, string_t output) {
 | 
					static void subghz_frequency_preset_to_str(SubGhz* subghz, string_t output) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					
 | 
				
			||||||
    string_cat_printf(
 | 
					    string_cat_printf(
 | 
				
			||||||
        output,
 | 
					        output,
 | 
				
			||||||
        "Frequency: %d\n"
 | 
					        "Frequency: %d\n"
 | 
				
			||||||
@ -77,9 +90,9 @@ void subghz_frequency_preset_to_str(void* context, string_t output) {
 | 
				
			|||||||
        (int)subghz->txrx->preset);
 | 
					        (int)subghz->txrx->preset);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_tx_start(void* context) {
 | 
					void subghz_tx_start(SubGhz* subghz) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					
 | 
				
			||||||
    subghz->txrx->encoder = subghz_protocol_encoder_common_alloc();
 | 
					    subghz->txrx->encoder = subghz_protocol_encoder_common_alloc();
 | 
				
			||||||
    subghz->txrx->encoder->repeat = 200; //max repeat with the button held down
 | 
					    subghz->txrx->encoder->repeat = 200; //max repeat with the button held down
 | 
				
			||||||
    //get upload
 | 
					    //get upload
 | 
				
			||||||
@ -87,14 +100,14 @@ void subghz_tx_start(void* context) {
 | 
				
			|||||||
        if(subghz->txrx->protocol_result->get_upload_protocol(
 | 
					        if(subghz->txrx->protocol_result->get_upload_protocol(
 | 
				
			||||||
               subghz->txrx->protocol_result, subghz->txrx->encoder)) {
 | 
					               subghz->txrx->protocol_result, subghz->txrx->encoder)) {
 | 
				
			||||||
            if(subghz->txrx->preset) {
 | 
					            if(subghz->txrx->preset) {
 | 
				
			||||||
                subghz_begin(subghz->txrx->preset);
 | 
					                subghz_begin(subghz, subghz->txrx->preset);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                subghz_begin(FuriHalSubGhzPresetOok270Async);
 | 
					                subghz_begin(subghz, FuriHalSubGhzPresetOok270Async);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(subghz->txrx->frequency) {
 | 
					            if(subghz->txrx->frequency) {
 | 
				
			||||||
                subghz_tx(subghz->txrx->frequency);
 | 
					                subghz_tx(subghz, subghz->txrx->frequency);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                subghz_tx(433920000);
 | 
					                subghz_tx(subghz, 433920000);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Start TX
 | 
					            //Start TX
 | 
				
			||||||
@ -104,15 +117,15 @@ void subghz_tx_start(void* context) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_tx_stop(void* context) {
 | 
					void subghz_tx_stop(SubGhz* subghz) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					    furi_assert(subghz->txrx->txrx_state == SubGhzTxRxStateTx);
 | 
				
			||||||
    //Stop TX
 | 
					    //Stop TX
 | 
				
			||||||
    furi_hal_subghz_stop_async_tx();
 | 
					    furi_hal_subghz_stop_async_tx();
 | 
				
			||||||
    subghz_protocol_encoder_common_free(subghz->txrx->encoder);
 | 
					    subghz_protocol_encoder_common_free(subghz->txrx->encoder);
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    subghz_idle(subghz);
 | 
				
			||||||
    //if protocol dynamic then we save the last upload
 | 
					    //if protocol dynamic then we save the last upload
 | 
				
			||||||
    if(subghz->txrx->protocol_result->type_protocol == TYPE_PROTOCOL_DYNAMIC) {
 | 
					    if(subghz->txrx->protocol_result->type_protocol == SubGhzProtocolCommonTypeDynamic) {
 | 
				
			||||||
        subghz_save_protocol_to_file(subghz, subghz->text_store);
 | 
					        subghz_save_protocol_to_file(subghz, subghz->text_store);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    notification_message(subghz->notifications, &sequence_reset_red);
 | 
					    notification_message(subghz->notifications, &sequence_reset_red);
 | 
				
			||||||
@ -164,7 +177,7 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
 | 
				
			|||||||
        // strlen("Protocol: ") = 10
 | 
					        // strlen("Protocol: ") = 10
 | 
				
			||||||
        string_right(temp_str, 10);
 | 
					        string_right(temp_str, 10);
 | 
				
			||||||
        subghz->txrx->protocol_result =
 | 
					        subghz->txrx->protocol_result =
 | 
				
			||||||
            subghz_protocol_get_by_name(subghz->txrx->protocol, string_get_cstr(temp_str));
 | 
					            subghz_parser_get_by_name(subghz->txrx->parser, string_get_cstr(temp_str));
 | 
				
			||||||
        if(subghz->txrx->protocol_result == NULL) {
 | 
					        if(subghz->txrx->protocol_result == NULL) {
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -186,10 +199,10 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
 | 
				
			|||||||
    return loaded;
 | 
					    return loaded;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool subghz_save_protocol_to_file(void* context, const char* dev_name) {
 | 
					bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    SubGhz* subghz = context;
 | 
					 | 
				
			||||||
    furi_assert(subghz->txrx->protocol_result);
 | 
					    furi_assert(subghz->txrx->protocol_result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FileWorker* file_worker = file_worker_alloc(false);
 | 
					    FileWorker* file_worker = file_worker_alloc(false);
 | 
				
			||||||
    string_t dev_file_name;
 | 
					    string_t dev_file_name;
 | 
				
			||||||
    string_init(dev_file_name);
 | 
					    string_init(dev_file_name);
 | 
				
			||||||
@ -308,7 +321,7 @@ bool subghz_load_protocol_from_file(SubGhz* subghz) {
 | 
				
			|||||||
        // strlen("Protocol: ") = 10
 | 
					        // strlen("Protocol: ") = 10
 | 
				
			||||||
        string_right(temp_str, 10);
 | 
					        string_right(temp_str, 10);
 | 
				
			||||||
        subghz->txrx->protocol_result =
 | 
					        subghz->txrx->protocol_result =
 | 
				
			||||||
            subghz_protocol_get_by_name(subghz->txrx->protocol, string_get_cstr(temp_str));
 | 
					            subghz_parser_get_by_name(subghz->txrx->parser, string_get_cstr(temp_str));
 | 
				
			||||||
        if(subghz->txrx->protocol_result == NULL) {
 | 
					        if(subghz->txrx->protocol_result == NULL) {
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -342,11 +355,10 @@ uint32_t subghz_random_serial(void) {
 | 
				
			|||||||
    return (uint32_t)rand();
 | 
					    return (uint32_t)rand();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_hopper_update(void* context) {
 | 
					void subghz_hopper_update(SubGhz* subghz) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    furi_assert(subghz);
 | 
				
			||||||
    SubGhzTxRx* txrx = context;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch(txrx->hopper_state) {
 | 
					    switch(subghz->txrx->hopper_state) {
 | 
				
			||||||
    case SubGhzHopperStateOFF:
 | 
					    case SubGhzHopperStateOFF:
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
@ -354,8 +366,8 @@ void subghz_hopper_update(void* context) {
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case SubGhzHopperStateRSSITimeOut:
 | 
					    case SubGhzHopperStateRSSITimeOut:
 | 
				
			||||||
        if(txrx->hopper_timeout != 0) {
 | 
					        if(subghz->txrx->hopper_timeout != 0) {
 | 
				
			||||||
            txrx->hopper_timeout--;
 | 
					            subghz->txrx->hopper_timeout--;
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
@ -363,35 +375,33 @@ void subghz_hopper_update(void* context) {
 | 
				
			|||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    float rssi = -127.0f;
 | 
					    float rssi = -127.0f;
 | 
				
			||||||
    if(txrx->hopper_state != SubGhzHopperStateRSSITimeOut) {
 | 
					    if(subghz->txrx->hopper_state != SubGhzHopperStateRSSITimeOut) {
 | 
				
			||||||
        // See RSSI Calculation timings in CC1101 17.3 RSSI
 | 
					        // See RSSI Calculation timings in CC1101 17.3 RSSI
 | 
				
			||||||
        rssi = furi_hal_subghz_get_rssi();
 | 
					        rssi = furi_hal_subghz_get_rssi();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Stay if RSSI is high enough
 | 
					        // Stay if RSSI is high enough
 | 
				
			||||||
        if(rssi > -90.0f) {
 | 
					        if(rssi > -90.0f) {
 | 
				
			||||||
            txrx->hopper_timeout = 10;
 | 
					            subghz->txrx->hopper_timeout = 10;
 | 
				
			||||||
            txrx->hopper_state = SubGhzHopperStateRSSITimeOut;
 | 
					            subghz->txrx->hopper_state = SubGhzHopperStateRSSITimeOut;
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        txrx->hopper_state = SubGhzHopperStateRunnig;
 | 
					        subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Select next frequency
 | 
					    // Select next frequency
 | 
				
			||||||
    if(txrx->hopper_idx_frequency < subghz_hopper_frequencies_count - 1) {
 | 
					    if(subghz->txrx->hopper_idx_frequency < subghz_hopper_frequencies_count - 1) {
 | 
				
			||||||
        txrx->hopper_idx_frequency++;
 | 
					        subghz->txrx->hopper_idx_frequency++;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        txrx->hopper_idx_frequency = 0;
 | 
					        subghz->txrx->hopper_idx_frequency = 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
					    if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
 | 
				
			||||||
        subghz_rx_end(txrx->worker);
 | 
					        subghz_rx_end(subghz);
 | 
				
			||||||
        txrx->txrx_state = SubGhzTxRxStateIdle;
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    if(txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
					    if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
 | 
				
			||||||
        subghz_protocol_reset(txrx->protocol);
 | 
					        subghz_parser_reset(subghz->txrx->parser);
 | 
				
			||||||
        txrx->frequency = subghz_hopper_frequencies[txrx->hopper_idx_frequency];
 | 
					        subghz->txrx->frequency = subghz_hopper_frequencies[subghz->txrx->hopper_idx_frequency];
 | 
				
			||||||
        subghz_rx(txrx->worker, txrx->frequency);
 | 
					        subghz_rx(subghz, subghz->txrx->frequency);
 | 
				
			||||||
        txrx->txrx_state = SubGhzTxRxStateRx;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,8 @@
 | 
				
			|||||||
#include <subghz/scenes/subghz_scene.h>
 | 
					#include <subghz/scenes/subghz_scene.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <lib/subghz/subghz_worker.h>
 | 
					#include <lib/subghz/subghz_worker.h>
 | 
				
			||||||
#include <lib/subghz/protocols/subghz_protocol.h>
 | 
					
 | 
				
			||||||
 | 
					#include <lib/subghz/subghz_parser.h>
 | 
				
			||||||
#include <lib/subghz/protocols/subghz_protocol_common.h>
 | 
					#include <lib/subghz/protocols/subghz_protocol_common.h>
 | 
				
			||||||
#include "subghz_history.h"
 | 
					#include "subghz_history.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -47,6 +48,7 @@ typedef enum {
 | 
				
			|||||||
    SubGhzTxRxStateIdle,
 | 
					    SubGhzTxRxStateIdle,
 | 
				
			||||||
    SubGhzTxRxStateRx,
 | 
					    SubGhzTxRxStateRx,
 | 
				
			||||||
    SubGhzTxRxStateTx,
 | 
					    SubGhzTxRxStateTx,
 | 
				
			||||||
 | 
					    SubGhzTxRxStateSleep,
 | 
				
			||||||
} SubGhzTxRxState;
 | 
					} SubGhzTxRxState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** SubGhzHopperState state */
 | 
					/** SubGhzHopperState state */
 | 
				
			||||||
@ -59,7 +61,7 @@ typedef enum {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
struct SubGhzTxRx {
 | 
					struct SubGhzTxRx {
 | 
				
			||||||
    SubGhzWorker* worker;
 | 
					    SubGhzWorker* worker;
 | 
				
			||||||
    SubGhzProtocol* protocol;
 | 
					    SubGhzParser* parser;
 | 
				
			||||||
    SubGhzProtocolCommon* protocol_result;
 | 
					    SubGhzProtocolCommon* protocol_result;
 | 
				
			||||||
    SubGhzProtocolCommonEncoder* encoder;
 | 
					    SubGhzProtocolCommonEncoder* encoder;
 | 
				
			||||||
    uint32_t frequency;
 | 
					    uint32_t frequency;
 | 
				
			||||||
@ -115,15 +117,14 @@ typedef enum {
 | 
				
			|||||||
    SubGhzViewTestPacket,
 | 
					    SubGhzViewTestPacket,
 | 
				
			||||||
} SubGhzView;
 | 
					} SubGhzView;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void subghz_begin(FuriHalSubGhzPreset preset);
 | 
					void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset);
 | 
				
			||||||
uint32_t subghz_rx(void* context, uint32_t frequency);
 | 
					uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency);
 | 
				
			||||||
uint32_t subghz_tx(uint32_t frequency);
 | 
					void subghz_rx_end(SubGhz* subghz);
 | 
				
			||||||
void subghz_idle(void);
 | 
					void subghz_sleep(SubGhz* subghz);
 | 
				
			||||||
void subghz_rx_end(void* context);
 | 
					void subghz_tx_start(SubGhz* subghz);
 | 
				
			||||||
void subghz_sleep(void);
 | 
					void subghz_tx_stop(SubGhz* subghz);
 | 
				
			||||||
void subghz_tx_start(void* context);
 | 
					 | 
				
			||||||
void subghz_tx_stop(void* context);
 | 
					 | 
				
			||||||
bool subghz_key_load(SubGhz* subghz, const char* file_path);
 | 
					bool subghz_key_load(SubGhz* subghz, const char* file_path);
 | 
				
			||||||
bool subghz_save_protocol_to_file(void* context, const char* dev_name);
 | 
					bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name);
 | 
				
			||||||
bool subghz_load_protocol_from_file(SubGhz* subghz);
 | 
					bool subghz_load_protocol_from_file(SubGhz* subghz);
 | 
				
			||||||
uint32_t subghz_random_serial(void);
 | 
					uint32_t subghz_random_serial(void);
 | 
				
			||||||
 | 
					void subghz_hopper_update(SubGhz* subghz);
 | 
				
			||||||
 | 
				
			|||||||
@ -29,9 +29,9 @@ struct SubGhzReceiverHistory {
 | 
				
			|||||||
typedef struct SubGhzReceiverHistory SubGhzReceiverHistory;
 | 
					typedef struct SubGhzReceiverHistory SubGhzReceiverHistory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const Icon* ReceiverItemIcons[] = {
 | 
					static const Icon* ReceiverItemIcons[] = {
 | 
				
			||||||
    [TYPE_PROTOCOL_UNKNOWN] = &I_Quest_7x8,
 | 
					    [SubGhzProtocolCommonTypeUnknown] = &I_Quest_7x8,
 | 
				
			||||||
    [TYPE_PROTOCOL_STATIC] = &I_Unlock_7x8,
 | 
					    [SubGhzProtocolCommonTypeStatic] = &I_Unlock_7x8,
 | 
				
			||||||
    [TYPE_PROTOCOL_DYNAMIC] = &I_Lock_7x8,
 | 
					    [SubGhzProtocolCommonTypeDynamic] = &I_Lock_7x8,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct SubghzReceiver {
 | 
					struct SubghzReceiver {
 | 
				
			||||||
@ -90,7 +90,13 @@ void subghz_receiver_add_item_to_menu(
 | 
				
			|||||||
                SubGhzReceiverMenuItemArray_push_raw(model->history->data);
 | 
					                SubGhzReceiverMenuItemArray_push_raw(model->history->data);
 | 
				
			||||||
            string_init_set_str(item_menu->item_str, name);
 | 
					            string_init_set_str(item_menu->item_str, name);
 | 
				
			||||||
            item_menu->type = type;
 | 
					            item_menu->type = type;
 | 
				
			||||||
            model->history_item++;
 | 
					            if((model->idx == model->history_item - 1)) {
 | 
				
			||||||
 | 
					                model->history_item++;
 | 
				
			||||||
 | 
					                model->idx++;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                model->history_item++;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    subghz_receiver_update_offset(subghz_receiver);
 | 
					    subghz_receiver_update_offset(subghz_receiver);
 | 
				
			||||||
 | 
				
			|||||||
@ -129,10 +129,7 @@ static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t inp
 | 
				
			|||||||
        for(int i = 0; i < timings_len; ++i) {
 | 
					        for(int i = 0; i < timings_len; ++i) {
 | 
				
			||||||
            message_decoded = irda_decode(decoder_handler, level, timings[i]);
 | 
					            message_decoded = irda_decode(decoder_handler, level, timings[i]);
 | 
				
			||||||
            if((i == timings_len - 2) && level && message_decoded) {
 | 
					            if((i == timings_len - 2) && level && message_decoded) {
 | 
				
			||||||
                /* In case we end with space timing - message can be decoded at last mark.
 | 
					                /* In case we end with space timing - message can be decoded at last mark */
 | 
				
			||||||
                 * Exception - SIRC protocol, which has variable message length (12/15/20),
 | 
					 | 
				
			||||||
                 * and decoder recognizes protocol by silence time before next message
 | 
					 | 
				
			||||||
                 * or by timeout (irda_check_decoder_ready()). */
 | 
					 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            } else if(i < timings_len - 1) {
 | 
					            } else if(i < timings_len - 1) {
 | 
				
			||||||
                mu_check(!message_decoded);
 | 
					                mu_check(!message_decoded);
 | 
				
			||||||
@ -225,17 +222,16 @@ MU_TEST(test_mix) {
 | 
				
			|||||||
    RUN_DECODER(test_decoder_rc6_input1, test_decoder_rc6_expected1);
 | 
					    RUN_DECODER(test_decoder_rc6_input1, test_decoder_rc6_expected1);
 | 
				
			||||||
    RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
 | 
					    RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
 | 
				
			||||||
    RUN_DECODER(test_decoder_sirc_input5, test_decoder_sirc_expected5);
 | 
					    RUN_DECODER(test_decoder_sirc_input5, test_decoder_sirc_expected5);
 | 
				
			||||||
 | 
					    RUN_DECODER(test_decoder_nec_input3, test_decoder_nec_expected3);
 | 
				
			||||||
    RUN_DECODER(test_decoder_rc5_input5, test_decoder_rc5_expected5);
 | 
					    RUN_DECODER(test_decoder_rc5_input5, test_decoder_rc5_expected5);
 | 
				
			||||||
    RUN_DECODER(test_decoder_samsung32_input1, test_decoder_samsung32_expected1);
 | 
					    RUN_DECODER(test_decoder_samsung32_input1, test_decoder_samsung32_expected1);
 | 
				
			||||||
    RUN_DECODER(test_decoder_sirc_input3, test_decoder_sirc_expected3);
 | 
					    RUN_DECODER(test_decoder_sirc_input3, test_decoder_sirc_expected3);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MU_TEST(test_decoder_nec1) {
 | 
					MU_TEST(test_decoder_nec) {
 | 
				
			||||||
    RUN_DECODER(test_decoder_nec_input1, test_decoder_nec_expected1);
 | 
					    RUN_DECODER(test_decoder_nec_input1, test_decoder_nec_expected1);
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
MU_TEST(test_decoder_nec2) {
 | 
					 | 
				
			||||||
    RUN_DECODER(test_decoder_nec_input2, test_decoder_nec_expected2);
 | 
					    RUN_DECODER(test_decoder_nec_input2, test_decoder_nec_expected2);
 | 
				
			||||||
 | 
					    RUN_DECODER(test_decoder_nec_input3, test_decoder_nec_expected3);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MU_TEST(test_decoder_unexpected_end_in_sequence) {
 | 
					MU_TEST(test_decoder_unexpected_end_in_sequence) {
 | 
				
			||||||
@ -295,6 +291,8 @@ MU_TEST(test_encoder_rc6) {
 | 
				
			|||||||
MU_TEST(test_encoder_decoder_all) {
 | 
					MU_TEST(test_encoder_decoder_all) {
 | 
				
			||||||
    RUN_ENCODER_DECODER(test_nec);
 | 
					    RUN_ENCODER_DECODER(test_nec);
 | 
				
			||||||
    RUN_ENCODER_DECODER(test_necext);
 | 
					    RUN_ENCODER_DECODER(test_necext);
 | 
				
			||||||
 | 
					    RUN_ENCODER_DECODER(test_nec42);
 | 
				
			||||||
 | 
					    RUN_ENCODER_DECODER(test_nec42ext);
 | 
				
			||||||
    RUN_ENCODER_DECODER(test_samsung32);
 | 
					    RUN_ENCODER_DECODER(test_samsung32);
 | 
				
			||||||
    RUN_ENCODER_DECODER(test_rc6);
 | 
					    RUN_ENCODER_DECODER(test_rc6);
 | 
				
			||||||
    RUN_ENCODER_DECODER(test_rc5);
 | 
					    RUN_ENCODER_DECODER(test_rc5);
 | 
				
			||||||
@ -312,8 +310,7 @@ MU_TEST_SUITE(test_irda_decoder_encoder) {
 | 
				
			|||||||
    MU_RUN_TEST(test_decoder_rc6);
 | 
					    MU_RUN_TEST(test_decoder_rc6);
 | 
				
			||||||
    MU_RUN_TEST(test_encoder_rc6);
 | 
					    MU_RUN_TEST(test_encoder_rc6);
 | 
				
			||||||
    MU_RUN_TEST(test_decoder_unexpected_end_in_sequence);
 | 
					    MU_RUN_TEST(test_decoder_unexpected_end_in_sequence);
 | 
				
			||||||
    MU_RUN_TEST(test_decoder_nec1);
 | 
					    MU_RUN_TEST(test_decoder_nec);
 | 
				
			||||||
    MU_RUN_TEST(test_decoder_nec2);
 | 
					 | 
				
			||||||
    MU_RUN_TEST(test_decoder_samsung32);
 | 
					    MU_RUN_TEST(test_decoder_samsung32);
 | 
				
			||||||
    MU_RUN_TEST(test_decoder_necext1);
 | 
					    MU_RUN_TEST(test_decoder_necext1);
 | 
				
			||||||
    MU_RUN_TEST(test_mix);
 | 
					    MU_RUN_TEST(test_mix);
 | 
				
			||||||
 | 
				
			|||||||
@ -178,6 +178,45 @@ const IrdaMessage test_decoder_nec_expected2[] = {
 | 
				
			|||||||
    {IrdaProtocolNEC,     0x00,      0x0A,   true},
 | 
					    {IrdaProtocolNEC,     0x00,      0x0A,   true},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const uint32_t test_decoder_nec_input3[] = {
 | 
				
			||||||
 | 
					200000,         8862, 4452, 562, 563, 559, 1681, 563, 1646, 567, 586, 556, 569, 563, 583, 559, 571, 561, 1675, 559, 565, 567, 1673, 561, 561, 561, 592, 561, 565, 567, 579, 563, 567, 565, 584, 558, 1652, 561, 592, 561, 561, 561, 1679, 565, 560, 562, 584, 558, 1659, 564, 585, 557, 566, 566, 1675, 559, 1649, 564, 589, 564, 1649, 564, 1668, 566, 565, 567, 1669, 565,
 | 
				
			||||||
 | 
					    43470,      8896, 4432, 561, 561, 561, 1679, 565, 1648, 565, 581, 561, 568, 564, 586, 567, 558, 564, 1676, 558, 564, 558, 1681, 563, 563, 559, 587, 566, 565, 567, 582, 561, 564, 558, 595, 558, 1650, 563, 590, 563, 563, 559, 1674, 560, 570, 562, 587, 566, 1645, 568, 586, 556, 565, 567, 1672, 562, 1651, 562, 584, 558, 1658, 566, 1671, 563, 561, 561, 1679, 565,
 | 
				
			||||||
 | 
					200000,         8881, 4383, 569, 549, 573, 548, 574, 541, 571, 550, 572, 547, 575, 539, 573, 551, 571, 1651, 573, 545, 567, 554, 568, 548, 574, 1652, 572, 547, 575, 1645, 568, 1661, 573, 545, 567, 1657, 567, 554, 568, 547, 575, 1652, 572, 547, 575, 539, 573, 1657, 567, 550, 572, 545, 577, 1651, 573, 1648, 576, 545, 567, 1659, 575, 1645, 568, 555, 567, 1657, 567,
 | 
				
			||||||
 | 
					    38995,      8883, 4369, 573, 543, 569, 552, 570, 549, 573, 541, 571, 553, 569, 548, 574, 543, 569, 1658, 566, 550, 572, 548, 574, 546, 566, 1653, 571, 553, 569, 1654, 570, 1654, 570, 551, 571, 1651, 573, 547, 575, 545, 567, 1653, 571, 552, 570, 547, 575, 1649, 564, 556, 566, 550, 572, 1655, 569, 1656, 568, 546, 566, 1664, 570, 1653, 571, 547, 565, 1663, 571,
 | 
				
			||||||
 | 
					200000,         8987, 4504, 561, 593, 539, 589, 533, 596, 515, 586, 536, 592, 540, 588, 534, 595, 517, 1713, 541, 1664, 570, 1686, 558, 596, 515, 587, 535, 593, 539, 1691, 543, 1689, 565, 588, 513, 1691, 563, 1668, 617, 1613, 641, 1615, 567, 587, 535, 593, 519, 610, 512, 590, 542, 1714, 510, 593, 539, 1691, 563, 591, 510, 1720, 535, 594, 518, 584, 538, 591, 541,
 | 
				
			||||||
 | 
					    39546,      8990, 4501, 565, 590, 542, 586, 536, 593, 508, 593, 539, 589, 543, 585, 537, 592, 509, 1720, 545, 1660, 615, 1642, 561, 567, 534, 594, 538, 590, 542, 1688, 535, 1696, 558, 595, 517, 1687, 567, 1664, 621, 1635, 619, 1611, 561, 594, 538, 590, 511, 617, 515, 586, 536, 1721, 513, 589, 543, 1687, 568, 587, 514, 1691, 563, 590, 511, 591, 541, 587, 535,
 | 
				
			||||||
 | 
					200000,         8986, 4505, 560, 594, 538, 590, 542, 586, 515, 586, 536, 593, 539, 589, 533, 595, 517, 1714, 540, 587, 535, 594, 518, 1713, 542, 586, 515, 587, 535, 1722, 543, 1662, 562, 592, 540, 1664, 570, 585, 537, 591, 541, 1689, 545, 584, 538, 590, 542, 1688, 536, 593, 539, 589, 512, 590, 542, 586, 536, 1720, 514, 588, 544, 585, 537, 591, 541, 587, 514,
 | 
				
			||||||
 | 
					    40671,      8986, 4505, 560, 594, 538, 590, 542, 586, 515, 587, 535, 593, 539, 589, 533, 595, 516, 1714, 541, 587, 535, 594, 518, 1712, 542, 586, 515, 587, 535, 1722, 543, 1662, 561, 592, 540, 1664, 570, 585, 537, 591, 541, 1689, 545, 584, 538, 590, 542, 1688, 536, 593, 539, 589, 512, 590, 542, 586, 536, 1720, 514, 588, 544, 585, 537, 591, 541, 587, 514,
 | 
				
			||||||
 | 
					200000,         8990, 4500, 566, 1692, 562, 1668, 566, 588, 534, 594, 518, 584, 538, 591, 541, 587, 535, 1669, 565, 589, 543, 1688, 536, 592, 540, 1691, 563, 1667, 567, 1664, 621, 1635, 568, 586, 515, 587, 535, 593, 539, 589, 543, 1662, 562, 592, 540, 588, 534, 594, 518, 585, 537, 591, 541, 587, 514, 587, 535, 594, 538, 590, 542, 586, 515, 586, 536, 593, 539,
 | 
				
			||||||
 | 
					    39544,      8993, 4498, 567, 1690, 564, 1666, 568, 586, 536, 593, 508, 593, 539, 589, 543, 585, 537, 1668, 566, 588, 544, 1687, 537, 591, 541, 1690, 564, 1666, 568, 1663, 561, 1696, 569, 585, 516, 586, 536, 593, 539, 589, 543, 1661, 562, 592, 540, 588, 534, 594, 517, 584, 538, 591, 541, 587, 514, 587, 535, 593, 539, 589, 543, 585, 516, 586, 536, 592, 540,
 | 
				
			||||||
 | 
					200000,         8894, 4456, 589, 1676, 589, 571, 582, 574, 589, 571, 582, 1683, 582, 1677, 588, 1682, 583, 574, 589, 568, 585, 1682, 583, 1678, 587, 1680, 585, 574, 589, 565, 588, 575, 588, 1675, 590, 567, 586, 1681, 584, 571, 582, 1685, 590, 568, 585, 569, 584, 1685, 590, 567, 586, 1678, 587, 574, 589, 1672, 582, 578, 585, 1679, 586, 1674, 591, 572, 591, 1672, 582,
 | 
				
			||||||
 | 
					    39632,      8912, 4464, 560, 1703, 562, 598, 565, 594, 559, 594, 559, 1711, 564, 1698, 567, 1697, 568, 593, 560, 595, 568, 1698, 567, 1698, 567, 1693, 561, 602, 561, 596, 567, 590, 563, 1704, 561, 594, 559, 1707, 568, 591, 562, 1697, 568, 596, 567, 590, 563, 1700, 565, 596, 567, 1693, 561, 599, 564, 1701, 564, 589, 564, 1706, 559, 1704, 561, 597, 566, 1700, 565,
 | 
				
			||||||
 | 
					200000,         9018, 4500, 565, 1666, 568, 1689, 565, 588, 513, 1691, 615, 1616, 618, 1639, 564, 1667, 567, 587, 535, 594, 538, 563, 538, 590, 542, 586, 536, 593, 508, 593, 539, 589, 543, 1688, 535, 592, 540, 588, 544, 585, 537, 591, 510, 1694, 560, 1670, 564, 1693, 562, 1669, 565, 1692, 542, 1689, 565, 588, 534, 595, 517, 585, 537, 591, 541, 587, 535, 568, 544, 584, 538, 591, 541, 1663, 560, 1696, 569, 1662, 562, 1695, 539, 1692, 614, 1616, 566, 1691, 563, 1667, 567,
 | 
				
			||||||
 | 
					    23184,      9012, 4505, 560, 1697, 537, 1693, 561, 593, 508, 1696, 569, 1662, 562, 1695, 560, 1671, 563, 591, 541, 587, 535, 594, 518, 584, 538, 590, 542, 586, 515, 613, 509, 593, 539, 1692, 542, 585, 537, 592, 540, 588, 534, 594, 518, 1687, 567, 1663, 560, 1697, 568, 1662, 562, 1695, 539, 1692, 563, 591, 541, 587, 514, 588, 544, 584, 538, 590, 542, 586, 515, 587, 535, 593, 539, 1666, 568, 1689, 565, 1665, 569, 1688, 536, 1695, 570, 1661, 562, 1694, 561, 1670, 564,
 | 
				
			||||||
 | 
					200000,         8835, 4446, 537, 562, 539, 562, 539, 1663, 540, 1667, 536, 1669, 534, 560, 531, 573, 539, 559, 532, 1672, 531, 570, 531, 564, 537, 563, 538, 561, 540, 1660, 533, 1677, 536, 561, 540, 557, 534, 567, 534, 1668, 535, 1672, 531, 1675, 538, 555, 536, 1674, 539, 1665, 538, 1666, 537, 1671, 532, 563, 538, 1669, 534, 566, 535, 558, 533, 1677, 536, 562, 539, 558, 533, 568, 533, 1668, 535, 566, 535, 1670, 533, 1667, 536, 568, 533, 1671, 532, 1672, 531, 1676, 537,
 | 
				
			||||||
 | 
					    22779,      8870, 4437, 535,
 | 
				
			||||||
 | 
					    92592,      8861, 4414, 538,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const IrdaMessage test_decoder_nec_expected3[] = {
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x286,      0xB649,     false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x286,      0xB649,     false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x6880,     0xB649,     false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x6880,     0xB649,     false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x6380,     0x150F,     false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x6380,     0x150F,     false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x6480,     0x849,      false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x6480,     0x849,      false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x7A83,     0x8,        false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNECext,    0x7A83,     0x8,        false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC,       0x71,       0x4A,       false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC,       0x71,       0x4A,       false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x7B,       0x0,        false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x7B,       0x0,        false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x11C,      0x12,       false},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const IrdaMessage test_nec[] = {
 | 
					const IrdaMessage test_nec[] = {
 | 
				
			||||||
    {IrdaProtocolNEC,     0x00,      0x00,  false},
 | 
					    {IrdaProtocolNEC,     0x00,      0x00,  false},
 | 
				
			||||||
    {IrdaProtocolNEC,     0x01,      0x00,  false},
 | 
					    {IrdaProtocolNEC,     0x01,      0x00,  false},
 | 
				
			||||||
@ -209,4 +248,61 @@ const IrdaMessage test_nec[] = {
 | 
				
			|||||||
    {IrdaProtocolNEC,     0x55,      0x55,  true},
 | 
					    {IrdaProtocolNEC,     0x55,      0x55,  true},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const IrdaMessage test_nec42[] = {
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0000,      0x00,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0001,      0x00,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0001,      0x80,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0000,      0x80,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0000,      0x00,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0000,      0x00,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0000,      0x00,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0000,      0x00,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1FFF,      0xFF,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1FFE,      0xFF,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1FFE,      0x7F,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1FFF,      0x7F,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1FFF,      0xFF,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1FFF,      0xFF,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0AAA,      0x55,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1555,      0xAA,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1555,      0x55,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0AAA,      0xAA,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0AAA,      0xAA,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0AAA,      0xAA,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0AAA,      0xAA,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x0AAA,      0xAA,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1555,      0x55,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1555,      0x55,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1555,      0x55,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42,     0x1555,      0x55,  true},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const IrdaMessage test_nec42ext[] = {
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000000,      0x0000,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000001,      0x0000,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000001,      0x8000,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000000,      0x8000,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000000,      0x0000,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000000,      0x0000,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000000,      0x0000,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x0000000,      0x0000,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x3F000FF,      0xF00F,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x3F000FE,      0xF00F,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x3F000FE,      0x700F,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x3F000FF,      0x700F,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x3F000FF,      0xF00F,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x3F000FF,      0xF00F,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x2AAAAAA,      0x5555,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x1555555,      0xAAAA,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x1555555,      0x5555,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x2AAAAAA,      0xAAAA,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x2AAAAAA,      0xAAAA,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x2AAAAAA,      0xAAAA,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x2AAAAAA,      0xAAAA,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x2AAAAAA,      0xAAAA,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x1555555,      0x5555,  false},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x1555555,      0x5555,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x1555555,      0x5555,  true},
 | 
				
			||||||
 | 
					    {IrdaProtocolNEC42ext,     0x1555555,      0x5555,  true},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -111,147 +111,145 @@ const uint32_t test_decoder_necext_input1[] = {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const IrdaMessage test_decoder_necext_expected1[] = {
 | 
					const IrdaMessage test_decoder_necext_expected1[] = {
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  false},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x7984,    0x12,  true},
 | 
					    {IrdaProtocolNECext,     0x7984,    0xed12,  true},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const IrdaMessage test_necext[] = {
 | 
					const IrdaMessage test_necext[] = {
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0000,      0x00,  false},
 | 
					    {IrdaProtocolNECext,     0x0000,      0x0000,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0001,      0x00,  false},
 | 
					    {IrdaProtocolNECext,     0x0001,      0x0000,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0001,      0x80,  false},
 | 
					    {IrdaProtocolNECext,     0x0001,      0x8000,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0000,      0x80,  false},
 | 
					    {IrdaProtocolNECext,     0x0000,      0x8000,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0000,      0x00,  false},
 | 
					    {IrdaProtocolNECext,     0x0000,      0x0000,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0000,      0x00,  true},
 | 
					    {IrdaProtocolNECext,     0x0000,      0x0000,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0000,      0x00,  false},
 | 
					    {IrdaProtocolNECext,     0x0000,      0x0000,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x0000,      0x00,  true},
 | 
					    {IrdaProtocolNECext,     0x0000,      0x0000,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xFFFF,      0xFF,  false},
 | 
					    {IrdaProtocolNECext,     0xFFFF,      0xFFFF,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xFFFE,      0xFF,  false},
 | 
					    {IrdaProtocolNECext,     0xFFFE,      0xFFFF,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xFFFE,      0x7F,  false},
 | 
					    {IrdaProtocolNECext,     0xFFFE,      0x7FFF,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xFFFF,      0x7F,  false},
 | 
					    {IrdaProtocolNECext,     0xFFFF,      0x7FFF,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xFFFF,      0xFF,  false},
 | 
					    {IrdaProtocolNECext,     0xFFFF,      0xFFFF,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xFFFF,      0xFF,  true},
 | 
					    {IrdaProtocolNECext,     0xFFFF,      0xFFFF,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xAAAA,      0x55,  false},
 | 
					    {IrdaProtocolNECext,     0xAAAA,      0x5555,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x5555,      0xAA,  false},
 | 
					    {IrdaProtocolNECext,     0x5555,      0xAAAA,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x5555,      0x55,  false},
 | 
					    {IrdaProtocolNECext,     0x5555,      0x5555,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xAAAA,      0xAA,  false},
 | 
					    {IrdaProtocolNECext,     0xAAAA,      0xAAAA,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xAAAA,      0xAA,  true},
 | 
					    {IrdaProtocolNECext,     0xAAAA,      0xAAAA,  true},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {IrdaProtocolNECext,     0xAAAA,      0xAA,  false},
 | 
					    {IrdaProtocolNECext,     0xAAAA,      0xAAAA,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xAAAA,      0xAA,  true},
 | 
					    {IrdaProtocolNECext,     0xAAAA,      0xAAAA,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0xAAAA,      0xAA,  true},
 | 
					    {IrdaProtocolNECext,     0xAAAA,      0xAAAA,  true},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {IrdaProtocolNECext,     0x5555,      0x55,  false},
 | 
					    {IrdaProtocolNECext,     0x5555,      0x5555,  false},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x5555,      0x55,  true},
 | 
					    {IrdaProtocolNECext,     0x5555,      0x5555,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x5555,      0x55,  true},
 | 
					    {IrdaProtocolNECext,     0x5555,      0x5555,  true},
 | 
				
			||||||
    {IrdaProtocolNECext,     0x5555,      0x55,  true},
 | 
					    {IrdaProtocolNECext,     0x5555,      0x5555,  true},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -426,20 +426,14 @@ const IrdaMessage test_decoder_sirc_expected5[] = {
 | 
				
			|||||||
    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
 | 
					    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const IrdaMessage test_encoder_sirc_input1[] = {
 | 
					const IrdaMessage test_encoder_sirc_input1[] = {
 | 
				
			||||||
    {IrdaProtocolSIRC, 0xA, 0x55, false},
 | 
					    {IrdaProtocolSIRC, 0xA, 0x55, false},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const uint32_t test_encoder_sirc_expected1[] = {
 | 
					const uint32_t test_encoder_sirc_expected1[] = {
 | 
				
			||||||
10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600,
 | 
					10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const IrdaMessage test_encoder_sirc_input2[] = {
 | 
					const IrdaMessage test_encoder_sirc_input2[] = {
 | 
				
			||||||
    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
 | 
					    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
 | 
				
			||||||
    {IrdaProtocolSIRC15, 0x7D, 0x53, true},
 | 
					    {IrdaProtocolSIRC15, 0x7D, 0x53, true},
 | 
				
			||||||
@ -447,9 +441,9 @@ const IrdaMessage test_encoder_sirc_input2[] = {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const uint32_t test_encoder_sirc_expected2[] = {
 | 
					const uint32_t test_encoder_sirc_expected2[] = {
 | 
				
			||||||
    10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, 600, /* 2 low levels in row */
 | 
					    10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
 | 
				
			||||||
    18000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, 600, /* 2 low levels in row */
 | 
					    18600, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
 | 
				
			||||||
    18000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, 600,
 | 
					    18600, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const IrdaMessage test_sirc[] = {
 | 
					const IrdaMessage test_sirc[] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -3,10 +3,7 @@
 | 
				
			|||||||
#include <furi-hal-console.h>
 | 
					#include <furi-hal-console.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void __furi_abort(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void __furi_print_name(void) {
 | 
					void __furi_print_name(void) {
 | 
				
			||||||
    furi_hal_console_puts("\r\n\033[0;31m[E]");
 | 
					 | 
				
			||||||
    if(task_is_isr_context()) {
 | 
					    if(task_is_isr_context()) {
 | 
				
			||||||
        furi_hal_console_puts("[ISR] ");
 | 
					        furi_hal_console_puts("[ISR] ");
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
@ -19,13 +16,6 @@ void __furi_print_name(void) {
 | 
				
			|||||||
            furi_hal_console_puts("] ");
 | 
					            furi_hal_console_puts("] ");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    furi_hal_console_puts("\033[0m");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void __furi_check(void) {
 | 
					 | 
				
			||||||
    __furi_print_name();
 | 
					 | 
				
			||||||
    furi_hal_console_puts("assertion failed\r\n");
 | 
					 | 
				
			||||||
    __furi_abort();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void __furi_abort(void) {
 | 
					void __furi_abort(void) {
 | 
				
			||||||
@ -33,4 +23,13 @@ void __furi_abort(void) {
 | 
				
			|||||||
    asm("bkpt 1");
 | 
					    asm("bkpt 1");
 | 
				
			||||||
    while(1) {
 | 
					    while(1) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void furi_crash(const char* message) {
 | 
				
			||||||
 | 
					    furi_hal_console_puts("\r\n\033[0;31m[CRASH]");
 | 
				
			||||||
 | 
					    __furi_print_name();
 | 
				
			||||||
 | 
					    furi_hal_console_puts(message ? message : "Programming Error");
 | 
				
			||||||
 | 
					    furi_hal_console_puts("\r\nSystem halted. Connect debugger for more info\r\n");
 | 
				
			||||||
 | 
					    furi_hal_console_puts("\033[0m\r\n");
 | 
				
			||||||
 | 
					    __furi_abort();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -4,40 +4,18 @@
 | 
				
			|||||||
extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Find how to how get function's pretty name
 | 
					/** Check condition and crash if check failed */
 | 
				
			||||||
#ifndef __FURI_CHECK_FUNC
 | 
					#define furi_check(__e) ((__e) ? (void)0 : furi_crash("fury_check failed\r\n"))
 | 
				
			||||||
// Use g++'s demangled names in C++
 | 
					 | 
				
			||||||
#if defined __cplusplus && defined __GNUC__
 | 
					 | 
				
			||||||
#define __FURI_CHECK_FUNC __PRETTY_FUNCTION__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// C99 requires the use of __func__
 | 
					 | 
				
			||||||
#elif __STDC_VERSION__ >= 199901L
 | 
					 | 
				
			||||||
#define __FURI_CHECK_FUNC __func__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Older versions of gcc don't have __func__ but can use __FUNCTION__
 | 
					 | 
				
			||||||
#elif __GNUC__ >= 2
 | 
					 | 
				
			||||||
#define __FURI_CHECK_FUNC __FUNCTION__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// failed to detect __func__ support
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
#define __FURI_CHECK_FUNC ((char*)0)
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
// !__FURI_CHECK_FUNC
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// We have two levels of assertion
 | 
					 | 
				
			||||||
// One - furi_check, which always runs, the only difference is in the level of debug information
 | 
					 | 
				
			||||||
// The second is furi_assert, which doesn't compile in release mode
 | 
					 | 
				
			||||||
#define furi_check(__e) ((__e) ? (void)0 : __furi_check())
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Only in debug build: Assert condition and crash if assert failed  */
 | 
				
			||||||
#ifdef NDEBUG
 | 
					#ifdef NDEBUG
 | 
				
			||||||
#define furi_assert(__e) ((void)0)
 | 
					#define furi_assert(__e) ((void)0)
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#define furi_assert(__e) ((__e) ? (void)0 : __furi_check())
 | 
					#define furi_assert(__e) ((__e) ? (void)0 : furi_crash("furi_assert failed\r\n"))
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
// !NDEBUG
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void __furi_check(void);
 | 
					/** Crash system */
 | 
				
			||||||
 | 
					void furi_crash(const char* message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,54 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    aes.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the aes.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __AES_H__
 | 
					 | 
				
			||||||
#define __AES_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern CRYP_HandleTypeDef hcryp1;
 | 
					 | 
				
			||||||
extern CRYP_HandleTypeDef hcryp2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_AES1_Init(void);
 | 
					 | 
				
			||||||
void MX_AES2_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __AES_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,52 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    pka.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the pka.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __PKA_H__
 | 
					 | 
				
			||||||
#define __PKA_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern PKA_HandleTypeDef hpka;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_PKA_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __PKA_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,50 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rf.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the rf.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __RF_H__
 | 
					 | 
				
			||||||
#define __RF_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_RF_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __RF_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,52 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rng.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the rng.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __RNG_H__
 | 
					 | 
				
			||||||
#define __RNG_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern RNG_HandleTypeDef hrng;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_RNG_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __RNG_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,127 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    aes.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the AES instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "aes.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
CRYP_HandleTypeDef hcryp1;
 | 
					 | 
				
			||||||
__ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END = {
 | 
					 | 
				
			||||||
                            0x00000000,0x00000000,0x00000000,0x00000000};
 | 
					 | 
				
			||||||
CRYP_HandleTypeDef hcryp2;
 | 
					 | 
				
			||||||
__ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END = {
 | 
					 | 
				
			||||||
                            0x00000000,0x00000000,0x00000000,0x00000000};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* AES1 init function */
 | 
					 | 
				
			||||||
void MX_AES1_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hcryp1.Instance = AES1;
 | 
					 | 
				
			||||||
  hcryp1.Init.DataType = CRYP_DATATYPE_32B;
 | 
					 | 
				
			||||||
  hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
 | 
					 | 
				
			||||||
  hcryp1.Init.pKey = (uint32_t *)pKeyAES1;
 | 
					 | 
				
			||||||
  hcryp1.Init.Algorithm = CRYP_AES_ECB;
 | 
					 | 
				
			||||||
  hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
 | 
					 | 
				
			||||||
  hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
 | 
					 | 
				
			||||||
  if (HAL_CRYP_Init(&hcryp1) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
/* AES2 init function */
 | 
					 | 
				
			||||||
void MX_AES2_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hcryp2.Instance = AES2;
 | 
					 | 
				
			||||||
  hcryp2.Init.DataType = CRYP_DATATYPE_32B;
 | 
					 | 
				
			||||||
  hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
 | 
					 | 
				
			||||||
  hcryp2.Init.pKey = (uint32_t *)pKeyAES2;
 | 
					 | 
				
			||||||
  hcryp2.Init.Algorithm = CRYP_AES_ECB;
 | 
					 | 
				
			||||||
  hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
 | 
					 | 
				
			||||||
  hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
 | 
					 | 
				
			||||||
  if (HAL_CRYP_Init(&hcryp2) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(crypHandle->Instance==AES1)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspInit 0 */
 | 
					 | 
				
			||||||
    /* AES1 clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES1_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  else if(crypHandle->Instance==AES2)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspInit 0 */
 | 
					 | 
				
			||||||
    /* AES2 clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES2_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(crypHandle->Instance==AES1)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES1_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  else if(crypHandle->Instance==AES2)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES2_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,77 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    pka.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the PKA instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "pka.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
PKA_HandleTypeDef hpka;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* PKA init function */
 | 
					 | 
				
			||||||
void MX_PKA_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hpka.Instance = PKA;
 | 
					 | 
				
			||||||
  if (HAL_PKA_Init(&hpka) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_PKA_MspInit(PKA_HandleTypeDef* pkaHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(pkaHandle->Instance==PKA)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspInit 0 */
 | 
					 | 
				
			||||||
    /* PKA clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_PKA_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_PKA_MspDeInit(PKA_HandleTypeDef* pkaHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(pkaHandle->Instance==PKA)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_PKA_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,37 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rf.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the RF instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "rf.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* RF init function */
 | 
					 | 
				
			||||||
void MX_RF_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,77 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rng.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the RNG instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "rng.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RNG_HandleTypeDef hrng;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* RNG init function */
 | 
					 | 
				
			||||||
void MX_RNG_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hrng.Instance = RNG;
 | 
					 | 
				
			||||||
  if (HAL_RNG_Init(&hrng) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(rngHandle->Instance==RNG)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspInit 0 */
 | 
					 | 
				
			||||||
    /* RNG clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_RNG_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(rngHandle->Instance==RNG)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_RNG_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,140 +0,0 @@
 | 
				
			|||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "app_entry.h"
 | 
					 | 
				
			||||||
#include "app_common.h"
 | 
					 | 
				
			||||||
#include "dbg_trace.h"
 | 
					 | 
				
			||||||
#include "ble.h"
 | 
					 | 
				
			||||||
#include "tl.h"
 | 
					 | 
				
			||||||
#include "app_ble.h"
 | 
					 | 
				
			||||||
#include "shci.h"
 | 
					 | 
				
			||||||
#include "cmsis_os.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <furi-hal.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// PLACE_IN_SECTION("TAG_OTA_END") const uint32_t MagicKeywordValue = 0x94448A29 ;
 | 
					 | 
				
			||||||
// PLACE_IN_SECTION("TAG_OTA_START") const uint32_t MagicKeywordAddress = (uint32_t)&MagicKeywordValue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
osMutexId_t MtxHciId;
 | 
					 | 
				
			||||||
osSemaphoreId_t SemHciId;
 | 
					 | 
				
			||||||
osThreadId_t HciUserEvtProcessId;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const osThreadAttr_t HciUserEvtProcess_attr = {
 | 
					 | 
				
			||||||
    .name = CFG_HCI_USER_EVT_PROCESS_NAME,
 | 
					 | 
				
			||||||
    .attr_bits = CFG_HCI_USER_EVT_PROCESS_ATTR_BITS,
 | 
					 | 
				
			||||||
    .cb_mem = CFG_HCI_USER_EVT_PROCESS_CB_MEM,
 | 
					 | 
				
			||||||
    .cb_size = CFG_HCI_USER_EVT_PROCESS_CB_SIZE,
 | 
					 | 
				
			||||||
    .stack_mem = CFG_HCI_USER_EVT_PROCESS_STACK_MEM,
 | 
					 | 
				
			||||||
    .priority = CFG_HCI_USER_EVT_PROCESS_PRIORITY,
 | 
					 | 
				
			||||||
    .stack_size = CFG_HCI_USER_EVT_PROCESS_STACK_SIZE
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Private function prototypes -----------------------------------------------*/
 | 
					 | 
				
			||||||
static void HciUserEvtProcess(void *argument);
 | 
					 | 
				
			||||||
static void BLE_UserEvtRx( void * pPayload );
 | 
					 | 
				
			||||||
static void BLE_StatusNot( HCI_TL_CmdStatus_t status );
 | 
					 | 
				
			||||||
static void Ble_Tl_Init( void );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool APP_BLE_Init() {
 | 
					 | 
				
			||||||
  SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = {
 | 
					 | 
				
			||||||
    {{0,0,0}},                  /**< Header unused */
 | 
					 | 
				
			||||||
    {0,                         /** pBleBufferAddress not used */
 | 
					 | 
				
			||||||
    0,                          /** BleBufferSize not used */
 | 
					 | 
				
			||||||
    CFG_BLE_NUM_GATT_ATTRIBUTES,
 | 
					 | 
				
			||||||
    CFG_BLE_NUM_GATT_SERVICES,
 | 
					 | 
				
			||||||
    CFG_BLE_ATT_VALUE_ARRAY_SIZE,
 | 
					 | 
				
			||||||
    CFG_BLE_NUM_LINK,
 | 
					 | 
				
			||||||
    CFG_BLE_DATA_LENGTH_EXTENSION,
 | 
					 | 
				
			||||||
    CFG_BLE_PREPARE_WRITE_LIST_SIZE,
 | 
					 | 
				
			||||||
    CFG_BLE_MBLOCK_COUNT,
 | 
					 | 
				
			||||||
    CFG_BLE_MAX_ATT_MTU,
 | 
					 | 
				
			||||||
    CFG_BLE_SLAVE_SCA,
 | 
					 | 
				
			||||||
    CFG_BLE_MASTER_SCA,
 | 
					 | 
				
			||||||
    CFG_BLE_LSE_SOURCE,
 | 
					 | 
				
			||||||
    CFG_BLE_MAX_CONN_EVENT_LENGTH,
 | 
					 | 
				
			||||||
    CFG_BLE_HSE_STARTUP_TIME,
 | 
					 | 
				
			||||||
    CFG_BLE_VITERBI_MODE,
 | 
					 | 
				
			||||||
    CFG_BLE_LL_ONLY,
 | 
					 | 
				
			||||||
    0}
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Initialize Ble Transport Layer
 | 
					 | 
				
			||||||
  Ble_Tl_Init( );
 | 
					 | 
				
			||||||
  // Register the hci transport layer to handle BLE User Asynchronous Events
 | 
					 | 
				
			||||||
  HciUserEvtProcessId = osThreadNew(HciUserEvtProcess, NULL, &HciUserEvtProcess_attr);
 | 
					 | 
				
			||||||
  // Starts the BLE Stack on CPU2
 | 
					 | 
				
			||||||
  return (SHCI_C2_BLE_Init( &ble_init_cmd_packet ) == SHCI_Success);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void Ble_Tl_Init( void ) {
 | 
					 | 
				
			||||||
  HCI_TL_HciInitConf_t Hci_Tl_Init_Conf;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  MtxHciId = osMutexNew( NULL );
 | 
					 | 
				
			||||||
  SemHciId = osSemaphoreNew( 1, 0, NULL ); /*< Create the semaphore and make it busy at initialization */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  Hci_Tl_Init_Conf.p_cmdbuffer = (uint8_t*)&BleCmdBuffer;
 | 
					 | 
				
			||||||
  Hci_Tl_Init_Conf.StatusNotCallBack = BLE_StatusNot;
 | 
					 | 
				
			||||||
  hci_init(BLE_UserEvtRx, (void*) &Hci_Tl_Init_Conf);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void HciUserEvtProcess(void *argument) {
 | 
					 | 
				
			||||||
  UNUSED(argument);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  for(;;)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    osThreadFlagsWait( 1, osFlagsWaitAny, osWaitForever);
 | 
					 | 
				
			||||||
    hci_user_evt_proc( );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*************************************************************
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * WRAP FUNCTIONS
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *************************************************************/
 | 
					 | 
				
			||||||
void hci_notify_asynch_evt(void* pdata) {
 | 
					 | 
				
			||||||
  UNUSED(pdata);
 | 
					 | 
				
			||||||
  osThreadFlagsSet( HciUserEvtProcessId, 1 );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void hci_cmd_resp_release(uint32_t flag) {
 | 
					 | 
				
			||||||
  UNUSED(flag);
 | 
					 | 
				
			||||||
  osSemaphoreRelease( SemHciId );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void hci_cmd_resp_wait(uint32_t timeout) {
 | 
					 | 
				
			||||||
  UNUSED(timeout);
 | 
					 | 
				
			||||||
  osSemaphoreAcquire( SemHciId, osWaitForever );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void BLE_UserEvtRx( void * pPayload ) {
 | 
					 | 
				
			||||||
  SVCCTL_UserEvtFlowStatus_t svctl_return_status;
 | 
					 | 
				
			||||||
  tHCI_UserEvtRxParam *pParam;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  pParam = (tHCI_UserEvtRxParam *)pPayload;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  svctl_return_status = SVCCTL_UserEvtRx((void *)&(pParam->pckt->evtserial));
 | 
					 | 
				
			||||||
  if (svctl_return_status != SVCCTL_UserEvtFlowDisable) {
 | 
					 | 
				
			||||||
    pParam->status = HCI_TL_UserEventFlow_Enable;
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    pParam->status = HCI_TL_UserEventFlow_Disable;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void BLE_StatusNot( HCI_TL_CmdStatus_t status ) {
 | 
					 | 
				
			||||||
  switch (status) {
 | 
					 | 
				
			||||||
    case HCI_TL_CmdBusy:
 | 
					 | 
				
			||||||
      osMutexAcquire( MtxHciId, osWaitForever );
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    case HCI_TL_CmdAvailable:
 | 
					 | 
				
			||||||
      osMutexRelease( MtxHciId );
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    default:
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SVCCTL_ResumeUserEventFlow( void ) {
 | 
					 | 
				
			||||||
  hci_resume_flow();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -427,9 +427,6 @@ typedef enum
 | 
				
			|||||||
#define DBG_TRACE_MSG_QUEUE_SIZE 4096
 | 
					#define DBG_TRACE_MSG_QUEUE_SIZE 4096
 | 
				
			||||||
#define MAX_DBG_TRACE_MSG_SIZE 1024
 | 
					#define MAX_DBG_TRACE_MSG_SIZE 1024
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CFG_LED_SUPPORTED         0
 | 
					 | 
				
			||||||
#define CFG_BUTTON_SUPPORTED      0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/******************************************************************************
 | 
					/******************************************************************************
 | 
				
			||||||
 * FreeRTOS
 | 
					 * FreeRTOS
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
@ -441,34 +438,5 @@ typedef enum
 | 
				
			|||||||
#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY    osPriorityNone
 | 
					#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY    osPriorityNone
 | 
				
			||||||
#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE  (128 * 7)
 | 
					#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE  (128 * 7)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_NAME         "ble_hci_evt"
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_ATTR_BITS    (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_CB_MEM       (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_CB_SIZE      (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_STACK_MEM    (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_PRIORITY     osPriorityNone
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_STACK_SIZE   (128 * 8)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_NAME           "ble_adv_upd"
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_ATTR_BITS      (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_CB_MEM         (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_CB_SIZE        (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_STACK_MEM      (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_PRIORITY       osPriorityNone
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_STACK_SIZE     (128 * 6)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_NAME                  "hrs"
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_ATTR_BITS             (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_CB_MEM                (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_CB_SIZE               (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_STACK_MEM             (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_PRIORITY              osPriorityNone
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_STACK_SIZE            (128 * 8)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef enum {
 | 
					 | 
				
			||||||
    CFG_LPM_APP,
 | 
					 | 
				
			||||||
    CFG_LPM_APP_BLE,
 | 
					 | 
				
			||||||
} CFG_LPM_Id_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define CFG_OTP_BASE_ADDRESS    OTP_AREA_BASE
 | 
					#define CFG_OTP_BASE_ADDRESS    OTP_AREA_BASE
 | 
				
			||||||
#define CFG_OTP_END_ADRESS      OTP_AREA_END_ADDR
 | 
					#define CFG_OTP_END_ADRESS      OTP_AREA_END_ADDR
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
#include "app_common.h"
 | 
					#include "app_common.h"
 | 
				
			||||||
#include "main.h"
 | 
					#include "main.h"
 | 
				
			||||||
#include "app_entry.h"
 | 
					#include "app_entry.h"
 | 
				
			||||||
#include "app_ble.h"
 | 
					#include "ble_app.h"
 | 
				
			||||||
#include "ble.h"
 | 
					#include "ble.h"
 | 
				
			||||||
#include "tl.h"
 | 
					#include "tl.h"
 | 
				
			||||||
#include "cmsis_os.h"
 | 
					#include "cmsis_os.h"
 | 
				
			||||||
@ -47,8 +47,6 @@ void APPE_Init() {
 | 
				
			|||||||
  ble_glue_status = BleGlueStatusStartup;
 | 
					  ble_glue_status = BleGlueStatusStartup;
 | 
				
			||||||
  SystemPower_Config(); /**< Configure the system Power Mode */
 | 
					  SystemPower_Config(); /**< Configure the system Power Mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  HW_TS_Init(hw_ts_InitMode_Full, &hrtc); /**< Initialize the TimerServer */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // APPD_Init();
 | 
					  // APPD_Init();
 | 
				
			||||||
  furi_hal_power_insomnia_enter();
 | 
					  furi_hal_power_insomnia_enter();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -137,7 +135,7 @@ static void APPE_SysUserEvtRx( void * pPayload ) {
 | 
				
			|||||||
  /* Traces channel initialization */
 | 
					  /* Traces channel initialization */
 | 
				
			||||||
  // APPD_EnableCPU2( );
 | 
					  // APPD_EnableCPU2( );
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if (APP_BLE_Init()) {
 | 
					  if(ble_app_init()) {
 | 
				
			||||||
    FURI_LOG_I("Core2", "BLE stack started");
 | 
					    FURI_LOG_I("Core2", "BLE stack started");
 | 
				
			||||||
    ble_glue_status = BleGlueStatusStarted;
 | 
					    ble_glue_status = BleGlueStatusStarted;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@ void battery_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t *) &char_battery_level_uuid,
 | 
					                                (Char_UUID_t *) &char_battery_level_uuid,
 | 
				
			||||||
                                1,
 | 
					                                1,
 | 
				
			||||||
                                CHAR_PROP_READ | CHAR_PROP_NOTIFY,
 | 
					                                CHAR_PROP_READ | CHAR_PROP_NOTIFY,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										119
									
								
								firmware/targets/f6/ble-glue/ble_app.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								firmware/targets/f6/ble-glue/ble_app.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,119 @@
 | 
				
			|||||||
 | 
					#include "ble_app.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "hci_tl.h"
 | 
				
			||||||
 | 
					#include "ble.h"
 | 
				
			||||||
 | 
					#include "shci.h"
 | 
				
			||||||
 | 
					#include "cmsis_os.h"
 | 
				
			||||||
 | 
					#include "gap.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <furi-hal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define BLE_APP_TAG "ble app"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t ble_app_cmd_buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    osMutexId_t hci_mtx;
 | 
				
			||||||
 | 
					    osSemaphoreId_t hci_sem;
 | 
				
			||||||
 | 
					    osThreadId_t hci_thread_id;
 | 
				
			||||||
 | 
					    osThreadAttr_t hci_thread_attr;
 | 
				
			||||||
 | 
					} BleApp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static BleApp* ble_app;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_thread(void *arg);
 | 
				
			||||||
 | 
					static void ble_app_hci_event_handler(void * pPayload);
 | 
				
			||||||
 | 
					static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool ble_app_init() {
 | 
				
			||||||
 | 
					    ble_app = furi_alloc(sizeof(BleApp));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Allocate semafore and mutex for ble command buffer access
 | 
				
			||||||
 | 
					    ble_app->hci_mtx = osMutexNew(NULL);
 | 
				
			||||||
 | 
					    ble_app->hci_sem = osSemaphoreNew(1, 0, NULL);
 | 
				
			||||||
 | 
					    // HCI transport layer thread to handle user asynch events
 | 
				
			||||||
 | 
					    ble_app->hci_thread_attr.name = "ble hci";
 | 
				
			||||||
 | 
					    ble_app->hci_thread_attr.stack_size = 1024;
 | 
				
			||||||
 | 
					    ble_app->hci_thread_id = osThreadNew(ble_app_hci_thread, NULL, &ble_app->hci_thread_attr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Initialize Ble Transport Layer
 | 
				
			||||||
 | 
					    HCI_TL_HciInitConf_t hci_tl_config = {
 | 
				
			||||||
 | 
					        .p_cmdbuffer = (uint8_t*)&ble_app_cmd_buffer,
 | 
				
			||||||
 | 
					        .StatusNotCallBack = ble_app_hci_status_not_handler,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    hci_init(ble_app_hci_event_handler, (void*)&hci_tl_config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Start ble stack on 2nd core
 | 
				
			||||||
 | 
					    SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = {
 | 
				
			||||||
 | 
					        .Header = {{0,0,0}}, // Header unused
 | 
				
			||||||
 | 
					        .Param = {
 | 
				
			||||||
 | 
					            0, // pBleBufferAddress not used
 | 
				
			||||||
 | 
					            0, // BleBufferSize not used
 | 
				
			||||||
 | 
					            CFG_BLE_NUM_GATT_ATTRIBUTES,
 | 
				
			||||||
 | 
					            CFG_BLE_NUM_GATT_SERVICES,
 | 
				
			||||||
 | 
					            CFG_BLE_ATT_VALUE_ARRAY_SIZE,
 | 
				
			||||||
 | 
					            CFG_BLE_NUM_LINK,
 | 
				
			||||||
 | 
					            CFG_BLE_DATA_LENGTH_EXTENSION,
 | 
				
			||||||
 | 
					            CFG_BLE_PREPARE_WRITE_LIST_SIZE,
 | 
				
			||||||
 | 
					            CFG_BLE_MBLOCK_COUNT,
 | 
				
			||||||
 | 
					            CFG_BLE_MAX_ATT_MTU,
 | 
				
			||||||
 | 
					            CFG_BLE_SLAVE_SCA,
 | 
				
			||||||
 | 
					            CFG_BLE_MASTER_SCA,
 | 
				
			||||||
 | 
					            CFG_BLE_LSE_SOURCE,
 | 
				
			||||||
 | 
					            CFG_BLE_MAX_CONN_EVENT_LENGTH,
 | 
				
			||||||
 | 
					            CFG_BLE_HSE_STARTUP_TIME,
 | 
				
			||||||
 | 
					            CFG_BLE_VITERBI_MODE,
 | 
				
			||||||
 | 
					            CFG_BLE_LL_ONLY,
 | 
				
			||||||
 | 
					            0,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    SHCI_CmdStatus_t status = SHCI_C2_BLE_Init(&ble_init_cmd_packet);
 | 
				
			||||||
 | 
					    if(status) {
 | 
				
			||||||
 | 
					        FURI_LOG_E(BLE_APP_TAG, "Failed to start ble stack: %d", status);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return status == SHCI_Success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_thread(void *arg) {
 | 
				
			||||||
 | 
					    while(1) {
 | 
				
			||||||
 | 
					        osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);
 | 
				
			||||||
 | 
					        hci_user_evt_proc();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Called by WPAN lib
 | 
				
			||||||
 | 
					void hci_notify_asynch_evt(void* pdata) {
 | 
				
			||||||
 | 
					    osThreadFlagsSet(ble_app->hci_thread_id, 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void hci_cmd_resp_release(uint32_t flag) {
 | 
				
			||||||
 | 
					    osSemaphoreRelease(ble_app->hci_sem);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void hci_cmd_resp_wait(uint32_t timeout) {
 | 
				
			||||||
 | 
					    osSemaphoreAcquire(ble_app->hci_sem, osWaitForever);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_event_handler( void * pPayload ) {
 | 
				
			||||||
 | 
					    SVCCTL_UserEvtFlowStatus_t svctl_return_status;
 | 
				
			||||||
 | 
					    tHCI_UserEvtRxParam *pParam = (tHCI_UserEvtRxParam *)pPayload;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    svctl_return_status = SVCCTL_UserEvtRx((void *)&(pParam->pckt->evtserial));
 | 
				
			||||||
 | 
					    if (svctl_return_status != SVCCTL_UserEvtFlowDisable) {
 | 
				
			||||||
 | 
					        pParam->status = HCI_TL_UserEventFlow_Enable;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        pParam->status = HCI_TL_UserEventFlow_Disable;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_status_not_handler( HCI_TL_CmdStatus_t status ) {
 | 
				
			||||||
 | 
					    if(status == HCI_TL_CmdBusy) {
 | 
				
			||||||
 | 
					        osMutexAcquire(ble_app->hci_mtx, osWaitForever );
 | 
				
			||||||
 | 
					    } else if(status == HCI_TL_CmdAvailable) {
 | 
				
			||||||
 | 
					        osMutexRelease(ble_app->hci_mtx);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SVCCTL_ResumeUserEventFlow( void ) {
 | 
				
			||||||
 | 
					    hci_resume_flow();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -5,9 +5,8 @@ extern "C" {
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include "hci_tl.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool APP_BLE_Init();
 | 
					bool ble_app_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -39,7 +39,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_man_name),
 | 
					                                strlen(dev_info_man_name),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
@ -53,7 +53,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_serial_num),
 | 
					                                strlen(dev_info_serial_num),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
@ -67,7 +67,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_firmware_rev_num),
 | 
					                                strlen(dev_info_firmware_rev_num),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
@ -81,7 +81,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_software_rev_num),
 | 
					                                strlen(dev_info_software_rev_num),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
 | 
				
			|||||||
@ -31,13 +31,22 @@ typedef struct {
 | 
				
			|||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  GapSvc gap_svc;
 | 
					  GapSvc gap_svc;
 | 
				
			||||||
  GapState state;
 | 
					  GapState state;
 | 
				
			||||||
 | 
					  osMutexId_t state_mutex;
 | 
				
			||||||
  uint8_t mac_address[BD_ADDR_SIZE_LOCAL];
 | 
					  uint8_t mac_address[BD_ADDR_SIZE_LOCAL];
 | 
				
			||||||
  Bt* bt;
 | 
					  Bt* bt;
 | 
				
			||||||
  osTimerId advertise_timer;
 | 
					  osTimerId advertise_timer;
 | 
				
			||||||
  osThreadAttr_t thread_attr;
 | 
					  osThreadAttr_t thread_attr;
 | 
				
			||||||
  osThreadId_t thread_id;
 | 
					  osThreadId_t thread_id;
 | 
				
			||||||
 | 
					  osMessageQueueId_t command_queue;
 | 
				
			||||||
 | 
					  bool enable_adv;
 | 
				
			||||||
} Gap;
 | 
					} Gap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					    GapCommandAdvFast,
 | 
				
			||||||
 | 
					    GapCommandAdvLowPower,
 | 
				
			||||||
 | 
					    GapCommandAdvStop,
 | 
				
			||||||
 | 
					} GapCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Identity root key
 | 
					// Identity root key
 | 
				
			||||||
static const uint8_t gap_irk[16] = {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
 | 
					static const uint8_t gap_irk[16] = {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
 | 
				
			||||||
// Encryption root key
 | 
					// Encryption root key
 | 
				
			||||||
@ -49,150 +58,151 @@ static const uint8_t gap_default_mac_addr[] = {0x6c, 0x7a, 0xd8, 0xac, 0x57, 0x7
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static Gap* gap = NULL;
 | 
					static Gap* gap = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advertise(GapState new_state);
 | 
					static void gap_advertise_start(GapState new_state);
 | 
				
			||||||
static void gap_app(void *arg);
 | 
					static void gap_app(void *arg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
 | 
					SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  hci_event_pckt *event_pckt;
 | 
					    hci_event_pckt *event_pckt;
 | 
				
			||||||
  evt_le_meta_event *meta_evt;
 | 
					    evt_le_meta_event *meta_evt;
 | 
				
			||||||
  evt_blue_aci *blue_evt;
 | 
					    evt_blue_aci *blue_evt;
 | 
				
			||||||
  hci_le_phy_update_complete_event_rp0 *evt_le_phy_update_complete;
 | 
					    hci_le_phy_update_complete_event_rp0 *evt_le_phy_update_complete;
 | 
				
			||||||
  uint8_t tx_phy;
 | 
					    uint8_t tx_phy;
 | 
				
			||||||
  uint8_t rx_phy;
 | 
					    uint8_t rx_phy;
 | 
				
			||||||
  tBleStatus ret = BLE_STATUS_INVALID_PARAMS;
 | 
					    tBleStatus ret = BLE_STATUS_INVALID_PARAMS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data;
 | 
					    event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (event_pckt->evt) {
 | 
					    osMutexAcquire(gap->state_mutex, osWaitForever);
 | 
				
			||||||
    case EVT_DISCONN_COMPLETE:
 | 
					    switch (event_pckt->evt) {
 | 
				
			||||||
    {
 | 
					        case EVT_DISCONN_COMPLETE:
 | 
				
			||||||
        hci_disconnection_complete_event_rp0 *disconnection_complete_event = (hci_disconnection_complete_event_rp0 *) event_pckt->data;
 | 
					        {
 | 
				
			||||||
        if (disconnection_complete_event->Connection_Handle == gap->gap_svc.connection_handle) {
 | 
					            hci_disconnection_complete_event_rp0 *disconnection_complete_event = (hci_disconnection_complete_event_rp0 *) event_pckt->data;
 | 
				
			||||||
            gap->gap_svc.connection_handle = 0;
 | 
					            if (disconnection_complete_event->Connection_Handle == gap->gap_svc.connection_handle) {
 | 
				
			||||||
            gap->state = GapStateIdle;
 | 
					                gap->gap_svc.connection_handle = 0;
 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Disconnect from client");
 | 
					                gap->state = GapStateIdle;
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Disconnect from client");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if(gap->enable_adv) {
 | 
				
			||||||
 | 
					                // Restart advertising
 | 
				
			||||||
 | 
					                gap_start_advertising();
 | 
				
			||||||
 | 
					                furi_hal_power_insomnia_exit();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Restart advertising
 | 
					        break;
 | 
				
			||||||
        gap_advertise(GapStateAdvFast);
 | 
					 | 
				
			||||||
        furi_hal_power_insomnia_exit();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case EVT_LE_META_EVENT:
 | 
					        case EVT_LE_META_EVENT:
 | 
				
			||||||
        meta_evt = (evt_le_meta_event*) event_pckt->data;
 | 
					            meta_evt = (evt_le_meta_event*) event_pckt->data;
 | 
				
			||||||
        switch (meta_evt->subevent) {
 | 
					            switch (meta_evt->subevent) {
 | 
				
			||||||
            case EVT_LE_CONN_UPDATE_COMPLETE:
 | 
					                case EVT_LE_CONN_UPDATE_COMPLETE:
 | 
				
			||||||
            FURI_LOG_D(GAP_TAG, "Connection update event");
 | 
					                FURI_LOG_D(GAP_TAG, "Connection update event");
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case EVT_LE_PHY_UPDATE_COMPLETE:
 | 
					                case EVT_LE_PHY_UPDATE_COMPLETE:
 | 
				
			||||||
            evt_le_phy_update_complete = (hci_le_phy_update_complete_event_rp0*)meta_evt->data;
 | 
					                evt_le_phy_update_complete = (hci_le_phy_update_complete_event_rp0*)meta_evt->data;
 | 
				
			||||||
            if(evt_le_phy_update_complete->Status) {
 | 
					                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(GAP_TAG, "Update PHY failed, status %d", evt_le_phy_update_complete->Status);
 | 
				
			||||||
            } else {
 | 
					                } else {
 | 
				
			||||||
                FURI_LOG_I(GAP_TAG, "Update PHY succeed");
 | 
					                    FURI_LOG_I(GAP_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);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    FURI_LOG_I(GAP_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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Stop advertising as connection completed
 | 
				
			||||||
 | 
					                osTimerStop(gap->advertise_timer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Update connection status and handle
 | 
				
			||||||
 | 
					                gap->state = GapStateConnected;
 | 
				
			||||||
 | 
					                gap->gap_svc.connection_handle = connection_complete_event->Connection_Handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Start pairing by sending security request
 | 
				
			||||||
 | 
					                aci_gap_slave_security_req(connection_complete_event->Connection_Handle);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            ret = hci_le_read_phy(gap->gap_svc.connection_handle,&tx_phy,&rx_phy);
 | 
					        break;
 | 
				
			||||||
            if(ret) {
 | 
					
 | 
				
			||||||
                FURI_LOG_E(GAP_TAG, "Read PHY failed, status: %d", ret);
 | 
					        case EVT_VENDOR:
 | 
				
			||||||
            } else {
 | 
					            blue_evt = (evt_blue_aci*) event_pckt->data;
 | 
				
			||||||
                FURI_LOG_I(GAP_TAG, "PHY Params TX= %d, RX= %d ", tx_phy, rx_phy);
 | 
					            switch (blue_evt->ecode) {
 | 
				
			||||||
 | 
					                aci_gap_pairing_complete_event_rp0 *pairing_complete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_LIMITED_DISCOVERABLE:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Limited discoverable event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_PASS_KEY_REQUEST:
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // 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);
 | 
				
			||||||
 | 
					                bt_pin_code_show(gap->bt, pin);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case EVT_LE_CONN_COMPLETE:
 | 
					            case EVT_BLUE_GAP_AUTHORIZATION_REQUEST:
 | 
				
			||||||
            furi_hal_power_insomnia_enter();
 | 
					                FURI_LOG_I(GAP_TAG, "Authorization request event");
 | 
				
			||||||
            hci_le_connection_complete_event_rp0* connection_complete_event = (hci_le_connection_complete_event_rp0 *) meta_evt->data;
 | 
					                break;
 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Connection complete for connection handle 0x%x", connection_complete_event->Connection_Handle);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Stop advertising as connection completed
 | 
					            case EVT_BLUE_GAP_SLAVE_SECURITY_INITIATED:
 | 
				
			||||||
            osTimerStop(gap->advertise_timer);
 | 
					                FURI_LOG_I(GAP_TAG, "Slave security initiated");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Update connection status and handle
 | 
					            case EVT_BLUE_GAP_BOND_LOST:
 | 
				
			||||||
            gap->state = GapStateConnected;
 | 
					                FURI_LOG_I(GAP_TAG, "Bond lost event. Start rebonding");
 | 
				
			||||||
            gap->gap_svc.connection_handle = connection_complete_event->Connection_Handle;
 | 
					                aci_gap_allow_rebond(gap->gap_svc.connection_handle);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Start pairing by sending security request
 | 
					            case EVT_BLUE_GAP_DEVICE_FOUND:
 | 
				
			||||||
            aci_gap_slave_security_req(connection_complete_event->Connection_Handle);
 | 
					                FURI_LOG_I(GAP_TAG, "Device found event");
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_ADDR_NOT_RESOLVED:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Address not resolved event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_KEYPRESS_NOTIFICATION:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Key press notification event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            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);
 | 
				
			||||||
 | 
					                    aci_gap_terminate(gap->gap_svc.connection_handle, 5);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    FURI_LOG_I(GAP_TAG, "Pairing complete");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_PROCEDURE_COMPLETE:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Procedure complete event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    osMutexRelease(gap->state_mutex);
 | 
				
			||||||
 | 
					    return SVCCTL_UserEvtFlowEnable;
 | 
				
			||||||
    case EVT_VENDOR:
 | 
					 | 
				
			||||||
        blue_evt = (evt_blue_aci*) event_pckt->data;
 | 
					 | 
				
			||||||
        switch (blue_evt->ecode) {
 | 
					 | 
				
			||||||
            aci_gap_pairing_complete_event_rp0 *pairing_complete;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_LIMITED_DISCOVERABLE:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Limited discoverable event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_PASS_KEY_REQUEST:
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // 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);
 | 
					 | 
				
			||||||
            bt_pin_code_show(gap->bt, pin);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_AUTHORIZATION_REQUEST:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Authorization request event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_SLAVE_SECURITY_INITIATED:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Slave security initiated");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_BOND_LOST:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_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");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_ADDR_NOT_RESOLVED:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Address not resolved event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_KEYPRESS_NOTIFICATION:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Key press notification event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_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;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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);
 | 
					 | 
				
			||||||
            aci_gap_terminate(gap->gap_svc.connection_handle, 5);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Pairing complete");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_PROCEDURE_COMPLETE:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Procedure complete event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return SVCCTL_UserEvtFlowEnable;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SVCCTL_SvcInit() {
 | 
					void SVCCTL_SvcInit() {
 | 
				
			||||||
@ -213,7 +223,7 @@ static void set_advertisment_service_uid(uint8_t* uid, uint8_t uid_len) {
 | 
				
			|||||||
    gap->gap_svc.adv_svc_uuid_len += uid_len;
 | 
					    gap->gap_svc.adv_svc_uuid_len += uid_len;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GapState gap_get_status() {
 | 
					GapState gap_get_state() {
 | 
				
			||||||
    return gap->state;
 | 
					    return gap->state;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -293,7 +303,7 @@ static void gap_init_svc(Gap* gap) {
 | 
				
			|||||||
    aci_gap_configure_whitelist();
 | 
					    aci_gap_configure_whitelist();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advertise(GapState new_state)
 | 
					static void gap_advertise_start(GapState new_state)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    tBleStatus status;
 | 
					    tBleStatus status;
 | 
				
			||||||
    uint16_t min_interval;
 | 
					    uint16_t min_interval;
 | 
				
			||||||
@ -317,7 +327,6 @@ static void gap_advertise(GapState new_state)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Configure advertising
 | 
					    // Configure advertising
 | 
				
			||||||
    gap->state = new_state;
 | 
					 | 
				
			||||||
    const char* name = furi_hal_version_get_ble_local_device_name_ptr();
 | 
					    const char* name = furi_hal_version_get_ble_local_device_name_ptr();
 | 
				
			||||||
    status = aci_gap_set_discoverable(ADV_IND, min_interval, max_interval, PUBLIC_ADDR, 0,
 | 
					    status = aci_gap_set_discoverable(ADV_IND, min_interval, max_interval, PUBLIC_ADDR, 0,
 | 
				
			||||||
                                        strlen(name), (uint8_t*)name,
 | 
					                                        strlen(name), (uint8_t*)name,
 | 
				
			||||||
@ -325,17 +334,40 @@ static void gap_advertise(GapState new_state)
 | 
				
			|||||||
    if(status) {
 | 
					    if(status) {
 | 
				
			||||||
        FURI_LOG_E(GAP_TAG, "Set discoverable err: %d", status);
 | 
					        FURI_LOG_E(GAP_TAG, "Set discoverable err: %d", status);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    gap->state = new_state;
 | 
				
			||||||
 | 
					    bt_update_statusbar(gap->bt);
 | 
				
			||||||
    osTimerStart(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
 | 
					    osTimerStart(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advertise_request(Gap* gap) {
 | 
					static void gap_advertise_stop() {
 | 
				
			||||||
    osThreadFlagsSet(gap->thread_id, 1);
 | 
					    if(gap->state == GapStateConnected) {
 | 
				
			||||||
 | 
					        // Terminate connection
 | 
				
			||||||
 | 
					        aci_gap_terminate(gap->gap_svc.connection_handle, 0x13);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if(gap->state > GapStateIdle) {
 | 
				
			||||||
 | 
					        // Stop advertising
 | 
				
			||||||
 | 
					        osTimerStop(gap->advertise_timer);
 | 
				
			||||||
 | 
					        aci_gap_set_non_discoverable();
 | 
				
			||||||
 | 
					        gap->state = GapStateIdle;
 | 
				
			||||||
 | 
					        bt_update_statusbar(gap->bt);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gap_start_advertising() {
 | 
				
			||||||
 | 
					    gap->enable_adv = true;
 | 
				
			||||||
 | 
					    GapCommand command = GapCommandAdvFast;
 | 
				
			||||||
 | 
					    furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gap_stop_advertising() {
 | 
				
			||||||
 | 
					    gap->enable_adv = false;
 | 
				
			||||||
 | 
					    GapCommand command = GapCommandAdvStop;
 | 
				
			||||||
 | 
					    furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advetise_timer_callback(void* context) {
 | 
					static void gap_advetise_timer_callback(void* context) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    GapCommand command = GapCommandAdvLowPower;
 | 
				
			||||||
    Gap* gap = context;
 | 
					    furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
 | 
				
			||||||
    gap_advertise_request(gap);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool gap_init() {
 | 
					bool gap_init() {
 | 
				
			||||||
@ -348,20 +380,25 @@ bool gap_init() {
 | 
				
			|||||||
    // Open Bt record
 | 
					    // Open Bt record
 | 
				
			||||||
    gap->bt = furi_record_open("bt");
 | 
					    gap->bt = furi_record_open("bt");
 | 
				
			||||||
    // Create advertising timer
 | 
					    // Create advertising timer
 | 
				
			||||||
    gap->advertise_timer = osTimerNew(gap_advetise_timer_callback, osTimerOnce, &gap, NULL);
 | 
					    gap->advertise_timer = osTimerNew(gap_advetise_timer_callback, osTimerOnce, NULL, NULL);
 | 
				
			||||||
    // Initialization of HCI & GATT & GAP layer
 | 
					    // Initialization of GATT & GAP layer
 | 
				
			||||||
    gap_init_svc(gap);
 | 
					    gap_init_svc(gap);
 | 
				
			||||||
    // Initialization of the BLE Services
 | 
					    // Initialization of the BLE Services
 | 
				
			||||||
    SVCCTL_Init();
 | 
					    SVCCTL_Init();
 | 
				
			||||||
    // Initialization of the BLE App Context
 | 
					    // Initialization of the GAP state
 | 
				
			||||||
 | 
					    gap->state_mutex = osMutexNew(NULL);
 | 
				
			||||||
    gap->state = GapStateIdle;
 | 
					    gap->state = GapStateIdle;
 | 
				
			||||||
    gap->gap_svc.connection_handle = 0xFFFF;
 | 
					    gap->gap_svc.connection_handle = 0xFFFF;
 | 
				
			||||||
 | 
					    gap->enable_adv = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Thread configuration
 | 
					    // Thread configuration
 | 
				
			||||||
    gap->thread_attr.name = "BLE advertising";
 | 
					    gap->thread_attr.name = "BLE advertising";
 | 
				
			||||||
    gap->thread_attr.stack_size = 512;
 | 
					    gap->thread_attr.stack_size = 1024;
 | 
				
			||||||
    gap->thread_id = osThreadNew(gap_app, NULL, &gap->thread_attr);
 | 
					    gap->thread_id = osThreadNew(gap_app, NULL, &gap->thread_attr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Command queue allocation
 | 
				
			||||||
 | 
					    gap->command_queue = osMessageQueueNew(8, sizeof(GapCommand), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Start Device Information service
 | 
					    // Start Device Information service
 | 
				
			||||||
    dev_info_svc_start();
 | 
					    dev_info_svc_start();
 | 
				
			||||||
    // Start Battery service
 | 
					    // Start Battery service
 | 
				
			||||||
@ -374,14 +411,21 @@ bool gap_init() {
 | 
				
			|||||||
    adv_service_uid[1] = 0x30;
 | 
					    adv_service_uid[1] = 0x30;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set_advertisment_service_uid(adv_service_uid, sizeof(adv_service_uid));
 | 
					    set_advertisment_service_uid(adv_service_uid, sizeof(adv_service_uid));
 | 
				
			||||||
    gap_advertise(GapStateAdvFast);
 | 
					 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_app(void *arg) {
 | 
					static void gap_app(void *arg) {
 | 
				
			||||||
    // TODO Exit from app, stop service, clean memory
 | 
					    GapCommand command;
 | 
				
			||||||
    while(1) {
 | 
					    while(1) {
 | 
				
			||||||
        osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);
 | 
					        furi_check(osMessageQueueGet(gap->command_queue, &command, NULL, osWaitForever) == osOK);
 | 
				
			||||||
        gap_advertise(GapStateAdvLowPower);
 | 
					        osMutexAcquire(gap->state_mutex, osWaitForever);
 | 
				
			||||||
 | 
					        if(command == GapCommandAdvFast) {
 | 
				
			||||||
 | 
					            gap_advertise_start(GapStateAdvFast);
 | 
				
			||||||
 | 
					        } else if(command == GapCommandAdvLowPower) {
 | 
				
			||||||
 | 
					            gap_advertise_start(GapStateAdvLowPower);
 | 
				
			||||||
 | 
					        } else if(command == GapCommandAdvStop) {
 | 
				
			||||||
 | 
					            gap_advertise_stop();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        osMutexRelease(gap->state_mutex);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,11 @@ typedef enum {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool gap_init();
 | 
					bool gap_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GapState gap_get_status();
 | 
					void gap_start_advertising();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gap_stop_advertising();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GapState gap_get_state();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -61,7 +61,7 @@ void serial_svc_start() {
 | 
				
			|||||||
    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_tx_uuid,
 | 
					    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_tx_uuid,
 | 
				
			||||||
                                SERIAL_SVC_DATA_LEN_MAX,
 | 
					                                SERIAL_SVC_DATA_LEN_MAX,
 | 
				
			||||||
                                CHAR_PROP_WRITE_WITHOUT_RESP | CHAR_PROP_WRITE | CHAR_PROP_READ,
 | 
					                                CHAR_PROP_WRITE_WITHOUT_RESP | CHAR_PROP_WRITE | CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ | ATTR_PERMISSION_AUTHEN_WRITE,
 | 
				
			||||||
                                GATT_NOTIFY_ATTRIBUTE_WRITE,
 | 
					                                GATT_NOTIFY_ATTRIBUTE_WRITE,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_VARIABLE,
 | 
					                                CHAR_VALUE_LEN_VARIABLE,
 | 
				
			||||||
@ -74,7 +74,7 @@ void serial_svc_start() {
 | 
				
			|||||||
    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_rx_uuid,
 | 
					    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_rx_uuid,
 | 
				
			||||||
                                SERIAL_SVC_DATA_LEN_MAX,                                  
 | 
					                                SERIAL_SVC_DATA_LEN_MAX,                                  
 | 
				
			||||||
                                CHAR_PROP_READ | CHAR_PROP_INDICATE,
 | 
					                                CHAR_PROP_READ | CHAR_PROP_INDICATE,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_VARIABLE,
 | 
					                                CHAR_VALUE_LEN_VARIABLE,
 | 
				
			||||||
@ -108,13 +108,15 @@ void serial_svc_stop() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool serial_svc_update_rx(uint8_t* data, uint8_t data_len) {
 | 
					bool serial_svc_update_rx(uint8_t* data, uint8_t data_len) {
 | 
				
			||||||
    furi_assert(data_len < SERIAL_SVC_DATA_LEN_MAX);
 | 
					    if(data_len > SERIAL_SVC_DATA_LEN_MAX) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tBleStatus result = aci_gatt_update_char_value(serial_svc->svc_handle,
 | 
					    tBleStatus result = aci_gatt_update_char_value(serial_svc->svc_handle,
 | 
				
			||||||
                                          serial_svc->rx_char_handle,
 | 
					                                        serial_svc->rx_char_handle,
 | 
				
			||||||
                                          0,
 | 
					                                        0,
 | 
				
			||||||
                                          data_len,
 | 
					                                        data_len,
 | 
				
			||||||
                                          data);
 | 
					                                        data);
 | 
				
			||||||
    if(result) {
 | 
					    if(result) {
 | 
				
			||||||
        FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed updating RX characteristic: %d", result);
 | 
					        FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed updating RX characteristic: %d", result);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,6 @@
 | 
				
			|||||||
#include <stm32wbxx.h>
 | 
					#include <stm32wbxx.h>
 | 
				
			||||||
#include <shci.h>
 | 
					#include <shci.h>
 | 
				
			||||||
#include <cmsis_os2.h>
 | 
					#include <cmsis_os2.h>
 | 
				
			||||||
#include <app_ble.h>
 | 
					 | 
				
			||||||
#include <gap.h>
 | 
					#include <gap.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_bt_init() {
 | 
					void furi_hal_bt_init() {
 | 
				
			||||||
@ -14,10 +13,22 @@ void furi_hal_bt_init() {
 | 
				
			|||||||
    APPE_Init();
 | 
					    APPE_Init();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool furi_hal_bt_start_app() {
 | 
					bool furi_hal_bt_init_app() {
 | 
				
			||||||
    return gap_init();
 | 
					    return gap_init();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void furi_hal_bt_start_advertising() {
 | 
				
			||||||
 | 
					    if(gap_get_state() == GapStateIdle) {
 | 
				
			||||||
 | 
					        gap_start_advertising();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void furi_hal_bt_stop_advertising() {
 | 
				
			||||||
 | 
					    if(furi_hal_bt_is_alive()) {
 | 
				
			||||||
 | 
					        gap_stop_advertising();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_bt_dump_state(string_t buffer) {
 | 
					void furi_hal_bt_dump_state(string_t buffer) {
 | 
				
			||||||
    BleGlueStatus status = APPE_Status();
 | 
					    BleGlueStatus status = APPE_Status();
 | 
				
			||||||
    if (status == BleGlueStatusStarted) {
 | 
					    if (status == BleGlueStatusStarted) {
 | 
				
			||||||
@ -41,7 +52,7 @@ void furi_hal_bt_dump_state(string_t buffer) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool furi_hal_bt_is_alive() {
 | 
					bool furi_hal_bt_is_alive() {
 | 
				
			||||||
    return APPE_Status() == BleGlueStatusStarted;
 | 
					    return gap_get_state() > GapStateIdle;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool furi_hal_bt_wait_startup() {
 | 
					bool furi_hal_bt_wait_startup() {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
#include <furi-hal-clock.h>
 | 
					#include <furi-hal-clock.h>
 | 
				
			||||||
 | 
					#include <furi.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <main.h>
 | 
					 | 
				
			||||||
#include <stm32wbxx_ll_pwr.h>
 | 
					#include <stm32wbxx_ll_pwr.h>
 | 
				
			||||||
#include <stm32wbxx_ll_rcc.h>
 | 
					#include <stm32wbxx_ll_rcc.h>
 | 
				
			||||||
#include <stm32wbxx_ll_utils.h>
 | 
					#include <stm32wbxx_ll_utils.h>
 | 
				
			||||||
@ -107,6 +107,12 @@ void furi_hal_clock_init() {
 | 
				
			|||||||
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE);
 | 
					    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE);
 | 
				
			||||||
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
 | 
					    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
 | 
				
			||||||
    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
 | 
					    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
 | 
				
			||||||
 | 
					    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_AES1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // AHB3
 | 
				
			||||||
 | 
					    LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PKA);
 | 
				
			||||||
 | 
					    LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_RNG);
 | 
				
			||||||
 | 
					    LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_AES2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // APB1
 | 
					    // APB1
 | 
				
			||||||
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
 | 
					    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
 | 
				
			||||||
@ -114,6 +120,8 @@ void furi_hal_clock_init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // APB2
 | 
					    // APB2
 | 
				
			||||||
    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
 | 
					    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FURI_LOG_I("FuriHalClock", "Init OK");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_clock_switch_to_hsi() {
 | 
					void furi_hal_clock_switch_to_hsi() {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										69
									
								
								firmware/targets/f6/furi-hal/furi-hal-crypto.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								firmware/targets/f6/furi-hal/furi-hal-crypto.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					#include <furi-hal-crypto.h>
 | 
				
			||||||
 | 
					#include <furi.h>
 | 
				
			||||||
 | 
					#include <shci.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CRYP_HandleTypeDef crypt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void furi_hal_crypto_init() {
 | 
				
			||||||
 | 
					    FURI_LOG_I("FuriHalCrypto", "Init OK");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
 | 
				
			||||||
 | 
					    furi_assert(key);
 | 
				
			||||||
 | 
					    furi_assert(slot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t pParam;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (key->type == FuriHalCryptoKeyTypeMaster) {
 | 
				
			||||||
 | 
					        pParam.KeyType = KEYTYPE_MASTER;
 | 
				
			||||||
 | 
					    } else if (key->type == FuriHalCryptoKeyTypeSimple) {
 | 
				
			||||||
 | 
					        pParam.KeyType = KEYTYPE_SIMPLE;
 | 
				
			||||||
 | 
					    } else if (key->type == FuriHalCryptoKeyTypeEncrypted) {
 | 
				
			||||||
 | 
					        pParam.KeyType = KEYTYPE_ENCRYPTED;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        furi_crash("Incorrect key type");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (key->size == FuriHalCryptoKeySize128) {
 | 
				
			||||||
 | 
					        pParam.KeySize = KEYSIZE_16;
 | 
				
			||||||
 | 
					    } else if (key->size == FuriHalCryptoKeySize256) {
 | 
				
			||||||
 | 
					        pParam.KeySize = KEYSIZE_32;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        furi_crash("Incorrect key size");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return SHCI_C2_FUS_StoreUsrKey(&pParam, slot) == SHCI_Success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
 | 
				
			||||||
 | 
					    furi_assert(slot > 0 && slot <= 100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    crypt.Instance = AES1;
 | 
				
			||||||
 | 
					    crypt.Init.DataType = CRYP_DATATYPE_32B;
 | 
				
			||||||
 | 
					    crypt.Init.KeySize = CRYP_KEYSIZE_256B;
 | 
				
			||||||
 | 
					    crypt.Init.Algorithm = CRYP_AES_CBC;
 | 
				
			||||||
 | 
					    crypt.Init.pInitVect = (uint32_t*)iv;
 | 
				
			||||||
 | 
					    crypt.Init.pKey = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_unload_key(uint8_t slot) {
 | 
				
			||||||
 | 
					    furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
 | 
				
			||||||
 | 
					    return SHCI_C2_FUS_UnloadUsrKey(slot) == SHCI_Success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size) {
 | 
				
			||||||
 | 
					    return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size) {
 | 
				
			||||||
 | 
					    return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -41,7 +41,7 @@ void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR is
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        furi_hal_tim_tim1_isr = isr;
 | 
					        furi_hal_tim_tim1_isr = isr;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -54,7 +54,7 @@ void furi_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel,
 | 
				
			|||||||
    } else if (dma == DMA2) {
 | 
					    } else if (dma == DMA2) {
 | 
				
			||||||
        furi_hal_dma_channel_isr[1][channel] = isr;
 | 
					        furi_hal_dma_channel_isr[1][channel] = isr;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -244,7 +244,7 @@ static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) {
 | 
				
			|||||||
static void furi_hal_irda_tx_dma_polarity_isr() {
 | 
					static void furi_hal_irda_tx_dma_polarity_isr() {
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
 | 
					    if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TE1(DMA1);
 | 
					        LL_DMA_ClearFlag_TE1(DMA1);
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
 | 
					    if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TC1(DMA1);
 | 
					        LL_DMA_ClearFlag_TC1(DMA1);
 | 
				
			||||||
@ -261,7 +261,7 @@ static void furi_hal_irda_tx_dma_polarity_isr() {
 | 
				
			|||||||
static void furi_hal_irda_tx_dma_isr() {
 | 
					static void furi_hal_irda_tx_dma_isr() {
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
 | 
					    if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TE2(DMA1);
 | 
					        LL_DMA_ClearFlag_TE2(DMA1);
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
 | 
					    if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_HT2(DMA1);
 | 
					        LL_DMA_ClearFlag_HT2(DMA1);
 | 
				
			||||||
@ -277,7 +277,7 @@ static void furi_hal_irda_tx_dma_isr() {
 | 
				
			|||||||
        } else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
 | 
					        } else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
 | 
				
			||||||
            /* fallthrough */
 | 
					            /* fallthrough */
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            furi_check(0);
 | 
					            furi_crash(NULL);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
 | 
					    if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
 | 
				
			||||||
@ -557,7 +557,7 @@ static void furi_hal_irda_async_tx_free_resources(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
 | 
					void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
 | 
				
			||||||
    if ((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) {
 | 
					    if ((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_assert(furi_hal_irda_state == IrdaStateIdle);
 | 
					    furi_assert(furi_hal_irda_state == IrdaStateIdle);
 | 
				
			||||||
 | 
				
			|||||||
@ -252,7 +252,7 @@ void furi_hal_rfid_set_emulate_pulse(uint32_t pulse) {
 | 
				
			|||||||
        LFRFID_EMULATE_TIM.Instance->CCR4 = pulse;
 | 
					        LFRFID_EMULATE_TIM.Instance->CCR4 = pulse;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -276,7 +276,7 @@ void furi_hal_rfid_set_read_pulse(uint32_t pulse) {
 | 
				
			|||||||
        LFRFID_TIM.Instance->CCR4 = pulse;
 | 
					        LFRFID_TIM.Instance->CCR4 = pulse;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -15,166 +15,174 @@ static const uint8_t furi_hal_subghz_preset_ook_270khz_async_regs[][2] = {
 | 
				
			|||||||
    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
					    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* GPIO GD0 */
 | 
					    /* GPIO GD0 */
 | 
				
			||||||
    { CC1101_IOCFG0,    0x0D }, // GD0 as async serial data output/input
 | 
					    {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* FIFO and internals */
 | 
					    /* FIFO and internals */
 | 
				
			||||||
    { CC1101_FIFOTHR,   0x47 }, // The only important bit is ADC_RETENTION, FIFO Tx=33 Rx=32
 | 
					    {CC1101_FIFOTHR, 0x47}, // The only important bit is ADC_RETENTION, FIFO Tx=33 Rx=32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Packet engine */
 | 
					    /* Packet engine */
 | 
				
			||||||
    { CC1101_PKTCTRL0,  0x32 }, // Async, continious, no whitening
 | 
					    {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Control */
 | 
					    /* Frequency Synthesizer Control */
 | 
				
			||||||
    { CC1101_FSCTRL1,   0x06 }, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
					    {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Modem Configuration
 | 
					    // Modem Configuration
 | 
				
			||||||
    { CC1101_MDMCFG0,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG1,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG2,   0x30 }, // Format ASK/OOK, No preamble/sync
 | 
					    {CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
 | 
				
			||||||
    { CC1101_MDMCFG3,   0x32 }, // Data rate is 3.79372 kBaud
 | 
					    {CC1101_MDMCFG3, 0x32}, // Data rate is 3.79372 kBaud
 | 
				
			||||||
    { CC1101_MDMCFG4,   0x67 }, // Rx BW filter is 270.833333kHz
 | 
					    {CC1101_MDMCFG4, 0x67}, // Rx BW filter is 270.833333kHz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Main Radio Control State Machine */
 | 
					    /* Main Radio Control State Machine */
 | 
				
			||||||
    { CC1101_MCSM0,     0x18 }, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
					    {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Offset Compensation Configuration */
 | 
					    /* Frequency Offset Compensation Configuration */
 | 
				
			||||||
    { CC1101_FOCCFG,    0x18 }, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
					    {CC1101_FOCCFG,
 | 
				
			||||||
 | 
					     0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Automatic Gain Control */
 | 
					    /* Automatic Gain Control */
 | 
				
			||||||
    { CC1101_AGCTRL0,   0x40 }, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
					    {CC1101_AGCTRL0,
 | 
				
			||||||
    { CC1101_AGCTRL1,   0x00 }, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
					     0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
				
			||||||
    { CC1101_AGCTRL2,   0x03 }, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
					    {CC1101_AGCTRL1,
 | 
				
			||||||
 | 
					     0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
				
			||||||
 | 
					    {CC1101_AGCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Wake on radio and timeouts control */
 | 
					    /* Wake on radio and timeouts control */
 | 
				
			||||||
    { CC1101_WORCTRL,   0xFB }, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours 
 | 
					    {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frontend configuration */
 | 
					    /* Frontend configuration */
 | 
				
			||||||
    { CC1101_FREND0,    0x11 }, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
					    {CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
				
			||||||
    { CC1101_FREND1,    0xB6 }, // 
 | 
					    {CC1101_FREND1, 0xB6}, //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
					    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
				
			||||||
    { CC1101_FSCAL3,    0xE9 },
 | 
					    {CC1101_FSCAL3, 0xE9},
 | 
				
			||||||
    { CC1101_FSCAL2,    0x2A },
 | 
					    {CC1101_FSCAL2, 0x2A},
 | 
				
			||||||
    { CC1101_FSCAL1,    0x00 },
 | 
					    {CC1101_FSCAL1, 0x00},
 | 
				
			||||||
    { CC1101_FSCAL0,    0x1F }, 
 | 
					    {CC1101_FSCAL0, 0x1F},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Magic f4ckery */
 | 
					    /* Magic f4ckery */
 | 
				
			||||||
    { CC1101_TEST2,     0x81 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST2, 0x81}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST1,     0x35 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST1, 0x35}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST0,     0x09 }, // VCO selection calibration stage is disabled
 | 
					    {CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* End  */
 | 
					    /* End  */
 | 
				
			||||||
    { 0, 0 },
 | 
					    {0, 0},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_ook_650khz_async_regs[][2] = {
 | 
					static const uint8_t furi_hal_subghz_preset_ook_650khz_async_regs[][2] = {
 | 
				
			||||||
    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
					    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* GPIO GD0 */
 | 
					    /* GPIO GD0 */
 | 
				
			||||||
    { CC1101_IOCFG0,    0x0D }, // GD0 as async serial data output/input
 | 
					    {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* FIFO and internals */
 | 
					    /* FIFO and internals */
 | 
				
			||||||
    { CC1101_FIFOTHR,   0x07 }, // The only important bit is ADC_RETENTION
 | 
					    {CC1101_FIFOTHR, 0x07}, // The only important bit is ADC_RETENTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Packet engine */
 | 
					    /* Packet engine */
 | 
				
			||||||
    { CC1101_PKTCTRL0,  0x32 }, // Async, continious, no whitening
 | 
					    {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Control */
 | 
					    /* Frequency Synthesizer Control */
 | 
				
			||||||
    { CC1101_FSCTRL1,   0x06 }, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
					    {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Modem Configuration
 | 
					    // Modem Configuration
 | 
				
			||||||
    { CC1101_MDMCFG0,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG1,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG2,   0x30 }, // Format ASK/OOK, No preamble/sync
 | 
					    {CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
 | 
				
			||||||
    { CC1101_MDMCFG3,   0x32 }, // Data rate is 3.79372 kBaud
 | 
					    {CC1101_MDMCFG3, 0x32}, // Data rate is 3.79372 kBaud
 | 
				
			||||||
    { CC1101_MDMCFG4,   0x17  }, // Rx BW filter is 650.000kHz
 | 
					    {CC1101_MDMCFG4, 0x17}, // Rx BW filter is 650.000kHz
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    /* Main Radio Control State Machine */
 | 
					    /* Main Radio Control State Machine */
 | 
				
			||||||
    { CC1101_MCSM0,     0x18 }, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
					    {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Offset Compensation Configuration */
 | 
					    /* Frequency Offset Compensation Configuration */
 | 
				
			||||||
    { CC1101_FOCCFG,    0x18 }, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
					    {CC1101_FOCCFG,
 | 
				
			||||||
 | 
					     0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Automatic Gain Control */
 | 
					    /* Automatic Gain Control */
 | 
				
			||||||
    { CC1101_AGCTRL0,   0x40 }, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
					    {CC1101_AGCTRL0,
 | 
				
			||||||
    { CC1101_AGCTRL1,   0x00 }, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
					     0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
				
			||||||
    { CC1101_AGCTRL2,   0x03 }, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
					    {CC1101_AGCTRL1,
 | 
				
			||||||
 | 
					     0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
				
			||||||
 | 
					    {CC1101_AGCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Wake on radio and timeouts control */
 | 
					    /* Wake on radio and timeouts control */
 | 
				
			||||||
    { CC1101_WORCTRL,   0xFB }, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours 
 | 
					    {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frontend configuration */
 | 
					    /* Frontend configuration */
 | 
				
			||||||
    { CC1101_FREND0,    0x11 }, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
					    {CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
				
			||||||
    { CC1101_FREND1,    0xB6 }, // 
 | 
					    {CC1101_FREND1, 0xB6}, //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
					    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
				
			||||||
    { CC1101_FSCAL3,    0xE9 },
 | 
					    {CC1101_FSCAL3, 0xE9},
 | 
				
			||||||
    { CC1101_FSCAL2,    0x2A },
 | 
					    {CC1101_FSCAL2, 0x2A},
 | 
				
			||||||
    { CC1101_FSCAL1,    0x00 },
 | 
					    {CC1101_FSCAL1, 0x00},
 | 
				
			||||||
    { CC1101_FSCAL0,    0x1F }, 
 | 
					    {CC1101_FSCAL0, 0x1F},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Magic f4ckery */
 | 
					    /* Magic f4ckery */
 | 
				
			||||||
    { CC1101_TEST2,     0x88 },
 | 
					    {CC1101_TEST2, 0x88},
 | 
				
			||||||
    { CC1101_TEST1,     0x31 },
 | 
					    {CC1101_TEST1, 0x31},
 | 
				
			||||||
    { CC1101_TEST0,     0x09 }, // VCO selection calibration stage is disabled
 | 
					    {CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* End  */
 | 
					    /* End  */
 | 
				
			||||||
    { 0, 0 },
 | 
					    {0, 0},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
 | 
					static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
 | 
				
			||||||
    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* GPIO GD0 */
 | 
					    /* GPIO GD0 */
 | 
				
			||||||
    { CC1101_IOCFG0,    0x0D }, // GD0 as async serial data output/input
 | 
					    {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* FIFO and internals */
 | 
					    /* FIFO and internals */
 | 
				
			||||||
    { CC1101_FIFOTHR,   0x47 }, // The only important bit is ADC_RETENTION
 | 
					    {CC1101_FIFOTHR, 0x47}, // The only important bit is ADC_RETENTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Packet engine */
 | 
					    /* Packet engine */
 | 
				
			||||||
    { CC1101_PKTCTRL0,  0x32 }, // Async, continious, no whitening
 | 
					    {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Control */
 | 
					    /* Frequency Synthesizer Control */
 | 
				
			||||||
    { CC1101_FSCTRL1,   0x06 }, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
					    {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Modem Configuration
 | 
					    // Modem Configuration
 | 
				
			||||||
    { CC1101_MDMCFG0,   0xF8 }, 
 | 
					    {CC1101_MDMCFG0, 0x00},
 | 
				
			||||||
    { CC1101_MDMCFG1,   0x00 }, // No preamble/sync
 | 
					    {CC1101_MDMCFG1, 0x02},
 | 
				
			||||||
    { CC1101_MDMCFG2,   0x80 }, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
 | 
					    {CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
 | 
				
			||||||
    { CC1101_MDMCFG3,   0x83 }, // Data rate is 9.59587 kBaud
 | 
					    {CC1101_MDMCFG3, 0x8B}, // Data rate is 19.5885 kBaud
 | 
				
			||||||
    { CC1101_MDMCFG4,   0x88 }, // Rx BW filter is 203.125000kHz
 | 
					    {CC1101_MDMCFG4, 0x69}, // Rx BW filter is 270.833333 kHz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    { CC1101_DEVIATN,  0x14}, //Deviation 4.760742 khz
 | 
					    {CC1101_DEVIATN, 0x47}, //Deviation 47.607422 khz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Main Radio Control State Machine */
 | 
					    /* Main Radio Control State Machine */
 | 
				
			||||||
    { CC1101_MCSM0,     0x18 }, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
					    {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Offset Compensation Configuration */
 | 
					    /* Frequency Offset Compensation Configuration */
 | 
				
			||||||
    { CC1101_FOCCFG,    0x18 }, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
					    {CC1101_FOCCFG,
 | 
				
			||||||
 | 
					     0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Automatic Gain Control */
 | 
					    /* Automatic Gain Control */
 | 
				
			||||||
    { CC1101_AGCTRL0,   0x40 }, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
					    {CC1101_AGCTRL0,
 | 
				
			||||||
    { CC1101_AGCTRL1,   0x00 }, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
					     0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
				
			||||||
    { CC1101_AGCTRL2,   0x03 }, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
					    {CC1101_AGCTRL1,
 | 
				
			||||||
 | 
					     0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
				
			||||||
 | 
					    {CC1101_AGCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Wake on radio and timeouts control */
 | 
					    /* Wake on radio and timeouts control */
 | 
				
			||||||
    { CC1101_WORCTRL,   0xFB }, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours 
 | 
					    {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frontend configuration */
 | 
					    /* Frontend configuration */
 | 
				
			||||||
    { CC1101_FREND0,    0x10 }, // Adjusts current TX LO buffer
 | 
					    {CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
 | 
				
			||||||
    { CC1101_FREND1,    0xB6 }, // 
 | 
					    {CC1101_FREND1, 0xB6}, //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
					    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
				
			||||||
    { CC1101_FSCAL3,    0xE9 },
 | 
					    {CC1101_FSCAL3, 0xE9},
 | 
				
			||||||
    { CC1101_FSCAL2,    0x2A },
 | 
					    {CC1101_FSCAL2, 0x2A},
 | 
				
			||||||
    { CC1101_FSCAL1,    0x00 },
 | 
					    {CC1101_FSCAL1, 0x00},
 | 
				
			||||||
    { CC1101_FSCAL0,    0x1F }, 
 | 
					    {CC1101_FSCAL0, 0x1F},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Magic f4ckery */
 | 
					    /* Magic f4ckery */
 | 
				
			||||||
    { CC1101_TEST2,     0x81 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST2, 0x81}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST1,     0x35 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST1, 0x35}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST0,     0x09 }, // VCO selection calibration stage is disabled
 | 
					    {CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* End  */
 | 
					    /* End  */
 | 
				
			||||||
    { 0, 0 },
 | 
					    {0, 0},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
 | 
					static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
@ -184,8 +192,7 @@ static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
 | 
				
			|||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00
 | 
					    0x00};
 | 
				
			||||||
};
 | 
					 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = {
 | 
					static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = {
 | 
				
			||||||
    0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
 | 
					    0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
@ -195,6 +202,7 @@ static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = {
 | 
				
			|||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00
 | 
					    0x00
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_subghz_init() {
 | 
					void furi_hal_subghz_init() {
 | 
				
			||||||
@ -217,11 +225,13 @@ void furi_hal_subghz_init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // GD0 low
 | 
					    // GD0 low
 | 
				
			||||||
    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW);
 | 
					    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW);
 | 
				
			||||||
    while(hal_gpio_read(&gpio_cc1101_g0) != false);
 | 
					    while(hal_gpio_read(&gpio_cc1101_g0) != false)
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // GD0 high
 | 
					    // GD0 high
 | 
				
			||||||
    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
					    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
				
			||||||
    while(hal_gpio_read(&gpio_cc1101_g0) != true);
 | 
					    while(hal_gpio_read(&gpio_cc1101_g0) != true)
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Reset GD0 to floating state
 | 
					    // Reset GD0 to floating state
 | 
				
			||||||
    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHighImpedance);
 | 
					    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHighImpedance);
 | 
				
			||||||
@ -257,8 +267,7 @@ void furi_hal_subghz_dump_state() {
 | 
				
			|||||||
    printf(
 | 
					    printf(
 | 
				
			||||||
        "[furi_hal_subghz] cc1101 chip %d, version %d\r\n",
 | 
					        "[furi_hal_subghz] cc1101 chip %d, version %d\r\n",
 | 
				
			||||||
        cc1101_get_partnumber(device),
 | 
					        cc1101_get_partnumber(device),
 | 
				
			||||||
        cc1101_get_version(device)
 | 
					        cc1101_get_version(device));
 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    furi_hal_spi_device_return(device);
 | 
					    furi_hal_spi_device_return(device);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -266,14 +275,14 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
 | 
				
			|||||||
    if(preset == FuriHalSubGhzPresetOok650Async) {
 | 
					    if(preset == FuriHalSubGhzPresetOok650Async) {
 | 
				
			||||||
        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_650khz_async_regs);
 | 
					        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_650khz_async_regs);
 | 
				
			||||||
        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
					        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
				
			||||||
    } else if(preset == FuriHalSubGhzPresetOok270Async){
 | 
					    } else if(preset == FuriHalSubGhzPresetOok270Async) {
 | 
				
			||||||
        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_270khz_async_regs);
 | 
					        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_270khz_async_regs);
 | 
				
			||||||
        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
					        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
				
			||||||
    } else if(preset == FuriHalSubGhzPreset2FSKAsync){
 | 
					    } else if(preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
				
			||||||
        furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
 | 
					        furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
 | 
				
			||||||
        furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
 | 
					        furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
 | 
				
			||||||
    }else {
 | 
					    }else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -289,7 +298,7 @@ void furi_hal_subghz_load_registers(const uint8_t data[][2]) {
 | 
				
			|||||||
    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
					    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
				
			||||||
    cc1101_reset(device);
 | 
					    cc1101_reset(device);
 | 
				
			||||||
    uint32_t i = 0;
 | 
					    uint32_t i = 0;
 | 
				
			||||||
    while (data[i][0]) {
 | 
					    while(data[i][0]) {
 | 
				
			||||||
        cc1101_write_reg(device, data[i][0], data[i][1]);
 | 
					        cc1101_write_reg(device, data[i][0], data[i][1]);
 | 
				
			||||||
        i++;
 | 
					        i++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -388,7 +397,7 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
 | 
				
			|||||||
    } else if(value >= 778999847 && value <= 928000000) {
 | 
					    } else if(value >= 778999847 && value <= 928000000) {
 | 
				
			||||||
        furi_hal_subghz_set_path(FuriHalSubGhzPath868);
 | 
					        furi_hal_subghz_set_path(FuriHalSubGhzPath868);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return value;
 | 
					    return value;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -401,7 +410,7 @@ uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    while(true) {
 | 
					    while(true) {
 | 
				
			||||||
        CC1101Status status = cc1101_get_status(device);
 | 
					        CC1101Status status = cc1101_get_status(device);
 | 
				
			||||||
        if (status.STATE == CC1101StateIDLE) break;
 | 
					        if(status.STATE == CC1101StateIDLE) break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_hal_spi_device_return(device);
 | 
					    furi_hal_spi_device_return(device);
 | 
				
			||||||
@ -411,20 +420,20 @@ uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
 | 
					void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
 | 
				
			||||||
    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
					    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
				
			||||||
    if (path == FuriHalSubGhzPath433) {
 | 
					    if(path == FuriHalSubGhzPath433) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
				
			||||||
    } else if (path == FuriHalSubGhzPath315) {
 | 
					    } else if(path == FuriHalSubGhzPath315) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
				
			||||||
    } else if (path == FuriHalSubGhzPath868) {
 | 
					    } else if(path == FuriHalSubGhzPath868) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
				
			||||||
    } else if (path == FuriHalSubGhzPathIsolate) {
 | 
					    } else if(path == FuriHalSubGhzPathIsolate) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    furi_hal_spi_device_return(device);
 | 
					    furi_hal_spi_device_return(device);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -438,24 +447,25 @@ static void furi_hal_subghz_capture_ISR() {
 | 
				
			|||||||
    if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
 | 
					    if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
 | 
				
			||||||
        LL_TIM_ClearFlag_CC1(TIM2);
 | 
					        LL_TIM_ClearFlag_CC1(TIM2);
 | 
				
			||||||
        furi_hal_subghz_capture_delta_duration = LL_TIM_IC_GetCaptureCH1(TIM2);
 | 
					        furi_hal_subghz_capture_delta_duration = LL_TIM_IC_GetCaptureCH1(TIM2);
 | 
				
			||||||
        if (furi_hal_subghz_capture_callback) {
 | 
					        if(furi_hal_subghz_capture_callback) {
 | 
				
			||||||
            furi_hal_subghz_capture_callback(true, furi_hal_subghz_capture_delta_duration,
 | 
					            furi_hal_subghz_capture_callback(
 | 
				
			||||||
                (void*)furi_hal_subghz_capture_callback_context
 | 
					                true,
 | 
				
			||||||
            );
 | 
					                furi_hal_subghz_capture_delta_duration,
 | 
				
			||||||
 | 
					                (void*)furi_hal_subghz_capture_callback_context);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Channel 2
 | 
					    // Channel 2
 | 
				
			||||||
    if(LL_TIM_IsActiveFlag_CC2(TIM2)) {
 | 
					    if(LL_TIM_IsActiveFlag_CC2(TIM2)) {
 | 
				
			||||||
        LL_TIM_ClearFlag_CC2(TIM2);
 | 
					        LL_TIM_ClearFlag_CC2(TIM2);
 | 
				
			||||||
        if (furi_hal_subghz_capture_callback) {
 | 
					        if(furi_hal_subghz_capture_callback) {
 | 
				
			||||||
            furi_hal_subghz_capture_callback(false, LL_TIM_IC_GetCaptureCH2(TIM2) - furi_hal_subghz_capture_delta_duration,
 | 
					            furi_hal_subghz_capture_callback(
 | 
				
			||||||
                (void*)furi_hal_subghz_capture_callback_context
 | 
					                false,
 | 
				
			||||||
            );
 | 
					                LL_TIM_IC_GetCaptureCH2(TIM2) - furi_hal_subghz_capture_delta_duration,
 | 
				
			||||||
 | 
					                (void*)furi_hal_subghz_capture_callback_context);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context) {
 | 
					void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context) {
 | 
				
			||||||
    furi_assert(furi_hal_subghz_state == SubGhzStateIdle);
 | 
					    furi_assert(furi_hal_subghz_state == SubGhzStateIdle);
 | 
				
			||||||
    furi_hal_subghz_state = SubGhzStateAsyncRx;
 | 
					    furi_hal_subghz_state = SubGhzStateAsyncRx;
 | 
				
			||||||
@ -463,12 +473,13 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
 | 
				
			|||||||
    furi_hal_subghz_capture_callback = callback;
 | 
					    furi_hal_subghz_capture_callback = callback;
 | 
				
			||||||
    furi_hal_subghz_capture_callback_context = context;
 | 
					    furi_hal_subghz_capture_callback_context = context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hal_gpio_init_ex(&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
 | 
					    hal_gpio_init_ex(
 | 
				
			||||||
 | 
					        &gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Timer: base
 | 
					    // Timer: base
 | 
				
			||||||
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
					    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
				
			||||||
    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
					    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
				
			||||||
    TIM_InitStruct.Prescaler = 64-1; 
 | 
					    TIM_InitStruct.Prescaler = 64 - 1;
 | 
				
			||||||
    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
					    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
				
			||||||
    TIM_InitStruct.Autoreload = 0x7FFFFFFE;
 | 
					    TIM_InitStruct.Autoreload = 0x7FFFFFFE;
 | 
				
			||||||
    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
					    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
				
			||||||
@ -498,7 +509,7 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // ISR setup
 | 
					    // ISR setup
 | 
				
			||||||
    furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_subghz_capture_ISR);
 | 
					    furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_subghz_capture_ISR);
 | 
				
			||||||
    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
 | 
					    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
 | 
				
			||||||
    NVIC_EnableIRQ(TIM2_IRQn);
 | 
					    NVIC_EnableIRQ(TIM2_IRQn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Interrupts and channels
 | 
					    // Interrupts and channels
 | 
				
			||||||
@ -508,7 +519,7 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
 | 
				
			|||||||
    LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
 | 
					    LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Enable NVIC
 | 
					    // Enable NVIC
 | 
				
			||||||
    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
 | 
					    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
 | 
				
			||||||
    NVIC_EnableIRQ(TIM2_IRQn);
 | 
					    NVIC_EnableIRQ(TIM2_IRQn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Start timer
 | 
					    // Start timer
 | 
				
			||||||
@ -534,8 +545,8 @@ void furi_hal_subghz_stop_async_rx() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256)
 | 
					#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256)
 | 
				
			||||||
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL/2)
 | 
					#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL / 2)
 | 
				
			||||||
#define API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME  333
 | 
					#define API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME 333
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    uint32_t* buffer;
 | 
					    uint32_t* buffer;
 | 
				
			||||||
@ -547,12 +558,13 @@ typedef struct {
 | 
				
			|||||||
static FuriHalSubGhzAsyncTx furi_hal_subghz_async_tx = {0};
 | 
					static FuriHalSubGhzAsyncTx furi_hal_subghz_async_tx = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
					static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
				
			||||||
    while (samples > 0) {
 | 
					    while(samples > 0) {
 | 
				
			||||||
        bool is_odd = samples % 2;
 | 
					        bool is_odd = samples % 2;
 | 
				
			||||||
        LevelDuration ld = furi_hal_subghz_async_tx.callback(furi_hal_subghz_async_tx.callback_context);
 | 
					        LevelDuration ld =
 | 
				
			||||||
        if (level_duration_is_reset(ld)) {
 | 
					            furi_hal_subghz_async_tx.callback(furi_hal_subghz_async_tx.callback_context);
 | 
				
			||||||
 | 
					        if(level_duration_is_reset(ld)) {
 | 
				
			||||||
            // One more even sample required to end at low level
 | 
					            // One more even sample required to end at low level
 | 
				
			||||||
            if (is_odd) {
 | 
					            if(is_odd) {
 | 
				
			||||||
                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
					                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
				
			||||||
                buffer++;
 | 
					                buffer++;
 | 
				
			||||||
                samples--;
 | 
					                samples--;
 | 
				
			||||||
@ -560,7 +572,7 @@ static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            // Inject guard time if level is incorrect
 | 
					            // Inject guard time if level is incorrect
 | 
				
			||||||
            if (is_odd == level_duration_get_level(ld)) {
 | 
					            if(is_odd == level_duration_get_level(ld)) {
 | 
				
			||||||
                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
					                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
				
			||||||
                buffer++;
 | 
					                buffer++;
 | 
				
			||||||
                samples--;
 | 
					                samples--;
 | 
				
			||||||
@ -579,21 +591,24 @@ static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void furi_hal_subghz_async_tx_dma_isr() {
 | 
					static void furi_hal_subghz_async_tx_dma_isr() {
 | 
				
			||||||
    furi_assert(furi_hal_subghz_state == SubGhzStateAsyncTx);
 | 
					    furi_assert(furi_hal_subghz_state == SubGhzStateAsyncTx);
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_HT1(DMA1)) {
 | 
					    if(LL_DMA_IsActiveFlag_HT1(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_HT1(DMA1);
 | 
					        LL_DMA_ClearFlag_HT1(DMA1);
 | 
				
			||||||
        furi_hal_subghz_async_tx_refill(furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
					        furi_hal_subghz_async_tx_refill(
 | 
				
			||||||
 | 
					            furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TC1(DMA1)) {
 | 
					    if(LL_DMA_IsActiveFlag_TC1(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TC1(DMA1);
 | 
					        LL_DMA_ClearFlag_TC1(DMA1);
 | 
				
			||||||
        furi_hal_subghz_async_tx_refill(furi_hal_subghz_async_tx.buffer+API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
					        furi_hal_subghz_async_tx_refill(
 | 
				
			||||||
 | 
					            furi_hal_subghz_async_tx.buffer + API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF,
 | 
				
			||||||
 | 
					            API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void furi_hal_subghz_async_tx_timer_isr() {
 | 
					static void furi_hal_subghz_async_tx_timer_isr() {
 | 
				
			||||||
    if(LL_TIM_IsActiveFlag_UPDATE(TIM2)) {
 | 
					    if(LL_TIM_IsActiveFlag_UPDATE(TIM2)) {
 | 
				
			||||||
        LL_TIM_ClearFlag_UPDATE(TIM2);
 | 
					        LL_TIM_ClearFlag_UPDATE(TIM2);
 | 
				
			||||||
        if (LL_TIM_GetAutoReload(TIM2) == 0) {
 | 
					        if(LL_TIM_GetAutoReload(TIM2) == 0) {
 | 
				
			||||||
            if (furi_hal_subghz_state == SubGhzStateAsyncTx) {
 | 
					            if(furi_hal_subghz_state == SubGhzStateAsyncTx) {
 | 
				
			||||||
                furi_hal_subghz_state = SubGhzStateAsyncTxLast;
 | 
					                furi_hal_subghz_state = SubGhzStateAsyncTxLast;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                furi_hal_subghz_state = SubGhzStateAsyncTxEnd;
 | 
					                furi_hal_subghz_state = SubGhzStateAsyncTxEnd;
 | 
				
			||||||
@ -612,15 +627,18 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    furi_hal_subghz_state = SubGhzStateAsyncTx;
 | 
					    furi_hal_subghz_state = SubGhzStateAsyncTx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_hal_subghz_async_tx.buffer = furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
 | 
					    furi_hal_subghz_async_tx.buffer =
 | 
				
			||||||
    furi_hal_subghz_async_tx_refill(furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL);
 | 
					        furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
 | 
				
			||||||
 | 
					    furi_hal_subghz_async_tx_refill(
 | 
				
			||||||
 | 
					        furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Connect CC1101_GD0 to TIM2 as output
 | 
					    // Connect CC1101_GD0 to TIM2 as output
 | 
				
			||||||
    hal_gpio_init_ex(&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullDown, GpioSpeedLow, GpioAltFn1TIM2);
 | 
					    hal_gpio_init_ex(
 | 
				
			||||||
 | 
					        &gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullDown, GpioSpeedLow, GpioAltFn1TIM2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Configure DMA
 | 
					    // Configure DMA
 | 
				
			||||||
    LL_DMA_InitTypeDef dma_config = {0};
 | 
					    LL_DMA_InitTypeDef dma_config = {0};
 | 
				
			||||||
    dma_config.PeriphOrM2MSrcAddress = (uint32_t)&(TIM2->ARR);
 | 
					    dma_config.PeriphOrM2MSrcAddress = (uint32_t) & (TIM2->ARR);
 | 
				
			||||||
    dma_config.MemoryOrM2MDstAddress = (uint32_t)furi_hal_subghz_async_tx.buffer;
 | 
					    dma_config.MemoryOrM2MDstAddress = (uint32_t)furi_hal_subghz_async_tx.buffer;
 | 
				
			||||||
    dma_config.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
 | 
					    dma_config.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
 | 
				
			||||||
    dma_config.Mode = LL_DMA_MODE_CIRCULAR;
 | 
					    dma_config.Mode = LL_DMA_MODE_CIRCULAR;
 | 
				
			||||||
@ -632,7 +650,8 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
    dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM2_UP;
 | 
					    dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM2_UP;
 | 
				
			||||||
    dma_config.Priority = LL_DMA_MODE_NORMAL;
 | 
					    dma_config.Priority = LL_DMA_MODE_NORMAL;
 | 
				
			||||||
    LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config);
 | 
					    LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config);
 | 
				
			||||||
    furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, furi_hal_subghz_async_tx_dma_isr);
 | 
					    furi_hal_interrupt_set_dma_channel_isr(
 | 
				
			||||||
 | 
					        DMA1, LL_DMA_CHANNEL_1, furi_hal_subghz_async_tx_dma_isr);
 | 
				
			||||||
    LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
 | 
					    LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
 | 
				
			||||||
    LL_DMA_EnableIT_HT(DMA1, LL_DMA_CHANNEL_1);
 | 
					    LL_DMA_EnableIT_HT(DMA1, LL_DMA_CHANNEL_1);
 | 
				
			||||||
    LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
 | 
					    LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
 | 
				
			||||||
@ -640,7 +659,7 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
    // Configure TIM2
 | 
					    // Configure TIM2
 | 
				
			||||||
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
					    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
				
			||||||
    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
					    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
				
			||||||
    TIM_InitStruct.Prescaler = 64-1;
 | 
					    TIM_InitStruct.Prescaler = 64 - 1;
 | 
				
			||||||
    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
					    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
				
			||||||
    TIM_InitStruct.Autoreload = 1000;
 | 
					    TIM_InitStruct.Autoreload = 1000;
 | 
				
			||||||
    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
					    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
				
			||||||
@ -672,7 +691,7 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
    furi_hal_subghz_tx();
 | 
					    furi_hal_subghz_tx();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Enable NVIC
 | 
					    // Enable NVIC
 | 
				
			||||||
    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
 | 
					    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
 | 
				
			||||||
    NVIC_EnableIRQ(TIM2_IRQn);
 | 
					    NVIC_EnableIRQ(TIM2_IRQn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    LL_TIM_SetCounter(TIM2, 0);
 | 
					    LL_TIM_SetCounter(TIM2, 0);
 | 
				
			||||||
@ -685,10 +704,9 @@ bool furi_hal_subghz_is_async_tx_complete() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void furi_hal_subghz_stop_async_tx() {
 | 
					void furi_hal_subghz_stop_async_tx() {
 | 
				
			||||||
    furi_assert(
 | 
					    furi_assert(
 | 
				
			||||||
        furi_hal_subghz_state == SubGhzStateAsyncTx
 | 
					        furi_hal_subghz_state == SubGhzStateAsyncTx ||
 | 
				
			||||||
        || furi_hal_subghz_state == SubGhzStateAsyncTxLast
 | 
					        furi_hal_subghz_state == SubGhzStateAsyncTxLast ||
 | 
				
			||||||
        || furi_hal_subghz_state == SubGhzStateAsyncTxEnd
 | 
					        furi_hal_subghz_state == SubGhzStateAsyncTxEnd);
 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Shutdown radio
 | 
					    // Shutdown radio
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    furi_hal_subghz_idle();
 | 
				
			||||||
 | 
				
			|||||||
@ -163,7 +163,7 @@ void furi_hal_version_init() {
 | 
				
			|||||||
        case FuriHalVersionOtpVersion1:
 | 
					        case FuriHalVersionOtpVersion1:
 | 
				
			||||||
            furi_hal_version_load_otp_v1();
 | 
					            furi_hal_version_load_otp_v1();
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
        default: furi_check(0);
 | 
					        default: furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    FURI_LOG_I("FuriHalVersion", "Init OK");
 | 
					    FURI_LOG_I("FuriHalVersion", "Init OK");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,6 @@
 | 
				
			|||||||
#include <furi-hal.h>
 | 
					#include <furi-hal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <aes.h>
 | 
					 | 
				
			||||||
#include <comp.h>
 | 
					#include <comp.h>
 | 
				
			||||||
#include <pka.h>
 | 
					 | 
				
			||||||
#include <rf.h>
 | 
					 | 
				
			||||||
#include <rng.h>
 | 
					 | 
				
			||||||
#include <rtc.h>
 | 
					#include <rtc.h>
 | 
				
			||||||
#include <tim.h>
 | 
					#include <tim.h>
 | 
				
			||||||
#include <usb_device.h>
 | 
					#include <usb_device.h>
 | 
				
			||||||
@ -34,16 +30,8 @@ void furi_hal_init() {
 | 
				
			|||||||
    FURI_LOG_I("HAL", "TIM16 OK");
 | 
					    FURI_LOG_I("HAL", "TIM16 OK");
 | 
				
			||||||
    MX_COMP1_Init();
 | 
					    MX_COMP1_Init();
 | 
				
			||||||
    FURI_LOG_I("HAL", "COMP1 OK");
 | 
					    FURI_LOG_I("HAL", "COMP1 OK");
 | 
				
			||||||
    MX_RF_Init();
 | 
					
 | 
				
			||||||
    FURI_LOG_I("HAL", "RF OK");
 | 
					    furi_hal_crypto_init();
 | 
				
			||||||
    MX_PKA_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "PKA OK");
 | 
					 | 
				
			||||||
    MX_RNG_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "RNG OK");
 | 
					 | 
				
			||||||
    MX_AES1_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "AES1 OK");
 | 
					 | 
				
			||||||
    MX_AES2_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "AES2 OK");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // VCP + USB
 | 
					    // VCP + USB
 | 
				
			||||||
    furi_hal_vcp_init();
 | 
					    furi_hal_vcp_init();
 | 
				
			||||||
 | 
				
			|||||||
@ -1,445 +1,444 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
  ******************************************************************************
 | 
					  ******************************************************************************
 | 
				
			||||||
  * @file      startup_stm32wb55xx_cm4.s
 | 
					  * @file      startup_stm32wb55xx_cm4.s
 | 
				
			||||||
  * @author    MCD Application Team
 | 
					  * @author    MCD Application Team
 | 
				
			||||||
  * @brief     STM32WB55xx devices vector table GCC toolchain.
 | 
					  * @brief     STM32WB55xx devices vector table GCC toolchain.
 | 
				
			||||||
  *            This module performs:
 | 
					  *            This module performs:
 | 
				
			||||||
  *                - Set the initial SP
 | 
					  *                - Set the initial SP
 | 
				
			||||||
  *                - Set the initial PC == Reset_Handler,
 | 
					  *                - Set the initial PC == Reset_Handler,
 | 
				
			||||||
  *                - Set the vector table entries with the exceptions ISR address
 | 
					  *                - Set the vector table entries with the exceptions ISR address
 | 
				
			||||||
  *                - Branches to main in the C library (which eventually
 | 
					  *                - Branches to main in the C library (which eventually
 | 
				
			||||||
  *                  calls main()).
 | 
					  *                  calls main()).
 | 
				
			||||||
  *            After Reset the Cortex-M4 processor is in Thread mode,
 | 
					  *            After Reset the Cortex-M4 processor is in Thread mode,
 | 
				
			||||||
  *            priority is Privileged, and the Stack is set to Main.
 | 
					  *            priority is Privileged, and the Stack is set to Main.
 | 
				
			||||||
  ******************************************************************************
 | 
					  ******************************************************************************
 | 
				
			||||||
  * @attention
 | 
					  * @attention
 | 
				
			||||||
  *
 | 
					  *
 | 
				
			||||||
  * <h2><center>© Copyright (c) 2019 STMicroelectronics. 
 | 
					  * Copyright (c) 2019-2021 STMicroelectronics.
 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					  * All rights reserved.
 | 
				
			||||||
  *
 | 
					  *
 | 
				
			||||||
  * This software component is licensed by ST under BSD 3-Clause license,
 | 
					  * This software is licensed under terms that can be found in the LICENSE file
 | 
				
			||||||
  * the "License"; You may not use this file except in compliance with the 
 | 
					  * in the root directory of this software component.
 | 
				
			||||||
  * License. You may obtain a copy of the License at:
 | 
					  * If no LICENSE file comes with this software, it is provided AS-IS.
 | 
				
			||||||
  *                        opensource.org/licenses/BSD-3-Clause
 | 
					  *
 | 
				
			||||||
  *
 | 
					  ******************************************************************************
 | 
				
			||||||
  ******************************************************************************
 | 
					  */
 | 
				
			||||||
  */
 | 
					
 | 
				
			||||||
 | 
					  .syntax unified
 | 
				
			||||||
  .syntax unified
 | 
						.cpu cortex-m4
 | 
				
			||||||
	.cpu cortex-m4
 | 
						.fpu softvfp
 | 
				
			||||||
	.fpu softvfp
 | 
						.thumb
 | 
				
			||||||
	.thumb
 | 
					
 | 
				
			||||||
 | 
					.global	g_pfnVectors
 | 
				
			||||||
.global	g_pfnVectors
 | 
					.global	Default_Handler
 | 
				
			||||||
.global	Default_Handler
 | 
					
 | 
				
			||||||
 | 
					/* start address for the initialization values of the .data section.
 | 
				
			||||||
/* start address for the initialization values of the .data section.
 | 
					defined in linker script */
 | 
				
			||||||
defined in linker script */
 | 
					.word	_sidata
 | 
				
			||||||
.word	_sidata
 | 
					/* start address for the .data section. defined in linker script */
 | 
				
			||||||
/* start address for the .data section. defined in linker script */
 | 
					.word	_sdata
 | 
				
			||||||
.word	_sdata
 | 
					/* end address for the .data section. defined in linker script */
 | 
				
			||||||
/* end address for the .data section. defined in linker script */
 | 
					.word	_edata
 | 
				
			||||||
.word	_edata
 | 
					/* start address for the .bss section. defined in linker script */
 | 
				
			||||||
/* start address for the .bss section. defined in linker script */
 | 
					.word	_sbss
 | 
				
			||||||
.word	_sbss
 | 
					/* end address for the .bss section. defined in linker script */
 | 
				
			||||||
/* end address for the .bss section. defined in linker script */
 | 
					.word	_ebss
 | 
				
			||||||
.word	_ebss
 | 
					/* start address for the .MB_MEM2 section. defined in linker script */
 | 
				
			||||||
/* start address for the .MB_MEM2 section. defined in linker script */
 | 
					.word _sMB_MEM2
 | 
				
			||||||
.word _sMB_MEM2
 | 
					/* end address for the .MB_MEM2 section. defined in linker script */
 | 
				
			||||||
/* end address for the .MB_MEM2 section. defined in linker script */
 | 
					.word _eMB_MEM2
 | 
				
			||||||
.word _eMB_MEM2
 | 
					
 | 
				
			||||||
 | 
					/* INIT_BSS macro is used to fill the specified region [start : end] with zeros */
 | 
				
			||||||
/* INIT_BSS macro is used to fill the specified region [start : end] with zeros */
 | 
					.macro INIT_BSS start, end
 | 
				
			||||||
.macro INIT_BSS start, end
 | 
					  ldr r0, =\start
 | 
				
			||||||
  ldr r0, =\start
 | 
					  ldr r1, =\end
 | 
				
			||||||
  ldr r1, =\end
 | 
					  movs r3, #0
 | 
				
			||||||
  movs r3, #0
 | 
					  bl LoopFillZerobss
 | 
				
			||||||
  bl LoopFillZerobss
 | 
					.endm
 | 
				
			||||||
.endm
 | 
					
 | 
				
			||||||
 | 
					/* INIT_DATA macro is used to copy data in the region [start : end] starting from 'src' */
 | 
				
			||||||
/* INIT_DATA macro is used to copy data in the region [start : end] starting from 'src' */
 | 
					.macro INIT_DATA start, end, src
 | 
				
			||||||
.macro INIT_DATA start, end, src
 | 
					  ldr r0, =\start
 | 
				
			||||||
  ldr r0, =\start
 | 
					  ldr r1, =\end
 | 
				
			||||||
  ldr r1, =\end
 | 
					  ldr r2, =\src
 | 
				
			||||||
  ldr r2, =\src
 | 
					  movs r3, #0
 | 
				
			||||||
  movs r3, #0
 | 
					  bl LoopCopyDataInit
 | 
				
			||||||
  bl LoopCopyDataInit
 | 
					.endm
 | 
				
			||||||
.endm
 | 
					
 | 
				
			||||||
 | 
					.section  .text.data_initializers
 | 
				
			||||||
.section  .text.data_initializers
 | 
					CopyDataInit:
 | 
				
			||||||
CopyDataInit:
 | 
					  ldr r4, [r2, r3]
 | 
				
			||||||
  ldr r4, [r2, r3]
 | 
					  str r4, [r0, r3]
 | 
				
			||||||
  str r4, [r0, r3]
 | 
					  adds r3, r3, #4
 | 
				
			||||||
  adds r3, r3, #4
 | 
					
 | 
				
			||||||
 | 
					LoopCopyDataInit:
 | 
				
			||||||
LoopCopyDataInit:
 | 
					  adds r4, r0, r3
 | 
				
			||||||
  adds r4, r0, r3
 | 
					  cmp r4, r1
 | 
				
			||||||
  cmp r4, r1
 | 
					  bcc  CopyDataInit
 | 
				
			||||||
  bcc  CopyDataInit
 | 
					  bx lr
 | 
				
			||||||
  bx lr
 | 
					
 | 
				
			||||||
 | 
					FillZerobss:
 | 
				
			||||||
FillZerobss:
 | 
					  str  r3, [r0]
 | 
				
			||||||
  str  r3, [r0]
 | 
					  adds r0, r0, #4
 | 
				
			||||||
  adds r0, r0, #4
 | 
					
 | 
				
			||||||
 | 
					LoopFillZerobss:
 | 
				
			||||||
LoopFillZerobss:
 | 
					  cmp r0, r1
 | 
				
			||||||
  cmp r0, r1
 | 
					  bcc FillZerobss
 | 
				
			||||||
  bcc FillZerobss
 | 
					  bx lr
 | 
				
			||||||
  bx lr
 | 
					
 | 
				
			||||||
 | 
					  .section .text.Reset_Handler
 | 
				
			||||||
  .section .text.Reset_Handler
 | 
					  .weak Reset_Handler
 | 
				
			||||||
  .weak Reset_Handler
 | 
					  .type Reset_Handler, %function
 | 
				
			||||||
  .type Reset_Handler, %function
 | 
					Reset_Handler:
 | 
				
			||||||
Reset_Handler:
 | 
					  ldr   r0, =_estack
 | 
				
			||||||
  ldr   r0, =_estack
 | 
					  mov   sp, r0          /* set stack pointer */
 | 
				
			||||||
  mov   sp, r0          /* set stack pointer */
 | 
					/* Call the clock system intitialization function.*/
 | 
				
			||||||
/* Call the clock system intitialization function.*/
 | 
					  bl  SystemInit
 | 
				
			||||||
  bl  SystemInit
 | 
					
 | 
				
			||||||
 | 
					/* Copy the data segment initializers from flash to SRAM */
 | 
				
			||||||
/* Copy the data segment initializers from flash to SRAM */
 | 
					  INIT_DATA _sdata, _edata, _sidata
 | 
				
			||||||
  INIT_DATA _sdata, _edata, _sidata
 | 
					
 | 
				
			||||||
 | 
					/* Zero fill the bss segments. */
 | 
				
			||||||
/* Zero fill the bss segments. */
 | 
					  INIT_BSS _sbss, _ebss
 | 
				
			||||||
  INIT_BSS _sbss, _ebss
 | 
					  INIT_BSS _sMB_MEM2, _eMB_MEM2
 | 
				
			||||||
  INIT_BSS _sMB_MEM2, _eMB_MEM2
 | 
					
 | 
				
			||||||
 | 
					/* Call static constructors */
 | 
				
			||||||
/* Call static constructors */
 | 
					  bl __libc_init_array
 | 
				
			||||||
  bl __libc_init_array
 | 
					/* Call the application s entry point.*/
 | 
				
			||||||
/* Call the application s entry point.*/
 | 
						bl	main
 | 
				
			||||||
	bl	main
 | 
					
 | 
				
			||||||
 | 
					LoopForever:
 | 
				
			||||||
LoopForever:
 | 
					  b LoopForever
 | 
				
			||||||
  b LoopForever
 | 
					    
 | 
				
			||||||
    
 | 
					.size	Reset_Handler, .-Reset_Handler
 | 
				
			||||||
.size	Reset_Handler, .-Reset_Handler
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
/**
 | 
					 * @brief  This is the code that gets called when the processor receives an
 | 
				
			||||||
 * @brief  This is the code that gets called when the processor receives an
 | 
					 *         unexpected interrupt.  This simply enters an infinite loop, preserving
 | 
				
			||||||
 *         unexpected interrupt.  This simply enters an infinite loop, preserving
 | 
					 *         the system state for examination by a debugger.
 | 
				
			||||||
 *         the system state for examination by a debugger.
 | 
					 *
 | 
				
			||||||
 *
 | 
					 * @param  None
 | 
				
			||||||
 * @param  None
 | 
					 * @retval None
 | 
				
			||||||
 * @retval None
 | 
					*/
 | 
				
			||||||
*/
 | 
					  .section .text.Default_Handler,"ax",%progbits
 | 
				
			||||||
  .section .text.Default_Handler,"ax",%progbits
 | 
					Default_Handler:
 | 
				
			||||||
Default_Handler:
 | 
					Infinite_Loop:
 | 
				
			||||||
Infinite_Loop:
 | 
						b	Infinite_Loop
 | 
				
			||||||
	b	Infinite_Loop
 | 
						.size	Default_Handler, .-Default_Handler
 | 
				
			||||||
	.size	Default_Handler, .-Default_Handler
 | 
					/******************************************************************************
 | 
				
			||||||
/******************************************************************************
 | 
					*
 | 
				
			||||||
*
 | 
					* The minimal vector table for a Cortex-M4.  Note that the proper constructs
 | 
				
			||||||
* The minimal vector table for a Cortex-M4.  Note that the proper constructs
 | 
					* must be placed on this to ensure that it ends up at physical address
 | 
				
			||||||
* must be placed on this to ensure that it ends up at physical address
 | 
					* 0x0000.0000.
 | 
				
			||||||
* 0x0000.0000.
 | 
					*
 | 
				
			||||||
*
 | 
					******************************************************************************/
 | 
				
			||||||
******************************************************************************/
 | 
					 	.section	.isr_vector,"a",%progbits
 | 
				
			||||||
 	.section	.isr_vector,"a",%progbits
 | 
						.type	g_pfnVectors, %object
 | 
				
			||||||
	.type	g_pfnVectors, %object
 | 
						.size	g_pfnVectors, .-g_pfnVectors
 | 
				
			||||||
	.size	g_pfnVectors, .-g_pfnVectors
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					g_pfnVectors:
 | 
				
			||||||
g_pfnVectors:
 | 
					  .word _estack
 | 
				
			||||||
  .word _estack
 | 
					  .word Reset_Handler
 | 
				
			||||||
  .word Reset_Handler
 | 
						.word	NMI_Handler
 | 
				
			||||||
	.word	NMI_Handler
 | 
					  .word HardFault_Handler
 | 
				
			||||||
  .word HardFault_Handler
 | 
					  .word MemManage_Handler
 | 
				
			||||||
  .word MemManage_Handler
 | 
					  .word BusFault_Handler
 | 
				
			||||||
  .word BusFault_Handler
 | 
					  .word UsageFault_Handler
 | 
				
			||||||
  .word UsageFault_Handler
 | 
					  .word 0
 | 
				
			||||||
  .word 0
 | 
					  .word 0
 | 
				
			||||||
  .word 0
 | 
					  .word 0
 | 
				
			||||||
  .word 0
 | 
					  .word 0
 | 
				
			||||||
  .word 0
 | 
					  .word SVC_Handler
 | 
				
			||||||
  .word SVC_Handler
 | 
					  .word DebugMon_Handler
 | 
				
			||||||
  .word DebugMon_Handler
 | 
					  .word 0
 | 
				
			||||||
  .word 0
 | 
					  .word PendSV_Handler
 | 
				
			||||||
  .word PendSV_Handler
 | 
					  .word SysTick_Handler
 | 
				
			||||||
  .word SysTick_Handler
 | 
					  .word WWDG_IRQHandler
 | 
				
			||||||
  .word WWDG_IRQHandler
 | 
					  .word PVD_PVM_IRQHandler
 | 
				
			||||||
  .word PVD_PVM_IRQHandler
 | 
					  .word TAMP_STAMP_LSECSS_IRQHandler
 | 
				
			||||||
  .word TAMP_STAMP_LSECSS_IRQHandler
 | 
					  .word RTC_WKUP_IRQHandler
 | 
				
			||||||
  .word RTC_WKUP_IRQHandler
 | 
					  .word FLASH_IRQHandler
 | 
				
			||||||
  .word FLASH_IRQHandler
 | 
					  .word RCC_IRQHandler
 | 
				
			||||||
  .word RCC_IRQHandler
 | 
					  .word EXTI0_IRQHandler
 | 
				
			||||||
  .word EXTI0_IRQHandler
 | 
					  .word EXTI1_IRQHandler
 | 
				
			||||||
  .word EXTI1_IRQHandler
 | 
					  .word EXTI2_IRQHandler
 | 
				
			||||||
  .word EXTI2_IRQHandler
 | 
					  .word EXTI3_IRQHandler
 | 
				
			||||||
  .word EXTI3_IRQHandler
 | 
					  .word EXTI4_IRQHandler
 | 
				
			||||||
  .word EXTI4_IRQHandler
 | 
					  .word DMA1_Channel1_IRQHandler
 | 
				
			||||||
  .word DMA1_Channel1_IRQHandler
 | 
					  .word DMA1_Channel2_IRQHandler
 | 
				
			||||||
  .word DMA1_Channel2_IRQHandler
 | 
					  .word DMA1_Channel3_IRQHandler
 | 
				
			||||||
  .word DMA1_Channel3_IRQHandler
 | 
					  .word DMA1_Channel4_IRQHandler
 | 
				
			||||||
  .word DMA1_Channel4_IRQHandler
 | 
					  .word DMA1_Channel5_IRQHandler
 | 
				
			||||||
  .word DMA1_Channel5_IRQHandler
 | 
					  .word DMA1_Channel6_IRQHandler
 | 
				
			||||||
  .word DMA1_Channel6_IRQHandler
 | 
					  .word DMA1_Channel7_IRQHandler
 | 
				
			||||||
  .word DMA1_Channel7_IRQHandler
 | 
					  .word ADC1_IRQHandler
 | 
				
			||||||
  .word ADC1_IRQHandler
 | 
					  .word USB_HP_IRQHandler
 | 
				
			||||||
  .word USB_HP_IRQHandler
 | 
					  .word USB_LP_IRQHandler
 | 
				
			||||||
  .word USB_LP_IRQHandler
 | 
					  .word C2SEV_PWR_C2H_IRQHandler
 | 
				
			||||||
  .word C2SEV_PWR_C2H_IRQHandler
 | 
					  .word COMP_IRQHandler
 | 
				
			||||||
  .word COMP_IRQHandler
 | 
					  .word EXTI9_5_IRQHandler
 | 
				
			||||||
  .word EXTI9_5_IRQHandler
 | 
					  .word TIM1_BRK_IRQHandler
 | 
				
			||||||
  .word TIM1_BRK_IRQHandler
 | 
					  .word TIM1_UP_TIM16_IRQHandler
 | 
				
			||||||
  .word TIM1_UP_TIM16_IRQHandler
 | 
					  .word TIM1_TRG_COM_TIM17_IRQHandler
 | 
				
			||||||
  .word TIM1_TRG_COM_TIM17_IRQHandler
 | 
					  .word TIM1_CC_IRQHandler
 | 
				
			||||||
  .word TIM1_CC_IRQHandler
 | 
					  .word TIM2_IRQHandler
 | 
				
			||||||
  .word TIM2_IRQHandler
 | 
					  .word PKA_IRQHandler
 | 
				
			||||||
  .word PKA_IRQHandler
 | 
					  .word I2C1_EV_IRQHandler
 | 
				
			||||||
  .word I2C1_EV_IRQHandler
 | 
					  .word I2C1_ER_IRQHandler
 | 
				
			||||||
  .word I2C1_ER_IRQHandler
 | 
					  .word I2C3_EV_IRQHandler
 | 
				
			||||||
  .word I2C3_EV_IRQHandler
 | 
					  .word I2C3_ER_IRQHandler
 | 
				
			||||||
  .word I2C3_ER_IRQHandler
 | 
					  .word SPI1_IRQHandler
 | 
				
			||||||
  .word SPI1_IRQHandler
 | 
					  .word SPI2_IRQHandler
 | 
				
			||||||
  .word SPI2_IRQHandler
 | 
					  .word USART1_IRQHandler
 | 
				
			||||||
  .word USART1_IRQHandler
 | 
					  .word LPUART1_IRQHandler
 | 
				
			||||||
  .word LPUART1_IRQHandler
 | 
					  .word SAI1_IRQHandler
 | 
				
			||||||
  .word SAI1_IRQHandler
 | 
					  .word TSC_IRQHandler
 | 
				
			||||||
  .word TSC_IRQHandler
 | 
					  .word EXTI15_10_IRQHandler
 | 
				
			||||||
  .word EXTI15_10_IRQHandler
 | 
					  .word RTC_Alarm_IRQHandler
 | 
				
			||||||
  .word RTC_Alarm_IRQHandler
 | 
					  .word CRS_IRQHandler
 | 
				
			||||||
  .word CRS_IRQHandler
 | 
					  .word PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
 | 
				
			||||||
  .word PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
 | 
					  .word IPCC_C1_RX_IRQHandler
 | 
				
			||||||
  .word IPCC_C1_RX_IRQHandler
 | 
					  .word IPCC_C1_TX_IRQHandler
 | 
				
			||||||
  .word IPCC_C1_TX_IRQHandler
 | 
					  .word HSEM_IRQHandler
 | 
				
			||||||
  .word HSEM_IRQHandler
 | 
					  .word LPTIM1_IRQHandler
 | 
				
			||||||
  .word LPTIM1_IRQHandler
 | 
					  .word LPTIM2_IRQHandler
 | 
				
			||||||
  .word LPTIM2_IRQHandler
 | 
					  .word LCD_IRQHandler
 | 
				
			||||||
  .word LCD_IRQHandler
 | 
					  .word QUADSPI_IRQHandler
 | 
				
			||||||
  .word QUADSPI_IRQHandler
 | 
					  .word AES1_IRQHandler
 | 
				
			||||||
  .word AES1_IRQHandler
 | 
					  .word AES2_IRQHandler
 | 
				
			||||||
  .word AES2_IRQHandler
 | 
					  .word RNG_IRQHandler
 | 
				
			||||||
  .word RNG_IRQHandler
 | 
					  .word FPU_IRQHandler
 | 
				
			||||||
  .word FPU_IRQHandler
 | 
					  .word DMA2_Channel1_IRQHandler
 | 
				
			||||||
  .word DMA2_Channel1_IRQHandler
 | 
					  .word DMA2_Channel2_IRQHandler
 | 
				
			||||||
  .word DMA2_Channel2_IRQHandler
 | 
					  .word DMA2_Channel3_IRQHandler
 | 
				
			||||||
  .word DMA2_Channel3_IRQHandler
 | 
					  .word DMA2_Channel4_IRQHandler
 | 
				
			||||||
  .word DMA2_Channel4_IRQHandler
 | 
					  .word DMA2_Channel5_IRQHandler
 | 
				
			||||||
  .word DMA2_Channel5_IRQHandler
 | 
					  .word DMA2_Channel6_IRQHandler
 | 
				
			||||||
  .word DMA2_Channel6_IRQHandler
 | 
					  .word DMA2_Channel7_IRQHandler
 | 
				
			||||||
  .word DMA2_Channel7_IRQHandler
 | 
					  .word DMAMUX1_OVR_IRQHandler
 | 
				
			||||||
  .word DMAMUX1_OVR_IRQHandler
 | 
					
 | 
				
			||||||
 | 
					/*******************************************************************************
 | 
				
			||||||
/*******************************************************************************
 | 
					*
 | 
				
			||||||
*
 | 
					* Provide weak aliases for each Exception handler to the Default_Handler.
 | 
				
			||||||
* Provide weak aliases for each Exception handler to the Default_Handler.
 | 
					* As they are weak aliases, any function with the same name will override
 | 
				
			||||||
* As they are weak aliases, any function with the same name will override
 | 
					* this definition.
 | 
				
			||||||
* this definition.
 | 
					*
 | 
				
			||||||
*
 | 
					*******************************************************************************/
 | 
				
			||||||
*******************************************************************************/
 | 
					  .weak	NMI_Handler
 | 
				
			||||||
  .weak	NMI_Handler
 | 
					  .thumb_set NMI_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set NMI_Handler,Default_Handler
 | 
					  
 | 
				
			||||||
  
 | 
					  .weak  HardFault_Handler
 | 
				
			||||||
  .weak  HardFault_Handler
 | 
					  .thumb_set HardFault_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set HardFault_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  MemManage_Handler
 | 
				
			||||||
  .weak  MemManage_Handler
 | 
					  .thumb_set MemManage_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set MemManage_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  BusFault_Handler
 | 
				
			||||||
  .weak  BusFault_Handler
 | 
					  .thumb_set BusFault_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set BusFault_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  UsageFault_Handler
 | 
				
			||||||
  .weak  UsageFault_Handler
 | 
					  .thumb_set UsageFault_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set UsageFault_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  SVC_Handler
 | 
				
			||||||
  .weak  SVC_Handler
 | 
					  .thumb_set SVC_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set SVC_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DebugMon_Handler
 | 
				
			||||||
  .weak  DebugMon_Handler
 | 
					  .thumb_set DebugMon_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set DebugMon_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  PendSV_Handler
 | 
				
			||||||
  .weak  PendSV_Handler
 | 
					  .thumb_set PendSV_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set PendSV_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  SysTick_Handler
 | 
				
			||||||
  .weak  SysTick_Handler
 | 
					  .thumb_set SysTick_Handler,Default_Handler
 | 
				
			||||||
  .thumb_set SysTick_Handler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  WWDG_IRQHandler
 | 
				
			||||||
  .weak  WWDG_IRQHandler
 | 
					  .thumb_set WWDG_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set WWDG_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  PVD_PVM_IRQHandler
 | 
				
			||||||
  .weak  PVD_PVM_IRQHandler
 | 
					  .thumb_set PVD_PVM_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set PVD_PVM_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  TAMP_STAMP_LSECSS_IRQHandler
 | 
				
			||||||
  .weak  TAMP_STAMP_LSECSS_IRQHandler
 | 
					  .thumb_set TAMP_STAMP_LSECSS_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set TAMP_STAMP_LSECSS_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  RTC_WKUP_IRQHandler
 | 
				
			||||||
  .weak  RTC_WKUP_IRQHandler
 | 
					  .thumb_set RTC_WKUP_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set RTC_WKUP_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  FLASH_IRQHandler
 | 
				
			||||||
  .weak  FLASH_IRQHandler
 | 
					  .thumb_set FLASH_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set FLASH_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  RCC_IRQHandler
 | 
				
			||||||
  .weak  RCC_IRQHandler
 | 
					  .thumb_set RCC_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set RCC_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  EXTI0_IRQHandler
 | 
				
			||||||
  .weak  EXTI0_IRQHandler
 | 
					  .thumb_set EXTI0_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set EXTI0_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  EXTI1_IRQHandler
 | 
				
			||||||
  .weak  EXTI1_IRQHandler
 | 
					  .thumb_set EXTI1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set EXTI1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  EXTI2_IRQHandler
 | 
				
			||||||
  .weak  EXTI2_IRQHandler
 | 
					  .thumb_set EXTI2_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set EXTI2_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  EXTI3_IRQHandler
 | 
				
			||||||
  .weak  EXTI3_IRQHandler
 | 
					  .thumb_set EXTI3_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set EXTI3_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  EXTI4_IRQHandler
 | 
				
			||||||
  .weak  EXTI4_IRQHandler
 | 
					  .thumb_set EXTI4_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set EXTI4_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA1_Channel1_IRQHandler
 | 
				
			||||||
  .weak  DMA1_Channel1_IRQHandler
 | 
					  .thumb_set DMA1_Channel1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA1_Channel1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA1_Channel2_IRQHandler
 | 
				
			||||||
  .weak  DMA1_Channel2_IRQHandler
 | 
					  .thumb_set DMA1_Channel2_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA1_Channel2_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA1_Channel3_IRQHandler
 | 
				
			||||||
  .weak  DMA1_Channel3_IRQHandler
 | 
					  .thumb_set DMA1_Channel3_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA1_Channel3_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA1_Channel4_IRQHandler
 | 
				
			||||||
  .weak  DMA1_Channel4_IRQHandler
 | 
					  .thumb_set DMA1_Channel4_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA1_Channel4_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA1_Channel5_IRQHandler
 | 
				
			||||||
  .weak  DMA1_Channel5_IRQHandler
 | 
					  .thumb_set DMA1_Channel5_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA1_Channel5_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA1_Channel6_IRQHandler
 | 
				
			||||||
  .weak  DMA1_Channel6_IRQHandler
 | 
					  .thumb_set DMA1_Channel6_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA1_Channel6_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA1_Channel7_IRQHandler
 | 
				
			||||||
  .weak  DMA1_Channel7_IRQHandler
 | 
					  .thumb_set DMA1_Channel7_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA1_Channel7_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  ADC1_IRQHandler
 | 
				
			||||||
  .weak  ADC1_IRQHandler
 | 
					  .thumb_set ADC1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set ADC1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  USB_HP_IRQHandler
 | 
				
			||||||
  .weak  USB_HP_IRQHandler
 | 
					  .thumb_set USB_HP_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set USB_HP_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  USB_LP_IRQHandler
 | 
				
			||||||
  .weak  USB_LP_IRQHandler
 | 
					  .thumb_set USB_LP_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set USB_LP_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  C2SEV_PWR_C2H_IRQHandler
 | 
				
			||||||
  .weak  C2SEV_PWR_C2H_IRQHandler
 | 
					  .thumb_set C2SEV_PWR_C2H_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set C2SEV_PWR_C2H_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  COMP_IRQHandler
 | 
				
			||||||
  .weak  COMP_IRQHandler
 | 
					  .thumb_set COMP_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set COMP_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  EXTI9_5_IRQHandler
 | 
				
			||||||
  .weak  EXTI9_5_IRQHandler
 | 
					  .thumb_set EXTI9_5_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set EXTI9_5_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  TIM1_BRK_IRQHandler
 | 
				
			||||||
  .weak  TIM1_BRK_IRQHandler
 | 
					  .thumb_set TIM1_BRK_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set TIM1_BRK_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  TIM1_UP_TIM16_IRQHandler
 | 
				
			||||||
  .weak  TIM1_UP_TIM16_IRQHandler
 | 
					  .thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  TIM1_TRG_COM_TIM17_IRQHandler
 | 
				
			||||||
  .weak  TIM1_TRG_COM_TIM17_IRQHandler
 | 
					  .thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  TIM1_CC_IRQHandler
 | 
				
			||||||
  .weak  TIM1_CC_IRQHandler
 | 
					  .thumb_set TIM1_CC_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set TIM1_CC_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  TIM2_IRQHandler
 | 
				
			||||||
  .weak  TIM2_IRQHandler
 | 
					  .thumb_set TIM2_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set TIM2_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  PKA_IRQHandler
 | 
				
			||||||
  .weak  PKA_IRQHandler
 | 
					  .thumb_set PKA_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set PKA_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  I2C1_EV_IRQHandler
 | 
				
			||||||
  .weak  I2C1_EV_IRQHandler
 | 
					  .thumb_set I2C1_EV_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set I2C1_EV_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  I2C1_ER_IRQHandler
 | 
				
			||||||
  .weak  I2C1_ER_IRQHandler
 | 
					  .thumb_set I2C1_ER_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set I2C1_ER_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  I2C3_EV_IRQHandler
 | 
				
			||||||
  .weak  I2C3_EV_IRQHandler
 | 
					  .thumb_set I2C3_EV_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set I2C3_EV_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  I2C3_ER_IRQHandler
 | 
				
			||||||
  .weak  I2C3_ER_IRQHandler
 | 
					  .thumb_set I2C3_ER_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set I2C3_ER_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  SPI1_IRQHandler
 | 
				
			||||||
  .weak  SPI1_IRQHandler
 | 
					  .thumb_set SPI1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set SPI1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  SPI2_IRQHandler
 | 
				
			||||||
  .weak  SPI2_IRQHandler
 | 
					  .thumb_set SPI2_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set SPI2_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  USART1_IRQHandler
 | 
				
			||||||
  .weak  USART1_IRQHandler
 | 
					  .thumb_set USART1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set USART1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  LPUART1_IRQHandler
 | 
				
			||||||
  .weak  LPUART1_IRQHandler
 | 
					  .thumb_set LPUART1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set LPUART1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  SAI1_IRQHandler
 | 
				
			||||||
  .weak  SAI1_IRQHandler
 | 
					  .thumb_set SAI1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set SAI1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  TSC_IRQHandler
 | 
				
			||||||
  .weak  TSC_IRQHandler
 | 
					  .thumb_set TSC_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set TSC_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  EXTI15_10_IRQHandler
 | 
				
			||||||
  .weak  EXTI15_10_IRQHandler
 | 
					  .thumb_set EXTI15_10_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set EXTI15_10_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  RTC_Alarm_IRQHandler
 | 
				
			||||||
  .weak  RTC_Alarm_IRQHandler
 | 
					  .thumb_set RTC_Alarm_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set RTC_Alarm_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  CRS_IRQHandler
 | 
				
			||||||
  .weak  CRS_IRQHandler
 | 
					  .thumb_set CRS_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set CRS_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
 | 
				
			||||||
  .weak  PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
 | 
					  .thumb_set PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  IPCC_C1_RX_IRQHandler
 | 
				
			||||||
  .weak  IPCC_C1_RX_IRQHandler
 | 
					  .thumb_set IPCC_C1_RX_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set IPCC_C1_RX_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  IPCC_C1_TX_IRQHandler
 | 
				
			||||||
  .weak  IPCC_C1_TX_IRQHandler
 | 
					  .thumb_set IPCC_C1_TX_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set IPCC_C1_TX_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  HSEM_IRQHandler
 | 
				
			||||||
  .weak  HSEM_IRQHandler
 | 
					  .thumb_set HSEM_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set HSEM_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  LPTIM1_IRQHandler
 | 
				
			||||||
  .weak  LPTIM1_IRQHandler
 | 
					  .thumb_set LPTIM1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set LPTIM1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  LPTIM2_IRQHandler
 | 
				
			||||||
  .weak  LPTIM2_IRQHandler
 | 
					  .thumb_set LPTIM2_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set LPTIM2_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  LCD_IRQHandler
 | 
				
			||||||
  .weak  LCD_IRQHandler
 | 
					  .thumb_set LCD_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set LCD_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  QUADSPI_IRQHandler
 | 
				
			||||||
  .weak  QUADSPI_IRQHandler
 | 
					  .thumb_set QUADSPI_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set QUADSPI_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  AES1_IRQHandler
 | 
				
			||||||
  .weak  AES1_IRQHandler
 | 
					  .thumb_set AES1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set AES1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  AES2_IRQHandler
 | 
				
			||||||
  .weak  AES2_IRQHandler
 | 
					  .thumb_set AES2_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set AES2_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  RNG_IRQHandler
 | 
				
			||||||
  .weak  RNG_IRQHandler
 | 
					  .thumb_set RNG_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set RNG_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  FPU_IRQHandler
 | 
				
			||||||
  .weak  FPU_IRQHandler
 | 
					  .thumb_set FPU_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set FPU_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA2_Channel1_IRQHandler
 | 
				
			||||||
  .weak  DMA2_Channel1_IRQHandler
 | 
					  .thumb_set DMA2_Channel1_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA2_Channel1_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA2_Channel2_IRQHandler
 | 
				
			||||||
  .weak  DMA2_Channel2_IRQHandler
 | 
					  .thumb_set DMA2_Channel2_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA2_Channel2_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA2_Channel3_IRQHandler
 | 
				
			||||||
  .weak  DMA2_Channel3_IRQHandler
 | 
					  .thumb_set DMA2_Channel3_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA2_Channel3_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA2_Channel4_IRQHandler
 | 
				
			||||||
  .weak  DMA2_Channel4_IRQHandler
 | 
					  .thumb_set DMA2_Channel4_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA2_Channel4_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA2_Channel5_IRQHandler
 | 
				
			||||||
  .weak  DMA2_Channel5_IRQHandler
 | 
					  .thumb_set DMA2_Channel5_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA2_Channel5_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA2_Channel6_IRQHandler
 | 
				
			||||||
  .weak  DMA2_Channel6_IRQHandler
 | 
					  .thumb_set DMA2_Channel6_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA2_Channel6_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMA2_Channel7_IRQHandler
 | 
				
			||||||
  .weak  DMA2_Channel7_IRQHandler
 | 
					  .thumb_set DMA2_Channel7_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMA2_Channel7_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					  .weak  DMAMUX1_OVR_IRQHandler
 | 
				
			||||||
  .weak  DMAMUX1_OVR_IRQHandler
 | 
					  .thumb_set DMAMUX1_OVR_IRQHandler,Default_Handler
 | 
				
			||||||
  .thumb_set DMAMUX1_OVR_IRQHandler,Default_Handler
 | 
					
 | 
				
			||||||
 | 
					/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -53,12 +53,9 @@ C_SOURCES += \
 | 
				
			|||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc_ex.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rng.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
 | 
				
			||||||
@ -81,7 +78,6 @@ CFLAGS += \
 | 
				
			|||||||
	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
 | 
						-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
 | 
				
			||||||
	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
 | 
						-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
 | 
				
			||||||
C_SOURCES += \
 | 
					C_SOURCES += \
 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
 | 
						$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
 | 
						$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/queue.c \
 | 
						$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/queue.c \
 | 
				
			||||||
 | 
				
			|||||||
@ -1,54 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    aes.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the aes.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __AES_H__
 | 
					 | 
				
			||||||
#define __AES_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern CRYP_HandleTypeDef hcryp1;
 | 
					 | 
				
			||||||
extern CRYP_HandleTypeDef hcryp2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_AES1_Init(void);
 | 
					 | 
				
			||||||
void MX_AES2_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __AES_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,52 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    pka.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the pka.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __PKA_H__
 | 
					 | 
				
			||||||
#define __PKA_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern PKA_HandleTypeDef hpka;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_PKA_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __PKA_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,50 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rf.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the rf.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __RF_H__
 | 
					 | 
				
			||||||
#define __RF_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_RF_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __RF_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,52 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rng.h
 | 
					 | 
				
			||||||
  * @brief   This file contains all the function prototypes for
 | 
					 | 
				
			||||||
  *          the rng.c file
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
/* Define to prevent recursive inclusion -------------------------------------*/
 | 
					 | 
				
			||||||
#ifndef __RNG_H__
 | 
					 | 
				
			||||||
#define __RNG_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Includes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
extern RNG_HandleTypeDef hrng;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Private defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void MX_RNG_Init(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END Prototypes */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* __RNG_H__ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,127 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    aes.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the AES instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "aes.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
CRYP_HandleTypeDef hcryp1;
 | 
					 | 
				
			||||||
__ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END = {
 | 
					 | 
				
			||||||
                            0x00000000,0x00000000,0x00000000,0x00000000};
 | 
					 | 
				
			||||||
CRYP_HandleTypeDef hcryp2;
 | 
					 | 
				
			||||||
__ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END = {
 | 
					 | 
				
			||||||
                            0x00000000,0x00000000,0x00000000,0x00000000};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* AES1 init function */
 | 
					 | 
				
			||||||
void MX_AES1_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hcryp1.Instance = AES1;
 | 
					 | 
				
			||||||
  hcryp1.Init.DataType = CRYP_DATATYPE_32B;
 | 
					 | 
				
			||||||
  hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
 | 
					 | 
				
			||||||
  hcryp1.Init.pKey = (uint32_t *)pKeyAES1;
 | 
					 | 
				
			||||||
  hcryp1.Init.Algorithm = CRYP_AES_ECB;
 | 
					 | 
				
			||||||
  hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
 | 
					 | 
				
			||||||
  hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
 | 
					 | 
				
			||||||
  if (HAL_CRYP_Init(&hcryp1) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
/* AES2 init function */
 | 
					 | 
				
			||||||
void MX_AES2_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hcryp2.Instance = AES2;
 | 
					 | 
				
			||||||
  hcryp2.Init.DataType = CRYP_DATATYPE_32B;
 | 
					 | 
				
			||||||
  hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
 | 
					 | 
				
			||||||
  hcryp2.Init.pKey = (uint32_t *)pKeyAES2;
 | 
					 | 
				
			||||||
  hcryp2.Init.Algorithm = CRYP_AES_ECB;
 | 
					 | 
				
			||||||
  hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
 | 
					 | 
				
			||||||
  hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
 | 
					 | 
				
			||||||
  if (HAL_CRYP_Init(&hcryp2) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(crypHandle->Instance==AES1)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspInit 0 */
 | 
					 | 
				
			||||||
    /* AES1 clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES1_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  else if(crypHandle->Instance==AES2)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspInit 0 */
 | 
					 | 
				
			||||||
    /* AES2 clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES2_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(crypHandle->Instance==AES1)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES1_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES1_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES1_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  else if(crypHandle->Instance==AES2)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_AES2_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN AES2_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END AES2_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,77 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    pka.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the PKA instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "pka.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
PKA_HandleTypeDef hpka;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* PKA init function */
 | 
					 | 
				
			||||||
void MX_PKA_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hpka.Instance = PKA;
 | 
					 | 
				
			||||||
  if (HAL_PKA_Init(&hpka) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_PKA_MspInit(PKA_HandleTypeDef* pkaHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(pkaHandle->Instance==PKA)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspInit 0 */
 | 
					 | 
				
			||||||
    /* PKA clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_PKA_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_PKA_MspDeInit(PKA_HandleTypeDef* pkaHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(pkaHandle->Instance==PKA)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_PKA_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN PKA_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END PKA_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,37 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rf.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the RF instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "rf.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* RF init function */
 | 
					 | 
				
			||||||
void MX_RF_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,77 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @file    rng.c
 | 
					 | 
				
			||||||
  * @brief   This file provides code for the configuration
 | 
					 | 
				
			||||||
  *          of the RNG instances.
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  * @attention
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
 | 
					 | 
				
			||||||
  * All rights reserved.</center></h2>
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  * This software component is licensed by ST under Ultimate Liberty license
 | 
					 | 
				
			||||||
  * SLA0044, the "License"; You may not use this file except in compliance with
 | 
					 | 
				
			||||||
  * the License. You may obtain a copy of the License at:
 | 
					 | 
				
			||||||
  *                             www.st.com/SLA0044
 | 
					 | 
				
			||||||
  *
 | 
					 | 
				
			||||||
  ******************************************************************************
 | 
					 | 
				
			||||||
  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Includes ------------------------------------------------------------------*/
 | 
					 | 
				
			||||||
#include "rng.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RNG_HandleTypeDef hrng;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* RNG init function */
 | 
					 | 
				
			||||||
void MX_RNG_Init(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  hrng.Instance = RNG;
 | 
					 | 
				
			||||||
  if (HAL_RNG_Init(&hrng) != HAL_OK)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    Error_Handler();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(rngHandle->Instance==RNG)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspInit 0 */
 | 
					 | 
				
			||||||
    /* RNG clock enable */
 | 
					 | 
				
			||||||
    __HAL_RCC_RNG_CLK_ENABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(rngHandle->Instance==RNG)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspDeInit 0 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspDeInit 0 */
 | 
					 | 
				
			||||||
    /* Peripheral clock disable */
 | 
					 | 
				
			||||||
    __HAL_RCC_RNG_CLK_DISABLE();
 | 
					 | 
				
			||||||
  /* USER CODE BEGIN RNG_MspDeInit 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /* USER CODE END RNG_MspDeInit 1 */
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE BEGIN 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* USER CODE END 1 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
					 | 
				
			||||||
@ -1,140 +0,0 @@
 | 
				
			|||||||
#include "main.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "app_entry.h"
 | 
					 | 
				
			||||||
#include "app_common.h"
 | 
					 | 
				
			||||||
#include "dbg_trace.h"
 | 
					 | 
				
			||||||
#include "ble.h"
 | 
					 | 
				
			||||||
#include "tl.h"
 | 
					 | 
				
			||||||
#include "app_ble.h"
 | 
					 | 
				
			||||||
#include "shci.h"
 | 
					 | 
				
			||||||
#include "cmsis_os.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <furi-hal.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// PLACE_IN_SECTION("TAG_OTA_END") const uint32_t MagicKeywordValue = 0x94448A29 ;
 | 
					 | 
				
			||||||
// PLACE_IN_SECTION("TAG_OTA_START") const uint32_t MagicKeywordAddress = (uint32_t)&MagicKeywordValue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
osMutexId_t MtxHciId;
 | 
					 | 
				
			||||||
osSemaphoreId_t SemHciId;
 | 
					 | 
				
			||||||
osThreadId_t HciUserEvtProcessId;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const osThreadAttr_t HciUserEvtProcess_attr = {
 | 
					 | 
				
			||||||
    .name = CFG_HCI_USER_EVT_PROCESS_NAME,
 | 
					 | 
				
			||||||
    .attr_bits = CFG_HCI_USER_EVT_PROCESS_ATTR_BITS,
 | 
					 | 
				
			||||||
    .cb_mem = CFG_HCI_USER_EVT_PROCESS_CB_MEM,
 | 
					 | 
				
			||||||
    .cb_size = CFG_HCI_USER_EVT_PROCESS_CB_SIZE,
 | 
					 | 
				
			||||||
    .stack_mem = CFG_HCI_USER_EVT_PROCESS_STACK_MEM,
 | 
					 | 
				
			||||||
    .priority = CFG_HCI_USER_EVT_PROCESS_PRIORITY,
 | 
					 | 
				
			||||||
    .stack_size = CFG_HCI_USER_EVT_PROCESS_STACK_SIZE
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Private function prototypes -----------------------------------------------*/
 | 
					 | 
				
			||||||
static void HciUserEvtProcess(void *argument);
 | 
					 | 
				
			||||||
static void BLE_UserEvtRx( void * pPayload );
 | 
					 | 
				
			||||||
static void BLE_StatusNot( HCI_TL_CmdStatus_t status );
 | 
					 | 
				
			||||||
static void Ble_Tl_Init( void );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool APP_BLE_Init() {
 | 
					 | 
				
			||||||
  SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = {
 | 
					 | 
				
			||||||
    {{0,0,0}},                  /**< Header unused */
 | 
					 | 
				
			||||||
    {0,                         /** pBleBufferAddress not used */
 | 
					 | 
				
			||||||
    0,                          /** BleBufferSize not used */
 | 
					 | 
				
			||||||
    CFG_BLE_NUM_GATT_ATTRIBUTES,
 | 
					 | 
				
			||||||
    CFG_BLE_NUM_GATT_SERVICES,
 | 
					 | 
				
			||||||
    CFG_BLE_ATT_VALUE_ARRAY_SIZE,
 | 
					 | 
				
			||||||
    CFG_BLE_NUM_LINK,
 | 
					 | 
				
			||||||
    CFG_BLE_DATA_LENGTH_EXTENSION,
 | 
					 | 
				
			||||||
    CFG_BLE_PREPARE_WRITE_LIST_SIZE,
 | 
					 | 
				
			||||||
    CFG_BLE_MBLOCK_COUNT,
 | 
					 | 
				
			||||||
    CFG_BLE_MAX_ATT_MTU,
 | 
					 | 
				
			||||||
    CFG_BLE_SLAVE_SCA,
 | 
					 | 
				
			||||||
    CFG_BLE_MASTER_SCA,
 | 
					 | 
				
			||||||
    CFG_BLE_LSE_SOURCE,
 | 
					 | 
				
			||||||
    CFG_BLE_MAX_CONN_EVENT_LENGTH,
 | 
					 | 
				
			||||||
    CFG_BLE_HSE_STARTUP_TIME,
 | 
					 | 
				
			||||||
    CFG_BLE_VITERBI_MODE,
 | 
					 | 
				
			||||||
    CFG_BLE_LL_ONLY,
 | 
					 | 
				
			||||||
    0}
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Initialize Ble Transport Layer
 | 
					 | 
				
			||||||
  Ble_Tl_Init( );
 | 
					 | 
				
			||||||
  // Register the hci transport layer to handle BLE User Asynchronous Events
 | 
					 | 
				
			||||||
  HciUserEvtProcessId = osThreadNew(HciUserEvtProcess, NULL, &HciUserEvtProcess_attr);
 | 
					 | 
				
			||||||
  // Starts the BLE Stack on CPU2
 | 
					 | 
				
			||||||
  return (SHCI_C2_BLE_Init( &ble_init_cmd_packet ) == SHCI_Success);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void Ble_Tl_Init( void ) {
 | 
					 | 
				
			||||||
  HCI_TL_HciInitConf_t Hci_Tl_Init_Conf;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  MtxHciId = osMutexNew( NULL );
 | 
					 | 
				
			||||||
  SemHciId = osSemaphoreNew( 1, 0, NULL ); /*< Create the semaphore and make it busy at initialization */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  Hci_Tl_Init_Conf.p_cmdbuffer = (uint8_t*)&BleCmdBuffer;
 | 
					 | 
				
			||||||
  Hci_Tl_Init_Conf.StatusNotCallBack = BLE_StatusNot;
 | 
					 | 
				
			||||||
  hci_init(BLE_UserEvtRx, (void*) &Hci_Tl_Init_Conf);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void HciUserEvtProcess(void *argument) {
 | 
					 | 
				
			||||||
  UNUSED(argument);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  for(;;)
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    osThreadFlagsWait( 1, osFlagsWaitAny, osWaitForever);
 | 
					 | 
				
			||||||
    hci_user_evt_proc( );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*************************************************************
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * WRAP FUNCTIONS
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *************************************************************/
 | 
					 | 
				
			||||||
void hci_notify_asynch_evt(void* pdata) {
 | 
					 | 
				
			||||||
  UNUSED(pdata);
 | 
					 | 
				
			||||||
  osThreadFlagsSet( HciUserEvtProcessId, 1 );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void hci_cmd_resp_release(uint32_t flag) {
 | 
					 | 
				
			||||||
  UNUSED(flag);
 | 
					 | 
				
			||||||
  osSemaphoreRelease( SemHciId );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void hci_cmd_resp_wait(uint32_t timeout) {
 | 
					 | 
				
			||||||
  UNUSED(timeout);
 | 
					 | 
				
			||||||
  osSemaphoreAcquire( SemHciId, osWaitForever );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void BLE_UserEvtRx( void * pPayload ) {
 | 
					 | 
				
			||||||
  SVCCTL_UserEvtFlowStatus_t svctl_return_status;
 | 
					 | 
				
			||||||
  tHCI_UserEvtRxParam *pParam;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  pParam = (tHCI_UserEvtRxParam *)pPayload;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  svctl_return_status = SVCCTL_UserEvtRx((void *)&(pParam->pckt->evtserial));
 | 
					 | 
				
			||||||
  if (svctl_return_status != SVCCTL_UserEvtFlowDisable) {
 | 
					 | 
				
			||||||
    pParam->status = HCI_TL_UserEventFlow_Enable;
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    pParam->status = HCI_TL_UserEventFlow_Disable;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void BLE_StatusNot( HCI_TL_CmdStatus_t status ) {
 | 
					 | 
				
			||||||
  switch (status) {
 | 
					 | 
				
			||||||
    case HCI_TL_CmdBusy:
 | 
					 | 
				
			||||||
      osMutexAcquire( MtxHciId, osWaitForever );
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    case HCI_TL_CmdAvailable:
 | 
					 | 
				
			||||||
      osMutexRelease( MtxHciId );
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    default:
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SVCCTL_ResumeUserEventFlow( void ) {
 | 
					 | 
				
			||||||
  hci_resume_flow();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -427,9 +427,6 @@ typedef enum
 | 
				
			|||||||
#define DBG_TRACE_MSG_QUEUE_SIZE 4096
 | 
					#define DBG_TRACE_MSG_QUEUE_SIZE 4096
 | 
				
			||||||
#define MAX_DBG_TRACE_MSG_SIZE 1024
 | 
					#define MAX_DBG_TRACE_MSG_SIZE 1024
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CFG_LED_SUPPORTED         0
 | 
					 | 
				
			||||||
#define CFG_BUTTON_SUPPORTED      0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/******************************************************************************
 | 
					/******************************************************************************
 | 
				
			||||||
 * FreeRTOS
 | 
					 * FreeRTOS
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
@ -441,34 +438,5 @@ typedef enum
 | 
				
			|||||||
#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY    osPriorityNone
 | 
					#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY    osPriorityNone
 | 
				
			||||||
#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE  (128 * 7)
 | 
					#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE  (128 * 7)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_NAME         "ble_hci_evt"
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_ATTR_BITS    (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_CB_MEM       (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_CB_SIZE      (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_STACK_MEM    (0)
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_PRIORITY     osPriorityNone
 | 
					 | 
				
			||||||
#define CFG_HCI_USER_EVT_PROCESS_STACK_SIZE   (128 * 8)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_NAME           "ble_adv_upd"
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_ATTR_BITS      (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_CB_MEM         (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_CB_SIZE        (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_STACK_MEM      (0)
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_PRIORITY       osPriorityNone
 | 
					 | 
				
			||||||
#define CFG_ADV_UPDATE_PROCESS_STACK_SIZE     (128 * 6)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_NAME                  "hrs"
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_ATTR_BITS             (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_CB_MEM                (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_CB_SIZE               (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_STACK_MEM             (0)
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_PRIORITY              osPriorityNone
 | 
					 | 
				
			||||||
#define CFG_HRS_PROCESS_STACK_SIZE            (128 * 8)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef enum {
 | 
					 | 
				
			||||||
    CFG_LPM_APP,
 | 
					 | 
				
			||||||
    CFG_LPM_APP_BLE,
 | 
					 | 
				
			||||||
} CFG_LPM_Id_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define CFG_OTP_BASE_ADDRESS    OTP_AREA_BASE
 | 
					#define CFG_OTP_BASE_ADDRESS    OTP_AREA_BASE
 | 
				
			||||||
#define CFG_OTP_END_ADRESS      OTP_AREA_END_ADDR
 | 
					#define CFG_OTP_END_ADRESS      OTP_AREA_END_ADDR
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
#include "app_common.h"
 | 
					#include "app_common.h"
 | 
				
			||||||
#include "main.h"
 | 
					#include "main.h"
 | 
				
			||||||
#include "app_entry.h"
 | 
					#include "app_entry.h"
 | 
				
			||||||
#include "app_ble.h"
 | 
					#include "ble_app.h"
 | 
				
			||||||
#include "ble.h"
 | 
					#include "ble.h"
 | 
				
			||||||
#include "tl.h"
 | 
					#include "tl.h"
 | 
				
			||||||
#include "cmsis_os.h"
 | 
					#include "cmsis_os.h"
 | 
				
			||||||
@ -47,8 +47,6 @@ void APPE_Init() {
 | 
				
			|||||||
  ble_glue_status = BleGlueStatusStartup;
 | 
					  ble_glue_status = BleGlueStatusStartup;
 | 
				
			||||||
  SystemPower_Config(); /**< Configure the system Power Mode */
 | 
					  SystemPower_Config(); /**< Configure the system Power Mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  HW_TS_Init(hw_ts_InitMode_Full, &hrtc); /**< Initialize the TimerServer */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // APPD_Init();
 | 
					  // APPD_Init();
 | 
				
			||||||
  furi_hal_power_insomnia_enter();
 | 
					  furi_hal_power_insomnia_enter();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -137,7 +135,7 @@ static void APPE_SysUserEvtRx( void * pPayload ) {
 | 
				
			|||||||
  /* Traces channel initialization */
 | 
					  /* Traces channel initialization */
 | 
				
			||||||
  // APPD_EnableCPU2( );
 | 
					  // APPD_EnableCPU2( );
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if (APP_BLE_Init()) {
 | 
					  if(ble_app_init()) {
 | 
				
			||||||
    FURI_LOG_I("Core2", "BLE stack started");
 | 
					    FURI_LOG_I("Core2", "BLE stack started");
 | 
				
			||||||
    ble_glue_status = BleGlueStatusStarted;
 | 
					    ble_glue_status = BleGlueStatusStarted;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@ void battery_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t *) &char_battery_level_uuid,
 | 
					                                (Char_UUID_t *) &char_battery_level_uuid,
 | 
				
			||||||
                                1,
 | 
					                                1,
 | 
				
			||||||
                                CHAR_PROP_READ | CHAR_PROP_NOTIFY,
 | 
					                                CHAR_PROP_READ | CHAR_PROP_NOTIFY,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										119
									
								
								firmware/targets/f7/ble-glue/ble_app.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								firmware/targets/f7/ble-glue/ble_app.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,119 @@
 | 
				
			|||||||
 | 
					#include "ble_app.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "hci_tl.h"
 | 
				
			||||||
 | 
					#include "ble.h"
 | 
				
			||||||
 | 
					#include "shci.h"
 | 
				
			||||||
 | 
					#include "cmsis_os.h"
 | 
				
			||||||
 | 
					#include "gap.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <furi-hal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define BLE_APP_TAG "ble app"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t ble_app_cmd_buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    osMutexId_t hci_mtx;
 | 
				
			||||||
 | 
					    osSemaphoreId_t hci_sem;
 | 
				
			||||||
 | 
					    osThreadId_t hci_thread_id;
 | 
				
			||||||
 | 
					    osThreadAttr_t hci_thread_attr;
 | 
				
			||||||
 | 
					} BleApp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static BleApp* ble_app;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_thread(void *arg);
 | 
				
			||||||
 | 
					static void ble_app_hci_event_handler(void * pPayload);
 | 
				
			||||||
 | 
					static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool ble_app_init() {
 | 
				
			||||||
 | 
					    ble_app = furi_alloc(sizeof(BleApp));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Allocate semafore and mutex for ble command buffer access
 | 
				
			||||||
 | 
					    ble_app->hci_mtx = osMutexNew(NULL);
 | 
				
			||||||
 | 
					    ble_app->hci_sem = osSemaphoreNew(1, 0, NULL);
 | 
				
			||||||
 | 
					    // HCI transport layer thread to handle user asynch events
 | 
				
			||||||
 | 
					    ble_app->hci_thread_attr.name = "ble hci";
 | 
				
			||||||
 | 
					    ble_app->hci_thread_attr.stack_size = 1024;
 | 
				
			||||||
 | 
					    ble_app->hci_thread_id = osThreadNew(ble_app_hci_thread, NULL, &ble_app->hci_thread_attr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Initialize Ble Transport Layer
 | 
				
			||||||
 | 
					    HCI_TL_HciInitConf_t hci_tl_config = {
 | 
				
			||||||
 | 
					        .p_cmdbuffer = (uint8_t*)&ble_app_cmd_buffer,
 | 
				
			||||||
 | 
					        .StatusNotCallBack = ble_app_hci_status_not_handler,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    hci_init(ble_app_hci_event_handler, (void*)&hci_tl_config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Start ble stack on 2nd core
 | 
				
			||||||
 | 
					    SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = {
 | 
				
			||||||
 | 
					        .Header = {{0,0,0}}, // Header unused
 | 
				
			||||||
 | 
					        .Param = {
 | 
				
			||||||
 | 
					            0, // pBleBufferAddress not used
 | 
				
			||||||
 | 
					            0, // BleBufferSize not used
 | 
				
			||||||
 | 
					            CFG_BLE_NUM_GATT_ATTRIBUTES,
 | 
				
			||||||
 | 
					            CFG_BLE_NUM_GATT_SERVICES,
 | 
				
			||||||
 | 
					            CFG_BLE_ATT_VALUE_ARRAY_SIZE,
 | 
				
			||||||
 | 
					            CFG_BLE_NUM_LINK,
 | 
				
			||||||
 | 
					            CFG_BLE_DATA_LENGTH_EXTENSION,
 | 
				
			||||||
 | 
					            CFG_BLE_PREPARE_WRITE_LIST_SIZE,
 | 
				
			||||||
 | 
					            CFG_BLE_MBLOCK_COUNT,
 | 
				
			||||||
 | 
					            CFG_BLE_MAX_ATT_MTU,
 | 
				
			||||||
 | 
					            CFG_BLE_SLAVE_SCA,
 | 
				
			||||||
 | 
					            CFG_BLE_MASTER_SCA,
 | 
				
			||||||
 | 
					            CFG_BLE_LSE_SOURCE,
 | 
				
			||||||
 | 
					            CFG_BLE_MAX_CONN_EVENT_LENGTH,
 | 
				
			||||||
 | 
					            CFG_BLE_HSE_STARTUP_TIME,
 | 
				
			||||||
 | 
					            CFG_BLE_VITERBI_MODE,
 | 
				
			||||||
 | 
					            CFG_BLE_LL_ONLY,
 | 
				
			||||||
 | 
					            0,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    SHCI_CmdStatus_t status = SHCI_C2_BLE_Init(&ble_init_cmd_packet);
 | 
				
			||||||
 | 
					    if(status) {
 | 
				
			||||||
 | 
					        FURI_LOG_E(BLE_APP_TAG, "Failed to start ble stack: %d", status);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return status == SHCI_Success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_thread(void *arg) {
 | 
				
			||||||
 | 
					    while(1) {
 | 
				
			||||||
 | 
					        osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);
 | 
				
			||||||
 | 
					        hci_user_evt_proc();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Called by WPAN lib
 | 
				
			||||||
 | 
					void hci_notify_asynch_evt(void* pdata) {
 | 
				
			||||||
 | 
					    osThreadFlagsSet(ble_app->hci_thread_id, 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void hci_cmd_resp_release(uint32_t flag) {
 | 
				
			||||||
 | 
					    osSemaphoreRelease(ble_app->hci_sem);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void hci_cmd_resp_wait(uint32_t timeout) {
 | 
				
			||||||
 | 
					    osSemaphoreAcquire(ble_app->hci_sem, osWaitForever);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_event_handler( void * pPayload ) {
 | 
				
			||||||
 | 
					    SVCCTL_UserEvtFlowStatus_t svctl_return_status;
 | 
				
			||||||
 | 
					    tHCI_UserEvtRxParam *pParam = (tHCI_UserEvtRxParam *)pPayload;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    svctl_return_status = SVCCTL_UserEvtRx((void *)&(pParam->pckt->evtserial));
 | 
				
			||||||
 | 
					    if (svctl_return_status != SVCCTL_UserEvtFlowDisable) {
 | 
				
			||||||
 | 
					        pParam->status = HCI_TL_UserEventFlow_Enable;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        pParam->status = HCI_TL_UserEventFlow_Disable;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ble_app_hci_status_not_handler( HCI_TL_CmdStatus_t status ) {
 | 
				
			||||||
 | 
					    if(status == HCI_TL_CmdBusy) {
 | 
				
			||||||
 | 
					        osMutexAcquire(ble_app->hci_mtx, osWaitForever );
 | 
				
			||||||
 | 
					    } else if(status == HCI_TL_CmdAvailable) {
 | 
				
			||||||
 | 
					        osMutexRelease(ble_app->hci_mtx);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SVCCTL_ResumeUserEventFlow( void ) {
 | 
				
			||||||
 | 
					    hci_resume_flow();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -5,9 +5,8 @@ extern "C" {
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include "hci_tl.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool APP_BLE_Init();
 | 
					bool ble_app_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -39,7 +39,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_man_name),
 | 
					                                strlen(dev_info_man_name),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
@ -53,7 +53,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_serial_num),
 | 
					                                strlen(dev_info_serial_num),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
@ -67,7 +67,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_firmware_rev_num),
 | 
					                                strlen(dev_info_firmware_rev_num),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
@ -81,7 +81,7 @@ void dev_info_svc_start() {
 | 
				
			|||||||
                                (Char_UUID_t*)&uuid,
 | 
					                                (Char_UUID_t*)&uuid,
 | 
				
			||||||
                                strlen(dev_info_software_rev_num),
 | 
					                                strlen(dev_info_software_rev_num),
 | 
				
			||||||
                                CHAR_PROP_READ,
 | 
					                                CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_CONSTANT,
 | 
					                                CHAR_VALUE_LEN_CONSTANT,
 | 
				
			||||||
 | 
				
			|||||||
@ -31,13 +31,22 @@ typedef struct {
 | 
				
			|||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  GapSvc gap_svc;
 | 
					  GapSvc gap_svc;
 | 
				
			||||||
  GapState state;
 | 
					  GapState state;
 | 
				
			||||||
 | 
					  osMutexId_t state_mutex;
 | 
				
			||||||
  uint8_t mac_address[BD_ADDR_SIZE_LOCAL];
 | 
					  uint8_t mac_address[BD_ADDR_SIZE_LOCAL];
 | 
				
			||||||
  Bt* bt;
 | 
					  Bt* bt;
 | 
				
			||||||
  osTimerId advertise_timer;
 | 
					  osTimerId advertise_timer;
 | 
				
			||||||
  osThreadAttr_t thread_attr;
 | 
					  osThreadAttr_t thread_attr;
 | 
				
			||||||
  osThreadId_t thread_id;
 | 
					  osThreadId_t thread_id;
 | 
				
			||||||
 | 
					  osMessageQueueId_t command_queue;
 | 
				
			||||||
 | 
					  bool enable_adv;
 | 
				
			||||||
} Gap;
 | 
					} Gap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					    GapCommandAdvFast,
 | 
				
			||||||
 | 
					    GapCommandAdvLowPower,
 | 
				
			||||||
 | 
					    GapCommandAdvStop,
 | 
				
			||||||
 | 
					} GapCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Identity root key
 | 
					// Identity root key
 | 
				
			||||||
static const uint8_t gap_irk[16] = {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
 | 
					static const uint8_t gap_irk[16] = {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
 | 
				
			||||||
// Encryption root key
 | 
					// Encryption root key
 | 
				
			||||||
@ -49,150 +58,151 @@ static const uint8_t gap_default_mac_addr[] = {0x6c, 0x7a, 0xd8, 0xac, 0x57, 0x7
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static Gap* gap = NULL;
 | 
					static Gap* gap = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advertise(GapState new_state);
 | 
					static void gap_advertise_start(GapState new_state);
 | 
				
			||||||
static void gap_app(void *arg);
 | 
					static void gap_app(void *arg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
 | 
					SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  hci_event_pckt *event_pckt;
 | 
					    hci_event_pckt *event_pckt;
 | 
				
			||||||
  evt_le_meta_event *meta_evt;
 | 
					    evt_le_meta_event *meta_evt;
 | 
				
			||||||
  evt_blue_aci *blue_evt;
 | 
					    evt_blue_aci *blue_evt;
 | 
				
			||||||
  hci_le_phy_update_complete_event_rp0 *evt_le_phy_update_complete;
 | 
					    hci_le_phy_update_complete_event_rp0 *evt_le_phy_update_complete;
 | 
				
			||||||
  uint8_t tx_phy;
 | 
					    uint8_t tx_phy;
 | 
				
			||||||
  uint8_t rx_phy;
 | 
					    uint8_t rx_phy;
 | 
				
			||||||
  tBleStatus ret = BLE_STATUS_INVALID_PARAMS;
 | 
					    tBleStatus ret = BLE_STATUS_INVALID_PARAMS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data;
 | 
					    event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (event_pckt->evt) {
 | 
					    osMutexAcquire(gap->state_mutex, osWaitForever);
 | 
				
			||||||
    case EVT_DISCONN_COMPLETE:
 | 
					    switch (event_pckt->evt) {
 | 
				
			||||||
    {
 | 
					        case EVT_DISCONN_COMPLETE:
 | 
				
			||||||
        hci_disconnection_complete_event_rp0 *disconnection_complete_event = (hci_disconnection_complete_event_rp0 *) event_pckt->data;
 | 
					        {
 | 
				
			||||||
        if (disconnection_complete_event->Connection_Handle == gap->gap_svc.connection_handle) {
 | 
					            hci_disconnection_complete_event_rp0 *disconnection_complete_event = (hci_disconnection_complete_event_rp0 *) event_pckt->data;
 | 
				
			||||||
            gap->gap_svc.connection_handle = 0;
 | 
					            if (disconnection_complete_event->Connection_Handle == gap->gap_svc.connection_handle) {
 | 
				
			||||||
            gap->state = GapStateIdle;
 | 
					                gap->gap_svc.connection_handle = 0;
 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Disconnect from client");
 | 
					                gap->state = GapStateIdle;
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Disconnect from client");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if(gap->enable_adv) {
 | 
				
			||||||
 | 
					                // Restart advertising
 | 
				
			||||||
 | 
					                gap_start_advertising();
 | 
				
			||||||
 | 
					                furi_hal_power_insomnia_exit();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Restart advertising
 | 
					        break;
 | 
				
			||||||
        gap_advertise(GapStateAdvFast);
 | 
					 | 
				
			||||||
        furi_hal_power_insomnia_exit();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case EVT_LE_META_EVENT:
 | 
					        case EVT_LE_META_EVENT:
 | 
				
			||||||
        meta_evt = (evt_le_meta_event*) event_pckt->data;
 | 
					            meta_evt = (evt_le_meta_event*) event_pckt->data;
 | 
				
			||||||
        switch (meta_evt->subevent) {
 | 
					            switch (meta_evt->subevent) {
 | 
				
			||||||
            case EVT_LE_CONN_UPDATE_COMPLETE:
 | 
					                case EVT_LE_CONN_UPDATE_COMPLETE:
 | 
				
			||||||
            FURI_LOG_D(GAP_TAG, "Connection update event");
 | 
					                FURI_LOG_D(GAP_TAG, "Connection update event");
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case EVT_LE_PHY_UPDATE_COMPLETE:
 | 
					                case EVT_LE_PHY_UPDATE_COMPLETE:
 | 
				
			||||||
            evt_le_phy_update_complete = (hci_le_phy_update_complete_event_rp0*)meta_evt->data;
 | 
					                evt_le_phy_update_complete = (hci_le_phy_update_complete_event_rp0*)meta_evt->data;
 | 
				
			||||||
            if(evt_le_phy_update_complete->Status) {
 | 
					                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(GAP_TAG, "Update PHY failed, status %d", evt_le_phy_update_complete->Status);
 | 
				
			||||||
            } else {
 | 
					                } else {
 | 
				
			||||||
                FURI_LOG_I(GAP_TAG, "Update PHY succeed");
 | 
					                    FURI_LOG_I(GAP_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);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    FURI_LOG_I(GAP_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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Stop advertising as connection completed
 | 
				
			||||||
 | 
					                osTimerStop(gap->advertise_timer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Update connection status and handle
 | 
				
			||||||
 | 
					                gap->state = GapStateConnected;
 | 
				
			||||||
 | 
					                gap->gap_svc.connection_handle = connection_complete_event->Connection_Handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Start pairing by sending security request
 | 
				
			||||||
 | 
					                aci_gap_slave_security_req(connection_complete_event->Connection_Handle);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            ret = hci_le_read_phy(gap->gap_svc.connection_handle,&tx_phy,&rx_phy);
 | 
					        break;
 | 
				
			||||||
            if(ret) {
 | 
					
 | 
				
			||||||
                FURI_LOG_E(GAP_TAG, "Read PHY failed, status: %d", ret);
 | 
					        case EVT_VENDOR:
 | 
				
			||||||
            } else {
 | 
					            blue_evt = (evt_blue_aci*) event_pckt->data;
 | 
				
			||||||
                FURI_LOG_I(GAP_TAG, "PHY Params TX= %d, RX= %d ", tx_phy, rx_phy);
 | 
					            switch (blue_evt->ecode) {
 | 
				
			||||||
 | 
					                aci_gap_pairing_complete_event_rp0 *pairing_complete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_LIMITED_DISCOVERABLE:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Limited discoverable event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_PASS_KEY_REQUEST:
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // 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);
 | 
				
			||||||
 | 
					                bt_pin_code_show(gap->bt, pin);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case EVT_LE_CONN_COMPLETE:
 | 
					            case EVT_BLUE_GAP_AUTHORIZATION_REQUEST:
 | 
				
			||||||
            furi_hal_power_insomnia_enter();
 | 
					                FURI_LOG_I(GAP_TAG, "Authorization request event");
 | 
				
			||||||
            hci_le_connection_complete_event_rp0* connection_complete_event = (hci_le_connection_complete_event_rp0 *) meta_evt->data;
 | 
					                break;
 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Connection complete for connection handle 0x%x", connection_complete_event->Connection_Handle);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Stop advertising as connection completed
 | 
					            case EVT_BLUE_GAP_SLAVE_SECURITY_INITIATED:
 | 
				
			||||||
            osTimerStop(gap->advertise_timer);
 | 
					                FURI_LOG_I(GAP_TAG, "Slave security initiated");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Update connection status and handle
 | 
					            case EVT_BLUE_GAP_BOND_LOST:
 | 
				
			||||||
            gap->state = GapStateConnected;
 | 
					                FURI_LOG_I(GAP_TAG, "Bond lost event. Start rebonding");
 | 
				
			||||||
            gap->gap_svc.connection_handle = connection_complete_event->Connection_Handle;
 | 
					                aci_gap_allow_rebond(gap->gap_svc.connection_handle);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Start pairing by sending security request
 | 
					            case EVT_BLUE_GAP_DEVICE_FOUND:
 | 
				
			||||||
            aci_gap_slave_security_req(connection_complete_event->Connection_Handle);
 | 
					                FURI_LOG_I(GAP_TAG, "Device found event");
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_ADDR_NOT_RESOLVED:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Address not resolved event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_KEYPRESS_NOTIFICATION:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Key press notification event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            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);
 | 
				
			||||||
 | 
					                    aci_gap_terminate(gap->gap_svc.connection_handle, 5);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    FURI_LOG_I(GAP_TAG, "Pairing complete");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case EVT_BLUE_GAP_PROCEDURE_COMPLETE:
 | 
				
			||||||
 | 
					                FURI_LOG_I(GAP_TAG, "Procedure complete event");
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
        }
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    osMutexRelease(gap->state_mutex);
 | 
				
			||||||
 | 
					    return SVCCTL_UserEvtFlowEnable;
 | 
				
			||||||
    case EVT_VENDOR:
 | 
					 | 
				
			||||||
        blue_evt = (evt_blue_aci*) event_pckt->data;
 | 
					 | 
				
			||||||
        switch (blue_evt->ecode) {
 | 
					 | 
				
			||||||
            aci_gap_pairing_complete_event_rp0 *pairing_complete;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_LIMITED_DISCOVERABLE:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Limited discoverable event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_PASS_KEY_REQUEST:
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // 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);
 | 
					 | 
				
			||||||
            bt_pin_code_show(gap->bt, pin);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_AUTHORIZATION_REQUEST:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Authorization request event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_SLAVE_SECURITY_INITIATED:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Slave security initiated");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_BOND_LOST:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_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");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_ADDR_NOT_RESOLVED:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Address not resolved event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_KEYPRESS_NOTIFICATION:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Key press notification event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_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;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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);
 | 
					 | 
				
			||||||
            aci_gap_terminate(gap->gap_svc.connection_handle, 5);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Pairing complete");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case EVT_BLUE_GAP_PROCEDURE_COMPLETE:
 | 
					 | 
				
			||||||
            FURI_LOG_I(GAP_TAG, "Procedure complete event");
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return SVCCTL_UserEvtFlowEnable;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SVCCTL_SvcInit() {
 | 
					void SVCCTL_SvcInit() {
 | 
				
			||||||
@ -213,7 +223,7 @@ static void set_advertisment_service_uid(uint8_t* uid, uint8_t uid_len) {
 | 
				
			|||||||
    gap->gap_svc.adv_svc_uuid_len += uid_len;
 | 
					    gap->gap_svc.adv_svc_uuid_len += uid_len;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GapState gap_get_status() {
 | 
					GapState gap_get_state() {
 | 
				
			||||||
    return gap->state;
 | 
					    return gap->state;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -293,7 +303,7 @@ static void gap_init_svc(Gap* gap) {
 | 
				
			|||||||
    aci_gap_configure_whitelist();
 | 
					    aci_gap_configure_whitelist();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advertise(GapState new_state)
 | 
					static void gap_advertise_start(GapState new_state)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    tBleStatus status;
 | 
					    tBleStatus status;
 | 
				
			||||||
    uint16_t min_interval;
 | 
					    uint16_t min_interval;
 | 
				
			||||||
@ -317,7 +327,6 @@ static void gap_advertise(GapState new_state)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Configure advertising
 | 
					    // Configure advertising
 | 
				
			||||||
    gap->state = new_state;
 | 
					 | 
				
			||||||
    const char* name = furi_hal_version_get_ble_local_device_name_ptr();
 | 
					    const char* name = furi_hal_version_get_ble_local_device_name_ptr();
 | 
				
			||||||
    status = aci_gap_set_discoverable(ADV_IND, min_interval, max_interval, PUBLIC_ADDR, 0,
 | 
					    status = aci_gap_set_discoverable(ADV_IND, min_interval, max_interval, PUBLIC_ADDR, 0,
 | 
				
			||||||
                                        strlen(name), (uint8_t*)name,
 | 
					                                        strlen(name), (uint8_t*)name,
 | 
				
			||||||
@ -325,17 +334,40 @@ static void gap_advertise(GapState new_state)
 | 
				
			|||||||
    if(status) {
 | 
					    if(status) {
 | 
				
			||||||
        FURI_LOG_E(GAP_TAG, "Set discoverable err: %d", status);
 | 
					        FURI_LOG_E(GAP_TAG, "Set discoverable err: %d", status);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    gap->state = new_state;
 | 
				
			||||||
 | 
					    bt_update_statusbar(gap->bt);
 | 
				
			||||||
    osTimerStart(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
 | 
					    osTimerStart(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advertise_request(Gap* gap) {
 | 
					static void gap_advertise_stop() {
 | 
				
			||||||
    osThreadFlagsSet(gap->thread_id, 1);
 | 
					    if(gap->state == GapStateConnected) {
 | 
				
			||||||
 | 
					        // Terminate connection
 | 
				
			||||||
 | 
					        aci_gap_terminate(gap->gap_svc.connection_handle, 0x13);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if(gap->state > GapStateIdle) {
 | 
				
			||||||
 | 
					        // Stop advertising
 | 
				
			||||||
 | 
					        osTimerStop(gap->advertise_timer);
 | 
				
			||||||
 | 
					        aci_gap_set_non_discoverable();
 | 
				
			||||||
 | 
					        gap->state = GapStateIdle;
 | 
				
			||||||
 | 
					        bt_update_statusbar(gap->bt);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gap_start_advertising() {
 | 
				
			||||||
 | 
					    gap->enable_adv = true;
 | 
				
			||||||
 | 
					    GapCommand command = GapCommandAdvFast;
 | 
				
			||||||
 | 
					    furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gap_stop_advertising() {
 | 
				
			||||||
 | 
					    gap->enable_adv = false;
 | 
				
			||||||
 | 
					    GapCommand command = GapCommandAdvStop;
 | 
				
			||||||
 | 
					    furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_advetise_timer_callback(void* context) {
 | 
					static void gap_advetise_timer_callback(void* context) {
 | 
				
			||||||
    furi_assert(context);
 | 
					    GapCommand command = GapCommandAdvLowPower;
 | 
				
			||||||
    Gap* gap = context;
 | 
					    furi_check(osMessageQueuePut(gap->command_queue, &command, 0, 0) == osOK);
 | 
				
			||||||
    gap_advertise_request(gap);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool gap_init() {
 | 
					bool gap_init() {
 | 
				
			||||||
@ -348,20 +380,25 @@ bool gap_init() {
 | 
				
			|||||||
    // Open Bt record
 | 
					    // Open Bt record
 | 
				
			||||||
    gap->bt = furi_record_open("bt");
 | 
					    gap->bt = furi_record_open("bt");
 | 
				
			||||||
    // Create advertising timer
 | 
					    // Create advertising timer
 | 
				
			||||||
    gap->advertise_timer = osTimerNew(gap_advetise_timer_callback, osTimerOnce, &gap, NULL);
 | 
					    gap->advertise_timer = osTimerNew(gap_advetise_timer_callback, osTimerOnce, NULL, NULL);
 | 
				
			||||||
    // Initialization of HCI & GATT & GAP layer
 | 
					    // Initialization of GATT & GAP layer
 | 
				
			||||||
    gap_init_svc(gap);
 | 
					    gap_init_svc(gap);
 | 
				
			||||||
    // Initialization of the BLE Services
 | 
					    // Initialization of the BLE Services
 | 
				
			||||||
    SVCCTL_Init();
 | 
					    SVCCTL_Init();
 | 
				
			||||||
    // Initialization of the BLE App Context
 | 
					    // Initialization of the GAP state
 | 
				
			||||||
 | 
					    gap->state_mutex = osMutexNew(NULL);
 | 
				
			||||||
    gap->state = GapStateIdle;
 | 
					    gap->state = GapStateIdle;
 | 
				
			||||||
    gap->gap_svc.connection_handle = 0xFFFF;
 | 
					    gap->gap_svc.connection_handle = 0xFFFF;
 | 
				
			||||||
 | 
					    gap->enable_adv = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Thread configuration
 | 
					    // Thread configuration
 | 
				
			||||||
    gap->thread_attr.name = "BLE advertising";
 | 
					    gap->thread_attr.name = "BLE advertising";
 | 
				
			||||||
    gap->thread_attr.stack_size = 512;
 | 
					    gap->thread_attr.stack_size = 1024;
 | 
				
			||||||
    gap->thread_id = osThreadNew(gap_app, NULL, &gap->thread_attr);
 | 
					    gap->thread_id = osThreadNew(gap_app, NULL, &gap->thread_attr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Command queue allocation
 | 
				
			||||||
 | 
					    gap->command_queue = osMessageQueueNew(8, sizeof(GapCommand), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Start Device Information service
 | 
					    // Start Device Information service
 | 
				
			||||||
    dev_info_svc_start();
 | 
					    dev_info_svc_start();
 | 
				
			||||||
    // Start Battery service
 | 
					    // Start Battery service
 | 
				
			||||||
@ -374,14 +411,21 @@ bool gap_init() {
 | 
				
			|||||||
    adv_service_uid[1] = 0x30;
 | 
					    adv_service_uid[1] = 0x30;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set_advertisment_service_uid(adv_service_uid, sizeof(adv_service_uid));
 | 
					    set_advertisment_service_uid(adv_service_uid, sizeof(adv_service_uid));
 | 
				
			||||||
    gap_advertise(GapStateAdvFast);
 | 
					 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void gap_app(void *arg) {
 | 
					static void gap_app(void *arg) {
 | 
				
			||||||
    // TODO Exit from app, stop service, clean memory
 | 
					    GapCommand command;
 | 
				
			||||||
    while(1) {
 | 
					    while(1) {
 | 
				
			||||||
        osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);
 | 
					        furi_check(osMessageQueueGet(gap->command_queue, &command, NULL, osWaitForever) == osOK);
 | 
				
			||||||
        gap_advertise(GapStateAdvLowPower);
 | 
					        osMutexAcquire(gap->state_mutex, osWaitForever);
 | 
				
			||||||
 | 
					        if(command == GapCommandAdvFast) {
 | 
				
			||||||
 | 
					            gap_advertise_start(GapStateAdvFast);
 | 
				
			||||||
 | 
					        } else if(command == GapCommandAdvLowPower) {
 | 
				
			||||||
 | 
					            gap_advertise_start(GapStateAdvLowPower);
 | 
				
			||||||
 | 
					        } else if(command == GapCommandAdvStop) {
 | 
				
			||||||
 | 
					            gap_advertise_stop();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        osMutexRelease(gap->state_mutex);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,11 @@ typedef enum {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool gap_init();
 | 
					bool gap_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GapState gap_get_status();
 | 
					void gap_start_advertising();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gap_stop_advertising();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GapState gap_get_state();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -61,7 +61,7 @@ void serial_svc_start() {
 | 
				
			|||||||
    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_tx_uuid,
 | 
					    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_tx_uuid,
 | 
				
			||||||
                                SERIAL_SVC_DATA_LEN_MAX,
 | 
					                                SERIAL_SVC_DATA_LEN_MAX,
 | 
				
			||||||
                                CHAR_PROP_WRITE_WITHOUT_RESP | CHAR_PROP_WRITE | CHAR_PROP_READ,
 | 
					                                CHAR_PROP_WRITE_WITHOUT_RESP | CHAR_PROP_WRITE | CHAR_PROP_READ,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ | ATTR_PERMISSION_AUTHEN_WRITE,
 | 
				
			||||||
                                GATT_NOTIFY_ATTRIBUTE_WRITE,
 | 
					                                GATT_NOTIFY_ATTRIBUTE_WRITE,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_VARIABLE,
 | 
					                                CHAR_VALUE_LEN_VARIABLE,
 | 
				
			||||||
@ -74,7 +74,7 @@ void serial_svc_start() {
 | 
				
			|||||||
    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_rx_uuid,
 | 
					    status = aci_gatt_add_char(serial_svc->svc_handle, UUID_TYPE_128, (const Char_UUID_t*)char_rx_uuid,
 | 
				
			||||||
                                SERIAL_SVC_DATA_LEN_MAX,                                  
 | 
					                                SERIAL_SVC_DATA_LEN_MAX,                                  
 | 
				
			||||||
                                CHAR_PROP_READ | CHAR_PROP_INDICATE,
 | 
					                                CHAR_PROP_READ | CHAR_PROP_INDICATE,
 | 
				
			||||||
                                ATTR_PERMISSION_NONE,
 | 
					                                ATTR_PERMISSION_AUTHEN_READ,
 | 
				
			||||||
                                GATT_DONT_NOTIFY_EVENTS,
 | 
					                                GATT_DONT_NOTIFY_EVENTS,
 | 
				
			||||||
                                10,
 | 
					                                10,
 | 
				
			||||||
                                CHAR_VALUE_LEN_VARIABLE,
 | 
					                                CHAR_VALUE_LEN_VARIABLE,
 | 
				
			||||||
@ -108,13 +108,15 @@ void serial_svc_stop() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool serial_svc_update_rx(uint8_t* data, uint8_t data_len) {
 | 
					bool serial_svc_update_rx(uint8_t* data, uint8_t data_len) {
 | 
				
			||||||
    furi_assert(data_len < SERIAL_SVC_DATA_LEN_MAX);
 | 
					    if(data_len > SERIAL_SVC_DATA_LEN_MAX) {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tBleStatus result = aci_gatt_update_char_value(serial_svc->svc_handle,
 | 
					    tBleStatus result = aci_gatt_update_char_value(serial_svc->svc_handle,
 | 
				
			||||||
                                          serial_svc->rx_char_handle,
 | 
					                                        serial_svc->rx_char_handle,
 | 
				
			||||||
                                          0,
 | 
					                                        0,
 | 
				
			||||||
                                          data_len,
 | 
					                                        data_len,
 | 
				
			||||||
                                          data);
 | 
					                                        data);
 | 
				
			||||||
    if(result) {
 | 
					    if(result) {
 | 
				
			||||||
        FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed updating RX characteristic: %d", result);
 | 
					        FURI_LOG_E(SERIAL_SERVICE_TAG, "Failed updating RX characteristic: %d", result);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,6 @@
 | 
				
			|||||||
#include <stm32wbxx.h>
 | 
					#include <stm32wbxx.h>
 | 
				
			||||||
#include <shci.h>
 | 
					#include <shci.h>
 | 
				
			||||||
#include <cmsis_os2.h>
 | 
					#include <cmsis_os2.h>
 | 
				
			||||||
#include <app_ble.h>
 | 
					 | 
				
			||||||
#include <gap.h>
 | 
					#include <gap.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_bt_init() {
 | 
					void furi_hal_bt_init() {
 | 
				
			||||||
@ -14,10 +13,22 @@ void furi_hal_bt_init() {
 | 
				
			|||||||
    APPE_Init();
 | 
					    APPE_Init();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool furi_hal_bt_start_app() {
 | 
					bool furi_hal_bt_init_app() {
 | 
				
			||||||
    return gap_init();
 | 
					    return gap_init();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void furi_hal_bt_start_advertising() {
 | 
				
			||||||
 | 
					    if(gap_get_state() == GapStateIdle) {
 | 
				
			||||||
 | 
					        gap_start_advertising();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void furi_hal_bt_stop_advertising() {
 | 
				
			||||||
 | 
					    if(furi_hal_bt_is_alive()) {
 | 
				
			||||||
 | 
					        gap_stop_advertising();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_bt_dump_state(string_t buffer) {
 | 
					void furi_hal_bt_dump_state(string_t buffer) {
 | 
				
			||||||
    BleGlueStatus status = APPE_Status();
 | 
					    BleGlueStatus status = APPE_Status();
 | 
				
			||||||
    if (status == BleGlueStatusStarted) {
 | 
					    if (status == BleGlueStatusStarted) {
 | 
				
			||||||
@ -41,7 +52,7 @@ void furi_hal_bt_dump_state(string_t buffer) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool furi_hal_bt_is_alive() {
 | 
					bool furi_hal_bt_is_alive() {
 | 
				
			||||||
    return APPE_Status() == BleGlueStatusStarted;
 | 
					    return gap_get_state() > GapStateIdle;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool furi_hal_bt_wait_startup() {
 | 
					bool furi_hal_bt_wait_startup() {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
#include <furi-hal-clock.h>
 | 
					#include <furi-hal-clock.h>
 | 
				
			||||||
 | 
					#include <furi.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <main.h>
 | 
					 | 
				
			||||||
#include <stm32wbxx_ll_pwr.h>
 | 
					#include <stm32wbxx_ll_pwr.h>
 | 
				
			||||||
#include <stm32wbxx_ll_rcc.h>
 | 
					#include <stm32wbxx_ll_rcc.h>
 | 
				
			||||||
#include <stm32wbxx_ll_utils.h>
 | 
					#include <stm32wbxx_ll_utils.h>
 | 
				
			||||||
@ -107,6 +107,12 @@ void furi_hal_clock_init() {
 | 
				
			|||||||
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE);
 | 
					    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE);
 | 
				
			||||||
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
 | 
					    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
 | 
				
			||||||
    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
 | 
					    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
 | 
				
			||||||
 | 
					    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_AES1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // AHB3
 | 
				
			||||||
 | 
					    LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PKA);
 | 
				
			||||||
 | 
					    LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_RNG);
 | 
				
			||||||
 | 
					    LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_AES2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // APB1
 | 
					    // APB1
 | 
				
			||||||
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
 | 
					    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
 | 
				
			||||||
@ -114,6 +120,8 @@ void furi_hal_clock_init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // APB2
 | 
					    // APB2
 | 
				
			||||||
    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
 | 
					    LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FURI_LOG_I("FuriHalClock", "Init OK");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_clock_switch_to_hsi() {
 | 
					void furi_hal_clock_switch_to_hsi() {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										69
									
								
								firmware/targets/f7/furi-hal/furi-hal-crypto.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								firmware/targets/f7/furi-hal/furi-hal-crypto.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					#include <furi-hal-crypto.h>
 | 
				
			||||||
 | 
					#include <furi.h>
 | 
				
			||||||
 | 
					#include <shci.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CRYP_HandleTypeDef crypt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void furi_hal_crypto_init() {
 | 
				
			||||||
 | 
					    FURI_LOG_I("FuriHalCrypto", "Init OK");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
 | 
				
			||||||
 | 
					    furi_assert(key);
 | 
				
			||||||
 | 
					    furi_assert(slot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t pParam;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (key->type == FuriHalCryptoKeyTypeMaster) {
 | 
				
			||||||
 | 
					        pParam.KeyType = KEYTYPE_MASTER;
 | 
				
			||||||
 | 
					    } else if (key->type == FuriHalCryptoKeyTypeSimple) {
 | 
				
			||||||
 | 
					        pParam.KeyType = KEYTYPE_SIMPLE;
 | 
				
			||||||
 | 
					    } else if (key->type == FuriHalCryptoKeyTypeEncrypted) {
 | 
				
			||||||
 | 
					        pParam.KeyType = KEYTYPE_ENCRYPTED;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        furi_crash("Incorrect key type");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (key->size == FuriHalCryptoKeySize128) {
 | 
				
			||||||
 | 
					        pParam.KeySize = KEYSIZE_16;
 | 
				
			||||||
 | 
					    } else if (key->size == FuriHalCryptoKeySize256) {
 | 
				
			||||||
 | 
					        pParam.KeySize = KEYSIZE_32;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        furi_crash("Incorrect key size");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return SHCI_C2_FUS_StoreUsrKey(&pParam, slot) == SHCI_Success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
 | 
				
			||||||
 | 
					    furi_assert(slot > 0 && slot <= 100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    crypt.Instance = AES1;
 | 
				
			||||||
 | 
					    crypt.Init.DataType = CRYP_DATATYPE_32B;
 | 
				
			||||||
 | 
					    crypt.Init.KeySize = CRYP_KEYSIZE_256B;
 | 
				
			||||||
 | 
					    crypt.Init.Algorithm = CRYP_AES_CBC;
 | 
				
			||||||
 | 
					    crypt.Init.pInitVect = (uint32_t*)iv;
 | 
				
			||||||
 | 
					    crypt.Init.pKey = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_unload_key(uint8_t slot) {
 | 
				
			||||||
 | 
					    furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
 | 
				
			||||||
 | 
					    return SHCI_C2_FUS_UnloadUsrKey(slot) == SHCI_Success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size) {
 | 
				
			||||||
 | 
					    return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size) {
 | 
				
			||||||
 | 
					    return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -41,7 +41,7 @@ void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR is
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        furi_hal_tim_tim1_isr = isr;
 | 
					        furi_hal_tim_tim1_isr = isr;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -54,7 +54,7 @@ void furi_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel,
 | 
				
			|||||||
    } else if (dma == DMA2) {
 | 
					    } else if (dma == DMA2) {
 | 
				
			||||||
        furi_hal_dma_channel_isr[1][channel] = isr;
 | 
					        furi_hal_dma_channel_isr[1][channel] = isr;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -244,7 +244,7 @@ static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) {
 | 
				
			|||||||
static void furi_hal_irda_tx_dma_polarity_isr() {
 | 
					static void furi_hal_irda_tx_dma_polarity_isr() {
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
 | 
					    if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TE1(DMA1);
 | 
					        LL_DMA_ClearFlag_TE1(DMA1);
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
 | 
					    if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TC1(DMA1);
 | 
					        LL_DMA_ClearFlag_TC1(DMA1);
 | 
				
			||||||
@ -261,7 +261,7 @@ static void furi_hal_irda_tx_dma_polarity_isr() {
 | 
				
			|||||||
static void furi_hal_irda_tx_dma_isr() {
 | 
					static void furi_hal_irda_tx_dma_isr() {
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
 | 
					    if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TE2(DMA1);
 | 
					        LL_DMA_ClearFlag_TE2(DMA1);
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
 | 
					    if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_HT2(DMA1);
 | 
					        LL_DMA_ClearFlag_HT2(DMA1);
 | 
				
			||||||
@ -277,7 +277,7 @@ static void furi_hal_irda_tx_dma_isr() {
 | 
				
			|||||||
        } else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
 | 
					        } else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
 | 
				
			||||||
            /* fallthrough */
 | 
					            /* fallthrough */
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            furi_check(0);
 | 
					            furi_crash(NULL);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
 | 
					    if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
 | 
				
			||||||
@ -557,7 +557,7 @@ static void furi_hal_irda_async_tx_free_resources(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
 | 
					void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
 | 
				
			||||||
    if ((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) {
 | 
					    if ((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_assert(furi_hal_irda_state == IrdaStateIdle);
 | 
					    furi_assert(furi_hal_irda_state == IrdaStateIdle);
 | 
				
			||||||
 | 
				
			|||||||
@ -261,7 +261,7 @@ void furi_hal_rfid_set_emulate_pulse(uint32_t pulse) {
 | 
				
			|||||||
        LFRFID_EMULATE_TIM.Instance->CCR4 = pulse;
 | 
					        LFRFID_EMULATE_TIM.Instance->CCR4 = pulse;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -285,7 +285,7 @@ void furi_hal_rfid_set_read_pulse(uint32_t pulse) {
 | 
				
			|||||||
        LFRFID_TIM.Instance->CCR4 = pulse;
 | 
					        LFRFID_TIM.Instance->CCR4 = pulse;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -15,166 +15,174 @@ static const uint8_t furi_hal_subghz_preset_ook_270khz_async_regs[][2] = {
 | 
				
			|||||||
    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
					    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* GPIO GD0 */
 | 
					    /* GPIO GD0 */
 | 
				
			||||||
    { CC1101_IOCFG0,    0x0D }, // GD0 as async serial data output/input
 | 
					    {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* FIFO and internals */
 | 
					    /* FIFO and internals */
 | 
				
			||||||
    { CC1101_FIFOTHR,   0x47 }, // The only important bit is ADC_RETENTION, FIFO Tx=33 Rx=32
 | 
					    {CC1101_FIFOTHR, 0x47}, // The only important bit is ADC_RETENTION, FIFO Tx=33 Rx=32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Packet engine */
 | 
					    /* Packet engine */
 | 
				
			||||||
    { CC1101_PKTCTRL0,  0x32 }, // Async, continious, no whitening
 | 
					    {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Control */
 | 
					    /* Frequency Synthesizer Control */
 | 
				
			||||||
    { CC1101_FSCTRL1,   0x06 }, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
					    {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Modem Configuration
 | 
					    // Modem Configuration
 | 
				
			||||||
    { CC1101_MDMCFG0,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG1,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG2,   0x30 }, // Format ASK/OOK, No preamble/sync
 | 
					    {CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
 | 
				
			||||||
    { CC1101_MDMCFG3,   0x32 }, // Data rate is 3.79372 kBaud
 | 
					    {CC1101_MDMCFG3, 0x32}, // Data rate is 3.79372 kBaud
 | 
				
			||||||
    { CC1101_MDMCFG4,   0x67 }, // Rx BW filter is 270.833333kHz
 | 
					    {CC1101_MDMCFG4, 0x67}, // Rx BW filter is 270.833333kHz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Main Radio Control State Machine */
 | 
					    /* Main Radio Control State Machine */
 | 
				
			||||||
    { CC1101_MCSM0,     0x18 }, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
					    {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Offset Compensation Configuration */
 | 
					    /* Frequency Offset Compensation Configuration */
 | 
				
			||||||
    { CC1101_FOCCFG,    0x18 }, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
					    {CC1101_FOCCFG,
 | 
				
			||||||
 | 
					     0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Automatic Gain Control */
 | 
					    /* Automatic Gain Control */
 | 
				
			||||||
    { CC1101_AGCTRL0,   0x40 }, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
					    {CC1101_AGCTRL0,
 | 
				
			||||||
    { CC1101_AGCTRL1,   0x00 }, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
					     0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
				
			||||||
    { CC1101_AGCTRL2,   0x03 }, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
					    {CC1101_AGCTRL1,
 | 
				
			||||||
 | 
					     0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
				
			||||||
 | 
					    {CC1101_AGCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Wake on radio and timeouts control */
 | 
					    /* Wake on radio and timeouts control */
 | 
				
			||||||
    { CC1101_WORCTRL,   0xFB }, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours 
 | 
					    {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frontend configuration */
 | 
					    /* Frontend configuration */
 | 
				
			||||||
    { CC1101_FREND0,    0x11 }, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
					    {CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
				
			||||||
    { CC1101_FREND1,    0xB6 }, // 
 | 
					    {CC1101_FREND1, 0xB6}, //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
					    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
				
			||||||
    { CC1101_FSCAL3,    0xE9 },
 | 
					    {CC1101_FSCAL3, 0xE9},
 | 
				
			||||||
    { CC1101_FSCAL2,    0x2A },
 | 
					    {CC1101_FSCAL2, 0x2A},
 | 
				
			||||||
    { CC1101_FSCAL1,    0x00 },
 | 
					    {CC1101_FSCAL1, 0x00},
 | 
				
			||||||
    { CC1101_FSCAL0,    0x1F }, 
 | 
					    {CC1101_FSCAL0, 0x1F},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Magic f4ckery */
 | 
					    /* Magic f4ckery */
 | 
				
			||||||
    { CC1101_TEST2,     0x81 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST2, 0x81}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST1,     0x35 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST1, 0x35}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST0,     0x09 }, // VCO selection calibration stage is disabled
 | 
					    {CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* End  */
 | 
					    /* End  */
 | 
				
			||||||
    { 0, 0 },
 | 
					    {0, 0},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_ook_650khz_async_regs[][2] = {
 | 
					static const uint8_t furi_hal_subghz_preset_ook_650khz_async_regs[][2] = {
 | 
				
			||||||
    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
					    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* GPIO GD0 */
 | 
					    /* GPIO GD0 */
 | 
				
			||||||
    { CC1101_IOCFG0,    0x0D }, // GD0 as async serial data output/input
 | 
					    {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* FIFO and internals */
 | 
					    /* FIFO and internals */
 | 
				
			||||||
    { CC1101_FIFOTHR,   0x07 }, // The only important bit is ADC_RETENTION
 | 
					    {CC1101_FIFOTHR, 0x07}, // The only important bit is ADC_RETENTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Packet engine */
 | 
					    /* Packet engine */
 | 
				
			||||||
    { CC1101_PKTCTRL0,  0x32 }, // Async, continious, no whitening
 | 
					    {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Control */
 | 
					    /* Frequency Synthesizer Control */
 | 
				
			||||||
    { CC1101_FSCTRL1,   0x06 }, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
					    {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Modem Configuration
 | 
					    // Modem Configuration
 | 
				
			||||||
    { CC1101_MDMCFG0,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG0, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG1,   0x00 }, // Channel spacing is 25kHz
 | 
					    {CC1101_MDMCFG1, 0x00}, // Channel spacing is 25kHz
 | 
				
			||||||
    { CC1101_MDMCFG2,   0x30 }, // Format ASK/OOK, No preamble/sync
 | 
					    {CC1101_MDMCFG2, 0x30}, // Format ASK/OOK, No preamble/sync
 | 
				
			||||||
    { CC1101_MDMCFG3,   0x32 }, // Data rate is 3.79372 kBaud
 | 
					    {CC1101_MDMCFG3, 0x32}, // Data rate is 3.79372 kBaud
 | 
				
			||||||
    { CC1101_MDMCFG4,   0x17  }, // Rx BW filter is 650.000kHz
 | 
					    {CC1101_MDMCFG4, 0x17}, // Rx BW filter is 650.000kHz
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    /* Main Radio Control State Machine */
 | 
					    /* Main Radio Control State Machine */
 | 
				
			||||||
    { CC1101_MCSM0,     0x18 }, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
					    {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Offset Compensation Configuration */
 | 
					    /* Frequency Offset Compensation Configuration */
 | 
				
			||||||
    { CC1101_FOCCFG,    0x18 }, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
					    {CC1101_FOCCFG,
 | 
				
			||||||
 | 
					     0x18}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Automatic Gain Control */
 | 
					    /* Automatic Gain Control */
 | 
				
			||||||
    { CC1101_AGCTRL0,   0x40 }, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
					    {CC1101_AGCTRL0,
 | 
				
			||||||
    { CC1101_AGCTRL1,   0x00 }, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
					     0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
				
			||||||
    { CC1101_AGCTRL2,   0x03 }, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
					    {CC1101_AGCTRL1,
 | 
				
			||||||
 | 
					     0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
				
			||||||
 | 
					    {CC1101_AGCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Wake on radio and timeouts control */
 | 
					    /* Wake on radio and timeouts control */
 | 
				
			||||||
    { CC1101_WORCTRL,   0xFB }, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours 
 | 
					    {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frontend configuration */
 | 
					    /* Frontend configuration */
 | 
				
			||||||
    { CC1101_FREND0,    0x11 }, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
					    {CC1101_FREND0, 0x11}, // Adjusts current TX LO buffer + high is PATABLE[1]
 | 
				
			||||||
    { CC1101_FREND1,    0xB6 }, // 
 | 
					    {CC1101_FREND1, 0xB6}, //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
					    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
				
			||||||
    { CC1101_FSCAL3,    0xE9 },
 | 
					    {CC1101_FSCAL3, 0xE9},
 | 
				
			||||||
    { CC1101_FSCAL2,    0x2A },
 | 
					    {CC1101_FSCAL2, 0x2A},
 | 
				
			||||||
    { CC1101_FSCAL1,    0x00 },
 | 
					    {CC1101_FSCAL1, 0x00},
 | 
				
			||||||
    { CC1101_FSCAL0,    0x1F }, 
 | 
					    {CC1101_FSCAL0, 0x1F},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Magic f4ckery */
 | 
					    /* Magic f4ckery */
 | 
				
			||||||
    { CC1101_TEST2,     0x88 },
 | 
					    {CC1101_TEST2, 0x88},
 | 
				
			||||||
    { CC1101_TEST1,     0x31 },
 | 
					    {CC1101_TEST1, 0x31},
 | 
				
			||||||
    { CC1101_TEST0,     0x09 }, // VCO selection calibration stage is disabled
 | 
					    {CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* End  */
 | 
					    /* End  */
 | 
				
			||||||
    { 0, 0 },
 | 
					    {0, 0},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
 | 
					static const uint8_t furi_hal_subghz_preset_2fsk_async_regs[][2] = {
 | 
				
			||||||
    // https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* GPIO GD0 */
 | 
					    /* GPIO GD0 */
 | 
				
			||||||
    { CC1101_IOCFG0,    0x0D }, // GD0 as async serial data output/input
 | 
					    {CC1101_IOCFG0, 0x0D}, // GD0 as async serial data output/input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* FIFO and internals */
 | 
					    /* FIFO and internals */
 | 
				
			||||||
    { CC1101_FIFOTHR,   0x47 }, // The only important bit is ADC_RETENTION
 | 
					    {CC1101_FIFOTHR, 0x47}, // The only important bit is ADC_RETENTION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Packet engine */
 | 
					    /* Packet engine */
 | 
				
			||||||
    { CC1101_PKTCTRL0,  0x32 }, // Async, continious, no whitening
 | 
					    {CC1101_PKTCTRL0, 0x32}, // Async, continious, no whitening
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Control */
 | 
					    /* Frequency Synthesizer Control */
 | 
				
			||||||
    { CC1101_FSCTRL1,   0x06 }, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
					    {CC1101_FSCTRL1, 0x06}, // IF = (26*10^6) / (2^10) * 0x06 = 152343.75Hz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Modem Configuration
 | 
					    // Modem Configuration
 | 
				
			||||||
    { CC1101_MDMCFG0,   0xF8 }, 
 | 
					    {CC1101_MDMCFG0, 0x00},
 | 
				
			||||||
    { CC1101_MDMCFG1,   0x00 }, // No preamble/sync
 | 
					    {CC1101_MDMCFG1, 0x02},
 | 
				
			||||||
    { CC1101_MDMCFG2,   0x80 }, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
 | 
					    {CC1101_MDMCFG2, 0x04}, // Format 2-FSK/FM, No preamble/sync, Disable (current optimized)
 | 
				
			||||||
    { CC1101_MDMCFG3,   0x83 }, // Data rate is 9.59587 kBaud
 | 
					    {CC1101_MDMCFG3, 0x8B}, // Data rate is 19.5885 kBaud
 | 
				
			||||||
    { CC1101_MDMCFG4,   0x88 }, // Rx BW filter is 203.125000kHz
 | 
					    {CC1101_MDMCFG4, 0x69}, // Rx BW filter is 270.833333 kHz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    { CC1101_DEVIATN,  0x14}, //Deviation 4.760742 khz
 | 
					    {CC1101_DEVIATN, 0x47}, //Deviation 47.607422 khz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Main Radio Control State Machine */
 | 
					    /* Main Radio Control State Machine */
 | 
				
			||||||
    { CC1101_MCSM0,     0x18 }, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
					    {CC1101_MCSM0, 0x18}, // Autocalibrate on idle-to-rx/tx, PO_TIMEOUT is 64 cycles(149-155us)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Offset Compensation Configuration */
 | 
					    /* Frequency Offset Compensation Configuration */
 | 
				
			||||||
    { CC1101_FOCCFG,    0x18 }, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
					    {CC1101_FOCCFG,
 | 
				
			||||||
 | 
					     0x16}, // no frequency offset compensation, POST_K same as PRE_K, PRE_K is 4K, GATE is off
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Automatic Gain Control */
 | 
					    /* Automatic Gain Control */
 | 
				
			||||||
    { CC1101_AGCTRL0,   0x40 }, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
					    {CC1101_AGCTRL0,
 | 
				
			||||||
    { CC1101_AGCTRL1,   0x00 }, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
					     0x40}, // 01 - Low hysteresis, small asymmetric dead zone, medium gain; 00 - 8 samples agc; 00 - Normal AGC, 00 - 4dB boundary
 | 
				
			||||||
    { CC1101_AGCTRL2,   0x03 }, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
					    {CC1101_AGCTRL1,
 | 
				
			||||||
 | 
					     0x00}, // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 0000 - RSSI to MAIN_TARGET
 | 
				
			||||||
 | 
					    {CC1101_AGCTRL2, 0x03}, // 00 - DVGA all; 000 - MAX LNA+LNA2; 011 - MAIN_TARGET 24 dB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Wake on radio and timeouts control */
 | 
					    /* Wake on radio and timeouts control */
 | 
				
			||||||
    { CC1101_WORCTRL,   0xFB }, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours 
 | 
					    {CC1101_WORCTRL, 0xFB}, // WOR_RES is 2^15 periods (0.91 - 0.94 s) 16.5 - 17.2 hours
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frontend configuration */
 | 
					    /* Frontend configuration */
 | 
				
			||||||
    { CC1101_FREND0,    0x10 }, // Adjusts current TX LO buffer
 | 
					    {CC1101_FREND0, 0x10}, // Adjusts current TX LO buffer
 | 
				
			||||||
    { CC1101_FREND1,    0xB6 }, // 
 | 
					    {CC1101_FREND1, 0xB6}, //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
					    /* Frequency Synthesizer Calibration, valid for 433.92 */
 | 
				
			||||||
    { CC1101_FSCAL3,    0xE9 },
 | 
					    {CC1101_FSCAL3, 0xE9},
 | 
				
			||||||
    { CC1101_FSCAL2,    0x2A },
 | 
					    {CC1101_FSCAL2, 0x2A},
 | 
				
			||||||
    { CC1101_FSCAL1,    0x00 },
 | 
					    {CC1101_FSCAL1, 0x00},
 | 
				
			||||||
    { CC1101_FSCAL0,    0x1F }, 
 | 
					    {CC1101_FSCAL0, 0x1F},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Magic f4ckery */
 | 
					    /* Magic f4ckery */
 | 
				
			||||||
    { CC1101_TEST2,     0x81 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST2, 0x81}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST1,     0x35 }, // FIFOTHR ADC_RETENTION=1 matched value
 | 
					    {CC1101_TEST1, 0x35}, // FIFOTHR ADC_RETENTION=1 matched value
 | 
				
			||||||
    { CC1101_TEST0,     0x09 }, // VCO selection calibration stage is disabled
 | 
					    {CC1101_TEST0, 0x09}, // VCO selection calibration stage is disabled
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* End  */
 | 
					    /* End  */
 | 
				
			||||||
    { 0, 0 },
 | 
					    {0, 0},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
 | 
					static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
@ -184,8 +192,7 @@ static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
 | 
				
			|||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00
 | 
					    0x00};
 | 
				
			||||||
};
 | 
					 | 
				
			||||||
static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = {
 | 
					static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = {
 | 
				
			||||||
    0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
 | 
					    0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
@ -194,8 +201,7 @@ static const uint8_t furi_hal_subghz_preset_2fsk_async_patable[8] = {
 | 
				
			|||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00,
 | 
					    0x00,
 | 
				
			||||||
    0x00
 | 
					    0x00};
 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void furi_hal_subghz_init() {
 | 
					void furi_hal_subghz_init() {
 | 
				
			||||||
    furi_assert(furi_hal_subghz_state == SubGhzStateInit);
 | 
					    furi_assert(furi_hal_subghz_state == SubGhzStateInit);
 | 
				
			||||||
@ -217,11 +223,13 @@ void furi_hal_subghz_init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // GD0 low
 | 
					    // GD0 low
 | 
				
			||||||
    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW);
 | 
					    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW);
 | 
				
			||||||
    while(hal_gpio_read(&gpio_cc1101_g0) != false);
 | 
					    while(hal_gpio_read(&gpio_cc1101_g0) != false)
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // GD0 high
 | 
					    // GD0 high
 | 
				
			||||||
    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
					    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
				
			||||||
    while(hal_gpio_read(&gpio_cc1101_g0) != true);
 | 
					    while(hal_gpio_read(&gpio_cc1101_g0) != true)
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Reset GD0 to floating state
 | 
					    // Reset GD0 to floating state
 | 
				
			||||||
    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHighImpedance);
 | 
					    cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHighImpedance);
 | 
				
			||||||
@ -257,8 +265,7 @@ void furi_hal_subghz_dump_state() {
 | 
				
			|||||||
    printf(
 | 
					    printf(
 | 
				
			||||||
        "[furi_hal_subghz] cc1101 chip %d, version %d\r\n",
 | 
					        "[furi_hal_subghz] cc1101 chip %d, version %d\r\n",
 | 
				
			||||||
        cc1101_get_partnumber(device),
 | 
					        cc1101_get_partnumber(device),
 | 
				
			||||||
        cc1101_get_version(device)
 | 
					        cc1101_get_version(device));
 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    furi_hal_spi_device_return(device);
 | 
					    furi_hal_spi_device_return(device);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -266,14 +273,14 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
 | 
				
			|||||||
    if(preset == FuriHalSubGhzPresetOok650Async) {
 | 
					    if(preset == FuriHalSubGhzPresetOok650Async) {
 | 
				
			||||||
        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_650khz_async_regs);
 | 
					        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_650khz_async_regs);
 | 
				
			||||||
        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
					        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
				
			||||||
    } else if(preset == FuriHalSubGhzPresetOok270Async){
 | 
					    } else if(preset == FuriHalSubGhzPresetOok270Async) {
 | 
				
			||||||
        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_270khz_async_regs);
 | 
					        furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_270khz_async_regs);
 | 
				
			||||||
        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
					        furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
 | 
				
			||||||
    } else if(preset == FuriHalSubGhzPreset2FSKAsync){
 | 
					    } else if(preset == FuriHalSubGhzPreset2FSKAsync) {
 | 
				
			||||||
        furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
 | 
					        furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
 | 
				
			||||||
        furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
 | 
					        furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
 | 
				
			||||||
    }else {
 | 
					    }else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -289,7 +296,7 @@ void furi_hal_subghz_load_registers(const uint8_t data[][2]) {
 | 
				
			|||||||
    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
					    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
				
			||||||
    cc1101_reset(device);
 | 
					    cc1101_reset(device);
 | 
				
			||||||
    uint32_t i = 0;
 | 
					    uint32_t i = 0;
 | 
				
			||||||
    while (data[i][0]) {
 | 
					    while(data[i][0]) {
 | 
				
			||||||
        cc1101_write_reg(device, data[i][0], data[i][1]);
 | 
					        cc1101_write_reg(device, data[i][0], data[i][1]);
 | 
				
			||||||
        i++;
 | 
					        i++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -388,7 +395,7 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
 | 
				
			|||||||
    } else if(value >= 778999847 && value <= 928000000) {
 | 
					    } else if(value >= 778999847 && value <= 928000000) {
 | 
				
			||||||
        furi_hal_subghz_set_path(FuriHalSubGhzPath868);
 | 
					        furi_hal_subghz_set_path(FuriHalSubGhzPath868);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return value;
 | 
					    return value;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -401,7 +408,7 @@ uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    while(true) {
 | 
					    while(true) {
 | 
				
			||||||
        CC1101Status status = cc1101_get_status(device);
 | 
					        CC1101Status status = cc1101_get_status(device);
 | 
				
			||||||
        if (status.STATE == CC1101StateIDLE) break;
 | 
					        if(status.STATE == CC1101StateIDLE) break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_hal_spi_device_return(device);
 | 
					    furi_hal_spi_device_return(device);
 | 
				
			||||||
@ -411,20 +418,20 @@ uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
 | 
					void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
 | 
				
			||||||
    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
					    const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
 | 
				
			||||||
    if (path == FuriHalSubGhzPath433) {
 | 
					    if(path == FuriHalSubGhzPath433) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
				
			||||||
    } else if (path == FuriHalSubGhzPath315) {
 | 
					    } else if(path == FuriHalSubGhzPath315) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
				
			||||||
    } else if (path == FuriHalSubGhzPath868) {
 | 
					    } else if(path == FuriHalSubGhzPath868) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 1);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
 | 
				
			||||||
    } else if (path == FuriHalSubGhzPathIsolate) {
 | 
					    } else if(path == FuriHalSubGhzPathIsolate) {
 | 
				
			||||||
        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
					        hal_gpio_write(&gpio_rf_sw_0, 0);
 | 
				
			||||||
        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
					        cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    furi_hal_spi_device_return(device);
 | 
					    furi_hal_spi_device_return(device);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -438,24 +445,25 @@ static void furi_hal_subghz_capture_ISR() {
 | 
				
			|||||||
    if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
 | 
					    if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
 | 
				
			||||||
        LL_TIM_ClearFlag_CC1(TIM2);
 | 
					        LL_TIM_ClearFlag_CC1(TIM2);
 | 
				
			||||||
        furi_hal_subghz_capture_delta_duration = LL_TIM_IC_GetCaptureCH1(TIM2);
 | 
					        furi_hal_subghz_capture_delta_duration = LL_TIM_IC_GetCaptureCH1(TIM2);
 | 
				
			||||||
        if (furi_hal_subghz_capture_callback) {
 | 
					        if(furi_hal_subghz_capture_callback) {
 | 
				
			||||||
            furi_hal_subghz_capture_callback(true, furi_hal_subghz_capture_delta_duration,
 | 
					            furi_hal_subghz_capture_callback(
 | 
				
			||||||
                (void*)furi_hal_subghz_capture_callback_context
 | 
					                true,
 | 
				
			||||||
            );
 | 
					                furi_hal_subghz_capture_delta_duration,
 | 
				
			||||||
 | 
					                (void*)furi_hal_subghz_capture_callback_context);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Channel 2
 | 
					    // Channel 2
 | 
				
			||||||
    if(LL_TIM_IsActiveFlag_CC2(TIM2)) {
 | 
					    if(LL_TIM_IsActiveFlag_CC2(TIM2)) {
 | 
				
			||||||
        LL_TIM_ClearFlag_CC2(TIM2);
 | 
					        LL_TIM_ClearFlag_CC2(TIM2);
 | 
				
			||||||
        if (furi_hal_subghz_capture_callback) {
 | 
					        if(furi_hal_subghz_capture_callback) {
 | 
				
			||||||
            furi_hal_subghz_capture_callback(false, LL_TIM_IC_GetCaptureCH2(TIM2) - furi_hal_subghz_capture_delta_duration,
 | 
					            furi_hal_subghz_capture_callback(
 | 
				
			||||||
                (void*)furi_hal_subghz_capture_callback_context
 | 
					                false,
 | 
				
			||||||
            );
 | 
					                LL_TIM_IC_GetCaptureCH2(TIM2) - furi_hal_subghz_capture_delta_duration,
 | 
				
			||||||
 | 
					                (void*)furi_hal_subghz_capture_callback_context);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context) {
 | 
					void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void* context) {
 | 
				
			||||||
    furi_assert(furi_hal_subghz_state == SubGhzStateIdle);
 | 
					    furi_assert(furi_hal_subghz_state == SubGhzStateIdle);
 | 
				
			||||||
    furi_hal_subghz_state = SubGhzStateAsyncRx;
 | 
					    furi_hal_subghz_state = SubGhzStateAsyncRx;
 | 
				
			||||||
@ -463,12 +471,13 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
 | 
				
			|||||||
    furi_hal_subghz_capture_callback = callback;
 | 
					    furi_hal_subghz_capture_callback = callback;
 | 
				
			||||||
    furi_hal_subghz_capture_callback_context = context;
 | 
					    furi_hal_subghz_capture_callback_context = context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hal_gpio_init_ex(&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
 | 
					    hal_gpio_init_ex(
 | 
				
			||||||
 | 
					        &gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Timer: base
 | 
					    // Timer: base
 | 
				
			||||||
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
					    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
				
			||||||
    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
					    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
				
			||||||
    TIM_InitStruct.Prescaler = 64-1; 
 | 
					    TIM_InitStruct.Prescaler = 64 - 1;
 | 
				
			||||||
    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
					    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
				
			||||||
    TIM_InitStruct.Autoreload = 0x7FFFFFFE;
 | 
					    TIM_InitStruct.Autoreload = 0x7FFFFFFE;
 | 
				
			||||||
    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
					    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
				
			||||||
@ -498,7 +507,7 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // ISR setup
 | 
					    // ISR setup
 | 
				
			||||||
    furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_subghz_capture_ISR);
 | 
					    furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_subghz_capture_ISR);
 | 
				
			||||||
    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
 | 
					    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
 | 
				
			||||||
    NVIC_EnableIRQ(TIM2_IRQn);
 | 
					    NVIC_EnableIRQ(TIM2_IRQn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Interrupts and channels
 | 
					    // Interrupts and channels
 | 
				
			||||||
@ -508,7 +517,7 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
 | 
				
			|||||||
    LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
 | 
					    LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Enable NVIC
 | 
					    // Enable NVIC
 | 
				
			||||||
    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
 | 
					    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
 | 
				
			||||||
    NVIC_EnableIRQ(TIM2_IRQn);
 | 
					    NVIC_EnableIRQ(TIM2_IRQn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Start timer
 | 
					    // Start timer
 | 
				
			||||||
@ -534,8 +543,8 @@ void furi_hal_subghz_stop_async_rx() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256)
 | 
					#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256)
 | 
				
			||||||
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL/2)
 | 
					#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL / 2)
 | 
				
			||||||
#define API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME  333
 | 
					#define API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME 333
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    uint32_t* buffer;
 | 
					    uint32_t* buffer;
 | 
				
			||||||
@ -547,12 +556,13 @@ typedef struct {
 | 
				
			|||||||
static FuriHalSubGhzAsyncTx furi_hal_subghz_async_tx = {0};
 | 
					static FuriHalSubGhzAsyncTx furi_hal_subghz_async_tx = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
					static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
				
			||||||
    while (samples > 0) {
 | 
					    while(samples > 0) {
 | 
				
			||||||
        bool is_odd = samples % 2;
 | 
					        bool is_odd = samples % 2;
 | 
				
			||||||
        LevelDuration ld = furi_hal_subghz_async_tx.callback(furi_hal_subghz_async_tx.callback_context);
 | 
					        LevelDuration ld =
 | 
				
			||||||
        if (level_duration_is_reset(ld)) {
 | 
					            furi_hal_subghz_async_tx.callback(furi_hal_subghz_async_tx.callback_context);
 | 
				
			||||||
 | 
					        if(level_duration_is_reset(ld)) {
 | 
				
			||||||
            // One more even sample required to end at low level
 | 
					            // One more even sample required to end at low level
 | 
				
			||||||
            if (is_odd) {
 | 
					            if(is_odd) {
 | 
				
			||||||
                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
					                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
				
			||||||
                buffer++;
 | 
					                buffer++;
 | 
				
			||||||
                samples--;
 | 
					                samples--;
 | 
				
			||||||
@ -560,7 +570,7 @@ static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            // Inject guard time if level is incorrect
 | 
					            // Inject guard time if level is incorrect
 | 
				
			||||||
            if (is_odd == level_duration_get_level(ld)) {
 | 
					            if(is_odd == level_duration_get_level(ld)) {
 | 
				
			||||||
                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
					                *buffer = API_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME;
 | 
				
			||||||
                buffer++;
 | 
					                buffer++;
 | 
				
			||||||
                samples--;
 | 
					                samples--;
 | 
				
			||||||
@ -579,21 +589,24 @@ static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void furi_hal_subghz_async_tx_dma_isr() {
 | 
					static void furi_hal_subghz_async_tx_dma_isr() {
 | 
				
			||||||
    furi_assert(furi_hal_subghz_state == SubGhzStateAsyncTx);
 | 
					    furi_assert(furi_hal_subghz_state == SubGhzStateAsyncTx);
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_HT1(DMA1)) {
 | 
					    if(LL_DMA_IsActiveFlag_HT1(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_HT1(DMA1);
 | 
					        LL_DMA_ClearFlag_HT1(DMA1);
 | 
				
			||||||
        furi_hal_subghz_async_tx_refill(furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
					        furi_hal_subghz_async_tx_refill(
 | 
				
			||||||
 | 
					            furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (LL_DMA_IsActiveFlag_TC1(DMA1)) {
 | 
					    if(LL_DMA_IsActiveFlag_TC1(DMA1)) {
 | 
				
			||||||
        LL_DMA_ClearFlag_TC1(DMA1);
 | 
					        LL_DMA_ClearFlag_TC1(DMA1);
 | 
				
			||||||
        furi_hal_subghz_async_tx_refill(furi_hal_subghz_async_tx.buffer+API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
					        furi_hal_subghz_async_tx_refill(
 | 
				
			||||||
 | 
					            furi_hal_subghz_async_tx.buffer + API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF,
 | 
				
			||||||
 | 
					            API_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void furi_hal_subghz_async_tx_timer_isr() {
 | 
					static void furi_hal_subghz_async_tx_timer_isr() {
 | 
				
			||||||
    if(LL_TIM_IsActiveFlag_UPDATE(TIM2)) {
 | 
					    if(LL_TIM_IsActiveFlag_UPDATE(TIM2)) {
 | 
				
			||||||
        LL_TIM_ClearFlag_UPDATE(TIM2);
 | 
					        LL_TIM_ClearFlag_UPDATE(TIM2);
 | 
				
			||||||
        if (LL_TIM_GetAutoReload(TIM2) == 0) {
 | 
					        if(LL_TIM_GetAutoReload(TIM2) == 0) {
 | 
				
			||||||
            if (furi_hal_subghz_state == SubGhzStateAsyncTx) {
 | 
					            if(furi_hal_subghz_state == SubGhzStateAsyncTx) {
 | 
				
			||||||
                furi_hal_subghz_state = SubGhzStateAsyncTxLast;
 | 
					                furi_hal_subghz_state = SubGhzStateAsyncTxLast;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                furi_hal_subghz_state = SubGhzStateAsyncTxEnd;
 | 
					                furi_hal_subghz_state = SubGhzStateAsyncTxEnd;
 | 
				
			||||||
@ -612,15 +625,18 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    furi_hal_subghz_state = SubGhzStateAsyncTx;
 | 
					    furi_hal_subghz_state = SubGhzStateAsyncTx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    furi_hal_subghz_async_tx.buffer = furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
 | 
					    furi_hal_subghz_async_tx.buffer =
 | 
				
			||||||
    furi_hal_subghz_async_tx_refill(furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL);
 | 
					        furi_alloc(API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
 | 
				
			||||||
 | 
					    furi_hal_subghz_async_tx_refill(
 | 
				
			||||||
 | 
					        furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Connect CC1101_GD0 to TIM2 as output
 | 
					    // Connect CC1101_GD0 to TIM2 as output
 | 
				
			||||||
    hal_gpio_init_ex(&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullDown, GpioSpeedLow, GpioAltFn1TIM2);
 | 
					    hal_gpio_init_ex(
 | 
				
			||||||
 | 
					        &gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullDown, GpioSpeedLow, GpioAltFn1TIM2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Configure DMA
 | 
					    // Configure DMA
 | 
				
			||||||
    LL_DMA_InitTypeDef dma_config = {0};
 | 
					    LL_DMA_InitTypeDef dma_config = {0};
 | 
				
			||||||
    dma_config.PeriphOrM2MSrcAddress = (uint32_t)&(TIM2->ARR);
 | 
					    dma_config.PeriphOrM2MSrcAddress = (uint32_t) & (TIM2->ARR);
 | 
				
			||||||
    dma_config.MemoryOrM2MDstAddress = (uint32_t)furi_hal_subghz_async_tx.buffer;
 | 
					    dma_config.MemoryOrM2MDstAddress = (uint32_t)furi_hal_subghz_async_tx.buffer;
 | 
				
			||||||
    dma_config.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
 | 
					    dma_config.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
 | 
				
			||||||
    dma_config.Mode = LL_DMA_MODE_CIRCULAR;
 | 
					    dma_config.Mode = LL_DMA_MODE_CIRCULAR;
 | 
				
			||||||
@ -632,7 +648,8 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
    dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM2_UP;
 | 
					    dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM2_UP;
 | 
				
			||||||
    dma_config.Priority = LL_DMA_MODE_NORMAL;
 | 
					    dma_config.Priority = LL_DMA_MODE_NORMAL;
 | 
				
			||||||
    LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config);
 | 
					    LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config);
 | 
				
			||||||
    furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, furi_hal_subghz_async_tx_dma_isr);
 | 
					    furi_hal_interrupt_set_dma_channel_isr(
 | 
				
			||||||
 | 
					        DMA1, LL_DMA_CHANNEL_1, furi_hal_subghz_async_tx_dma_isr);
 | 
				
			||||||
    LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
 | 
					    LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
 | 
				
			||||||
    LL_DMA_EnableIT_HT(DMA1, LL_DMA_CHANNEL_1);
 | 
					    LL_DMA_EnableIT_HT(DMA1, LL_DMA_CHANNEL_1);
 | 
				
			||||||
    LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
 | 
					    LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
 | 
				
			||||||
@ -640,7 +657,7 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
    // Configure TIM2
 | 
					    // Configure TIM2
 | 
				
			||||||
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
					    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
 | 
				
			||||||
    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
					    LL_TIM_InitTypeDef TIM_InitStruct = {0};
 | 
				
			||||||
    TIM_InitStruct.Prescaler = 64-1;
 | 
					    TIM_InitStruct.Prescaler = 64 - 1;
 | 
				
			||||||
    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
					    TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
 | 
				
			||||||
    TIM_InitStruct.Autoreload = 1000;
 | 
					    TIM_InitStruct.Autoreload = 1000;
 | 
				
			||||||
    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
					    TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
 | 
				
			||||||
@ -672,7 +689,7 @@ void furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
 | 
				
			|||||||
    furi_hal_subghz_tx();
 | 
					    furi_hal_subghz_tx();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Enable NVIC
 | 
					    // Enable NVIC
 | 
				
			||||||
    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
 | 
					    NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
 | 
				
			||||||
    NVIC_EnableIRQ(TIM2_IRQn);
 | 
					    NVIC_EnableIRQ(TIM2_IRQn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    LL_TIM_SetCounter(TIM2, 0);
 | 
					    LL_TIM_SetCounter(TIM2, 0);
 | 
				
			||||||
@ -685,10 +702,9 @@ bool furi_hal_subghz_is_async_tx_complete() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void furi_hal_subghz_stop_async_tx() {
 | 
					void furi_hal_subghz_stop_async_tx() {
 | 
				
			||||||
    furi_assert(
 | 
					    furi_assert(
 | 
				
			||||||
        furi_hal_subghz_state == SubGhzStateAsyncTx
 | 
					        furi_hal_subghz_state == SubGhzStateAsyncTx ||
 | 
				
			||||||
        || furi_hal_subghz_state == SubGhzStateAsyncTxLast
 | 
					        furi_hal_subghz_state == SubGhzStateAsyncTxLast ||
 | 
				
			||||||
        || furi_hal_subghz_state == SubGhzStateAsyncTxEnd
 | 
					        furi_hal_subghz_state == SubGhzStateAsyncTxEnd);
 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Shutdown radio
 | 
					    // Shutdown radio
 | 
				
			||||||
    furi_hal_subghz_idle();
 | 
					    furi_hal_subghz_idle();
 | 
				
			||||||
 | 
				
			|||||||
@ -163,7 +163,7 @@ void furi_hal_version_init() {
 | 
				
			|||||||
        case FuriHalVersionOtpVersion1:
 | 
					        case FuriHalVersionOtpVersion1:
 | 
				
			||||||
            furi_hal_version_load_otp_v1();
 | 
					            furi_hal_version_load_otp_v1();
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
        default: furi_check(0);
 | 
					        default: furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    FURI_LOG_I("FuriHalVersion", "Init OK");
 | 
					    FURI_LOG_I("FuriHalVersion", "Init OK");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,6 @@
 | 
				
			|||||||
#include <furi-hal.h>
 | 
					#include <furi-hal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <aes.h>
 | 
					 | 
				
			||||||
#include <comp.h>
 | 
					#include <comp.h>
 | 
				
			||||||
#include <pka.h>
 | 
					 | 
				
			||||||
#include <rf.h>
 | 
					 | 
				
			||||||
#include <rng.h>
 | 
					 | 
				
			||||||
#include <rtc.h>
 | 
					#include <rtc.h>
 | 
				
			||||||
#include <tim.h>
 | 
					#include <tim.h>
 | 
				
			||||||
#include <usb_device.h>
 | 
					#include <usb_device.h>
 | 
				
			||||||
@ -34,16 +30,8 @@ void furi_hal_init() {
 | 
				
			|||||||
    FURI_LOG_I("HAL", "TIM16 OK");
 | 
					    FURI_LOG_I("HAL", "TIM16 OK");
 | 
				
			||||||
    MX_COMP1_Init();
 | 
					    MX_COMP1_Init();
 | 
				
			||||||
    FURI_LOG_I("HAL", "COMP1 OK");
 | 
					    FURI_LOG_I("HAL", "COMP1 OK");
 | 
				
			||||||
    MX_RF_Init();
 | 
					
 | 
				
			||||||
    FURI_LOG_I("HAL", "RF OK");
 | 
					    furi_hal_crypto_init();
 | 
				
			||||||
    MX_PKA_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "PKA OK");
 | 
					 | 
				
			||||||
    MX_RNG_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "RNG OK");
 | 
					 | 
				
			||||||
    MX_AES1_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "AES1 OK");
 | 
					 | 
				
			||||||
    MX_AES2_Init();
 | 
					 | 
				
			||||||
    FURI_LOG_I("HAL", "AES2 OK");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // VCP + USB
 | 
					    // VCP + USB
 | 
				
			||||||
    furi_hal_vcp_init();
 | 
					    furi_hal_vcp_init();
 | 
				
			||||||
 | 
				
			|||||||
@ -53,12 +53,9 @@ C_SOURCES += \
 | 
				
			|||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc_ex.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rng.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \
 | 
				
			||||||
	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
 | 
						$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
 | 
				
			||||||
@ -81,7 +78,6 @@ CFLAGS += \
 | 
				
			|||||||
	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
 | 
						-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
 | 
				
			||||||
	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
 | 
						-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
 | 
				
			||||||
C_SOURCES += \
 | 
					C_SOURCES += \
 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
 | 
					 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
 | 
						$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
 | 
						$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
 | 
				
			||||||
	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/queue.c \
 | 
						$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/queue.c \
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,13 @@ extern "C" {
 | 
				
			|||||||
void furi_hal_bt_init();
 | 
					void furi_hal_bt_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Start BLE app */
 | 
					/** Start BLE app */
 | 
				
			||||||
bool furi_hal_bt_start_app();
 | 
					bool furi_hal_bt_init_app();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Start advertising */
 | 
				
			||||||
 | 
					void furi_hal_bt_start_advertising();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Stop advertising */
 | 
				
			||||||
 | 
					void furi_hal_bt_stop_advertising();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Get BT/BLE system component state */
 | 
					/** Get BT/BLE system component state */
 | 
				
			||||||
void furi_hal_bt_dump_state(string_t buffer);
 | 
					void furi_hal_bt_dump_state(string_t buffer);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										66
									
								
								firmware/targets/furi-hal-include/furi-hal-crypto.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								firmware/targets/furi-hal-include/furi-hal-crypto.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,66 @@
 | 
				
			|||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					#include <stddef.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** FuriHalCryptoKey Type */
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					    FuriHalCryptoKeyTypeMaster, /**< Master key */
 | 
				
			||||||
 | 
					    FuriHalCryptoKeyTypeSimple,  /**< Simple enencrypted key */
 | 
				
			||||||
 | 
					    FuriHalCryptoKeyTypeEncrypted, /**< Encrypted with Master key */
 | 
				
			||||||
 | 
					} FuriHalCryptoKeyType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** FuriHalCryptoKey Size in bits */
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					    FuriHalCryptoKeySize128,
 | 
				
			||||||
 | 
					    FuriHalCryptoKeySize256,
 | 
				
			||||||
 | 
					} FuriHalCryptoKeySize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** FuriHalCryptoKey */
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
					    FuriHalCryptoKeyType type;
 | 
				
			||||||
 | 
					    FuriHalCryptoKeySize size;
 | 
				
			||||||
 | 
					    uint8_t* data;
 | 
				
			||||||
 | 
					} FuriHalCryptoKey;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Initialize cryptography layer
 | 
				
			||||||
 | 
					 * This includes AES engines, PKA and RNG
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void furi_hal_crypto_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Store key in crypto storage
 | 
				
			||||||
 | 
					 * @param key - FuriHalCryptoKey to store. Only Master, Simple or Encrypted
 | 
				
			||||||
 | 
					 * @param slot - pinter to int where store slot number will be saved
 | 
				
			||||||
 | 
					 * @return true on success
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Init AES engine and load key from crypto store
 | 
				
			||||||
 | 
					 * @param slot - store slot number
 | 
				
			||||||
 | 
					 * @return true on success
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Unload key engine and deinit AES engine
 | 
				
			||||||
 | 
					 * @param slot - store slot number
 | 
				
			||||||
 | 
					 * @return true on success
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					bool furi_hal_crypto_store_unload_key(uint8_t slot);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Encrypt data
 | 
				
			||||||
 | 
					 * @param input - pointer to input data
 | 
				
			||||||
 | 
					 * @param output - pointer to output data
 | 
				
			||||||
 | 
					 * @param size - input/output buffer size in bytes
 | 
				
			||||||
 | 
					 * @return true on success
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Decrypt data
 | 
				
			||||||
 | 
					 * @param input - pointer to input data
 | 
				
			||||||
 | 
					 * @param output - pointer to output data
 | 
				
			||||||
 | 
					 * @param size - input/output buffer size in bytes
 | 
				
			||||||
 | 
					 * @return true on success
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size);
 | 
				
			||||||
@ -6,6 +6,7 @@ template <unsigned int N> struct STOP_EXTERNING_ME {};
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "furi-hal-boot.h"
 | 
					#include "furi-hal-boot.h"
 | 
				
			||||||
#include "furi-hal-clock.h"
 | 
					#include "furi-hal-clock.h"
 | 
				
			||||||
 | 
					#include "furi-hal-crypto.h"
 | 
				
			||||||
#include "furi-hal-console.h"
 | 
					#include "furi-hal-console.h"
 | 
				
			||||||
#include "furi-hal-os.h"
 | 
					#include "furi-hal-os.h"
 | 
				
			||||||
#include "furi-hal-i2c.h"
 | 
					#include "furi-hal-i2c.h"
 | 
				
			||||||
 | 
				
			|||||||
@ -36,7 +36,7 @@ template <class TState, class TEvent> AppTemplate<TState, TEvent>::AppTemplate()
 | 
				
			|||||||
    // TODO: use plain os mutex?
 | 
					    // TODO: use plain os mutex?
 | 
				
			||||||
    if(!init_mutex(&state_mutex, &state, sizeof(TState))) {
 | 
					    if(!init_mutex(&state_mutex, &state, sizeof(TState))) {
 | 
				
			||||||
        printf("cannot create mutex\n");
 | 
					        printf("cannot create mutex\n");
 | 
				
			||||||
        furi_check(0);
 | 
					        furi_crash(NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // open gui
 | 
					    // open gui
 | 
				
			||||||
 | 
				
			|||||||
Some files were not shown because too many files have changed in this diff Show More
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user