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

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

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

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

    tc->ftdi = ftdi;
    tc->completed = 0;
    tc->buf = buf;
    tc->size = size;
    tc->offset = 0;

    if (size < (int)ftdi->writebuffer_chunksize)
        write_size = size;
    else
        write_size = ftdi->writebuffer_chunksize;

    libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->in_ep, buf,
                              write_size, ftdi_write_data_cb, tc,
                              ftdi->usb_write_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;
}
/**
    Writes data to 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
*/
Writes data to 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
Writes data to 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_write_data_submit(struct ftdi_context *ftdi, unsigned char *buf, int size)
{
    struct ftdi_transfer_control *tc;
    struct libusb_transfer *transfer;
    int write_size, ret;
    if (ftdi == NULL || ftdi->usb_dev == NULL)
        return NULL;
    tc = (struct ftdi_transfer_control *) malloc (sizeof (*tc));
    if (!tc)
        return NULL;
    transfer = libusb_alloc_transfer(0);
    if (!transfer)
    {
        free(tc);
        return NULL;
    }
    tc->ftdi = ftdi;
    tc->completed = 0;
    tc->buf = buf;
    tc->size = size;
    tc->offset = 0;
    if (size < (int)ftdi->writebuffer_chunksize)
        write_size = size;
    else
        write_size = ftdi->writebuffer_chunksize;
    libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->in_ep, buf,
                              write_size, ftdi_write_data_cb, tc,
                              ftdi->usb_write_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_write_data_submit ( struct ftdi_context * ftdi , unsigned char * buf , int size ) { struct ftdi_transfer_control * tc ; struct libusb_transfer * transfer ; int write_size , ret ; if ( ftdi == NULL || ftdi -> usb_dev == NULL ) return NULL ; tc = ( struct ftdi_transfer_control * ) malloc ( sizeof ( * tc ) ) ; if ( ! tc ) return NULL ; transfer = libusb_alloc_transfer ( 0 ) ; if ( ! transfer ) { free ( tc ) ; return NULL ; } tc -> ftdi = ftdi ; tc -> completed = 0 ; tc -> buf = buf ; tc -> size = size ; tc -> offset = 0 ; if ( size < ( int ) ftdi -> writebuffer_chunksize ) write_size = size ; else write_size = ftdi -> writebuffer_chunksize ; libusb_fill_bulk_transfer ( transfer , ftdi -> usb_dev , ftdi -> in_ep , buf , write_size , ftdi_write_data_cb , tc , ftdi -> usb_write_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 ; }
Writes data to the chip.
Writes data to the chip .