1 /* sane - Scanner Access Now Easy. 2 3 Copyright (C) 2009-2012 stef.dev@free.fr 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 2 of the 8 License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19 /** @file p5_device.h 20 * @brief Declaration of low level structures used by the p5 backend. 21 * 22 * The structures and function declared here are used to do the low level 23 * communication with the physical device. 24 */ 25 26 #ifndef P5_DEVICE_H 27 #define P5_DEVICE_H 28 29 #include <stdlib.h> 30 #include <stdio.h> 31 #include <string.h> 32 #include "../include/_stdint.h" 33 34 #ifdef HAVE_LINUX_PPDEV_H 35 #include <errno.h> 36 #include <sys/stat.h> 37 #include <fcntl.h> 38 #include <sys/ioctl.h> 39 #include <linux/ppdev.h> 40 #include <linux/parport.h> 41 #endif 42 43 /** @name debugging levels 44 */ 45 /* @{ */ 46 #define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */ 47 #define DBG_error 1 /* fatal errors */ 48 #define DBG_warn 2 /* warnings and non-fatal errors */ 49 #define DBG_info 4 /* informational messages */ 50 #define DBG_proc 8 /* starting/finishing functions */ 51 #define DBG_trace 16 /* tracing messages */ 52 #define DBG_io 32 /* io functions */ 53 #define DBG_io2 64 /* io functions that are called very often */ 54 #define DBG_data 128 /* log image data */ 55 /* @} */ 56 57 /** 58 * maximal number of resolutions 59 */ 60 #define MAX_RESOLUTIONS 8 61 62 /**> sensor's number of pixels 8.5' @ 300 dpi */ 63 #define MAX_SENSOR_PIXELS 2550 64 65 /**> number of lines to skip when doing calibration */ 66 #define CALIBRATION_SKIP_LINES 80 67 68 /**> last value considered as black for calibration */ 69 #define BLACK_LEVEL 40 70 71 /**> white target value for calibration */ 72 #define WHITE_TARGET 220.0 73 74 /** per dpi calibration rgb data 75 * Calibration data structure 76 */ 77 typedef struct P5_Calibration_Data 78 { 79 unsigned int dpi; 80 uint8_t black_data[MAX_SENSOR_PIXELS * 3]; 81 uint8_t white_data[MAX_SENSOR_PIXELS * 3]; 82 } P5_Calibration_Data; 83 84 /** 85 * This structure describes a particular model which is handled by the backend. 86 * Contained data is immutable and is used to initialize the P5_Device 87 * structure. 88 */ 89 typedef struct P5_Model 90 { 91 /** @name device identifier 92 * These values are set up once the physical device has been detected. They 93 * are used to build the return value of sane_get_devices(). 94 */ 95 /* @{ */ 96 SANE_String_Const name; 97 SANE_String_Const vendor; 98 SANE_String_Const product; 99 SANE_String_Const type; 100 /* @} */ 101 102 /** @name resolution 103 * list of avalailable physical resolution. 104 * The resolutions must sorted from lower to higher value. The list is terminated 105 * by a value of 0. 106 */ 107 /* @{ */ 108 int xdpi_values[MAX_RESOLUTIONS]; /** possible x resolutions */ 109 int ydpi_values[MAX_RESOLUTIONS]; /** possible y resolutions */ 110 /* @} */ 111 112 /** @name scan area description 113 * Minimal and maximal values. It's easier to have dedicated members instead 114 * of searching these values in the dpi lists. They are initialized from dpi 115 * lists. 116 */ 117 /* @{ */ 118 int max_xdpi; /** physical maximum x dpi */ 119 int max_ydpi; /** physical maximum y dpi */ 120 int min_xdpi; /** physical minimum x dpi */ 121 int min_ydpi; /** physical minimum y dpi */ 122 /* @} */ 123 124 /** @name line distance shift 125 * Distance between CCD arrays for each color. Expressed in line 126 * number at maximum motor resolution. 127 */ 128 int lds; 129 130 /** @name scan area description 131 * The geometry values are expressed from the head parking position, 132 * or the start. For a given model, the scan area selected by a frontend 133 * will have to fit within these values. 134 */ 135 /* @{ */ 136 SANE_Fixed x_offset; /** Start of scan area in mm */ 137 SANE_Fixed y_offset; /** Start of scan area in mm */ 138 SANE_Fixed x_size; /** Size of scan area in mm */ 139 SANE_Fixed y_size; /** Size of scan area in mm */ 140 /* @} */ 141 142 } P5_Model; 143 144 145 /** 146 * Enumeration of configuration options for a device. It must starts at 0. 147 */ 148 enum P5_Configure_Option 149 { 150 CFG_MODEL_NAME = 0, /**<option to override model name */ 151 NUM_CFG_OPTIONS /** MUST be last to give the actual number of configuration options */ 152 }; 153 154 /** 155 * Device specific configuration structure to hold option values for 156 * devices handled by the p5 backend. There must one member for 157 * each configuration option. 158 */ 159 typedef struct P5_Config 160 { 161 SANE_String modelname; /** model name to use, overrinding the one from detection */ 162 } P5_Config; 163 164 165 /** 166 * Hardware device description. 167 * Since the settings used for a scan may actually differ from the one of the 168 * SANE level, it may contains scanning parameters and data relative to a current 169 * scan such as data buffers and counters. 170 */ 171 typedef struct P5_Device 172 { 173 /** 174 * Point to the next device in a linked list 175 */ 176 struct P5_Device *next; 177 178 /** 179 * Points to a structure that describes model capabilities, geometry 180 * and default settings. 181 */ 182 P5_Model *model; 183 184 /** 185 * @brief name of the device 186 * Name of the device: it may be the file name used to access the hardware. 187 * For instance parport0 for a parallel port device, or the libusb file name 188 * for an USB scanner. 189 */ 190 SANE_String name; 191 192 /** 193 * SANE_TRUE if the device is local (ie not over network) 194 */ 195 SANE_Bool local; 196 197 /** 198 * True if device has been initialized. 199 */ 200 SANE_Bool initialized; 201 202 /** 203 * Configuration options for the device read from 204 * configuration file at attach time. This member is filled at 205 * attach time. 206 */ 207 P5_Config *config; 208 209 /** @brief scan parameters 210 * The scan done by the hardware can be different from the one at the SANE 211 * frontend session. For instance: 212 * - xdpy and ydpi may be different to accommodate hardware capabilities. 213 * - many CCD scanners need to scan more lines to correct the 'line 214 * distance shift' effect. 215 * - emulated modes (lineart from gray scan, or gray scan for color one) 216 */ 217 /* @{ */ 218 int xdpi; /** real horizontal resolution */ 219 int ydpi; /** real vertical resolution */ 220 int lines; /** physical lines to scan */ 221 int pixels; /** physical width of scan area */ 222 int bytes_per_line; /** number of bytes per line */ 223 int xstart; /** x start coordinate */ 224 int ystart; /** y start coordinate */ 225 int mode; /** color, gray or lineart mode */ 226 int lds; /** line distance shift */ 227 /* @} */ 228 229 /** @brief device file descriptor 230 * low level device file descriptor 231 */ 232 int fd; 233 234 /** 235 * work buffer for scans 236 */ 237 uint8_t *buffer; 238 239 /** 240 * buffer size 241 */ 242 size_t size; 243 244 /** 245 * position in buffer 246 */ 247 size_t position; 248 249 /** 250 * top value of available bytes in buffer 251 */ 252 size_t top; 253 254 /** 255 * bottom value of available bytes in buffer 256 */ 257 size_t bottom; 258 259 /** 260 * True if device has been calibrated. 261 */ 262 SANE_Bool calibrated; 263 264 P5_Calibration_Data *calibration_data[MAX_RESOLUTIONS * 2]; 265 266 /**> correction coefficient for the current scan */ 267 float *gain; 268 uint8_t *offset; 269 270 } P5_Device; 271 272 273 #define DATA 0 274 #define STATUS 1 275 #define CONTROL 2 276 #define EPPADR 3 277 #define EPPDATA 4 278 279 #define REG0 0x00 280 #define REG1 0x11 281 #define REG2 0x22 282 #define REG3 0x33 283 #define REG4 0x44 284 #define REG5 0x55 285 #define REG6 0x66 286 #define REG7 0x77 287 #define REG8 0x88 288 #define REG9 0x99 289 #define REGA 0xAA 290 #define REGB 0xBB 291 #define REGC 0xCC 292 #define REGD 0xDD 293 #define REGE 0xEE 294 #define REGF 0xFF 295 296 #define MODE_COLOR 0 297 #define MODE_GRAY 1 298 #define MODE_LINEART 2 299 300 #endif /* not P5_DEVICE_H */ 301 302 /* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */ 303