From cef378aaa2ce0a2e480d0fed4d86aaa80b4ad5af Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sat, 1 Mar 2008 09:36:22 +0000 Subject: [PATCH] libftdi: (tomj) applied vala bindings, always document async mode --- ChangeLog | 1 + doc/Doxyfile.in | 2 +- src/ftdi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/ftdi.h | 3 +++ 4 files changed, 48 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b92cc8..b01901d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ New in 0.11 ----------- +* Vala bindings helper functions (ftdi_new, ftdi_free, ftdi_list_free2) (Even Nermerson) * Support for different EEPROM sizes (Andrew John Rogers, andrew@rogerstech.co.uk) * Async write support. Linux only and no error handling. You have to enable it via --with-async-code. diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index f21766e..f455bca 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -1012,7 +1012,7 @@ INCLUDE_FILE_PATTERNS = # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = +PREDEFINED = LIBFTDI_LINUX_ASYNC_MODE # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. diff --git a/src/ftdi.c b/src/ftdi.c index 16d86d1..9a80d7f 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -105,6 +105,27 @@ int ftdi_init(struct ftdi_context *ftdi) } /** + Allocate and initialize a new ftdi_context + + \return a pointer to a new ftdi_context, or NULL on failure +*/ +struct ftdi_context *ftdi_new() +{ + struct ftdi_context * ftdi = (struct ftdi_context *)malloc(sizeof(struct ftdi_context)); + + if (ftdi == NULL) { + return NULL; + } + + if (ftdi_init(ftdi) != 0) { + free(ftdi); + return NULL; + } + + return ftdi; +} + +/** Open selected channels on a chip, otherwise use first channel. \param ftdi pointer to ftdi_context @@ -151,6 +172,17 @@ void ftdi_deinit(struct ftdi_context *ftdi) } /** + Deinitialize and free an ftdi_context. + + \param ftdi pointer to ftdi_context +*/ +void ftdi_free(struct ftdi_context *ftdi) +{ + ftdi_deinit(ftdi); + free(ftdi); +} + +/** Use an already open libusb device. \param ftdi pointer to ftdi_context @@ -231,6 +263,16 @@ void ftdi_list_free(struct ftdi_device_list **devlist) } /** + Frees a usb device list. + + \param devlist USB device list created by ftdi_usb_find_all() +*/ +void ftdi_list_free2(struct ftdi_device_list *devlist) +{ + ftdi_list_free(&devlist); +} + +/** Return device ID strings from the usb device. The parameters manufacturer, description and serial may be NULL @@ -903,6 +945,7 @@ static int _usb_bulk_write_async(struct ftdi_context *ftdi, int ep, char *bytes, caller of completion or error - but this is not done yet, volunteers welcome. Works around libusb and directly accesses functions only available on Linux. + Only available if compiled with --with-async-mode. \param ftdi pointer to ftdi_context \param buf Buffer with the data diff --git a/src/ftdi.h b/src/ftdi.h index 7d5c212..e72cad2 100644 --- a/src/ftdi.h +++ b/src/ftdi.h @@ -235,14 +235,17 @@ extern "C" { #endif int ftdi_init(struct ftdi_context *ftdi); + struct ftdi_context *ftdi_new(); int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface); void ftdi_deinit(struct ftdi_context *ftdi); + void ftdi_free(struct ftdi_context *ftdi); void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usbdev); int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist, int vendor, int product); void ftdi_list_free(struct ftdi_device_list **devlist); + void ftdi_list_free2(struct ftdi_device_list *devlist); int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct usb_device *dev, char * manufacturer, int mnf_len, char * description, int desc_len, -- 1.7.1