1 /* sane - Scanner Access Now Easy.
2
3 Copyright (C) 2000 Adrian Perez Jorge
4
5 This file is part of the SANE package.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 As a special exception, the authors of SANE give permission for
21 additional uses of the libraries contained in this release of SANE.
22
23 The exception is that, if you link a SANE library with other files
24 to produce an executable, this does not by itself cause the
25 resulting executable to be covered by the GNU General Public
26 License. Your use of that executable is in no way restricted on
27 account of linking the SANE library code into it.
28
29 This exception does not, however, invalidate any other reasons why
30 the executable file might be covered by the GNU General Public
31 License.
32
33 If you submit changes to SANE to the maintainers to be included in
34 a subsequent release, you agree by submitting the changes that
35 those changes may be distributed with this exception intact.
36
37 If you write modifications of your own for SANE, it is your choice
38 whether to permit this exception to apply to your modifications.
39 If you do not wish that, delete this exception notice.
40
41 This file implements a backend for the HP4200C flatbed scanner
42 */
43
44
45 #include "hp4200_lm9830.h"
46
47 static SANE_Status
lm9830_read_register(int fd,unsigned char reg,unsigned char * data)48 lm9830_read_register (int fd, unsigned char reg, unsigned char *data)
49 {
50 SANE_Status retval;
51
52 if (!data)
53 return -SANE_STATUS_INVAL;
54 retval = sanei_pv8630_write_byte (fd, PV8630_REPPADDRESS, reg);
55 if (retval != SANE_STATUS_GOOD)
56 return retval;
57 return sanei_pv8630_read_byte (fd, PV8630_RDATA, data);
58 }
59
60 static SANE_Status
lm9830_write_register(int fd,unsigned char reg,unsigned char value)61 lm9830_write_register (int fd, unsigned char reg, unsigned char value)
62 {
63 SANE_Status retval;
64
65 retval = sanei_pv8630_write_byte (fd, PV8630_REPPADDRESS, reg);
66 if (retval != SANE_STATUS_GOOD)
67 return retval;
68
69 return sanei_pv8630_write_byte (fd, PV8630_RDATA, value);
70 }
71
72 #ifdef DEBUG
73 static int
lm9830_dump_registers(int fd)74 lm9830_dump_registers (int fd)
75 {
76 int i;
77 unsigned char value = 0;
78
79 for (i = 0; i < 0x80; i++)
80 {
81 lm9830_read_register (fd, i, &value);
82 printf ("%.2x:0x%.2x", i, value);
83 if ((i + 1) % 8)
84 printf (", ");
85 else
86 printf ("\n");
87 }
88 puts ("");
89 return 0;
90 }
91 #endif
92
93 #if 0
94 static int
95 pv8630_reset_buttons (int fd)
96 {
97 lm9830_write_register (fd, 0x59, 0x10);
98 lm9830_write_register (fd, 0x59, 0x90);
99 return 0;
100 }
101 #endif
102
103 #if 0
104 static int
105 lm9830_lamp_off (int fd)
106 {
107 lm9830_write_register (fd, 0x07, 0x00);
108 lm9830_write_register (fd, 0x2c, 0x00);
109 lm9830_write_register (fd, 0x2d, 0x01);
110 lm9830_write_register (fd, 0x2e, 0x3f);
111 lm9830_write_register (fd, 0x2f, 0xff);
112 return 0;
113 }
114
115 static int
116 lm9830_lamp_on (int fd)
117 {
118 lm9830_write_register (fd, 0x07, 0x00);
119 lm9830_write_register (fd, 0x2c, 0x3f);
120 lm9830_write_register (fd, 0x2d, 0xff);
121 lm9830_write_register (fd, 0x2e, 0x00);
122 lm9830_write_register (fd, 0x2f, 0x01);
123 return 0;
124 }
125 #endif
126
127 #if 0
128 /*
129 * This function prints what button was pressed (the time before this
130 * code was executed).
131 */
132
133 static int
134 hp4200c_what_button (int fd)
135 {
136 unsigned char button;
137
138 pv8630_read_buttons (fd, &button);
139
140 if (button & 0x08)
141 puts ("Scan");
142 if (button & 0x10)
143 puts ("Copy");
144 if (button & 0x20)
145 puts ("E-mail");
146 if ((button & 0x38) == 0)
147 puts ("None");
148
149 pv8630_reset_buttons (fd);
150 return 0;
151 }
152 #endif
153
154 static int
lm9830_ini_scanner(int fd,unsigned char * regs)155 lm9830_ini_scanner (int fd, unsigned char *regs)
156 {
157 #ifdef unused
158 unsigned char inittable[] = {
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160 0x02, 0x1A, 0x00, 0x0A, 0x60, 0x2F, 0x13, 0x06,
161 0x17, 0x01, 0x03, 0x03, 0x05, 0x00, 0x00, 0x0B,
162 0x00, 0x00, 0x00, 0x00, 0x0D, 0x21, 0x00, 0x40,
163 0x15, 0x18, 0x00, 0x40, 0x02, 0x98, 0x00, 0x00,
164 0x00, 0x01, 0x00, 0x00, 0x3F, 0xFF, 0x00, 0x01,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x30,
166 0x25, 0x25, 0x24, 0x28, 0x24, 0x28, 0x00, 0x00,
167 0x00, 0x00, 0x06, 0x1D, 0x00, 0x13, 0x05, 0x48,
168 0x01, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x5E, 0x02,
169 0x00, 0x15, 0x00, 0x45, 0x00, 0x10, 0x08, 0x17,
170 0x2B, 0x90, 0x00, 0x00, 0x01, 0x00, 0x80, 0x00
171 };
172 #endif
173
174 unsigned char daisy[] = { 0x99, 0x66, 0xcc, 0x33 };
175 unsigned char *regdata;
176 unsigned int i;
177
178 sanei_pv8630_write_byte (fd, PV8630_RMODE, 0x02);
179 for (i = 0; i < sizeof (daisy); i++)
180 {
181 sanei_pv8630_write_byte (fd, PV8630_RDATA, daisy[i]);
182 }
183 sanei_pv8630_write_byte (fd, PV8630_RMODE, 0x16);
184 lm9830_write_register (fd, 0x42, 0x06);
185
186 if (!regs)
187 return 0;
188 /* regdata = inittable; */
189 else
190 regdata = regs;
191
192 for (i = 8; i < 0x60; i++)
193 {
194 lm9830_write_register (fd, i, regdata[i]);
195 }
196 for (i = 0x60; i < 0x70; i++)
197 {
198 lm9830_write_register (fd, i, 0);
199 }
200 lm9830_write_register (fd, 0x70, 0x70);
201 for (i = 0x71; i < 0x80; i++)
202 {
203 lm9830_write_register (fd, i, 0);
204 }
205 return 0;
206 }
207
208 static int
lm9830_reset(int fd)209 lm9830_reset (int fd)
210 {
211 lm9830_write_register (fd, 0x07, 0x08);
212 usleep (100);
213 lm9830_write_register (fd, 0x07, 0x00);
214 usleep (100);
215
216 return 0;
217 }
218