2019-06-02 08:47:26 +00:00
 /* sane - Scanner Access Now Easy.
2005-06-27 20:07:45 +00:00
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 >
2016-02-12 07:11:20 +00:00
Copyright ( C ) 2004 - 2013 St é 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 .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
This file is part of the SANE package .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
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 .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
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 .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
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 .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
As a special exception , the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
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 .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
This exception does not , however , invalidate any other reasons why
the executable file might be covered by the GNU General Public
License .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
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 .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
If you write modifications of your own for SANE , it is your choice
whether to permit this exception to apply to your modifications .
2013-12-16 04:45:31 +00:00
If you do not wish that , delete this exception notice .
2005-06-27 20:07:45 +00:00
*/
# ifndef GENESYS_LOW_H
# define GENESYS_LOW_H
2011-11-02 07:33:45 +00:00
# include "../include/sane/config.h"
# include <errno.h>
# include <string.h>
# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# include <math.h>
2005-06-27 20:07:45 +00:00
# include <stddef.h>
2009-07-09 05:54:58 +00:00
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
2011-11-01 15:10:07 +00:00
# ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
2013-12-16 04:45:31 +00:00
# ifdef HAVE_MKDIR
2011-11-03 21:47:10 +00:00
# include <sys/stat.h>
# include <sys/types.h>
# endif
2011-11-02 07:33:45 +00:00
2005-06-27 20:07:45 +00:00
# include "../include/sane/sane.h"
2011-11-02 07:33:45 +00:00
# include "../include/sane/sanei.h"
# include "../include/sane/saneopts.h"
# include "../include/sane/sanei_backend.h"
# include "../include/sane/sanei_usb.h"
# include "../include/_stdint.h"
2005-06-27 20:07:45 +00:00
2019-08-02 19:35:16 +00:00
# include "genesys_device.h"
# include "genesys_enums.h"
2019-07-05 23:10:04 +00:00
# include "genesys_error.h"
2019-07-05 23:10:07 +00:00
# include "genesys_sanei.h"
2019-08-02 19:35:16 +00:00
# include "genesys_sensor.h"
2019-07-22 23:00:42 +00:00
# include "genesys_serialize.h"
2019-08-02 19:35:16 +00:00
# include "genesys_settings.h"
# include "genesys_register.h"
2019-07-05 23:10:04 +00:00
2019-05-25 08:15:26 +00:00
# include <algorithm>
# include <array>
2019-05-25 08:15:28 +00:00
# include <cstring>
2019-05-25 08:15:26 +00:00
# include <functional>
2019-07-22 23:00:42 +00:00
# include <iostream>
2019-06-08 11:04:14 +00:00
# include <limits>
2019-05-25 07:03:14 +00:00
# include <memory>
# include <stdexcept>
2019-05-25 08:15:42 +00:00
# include <string>
2019-05-25 08:15:26 +00:00
# include <vector>
2019-05-25 07:03:14 +00:00
2012-12-09 14:41:06 +00:00
# define GENESYS_RED 0
# define GENESYS_GREEN 1
# define GENESYS_BLUE 2
2005-06-27 20:07:45 +00:00
/* Flags */
2012-10-24 19:28:42 +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)
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_SKIP_WARMUP (1 << 4) /**< skip genesys_warmup() */
2011-11-02 07:33:45 +00:00
/** @brief offset calibration flag
* signals that the scanner does offset calibration . In this case off_calibration ( ) and
2013-12-16 04:45:31 +00:00
* coarse_gain_calibration ( ) functions must be implemented
2011-11-02 07:33:45 +00:00
*/
# define GENESYS_FLAG_OFFSET_CALIBRATION (1 << 5)
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_SEARCH_START (1 << 6) /**< do start search before scanning */
2013-12-16 04:45:31 +00:00
# define GENESYS_FLAG_REPARK (1 << 7) / **< repark head (and check for lock) by
2005-06-27 20:07:45 +00:00
moving without scanning */
2012-10-24 19:28:42 +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
2012-10-24 19:28:42 +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
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_HAS_UTA (1 << 11) /**< scanner has a transparency adapter */
2005-11-19 22:51:01 +00:00
2012-10-24 19:28:42 +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_SIS_SENSOR (1 << 16) /**< handling of multi-segments sensors in software */
# define GENESYS_FLAG_SHADING_NO_MOVE (1 << 17) /**< scanner doesn't move sensor during shading calibration */
# define GENESYS_FLAG_SHADING_REPARK (1 << 18) /**< repark head between shading scans */
# define GENESYS_FLAG_FULL_HWDPI_MODE (1 << 19) /**< scanner always use maximum hw dpi to setup the sensor */
2019-06-08 11:03:55 +00:00
// scanner has infrared transparency scanning capability
# define GENESYS_FLAG_HAS_UTA_INFRARED (1 << 20)
2009-01-19 05:46:43 +00:00
2012-10-24 19:28:42 +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 */
2013-01-31 05:12:09 +00:00
# define GENESYS_HAS_EXTRA_SW (1 << 8) /**< scanner has extra function button */
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
# 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
# define MAX_RESOLUTIONS 13
# define MAX_DPI 4
/* Forward typedefs */
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 .
*/
2019-07-14 20:40:55 +00:00
struct Genesys_Command_Set
2005-06-27 20:07:45 +00:00
{
/** @name Identification */
/*@{ */
/** Name of this command set */
SANE_String_Const name ;
/*@} */
2019-06-30 11:05:28 +00:00
bool ( * needs_home_before_init_regs_for_scan ) ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
/** For ASIC initialization */
2019-07-20 08:02:14 +00:00
void ( * init ) ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:02:19 +00:00
void ( * init_regs_for_warmup ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set * regs , int * channels , int * total_size ) ;
2019-07-20 08:02:17 +00:00
void ( * init_regs_for_coarse_calibration ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set & regs ) ;
2019-07-20 08:02:20 +00:00
void ( * init_regs_for_shading ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set & regs ) ;
2019-07-20 08:02:21 +00:00
void ( * init_regs_for_scan ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ) ;
2005-06-27 20:07:45 +00:00
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 ) ;
2019-07-14 20:41:02 +00:00
void ( * set_fe ) ( Genesys_Device * dev , const Genesys_Sensor & sensor , uint8_t set ) ;
2019-07-20 08:02:03 +00:00
void ( * set_powersaving ) ( Genesys_Device * dev , int delay ) ;
2019-07-20 08:02:02 +00:00
void ( * save_power ) ( Genesys_Device * dev , SANE_Bool enable ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:01:56 +00:00
void ( * begin_scan ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set * regs , SANE_Bool start_motor ) ;
2019-07-20 08:02:13 +00:00
void ( * end_scan ) ( Genesys_Device * dev , Genesys_Register_Set * regs , SANE_Bool check_stop ) ;
2005-06-27 20:07:45 +00:00
2012-12-09 14:41:06 +00:00
/**
* Send gamma tables to ASIC
*/
2019-07-20 08:02:06 +00:00
void ( * send_gamma_table ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:02:22 +00:00
void ( * search_start_position ) ( Genesys_Device * dev ) ;
2019-07-20 08:02:23 +00:00
void ( * offset_calibration ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set & regs ) ;
2019-07-20 08:02:24 +00:00
void ( * coarse_gain_calibration ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set & regs , int dpi ) ;
2019-07-20 08:02:25 +00:00
void ( * led_calibration ) ( Genesys_Device * dev , Genesys_Sensor & sensor ,
Genesys_Register_Set & regs ) ;
2005-06-27 20:07:45 +00:00
2019-06-30 11:05:27 +00:00
void ( * wait_for_motor_stop ) ( Genesys_Device * dev ) ;
2019-07-20 08:02:01 +00:00
void ( * slow_back_home ) ( Genesys_Device * dev , SANE_Bool wait_until_home ) ;
2019-07-20 08:02:31 +00:00
void ( * rewind ) ( Genesys_Device * dev ) ;
2009-01-16 15:31:10 +00:00
2019-07-14 20:40:44 +00:00
void ( * bulk_write_data ) ( Genesys_Device * dev , uint8_t addr , uint8_t * data , size_t len ) ;
2019-07-14 20:40:34 +00:00
void ( * bulk_read_data ) ( Genesys_Device * dev , uint8_t addr , uint8_t * data , size_t len ) ;
2005-06-27 20:07:45 +00:00
2019-06-08 11:03:47 +00:00
// Updates hardware sensor information in Genesys_Scanner.val[].
2019-07-20 08:02:26 +00:00
void ( * update_hardware_sensors ) ( struct Genesys_Scanner * s ) ;
2009-01-19 05:46:43 +00:00
/* functions for sheetfed scanners */
/**
* load document into scanner
*/
2019-07-20 08:02:27 +00:00
void ( * load_document ) ( Genesys_Device * dev ) ;
2009-01-19 05:46:43 +00:00
/**
* 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
*/
2019-07-20 08:02:28 +00:00
void ( * detect_document_end ) ( Genesys_Device * dev ) ;
2009-01-19 05:46:43 +00:00
/**
* eject document from scanner
*/
2019-07-20 08:02:09 +00:00
void ( * eject_document ) ( Genesys_Device * dev ) ;
2009-06-09 20:05:11 +00:00
/**
2013-12-16 04:45:31 +00:00
* search for an black or white area in forward or reverse
2009-06-09 20:05:11 +00:00
* direction */
2019-07-20 08:02:29 +00:00
void ( * search_strip ) ( Genesys_Device * dev , const Genesys_Sensor & sensor , SANE_Bool forward ,
SANE_Bool black ) ;
2009-03-25 12:57:24 +00:00
2019-06-30 11:05:16 +00:00
bool ( * is_compatible_calibration ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
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
*/
2019-07-20 08:02:30 +00:00
void ( * move_to_ta ) ( Genesys_Device * dev ) ;
2010-04-25 19:32:44 +00:00
/**
* write shading data calibration to ASIC
*/
2019-07-14 20:40:55 +00:00
void ( * send_shading_data ) ( Genesys_Device * dev , const Genesys_Sensor & sensor , uint8_t * data ,
int size ) ;
2010-04-25 19:32:44 +00:00
2019-06-30 11:05:15 +00:00
// calculate current scan setup
void ( * calculate_current_setup ) ( Genesys_Device * dev , const Genesys_Sensor & sensor ) ;
2011-07-31 20:09:46 +00:00
2013-01-28 21:04:37 +00:00
/**
* cold boot init function
*/
2019-07-20 08:01:52 +00:00
void ( * asic_boot ) ( Genesys_Device * dev , SANE_Bool cold ) ;
2013-01-28 21:04:37 +00:00
2019-07-14 20:40:55 +00:00
} ;
2005-06-27 20:07:45 +00:00
2019-07-20 06:16:33 +00:00
struct Genesys_USB_Device_Entry {
Genesys_USB_Device_Entry ( unsigned v , unsigned p , const Genesys_Model & m ) :
vendor ( v ) , product ( p ) , model ( m )
{ }
// USB vendor identifier
unsigned vendor ;
// USB product identifier
unsigned product ;
// Scanner model information
Genesys_Model model ;
} ;
2005-06-27 20:07:45 +00:00
2011-02-16 06:13:01 +00:00
/**
* structure for motor database
*/
typedef struct {
2012-10-24 19:28:42 +00:00
int motor_type ; /**< motor id */
int exposure ; /**< exposure for the slope table */
int step_type ; /**< default step type for given exposure */
2019-05-18 11:56:02 +00:00
uint32_t * table ; // 0-terminated slope table at full step (i.e. step_type == 0)
2011-02-16 06:13:01 +00:00
} Motor_Profile ;
2012-05-14 20:22:59 +00:00
# define FULL_STEP 0
# define HALF_STEP 1
# define QUARTER_STEP 2
# define EIGHTH_STEP 3
2011-02-16 06:13:01 +00:00
# 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 */
2011-11-09 14:20:29 +00:00
# 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
# define SCAN_FLAG_USE_XPA 0x400
2013-12-19 06:00:30 +00:00
# define SCAN_FLAG_ENABLE_LEDADD 0x800
2011-11-09 14:20:29 +00:00
# define MOTOR_FLAG_AUTO_GO_HOME 0x01
# define MOTOR_FLAG_DISABLE_BUFFER_FULL_MOVE 0x02
# define MOTOR_FLAG_FEED 0x04
# define MOTOR_FLAG_USE_XPA 0x08
2005-06-27 20:07:45 +00:00
/*--------------------------------------------------------------------------*/
/* common functions needed by low level specific functions */
/*--------------------------------------------------------------------------*/
2019-06-02 08:47:26 +00:00
inline GenesysRegister * sanei_genesys_get_address ( Genesys_Register_Set * regs , uint16_t addr )
{
auto * ret = regs - > find_reg_address ( addr ) ;
if ( ret = = nullptr ) {
DBG ( DBG_error , " %s: failed to find address for register 0x%02x, crash expected ! \n " ,
__func__ , addr ) ;
}
return ret ;
}
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:57 +00:00
extern void sanei_genesys_init_cmd_set ( Genesys_Device * dev ) ;
2010-11-06 20:12:56 +00:00
2019-07-14 20:40:39 +00:00
extern void sanei_genesys_read_register ( Genesys_Device * dev , uint16_t reg , uint8_t * val ) ;
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:41 +00:00
extern void sanei_genesys_write_register ( Genesys_Device * dev , uint16_t reg , uint8_t val ) ;
2005-06-27 20:07:45 +00:00
2019-08-02 19:39:00 +00:00
extern void sanei_genesys_bulk_write_register ( Genesys_Device * dev ,
const Genesys_Register_Set & regs ) ;
2013-01-28 21:04:37 +00:00
2019-07-14 20:40:37 +00:00
extern void sanei_genesys_write_0x8c ( Genesys_Device * dev , uint8_t index , uint8_t val ) ;
2010-11-06 20:12:56 +00:00
2019-05-11 09:05:17 +00:00
extern unsigned sanei_genesys_get_bulk_max_size ( Genesys_Device * dev ) ;
2019-07-14 20:40:34 +00:00
extern void sanei_genesys_bulk_read_data ( Genesys_Device * dev , uint8_t addr , uint8_t * data ,
size_t len ) ;
2019-05-11 09:05:09 +00:00
2019-07-14 20:40:44 +00:00
extern void sanei_genesys_bulk_write_data ( Genesys_Device * dev , uint8_t addr , uint8_t * data ,
2019-05-11 09:05:18 +00:00
size_t len ) ;
2019-07-14 20:40:46 +00:00
extern void sanei_genesys_get_status ( Genesys_Device * dev , uint8_t * status ) ;
2010-11-06 20:12:56 +00:00
extern void sanei_genesys_print_status ( uint8_t val ) ;
2019-07-14 20:40:50 +00:00
extern void sanei_genesys_write_ahb ( Genesys_Device * dev , uint32_t addr , uint32_t size ,
uint8_t * data ) ;
2005-06-27 20:07:45 +00:00
extern void sanei_genesys_init_structs ( Genesys_Device * dev ) ;
2019-06-02 08:47:51 +00:00
const Genesys_Sensor & sanei_genesys_find_sensor_any ( Genesys_Device * dev ) ;
Genesys_Sensor & sanei_genesys_find_sensor_any_for_write ( Genesys_Device * dev ) ;
2019-06-02 08:47:52 +00:00
const Genesys_Sensor & sanei_genesys_find_sensor ( Genesys_Device * dev , int dpi ,
2019-07-13 01:14:42 +00:00
ScanMethod scan_method ) ;
2019-06-02 08:47:52 +00:00
Genesys_Sensor & sanei_genesys_find_sensor_for_write ( Genesys_Device * dev , int dpi ,
2019-07-13 01:14:42 +00:00
ScanMethod scan_method ) ;
2019-06-02 08:47:51 +00:00
2019-08-03 23:48:29 +00:00
std : : vector < std : : reference_wrapper < const Genesys_Sensor > >
sanei_genesys_find_sensors_all ( Genesys_Device * dev , ScanMethod scan_method ) ;
std : : vector < std : : reference_wrapper < Genesys_Sensor > >
sanei_genesys_find_sensors_all_for_write ( Genesys_Device * dev , ScanMethod scan_method ) ;
2019-07-20 08:01:50 +00:00
extern void sanei_genesys_init_shading_data ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
int pixels_per_line ) ;
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:49 +00:00
extern void sanei_genesys_read_valid_words ( Genesys_Device * dev , unsigned int * steps ) ;
2009-01-19 05:46:43 +00:00
2019-07-14 20:40:48 +00:00
extern void sanei_genesys_read_scancnt ( Genesys_Device * dev , unsigned int * steps ) ;
2009-12-09 19:52:29 +00:00
2019-07-14 20:40:52 +00:00
extern void sanei_genesys_read_feed_steps ( Genesys_Device * dev , unsigned int * steps ) ;
2005-06-27 20:07:45 +00:00
2019-06-08 11:04:24 +00:00
void sanei_genesys_set_lamp_power ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set & regs , bool set ) ;
2019-06-08 11:04:25 +00:00
void sanei_genesys_set_motor_power ( Genesys_Register_Set & regs , bool set ) ;
2019-08-04 09:01:51 +00:00
/** Calculates the values of the Z{1,2}MOD registers. They are a phase correction to synchronize
with the line clock during acceleration and deceleration .
two_table is true if moving is done by two tables , false otherwise .
acceleration_steps is the number of steps for acceleration , i . e . the number written to
REG_STEPNO .
move_steps number of steps to move , i . e . the number written to REG_FEEDL .
buffer_acceleration_steps , the number of steps for acceleration when buffer condition is met ,
i . e . the number written to REG_FWDSTEP .
*/
void sanei_genesys_calculate_zmod ( SANE_Bool two_table ,
uint32_t exposure_time ,
const std : : vector < uint16_t > & slope_table ,
unsigned acceleration_steps ,
unsigned move_steps ,
unsigned buffer_acceleration_steps ,
uint32_t * out_z1 , uint32_t * out_z2 ) ;
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:42 +00:00
extern void sanei_genesys_set_buffer_address ( Genesys_Device * dev , uint32_t addr ) ;
2005-06-27 20:07:45 +00:00
2012-11-02 20:46:44 +00:00
/** @brief Reads data from frontend register.
* Reads data from the given frontend register . May be used to query
* analog frontend status by reading the right register .
*/
2019-07-14 20:40:53 +00:00
extern void sanei_genesys_fe_read_data ( Genesys_Device * dev , uint8_t addr , uint16_t * data ) ;
2012-11-02 20:46:44 +00:00
/** @brief Write data to frontend register.
* Writes data to analog frontend register at the given address .
* The use and address of registers change from model to model .
*/
2019-07-14 20:40:51 +00:00
extern void sanei_genesys_fe_write_data ( Genesys_Device * dev , uint8_t addr , uint16_t data ) ;
2005-06-27 20:07:45 +00:00
2019-08-04 09:01:49 +00:00
SANE_Int sanei_genesys_exposure_time2 ( Genesys_Device * dev , float ydpi , int step_type ,
int endpixel , int led_exposure ) ;
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 ) ;
2019-08-04 09:01:50 +00:00
SANE_Int sanei_genesys_generate_slope_table ( std : : vector < uint16_t > & slope_table , unsigned int max_steps ,
2009-02-26 03:15:43 +00:00
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
2019-08-04 09:01:50 +00:00
SANE_Int sanei_genesys_create_slope_table ( Genesys_Device * dev , std : : vector < uint16_t > & slope_table ,
int steps , int step_type , int exposure_time ,
SANE_Bool same_speed , double yres ) ;
SANE_Int sanei_genesys_create_slope_table3 ( Genesys_Device * dev ,
std : : vector < 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 ,
2019-08-04 09:01:49 +00:00
unsigned int * final_exposure ) ;
2005-11-19 22:51:01 +00:00
2019-06-02 08:47:49 +00:00
void sanei_genesys_create_default_gamma_table ( Genesys_Device * dev ,
std : : vector < uint16_t > & gamma_table , float gamma ) ;
2019-06-02 08:47:50 +00:00
std : : vector < uint16_t > get_gamma_table ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
int color ) ;
2019-07-20 08:02:06 +00:00
void sanei_genesys_send_gamma_table ( Genesys_Device * dev , const Genesys_Sensor & sensor ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:01:57 +00:00
extern void sanei_genesys_stop_motor ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:02:12 +00:00
extern void sanei_genesys_search_reference_point ( Genesys_Device * dev , Genesys_Sensor & sensor ,
2019-08-03 23:48:28 +00:00
const uint8_t * src_data , int start_pixel , int dpi ,
int width , int height ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:02:11 +00:00
extern void sanei_genesys_write_file ( const char * filename , uint8_t * data , size_t length ) ;
2019-05-11 09:12:29 +00:00
2019-07-20 08:02:10 +00:00
extern void sanei_genesys_write_pnm_file ( const char * filename , uint8_t * data , int depth ,
int channels , int pixels_per_line , int lines ) ;
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:47 +00:00
extern void sanei_genesys_test_buffer_empty ( Genesys_Device * dev , SANE_Bool * empty ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:02:15 +00:00
extern void sanei_genesys_read_data_from_scanner ( Genesys_Device * dev , uint8_t * data , size_t size ) ;
2005-06-27 20:07:45 +00:00
2019-06-02 08:47:31 +00:00
inline void sanei_genesys_set_exposure ( Genesys_Register_Set & regs , const SensorExposure & exposure )
{
regs . set8 ( 0x10 , ( exposure . red > > 8 ) & 0xff ) ;
regs . set8 ( 0x11 , exposure . red & 0xff ) ;
regs . set8 ( 0x12 , ( exposure . green > > 8 ) & 0xff ) ;
regs . set8 ( 0x13 , exposure . green & 0xff ) ;
regs . set8 ( 0x14 , ( exposure . blue > > 8 ) & 0xff ) ;
regs . set8 ( 0x15 , exposure . blue & 0xff ) ;
}
inline uint16_t sanei_genesys_fixup_exposure_value ( uint16_t value )
{
if ( ( value & 0xff00 ) = = 0 ) {
value | = 0x100 ;
}
if ( ( value & 0x00ff ) = = 0 ) {
value | = 0x1 ;
}
return value ;
}
inline SensorExposure sanei_genesys_fixup_exposure ( SensorExposure exposure )
{
exposure . red = sanei_genesys_fixup_exposure_value ( exposure . red ) ;
exposure . green = sanei_genesys_fixup_exposure_value ( exposure . green ) ;
exposure . blue = sanei_genesys_fixup_exposure_value ( exposure . blue ) ;
return exposure ;
}
2019-07-14 20:40:56 +00:00
extern void sanei_genesys_wait_for_home ( Genesys_Device * dev ) ;
2011-01-12 19:51:32 +00:00
2019-07-20 08:02:14 +00:00
extern void sanei_genesys_asic_init ( Genesys_Device * dev , SANE_Bool cold ) ;
2013-01-28 21:04:37 +00:00
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 ) ;
2019-08-04 09:01:50 +00:00
int sanei_genesys_slope_table ( std : : vector < uint16_t > & slope , int * steps , int dpi , int exposure ,
int base_dpi , int step_type , int factor , int motor_type ,
Motor_Profile * motors ) ;
2011-02-16 06:13:01 +00:00
2011-08-23 05:20:52 +00:00
/** @brief find lowest motor resolution for the device.
* Parses the resolution list for motor and
* returns the lowest value .
2012-10-24 19:28:42 +00:00
* @ param dev for which to find the lowest motor resolution
2011-08-23 05:20:52 +00:00
* @ return the lowest available motor resolution for the device
*/
2011-02-16 06:13:01 +00:00
extern
int sanei_genesys_get_lowest_ydpi ( Genesys_Device * dev ) ;
2011-08-23 05:20:52 +00:00
/** @brief find lowest resolution for the device.
* Parses the resolution list for motor and sensor and
* returns the lowest value .
2012-10-24 19:28:42 +00:00
* @ param dev for which to find the lowest resolution
2011-08-23 05:20:52 +00:00
* @ return the lowest available resolution for the device
*/
extern
int sanei_genesys_get_lowest_dpi ( Genesys_Device * dev ) ;
2019-06-30 11:05:16 +00:00
extern bool
2019-06-02 08:47:51 +00:00
sanei_genesys_is_compatible_calibration ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
2011-07-31 20:09:46 +00:00
Genesys_Calibration_Cache * cache ,
int for_overwrite ) ;
2011-09-22 04:17:02 +00:00
/** @brief compute maximum line distance shift
* compute maximum line distance shift for the motor and sensor
* combination . Line distance shift is the distance between different
* color component of CCD sensors . Since these components aren ' t at
* the same physical place , they scan diffrent lines . Software must
* take this into account to accurately mix color data .
* @ param dev device session to compute max_shift for
* @ param channels number of color channels for the scan
* @ param yres motor resolution used for the scan
* @ param flags scan flags
* @ return 0 or line distance shift
*/
2013-01-28 21:04:37 +00:00
extern
2011-09-22 04:17:02 +00:00
int sanei_genesys_compute_max_shift ( Genesys_Device * dev ,
int channels ,
int yres ,
int flags ) ;
2013-08-11 19:15:25 +00:00
2019-07-20 08:02:39 +00:00
extern void sanei_genesys_load_lut ( unsigned char * lut ,
int in_bits , int out_bits ,
int out_min , int out_max ,
int slope , int offset ) ;
2013-08-11 19:15:25 +00:00
2019-07-14 20:40:54 +00:00
extern void sanei_genesys_generate_gamma_buffer ( Genesys_Device * dev ,
2019-06-02 08:47:51 +00:00
const Genesys_Sensor & sensor ,
2013-08-11 19:15:25 +00:00
int bits ,
int max ,
int size ,
2019-07-14 20:40:54 +00:00
uint8_t * gamma ) ;
2013-08-11 19:15:25 +00:00
2005-06-27 20:07:45 +00:00
/*---------------------------------------------------------------------------*/
/* ASIC specific functions declarations */
/*---------------------------------------------------------------------------*/
2019-05-11 09:12:28 +00:00
// same as usleep, except that it does nothing if testing mode is enabled
extern void sanei_genesys_usleep ( unsigned int useconds ) ;
// same as sanei_genesys_usleep just that the duration is in milliseconds
extern void sanei_genesys_sleep_ms ( unsigned int milliseconds ) ;
2019-05-25 08:15:26 +00:00
void add_function_to_run_at_backend_exit ( std : : function < void ( ) > function ) ;
// calls functions added via add_function_to_run_at_backend_exit() in reverse order of being
// added.
void run_functions_at_backend_exit ( ) ;
template < class T >
class StaticInit {
public :
StaticInit ( ) = default ;
StaticInit ( const StaticInit & ) = delete ;
StaticInit & operator = ( const StaticInit & ) = delete ;
template < class . . . Args >
void init ( Args & & . . . args )
{
ptr_ = std : : unique_ptr < T > ( new T ( std : : forward < Args > ( args ) . . . ) ) ;
add_function_to_run_at_backend_exit ( [ this ] ( ) { deinit ( ) ; } ) ;
}
void deinit ( )
{
ptr_ . release ( ) ;
}
const T * operator - > ( ) const { return ptr_ . get ( ) ; }
T * operator - > ( ) { return ptr_ . get ( ) ; }
const T & operator * ( ) const { return * ptr_ . get ( ) ; }
T & operator * ( ) { return * ptr_ . get ( ) ; }
private :
std : : unique_ptr < T > ptr_ ;
} ;
2019-05-25 08:15:27 +00:00
extern StaticInit < std : : vector < Genesys_Sensor > > s_sensors ;
void genesys_init_sensor_tables ( ) ;
2019-06-02 08:48:03 +00:00
void genesys_init_frontend_tables ( ) ;
2019-08-04 09:01:48 +00:00
void genesys_init_motor_tables ( ) ;
2019-07-20 06:16:33 +00:00
void genesys_init_usb_device_tables ( ) ;
2019-05-25 08:15:27 +00:00
2019-06-08 11:03:59 +00:00
void debug_dump ( unsigned level , const Genesys_Settings & settings ) ;
2019-06-08 11:04:13 +00:00
void debug_dump ( unsigned level , const SetupParams & params ) ;
2019-08-03 23:48:27 +00:00
void debug_dump ( unsigned level , const ScanSession & session ) ;
2019-06-30 11:05:22 +00:00
void debug_dump ( unsigned level , const Genesys_Current_Setup & setup ) ;
2019-07-06 18:02:23 +00:00
void debug_dump ( unsigned level , const Genesys_Register_Set & regs ) ;
2019-08-03 23:48:27 +00:00
void debug_dump ( unsigned level , const GenesysRegisterSettingSet & regs ) ;
void debug_dump ( unsigned level , const Genesys_Sensor & sensor ) ;
2019-06-08 11:03:59 +00:00
2005-06-27 20:07:45 +00:00
# endif /* not GENESYS_LOW_H */