xref: /third_party/backends/backend/sm3600.h (revision 141cc406)
1/* sane - Scanner Access Now Easy.
2   Copyright (C) Marian Matthias Eichholz 2001
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#ifndef _H_SM3600
41#define _H_SM3600
42
43/* ======================================================================
44
45sm3600.h
46
47SANE backend master module.
48
49Definitions ported from "scantool.h" 5.4.2001.
50
51(C) Marian Matthias Eichholz 2001
52
53Start: 2.4.2001
54
55====================================================================== */
56
57#define DEBUG_SCAN     0x0001
58#define DEBUG_COMM     0x0002
59#define DEBUG_ORIG     0x0004
60#define DEBUG_BASE     0x0011
61#define DEBUG_DEVSCAN  0x0012
62#define DEBUG_REPLAY   0x0014
63#define DEBUG_BUFFER   0x0018
64#define DEBUG_SIGNALS  0x0020
65#define DEBUG_CALIB    0x0040
66
67#define DEBUG_CRITICAL 1
68#define DEBUG_VERBOSE  2
69#define DEBUG_INFO     3
70#define DEBUG_JUNK     5
71
72#define USB_TIMEOUT_JIFFIES  2000
73
74#define SCANNER_VENDOR     0x05DA
75
76#define MAX_PIXEL_PER_SCANLINE  5300
77
78/* ====================================================================== */
79
80typedef enum { false, true } TBool;
81
82typedef SANE_Status TState;
83
84typedef enum { unknown, sm3600, sm3700, sm3750 } TModel;
85
86typedef struct {
87  TBool         bCalibrated;
88  int           xMargin; /* in 1/600 inch */
89  int           yMargin; /* in 1/600 inch */
90  unsigned char nHoleGray;
91  unsigned char nBarGray;
92  long          rgbBias;
93  unsigned char      *achStripeY;
94  unsigned char      *achStripeR;
95  unsigned char      *achStripeG;
96  unsigned char      *achStripeB;
97} TCalibration;
98
99typedef struct {
100  int x;
101  int y;
102  int cx;
103  int cy;
104  int res; /* like all parameters in 1/1200 inch */
105  int nBrightness; /* -255 ... 255 */
106  int nContrast;   /* -128 ... 127 */
107} TScanParam;
108
109typedef enum { fast, high, best } TQuality;
110typedef enum { color, gray, line, halftone } TMode;
111
112#define INST_ASSERT() { if (this->nErrorState) return this->nErrorState; }
113
114#define CHECK_ASSERTION(a) if (!(a)) return SetError(this,SANE_STATUS_INVAL,"assertion failed in %s %d",__FILE__,__LINE__)
115
116#define CHECK_POINTER(p) \
117if (!(p)) return SetError(this,SANE_STATUS_NO_MEM,"memory failed in %s %d",__FILE__,__LINE__)
118
119#define dprintf debug_printf
120
121typedef struct TInstance *PTInstance;
122typedef TState (*TReadLineCB)(PTInstance);
123
124typedef struct TScanState {
125  TBool           bEOF;         /* EOF marker for sane_read */
126  TBool           bCanceled;
127  TBool           bScanning;    /* block is active? */
128  TBool           bLastBulk;    /* EOF announced */
129  int             iReadPos;     /* read() interface */
130  int             iBulkReadPos; /* bulk read pos */
131  int             iLine;        /* log no. line */
132  int             cchBulk;      /* available bytes in bulk buffer */
133  int             cchLineOut;   /* buffer size */
134  int             cxPixel,cyPixel; /* real pixel */
135  int             cxMax;        /* uninterpolated in real pixels */
136  int             cxWindow;     /* Window with in 600 DPI */
137  int             cyWindow;     /* Path length in 600 DPI */
138  int             cyTotalPath;  /* from bed start to window end in 600 dpi */
139  int             nFixAspect;   /* aspect ratio in percent, 75-100 */
140  int             cBacklog;     /* depth of ppchLines */
141  int             ySensorSkew;  /* distance in pixel between sensors */
142  char           *szOrder;      /* 123 or 231 or whatever */
143  unsigned char  *pchBuf;       /* bulk transfer buffer */
144  short         **ppchLines;    /* for error diffusion and color corr. */
145  unsigned char  *pchLineOut;   /* read() interface */
146  TReadLineCB     ReadProc;     /* line getter callback */
147} TScanState;
148
149
150#ifndef INSANE_VERSION
151
152#ifdef SM3600_SUPPORT_EXPOSURE
153#define NUM_OPTIONS 18
154#else
155#define NUM_OPTIONS 16
156#endif
157
158
159typedef struct TDevice {
160  struct TDevice        *pNext;
161  struct usb_device     *pdev;
162  TModel                 model;
163  SANE_Device            sane;
164  char			*szSaneName;
165} TDevice;
166
167#endif
168
169typedef struct TInstance {
170#ifndef INSANE_VERSION
171  struct TInstance         *pNext;
172  SANE_Option_Descriptor    aoptDesc[NUM_OPTIONS];
173  Option_Value              aoptVal[NUM_OPTIONS];
174#endif
175  SANE_Int           agammaY[4096];
176  SANE_Int           agammaR[4096];
177  SANE_Int           agammaG[4096];
178  SANE_Int           agammaB[4096];
179  TScanState         state;
180  TCalibration       calibration;
181  TState             nErrorState;
182  char              *szErrorReason;
183  TBool              bSANE;
184  TScanParam         param;
185  TBool              bWriteRaw;
186  TBool              bVerbose;
187  TBool              bOptSkipOriginate;
188  TQuality           quality;
189  TMode              mode;
190  TModel             model;
191  int                hScanner;
192  FILE              *fhLog;
193  FILE              *fhScan;
194  int                ichPageBuffer; /* write position in full page buffer */
195  int                cchPageBuffer; /* total size of '' */
196  unsigned char     *pchPageBuffer; /* the humble buffer */
197} TInstance;
198
199#define TRUE  1
200#define FALSE 0
201
202/* ====================================================================== */
203
204#define ERR_FAILED -1
205#define OK         0
206
207#define NUM_SCANREGS      74
208
209/* ====================================================================== */
210
211/* note: The first register has address 0x01 */
212
213#define R_ALL    0x01
214
215/* have to become an enumeration */
216
217typedef enum { none, hpos, hposH, hres } TRegIndex;
218
219/* WORD */
220#define R_SPOS   0x01
221#define R_XRES   0x03
222/* WORD */
223#define R_SWID   0x04
224/* WORD */
225#define R_STPS   0x06
226/* WORD */
227#define R_YRES   0x08
228/* WORD */
229#define R_SLEN   0x0A
230/* WORD*/
231#define R_INIT   0x12
232#define RVAL_INIT 0x1540
233/* RGB */
234#define R_CCAL   0x2F
235
236/* WORD */
237#define R_CSTAT  0x42
238#define R_CTL    0x46
239/* WORD */
240#define R_POS    0x52
241/* WORD */
242#define R_LMP    0x44
243#define R_QLTY   0x4A
244#define R_STAT   0x54
245
246#define LEN_MAGIC   0x24EA
247
248/* ====================================================================== */
249#define USB_CHUNK_SIZE 0x8000
250
251/* sm3600-scanutil.c */
252__SM3600EXPORT__ int SetError(TInstance *this, int nError, const char *szFormat, ...);
253__SM3600EXPORT__ void debug_printf(unsigned long ulType, const char *szFormat, ...);
254__SM3600EXPORT__ TState FreeState(TInstance *this, TState nReturn);
255__SM3600EXPORT__ TState EndScan(TInstance *this);
256__SM3600EXPORT__ TState ReadChunk(TInstance *this, unsigned char *achOut,
257				  int cchMax, int *pcchRead);
258#ifdef INSANE_VERSION
259__SM3600EXPORT__ void DumpBuffer(FILE *fh, const char *pch, int cch);
260__SM3600EXPORT__ TState DoScanFile(TInstance *this);
261#endif
262
263__SM3600EXPORT__ void   GetAreaSize(TInstance *this);
264__SM3600EXPORT__ void   ResetCalibration(TInstance *this);
265
266__SM3600EXPORT__ TState InitGammaTables(TInstance *this,
267					int nBrightness,
268					int nContrast);
269__SM3600EXPORT__ TState CancelScan(TInstance *this);
270
271/* sm3600-scanmtek.c */
272extern unsigned short aidProduct[];
273__SM3600EXPORT__ TState DoInit(TInstance *this);
274__SM3600EXPORT__ TState DoReset(TInstance *this);
275__SM3600EXPORT__ TState WaitWhileBusy(TInstance *this,int cSecs);
276__SM3600EXPORT__ TState WaitWhileScanning(TInstance *this,int cSecs);
277__SM3600EXPORT__ TModel GetScannerModel(unsigned short idVendor, unsigned short idProduct);
278
279#ifdef INSANE_VERSION
280__SM3600EXPORT__ TState DoLampSwitch(TInstance *this,int nPattern);
281#endif
282__SM3600EXPORT__ TState DoCalibration(TInstance *this);
283__SM3600EXPORT__ TState UploadGammaTable(TInstance *this, int iByteAddress, SANE_Int *pnGamma);
284__SM3600EXPORT__ TState UploadGainCorrection(TInstance *this, int iTableOffset);
285
286/* sm3600-scanusb.c */
287__SM3600EXPORT__ TState RegWrite(TInstance *this,int iRegister, int cb, unsigned long ulValue);
288__SM3600EXPORT__ TState RegWriteArray(TInstance *this,int iRegister, int cb, unsigned char *pchBuffer);
289#ifdef INSANE_VERSIONx
290__SM3600EXPORT__ TState RegCheck(TInstance *this,int iRegister, int cch, unsigned long ulValue);
291__SM3600EXPORT__ int BulkRead(TInstance *this,FILE *fhOut, unsigned int cchBulk);
292__SM3600EXPORT__ TState MemReadArray(TInstance *this, int iAddress, int cb, unsigned char *pchBuffer);
293#endif
294__SM3600EXPORT__ int BulkReadBuffer(TInstance *this,unsigned char *puchBufferOut, unsigned int cchBulk); /* gives count */
295__SM3600EXPORT__ unsigned int RegRead(TInstance *this,int iRegister, int cch);
296__SM3600EXPORT__ TState MemWriteArray(TInstance *this, int iAddress, int cb, unsigned char *pchBuffer);
297
298/* sm3600-gray.c */
299__SM3600EXPORT__ TState StartScanGray(TInstance *this);
300/* sm3600-color.c */
301__SM3600EXPORT__ TState StartScanColor(TInstance *this);
302
303/* sm3600-homerun.c */
304#ifdef INSANE_VERSION
305__SM3600EXPORT__ TState FakeCalibration(TInstance *this);
306#endif
307
308__SM3600EXPORT__ TState DoOriginate(TInstance *this, TBool bStepOut);
309__SM3600EXPORT__ TState DoJog(TInstance *this,int nDistance);
310
311/* ====================================================================== */
312
313#endif
314