fpi-usb.h 2.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (C) 2018 Bastien Nocera <hadess@hadess.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef __FPI_USB_H__
#define __FPI_USB_H__

#include <libusb.h>
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "fpi-dev.h"
#include "fpi-ssm.h"

/**
 * fpi_usb_transfer:
 *
 * A structure containing the arguments passed to fpi_usb_fill_bulk_transfer()
 * to be used with fpi_usb_submit_transfer().
 */
typedef struct fpi_usb_transfer fpi_usb_transfer;

/**
 * fpi_usb_transfer_cb_fn:
 * @transfer: a struct #libusb_transfer
 * @dev: the struct #fp_dev on which the operation was performed
 * @ssm: the #fpi_ssm state machine
 * @user_data: the user data passed to fpi_usb_fill_bulk_transfer()
 *
 * This callback will be called in response to a libusb bulk transfer
 * triggered via fpi_usb_fill_bulk_transfer() finishing. Note that the
 * struct #libusb_transfer does not need to be freed, as it will be
 * freed after the callback returns, similarly to
 * the [LIBUSB_TRANSFER_FREE_TRANSFER flag](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#gga1fb47dd0f7c209b60a3609ff0c03d56dacf3f064997b283a14097c9f4d6f8ccc1).
 *
 * Note that the cancelled status of the transfer should be checked
 * first thing, as the @dev, @ssm and @user_data pointers might not
 * be pointing to valid values anymore. See fpi_usb_cancel_transfer()
 * for more information.
 */
typedef void(*fpi_usb_transfer_cb_fn) (struct libusb_transfer *transfer,
				       struct fp_dev          *dev,
				       fpi_ssm                *ssm,
				       void                   *user_data);
56 57 58

struct libusb_transfer *fpi_usb_alloc(void) __attribute__((returns_nonnull));

59 60 61 62 63 64 65 66 67 68 69
fpi_usb_transfer *fpi_usb_fill_bulk_transfer (struct fp_dev          *dev,
					      fpi_ssm                *ssm,
					      unsigned char           endpoint,
					      unsigned char          *buffer,
					      int                     length,
					      fpi_usb_transfer_cb_fn  callback,
					      void                   *user_data,
					      unsigned int            timeout);
int fpi_usb_submit_transfer (fpi_usb_transfer *transfer);
int fpi_usb_cancel_transfer (fpi_usb_transfer *transfer);

70
#endif