src/app/host-serial/libftdi/ftdi.c
struct ftdi_transfer_control *ftdi_read_data_submit(struct ftdi_context *ftdi, unsigned char *buf, int size)
{
    struct ftdi_transfer_control *tc;
    struct libusb_transfer *transfer;
    int ret;

    if (ftdi == NULL || ftdi->usb_dev == NULL)
        return NULL;

    tc = (struct ftdi_transfer_control *) malloc (sizeof (*tc));
    if (!tc)
        return NULL;

    tc->ftdi = ftdi;
    tc->buf = buf;
    tc->size = size;

    if (size <= (int)ftdi->readbuffer_remaining)
    {
        memcpy (buf, ftdi->readbuffer+ftdi->readbuffer_offset, size);

        // Fix offsets
        ftdi->readbuffer_remaining -= size;
        ftdi->readbuffer_offset += size;

        /* printf("Returning bytes from buffer: %d - remaining: %d\n", size, ftdi->readbuffer_remaining); */

        tc->completed = 1;
        tc->offset = size;
        tc->transfer = NULL;
        return tc;
    }

    tc->completed = 0;
    if (ftdi->readbuffer_remaining != 0)
    {
        memcpy (buf, ftdi->readbuffer+ftdi->readbuffer_offset, ftdi->readbuffer_remaining);

        tc->offset = ftdi->readbuffer_remaining;
    }
    else
        tc->offset = 0;

    transfer = libusb_alloc_transfer(0);
    if (!transfer)
    {
        free (tc);
        return NULL;
    }

    ftdi->readbuffer_remaining = 0;
    ftdi->readbuffer_offset = 0;

    libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->out_ep, ftdi->readbuffer, ftdi->readbuffer_chunksize, ftdi_read_data_cb, tc, ftdi->usb_read_timeout);
    transfer->type = LIBUSB_TRANSFER_TYPE_BULK;

    ret = libusb_submit_transfer(transfer);
    if (ret < 0)
    {
        libusb_free_transfer(transfer);
        free (tc);
        return NULL;
    }
    tc->transfer = transfer;

    return tc;
}
/**
    Reads data from the chip. Does not wait for completion of the transfer
    nor does it make sure that the transfer was successful.

    Use libusb 1.0 asynchronous API.

    \param ftdi pointer to ftdi_context
    \param buf Buffer with the data
    \param size Size of the buffer

    \retval NULL: Some error happens when submit transfer
    \retval !NULL: Pointer to a ftdi_transfer_control
*/
Reads data from the chip. Does not wait for completion of the transfer
nor does it make sure that the transfer was successful.

Use libusb 1.0 asynchronous API.

\param ftdi pointer to ftdi_context
\param buf Buffer with the data
\param size Size of the buffer

\retval NULL: Some error happens when submit transfer
\retval !NULL: Pointer to a ftdi_transfer_control
Reads data from the chip . Does not wait for completion of the transfer nor does it make sure that the transfer was successful . Use libusb 1 . 0 asynchronous API . \ param ftdi pointer to ftdi_context \ param buf Buffer with the data \ param size Size of the buffer \ retval NULL : Some error happens when submit transfer \ retval !NULL : Pointer to a ftdi_transfer_control
struct ftdi_transfer_control *ftdi_read_data_submit(struct ftdi_context *ftdi, unsigned char *buf, int size)
{
    struct ftdi_transfer_control *tc;
    struct libusb_transfer *transfer;
    int ret;
    if (ftdi == NULL || ftdi->usb_dev == NULL)
        return NULL;
    tc = (struct ftdi_transfer_control *) malloc (sizeof (*tc));
    if (!tc)
        return NULL;
    tc->ftdi = ftdi;
    tc->buf = buf;
    tc->size = size;
    if (size <= (int)ftdi->readbuffer_remaining)
    {
        memcpy (buf, ftdi->readbuffer+ftdi->readbuffer_offset, size);
        ftdi->readbuffer_remaining -= size;
        ftdi->readbuffer_offset += size;
        tc->completed = 1;
        tc->offset = size;
        tc->transfer = NULL;
        return tc;
    }
    tc->completed = 0;
    if (ftdi->readbuffer_remaining != 0)
    {
        memcpy (buf, ftdi->readbuffer+ftdi->readbuffer_offset, ftdi->readbuffer_remaining);
        tc->offset = ftdi->readbuffer_remaining;
    }
    else
        tc->offset = 0;
    transfer = libusb_alloc_transfer(0);
    if (!transfer)
    {
        free (tc);
        return NULL;
    }
    ftdi->readbuffer_remaining = 0;
    ftdi->readbuffer_offset = 0;
    libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->out_ep, ftdi->readbuffer, ftdi->readbuffer_chunksize, ftdi_read_data_cb, tc, ftdi->usb_read_timeout);
    transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
    ret = libusb_submit_transfer(transfer);
    if (ret < 0)
    {
        libusb_free_transfer(transfer);
        free (tc);
        return NULL;
    }
    tc->transfer = transfer;
    return tc;
}
struct ftdi_transfer_control * ftdi_read_data_submit ( struct ftdi_context * ftdi , unsigned char * buf , int size ) { struct ftdi_transfer_control * tc ; struct libusb_transfer * transfer ; int ret ; if ( ftdi == NULL || ftdi -> usb_dev == NULL ) return NULL ; tc = ( struct ftdi_transfer_control * ) malloc ( sizeof ( * tc ) ) ; if ( ! tc ) return NULL ; tc -> ftdi = ftdi ; tc -> buf = buf ; tc -> size = size ; if ( size <= ( int ) ftdi -> readbuffer_remaining ) { memcpy ( buf , ftdi -> readbuffer + ftdi -> readbuffer_offset , size ) ; ftdi -> readbuffer_remaining -= size ; ftdi -> readbuffer_offset += size ; tc -> completed = 1 ; tc -> offset = size ; tc -> transfer = NULL ; return tc ; } tc -> completed = 0 ; if ( ftdi -> readbuffer_remaining != 0 ) { memcpy ( buf , ftdi -> readbuffer + ftdi -> readbuffer_offset , ftdi -> readbuffer_remaining ) ; tc -> offset = ftdi -> readbuffer_remaining ; } else tc -> offset = 0 ; transfer = libusb_alloc_transfer ( 0 ) ; if ( ! transfer ) { free ( tc ) ; return NULL ; } ftdi -> readbuffer_remaining = 0 ; ftdi -> readbuffer_offset = 0 ; libusb_fill_bulk_transfer ( transfer , ftdi -> usb_dev , ftdi -> out_ep , ftdi -> readbuffer , ftdi -> readbuffer_chunksize , ftdi_read_data_cb , tc , ftdi -> usb_read_timeout ) ; transfer -> type = LIBUSB_TRANSFER_TYPE_BULK ; ret = libusb_submit_transfer ( transfer ) ; if ( ret < 0 ) { libusb_free_transfer ( transfer ) ; free ( tc ) ; return NULL ; } tc -> transfer = transfer ; return tc ; }
Reads data from the chip.
Reads data from the chip .
// Fix offsets /* printf("Returning bytes from buffer: %d - remaining: %d\n", size, ftdi->readbuffer_remaining); */