1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy.
2141cc406Sopenharmony_ci
3141cc406Sopenharmony_ci   Copyright (C) 2007-2012 stef.dev@free.fr
4141cc406Sopenharmony_ci
5141cc406Sopenharmony_ci   This file is part of the SANE package.
6141cc406Sopenharmony_ci
7141cc406Sopenharmony_ci   This program is free software; you can redistribute it and/or
8141cc406Sopenharmony_ci   modify it under the terms of the GNU General Public License as
9141cc406Sopenharmony_ci   published by the Free Software Foundation; either version 2 of the
10141cc406Sopenharmony_ci   License, or (at your option) any later version.
11141cc406Sopenharmony_ci
12141cc406Sopenharmony_ci   This program is distributed in the hope that it will be useful, but
13141cc406Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
14141cc406Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15141cc406Sopenharmony_ci   General Public License for more details.
16141cc406Sopenharmony_ci
17141cc406Sopenharmony_ci   You should have received a copy of the GNU General Public License
18141cc406Sopenharmony_ci   along with this program.  If not, see <https://www.gnu.org/licenses/>.
19141cc406Sopenharmony_ci
20141cc406Sopenharmony_ci   As a special exception, the authors of SANE give permission for
21141cc406Sopenharmony_ci   additional uses of the libraries contained in this release of SANE.
22141cc406Sopenharmony_ci
23141cc406Sopenharmony_ci   The exception is that, if you link a SANE library with other files
24141cc406Sopenharmony_ci   to produce an executable, this does not by itself cause the
25141cc406Sopenharmony_ci   resulting executable to be covered by the GNU General Public
26141cc406Sopenharmony_ci   License.  Your use of that executable is in no way restricted on
27141cc406Sopenharmony_ci   account of linking the SANE library code into it.
28141cc406Sopenharmony_ci
29141cc406Sopenharmony_ci   This exception does not, however, invalidate any other reasons why
30141cc406Sopenharmony_ci   the executable file might be covered by the GNU General Public
31141cc406Sopenharmony_ci   License.
32141cc406Sopenharmony_ci
33141cc406Sopenharmony_ci   If you submit changes to SANE to the maintainers to be included in
34141cc406Sopenharmony_ci   a subsequent release, you agree by submitting the changes that
35141cc406Sopenharmony_ci   those changes may be distributed with this exception intact.
36141cc406Sopenharmony_ci
37141cc406Sopenharmony_ci   If you write modifications of your own for SANE, it is your choice
38141cc406Sopenharmony_ci   whether to permit this exception to apply to your modifications.
39141cc406Sopenharmony_ci   If you do not wish that, delete this exception notice.
40141cc406Sopenharmony_ci*/
41141cc406Sopenharmony_ci
42141cc406Sopenharmony_ci#ifndef RTS88XX_LIB_H
43141cc406Sopenharmony_ci#define RTS88XX_LIB_H
44141cc406Sopenharmony_ci#include "../include/sane/sane.h"
45141cc406Sopenharmony_ci#include "../include/sane/sanei_usb.h"
46141cc406Sopenharmony_ci#include <unistd.h>
47141cc406Sopenharmony_ci#include <string.h>
48141cc406Sopenharmony_ci
49141cc406Sopenharmony_ci/* TODO put his in a place where it can be reused */
50141cc406Sopenharmony_ci
51141cc406Sopenharmony_ci#define DBG_error0      0	/* errors/warnings printed even with debuglevel 0 */
52141cc406Sopenharmony_ci#define DBG_error       1	/* fatal errors */
53141cc406Sopenharmony_ci#define DBG_init        2	/* initialization and scanning time messages */
54141cc406Sopenharmony_ci#define DBG_warn        3	/* warnings and non-fatal errors */
55141cc406Sopenharmony_ci#define DBG_info        4	/* informational messages */
56141cc406Sopenharmony_ci#define DBG_proc        5	/* starting/finishing functions */
57141cc406Sopenharmony_ci#define DBG_io          6	/* io functions */
58141cc406Sopenharmony_ci#define DBG_io2         7	/* io functions that are called very often */
59141cc406Sopenharmony_ci#define DBG_data        8	/* log data sent and received */
60141cc406Sopenharmony_ci
61141cc406Sopenharmony_ci/*
62141cc406Sopenharmony_ci * defines for registers name
63141cc406Sopenharmony_ci */
64141cc406Sopenharmony_ci#define CONTROL_REG             0xb3
65141cc406Sopenharmony_ci#define CONTROLER_REG           0x1d
66141cc406Sopenharmony_ci
67141cc406Sopenharmony_ci/* geometry registers */
68141cc406Sopenharmony_ci#define START_LINE		0x60
69141cc406Sopenharmony_ci#define END_LINE		0x62
70141cc406Sopenharmony_ci#define START_PIXEL		0x66
71141cc406Sopenharmony_ci#define END_PIXEL		0x6c
72141cc406Sopenharmony_ci
73141cc406Sopenharmony_ci#define RTS88XX_MAX_XFER_SIZE 0xFFC0
74141cc406Sopenharmony_ci
75141cc406Sopenharmony_ci#define LOBYTE(x)  ((uint8_t)((x) & 0xFF))
76141cc406Sopenharmony_ci#define HIBYTE(x)  ((uint8_t)((x) >> 8))
77141cc406Sopenharmony_ci
78141cc406Sopenharmony_ci/* this function init the rts88xx library */
79141cc406Sopenharmony_civoid sanei_rts88xx_lib_init (void);
80141cc406Sopenharmony_ciSANE_Bool sanei_rts88xx_is_color (SANE_Byte * regs);
81141cc406Sopenharmony_ci
82141cc406Sopenharmony_civoid sanei_rts88xx_set_gray_scan (SANE_Byte * regs);
83141cc406Sopenharmony_civoid sanei_rts88xx_set_color_scan (SANE_Byte * regs);
84141cc406Sopenharmony_civoid sanei_rts88xx_set_offset (SANE_Byte * regs, SANE_Byte red,
85141cc406Sopenharmony_ci			       SANE_Byte green, SANE_Byte blue);
86141cc406Sopenharmony_civoid sanei_rts88xx_set_gain (SANE_Byte * regs, SANE_Byte red, SANE_Byte green,
87141cc406Sopenharmony_ci			     SANE_Byte blue);
88141cc406Sopenharmony_civoid sanei_rts88xx_set_scan_frequency (SANE_Byte * regs, int frequency);
89141cc406Sopenharmony_ci
90141cc406Sopenharmony_ci/*
91141cc406Sopenharmony_ci * set scan area
92141cc406Sopenharmony_ci */
93141cc406Sopenharmony_civoid sanei_rts88xx_set_scan_area (SANE_Byte * reg, SANE_Int ystart,
94141cc406Sopenharmony_ci				  SANE_Int yend, SANE_Int xstart,
95141cc406Sopenharmony_ci				  SANE_Int xend);
96141cc406Sopenharmony_ci
97141cc406Sopenharmony_ci/*
98141cc406Sopenharmony_ci * read one register at given index
99141cc406Sopenharmony_ci */
100141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_read_reg (SANE_Int devnum, SANE_Int index,
101141cc406Sopenharmony_ci				    SANE_Byte * reg);
102141cc406Sopenharmony_ci
103141cc406Sopenharmony_ci/*
104141cc406Sopenharmony_ci * read scanned data from scanner up to the size given. The actual length read is returned.
105141cc406Sopenharmony_ci */
106141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_read_data (SANE_Int devnum, SANE_Word * length,
107141cc406Sopenharmony_ci				     unsigned char *dest);
108141cc406Sopenharmony_ci
109141cc406Sopenharmony_ci/*
110141cc406Sopenharmony_ci * write one register at given index
111141cc406Sopenharmony_ci */
112141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_write_reg (SANE_Int devnum, SANE_Int index,
113141cc406Sopenharmony_ci				     SANE_Byte * reg);
114141cc406Sopenharmony_ci
115141cc406Sopenharmony_ci/*
116141cc406Sopenharmony_ci * write length consecutive registers, starting at index
117141cc406Sopenharmony_ci * register 0xb3 is never wrote in bulk register write, so we split
118141cc406Sopenharmony_ci * write if it belongs to the register set sent
119141cc406Sopenharmony_ci */
120141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_write_regs (SANE_Int devnum, SANE_Int start,
121141cc406Sopenharmony_ci				      SANE_Byte * source, SANE_Int length);
122141cc406Sopenharmony_ci
123141cc406Sopenharmony_ci/* read several registers starting at the given index */
124141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_read_regs (SANE_Int devnum, SANE_Int start,
125141cc406Sopenharmony_ci				     SANE_Byte * dest, SANE_Int length);
126141cc406Sopenharmony_ci
127141cc406Sopenharmony_ci/*
128141cc406Sopenharmony_ci * get status by reading registers 0x10 and 0x11
129141cc406Sopenharmony_ci */
130141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_get_status (SANE_Int devnum, SANE_Byte * regs);
131141cc406Sopenharmony_ci/*
132141cc406Sopenharmony_ci * set status by writing registers 0x10 and 0x11
133141cc406Sopenharmony_ci */
134141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_set_status (SANE_Int devnum, SANE_Byte * regs,
135141cc406Sopenharmony_ci				      SANE_Byte reg10, SANE_Byte reg11);
136141cc406Sopenharmony_ci
137141cc406Sopenharmony_ci/*
138141cc406Sopenharmony_ci * get lamp status by reading registers 0x84 to 0x8d
139141cc406Sopenharmony_ci */
140141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_get_lamp_status (SANE_Int devnum, SANE_Byte * regs);
141141cc406Sopenharmony_ci
142141cc406Sopenharmony_ci/* reset lamp */
143141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_reset_lamp (SANE_Int devnum, SANE_Byte * regs);
144141cc406Sopenharmony_ci
145141cc406Sopenharmony_ci/* get lcd panel status */
146141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_get_lcd (SANE_Int devnum, SANE_Byte * regs);
147141cc406Sopenharmony_ci
148141cc406Sopenharmony_ci/*
149141cc406Sopenharmony_ci * write to special control register CONTROL_REG=0xb3
150141cc406Sopenharmony_ci */
151141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_write_control (SANE_Int devnum, SANE_Byte value);
152141cc406Sopenharmony_ci
153141cc406Sopenharmony_ci/*
154141cc406Sopenharmony_ci * send the cancel control sequence
155141cc406Sopenharmony_ci */
156141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_cancel (SANE_Int devnum);
157141cc406Sopenharmony_ci
158141cc406Sopenharmony_ci/*
159141cc406Sopenharmony_ci * read available data count from scanner
160141cc406Sopenharmony_ci */
161141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_data_count (SANE_Int devnum, SANE_Word * count);
162141cc406Sopenharmony_ci
163141cc406Sopenharmony_ci/*
164141cc406Sopenharmony_ci * wait for scanned data to be available, if busy is true, check is scanner is busy
165141cc406Sopenharmony_ci * while waiting. The number of data bytes of available data is returned in 'count'.
166141cc406Sopenharmony_ci */
167141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_wait_data (SANE_Int devnum, SANE_Bool busy,
168141cc406Sopenharmony_ci				     SANE_Word * count);
169141cc406Sopenharmony_ci
170141cc406Sopenharmony_ci /*
171141cc406Sopenharmony_ci  * write the given number of bytes pointed by value into memory
172141cc406Sopenharmony_ci  */
173141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_write_mem (SANE_Int devnum, SANE_Int length,
174141cc406Sopenharmony_ci				     SANE_Int extra, SANE_Byte * value);
175141cc406Sopenharmony_ci
176141cc406Sopenharmony_ci /*
177141cc406Sopenharmony_ci  * set memory with the given data
178141cc406Sopenharmony_ci  */
179141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_set_mem (SANE_Int devnum, SANE_Byte ctrl1,
180141cc406Sopenharmony_ci				   SANE_Byte ctrl2, SANE_Int length,
181141cc406Sopenharmony_ci				   SANE_Byte * value);
182141cc406Sopenharmony_ci
183141cc406Sopenharmony_ci /*
184141cc406Sopenharmony_ci  * read the given number of bytes from memory into buffer
185141cc406Sopenharmony_ci  */
186141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_read_mem (SANE_Int devnum, SANE_Int length,
187141cc406Sopenharmony_ci				    SANE_Byte * value);
188141cc406Sopenharmony_ci
189141cc406Sopenharmony_ci /*
190141cc406Sopenharmony_ci  * get memory
191141cc406Sopenharmony_ci  */
192141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_get_mem (SANE_Int devnum, SANE_Byte ctrl1,
193141cc406Sopenharmony_ci				   SANE_Byte ctrl2, SANE_Int length,
194141cc406Sopenharmony_ci				   SANE_Byte * value);
195141cc406Sopenharmony_ci
196141cc406Sopenharmony_ci /*
197141cc406Sopenharmony_ci  * write to the nvram controller
198141cc406Sopenharmony_ci  */
199141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_nvram_ctrl (SANE_Int devnum, SANE_Int length,
200141cc406Sopenharmony_ci				      SANE_Byte * value);
201141cc406Sopenharmony_ci
202141cc406Sopenharmony_ci /*
203141cc406Sopenharmony_ci  * setup nvram
204141cc406Sopenharmony_ci  */
205141cc406Sopenharmony_ciSANE_Status sanei_rts88xx_setup_nvram (SANE_Int devnum, SANE_Int length,
206141cc406Sopenharmony_ci				       SANE_Byte * value);
207141cc406Sopenharmony_ci
208141cc406Sopenharmony_ci
209141cc406Sopenharmony_ci /* does a simple scan, putting data in image */
210141cc406Sopenharmony_ci/* SANE_Status sanei_rts88xx_simple_scan (SANE_Int devnum, SANE_Byte * regs, int regcount, SANE_Word size, unsigned char *image); */
211141cc406Sopenharmony_ci#endif /* not RTS88XX_LIB_H */
212