2005-06-27 20:07:45 +00:00
/* sane - Scanner Access Now Easy.
Copyright ( C ) 2003 Oliver Rauch
Copyright ( C ) 2003 , 2004 Henning Meier - Geinitz < henning @ meier - geinitz . de >
Copyright ( C ) 2004 , 2005 Gerhard Jaeger < gerhard @ gjaeger . de >
2011-02-16 06:13:01 +00:00
Copyright ( C ) 2004 - 2011 St <EFBFBD> phane Voltz < stef . dev @ free . fr >
2009-02-27 12:37:16 +00:00
Copyright ( C ) 2005 - 2009 Pierre Willenbrock < pierre @ pirsoft . dnsalias . org >
2006-03-27 14:41:30 +00:00
Copyright ( C ) 2006 Laurent Charpentier < laurent_pubs @ yahoo . com >
2005-06-27 20:07:45 +00:00
Parts of the structs have been taken from the gt68xx backend by
Sergey Vlasov < vsu @ altlinux . ru > et al .
This file is part of the SANE package .
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation ; either version 2 of the
License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston ,
MA 02111 - 1307 , USA .
As a special exception , the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE .
The exception is that , if you link a SANE library with other files
to produce an executable , this does not by itself cause the
resulting executable to be covered by the GNU General Public
License . Your use of that executable is in no way restricted on
account of linking the SANE library code into it .
This exception does not , however , invalidate any other reasons why
the executable file might be covered by the GNU General Public
License .
If you submit changes to SANE to the maintainers to be included in
a subsequent release , you agree by submitting the changes that
those changes may be distributed with this exception intact .
If you write modifications of your own for SANE , it is your choice
whether to permit this exception to apply to your modifications .
If you do not wish that , delete this exception notice .
*/
# ifndef GENESYS_LOW_H
# define GENESYS_LOW_H
# include <stddef.h>
2009-07-09 05:54:58 +00:00
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
2005-06-27 20:07:45 +00:00
# include "../include/sane/sane.h"
# define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */
# define DBG_error 1 /* fatal errors */
# define DBG_init 2 /* initialization and scanning time messages */
# define DBG_warn 3 /* warnings and non-fatal errors */
# define DBG_info 4 /* informational messages */
# define DBG_proc 5 /* starting/finishing functions */
# define DBG_io 6 /* io functions */
# define DBG_io2 7 /* io functions that are called very often */
# define DBG_data 8 /* log image data */
# define RIE(function) \
do { status = function ; \
if ( status ! = SANE_STATUS_GOOD ) return status ; \
} while ( SANE_FALSE )
2011-01-12 19:51:32 +00:00
# define DBGSTART DBG (DBG_proc, "%s start\n", __FUNCTION__);
# define DBGCOMPLETED DBG (DBG_proc, "%s completed\n", __FUNCTION__);
2005-06-27 20:07:45 +00:00
/* Flags */
2010-09-17 04:47:21 +00:00
# define GENESYS_FLAG_UNTESTED (1 << 0) /**> Print a warning for these scanners */
# define GENESYS_FLAG_14BIT_GAMMA (1 << 1) /**> use 14bit Gamma table instead of 12 */
# define GENESYS_FLAG_LAZY_INIT (1 << 2) /**> skip extensive ASIC test at init */
2010-02-16 06:24:56 +00:00
# define GENESYS_FLAG_XPA (1 << 3)
2010-09-17 04:47:21 +00:00
# define GENESYS_FLAG_SKIP_WARMUP (1 << 4) /**> skip genesys_warmup() */
# define GENESYS_FLAG_OFFSET_CALIBRATION (1 << 5) /**> do offset calibration */
# define GENESYS_FLAG_SEARCH_START (1 << 6) /**> do start search before scanning */
# define GENESYS_FLAG_REPARK (1 << 7) / **> repark head (and check for lock) by
2005-06-27 20:07:45 +00:00
moving without scanning */
2010-09-17 04:47:21 +00:00
# define GENESYS_FLAG_DARK_CALIBRATION (1 << 8) /**> do dark calibration */
# define GENESYS_FLAG_STAGGERED_LINE (1 << 9) /**> pixel columns are shifted vertically for hi-res modes */
2005-06-27 20:07:45 +00:00
2010-09-17 04:47:21 +00:00
# define GENESYS_FLAG_MUST_WAIT (1 << 10) /**> tells wether the scanner must wait for the head when parking */
2005-11-19 22:51:01 +00:00
2010-09-17 04:47:21 +00:00
# define GENESYS_FLAG_ALT_SLOPE_CREATE (1 << 11) /**> use alternative slope creation function */
2005-11-19 22:51:01 +00:00
2010-09-17 04:47:21 +00:00
# define GENESYS_FLAG_DARK_WHITE_CALIBRATION (1 << 12) /**> yet another calibration method. does white and dark shading in one run, depending on a black and a white strip*/
# define GENESYS_FLAG_CUSTOM_GAMMA (1 << 13) /**> allow custom gamma tables */
# define GENESYS_FLAG_NO_CALIBRATION (1 << 14) /**> allow scanners to use skip the calibration, needed for sheetfed scanners */
# define GENESYS_FLAG_HALF_CCD_MODE (1 << 15) /**> scanner has setting for half ccd mode */
2011-01-24 05:22:14 +00:00
# define GENESYS_FLAG_SIS_SENSOR (1 << 16) /**> handling of multi-segments sensors in software */
2009-01-19 05:46:43 +00:00
2010-09-17 04:47:21 +00:00
# define GENESYS_HAS_NO_BUTTONS 0 /**> scanner has no supported button */
# define GENESYS_HAS_SCAN_SW (1 << 0) /**> scanner has SCAN button */
# define GENESYS_HAS_FILE_SW (1 << 1) /**> scanner has FILE button */
# define GENESYS_HAS_COPY_SW (1 << 2) /**> scanner has COPY button */
# define GENESYS_HAS_EMAIL_SW (1 << 3) /**> scanner has EMAIL button */
# define GENESYS_HAS_PAGE_LOADED_SW (1 << 4) /**> scanner has paper in detection */
# define GENESYS_HAS_OCR_SW (1 << 5) /**> scanner has OCR button */
# define GENESYS_HAS_POWER_SW (1 << 6) /**> scanner has power button */
# define GENESYS_HAS_CALIBRATE (1 << 7) /**> scanner has 'calibrate' software button to start calibration */
2009-01-18 14:20:55 +00:00
2005-06-27 20:07:45 +00:00
/* USB control message values */
# define REQUEST_TYPE_IN (USB_TYPE_VENDOR | USB_DIR_IN)
# define REQUEST_TYPE_OUT (USB_TYPE_VENDOR | USB_DIR_OUT)
# define REQUEST_REGISTER 0x0c
# define REQUEST_BUFFER 0x04
# define VALUE_BUFFER 0x82
# define VALUE_SET_REGISTER 0x83
# define VALUE_READ_REGISTER 0x84
# define VALUE_WRITE_REGISTER 0x85
# define VALUE_INIT 0x87
# define GPIO_OUTPUT_ENABLE 0x89
# define GPIO_READ 0x8a
# define GPIO_WRITE 0x8b
2010-04-25 19:32:44 +00:00
# define VALUE_BUF_ENDACCESS 0x8c
# define VALUE_GET_REGISTER 0x8e
2005-06-27 20:07:45 +00:00
# define INDEX 0x00
/* todo: used?
# define VALUE_READ_STATUS 0x86
*/
/* Read/write bulk data/registers */
# define BULK_OUT 0x01
# define BULK_IN 0x00
# define BULK_RAM 0x00
# define BULK_REGISTER 0x11
2005-11-19 22:51:01 +00:00
# define BULKIN_MAXSIZE 0xFE00
2009-01-19 05:46:43 +00:00
# define GL646_BULKIN_MAXSIZE 0xFFC0
# define GL646_BULKIN_MINSIZE 0x0800
2005-06-27 20:07:45 +00:00
# define BULKOUT_MAXSIZE 0xF000
/* AFE values */
# define AFE_INIT 1
# define AFE_SET 2
# define AFE_POWER_SAVE 4
2010-04-25 19:32:44 +00:00
# define LOWORD(x) ((uint16_t)((x) & 0xffff))
# define HIWORD(x) ((uint16_t)((x) >> 16))
2009-02-26 03:15:43 +00:00
# define LOBYTE(x) ((uint8_t)((x) & 0xFF))
# define HIBYTE(x) ((uint8_t)((x) >> 8))
2005-06-27 20:07:45 +00:00
/* Global constants */
2010-11-06 20:12:56 +00:00
/* TODO: emove this leftover of early backend days */
2005-06-27 20:07:45 +00:00
# define MOTOR_SPEED_MAX 350
# define DARK_VALUE 0
2010-11-06 20:12:56 +00:00
# define PWRBIT 0x80
# define BUFEMPTY 0x40
# define FEEDFSH 0x20
# define SCANFSH 0x10
# define HOMESNR 0x08
# define LAMPSTS 0x04
# define FEBUSY 0x02
# define MOTORENB 0x01
2005-06-27 20:07:45 +00:00
typedef struct
{
SANE_Byte address ;
SANE_Byte value ;
} Genesys_Register_Set ;
typedef struct
{
2009-02-27 12:37:16 +00:00
uint8_t fe_id ; /**> id of the frontend description */
2009-02-26 03:15:43 +00:00
uint8_t reg [ 4 ] ;
uint8_t sign [ 3 ] ;
uint8_t offset [ 3 ] ;
uint8_t gain [ 3 ] ;
uint8_t reg2 [ 3 ] ;
2005-06-27 20:07:45 +00:00
} Genesys_Frontend ;
typedef struct
{
2009-02-27 12:37:16 +00:00
uint8_t sensor_id ; /**> id of the sensor description */
2005-06-27 20:07:45 +00:00
int optical_res ;
int black_pixels ;
2005-11-19 22:51:01 +00:00
int dummy_pixel ; /* value of dummy register. */
2005-06-27 20:07:45 +00:00
int CCD_start_xoffset ; /* last pixel of CCD margin at optical resolution */
int sensor_pixels ; /* total pixels used by the sensor */
int fau_gain_white_ref ; /* TA CCD target code (reference gain) */
int gain_white_ref ; /* CCD target code (reference gain) */
2009-02-26 03:15:43 +00:00
uint8_t regs_0x08_0x0b [ 4 ] ;
uint8_t regs_0x10_0x1d [ 14 ] ;
uint8_t regs_0x52_0x5e [ 13 ] ;
2005-06-27 20:07:45 +00:00
float red_gamma ;
float green_gamma ;
float blue_gamma ;
2009-02-26 03:15:43 +00:00
uint16_t * red_gamma_table ;
uint16_t * green_gamma_table ;
uint16_t * blue_gamma_table ;
2005-06-27 20:07:45 +00:00
} Genesys_Sensor ;
typedef struct
{
2009-02-27 12:37:16 +00:00
uint8_t gpo_id ; /**> id of the gpo description */
2009-02-26 03:15:43 +00:00
uint8_t value [ 2 ] ;
uint8_t enable [ 2 ] ;
2005-06-27 20:07:45 +00:00
} Genesys_Gpo ;
typedef struct
{
2005-11-19 22:51:01 +00:00
SANE_Int maximum_start_speed ; /* maximum speed allowed when accelerating from standstill. Unit: pixeltime/step */
SANE_Int maximum_speed ; /* maximum speed allowed. Unit: pixeltime/step */
SANE_Int minimum_steps ; /* number of steps used for default curve */
float g ; /* power for non-linear acceleration curves. */
/* vs*(1-i^g)+ve*(i^g) where
vs = start speed , ve = end speed ,
i = 0.0 for first entry and i = 1.0 for last entry in default table */
} Genesys_Motor_Slope ;
typedef struct
{
2009-02-27 12:37:16 +00:00
uint8_t motor_id ; /**> id of the motor description */
2005-11-19 22:51:01 +00:00
SANE_Int base_ydpi ; /* motor base steps. Unit: 1/" */
SANE_Int optical_ydpi ; /* maximum resolution in y-direction. Unit: 1/" */
SANE_Int max_step_type ; /* maximum step type. 0-2 */
2007-11-22 14:05:13 +00:00
SANE_Int power_mode_count ; /* number of power modes*/
Genesys_Motor_Slope slopes [ 2 ] [ 3 ] ; /* slopes to derive individual slopes from */
2005-06-27 20:07:45 +00:00
} Genesys_Motor ;
typedef enum Genesys_Color_Order
{
COLOR_ORDER_RGB ,
COLOR_ORDER_BGR
}
Genesys_Color_Order ;
2010-12-16 21:22:14 +00:00
# define MAX_SCANNERS 50
2005-06-27 20:07:45 +00:00
# define MAX_RESOLUTIONS 13
# define MAX_DPI 4
# define GENESYS_GL646 646
# define GENESYS_GL841 841
2010-07-20 20:04:11 +00:00
# define GENESYS_GL843 843
2010-04-25 19:32:44 +00:00
# define GENESYS_GL846 846
# define GENESYS_GL847 847
# define GENESYS_GL848 848
2010-11-06 20:12:56 +00:00
# define GENESYS_GL124 124
2005-06-27 20:07:45 +00:00
2010-04-29 20:01:34 +00:00
# define GENESYS_MAX_REGS 256
2005-06-27 20:07:45 +00:00
2009-01-19 05:46:43 +00:00
# define DAC_WOLFSON_UMAX 0
# define DAC_WOLFSON_ST12 1
# define DAC_WOLFSON_ST24 2
# define DAC_WOLFSON_5345 3
2005-06-27 20:07:45 +00:00
# define DAC_WOLFSON_HP2400 4
# define DAC_WOLFSON_HP2300 5
2009-01-19 05:46:43 +00:00
# define DAC_CANONLIDE35 6
# define DAC_AD_XP200 7 /* Analog Device frontend */
2009-02-08 18:59:59 +00:00
# define DAC_WOLFSON_XP300 8
2009-02-27 12:37:16 +00:00
# define DAC_WOLFSON_HP3670 9
2009-05-19 14:24:59 +00:00
# define DAC_WOLFSON_DSM600 10
2010-04-25 19:32:44 +00:00
# define DAC_CANONLIDE200 11
2010-07-20 20:04:11 +00:00
# define DAC_KVSS080 12
2010-07-30 04:47:01 +00:00
# define DAC_G4050 13
2010-11-06 20:12:56 +00:00
# define DAC_CANONLIDE110 14
2010-12-26 15:40:43 +00:00
# define DAC_PLUSTEK_3600 15
2005-06-27 20:07:45 +00:00
# define CCD_UMAX 0
# define CCD_ST12 1 /* SONY ILX548: 5340 Pixel ??? */
# define CCD_ST24 2 /* SONY ILX569: 10680 Pixel ??? */
# define CCD_5345 3
# define CCD_HP2400 4
# define CCD_HP2300 5
2005-11-19 22:51:01 +00:00
# define CCD_CANONLIDE35 6
2009-01-19 05:46:43 +00:00
# define CIS_XP200 7 /* CIS sensor for Strobe XP200 */
2009-10-17 12:52:42 +00:00
/* 8 is unused currently */
2009-02-27 12:37:16 +00:00
# define CCD_HP3670 9
2009-02-28 18:01:50 +00:00
# define CCD_DP665 10
2009-02-28 18:03:44 +00:00
# define CCD_ROADWARRIOR 11
2009-05-19 14:24:59 +00:00
# define CCD_DSMOBILE600 12
2009-10-06 04:32:24 +00:00
# define CCD_XP300 13
2009-12-05 06:23:40 +00:00
# define CCD_DP685 14
2010-04-25 19:32:44 +00:00
# define CIS_CANONLIDE200 15
2010-05-05 05:01:58 +00:00
# define CIS_CANONLIDE100 16
2010-07-20 20:04:11 +00:00
# define CCD_KVSS080 17
2010-07-30 04:47:01 +00:00
# define CCD_G4050 18
2010-11-06 20:12:56 +00:00
# define CIS_CANONLIDE110 19
2010-12-26 15:40:43 +00:00
# define CCD_PLUSTEK_3600 20
2005-06-27 20:07:45 +00:00
# define GPO_UMAX 0
# define GPO_ST12 1
# define GPO_ST24 2
# define GPO_5345 3
# define GPO_HP2400 4
# define GPO_HP2300 5
2005-11-19 22:51:01 +00:00
# define GPO_CANONLIDE35 6
2009-01-19 05:46:43 +00:00
# define GPO_XP200 7
2009-02-08 18:59:59 +00:00
# define GPO_XP300 8
2009-02-27 12:37:16 +00:00
# define GPO_HP3670 9
2009-02-28 18:01:50 +00:00
# define GPO_DP665 10
2009-12-05 06:23:40 +00:00
# define GPO_DP685 11
2010-04-25 19:32:44 +00:00
# define GPO_CANONLIDE200 12
2010-07-20 20:04:11 +00:00
# define GPO_KVSS080 13
2010-07-30 04:47:01 +00:00
# define GPO_G4050 14
2010-11-06 20:12:56 +00:00
# define GPO_CANONLIDE110 15
2010-12-26 15:40:43 +00:00
# define GPO_PLUSTEK_3600 16
2005-06-27 20:07:45 +00:00
# define MOTOR_UMAX 0
# define MOTOR_5345 1
# define MOTOR_ST24 2
# define MOTOR_HP2400 3
# define MOTOR_HP2300 4
2005-11-19 22:51:01 +00:00
# define MOTOR_CANONLIDE35 5
2009-01-19 05:46:43 +00:00
# define MOTOR_XP200 6
2009-02-08 18:59:59 +00:00
# define MOTOR_XP300 7
2009-02-27 12:37:16 +00:00
# define MOTOR_HP3670 9
2009-02-28 18:01:50 +00:00
# define MOTOR_DP665 10
2009-02-28 18:03:44 +00:00
# define MOTOR_ROADWARRIOR 11
2009-09-21 19:48:20 +00:00
# define MOTOR_DSMOBILE_600 12
2010-04-25 19:32:44 +00:00
# define MOTOR_CANONLIDE200 13
2010-05-05 05:01:58 +00:00
# define MOTOR_CANONLIDE100 14
2010-07-20 20:04:11 +00:00
# define MOTOR_KVSS080 15
2010-07-30 04:47:01 +00:00
# define MOTOR_G4050 16
2010-11-06 20:12:56 +00:00
# define MOTOR_CANONLIDE110 17
2010-12-26 15:40:43 +00:00
# define MOTOR_PLUSTEK_3600 18
2009-02-27 12:37:16 +00:00
2005-06-27 20:07:45 +00:00
/* Forward typedefs */
typedef struct Genesys_Device Genesys_Device ;
2009-01-18 13:56:57 +00:00
struct Genesys_Scanner ;
2009-03-25 12:57:24 +00:00
typedef struct Genesys_Calibration_Cache Genesys_Calibration_Cache ;
2005-06-27 20:07:45 +00:00
/**
* Scanner command set description .
*
* This description contains parts which are common to all scanners with the
* same command set , but may have different optical resolution and other
* parameters .
*/
typedef struct Genesys_Command_Set
{
/** @name Identification */
/*@{ */
/** Name of this command set */
SANE_String_Const name ;
/*@} */
/** For ASIC initialization */
SANE_Status ( * init ) ( Genesys_Device * dev ) ;
SANE_Status ( * init_regs_for_warmup ) ( Genesys_Device * dev ,
Genesys_Register_Set * regs ,
int * channels , int * total_size ) ;
SANE_Status ( * init_regs_for_coarse_calibration ) ( Genesys_Device * dev ) ;
SANE_Status ( * init_regs_for_shading ) ( Genesys_Device * dev ) ;
SANE_Status ( * init_regs_for_scan ) ( Genesys_Device * dev ) ;
SANE_Bool ( * get_filter_bit ) ( Genesys_Register_Set * reg ) ;
SANE_Bool ( * get_lineart_bit ) ( Genesys_Register_Set * reg ) ;
SANE_Bool ( * get_bitset_bit ) ( Genesys_Register_Set * reg ) ;
SANE_Bool ( * get_gain4_bit ) ( Genesys_Register_Set * reg ) ;
SANE_Bool ( * get_fast_feed_bit ) ( Genesys_Register_Set * reg ) ;
SANE_Bool ( * test_buffer_empty_bit ) ( SANE_Byte val ) ;
SANE_Bool ( * test_motor_flag_bit ) ( SANE_Byte val ) ;
int ( * bulk_full_size ) ( void ) ;
2009-02-26 03:15:43 +00:00
SANE_Status ( * set_fe ) ( Genesys_Device * dev , uint8_t set ) ;
2005-06-27 20:07:45 +00:00
SANE_Status ( * set_powersaving ) ( Genesys_Device * dev , int delay ) ;
2005-11-19 22:51:01 +00:00
SANE_Status ( * save_power ) ( Genesys_Device * dev , SANE_Bool enable ) ;
2005-06-27 20:07:45 +00:00
void ( * set_motor_power ) ( Genesys_Register_Set * regs , SANE_Bool set ) ;
2008-02-21 15:49:18 +00:00
void ( * set_lamp_power ) ( Genesys_Device * dev ,
Genesys_Register_Set * regs ,
SANE_Bool set ) ;
2005-06-27 20:07:45 +00:00
SANE_Status ( * begin_scan ) ( Genesys_Device * dev ,
Genesys_Register_Set * regs ,
SANE_Bool start_motor ) ;
SANE_Status ( * end_scan ) ( Genesys_Device * dev ,
Genesys_Register_Set * regs ,
SANE_Bool check_stop ) ;
SANE_Status ( * send_gamma_table ) ( Genesys_Device * dev , SANE_Bool generic ) ;
SANE_Status ( * search_start_position ) ( Genesys_Device * dev ) ;
SANE_Status ( * offset_calibration ) ( Genesys_Device * dev ) ;
SANE_Status ( * coarse_gain_calibration ) ( Genesys_Device * dev , int dpi ) ;
2005-11-19 22:51:01 +00:00
SANE_Status ( * led_calibration ) ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
SANE_Status ( * slow_back_home ) ( Genesys_Device * dev ,
SANE_Bool wait_until_home ) ;
2009-01-16 15:31:10 +00:00
2005-11-19 22:51:01 +00:00
SANE_Status ( * bulk_write_register ) ( Genesys_Device * dev ,
Genesys_Register_Set * reg ,
2007-11-11 21:50:00 +00:00
size_t elems ) ;
2009-02-26 03:15:43 +00:00
SANE_Status ( * bulk_write_data ) ( Genesys_Device * dev , uint8_t addr ,
uint8_t * data , size_t len ) ;
2005-11-19 22:51:01 +00:00
2009-02-26 03:15:43 +00:00
SANE_Status ( * bulk_read_data ) ( Genesys_Device * dev , uint8_t addr ,
uint8_t * data , size_t len ) ;
2005-06-27 20:07:45 +00:00
2009-01-16 15:31:10 +00:00
/* Updates hardware sensor information in Genesys_Scanner.val[].
If possible , just get information for given option .
The sensor state in Genesys_Scanner . val [ ] should be merged with the
new sensor state , using the information that was last read by the frontend
in Genesys_Scanner . last_val [ ] , in such a way that a button up / down
relative to Genesys_Scanner . last_val [ ] is not lost .
*/
2009-01-19 05:46:43 +00:00
SANE_Status ( * update_hardware_sensors ) ( struct Genesys_Scanner * s ) ;
/* functions for sheetfed scanners */
/**
* load document into scanner
*/
SANE_Status ( * load_document ) ( Genesys_Device * dev ) ;
/**
* detects is the scanned document has left scanner . In this
* case it updates the amount of data to read and set up
* flags in the dev struct
*/
SANE_Status ( * detect_document_end ) ( Genesys_Device * dev ) ;
/**
* eject document from scanner
*/
SANE_Status ( * eject_document ) ( Genesys_Device * dev ) ;
2009-06-09 20:05:11 +00:00
/**
* search for an black or white area in forward or reverse
* direction */
SANE_Status ( * search_strip ) ( Genesys_Device * dev , SANE_Bool forward , SANE_Bool black ) ;
2009-03-25 12:57:24 +00:00
SANE_Status ( * is_compatible_calibration ) (
Genesys_Device * dev ,
Genesys_Calibration_Cache * cache ,
SANE_Bool for_overwrite ) ;
2010-03-15 05:24:23 +00:00
/* functions for transparency adapter */
/**
* move scanning head to transparency adapter
*/
SANE_Status ( * move_to_ta ) ( Genesys_Device * dev ) ;
2010-04-25 19:32:44 +00:00
/**
* write shading data calibration to ASIC
*/
SANE_Status ( * send_shading_data ) ( Genesys_Device * dev , uint8_t * data , int size ) ;
2005-06-27 20:07:45 +00:00
} Genesys_Command_Set ;
typedef struct Genesys_Model
{
SANE_String_Const name ;
SANE_String_Const vendor ;
SANE_String_Const model ;
SANE_Int asic_type ; /* ASIC type gl646 or gl841 */
Genesys_Command_Set * cmd_set ; /* pointers to low level functions */
SANE_Int xdpi_values [ MAX_RESOLUTIONS ] ; /* possible x resolutions */
SANE_Int ydpi_values [ MAX_RESOLUTIONS ] ; /* possible y resolutions */
SANE_Int bpp_gray_values [ MAX_DPI ] ; /* possible depths in gray mode */
SANE_Int bpp_color_values [ MAX_DPI ] ; /* possible depths in color mode */
SANE_Fixed x_offset ; /* Start of scan area in mm */
2009-02-23 14:12:20 +00:00
SANE_Fixed y_offset ; /* Start of scan area in mm (Amount of
feeding needed to get to the medium ) */
2005-06-27 20:07:45 +00:00
SANE_Fixed x_size ; /* Size of scan area in mm */
SANE_Fixed y_size ; /* Size of scan area in mm */
SANE_Fixed y_offset_calib ; /* Start of white strip in mm */
SANE_Fixed x_offset_mark ; /* Start of black mark in mm */
SANE_Fixed x_offset_ta ; /* Start of scan area in TA mode in mm */
SANE_Fixed y_offset_ta ; /* Start of scan area in TA mode in mm */
SANE_Fixed x_size_ta ; /* Size of scan area in TA mode in mm */
SANE_Fixed y_size_ta ; /* Size of scan area in TA mode in mm */
SANE_Fixed y_offset_calib_ta ; /* Start of white strip in TA mode in mm */
2009-02-23 14:12:20 +00:00
SANE_Fixed post_scan ; /* Size of scan area after paper sensor stops
sensing document in mm */
SANE_Fixed eject_feed ; /* Amount of feeding needed to eject document
after finishing scanning in mm */
2005-06-27 20:07:45 +00:00
/* Line-distance correction (in pixel at optical_ydpi) for CCD scanners */
SANE_Int ld_shift_r ; /* red */
SANE_Int ld_shift_g ; /* green */
SANE_Int ld_shift_b ; /* blue */
Genesys_Color_Order line_mode_color_order ; /* Order of the CCD/CIS colors */
SANE_Bool is_cis ; /* Is this a CIS or CCD scanner? */
2009-01-19 05:46:43 +00:00
SANE_Bool is_sheetfed ; /* Is this sheetfed scanner? */
2005-06-27 20:07:45 +00:00
SANE_Int ccd_type ; /* which SENSOR type do we have ? */
SANE_Int dac_type ; /* which DAC do we have ? */
SANE_Int gpo_type ; /* General purpose output type */
SANE_Int motor_type ; /* stepper motor type */
SANE_Word flags ; /* Which hacks are needed for this scanner? */
2009-01-19 05:46:43 +00:00
SANE_Word buttons ; /* Button flags, described existing buttons for the model */
2005-06-27 20:07:45 +00:00
/*@} */
SANE_Int shading_lines ; /* how many lines are used for shading calibration */
SANE_Int search_lines ; /* how many lines are used to search start position */
} Genesys_Model ;
2009-02-27 12:37:16 +00:00
# define SCAN_METHOD_FLATBED 0 /**> normal scan method */
# define SCAN_METHOD_TRANSPARENCY 2 /**> scan using transparency adaptor */
# define SCAN_METHOD_NEGATIVE 0x88 /**> scan using negative adaptor */
# define SCAN_MODE_LINEART 0 /**> lineart scan mode */
# define SCAN_MODE_HALFTONE 1 /**> halftone scan mode */
# define SCAN_MODE_GRAY 2 /**> gray scan mode */
# define SCAN_MODE_COLOR 4 /**> color scan mode */
2005-06-27 20:07:45 +00:00
typedef struct
{
int scan_method ; /* todo: change >=2: Transparency, 0x88: negative film */
int scan_mode ; /* todo: change 0,1 = lineart, halftone; 2 = gray, 3 = 3pass color, 4=single pass color */
2010-01-12 05:17:09 +00:00
int xres ; /**> horizontal dpi */
int yres ; /**> vertical dpi */
2005-06-27 20:07:45 +00:00
double tl_x ; /* x start on scan table in mm */
double tl_y ; /* y start on scan table in mm */
2010-01-12 05:17:09 +00:00
unsigned int lines ; /**> number of lines at scan resolution */
unsigned int pixels ; /**> number of pixels at scan resolution */
2005-06-27 20:07:45 +00:00
2005-11-19 22:51:01 +00:00
unsigned int depth ; /* bit depth of the scan */
2005-06-27 20:07:45 +00:00
/* todo : remove these fields ? */
int exposure_time ;
2010-01-12 05:17:09 +00:00
unsigned int color_filter ;
2010-01-19 05:56:18 +00:00
/**> true if scan is true gray, false if monochrome scan */
int true_gray ;
2006-03-27 14:41:30 +00:00
2010-01-19 05:56:18 +00:00
/**> lineart threshold */
2006-03-27 14:41:30 +00:00
int threshold ;
2006-06-07 22:39:09 +00:00
2010-01-20 20:48:27 +00:00
/**> lineart threshold curve for dynamic rasterization */
int threshold_curve ;
2010-01-19 05:56:18 +00:00
/**> Disable interpolation for xres<yres*/
2006-06-07 22:39:09 +00:00
int disable_interpolation ;
2010-01-19 05:56:18 +00:00
2010-06-20 20:04:51 +00:00
/**> Use double x resolution internally to provide better
* quality */
int double_xres ;
2010-01-19 05:56:18 +00:00
/**> true is lineart is generated from gray data by
* the dynamic rasterization algo */
int dynamic_lineart ;
2005-06-27 20:07:45 +00:00
} Genesys_Settings ;
2005-11-19 22:51:01 +00:00
typedef struct Genesys_Current_Setup
{
int pixels ; /* pixel count expected from scanner */
int lines ; /* line count expected from scanner */
int depth ; /* depth expected from scanner */
int channels ; /* channel count expected from scanner */
2010-03-08 05:39:22 +00:00
int scan_method ; /* scanning method: flatbed or XPA */
2005-11-19 22:51:01 +00:00
int exposure_time ; /* used exposure time */
float xres ; /* used xres */
float yres ; /* used yres*/
SANE_Bool half_ccd ; /* half ccd mode */
SANE_Int stagger ;
SANE_Int max_shift ; /* max shift of any ccd component, including staggered pixels*/
} Genesys_Current_Setup ;
typedef struct Genesys_Buffer
{
SANE_Byte * buffer ;
size_t size ;
size_t pos ; /* current position in read buffer */
size_t avail ; /* data bytes currently in buffer */
} Genesys_Buffer ;
2005-06-27 20:07:45 +00:00
2009-03-25 12:57:24 +00:00
struct Genesys_Calibration_Cache
{
Genesys_Current_Setup used_setup ; /* used to check if entry is compatible */
time_t last_calibration ;
Genesys_Frontend frontend ;
Genesys_Sensor sensor ;
size_t calib_pixels ;
2009-04-17 13:03:35 +00:00
size_t calib_channels ;
2009-03-25 12:57:24 +00:00
size_t average_size ;
uint8_t * white_average_data ;
uint8_t * dark_average_data ;
struct Genesys_Calibration_Cache * next ;
} ;
2005-06-27 20:07:45 +00:00
struct Genesys_Device
{
SANE_Int dn ;
2010-07-30 04:47:01 +00:00
SANE_Bool usb_mode ;
2005-06-27 20:07:45 +00:00
SANE_String file_name ;
2009-03-25 12:57:24 +00:00
SANE_String calib_file ;
2005-06-27 20:07:45 +00:00
Genesys_Model * model ;
2010-04-29 20:01:34 +00:00
Genesys_Register_Set reg [ 256 ] ;
Genesys_Register_Set calib_reg [ 256 ] ;
2005-06-27 20:07:45 +00:00
Genesys_Settings settings ;
Genesys_Frontend frontend ;
Genesys_Sensor sensor ;
Genesys_Gpo gpo ;
Genesys_Motor motor ;
2009-02-26 03:15:43 +00:00
uint16_t slope_table0 [ 256 ] ;
uint16_t slope_table1 [ 256 ] ;
uint8_t control [ 6 ] ;
2005-06-27 20:07:45 +00:00
time_t init_date ;
2009-03-25 12:57:24 +00:00
size_t average_size ;
size_t calib_pixels ;
2009-04-17 13:03:35 +00:00
size_t calib_channels ;
2011-04-15 19:28:45 +00:00
size_t calib_resolution ;
2009-02-26 03:15:43 +00:00
uint8_t * white_average_data ;
uint8_t * dark_average_data ;
uint16_t dark [ 3 ] ;
2005-06-27 20:07:45 +00:00
SANE_Bool already_initialized ;
SANE_Int scanhead_position_in_steps ;
SANE_Int lamp_off_time ;
SANE_Bool read_active ;
2011-01-30 21:20:24 +00:00
SANE_Bool parking ; /**> signal wether the park command has been issued */
2010-01-20 20:48:27 +00:00
SANE_Bool document ; /**> for sheetfed scanner's, is TRUE when there
2009-01-19 05:46:43 +00:00
is a document in the scanner */
2005-11-19 22:51:01 +00:00
Genesys_Buffer read_buffer ;
Genesys_Buffer lines_buffer ;
Genesys_Buffer shrink_buffer ;
Genesys_Buffer out_buffer ;
2005-06-27 20:07:45 +00:00
size_t read_bytes_left ; /* bytes to read from scanner */
2005-11-19 22:51:01 +00:00
2005-06-27 20:07:45 +00:00
size_t total_bytes_read ; /* total bytes read sent to frontend */
2005-11-19 22:51:01 +00:00
size_t total_bytes_to_read ; /* total bytes read to be sent to frontend */
2009-01-19 05:46:43 +00:00
size_t wpl ; /* asic's word per line */
2005-06-27 20:07:45 +00:00
2005-11-19 22:51:01 +00:00
Genesys_Current_Setup current_setup ; /* contains the real used values */
2010-01-20 20:48:27 +00:00
/**> look up table used in dynamic rasterization */
unsigned char lineart_lut [ 256 ] ;
2005-06-27 20:07:45 +00:00
2009-03-25 12:57:24 +00:00
Genesys_Calibration_Cache * calibration_cache ;
2005-06-27 20:07:45 +00:00
struct Genesys_Device * next ;
2010-05-22 08:22:48 +00:00
2010-11-06 20:12:56 +00:00
int segnb ; /**> number of segments composing the sensor */
int line_interp ; /**> number of lines used in line interpolation */
int line_count ; /**> number of scan lines used during scan */
size_t bpl ; /**> bytes per full scan widthline */
size_t dist ; /**> bytes distance between an odd and an even pixel */
size_t len ; /**> number of even pixels */
size_t cur ; /**> current pixel position within sub window */
2010-05-22 08:22:48 +00:00
Genesys_Buffer oe_buffer ; /**> buffer to handle even/odd data */
2010-09-06 19:02:32 +00:00
2010-09-07 06:55:36 +00:00
SANE_Bool buffer_image ; /**> when true the scanned picture is first buffered
2010-11-06 20:12:56 +00:00
* to allow software image enhancements */
2010-09-07 06:55:36 +00:00
SANE_Byte * img_buffer ; /**> image buffer where the scanned picture is stored */
2005-06-27 20:07:45 +00:00
} ;
typedef struct Genesys_USB_Device_Entry
{
SANE_Word vendor ; /**< USB vendor identifier */
SANE_Word product ; /**< USB product identifier */
Genesys_Model * model ; /**< Scanner model information */
} Genesys_USB_Device_Entry ;
2011-02-16 06:13:01 +00:00
/**
* structure for motor database
*/
typedef struct {
int motor_type ; /**> motor id */
int exposure ; /**> exposure for the slope table */
int step_type ; /**> default step type for given exposure */
2011-03-09 21:33:48 +00:00
uint32_t * table ; /**> 0 terminated slope table at full step */
2011-02-16 06:13:01 +00:00
} Motor_Profile ;
# define SLOPE_TABLE_SIZE 1024
# define SCAN_TABLE 0 /* table 1 at 0x4000 for gl124 */
# define BACKTRACK_TABLE 1 /* table 2 at 0x4800 for gl124 */
# define STOP_TABLE 2 /* table 3 at 0x5000 for gl124 */
# define FAST_TABLE 3 /* table 4 at 0x5800 for gl124 */
# define HOME_TABLE 4 /* table 5 at 0x6000 for gl124 */
# define SCAN_FLAG_SINGLE_LINE 0x001
# define SCAN_FLAG_DISABLE_SHADING 0x002
# define SCAN_FLAG_DISABLE_GAMMA 0x004
# define SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE 0x008
# define SCAN_FLAG_IGNORE_LINE_DISTANCE 0x010
# define SCAN_FLAG_USE_OPTICAL_RES 0x020
# define SCAN_FLAG_DISABLE_LAMP 0x040
# define SCAN_FLAG_DYNAMIC_LINEART 0x080
# define SCAN_FLAG_CALIBRATION 0x100
# define SCAN_FLAG_FEEDING 0x200
2005-06-27 20:07:45 +00:00
/*--------------------------------------------------------------------------*/
/* common functions needed by low level specific functions */
/*--------------------------------------------------------------------------*/
extern Genesys_Register_Set * sanei_genesys_get_address ( Genesys_Register_Set *
regs , SANE_Byte addr ) ;
extern SANE_Byte
sanei_genesys_read_reg_from_set ( Genesys_Register_Set * regs ,
SANE_Byte address ) ;
extern void
sanei_genesys_set_reg_from_set ( Genesys_Register_Set * regs ,
SANE_Byte address , SANE_Byte value ) ;
2010-11-06 20:12:56 +00:00
extern SANE_Status sanei_genesys_init_cmd_set ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
extern SANE_Status
2009-02-26 03:15:43 +00:00
sanei_genesys_read_register ( Genesys_Device * dev , uint8_t reg ,
uint8_t * val ) ;
2005-06-27 20:07:45 +00:00
extern SANE_Status
2009-02-26 03:15:43 +00:00
sanei_genesys_write_register ( Genesys_Device * dev , uint8_t reg ,
uint8_t val ) ;
2005-06-27 20:07:45 +00:00
extern SANE_Status
2010-11-06 20:12:56 +00:00
sanei_genesys_read_hregister ( Genesys_Device * dev , uint8_t reg ,
uint8_t * val ) ;
extern SANE_Status
sanei_genesys_write_hregister ( Genesys_Device * dev , uint8_t reg ,
uint8_t val ) ;
extern SANE_Status sanei_genesys_write_0x8c ( Genesys_Device * dev , uint8_t index , uint8_t val ) ;
extern SANE_Status sanei_genesys_get_status ( Genesys_Device * dev , uint8_t * status ) ;
extern void sanei_genesys_print_status ( uint8_t val ) ;
extern SANE_Status
sanei_genesys_write_ahb ( SANE_Int dn , uint32_t addr , uint32_t size , uint8_t * data ) ;
2005-06-27 20:07:45 +00:00
extern void sanei_genesys_init_fe ( Genesys_Device * dev ) ;
extern void sanei_genesys_init_structs ( Genesys_Device * dev ) ;
extern SANE_Status
sanei_genesys_init_shading_data ( Genesys_Device * dev , int pixels_per_line ) ;
2009-01-19 05:46:43 +00:00
extern SANE_Status sanei_genesys_read_valid_words ( Genesys_Device * dev ,
unsigned int * steps ) ;
2009-12-09 19:52:29 +00:00
extern SANE_Status sanei_genesys_read_scancnt ( Genesys_Device * dev ,
unsigned int * steps ) ;
2005-06-27 20:07:45 +00:00
extern SANE_Status sanei_genesys_read_feed_steps ( Genesys_Device * dev ,
2005-11-19 22:51:01 +00:00
unsigned int * steps ) ;
2005-06-27 20:07:45 +00:00
extern void
sanei_genesys_calculate_zmode2 ( SANE_Bool two_table ,
2009-02-26 03:15:43 +00:00
uint32_t exposure_time ,
uint16_t * slope_table ,
2005-06-27 20:07:45 +00:00
int reg21 ,
2009-02-26 03:15:43 +00:00
int move , int reg22 , uint32_t * z1 ,
uint32_t * z2 ) ;
2005-06-27 20:07:45 +00:00
extern void
sanei_genesys_calculate_zmode ( Genesys_Device * dev ,
2009-02-26 03:15:43 +00:00
uint32_t exposure_time ,
uint32_t steps_sum ,
uint16_t last_speed , uint32_t feedl ,
uint8_t fastfed , uint8_t scanfed ,
uint8_t fwdstep , uint8_t tgtime ,
uint32_t * z1 , uint32_t * z2 ) ;
2005-06-27 20:07:45 +00:00
extern SANE_Status
2009-02-26 03:15:43 +00:00
sanei_genesys_set_buffer_address ( Genesys_Device * dev , uint32_t addr ) ;
2005-06-27 20:07:45 +00:00
2010-06-23 16:21:36 +00:00
extern SANE_Status
sanei_genesys_fe_read_data ( Genesys_Device * dev , uint8_t addr ,
uint16_t * data ) ;
2005-06-27 20:07:45 +00:00
extern SANE_Status
2009-02-26 03:15:43 +00:00
sanei_genesys_fe_write_data ( Genesys_Device * dev , uint8_t addr ,
uint16_t data ) ;
2005-06-27 20:07:45 +00:00
2005-11-19 22:51:01 +00:00
extern SANE_Int
sanei_genesys_exposure_time2 ( Genesys_Device * dev ,
float ydpi , int step_type , int endpixel ,
2007-11-22 14:05:13 +00:00
int led_exposure , int power_mode ) ;
2005-11-19 22:51:01 +00:00
2005-06-27 20:07:45 +00:00
extern SANE_Int
sanei_genesys_exposure_time ( Genesys_Device * dev , Genesys_Register_Set * reg ,
int xdpi ) ;
2009-01-19 05:46:43 +00:00
extern SANE_Int
2009-02-26 03:15:43 +00:00
sanei_genesys_generate_slope_table ( uint16_t * slope_table , unsigned int max_steps ,
unsigned int use_steps , uint16_t stop_at ,
uint16_t vstart , uint16_t vend ,
2009-01-19 05:46:43 +00:00
unsigned int steps , double g ,
unsigned int * used_steps , unsigned int * vfinal ) ;
2005-06-27 20:07:45 +00:00
extern SANE_Int
sanei_genesys_create_slope_table ( Genesys_Device * dev ,
2009-02-26 03:15:43 +00:00
uint16_t * slope_table , int steps ,
2005-06-27 20:07:45 +00:00
int step_type , int exposure_time ,
2007-11-22 14:05:13 +00:00
SANE_Bool same_speed , double yres ,
int power_mode ) ;
2005-06-27 20:07:45 +00:00
2005-11-19 22:51:01 +00:00
SANE_Int
sanei_genesys_create_slope_table3 ( Genesys_Device * dev ,
2009-02-26 03:15:43 +00:00
uint16_t * slope_table , int max_step ,
2005-11-19 22:51:01 +00:00
unsigned int use_steps ,
int step_type , int exposure_time ,
double yres ,
unsigned int * used_steps ,
2007-11-22 14:05:13 +00:00
unsigned int * final_exposure ,
int power_mode ) ;
2005-11-19 22:51:01 +00:00
2005-06-27 20:07:45 +00:00
extern void
2009-02-26 03:15:43 +00:00
sanei_genesys_create_gamma_table ( uint16_t * gamma_table , int size ,
2005-06-27 20:07:45 +00:00
float maximum , float gamma_max ,
float gamma ) ;
extern SANE_Status sanei_genesys_start_motor ( Genesys_Device * dev ) ;
extern SANE_Status sanei_genesys_stop_motor ( Genesys_Device * dev ) ;
extern SANE_Status
2009-02-26 03:15:43 +00:00
sanei_genesys_search_reference_point ( Genesys_Device * dev , uint8_t * data ,
2005-06-27 20:07:45 +00:00
int start_pixel , int dpi , int width ,
int height ) ;
extern SANE_Status
2009-02-26 03:15:43 +00:00
sanei_genesys_write_pnm_file ( char * filename , uint8_t * data , int depth ,
2005-06-27 20:07:45 +00:00
int channels , int pixels_per_line , int lines ) ;
extern SANE_Status
sanei_genesys_test_buffer_empty ( Genesys_Device * dev , SANE_Bool * empty ) ;
extern SANE_Status
2009-02-26 03:15:43 +00:00
sanei_genesys_read_data_from_scanner ( Genesys_Device * dev , uint8_t * data ,
2005-06-27 20:07:45 +00:00
size_t size ) ;
2005-11-19 22:51:01 +00:00
extern SANE_Status
sanei_genesys_buffer_alloc ( Genesys_Buffer * buf , size_t size ) ;
extern SANE_Status
sanei_genesys_buffer_free ( Genesys_Buffer * buf ) ;
extern SANE_Byte *
sanei_genesys_buffer_get_write_pos ( Genesys_Buffer * buf , size_t size ) ;
extern SANE_Byte *
sanei_genesys_buffer_get_read_pos ( Genesys_Buffer * buf ) ;
extern SANE_Status
sanei_genesys_buffer_produce ( Genesys_Buffer * buf , size_t size ) ;
extern SANE_Status
sanei_genesys_buffer_consume ( Genesys_Buffer * buf , size_t size ) ;
2010-11-06 20:12:56 +00:00
extern SANE_Status
sanei_genesys_set_double ( Genesys_Register_Set * regs , SANE_Byte addr , uint16_t value ) ;
extern SANE_Status
sanei_genesys_set_triple ( Genesys_Register_Set * regs , SANE_Byte addr , uint32_t value ) ;
extern SANE_Status
sanei_genesys_get_double ( Genesys_Register_Set * regs , SANE_Byte addr , uint16_t * value ) ;
extern SANE_Status
sanei_genesys_get_triple ( Genesys_Register_Set * regs , SANE_Byte addr , uint32_t * value ) ;
2005-06-27 20:07:45 +00:00
2011-01-12 19:51:32 +00:00
extern SANE_Status
sanei_genesys_wait_for_home ( Genesys_Device * dev ) ;
2011-01-24 05:22:14 +00:00
extern
int sanei_genesys_compute_dpihw ( Genesys_Device * dev , int xres ) ;
2011-02-16 06:13:01 +00:00
extern
Motor_Profile * sanei_genesys_get_motor_profile ( Motor_Profile * motors , int motor_type , int exposure ) ;
extern
int sanei_genesys_compute_step_type ( Motor_Profile * motors , int motor_type , int exposure ) ;
extern
int sanei_genesys_slope_table ( uint16_t * slope , int * steps , int dpi , int exposure , int base_dpi , int step_type , int factor , int motor_type , Motor_Profile * motors ) ;
extern
int sanei_genesys_get_lowest_ydpi ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
/*---------------------------------------------------------------------------*/
/* ASIC specific functions declarations */
/*---------------------------------------------------------------------------*/
extern SANE_Status sanei_gl646_init_cmd_set ( Genesys_Device * dev ) ;
extern SANE_Status sanei_gl841_init_cmd_set ( Genesys_Device * dev ) ;
2010-07-20 20:04:11 +00:00
extern SANE_Status sanei_gl843_init_cmd_set ( Genesys_Device * dev ) ;
2010-04-25 19:32:44 +00:00
extern SANE_Status sanei_gl847_init_cmd_set ( Genesys_Device * dev ) ;
2010-11-06 20:12:56 +00:00
extern SANE_Status sanei_gl124_init_cmd_set ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
# endif /* not GENESYS_LOW_H */