1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
|
/*
Copyright (C) 2001 Bertrik Sikken (bertrik@zonnet.nl)
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, see <https://www.gnu.org/licenses/>.
*/
/*
Core NIASH chip functions.
*/
#include <stdio.h> /* fopen, fread, fwrite, fclose etc */
#include <stdarg.h> /* va_list for vfprintf */
#include <string.h> /* memcpy, memset */
#include <unistd.h> /* unlink */
#include <stdlib.h> /* malloc, free */
#include <math.h> /* exp, pow */
#include "niash_xfer.h"
#include "niash_core.h"
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
#define XFER_BUF_SIZE 0xF000
/* HP3400 firmware data */
static unsigned char abData0000[] = {
0xfe, 0x9f, 0x58, 0x1b, 0x00, 0x03, 0xa4, 0x02, 0x63, 0x02, 0x33, 0x02,
0x0d, 0x02, 0xf0, 0x01,
0xd8, 0x01, 0xc5, 0x01, 0xb5, 0x01, 0xa8, 0x01, 0x9d, 0x01, 0x93, 0x01,
0x8b, 0x01, 0x84, 0x01,
0x7e, 0x01, 0x79, 0x01, 0x74, 0x01, 0x70, 0x01, 0x6d, 0x01, 0x69, 0x01,
0x67, 0x01, 0x64, 0x01,
0x62, 0x01, 0x60, 0x01, 0x5f, 0x01, 0x5d, 0x01, 0x5c, 0x01, 0x5b, 0x01,
0x5a, 0x01, 0x59, 0x01,
0x58, 0x01, 0x57, 0x01, 0x57, 0x01, 0x56, 0x01, 0x56, 0x01, 0x55, 0x01,
0x55, 0x01, 0x54, 0x01,
0x54, 0x01, 0x54, 0x01, 0x54, 0x01, 0x53, 0x01, 0x53, 0x01, 0x53, 0x01,
0x53, 0x01, 0x52, 0x81
};
/* 1st word : 0x9ffe = 40958, strip 15th bit: 0x1ffe = 8190
2nd word : 0x1b58 = 7000 -> coincidence ?
other words: formula: y = 676 / (2 - exp(0.113 * (1-x)) ), where x = 0 for first entry
*/
/* more HP3400 firmware data */
static unsigned char abData0400[] = {
0xa4, 0x82, 0x00, 0x80, 0xa4, 0x82, 0xaa, 0x02, 0xc0, 0x02, 0xe8, 0x02,
0x3e, 0x03, 0xc8, 0x03,
0x58, 0x1b, 0xfe, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
static void
_ConvertMotorTable (unsigned char *pabOld, unsigned char *pabNew, int iSize,
int iLpi)
{
int iData, i, iBit15;
for (i = 0; i < (iSize / 2); i++)
{
iData = pabOld[2 * i + 0] + (pabOld[2 * i + 1] << 8);
iBit15 = (iData & 0x8000);
iData = (iData & 0x7FFF);
if (iData <= 0x400)
{
iData = iData * iLpi / 300;
}
if (iBit15 != 0)
{
iData |= 0x8000;
}
pabNew[2 * i + 0] = iData & 255;
pabNew[2 * i + 1] = (iData >> 8) & 255;
}
}
/*************************************************************************
_ProbeRegisters
===============
Tries to determine certain hardware properties.
This is done by checking the writeability of some scanner registers.
We cannot rely simply on the scanner model to contain a specific
chip. The HP3300c for example uses one of at least three slightly
different scanner ASICs (NIASH00012, NIASH00013 and NIASH00014).
OUT pHWParams Hardware parameters, updated fields:
fGamma16 TRUE if 16 bit gamma tables can be used
fReg07 TRUE if reg07 is writeable
iBufferSize Size of scanner's internal buffer
Returns TRUE if a NIASH chipset was found.
*************************************************************************/
static SANE_Bool
_ProbeRegisters (THWParams * pHWParams)
{
unsigned char bData1, bData2;
int iHandle;
iHandle = pHWParams->iXferHandle;
DBG (DBG_MSG, "Probing scanner...\n");
/* check register 0x04 */
NiashWriteReg (iHandle, 0x04, 0x55);
NiashReadReg (iHandle, 0x04, &bData1);
NiashWriteReg (iHandle, 0x04, 0xAA);
NiashReadReg (iHandle, 0x04, &bData2);
NiashWriteReg (iHandle, 0x04, 0x07);
if ((bData1 != 0x55) || (bData2 != 0xAA))
{
DBG (DBG_ERR, " No NIASH chipset found!\n");
return SANE_FALSE;
}
/* check writeability of register 3 bit 1 */
NiashReadReg (iHandle, 0x03, &bData1);
NiashWriteReg (iHandle, 0x03, bData1 | 0x02);
NiashReadReg (iHandle, 0x03, &bData2);
NiashWriteReg (iHandle, 0x03, bData1);
pHWParams->fGamma16 = ((bData2 & 0x02) != 0);
DBG (DBG_MSG, " Gamma table entries are %d bit\n",
pHWParams->fGamma16 ? 16 : 8);
/* check register 0x07 */
NiashReadReg (iHandle, 0x07, &bData1);
NiashWriteReg (iHandle, 0x07, 0x1C);
NiashReadReg (iHandle, 0x07, &bData2);
NiashWriteReg (iHandle, 0x07, bData1);
pHWParams->fReg07 = (bData2 == 0x1C);
if (!pHWParams->fGamma16)
{
/* internal scan buffer size is an educated guess, but seems to correlate
well with the size calculated from several windows driver log files
size = 128kB - 44088 unsigned chars (space required for gamma/calibration table)
*/
pHWParams->iBufferSize = 86984L;
DBG (DBG_MSG, " NIASH version < 00014\n");
}
else
{
pHWParams->iBufferSize = 0x60000L;
if (!pHWParams->fReg07)
{
DBG (DBG_MSG, " NIASH version = 00014\n");
}
else
{
DBG (DBG_MSG, " NIASH version > 00014\n");
}
}
return SANE_TRUE;
}
/* returns 0 on success, < 0 otherwise */
STATIC int
NiashOpen (THWParams * pHWParams, const char *pszName)
{
int iXferHandle;
iXferHandle = NiashXferOpen (pszName, &pHWParams->eModel);
if (iXferHandle < 0)
{
DBG (DBG_ERR, "NiashXferOpen failed for '%s'\n", pszName);
return -1;
}
pHWParams->iXferHandle = iXferHandle;
NiashWakeup (pHWParams->iXferHandle);
/* default HW params */
pHWParams->iSensorSkew = 8;
pHWParams->iTopLeftX = 0;
pHWParams->iTopLeftY = 3;
pHWParams->fReg07 = SANE_FALSE;
pHWParams->iSkipLines = 0;
pHWParams->iExpTime = 5408;
pHWParams->iReversedHead = SANE_TRUE;
switch (pHWParams->eModel)
{
case eHp3300c:
DBG (DBG_MSG, "Setting params for Hp3300\n");
pHWParams->iTopLeftX = 4;
pHWParams->iTopLeftY = 11;
pHWParams->iSkipLines = 14;
break;
case eHp3400c:
case eHp4300c:
DBG (DBG_MSG, "Setting params for Hp3400c/Hp4300c\n");
pHWParams->iTopLeftX = 3;
pHWParams->iTopLeftY = 14;
pHWParams->fReg07 = SANE_TRUE;
break;
case eAgfaTouch:
DBG (DBG_MSG, "Setting params for AgfaTouch\n");
pHWParams->iReversedHead = SANE_FALSE; /* head not reversed on Agfa Touch */
pHWParams->iTopLeftX = 3;
pHWParams->iTopLeftY = 10;
pHWParams->iSkipLines = 7;
break;
case eUnknownModel:
DBG (DBG_MSG, "Setting params for UnknownModel\n");
break;
default:
DBG (DBG_ERR, "ERROR: internal error! (%d)\n", (int) pHWParams->eModel);
return -1;
}
/* autodetect some hardware properties */
if (!_ProbeRegisters (pHWParams))
{
DBG (DBG_ERR, "_ProbeRegisters failed!\n");
return -1;
}
return 0;
}
STATIC void
NiashClose (THWParams * pHWPar)
{
NiashXferClose (pHWPar->iXferHandle);
pHWPar->iXferHandle = 0;
}
static void
WriteRegWord (int iHandle, unsigned char bReg, SANE_Word wData)
{
NiashWriteReg (iHandle, bReg, wData & 0xFF);
NiashWriteReg (iHandle, bReg + 1, (wData >> 8) & 0xFF);
}
/* calculate a 4096 unsigned char gamma table */
STATIC void
CalcGamma (unsigned char *pabTable, double Gamma)
{
int i, iData;
/* fill gamma table */
for (i = 0; i < 4096; i++)
{
iData = floor (256.0 * pow (((double) i / 4096.0), 1.0 / Gamma));
pabTable[i] = iData;
}
}
/*
Hp3400WriteFw
=============
Writes data to scanners with a NIASH00019 chipset, e.g.
gamma, calibration and motor control data.
IN pabData pointer to firmware data
iLen Size of firmware date (unsigned chars)
iAddr Scanner address to write to
*/
static void
Hp3400cWriteFW (int iXferHandle, unsigned char *pabData, int iLen, int iAddr)
{
iAddr--;
NiashWriteReg (iXferHandle, 0x21, iAddr & 0xFF);
NiashWriteReg (iXferHandle, 0x22, (iAddr >> 8) & 0xFF);
NiashWriteReg (iXferHandle, 0x23, (iAddr >> 16) & 0xFF);
NiashWriteBulk (iXferHandle, pabData, iLen);
}
/* Writes the gamma and offset/gain tables to the scanner.
In case a calibration file exist, it will be used for offset/gain */
STATIC void
WriteGammaCalibTable (unsigned char *pabGammaR, unsigned char *pabGammaG,
unsigned char *pabGammaB, unsigned char *pabCalibTable,
int iGain, int iOffset, THWParams * pHWPar)
{
int i, j, k;
static unsigned char abGamma[60000];
int iData;
int iHandle;
iHandle = pHWPar->iXferHandle;
j = 0;
/* fill gamma table for red component */
/* pad entries with 0 for 16-bit gamma table */
for (i = 0; i < 4096; i++)
{
if (pHWPar->fGamma16)
{
abGamma[j++] = 0;
}
abGamma[j++] = pabGammaR[i];
}
/* fill gamma table for green component */
for (i = 0; i < 4096; i++)
{
if (pHWPar->fGamma16)
{
abGamma[j++] = 0;
}
abGamma[j++] = pabGammaG[i];
}
/* fill gamma table for blue component */
for (i = 0; i < 4096; i++)
{
if (pHWPar->fGamma16)
{
abGamma[j++] = 0;
}
abGamma[j++] = pabGammaB[i];
}
if (pabCalibTable == NULL)
{
iData = (iGain << 6) + iOffset;
for (i = 0; i < HW_PIXELS; i++)
{
for (k = 0; k < 3; k++)
{
abGamma[j++] = (iData) & 255;
abGamma[j++] = (iData >> 8) & 255;
}
}
}
else
{
memcpy (&abGamma[j], pabCalibTable, HW_PIXELS * 6);
j += HW_PIXELS * 6;
}
NiashWriteReg (iHandle, 0x02, 0x80);
NiashWriteReg (iHandle, 0x03, 0x01);
NiashWriteReg (iHandle, 0x03, 0x11);
NiashWriteReg (iHandle, 0x02, 0x84);
if (pHWPar->fReg07)
{
Hp3400cWriteFW (iHandle, abGamma, j, 0x2000);
}
else
{
NiashWriteBulk (iHandle, abGamma, j);
}
NiashWriteReg (iHandle, 0x02, 0x80);
}
static void
WriteAFEReg (int iHandle, int iReg, int iData)
{
NiashWriteReg (iHandle, 0x25, iReg);
NiashWriteReg (iHandle, 0x26, iData);
}
/* setup the analog front-end -> coarse calibration */
static void
WriteAFE (int iHandle)
{
/* see WM8143 datasheet */
WriteAFEReg (iHandle, 0x04, 0x00);
WriteAFEReg (iHandle, 0x03, 0x12);
WriteAFEReg (iHandle, 0x02, 0x04);
WriteAFEReg (iHandle, 0x05, 0x10);
WriteAFEReg (iHandle, 0x01, 0x03);
WriteAFEReg (iHandle, 0x20, 0xc0); /*c8 *//* red offset */
WriteAFEReg (iHandle, 0x21, 0xc0); /*c8 *//* green offset */
WriteAFEReg (iHandle, 0x22, 0xc0); /*d0 *//* blue offset */
WriteAFEReg (iHandle, 0x28, 0x05); /*5 *//* red gain */
WriteAFEReg (iHandle, 0x29, 0x03); /*3 *//* green gain */
WriteAFEReg (iHandle, 0x2A, 0x04); /*4 *//* blue gain */
}
/* wait for the carriage to return */
static void
WaitReadyBit (int iHandle)
{
unsigned char bData;
do
{
NiashReadReg (iHandle, 0x03, &bData);
}
while ((bData & 8) == 0);
}
/*
Initialisation specific for NIASH00014 and lower chips
*/
static void
InitNiash00014 (TScanParams * pParams, THWParams * pHWParams)
{
int iHandle, iLpiCode;
iHandle = pHWParams->iXferHandle;
/* exposure time (in units 24/Fcrystal)? */
WriteRegWord (iHandle, 0x08, pHWParams->iExpTime - 1);
/* width in pixels */
WriteRegWord (iHandle, 0x12, pParams->iWidth - 1);
/* top */
WriteRegWord (iHandle, 0x17, pParams->iTop);
WriteRegWord (iHandle, 0x19, pParams->iTop);
/* time between stepper motor steps (in units of 24/Fcrystal)? */
iLpiCode = pParams->iLpi * pHWParams->iExpTime / 1200L;
if (!pHWParams->fGamma16)
{
/* NIASH 00012 / 00013 init */
/* LPI specific settings */
if (pParams->iLpi < 600)
{
/* set halfres bit */
NiashWriteReg (iHandle, 0x06, 0x01);
/* double lpi code because of halfres bit */
iLpiCode *= 2;
}
else
{
/* clear halfres bit */
NiashWriteReg (iHandle, 0x06, 0x00);
/* add exptime to make it scan slower */
iLpiCode += pHWParams->iExpTime;
}
/* unknown setting */
WriteRegWord (iHandle, 0x27, 0x7FD2);
WriteRegWord (iHandle, 0x29, 0x6421);
}
else
{
/* NIASH 00014 init */
/* halfres bit always cleared */
NiashWriteReg (iHandle, 0x06, 0x00);
/* LPI specific settings */
if (pParams->iLpi >= 600)
{
/* add exptime to make it scan slower */
iLpiCode += pHWParams->iExpTime;
}
/* unknown setting */
WriteRegWord (iHandle, 0x27, 0xc862); /*c862 */
WriteRegWord (iHandle, 0x29, 0xb853); /*b853 */
}
/* LPI code */
WriteRegWord (iHandle, 0x0A, iLpiCode - 1);
/* backtrack reversing speed */
NiashWriteReg (iHandle, 0x1E, (iLpiCode - 1) / 32);
}
/*
Initialisation specific for NIASH00019 chips
*/
static void
InitNiash00019 (TScanParams * pParams, THWParams * pHWParams)
{
int iHandle, iLpiCode;
static unsigned char abMotor[512];
iHandle = pHWParams->iXferHandle;
/* exposure time (in units 24/Fcrystal)? */
WriteRegWord (iHandle, 0x08, pHWParams->iExpTime);
/* width in pixels */
WriteRegWord (iHandle, 0x12, pParams->iWidth);
/* ? */
WriteRegWord (iHandle, 0x27, 0xc862); /*c862 */
WriteRegWord (iHandle, 0x29, 0xb853); /*b853 */
/* specific handling of 150 dpi resolution */
if (pParams->iLpi == 150)
{
/* use 300 LPI but skip every other line */
pParams->iLpi = 300;
NiashWriteReg (iHandle, 0x06, 0x01);
}
else
{
NiashWriteReg (iHandle, 0x06, 0x00);
}
/* DPI and position table */
NiashWriteReg (iHandle, 0x07, 0x02);
_ConvertMotorTable (abData0000, abMotor, sizeof (abData0000),
pParams->iLpi);
Hp3400cWriteFW (iHandle, abMotor, sizeof (abData0000), 0x000);
_ConvertMotorTable (abData0400, abMotor, sizeof (abData0400),
pParams->iLpi);
Hp3400cWriteFW (iHandle, abMotor, sizeof (abData0400), 0x400);
/* backtrack reversing speed */
iLpiCode = pParams->iLpi * pHWParams->iExpTime / 1200L;
NiashWriteReg (iHandle, 0x1E, (iLpiCode - 1) / 32);
}
/*
Scanner initialisation common to all NIASH chips
*/
static void
InitNiashCommon (TScanParams * pParams, THWParams * pHWParams)
{
int iWidthHW, iHandle, iMaxLevel;
iHandle = pHWParams->iXferHandle;
NiashWriteReg (iHandle, 0x02, 0x80);
NiashWriteReg (iHandle, 0x03, 0x11);
NiashWriteReg (iHandle, 0x01, 0x8B);
NiashWriteReg (iHandle, 0x05, 0x01);
/* dpi */
WriteRegWord (iHandle, 0x0C, pParams->iDpi);
/* calculate width in units of HW resolution */
iWidthHW = pParams->iWidth * (HW_DPI / pParams->iDpi);
/* set left and right limits */
if (pHWParams->iReversedHead)
{
/* head is reversed */
/* right */
WriteRegWord (iHandle, 0x0E,
3 * (HW_PIXELS - (pParams->iLeft + iWidthHW)));
/* left */
WriteRegWord (iHandle, 0x10, 3 * (HW_PIXELS - pParams->iLeft) - 1);
}
else
{
/* head is not reversed */
/*left */
WriteRegWord (iHandle, 0x0E, 3 * pParams->iLeft);
/* right */
WriteRegWord (iHandle, 0x10, 3 * (pParams->iLeft + iWidthHW) - 1);
}
/* bottom */
WriteRegWord (iHandle, 0x1B, pParams->iBottom); /* 0x393C); */
/* forward jogging speed */
NiashWriteReg (iHandle, 0x1D, 0x60);
/* backtrack reversing speed? */
NiashWriteReg (iHandle, 0x2B, 0x15);
/* backtrack distance */
if (pParams->iLpi < 600)
{
NiashWriteReg (iHandle, 0x1F, 0x30);
}
else
{
NiashWriteReg (iHandle, 0x1F, 0x18);
}
/* max buffer level before backtrace */
iMaxLevel = MIN (pHWParams->iBufferSize / pParams->iWidth, 250);
NiashWriteReg (iHandle, 0x14, iMaxLevel - 1);
/* lamp PWM, max = 0x1ff? */
WriteRegWord (iHandle, 0x2C, 0x01FF);
/* not needed? */
NiashWriteReg (iHandle, 0x15, 0x90); /* 90 */
NiashWriteReg (iHandle, 0x16, 0x70); /* 70 */
WriteAFE (iHandle);
WaitReadyBit (iHandle);
NiashWriteReg (iHandle, 0x03, 0x05);
NiashWriteReg (iHandle, 0x02, pParams->fCalib ? 0x88 : 0xA8);
}
/* write registers */
STATIC SANE_Bool
InitScan (TScanParams * pParams, THWParams * pHWParams)
{
int iHeight;
int iExpTime;
TScanParams Params;
/* check validity of scanparameters */
switch (pParams->iDpi)
{
case 150:
case 300:
case 600:
break;
default:
DBG (DBG_ERR, "Invalid dpi (%d)\n", pParams->iDpi);
return SANE_FALSE;
}
iHeight = (pParams->iBottom - pParams->iTop + 1);
if (iHeight <= 0)
{
DBG (DBG_ERR, "Invalid height (%d)\n", iHeight);
return SANE_FALSE;
}
if (pParams->iWidth <= 0)
{
DBG (DBG_ERR, "Invalid width (%d)\n", pParams->iWidth);
return SANE_FALSE;
}
switch (pParams->iLpi)
{
case 150:
case 300:
case 600:
break;
default:
DBG (DBG_ERR, "Invalid lpi (%d)\n", pParams->iLpi);
return SANE_FALSE;
}
/* exposure time (in units of 24/Fcrystal?), must be divisible by 8 !!! */
iExpTime = 5408;
if ((iExpTime % 8) != 0)
{
DBG (DBG_ERR, "Invalid exposure time (%d)\n", iExpTime);
return SANE_FALSE;
}
/*
*** Done checking scan parameters validity ***
*/
/*
copy the parameters locally and make pParams point to the local copy
*/
memcpy (&Params, pParams, sizeof (Params));
pParams = &Params;
if (!pHWParams->fReg07)
{
/* init NIASH00014 and lower */
InitNiash00014 (pParams, pHWParams);
}
else
{
/* init NIASH00019 */
InitNiash00019 (pParams, pHWParams);
}
/* common NIASH init */
InitNiashCommon (pParams, pHWParams);
return SANE_TRUE;
}
/************************************************************************/
static SANE_Bool
XferBufferGetLine (int iHandle, TDataPipe * p, unsigned char *pabLine,
SANE_Bool fReturn)
{
unsigned char bData, bData2;
SANE_Bool fJustDone = SANE_FALSE;
/* all calculated transfers done ? */
if (p->iLinesLeft == 0)
return SANE_FALSE;
/* time for a fresh read? */
if (p->iCurLine == 0)
{
int iLines;
iLines = p->iLinesPerXferBuf;
/* read only as many lines as needed */
if (p->iLinesLeft > 0 && p->iLinesLeft <= iLines)
{
iLines = p->iLinesLeft;
DBG (DBG_MSG, "\n");
DBG (DBG_MSG, "last bulk read\n");
if (iLines < p->iLinesPerXferBuf)
{
DBG (DBG_MSG,
"reading reduced number of lines: %d instead of %d\n",
iLines, p->iLinesPerXferBuf);
}
fJustDone = SANE_TRUE;
}
/* reading old buffer level */
NiashReadReg (iHandle, 0x20, &bData);
NiashReadBulk (iHandle, p->pabXferBuf, iLines * p->iBytesPerLine);
/* reding new buffer level */
NiashReadReg (iHandle, 0x20, &bData2);
if (fJustDone && fReturn)
{
NiashWriteReg (iHandle, 0x02, 0x80);
DBG (DBG_MSG, "returning scanner head\n");
}
DBG (DBG_MSG,
"buffer level = %3d, <reading %5d unsigned chars>, buffer level = %3d\r",
(int) bData, iLines * p->iBytesPerLine, (int) bData2);
fflush (stdout);
}
/* copy one line */
if (pabLine != NULL)
{
memcpy (pabLine, &p->pabXferBuf[p->iCurLine * p->iBytesPerLine],
p->iBytesPerLine);
}
/* advance pointer */
p->iCurLine = (p->iCurLine + 1) % p->iLinesPerXferBuf;
/* one transfer line less to the XFerBuffer */
if (p->iLinesLeft > 0)
--(p->iLinesLeft);
return SANE_TRUE;
}
static void
XferBufferInit (int iHandle, TDataPipe * p)
{
int i;
p->pabXferBuf = (unsigned char *) malloc (XFER_BUF_SIZE);
p->iCurLine = 0;
/* skip garbage lines */
for (i = 0; i < p->iSkipLines; i++)
{
XferBufferGetLine (iHandle, p, NULL, SANE_FALSE);
}
}
/* static procedure that fills the circular buffer in advance to any
circular buffer data retrieval */
static void
CircBufferFill (int iHandle, TDataPipe * p, SANE_Bool iReversedHead)
{
int i;
for (i = 0; i < p->iLinesPerCircBuf; i++)
{
if (iReversedHead)
{
XferBufferGetLine (iHandle, p,
&p->pabCircBuf[p->iRedLine * p->iBytesPerLine],
SANE_FALSE);
}
else
{
XferBufferGetLine (iHandle, p,
&p->pabCircBuf[p->iBluLine * p->iBytesPerLine],
SANE_FALSE);
}
/* advance pointers */
p->iRedLine = (p->iRedLine + 1) % p->iLinesPerCircBuf;
p->iGrnLine = (p->iGrnLine + 1) % p->iLinesPerCircBuf;
p->iBluLine = (p->iBluLine + 1) % p->iLinesPerCircBuf;
}
}
static void
XferBufferExit (TDataPipe * p)
{
if (p->pabXferBuf != NULL)
{
free (p->pabXferBuf);
p->pabXferBuf = NULL;
}
else
{
DBG (DBG_ERR, "XferBufExit: Xfer buffer not initialised!\n");
}
}
/* unscrambles a line:
- combining the proper R, G and B lines and converting them to interpixel RGB
- mirroring left to right
*/
static void
_UnscrambleLine (unsigned char *pabLine,
unsigned char *pabRed, unsigned char *pabGrn,
unsigned char *pabBlu, int iWidth, SANE_Bool iReversedHead,
int iScaleDownDpi, int iBufWeight)
{
/* never change an approved algorithm ...
so take Bertriks original source for this special case */
if (iScaleDownDpi == 1 && iBufWeight == 0)
{
int i, j;
if (iReversedHead)
{
/* reversed */
for (i = 0; i < iWidth; i++)
{
j = (iWidth - i) * 3;
pabLine[j - 3] = pabRed[i];
pabLine[j - 2] = pabGrn[i + iWidth];
pabLine[j - 1] = pabBlu[i + iWidth * 2];
}
}
else
{
/* not reversed */
for (i = 0; i < iWidth; i++)
{
pabLine[3 * i] = pabRed[i];
pabLine[3 * i + 1] = pabGrn[i + iWidth];
pabLine[3 * i + 2] = pabBlu[i + iWidth * 2];
}
}
}
else
{
int i, j; /* loop variables */
int c; /* color buffer accumulator for horizontal average */
/* initialize for incremental color buffer access */
int iInc = 1;
int iStart = 0;
/* set for "from the end to the front" of the circular color buffers */
if (iReversedHead)
{
iStart = iWidth - iScaleDownDpi;
iInc = -1;
}
/* each pixel is the mean of iScaleDownDpi
so set the skip width accordingly */
iInc *= iScaleDownDpi;
for (i = iStart; i >= 0 && i < iWidth; i += iInc)
{
/* collect the red pixels */
for (c = j = 0; j < iScaleDownDpi; ++j)
c += pabRed[i + j];
*pabLine =
(*pabLine * iBufWeight + c / iScaleDownDpi) / (iBufWeight + 1);
pabLine++;
/* collect the green pixels */
for (c = j = 0; j < iScaleDownDpi; ++j)
c += pabGrn[i + iWidth + j];
*pabLine =
(*pabLine * iBufWeight + c / iScaleDownDpi) / (iBufWeight + 1);
pabLine++;
/* collect the blue pixels */
for (c = j = 0; j < iScaleDownDpi; ++j)
c += pabBlu[i + 2 * iWidth + j];
*pabLine =
(*pabLine * iBufWeight + c / iScaleDownDpi) / (iBufWeight + 1);
pabLine++;
}
}
}
/* gets an unscrambled line from the circular buffer. the first couple of lines contain garbage,
if fReturn==SANE_TRUE, the head will return automatically on an end of scan */
STATIC SANE_Bool
CircBufferGetLineEx (int iHandle, TDataPipe * p, unsigned char *pabLine,
SANE_Bool iReversedHead, SANE_Bool fReturn)
{
int iLineCount;
for (iLineCount = 0; iLineCount < p->iScaleDownLpi; ++iLineCount)
{
if (iReversedHead)
{
if (!XferBufferGetLine (iHandle, p,
&p->pabCircBuf[p->iRedLine *
p->iBytesPerLine], fReturn))
return SANE_FALSE;
}
else
{
if (!XferBufferGetLine (iHandle, p,
&p->pabCircBuf[p->iBluLine *
p->iBytesPerLine], fReturn))
return SANE_FALSE;
}
if (pabLine != NULL)
{
_UnscrambleLine (pabLine,
&p->pabCircBuf[p->iRedLine * p->iBytesPerLine],
&p->pabCircBuf[p->iGrnLine * p->iBytesPerLine],
&p->pabCircBuf[p->iBluLine * p->iBytesPerLine],
p->iWidth * p->iScaleDownDpi, iReversedHead,
p->iScaleDownDpi, iLineCount);
}
/* advance pointers */
p->iRedLine = (p->iRedLine + 1) % p->iLinesPerCircBuf;
p->iGrnLine = (p->iGrnLine + 1) % p->iLinesPerCircBuf;
p->iBluLine = (p->iBluLine + 1) % p->iLinesPerCircBuf;
}
return SANE_TRUE;
}
/* gets an unscrambled line from the circular buffer. the first couple of lines contain garbage */
STATIC SANE_Bool
CircBufferGetLine (int iHandle, TDataPipe * p, unsigned char *pabLine,
SANE_Bool iReversedHead)
{
return CircBufferGetLineEx (iHandle, p, pabLine, iReversedHead, SANE_FALSE);
}
/* try to keep the number of transfers the same, but make them all
as good as possible the same size to avoid cranking in critical
situations
*/
static int
_OptimizeXferSize (int iLines, int iLinesPerXfer)
{
int iXfers;
iXfers = (iLines + iLinesPerXfer - 1) / iLinesPerXfer;
while (--iLinesPerXfer > 0
&& (iLines + iLinesPerXfer - 1) / iLinesPerXfer == iXfers);
return iLinesPerXfer + 1;
}
STATIC void
CircBufferInit (int iHandle, TDataPipe * p,
int iWidth, int iHeight,
int iMisAlignment, SANE_Bool iReversedHead,
int iScaleDownDpi, int iScaleDownLpi)
{
/* relevant for internal read and write functions */
p->iScaleDownLpi = iScaleDownLpi;
p->iScaleDownDpi = iScaleDownDpi;
p->iWidth = iWidth;
p->iBytesPerLine = iWidth * iScaleDownDpi * BYTES_PER_PIXEL;
p->iSaneBytesPerLine = iWidth * BYTES_PER_PIXEL;
if (iMisAlignment == 0)
{
p->iLinesPerCircBuf = 1;
}
else
{
p->iLinesPerCircBuf = 3 * iMisAlignment;
}
DBG (DBG_MSG, "_iScaleDown (Dpi,Lpi) = (%d,%d)\n", p->iScaleDownDpi,
p->iScaleDownLpi);
DBG (DBG_MSG, "_iBytesPerLine = %d\n", p->iBytesPerLine);
DBG (DBG_MSG, "_iLinesPerCircBuf = %d\n", p->iLinesPerCircBuf);
p->pabCircBuf =
(unsigned char *) malloc (p->iBytesPerLine * p->iLinesPerCircBuf);
if (p->pabCircBuf == NULL)
{
DBG (DBG_ERR,
"Unable to allocate %d unsigned chars for circular buffer\n",
(int) (p->iBytesPerLine * p->iLinesPerCircBuf));
return;
}
DBG (DBG_MSG, "Allocated %d unsigned chars for circular buffer\n",
p->iBytesPerLine * p->iLinesPerCircBuf);
if (iReversedHead)
{
p->iBluLine = 0;
p->iGrnLine = iMisAlignment;
p->iRedLine = iMisAlignment * 2;
}
else
{
p->iRedLine = 0;
p->iGrnLine = iMisAlignment;
p->iBluLine = iMisAlignment * 2;
}
/* negative height is an indication for "no Check" */
if (iHeight < 0)
{
p->iLinesLeft = -1;
p->iLinesPerXferBuf = XFER_BUF_SIZE / p->iBytesPerLine;
DBG (DBG_MSG, "using unchecked XFER_BUF_SIZE\n");
DBG (DBG_MSG, "_iXFerSize = %d\n",
p->iBytesPerLine * p->iLinesPerXferBuf);
}
else
{
#define SAFETY_LINES 0
#define MAX_LINES_PER_XFERBUF 800
/* estimate of number of unsigned chars to transfer at all via the USB */
/* add some lines for security */
p->iLinesLeft =
iHeight + p->iSkipLines + p->iLinesPerCircBuf + SAFETY_LINES;
p->iLinesPerXferBuf = XFER_BUF_SIZE / p->iBytesPerLine;
/* with more than 800 lines the timing is spoiled */
if (p->iLinesPerXferBuf > MAX_LINES_PER_XFERBUF)
{
p->iLinesPerXferBuf = MAX_LINES_PER_XFERBUF;
}
/* final optimization to keep critical scans smooth */
p->iLinesPerXferBuf =
_OptimizeXferSize (p->iLinesLeft, p->iLinesPerXferBuf);
DBG (DBG_MSG, "_iXFerSize = %d for %d transfer(s)\n",
(int) p->iLinesPerXferBuf * p->iBytesPerLine,
(p->iLinesLeft + p->iLinesPerXferBuf - 1) / p->iLinesPerXferBuf);
}
DBG (DBG_MSG, "_iLinesPerXferBuf = %d\n", p->iLinesPerXferBuf);
/* init transfer buffer */
XferBufferInit (iHandle, p);
/* fill circular buffer */
CircBufferFill (iHandle, p, iReversedHead);
}
STATIC void
CircBufferExit (TDataPipe * p)
{
XferBufferExit (p);
if (p->pabCircBuf != NULL)
{
DBG (DBG_MSG, "\n");
free (p->pabCircBuf);
p->pabCircBuf = NULL;
}
else
{
DBG (DBG_ERR, "CircBufferExit: Circular buffer not initialised!\n");
}
}
/************************************************************************/
static int
_CalcAvg (unsigned char *pabBuf, int n, int iStep)
{
int i, j, x;
for (i = j = x = 0; i < n; i++)
{
x += pabBuf[j];
j += iStep;
}
return (x / n);
}
/* converts white line data and black point data into a calibration table */
static void
CreateCalibTable (unsigned char *abWhite, unsigned char bBlackR,
unsigned char bBlackG, unsigned char bBlackB,
int iReversedHead, unsigned char *pabCalibTable)
{
int i, j, iGain, iOffset, iData;
unsigned char *pabPixel;
j = 0;
for (i = 0; i < HW_PIXELS; i++)
{
if (iReversedHead)
{
pabPixel = &abWhite[(HW_PIXELS - i - 1) * 3];
}
else
{
pabPixel = &abWhite[i * 3];
}
/* red */
if (bBlackR > 16)
bBlackR = 16;
iGain = 65536 / MAX (1, pabPixel[0] - bBlackR);
iOffset = bBlackR * 4;
if (iOffset > 63)
iOffset = 63;
iData = (iGain << 6) + iOffset;
pabCalibTable[j++] = (iData) & 255;
pabCalibTable[j++] = (iData >> 8) & 255;
/* green */
if (bBlackG > 16)
bBlackG = 16;
iGain = 65536 / MAX (1, pabPixel[1] - bBlackG);
iOffset = bBlackG * 4;
if (iOffset > 63)
iOffset = 63;
iData = (iGain << 6) + iOffset;
pabCalibTable[j++] = (iData) & 255;
pabCalibTable[j++] = (iData >> 8) & 255;
/* blue */
if (bBlackB > 16)
bBlackB = 16;
iGain = 65536 / MAX (1, pabPixel[2] - bBlackB);
iOffset = bBlackB * 4;
if (iOffset > 63)
iOffset = 63;
iData = (iGain << 6) + iOffset;
pabCalibTable[j++] = (iData) & 255;
pabCalibTable[j++] = (iData >> 8) & 255;
}
}
/*************************************************************************
Lamp control functions
*************************************************************************/
STATIC SANE_Bool
GetLamp (THWParams * pHWParams, SANE_Bool * pfLampIsOn)
{
unsigned char bData;
NiashReadReg (pHWParams->iXferHandle, 0x03, &bData);
*pfLampIsOn = ((bData & 0x01) != 0);
return SANE_TRUE;
}
STATIC SANE_Bool
SetLamp (THWParams * pHWParams, SANE_Bool fLampOn)
{
unsigned char bData;
int iHandle;
iHandle = pHWParams->iXferHandle;
NiashReadReg (iHandle, 0x03, &bData);
if (fLampOn)
{
NiashWriteReg (iHandle, 0x03, bData | 0x01);
}
else
{
NiashWriteReg (iHandle, 0x03, bData & ~0x01);
}
return SANE_TRUE;
}
/*************************************************************************
Experimental simple calibration, but also returning the white levels
*************************************************************************/
STATIC SANE_Bool
SimpleCalibExt (THWParams * pHWPar, unsigned char *pabCalibTable,
unsigned char *pabCalWhite)
{
unsigned char bMinR, bMinG, bMinB;
TDataPipe DataPipe;
TScanParams Params;
unsigned char abGamma[4096];
int i, j;
static unsigned char abBuf[HW_PIXELS * 3 * 71]; /* Careful : see startWhite and endWhite below */
static unsigned char abLine[HW_PIXELS * 3];
static unsigned char abWhite[HW_PIXELS * 3];
unsigned char *pabWhite;
int iWhiteR, iWhiteG, iWhiteB;
int iHandle;
SANE_Bool iReversedHead;
int startWhiteY, endWhiteY;
int startBlackY, endBlackY;
int endBlackX;
iHandle = pHWPar->iXferHandle;
iReversedHead = pHWPar->iReversedHead;
DataPipe.iSkipLines = pHWPar->iSkipLines;
Params.iDpi = HW_DPI;
Params.iLpi = HW_DPI;
if (iReversedHead) /* hp scanners */
Params.iTop = 60;
else /* agfa scanners */
Params.iTop = 30;
Params.iBottom = HP3300C_BOTTOM;
Params.iLeft = 0;
Params.iWidth = HW_PIXELS;
Params.iHeight = 54;
Params.fCalib = SANE_TRUE;
/* write gamma table with neutral gain / offset */
CalcGamma (abGamma, 1.0);
WriteGammaCalibTable (abGamma, abGamma, abGamma, NULL, 256, 0, pHWPar);
if (!InitScan (&Params, pHWPar))
{
if (pabCalWhite)
pabCalWhite[0] = pabCalWhite[1] = pabCalWhite[2] = 0;
return SANE_FALSE;
}
/* Definition of white and black areas */
if (iReversedHead)
{ /* hp scanners */
startWhiteY = 0;
endWhiteY = 15;
startBlackY = 16;
endBlackY = 135;
endBlackX = HW_PIXELS;
}
else
{ /* agfa scanners */
startWhiteY = 0;
endWhiteY = 70;
startBlackY = 86;
endBlackY = 135;
endBlackX = 3374;
}
CircBufferInit (iHandle, &DataPipe, HW_PIXELS, -1, Params.iLpi / 150,
iReversedHead, 1, 1);
/* white level */
/* skip some lines */
for (i = 0; i < startWhiteY; i++)
{
CircBufferGetLine (iHandle, &DataPipe, abLine, iReversedHead);
}
/* Get white lines */
for (i = 0; i < endWhiteY - startWhiteY + 1; i++)
{
CircBufferGetLine (iHandle, &DataPipe, &abBuf[i * HW_PIXELS * 3],
iReversedHead);
}
/* black level */
bMinR = 255;
bMinG = 255;
bMinB = 255;
/* Skip some lines */
for (i = 0; i < startBlackY; i++)
{
CircBufferGetLine (iHandle, &DataPipe, abLine, iReversedHead);
}
for (i = 0; i < endBlackY - startBlackY + 1; i++)
{
CircBufferGetLine (iHandle, &DataPipe, abLine, iReversedHead);
for (j = 0; j < endBlackX; j++)
{
bMinR = MIN (abLine[j * 3 + 0], bMinR);
bMinG = MIN (abLine[j * 3 + 1], bMinG);
bMinB = MIN (abLine[j * 3 + 2], bMinB);
}
}
CircBufferExit (&DataPipe);
FinishScan (pHWPar);
/* calc average white level */
pabWhite = abBuf;
for (i = 0; i < HW_PIXELS; i++)
{
abWhite[i * 3 + 0] =
_CalcAvg (&pabWhite[i * 3 + 0], endWhiteY - startWhiteY + 1,
HW_PIXELS * 3);
abWhite[i * 3 + 1] =
_CalcAvg (&pabWhite[i * 3 + 1], endWhiteY - startWhiteY + 1,
HW_PIXELS * 3);
abWhite[i * 3 + 2] =
_CalcAvg (&pabWhite[i * 3 + 2], endWhiteY - startWhiteY + 1,
HW_PIXELS * 3);
}
iWhiteR = _CalcAvg (&abWhite[0], HW_PIXELS, 3);
iWhiteG = _CalcAvg (&abWhite[1], HW_PIXELS, 3);
iWhiteB = _CalcAvg (&abWhite[2], HW_PIXELS, 3);
DBG (DBG_MSG, "Black level (%d,%d,%d), White level (%d,%d,%d)\n",
(int) bMinR, (int) bMinG, (int) bMinB, iWhiteR, iWhiteG, iWhiteB);
/* convert the white line and black point into a calibration table */
CreateCalibTable (abWhite, bMinR, bMinG, bMinB, iReversedHead,
pabCalibTable);
/* assign the White Levels */
if (pabCalWhite)
{
pabCalWhite[0] = iWhiteR;
pabCalWhite[1] = iWhiteG;
pabCalWhite[2] = iWhiteB;
}
return SANE_TRUE;
}
/*************************************************************************
FinishScan
==========
Finishes the scan. Makes the scanner head move back to the home position.
*************************************************************************/
STATIC void
FinishScan (THWParams * pHWParams)
{
NiashWriteReg (pHWParams->iXferHandle, 0x02, 0x80);
}
|