X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=src%2Fexamples%2Fcpmfg.c;h=e8b2efbf04a433e411b06f1cf171d3b2fc441ce2;hb=31344b807962b968af815c4708f0edadfc657d54;hp=ed8524a5320da55132ce7bf48d5f3406660f09bf;hpb=db657625822bb2d96ee0ee8117f3cf81f0d9af08;p=cp210x.git diff --git a/src/examples/cpmfg.c b/src/examples/cpmfg.c index ed8524a..e8b2efb 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 cpSetLeds(int fd) +void cpSetPortConf(int fd, int pullups) { int ret; cp2101_port_config_t config; @@ -106,14 +106,21 @@ 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. Some boards may + * require weak pull-ups, but not 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.reset.mode |= 0x0800; /* GPIO_3 gets push-pull driver */ + config.enhancedFxn |= (pullups) ? 0x13 : 0x03; + if ((ret = ioctl(fd, IOCTL_PORTCONFSET, &config))) { fprintf(stderr, "portconfset ioctl failed %d\n", ret); exit(1); @@ -131,27 +138,47 @@ void cpReset(int fd) } } +void usage(char* program) +{ + fprintf(stderr, "usage: %s [--pullups] \n", + program); +} + int main(int argc, char* argv[]) { - /* char newmfg[255] = "Company Name"; */ - char newprod[255] = "CompanyName "; + /* char newmfg[255]; */ + char newprod[255]; char newsn[255]; int fd; + int pullups = 0; - if (argc != 4) { - fprintf(stderr, "usage: %s \n", argv[0]); - exit(1); + if (argc < 5 || argc > 6) { + usage(argv[0]); + exit(1); + } + + if (argc == 6) { + if (strncmp(argv[1], "--p", 3) == 0) + pullups = 1; + else { + usage(argv[0]); + exit(1); + } } - strcat(newprod, argv[2]); - strcpy(newsn, argv[3]); - fd = cpConnect(argv[1]); + /* strcpy(newmfg, argv[pullups + 2]); + * strcpy(newprod, argv[pullups + 3]); + */ + snprintf(newprod, sizeof(newprod), "%s %s", argv[pullups + 2], + argv[pullups + 3]); + strcpy(newsn, argv[pullups + 4]); + fd = cpConnect(argv[pullups + 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, pullups); cpReset(fd); cpDisconnect(fd); printf("done\n");