]> oss.titaniummirror.com Git - cp210x.git/blobdiff - src/examples/cpio.c
Make CP2103 weak pullups the default configuration.
[cp210x.git] / src / examples / cpio.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");