diff --git a/backend/mustek_usb2.c b/backend/mustek_usb2.c index e9d9229fa..4c45530d2 100644 --- a/backend/mustek_usb2.c +++ b/backend/mustek_usb2.c @@ -102,7 +102,7 @@ static const Scanner_Model models[] = { 0x055f, 0x0409, /* USB vendor and product ID */ - ¶msMustekBP2448TAPro, + ¶msMustekBP2448TAPro, /* model specific parameters for ASIC layer */ {5 /* count */, 1200, 600, 300, 150, 75}, /* possible resolutions */ @@ -136,7 +136,7 @@ static const Scanner_Model models[] = { 0x05da, 0x3025, /* USB vendor and product ID */ - ¶msMicrotek4800H48U, + ¶msMicrotek4800H48U, /* model specific parameters for ASIC layer */ {5 /* count */, 1200, 600, 300, 150, 75}, /* possible resolutions */ diff --git a/backend/mustek_usb2_asic.c b/backend/mustek_usb2_asic.c index 23f7dfa69..d49215f8f 100644 --- a/backend/mustek_usb2_asic.c +++ b/backend/mustek_usb2_asic.c @@ -63,19 +63,26 @@ #include "mustek_usb2_asic.h" -const ASIC_ModelParams paramsMustekBP2448TAPro = { - SDRAMCLK_DELAY_12_ns -}; - -const ASIC_ModelParams paramsMicrotek4800H48U = { - SDRAMCLK_DELAY_8_ns -}; - - static SANE_Status PrepareScanChip (ASIC * chip); static SANE_Status WaitCarriageHome (ASIC * chip); static SANE_Status WaitUnitReady (ASIC * chip); +static SANE_Status Mustek_SetMotorCurrentAndPhase ( + ASIC * chip, MOTOR_CURRENT_AND_PHASE * MotorCurrentAndPhase); +static SANE_Status Microtek_SetMotorCurrentAndPhase ( + ASIC * chip, MOTOR_CURRENT_AND_PHASE * MotorCurrentAndPhase); + + +const ASIC_ModelParams paramsMustekBP2448TAPro = { + SDRAMCLK_DELAY_12_ns, + Mustek_SetMotorCurrentAndPhase +}; + +const ASIC_ModelParams paramsMicrotek4800H48U = { + SDRAMCLK_DELAY_8_ns, + Microtek_SetMotorCurrentAndPhase +}; + /* ---------------------- low level ASIC functions -------------------------- */ @@ -434,15 +441,16 @@ RamAccess (ASIC * chip, RAMACCESS * access) return status; } -static void -SetMotorCurrentAndPhase (ASIC * chip, - MOTOR_CURRENT_AND_PHASE * MotorCurrentAndPhase) -{ - static const SANE_Byte MotorPhaseFullStep[] = - { 0x08, 0x09, 0x01, 0x00 }; - static const SANE_Byte MotorPhaseHalfStep[] = - { 0x25, 0x07, 0x24, 0x30, 0x2c, 0x0e, 0x2d, 0x39 }; +static const SANE_Byte MotorPhaseFullStep[] = + { 0x08, 0x09, 0x01, 0x00 }; +static const SANE_Byte MotorPhaseHalfStep[] = + { 0x25, 0x07, 0x24, 0x30, 0x2c, 0x0e, 0x2d, 0x39 }; + +static SANE_Status +Mustek_SetMotorCurrentAndPhase (ASIC * chip, + MOTOR_CURRENT_AND_PHASE * MotorCurrentAndPhase) +{ SANE_Byte MotorPhaseMask; int i; DBG_ASIC_ENTER (); @@ -489,11 +497,21 @@ SetMotorCurrentAndPhase (ASIC * chip, for (i = 0; i < 16; i++) { - double x = (((i % 4) * M_PI * 90) / 4) / 180; - SendData2Byte (chip, ES02_52_MOTOR_CURRENT_TABLE_A, (SANE_Byte) - (MotorCurrentAndPhase->MotorCurrent * sin (x))); - SendData2Byte (chip, ES02_53_MOTOR_CURRENT_TABLE_B, (SANE_Byte) - (MotorCurrentAndPhase->MotorCurrent * cos (x))); + double x = ((i % 4) * M_PI_2) / 4; + if (i & 4) + { + SendData2Byte (chip, ES02_52_MOTOR_CURRENT_TABLE_A, (SANE_Byte) + (MotorCurrentAndPhase->MotorCurrent * cos (x))); + SendData2Byte (chip, ES02_53_MOTOR_CURRENT_TABLE_B, (SANE_Byte) + (MotorCurrentAndPhase->MotorCurrent * sin (x))); + } + else + { + SendData2Byte (chip, ES02_52_MOTOR_CURRENT_TABLE_A, (SANE_Byte) + (MotorCurrentAndPhase->MotorCurrent * sin (x))); + SendData2Byte (chip, ES02_53_MOTOR_CURRENT_TABLE_B, (SANE_Byte) + (MotorCurrentAndPhase->MotorCurrent * cos (x))); + } SendData2Byte (chip, ES02_51_MOTOR_PHASE_TABLE_1, MotorPhaseFullStep[i / 4] & MotorPhaseMask); } @@ -504,13 +522,14 @@ SetMotorCurrentAndPhase (ASIC * chip, for (i = 0; i < 32; i++) { - double x = (((i % 8) * M_PI * 90) / 8) / 180; + double x = ((i % 8) * M_PI_2) / 8; SendData2Byte (chip, ES02_52_MOTOR_CURRENT_TABLE_A, (SANE_Byte) (MotorCurrentAndPhase->MotorCurrent * sin (x))); SendData2Byte (chip, ES02_53_MOTOR_CURRENT_TABLE_B, (SANE_Byte) (MotorCurrentAndPhase->MotorCurrent * cos (x))); SendData2Byte (chip, ES02_51_MOTOR_PHASE_TABLE_1, - MotorPhaseFullStep[i / 8] & MotorPhaseMask); + MotorPhaseFullStep[(3 + (i / 8)) % 4] & + MotorPhaseMask); } } @@ -518,6 +537,46 @@ SetMotorCurrentAndPhase (ASIC * chip, MotorCurrentAndPhase->MoveType); DBG_ASIC_LEAVE (); + return SANE_STATUS_GOOD; +} + +static SANE_Status +Microtek_SetMotorCurrentAndPhase (ASIC * chip, + MOTOR_CURRENT_AND_PHASE * MotorCurrentAndPhase) +{ + int i; + DBG_ASIC_ENTER (); + + SendData (chip, ES02_50_MOTOR_CURRENT_CONTORL, DOWN_LOAD_MOTOR_TABLE_ENABLE); + + if (MotorCurrentAndPhase->MoveType == _8_TABLE_SPACE_FOR_1_DIV_2_STEP) + { + SendData (chip, ES01_AB_PWM_CURRENT_CONTROL, MOTOR_PWM_CURRENT_1); + + for (i = 0; i < 8; i++) + { + double x = ((i % 4) * M_PI) / 4; + double y = (((i + 2) % 4) * M_PI) / 4; + SendData2Byte (chip, ES02_52_MOTOR_CURRENT_TABLE_A, (SANE_Byte) + (MotorCurrentAndPhase->MotorCurrent * sin (x))); + SendData2Byte (chip, ES02_53_MOTOR_CURRENT_TABLE_B, (SANE_Byte) + (MotorCurrentAndPhase->MotorCurrent * sin (y))); + SendData2Byte (chip, ES02_51_MOTOR_PHASE_TABLE_1, + MotorPhaseFullStep[i / 2]); + } + } + else + { + DBG (DBG_ERR, "invalid motor move type %d\n", + MotorCurrentAndPhase->MoveType); + return SANE_STATUS_INVAL; + } + + SendData (chip, ES02_50_MOTOR_CURRENT_CONTORL, + MotorCurrentAndPhase->MoveType); + + DBG_ASIC_LEAVE (); + return SANE_STATUS_GOOD; } static SANE_Status @@ -988,7 +1047,9 @@ SimpleMotorMove (ASIC * chip, CurrentPhase.MoveType = _4_TABLE_SPACE_FOR_FULL_STEP; CurrentPhase.MotorDriverIs3967 = 0; CurrentPhase.MotorCurrent = bMotorCurrent; - SetMotorCurrentAndPhase (chip, &CurrentPhase); + status = chip->params->pSetMotorCurrentAndPhase (chip, &CurrentPhase); + if (status != SANE_STATUS_GOOD) + return status; status = SetMotorTable (chip, 0x3000, MotorTable); free (MotorTable); @@ -2298,7 +2359,9 @@ Asic_SetWindow (ASIC * chip, SCANSOURCE lsLightSource, CalculateMoveMotorTable (&CalMotorTable); CurrentPhase.MotorCurrent = 200; } - SetMotorCurrentAndPhase (chip, &CurrentPhase); + status = chip->params->pSetMotorCurrentAndPhase (chip, &CurrentPhase); + if (status != SANE_STATUS_GOOD) + return status; DBG (DBG_ASIC, "MotorCurrent=%d,LinePixelReport=%d\n", CurrentPhase.MotorCurrent, dwLinePixelReport); diff --git a/backend/mustek_usb2_asic.h b/backend/mustek_usb2_asic.h index 998645e7b..cd2938dec 100644 --- a/backend/mustek_usb2_asic.h +++ b/backend/mustek_usb2_asic.h @@ -148,9 +148,13 @@ typedef struct SANE_Byte bScanDecSteps; } MOTORMOVE; +struct ASIC; + typedef struct { SANE_Byte SDRAM_Delay; + SANE_Status (* pSetMotorCurrentAndPhase) (struct ASIC *, + MOTOR_CURRENT_AND_PHASE *); } ASIC_ModelParams; typedef struct @@ -194,7 +198,7 @@ typedef struct SANE_Bool Direction[3]; } ADConverter; -typedef struct +typedef struct ASIC { SANE_String_Const device_name; int fd; /* file descriptor of scanner */ diff --git a/backend/mustek_usb2_high.c b/backend/mustek_usb2_high.c index b6092dd5b..cfe0c3348 100644 --- a/backend/mustek_usb2_high.c +++ b/backend/mustek_usb2_high.c @@ -859,7 +859,7 @@ ReadDataFromScanner (void * param) static SANE_Status GetLine (Scanner_State * st, SANE_Byte * pLine, unsigned short * wLinesCount, - void (* pFunc)(Scanner_State *, SANE_Byte *, SANE_Bool), + void (* pFunc) (Scanner_State *, SANE_Byte *, SANE_Bool), SANE_Bool isOrderInvert, SANE_Bool fixEvenOdd) { unsigned short wWantedTotalLines; @@ -953,7 +953,7 @@ Scanner_GetRows (Scanner_State * st, SANE_Byte * pBlock, { SANE_Status status; SANE_Bool fixEvenOdd = SANE_FALSE; - void (* pFunc)(Scanner_State *, SANE_Byte *, SANE_Bool) = NULL; + void (* pFunc) (Scanner_State *, SANE_Byte *, SANE_Bool) = NULL; DBG_ENTER (); if (!st->bOpened || !st->bPrepared)