graphlcd-base/glcddrivers/port.h
changeset 4 df6a40031aa5
child 5 37602e25a04a
equal deleted inserted replaced
3:d0e62fc47285 4:df6a40031aa5
       
     1 /*
       
     2  * GraphLCD driver library
       
     3  *
       
     4  * port.h  -  parallel port class with low level routines
       
     5  *
       
     6  * This file is released under the GNU General Public License. Refer
       
     7  * to the COPYING file distributed with this package.
       
     8  *
       
     9  * (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
       
    10  */
       
    11 
       
    12 #ifndef _GLCDDRIVERS_PORT_H_
       
    13 #define _GLCDDRIVERS_PORT_H_
       
    14 
       
    15 namespace GLCD
       
    16 {
       
    17 
       
    18 const int kForward = 0;
       
    19 const int kReverse = 1;
       
    20 
       
    21 const unsigned char kStrobeHigh = 0x00; // Pin 1
       
    22 const unsigned char kStrobeLow  = 0x01;
       
    23 const unsigned char kAutoHigh   = 0x00; // Pin 14
       
    24 const unsigned char kAutoLow    = 0x02;
       
    25 const unsigned char kInitHigh   = 0x04; // Pin 16
       
    26 const unsigned char kInitLow    = 0x00;
       
    27 const unsigned char kSelectHigh = 0x00; // Pin 17
       
    28 const unsigned char kSelectLow  = 0x08;
       
    29 
       
    30 class cParallelPort
       
    31 {
       
    32 private:
       
    33     int fd;
       
    34     int port;
       
    35     bool usePPDev;
       
    36 
       
    37 public:
       
    38     cParallelPort();
       
    39     ~cParallelPort();
       
    40 
       
    41     int Open(int port);
       
    42     int Open(const char * device);
       
    43     int Close();
       
    44 
       
    45     bool IsDirectIO() const { return (!usePPDev); }
       
    46     int GetPortHandle() const { return ((usePPDev) ? fd : port); }
       
    47 
       
    48     void Claim();
       
    49     void Release();
       
    50 
       
    51     void SetDirection(int direction);
       
    52     unsigned char ReadControl();
       
    53     void WriteControl(unsigned char values);
       
    54     unsigned char ReadStatus();
       
    55     unsigned char ReadData();
       
    56     void WriteData(unsigned char data);
       
    57 };
       
    58 
       
    59 class cSerialPort
       
    60 {
       
    61 private:
       
    62     int fd;
       
    63 
       
    64 public:
       
    65     cSerialPort();
       
    66     ~cSerialPort();
       
    67 
       
    68     int Open(const char * device);
       
    69     int Close();
       
    70 
       
    71     int ReadData(unsigned char * data);
       
    72     void WriteData(unsigned char data);
       
    73     void WriteData(unsigned char * data, unsigned short length);
       
    74 };
       
    75 
       
    76 } // end of namespace
       
    77 
       
    78 #endif