• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 2003 Gerhard Jaeger <gerhard@gjaeger.de>
3    This file is part of the SANE package.
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 
18    As a special exception, the authors of SANE give permission for
19    additional uses of the libraries contained in this release of SANE.
20 
21    The exception is that, if you link a SANE library with other files
22    to produce an executable, this does not by itself cause the
23    resulting executable to be covered by the GNU General Public
24    License.  Your use of that executable is in no way restricted on
25    account of linking the SANE library code into it.
26 
27    This exception does not, however, invalidate any other reasons why
28    the executable file might be covered by the GNU General Public
29    License.
30 
31    If you submit changes to SANE to the maintainers to be included in
32    a subsequent release, you agree by submitting the changes that
33    those changes may be distributed with this exception intact.
34 
35    If you write modifications of your own for SANE, it is your choice
36    whether to permit this exception to apply to your modifications.
37    If you do not wish that, delete this exception notice.
38 */
39 
40 /** @file sanei_pp.h
41  * This file implements an interface for accessing the parallel-port
42  *
43  * @sa sanei_pp.h
44  */
45 #ifndef sanei_pp_h
46 #define sanei_pp_h
47 
48 #include <sys/types.h>
49 #include <sane/sane.h>
50 
51 /** some modes, we'd like to see/use. */
52 enum sanei_pp_mode {
53   	SANEI_PP_MODE_SPP  = (1<<1), 		/**< SPP */
54 	SANEI_PP_MODE_BIDI = (1<<2), 		/**< BIDI */
55 	SANEI_PP_MODE_EPP  = (1<<4), 		/**< EPP */
56 	SANEI_PP_MODE_ECP  = (1<<8) 		/**< ECP */
57 };
58 
59 #define SANEI_PP_DATAIN  1
60 #define SANEI_PP_DATAOUT 0
61 
62 /* @{ */
63 /** Parallelport Control-Register definitions */
64 #define SANEI_PP_CTRL_STROBE        0x01
65 #define SANEI_PP_CTRL_AUTOLF        0x02
66 #define SANEI_PP_CTRL_NOT_INIT      0x04
67 #define SANEI_PP_CTRL_SELECT_IN     0x08
68 #define SANEI_PP_CTRL_ENABLE_IRQ    0x10
69 #define SANEI_PP_CTRL_DIRECTION     0x20
70 #define SANEI_PP_CTRL_RESERVED      0xc0
71 /* @} */
72 
73 /** Initialize sanei_pp.
74  *
75  * This function must be called before any other sanei_pp function.
76  */
77 extern SANE_Status sanei_pp_init( void );
78 
79 /** Open a parport device.
80  *
81  * @param dev - name of device to open.
82  * @param fd  - pointer to variable that should revceive the handle.
83  * @return
84  */
85 extern SANE_Status sanei_pp_open( const char *dev, int *fd );
86 
87 /* Close a previously opened parport device.
88  *
89  * @param fd - handle of the device to close
90  */
91 extern void sanei_pp_close( int fd );
92 
93 /** Claim a parport device
94  *
95  * @param fd - handle of the device to claim
96  * @return
97  */
98 extern SANE_Status sanei_pp_claim( int fd );
99 
100 /** Release a previously claimed device
101  *
102  * @param fd - handle of the device to release
103  * @return
104  */
105 extern SANE_Status sanei_pp_release( int fd );
106 
107 /** Set the data direction
108  *
109  * @param fd  - handle of the device, where to change the direction.
110  * @param rev -
111  * @return SANE_STATUS_GOOD on success
112  */
113 extern SANE_Status sanei_pp_set_datadir( int fd, int rev );
114 
115 /** Check whether for libieee1284 usage.
116  *
117  * This function can be used to check if the lib uses libieee1284 or
118  * in/out functions directly.
119  *
120  * @return SANE_TRUE if we use direct access, SANE_FALSE if the lib uses
121  *         libieee1284 functions.
122  */
123 extern SANE_Bool sanei_pp_uses_directio( void );
124 
125 /** Determine the available parallel port modes for a given device.
126  *
127  * @param fd   - handle of the device, whose modes shall be checked for.
128  * @param mode - pointer to variable, which should receive the modes.
129  * @return SANE_STATUS_GOOD on success.
130  */
131 extern SANE_Status sanei_pp_getmodes( int fd, int *mode );
132 
133 /** Set the operation mode for a given device.
134  *
135  * @param fd   - handle of the device, whose modes shall be set.
136  * @param mode - mode to set, see sanei_pp_mode.
137  * @return SANE_STATUS_GOOD on success.
138  */
139 extern SANE_Status sanei_pp_setmode( int fd, int mode );
140 
141 /** Write data to ports (spp-data, ctrl, epp-address and epp-data)
142  *
143  * @param fd  - handle of device to which shall be written to.
144  * @param val - data to write.
145  * @return SANE_STATUS_GOOD on success.
146  */
147 extern SANE_Status sanei_pp_outb_data( int fd, SANE_Byte val );
148 extern SANE_Status sanei_pp_outb_ctrl( int fd, SANE_Byte val );
149 extern SANE_Status sanei_pp_outb_addr( int fd, SANE_Byte val );
150 extern SANE_Status sanei_pp_outb_epp ( int fd, SANE_Byte val );
151 
152 /** Read data from ports (spp-data, status, ctrl and epp-data)
153  * @param fd - handle of device who should be read from.
154  * @return value got from port
155  */
156 extern SANE_Byte sanei_pp_inb_data( int fd );
157 extern SANE_Byte sanei_pp_inb_stat( int fd );
158 extern SANE_Byte sanei_pp_inb_ctrl( int fd );
159 extern SANE_Byte sanei_pp_inb_epp ( int fd );
160 
161 /** Delay execution for some micro-seconds.
162  *  Please note, that the accuracy highly depends on your system architecture
163  *  and the time to delay. It is internally implemented as system calls to
164  *  gettimeofday().
165  *
166  * @param usec - number of micro-seconds to delay
167  */
168 extern void sanei_pp_udelay( unsigned long usec );
169 
170 #endif
171