~ubuntu-branches/ubuntu/trusty/lcdproc/trusty-proposed

« back to all changes in this revision

Viewing changes to server/drivers/serialVFD_io.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Tallon
  • Date: 2006-10-15 14:48:37 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061015144837-wybst1fonzi46a0c
Tags: 0.5.1-1
* New upstream version
  - Fixes compiling on hppa (Closes: #389294)
  - Many new features and some config changes. Please read upstream's
  release notes for more information

* Avoid needing a /etc/mtab file at build time (Closes: #391912)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*      This file is part the LCDproc driver for various serial VFD Devices.
 
2
 
 
3
        It contains the hardwaredependent commands ach characterset.
 
4
 
 
5
        If you want to add a new device to the driver add a new section
 
6
        to the displaytype-switch-case in the init-function, add a new load_...
 
7
        function below and fill it with the corrrect commands for the display.
 
8
        (Try wich displaytype works best with your display, copy and modify
 
9
        it's section that is the easiest way I guess.)
 
10
 
 
11
        Copyright (C) 2006 Stefan Herdler
 
12
 
 
13
        2006-05-15 Version 0.3: everything should work (not all hardware tested!)
 
14
 
 
15
        This program is free software; you can redistribute it and/or modify
 
16
        it under the terms of the GNU General Public License as published by
 
17
        the Free Software Foundation; either version 2 of the License, or
 
18
        any later version.
 
19
 
 
20
        This program is distributed in the hope that it will be useful,
 
21
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
        GNU General Public License for more details.
 
24
 
 
25
        You should have received a copy of the GNU General Public License
 
26
        along with this program; if not, write to the Free Software
 
27
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 
28
 
 
29
*/
 
30
 
 
31
 
 
32
#include "port.h"
 
33
#include "serialVFD_io.h"
 
34
#include "serialVFD.h"
 
35
#include "lcd.h"
 
36
#define WR_on  0x10
 
37
#define WR_off 0x11
 
38
#define Busy   0x80
 
39
#define LPTPORT 0x378
 
40
 
 
41
#define MAXBUSY 300
 
42
 
 
43
void
 
44
serialVFD_write_serial (Driver *drvthis, char *dat, size_t length)
 
45
{
 
46
        PrivateData *p = drvthis->private_data;
 
47
        write (p->fd,dat,length);
 
48
}
 
49
 
 
50
void
 
51
serialVFD_write_parallel (Driver *drvthis, char *dat, size_t length)
 
52
{
 
53
        PrivateData *p = drvthis->private_data;
 
54
        int i_para, j_para;
 
55
 
 
56
        for(i_para = 0; i_para < length; i_para++) {
 
57
                port_out(p->port, dat[i_para]);
 
58
                port_in(p->port+1);
 
59
                port_out(p->port+2, WR_on);
 
60
                port_in(p->port+1);
 
61
                port_out(p->port+2, WR_off);
 
62
 
 
63
                for(j_para=0; j_para < MAXBUSY; j_para++) {
 
64
                        if((port_in(p->port+1)) & Busy)
 
65
                                break;
 
66
                }
 
67
        }
 
68
}
 
69
 
 
70
int
 
71
serialVFD_init_serial (Driver *drvthis)
 
72
{
 
73
        PrivateData *p = drvthis->private_data;
 
74
        struct termios portset;
 
75
 
 
76
        /* Set up io port correctly, and open it...*/
 
77
        debug( RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device);
 
78
        p->fd = open (p->device, O_RDWR | O_NOCTTY | O_NDELAY);
 
79
 
 
80
        if (p->fd == -1) {
 
81
                report (RPT_ERR, "%s: open() of %s failed (%s)\n", __FUNCTION__, p->device, strerror (errno));
 
82
                return -1;
 
83
        }
 
84
 
 
85
        tcgetattr (p->fd, &portset);
 
86
 
 
87
        // We use RAW mode
 
88
#ifdef HAVE_CFMAKERAW
 
89
        // The easy way
 
90
        cfmakeraw( &portset );
 
91
#else
 
92
        // The hard way
 
93
        portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP
 
94
                           | INLCR | IGNCR | ICRNL | IXON );
 
95
        portset.c_oflag &= ~OPOST;
 
96
        portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
 
97
        portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS );
 
98
        portset.c_cflag |= CS8 | CREAD | CLOCAL ;
 
99
#endif
 
100
 
 
101
        // Set port speed
 
102
        cfsetospeed (&portset, p->speed);
 
103
        cfsetispeed (&portset, B0);
 
104
 
 
105
        // Do it...
 
106
        tcsetattr (p->fd, TCSANOW, &portset);
 
107
        return 0;
 
108
}
 
109
 
 
110
int
 
111
serialVFD_init_parallel (Driver *drvthis)
 
112
{
 
113
        int ret=0;
 
114
        PrivateData *p = drvthis->private_data;
 
115
        debug( RPT_DEBUG, "%s: Opening parallelport at: 0x%X", __FUNCTION__, p->port);
 
116
//      if(port_access_multiple(p->port,3)) return -1;
 
117
        if(port_access(p->port) != 0) ret=-1;
 
118
        if(port_access(p->port+1) != 0) ret=-1;
 
119
        if(port_access(p->port+2) != 0) ret=-1;
 
120
        if(ret == -1) {
 
121
                report (RPT_ERR, "%s: port_access() of 0x%X failed (%s)\n", __FUNCTION__, p->port, strerror (errno));
 
122
                return -1;
 
123
        }
 
124
        return 0;
 
125
}
 
126
 
 
127