OpenCores
URL https://opencores.org/ocsvn/ftdi_wb_bridge/ftdi_wb_bridge/trunk

Subversion Repositories ftdi_wb_bridge

[/] [ftdi_wb_bridge/] [trunk/] [sw/] [gpio_write.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ultra_embe
#include <stdio.h>
2
#include <string.h>
3
#include <stdlib.h>
4
#include <unistd.h>
5
#include "ftdi_hw.h"
6
 
7
//-----------------------------------------------------------------
8
// Defines:
9
//-----------------------------------------------------------------
10
#define DEFAULT_FTDI_IFACE  1
11
 
12
//-----------------------------------------------------------------
13
// main:
14
//-----------------------------------------------------------------
15
int main(int argc, char *argv[])
16
{
17
    int err = 0;
18
    int c;
19
    int help = 0;
20
    int ftdi_iface = DEFAULT_FTDI_IFACE;
21
    uint8_t value = 0;
22
    int quiet = 0;
23
 
24
    while ((c = getopt (argc, argv, "v:i:q")) != -1)
25
    {
26
        switch(c)
27
        {
28
            case 'v':
29
                 value = (uint8_t)strtoul(optarg, NULL, 0);
30
                 break;
31
            case 'i':
32
                 ftdi_iface = (int)strtol(optarg, NULL, 0);
33
                 break;
34
            case 'q':
35
                quiet = 1;
36
                break;
37
            default:
38
                help = 1;
39
                break;
40
        }
41
    }
42
 
43
    if (help)
44
    {
45
        fprintf (stderr,"Usage:\n");
46
        fprintf (stderr,"-v 0xNN           = Data to write\n");
47
        fprintf (stderr,"-i id             = FTDI interface ID (0 = A, 1 = B)\n");
48
        fprintf (stderr,"-q                = Quiet mode\n");
49
 
50
        exit(-1);
51
    }
52
 
53
    // Try and communicate with FTDI interface
54
    if (ftdi_hw_init(ftdi_iface) != 0)
55
    {
56
        fprintf(stderr, "ERROR: Could not open FTDI interface, try SUDOing / check connection\n");
57
        exit(-2);
58
    }
59
 
60
    if (!quiet)
61
        printf("Write 0x%x to GPIO\n", value);
62
 
63
    if (ftdi_hw_gpio_write(value) != 0)
64
    {
65
        fprintf(stderr, "ERROR: Could not write to device\n");
66
        err = 1;
67
    }
68
 
69
    ftdi_hw_close();
70
 
71
    return err;
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.