Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Sunxi Tools
Commits
36978e3e
Commit
36978e3e
authored
Nov 19, 2016
by
Bernhard Nortmann
Browse files
fel_lib: Arrange for auto-initialization on first open_fel_device()
Signed-off-by:
Bernhard Nortmann
<
bernhard.nortmann@web.de
>
parent
aaa677d5
Changes
2
Show whitespace changes
Inline
Side-by-side
fel.c
View file @
36978e3e
...
@@ -1194,7 +1194,6 @@ int main(int argc, char **argv)
...
@@ -1194,7 +1194,6 @@ int main(int argc, char **argv)
argv
+=
1
;
argv
+=
1
;
}
}
feldev_init
();
handle
=
feldev_open
(
busnum
,
devnum
,
AW_USB_VENDOR_ID
,
AW_USB_PRODUCT_ID
);
handle
=
feldev_open
(
busnum
,
devnum
,
AW_USB_VENDOR_ID
,
AW_USB_PRODUCT_ID
);
while
(
argc
>
1
)
{
while
(
argc
>
1
)
{
...
...
fel_lib.c
View file @
36978e3e
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#define USB_TIMEOUT 10000
/* 10 seconds */
#define USB_TIMEOUT 10000
/* 10 seconds */
static
bool
fel_lib_initialized
=
false
;
/* This is out 'private' data type that will be part of a "FEL device" handle */
/* This is out 'private' data type that will be part of a "FEL device" handle */
struct
_felusb_handle
{
struct
_felusb_handle
{
...
@@ -315,6 +316,8 @@ void feldev_release(feldev_handle *dev)
...
@@ -315,6 +316,8 @@ void feldev_release(feldev_handle *dev)
feldev_handle
*
feldev_open
(
int
busnum
,
int
devnum
,
feldev_handle
*
feldev_open
(
int
busnum
,
int
devnum
,
uint16_t
vendor_id
,
uint16_t
product_id
)
uint16_t
vendor_id
,
uint16_t
product_id
)
{
{
if
(
!
fel_lib_initialized
)
/* if not already done: auto-initialize */
feldev_init
();
feldev_handle
*
result
=
calloc
(
1
,
sizeof
(
feldev_handle
));
feldev_handle
*
result
=
calloc
(
1
,
sizeof
(
feldev_handle
));
if
(
!
result
)
{
if
(
!
result
)
{
fprintf
(
stderr
,
"FAILED to allocate feldev_handle memory.
\n
"
);
fprintf
(
stderr
,
"FAILED to allocate feldev_handle memory.
\n
"
);
...
@@ -404,11 +407,12 @@ void feldev_init(void)
...
@@ -404,11 +407,12 @@ void feldev_init(void)
int
rc
=
libusb_init
(
NULL
);
int
rc
=
libusb_init
(
NULL
);
if
(
rc
!=
0
)
if
(
rc
!=
0
)
usb_error
(
rc
,
"libusb_init()"
,
1
);
usb_error
(
rc
,
"libusb_init()"
,
1
);
fel_lib_initialized
=
true
;
}
}
void
feldev_done
(
feldev_handle
*
dev
)
void
feldev_done
(
feldev_handle
*
dev
)
{
{
feldev_close
(
dev
);
feldev_close
(
dev
);
free
(
dev
);
free
(
dev
);
libusb_exit
(
NULL
);
if
(
fel_lib_initialized
)
libusb_exit
(
NULL
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment