Skip to content
Snippets Groups Projects
Commit c395bcb6 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Re-use function from tests in example.

parent 5f17d2cd
No related branches found
No related tags found
No related merge requests found
...@@ -172,6 +172,21 @@ static struct { ...@@ -172,6 +172,21 @@ static struct {
{ "PIO_WRITER", PIO_WRITER }, { "PIO_WRITER", PIO_WRITER },
{ "PIO_FPGUARD", PIO_FPGUARD}, { "PIO_FPGUARD", PIO_FPGUARD},
}; };
static inline int
search_iomode_str(const char *modestr)
{
int retval = -1;
for (size_t i = 0;
i < sizeof (mode_map) / sizeof (mode_map[0]);
++i)
if (!strcmp(modestr, mode_map[i].text))
{
retval = (int)i;
break;
}
return retval;
}
#endif #endif
...@@ -197,21 +212,13 @@ int main (int argc, char *argv[]) ...@@ -197,21 +212,13 @@ int main (int argc, char *argv[])
switch (opt) { switch (opt) {
case 'p': case 'p':
{ {
int found=0; int entry = search_iomode_str(optarg);
for (size_t i = 0; if (entry < 0)
i < sizeof (mode_map) / sizeof (mode_map[0]);
++i)
if (!strcmp(optarg, mode_map[i].text))
{
found = 1;
IOMode = mode_map[i].mode;
break;
}
if (!found)
{ {
fprintf(stderr, "Unsupported PIO mode requested: %s\n", optarg); fprintf(stderr, "Unsupported PIO mode requested: %s\n", optarg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
IOMode = mode_map[entry].mode;
} }
break; break;
case 'w': case 'w':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment