1141cc406Sopenharmony_ci/*
2141cc406Sopenharmony_ci  Copyright (C) 2000 by Adrian Perez Jorge
3141cc406Sopenharmony_ci
4141cc406Sopenharmony_ci  This program is free software; you can redistribute it and/or
5141cc406Sopenharmony_ci  modify it under the terms of the GNU General Public License
6141cc406Sopenharmony_ci  as published by the Free Software Foundation; either version 2
7141cc406Sopenharmony_ci  of the License, or (at your option) any later version.
8141cc406Sopenharmony_ci
9141cc406Sopenharmony_ci  This program is distributed in the hope that it will be useful,
10141cc406Sopenharmony_ci  but WITHOUT ANY WARRANTY; without even the implied warranty of
11141cc406Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12141cc406Sopenharmony_ci  GNU General Public License for more details.
13141cc406Sopenharmony_ci
14141cc406Sopenharmony_ci  You should have received a copy of the GNU General Public License
15141cc406Sopenharmony_ci  along with this program.  If not, see <https://www.gnu.org/licenses/>.
16141cc406Sopenharmony_ci */
17141cc406Sopenharmony_ci
18141cc406Sopenharmony_ci#ifndef _HP4200_H
19141cc406Sopenharmony_ci#define _HP4200_H
20141cc406Sopenharmony_ci
21141cc406Sopenharmony_ci#include <sys/types.h>
22141cc406Sopenharmony_ci
23141cc406Sopenharmony_ci#define MCLKDIV_SCALING 2
24141cc406Sopenharmony_ci#define NUM_REGISTERS 0x80
25141cc406Sopenharmony_ci
26141cc406Sopenharmony_ci#define min(a, b) (((a) < (b)) ? (a) : (b))
27141cc406Sopenharmony_ci#define max(a, b) (((a) > (b)) ? (a) : (b))
28141cc406Sopenharmony_ci
29141cc406Sopenharmony_ci
30141cc406Sopenharmony_ci/*--------------------------------------------------------------------------*/
31141cc406Sopenharmony_ci
32141cc406Sopenharmony_ci#define DBG_error0  0
33141cc406Sopenharmony_ci#define DBG_error   1
34141cc406Sopenharmony_ci#define DBG_sense   2
35141cc406Sopenharmony_ci#define DBG_warning 3
36141cc406Sopenharmony_ci#define DBG_inquiry 4
37141cc406Sopenharmony_ci#define DBG_info    5
38141cc406Sopenharmony_ci#define DBG_info2   6
39141cc406Sopenharmony_ci#define DBG_proc    7
40141cc406Sopenharmony_ci#define DBG_read    8
41141cc406Sopenharmony_ci#define DBG_sane_init   10
42141cc406Sopenharmony_ci#define DBG_sane_proc   11
43141cc406Sopenharmony_ci#define DBG_sane_info   12
44141cc406Sopenharmony_ci#define DBG_sane_option 13
45141cc406Sopenharmony_ci
46141cc406Sopenharmony_ci/*--------------------------------------------------------------------------*/
47141cc406Sopenharmony_ci
48141cc406Sopenharmony_cienum HP4200_Option
49141cc406Sopenharmony_ci{
50141cc406Sopenharmony_ci  OPT_NUM_OPTS = 0,
51141cc406Sopenharmony_ci
52141cc406Sopenharmony_ci  OPT_RES,
53141cc406Sopenharmony_ci
54141cc406Sopenharmony_ci  OPT_TL_X,			/* top-left x */
55141cc406Sopenharmony_ci  OPT_TL_Y,			/* top-left y */
56141cc406Sopenharmony_ci  OPT_BR_X,			/* bottom-right x */
57141cc406Sopenharmony_ci  OPT_BR_Y,			/* bottom-right y */
58141cc406Sopenharmony_ci
59141cc406Sopenharmony_ci  OPT_BACKTRACK,
60141cc406Sopenharmony_ci
61141cc406Sopenharmony_ci  OPT_GAMMA_VECTOR_R,
62141cc406Sopenharmony_ci  OPT_GAMMA_VECTOR_G,
63141cc406Sopenharmony_ci  OPT_GAMMA_VECTOR_B,
64141cc406Sopenharmony_ci
65141cc406Sopenharmony_ci  OPT_PREVIEW,
66141cc406Sopenharmony_ci
67141cc406Sopenharmony_ci  NUM_OPTIONS			/* must come last */
68141cc406Sopenharmony_ci};
69141cc406Sopenharmony_ci
70141cc406Sopenharmony_ci/* already declared in the sane includes...
71141cc406Sopenharmony_citypedef union
72141cc406Sopenharmony_ci{
73141cc406Sopenharmony_ci	SANE_Word w;
74141cc406Sopenharmony_ci	SANE_Bool b;
75141cc406Sopenharmony_ci	SANE_Fixed f;
76141cc406Sopenharmony_ci	SANE_Word *wa;
77141cc406Sopenharmony_ci}
78141cc406Sopenharmony_ciOption_Value;
79141cc406Sopenharmony_ci*/
80141cc406Sopenharmony_ci
81141cc406Sopenharmony_cienum ScannerModels
82141cc406Sopenharmony_ci{
83141cc406Sopenharmony_ci  HP4200
84141cc406Sopenharmony_ci};
85141cc406Sopenharmony_ci
86141cc406Sopenharmony_citypedef struct HP4200_Device
87141cc406Sopenharmony_ci{
88141cc406Sopenharmony_ci  struct HP4200_Device *next;
89141cc406Sopenharmony_ci  SANE_Device dev;
90141cc406Sopenharmony_ci  SANE_Handle handle;
91141cc406Sopenharmony_ci}
92141cc406Sopenharmony_ciHP4200_Device;
93141cc406Sopenharmony_ci
94141cc406Sopenharmony_cistruct _scanner_buffer_t
95141cc406Sopenharmony_ci{
96141cc406Sopenharmony_ci  unsigned char *buffer;	/* buffer memory space */
97141cc406Sopenharmony_ci  int size;			/* size of the buffer */
98141cc406Sopenharmony_ci  int num_bytes;		/* number of bytes left (to read) */
99141cc406Sopenharmony_ci  unsigned char *data_ptr;	/* cursor in buffer */
100141cc406Sopenharmony_ci};
101141cc406Sopenharmony_ci
102141cc406Sopenharmony_citypedef struct _scanner_buffer_t scanner_buffer_t;
103141cc406Sopenharmony_ci
104141cc406Sopenharmony_cistruct _ciclic_buffer_t
105141cc406Sopenharmony_ci{
106141cc406Sopenharmony_ci  int good_bytes;		/* number of valid bytes of the image */
107141cc406Sopenharmony_ci  int num_lines;		/* number of lines of the ciclic buffer */
108141cc406Sopenharmony_ci  int size;			/* size in bytes of the buffer space */
109141cc406Sopenharmony_ci  unsigned char *buffer;	/* pointer to the buffer space */
110141cc406Sopenharmony_ci  unsigned char **buffer_ptrs;	/* pointers to the beginning of each
111141cc406Sopenharmony_ci				   line in the buffer space */
112141cc406Sopenharmony_ci  int can_consume;		/* num of bytes the ciclic buf can consume */
113141cc406Sopenharmony_ci  int current_line;		/* current scanned line */
114141cc406Sopenharmony_ci  int first_good_line;		/* number of lines to fill the ``pipeline'' */
115141cc406Sopenharmony_ci  unsigned char *buffer_position;	/* pointer to the first byte that
116141cc406Sopenharmony_ci					   can be copied */
117141cc406Sopenharmony_ci  int pixel_position;		/* pixel position in current line */
118141cc406Sopenharmony_ci
119141cc406Sopenharmony_ci  /* color indexes for the proper line in the ciclic buffer */
120141cc406Sopenharmony_ci  int red_idx;
121141cc406Sopenharmony_ci  int green_idx;
122141cc406Sopenharmony_ci  int blue_idx;
123141cc406Sopenharmony_ci};
124141cc406Sopenharmony_ci
125141cc406Sopenharmony_citypedef struct _ciclic_buffer_t ciclic_buffer_t;
126141cc406Sopenharmony_ci
127141cc406Sopenharmony_cistruct _hardware_parameters_t
128141cc406Sopenharmony_ci{
129141cc406Sopenharmony_ci  unsigned int SRAM_size;
130141cc406Sopenharmony_ci  unsigned char SRAM_bandwidth;
131141cc406Sopenharmony_ci  unsigned long crystal_frequency;
132141cc406Sopenharmony_ci  unsigned int min_pixel_data_buffer_limit;
133141cc406Sopenharmony_ci  unsigned int motor_full_steps_per_inch;
134141cc406Sopenharmony_ci  float motor_max_speed;
135141cc406Sopenharmony_ci  unsigned int scan_bar_max_speed;
136141cc406Sopenharmony_ci  unsigned int start_of_scanning_area;
137141cc406Sopenharmony_ci  unsigned int calibration_strip_height;
138141cc406Sopenharmony_ci  unsigned int scan_area_width;
139141cc406Sopenharmony_ci  double scan_area_length;	/* in inches */
140141cc406Sopenharmony_ci  unsigned int sensor_num_pixels;
141141cc406Sopenharmony_ci  unsigned int sensor_pixel_start;
142141cc406Sopenharmony_ci  unsigned int sensor_pixel_end;
143141cc406Sopenharmony_ci  int sensor_cds_state;		/* 0 == off, 1 == on */
144141cc406Sopenharmony_ci  int sensor_signal_polarity;	/* 0 == ??, 1 == ?? */
145141cc406Sopenharmony_ci  int sensor_max_integration_time;
146141cc406Sopenharmony_ci  int sensor_line_separation;
147141cc406Sopenharmony_ci  int sensor_type;
148141cc406Sopenharmony_ci  unsigned int sensor_resolution;
149141cc406Sopenharmony_ci  int sensor_control_signals_polarity;
150141cc406Sopenharmony_ci  int sensor_control_signals_state;
151141cc406Sopenharmony_ci  int sensor_control_pixel_rate_timing;
152141cc406Sopenharmony_ci  int sensor_control_line_rate_timing;
153141cc406Sopenharmony_ci  unsigned int sensor_black_clamp_timing;	/* ??? */
154141cc406Sopenharmony_ci  unsigned int sensor_CIS_timing;
155141cc406Sopenharmony_ci  int sensor_toshiba_timing;
156141cc406Sopenharmony_ci  int sensor_color_modes;	/* bitmask telling color modes supported */
157141cc406Sopenharmony_ci  int illumination_mode;
158141cc406Sopenharmony_ci  int motor_control_mode;
159141cc406Sopenharmony_ci  int motor_paper_sense_mode;
160141cc406Sopenharmony_ci  int motor_pause_reverse_mode;
161141cc406Sopenharmony_ci  int misc_io_mode;
162141cc406Sopenharmony_ci  int num_tr_pulses;
163141cc406Sopenharmony_ci  int guard_band_duration;
164141cc406Sopenharmony_ci  int pulse_duration;
165141cc406Sopenharmony_ci  int fsteps_25_speed;
166141cc406Sopenharmony_ci  int fsteps_50_speed;
167141cc406Sopenharmony_ci  int steps_to_reverse;
168141cc406Sopenharmony_ci  struct
169141cc406Sopenharmony_ci  {
170141cc406Sopenharmony_ci    int red;
171141cc406Sopenharmony_ci    int green;
172141cc406Sopenharmony_ci    int blue;
173141cc406Sopenharmony_ci  }
174141cc406Sopenharmony_ci  target_value;
175141cc406Sopenharmony_ci  unsigned short home_sensor;
176141cc406Sopenharmony_ci};
177141cc406Sopenharmony_ci
178141cc406Sopenharmony_citypedef struct _hardware_parameters_t hardware_parameters_t;
179141cc406Sopenharmony_ci
180141cc406Sopenharmony_cistruct _user_parameters_t
181141cc406Sopenharmony_ci{
182141cc406Sopenharmony_ci  unsigned int image_width;
183141cc406Sopenharmony_ci  unsigned int lines_to_scan;
184141cc406Sopenharmony_ci  unsigned int horizontal_resolution;
185141cc406Sopenharmony_ci  unsigned int vertical_resolution;
186141cc406Sopenharmony_ci  int hres_reduction_method;	/* interpolation/??? */
187141cc406Sopenharmony_ci  int vres_reduction_method;
188141cc406Sopenharmony_ci  SANE_Bool color;		/* color/grayscale */
189141cc406Sopenharmony_ci  int bpp;
190141cc406Sopenharmony_ci  int scan_mode;		/* preview/full scan */
191141cc406Sopenharmony_ci  SANE_Bool no_reverse;
192141cc406Sopenharmony_ci  SANE_Word gamma[3][1024];	/* gamma table for rgb */
193141cc406Sopenharmony_ci};
194141cc406Sopenharmony_ci
195141cc406Sopenharmony_citypedef struct _user_parameters_t user_parameters_t;
196141cc406Sopenharmony_ci
197141cc406Sopenharmony_cistruct _measured_parameters_t
198141cc406Sopenharmony_ci{
199141cc406Sopenharmony_ci  unsigned int datalink_bandwidth;
200141cc406Sopenharmony_ci  struct
201141cc406Sopenharmony_ci  {
202141cc406Sopenharmony_ci    int red;
203141cc406Sopenharmony_ci    int green;
204141cc406Sopenharmony_ci    int blue;
205141cc406Sopenharmony_ci  }
206141cc406Sopenharmony_ci  coarse_calibration_data;
207141cc406Sopenharmony_ci  struct
208141cc406Sopenharmony_ci  {
209141cc406Sopenharmony_ci    int *pRedOffset;
210141cc406Sopenharmony_ci    int *pGreenOffset;
211141cc406Sopenharmony_ci    int *pBlueOffset;
212141cc406Sopenharmony_ci    int *pRedGain;
213141cc406Sopenharmony_ci    int *pGreenGain;
214141cc406Sopenharmony_ci    int *pBlueGain;
215141cc406Sopenharmony_ci  }
216141cc406Sopenharmony_ci  fine_calibration_data;
217141cc406Sopenharmony_ci  int max_integration_time;
218141cc406Sopenharmony_ci  int color_mode;
219141cc406Sopenharmony_ci};
220141cc406Sopenharmony_ci
221141cc406Sopenharmony_citypedef struct _measured_parameters_t measured_parameters_t;
222141cc406Sopenharmony_ci
223141cc406Sopenharmony_cistruct _runtime_parameters_t
224141cc406Sopenharmony_ci{
225141cc406Sopenharmony_ci  long num_bytes_left_to_scan;
226141cc406Sopenharmony_ci  int status_bytes;		/* number of status bytes per line */
227141cc406Sopenharmony_ci  int image_line_size;		/* line size in bytes without status bytes */
228141cc406Sopenharmony_ci  int scanner_line_size;	/* line size in bytes including the
229141cc406Sopenharmony_ci				   status bytes */
230141cc406Sopenharmony_ci  int first_pixel;		/* first pixel in the line to be scanned */
231141cc406Sopenharmony_ci  int steps_to_skip;
232141cc406Sopenharmony_ci};
233141cc406Sopenharmony_ci
234141cc406Sopenharmony_citypedef struct _runtime_parameters_t runtime_parameters_t;
235141cc406Sopenharmony_ci
236141cc406Sopenharmony_cistruct _HP4200_Scanner
237141cc406Sopenharmony_ci{
238141cc406Sopenharmony_ci  struct _HP4200_Scanner *next;
239141cc406Sopenharmony_ci
240141cc406Sopenharmony_ci  SANE_Option_Descriptor opt[NUM_OPTIONS];
241141cc406Sopenharmony_ci  Option_Value val[NUM_OPTIONS];
242141cc406Sopenharmony_ci
243141cc406Sopenharmony_ci  SANE_Bool scanning;
244141cc406Sopenharmony_ci  SANE_Bool aborted_by_user;
245141cc406Sopenharmony_ci
246141cc406Sopenharmony_ci  SANE_Parameters params;
247141cc406Sopenharmony_ci
248141cc406Sopenharmony_ci  HP4200_Device *dev;
249141cc406Sopenharmony_ci  hardware_parameters_t hw_parms;
250141cc406Sopenharmony_ci  user_parameters_t user_parms;
251141cc406Sopenharmony_ci  measured_parameters_t msrd_parms;
252141cc406Sopenharmony_ci  unsigned int regs[NUM_REGISTERS];
253141cc406Sopenharmony_ci  int mclk;
254141cc406Sopenharmony_ci  float mclk_div;
255141cc406Sopenharmony_ci
256141cc406Sopenharmony_ci  int fd;
257141cc406Sopenharmony_ci
258141cc406Sopenharmony_ci  ciclic_buffer_t ciclic_buffer;
259141cc406Sopenharmony_ci  scanner_buffer_t scanner_buffer;
260141cc406Sopenharmony_ci  runtime_parameters_t runtime_parms;
261141cc406Sopenharmony_ci};
262141cc406Sopenharmony_ci
263141cc406Sopenharmony_citypedef struct _HP4200_Scanner HP4200_Scanner;
264141cc406Sopenharmony_ci
265141cc406Sopenharmony_ci#endif /* !_HP4200_H */
266