src/app/host-serial/libftdi/ftdi.c
int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer,
                             char * product, char * serial)
{
    struct ftdi_eeprom *eeprom;

    if (ftdi == NULL)
        ftdi_error_return(-1, "No struct ftdi_context");

    if (ftdi->eeprom == NULL)
        ftdi_error_return(-2,"No struct ftdi_eeprom");

    eeprom = ftdi->eeprom;
    memset(eeprom, 0, sizeof(struct ftdi_eeprom));

    if (ftdi->usb_dev == NULL)
        ftdi_error_return(-3, "No connected device or device not yet opened");

    eeprom->vendor_id = 0x0403;
    eeprom->use_serial = 1;
    if ((ftdi->type == TYPE_AM) || (ftdi->type == TYPE_BM) ||
            (ftdi->type == TYPE_R))
        eeprom->product_id = 0x6001;
    else if (ftdi->type == TYPE_4232H)
        eeprom->product_id = 0x6011;
    else if (ftdi->type == TYPE_232H)
        eeprom->product_id = 0x6014;
    else if (ftdi->type == TYPE_230X)
        eeprom->product_id = 0x6015;
    else
        eeprom->product_id = 0x6010;

    if (ftdi->type == TYPE_AM)
        eeprom->usb_version = 0x0101;
    else
        eeprom->usb_version = 0x0200;
    eeprom->max_power = 100;

    if (eeprom->manufacturer)
        free (eeprom->manufacturer);
    eeprom->manufacturer = NULL;
    if (manufacturer)
    {
        eeprom->manufacturer = malloc(strlen(manufacturer)+1);
        if (eeprom->manufacturer)
            strcpy(eeprom->manufacturer, manufacturer);
    }

    if (eeprom->product)
        free (eeprom->product);
    eeprom->product = NULL;
    if(product)
    {
        eeprom->product = malloc(strlen(product)+1);
        if (eeprom->product)
            strcpy(eeprom->product, product);
    }
    else
    {
        const char* default_product;
        switch(ftdi->type)
        {
            case TYPE_AM:    default_product = "AM"; break;
            case TYPE_BM:    default_product = "BM"; break;
            case TYPE_2232C: default_product = "Dual RS232"; break;
            case TYPE_R:     default_product = "FT232R USB UART"; break;
            case TYPE_2232H: default_product = "Dual RS232-HS"; break;
            case TYPE_4232H: default_product = "FT4232H"; break;
            case TYPE_232H:  default_product = "Single-RS232-HS"; break;
            case TYPE_230X:  default_product = "FT230X Basic UART"; break;
            default:
                ftdi_error_return(-3, "Unknown chip type");
        }
        eeprom->product = malloc(strlen(default_product) +1);
        if (eeprom->product)
            strcpy(eeprom->product, default_product);
    }

    if (eeprom->serial)
        free (eeprom->serial);
    eeprom->serial = NULL;
    if (serial)
    {
        eeprom->serial = malloc(strlen(serial)+1);
        if (eeprom->serial)
            strcpy(eeprom->serial, serial);
    }

    if (ftdi->type == TYPE_R)
    {
        eeprom->max_power = 90;
        eeprom->size = 0x80;
        eeprom->cbus_function[0] = CBUS_TXLED;
        eeprom->cbus_function[1] = CBUS_RXLED;
        eeprom->cbus_function[2] = CBUS_TXDEN;
        eeprom->cbus_function[3] = CBUS_PWREN;
        eeprom->cbus_function[4] = CBUS_SLEEP;
    }
    else if (ftdi->type == TYPE_230X)
    {
        eeprom->max_power = 90;
        eeprom->size = 0x100;
        eeprom->cbus_function[0] = CBUSH_TXDEN;
        eeprom->cbus_function[1] = CBUSH_RXLED;
        eeprom->cbus_function[2] = CBUSH_TXLED;
        eeprom->cbus_function[3] = CBUSH_SLEEP;
    }
    else
    {
        if(ftdi->type == TYPE_232H)
        {
            int i;
            for (i=0; i<10; i++)
                eeprom->cbus_function[i] = CBUSH_TRISTATE;
        }
        eeprom->size = -1;
    }
    switch (ftdi->type)
    {
        case TYPE_AM:
            eeprom->release_number = 0x0200;
            break;
        case TYPE_BM:
            eeprom->release_number = 0x0400;
            break;
        case TYPE_2232C:
            eeprom->release_number = 0x0500;
            break;
        case TYPE_R:
            eeprom->release_number = 0x0600;
            break;
        case TYPE_2232H:
            eeprom->release_number = 0x0700;
            break;
        case TYPE_4232H:
            eeprom->release_number = 0x0800;
            break;
        case TYPE_232H:
            eeprom->release_number = 0x0900;
            break;
        case TYPE_230X:
            eeprom->release_number = 0x1000;
            break;
        default:
            eeprom->release_number = 0x00;
    }
    return 0;
}
/**
    Init eeprom with default values for the connected device
    \param ftdi pointer to ftdi_context
    \param manufacturer String to use as Manufacturer
    \param product String to use as Product description
    \param serial String to use as Serial number description

    \retval  0: all fine
    \retval -1: No struct ftdi_context
    \retval -2: No struct ftdi_eeprom
    \retval -3: No connected device or device not yet opened
*/
Init eeprom with default values for the connected device
\param ftdi pointer to ftdi_context
\param manufacturer String to use as Manufacturer
\param product String to use as Product description
\param serial String to use as Serial number description

\retval  0: all fine
\retval -1: No struct ftdi_context
\retval -2: No struct ftdi_eeprom
\retval -3: No connected device or device not yet opened
Init eeprom with default values for the connected device \ param ftdi pointer to ftdi_context \ param manufacturer String to use as Manufacturer \ param product String to use as Product description \ param serial String to use as Serial number description \ retval 0 : all fine \ retval - 1 : No struct ftdi_context \ retval - 2 : No struct ftdi_eeprom \ retval - 3 : No connected device or device not yet opened
int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer,
                             char * product, char * serial)
{
    struct ftdi_eeprom *eeprom;
    if (ftdi == NULL)
        ftdi_error_return(-1, "No struct ftdi_context");
    if (ftdi->eeprom == NULL)
        ftdi_error_return(-2,"No struct ftdi_eeprom");
    eeprom = ftdi->eeprom;
    memset(eeprom, 0, sizeof(struct ftdi_eeprom));
    if (ftdi->usb_dev == NULL)
        ftdi_error_return(-3, "No connected device or device not yet opened");
    eeprom->vendor_id = 0x0403;
    eeprom->use_serial = 1;
    if ((ftdi->type == TYPE_AM) || (ftdi->type == TYPE_BM) ||
            (ftdi->type == TYPE_R))
        eeprom->product_id = 0x6001;
    else if (ftdi->type == TYPE_4232H)
        eeprom->product_id = 0x6011;
    else if (ftdi->type == TYPE_232H)
        eeprom->product_id = 0x6014;
    else if (ftdi->type == TYPE_230X)
        eeprom->product_id = 0x6015;
    else
        eeprom->product_id = 0x6010;
    if (ftdi->type == TYPE_AM)
        eeprom->usb_version = 0x0101;
    else
        eeprom->usb_version = 0x0200;
    eeprom->max_power = 100;
    if (eeprom->manufacturer)
        free (eeprom->manufacturer);
    eeprom->manufacturer = NULL;
    if (manufacturer)
    {
        eeprom->manufacturer = malloc(strlen(manufacturer)+1);
        if (eeprom->manufacturer)
            strcpy(eeprom->manufacturer, manufacturer);
    }
    if (eeprom->product)
        free (eeprom->product);
    eeprom->product = NULL;
    if(product)
    {
        eeprom->product = malloc(strlen(product)+1);
        if (eeprom->product)
            strcpy(eeprom->product, product);
    }
    else
    {
        const char* default_product;
        switch(ftdi->type)
        {
            case TYPE_AM:    default_product = "AM"; break;
            case TYPE_BM:    default_product = "BM"; break;
            case TYPE_2232C: default_product = "Dual RS232"; break;
            case TYPE_R:     default_product = "FT232R USB UART"; break;
            case TYPE_2232H: default_product = "Dual RS232-HS"; break;
            case TYPE_4232H: default_product = "FT4232H"; break;
            case TYPE_232H:  default_product = "Single-RS232-HS"; break;
            case TYPE_230X:  default_product = "FT230X Basic UART"; break;
            default:
                ftdi_error_return(-3, "Unknown chip type");
        }
        eeprom->product = malloc(strlen(default_product) +1);
        if (eeprom->product)
            strcpy(eeprom->product, default_product);
    }
    if (eeprom->serial)
        free (eeprom->serial);
    eeprom->serial = NULL;
    if (serial)
    {
        eeprom->serial = malloc(strlen(serial)+1);
        if (eeprom->serial)
            strcpy(eeprom->serial, serial);
    }
    if (ftdi->type == TYPE_R)
    {
        eeprom->max_power = 90;
        eeprom->size = 0x80;
        eeprom->cbus_function[0] = CBUS_TXLED;
        eeprom->cbus_function[1] = CBUS_RXLED;
        eeprom->cbus_function[2] = CBUS_TXDEN;
        eeprom->cbus_function[3] = CBUS_PWREN;
        eeprom->cbus_function[4] = CBUS_SLEEP;
    }
    else if (ftdi->type == TYPE_230X)
    {
        eeprom->max_power = 90;
        eeprom->size = 0x100;
        eeprom->cbus_function[0] = CBUSH_TXDEN;
        eeprom->cbus_function[1] = CBUSH_RXLED;
        eeprom->cbus_function[2] = CBUSH_TXLED;
        eeprom->cbus_function[3] = CBUSH_SLEEP;
    }
    else
    {
        if(ftdi->type == TYPE_232H)
        {
            int i;
            for (i=0; i<10; i++)
                eeprom->cbus_function[i] = CBUSH_TRISTATE;
        }
        eeprom->size = -1;
    }
    switch (ftdi->type)
    {
        case TYPE_AM:
            eeprom->release_number = 0x0200;
            break;
        case TYPE_BM:
            eeprom->release_number = 0x0400;
            break;
        case TYPE_2232C:
            eeprom->release_number = 0x0500;
            break;
        case TYPE_R:
            eeprom->release_number = 0x0600;
            break;
        case TYPE_2232H:
            eeprom->release_number = 0x0700;
            break;
        case TYPE_4232H:
            eeprom->release_number = 0x0800;
            break;
        case TYPE_232H:
            eeprom->release_number = 0x0900;
            break;
        case TYPE_230X:
            eeprom->release_number = 0x1000;
            break;
        default:
            eeprom->release_number = 0x00;
    }
    return 0;
}
int ftdi_eeprom_initdefaults ( struct ftdi_context * ftdi , char * manufacturer , char * product , char * serial ) { struct ftdi_eeprom * eeprom ; if ( ftdi == NULL ) ftdi_error_return ( -1 , " " ) ; if ( ftdi -> eeprom == NULL ) ftdi_error_return ( -2 , " " ) ; eeprom = ftdi -> eeprom ; memset ( eeprom , 0 , sizeof ( struct ftdi_eeprom ) ) ; if ( ftdi -> usb_dev == NULL ) ftdi_error_return ( -3 , " " ) ; eeprom -> vendor_id = 0x0403 ; eeprom -> use_serial = 1 ; if ( ( ftdi -> type == TYPE_AM ) || ( ftdi -> type == TYPE_BM ) || ( ftdi -> type == TYPE_R ) ) eeprom -> product_id = 0x6001 ; else if ( ftdi -> type == TYPE_4232H ) eeprom -> product_id = 0x6011 ; else if ( ftdi -> type == TYPE_232H ) eeprom -> product_id = 0x6014 ; else if ( ftdi -> type == TYPE_230X ) eeprom -> product_id = 0x6015 ; else eeprom -> product_id = 0x6010 ; if ( ftdi -> type == TYPE_AM ) eeprom -> usb_version = 0x0101 ; else eeprom -> usb_version = 0x0200 ; eeprom -> max_power = 100 ; if ( eeprom -> manufacturer ) free ( eeprom -> manufacturer ) ; eeprom -> manufacturer = NULL ; if ( manufacturer ) { eeprom -> manufacturer = malloc ( strlen ( manufacturer ) + 1 ) ; if ( eeprom -> manufacturer ) strcpy ( eeprom -> manufacturer , manufacturer ) ; } if ( eeprom -> product ) free ( eeprom -> product ) ; eeprom -> product = NULL ; if ( product ) { eeprom -> product = malloc ( strlen ( product ) + 1 ) ; if ( eeprom -> product ) strcpy ( eeprom -> product , product ) ; } else { const char * default_product ; switch ( ftdi -> type ) { case TYPE_AM : default_product = " " ; break ; case TYPE_BM : default_product = " " ; break ; case TYPE_2232C : default_product = " " ; break ; case TYPE_R : default_product = " " ; break ; case TYPE_2232H : default_product = " " ; break ; case TYPE_4232H : default_product = " " ; break ; case TYPE_232H : default_product = " " ; break ; case TYPE_230X : default_product = " " ; break ; default : ftdi_error_return ( -3 , " " ) ; } eeprom -> product = malloc ( strlen ( default_product ) + 1 ) ; if ( eeprom -> product ) strcpy ( eeprom -> product , default_product ) ; } if ( eeprom -> serial ) free ( eeprom -> serial ) ; eeprom -> serial = NULL ; if ( serial ) { eeprom -> serial = malloc ( strlen ( serial ) + 1 ) ; if ( eeprom -> serial ) strcpy ( eeprom -> serial , serial ) ; } if ( ftdi -> type == TYPE_R ) { eeprom -> max_power = 90 ; eeprom -> size = 0x80 ; eeprom -> cbus_function [ 0 ] = CBUS_TXLED ; eeprom -> cbus_function [ 1 ] = CBUS_RXLED ; eeprom -> cbus_function [ 2 ] = CBUS_TXDEN ; eeprom -> cbus_function [ 3 ] = CBUS_PWREN ; eeprom -> cbus_function [ 4 ] = CBUS_SLEEP ; } else if ( ftdi -> type == TYPE_230X ) { eeprom -> max_power = 90 ; eeprom -> size = 0x100 ; eeprom -> cbus_function [ 0 ] = CBUSH_TXDEN ; eeprom -> cbus_function [ 1 ] = CBUSH_RXLED ; eeprom -> cbus_function [ 2 ] = CBUSH_TXLED ; eeprom -> cbus_function [ 3 ] = CBUSH_SLEEP ; } else { if ( ftdi -> type == TYPE_232H ) { int i ; for ( i = 0 ; i < 10 ; i ++ ) eeprom -> cbus_function [ i ] = CBUSH_TRISTATE ; } eeprom -> size = -1 ; } switch ( ftdi -> type ) { case TYPE_AM : eeprom -> release_number = 0x0200 ; break ; case TYPE_BM : eeprom -> release_number = 0x0400 ; break ; case TYPE_2232C : eeprom -> release_number = 0x0500 ; break ; case TYPE_R : eeprom -> release_number = 0x0600 ; break ; case TYPE_2232H : eeprom -> release_number = 0x0700 ; break ; case TYPE_4232H : eeprom -> release_number = 0x0800 ; break ; case TYPE_232H : eeprom -> release_number = 0x0900 ; break ; case TYPE_230X : eeprom -> release_number = 0x1000 ; break ; default : eeprom -> release_number = 0x00 ; } return 0 ; }
Init eeprom with default values for the connected device
\param ftdi pointer to ftdi_context
\param manufacturer String to use as Manufacturer
\param product String to use as Product description
\param serial String to use as Serial number description
Init eeprom with default values for the connected device \ param ftdi pointer to ftdi_context \ param manufacturer String to use as Manufacturer \ param product String to use as Product description \ param serial String to use as Serial number description