From: smckown Date: Mon, 2 Nov 2009 21:18:57 +0000 (+0000) Subject: Make CP2103 weak pullups the default configuration. X-Git-Tag: debian/0.11.2-5.2tmi~13 X-Git-Url: https://oss.titaniummirror.com/gitweb?p=cp210x.git;a=commitdiff_plain;h=9a6ce48371002e94e2adfef323fbf6c1f6d069c4 Make CP2103 weak pullups the default configuration. Also, remove the requirement for GPIO_3 to be non-default. This is the best configuration, it seems. --- diff --git a/src/examples/cpio.c b/src/examples/cpio.c index b08ee23..8fec895 100644 --- a/src/examples/cpio.c +++ b/src/examples/cpio.c @@ -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] \n", + fprintf(stderr, "usage: %s [--nopullups] \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"); diff --git a/src/examples/cpmfg.c b/src/examples/cpmfg.c index e8b2efb..a8a94d8 100644 --- a/src/examples/cpmfg.c +++ b/src/examples/cpmfg.c @@ -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] \n", + fprintf(stderr, "usage: %s [--nopullups] \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");