]> oss.titaniummirror.com Git - cp210x.git/blobdiff - src/examples/cpio.c
All example programs updated to fit new cp210x.h.
[cp210x.git] / src / examples / cpio.c
index 8fec895da3ffd73d13ab49d106df41e185f229cc..b62afb0b2b4145e3d5832ccc36d870580e325da3 100644 (file)
@@ -4,35 +4,19 @@
  * Configure the and GPIO configuration for a cp2103-equipped device.
  */
 
+#include <fcntl.h>
 #include <netinet/in.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-
-#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 <unistd.h>
+#include <cp210x.h>
 
 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);
     }