]> oss.titaniummirror.com Git - cp210x.git/commitdiff
Make CP2103 weak pullups the default configuration.
authorsmckown <smckown@986fd584-583e-0410-b54d-b9fe63dff8e5>
Mon, 2 Nov 2009 21:18:57 +0000 (21:18 +0000)
committersmckown <smckown@986fd584-583e-0410-b54d-b9fe63dff8e5>
Mon, 2 Nov 2009 21:18:57 +0000 (21:18 +0000)
Also, remove the requirement for GPIO_3 to be non-default.  This is the best
configuration, it seems.

src/examples/cpio.c
src/examples/cpmfg.c

index b08ee23f7b4b27f16d231cb4cc7aeaa02b21f892..8fec895da3ffd73d13ab49d106df41e185f229cc 100644 (file)
@@ -48,7 +48,7 @@ void cpDisconnect(int fd)
        close(fd);
 }
 
-void cpSetPortConf(int fd, int pullups)
+void cpSetPortConf(int fd, int nopullups)
 {
     int ret;
     cp2101_port_config_t config;
@@ -61,8 +61,8 @@ void cpSetPortConf(int fd, int pullups)
 
     /* 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.  Some boards may
-     * require weak pull-ups, but not TMI's RWS.
+     * 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
@@ -71,8 +71,9 @@ void cpSetPortConf(int fd, int pullups)
      *   GPIO_3 -> MSP430 UC_RST
      *
      */
-    config.reset.mode |= 0x0800; /* GPIO_3 gets push-pull driver */
-    config.enhancedFxn |= (pullups) ? 0x13 : 0x03;
+    config.enhancedFxn |= 0x13;
+    if (nopullups)
+       config.enhancedFxn &= ~0x10;
 
     if ((ret = ioctl(fd, IOCTL_PORTCONFSET, &config))) {
        fprintf(stderr, "portconfset ioctl failed %d\n", ret);
@@ -93,14 +94,14 @@ void cpReset(int fd)
 
 void usage(char* program)
 {
-    fprintf(stderr, "usage: %s [--pullups] <tty> <mfg> <part#> <sn#>\n",
+    fprintf(stderr, "usage: %s [--nopullups] <tty> <mfg> <part#> <sn#>\n",
        program);
 }
 
 int main(int argc, char* argv[])
 {
     int fd;
-    int pullups = 0;
+    int nopullups = 0;
 
     if (argc < 2 || argc > 3) {
        usage(argv[0]);
@@ -108,16 +109,16 @@ int main(int argc, char* argv[])
     }
 
     if (argc == 3) {
-       if (strncmp(argv[1], "--p", 3) == 0)
-           pullups = 1;
+       if (strncmp(argv[1], "--n", 3) == 0)
+           nopullups = 1;
        else {
            usage(argv[0]);
            exit(1);
        }
     }
 
-    fd = cpConnect(argv[pullups + 1]);
-    cpSetPortConf(fd, pullups);
+    fd = cpConnect(argv[nopullups + 1]);
+    cpSetPortConf(fd, nopullups);
     cpReset(fd);
     cpDisconnect(fd);
     printf("done\n");
index e8b2efbf04a433e411b06f1cf171d3b2fc441ce2..a8a94d87d5a77f488822f915593aad643be5487f 100644 (file)
@@ -95,7 +95,7 @@ void cpSetStr(int fd, unsigned int ioctlno, char* string, size_t len)
     }
 }
 
-void cpSetPortConf(int fd, int pullups)
+void cpSetPortConf(int fd, int nopullups)
 {
     int ret;
     cp2101_port_config_t config;
@@ -108,8 +108,8 @@ void cpSetPortConf(int fd, int pullups)
 
     /* 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.  Some boards may
-     * require weak pull-ups, but not TMI's RWS.
+     * 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
@@ -118,8 +118,9 @@ void cpSetPortConf(int fd, int pullups)
      *   GPIO_3 -> MSP430 UC_RST
      *
      */
-    config.reset.mode |= 0x0800; /* GPIO_3 gets push-pull driver */
-    config.enhancedFxn |= (pullups) ? 0x13 : 0x03;
+    config.enhancedFxn |= 0x13;
+    if (nopullups)
+       config.enhancedFxn &= ~0x10;
 
     if ((ret = ioctl(fd, IOCTL_PORTCONFSET, &config))) {
        fprintf(stderr, "portconfset ioctl failed %d\n", ret);
@@ -140,7 +141,7 @@ void cpReset(int fd)
 
 void usage(char* program)
 {
-    fprintf(stderr, "usage: %s [--pullups] <tty> <mfg> <part#> <sn#>\n",
+    fprintf(stderr, "usage: %s [--nopullups] <tty> <mfg> <part#> <sn#>\n",
        program);
 }
 
@@ -150,7 +151,7 @@ int main(int argc, char* argv[])
     char newprod[255];
     char newsn[255];
     int fd;
-    int pullups = 0;
+    int nopullups = 0;
 
     if (argc < 5 || argc > 6) {
        usage(argv[0]);
@@ -158,27 +159,27 @@ int main(int argc, char* argv[])
     }
 
     if (argc == 6) {
-       if (strncmp(argv[1], "--p", 3) == 0)
-           pullups = 1;
+       if (strncmp(argv[1], "--n", 3) == 0)
+           nopullups = 1;
        else {
            usage(argv[0]);
            exit(1);
        }
     }
 
-    /* strcpy(newmfg, argv[pullups + 2]);
-     * strcpy(newprod, argv[pullups + 3]);
+    /* strcpy(newmfg, argv[nopullups + 2]);
+     * strcpy(newprod, argv[nopullups + 3]);
      */
-    snprintf(newprod, sizeof(newprod), "%s %s", argv[pullups + 2],
-           argv[pullups + 3]);
-    strcpy(newsn, argv[pullups + 4]);
-    fd = cpConnect(argv[pullups + 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));
-    cpSetPortConf(fd, pullups);
+    cpSetPortConf(fd, nopullups);
     cpReset(fd);
     cpDisconnect(fd);
     printf("done\n");