1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2000 Mustek.
4    Originally maintained by Tom Wang <tom.wang@mustek.com.tw>
5 
6    Copyright (C) 2001, 2002 by Henning Meier-Geinitz.
7 
8    This file is part of the SANE package.
9 
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2 of the
13    License, or (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <https://www.gnu.org/licenses/>.
22 
23    As a special exception, the authors of SANE give permission for
24    additional uses of the libraries contained in this release of SANE.
25 
26    The exception is that, if you link a SANE library with other files
27    to produce an executable, this does not by itself cause the
28    resulting executable to be covered by the GNU General Public
29    License.  Your use of that executable is in no way restricted on
30    account of linking the SANE library code into it.
31 
32    This exception does not, however, invalidate any other reasons why
33    the executable file might be covered by the GNU General Public
34    License.
35 
36    If you submit changes to SANE to the maintainers to be included in
37    a subsequent release, you agree by submitting the changes that
38    those changes may be distributed with this exception intact.
39 
40    If you write modifications of your own for SANE, it is your choice
41    whether to permit this exception to apply to your modifications.
42    If you do not wish that, delete this exception notice.
43 
44    This file implements a SANE backend for Mustek 1200UB and similar
45    USB flatbed scanners.  */
46 
47 #include "mustek_usb_mid.h"
48 #include "mustek_usb_low.c"
49 
50 /* ------------------ sensor NEC 3797 600 CIS functions ------------------- */
51 
52 static SANE_Word usb_mid_n600_optical_x_dpi[] =
53   { 600, 400, 300, 200, 100, 50, 0 };
54 
55 SANE_Status
usb_mid_n600_prepare_rgb_600_dpi(ma1017 * chip)56 usb_mid_n600_prepare_rgb_600_dpi (ma1017 * chip)
57 {
58   SANE_Status status;
59 
60   DBG (6, "usb_mid_n600_prepare_rgb_600_dpi: start\n");
61   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P6P6));
62   RIE (usb_low_set_soft_resample (chip, 1));
63   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
64   DBG (6, "usb_mid_n600_prepare_rgb_600_dpi: exit\n");
65   return SANE_STATUS_GOOD;
66 }
67 
68 SANE_Status
usb_mid_n600_prepare_rgb_400_dpi(ma1017 * chip)69 usb_mid_n600_prepare_rgb_400_dpi (ma1017 * chip)
70 {
71   SANE_Status status;
72 
73   DBG (6, "usb_mid_n600_prepare_rgb_400_dpi: start\n");
74   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P4P6));
75   RIE (usb_low_set_soft_resample (chip, 1));
76   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
77   DBG (6, "usb_mid_n600_prepare_rgb_400_dpi: exit\n");
78   return SANE_STATUS_GOOD;
79 }
80 
81 SANE_Status
usb_mid_n600_prepare_rgb_300_dpi(ma1017 * chip)82 usb_mid_n600_prepare_rgb_300_dpi (ma1017 * chip)
83 {
84   SANE_Status status;
85 
86   DBG (6, "usb_mid_n600_prepare_rgb_300_dpi: start\n");
87   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P3P6));
88   RIE (usb_low_set_soft_resample (chip, 1));
89   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
90   DBG (6, "usb_mid_n600_prepare_rgb_300_dpi: exit\n");
91   return SANE_STATUS_GOOD;
92 }
93 
94 SANE_Status
usb_mid_n600_prepare_rgb_200_dpi(ma1017 * chip)95 usb_mid_n600_prepare_rgb_200_dpi (ma1017 * chip)
96 {
97   SANE_Status status;
98 
99   DBG (6, "usb_mid_n600_prepare_rgb_200_dpi: start\n");
100   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P2P6));
101   RIE (usb_low_set_soft_resample (chip, 1));
102   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
103   DBG (6, "usb_mid_n600_prepare_rgb_200_dpi: exit\n");
104   return SANE_STATUS_GOOD;
105 }
106 
107 SANE_Status
usb_mid_n600_prepare_rgb_100_dpi(ma1017 * chip)108 usb_mid_n600_prepare_rgb_100_dpi (ma1017 * chip)
109 {
110   SANE_Status status;
111 
112   DBG (6, "usb_mid_n600_prepare_rgb_100_dpi: start\n");
113   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P1P6));
114   RIE (usb_low_set_soft_resample (chip, 1));
115   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
116   DBG (6, "usb_mid_n600_prepare_rgb_100_dpi: exit\n");
117   return SANE_STATUS_GOOD;
118 }
119 
120 SANE_Status
usb_mid_n600_prepare_rgb_50_dpi(ma1017 * chip)121 usb_mid_n600_prepare_rgb_50_dpi (ma1017 * chip)
122 {
123   SANE_Status status;
124 
125   DBG (6, "usb_mid_n600_prepare_rgb_50_dpi: start\n");
126   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P1P6));
127   RIE (usb_low_set_soft_resample (chip, 2));
128   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
129   DBG (6, "usb_mid_n600_prepare_rgb_50_dpi: exit\n");
130   return SANE_STATUS_GOOD;
131 }
132 
133 SANE_Status
usb_mid_n600_prepare_mono_600_dpi(ma1017 * chip)134 usb_mid_n600_prepare_mono_600_dpi (ma1017 * chip)
135 {
136   SANE_Status status;
137 
138   DBG (6, "usb_mid_n600_prepare_mono_600_dpi: start\n");
139   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P6P6));
140   RIE (usb_low_set_soft_resample (chip, 1));
141   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
142   DBG (6, "usb_mid_n600_prepare_mono_600_dpi: exit\n");
143   return SANE_STATUS_GOOD;
144 }
145 
146 SANE_Status
usb_mid_n600_prepare_mono_400_dpi(ma1017 * chip)147 usb_mid_n600_prepare_mono_400_dpi (ma1017 * chip)
148 {
149   SANE_Status status;
150 
151   DBG (6, "usb_mid_n600_prepare_mono_400_dpi: start\n");
152   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P4P6));
153   RIE (usb_low_set_soft_resample (chip, 1));
154   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
155   DBG (6, "usb_mid_n600_prepare_mono_400_dpi: exit\n");
156   return SANE_STATUS_GOOD;
157 }
158 
159 SANE_Status
usb_mid_n600_prepare_mono_300_dpi(ma1017 * chip)160 usb_mid_n600_prepare_mono_300_dpi (ma1017 * chip)
161 {
162   SANE_Status status;
163 
164   DBG (6, "usb_mid_n600_prepare_mono_300_dpi: start\n");
165   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P3P6));
166   RIE (usb_low_set_soft_resample (chip, 1));
167   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
168   DBG (6, "usb_mid_n600_prepare_mono_300_dpi: exit\n");
169   return SANE_STATUS_GOOD;
170 }
171 
172 SANE_Status
usb_mid_n600_prepare_mono_200_dpi(ma1017 * chip)173 usb_mid_n600_prepare_mono_200_dpi (ma1017 * chip)
174 {
175   SANE_Status status;
176 
177   DBG (6, "usb_mid_n600_prepare_mono_200_dpi: start\n");
178   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P2P6));
179   RIE (usb_low_set_soft_resample (chip, 1));
180   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
181   DBG (6, "usb_mid_n600_prepare_mono_200_dpi: exit\n");
182   return SANE_STATUS_GOOD;
183 }
184 
185 SANE_Status
usb_mid_n600_prepare_mono_100_dpi(ma1017 * chip)186 usb_mid_n600_prepare_mono_100_dpi (ma1017 * chip)
187 {
188   SANE_Status status;
189 
190   DBG (6, "usb_mid_n600_prepare_mono_100_dpi: start\n");
191   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P1P6));
192   RIE (usb_low_set_soft_resample (chip, 1));
193   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
194   DBG (6, "usb_mid_n600_prepare_mono_100_dpi: exit\n");
195   return SANE_STATUS_GOOD;
196 }
197 
198 SANE_Status
usb_mid_n600_prepare_mono_50_dpi(ma1017 * chip)199 usb_mid_n600_prepare_mono_50_dpi (ma1017 * chip)
200 {
201   SANE_Status status;
202 
203   DBG (6, "usb_mid_n600_prepare_mono_50_dpi: start\n");
204   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P1P6));
205   RIE (usb_low_set_soft_resample (chip, 2));
206   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
207   DBG (6, "usb_mid_n600_prepare_mono_50_dpi: exit\n");
208   return SANE_STATUS_GOOD;
209 }
210 
211 SANE_Status
usb_mid_n600_prepare_rgb(ma1017 * chip,SANE_Word dpi)212 usb_mid_n600_prepare_rgb (ma1017 * chip, SANE_Word dpi)
213 {
214   DBG (6, "usb_mid_n600_prepare_rgb: start\n");
215   switch (dpi)
216     {
217     case 50:
218       return usb_mid_n600_prepare_rgb_50_dpi (chip);
219       break;
220     case 100:
221       return usb_mid_n600_prepare_rgb_100_dpi (chip);
222       break;
223     case 200:
224       return usb_mid_n600_prepare_rgb_200_dpi (chip);
225       break;
226     case 300:
227       return usb_mid_n600_prepare_rgb_300_dpi (chip);
228       break;
229     case 400:
230       return usb_mid_n600_prepare_rgb_400_dpi (chip);
231       break;
232     case 600:
233       return usb_mid_n600_prepare_rgb_600_dpi (chip);
234       break;
235     default:
236       DBG (3, "usb_mid_n600_prepare_rgb: unmatched dpi: %d\n", dpi);
237       return SANE_STATUS_INVAL;
238       break;
239     }
240   DBG (6, "usb_mid_n600_prepare_rgb: exit\n");
241   return SANE_STATUS_GOOD;
242 }
243 
244 SANE_Status
usb_mid_n600_prepare_mono(ma1017 * chip,SANE_Word dpi)245 usb_mid_n600_prepare_mono (ma1017 * chip, SANE_Word dpi)
246 {
247   DBG (6, "usb_mid_n600_prepare_mono: start\n");
248   switch (dpi)
249     {
250     case 50:
251       return usb_mid_n600_prepare_mono_50_dpi (chip);
252       break;
253     case 100:
254       return usb_mid_n600_prepare_mono_100_dpi (chip);
255       break;
256     case 200:
257       return usb_mid_n600_prepare_mono_200_dpi (chip);
258       break;
259     case 300:
260       return usb_mid_n600_prepare_mono_300_dpi (chip);
261       break;
262     case 400:
263       return usb_mid_n600_prepare_mono_400_dpi (chip);
264       break;
265     case 600:
266       return usb_mid_n600_prepare_mono_600_dpi (chip);
267       break;
268     default:
269       DBG (6, "usb_mid_n600_prepare_mono: unmatched dpi: %d\n", dpi);
270       return SANE_STATUS_INVAL;
271       break;
272     }
273   return SANE_STATUS_GOOD;
274 }
275 
276 /* ---------------------- sensor 600 CIS functions ----------------------- */
277 
278 static SANE_Word usb_mid_c600_optical_x_dpi[] =
279   { 600, 400, 300, 200, 150, 100, 50, 0 };
280 
281 SANE_Status
usb_mid_c600_prepare_rgb_600_dpi(ma1017 * chip)282 usb_mid_c600_prepare_rgb_600_dpi (ma1017 * chip)
283 {
284   SANE_Status status;
285 
286   DBG (6, "usb_mid_c600_prepare_rgb_600_dpi: start\n");
287   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P6P6));
288   RIE (usb_low_set_soft_resample (chip, 1));
289   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
290   DBG (6, "usb_mid_c600_prepare_rgb_600_dpi: exit\n");
291   return SANE_STATUS_GOOD;
292 }
293 
294 SANE_Status
usb_mid_c600_prepare_rgb_400_dpi(ma1017 * chip)295 usb_mid_c600_prepare_rgb_400_dpi (ma1017 * chip)
296 {
297   SANE_Status status;
298 
299   DBG (6, "usb_mid_c600_prepare_rgb_400_dpi: start\n");
300   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P4P6));
301   RIE (usb_low_set_soft_resample (chip, 1));
302   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
303   DBG (6, "usb_mid_c600_prepare_rgb_400_dpi: exit\n");
304   return SANE_STATUS_GOOD;
305 }
306 
307 SANE_Status
usb_mid_c600_prepare_rgb_300_dpi(ma1017 * chip)308 usb_mid_c600_prepare_rgb_300_dpi (ma1017 * chip)
309 {
310   SANE_Status status;
311 
312   DBG (6, "usb_mid_c600_prepare_rgb_300_dpi: start\n");
313   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P3P6));
314   RIE (usb_low_set_soft_resample (chip, 1));
315   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
316   DBG (6, "usb_mid_c600_prepare_rgb_300_dpi: exit\n");
317   return SANE_STATUS_GOOD;
318 }
319 
320 SANE_Status
usb_mid_c600_prepare_rgb_200_dpi(ma1017 * chip)321 usb_mid_c600_prepare_rgb_200_dpi (ma1017 * chip)
322 {
323   SANE_Status status;
324 
325   DBG (6, "usb_mid_c600_prepare_rgb_200_dpi: start\n");
326   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P2P6));
327   RIE (usb_low_set_soft_resample (chip, 1));
328   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
329   DBG (6, "usb_mid_c600_prepare_rgb_200_dpi: exit\n");
330   return SANE_STATUS_GOOD;
331 }
332 
333 SANE_Status
usb_mid_c600_prepare_rgb_150_dpi(ma1017 * chip)334 usb_mid_c600_prepare_rgb_150_dpi (ma1017 * chip)
335 {
336   SANE_Status status;
337 
338   DBG (6, "usb_mid_c600_prepare_rgb_150_dpi: start\n");
339   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P3P6));
340   RIE (usb_low_set_soft_resample (chip, 2));
341   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
342   DBG (6, "usb_mid_c600_prepare_rgb_150_dpi: exit\n");
343   return SANE_STATUS_GOOD;
344 }
345 
346 SANE_Status
usb_mid_c600_prepare_rgb_100_dpi(ma1017 * chip)347 usb_mid_c600_prepare_rgb_100_dpi (ma1017 * chip)
348 {
349   SANE_Status status;
350 
351   DBG (6, "usb_mid_c600_prepare_rgb_100_dpi: start\n");
352   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P1P6));
353   RIE (usb_low_set_soft_resample (chip, 1));
354   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
355   DBG (6, "usb_mid_c600_prepare_rgb_100_dpi: exit\n");
356   return SANE_STATUS_GOOD;
357 }
358 
359 SANE_Status
usb_mid_c600_prepare_rgb_50_dpi(ma1017 * chip)360 usb_mid_c600_prepare_rgb_50_dpi (ma1017 * chip)
361 {
362   SANE_Status status;
363 
364   DBG (6, "usb_mid_c600_prepare_rgb_50_dpi: start\n");
365   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P1P6));
366   RIE (usb_low_set_soft_resample (chip, 2));
367   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
368   DBG (6, "usb_mid_c600_prepare_rgb_50_dpi: exit\n");
369   return SANE_STATUS_GOOD;
370 }
371 
372 SANE_Status
usb_mid_c600_prepare_mono_600_dpi(ma1017 * chip)373 usb_mid_c600_prepare_mono_600_dpi (ma1017 * chip)
374 {
375   SANE_Status status;
376 
377   DBG (6, "usb_mid_c600_prepare_mono_600_dpi: start\n");
378   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P6P6));
379   RIE (usb_low_set_soft_resample (chip, 1));
380   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
381   DBG (6, "usb_mid_c600_prepare_mono_600_dpi: exit\n");
382   return SANE_STATUS_GOOD;
383 }
384 
385 SANE_Status
usb_mid_c600_prepare_mono_400_dpi(ma1017 * chip)386 usb_mid_c600_prepare_mono_400_dpi (ma1017 * chip)
387 {
388   SANE_Status status;
389 
390   DBG (6, "usb_mid_c600_prepare_mono_400_dpi: start\n");
391   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P4P6));
392   RIE (usb_low_set_soft_resample (chip, 1));
393   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
394   DBG (6, "usb_mid_c600_prepare_mono_400_dpi: exit\n");
395   return SANE_STATUS_GOOD;
396 }
397 
398 SANE_Status
usb_mid_c600_prepare_mono_300_dpi(ma1017 * chip)399 usb_mid_c600_prepare_mono_300_dpi (ma1017 * chip)
400 {
401   SANE_Status status;
402 
403   DBG (6, "usb_mid_c600_prepare_mono_300_dpi: start\n");
404   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P3P6));
405   RIE (usb_low_set_soft_resample (chip, 1));
406   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
407   DBG (6, "usb_mid_c600_prepare_mono_300_dpi: exit\n");
408   return SANE_STATUS_GOOD;
409 }
410 
411 SANE_Status
usb_mid_c600_prepare_mono_200_dpi(ma1017 * chip)412 usb_mid_c600_prepare_mono_200_dpi (ma1017 * chip)
413 {
414   SANE_Status status;
415 
416   DBG (6, "usb_mid_c600_prepare_mono_200_dpi: start\n");
417   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P2P6));
418   RIE (usb_low_set_soft_resample (chip, 1));
419   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
420   DBG (6, "usb_mid_c600_prepare_mono_200_dpi: exit\n");
421   return SANE_STATUS_GOOD;
422 }
423 
424 SANE_Status
usb_mid_c600_prepare_mono_150_dpi(ma1017 * chip)425 usb_mid_c600_prepare_mono_150_dpi (ma1017 * chip)
426 {
427   SANE_Status status;
428 
429   DBG (6, "usb_mid_c600_prepare_mono_150_dpi: start\n");
430   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P3P6));
431   RIE (usb_low_set_soft_resample (chip, 2));
432   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
433   DBG (6, "usb_mid_c600_prepare_mono_150_dpi: exit\n");
434   return SANE_STATUS_GOOD;
435 }
436 
437 SANE_Status
usb_mid_c600_prepare_mono_100_dpi(ma1017 * chip)438 usb_mid_c600_prepare_mono_100_dpi (ma1017 * chip)
439 {
440   SANE_Status status;
441 
442   DBG (6, "usb_mid_c600_prepare_mono_100_dpi: start\n");
443   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P1P6));
444   RIE (usb_low_set_soft_resample (chip, 1));
445   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
446   DBG (6, "usb_mid_c600_prepare_mono_100_dpi: exit\n");
447   return SANE_STATUS_GOOD;
448 }
449 
450 SANE_Status
usb_mid_c600_prepare_mono_50_dpi(ma1017 * chip)451 usb_mid_c600_prepare_mono_50_dpi (ma1017 * chip)
452 {
453   SANE_Status status;
454 
455   DBG (6, "usb_mid_c600_prepare_mono_50_dpi: start\n");
456   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P1P6));
457   RIE (usb_low_set_soft_resample (chip, 2));
458   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
459   DBG (6, "usb_mid_c600_prepare_mono_50_dpi: exit\n");
460   return SANE_STATUS_GOOD;
461 }
462 
463 SANE_Status
usb_mid_c600_prepare_rgb(ma1017 * chip,SANE_Word dpi)464 usb_mid_c600_prepare_rgb (ma1017 * chip, SANE_Word dpi)
465 {
466   DBG (6, "usb_mid_c600_prepare_rgb: start\n");
467   switch (dpi)
468     {
469     case 50:
470       return usb_mid_c600_prepare_rgb_50_dpi (chip);
471       break;
472     case 100:
473       return usb_mid_c600_prepare_rgb_100_dpi (chip);
474       break;
475     case 150:
476       return usb_mid_c600_prepare_rgb_150_dpi (chip);
477       break;
478     case 200:
479       return usb_mid_c600_prepare_rgb_200_dpi (chip);
480       break;
481     case 300:
482       return usb_mid_c600_prepare_rgb_300_dpi (chip);
483       break;
484     case 400:
485       return usb_mid_c600_prepare_rgb_400_dpi (chip);
486       break;
487     case 600:
488       return usb_mid_c600_prepare_rgb_600_dpi (chip);
489       break;
490     default:
491       DBG (3, "usb_mid_c600_prepare_rgb: unmatched dpi: %d\n", dpi);
492       return SANE_STATUS_INVAL;
493       break;
494     }
495   DBG (6, "usb_mid_c600_prepare_rgb: exit\n");
496   return SANE_STATUS_GOOD;
497 }
498 
499 SANE_Status
usb_mid_c600_prepare_mono(ma1017 * chip,SANE_Word dpi)500 usb_mid_c600_prepare_mono (ma1017 * chip, SANE_Word dpi)
501 {
502   DBG (6, "usb_mid_c600_prepare_mono: start\n");
503   switch (dpi)
504     {
505     case 50:
506       return usb_mid_c600_prepare_mono_50_dpi (chip);
507       break;
508     case 100:
509       return usb_mid_c600_prepare_mono_100_dpi (chip);
510       break;
511     case 150:
512       return usb_mid_c600_prepare_mono_150_dpi (chip);
513       break;
514     case 200:
515       return usb_mid_c600_prepare_mono_200_dpi (chip);
516       break;
517     case 300:
518       return usb_mid_c600_prepare_mono_300_dpi (chip);
519       break;
520     case 400:
521       return usb_mid_c600_prepare_mono_400_dpi (chip);
522       break;
523     case 600:
524       return usb_mid_c600_prepare_mono_600_dpi (chip);
525       break;
526     default:
527       DBG (6, "usb_mid_c600_prepare_mono: unmatched dpi: %d\n", dpi);
528       return SANE_STATUS_INVAL;
529       break;
530     }
531   return SANE_STATUS_GOOD;
532 }
533 
534 
535 
536 /* ------------------- sensor 300/600 CIS functions ----------------------- */
537 
538 
539 static SANE_Word usb_mid_c300600_optical_x_dpi[] =
540   { 600, 400, 300, 200, 150, 100, 50, 0 };
541 
542 SANE_Status
usb_mid_c300600_prepare_rgb_600_dpi(ma1017 * chip)543 usb_mid_c300600_prepare_rgb_600_dpi (ma1017 * chip)
544 {
545   SANE_Status status;
546 
547   DBG (6, "usb_mid_c300600_prepare_rgb_600_dpi: start\n");
548   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P6P6));
549   RIE (usb_low_set_soft_resample (chip, 1));
550   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
551   DBG (6, "usb_mid_c300600_prepare_rgb_600_dpi: exit\n");
552   return SANE_STATUS_GOOD;
553 }
554 
555 SANE_Status
usb_mid_c300600_prepare_rgb_400_dpi(ma1017 * chip)556 usb_mid_c300600_prepare_rgb_400_dpi (ma1017 * chip)
557 {
558   SANE_Status status;
559 
560   DBG (6, "usb_mid_c300600_prepare_rgb_400_dpi: start\n");
561   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P4P6));
562   RIE (usb_low_set_soft_resample (chip, 1));
563   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
564   DBG (6, "usb_mid_c300600_prepare_rgb_400_dpi: exit\n");
565   return SANE_STATUS_GOOD;
566 }
567 
568 SANE_Status
usb_mid_c300600_prepare_rgb_300_dpi(ma1017 * chip)569 usb_mid_c300600_prepare_rgb_300_dpi (ma1017 * chip)
570 {
571   SANE_Status status;
572 
573   DBG (6, "usb_mid_c300600_prepare_rgb_300_dpi: start\n");
574   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P6P6));
575   RIE (usb_low_set_soft_resample (chip, 1));
576   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
577   DBG (6, "usb_mid_c300600_prepare_rgb_300_dpi: exit\n");
578   return SANE_STATUS_GOOD;
579 }
580 
581 SANE_Status
usb_mid_c300600_prepare_rgb_200_dpi(ma1017 * chip)582 usb_mid_c300600_prepare_rgb_200_dpi (ma1017 * chip)
583 {
584   SANE_Status status;
585 
586   DBG (6, "usb_mid_c300600_prepare_rgb_200_dpi: start\n");
587   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P2P6));
588   RIE (usb_low_set_soft_resample (chip, 1));
589   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
590   DBG (6, "usb_mid_c300600_prepare_rgb_200_dpi: exit\n");
591   return SANE_STATUS_GOOD;
592 }
593 
594 
595 SANE_Status
usb_mid_c300600_prepare_rgb_150_dpi(ma1017 * chip)596 usb_mid_c300600_prepare_rgb_150_dpi (ma1017 * chip)
597 {
598   SANE_Status status;
599 
600   DBG (6, "usb_mid_c300600_prepare_rgb_150_dpi: start\n");
601   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P3P6));
602   RIE (usb_low_set_soft_resample (chip, 1));
603   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
604   DBG (6, "usb_mid_c300600_prepare_rgb_150_dpi: exit\n");
605   return SANE_STATUS_GOOD;
606 }
607 
608 SANE_Status
usb_mid_c300600_prepare_rgb_100_dpi(ma1017 * chip)609 usb_mid_c300600_prepare_rgb_100_dpi (ma1017 * chip)
610 {
611   SANE_Status status;
612 
613   DBG (6, "usb_mid_c300600_prepare_rgb_100_dpi: start\n");
614   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P2P6));
615   RIE (usb_low_set_soft_resample (chip, 1));
616   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
617   DBG (6, "usb_mid_c300600_prepare_rgb_100_dpi: exit\n");
618   return SANE_STATUS_GOOD;
619 }
620 
621 SANE_Status
usb_mid_c300600_prepare_rgb_50_dpi(ma1017 * chip)622 usb_mid_c300600_prepare_rgb_50_dpi (ma1017 * chip)
623 {
624   SANE_Status status;
625 
626   DBG (6, "usb_mid_c300600_prepare_rgb_50_dpi: start\n");
627   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P1P6));
628   RIE (usb_low_set_soft_resample (chip, 1));
629   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
630   DBG (6, "usb_mid_c300600_prepare_rgb_50_dpi: exit\n");
631   return SANE_STATUS_GOOD;
632 }
633 
634 SANE_Status
usb_mid_c300600_prepare_mono_600_dpi(ma1017 * chip)635 usb_mid_c300600_prepare_mono_600_dpi (ma1017 * chip)
636 {
637   SANE_Status status;
638 
639   DBG (6, "usb_mid_c300600_prepare_mono_600_dpi: start\n");
640   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P6P6));
641   RIE (usb_low_set_soft_resample (chip, 1));
642   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
643   DBG (6, "usb_mid_c300600_prepare_mono_600_dpi: exit\n");
644   return SANE_STATUS_GOOD;
645 }
646 
647 SANE_Status
usb_mid_c300600_prepare_mono_400_dpi(ma1017 * chip)648 usb_mid_c300600_prepare_mono_400_dpi (ma1017 * chip)
649 {
650   SANE_Status status;
651 
652   DBG (6, "usb_mid_c300600_prepare_mono_400_dpi: start\n");
653   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P4P6));
654   RIE (usb_low_set_soft_resample (chip, 1));
655   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
656   DBG (6, "usb_mid_c300600_prepare_mono_400_dpi: exit\n");
657   return SANE_STATUS_GOOD;
658 }
659 
660 SANE_Status
usb_mid_c300600_prepare_mono_300_dpi(ma1017 * chip)661 usb_mid_c300600_prepare_mono_300_dpi (ma1017 * chip)
662 {
663   SANE_Status status;
664 
665   DBG (6, "usb_mid_c300600_prepare_mono_300_dpi: start\n");
666   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P6P6));
667   RIE (usb_low_set_soft_resample (chip, 1));
668   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
669   DBG (6, "usb_mid_c300600_prepare_mono_300_dpi: exit\n");
670   return SANE_STATUS_GOOD;
671 }
672 
673 SANE_Status
usb_mid_c300600_prepare_mono_200_dpi(ma1017 * chip)674 usb_mid_c300600_prepare_mono_200_dpi (ma1017 * chip)
675 {
676   SANE_Status status;
677 
678   DBG (6, "usb_mid_c300600_prepare_mono_200_dpi: start\n");
679   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P2P6));
680   RIE (usb_low_set_soft_resample (chip, 1));
681   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
682   DBG (6, "usb_mid_c300600_prepare_mono_200_dpi: exit\n");
683   return SANE_STATUS_GOOD;
684 }
685 
686 SANE_Status
usb_mid_c300600_prepare_mono_150_dpi(ma1017 * chip)687 usb_mid_c300600_prepare_mono_150_dpi (ma1017 * chip)
688 {
689   SANE_Status status;
690 
691   DBG (6, "usb_mid_c300600_prepare_mono_150_dpi: start\n");
692   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P3P6));
693   RIE (usb_low_set_soft_resample (chip, 1));
694   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
695   DBG (6, "usb_mid_c300600_prepare_mono_150_dpi: exit\n");
696   return SANE_STATUS_GOOD;
697 }
698 
699 SANE_Status
usb_mid_c300600_prepare_mono_100_dpi(ma1017 * chip)700 usb_mid_c300600_prepare_mono_100_dpi (ma1017 * chip)
701 {
702   SANE_Status status;
703 
704   DBG (6, "usb_mid_c300600_prepare_mono_100_dpi: start\n");
705   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P2P6));
706   RIE (usb_low_set_soft_resample (chip, 1));
707   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
708   DBG (6, "usb_mid_c300600_prepare_mono_100_dpi: exit\n");
709   return SANE_STATUS_GOOD;
710 }
711 
712 SANE_Status
usb_mid_c300600_prepare_mono_50_dpi(ma1017 * chip)713 usb_mid_c300600_prepare_mono_50_dpi (ma1017 * chip)
714 {
715   SANE_Status status;
716 
717   DBG (6, "usb_mid_c300600_prepare_mono_50_dpi: start\n");
718   RIE (usb_low_set_image_dpi (chip, SANE_FALSE, SW_P1P6));
719   RIE (usb_low_set_soft_resample (chip, 1));
720   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
721   DBG (6, "usb_mid_c300600_prepare_mono_50_dpi: exit\n");
722   return SANE_STATUS_GOOD;
723 }
724 
725 SANE_Status
usb_mid_c300600_prepare_rgb(ma1017 * chip,SANE_Word dpi)726 usb_mid_c300600_prepare_rgb (ma1017 * chip, SANE_Word dpi)
727 {
728   DBG (6, "usb_mid_c300600_prepare_rgb: start\n");
729   switch (dpi)
730     {
731     case 50:
732       return usb_mid_c300600_prepare_rgb_50_dpi (chip);
733       break;
734     case 100:
735       return usb_mid_c300600_prepare_rgb_100_dpi (chip);
736       break;
737     case 150:
738       return usb_mid_c300600_prepare_rgb_150_dpi (chip);
739       break;
740     case 200:
741       return usb_mid_c300600_prepare_rgb_200_dpi (chip);
742       break;
743     case 300:
744       return usb_mid_c300600_prepare_rgb_300_dpi (chip);
745       break;
746     case 400:
747       return usb_mid_c300600_prepare_rgb_400_dpi (chip);
748       break;
749     case 600:
750       return usb_mid_c300600_prepare_rgb_600_dpi (chip);
751       break;
752     default:
753       DBG (3, "usb_mid_c300600_prepare_rgb: unmatched dpi: %d\n", dpi);
754       return SANE_STATUS_INVAL;
755       break;
756     }
757   return SANE_STATUS_GOOD;
758 }
759 
760 SANE_Status
usb_mid_c300600_prepare_mono(ma1017 * chip,SANE_Word dpi)761 usb_mid_c300600_prepare_mono (ma1017 * chip, SANE_Word dpi)
762 {
763   switch (dpi)
764     {
765     case 50:
766       return usb_mid_c300600_prepare_mono_50_dpi (chip);
767       break;
768     case 100:
769       return usb_mid_c300600_prepare_mono_100_dpi (chip);
770       break;
771     case 150:
772       return usb_mid_c300600_prepare_mono_150_dpi (chip);
773       break;
774     case 200:
775       return usb_mid_c300600_prepare_mono_200_dpi (chip);
776       break;
777     case 300:
778       return usb_mid_c300600_prepare_mono_300_dpi (chip);
779       break;
780     case 400:
781       return usb_mid_c300600_prepare_mono_400_dpi (chip);
782       break;
783     case 600:
784       return usb_mid_c300600_prepare_mono_600_dpi (chip);
785       break;
786     default:
787       DBG (3, "usb_mid_c300600_prepare_mono: unmatched dpi: %d\n", dpi);
788       return SANE_STATUS_INVAL;
789       break;
790     }
791   return SANE_STATUS_GOOD;
792 }
793 
794 /* ---------------------- sensor 300 CIS functions ----------------------- */
795 
796 static SANE_Word usb_mid_c300_optical_x_dpi[] = { 300, 200, 150, 100, 50, 0 };
797 
798 SANE_Status
usb_mid_c300_prepare_rgb_300_dpi(ma1017 * chip)799 usb_mid_c300_prepare_rgb_300_dpi (ma1017 * chip)
800 {
801   SANE_Status status;
802 
803   DBG (6, "usb_mid_c300_prepare_rgb_300_dpi: start\n");
804   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P6P6));
805   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
806   DBG (6, "usb_mid_c300_prepare_rgb_300_dpi: exit\n");
807   return SANE_STATUS_GOOD;
808 }
809 
810 SANE_Status
usb_mid_c300_prepare_rgb_200_dpi(ma1017 * chip)811 usb_mid_c300_prepare_rgb_200_dpi (ma1017 * chip)
812 {
813   SANE_Status status;
814 
815   DBG (6, "usb_mid_c300_prepare_rgb_200_dpi: start\n");
816   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P4P6));
817   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
818   DBG (6, "usb_mid_c300_prepare_rgb_200_dpi: exit\n");
819   return SANE_STATUS_GOOD;
820 }
821 
822 SANE_Status
usb_mid_c300_prepare_rgb_150_dpi(ma1017 * chip)823 usb_mid_c300_prepare_rgb_150_dpi (ma1017 * chip)
824 {
825   SANE_Status status;
826 
827   DBG (6, "usb_mid_c300_prepare_rgb_150_dpi: start\n");
828   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P3P6));
829   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
830   DBG (6, "usb_mid_c300_prepare_rgb_150_dpi: exit\n");
831   return SANE_STATUS_GOOD;
832 }
833 
834 SANE_Status
usb_mid_c300_prepare_rgb_100_dpi(ma1017 * chip)835 usb_mid_c300_prepare_rgb_100_dpi (ma1017 * chip)
836 {
837   SANE_Status status;
838 
839   DBG (6, "usb_mid_c300_prepare_rgb_100_dpi: start\n");
840   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P2P6));
841   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
842   DBG (6, "usb_mid_c300_prepare_rgb_100_dpi: exit\n");
843   return SANE_STATUS_GOOD;
844 }
845 
846 SANE_Status
usb_mid_c300_prepare_rgb_50_dpi(ma1017 * chip)847 usb_mid_c300_prepare_rgb_50_dpi (ma1017 * chip)
848 {
849   SANE_Status status;
850 
851   DBG (6, "usb_mid_c300_prepare_rgb_50_dpi: start\n");
852   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P1P6));
853   RIE (usb_low_set_led_light_all (chip, SANE_FALSE));
854   DBG (6, "usb_mid_c300_prepare_rgb_50_dpi: start\n");
855   return SANE_STATUS_GOOD;
856 }
857 
858 SANE_Status
usb_mid_c300_prepare_mono_300_dpi(ma1017 * chip)859 usb_mid_c300_prepare_mono_300_dpi (ma1017 * chip)
860 {
861   SANE_Status status;
862 
863   DBG (6, "usb_mid_c300_prepare_mono_300_dpi: start\n");
864   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P6P6));
865   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
866   DBG (6, "usb_mid_c300_prepare_mono_300_dpi: exit\n");
867   return SANE_STATUS_GOOD;
868 }
869 
870 SANE_Status
usb_mid_c300_prepare_mono_200_dpi(ma1017 * chip)871 usb_mid_c300_prepare_mono_200_dpi (ma1017 * chip)
872 {
873   SANE_Status status;
874 
875   DBG (6, "usb_mid_c300_prepare_mono_200_dpi: start\n");
876   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P4P6));
877   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
878   DBG (6, "usb_mid_c300_prepare_mono_200_dpi: exit\n");
879   return SANE_STATUS_GOOD;
880 }
881 
882 SANE_Status
usb_mid_c300_prepare_mono_150_dpi(ma1017 * chip)883 usb_mid_c300_prepare_mono_150_dpi (ma1017 * chip)
884 {
885   SANE_Status status;
886 
887   DBG (6, "usb_mid_c300_prepare_mono_150_dpi: start\n");
888   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P3P6));
889   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
890   DBG (6, "usb_mid_c300_prepare_mono_150_dpi: exit\n");
891   return SANE_STATUS_GOOD;
892 }
893 
894 SANE_Status
usb_mid_c300_prepare_mono_100_dpi(ma1017 * chip)895 usb_mid_c300_prepare_mono_100_dpi (ma1017 * chip)
896 {
897   SANE_Status status;
898 
899   DBG (6, "usb_mid_c300_prepare_mono_100_dpi: start\n");
900   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P2P6));
901   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
902   DBG (6, "usb_mid_c300_prepare_mono_100_dpi: exit\n");
903   return SANE_STATUS_GOOD;
904 }
905 
906 SANE_Status
usb_mid_c300_prepare_mono_50_dpi(ma1017 * chip)907 usb_mid_c300_prepare_mono_50_dpi (ma1017 * chip)
908 {
909   SANE_Status status;
910 
911   DBG (6, "usb_mid_c300_prepare_mono_50_dpi: start\n");
912   RIE (usb_low_set_image_dpi (chip, SANE_TRUE, SW_P1P6));
913   RIE (usb_low_set_led_light_all (chip, SANE_TRUE));
914   DBG (6, "usb_mid_c300_prepare_mono_50_dpi: exit\n");
915   return SANE_STATUS_GOOD;
916 }
917 
918 SANE_Status
usb_mid_c300_prepare_rgb(ma1017 * chip,SANE_Word dpi)919 usb_mid_c300_prepare_rgb (ma1017 * chip, SANE_Word dpi)
920 {
921   DBG (6, "usb_mid_c300_prepare_rgb: start\n");
922   switch (dpi)
923     {
924     case 50:
925       return usb_mid_c300_prepare_rgb_50_dpi (chip);
926       break;
927     case 100:
928       return usb_mid_c300_prepare_rgb_100_dpi (chip);
929       break;
930     case 150:
931       return usb_mid_c300_prepare_rgb_150_dpi (chip);
932       break;
933     case 200:
934       return usb_mid_c300_prepare_rgb_200_dpi (chip);
935       break;
936     case 300:
937       return usb_mid_c300_prepare_rgb_300_dpi (chip);
938       break;
939     default:
940       DBG (3, "usb_mid_c300_prepare_rgb: unmatched dpi: %d\n", dpi);
941       return SANE_STATUS_INVAL;
942       break;
943     }
944   return SANE_STATUS_GOOD;
945 }
946 
947 SANE_Status
usb_mid_c300_prepare_mono(ma1017 * chip,SANE_Word dpi)948 usb_mid_c300_prepare_mono (ma1017 * chip, SANE_Word dpi)
949 {
950   DBG (6, "usb_mid_c300_prepare_mono: start\n");
951   switch (dpi)
952     {
953     case 50:
954       return usb_mid_c300_prepare_mono_50_dpi (chip);
955       break;
956     case 100:
957       return usb_mid_c300_prepare_mono_100_dpi (chip);
958       break;
959     case 150:
960       return usb_mid_c300_prepare_mono_150_dpi (chip);
961       break;
962     case 200:
963       return usb_mid_c300_prepare_mono_200_dpi (chip);
964       break;
965     case 300:
966       return usb_mid_c300_prepare_mono_300_dpi (chip);
967       break;
968     default:
969       DBG (3, "usb_mid_c300_prepare_mono: unmatched dpi: %d\n", dpi);
970       return SANE_STATUS_INVAL;
971       break;
972     }
973   return SANE_STATUS_GOOD;
974 }
975 
976 /* -------------------------- sensor functions ---------------------------- */
977 
978 SANE_Bool
usb_mid_sensor_is600_mode(ma1017 * chip,SANE_Word dpi)979 usb_mid_sensor_is600_mode (ma1017 * chip, SANE_Word dpi)
980 {
981   if (chip->sensor == ST_CANON300)
982     {
983       DBG (6, "usb_mid_sensor_is600_mode: chip=%p, dpi=%d, FALSE\n",
984 	   (void *) chip, dpi);
985       return SANE_FALSE;
986     }
987   else if ((chip->sensor == ST_CANON600) || (chip->sensor == ST_NEC600))
988     {
989       DBG (6, "usb_mid_sensor_is600_mode: chip=%p, dpi=%d, TRUE\n",
990 	   (void *) chip, dpi);
991       return SANE_TRUE;
992     }
993   else
994     {
995       switch (dpi)
996 	{
997 	case 300:
998 	case 150:
999 	case 100:
1000 	case 50:
1001 	  DBG (6, "usb_mid_sensor_is600_mode: chip=%p, dpi=%d, FALSE\n",
1002 	       (void *) chip, dpi);
1003 	  return SANE_FALSE;
1004 	case 600:
1005 	case 400:
1006 	case 200:
1007 	  DBG (6, "usb_mid_sensor_is600_mode: chip=%p, dpi=%d, TRUE\n",
1008 	       (void *) chip, dpi);
1009 	  return SANE_TRUE;
1010 	default:
1011 	  DBG (3, "usb_mid_sensor_is600_mode: unmatched dpi: %d\n", dpi);
1012 	  return SANE_FALSE;
1013 	  break;
1014 	}
1015 
1016     }
1017 
1018   return SANE_FALSE;
1019 }
1020 
1021 static SANE_Status
usb_mid_sensor_prepare_rgb(ma1017 * chip,SANE_Word dpi)1022 usb_mid_sensor_prepare_rgb (ma1017 * chip, SANE_Word dpi)
1023 {
1024   if (chip->sensor == ST_CANON300)
1025     return usb_mid_c300_prepare_rgb (chip, dpi);
1026   else if (chip->sensor == ST_CANON600)
1027     return usb_mid_c600_prepare_rgb (chip, dpi);
1028   else if (chip->sensor == ST_NEC600)
1029     return usb_mid_n600_prepare_rgb (chip, dpi);
1030   else
1031     return usb_mid_c300600_prepare_rgb (chip, dpi);
1032 
1033   return SANE_STATUS_INVAL;
1034 }
1035 
1036 static SANE_Status
usb_mid_sensor_prepare_mono(ma1017 * chip,SANE_Word dpi)1037 usb_mid_sensor_prepare_mono (ma1017 * chip, SANE_Word dpi)
1038 {
1039   if (chip->sensor == ST_CANON300)
1040     return usb_mid_c300_prepare_mono (chip, dpi);
1041   else if (chip->sensor == ST_CANON600)
1042     return usb_mid_c600_prepare_mono (chip, dpi);
1043   else if (chip->sensor == ST_NEC600)
1044     return usb_mid_n600_prepare_mono (chip, dpi);
1045   else
1046     return usb_mid_c300600_prepare_mono (chip, dpi);
1047 
1048   return SANE_STATUS_INVAL;
1049 }
1050 
1051 static SANE_Status
usb_mid_sensor_get_dpi(ma1017 * chip,SANE_Word wanted_dpi,SANE_Word * dpi)1052 usb_mid_sensor_get_dpi (ma1017 * chip, SANE_Word wanted_dpi, SANE_Word * dpi)
1053 {
1054   SANE_Word *dpi_list;
1055   SANE_Word i;
1056 
1057   if (!dpi)
1058     return SANE_STATUS_INVAL;
1059 
1060   DBG (5, "usb_mid_sensor_get_dpi: chip->sensor=%d\n", chip->sensor);
1061 
1062   if (chip->sensor == ST_CANON300)
1063     dpi_list = usb_mid_c300_optical_x_dpi;
1064   else if (chip->sensor == ST_CANON300600)
1065     dpi_list = usb_mid_c300600_optical_x_dpi;
1066   else if (chip->sensor == ST_CANON600)
1067     dpi_list = usb_mid_c600_optical_x_dpi;
1068   else if (chip->sensor == ST_NEC600)
1069     dpi_list = usb_mid_n600_optical_x_dpi;
1070   else
1071     return SANE_STATUS_INVAL;
1072 
1073   for (i = 0; dpi_list[i] != 0; i++)
1074     {
1075       if (wanted_dpi > dpi_list[i])
1076 	break;
1077     }
1078   if (i)
1079     i--;
1080   *dpi = dpi_list[i];
1081   DBG (5, "usb_mid_sensor_get_dpi: wanted %d dpi, got %d dpi\n", wanted_dpi,
1082        *dpi);
1083   return SANE_STATUS_GOOD;
1084 }
1085 
1086 
1087 /* ---------------1200 dpi motor function declarations --------------------- */
1088 
1089 static SANE_Word usb_mid_motor1200_optical_dpi[] =
1090   { 1200, 600, 400, 300, 200, 150, 100, 50, 0 };
1091 
1092 SANE_Status
usb_mid_motor1200_prepare_rgb_1200_dpi(ma1017 * chip)1093 usb_mid_motor1200_prepare_rgb_1200_dpi (ma1017 * chip)
1094 {
1095   SANE_Status status;
1096 
1097   DBG (6, "usb_mid_motor1200_prepare_rgb_1200_dpi: start\n");
1098   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1099   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_FALSE, SANE_TRUE));
1100   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1101   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1102   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1103   RIE (usb_low_set_cmt_table_length (chip, 4));
1104   RIE (usb_low_set_cmt_second_position (chip, 0));
1105   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1106   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1107   RIE (usb_low_set_io_3 (chip, SANE_FALSE));
1108   DBG (6, "usb_mid_motor1200_prepare_rgb_1200_dpi: exit\n");
1109   return SANE_STATUS_GOOD;
1110 }
1111 
1112 
1113 SANE_Status
usb_mid_motor1200_prepare_rgb_600_dpi(ma1017 * chip)1114 usb_mid_motor1200_prepare_rgb_600_dpi (ma1017 * chip)
1115 {
1116   SANE_Status status;
1117 
1118   DBG (6, "usb_mid_motor1200_prepare_rgb_600_dpi: start\n");
1119   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1120   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_FALSE, SANE_TRUE));
1121   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1122   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1123   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1124   RIE (usb_low_set_cmt_table_length (chip, 4));
1125   RIE (usb_low_set_cmt_second_position (chip, 0));
1126   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1127   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1128   RIE (usb_low_set_io_3 (chip, SANE_FALSE));
1129   DBG (6, "usb_mid_motor1200_prepare_rgb_600_dpi: exit\n");
1130   return SANE_STATUS_GOOD;
1131 }
1132 
1133 SANE_Status
usb_mid_motor1200_prepare_rgb_400_dpi(ma1017 * chip)1134 usb_mid_motor1200_prepare_rgb_400_dpi (ma1017 * chip)
1135 {
1136   SANE_Status status;
1137 
1138   DBG (6, "usb_mid_motor1200_prepare_rgb_400_dpi: start\n");
1139   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1140   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_TRUE, SANE_TRUE));
1141   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1142   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1143   RIE (usb_low_set_cmt_table_length (chip, 3));
1144   RIE (usb_low_set_cmt_second_position (chip, 0));
1145   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1146   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1147   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1148   DBG (6, "usb_mid_motor1200_prepare_rgb_400_dpi: exit\n");
1149   return SANE_STATUS_GOOD;
1150 }
1151 
1152 SANE_Status
usb_mid_motor1200_prepare_rgb_300_dpi(ma1017 * chip)1153 usb_mid_motor1200_prepare_rgb_300_dpi (ma1017 * chip)
1154 {
1155   SANE_Status status;
1156 
1157   DBG (6, "usb_mid_motor1200_prepare_rgb_300_dpi: start\n");
1158   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1159   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_TRUE, SANE_TRUE));
1160   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1161   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_TRUE, SANE_FALSE));
1162   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1163   RIE (usb_low_set_cmt_table_length (chip, 4));
1164   RIE (usb_low_set_cmt_second_position (chip, 0));
1165   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1166   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1167   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1168   DBG (6, "usb_mid_motor1200_prepare_rgb_300_dpi: exit\n");
1169   return SANE_STATUS_GOOD;
1170 }
1171 
1172 SANE_Status
usb_mid_motor1200_prepare_rgb_200_dpi(ma1017 * chip)1173 usb_mid_motor1200_prepare_rgb_200_dpi (ma1017 * chip)
1174 {
1175   SANE_Status status;
1176 
1177   DBG (6, "usb_mid_motor1200_prepare_rgb_200_dpi: start\n");
1178   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1179   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_TRUE, SANE_TRUE));
1180   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1181   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1182   RIE (usb_low_set_cmt_table_length (chip, 3));
1183   RIE (usb_low_set_cmt_second_position (chip, 0));
1184   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1185   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1186   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1187   DBG (6, "usb_mid_motor1200_prepare_rgb_200_dpi: exit\n");
1188   return SANE_STATUS_GOOD;
1189 }
1190 
1191 
1192 
1193 SANE_Status
usb_mid_motor1200_prepare_rgb_150_dpi(ma1017 * chip)1194 usb_mid_motor1200_prepare_rgb_150_dpi (ma1017 * chip)
1195 {
1196   SANE_Status status;
1197 
1198   DBG (6, "usb_mid_motor1200_prepare_rgb_150_dpi: start\n");
1199   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1200   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_TRUE, SANE_TRUE));
1201   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1202   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_TRUE, SANE_FALSE));
1203   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1204   RIE (usb_low_set_cmt_table_length (chip, 4));
1205   RIE (usb_low_set_cmt_second_position (chip, 0));
1206   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1207   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1208   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1209   DBG (6, "usb_mid_motor1200_prepare_rgb_150_dpi: exit\n");
1210   return SANE_STATUS_GOOD;
1211 }
1212 
1213 SANE_Status
usb_mid_motor1200_prepare_rgb_100_dpi(ma1017 * chip)1214 usb_mid_motor1200_prepare_rgb_100_dpi (ma1017 * chip)
1215 {
1216   SANE_Status status;
1217 
1218   DBG (6, "usb_mid_motor1200_prepare_rgb_100_dpi: start\n");
1219   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1220   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_TRUE, SANE_TRUE));
1221   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1222   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1223   RIE (usb_low_set_cmt_table_length (chip, 3));
1224   RIE (usb_low_set_cmt_second_position (chip, 0));
1225   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1226   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1227   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1228   DBG (6, "usb_mid_motor1200_prepare_rgb_100_dpi: exit\n");
1229   return SANE_STATUS_GOOD;
1230 }
1231 
1232 SANE_Status
usb_mid_motor1200_prepare_rgb_50_dpi(ma1017 * chip)1233 usb_mid_motor1200_prepare_rgb_50_dpi (ma1017 * chip)
1234 {
1235   SANE_Status status;
1236 
1237   DBG (6, "usb_mid_motor1200_prepare_rgb_50_dpi: start\n");
1238   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1239   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1240   RIE (usb_low_set_cmt_table (chip, 2, CH_BLUE, SANE_TRUE, SANE_TRUE));
1241   RIE (usb_low_set_cmt_table (chip, 3, CH_BLUE, SANE_TRUE, SANE_FALSE));
1242   RIE (usb_low_set_cmt_table (chip, 4, CH_RED, SANE_TRUE, SANE_TRUE));
1243   RIE (usb_low_set_cmt_table (chip, 5, CH_RED, SANE_TRUE, SANE_FALSE));
1244   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_FALSE, SANE_FALSE));
1245   RIE (usb_low_set_cmt_table_length (chip, 6));
1246   RIE (usb_low_set_cmt_second_position (chip, 0));
1247   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1248   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1249   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1250   DBG (6, "usb_mid_motor1200_prepare_rgb_50_dpi: exit\n");
1251   return SANE_STATUS_GOOD;
1252 }
1253 
1254 SANE_Status
usb_mid_motor1200_prepare_mono_1200_dpi(ma1017 * chip)1255 usb_mid_motor1200_prepare_mono_1200_dpi (ma1017 * chip)
1256 {
1257   SANE_Status status;
1258 
1259   DBG (6, "usb_mid_motor1200_prepare_mono_1200_dpi: start\n");
1260   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1261   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
1262   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
1263   RIE (usb_low_set_cmt_table_length (chip, 2));
1264   RIE (usb_low_set_cmt_second_position (chip, 0));
1265   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1266   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1267   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1268   DBG (6, "usb_mid_motor1200_prepare_mono_1200_dpi: exit\n");
1269   return SANE_STATUS_GOOD;
1270 }
1271 
1272 SANE_Status
usb_mid_motor1200_prepare_mono_600_dpi(ma1017 * chip)1273 usb_mid_motor1200_prepare_mono_600_dpi (ma1017 * chip)
1274 {
1275   SANE_Status status;
1276 
1277   DBG (6, "usb_mid_motor1200_prepare_mono_600_dpi: start\n");
1278   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1279   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_FALSE, SANE_FALSE));
1280   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
1281   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1282   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1283   RIE (usb_low_set_cmt_table (chip, 5, CH_GREEN, SANE_FALSE, SANE_FALSE));
1284   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_TRUE, SANE_FALSE));
1285   RIE (usb_low_set_cmt_table (chip, 7, CH_GREEN, SANE_FALSE, SANE_FALSE));
1286   RIE (usb_low_set_cmt_table (chip, 8, CH_GREEN, SANE_FALSE, SANE_FALSE));
1287   RIE (usb_low_set_cmt_table (chip, 9, CH_GREEN, SANE_FALSE, SANE_FALSE));
1288   RIE (usb_low_set_cmt_table (chip, 10, CH_GREEN, SANE_FALSE, SANE_FALSE));
1289   RIE (usb_low_set_cmt_table (chip, 11, CH_GREEN, SANE_FALSE, SANE_FALSE));
1290   RIE (usb_low_set_cmt_table (chip, 12, CH_GREEN, SANE_TRUE, SANE_TRUE));
1291   RIE (usb_low_set_cmt_table (chip, 13, CH_GREEN, SANE_FALSE, SANE_FALSE));
1292   RIE (usb_low_set_cmt_table (chip, 14, CH_GREEN, SANE_FALSE, SANE_FALSE));
1293   RIE (usb_low_set_cmt_table (chip, 15, CH_GREEN, SANE_FALSE, SANE_FALSE));
1294   RIE (usb_low_set_cmt_table (chip, 16, CH_GREEN, SANE_TRUE, SANE_FALSE));
1295   RIE (usb_low_set_cmt_table (chip, 17, CH_GREEN, SANE_FALSE, SANE_FALSE));
1296   RIE (usb_low_set_cmt_table (chip, 18, CH_GREEN, SANE_FALSE, SANE_FALSE));
1297   RIE (usb_low_set_cmt_table (chip, 19, CH_GREEN, SANE_FALSE, SANE_FALSE));
1298   RIE (usb_low_set_cmt_table (chip, 20, CH_GREEN, SANE_TRUE, SANE_TRUE));
1299   RIE (usb_low_set_cmt_table (chip, 21, CH_GREEN, SANE_FALSE, SANE_FALSE));
1300   RIE (usb_low_set_cmt_table (chip, 22, CH_GREEN, SANE_TRUE, SANE_FALSE));
1301   RIE (usb_low_set_cmt_table (chip, 23, CH_GREEN, SANE_FALSE, SANE_FALSE));
1302   RIE (usb_low_set_cmt_table (chip, 24, CH_GREEN, SANE_TRUE, SANE_TRUE));
1303   RIE (usb_low_set_cmt_table (chip, 25, CH_GREEN, SANE_TRUE, SANE_FALSE));
1304   RIE (usb_low_set_cmt_table (chip, 26, CH_GREEN, SANE_FALSE, SANE_FALSE));
1305   RIE (usb_low_set_cmt_table_length (chip, 26));
1306   RIE (usb_low_set_cmt_second_position (chip, 24));
1307   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1308   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1309   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1310   DBG (6, "usb_mid_motor1200_prepare_mono_600_dpi: exit\n");
1311   return SANE_STATUS_GOOD;
1312 }
1313 
1314 SANE_Status
usb_mid_motor1200_prepare_mono_400_dpi(ma1017 * chip)1315 usb_mid_motor1200_prepare_mono_400_dpi (ma1017 * chip)
1316 {
1317   SANE_Status status;
1318 
1319   DBG (6, "usb_mid_motor1200_prepare_mono_400_dpi: start\n");
1320   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1321   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1322   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
1323   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1324   RIE (usb_low_set_cmt_table_length (chip, 3));
1325   RIE (usb_low_set_cmt_second_position (chip, 0));
1326   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1327   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1328   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1329   DBG (6, "usb_mid_motor1200_prepare_mono_400_dpi: exit\n");
1330   return SANE_STATUS_GOOD;
1331 }
1332 
1333 SANE_Status
usb_mid_motor1200_prepare_mono_300_dpi(ma1017 * chip)1334 usb_mid_motor1200_prepare_mono_300_dpi (ma1017 * chip)
1335 {
1336   SANE_Status status;
1337 
1338   DBG (6, "usb_mid_motor1200_prepare_mono_300_dpi: start\n");
1339   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1340   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_FALSE, SANE_FALSE));
1341   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
1342   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1343   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1344   RIE (usb_low_set_cmt_table (chip, 5, CH_GREEN, SANE_FALSE, SANE_FALSE));
1345   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_TRUE, SANE_FALSE));
1346   RIE (usb_low_set_cmt_table (chip, 7, CH_GREEN, SANE_FALSE, SANE_FALSE));
1347   RIE (usb_low_set_cmt_table (chip, 8, CH_GREEN, SANE_FALSE, SANE_FALSE));
1348   RIE (usb_low_set_cmt_table (chip, 9, CH_GREEN, SANE_FALSE, SANE_FALSE));
1349   RIE (usb_low_set_cmt_table (chip, 10, CH_GREEN, SANE_FALSE, SANE_FALSE));
1350   RIE (usb_low_set_cmt_table (chip, 11, CH_GREEN, SANE_FALSE, SANE_FALSE));
1351   RIE (usb_low_set_cmt_table (chip, 12, CH_GREEN, SANE_TRUE, SANE_TRUE));
1352   RIE (usb_low_set_cmt_table (chip, 13, CH_GREEN, SANE_FALSE, SANE_FALSE));
1353   RIE (usb_low_set_cmt_table (chip, 14, CH_GREEN, SANE_FALSE, SANE_FALSE));
1354   RIE (usb_low_set_cmt_table (chip, 15, CH_GREEN, SANE_FALSE, SANE_FALSE));
1355   RIE (usb_low_set_cmt_table (chip, 16, CH_GREEN, SANE_TRUE, SANE_FALSE));
1356   RIE (usb_low_set_cmt_table (chip, 17, CH_GREEN, SANE_FALSE, SANE_FALSE));
1357   RIE (usb_low_set_cmt_table (chip, 18, CH_GREEN, SANE_FALSE, SANE_FALSE));
1358   RIE (usb_low_set_cmt_table (chip, 19, CH_GREEN, SANE_FALSE, SANE_FALSE));
1359   RIE (usb_low_set_cmt_table (chip, 20, CH_GREEN, SANE_TRUE, SANE_TRUE));
1360   RIE (usb_low_set_cmt_table (chip, 21, CH_GREEN, SANE_FALSE, SANE_FALSE));
1361   RIE (usb_low_set_cmt_table (chip, 22, CH_GREEN, SANE_TRUE, SANE_FALSE));
1362   RIE (usb_low_set_cmt_table (chip, 23, CH_GREEN, SANE_FALSE, SANE_FALSE));
1363   RIE (usb_low_set_cmt_table (chip, 24, CH_GREEN, SANE_TRUE, SANE_TRUE));
1364   RIE (usb_low_set_cmt_table (chip, 25, CH_GREEN, SANE_TRUE, SANE_FALSE));
1365   RIE (usb_low_set_cmt_table (chip, 26, CH_GREEN, SANE_FALSE, SANE_FALSE));
1366   RIE (usb_low_set_cmt_table_length (chip, 26));
1367   RIE (usb_low_set_cmt_second_position (chip, 24));
1368   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1369   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1370   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1371   DBG (6, "usb_mid_motor1200_prepare_mono_300_dpi: exit\n");
1372   return SANE_STATUS_GOOD;
1373 }
1374 
1375 SANE_Status
usb_mid_motor1200_prepare_mono_200_dpi(ma1017 * chip)1376 usb_mid_motor1200_prepare_mono_200_dpi (ma1017 * chip)
1377 {
1378   SANE_Status status;
1379 
1380   DBG (6, "usb_mid_motor1200_prepare_mono_200_dpi: start\n");
1381   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1382   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1383   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
1384   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1385   RIE (usb_low_set_cmt_table_length (chip, 3));
1386   RIE (usb_low_set_cmt_second_position (chip, 0));
1387   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1388   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1389   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1390   DBG (6, "usb_mid_motor1200_prepare_mono_200_dpi: exit\n");
1391   return SANE_STATUS_GOOD;
1392 }
1393 
1394 
1395 SANE_Status
usb_mid_motor1200_prepare_mono_150_dpi(ma1017 * chip)1396 usb_mid_motor1200_prepare_mono_150_dpi (ma1017 * chip)
1397 {
1398   SANE_Status status;
1399 
1400   DBG (6, "usb_mid_motor1200_prepare_mono_150_dpi: start\n");
1401   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1402   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1403   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
1404   RIE (usb_low_set_cmt_table_length (chip, 2));
1405   RIE (usb_low_set_cmt_second_position (chip, 0));
1406   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1407   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1408   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1409   DBG (6, "usb_mid_motor1200_prepare_mono_150_dpi: exit\n");
1410   return SANE_STATUS_GOOD;
1411 }
1412 
1413 SANE_Status
usb_mid_motor1200_prepare_mono_100_dpi(ma1017 * chip)1414 usb_mid_motor1200_prepare_mono_100_dpi (ma1017 * chip)
1415 {
1416   SANE_Status status;
1417 
1418   DBG (6, "usb_mid_motor1200_prepare_mono_100_dpi: start\n");
1419   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1420   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1421   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
1422   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1423   RIE (usb_low_set_cmt_table_length (chip, 3));
1424   RIE (usb_low_set_cmt_second_position (chip, 0));
1425   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1426   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1427   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1428   DBG (6, "usb_mid_motor1200_prepare_mono_100_dpi: exit\n");
1429   return SANE_STATUS_GOOD;
1430 }
1431 
1432 SANE_Status
usb_mid_motor1200_prepare_mono_50_dpi(ma1017 * chip)1433 usb_mid_motor1200_prepare_mono_50_dpi (ma1017 * chip)
1434 {
1435   SANE_Status status;
1436 
1437   DBG (6, "usb_mid_motor1200_prepare_mono_50_dpi: start\n");
1438   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1439   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1440   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
1441   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_TRUE, SANE_FALSE));
1442   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_TRUE, SANE_FALSE));
1443   RIE (usb_low_set_cmt_table (chip, 5, CH_GREEN, SANE_TRUE, SANE_FALSE));
1444   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_FALSE, SANE_FALSE));
1445   RIE (usb_low_set_cmt_table_length (chip, 6));
1446   RIE (usb_low_set_cmt_second_position (chip, 0));
1447   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1448   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1449   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1450   DBG (6, "usb_mid_motor1200_prepare_mono_50_dpi: exit\n");
1451   return SANE_STATUS_GOOD;
1452 }
1453 
1454 SANE_Status
usb_mid_motor1200_prepare_rgb_half_300_dpi(ma1017 * chip)1455 usb_mid_motor1200_prepare_rgb_half_300_dpi (ma1017 * chip)
1456 {
1457   SANE_Status status;
1458 
1459   DBG (6, "usb_mid_motor1200_prepare_rgb_half_300_dpi: start\n");
1460   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1461   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_FALSE, SANE_TRUE));
1462   RIE (usb_low_set_cmt_table (chip, 2, CH_BLUE, SANE_TRUE, SANE_TRUE));
1463   RIE (usb_low_set_cmt_table (chip, 3, CH_BLUE, SANE_TRUE, SANE_TRUE));
1464   RIE (usb_low_set_cmt_table (chip, 4, CH_RED, SANE_FALSE, SANE_TRUE));
1465   RIE (usb_low_set_cmt_table (chip, 5, CH_RED, SANE_TRUE, SANE_TRUE));
1466   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_FALSE, SANE_FALSE));
1467   RIE (usb_low_set_cmt_table_length (chip, 6));
1468   RIE (usb_low_set_cmt_second_position (chip, 0));
1469   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1470   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1471   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1472   DBG (6, "usb_mid_motor1200_prepare_rgb_half_300_dpi: exit\n");
1473   return SANE_STATUS_GOOD;
1474 }
1475 
1476 SANE_Status
usb_mid_motor1200_prepare_rgb_bi_full_300_dpi(ma1017 * chip)1477 usb_mid_motor1200_prepare_rgb_bi_full_300_dpi (ma1017 * chip)
1478 {
1479   SANE_Status status;
1480 
1481   DBG (6, "usb_mid_motor1200_prepare_rgb_bi_full_300_dpi: start\n");
1482   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1483   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
1484   RIE (usb_low_set_cmt_table (chip, 2, CH_BLUE, SANE_FALSE, SANE_TRUE));
1485   RIE (usb_low_set_cmt_table (chip, 3, CH_BLUE, SANE_FALSE, SANE_TRUE));
1486   RIE (usb_low_set_cmt_table (chip, 4, CH_RED, SANE_TRUE, SANE_TRUE));
1487   RIE (usb_low_set_cmt_table (chip, 5, CH_RED, SANE_FALSE, SANE_TRUE));
1488   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_FALSE, SANE_FALSE));
1489   RIE (usb_low_set_cmt_table_length (chip, 6));
1490   RIE (usb_low_set_cmt_second_position (chip, 0));
1491   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1492   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1493   RIE (usb_low_set_io_3 (chip, SANE_FALSE));
1494   DBG (6, "usb_mid_motor1200_prepare_rgb_bi_full_300_dpi: exit\n");
1495   return SANE_STATUS_GOOD;
1496 }
1497 
1498 SANE_Status
usb_mid_motor1200_prepare_rgb_bi_full_x2300_dpi(ma1017 * chip)1499 usb_mid_motor1200_prepare_rgb_bi_full_x2300_dpi (ma1017 * chip)
1500 {
1501   SANE_Status status;
1502 
1503   DBG (6, "usb_mid_motor1200_prepare_rgb_bi_full_x2300_dpi: start\n");
1504   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1505   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_FALSE, SANE_TRUE));
1506   RIE (usb_low_set_cmt_table (chip, 2, CH_BLUE, SANE_FALSE, SANE_TRUE));
1507   RIE (usb_low_set_cmt_table (chip, 3, CH_BLUE, SANE_FALSE, SANE_TRUE));
1508   RIE (usb_low_set_cmt_table (chip, 4, CH_RED, SANE_FALSE, SANE_TRUE));
1509   RIE (usb_low_set_cmt_table (chip, 5, CH_RED, SANE_TRUE, SANE_TRUE));
1510   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_FALSE, SANE_FALSE));
1511   RIE (usb_low_set_cmt_table_length (chip, 6));
1512   RIE (usb_low_set_cmt_second_position (chip, 0));
1513   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1514   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1515   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1516   DBG (6, "usb_mid_motor1200_prepare_rgb_bi_full_x2300_dpi: exit\n");
1517   return SANE_STATUS_GOOD;
1518 }
1519 
1520 SANE_Status
usb_mid_motor1200_prepare_mono_half_300_dpi(ma1017 * chip)1521 usb_mid_motor1200_prepare_mono_half_300_dpi (ma1017 * chip)
1522 {
1523   SANE_Status status;
1524 
1525   DBG (6, "usb_mid_motor1200_prepare_mono_half_300_dpi: start\n");
1526   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1527   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1528   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
1529   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_TRUE, SANE_FALSE));
1530   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1531   RIE (usb_low_set_cmt_table_length (chip, 4));
1532   RIE (usb_low_set_cmt_second_position (chip, 0));
1533   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1534   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1535   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1536   DBG (6, "usb_mid_motor1200_prepare_mono_half_300_dpi: exit\n");
1537   return SANE_STATUS_GOOD;
1538 
1539 }
1540 
1541 SANE_Status
usb_mid_motor1200_prepare_mono_bi_full_300_dpi(ma1017 * chip)1542 usb_mid_motor1200_prepare_mono_bi_full_300_dpi (ma1017 * chip)
1543 {
1544   SANE_Status status;
1545 
1546   DBG (6, "usb_mid_motor1200_prepare_mono_bi_full_300_dpi: start\n");
1547   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1548   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1549   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
1550   RIE (usb_low_set_cmt_table_length (chip, 2));
1551   RIE (usb_low_set_cmt_second_position (chip, 0));
1552   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1553   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1554   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1555   DBG (6, "usb_mid_motor1200_prepare_mono_bi_full_300_dpi: exit\n");
1556   return SANE_STATUS_GOOD;
1557 }
1558 
1559 SANE_Status
usb_mid_motor1200_prepare_mono_bi_full_x2300_dpi(ma1017 * chip)1560 usb_mid_motor1200_prepare_mono_bi_full_x2300_dpi (ma1017 * chip)
1561 {
1562   SANE_Status status;
1563 
1564   DBG (6, "usb_mid_motor1200_prepare_mono_bi_full_x2300_dpi: start\n");
1565   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1566   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
1567   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
1568   RIE (usb_low_set_cmt_table_length (chip, 2));
1569   RIE (usb_low_set_cmt_second_position (chip, 0));
1570   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1571   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1572   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1573   DBG (6, "usb_mid_motor1200_prepare_mono_bi_full_x2300_dpi: exit\n");
1574   return SANE_STATUS_GOOD;
1575 }
1576 
1577 SANE_Status
usb_mid_motor1200_prepare_rgb(ma1017 * chip,SANE_Word dpi)1578 usb_mid_motor1200_prepare_rgb (ma1017 * chip, SANE_Word dpi)
1579 {
1580   SANE_Status status;
1581 
1582   DBG (6, "usb_mid_motor1200_prepare_rgb: start\n");
1583   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
1584   /* No Motor & Forward */
1585   RIE (usb_low_set_motor_direction (chip, SANE_FALSE));
1586   RIE (usb_low_enable_motor (chip, SANE_TRUE));
1587   switch (dpi)
1588     {
1589     case 1200:
1590       return usb_mid_motor1200_prepare_rgb_1200_dpi (chip);
1591       break;
1592     case 600:
1593       return usb_mid_motor1200_prepare_rgb_600_dpi (chip);
1594       break;
1595     case 400:
1596       return usb_mid_motor1200_prepare_rgb_400_dpi (chip);
1597       break;
1598     case 300:
1599       return usb_mid_motor1200_prepare_rgb_300_dpi (chip);
1600       break;
1601     case 200:
1602       return usb_mid_motor1200_prepare_rgb_200_dpi (chip);
1603       break;
1604     case 150:
1605       return usb_mid_motor1200_prepare_rgb_150_dpi (chip);
1606       break;
1607     case 100:
1608       return usb_mid_motor1200_prepare_rgb_100_dpi (chip);
1609       break;
1610     case 50:
1611       return usb_mid_motor1200_prepare_rgb_50_dpi (chip);
1612       break;
1613     default:
1614       DBG (3, "usb_mid_motor1200_prepare_rgb: unmatched dpi: %d\n", dpi);
1615       return SANE_STATUS_INVAL;
1616       break;
1617     }
1618   return SANE_STATUS_GOOD;
1619 }
1620 
1621 SANE_Status
usb_mid_motor1200_prepare_mono(ma1017 * chip,SANE_Word dpi)1622 usb_mid_motor1200_prepare_mono (ma1017 * chip, SANE_Word dpi)
1623 {
1624   SANE_Status status;
1625 
1626   DBG (3, "usb_mid_motor1200_prepare_mono: start\n");
1627   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
1628   /* No Motor & Forward */
1629   RIE (usb_low_set_motor_direction (chip, SANE_FALSE));
1630   RIE (usb_low_enable_motor (chip, SANE_TRUE));
1631   switch (dpi)
1632     {
1633     case 1200:
1634       return usb_mid_motor1200_prepare_mono_1200_dpi (chip);
1635       break;
1636     case 600:
1637       return usb_mid_motor1200_prepare_mono_600_dpi (chip);
1638       break;
1639     case 400:
1640       return usb_mid_motor1200_prepare_mono_400_dpi (chip);
1641       break;
1642     case 300:
1643       return usb_mid_motor1200_prepare_mono_300_dpi (chip);
1644       break;
1645     case 200:
1646       return usb_mid_motor1200_prepare_mono_200_dpi (chip);
1647       break;
1648     case 150:
1649       return usb_mid_motor1200_prepare_mono_150_dpi (chip);
1650       break;
1651     case 100:
1652       return usb_mid_motor1200_prepare_mono_100_dpi (chip);
1653       break;
1654     case 50:
1655       return usb_mid_motor1200_prepare_mono_50_dpi (chip);
1656       break;
1657     default:
1658       DBG (3, "usb_mid_motor1200_prepare_mono_: unmatched dpi: %d\n", dpi);
1659       return SANE_STATUS_INVAL;
1660       break;
1661     }
1662   return SANE_STATUS_GOOD;
1663 }
1664 
1665 SANE_Status
usb_mid_motor1200_prepare_calibrate_rgb(ma1017 * chip,SANE_Word dpi)1666 usb_mid_motor1200_prepare_calibrate_rgb (ma1017 * chip, SANE_Word dpi)
1667 {
1668   SANE_Status status;
1669 
1670   DBG (6, "usb_mid_motor1200_prepare_calibrate_rgb: start\n");
1671   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
1672   /* No Motor & Forward */
1673   RIE (usb_low_set_motor_direction (chip, SANE_FALSE));
1674   RIE (usb_low_enable_motor (chip, SANE_TRUE));
1675   switch (dpi)
1676     {
1677     case 1200:
1678     case 400:
1679     case 300:
1680       return usb_mid_motor1200_prepare_rgb_half_300_dpi (chip);
1681       break;
1682     case 600:
1683     case 200:
1684     case 150:
1685       return usb_mid_motor1200_prepare_rgb_bi_full_300_dpi (chip);
1686       break;
1687     case 100:
1688     case 50:
1689       return usb_mid_motor1200_prepare_rgb_bi_full_x2300_dpi (chip);
1690       break;
1691     default:
1692       DBG (3, "usb_mid_motor1200_prepare_calibrate_rgb: unmatched dpi: "
1693 	   "%d\n", dpi);
1694       return SANE_STATUS_INVAL;
1695       break;
1696     }
1697   return SANE_STATUS_GOOD;
1698 }
1699 
1700 SANE_Status
usb_mid_motor1200_prepare_calibrate_mono(ma1017 * chip,SANE_Word dpi)1701 usb_mid_motor1200_prepare_calibrate_mono (ma1017 * chip, SANE_Word dpi)
1702 {
1703   SANE_Status status;
1704 
1705   DBG (6, "usb_mid_motor1200_prepare_calibrate_mono: start\n");
1706   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
1707   /* No Motor & Forward */
1708   RIE (usb_low_set_motor_direction (chip, SANE_FALSE));
1709   RIE (usb_low_enable_motor (chip, SANE_TRUE));
1710   switch (dpi)
1711     {
1712     case 1200:
1713     case 600:
1714     case 400:
1715       return usb_mid_motor1200_prepare_mono_half_300_dpi (chip);
1716       break;
1717     case 300:
1718     case 200:
1719       return usb_mid_motor1200_prepare_mono_bi_full_300_dpi (chip);
1720       break;
1721     case 150:
1722     case 100:
1723     case 50:
1724       return usb_mid_motor1200_prepare_mono_bi_full_x2300_dpi (chip);
1725       break;
1726     default:
1727       DBG (3, "usb_mid_motor1200_prepare_calibrate_mono: unmatched dpi: %d\n",
1728 	   dpi);
1729       return SANE_STATUS_INVAL;
1730       break;
1731     }
1732   return SANE_STATUS_GOOD;
1733 }
1734 
1735 SANE_Status
usb_mid_motor1200_prepare_step(ma1017 * chip,SANE_Word step_count)1736 usb_mid_motor1200_prepare_step (ma1017 * chip, SANE_Word step_count)
1737 {
1738   SANE_Status status;
1739 
1740   DBG (6, "usb_mid_motor1200_prepare_step: start\n");
1741   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1742   /* Make it in 600dpi */
1743   RIE (usb_low_set_io_3 (chip, SANE_TRUE));	/* (IO3) ? High power : Low power */
1744   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
1745   /* No Motor & Forward */
1746   if (step_count == 1)
1747     {
1748       RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_FALSE));
1749       RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_FALSE, SANE_FALSE));
1750       RIE (usb_low_set_cmt_table_length (chip, 1));
1751       RIE (usb_low_set_cmt_second_position (chip, 0));
1752       RIE (usb_low_set_cmt_loop_count (chip, step_count));
1753     }
1754   else if (step_count % 2 == 1)
1755     {
1756       RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_FALSE));
1757       RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1758       RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
1759       RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1760       RIE (usb_low_set_cmt_table_length (chip, 3));
1761       RIE (usb_low_set_cmt_second_position (chip, 1));
1762       RIE (usb_low_set_cmt_loop_count (chip, (step_count - 1) / 2));
1763     }
1764   else
1765     {
1766       RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_FALSE));
1767       RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
1768       RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
1769       RIE (usb_low_set_cmt_table_length (chip, 2));
1770       RIE (usb_low_set_cmt_second_position (chip, 0));
1771       RIE (usb_low_set_cmt_loop_count (chip, step_count / 2));
1772     }
1773   RIE (usb_low_enable_motor (chip, SANE_TRUE));
1774   DBG (6, "usb_mid_motor1200_prepare_step: exit\n");
1775   return SANE_STATUS_GOOD;
1776 }
1777 
1778 SANE_Status
usb_mid_motor1200_prepare_home(ma1017 * chip)1779 usb_mid_motor1200_prepare_home (ma1017 * chip)
1780 {
1781   SANE_Status status;
1782 
1783   DBG (6, "usb_mid_motor1200_prepare_home: start\n");
1784   if (chip->sensor == ST_NEC600)
1785     RIE (usb_low_set_motor_movement
1786 	 (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1787   else
1788     RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1789   /* Make it in 600dpi */
1790   RIE (usb_low_set_io_3 (chip, SANE_TRUE));	/* (IO3) ? High power : Low power */
1791   RIE (usb_low_move_motor_home (chip, SANE_TRUE, SANE_TRUE));
1792   DBG (6, "usb_mid_motor1200_prepare_home: exit\n");
1793   return SANE_STATUS_GOOD;
1794 }
1795 
1796 SANE_Status
usb_mid_motor1200_prepare_adjust(ma1017 * chip,Channel channel)1797 usb_mid_motor1200_prepare_adjust (ma1017 * chip, Channel channel)
1798 {
1799   SANE_Status status;
1800 
1801   DBG (6, "usb_mid_motor1200_prepare_adjust: start\n");
1802   RIE (usb_low_set_cmt_table (chip, 0, channel, SANE_FALSE, SANE_TRUE));
1803   RIE (usb_low_set_cmt_table (chip, 1, channel, SANE_FALSE, SANE_TRUE));
1804   RIE (usb_low_set_cmt_table (chip, 2, channel, SANE_FALSE, SANE_FALSE));
1805   RIE (usb_low_set_cmt_table_length (chip, 2));
1806   RIE (usb_low_set_cmt_second_position (chip, 0));
1807   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1808   DBG (6, "usb_mid_motor1200_prepare_adjust: exit\n");
1809   return SANE_STATUS_GOOD;
1810 }
1811 
1812 
1813 SANE_Word
usb_mid_motor1200_rgb_capability(SANE_Word dpi)1814 usb_mid_motor1200_rgb_capability (SANE_Word dpi)
1815 {
1816   DBG (6, "usb_mid_motor1200_rgb_capability: start\n");
1817   switch (dpi)
1818     {
1819     case 1200:
1820     case 400:
1821       return 3008; /* 2816 */ ;
1822     case 600:
1823       return 3008;
1824     case 200:
1825       return 5056;
1826     case 300:
1827       return 3008;
1828     case 150:
1829       return 5056;
1830     case 100:
1831     case 50:
1832       return 10048;
1833     default:
1834       DBG (3, "usb_mid_motor1200_rgb_capability: unmatched dpi: %d\n", dpi);
1835       return 0;
1836     }
1837 }
1838 
1839 SANE_Word
usb_mid_motor1200_mono_capability(SANE_Word dpi)1840 usb_mid_motor1200_mono_capability (SANE_Word dpi)
1841 {
1842   DBG (5, "usb_mid_motor1200_mono_capability: start\n");
1843   switch (dpi)
1844     {
1845     case 1200:
1846     case 400:
1847       return 3008;
1848     case 600:
1849       return 3008;
1850     case 200:
1851       return 5056;
1852     case 300:
1853       return 5056;
1854     case 150:
1855     case 100:
1856     case 50:
1857       return 10048;
1858     default:
1859       DBG (3, "usb_mid_motor1200_mono_capability: unmatched dpi: %d\n", dpi);
1860       return 0;
1861     }
1862 }
1863 
1864 /* ---------------600 dpi motor function declarations --------------------- */
1865 
1866 
1867 static SANE_Word usb_mid_motor600_optical_dpi[] =
1868   { 600, 300, 200, 150, 100, 50, 0 };
1869 
1870 
1871 SANE_Status
usb_mid_motor600_prepare_rgb_600_dpi(ma1017 * chip)1872 usb_mid_motor600_prepare_rgb_600_dpi (ma1017 * chip)
1873 {
1874   SANE_Status status;
1875 
1876   DBG (6, "usb_mid_motor600_prepare_rgb_600_dpi: start\n");
1877   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1878   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_FALSE, SANE_TRUE));
1879   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1880   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1881   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1882   RIE (usb_low_set_cmt_table_length (chip, 4));
1883   RIE (usb_low_set_cmt_second_position (chip, 0));
1884   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1885   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1886   RIE (usb_low_set_io_3 (chip, SANE_FALSE));
1887   DBG (6, "usb_mid_motor600_prepare_rgb_600_dpi: exit\n");
1888   return SANE_STATUS_GOOD;
1889 }
1890 
1891 SANE_Status
usb_mid_motor600_prepare_rgb_300_dpi(ma1017 * chip)1892 usb_mid_motor600_prepare_rgb_300_dpi (ma1017 * chip)
1893 {
1894   SANE_Status status;
1895 
1896   DBG (6, "usb_mid_motor600_prepare_rgb_300_dpi: start\n");
1897   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1898   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_FALSE, SANE_TRUE));
1899   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1900   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1901   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_FALSE, SANE_FALSE));
1902   RIE (usb_low_set_cmt_table_length (chip, 4));
1903   RIE (usb_low_set_cmt_second_position (chip, 0));
1904   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1905   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1906   RIE (usb_low_set_io_3 (chip, SANE_FALSE));
1907   DBG (6, "usb_mid_motor600_prepare_rgb_300_dpi: exit\n");
1908   return SANE_STATUS_GOOD;
1909 }
1910 
1911 SANE_Status
usb_mid_motor600_prepare_rgb_200_dpi(ma1017 * chip)1912 usb_mid_motor600_prepare_rgb_200_dpi (ma1017 * chip)
1913 {
1914   SANE_Status status;
1915 
1916   DBG (6, "usb_mid_motor600_prepare_rgb_200_dpi: start\n");
1917   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1918   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_FALSE, SANE_TRUE));
1919   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1920   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_TRUE, SANE_FALSE));
1921   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_TRUE, SANE_FALSE));
1922   RIE (usb_low_set_cmt_table (chip, 5, CH_GREEN, SANE_FALSE, SANE_FALSE));
1923   RIE (usb_low_set_cmt_table_length (chip, 5));
1924   RIE (usb_low_set_cmt_second_position (chip, 0));
1925   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1926   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
1927   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1928   DBG (6, "usb_mid_motor600_prepare_rgb_200_dpi: exit\n");
1929   return SANE_STATUS_GOOD;
1930 }
1931 
1932 
1933 
1934 SANE_Status
usb_mid_motor600_prepare_rgb_150_dpi(ma1017 * chip)1935 usb_mid_motor600_prepare_rgb_150_dpi (ma1017 * chip)
1936 {
1937   SANE_Status status;
1938 
1939   DBG (6, "usb_mid_motor600_prepare_rgb_150_dpi: start\n");
1940   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1941   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_FALSE, SANE_TRUE));
1942   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1943   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1944   RIE (usb_low_set_cmt_table_length (chip, 3));
1945   RIE (usb_low_set_cmt_second_position (chip, 0));
1946   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1947   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1948   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1949   DBG (6, "usb_mid_motor600_prepare_rgb_150_dpi: exit\n");
1950   return SANE_STATUS_GOOD;
1951 }
1952 
1953 SANE_Status
usb_mid_motor600_prepare_rgb_100_dpi(ma1017 * chip)1954 usb_mid_motor600_prepare_rgb_100_dpi (ma1017 * chip)
1955 {
1956   SANE_Status status;
1957 
1958   DBG (6, "usb_mid_motor600_prepare_rgb_100_dpi: start\n");
1959   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
1960   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_FALSE, SANE_TRUE));
1961   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1962   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_TRUE, SANE_FALSE));
1963   RIE (usb_low_set_cmt_table (chip, 4, CH_GREEN, SANE_TRUE, SANE_FALSE));
1964   RIE (usb_low_set_cmt_table (chip, 5, CH_GREEN, SANE_FALSE, SANE_FALSE));
1965   RIE (usb_low_set_cmt_table_length (chip, 5));
1966   RIE (usb_low_set_cmt_second_position (chip, 0));
1967   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1968   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
1969   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1970   DBG (6, "usb_mid_motor600_prepare_rgb_100_dpi: exit\n");
1971   return SANE_STATUS_GOOD;
1972 }
1973 
1974 SANE_Status
usb_mid_motor600_prepare_rgb_50_dpi(ma1017 * chip)1975 usb_mid_motor600_prepare_rgb_50_dpi (ma1017 * chip)
1976 {
1977   SANE_Status status;
1978 
1979   DBG (6, "usb_mid_motor600_prepare_rgb_50_dpi: start\n");
1980   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
1981   RIE (usb_low_set_cmt_table (chip, 1, CH_BLUE, SANE_TRUE, SANE_TRUE));
1982   RIE (usb_low_set_cmt_table (chip, 2, CH_RED, SANE_TRUE, SANE_TRUE));
1983   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
1984   RIE (usb_low_set_cmt_table_length (chip, 3));
1985   RIE (usb_low_set_cmt_second_position (chip, 0));
1986   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
1987   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
1988   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
1989   DBG (6, "usb_mid_motor600_prepare_rgb_50_dpi: exit\n");
1990   return SANE_STATUS_GOOD;
1991 }
1992 
1993 SANE_Status
usb_mid_motor600_prepare_mono_600_dpi(ma1017 * chip)1994 usb_mid_motor600_prepare_mono_600_dpi (ma1017 * chip)
1995 {
1996   SANE_Status status;
1997 
1998   DBG (6, "usb_mid_motor600_prepare_mono_600_dpi: start\n");
1999   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2000   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
2001   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
2002   RIE (usb_low_set_cmt_table_length (chip, 2));
2003   RIE (usb_low_set_cmt_second_position (chip, 0));
2004   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2005   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
2006   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2007   DBG (6, "usb_mid_motor600_prepare_mono_600_dpi: exit\n");
2008   return SANE_STATUS_GOOD;
2009 }
2010 
2011 SANE_Status
usb_mid_motor600_prepare_mono_300_dpi(ma1017 * chip)2012 usb_mid_motor600_prepare_mono_300_dpi (ma1017 * chip)
2013 {
2014   SANE_Status status;
2015 
2016   DBG (6, "usb_mid_motor600_prepare_mono_300_dpi: start\n");
2017   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2018   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
2019   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
2020   RIE (usb_low_set_cmt_table_length (chip, 2));
2021   RIE (usb_low_set_cmt_second_position (chip, 0));
2022   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2023   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
2024   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2025   DBG (6, "usb_mid_motor600_prepare_mono_300_dpi: exit\n");
2026   return SANE_STATUS_GOOD;
2027 }
2028 
2029 SANE_Status
usb_mid_motor600_prepare_mono_200_dpi(ma1017 * chip)2030 usb_mid_motor600_prepare_mono_200_dpi (ma1017 * chip)
2031 {
2032   SANE_Status status;
2033 
2034   DBG (6, "usb_mid_motor600_prepare_mono_200_dpi: start\n");
2035   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2036   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
2037   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
2038   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
2039   RIE (usb_low_set_cmt_table_length (chip, 3));
2040   RIE (usb_low_set_cmt_second_position (chip, 0));
2041   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2042   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
2043   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2044   DBG (6, "usb_mid_motor600_prepare_mono_200_dpi: exit\n");
2045   return SANE_STATUS_GOOD;
2046 }
2047 
2048 
2049 SANE_Status
usb_mid_motor600_prepare_mono_150_dpi(ma1017 * chip)2050 usb_mid_motor600_prepare_mono_150_dpi (ma1017 * chip)
2051 {
2052   SANE_Status status;
2053 
2054   DBG (6, "usb_mid_motor600_prepare_mono_150_dpi: start\n");
2055   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2056   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
2057   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
2058   RIE (usb_low_set_cmt_table_length (chip, 2));
2059   RIE (usb_low_set_cmt_second_position (chip, 0));
2060   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2061   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
2062   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2063   DBG (6, "usb_mid_motor600_prepare_mono_150_dpi: exit\n");
2064   return SANE_STATUS_GOOD;
2065 }
2066 
2067 SANE_Status
usb_mid_motor600_prepare_mono_100_dpi(ma1017 * chip)2068 usb_mid_motor600_prepare_mono_100_dpi (ma1017 * chip)
2069 {
2070   SANE_Status status;
2071 
2072   DBG (6, "usb_mid_motor600_prepare_mono_100_dpi: start\n");
2073   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2074   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
2075   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
2076   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
2077   RIE (usb_low_set_cmt_table_length (chip, 3));
2078   RIE (usb_low_set_cmt_second_position (chip, 0));
2079   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2080   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
2081   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2082   DBG (6, "usb_mid_motor600_prepare_mono_100_dpi: exit\n");
2083   return SANE_STATUS_GOOD;
2084 }
2085 
2086 SANE_Status
usb_mid_motor600_prepare_mono_50_dpi(ma1017 * chip)2087 usb_mid_motor600_prepare_mono_50_dpi (ma1017 * chip)
2088 {
2089   SANE_Status status;
2090 
2091   DBG (6, "usb_mid_motor600_prepare_mono_50_dpi: start\n");
2092   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2093   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
2094   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
2095   RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
2096   RIE (usb_low_set_cmt_table_length (chip, 3));
2097   RIE (usb_low_set_cmt_second_position (chip, 0));
2098   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2099   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_TRUE));
2100   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2101   DBG (6, "usb_mid_motor600_prepare_mono_50_dpi: exit\n");
2102   return SANE_STATUS_GOOD;
2103 }
2104 
2105 SANE_Status
usb_mid_motor600_prepare_rgb_half_300_dpi(ma1017 * chip)2106 usb_mid_motor600_prepare_rgb_half_300_dpi (ma1017 * chip)
2107 {
2108   SANE_Status status;
2109 
2110   DBG (6, "usb_mid_motor600_prepare_rgb_half_300_dpi: start\n");
2111   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2112   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_FALSE, SANE_TRUE));
2113   RIE (usb_low_set_cmt_table (chip, 2, CH_BLUE, SANE_TRUE, SANE_TRUE));
2114   RIE (usb_low_set_cmt_table (chip, 3, CH_BLUE, SANE_TRUE, SANE_TRUE));
2115   RIE (usb_low_set_cmt_table (chip, 4, CH_RED, SANE_FALSE, SANE_TRUE));
2116   RIE (usb_low_set_cmt_table (chip, 5, CH_RED, SANE_TRUE, SANE_TRUE));
2117   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_FALSE, SANE_FALSE));
2118   RIE (usb_low_set_cmt_table_length (chip, 6));
2119   RIE (usb_low_set_cmt_second_position (chip, 0));
2120   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2121   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
2122   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2123   DBG (6, "usb_mid_motor600_prepare_rgb_half_300_dpi: exit\n");
2124   return SANE_STATUS_GOOD;
2125 }
2126 
2127 SANE_Status
usb_mid_motor600_prepare_rgb_bi_full_300_dpi(ma1017 * chip)2128 usb_mid_motor600_prepare_rgb_bi_full_300_dpi (ma1017 * chip)
2129 {
2130   SANE_Status status;
2131 
2132   DBG (6, "usb_mid_motor600_prepare_rgb_bi_full_300_dpi: start\n");
2133   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_FALSE, SANE_TRUE));
2134   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
2135   RIE (usb_low_set_cmt_table (chip, 2, CH_BLUE, SANE_FALSE, SANE_TRUE));
2136   RIE (usb_low_set_cmt_table (chip, 3, CH_BLUE, SANE_FALSE, SANE_TRUE));
2137   RIE (usb_low_set_cmt_table (chip, 4, CH_RED, SANE_TRUE, SANE_TRUE));
2138   RIE (usb_low_set_cmt_table (chip, 5, CH_RED, SANE_FALSE, SANE_TRUE));
2139   RIE (usb_low_set_cmt_table (chip, 6, CH_GREEN, SANE_FALSE, SANE_FALSE));
2140   RIE (usb_low_set_cmt_table_length (chip, 6));
2141   RIE (usb_low_set_cmt_second_position (chip, 0));
2142   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2143   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
2144   RIE (usb_low_set_io_3 (chip, SANE_FALSE));
2145   DBG (6, "usb_mid_motor600_prepare_rgb_bi_full_300_dpi: exit\n");
2146   return SANE_STATUS_GOOD;
2147 }
2148 
2149 SANE_Status
usb_mid_motor600_prepare_mono_half_300_dpi(ma1017 * chip)2150 usb_mid_motor600_prepare_mono_half_300_dpi (ma1017 * chip)
2151 {
2152   SANE_Status status;
2153 
2154   DBG (6, "usb_mid_motor600_prepare_mono_half_300_dpi: start\n");
2155   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2156   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
2157   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
2158   RIE (usb_low_set_cmt_table_length (chip, 2));
2159   RIE (usb_low_set_cmt_second_position (chip, 0));
2160   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2161   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
2162   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2163   DBG (6, "usb_mid_motor600_prepare_mono_half_300_dpi: exit\n");
2164   return SANE_STATUS_GOOD;
2165 
2166 }
2167 
2168 SANE_Status
usb_mid_motor600_prepare_mono_bi_full_300_dpi(ma1017 * chip)2169 usb_mid_motor600_prepare_mono_bi_full_300_dpi (ma1017 * chip)
2170 {
2171   SANE_Status status;
2172 
2173   DBG (6, "usb_mid_motor600_prepare_mono_bi_full_300_dpi: start\n");
2174   RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_TRUE));
2175   RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_TRUE));
2176   RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
2177   RIE (usb_low_set_cmt_table_length (chip, 2));
2178   RIE (usb_low_set_cmt_second_position (chip, 0));
2179   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2180   RIE (usb_low_set_motor_movement (chip, SANE_TRUE, SANE_TRUE, SANE_FALSE));
2181   RIE (usb_low_set_io_3 (chip, SANE_TRUE));
2182   DBG (6, "usb_mid_motor600_prepare_mono_bi_full_300_dpi: exit\n");
2183   return SANE_STATUS_GOOD;
2184 }
2185 
2186 
2187 SANE_Status
usb_mid_motor600_prepare_rgb(ma1017 * chip,SANE_Word dpi)2188 usb_mid_motor600_prepare_rgb (ma1017 * chip, SANE_Word dpi)
2189 {
2190   DBG (6, "usb_mid_motor600_prepare_rgb: start\n");
2191   switch (dpi)
2192     {
2193     case 600:
2194       return usb_mid_motor600_prepare_rgb_600_dpi (chip);
2195       break;
2196     case 300:
2197       return usb_mid_motor600_prepare_rgb_300_dpi (chip);
2198       break;
2199     case 200:
2200       return usb_mid_motor600_prepare_rgb_200_dpi (chip);
2201       break;
2202     case 150:
2203       return usb_mid_motor600_prepare_rgb_150_dpi (chip);
2204       break;
2205     case 100:
2206       return usb_mid_motor600_prepare_rgb_100_dpi (chip);
2207       break;
2208     case 50:
2209       return usb_mid_motor600_prepare_rgb_50_dpi (chip);
2210       break;
2211     default:
2212       DBG (3, "usb_mid_motor600_prepare_rgb: unmatched dpi: %d\n", dpi);
2213       return SANE_STATUS_INVAL;
2214       break;
2215     }
2216   return SANE_STATUS_GOOD;
2217 }
2218 
2219 SANE_Status
usb_mid_motor600_prepare_mono(ma1017 * chip,SANE_Word dpi)2220 usb_mid_motor600_prepare_mono (ma1017 * chip, SANE_Word dpi)
2221 {
2222   DBG (6, "usb_mid_motor600_prepare_mono: start\n");
2223   switch (dpi)
2224     {
2225     case 600:
2226       return usb_mid_motor600_prepare_mono_600_dpi (chip);
2227       break;
2228     case 300:
2229       return usb_mid_motor600_prepare_mono_300_dpi (chip);
2230       break;
2231     case 200:
2232       return usb_mid_motor600_prepare_mono_200_dpi (chip);
2233       break;
2234     case 150:
2235       return usb_mid_motor600_prepare_mono_150_dpi (chip);
2236       break;
2237     case 100:
2238       return usb_mid_motor600_prepare_mono_100_dpi (chip);
2239       break;
2240     case 50:
2241       return usb_mid_motor600_prepare_mono_50_dpi (chip);
2242       break;
2243     default:
2244       DBG (3, "usb_mid_motor600_prepare_mono_: unmatched dpi: %d\n", dpi);
2245       return SANE_STATUS_INVAL;
2246       break;
2247     }
2248   return SANE_STATUS_GOOD;
2249 }
2250 
2251 SANE_Status
usb_mid_motor600_prepare_calibrate_rgb(ma1017 * chip,SANE_Word dpi)2252 usb_mid_motor600_prepare_calibrate_rgb (ma1017 * chip, SANE_Word dpi)
2253 {
2254   SANE_Status status;
2255 
2256   DBG (6, "usb_mid_motor600_prepare_calibrate_rgb: start\n");
2257   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
2258   /* No Motor & Forward */
2259   RIE (usb_low_set_motor_direction (chip, SANE_FALSE));
2260   RIE (usb_low_enable_motor (chip, SANE_TRUE));
2261   switch (dpi)
2262     {
2263     case 600:
2264     case 200:
2265       return usb_mid_motor600_prepare_rgb_half_300_dpi (chip);
2266       break;
2267     case 300:
2268     case 150:
2269     case 100:
2270     case 50:
2271       return usb_mid_motor600_prepare_rgb_bi_full_300_dpi (chip);
2272       break;
2273     default:
2274       DBG (3, "usb_mid_motor600_prepare_calibrate_rgb: unmatched dpi: %d\n",
2275 	   dpi);
2276       return SANE_STATUS_INVAL;
2277       break;
2278     }
2279   return SANE_STATUS_GOOD;
2280 }
2281 
2282 SANE_Status
usb_mid_motor600_prepare_calibrate_mono(ma1017 * chip,SANE_Word dpi)2283 usb_mid_motor600_prepare_calibrate_mono (ma1017 * chip, SANE_Word dpi)
2284 {
2285   SANE_Status status;
2286 
2287   DBG (6, "usb_mid_motor600_prepare_calibrate_mono: start\n");
2288   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
2289   /* No Motor & Forward */
2290   RIE (usb_low_set_motor_direction (chip, SANE_FALSE));
2291   RIE (usb_low_enable_motor (chip, SANE_TRUE));
2292   switch (dpi)
2293     {
2294     case 600:
2295     case 200:
2296       return usb_mid_motor600_prepare_mono_half_300_dpi (chip);
2297       break;
2298     case 300:
2299     case 150:
2300     case 100:
2301     case 50:
2302       return usb_mid_motor600_prepare_mono_bi_full_300_dpi (chip);
2303       break;
2304     default:
2305       DBG (3, "usb_mid_motor600_prepare_calibrate_mono: unmatched dpi: %d\n",
2306 	   dpi);
2307       return SANE_STATUS_INVAL;
2308       break;
2309     }
2310   return SANE_STATUS_GOOD;
2311 }
2312 
2313 SANE_Status
usb_mid_motor600_prepare_step(ma1017 * chip,SANE_Word step_count)2314 usb_mid_motor600_prepare_step (ma1017 * chip, SANE_Word step_count)
2315 {
2316   SANE_Status status;
2317 
2318   DBG (6, "usb_mid_motor600_prepare_step: start\n");
2319   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_FALSE));
2320   /* Make it in 300dpi */
2321   RIE (usb_low_set_io_3 (chip, SANE_TRUE));	/* (IO3) ? High power : Low power */
2322   RIE (usb_low_move_motor_home (chip, SANE_FALSE, SANE_FALSE));
2323   /* No Motor & Forward */
2324   if (step_count == 1)
2325     {
2326       RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_FALSE));
2327       RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_FALSE, SANE_FALSE));
2328       RIE (usb_low_set_cmt_table_length (chip, 1));
2329       RIE (usb_low_set_cmt_second_position (chip, 0));
2330       RIE (usb_low_set_cmt_loop_count (chip, step_count));
2331     }
2332   else if (step_count % 2 == 1)
2333     {
2334       RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_FALSE));
2335       RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
2336       RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_TRUE, SANE_FALSE));
2337       RIE (usb_low_set_cmt_table (chip, 3, CH_GREEN, SANE_FALSE, SANE_FALSE));
2338       RIE (usb_low_set_cmt_table_length (chip, 3));
2339       RIE (usb_low_set_cmt_second_position (chip, 1));
2340       RIE (usb_low_set_cmt_loop_count (chip, (step_count - 1) / 2));
2341     }
2342   else
2343     {
2344       RIE (usb_low_set_cmt_table (chip, 0, CH_GREEN, SANE_TRUE, SANE_FALSE));
2345       RIE (usb_low_set_cmt_table (chip, 1, CH_GREEN, SANE_TRUE, SANE_FALSE));
2346       RIE (usb_low_set_cmt_table (chip, 2, CH_GREEN, SANE_FALSE, SANE_FALSE));
2347       RIE (usb_low_set_cmt_table_length (chip, 2));
2348       RIE (usb_low_set_cmt_second_position (chip, 0));
2349       RIE (usb_low_set_cmt_loop_count (chip, step_count / 2));
2350     }
2351   RIE (usb_low_enable_motor (chip, SANE_TRUE));
2352   DBG (6, "usb_mid_motor600_prepare_step: exit\n");
2353   return SANE_STATUS_GOOD;
2354 }
2355 
2356 SANE_Status
usb_mid_motor600_prepare_home(ma1017 * chip)2357 usb_mid_motor600_prepare_home (ma1017 * chip)
2358 {
2359   SANE_Status status;
2360 
2361   DBG (6, "usb_mid_motor600_prepare_home: start\n");
2362   RIE (usb_low_set_motor_movement (chip, SANE_FALSE, SANE_TRUE, SANE_TRUE));
2363   /* Make it in 600dpi */
2364   RIE (usb_low_set_io_3 (chip, SANE_TRUE));	/* (IO3) ? High power : Low power */
2365   RIE (usb_low_move_motor_home (chip, SANE_TRUE, SANE_TRUE));
2366   DBG (6, "usb_mid_motor600_prepare_home: exit\n");
2367   return SANE_STATUS_GOOD;
2368 }
2369 
2370 SANE_Status
usb_mid_motor600_prepare_adjust(ma1017 * chip,Channel channel)2371 usb_mid_motor600_prepare_adjust (ma1017 * chip, Channel channel)
2372 {
2373   SANE_Status status;
2374 
2375   DBG (6, "usb_mid_motor600_prepare_adjust: start\n");
2376   RIE (usb_low_set_cmt_table (chip, 0, channel, SANE_FALSE, SANE_TRUE));
2377   RIE (usb_low_set_cmt_table (chip, 1, channel, SANE_FALSE, SANE_TRUE));
2378   RIE (usb_low_set_cmt_table (chip, 2, channel, SANE_FALSE, SANE_FALSE));
2379   RIE (usb_low_set_cmt_table_length (chip, 2));
2380   RIE (usb_low_set_cmt_second_position (chip, 0));
2381   RIE (usb_low_set_cmt_loop_count (chip, 0xefff));
2382   DBG (6, "usb_mid_motor600_prepare_adjust: exit\n");
2383   return SANE_STATUS_GOOD;
2384 }
2385 
2386 
2387 SANE_Word
usb_mid_motor600_rgb_capability(SANE_Word dpi)2388 usb_mid_motor600_rgb_capability (SANE_Word dpi)
2389 {
2390   DBG (6, "usb_mid_motor600_rgb_capability: start\n");
2391   switch (dpi)
2392     {
2393     case 600:
2394     case 300:
2395     case 200:
2396       return 2600;
2397     case 100:
2398       return 4500;
2399     case 150:
2400     case 50:
2401       return 9000;
2402     default:
2403       DBG (3, "usb_mid_motor600_rgb_capability: unmatched dpi: %d\n", dpi);
2404       return 0;
2405     }
2406 }
2407 
2408 SANE_Word
usb_mid_motor600_mono_capability(SANE_Word dpi)2409 usb_mid_motor600_mono_capability (SANE_Word dpi)
2410 {
2411   DBG (5, "usb_mid_motor600_mono_capability: start\n");
2412   switch (dpi)
2413     {
2414     case 600:
2415     case 200:
2416       return 2600;
2417     case 300:
2418     case 100:
2419       return 4500;
2420     case 150:
2421     case 50:
2422       return 9000;
2423     default:
2424       DBG (3, "usb_mid_motor600_mono_capability: unmatched dpi: %d\n", dpi);
2425       return 0;
2426     }
2427 }
2428 
2429 /* ------------------ motor function declarations ------------------------ */
2430 static SANE_Status
usb_mid_motor_prepare_home(ma1017 * chip)2431 usb_mid_motor_prepare_home (ma1017 * chip)
2432 {
2433   if (chip->motor == MT_600)
2434     return usb_mid_motor600_prepare_home (chip);
2435   else
2436     return usb_mid_motor1200_prepare_home (chip);
2437 }
2438 
2439 static SANE_Status
usb_mid_motor_prepare_rgb(ma1017 * chip,SANE_Word dpi)2440 usb_mid_motor_prepare_rgb (ma1017 * chip, SANE_Word dpi)
2441 {
2442   if (chip->motor == MT_600)
2443     return usb_mid_motor600_prepare_rgb (chip, dpi);
2444   else
2445     return usb_mid_motor1200_prepare_rgb (chip, dpi);
2446 }
2447 
2448 static SANE_Status
usb_mid_motor_prepare_mono(ma1017 * chip,SANE_Word dpi)2449 usb_mid_motor_prepare_mono (ma1017 * chip, SANE_Word dpi)
2450 {
2451   if (chip->motor == MT_600)
2452     return usb_mid_motor600_prepare_mono (chip, dpi);
2453   else
2454     return usb_mid_motor1200_prepare_mono (chip, dpi);
2455 }
2456 
2457 static SANE_Status
usb_mid_motor_prepare_adjust(ma1017 * chip,Channel channel)2458 usb_mid_motor_prepare_adjust (ma1017 * chip, Channel channel)
2459 {
2460   if (chip->motor == MT_600)
2461     return usb_mid_motor600_prepare_adjust (chip, channel);
2462   else
2463     return usb_mid_motor1200_prepare_adjust (chip, channel);
2464 }
2465 
2466 static SANE_Status
usb_mid_motor_prepare_calibrate_rgb(ma1017 * chip,SANE_Word dpi)2467 usb_mid_motor_prepare_calibrate_rgb (ma1017 * chip, SANE_Word dpi)
2468 {
2469   if (chip->motor == MT_600)
2470     return usb_mid_motor600_prepare_calibrate_rgb (chip, dpi);
2471   else
2472     return usb_mid_motor1200_prepare_calibrate_rgb (chip, dpi);
2473 }
2474 
2475 static SANE_Status
usb_mid_motor_prepare_calibrate_mono(ma1017 * chip,SANE_Word dpi)2476 usb_mid_motor_prepare_calibrate_mono (ma1017 * chip, SANE_Word dpi)
2477 {
2478   if (chip->motor == MT_600)
2479     return usb_mid_motor600_prepare_calibrate_mono (chip, dpi);
2480   else
2481     return usb_mid_motor1200_prepare_calibrate_mono (chip, dpi);
2482 }
2483 
2484 static SANE_Status
usb_mid_motor_prepare_step(ma1017 * chip,SANE_Word step_count)2485 usb_mid_motor_prepare_step (ma1017 * chip, SANE_Word step_count)
2486 {
2487   if (chip->motor == MT_600)
2488     return usb_mid_motor600_prepare_step (chip, step_count);
2489   else
2490     return usb_mid_motor1200_prepare_step (chip, step_count);
2491 }
2492 
2493 static SANE_Word
usb_mid_motor_rgb_capability(ma1017 * chip,SANE_Word dpi)2494 usb_mid_motor_rgb_capability (ma1017 * chip, SANE_Word dpi)
2495 {
2496   if (chip->motor == MT_600)
2497     return usb_mid_motor600_rgb_capability (dpi);
2498   else
2499     return usb_mid_motor1200_rgb_capability (dpi);
2500 }
2501 
2502 static SANE_Word
usb_mid_motor_mono_capability(ma1017 * chip,SANE_Word dpi)2503 usb_mid_motor_mono_capability (ma1017 * chip, SANE_Word dpi)
2504 {
2505   if (chip->motor == MT_600)
2506     return usb_mid_motor600_mono_capability (dpi);
2507   else
2508     return usb_mid_motor1200_mono_capability (dpi);
2509 }
2510 
2511 
2512 static SANE_Status
usb_mid_motor_get_dpi(ma1017 * chip,SANE_Word wanted_dpi,SANE_Word * dpi)2513 usb_mid_motor_get_dpi (ma1017 * chip, SANE_Word wanted_dpi, SANE_Word * dpi)
2514 {
2515   SANE_Word *dpi_list;
2516   SANE_Word i;
2517 
2518   if (!dpi)
2519     return SANE_STATUS_INVAL;
2520 
2521   if (chip->motor == MT_600)
2522     dpi_list = usb_mid_motor600_optical_dpi;
2523   else if (chip->motor == MT_1200)
2524     dpi_list = usb_mid_motor1200_optical_dpi;
2525   else
2526     return SANE_STATUS_INVAL;
2527 
2528   for (i = 0; dpi_list[i] != 0; i++)
2529     {
2530       if (wanted_dpi > dpi_list[i])
2531 	break;
2532     }
2533   if (i)
2534     i--;
2535   *dpi = dpi_list[i];
2536   DBG (5, "usb_mid_motor_get_dpi: wanted %d dpi, got %d dpi\n", wanted_dpi,
2537        *dpi);
2538   return SANE_STATUS_GOOD;
2539 }
2540 
2541 /* ----------------------------- frontend ------------------------------- */
2542 
2543 SANE_Status
usb_mid_front_set_front_end_mode(ma1017 * chip,SANE_Byte mode)2544 usb_mid_front_set_front_end_mode (ma1017 * chip, SANE_Byte mode)
2545 {
2546   SANE_Status status;
2547 
2548   DBG (6, "usb_mid_front_set_front_end_mode: start\n");
2549   RIE (usb_low_set_serial_format (chip, mode));
2550   DBG (6, "usb_mid_front_set_front_end_mode: exit\n");
2551   return SANE_STATUS_GOOD;
2552 }
2553 
2554 SANE_Status
usb_mid_front_enable(ma1017 * chip,SANE_Bool is_enable)2555 usb_mid_front_enable (ma1017 * chip, SANE_Bool is_enable)
2556 {
2557   SANE_Status status;
2558 
2559   DBG (6, "usb_mid_front_enable: start\n");
2560   RIE (usb_low_turn_frontend_mode (chip, is_enable));
2561   DBG (6, "usb_mid_front_enable: exit\n");
2562   return SANE_STATUS_GOOD;
2563 }
2564 
2565 SANE_Status
usb_mid_front_set_top_reference(ma1017 * chip,SANE_Byte top)2566 usb_mid_front_set_top_reference (ma1017 * chip, SANE_Byte top)
2567 {
2568   SANE_Status status;
2569 
2570   DBG (6, "usb_mid_front_set_top_reference: start\n");
2571   RIE (usb_mid_front_enable (chip, SANE_TRUE));
2572   RIE (usb_low_set_serial_byte1 (chip, 0x00));
2573   RIE (usb_low_set_serial_byte2 (chip, top));
2574   RIE (usb_mid_front_enable (chip, SANE_FALSE));
2575   DBG (6, "usb_mid_front_set_top_reference: exit\n");
2576   return SANE_STATUS_GOOD;
2577 }
2578 
2579 SANE_Status
usb_mid_front_set_red_offset(ma1017 * chip,SANE_Byte offset)2580 usb_mid_front_set_red_offset (ma1017 * chip, SANE_Byte offset)
2581 {
2582   SANE_Status status;
2583 
2584   DBG (6, "usb_mid_front_set_red_offset: start\n");
2585   RIE (usb_mid_front_enable (chip, SANE_TRUE));
2586   RIE (usb_low_set_serial_byte1 (chip, 0x10));
2587   RIE (usb_low_set_serial_byte2 (chip, offset));
2588   RIE (usb_mid_front_enable (chip, SANE_FALSE));
2589   DBG (6, "usb_mid_front_set_red_offset: exit\n");
2590   return SANE_STATUS_GOOD;
2591 }
2592 
2593 SANE_Status
usb_mid_front_set_green_offset(ma1017 * chip,SANE_Byte offset)2594 usb_mid_front_set_green_offset (ma1017 * chip, SANE_Byte offset)
2595 {
2596   SANE_Status status;
2597 
2598   DBG (6, "usb_mid_front_set_green_offset: start\n");
2599   RIE (usb_mid_front_enable (chip, SANE_TRUE));
2600   RIE (usb_low_set_serial_byte1 (chip, 0x50));
2601   RIE (usb_low_set_serial_byte2 (chip, offset));
2602   RIE (usb_mid_front_enable (chip, SANE_FALSE));
2603   DBG (6, "usb_mid_front_set_green_offset: exit\n");
2604   return SANE_STATUS_GOOD;
2605 }
2606 
2607 SANE_Status
usb_mid_front_set_blue_offset(ma1017 * chip,SANE_Byte offset)2608 usb_mid_front_set_blue_offset (ma1017 * chip, SANE_Byte offset)
2609 {
2610   SANE_Status status;
2611 
2612   DBG (6, "usb_mid_front_set_blue_offset: start\n");
2613   RIE (usb_mid_front_enable (chip, SANE_TRUE));
2614   RIE (usb_low_set_serial_byte1 (chip, 0x30));
2615   RIE (usb_low_set_serial_byte2 (chip, offset));
2616   RIE (usb_mid_front_enable (chip, SANE_FALSE));
2617   DBG (6, "usb_mid_front_set_blue_offset: exit\n");
2618   return SANE_STATUS_GOOD;
2619 }
2620 
2621 #if 0
2622 /* CCD */
2623 SANE_Word
2624 usb_mid_frontend_max_offset_index (ma1017 * chip)
2625 {
2626   DBG (6, "usb_mid_front_max_offset_index: start (chip = %p)\n", chip);
2627 
2628   DBG (6, "usb_mid_front_max_offset_index: exit\n");
2629   return (OFFSET_TABLE_SIZE - 1);
2630 }
2631 #endif
2632 
2633 SANE_Status
usb_mid_front_set_red_pga(ma1017 * chip,SANE_Byte pga)2634 usb_mid_front_set_red_pga (ma1017 * chip, SANE_Byte pga)
2635 {
2636   SANE_Status status;
2637 
2638   DBG (6, "usb_mid_front_set_red_pga: start\n");
2639   RIE (usb_mid_front_enable (chip, SANE_TRUE));
2640   RIE (usb_low_set_serial_byte1 (chip, 0x40));
2641   RIE (usb_low_set_serial_byte2 (chip, pga));
2642   RIE (usb_mid_front_enable (chip, SANE_FALSE));
2643   DBG (6, "usb_mid_front_set_red_pga: start\n");
2644   return SANE_STATUS_GOOD;
2645 }
2646 
2647 SANE_Status
usb_mid_front_set_green_pga(ma1017 * chip,SANE_Byte pga)2648 usb_mid_front_set_green_pga (ma1017 * chip, SANE_Byte pga)
2649 {
2650   SANE_Status status;
2651 
2652   DBG (6, "usb_mid_front_set_green_pga: start\n");
2653   RIE (usb_mid_front_enable (chip, SANE_TRUE));
2654   RIE (usb_low_set_serial_byte1 (chip, 0x20));
2655   RIE (usb_low_set_serial_byte2 (chip, pga));
2656   RIE (usb_mid_front_enable (chip, SANE_FALSE));
2657   DBG (6, "usb_mid_front_set_green_pga: exit\n");
2658   return SANE_STATUS_GOOD;
2659 }
2660 
2661 SANE_Status
usb_mid_front_set_blue_pga(ma1017 * chip,SANE_Byte pga)2662 usb_mid_front_set_blue_pga (ma1017 * chip, SANE_Byte pga)
2663 {
2664   SANE_Status status;
2665 
2666   DBG (6, "usb_mid_front_set_blue_pga: start\n");
2667   RIE (usb_mid_front_enable (chip, SANE_TRUE));
2668   RIE (usb_low_set_serial_byte1 (chip, 0x60));
2669   RIE (usb_low_set_serial_byte2 (chip, pga));
2670   RIE (usb_mid_front_enable (chip, SANE_FALSE));
2671   DBG (6, "usb_mid_front_set_blue_pga: exit\n");
2672   return SANE_STATUS_GOOD;
2673 }
2674 
2675 SANE_Status
usb_mid_front_set_rgb_signal(ma1017 * chip)2676 usb_mid_front_set_rgb_signal (ma1017 * chip)
2677 {
2678   SANE_Status status;
2679 
2680   DBG (6, "usb_mid_front_set_rgb_signal: start\n");
2681   RIE (usb_low_set_red_ref (chip, 0xEF));
2682   RIE (usb_low_set_green_ref (chip, 0xF7));
2683   RIE (usb_low_set_blue_ref (chip, 0xFF));
2684   DBG (6, "usb_mid_front_set_rgb_signal: exit\n");
2685   return SANE_STATUS_GOOD;
2686 }
2687