1 /* sane - Scanner Access Now Easy. 2 3 Copyright (C) 2007-2012 stef.dev@free.fr 4 5 This file is part of the SANE package. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the 10 License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <https://www.gnu.org/licenses/>. 19 20 As a special exception, the authors of SANE give permission for 21 additional uses of the libraries contained in this release of SANE. 22 23 The exception is that, if you link a SANE library with other files 24 to produce an executable, this does not by itself cause the 25 resulting executable to be covered by the GNU General Public 26 License. Your use of that executable is in no way restricted on 27 account of linking the SANE library code into it. 28 29 This exception does not, however, invalidate any other reasons why 30 the executable file might be covered by the GNU General Public 31 License. 32 33 If you submit changes to SANE to the maintainers to be included in 34 a subsequent release, you agree by submitting the changes that 35 those changes may be distributed with this exception intact. 36 37 If you write modifications of your own for SANE, it is your choice 38 whether to permit this exception to apply to your modifications. 39 If you do not wish that, delete this exception notice. 40 */ 41 42 #ifndef RTS8891_LOW_H 43 #define RTS8891_LOW_H 44 45 #include <stddef.h> 46 #include "../include/sane/sane.h" 47 48 #define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */ 49 #define DBG_error 1 /* fatal errors */ 50 #define DBG_init 2 /* initialization and scanning time messages */ 51 #define DBG_warn 3 /* warnings and non-fatal errors */ 52 #define DBG_info 4 /* informational messages */ 53 #define DBG_proc 5 /* starting/finishing functions */ 54 #define DBG_io 6 /* io functions */ 55 #define DBG_io2 7 /* io functions that are called very often */ 56 #define DBG_data 8 /* log image data */ 57 58 59 /* Flags */ 60 #define RTS8891_FLAG_UNTESTED (1 << 0) /* Print a warning for these scanners */ 61 #define RTS8891_FLAG_EMULATED_GRAY_MODE (2 << 0) /* gray scans are emulated using color modes */ 62 63 #define LOWORD(x) ((uint16_t)(x & 0xffff)) 64 #define HIWORD(x) ((uint16_t)(x >> 16)) 65 #define LOBYTE(x) ((uint8_t)((x) & 0xFF)) 66 #define HIBYTE(x) ((uint8_t)((x) >> 8)) 67 68 #define MAX_SCANNERS 32 69 #define MAX_RESOLUTIONS 16 70 71 #define SENSOR_TYPE_BARE 0 /* sensor for hp4470 sold bare */ 72 #define SENSOR_TYPE_XPA 1 /* sensor for hp4470 sold with XPA */ 73 #define SENSOR_TYPE_4400 2 /* sensor for hp4400 */ 74 #define SENSOR_TYPE_4400_BARE 3 /* sensor for hp4400 */ 75 #define SENSOR_TYPE_MAX 3 /* maximum sensor number value */ 76 77 /* Forward typedefs */ 78 typedef struct Rts8891_Device Rts8891_Device; 79 80 #define SET_DOUBLE(regs,idx,value) regs[idx]=(SANE_Byte)((value)>>8); regs[idx-1]=(SANE_Byte)((value) & 0xff); 81 /* 82 * defines for RTS8891 registers name 83 */ 84 #define BUTTONS_REG2 0x1a 85 #define LINK_REG 0xb1 86 #define LAMP_REG 0xd9 87 #define LAMP_BRIGHT_REG 0xda 88 89 /* double reg (E6,E5) -> timing doubles when y resolution doubles 90 * E6 is high byte, possibly exposure */ 91 #define EXPOSURE_REG 0xe6 92 93 94 #define TIMING_REG 0x81 95 #define TIMING1_REG 0x83 /* holds REG8180+1 */ 96 #define TIMING2_REG 0x8a /* holds REG8180+2 */ 97 98 99 /* this struct describes a particular model which is handled by the backend */ 100 /* available resolutions, physical goemetry, scanning area, ... */ 101 typedef struct Rts8891_Model 102 { 103 SANE_String_Const name; 104 SANE_String_Const vendor; 105 SANE_String_Const product; 106 SANE_String_Const type; 107 108 SANE_Int xdpi_values[MAX_RESOLUTIONS]; /* possible x resolutions */ 109 SANE_Int ydpi_values[MAX_RESOLUTIONS]; /* possible y resolutions */ 110 111 SANE_Int max_xdpi; /* physical maximum x dpi */ 112 SANE_Int max_ydpi; /* physical maximum y dpi */ 113 SANE_Int min_ydpi; /* physical minimum y dpi */ 114 115 SANE_Fixed x_offset; /* Start of scan area in mm */ 116 SANE_Fixed y_offset; /* Start of scan area in mm */ 117 SANE_Fixed x_size; /* Size of scan area in mm */ 118 SANE_Fixed y_size; /* Size of scan area in mm */ 119 120 SANE_Fixed x_offset_ta; /* Start of scan area in TA mode in mm */ 121 SANE_Fixed y_offset_ta; /* Start of scan area in TA mode in mm */ 122 SANE_Fixed x_size_ta; /* Size of scan area in TA mode in mm */ 123 SANE_Fixed y_size_ta; /* Size of scan area in TA mode in mm */ 124 125 /* Line-distance correction (in pixel at max optical dpi) for CCD scanners */ 126 SANE_Int ld_shift_r; /* red */ 127 SANE_Int ld_shift_g; /* green */ 128 SANE_Int ld_shift_b; /* blue */ 129 130 /* default sensor type */ 131 SANE_Int sensor; 132 133 /* default gamma table */ 134 SANE_Word gamma[256]; 135 SANE_Int buttons; /* number of buttons for the scanner */ 136 char *button_name[11]; /* option names for buttons */ 137 char *button_title[11]; /* option titles for buttons */ 138 SANE_Word flags; /* allow per model behaviour control */ 139 } Rts8891_Model; 140 141 142 /** 143 * device specific configuration structure to hold option values */ 144 typedef struct Rts8891_Config 145 { 146 /**< index number in device table to override detection */ 147 SANE_Word modelnumber; 148 149 /**< id of the snedor type, must match SENSOR_TYPE_* defines */ 150 SANE_Word sensornumber; 151 152 /**< if true, use release/acquire to allow the same device 153 * to be used by several frontends */ 154 SANE_Bool allowsharing; 155 } Rts8891_Config; 156 157 158 /** 159 * device descriptor 160 */ 161 struct Rts8891_Device 162 { 163 /**< Next device in linked list */ 164 struct Rts8891_Device *next; 165 166 /**< USB device number for libusb */ 167 SANE_Int devnum; 168 SANE_String file_name; 169 Rts8891_Model *model; /* points to a structure that describes model specifics */ 170 171 SANE_Int sensor; /* sensor id */ 172 173 SANE_Bool initialized; /* true if device has been initialized */ 174 SANE_Bool needs_warming; /* true if device needs warming up */ 175 SANE_Bool parking; /* true if device is parking head */ 176 177 /* values detected during find origin */ 178 /* TODO these are currently unused after detection */ 179 SANE_Int left_offset; /* pixels to skip to be on left start of the scanning area */ 180 SANE_Int top_offset; /* lines to skip to be at top of the scanning area */ 181 182 /* gains from calibration */ 183 SANE_Int red_gain; 184 SANE_Int green_gain; 185 SANE_Int blue_gain; 186 187 /* offsets from calibration */ 188 SANE_Int red_offset; 189 SANE_Int green_offset; 190 SANE_Int blue_offset; 191 192 /* actual dpi used at hardware level may differ from the one 193 * at SANE level */ 194 SANE_Int xdpi; 195 SANE_Int ydpi; 196 197 /* the effective scan area at hardware level may be different from 198 * the one at the SANE level*/ 199 SANE_Int lines; /* lines to scan */ 200 SANE_Int pixels; /* width of scan area */ 201 SANE_Int bytes_per_line; /* number of bytes per line */ 202 SANE_Int xstart; /* x start coordinate */ 203 SANE_Int ystart; /* y start coordinate */ 204 205 /* line distance shift for the active scan */ 206 SANE_Int lds_r; 207 SANE_Int lds_g; 208 SANE_Int lds_b; 209 210 /* threshold to give 0/1 nit in lineart */ 211 SANE_Int threshold; 212 213 /* max value from lds_r, lds_g and lds_b */ 214 SANE_Int lds_max; 215 216 /* amount of data needed to correct ripple effect at highest dpi */ 217 SANE_Int ripple; 218 219 /* register set of the scanner */ 220 SANE_Int reg_count; 221 SANE_Byte regs[255]; 222 223 /* shading calibration data */ 224 SANE_Byte *shading_data; 225 226 /* data buffer read from scanner */ 227 SANE_Byte *scanned_data; 228 229 /* size of the buffer */ 230 SANE_Int data_size; 231 232 /* start of the data within scanned data */ 233 SANE_Byte *start; 234 235 /* current pointer within scanned data */ 236 SANE_Byte *current; 237 238 /* end of the data buffer */ 239 SANE_Byte *end; 240 241 /** 242 * amount of bytes read from scanner 243 */ 244 SANE_Int read; 245 246 /** 247 * total amount of bytes to read for the scan 248 */ 249 SANE_Int to_read; 250 251 #ifdef HAVE_SYS_TIME_H 252 /** 253 * last scan time, used to detect if warming-up is needed 254 */ 255 struct timeval last_scan; 256 257 /** 258 * warming-up start time 259 */ 260 struct timeval start_time; 261 #endif 262 263 /** 264 * device configuration options 265 */ 266 Rts8891_Config conf; 267 }; 268 269 /* 270 * This struct is used to build a static list of USB IDs and link them 271 * to a struct that describes the corresponding model. 272 */ 273 typedef struct Rts8891_USB_Device_Entry 274 { 275 SANE_Word vendor_id; /**< USB vendor identifier */ 276 SANE_Word product_id; /**< USB product identifier */ 277 Rts8891_Model *model; /**< Scanner model information */ 278 } Rts8891_USB_Device_Entry; 279 280 /* this function init the rts8891 library */ 281 void rts8891_lib_init (void); 282 283 /***********************************/ 284 /* RTS8891 ASIC specific functions */ 285 /***********************************/ 286 287 /* this functions commits pending scan command */ 288 static SANE_Status rts8891_commit (SANE_Int devnum, SANE_Byte value); 289 290 /* wait for head to park to home position */ 291 static SANE_Status rts8891_wait_for_home (struct Rts8891_Device *device, SANE_Byte * regs); 292 293 /** 294 * move the head backward by a huge line number then poll home sensor until 295 * head has get back home 296 */ 297 static SANE_Status rts8891_park (struct Rts8891_Device *device, SANE_Byte * regs, SANE_Bool wait); 298 299 #endif /* not RTS8891_LOW_H */ 300