config parser to associate ftdi2232 devices with parallel port
This commit is contained in:
parent
617583d072
commit
61e0de7a4b
151
config.c
151
config.c
@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <string.h>
|
||||||
#include "usb-driver.h"
|
#include "usb-driver.h"
|
||||||
#include "parport.h"
|
#include "parport.h"
|
||||||
#ifdef JTAGKEY
|
#ifdef JTAGKEY
|
||||||
@ -8,11 +9,19 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#define LINELEN 1024
|
||||||
|
|
||||||
|
#define PARSEERROR fprintf(stderr,"LIBUSB-DRIVER WARNING: Invalid config statement at line %d\n", line)
|
||||||
|
|
||||||
static struct parport_config pp_config[4];
|
static struct parport_config pp_config[4];
|
||||||
|
|
||||||
static void read_config() {
|
static void read_config() {
|
||||||
int i;
|
int i;
|
||||||
|
int line, len, num;
|
||||||
static int config_read = 0;
|
static int config_read = 0;
|
||||||
|
FILE *cfg;
|
||||||
|
char buf[LINELEN], *pbuf;
|
||||||
|
unsigned short vid, pid;
|
||||||
|
|
||||||
if (config_read)
|
if (config_read)
|
||||||
return;
|
return;
|
||||||
@ -28,14 +37,144 @@ static void read_config() {
|
|||||||
pp_config[i].transfer = parport_transfer;
|
pp_config[i].transfer = parport_transfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%s/.libusb-driverrc", getenv("HOME"));
|
||||||
|
|
||||||
|
cfg = fopen(buf, "r");
|
||||||
|
if (cfg) {
|
||||||
#ifdef JTAGKEY
|
#ifdef JTAGKEY
|
||||||
pp_config[3].real = 0;
|
line = 0;
|
||||||
pp_config[3].usb_vid = 0x0403;
|
do {
|
||||||
pp_config[3].usb_pid = 0xcff8;
|
pbuf = fgets(buf, sizeof(buf), cfg);
|
||||||
pp_config[3].open = jtagkey_open;
|
if (!pbuf)
|
||||||
pp_config[3].close = jtagkey_close;
|
break;
|
||||||
pp_config[3].transfer = jtagkey_transfer;
|
|
||||||
|
line++;
|
||||||
|
|
||||||
|
len = strlen(buf);
|
||||||
|
|
||||||
|
if (len > 0 && buf[len-1] == '\n') {
|
||||||
|
buf[len-1] = '\0';
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
if (len > 0 && buf[len-1] == '\r') {
|
||||||
|
buf[len-1] = '\0';
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (buf[i] != ' ' && buf[i] != '\t')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf[i] == '#' || buf[i] == ';' || buf[i] == '\0')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!strncasecmp(buf+i, "LPT", 3)) {
|
||||||
|
unsigned char equal_seen = 0;
|
||||||
|
|
||||||
|
i += 3;
|
||||||
|
pbuf = buf+i;
|
||||||
|
for (; i < len; i++) {
|
||||||
|
if (buf[i] == ' ' || buf[i] == '\t' || buf[i] == '=') {
|
||||||
|
if (buf[i] == '=')
|
||||||
|
equal_seen = 1;
|
||||||
|
|
||||||
|
buf[i] = '\0';
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*pbuf == '\0') {
|
||||||
|
PARSEERROR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
num = 0;
|
||||||
|
num = strtol(pbuf, NULL, 10);
|
||||||
|
if (num < 1) {
|
||||||
|
PARSEERROR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
num--;
|
||||||
|
|
||||||
|
for (; (i < len) && (!equal_seen) ; i++) {
|
||||||
|
if (buf[i] == '=') {
|
||||||
|
equal_seen = 1;
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
} else if (buf[i] != ' ' && buf[i] != '\t') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!equal_seen) {
|
||||||
|
PARSEERROR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; i < len; i++) {
|
||||||
|
if (buf[i] != ' ' && buf[i] != '\t')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncasecmp(buf+i, "FTDI:", 5)) {
|
||||||
|
PARSEERROR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
i += 5;
|
||||||
|
pbuf = buf + i;
|
||||||
|
|
||||||
|
for (; i < len; i++) {
|
||||||
|
if (buf[i] == ':')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf[i] != ':') {
|
||||||
|
PARSEERROR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[i] = '\0';
|
||||||
|
|
||||||
|
vid = 0;
|
||||||
|
vid = strtol(pbuf, NULL, 16);
|
||||||
|
if (!num) {
|
||||||
|
PARSEERROR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
pbuf = buf + i;
|
||||||
|
|
||||||
|
for (; i < len; i++) {
|
||||||
|
if (buf[i] == ' ' || buf[i] == '\t')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = 0;
|
||||||
|
pid = strtol(pbuf, NULL, 16);
|
||||||
|
if (!num) {
|
||||||
|
PARSEERROR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pp_config[num].real = 0;
|
||||||
|
pp_config[num].usb_vid = vid;
|
||||||
|
pp_config[num].usb_pid = pid;
|
||||||
|
pp_config[num].open = jtagkey_open;
|
||||||
|
pp_config[num].close = jtagkey_close;
|
||||||
|
pp_config[num].transfer = jtagkey_transfer;
|
||||||
|
} else {
|
||||||
|
PARSEERROR;
|
||||||
|
}
|
||||||
|
} while (pbuf);
|
||||||
|
#else
|
||||||
|
fprintf(stderr,"libusb-driver not compiled with FTDI2232-support, config file ignored!\n");
|
||||||
#endif
|
#endif
|
||||||
|
fclose(cfg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct parport_config *config_get(int num) {
|
struct parport_config *config_get(int num) {
|
||||||
|
6
libusb-driverrc
Normal file
6
libusb-driverrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Copy this file to ~/.libusb-driverrc if you want to use FTDI2232 cables
|
||||||
|
# All parallel ports not defined in this file are mapped to real ports on the
|
||||||
|
# system
|
||||||
|
|
||||||
|
# Amontec Jtagkey
|
||||||
|
LPT2 = FTDI:0403:cff8
|
@ -245,7 +245,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
switch(request & ~(0xc0000000)) {
|
switch(request & ~(0xc0000000)) {
|
||||||
case VERSION:
|
case VERSION:
|
||||||
version = (struct version_struct*)(wdheader->data);
|
version = (struct version_struct*)(wdheader->data);
|
||||||
strcpy(version->version, "libusb-driver.so $Revision: 1.68 $");
|
strcpy(version->version, "libusb-driver.so $Revision: 1.69 $");
|
||||||
version->versionul = 802;
|
version->versionul = 802;
|
||||||
DPRINTF("VERSION\n");
|
DPRINTF("VERSION\n");
|
||||||
break;
|
break;
|
||||||
@ -276,6 +276,9 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
pport = config_get((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
pport = config_get((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
||||||
|
if (!pport)
|
||||||
|
break;
|
||||||
|
|
||||||
ret = pport->open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
ret = pport->open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
|
||||||
|
|
||||||
ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
|
ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
|
||||||
|
Reference in New Issue
Block a user