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

Subversion Repositories ftdi_wb_bridge

[/] [ftdi_wb_bridge/] [trunk/] [sw/] [gpio_read.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, "i:q")) != -1)
25
    {
26
        switch(c)
27
        {
28
            case 'i':
29
                 ftdi_iface = (int)strtol(optarg, NULL, 0);
30
                 break;
31
            case 'q':
32
                quiet = 1;
33
                break;
34
            default:
35
                help = 1;
36
                break;
37
        }
38
    }
39
 
40
    if (help)
41
    {
42
        fprintf (stderr,"Usage:\n");
43
        fprintf (stderr,"-v 0xNN           = Data to write\n");
44
        fprintf (stderr,"-i id             = FTDI interface ID (0 = A, 1 = B)\n");
45
        fprintf (stderr,"-q                = Quiet mode (data returned via return value)\n");
46
 
47
        exit(-1);
48
    }
49
 
50
    // Try and communicate with FTDI interface
51
    if (ftdi_hw_init(ftdi_iface) != 0)
52
    {
53
        fprintf(stderr, "ERROR: Could not open FTDI interface, try SUDOing / check connection\n");
54
        exit(-2);
55
    }
56
 
57
    if (ftdi_hw_gpio_read(&value) != 0)
58
    {
59
        fprintf(stderr, "ERROR: Could not read from device\n");
60
        err = 1;
61
    }
62
 
63
    if (!quiet)
64
    {
65
        printf("Read 0x%x from GPIO\n", value);
66
        value = 0;
67
    }
68
 
69
    ftdi_hw_close();
70
 
71
    return err ? -1 : value;
72
}

powered by: WebSVN 2.1.0

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