From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH v2 7/7] sandbox: parse libftdi options
Date: Mon, 15 Jan 2018 00:22:52 +0300 [thread overview]
Message-ID: <20180114212252.29682-8-antonynpavlov@gmail.com> (raw)
In-Reply-To: <20180114212252.29682-1-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
arch/sandbox/Makefile | 2 +-
arch/sandbox/os/common.c | 12 ++++++++++--
arch/sandbox/os/ftdi.c | 14 +++++++++++++-
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index 85c70b5e80..95ef7c84fb 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -23,7 +23,7 @@ CFLAGS += -Dmalloc=barebox_malloc -Dcalloc=barebox_calloc \
-Dglob=barebox_glob -Dglobfree=barebox_globfree \
-Dioctl=barebox_ioctl -Dfstat=barebox_fstat \
-Dopendir=barebox_opendir -Dreaddir=barebox_readdir \
- -Dclosedir=barebox_closedir
+ -Dclosedir=barebox_closedir -Dstrdup=barebox_strdup
machdirs := $(patsubst %,arch/sandbox/mach-%/,$(machine-y))
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 665e8194ef..161ea5c849 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -51,6 +51,8 @@ int sdl_yres;
static struct termios term_orig, term_vi;
static char erase_char; /* the users erase character */
+const char *libftdi_options;
+
static void rawmode(void)
{
tcgetattr(0, &term_orig);
@@ -322,10 +324,11 @@ static struct option long_options[] = {
{"stdinout", 1, 0, 'B'},
{"xres", 1, 0, 'x'},
{"yres", 1, 0, 'y'},
+ {"libftdi", 1, 0, 'f'},
{0, 0, 0, 0},
};
-static const char optstring[] = "hm:i:e:d:O:I:B:x:y:";
+static const char optstring[] = "hm:i:e:d:O:I:B:x:y:f:";
int main(int argc, char *argv[])
{
@@ -367,6 +370,9 @@ int main(int argc, char *argv[])
case 'y':
sdl_yres = strtoul(optarg, NULL, 0);
break;
+ case 'f':
+ libftdi_options = strdup(optarg);
+ break;
default:
break;
}
@@ -495,7 +501,9 @@ static void print_usage(const char *prgname)
" stdin and stdout. <filein> and <fileout> can be regular\n"
" files or FIFOs.\n"
" -x, --xres=<res> SDL width.\n"
-" -y, --yres=<res> SDL height.\n",
+" -y, --yres=<res> SDL height.\n"
+" -f, --libftdi=<opts> libftdi options, e.g.\n"
+" --libftdi=vendor_id=0x1234,device_id=0x5678,serial=AB0055\n",
prgname
);
}
diff --git a/arch/sandbox/os/ftdi.c b/arch/sandbox/os/ftdi.c
index 7302dd0989..d69bc43180 100644
--- a/arch/sandbox/os/ftdi.c
+++ b/arch/sandbox/os/ftdi.c
@@ -34,6 +34,11 @@ struct ft2232_bitbang {
static struct ft2232_bitbang ftbb;
+extern const char *libftdi_options;
+
+extern void parseopt_u16(const char *options, const char *opt, uint16_t *val);
+extern void parseopt_str(const char *options, const char *opt, char **val);
+
static inline int ftdi_flush(struct ftdi_context *ftdi)
{
uint8_t buf[1];
@@ -119,6 +124,7 @@ static int barebox_libftdi1_init(void)
/* default FT2232 values */
uint16_t vendor_id = FTDI_VID;
uint16_t device_id = FTDI_8U2232C_PID;
+ char *serial = NULL;
ftdi = ftdi_new();
if (!ftdi) {
@@ -126,7 +132,13 @@ static int barebox_libftdi1_init(void)
goto error;
}
- ret = ftdi_usb_open(ftdi, vendor_id, device_id);
+ if (libftdi_options) {
+ parseopt_u16(libftdi_options, "device_id", &device_id);
+ parseopt_u16(libftdi_options, "vendor_id", &vendor_id);
+ parseopt_str(libftdi_options, "serial", &serial);
+ }
+
+ ret = ftdi_usb_open_desc(ftdi, vendor_id, device_id, NULL, serial);
if (ret < 0 && ret != -5) {
fprintf(stderr, "unable to open ftdi device: %d (%s)\n",
ret, ftdi_get_error_string(ftdi));
--
2.15.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-01-14 21:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-14 21:22 [PATCH v2 0/7] sandbox: add gpio support with libftdi1 Antony Pavlov
2018-01-14 21:22 ` [PATCH v2 1/7] sandbox: avoid symbol conflict for {open, read, close}dir Antony Pavlov
2018-01-14 21:22 ` [PATCH v2 2/7] sandbox: add gpio support with libftdi1 Antony Pavlov
2018-01-14 21:22 ` [PATCH v2 3/7] sandbox: add i2c and spi libftdi1 bit-bang example Antony Pavlov
2018-01-17 10:01 ` Sascha Hauer
2018-01-19 9:14 ` Antony Pavlov
2018-01-14 21:22 ` [PATCH v2 4/7] move parseopt to lib/ Antony Pavlov
2018-01-14 21:22 ` [PATCH v2 5/7] include/parseopt.h: add guard macro Antony Pavlov
2018-01-14 21:22 ` [PATCH v2 6/7] parseopt: introduce parseopt_u16() and parseopt_str() Antony Pavlov
2018-01-14 21:22 ` Antony Pavlov [this message]
2018-01-17 9:53 ` [PATCH v2 0/7] sandbox: add gpio support with libftdi1 Sascha Hauer
2018-01-19 9:29 ` Antony Pavlov
2018-01-19 9:40 ` Sascha Hauer
2018-01-19 11:39 ` Antony Pavlov
2018-01-18 18:13 ` Antony Pavlov
2018-01-19 7:32 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180114212252.29682-8-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox