Lines Matching defs:dev

80 static SANE_Int hp4370_prueba (struct st_device *dev);
82 void shadingtest1 (struct st_device *dev, SANE_Byte * Regs,
84 static SANE_Int Calib_test (struct st_device *dev, SANE_Byte * Regs,
87 static SANE_Int Calib_BlackShading_jkd (struct st_device *dev,
93 /*static void show_diff(struct st_device *dev, SANE_Byte *original);*/
97 static void RTS_Free (struct st_device *dev);
100 static SANE_Int RTS_Scanner_Init (struct st_device *dev);
101 static SANE_Int RTS_Scanner_SetParams (struct st_device *dev,
103 static SANE_Int RTS_Scanner_StartScan (struct st_device *dev);
104 static void RTS_Scanner_StopScan (struct st_device *dev, SANE_Int wait);
105 static void RTS_Scanner_End (struct st_device *dev);
108 static SANE_Int Load_Buttons (struct st_device *dev);
109 static SANE_Int Load_Chipset (struct st_device *dev);
110 static SANE_Int Load_Config (struct st_device *dev);
111 static SANE_Int Load_Constrains (struct st_device *dev);
112 static SANE_Int Load_Motor (struct st_device *dev);
113 static SANE_Int Load_MotorCurves (struct st_device *dev);
114 static SANE_Int Load_Motormoves (struct st_device *dev);
115 static SANE_Int Load_Scanmodes (struct st_device *dev);
116 static SANE_Int Load_Sensor (struct st_device *dev);
117 static SANE_Int Load_Timings (struct st_device *dev);
120 static void Free_Buttons (struct st_device *dev);
121 static void Free_Chipset (struct st_device *dev);
122 static void Free_Config (struct st_device *dev);
123 static void Free_Constrains (struct st_device *dev);
124 static void Free_Motor (struct st_device *dev);
125 static void Free_MotorCurves (struct st_device *dev);
126 static void Free_Motormoves (struct st_device *dev);
127 static void Free_Scanmodes (struct st_device *dev);
128 static void Free_Sensor (struct st_device *dev);
129 static void Free_Timings (struct st_device *dev);
145 static SANE_Int Chipset_ID (struct st_device *dev);
146 static SANE_Int Chipset_Name (struct st_device *dev, char *name,
148 static SANE_Int Chipset_Reset (struct st_device *dev);
151 static SANE_Int Init_Registers (struct st_device *dev);
152 static SANE_Int Init_USBData (struct st_device *dev);
156 static SANE_Int Scanmode_fitres (struct st_device *dev, SANE_Int scantype,
158 static SANE_Int Scanmode_maxres (struct st_device *dev, SANE_Int scantype,
160 static SANE_Int Scanmode_minres (struct st_device *dev, SANE_Int scantype,
164 static SANE_Int RTS_USBType (struct st_device *dev);
167 static SANE_Int RTS_Enable_CCD (struct st_device *dev, SANE_Byte * Regs,
171 static SANE_Int RTS_DMA_Cancel (struct st_device *dev);
172 static SANE_Int RTS_DMA_CheckType (struct st_device *dev, SANE_Byte * Regs);
173 static SANE_Int RTS_DMA_Enable_Read (struct st_device *dev, SANE_Int dmacs,
175 static SANE_Int RTS_DMA_Enable_Write (struct st_device *dev, SANE_Int dmacs,
177 static SANE_Int RTS_DMA_Read (struct st_device *dev, SANE_Int dmacs,
180 static SANE_Int RTS_DMA_Reset (struct st_device *dev);
181 static SANE_Int RTS_DMA_SetType (struct st_device *dev, SANE_Byte * Regs,
183 static SANE_Int RTS_DMA_WaitReady (struct st_device *dev, SANE_Int msecs);
184 static SANE_Int RTS_DMA_Write (struct st_device *dev, SANE_Int dmacs,
205 static SANE_Int RTS_Execute (struct st_device *dev);
206 static SANE_Int RTS_Warm_Reset (struct st_device *dev);
207 static SANE_Byte RTS_IsExecuting (struct st_device *dev, SANE_Byte * Regs);
209 static SANE_Int RTS_GetScanmode (struct st_device *dev, SANE_Int scantype,
211 static SANE_Int RTS_GetImage (struct st_device *dev, SANE_Byte * Regs,
217 static SANE_Int RTS_GetImage_GetBuffer (struct st_device *dev, double dSize,
220 static SANE_Int RTS_GetImage_Read (struct st_device *dev, SANE_Byte * buffer,
224 static SANE_Int RTS_isTmaAttached (struct st_device *dev);
227 static SANE_Int RTS_WaitInitEnd (struct st_device *dev, SANE_Int msecs);
228 static SANE_Int RTS_WaitScanEnd (struct st_device *dev, SANE_Int msecs);
235 static SANE_Int RTS_ScanCounter_Inc (struct st_device *dev);
236 static SANE_Int RTS_ScanCounter_Get (struct st_device *dev);
239 static SANE_Int RTS_Setup (struct st_device *dev, SANE_Byte * Regs,
243 static void RTS_Setup_Arrangeline (struct st_device *dev,
246 static void RTS_Setup_Channels (struct st_device *dev, SANE_Byte * Regs,
260 static SANE_Int RTS_Setup_Line_Distances (struct st_device *dev,
266 static SANE_Int RTS_Setup_Motor (struct st_device *dev, SANE_Byte * Regs,
269 static void RTS_Setup_RefVoltages (struct st_device *dev, SANE_Byte * Regs);
270 static void RTS_Setup_SensorTiming (struct st_device *dev, SANE_Int mytiming,
277 static SANE_Int Scan_Start (struct st_device *dev);
281 static SANE_Int fn3330 (struct st_device *dev, SANE_Byte * Regs,
287 static SANE_Int fn3730 (struct st_device *dev, struct st_cal2 *calbuffers,
291 static SANE_Int Reading_CreateBuffers (struct st_device *dev);
292 static SANE_Int Reading_DestroyBuffers (struct st_device *dev);
293 static SANE_Int Reading_BufferSize_Get (struct st_device *dev,
296 static SANE_Int Reading_BufferSize_Notify (struct st_device *dev,
298 static SANE_Int Reading_Wait (struct st_device *dev,
304 static SANE_Int Read_Image (struct st_device *dev, SANE_Int buffer_size,
306 static SANE_Int Read_ResizeBlock (struct st_device *dev, SANE_Byte * buffer,
309 static SANE_Int Read_Block (struct st_device *dev, SANE_Int buffer_size,
311 static SANE_Int Read_NonColor_Block (struct st_device *dev,
321 static SANE_Int Refs_Counter_Inc (struct st_device *dev);
322 static SANE_Byte Refs_Counter_Load (struct st_device *dev);
323 static SANE_Int Refs_Counter_Save (struct st_device *dev, SANE_Byte data);
324 static SANE_Int Refs_Detect (struct st_device *dev, SANE_Byte * Regs,
327 static SANE_Int Refs_Load (struct st_device *dev, SANE_Int * x, SANE_Int * y);
328 static SANE_Int Refs_Save (struct st_device *dev, SANE_Int left_leading,
330 static SANE_Int Refs_Set (struct st_device *dev, SANE_Byte * Regs,
334 static SANE_Int Constrains_Check (struct st_device *dev, SANE_Int Resolution,
337 static struct st_coords *Constrains_Get (struct st_device *dev,
341 static SANE_Int GainOffset_Clear (struct st_device *dev);
342 static SANE_Int GainOffset_Get (struct st_device *dev);
343 static SANE_Int GainOffset_Save (struct st_device *dev, SANE_Int * offset,
345 static SANE_Int GainOffset_Counter_Inc (struct st_device *dev,
347 static SANE_Byte GainOffset_Counter_Load (struct st_device *dev);
348 static SANE_Int GainOffset_Counter_Save (struct st_device *dev,
353 static SANE_Int Gamma_Apply (struct st_device *dev, SANE_Byte * Regs,
358 static SANE_Int Gamma_SendTables (struct st_device *dev, SANE_Byte * Regs,
360 static SANE_Int Gamma_GetTables (struct st_device *dev,
364 static SANE_Byte Lamp_GetGainMode (struct st_device *dev, SANE_Int resolution,
366 static void Lamp_SetGainMode (struct st_device *dev, SANE_Byte * Regs,
368 static SANE_Int Lamp_PWM_DutyCycle_Get (struct st_device *dev,
370 static SANE_Int Lamp_PWM_DutyCycle_Set (struct st_device *dev,
372 static SANE_Int Lamp_PWM_Setup (struct st_device *dev, SANE_Int lamp);
373 static SANE_Int Lamp_PWM_use (struct st_device *dev, SANE_Int enable);
374 static SANE_Int Lamp_PWM_CheckStable (struct st_device *dev,
376 static SANE_Int Lamp_PWM_Save (struct st_device *dev, SANE_Int fixedpwm);
377 static SANE_Int Lamp_PWM_SaveStatus (struct st_device *dev, SANE_Byte status);
378 static SANE_Int Lamp_Status_Get (struct st_device *dev, SANE_Byte * flb_lamp,
380 static SANE_Int Lamp_Status_Set (struct st_device *dev, SANE_Byte * Regs,
382 static SANE_Int Lamp_Status_Timer_Set (struct st_device *dev,
384 static SANE_Int Lamp_Warmup (struct st_device *dev, SANE_Byte * Regs,
388 static SANE_Int Head_IsAtHome (struct st_device *dev, SANE_Byte * Regs);
389 static SANE_Int Head_ParkHome (struct st_device *dev, SANE_Int bWait,
391 static SANE_Int Head_Relocate (struct st_device *dev, SANE_Int speed,
397 static SANE_Int Motor_Change (struct st_device *dev, SANE_Byte * buffer,
400 static SANE_Int Motor_Move (struct st_device *dev, SANE_Byte * Regs,
403 static void Motor_Release (struct st_device *dev);
404 static SANE_Int Motor_Setup_Steps (struct st_device *dev, SANE_Byte * Regs,
406 static SANE_Int Motor_Curve_Equal (struct st_device *dev,
411 static struct st_curve *Motor_Curve_Get (struct st_device *dev,
418 static SANE_Int Arrange_Colour (struct st_device *dev, SANE_Byte * buffer,
420 static SANE_Int Arrange_Compose (struct st_device *dev, SANE_Byte * buffer,
423 static SANE_Int Arrange_NonColour (struct st_device *dev, SANE_Byte * buffer,
432 static void Triplet_Compose_Order (struct st_device *dev, SANE_Byte * pRed,
445 static void Triplet_Colour_Order (struct st_device *dev, SANE_Byte * pRed,
461 static SANE_Int Resize_Start (struct st_device *dev, SANE_Int * transferred);
462 static SANE_Int Resize_CreateBuffers (struct st_device *dev, SANE_Int size1,
464 static SANE_Int Resize_DestroyBuffers (struct st_device *dev);
477 static SANE_Int Buttons_Count (struct st_device *dev);
478 static SANE_Int Buttons_Enable (struct st_device *dev);
479 static SANE_Int Buttons_Order (struct st_device *dev, SANE_Int mask);
480 static SANE_Int Buttons_Status (struct st_device *dev);
481 static SANE_Int Buttons_Released (struct st_device *dev);
484 static SANE_Int Calib_CreateBuffers (struct st_device *dev,
489 static void Calib_LoadCut (struct st_device *dev,
492 static SANE_Int Calib_AdcGain (struct st_device *dev,
495 static SANE_Int Calib_AdcOffsetRT (struct st_device *dev,
498 static SANE_Int Calib_BlackShading (struct st_device *dev,
505 static SANE_Int Calib_WhiteShading_3 (struct st_device *dev,
514 static SANE_Int Calib_ReadTable (struct st_device *dev, SANE_Byte * table,
516 static SANE_Int Calib_WriteTable (struct st_device *dev, SANE_Byte * table,
518 static SANE_Int Calib_LoadConfig (struct st_device *dev,
522 static SANE_Int Calib_PAGain (struct st_device *dev,
525 static SANE_Int Calibration (struct st_device *dev, SANE_Byte * Regs,
530 static SANE_Int WShading_Calibrate (struct st_device *dev, SANE_Byte * Regs,
537 static SANE_Int Shading_apply (struct st_device *dev, SANE_Byte * Regs,
540 static SANE_Int Shading_black_apply (struct st_device *dev, SANE_Byte * Regs,
544 static SANE_Int Shading_white_apply (struct st_device *dev, SANE_Byte * Regs,
550 static SANE_Int SSCG_Enable (struct st_device *dev);
554 static SANE_Int Scan_Read_BufferA (struct st_device *dev,
559 static SANE_Int Bulk_Operation (struct st_device *dev, SANE_Byte op,
563 static SANE_Int GetOneLineInfo (struct st_device *dev, SANE_Int resolution,
571 static SANE_Int SetMultiExposure (struct st_device *dev, SANE_Byte * Regs);
573 static void Set_E950_Mode (struct st_device *dev, SANE_Byte mode);
575 static SANE_Int LoadImagingParams (struct st_device *dev, SANE_Int inifile);
577 static SANE_Int SetScanParams (struct st_device *dev, SANE_Byte * Regs,
580 static SANE_Int IsScannerLinked (struct st_device *dev);
582 static SANE_Int Read_FE3E (struct st_device *dev, SANE_Byte * destino);
591 RTS_Free (struct st_device *dev)
595 if (dev != NULL)
599 Free_Config (dev);
601 if (dev->init_regs != NULL)
602 free (dev->init_regs);
604 if (dev->Resize != NULL)
605 free (dev->Resize);
607 if (dev->Reading != NULL)
608 free (dev->Reading);
610 if (dev->scanning != NULL)
611 free (dev->scanning);
613 if (dev->status != NULL)
614 free (dev->status);
616 free (dev);
625 struct st_device *dev = NULL;
627 dev = malloc (sizeof (struct st_device));
628 if (dev != NULL)
632 memset (dev, 0, sizeof (struct st_device));
635 dev->init_regs = malloc (sizeof (SANE_Byte) * RT_BUFFER_LEN);
636 if (dev->init_regs != NULL)
637 memset (dev->init_regs, 0, sizeof (SANE_Byte) * RT_BUFFER_LEN);
643 dev->scanning = malloc (sizeof (struct st_scanning));
644 if (dev->scanning != NULL)
645 memset (dev->scanning, 0, sizeof (struct st_scanning));
652 dev->Reading = malloc (sizeof (struct st_readimage));
653 if (dev->Reading != NULL)
654 memset (dev->Reading, 0, sizeof (struct st_readimage));
661 dev->Resize = malloc (sizeof (struct st_resize));
662 if (dev->Resize != NULL)
663 memset (dev->Resize, 0, sizeof (struct st_resize));
670 dev->status = malloc (sizeof (struct st_status));
671 if (dev->status != NULL)
672 memset (dev->status, 0, sizeof (struct st_status));
680 RTS_Free (dev);
681 dev = NULL;
685 return dev;
689 RTS_Scanner_End (struct st_device *dev)
692 Free_Config (dev);
703 RTS_Scanner_Init (struct st_device *dev)
714 RTS_Debug->usbtype = RTS_USBType (dev);
718 DBG (DBG_FNC, " -> Chipset model ID: %i\n", Chipset_ID (dev));
720 Chipset_Reset (dev);
722 if (Load_Config (dev) == OK)
724 if (IsScannerLinked (dev) == OK)
726 Set_E950_Mode (dev, 0);
731 Free_Config (dev);
793 Set_E950_Mode (struct st_device *dev, SANE_Byte mode)
799 if (Read_Word (dev->usb_handle, 0xe950, &data) == OK)
802 Write_Word (dev->usb_handle, 0xe950, data);
809 Motor_Curve_Get (struct st_device *dev, SANE_Int motorcurve,
814 if (dev != NULL)
816 if ((dev->mtrsetting != NULL) && (motorcurve < dev->mtrsetting_count))
818 struct st_motorcurve *mtc = dev->mtrsetting[motorcurve];
853 Motor_Curve_Equal (struct st_device *dev, SANE_Int motorsetting,
861 Motor_Curve_Get (dev, motorsetting, direction, curve1);
863 Motor_Curve_Get (dev, motorsetting, direction, curve2);
1110 Free_Scanmodes (struct st_device *dev)
1114 if (dev->scanmodes != NULL)
1116 if (dev->scanmodes_count > 0)
1119 for (a = 0; a < dev->scanmodes_count; a++)
1120 if (dev->scanmodes[a] != NULL)
1121 free (dev->scanmodes[a]);
1124 free (dev->scanmodes);
1125 dev->scanmodes = NULL;
1128 dev->scanmodes_count = 0;
1132 Load_Scanmodes (struct st_device *dev)
1140 if ((dev->scanmodes != NULL) || (dev->scanmodes_count > 0))
1141 Free_Scanmodes (dev);
1144 while ((cfg_scanmode_get (dev->sensorcfg->type, a, &reg) == OK)
1164 dev->scanmodes =
1165 (struct st_scanmode **) realloc (dev->scanmodes,
1166 (dev->scanmodes_count +
1169 if (dev->scanmodes != NULL)
1171 dev->scanmodes[dev->scanmodes_count] = mode;
1172 dev->scanmodes_count++;
1184 Free_Scanmodes (dev);
1186 DBG (DBG_FNC, " -> Found %i scanmodes\n", dev->scanmodes_count);
1187 dbg_scanmodes (dev);
1193 Free_Config (struct st_device *dev)
1198 Free_Buttons (dev);
1201 Free_Motor (dev);
1204 Free_Sensor (dev);
1207 Free_Timings (dev);
1210 Free_MotorCurves (dev);
1213 Free_Motormoves (dev);
1216 Free_Scanmodes (dev);
1219 Free_Constrains (dev);
1222 Free_Chipset (dev);
1228 Free_Chipset (struct st_device *dev)
1232 if (dev->chipset != NULL)
1234 if (dev->chipset->name != NULL)
1235 free (dev->chipset->name);
1237 free (dev->chipset);
1238 dev->chipset = NULL;
1243 Load_Chipset (struct st_device *dev)
1249 if (dev->chipset != NULL)
1250 Free_Chipset (dev);
1252 dev->chipset = malloc (sizeof (struct st_chip));
1253 if (dev->chipset != NULL)
1257 memset (dev->chipset, 0, sizeof (struct st_chip));
1263 rst = cfg_chipset_get (model, dev->chipset);
1272 Load_Config (struct st_device *dev)
1277 Load_Chipset (dev);
1280 Load_Buttons (dev);
1283 Load_Constrains (dev);
1286 Load_Motor (dev);
1289 Load_Sensor (dev);
1291 if (dev->sensorcfg->type == -1)
1293 dev->sensorcfg->type = RTS_Sensor_Type (dev->usb_handle);
1296 Load_Timings (dev);
1299 Load_MotorCurves (dev);
1302 Load_Motormoves (dev);
1305 Load_Scanmodes (dev);
1308 if (dev->sensorcfg->type == CCD_SENSOR)
1325 LoadImagingParams (dev, usbfile);
1333 LoadImagingParams (struct st_device *dev, SANE_Int inifile)
1343 cfg_gainoffset_get (dev->sensorcfg->type, default_gain_offset);
1356 Arrange_Colour (struct st_device *dev, SANE_Byte * buffer,
1375 scn = dev->scanning;
1379 if (dev->sensorcfg->type == CCD_SENSOR)
1381 (dev->sensorcfg->line_distance * scan2.resolution_y) /
1382 dev->sensorcfg->resolution;
1409 if (Read_Block (dev, scn->bfsize, scn->imagebuffer, transferred) != OK)
1423 if ((((dev->sensorcfg->line_distance * scan2.resolution_y) *
1424 2) / dev->sensorcfg->resolution) == 1)
1429 ((dev->sensorcfg->rgb_order[c] / 2) * line_size) +
1439 (dev->sensorcfg->rgb_order[c] * (mydistance * line_size)) +
1485 Triplet_Colour_Order (dev, scn->pColour[CL_RED],
1502 if (Read_Block (dev, line_size, scn->imagepointer, transferred) ==
1536 RTS_Scanner_SetParams (struct st_device *dev, struct params *param)
1596 data_bitset (&dev->init_regs[0x146], 0x40,
1597 ((dev->sensorcfg->type == CIS_SENSOR) ? 0 : 1));
1601 Lamp_Status_Set (dev, NULL, TRUE, FLB_LAMP);
1603 Lamp_Status_Set (dev, NULL, TRUE, TMA_LAMP);
1606 if (RTS_IsExecuting (dev, mybuffer) == FALSE)
1607 RTS_WriteRegs (dev->usb_handle, dev->init_regs);
1620 hwdcfg.sensorevenodddistance = dev->sensorcfg->evenodd_distance;
1622 SetScanParams (dev, dev->init_regs, &scan, &hwdcfg);
1636 SetScanParams (struct st_device *dev, SANE_Byte * Regs,
1674 dev->Resize->resolution_x = scancfg->resolution_x;
1675 dev->Resize->resolution_y = scancfg->resolution_y;
1677 mymode = RTS_GetScanmode (dev, hwdcfg->scantype, myvalue, scancfg->resolution_x); /*0x0b */
1684 Scanmode_fitres (dev, hwdcfg->scantype, scancfg->colormode,
1689 dev->Resize->type = RSZ_DECREASE;
1693 dev->Resize->type = RSZ_INCREASE;
1695 Scanmode_maxres (dev, hwdcfg->scantype, scancfg->colormode);
1702 RTS_GetScanmode (dev, hwdcfg->scantype, myvalue, scan2.resolution_x);
1707 dev->Resize->towidth = scancfg->coord.width;
1712 dev->Resize->resolution_x;
1715 dev->Resize->resolution_x;
1717 (scan2.resolution_y * scancfg->coord.top) / dev->Resize->resolution_y;
1720 dev->Resize->resolution_y) + 2;
1725 if ((dev->scanmodes[mymode]->samplerate == PIXEL_RATE)
1727 dev->Resize->towidth *= 2;
1730 dev->Resize->mode = (scan2.depth == 8) ? RSZ_GRAYL : RSZ_GRAYH;
1731 dev->Resize->bytesperline = dev->Resize->towidth * channel_size;
1734 if (dev->scanmodes[mymode]->samplerate == PIXEL_RATE)
1735 dev->Resize->towidth *= 2;
1737 dev->Resize->mode = RSZ_LINEART;
1738 dev->Resize->bytesperline = (dev->Resize->towidth + 7) / 8;
1743 dev->Resize->mode = (scan2.depth == 8) ? RSZ_COLOURL : RSZ_COLOURH;
1744 dev->Resize->bytesperline =
1752 dev->Resize->type = RSZ_NONE;
1761 scancfg->timing = dev->scanmodes[mymode]->timing;
1763 scan2.sensorresolution = dev->timings[scancfg->timing]->sensorresolution;
1771 dev->scanning->arrange_compression = ((mycolormode != CM_LINEART)
1783 dev->scanning->arrange_hres = FALSE;
1784 dev->scanning->arrange_sensor_evenodd_dist = 0;
1789 dev->scanning->arrange_hres = TRUE;
1790 dev->scanning->arrange_sensor_evenodd_dist =
1825 (dev->scanmodes[mymode]->samplerate ==
1830 dev->Resize->fromwidth = line_size * 8;
1844 channel_count = (dev->scanmodes[mymode]->samplerate == PIXEL_RATE) ? 2 : 1; /*1 */
1854 dev->Resize->fromwidth = line_size / (channel_count * channel_size);
1859 dev->scanning->arrange_size = imagesize;
1874 (dev->Resize->type == RSZ_NONE) ? line_size : dev->Resize->bytesperline;
1900 GainOffset_Counter_Save (struct st_device *dev, SANE_Byte data)
1907 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
1910 rst = RTS_EEPROM_WriteByte (dev->usb_handle, 0x0077, data);
1917 GainOffset_Counter_Inc (struct st_device *dev, SANE_Int * arg1)
1925 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
1927 count = GainOffset_Counter_Load (dev);
1928 if ((count >= 0x0f) || (GainOffset_Get (dev) != OK))
1941 rst = GainOffset_Counter_Save (dev, count);
1952 GainOffset_Get (struct st_device *dev)
1962 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
1965 if (RTS_EEPROM_ReadByte (dev->usb_handle, 0x76, &checksum) == OK)
1972 if (RTS_EEPROM_ReadWord (dev->usb_handle, 0x70 + (2 * a), &data)
2025 Scanmode_maxres (struct st_device *dev, SANE_Int scantype, SANE_Int colormode)
2032 for (a = 0; a < dev->scanmodes_count; a++)
2034 reg = dev->scanmodes[a];
2048 rst = Scanmode_maxres (dev, scantype, CM_GRAY);
2058 Scanmode_minres (struct st_device *dev, SANE_Int scantype, SANE_Int colormode)
2064 rst = Scanmode_maxres (dev, scantype, colormode);
2066 for (a = 0; a < dev->scanmodes_count; a++)
2068 reg = dev->scanmodes[a];
2082 rst = Scanmode_minres (dev, scantype, CM_GRAY);
2092 Scanmode_fitres (struct st_device *dev, SANE_Int scantype, SANE_Int colormode,
2100 nullres = Scanmode_maxres (dev, scantype, colormode) + 1;
2103 for (a = 0; a < dev->scanmodes_count; a++)
2105 reg = dev->scanmodes[a];
2127 rst = Scanmode_minres (dev, scantype, CM_GRAY);
2138 RTS_GetScanmode (struct st_device *dev, SANE_Int scantype, SANE_Int colormode,
2146 for (a = 0; a < dev->scanmodes_count; a++)
2148 reg = dev->scanmodes[a];
2168 rst = RTS_GetScanmode (dev, scantype, CM_GRAY, resolution);
2179 Free_Motor (struct st_device *dev)
2185 if (dev->motorcfg != NULL)
2187 free (dev->motorcfg);
2188 dev->motorcfg = NULL;
2193 Load_Motor (struct st_device *dev)
2201 if (dev->motorcfg != NULL)
2202 Free_Motor (dev);
2204 dev->motorcfg = malloc (sizeof (struct st_motorcfg));
2205 if (dev->motorcfg != NULL)
2207 rst = cfg_motor_get (dev->motorcfg);
2208 dbg_motorcfg (dev->motorcfg);
2215 Free_Sensor (struct st_device *dev)
2221 if (dev->sensorcfg != NULL)
2223 free (dev->sensorcfg);
2224 dev->sensorcfg = NULL;
2229 Free_Buttons (struct st_device *dev)
2235 if (dev->buttons != NULL)
2237 free (dev->buttons);
2238 dev->buttons = NULL;
2243 Load_Buttons (struct st_device *dev)
2251 if (dev->buttons != NULL)
2252 Free_Buttons (dev);
2254 dev->buttons = malloc (sizeof (struct st_buttons));
2255 if (dev->buttons != NULL)
2257 rst = cfg_buttons_get (dev->buttons);
2258 dbg_buttons (dev->buttons);
2265 Load_Sensor (struct st_device *dev)
2273 if (dev->sensorcfg != NULL)
2274 Free_Sensor (dev);
2276 dev->sensorcfg = malloc (sizeof (struct st_sensorcfg));
2277 if (dev->sensorcfg != NULL)
2279 rst = cfg_sensor_get (dev->sensorcfg);
2280 dbg_sensor (dev->sensorcfg);
2287 Free_Timings (struct st_device *dev)
2292 if (dev->timings != NULL)
2294 if (dev->timings_count > 0)
2297 for (a = 0; a < dev->timings_count; a++)
2298 if (dev->timings[a] != NULL)
2299 free (dev->timings[a]);
2301 dev->timings_count = 0;
2304 free (dev->timings);
2305 dev->timings = NULL;
2310 Load_Timings (struct st_device *dev)
2318 if (dev->timings != NULL)
2319 Free_Timings (dev);
2323 while ((cfg_timing_get (dev->sensorcfg->type, a, &reg) == OK)
2331 dev->timings_count++;
2332 dev->timings =
2333 (struct st_timing **) realloc (dev->timings,
2335 dev->timings_count);
2336 if (dev->timings == NULL)
2339 dev->timings_count = 0;
2342 dev->timings[dev->timings_count - 1] = tmg;
2351 Free_Timings (dev);
2353 DBG (DBG_FNC, " -> Found %i timing registers\n", dev->timings_count);
2359 IsScannerLinked (struct st_device *dev)
2366 Read_FE3E (dev, &v1619);
2367 Init_USBData (dev);
2370 RTS_WaitInitEnd (dev, 0x30000);
2375 if (Read_Word (dev->usb_handle, 0xe829, &var2) == OK)
2392 Lamp_Status_Get (dev, &flb_lamp, &tma_lamp);
2398 GainOffset_Clear (dev);
2399 GainOffset_Counter_Save (dev, 0);
2402 Refs_Counter_Save (dev, 0);
2404 Buttons_Enable (dev);
2405 Lamp_Status_Timer_Set (dev, 13);
2411 if (RTS_Warm_Reset (dev) != OK)
2414 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
2416 Lamp_Status_Timer_Set (dev, 13);
2421 Lamp_PWM_Save (dev, cfg_fixedpwm_get (dev->sensorcfg->type, ST_NORMAL));
2423 Lamp_PWM_SaveStatus (dev, TRUE);
2426 Lamp_PWM_Setup (dev, lamp);
2434 Lamp_PWM_SaveStatus (struct st_device *dev, SANE_Byte status)
2442 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
2446 if (RTS_EEPROM_ReadByte (dev->usb_handle, 0x007b, &mypwm) == OK)
2450 if (RTS_EEPROM_WriteByte (dev->usb_handle, 0x007b, mypwm) == OK)
2461 Lamp_PWM_Save (struct st_device *dev, SANE_Int fixedpwm)
2468 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
2470 RTS_EEPROM_WriteByte (dev->usb_handle, 0x7b, ((fixedpwm << 2) | 0x80));
2480 Lamp_PWM_Setup (struct st_device *dev, SANE_Int lamp)
2487 if (Lamp_PWM_use (dev, 1) == OK)
2493 cfg_fixedpwm_get (dev->sensorcfg->type,
2496 if (Lamp_PWM_DutyCycle_Get (dev, &currentpwd) == OK)
2500 rst = Lamp_PWM_DutyCycle_Set (dev, fixedpwm);
2503 rst = Lamp_PWM_DutyCycle_Set (dev, fixedpwm);
2512 Lamp_PWM_DutyCycle_Get (struct st_device *dev, SANE_Int * data)
2519 if (Read_Byte (dev->usb_handle, 0xe948, &a) == OK)
2531 Lamp_PWM_DutyCycle_Set (struct st_device *dev, SANE_Int duty_cycle)
2543 if (RTS_ReadRegs (dev->usb_handle, Regs) == OK)
2553 data_bitset (&dev->init_regs[0x148], 0x7f, Regs[0x148]);
2554 data_bitset (&dev->init_regs[0x1e0], 0x3f, Regs[0x1e0]);
2556 Write_Byte (dev->usb_handle, 0xe948, Regs[0x0148]);
2558 rst = Write_Byte (dev->usb_handle, 0xe9e0, Regs[0x01e0]);
2570 Head_ParkHome (struct st_device *dev, SANE_Int bWait, SANE_Int movement)
2582 memcpy (Regs, dev->init_regs, RT_BUFFER_LEN * sizeof (SANE_Byte));
2587 if (RTS_WaitScanEnd (dev, 0x3a98) != OK)
2595 if (RTS_IsExecuting (dev, Regs) == FALSE)
2604 if ((rst == OK) && (Head_IsAtHome (dev, Regs) == FALSE))
2613 dev->status->parkhome = TRUE;
2615 if ((movement != -1) && (movement < dev->motormove_count))
2617 memcpy (&mymotor, dev->motormove[movement],
2636 Motor_Move (dev, Regs, &mymotor, &mtrpos);
2640 rst = RTS_WaitScanEnd (dev, 15000);
2642 dev->status->parkhome = FALSE;
2654 Motor_Move (struct st_device *dev, SANE_Byte * Regs,
2770 Motor_Curve_Get (dev, mymotor->motorcurve, ACC_CURVE,
2777 v12dcf8 = Motor_Setup_Steps (dev, cpRegs, mymotor->motorcurve);
2783 Motor_Curve_Get (dev, mymotor->motorcurve, DEC_CURVE,
2858 Motor_Release (dev);
2860 RTS_Warm_Reset (dev);
2863 data = RTS_WriteRegs (dev->usb_handle, cpRegs);
2865 RTS_Execute (dev);
2868 RTS_WaitScanEnd (dev, 10000);
2870 rst = (data != OK) ? v12dcf8 : RTS_WaitScanEnd (dev, 20000);
2881 Free_Motormoves (struct st_device *dev)
2885 if (dev->motormove != NULL)
2890 for (a = 0; a < dev->motormove_count; a++)
2892 ms = dev->motormove[a];
2897 free (dev->motormove);
2898 dev->motormove = NULL;
2901 dev->motormove_count = 0;
2905 Free_MotorCurves (struct st_device *dev)
2908 if (dev->mtrsetting != NULL)
2909 Motor_Curve_Free (dev->mtrsetting, &dev->mtrsetting_count);
2911 dev->mtrsetting = NULL;
2912 dev->mtrsetting_count = 0;
2916 Load_MotorCurves (struct st_device *dev)
2921 if (dev->mtrsetting != NULL)
2922 Free_MotorCurves (dev);
2931 dev->mtrsetting = Motor_Curve_Parse (&dev->mtrsetting_count, mtc);
2932 if (dev->mtrsetting != NULL)
2938 DBG (DBG_FNC, " -> Found %i motor settings\n", dev->mtrsetting_count);
2939 dbg_motorcurves (dev);
2948 Load_Motormoves (struct st_device *dev)
2957 if (dev->motormove != NULL)
2958 Free_Motormoves (dev);
2961 while ((cfg_motormove_get (dev->sensorcfg->type, a, &reg) != ERROR)
2964 dev->motormove_count++;
2965 dev->motormove =
2966 (struct st_motormove **) realloc (dev->motormove,
2968 dev->motormove_count);
2969 if (dev->motormove != NULL)
2975 dev->motormove[dev->motormove_count - 1] = mm;
2987 Free_Motormoves (dev);
2989 DBG (DBG_FNC, " -> Found %i motormoves\n", dev->motormove_count);
2990 dbg_motormoves (dev);
3011 Motor_Setup_Steps (struct st_device *dev, SANE_Byte * Regs,
3033 mycurve = Motor_Curve_Get (dev, mysetting, ACC_CURVE, CRV_NORMALSCAN);
3088 mycurve = Motor_Curve_Get (dev, mysetting, DEC_CURVE, CRV_BUFFERFULL);
3107 myvalor = dev->mtrsetting[mysetting]->motorbackstep;
3133 if (Motor_Curve_Get (dev, mysetting, ACC_CURVE, CRV_SMEARING) != NULL)
3137 (dev, mysetting, ACC_CURVE, CRV_SMEARING, CRV_NORMALSCAN) == TRUE)
3152 mycurve = Motor_Curve_Get (dev, mysetting, ACC_CURVE, CRV_SMEARING);
3174 if (Motor_Curve_Get (dev, mysetting, DEC_CURVE, CRV_SMEARING) != NULL)
3178 (dev, mysetting, DEC_CURVE, CRV_SMEARING, CRV_BUFFERFULL) == TRUE)
3194 mycurve = Motor_Curve_Get (dev, mysetting, DEC_CURVE, CRV_SMEARING);
3216 if (Motor_Curve_Get (dev, mysetting, DEC_CURVE, CRV_NORMALSCAN) != NULL)
3220 (dev, mysetting, DEC_CURVE, CRV_NORMALSCAN, CRV_BUFFERFULL) == TRUE)
3230 (dev, mysetting, DEC_CURVE, CRV_NORMALSCAN, CRV_SMEARING) == TRUE)
3247 Motor_Curve_Get (dev, mysetting, DEC_CURVE, CRV_NORMALSCAN);
3268 if (Motor_Curve_Get (dev, mysetting, ACC_CURVE, CRV_PARKHOME) != NULL)
3273 (dev, mysetting, ACC_CURVE, CRV_PARKHOME, CRV_NORMALSCAN) == TRUE)
3284 (dev, mysetting, ACC_CURVE, CRV_PARKHOME, CRV_SMEARING) == TRUE)
3300 mycurve = Motor_Curve_Get (dev, mysetting, ACC_CURVE, CRV_PARKHOME);
3323 if (Motor_Curve_Get (dev, mysetting, DEC_CURVE, CRV_PARKHOME) != NULL)
3327 (dev, mysetting, DEC_CURVE, CRV_PARKHOME, CRV_BUFFERFULL) == TRUE)
3337 (dev, mysetting, DEC_CURVE, CRV_PARKHOME, CRV_SMEARING) == TRUE)
3347 (dev, mysetting, DEC_CURVE, CRV_PARKHOME, CRV_NORMALSCAN) == TRUE)
3363 mycurve = Motor_Curve_Get (dev, mysetting, DEC_CURVE, CRV_PARKHOME);
3419 RTS_Warm_Reset (dev);
3427 SetLock (dev->usb_handle, Regs, TRUE);
3430 RTS_DMA_Write (dev, 0x0000, v15f8, bwriten, steps);
3433 SetLock (dev->usb_handle, Regs, FALSE);
3445 Lamp_PWM_use (struct st_device *dev, SANE_Int enable)
3452 if (Read_Byte (dev->usb_handle, 0xe948, &a) == OK)
3454 if (Read_Byte (dev->usb_handle, 0xe9e0, &b) == OK)
3461 dev->init_regs[0x01e0] &= 0x3f;
3462 dev->init_regs[0x01e0] |= 0x80;
3468 dev->init_regs[0x0148] |= 0x40;
3469 dev->init_regs[0x01e0] &= 0x3f;
3478 if (Write_Byte (dev->usb_handle, 0xe948, a) == OK)
3479 rst = Write_Byte (dev->usb_handle, 0xe9e0, b);
3489 SSCG_Enable (struct st_device *dev)
3502 if ((Read_Byte (dev->usb_handle, 0xfe3a, &data1) == OK)
3503 && (Read_Byte (dev->usb_handle, 0xfe39, &data2) == OK))
3516 rst = Write_Word (dev->usb_handle, 0xfe39, sscg);
3528 RTS_Setup_RefVoltages (struct st_device *dev, SANE_Byte * Regs)
3538 cfg_refvoltages_get (dev->sensorcfg->type, &vrts, &vrms, &vrbs);
3552 Init_USBData (struct st_device *dev)
3559 if (Read_Byte (dev->usb_handle, 0xf8ff, &data) != OK)
3563 if (Write_Byte (dev->usb_handle, 0xf8ff, data) != OK)
3566 if (SSCG_Enable (dev) != OK)
3569 Init_Registers (dev);
3572 data_bitset (&dev->init_regs[0x1d0], 0x30, 0x00); /*--00----*/
3575 data_bitset (&dev->init_regs[0x12], 0xc0, 0x03); /*xx------ */
3578 data_bitset (&dev->init_regs[0x00], 0x0f, 0x05); /*----xxxx*/
3581 data_bitset (&dev->init_regs[0x96], 0x3f, 0x17); /*--xxxxxx*/
3584 data_bitset (&dev->init_regs[0x60a], 0x7f, 0x24); /*-xxxxxxx*/
3587 data_bitset (&dev->init_regs[0x10], 0x1f, get_value (SCAN_PARAM, CRVS, 7, usbfile)); /*---xxxxx*/
3590 RTS_Setup_RefVoltages (dev, dev->init_regs);
3592 dev->init_regs[0x11] |= 0x10;
3594 data_bitset (&dev->init_regs[0x26], 0x70, 5); /*-101----*/
3596 dev->init_regs[0x185] = 0x88;
3597 dev->init_regs[0x186] = 0x88;
3601 data_bitset (&dev->init_regs[0x187], 0x0f, 0x08); /*----xxxx*/
3602 data_bitset (&dev->init_regs[0x187], 0xf0, data); /*xxxx---- */
3632 dev->init_regs[0x187] = _B0 (data);
3635 data_bitset (&dev->init_regs[0x26], 0x0f, 0); /*----0000*/
3637 dev->init_regs[0x27] &= 0x3f;
3638 dev->init_regs[0x29] = 0x24;
3639 dev->init_regs[0x2a] = 0x10;
3640 dev->init_regs[0x150] = 0xff;
3641 dev->init_regs[0x151] = 0x13;
3642 dev->init_regs[0x156] = 0xf0;
3643 dev->init_regs[0x157] = 0xfd;
3645 if (dev->motorcfg->changemotorcurrent != FALSE)
3646 Motor_Change (dev, dev->init_regs, 3);
3648 dev->init_regs[0xde] = 0;
3649 data_bitset (&dev->init_regs[0xdf], 0x0f, 0);
3651 /* loads motor resource for this dev */
3654 memcpy (&dev->init_regs[0x104], resource, data);
3657 dev->init_regs[0x01] |= 0x40; /*-1------*/
3659 dev->init_regs[0x124] = 0x94;
3662 Motor_Release (dev);
3670 Init_Registers (struct st_device *dev)
3676 /* Lee dev->init_regs */
3677 memset (dev->init_regs, 0, RT_BUFFER_LEN);
3678 RTS_ReadRegs (dev->usb_handle, dev->init_regs);
3679 Read_FE3E (dev, &v1619);
3681 if (dev->sensorcfg->type == CCD_SENSOR)
3684 data_bitset (&dev->init_regs[0x11], 0xc0, 0); /*xx------ */
3685 data_bitset (&dev->init_regs[0x146], 0x80, 1); /*x------- */
3686 data_bitset (&dev->init_regs[0x146], 0x40, 1); /*-x------*/
3692 data_bitset (&dev->init_regs[0x146], 0x80, 0); /*0------- */
3693 data_bitset (&dev->init_regs[0x146], 0x40, 0); /*-0------*/
3694 data_bitset (&dev->init_regs[0x11], 0xc0, 2); /*xx------ */
3695 data_bitset (&dev->init_regs[0xae], 0x3f, 0x14); /*--xxxxxx*/
3696 data_bitset (&dev->init_regs[0xaf], 0x07, 1); /*-----xxx*/
3698 dev->init_regs[0x9c] = dev->init_regs[0xa2] = dev->init_regs[0xa8] =
3700 dev->init_regs[0x9d] = dev->init_regs[0xa3] = dev->init_regs[0xa9] = 0;
3701 dev->init_regs[0x9e] = dev->init_regs[0xa4] = dev->init_regs[0xaa] = 0;
3702 dev->init_regs[0x9f] = dev->init_regs[0xa5] = dev->init_regs[0xab] = 0;
3703 dev->init_regs[0xa0] = dev->init_regs[0xa6] = dev->init_regs[0xac] = 0;
3704 dev->init_regs[0xa1] = dev->init_regs[0xa7] = dev->init_regs[0xad] =
3709 data_bitset (&dev->init_regs[0x10], 0xe0, 0); /*xxx----- */
3710 data_bitset (&dev->init_regs[0x13], 0x80, 0); /*x------- */
3713 data_bitset (&dev->init_regs[0x146], 0x10, 1); /*---x----*/
3716 dev->init_regs[0x147] = 0xff;
3719 data_lsb_set (&dev->init_regs[0xe1], 0x2af8, 3);
3722 dev->init_regs[0xda] = 0x02;
3723 data_bitset (&dev->init_regs[0xdd], 0x03, 0); /*------xx*/
3726 data_lsb_set (&dev->init_regs[0x19e], binarythresholdl, 2);
3727 data_lsb_set (&dev->init_regs[0x1a0], binarythresholdh, 2);
3730 data_bitset (&dev->init_regs[0x01], 0x08, 0); /*----x---*/
3731 data_bitset (&dev->init_regs[0x16f], 0x40, 0); /*-x------*/
3732 dev->init_regs[0x0bf] = (dev->init_regs[0x00bf] & 0xe0) | 0x20;
3733 dev->init_regs[0x163] = (dev->init_regs[0x0163] & 0x3f) | 0x40;
3735 data_bitset (&dev->init_regs[0xd6], 0x0f, 8); /*----xxxx*/
3736 data_bitset (&dev->init_regs[0x164], 0x80, 1); /*x------- */
3738 dev->init_regs[0x0bc] = 0x00;
3739 dev->init_regs[0x0bd] = 0x00;
3741 dev->init_regs[0x165] = (dev->init_regs[0x0165] & 0x3f) | 0x80;
3742 dev->init_regs[0x0ed] = 0x10;
3743 dev->init_regs[0x0be] = 0x00;
3744 dev->init_regs[0x0d5] = 0x00;
3746 dev->init_regs[0xee] = 0x00;
3747 dev->init_regs[0xef] = 0x00;
3748 dev->init_regs[0xde] = 0xff;
3751 data_bitset (&dev->init_regs[0xdf], 0x10, 0); /*---x----*/
3752 data_bitset (&dev->init_regs[0xdf], 0x0f, 0); /*----xxxx*/
3755 data_bitset (&dev->init_regs[0xd7], 0x80, dev->motorcfg->type); /*x------- */
3757 if (dev->motorcfg->type == MT_ONCHIP_PWM)
3759 data_bitset (&dev->init_regs[0x14e], 0x10, 1); /*---x----*/
3762 data_bitset (&dev->init_regs[0xd7], 0x3f, dev->motorcfg->pwmfrequency); /*--xxxxxx*/
3765 dev->init_regs[0x600] &= 0xfb;
3766 dev->init_regs[0x1d8] |= 0x08;
3772 RTS_DMA_CheckType (dev, dev->init_regs);
3773 rst = RTS_DMA_WaitReady (dev, 1500);
3781 Read_FE3E (struct st_device *dev, SANE_Byte * destino)
3791 if (Read_Byte (dev->usb_handle, 0xfe3e, &data) == 0)
3805 Head_IsAtHome (struct st_device *dev, SANE_Byte * Regs)
3817 if (Read_Byte (dev->usb_handle, 0xe96f, &data) == OK)
3832 RTS_IsExecuting (struct st_device *dev, SANE_Byte * Regs)
3843 if (Read_Byte (dev->usb_handle, 0xe800, &data) == OK)
3856 RTS_WaitScanEnd (struct st_device *dev, SANE_Int msecs)
3868 if (Read_Byte (dev->usb_handle, 0xe800, &data) == OK)
3874 rst = Read_Byte (dev->usb_handle, 0xe800, &data);
3884 RTS_Enable_CCD (struct st_device *dev, SANE_Byte * Regs, SANE_Int channels)
3890 if (Read_Buffer (dev->usb_handle, 0xe810, &Regs[0x10], 4) == OK)
3895 Write_Buffer (dev->usb_handle, 0xe810, &Regs[0x10], 4);
3905 RTS_Warm_Reset (struct st_device *dev)
3913 if (Read_Byte (dev->usb_handle, 0xe800, &data) == OK)
3916 if (Write_Byte (dev->usb_handle, 0xe800, data) == OK)
3919 rst = Write_Byte (dev->usb_handle, 0xe800, data);
3929 Lamp_Status_Timer_Set (struct st_device *dev, SANE_Int minutes)
3936 MyBuffer[0] = dev->init_regs[0x0146] & 0xef;
3937 MyBuffer[1] = dev->init_regs[0x0147];
3950 dev->init_regs[0x147] = MyBuffer[1];
3951 dev->init_regs[0x146] =
3952 (dev->init_regs[0x146] & 0xef) | (MyBuffer[0] & 0x10);
3955 Write_Word (dev->usb_handle, 0xe946,
3964 Buttons_Enable (struct st_device *dev)
3970 if (Read_Word (dev->usb_handle, 0xe958, &data) == OK)
3973 rst = Write_Word (dev->usb_handle, 0xe958, data);
3984 Buttons_Count (struct st_device *dev)
3990 if (dev->buttons != NULL)
3991 rst = dev->buttons->count;
3999 Buttons_Status (struct st_device *dev)
4009 if (Read_Byte (dev->usb_handle, 0xe968, &data) == OK)
4018 Buttons_Released (struct st_device *dev)
4028 if (Read_Byte (dev->usb_handle, 0xe96a, &data) == OK)
4037 Buttons_Order (struct st_device *dev, SANE_Int mask)
4042 if (dev->buttons != NULL)
4048 if (dev->buttons->mask[a] == mask)
4060 GainOffset_Clear (struct st_device *dev)
4071 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
4076 RTS_EEPROM_WriteWord (dev->usb_handle, 0x70 + (2 * a), 0);
4079 rst = RTS_EEPROM_WriteByte (dev->usb_handle, 0x76, 0);
4088 Lamp_Status_Get (struct st_device *dev, SANE_Byte * flb_lamp,
4104 if (Read_Byte (dev->usb_handle, 0xe946, &data2) == OK)
4106 if (Read_Word (dev->usb_handle, 0xe954, &data1) == OK)
4113 switch (dev->chipset->model)
4138 RTS_DMA_WaitReady (struct st_device *dev, SANE_Int msecs)
4151 if (Read_Byte (dev->usb_handle, 0xef09, &data) == OK)
4168 RTS_WaitInitEnd (struct st_device *dev, SANE_Int msecs)
4181 if (Read_Byte (dev->usb_handle, 0xf910, &data) == OK)
4198 Motor_Change (struct st_device *dev, SANE_Byte * buffer, SANE_Byte value)
4204 if (Read_Word (dev->usb_handle, 0xe954, &data) == OK)
4223 rst = Write_Byte (dev->usb_handle, 0xe954, buffer[0x154]);
4234 RTS_DMA_Read (struct st_device *dev, SANE_Int dmacs, SANE_Int options,
4247 if (RTS_DMA_Reset (dev) == OK)
4250 if (RTS_DMA_Enable_Read (dev, dmacs, size, options) == OK)
4255 Bulk_Operation (dev, BLK_READ, size, buffer, &transferred);
4266 RTS_DMA_Write (struct st_device *dev, SANE_Int dmacs, SANE_Int options,
4279 if (RTS_DMA_Reset (dev) == OK)
4282 if (RTS_DMA_Enable_Write (dev, dmacs, size, options) == OK)
4295 Bulk_Operation (dev, BLK_WRITE, size, buffer,
4299 if (RTS_DMA_Enable_Read (dev, dmacs, size, options) ==
4305 Bulk_Operation (dev, BLK_READ, size, check_buffer,
4321 RTS_DMA_Cancel (dev);
4325 (dev, dmacs, size, options) != OK)
4346 Bulk_Operation (dev, BLK_WRITE, size, buffer, &transferred);
4359 RTS_DMA_CheckType (struct st_device *dev, SANE_Byte * Regs)
4400 if (RTS_DMA_SetType (dev, Regs, a) != OK)
4404 if (RTS_DMA_WaitReady (dev, 1500) == OK)
4407 RTS_DMA_Reset (dev);
4410 RTS_DMA_Write (dev, 0x0004, 0x102, 2072, out_buffer);
4413 RTS_DMA_Read (dev, 0x0004, 0x102, 2072, in_buffer);
4438 (dev, 0x0004, 0x0000, 0x20, out_buffer) == OK)
4450 (dev, 0x0004, (_B0 (c) << 0x11) >> 0x04,
4454 (dev, 0x0004, 0x0000, 0x20,
4510 RTS_DMA_SetType (dev, Regs, Regs[0x708] >> 5);
4533 RTS_DMA_SetType (struct st_device *dev, SANE_Byte * Regs, SANE_Byte ramtype)
4543 if (Write_Byte (dev->usb_handle, 0xef08, Regs[0x708]) == OK)
4547 if (Write_Byte (dev->usb_handle, 0xef08, Regs[0x708]) == OK)
4550 rst = Write_Byte (dev->usb_handle, 0xef08, Regs[0x708]);
4561 Motor_Release (struct st_device *dev)
4567 if (Read_Byte (dev->usb_handle, 0xe8d9, &data) == OK)
4570 Write_Byte (dev->usb_handle, 0xe8d9, data);
4577 GainOffset_Counter_Load (struct st_device *dev)
4584 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
4585 if (RTS_EEPROM_ReadByte (dev->usb_handle, 0x77, &data) != OK)
4594 RTS_Execute (struct st_device *dev)
4605 if (Read_Byte (dev->usb_handle, 0xe800, &e800) == OK)
4607 if (Read_Byte (dev->usb_handle, 0xe813, &e813) == OK)
4610 if (Write_Byte (dev->usb_handle, 0xe813, e813) == OK)
4613 if (Write_Byte (dev->usb_handle, 0xe800, e800) == OK)
4616 if (Write_Byte (dev->usb_handle, 0xe813, e813) == OK)
4619 if (Write_Byte (dev->usb_handle, 0xe800, e800) == OK)
4623 ret = Write_Byte (dev->usb_handle, 0xe800, e800);
4637 RTS_isTmaAttached (struct st_device *dev)
4644 if (Read_Word (dev->usb_handle, 0xe968, &rst) == OK)
4712 Gamma_Apply (struct st_device *dev, SANE_Byte * Regs,
4782 Write_Byte (dev->usb_handle, 0xee0b, Regs[0x060b] & 0xaf);
4783 rst = Gamma_SendTables (dev, Regs, gammabuffer, buffersize);
4784 Write_Byte (dev->usb_handle, 0xee0b, Regs[0x060b]);
5066 RTS_Setup_SensorTiming (struct st_device *dev, SANE_Int mytiming,
5071 if ((Regs != NULL) && (mytiming < dev->timings_count))
5073 struct st_timing *mt = dev->timings[mytiming];
5103 if (dev->chipset->model == RTS8822L_02A)
5163 SetMultiExposure (struct st_device *dev, SANE_Byte * Regs)
5215 iValue /= dev->motorcfg->basespeedpps;
5416 Lamp_SetGainMode (struct st_device *dev, SANE_Byte * Regs,
5422 if (dev->chipset->model == RTS8822L_02A)
5471 if (dev->sensorcfg->type == CIS_SENSOR)
5473 else if (dev->sensorcfg->type == CCD_SENSOR)
5483 RTS_Scanner_StartScan (struct st_device *dev)
5492 Lamp_PWM_DutyCycle_Get (dev, &data);
5502 dev->status->cancel = FALSE;
5504 if (Scan_Start (dev) == OK)
5510 if (dev->scanning->imagebuffer != NULL)
5512 free (dev->scanning->imagebuffer);
5513 dev->scanning->imagebuffer = NULL;
5516 SetLock (dev->usb_handle, NULL, (scan2.depth == 16) ? FALSE : TRUE);
5519 Reading_CreateBuffers (dev);
5521 if (dev->Resize->type != RSZ_NONE)
5522 Resize_Start (dev, &transferred); /* 6729 */
5524 RTS_ScanCounter_Inc (dev);
5615 Arrange_NonColour (struct st_device *dev, SANE_Byte * buffer,
5633 scn = dev->scanning;
5644 if (Read_Block (dev, scn->bfsize, scn->imagebuffer, transferred)
5689 rst = Read_Block (dev, line_size, scn->imagepointer, transferred);
6074 Resize_Start (struct st_device *dev, SANE_Int * transferred)
6077 struct st_resize *rz = dev->Resize;
6082 (dev, line_size, rz->bytesperline, rz->bytesperline) == ERROR)
6089 rst = Arrange_Colour (dev, rz->v3624, line_size, transferred);
6091 rst = Arrange_NonColour (dev, rz->v3624, line_size, transferred);
6094 rst = Read_Block (dev, line_size, rz->v3624, transferred); /* ff03 */
6113 rst = Arrange_Colour (dev, rz->v3624, line_size, transferred);
6115 rst = Arrange_NonColour (dev, rz->v3624, line_size, transferred);
6118 rst = Read_Block (dev, line_size, rz->v3624, transferred); /* ffe0 */
6134 Resize_CreateBuffers (struct st_device *dev, SANE_Int size1, SANE_Int size2,
6138 struct st_resize *rz = dev->Resize;
6145 Resize_DestroyBuffers (dev);
6156 Resize_DestroyBuffers (struct st_device *dev)
6158 struct st_resize *rz = dev->Resize;
6177 Reading_DestroyBuffers (struct st_device *dev)
6181 if (dev->Reading->DMABuffer != NULL)
6182 free (dev->Reading->DMABuffer);
6184 if (dev->scanning->imagebuffer != NULL)
6186 free (dev->scanning->imagebuffer);
6187 dev->scanning->imagebuffer = NULL;
6190 memset (dev->Reading, 0, sizeof (struct st_readimage));
6196 Gamma_SendTables (struct st_device *dev, SANE_Byte * Regs,
6212 SetLock (dev->usb_handle, Regs, TRUE);
6226 if (IWrite_Word (dev->usb_handle, 0x0000, 0x0014, 0x0800) == OK)
6229 if (RTS_DMA_Enable_Write (dev, 0x0000, size, first_table) ==
6234 (dev, BLK_WRITE, size, gammatable,
6239 (dev, 0x0000, size, first_table) == OK)
6243 (dev, BLK_READ, size, mybuffer,
6267 SetLock (dev->usb_handle, Regs, FALSE);
6276 Gamma_GetTables (struct st_device *dev, SANE_Byte * Gamma_buffer)
6286 if (IWrite_Word (dev->usb_handle, 0x0000, 0x0014, 0x0800) == 0x00)
6290 if (RTS_DMA_Enable_Read (dev, 0x0000, size, 0) == OK)
6297 Bulk_Operation (dev, BLK_READ, size, Gamma_buffer, &transferred);
6325 RTS_Scanner_StopScan (struct st_device *dev, SANE_Int wait)
6333 Reading_DestroyBuffers (dev);
6334 Resize_DestroyBuffers (dev);
6336 RTS_DMA_Reset (dev);
6338 data_bitset (&dev->init_regs[0x60b], 0x10, 0);
6339 data_bitset (&dev->init_regs[0x60a], 0x40, 0);
6341 if (Write_Buffer (dev->usb_handle, 0xee0a, &dev->init_regs[0x60a], 2) == OK)
6342 Motor_Change (dev, dev->init_regs, 3);
6348 Read_Byte (dev->usb_handle, 0xe801, &data);
6351 if (Head_IsAtHome (dev, dev->init_regs) == FALSE)
6354 data_bitset (&dev->init_regs[0x00], 0x80, 0);
6356 Write_Byte (dev->usb_handle, 0x00, dev->init_regs[0x00]);
6357 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
6365 data_bitset (&dev->init_regs[0x00], 0x80, 0);
6367 Write_Byte (dev->usb_handle, 0x00, dev->init_regs[0x00]);
6368 if (Head_IsAtHome (dev, dev->init_regs) == FALSE)
6369 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
6373 RTS_Enable_CCD (dev, dev->init_regs, 0);
6375 Lamp_Status_Timer_Set (dev, 13);
6381 Reading_CreateBuffers (struct st_device *dev)
6392 if (Read_Byte (dev->usb_handle, 0xe9a1, &data) == OK)
6398 dev->Reading->Max_Size = 0xfc00;
6399 dev->Reading->DMAAmount = 0;
6407 dev->Reading->DMABufferSize = mybuffersize; /*3FFC00 4193280 */
6411 dev->Reading->DMABuffer =
6412 (SANE_Byte *) malloc (dev->Reading->DMABufferSize *
6414 if (dev->Reading->DMABuffer != NULL)
6416 dev->Reading->DMABufferSize -= dev->Reading->Max_Size;
6418 while (dev->Reading->DMABufferSize >= dev->Reading->Max_Size);
6421 dev->Reading->Starting = TRUE;
6423 dev->Reading->Size4Lines = (mybytesperline > dev->Reading->Max_Size) ?
6424 mybytesperline : (dev->Reading->Max_Size / mybytesperline) *
6427 dev->Reading->ImageSize = imagesize;
6436 RTS_ScanCounter_Inc (struct st_device *dev)
6445 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
6450 switch (dev->chipset->model)
6455 if (RTS_EEPROM_ReadInteger (dev->usb_handle, 0x21, &idata) == OK)
6459 RTS_EEPROM_WriteInteger (dev->usb_handle, 0x21, idata);
6467 RTS_EEPROM_ReadInteger (dev->usb_handle, 0x21, &idata);
6470 RTS_EEPROM_ReadByte (dev->usb_handle, 0x003a, &cdata);
6472 RTS_EEPROM_WriteBuffer (dev->usb_handle, 0x21, somebuffer, 0x1a);
6483 RTS_ScanCounter_Get (struct st_device *dev)
6492 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
6494 RTS_EEPROM_ReadInteger (dev->usb_handle, 0x21, &idata);
6496 switch (dev->chipset->model)
6516 Read_Image (struct st_device *dev, SANE_Int buffer_size, SANE_Byte * buffer,
6531 if (dev->Resize->type == RSZ_NONE)
6538 rst = Arrange_Colour (dev, buffer, buffer_size, transferred);
6541 rst = Arrange_Compose (dev, buffer, buffer_size, transferred);
6544 rst = Arrange_NonColour (dev, buffer, buffer_size, transferred);
6549 rst = Read_Block (dev, buffer_size, buffer, transferred); /*00fe */
6552 rst = Read_ResizeBlock (dev, buffer, buffer_size, transferred); /*010d */
6560 Arrange_Compose (struct st_device *dev, SANE_Byte * buffer,
6584 scn = dev->scanning;
6588 if (dev->sensorcfg->type == CCD_SENSOR)
6590 (dev->sensorcfg->line_distance * scan2.resolution_y) /
6591 dev->sensorcfg->resolution;
6612 if (Read_Block (dev, scn->bfsize, scn->imagebuffer, transferred) ==
6625 if ((((dev->sensorcfg->line_distance * scan2.resolution_y) *
6626 2) / dev->sensorcfg->resolution) == 1)
6631 ((dev->sensorcfg->rgb_order[c] / 2) * line_size) +
6641 (dev->sensorcfg->rgb_order[c] * (mydistance * line_size)) +
6689 Triplet_Compose_Order (dev, scn->pColour[CL_RED],
6707 if (Read_Block (dev, line_size, scn->imagepointer, transferred) ==
6808 Triplet_Compose_Order (struct st_device *dev, SANE_Byte * pRed,
6844 if (dev->sensorcfg->rgb_order[CL_RED] == 1)
6850 else if (dev->sensorcfg->rgb_order[CL_GREEN] == 1)
6923 Triplet_Colour_Order (struct st_device *dev, SANE_Byte * pRed,
6958 if (dev->sensorcfg->rgb_order[CL_RED] == 1)
6960 else if (dev->sensorcfg->rgb_order[CL_GREEN] == 1)
7083 Read_ResizeBlock (struct st_device *dev, SANE_Byte * buffer,
7097 struct st_resize *rz = dev->Resize;
7117 rst = Arrange_Colour (dev, rz->v3624, line_size, transferred);
7120 Arrange_NonColour (dev, rz->v3624, line_size, transferred);
7123 rst = Read_Block (dev, line_size, rz->v3624, transferred);
7326 Arrange_Colour (dev, rz->v3624, line_size, &transferred);
7329 Arrange_NonColour (dev, rz->v3624, line_size, &transferred);
7332 rst = Read_Block (dev, line_size, rz->v3624, &transferred); /*f77a */
7396 Read_NonColor_Block (struct st_device *dev, SANE_Byte * buffer,
7443 dev->Reading->Size4Lines) ? mysize : dev->Reading->Size4Lines;
7453 Scan_Read_BufferA (dev, (mysize4lines * 3) / 4, 0,
7477 Scan_Read_BufferA (dev, mysize4lines, 0, mybuffer,
7523 Scan_Read_BufferA (dev, mysize4lines, 0, mybuffer,
7569 while ((mysize > 0) && (dev->status->cancel == FALSE));
7583 Read_Block (struct st_device *dev, SANE_Int buffer_size, SANE_Byte * buffer,
7615 return Read_NonColor_Block (dev, buffer, buffer_size, scan2.colormode,
7629 (dev->Reading->Size4Lines <
7630 mysize) ? dev->Reading->Size4Lines : mysize;
7636 Scan_Read_BufferA (dev, buffer_size, 0, readbuffer,
7663 Scan_Read_BufferA (dev, buffer_size, 0, readbuffer,
7683 while ((mysize > 0) && (dev->status->cancel == FALSE));
7694 Scan_Read_BufferA (struct st_device *dev, SANE_Int buffer_size, SANE_Int arg2,
7700 struct st_readimage *rd = dev->Reading;
7714 && (dev->status->cancel == FALSE))
7723 if (Read_Byte (dev->usb_handle, 0xe812, &data) == OK)
7731 if (Read_Byte (dev->usb_handle, 0xee0b, &data) == OK)
7757 Reading_BufferSize_Notify (dev, 0, rd->DMAAmount);
7785 opStatus = Reading_Wait (dev, rd->Channels_per_dot,
7804 Bulk_Operation (dev, BLK_READ, iAmount, ptImg,
7906 RTS_DMA_Cancel (dev);
7920 Reading_BufferSize_Get (struct st_device *dev, SANE_Byte channels_per_dot,
7940 if (Read_Byte (dev->usb_handle, 0xe812, &channels_per_dot) == OK)
7947 if (Read_Integer (dev->usb_handle, 0xef16, &myAmount) == OK)
7957 Lamp_Warmup (struct st_device *dev, SANE_Byte * Regs, SANE_Int lamp,
7970 Lamp_Status_Get (dev, &flb_lamp, &tma_lamp);
7980 Lamp_Status_Set (dev, Regs, TRUE, FLB_LAMP);
7987 if (RTS_isTmaAttached (dev) == TRUE)
7994 Lamp_Status_Set (dev, Regs, FALSE, TMA_LAMP);
8005 Lamp_PWM_Setup (dev, lamp);
8009 /*Lamp_PWM_DutyCycle_Set(dev, (lamp == TMA_LAMP)? 0x0e : 0x00); */
8017 dev->status->warmup = TRUE;
8022 Lamp_PWM_CheckStable (dev, resolution, lamp);
8029 /*Lamp_PWM_Setup(dev, lamp);
8034 Lamp_PWM_CheckStable(dev, resolution, lamp);
8044 dev->status->warmup = FALSE;
8052 Scan_Start (struct st_device *dev)
8059 if (RTS_Enable_CCD (dev, dev->init_regs, 0x0f) == OK)
8068 memcpy (&Regs, dev->init_regs, RT_BUFFER_LEN * sizeof (SANE_Byte));
8080 while ((Head_IsAtHome (dev, Regs) == FALSE)
8087 if (GainOffset_Counter_Inc (dev, &lfaa0) != OK)
8094 Refs_Set (dev, Regs, &scancfg);
8099 Head_Relocate (dev, dev->motorcfg->parkhomemotormove, MTR_FORWARD,
8104 (dev, Regs, (scancfg.scantype == ST_NORMAL) ? FLB_LAMP : TMA_LAMP,
8111 if (Calib_CreateBuffers (dev, &myCalib, v14b4) != OK)
8117 if (Calib_BlackShading_jkd(dev, Regs, &myCalib, &scancfg) == OK)
8118 Head_ParkHome(dev, TRUE, dev->motorcfg->parkhomemotormove);
8122 if (Calib_test(dev, Regs, &myCalib, &scancfg) == OK )
8123 Head_ParkHome(dev, TRUE, dev->motorcfg->parkhomemotormove);
8128 if (WShading_Calibrate (dev, Regs, &myCalib, &scancfg) == OK)
8129 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
8146 memcpy (&Regs, dev->init_regs,
8149 if (Calibration (dev, Regs, &scancfg, &myCalib, 0) != OK)
8166 Head_ParkHome (dev, TRUE, dev->motorcfg->basespeedmotormove);
8178 Lamp_Status_Set (dev, NULL, TRUE, FLB_LAMP);
8185 Lamp_Status_Set (dev, NULL, FALSE, TMA_LAMP);
8191 Head_Relocate(dev, dev->motorcfg->highspeedmotormove, MTR_FORWARD, ta_y_start);
8199 Head_Relocate(dev, dev->motorcfg->basespeedmotormove, MTR_FORWARD, ta_y_start);
8221 hwdcfg.sensorevenodddistance = dev->sensorcfg->evenodd_distance;
8259 if (dev->sensorcfg->type == CCD_SENSOR)
8340 Head_Relocate (dev, dev->motorcfg->highspeedmotormove, MTR_FORWARD, (dev->motorcfg->resolution / scancfg.resolution_y) * val1); /*x168 */
8356 RTS_Setup (dev, Regs, &scancfg, &hwdcfg, &calibdata->gain_offset);
8368 RTS_WriteRegs (dev->usb_handle, Regs);
8371 Gamma_Apply (dev, Regs, &scancfg, &hwdcfg, hp_gamma);
8373 Shading_apply (dev, Regs, &scancfg, &myCalib);
8380 RTS_Setup (dev, Regs, &scancfg, &hwdcfg, default_gain_offset);
8403 if (dev->motorcfg->changemotorcurrent != FALSE)
8404 Motor_Change (dev, Regs,
8408 Lamp_SetGainMode (dev, Regs, scancfg.resolution_x,
8409 Lamp_GetGainMode (dev, scancfg.resolution_x,
8412 RTS_WaitScanEnd (dev, 15000);
8417 Motor_Release (dev);
8423 /*WShading_Calibrate(dev, Regs, &myCalib, &scancfg); */
8424 /*shadingtest1(dev, Regs, &myCalib); */
8427 if (RTS_Warm_Reset (dev) == OK)
8429 RTS_WriteRegs (dev->usb_handle, Regs);
8432 if (RTS_Execute (dev) == OK)
8434 Lamp_Status_Timer_Set (dev, 0);
8437 if ((dev->chipset->model == RTS8822L_02A)
8452 RTS_Setup_Motor (struct st_device *dev, SANE_Byte * Regs,
8468 RTS_GetScanmode (dev, scantype, colormode, scancfg->resolution_x);
8476 sm = dev->scanmodes[mymode];
8533 _B0 ((dev->motorcfg->resolution * step_type) /
8550 if (sm->motorcurve < dev->mtrsetting_count)
8552 struct st_motorcurve *ms = dev->mtrsetting[sm->motorcurve];
8558 lf02c = Motor_Setup_Steps (dev, Regs, sm->motorcurve);
8678 RTS_Setup_Line_Distances (struct st_device *dev, SANE_Byte * Regs,
8691 (dev->sensorcfg->line_distance * scancfg->resolution_y) /
8692 dev->sensorcfg->resolution;
8697 dev->sensorcfg->resolution;
8723 (dev->sensorcfg->line_distance * scan2.resolution_y) * 2;
8725 (iLineDistance / dev->sensorcfg->resolution) + 1;
8735 ((dev->sensorcfg->line_distance * 2) +
8739 dev->sensorcfg->line_distance * scan2.resolution_y;
8742 (iLineDistance / dev->sensorcfg->resolution) + 1;
8930 RTS_Setup_Arrangeline (struct st_device *dev, struct st_hwdconfig *hwdcfg,
8933 dev->scanning->arrange_compression =
8942 dev->scanning->arrange_hres = hwdcfg->highresolution;
8943 dev->scanning->arrange_sensor_evenodd_dist =
8948 RTS_Setup_Channels (struct st_device *dev, SANE_Byte * Regs,
8964 data_bitset (&Regs[0x12], 0x03, dev->sensorcfg->rgb_order[scancfg->channel]); /*------xx*/
8975 if (scancfg->channel == dev->sensorcfg->rgb_order[1])
8985 else if (scancfg->channel == dev->sensorcfg->rgb_order[2])
9003 data_bitset (&Regs[0x12], 0x03, dev->sensorcfg->channel_gray[0]); /*------xx*/
9004 data_bitset (&Regs[0x12], 0x0c, dev->sensorcfg->channel_gray[1]); /*----xx--*/
9028 data_bitset (&Regs[0x60a], 0x03, dev->sensorcfg->channel_color[2]); /*------xx*/
9029 data_bitset (&Regs[0x60a], 0x0c, dev->sensorcfg->channel_color[1]); /*----xx--*/
9030 data_bitset (&Regs[0x60a], 0x30, dev->sensorcfg->channel_color[0]); /*--xx----*/
9033 data_bitset (&Regs[0x12], 0x03, dev->sensorcfg->rgb_order[0]); /*------xx*/
9034 data_bitset (&Regs[0x12], 0x0c, dev->sensorcfg->rgb_order[1]); /*----xx--*/
9035 data_bitset (&Regs[0x12], 0x30, dev->sensorcfg->rgb_order[2]); /*--xx----*/
9041 RTS_Setup (struct st_device *dev, SANE_Byte * Regs,
9073 RTS_GetScanmode (dev, scantype, mycolormode, scancfg->resolution_x);
9076 struct st_scanmode *sm = dev->scanmodes[lSMode];
9087 dev->timings[scancfg->timing]->sensorresolution;
9101 RTS_Setup_Arrangeline (dev, hwdcfg, mycolormode);
9105 RTS_Setup_Line_Distances (dev, Regs, scancfg, hwdcfg, mycolormode,
9111 RTS_Setup_Channels (dev, Regs, scancfg, mycolormode);
9124 RTS_Setup_SensorTiming (dev, scancfg->timing, Regs);
9139 RTS_Setup_Motor (dev, Regs, scancfg,
9170 if (dev->scanning->arrange_compression != FALSE)
9193 dev->scanning->arrange_compression = FALSE;
9484 Calib_WriteTable (struct st_device *dev, SANE_Byte * table, SANE_Int size,
9495 if (RTS_DMA_Reset (dev) == OK)
9498 if (RTS_DMA_Enable_Write (dev, 0x0004, size, data) == OK)
9500 rst = Bulk_Operation (dev, BLK_WRITE, size, table, &transferred);
9510 Calib_ReadTable (struct st_device *dev, SANE_Byte * table, SANE_Int size,
9521 if (RTS_DMA_Reset (dev) == OK)
9524 if (RTS_DMA_Enable_Read (dev, 0x0004, size, data) == OK)
9526 rst = Bulk_Operation (dev, BLK_READ, size, table, &transferred);
9536 fn3330 (struct st_device *dev, SANE_Byte * Regs, struct st_cal2 *calbuffers,
9657 (dev, (SANE_Byte *) calbuffers->table2, calbuffers->tables_size,
9680 fn3730 (struct st_device *dev, struct st_cal2 *calbuffers, SANE_Byte * Regs,
9698 rst = fn3330 (dev, Regs, calbuffers, sensorchannelcolor, pos, data);
9706 Shading_white_apply (struct st_device *dev, SANE_Byte * Regs,
9736 (dev, dev->sensorcfg->channel_color[chnl] | 0x14,
9739 Bulk_Operation (dev, BLK_WRITE,
9747 (dev, calbuffers, Regs,
9749 dev->sensorcfg->channel_color[chnl], 1) == OK)
9755 RTS_DMA_Cancel (dev);
9768 Shading_black_apply (struct st_device *dev, SANE_Byte * Regs,
9799 (dev, dev->sensorcfg->channel_color[chnl] | 0x10,
9802 Bulk_Operation (dev, BLK_WRITE,
9810 (dev, calbuffers, Regs,
9812 dev->sensorcfg->channel_color[chnl], 0) == OK)
9818 RTS_DMA_Cancel (dev);
9832 Shading_apply (struct st_device *dev, SANE_Byte * Regs,
9858 rst = Write_Byte (dev->usb_handle, 0xee0b, Regs[0x060b]);
10015 Shading_black_apply (dev, Regs, channels, myCalib, &calbuffers);
10021 Shading_white_apply (dev, Regs, channels, myCalib, &calbuffers);
10029 rst = Write_Byte (dev->usb_handle, 0xee0b, Regs[0x060b]);
10040 Bulk_Operation (struct st_device *dev, SANE_Byte op, SANE_Int buffer_size,
10066 Read_Bulk (dev->usb_handle, &buffer[iPos], iTransferSize);
10089 if (Write_Bulk (dev->usb_handle, &buffer[iPos], iTransferSize) !=
10112 Reading_BufferSize_Notify (struct st_device *dev, SANE_Int data,
10120 rst = RTS_DMA_Enable_Read (dev, 0x0008, size, data);
10128 Reading_Wait (struct st_device *dev, SANE_Byte Channels_per_dot,
10145 myAmount = Reading_BufferSize_Get (dev, Channels_per_dot, Channel_size);
10156 Reading_BufferSize_Get (dev, Channels_per_dot, Channel_size);
10162 || (RTS_IsExecuting (dev, &executing) == FALSE))
10205 RTS_GetImage_GetBuffer (struct st_device *dev, double dSize,
10234 if (Reading_Wait (dev, 0, 1, myLength * 2, NULL, 5, FALSE) == OK)
10236 if (Reading_BufferSize_Notify (dev, 0, myLength * 2) == OK)
10238 Bulk_Operation (dev, BLK_READ, myLength * 2, &buffer[iPos],
10257 RTS_DMA_Cancel (dev);
10265 RTS_GetImage_Read (struct st_device *dev, SANE_Byte * buffer,
10293 rst = RTS_GetImage_GetBuffer (dev, dSize, buffer, &transferred);
10297 RTS_WaitScanEnd (dev, 1500);
10306 RTS_GetImage (struct st_device *dev, SANE_Byte * Regs,
10349 Write_Byte (dev->usb_handle, 0xe946, Regs[0x146]);
10375 ((dev->sensorcfg->type == CCD_SENSOR) ? 24 : 50);
10390 RTS_Setup (dev, Regs, myscancfg, hwdcfg, gain_offset);
10408 RTS_Setup (dev, myRegs, &scan, hwdcfg,
10455 SetMultiExposure (dev, Regs);
10460 SetMultiExposure (dev, Regs);
10463 RTS_WriteRegs (dev->usb_handle, Regs);
10465 Shading_apply (dev, Regs, myscancfg, myCalib);
10467 if (dev->motorcfg->changemotorcurrent != FALSE)
10468 Motor_Change (dev, Regs,
10478 Motor_Release (dev);
10480 if (RTS_Warm_Reset (dev) == OK)
10484 SetLock (dev->usb_handle, Regs,
10488 Lamp_SetGainMode (dev, Regs, myscancfg->resolution_x,
10492 if (RTS_WriteRegs (dev->usb_handle, Regs) == OK)
10495 if (RTS_Execute (dev) == OK)
10496 RTS_GetImage_Read (dev, buffer, myscancfg, hwdcfg); /*92e7 */
10500 SetLock (dev->usb_handle, Regs, FALSE);
10507 Write_Byte (dev->usb_handle, 0xe946, Regs[0x146]);
10513 if (dev->motorcfg->changemotorcurrent == TRUE)
10514 Motor_Change (dev, dev->init_regs, 3);
10533 Refs_Detect (struct st_device *dev, SANE_Byte * Regs, SANE_Int resolution_x,
10575 gaincontrol = Lamp_GetGainMode (dev, resolution_x, ST_NORMAL); /* scan.scantype */
10577 Lamp_PWM_use (dev, 1);
10578 Lamp_PWM_DutyCycle_Set (dev, (gaincontrol == 0) ? 0x12 : 0x26);
10581 Lamp_Status_Set (dev, NULL, TRUE, FLB_LAMP);
10588 Lamp_PWM_use (dev, 1);
10599 Lamp_Warmup (dev, Regs, FLB_LAMP, resolution_x);
10603 (dev, Regs, &scancfg, &gain_offset, image, 0, 0x20000000,
10647 Refs_Set (struct st_device *dev, SANE_Byte * Regs,
10660 cfg_vrefs_get (dev->sensorcfg->type, scancfg->resolution_x, &scan.ler,
10671 if (Refs_Counter_Load (dev) == 0)
10684 (dev, Regs, refcfg.resolution, refcfg.resolution, &x, &y) == OK)
10685 Refs_Save (dev, x, y);
10689 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
10694 if (Refs_Load (dev, &x, &y) == ERROR)
10697 (dev, Regs, refcfg.resolution, refcfg.resolution, &x,
10699 Refs_Save (dev, x, y);
10703 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
10729 Refs_Counter_Inc (dev);
10738 Lamp_Status_Set (struct st_device *dev, SANE_Byte * Regs, SANE_Int turn_on,
10759 RTS_ReadRegs (dev->usb_handle, Regs);
10762 switch (dev->chipset->model)
10787 /*dev->init_regs[0x0146] = (dev->init_regs[0x146] & 0xbf) | (Regs[0x146] & 0x40); */
10788 dev->init_regs[0x0146] = (dev->init_regs[0x146] & 0x9f) | (Regs[0x146] & 0x60); /*-xx-----*/
10791 dev->init_regs[0x0155] = Regs[0x0155];
10792 Write_Byte (dev->usb_handle, 0xe946, Regs[0x0146]);
10794 Write_Buffer (dev->usb_handle, 0xe954, &Regs[0x0154], 2);
10854 Lamp_GetGainMode (struct st_device *dev, SANE_Int resolution,
10884 if (dev->chipset->model == RTS8822L_02A)
10964 GetOneLineInfo (struct st_device *dev, SANE_Int resolution,
10985 memcpy (Regs, dev->init_regs, RT_BUFFER_LEN * sizeof (SANE_Byte));
11003 RTS_GetScanmode (dev, scantype, 0, resolution);
11026 Lamp_GetGainMode (dev, resolution & 0xffff, scan.scantype);
11028 (dev, Regs, &scancfg, &gain_offset, image, 0,
11138 Lamp_PWM_CheckStable (struct st_device *dev, SANE_Int resolution,
11162 rst = GetOneLineInfo (dev, resolution, maximus, minimus, average);
11191 Refs_Counter_Load (struct st_device *dev)
11198 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
11199 if (RTS_EEPROM_ReadByte (dev->usb_handle, 0x78, &data) != OK)
11208 Refs_Counter_Save (struct st_device *dev, SANE_Byte data)
11215 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
11220 rst = RTS_EEPROM_WriteByte (dev->usb_handle, 0x78, data);
11229 Refs_Counter_Inc (struct st_device *dev)
11235 data = Refs_Counter_Load (dev) + 1;
11240 Refs_Counter_Save (dev, data);
11275 Head_Relocate (struct st_device *dev, SANE_Int speed, SANE_Int direction,
11293 memcpy (Regs, dev->init_regs, RT_BUFFER_LEN * sizeof (SANE_Byte));
11295 if (speed < dev->motormove_count)
11296 memcpy (&mymotor, dev->motormove[speed],
11307 Motor_Move (dev, Regs, &mymotor, &mtrpos);
11310 RTS_WaitScanEnd (dev, 15000);
11361 Calib_CreateBuffers (struct st_device *dev, struct st_calibration *buffer,
11367 (void) dev;
11448 Calib_LoadConfig (struct st_device *dev,
11478 cfg_wrefs_get (dev->sensorcfg->type, bitmode, resolution, scantype,
11511 cfg_offset_get (dev->sensorcfg->type, resolution, scantype,
11581 cfg_effectivepixel_get (dev->sensorcfg->type, resolution);
11587 Calib_AdcGain (struct st_device *dev, struct st_calibration_config *calibcfg,
11623 Lamp_SetGainMode (dev, myRegs, scancfg->resolution_x, gaincontrol);
11688 (dev, myRegs, scancfg, &calibdata->gain_offset, image, NULL,
11867 GainOffset_Save (struct st_device *dev, SANE_Int * offset, SANE_Byte * gain)
11874 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
11886 RTS_EEPROM_WriteWord (dev->usb_handle, 0x70 + (a * 2), value);
11890 rst = RTS_EEPROM_WriteByte (dev->usb_handle, 0x76, crc);
11902 Calib_PAGain (struct st_device *dev, struct st_calibration_config *calibcfg,
11980 RTS_GetImage (dev, Regs, scancfg, &calibdata->gain_offset,
12060 Chipset_ID (struct st_device *dev)
12064 if (Read_Word (dev->usb_handle, 0xfe3c, &ret) == OK)
12075 Chipset_Name (struct st_device *dev, char *name, SANE_Int size)
12081 strncpy (name, dev->chipset->name, size);
12089 Refs_Load (struct st_device *dev, SANE_Int * x, SANE_Int * y)
12098 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
12104 if (RTS_EEPROM_ReadWord (dev->usb_handle, 0x6a, &data) == OK)
12107 if (RTS_EEPROM_ReadWord (dev->usb_handle, 0x6c, &data) == OK)
12110 if (RTS_EEPROM_ReadWord (dev->usb_handle, 0x6e, &data) == OK)
12125 Refs_Save (struct st_device *dev, SANE_Int left_leading, SANE_Int start_pos)
12133 if ((dev->chipset->capabilities & CAP_EEPROM) != 0)
12137 if (RTS_EEPROM_WriteWord (dev->usb_handle, 0x6a, left_leading) == OK)
12139 if (RTS_EEPROM_WriteWord (dev->usb_handle, 0x6c, start_pos) == OK)
12142 ret = RTS_EEPROM_WriteByte (dev->usb_handle, 0x6e, data);
12153 Calib_AdcOffsetRT (struct st_device *dev,
12256 gainmode = Lamp_GetGainMode (dev, scancfg.resolution_x, scan.scantype);
12258 (dev, Regs, &scancfg, &calibdata->gain_offset, scanbuffer, 0,
12571 Calib_LoadCut (struct st_device *dev, struct st_scanparams *scancfg,
12579 cfg_shading_cut_get (dev->sensorcfg->type, scancfg->depth,
12613 Calib_WhiteShading_3 (struct st_device *dev,
12653 Lamp_SetGainMode (dev, myRegs, scancfg.resolution_x, gainmode);
12733 RTS_GetImage (dev, myRegs, &scancfg, &calibdata->gain_offset, scanbuffer,
13128 Calib_BlackShading (struct st_device *dev,
13172 Lamp_SetGainMode (dev, myRegs, scancfg.resolution_x, gainmode);
13225 Calib_LoadCut (dev, &scancfg, scan.scantype, calibcfg);
13281 Lamp_Status_Set (dev, NULL, FALSE, FLB_LAMP);
13287 RTS_GetImage (dev, myRegs, &scancfg, &calibdata->gain_offset, buffer,
13305 Lamp_Status_Set (dev, NULL, FALSE, TMA_LAMP);
13309 Lamp_Status_Set (dev, NULL, TRUE, FLB_LAMP);
13612 Calibration (struct st_device *dev, SANE_Byte * Regs,
13633 Calib_LoadConfig (dev, &calibcfg, scan.scantype, scancfg->resolution_x,
13656 gainmode = Lamp_GetGainMode (dev, scancfg->resolution_x, scan.scantype); /* [lf904] = 1 */
13670 if (Calib_PAGain (dev, &calibcfg, gainmode) != 0)
13716 lf900 = Calib_AdcOffsetRT (dev, &calibcfg, 1);
13751 lf900 = Calib_AdcGain (dev, &calibcfg, 1, gainmode);
13754 GainOffset_Save (dev, &calibdata->gain_offset.edcg1[0],
13771 lf900 = Calib_AdcOffsetRT (dev, &calibcfg, 2);
13792 lf900 = Calib_AdcGain (dev, &calibcfg, 0, gainmode);
13813 lf900 = Calib_BlackShading (dev, &calibcfg, myCalib, gainmode);
13824 Calib_WhiteShading_3 (dev, &calibcfg, myCalib, gainmode);
13847 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
13852 /*static void show_diff(struct st_device *dev, SANE_Byte *original)
13860 if (RTS_ReadRegs(dev->usb_handle, buffer) != OK)
13879 Load_Constrains (struct st_device *dev)
13883 if (dev->constrains != NULL)
13884 Free_Constrains (dev);
13888 dev->constrains =
13890 if (dev->constrains != NULL)
13892 cfg_constrains_get (dev->constrains);
13900 Constrains_Check (struct st_device *dev, SANE_Int Resolution,
13913 if (dev->constrains != NULL)
13924 mc = &dev->constrains->slide;
13927 mc = &dev->constrains->negative;
13930 mc = &dev->constrains->reflective;
13969 Constrains_Get (struct st_device *dev, SANE_Byte scantype)
13973 if (dev->constrains != NULL)
13978 rst = &dev->constrains->slide;
13981 rst = &dev->constrains->negative;
13984 rst = &dev->constrains->reflective;
13993 Free_Constrains (struct st_device *dev)
13997 if (dev->constrains != NULL)
13999 free (dev->constrains);
14000 dev->constrains = NULL;
14087 RTS_USBType (struct st_device *dev)
14096 if (Read_Byte (dev->usb_handle, 0xfe11, &data) == OK)
14203 Chipset_Reset (struct st_device *dev)
14211 if (Read_Byte(dev->usb_handle, 0xe800, &data) == OK)
14214 if (Write_Byte(dev->usb_handle, 0xe800, data) == OK)
14217 rst = Write_Byte(dev->usb_handle, 0xe800, data);
14222 rst = IWrite_Buffer (dev->usb_handle, 0x0000, NULL, 0, 0x0801);
14230 RTS_DMA_Enable_Read (struct st_device *dev, SANE_Int dmacs, SANE_Int size,
14245 rst = IWrite_Buffer (dev->usb_handle, dmacs, buffer, 6, 0x0400);
14253 RTS_DMA_Enable_Write (struct st_device *dev, SANE_Int dmacs, SANE_Int size,
14268 rst = IWrite_Buffer (dev->usb_handle, dmacs, buffer, 6, 0x0401);
14276 RTS_DMA_Cancel (struct st_device *dev)
14282 rst = IWrite_Word (dev->usb_handle, 0x0000, 0, 0x0600);
14290 RTS_DMA_Reset (struct st_device *dev)
14296 rst = IWrite_Word (dev->usb_handle, 0x0000, 0x0000, 0x0800);
14451 WShading_Calibrate (struct st_device *dev, SANE_Byte * Regs,
14488 Calib_LoadConfig (dev, calibcfg, scan.scantype, myscancfg->resolution_x,
14490 gainmode = Lamp_GetGainMode (dev, myscancfg->resolution_x, scan.scantype);
14492 Lamp_SetGainMode (dev, myRegs, myscancfg->resolution_x, gainmode);
14536 RTS_GetImage (dev, myRegs, myscancfg, &myCalibTable, pattern, myCalib,
14674 motor_pos (struct st_device *dev, SANE_Byte * Regs,
14702 Calib_LoadConfig (dev, calibcfg, scan.scantype, myscancfg->resolution_x,
14704 gainmode = Lamp_GetGainMode (dev, myscancfg->resolution_x, scan.scantype);
14706 Lamp_SetGainMode (dev, myRegs, myscancfg->resolution_x, gainmode);
14744 /*Head_Relocate(dev, dev->motorcfg->highspeedmotormove, MTR_FORWARD, 5500); */
14758 Head_Relocate (dev, dev->motorcfg->highspeedmotormove, MTR_FORWARD,
14761 RTS_GetImage (dev, myRegs, myscancfg, &myCalibTable, scanbuffer,
14763 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
14788 hp4370_prueba (struct st_device *dev)
14798 rst = IWrite_Word (dev->usb_handle, 0x0000, data, 0x0800);
14799 RTS_DMA_Enable_Write (dev, 0x4, 512, 0);
14800 Bulk_Operation (dev, BLK_WRITE, 512, buffer, &transferred);
14806 Calib_BlackShading_jkd (struct st_device *dev, SANE_Byte * Regs,
14842 Calib_LoadConfig (dev, calibcfg, scan.scantype, myscancfg->resolution_x,
14844 gainmode = Lamp_GetGainMode (dev, myscancfg->resolution_x, scan.scantype);
14846 Lamp_SetGainMode (dev, myRegs, myscancfg->resolution_x, gainmode);
14883 Lamp_Status_Set (dev, NULL, FALSE, FLB_LAMP);
14889 RTS_GetImage (dev, myRegs, myscancfg, &myCalibTable, scanbuffer, myCalib,
14895 Lamp_Status_Set (dev, NULL, FALSE, TMA_LAMP);
14899 Lamp_Status_Set (dev, NULL, TRUE, FLB_LAMP);
14942 Calib_test (struct st_device *dev, SANE_Byte * Regs,
14970 Calib_LoadConfig (dev, calibcfg, scan.scantype, myscancfg->resolution_x,
14972 gainmode = Lamp_GetGainMode (dev, myscancfg->resolution_x, scan.scantype);
14974 Lamp_SetGainMode (dev, myRegs, myscancfg->resolution_x, gainmode);
15012 /*Head_Relocate(dev, dev->motorcfg->highspeedmotormove, MTR_FORWARD, 5500); */
15024 Head_Relocate (dev, dev->motorcfg->highspeedmotormove, MTR_FORWARD,
15027 RTS_GetImage (dev, myRegs, myscancfg, &myCalibTable, scanbuffer,
15029 Head_ParkHome (dev, TRUE, dev->motorcfg->parkhomemotormove);
15070 shadingtest1 (struct st_device *dev, SANE_Byte * Regs,
15082 RTS_DMA_Reset (dev);
15088 Write_Byte (dev->usb_handle, 0xee0b, Regs[0x060b]);
15095 Write_Byte (dev->usb_handle, 0xe9cf, Regs[0x01cf]);
15107 RTS_DMA_Write (dev, a | 0x14, 0,
15115 Write_Byte (dev->usb_handle, 0xee0b, Regs[0x060b]);