Parcourir la source

upd avr isp

testing with usbunlock by willy-jl
MX il y a 8 mois
Parent
commit
252e1cda45
4 fichiers modifiés avec 37 ajouts et 27 suppressions
  1. 1 1
      application.fam
  2. 21 1
      avr_isp_app.c
  3. 15 25
      helpers/avr_isp_worker.c
  4. BIN
      images/ActiveConnection_50x64.png

+ 1 - 1
application.fam

@@ -6,7 +6,7 @@ App(
     requires=["gui"],
     stack_size=4 * 1024,
     fap_description="Application for flashing AVR microcontrollers",
-    fap_version="1.4",
+    fap_version="1.5",
     fap_icon="avr_app_icon_10px.png",
     fap_category="GPIO",
     fap_icon_assets="images",

+ 21 - 1
avr_isp_app.c

@@ -31,7 +31,6 @@ AvrIspApp* avr_isp_app_alloc() {
     // View Dispatcher
     app->view_dispatcher = view_dispatcher_alloc();
     app->scene_manager = scene_manager_alloc(&avr_isp_scene_handlers, app);
-    
 
     view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
     view_dispatcher_set_custom_event_callback(
@@ -169,6 +168,27 @@ void avr_isp_app_free(AvrIspApp* app) {
 
 int32_t avr_isp_app(void* p) {
     UNUSED(p);
+
+    furi_hal_usb_unlock();
+
+    if(furi_hal_usb_is_locked()) {
+        DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
+        DialogMessage* message = dialog_message_alloc();
+        dialog_message_set_header(message, "Connection\nis active!", 3, 2, AlignLeft, AlignTop);
+        dialog_message_set_text(
+            message,
+            "Disconnect\ncompanion app to\nuse this function.",
+            3,
+            30,
+            AlignLeft,
+            AlignTop);
+        dialog_message_set_icon(message, &I_ActiveConnection_50x64, 78, 0);
+        dialog_message_show(dialogs, message);
+        dialog_message_free(message);
+        furi_record_close(RECORD_DIALOGS);
+        return -1;
+    }
+
     AvrIspApp* avr_isp_app = avr_isp_app_alloc();
 
     view_dispatcher_run(avr_isp_app->view_dispatcher);

+ 15 - 25
helpers/avr_isp_worker.c

@@ -1,10 +1,11 @@
 #include "avr_isp_worker.h"
-#include <furi_hal_pwm.h>
 #include "../lib/driver/avr_isp_prog.h"
 #include "../lib/driver/avr_isp_prog_cmd.h"
 #include "../lib/driver/avr_isp_chip_arr.h"
 
 #include <furi.h>
+#include <furi_hal_pwm.h>
+#include <cli/cli_vcp.h>
 
 #define TAG "AvrIspWorker"
 
@@ -26,6 +27,7 @@ struct AvrIspWorker {
     uint8_t connect_usb;
     AvrIspWorkerCallback callback;
     void* context;
+    CliVcp* cli_vcp;
 };
 
 #define AVR_ISP_WORKER_PROG_ALL_EVENTS (AvrIspWorkerEvtStop)
@@ -35,9 +37,6 @@ struct AvrIspWorker {
 
 //########################/* VCP CDC */#############################################
 #include "usb_cdc.h"
-#include <cli/cli_vcp.h>
-#include <toolbox/cli/cli_command.h>
-#include <cli/cli_main_commands.h>
 #include <furi_hal_usb_cdc.h>
 
 #define AVR_ISP_VCP_CDC_CH           1
@@ -90,34 +89,25 @@ static void vcp_on_line_config(void* context, struct usb_cdc_line_coding* config
     UNUSED(config);
 }
 
-static void avr_isp_worker_vcp_cdc_init(void* context) {
-    furi_hal_usb_unlock();
-    CliVcp* cli_vcp = furi_record_open(RECORD_CLI_VCP);
-    //close cli
-    cli_vcp_disable(cli_vcp);
-    //disable callbacks VCP_CDC=0
-    furi_hal_cdc_set_callbacks(0, NULL, NULL);
-    //set 2 cdc
+static void avr_isp_worker_vcp_cdc_init(AvrIspWorker* worker) {
+    worker->cli_vcp = furi_record_open(RECORD_CLI_VCP);
+
+    cli_vcp_disable(worker->cli_vcp);
     furi_check(furi_hal_usb_set_config(&usb_cdc_dual, NULL) == true);
-    //open cli VCP_CDC=0
-    cli_vcp_enable(cli_vcp);
-    furi_record_close(RECORD_CLI_VCP);
+    furi_hal_usb_lock();
+    cli_vcp_enable(worker->cli_vcp);
 
-    furi_hal_cdc_set_callbacks(AVR_ISP_VCP_CDC_CH, (CdcCallbacks*)&cdc_cb, context);
+    furi_hal_cdc_set_callbacks(AVR_ISP_VCP_CDC_CH, (CdcCallbacks*)&cdc_cb, worker);
 }
 
-static void avr_isp_worker_vcp_cdc_deinit(void) {
-    //disable callbacks AVR_ISP_VCP_CDC_CH
+static void avr_isp_worker_vcp_cdc_deinit(AvrIspWorker* worker) {
     furi_hal_cdc_set_callbacks(AVR_ISP_VCP_CDC_CH, NULL, NULL);
 
-    CliVcp* cli_vcp = furi_record_open(RECORD_CLI_VCP);
-    //close cli
-    cli_vcp_disable(cli_vcp);
+    cli_vcp_disable(worker->cli_vcp);
     furi_hal_usb_unlock();
-    //set 1 cdc
     furi_check(furi_hal_usb_set_config(&usb_cdc_single, NULL) == true);
-    //open cli VCP_CDC=0
-    cli_vcp_enable(cli_vcp);
+    cli_vcp_enable(worker->cli_vcp);
+
     furi_record_close(RECORD_CLI_VCP);
 }
 
@@ -210,7 +200,7 @@ static int32_t avr_isp_worker_thread(void* context) {
 
     avr_isp_prog_free(prog);
     furi_hal_pwm_stop(FuriHalPwmOutputIdLptim2PA4);
-    avr_isp_worker_vcp_cdc_deinit();
+    avr_isp_worker_vcp_cdc_deinit(instance);
     return 0;
 }
 

BIN
images/ActiveConnection_50x64.png