Add PRODUCT ID option to command line interface 40/114940/5
authorAdam Malinowski <a.malinowsk2@partner.samsung.com>
Wed, 15 Feb 2017 18:02:13 +0000 (19:02 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Tue, 18 Jul 2017 10:42:42 +0000 (12:42 +0200)
This change introduces possiblity of using FTDI devices
other than FT245RL.

Change-Id: Ic4a2c51a45ed0fc3d389ecdd38a4edbd9f5df3c1

doc/man/sd-mux-ctrl.1
etc/bash_completion.d/sd-mux-ctrl
src/main.cpp

index c778a37..0fce0b1 100644 (file)
@@ -10,7 +10,7 @@ sd-mux-ctrl - control software for sd-mux devices
 .PP
 .B  sd-mux-ctrl [-liuortdspcmvexn?] [-l|--list] [-i|--info] [-u|--status] [-o|--show-serial] [-r|--set-serial=STRING] [-t|--init] [-d|--dut]
 .B [-s|--ts] [-p|--pins=INT] [-c|--tick] [-y|--dyper1=STRING] [-z|--dyper2=STRING] [-m|--tick-time=INT] [-v|--device-id=INT]
-.B [-e|--device-serial=STRING] [-x|--vendor=INT] [-n|--invert] [-?|--help] [--usage]
+.B [-e|--device-serial=STRING] [-x|--vendor=INT] [-a|--product=INT] [-n|--invert] [-?|--help] [--usage]
 
 .SH DESCRIPTION
 
@@ -30,7 +30,7 @@ following actions:
 4. \fBreset\fR connected DUT by power disconnecting and reconnecting after specified timeout
 .RE
 .PP
-After manufacturing, each new sd-mux device has VENDOR ID set to 0x0403 which is the ID of FTDI company on whose chip
+After manufacturing, each new sd-mux device has VENDOR ID set to 0x0403 which is the ID of FTDI company of whose chip
 (FT245RL) the device is based.
 Before first real use, the device should be given a unique serial number.
 To do that \fB--set-serial\fR command must be executed. \fB--set-serial\fR command writes additional information and
@@ -70,7 +70,13 @@ This is the recommended way of addressing devices.
 \-x, \-\-vendor
 .RS 2
 Set VENDOR ID of devices which are to be used by sd-mux-ctrl. Default value is 0x04e8 which is assigned to
-SAMSUNG Electronics Company. DEVICE ID is hard-coded and is equal to 0x6001 - the default FTDI value.
+SAMSUNG Electronics Company. Default PRODUCT ID is equal to 0x6001 - the default FTDI value.
+.RE
+
+.PP
+\-a, \-\-product
+.RS 2
+Set PRODUCT ID of devices which are to be used by sd-mux-ctrl. Default value is 0x6001.
 .RE
 
 .PP
@@ -99,10 +105,10 @@ Print list of command and options and exit.
 .SS \fB\-l, \-\-list\fR
 
 .RS 2
-Print list of all connected sd-mux devices and exit. It takes optional \fB--vendor\fR argument which allows to use
-other VENDOR ID then the default one.
-The default value is 0x04e8 which belongs to SAMSUNG Electronics Company.
-VENDOR ID is used to discover all connected sd-mux devices. This is very important in post production
+Print list of all connected sd-mux devices and exit. It takes optional \fB--vendor --product\fR arguments that allow to use
+other VENDOR and PRODUCT IDs then the default ones.
+The default value is 0x04e8:6001 which belongs to SAMSUNG Electronics Company.
+VENDOR and PRODUCT IDs are used to discover all connected sd-mux devices. This is very important in post production
 (sd-mux device) phase, before first use.
 .RE
 
index b4aca0c..e554622 100644 (file)
@@ -22,7 +22,7 @@ _sdmux()
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
-    opts="--help --usage --list --device-serial --device-id --show-serial --set-serial --info --status --init --tick --dyper1 --dyper2 --tick-time --dut --ts --vendor --pins --invert"
+    opts="--help --usage --list --device-serial --device-id --show-serial --set-serial --info --status --init --tick --dyper1 --dyper2 --tick-time --dut --ts --vendor --product --pins --invert"
 
     case "${prev}" in
       --device-serial)
index 87c3fb7..4ddc377 100644 (file)
@@ -66,6 +66,7 @@ enum CCOption {
     CCO_TickTime,
     CCO_BitsInvert,
     CCO_Vendor,
+    CCO_Product,
     CCO_DyPer,
     CCO_MAX
 };
@@ -91,7 +92,7 @@ int listDevices(CCOptionValue options[]) {
         return EXIT_FAILURE;
     }
 
-    if ((fret = ftdi_usb_find_all(ftdi, &devlist, options[CCO_Vendor].argn, PRODUCT)) < 0) {
+    if ((fret = ftdi_usb_find_all(ftdi, &devlist, options[CCO_Vendor].argn, options[CCO_Product].argn)) < 0) {
         fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", fret, ftdi_get_error_string(ftdi));
         ftdi_free(ftdi);
         return EXIT_FAILURE;
@@ -142,9 +143,9 @@ struct ftdi_context* openDevice(CCOptionValue options[]) {
     }
 
     if (options[CCO_DeviceSerial].args != NULL) {
-        fret = ftdi_usb_open_desc_index(ftdi, options[CCO_Vendor].argn, PRODUCT, NULL, options[CCO_DeviceSerial].args, 0);
+        fret = ftdi_usb_open_desc_index(ftdi, options[CCO_Vendor].argn, options[CCO_Product].argn, NULL, options[CCO_DeviceSerial].args, 0);
     } else {
-        fret = ftdi_usb_open_desc_index(ftdi, options[CCO_Vendor].argn, PRODUCT, NULL, NULL, options[CCO_DeviceId].argn);
+        fret = ftdi_usb_open_desc_index(ftdi, options[CCO_Vendor].argn, options[CCO_Product].argn, NULL, NULL, options[CCO_DeviceId].argn);
     }
     if (fret < 0) {
         fprintf(stderr, "Unable to open ftdi device: %d (%s)\n", fret, ftdi_get_error_string(ftdi));
@@ -218,6 +219,12 @@ int setSerial(char *serialNumber, CCOptionValue options[]) {
         goto finish_him;
     }
 
+    f = ftdi_set_eeprom_value(ftdi, PRODUCT_ID, PRODUCT);
+    if (f < 0) {
+        fprintf(stderr, "Unable to set eeprom strings: %d (%s)\n", f, ftdi_get_error_string(ftdi));
+        goto finish_him;
+    }
+
     f = ftdi_eeprom_build(ftdi);
     if (f < 0) {
         fprintf(stderr, "Unable to build eeprom: %d (%s)\n", f, ftdi_get_error_string(ftdi));
@@ -480,6 +487,7 @@ int parseArguments(int argc, const char **argv, CCCommand *cmd, int *arg, char *
             { "device-serial", 'e', POPT_ARG_STRING, &options[CCO_DeviceSerial].args, 'e',
                     "use device with given serial number", NULL },
             { "vendor", 'x', POPT_ARG_INT, &options[CCO_Vendor].argn, 'x', "use device with given vendor id", NULL },
+            { "product", 'a', POPT_ARG_INT, &options[CCO_Product].argn, 'a', "use device with given product id", NULL },
             { "invert", 'n', POPT_ARG_NONE, NULL, 'n', "invert bits for --pins command", NULL },
             POPT_AUTOHELP
             { NULL, 0, 0, NULL, 0, NULL, NULL }
@@ -558,6 +566,7 @@ int main(int argc, const char **argv) {
     memset(&options, 0, sizeof(options));
     options[CCO_DeviceId].argn = -1;
     options[CCO_Vendor].argn = SAMSUNG_VENDOR;
+    options[CCO_Product].argn = PRODUCT;
 
     if (parseArguments(argc, argv, &cmd, &arg, args, sizeof(args), options) != EXIT_SUCCESS) {
         return EXIT_FAILURE;