summaryrefslogtreecommitdiff
path: root/glcddrivers/port.h
blob: 29204618af773c079b1210530c1a62bd4c72dd5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * GraphLCD driver library
 *
 * port.h  -  parallel port class with low level routines
 *
 * This file is released under the GNU General Public License. Refer
 * to the COPYING file distributed with this package.
 *
 * (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
 */

#ifndef _GLCDDRIVERS_PORT_H_
#define _GLCDDRIVERS_PORT_H_

namespace GLCD
{

const int kForward = 0;
const int kReverse = 1;

const unsigned char kStrobeHigh = 0x00; // Pin 1
const unsigned char kStrobeLow  = 0x01;
const unsigned char kAutoHigh   = 0x00; // Pin 14
const unsigned char kAutoLow    = 0x02;
const unsigned char kInitHigh   = 0x04; // Pin 16
const unsigned char kInitLow    = 0x00;
const unsigned char kSelectHigh = 0x00; // Pin 17
const unsigned char kSelectLow  = 0x08;

class cParallelPort
{
private:
    int fd;
    int port;
    bool usePPDev;

public:
    cParallelPort();
    ~cParallelPort();

    int Open(int port);
    int Open(const char * device);
    int Close();

    bool IsDirectIO() const { return (!usePPDev); }
    int GetPortHandle() const { return ((usePPDev) ? fd : port); }

    void Claim();
    void Release();

    void SetDirection(int direction);
    unsigned char ReadControl();
    void WriteControl(unsigned char values);
    unsigned char ReadStatus();
    unsigned char ReadData();
    void WriteData(unsigned char data);
};

class cSerialPort
{
private:
    int fd;

public:
    cSerialPort();
    ~cSerialPort();

    int Open(const char * device);
    int Close();

    int ReadData(unsigned char * data);
    void WriteData(unsigned char data);
    void WriteData(unsigned char * data, unsigned short length);
};

} // end of namespace

#endif