* 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);
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);
}
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);
}
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);
}