From 6e9c41a892ed0e0da326e0278b3221ce3f5713b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 6 Oct 2014 14:00:40 +0200 Subject: Initial import of sane-backends version 1.0.24-1.2 --- backend/mustek_usb2_asic.h | 1421 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1421 insertions(+) create mode 100644 backend/mustek_usb2_asic.h (limited to 'backend/mustek_usb2_asic.h') diff --git a/backend/mustek_usb2_asic.h b/backend/mustek_usb2_asic.h new file mode 100644 index 0000000..ffc92ff --- /dev/null +++ b/backend/mustek_usb2_asic.h @@ -0,0 +1,1421 @@ +/* sane - Scanner Access Now Easy. + + Copyright (C) 2005 Mustek. + Originally maintained by Mustek + Author:Roy 2005.5.24 + + 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. + + This file implements a SANE backend for the Mustek BearPaw 2448 TA Pro + and similar USB2 scanners. */ + +#ifndef MUSTEK_USB2_ASIC_H +#define MUSTEK_USB2_ASIC_H + +#include "../include/sane/sanei_usb.h" + +/* ---------------------- low level asic defines -------------------------- */ + +#define TRUE 1 +#define FALSE 0 + +#define _MAX(a,b) ((a)>(b)?(a):(b)) +#define _MIN(a,b) ((a)<(b)?(a):(b)) + +#ifndef LOBYTE +#define LOBYTE(w) (SANE_Byte)((unsigned short)(w) & 0x00ff) +#endif + +#ifndef HIBYTE +#define HIBYTE(w) (SANE_Byte)((unsigned short)(w)>>8 & 0x00ff) +#endif + + +typedef enum tagFIRMWARESTATE +{ + FS_NULL = 0, + FS_ATTACHED = 1, + FS_OPENED = 2, + FS_SCANNING = 3 +} FIRMWARESTATE, *LPFIRMWARESTATE; + +typedef enum tagMOTORSTATE +{ + MS_STILL = 0, + MS_MOVED = 1 +} MOTORSTATE, *LPMOTORSTATE; + +typedef enum tagUSBHOST +{ + HT_USB10 = 0, + HT_USB20 = 1 +} USBHOST; + +typedef enum tagLIGHTSOURCE +{ + LS_REFLECTIVE = 1, + LS_POSITIVE = 2, + LS_NEGATIVE = 4 +} LIGHTSOURCE; + +typedef struct +{ + unsigned int LongX; + unsigned int PicWidth; + unsigned int PicHeight; + + unsigned int Top; + unsigned int Bottom; + unsigned int Left; + unsigned int Right; + unsigned int ScanMode; + unsigned int Dpi; + unsigned int TotalMotorSteps; + + unsigned int CCD_Pixel_Length; + SANE_Byte LineGap; + SANE_Byte TG_Pulse_Width_Pixel; + SANE_Byte TG_Wait_Width_Pixel; + unsigned short Multi_TG_Dummy_Pixel; + unsigned short CCD_Dummy_Pixel; + SANE_Byte Dummy_Cycle; + SANE_Byte TG_Times; + + double LineTime; + + unsigned short StartPixel; + unsigned short StartLine; +} +ScanParam; + +typedef struct +{ + unsigned int Shading_Table_Size; + unsigned int Image_Buffer_Size; + unsigned int Full_Bank; + unsigned int Line_Pixel; + double Line_Time; + SANE_Byte LineGap; +} +Temps; + +typedef struct +{ + /* AFE */ + unsigned int AFE_ADCCLK_Timing; + unsigned int AFE_ADCVS_Timing; + unsigned int AFE_ADCRS_Timing; + unsigned short AFE_ChannelA_LatchPos; + unsigned short AFE_ChannelB_LatchPos; + unsigned short AFE_ChannelC_LatchPos; + unsigned short AFE_ChannelD_LatchPos; + SANE_Byte AFE_Secondary_FF_LatchPos; + /* Sensor */ + unsigned int CCD_DummyCycleTiming; + SANE_Byte PHTG_PluseWidth; + SANE_Byte PHTG_WaitWidth; + unsigned short ChannelR_StartPixel; + unsigned short ChannelR_EndPixel; + unsigned short ChannelG_StartPixel; + unsigned short ChannelG_EndPixel; + unsigned short ChannelB_StartPixel; + unsigned short ChannelB_EndPixel; + SANE_Byte PHTG_TimingAdj; + SANE_Byte PHTG_TimingSetup; + + /*1200dpi */ + unsigned int CCD_PHRS_Timing_1200; + unsigned int CCD_PHCP_Timing_1200; + unsigned int CCD_PH1_Timing_1200; + unsigned int CCD_PH2_Timing_1200; + SANE_Byte DE_CCD_SETUP_REGISTER_1200; + unsigned short wCCDPixelNumber_1200; + + /*600dpi */ + unsigned int CCD_PHRS_Timing_600; + unsigned int CCD_PHCP_Timing_600; + unsigned int CCD_PH1_Timing_600; + unsigned int CCD_PH2_Timing_600; + SANE_Byte DE_CCD_SETUP_REGISTER_600; + unsigned short wCCDPixelNumber_600; +} Timings; + + +typedef struct tagADConverter +{ + SANE_Byte GainR; + SANE_Byte GainG; + SANE_Byte GainB; + SANE_Byte OffsetR; + SANE_Byte OffsetG; + SANE_Byte OffsetB; + SANE_Bool DirectionR; + SANE_Bool DirectionG; + SANE_Bool DirectionB; +} ADConverter, LPADConverter; + + + +typedef struct +{ + unsigned int Shading; + SANE_Byte Shading_0; + SANE_Byte Shading_1; + SANE_Byte Shading_2; + + unsigned int Motor; + SANE_Byte Motor_0; + SANE_Byte Motor_1; + SANE_Byte Motor_2; + + SANE_Byte ImageEndAddr_0; + SANE_Byte ImageEndAddr_1; + SANE_Byte ImageEndAddr_2; + + SANE_Byte ImageFullBank_0; + SANE_Byte ImageFullBank_1; +} +RamPosition; + +typedef enum tagTASSTATUS +{ + TA_NOT_PLUGIN = 0, + TA_PLUGIN = 1, + TA_UNKNOW = 2 +} TASTATUS; + +typedef struct +{ + int fd; /* File Description of Scanner */ + + FIRMWARESTATE firmwarestate; /* record firmware state */ + MOTORSTATE motorstate; /* record motor status */ + SANE_Bool isFirstOpenChip; /* If first open chip, is TRUE */ + USBHOST UsbHost; /* The type of USB port */ + LIGHTSOURCE lsLightSource; /* light source of scanner */ + ScanParam Scan; /* The parameters of Scan */ + + unsigned int dwBytesCountPerRow; + unsigned int dwCalibrationBytesCountPerRow; + + Temps Temp; + Timings Timing; + ADConverter AD; + + SANE_Bool isHardwareShading; + + RamPosition RamPositions; + + unsigned short * lpGammaTable; + SANE_Byte isMotorMove; + + unsigned int ibase1; + unsigned int ibase2; + + unsigned short SWWidth; + + TASTATUS TA_Status; + + SANE_Byte isMotorGoToFirstLine; /*Roy add */ + SANE_Byte * lpShadingTable; /*Roy add */ + SANE_Byte isUniformSpeedToScan; +} +Asic, *PAsic; + +typedef enum +{ + STATUS_GOOD = 0, + STATUS_CANCELLED, + STATUS_EOF, + STATUS_DEVICE_BUSY, + STATUS_INVAL, + STATUS_MEM_ERROR, + STATUS_IO_ERROR, + STATUS_ACCESS_ERROR +} +STATUS; + + +/* For ScanObj */ +typedef struct Point +{ + unsigned int x; + unsigned int y; +} +Point; + +typedef struct Rect +{ + unsigned int left; + unsigned int right; + unsigned int top; + unsigned int bottom; +} +Rect; + +typedef struct RGBColor +{ + unsigned short Red; + unsigned short Green; + unsigned short Blue; +} +RGBColor; + +/* debug levels */ +#define DBG_CRIT 0 /* Critical errors thatshould be printed even + if user hasn't enabled debugging -- use + with care and only after sane_open has been + called */ +#define DBG_ERR 1 /* Other errors */ +#define DBG_WARN 2 /* unusual conditions that may not be fatal */ +#define DBG_INFO 3 /* information useful for the deucated user */ +#define DBG_DET 4 /* more detailed information */ +#define DBG_FUNC 5 /* start and exits of high level functions */ +#define DBG_ASIC 6 /* starts and exits of low level functions */ +#define DBG_DBG 10 /* usefull only for tracing bugs */ + + +#define DPI_2400 0x8000 +#define DPI_1200 0x8000 +#define DPI_600 0x8000 +#define DPI_300 0x4000 +#define DPI_200 0x2aaa +#define DPI_150 0x2000 +#define DPI_100 0x1555 +#define DPI_75 0x1000 +#define DPI_50 0xaaa +#define PIXEL_TIME 333 /*unit : ms */ +#define DRAM_1Mx16_SIZE (1024*1024) /*unit : word */ +#define PackAreaStartAddress ((DRAM_1Mx16_SIZE/4)*3) + +#define TEMP_MEMORY_SIZE_64K 64*1024 + +#define CALIBRATION_PIXEL_WIDTH 10240 /*need 512x */ +#define CALIBRATE_WHITE_LINECOUNT 40 +#define CALIBRATE_DARK_LINECOUNT 2 + +#define ACTION_MODE_ACCDEC_MOVE 0 +#define ACTION_MODE_UNIFORM_SPEED_MOVE 1 + +#define ACTION_TYPE_BACKWARD 0 +#define ACTION_TYPE_FORWARD 1 +#define ACTION_TYPE_BACKTOHOME 2 +#define ACTION_TYPE_TEST_MODE 3 + + +#define SENSOR0_DETECTED 0x10 +#define SENSOR1_DETECTED 0x20 +#define SENSOR0AND1_DETECTED 0x30 + +#define READ_RAM 0 +#define WRITE_RAM 1 + +#define EXTERNAL_RAM 0 +#define ON_CHIP_PRE_GAMMA 1 +#define ON_CHIP_FINAL_GAMMA 2 + +#define MOTOR_TABLE_SIZE 512*8 + +#define ValidPixelNumberFor600DPI 5100 + 50 + 250 +#define ValidPixelNumberFor1200DPI 10200 + 100 + 500 + +#define OverLapPixelNumber600 0 +#define OverLapPixelNumber1200 0 +#define SegmentGap 0 +#define BANK_SIZE (64) + +#define WaitBufferOneLineSize 11000*6 + +#define CCD_PIXEL_NUMBER 21600 +#define CCD_Line_Spacing 24 +#define CCD_EvneOdd_Spacing 2 + +#define ShadingTableSize(x) ( ((x + 10)*6) + ( ((x + 10)*6)/240)*16 ) +#define ACC_DEC_STEP_TABLE_SIZE (512) /*unit : word */ +#define TableBase(x) ((((x)+((1<>TABLE_OFFSET_BASE)<