X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=src%2Fexamples%2Fcpio.c;fp=src%2Fexamples%2Fcpio.c;h=b62afb0b2b4145e3d5832ccc36d870580e325da3;hb=6000a45218d62d5e28a5b6c5150bdd2b84b84a01;hp=8fec895da3ffd73d13ab49d106df41e185f229cc;hpb=3c0ea1205a69103a17f39f9b0a96d99207fe0451;p=cp210x.git diff --git a/src/examples/cpio.c b/src/examples/cpio.c index 8fec895..b62afb0 100644 --- a/src/examples/cpio.c +++ b/src/examples/cpio.c @@ -4,35 +4,19 @@ * Configure the and GPIO configuration for a cp2103-equipped device. */ +#include #include #include #include +#include +#include #include #include -#include - -#define IOCTL_DEVICERESET 0x8004 /* Reset the cp210x */ -#define IOCTL_PORTCONFGET 0x8005 /* Get port configuration */ -#define IOCTL_PORTCONFSET 0x8006 /* Set port configuration */ - -/* Port config definitions */ -typedef struct { - uint16_t mode; /* Push-pull = 1, Open-drain = 0 */ - uint16_t lowPower; - uint16_t latch; /* Logic high = 1, Logic low = 0 */ -} cp2101_port_state_t; - -typedef struct { - cp2101_port_state_t reset; - cp2101_port_state_t suspend; - uint8_t enhancedFxn; -} cp2101_port_config_t; - -void exit(int); +#include +#include int cpConnect(char* device) { - int ret, ioval; int fd = open(device, O_RDWR); if (fd < 0) { fprintf(stderr, "cannot open %s\n", device); @@ -51,10 +35,10 @@ void cpDisconnect(int fd) void cpSetPortConf(int fd, int nopullups) { int ret; - cp2101_port_config_t config; + struct cp210x_port_config config; /* Read the current port configuration */ - if ((ret = ioctl(fd, IOCTL_PORTCONFGET, &config))) { + if ((ret = ioctl(fd, CP210x_IOCTL_PORTCONFGET, &config))) { fprintf(stderr, "portconfget ioctl failed %d\n", ret); exit(1); } @@ -75,7 +59,7 @@ void cpSetPortConf(int fd, int nopullups) if (nopullups) config.enhancedFxn &= ~0x10; - if ((ret = ioctl(fd, IOCTL_PORTCONFSET, &config))) { + if ((ret = ioctl(fd, CP210x_IOCTL_PORTCONFSET, &config))) { fprintf(stderr, "portconfset ioctl failed %d\n", ret); exit(1); } @@ -86,7 +70,7 @@ void cpReset(int fd) int ret; /* Reset the part */ - if ((ret = ioctl(fd, IOCTL_DEVICERESET, 0))) { + if ((ret = ioctl(fd, CP210x_IOCTL_DEVICERESET, 0))) { fprintf(stderr, "device reset ioctl %d\n", ret); exit(1); }