File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -25,3 +25,17 @@ void *dfu_malloc(size_t size) { return malloc(size); }
25
25
// This is the global DFU tree instance used in dfu_util.
26
26
struct dfu_if * dfu_root = NULL ;
27
27
28
+ libusb_context * ctx ;
29
+
30
+ const char * libusbOpen () {
31
+ int err = libusb_init (& ctx );
32
+ if (err != 0 ) {
33
+ return libusb_strerror (err );
34
+ }
35
+ return NULL ;
36
+ }
37
+
38
+ void libusbClose () {
39
+ libusb_exit (ctx );
40
+ ctx = NULL ;
41
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ package main
7
7
8
8
#include <dfu.h>
9
9
#include <dfu_util.h>
10
+
11
+ // Defined in main.c
12
+ const char *libusbOpen();
13
+ void libusbClose();
10
14
*/
11
15
import "C"
12
16
@@ -41,10 +45,14 @@ func (d *DFUDiscovery) Quit() {
41
45
42
46
// Stop is the handler for the pluggable-discovery STOP command
43
47
func (d * DFUDiscovery ) Stop () error {
48
+ C .libusbClose ()
44
49
return nil
45
50
}
46
51
47
52
// StartSync is the handler for the pluggable-discovery START_SYNC command
48
53
func (d * DFUDiscovery ) StartSync (eventCB discovery.EventCallback , errorCB discovery.ErrorCallback ) error {
54
+ if cErr := C .libusbOpen (); cErr != nil {
55
+ return fmt .Errorf ("can't open libusb: %s" , C .GoString (cErr ))
56
+ }
49
57
return nil
50
58
}
You can’t perform that action at this time.
0 commit comments