1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2001-2003 Eddy De Greef <eddy_de_greef at scarlet dot be>
4    This file is part of the SANE package.
5 
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 
19    As a special exception, the authors of SANE give permission for
20    additional uses of the libraries contained in this release of SANE.
21 
22    The exception is that, if you link a SANE library with other files
23    to produce an executable, this does not by itself cause the
24    resulting executable to be covered by the GNU General Public
25    License.  Your use of that executable is in no way restricted on
26    account of linking the SANE library code into it.
27 
28    This exception does not, however, invalidate any other reasons why
29    the executable file might be covered by the GNU General Public
30    License.
31 
32    If you submit changes to SANE to the maintainers to be included in
33    a subsequent release, you agree by submitting the changes that
34    those changes may be distributed with this exception intact.
35 
36    If you write modifications of your own for SANE, it is your choice
37    whether to permit this exception to apply to your modifications.
38    If you do not wish that, delete this exception notice.
39 
40    This file implements a SANE backend for Mustek PP flatbed _CIS_ scanners.
41 */
42 
43 #ifndef mustek_pp_cis_h
44 #define mustek_pp_cis_h
45 
46 #include "../include/sane/sane.h"
47 
48 /******************************************************************************
49  * Read register symbols.
50  *****************************************************************************/
51 typedef enum {
52                 MA1015R_ASIC       = 0x00,
53                 MA1015R_SCAN_VAL   = 0x01,
54                 MA1015R_MOTOR      = 0x02,
55                 MA1015R_BANK_COUNT = 0x03
56              }
57 Mustek_PP_1015R_reg;
58 
59 /******************************************************************************
60  * Read register bitmask symbols.
61  *****************************************************************************/
62 typedef enum {
63                 MA1015B_MOTOR_HOME   = 0x01,
64                 MA1015B_MOTOR_STABLE = 0x03
65              }
66 Mustek_PP_1015R_bit;
67 
68 /******************************************************************************
69  * Write register symbols: (bank number << 4) + register number.
70  *****************************************************************************/
71 
72 typedef enum {
73                 MA1015W_RED_REF        = 0x00,
74                 MA1015W_GREEN_REF      = 0x01,
75                 MA1015W_BLUE_REF       = 0x02,
76                 MA1015W_DPI_CONTROL    = 0x03,
77 
78                 MA1015W_BYTE_COUNT_HB  = 0x10,
79                 MA1015W_BYTE_COUNT_LB  = 0x11,
80                 MA1015W_SKIP_COUNT     = 0x12,
81                 MA1015W_EXPOSE_TIME    = 0x13,
82 
83                 MA1015W_SRAM_SOURCE_PC = 0x20,
84                 MA1015W_MOTOR_CONTROL  = 0x21,
85                 MA1015W_UNKNOWN_42     = 0x22,
86                 MA1015W_UNKNOWN_82     = 0x23,
87 
88                 MA1015W_POWER_ON_DELAY = 0x30,
89                 MA1015W_CCD_TIMING     = 0x31,
90                 MA1015W_CCD_TIMING_ADJ = 0x32,
91                 MA1015W_RIGHT_BOUND    = 0x33
92              }
93 Mustek_PP_1015W_reg;
94 
95 
96 /******************************************************************************
97  * Mustek MA1015 register tracing structure.
98  * Can be used to trace the status of the registers of the MA1015 chipset
99  * during debugging. Most fields are not used in production code.
100  *****************************************************************************/
101 typedef struct Mustek_PP_1015_Registers
102 {
103    SANE_Byte in_regs[4];
104    SANE_Byte out_regs[4][4];
105    SANE_Byte channel;
106 
107    Mustek_PP_1015R_reg current_read_reg;
108    SANE_Int read_count;
109 
110    Mustek_PP_1015W_reg current_write_reg; /* always used */
111    SANE_Int write_count;
112 }
113 Mustek_PP_1015_Registers;
114 
115 
116 /******************************************************************************
117  * CIS information
118  *****************************************************************************/
119 typedef struct Mustek_PP_CIS_Info
120 {
121    /* Expose time (= time the lamp is on ?) */
122    SANE_Byte exposeTime;
123 
124    /* Power-on delay (= time between lamp on and start of capturing ?) */
125    SANE_Byte powerOnDelay[3];
126 
127    /* Motor step control */
128    SANE_Byte phaseType;
129 
130    /* Use 8K bank or 4K bank */
131    SANE_Bool use8KBank;
132 
133    /* High resolution (600 DPI) or not (300 DPI) */
134    SANE_Bool highRes;
135 
136    /* delay between pixels; reading too fast causes stability problems */
137    SANE_Int delay;
138 
139    /* Register representation */
140    Mustek_PP_1015_Registers regs;
141 
142    /* Current color channel */
143    SANE_Int channel;
144 
145    /* Blocks motor movements during calibration */
146    SANE_Bool dontMove;
147 
148    /* Prevents read increment the before the first read */
149    SANE_Bool dontIncRead;
150 
151    /* Controls whether or not calibration parameters are transmitted
152       during CIS configuration */
153    SANE_Bool setParameters;
154 
155    /* Number of lines to skip to reach the origin (used during calibration) */
156    SANE_Int skipsToOrigin;
157 
158    /* Physical resolution of the CIS: either 300 or 600 DPI */
159    SANE_Int cisRes;
160 
161    /* CCD mode (color/grayscale/lineart) */
162    SANE_Int mode;
163 
164    /* how many positions to skip until scan area starts @ max res */
165    SANE_Int skipimagebytes;
166 
167    /* how many image bytes to scan @ max res */
168    SANE_Int imagebytes;
169 
170    /* total skip, adjusted to resolution */
171    SANE_Int adjustskip;
172 
173    /* current resolution */
174    SANE_Int res;
175 
176    /* current horizontal hardware resolution */
177    SANE_Int hw_hres;
178 
179    /* current vertical hardware resolution */
180    SANE_Int hw_vres;
181 
182    /* how many positions to scan for one pixel */
183    SANE_Int hres_step;
184 
185    /* how many lines to scan for one scanline */
186    SANE_Int line_step;
187 
188    /* inversion */
189    SANE_Bool invert;
190 
191 } Mustek_PP_CIS_Info;
192 
193 struct Mustek_pp_Handle;
194 typedef struct Mustek_PP_CIS_dev
195 {
196   /* device descriptor */
197   struct Mustek_pp_Handle *desc;
198 
199   /* model identification (600CP/1200CP/1200CP+) */
200   SANE_Int model;
201 
202   /* CIS status */
203   Mustek_PP_CIS_Info CIS;
204 
205   /* used during calibration & return_home */
206   Mustek_PP_CIS_Info Saved_CIS;
207 
208   /* bank count */
209   int bank_count;
210 
211   /* those are used to count the hardware line the scanner is at, the
212      line the current bank is at and the lines we've scanned */
213   int line;
214   int line_diff;
215   int ccd_line;
216   int lines_left;
217 
218   /* Configuration parameters that the user can calibrate */
219   /* Starting position at the top */
220   SANE_Int top_skip;
221   /* Use fast skipping method for head movements ? (default: yes) */
222   SANE_Bool fast_skip;
223   /* Discrimination value to choose between black and white */
224   SANE_Byte bw_limit;
225   /* Run in calibration mode ? (default: no) */
226   SANE_Bool calib_mode;
227   /* Extra delay between engine commands (ms). Default: zero. */
228   SANE_Int engine_delay;
229 
230   /* temporary buffer for 1 line (of one color) */
231   SANE_Byte *tmpbuf;
232 
233   /* calibration buffers (low cut, high cut) */
234   SANE_Byte *calib_low[3];
235   SANE_Byte *calib_hi[3];
236 
237   /* Number of pixels in calibration buffers (<= number of pixels to scan) */
238   int calib_pixels;
239 
240 } Mustek_PP_CIS_dev;
241 
242 #define CIS_AVERAGE_NONE(dev)         Mustek_PP_1015_send_command(dev, 0x05)
243 #define CIS_AVERAGE_TWOPIXEL(dev)     Mustek_PP_1015_send_command(dev, 0x15)
244 #define CIS_AVERAGE_THREEPIXEL(dev)   Mustek_PP_1015_send_command(dev, 0x35)
245 #define CIS_WIDTH_4K(dev)             Mustek_PP_1015_send_command(dev, 0x05)
246 #define CIS_WIDTH_8K(dev)             Mustek_PP_1015_send_command(dev, 0x45)
247 #define CIS_STOP_TOGGLE(dev)          Mustek_PP_1015_send_command(dev, 0x85)
248 
249 #define CIS_PIP_AS_INPUT(dev)         Mustek_PP_1015_send_command(dev, 0x46)
250 #define CIS_PIP_AS_OUTPUT_0(dev)      Mustek_PP_1015_send_command(dev, 0x06)
251 #define CIS_PIP_AS_OUTPUT_1(dev)      Mustek_PP_1015_send_command(dev, 0x16)
252 #define CIS_POP_AS_INPUT(dev)         Mustek_PP_1015_send_command(dev, 0x86)
253 #define CIS_POP_AS_OUTPUT_0(dev)      Mustek_PP_1015_send_command(dev, 0x06)
254 #define CIS_POP_AS_OUTPUT_1(dev)      Mustek_PP_1015_send_command(dev, 0x26)
255 
256 #define CIS_INC_READ(dev)             Mustek_PP_1015_send_command(dev, 0x07)
257 #define CIS_CLEAR_WRITE_BANK(dev)     Mustek_PP_1015_send_command(dev, 0x17)
258 #define CIS_CLEAR_READ_BANK(dev)      Mustek_PP_1015_send_command(dev, 0x27)
259 #define CIS_CLEAR_FULLFLAG(dev)       Mustek_PP_1015_send_command(dev, 0x37)
260 #define CIS_POWER_ON(dev)             Mustek_PP_1015_send_command(dev, 0x47)
261 #define CIS_POWER_OFF(dev)            Mustek_PP_1015_send_command(dev, 0x57)
262 #define CIS_CLEAR_WRITE_ADDR(dev)     Mustek_PP_1015_send_command(dev, 0x67)
263 #define CIS_CLEAR_TOGGLE(dev)         Mustek_PP_1015_send_command(dev, 0x77)
264 
265 #define CIS_NO(dev)                   Mustek_PP_1015_send_command(dev, 0x08)
266 #define CIS_OST_POS(dev)              Mustek_PP_1015_send_command(dev, 0x18)
267 #define CIS_OST_TYP(dev)              Mustek_PP_1015_send_command(dev, 0x28)
268 #define CIS_OP_MOD_0(dev)             Mustek_PP_1015_send_command(dev, 0x48)
269 #define CIS_OP_MOD_1(dev)             Mustek_PP_1015_send_command(dev, 0x88)
270 
271 #endif /* __mustek_pp_cis_h */
272