]> oss.titaniummirror.com Git - cp210x.git/blobdiff - src/examples/cpmfg.c
Make CP2103 weak pullups the default configuration.
[cp210x.git] / src / examples / cpmfg.c
index 832e75b356e6f9f86805f9ca9aa1ca480777b15c..a8a94d87d5a77f488822f915593aad643be5487f 100644 (file)
@@ -95,7 +95,7 @@ void cpSetStr(int fd, unsigned int ioctlno, char* string, size_t len)
     }
 }
 
-void cpSetLeds(int fd)
+void cpSetPortConf(int fd, int nopullups)
 {
     int ret;
     cp2101_port_config_t config;
@@ -106,15 +106,22 @@ void cpSetLeds(int fd)
        exit(1);
     }
 
-    /* Set the current port configuration; turn on GPIO_0 and GPIO_1 to get
-     * activity LEDs.  GPIO_2 and GPIO_3 are set for 'regular' gpio.
+    /* This section assumes the device is currently at factory defaults.  If
+     * not, first run 'cpfactory'.  The only delta from factory defaults is to
+     * activate the activity pin functions for GPIOs 0 and 1.  Most boards
+     * require the use of weak pull-ups, including TMI's RWS.
+     *
+     * GPIO mapping:
+     *   GPIO_0 -> TX activity, active low
+     *   GPIO_1 -> RX activity, active low
+     *   GPIO_2 -> MSP430 UC_TCK
+     *   GPIO_3 -> MSP430 UC_RST
+     *
      */
-    config.reset.mode &= ~0x0300;
-    config.suspend.mode &= ~0x0300;
-    config.reset.latch |= 0x0300;
-    config.enhancedFxn |= 0x03;
-    //config.enhancedFxn &= ~0x10; /* turn off weak pullups */
-    config.enhancedFxn |= 0x10; /* turn on weak pullups */
+    config.enhancedFxn |= 0x13;
+    if (nopullups)
+       config.enhancedFxn &= ~0x10;
+
     if ((ret = ioctl(fd, IOCTL_PORTCONFSET, &config))) {
        fprintf(stderr, "portconfset ioctl failed %d\n", ret);
        exit(1);
@@ -132,30 +139,47 @@ void cpReset(int fd)
     }
 }
 
+void usage(char* program)
+{
+    fprintf(stderr, "usage: %s [--nopullups] <tty> <mfg> <part#> <sn#>\n",
+       program);
+}
+
 int main(int argc, char* argv[])
 {
     /* char newmfg[255]; */
     char newprod[255];
     char newsn[255];
     int fd;
+    int nopullups = 0;
+
+    if (argc < 5 || argc > 6) {
+       usage(argv[0]);
+       exit(1);
+    }
 
-    if (argc != 5) {
-      fprintf(stderr, "usage: %s <tty> <mfg> <part#> <sn#>\n", argv[0]);
-      exit(1);
+    if (argc == 6) {
+       if (strncmp(argv[1], "--n", 3) == 0)
+           nopullups = 1;
+       else {
+           usage(argv[0]);
+           exit(1);
+       }
     }
 
-    /* strcpy(newmfg, argv[2]);
-     * strcpy(newprod, argv[3]);
+    /* strcpy(newmfg, argv[nopullups + 2]);
+     * strcpy(newprod, argv[nopullups + 3]);
      */
-    snprintf(newprod, sizeof(newprod), "%s %s", argv[2], argv[3]);
-    strcpy(newsn, argv[4]);
-    fd = cpConnect(argv[1]);
+    snprintf(newprod, sizeof(newprod), "%s %s", argv[nopullups + 2],
+           argv[nopullups + 3]);
+    strcpy(newsn, argv[nopullups + 4]);
+    fd = cpConnect(argv[nopullups + 1]);
     /* SiLabs doesn't allow set of mfg string on cp210x.
      * cpSetStr(fd, IOCTL_SETMFG, newmfg, strlen(newmfg));
      */
     cpSetStr(fd, IOCTL_SETPRODUCT, newprod, strlen(newprod));
     cpSetStr(fd, IOCTL_SETSERIAL, newsn, strlen(newsn));
-    cpSetLeds(fd);
+    cpSetPortConf(fd, nopullups);
     cpReset(fd);
     cpDisconnect(fd);
     printf("done\n");