kopia lustrzana https://gitlab.com/sane-project/backends
activated cancel function, added lamp off timer function, cleanup, stability fixes.
rodzic
da7ec7ea25
commit
21fbbbb312
|
@ -1106,8 +1106,14 @@ static void u12ccd_InitCCDandDAC( U12_Device *dev, SANE_Bool shading )
|
|||
|
||||
DBG( _DBG_INFO, "* [0x%02x] = 0x%02x\n", dev->DACRegs[w].reg,
|
||||
dev->DACRegs[w].val );
|
||||
#if 0
|
||||
u12io_DataRegisterToDAC( dev, dev->DACRegs[w].reg,
|
||||
dev->DACRegs[w].val );
|
||||
#else
|
||||
u12io_DataToRegister( dev, REG_ADCADDR, dev->DACRegs[w].reg );
|
||||
u12io_DataToRegister( dev, REG_ADCDATA, dev->DACRegs[w].val );
|
||||
u12io_DataToRegister( dev, REG_ADCSERIALOUT, dev->DACRegs[w].val );
|
||||
#endif
|
||||
}
|
||||
DBG( _DBG_INFO, "CCD & DAC init done.\n" );
|
||||
}
|
||||
|
|
189
backend/u12-hw.c
189
backend/u12-hw.c
|
@ -6,6 +6,7 @@
|
|||
* History:
|
||||
* - 0.01 - initial version
|
||||
* - 0.02 - cleanup
|
||||
* - added lampTimer stuff
|
||||
* .
|
||||
* <hr>
|
||||
* This file is part of the SANE package.
|
||||
|
@ -218,6 +219,9 @@ static void u12hw_InitiateComponentModel( U12_Device *dev )
|
|||
*/
|
||||
static SANE_Status u12hw_InitAsic( U12_Device *dev, SANE_Bool shading )
|
||||
{
|
||||
SANE_Byte rb[6];
|
||||
int c;
|
||||
|
||||
DBG( _DBG_INFO, "u12hw_InitAsic(%d)\n", shading );
|
||||
|
||||
/* get DAC and motor stuff */
|
||||
|
@ -254,12 +258,19 @@ static SANE_Status u12hw_InitAsic( U12_Device *dev, SANE_Bool shading )
|
|||
dev->regs.RD_Model1Control += _SCAN_GRAYTYPE;
|
||||
|
||||
DBG( _DBG_INFO, "* MotorDrvType = 0x%02x\n", dev->regs.RD_MotorDriverType);
|
||||
u12io_DataToRegister( dev, REG_MOTORDRVTYPE, dev->regs.RD_MotorDriverType);
|
||||
|
||||
u12io_DataToRegister( dev, REG_WAITSTATEINSERT, 4 );
|
||||
|
||||
DBG( _DBG_INFO, "* Model1Cntrl = 0x%02x\n", dev->regs.RD_Model1Control );
|
||||
|
||||
#if 0
|
||||
u12io_DataToRegister( dev, REG_MOTORDRVTYPE, dev->regs.RD_MotorDriverType);
|
||||
u12io_DataToRegister( dev, REG_WAITSTATEINSERT, 4 );
|
||||
u12io_DataToRegister( dev, REG_MODEL1CONTROL, dev->regs.RD_Model1Control );
|
||||
#else
|
||||
c = 0;
|
||||
_SET_REG( rb, c, REG_MOTORDRVTYPE, dev->regs.RD_MotorDriverType);
|
||||
_SET_REG( rb, c, REG_WAITSTATEINSERT, 4 );
|
||||
_SET_REG( rb, c, REG_MODEL1CONTROL, dev->regs.RD_Model1Control );
|
||||
u12io_DataToRegs( dev, rb, c );
|
||||
#endif
|
||||
|
||||
u12hw_ProgramCCD( dev );
|
||||
DBG( _DBG_INFO, "u12hw_InitAsic done.\n" );
|
||||
|
@ -597,7 +608,7 @@ static SANE_Status u12hw_CheckDevice( U12_Device *dev )
|
|||
return SANE_STATUS_IO_ERROR;
|
||||
}
|
||||
#else
|
||||
u12io_IsConnected( dev );
|
||||
/* u12io_IsConnected( dev ); */
|
||||
if( !u12io_OpenScanPath( dev ))
|
||||
return SANE_STATUS_IO_ERROR;
|
||||
#endif
|
||||
|
@ -634,6 +645,52 @@ static SANE_Status u12hw_CheckDevice( U12_Device *dev )
|
|||
#endif
|
||||
}
|
||||
|
||||
/* prototypes... */
|
||||
static void u12motor_PositionModuleToHome( U12_Device *);
|
||||
static void u12motor_ToHomePosition( U12_Device *, SANE_Bool );
|
||||
|
||||
/**
|
||||
*/
|
||||
static void u12hw_CancelSequence( U12_Device *dev )
|
||||
{
|
||||
int c = 0;
|
||||
SANE_Byte rb[6];
|
||||
|
||||
DBG( _DBG_INFO, "u12hw_CancelSequence()\n" );
|
||||
|
||||
u12motor_PositionModuleToHome( dev );
|
||||
|
||||
u12motor_ToHomePosition( dev, SANE_TRUE );
|
||||
|
||||
u12io_DataToRegister( dev, REG_MOTOR0CONTROL, 0 );
|
||||
u12io_DataToRegister( dev, REG_MODELCONTROL, 0x1a );
|
||||
|
||||
u12hw_PutToIdleMode( dev );
|
||||
u12io_SoftwareReset( dev );
|
||||
|
||||
u12motor_PositionModuleToHome( dev );
|
||||
|
||||
u12io_DataToRegister( dev, REG_SCANCONTROL, 0x05 );
|
||||
u12io_DataToRegister( dev, REG_MODELCONTROL, 0x1f );
|
||||
|
||||
u12hw_PutToIdleMode( dev );
|
||||
|
||||
u12io_DataToRegister( dev, REG_MODELCONTROL, 0x00 );
|
||||
|
||||
u12io_DataToRegister( dev, REG_ADCADDR, 0x01 );
|
||||
u12io_DataToRegister( dev, REG_ADCDATA, 0x00 );
|
||||
u12io_DataToRegister( dev, REG_ADCSERIALOUT, 0x00 );
|
||||
|
||||
_SET_REG( rb, c, REG_MODECONTROL, 0x19 );
|
||||
_SET_REG( rb, c, REG_STEPCONTROL, 0xff );
|
||||
_SET_REG( rb, c, REG_MOTOR0CONTROL, 0 );
|
||||
u12io_DataToRegs( dev, rb, c );
|
||||
|
||||
u12io_CloseScanPath( dev );
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
static SANE_Status u12hw_WarmupLamp( U12_Device *dev )
|
||||
{
|
||||
TimerDef timer;
|
||||
|
@ -655,4 +712,126 @@ static SANE_Status u12hw_WarmupLamp( U12_Device *dev )
|
|||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
/* FIXME: replace!!! */
|
||||
static U12_Device *dev_xxx = NULL;
|
||||
|
||||
/** ISR to switch lamp off after time has elapsed
|
||||
*/
|
||||
static void usb_LampTimerIrq( int sig )
|
||||
{
|
||||
SANE_Byte tmp;
|
||||
int handle = -1;
|
||||
|
||||
if( NULL == dev_xxx )
|
||||
return;
|
||||
|
||||
_VAR_NOT_USED( sig );
|
||||
DBG( _DBG_INFO, "*** LAMP OFF!!! ***\n" );
|
||||
|
||||
if( -1 == dev_xxx->fd ) {
|
||||
|
||||
if( SANE_STATUS_GOOD == sanei_usb_open(dev_xxx->sane.name, &handle)) {
|
||||
dev_xxx->fd = handle;
|
||||
}
|
||||
}
|
||||
|
||||
if( -1 != dev_xxx->fd ) {
|
||||
|
||||
if( !u12io_IsConnected( dev_xxx )) {
|
||||
|
||||
if( u12io_OpenScanPath( dev_xxx )) {
|
||||
|
||||
/* some setup stuff... */
|
||||
tmp = u12io_GetExtendedStatus( dev_xxx );
|
||||
if( tmp & _REFLECTIONLAMP_ON ) {
|
||||
DBG( _DBG_INFO, "* Normal lamp is ON\n" );
|
||||
} else if( tmp & _TPALAMP_ON ) {
|
||||
DBG( _DBG_INFO, "* TPA lamp is ON\n" );
|
||||
}
|
||||
|
||||
u12io_DataToRegister( dev_xxx, REG_SCANCONTROL, 0 );
|
||||
u12io_CloseScanPath( dev_xxx );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( -1 != handle ) {
|
||||
dev_xxx->fd = -1;
|
||||
sanei_usb_close( handle );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
static void u12hw_StartLampTimer( U12_Device *dev )
|
||||
{
|
||||
#ifdef HAVE_SETITIMER
|
||||
sigset_t block, pause_mask;
|
||||
struct sigaction s;
|
||||
struct itimerval interval;
|
||||
|
||||
/* block SIGALRM */
|
||||
sigemptyset( &block );
|
||||
sigaddset ( &block, SIGALRM );
|
||||
sigprocmask( SIG_BLOCK, &block, &pause_mask );
|
||||
|
||||
/* setup handler */
|
||||
sigemptyset( &s.sa_mask );
|
||||
sigaddset ( &s.sa_mask, SIGALRM );
|
||||
s.sa_flags = 0;
|
||||
s.sa_handler = usb_LampTimerIrq;
|
||||
|
||||
if( sigaction( SIGALRM, &s, NULL ) < 0 )
|
||||
DBG( _DBG_ERROR, "Can't setup timer-irq handler\n" );
|
||||
|
||||
sigprocmask( SIG_UNBLOCK, &block, &pause_mask );
|
||||
|
||||
/*
|
||||
* define a one-shot timer
|
||||
*/
|
||||
interval.it_value.tv_usec = 0;
|
||||
interval.it_value.tv_sec = dev->adj.lampOff;
|
||||
interval.it_interval.tv_usec = 0;
|
||||
interval.it_interval.tv_sec = 0;
|
||||
|
||||
dev_xxx = dev;
|
||||
|
||||
if( 0 != dev->adj.lampOff ) {
|
||||
setitimer( ITIMER_REAL, &interval, &dev->saveSettings );
|
||||
DBG( _DBG_INFO, "Lamp-Timer started (using ITIMER)\n" );
|
||||
}
|
||||
#else
|
||||
dev_xxx = dev;
|
||||
|
||||
alarm( dev->usbDev.dwLampOnPeriod );
|
||||
DBG( _DBG_INFO, "Lamp-Timer started (using ALARM)\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
static void u12hw_StopLampTimer( U12_Device *dev )
|
||||
{
|
||||
#ifdef HAVE_SETITIMER
|
||||
sigset_t block, pause_mask;
|
||||
|
||||
/* block SIGALRM */
|
||||
sigemptyset( &block );
|
||||
sigaddset ( &block, SIGALRM );
|
||||
sigprocmask( SIG_BLOCK, &block, &pause_mask );
|
||||
|
||||
if( 0 != dev->adj.lampOff )
|
||||
setitimer( ITIMER_REAL, &dev->saveSettings, NULL );
|
||||
|
||||
dev_xxx = NULL;
|
||||
|
||||
#else
|
||||
_VAR_NOT_USED( dev );
|
||||
dev_xxx = NULL;
|
||||
|
||||
alarm( 0 );
|
||||
#endif
|
||||
DBG( _DBG_INFO, "Lamp-Timer stopped\n" );
|
||||
}
|
||||
|
||||
/* END U12-HW.C .............................................................*/
|
||||
|
|
|
@ -173,8 +173,7 @@ static void u12if_shutdown( U12_Device *dev )
|
|||
u12io_DataToRegister(dev,REG_SCANCONTROL, dev->regs.RD_ScanControl );
|
||||
}
|
||||
|
||||
/* u12io_SoftwareReset( dev );
|
||||
*/ u12io_CloseScanPath( dev );
|
||||
u12io_CloseScanPath( dev );
|
||||
dev->fd = -1;
|
||||
sanei_usb_close( handle );
|
||||
}
|
||||
|
@ -195,16 +194,7 @@ static void u12if_shutdown( U12_Device *dev )
|
|||
static SANE_Bool u12if_IsDeviceSupported( U12_Device *dev )
|
||||
{
|
||||
int i;
|
||||
#if 0
|
||||
/* Plustek U12, UT12, U1212, U12B */
|
||||
if( !strcmp( dev->usbId, "0x07B3-0x0001" ))
|
||||
return SANE_TRUE;
|
||||
|
||||
/* Genius Colorpage Vivid III V2 */
|
||||
if( !strcmp( dev->usbId, "0x0458-0x2004" )) {
|
||||
return SANE_TRUE;
|
||||
}
|
||||
#else
|
||||
for( i = 0; NULL != u12Devices[i].name; i++ ) {
|
||||
|
||||
if( !strcmp( dev->usbId, u12Devices[i].vp )) {
|
||||
|
@ -212,7 +202,6 @@ static SANE_Bool u12if_IsDeviceSupported( U12_Device *dev )
|
|||
return SANE_TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return SANE_FALSE;
|
||||
}
|
||||
|
@ -497,6 +486,7 @@ static SANE_Status u12if_setScanEnv( U12_Device *dev, ImgDef *img )
|
|||
static SANE_Status u12if_startScan( U12_Device *dev )
|
||||
{
|
||||
DBG( _DBG_INFO, "u12if_startScan()\n" );
|
||||
u12hw_StopLampTimer( dev );
|
||||
u12hw_SetGeneralRegister( dev );
|
||||
u12hw_ControlLampOnOff( dev );
|
||||
return SANE_STATUS_GOOD;
|
||||
|
@ -508,10 +498,13 @@ static SANE_Status u12if_stopScan( U12_Device *dev )
|
|||
{
|
||||
DBG( _DBG_INFO, "u12if_stopScan()\n" );
|
||||
|
||||
u12motor_ToHomePosition( dev, SANE_FALSE );
|
||||
#if 0
|
||||
u12motor_ToHomePosition( dev, SANE_FALSE );
|
||||
#else
|
||||
u12motor_ToHomePosition( dev, SANE_TRUE );
|
||||
u12io_SoftwareReset( dev );
|
||||
#endif
|
||||
u12hw_StartLampTimer( dev );
|
||||
dev->DataInf.dwAppLinesPerArea = 0;
|
||||
dev->DataInf.dwScanFlag &= ~_SCANDEF_SCANNING;
|
||||
return SANE_STATUS_GOOD;
|
||||
|
|
|
@ -611,8 +611,10 @@ static SANE_Status u12image_SetupScanSettings( U12_Device *dev, ImgDef *img )
|
|||
DBG( _DBG_INFO, "48Bit buffer request: "
|
||||
"len=%lu bytes, available=%lu\n", b, _SIZE_TOTAL_BUF_TPA );
|
||||
|
||||
if( b > _SIZE_TOTAL_BUF_TPA )
|
||||
if( b > _SIZE_TOTAL_BUF_TPA ) {
|
||||
DBG( _DBG_ERROR, "Not that much FIFO memory available!\n" );
|
||||
return SANE_STATUS_NO_MEM;
|
||||
}
|
||||
|
||||
dev->scan.p48BitBuf.pb = dev->bufs.b1.pReadBuf;
|
||||
}
|
||||
|
|
|
@ -339,6 +339,7 @@ static void u12io_RegisterToScanner( U12_Device *dev, SANE_Byte reg )
|
|||
|
||||
/* signal that to the ASIC */
|
||||
outb_ctrl( dev->fd, _CTRL_SIGNAL_REGWRITE );
|
||||
_DODELAY(20);
|
||||
outb_ctrl( dev->fd, _CTRL_END_REGWRITE );
|
||||
}
|
||||
}
|
||||
|
@ -400,7 +401,11 @@ static SANE_Byte u12io_DataFromRegister( U12_Device *dev, SANE_Byte reg )
|
|||
*/
|
||||
static void u12io_CloseScanPath( U12_Device *dev )
|
||||
{
|
||||
DBG( _DBG_INFO, "u12io_CloseScanPath()\n" );
|
||||
/* FIXME: Probaly not needed */
|
||||
#if 0
|
||||
u12io_RegisterToScanner( dev, 0xff );
|
||||
#endif
|
||||
u12io_RegisterToScanner( dev, REG_SWITCHBUS );
|
||||
|
||||
dev->mode = _PP_MODE_SPP;
|
||||
|
@ -412,7 +417,7 @@ static SANE_Bool u12io_OpenScanPath( U12_Device *dev )
|
|||
{
|
||||
u_char tmp;
|
||||
|
||||
DBG( _DBG_IO, "u12io_OpenScanPath()\n" );
|
||||
DBG( _DBG_INFO, "u12io_OpenScanPath()\n" );
|
||||
|
||||
u12io_SwitchToSPPMode( dev );
|
||||
|
||||
|
@ -437,7 +442,7 @@ static SANE_Bool u12io_OpenScanPath( U12_Device *dev )
|
|||
return SANE_TRUE;
|
||||
}
|
||||
|
||||
DBG( _DBG_IO, "u12io_OpenScanPath() failed!\n" );
|
||||
DBG( _DBG_ERROR, "u12io_OpenScanPath() failed!\n" );
|
||||
return SANE_FALSE;
|
||||
}
|
||||
|
||||
|
@ -576,9 +581,8 @@ static void u12io_SoftwareReset( U12_Device *dev )
|
|||
*/
|
||||
static SANE_Bool u12io_IsConnected( U12_Device *dev )
|
||||
{
|
||||
int mode;
|
||||
SANE_Byte tmp;
|
||||
SANE_Byte buf[6];
|
||||
int c, mode;
|
||||
SANE_Byte tmp, rb[6];
|
||||
|
||||
DBG( _DBG_INFO, "u12io_IsConnected()\n" );
|
||||
tmp = inb_status( dev->fd );
|
||||
|
@ -591,33 +595,29 @@ static SANE_Bool u12io_IsConnected( U12_Device *dev )
|
|||
if( tmp != ASIC_ID ) {
|
||||
|
||||
DBG( _DBG_INFO, "* Scanner is NOT connected!\n" );
|
||||
/* FIXME: really needed? */
|
||||
#if 1
|
||||
if( dev->initialized ) {
|
||||
|
||||
tmp = inb_status( dev->fd );
|
||||
DBG( _DBG_INFO, "* tmp3 = 0x%02x\n", tmp );
|
||||
tmp = inb_status( dev->fd );
|
||||
DBG( _DBG_INFO, "* tmp2 = 0x%02x\n", tmp );
|
||||
|
||||
gl640WriteReq( dev->fd, GL640_EPP_ADDR, REG_ASICID );
|
||||
gl640ReadReq ( dev->fd, GL640_EPP_DATA_READ, &tmp );
|
||||
DBG( _DBG_INFO, "* REG_ASICID = 0x%02x\n", tmp );
|
||||
gl640WriteReq( dev->fd, GL640_EPP_ADDR, REG_ASICID );
|
||||
gl640ReadReq ( dev->fd, GL640_EPP_DATA_READ, &tmp );
|
||||
DBG( _DBG_INFO, "* REG_ASICID = 0x%02x\n", tmp );
|
||||
|
||||
if( tmp == 0x02 ) {
|
||||
|
||||
mode = dev->mode;
|
||||
dev->mode = _PP_MODE_EPP;
|
||||
u12io_DataToRegister( dev, REG_ADCADDR, 1 );
|
||||
u12io_DataToRegister( dev, REG_ADCDATA, 0 );
|
||||
u12io_DataToRegister( dev, REG_ADCSERIALOUT, 0 );
|
||||
u12io_DataToRegister( dev, REG_ADCADDR, 0x01 );
|
||||
u12io_DataToRegister( dev, REG_ADCDATA, 0x00 );
|
||||
u12io_DataToRegister( dev, REG_ADCSERIALOUT, 0x00 );
|
||||
|
||||
buf[0] = REG_MODECONTROL;
|
||||
buf[1] = 0x19;
|
||||
buf[2] = REG_STEPCONTROL;
|
||||
buf[3] = 0xff;
|
||||
buf[4] = REG_MOTOR0CONTROL;
|
||||
buf[5] = 0;
|
||||
u12io_DataToRegs( dev, buf, 3 );
|
||||
dev->mode = mode;
|
||||
c = 0;
|
||||
_SET_REG( rb, c, REG_MODECONTROL, 0x19 );
|
||||
_SET_REG( rb, c, REG_STEPCONTROL, 0xff );
|
||||
_SET_REG( rb, c, REG_MOTOR0CONTROL, 0 );
|
||||
u12io_DataToRegs( dev, rb, c );
|
||||
dev->mode = mode ;
|
||||
}
|
||||
#endif
|
||||
return SANE_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
#include "../include/sane/sanei.h"
|
||||
#include "../include/sane/saneopts.h"
|
||||
|
||||
#define BACKEND_VERSION "0.02-3"
|
||||
#define BACKEND_VERSION "0.02-4"
|
||||
#define BACKEND_NAME u12
|
||||
#include "../include/sane/sanei_backend.h"
|
||||
#include "../include/sane/sanei_config.h"
|
||||
|
@ -419,15 +419,9 @@ static SANE_Status do_cancel( U12_Scanner *scanner, SANE_Bool closepipe )
|
|||
scanner->reader_pid = 0;
|
||||
DBG( _DBG_PROC, "reader_process killed\n");
|
||||
|
||||
#if 1
|
||||
if( scanner->hw->fd >= 0 ) {
|
||||
u12io_SoftwareReset( scanner->hw );
|
||||
#if 0
|
||||
u12io_CloseScanPath( scanner->hw );
|
||||
_DODELAY(250);
|
||||
#endif
|
||||
u12hw_CancelSequence( scanner->hw );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if( SANE_TRUE == closepipe ) {
|
||||
|
|
Ładowanie…
Reference in New Issue