Lines Matching defs:chip

58   ma1017 *chip;
64 chip = (ma1017 *) malloc (sizeof (ma1017));
66 if (!chip)
68 DBG (3, "usb_low_init: couldn't malloc %ld bytes for chip\n",
73 *chip_address = chip;
76 chip->is_rowing = SANE_FALSE;
77 chip->is_opened = SANE_FALSE;
78 chip->fd = -1;
81 chip->is_opened = SANE_FALSE;
82 chip->is_rowing = SANE_FALSE;
85 chip->append = 0x00;
86 chip->test_sram = 0x00;
87 chip->fix_pattern = 0x00;
89 chip->select = 0x00;
90 chip->frontend = 0x00;
92 chip->rgb_sel_pin = 0x02;
93 chip->asic_io_pins = 0x9c;
95 chip->timing = 0xe8;
96 chip->sram_bank = 0x02;
98 chip->dummy_msb = 0x00;
99 chip->ccd_width_msb = 0x00;
100 chip->cmt_table_length = 0x00;
102 chip->cmt_second_pos = 0x00;
104 chip->ccd_width = 0x0c80;
106 chip->dummy = 0x0020;
108 chip->byte_width = 0x09f6;
110 chip->loop_count = 0x0db5;
112 chip->motor_enable = 0x00;
113 chip->motor_movement = 0x60;
114 chip->motor_direction = 0x10;
115 chip->motor_signal = 0x00;
116 chip->motor_home = 0x00;
118 chip->pixel_depth = 0x00;
119 chip->image_invert = 0x00;
120 chip->optical_600 = 0x00;
121 chip->sample_way = 0x06;
123 chip->red_ref = 0xff;
124 chip->green_ref = 0xff;
125 chip->blue_ref = 0xff;
127 chip->red_pd = 0x00;
128 chip->green_pd = 0x00;
129 chip->blue_pd = 0x00;
131 chip->a23 = 0x80;
133 chip->fy1_delay = 0x00;
134 chip->special_ad = 0x00;
136 chip->sclk = 0x00;
137 chip->sen = 0x00;
138 chip->serial_length = 0x10;
141 chip->get_row = NULL;
143 chip->cmt_table_length_word = 0x00000000;
144 chip->cmt_second_pos_word = 0x00000000;
145 chip->row_size = 0x00;
146 chip->soft_resample = 0x01;
147 chip->total_lines = 0x00;
148 chip->lines_left = 0x00;
150 chip->is_transfer_table[i] = SANE_FALSE;
151 chip->sensor = ST_CANON600;
152 chip->motor = MT_1200;
154 chip->total_read_urbs = 0;
155 chip->total_write_urbs = 0;
161 usb_low_exit (ma1017 * chip)
163 DBG (7, "usb_low_exit: chip = %p\n", (void *) chip);
164 if (chip)
166 if (chip->fd >= 0 && chip->is_opened)
167 usb_low_close (chip);
168 DBG (7, "usb_low_exit: freeing chip\n");
169 free (chip);
172 chip->total_read_urbs, chip->total_write_urbs);
179 usb_low_set_cmt_table (ma1017 * chip, SANE_Int index, Channel channel,
188 if (!chip->is_opened)
193 if (chip->is_rowing)
225 RIE (usb_low_write_reg (chip, reg_no, pattern));
227 chip->is_transfer_table[index] = is_transfer;
236 usb_low_get_a2 (ma1017 * chip, SANE_Byte * value)
242 if (!chip->is_opened)
247 if (chip->is_rowing)
252 RIE (usb_low_read_reg (chip, 2, &pattern));
254 chip->append = pattern & 0x10;
255 chip->test_sram = pattern & 0x20;
256 chip->fix_pattern = pattern & 0x80;
264 usb_low_start_cmt_table (ma1017 * chip)
272 data_field[0] = 0x02 | chip->append | chip->test_sram | chip->fix_pattern;
275 if (!chip->is_opened)
280 if (chip->is_rowing)
288 status = sanei_usb_write_bulk (chip->fd, data_field, &n);
295 chip->total_write_urbs++;
296 chip->is_rowing = SANE_TRUE;
302 usb_low_stop_cmt_table (ma1017 * chip)
311 if (!chip->is_opened)
316 if (!chip->is_rowing)
322 data_field[0] = 0x01 | chip->append | chip->test_sram | chip->fix_pattern;
326 status = sanei_usb_write_bulk (chip->fd, data_field, &n);
333 chip->total_write_urbs++;
335 status = sanei_usb_read_bulk (chip->fd, &read_byte, &n);
342 chip->total_read_urbs++;
343 chip->is_rowing = SANE_FALSE;
351 usb_low_set_test_sram_mode (ma1017 * chip, SANE_Bool is_test)
358 data = chip->append | chip->test_sram | chip->fix_pattern;
361 if (!chip->is_opened)
366 if (chip->is_rowing)
373 chip->test_sram = 0x20;
375 chip->test_sram = 0x00;
377 RIE (usb_low_write_reg (chip, reg_no, data));
384 usb_low_set_fix_pattern (ma1017 * chip, SANE_Bool is_fix)
391 data = chip->append | chip->test_sram | chip->fix_pattern;
394 if (!chip->is_opened)
399 if (chip->is_rowing)
406 chip->fix_pattern = 0x80;
408 chip->fix_pattern = 0x00;
410 RIE (usb_low_write_reg (chip, reg_no, data));
417 usb_low_adjust_timing (ma1017 * chip, SANE_Byte data)
426 if (!chip->is_opened)
431 if (chip->is_rowing)
437 RIE (usb_low_write_reg (chip, reg_no, data));
446 usb_low_get_a4 (ma1017 * chip, SANE_Byte * value)
452 if (!chip->is_opened)
457 if (chip->is_rowing)
463 RIE (usb_low_read_reg (chip, 4, &pattern));
465 chip->select = pattern & 0xfe;
466 chip->frontend = pattern & 0x01;
477 usb_low_select_timing (ma1017 * chip, SANE_Byte data)
486 if (!chip->is_opened)
491 if (chip->is_rowing)
497 chip->select = data & 0xfe;
498 chip->frontend = data & 0x01;
500 RIE (usb_low_write_reg (chip, reg_no, data));
507 usb_low_turn_frontend_mode (ma1017 * chip, SANE_Bool is_on)
513 if (!chip->is_opened)
518 if (chip->is_rowing)
525 chip->frontend = 0x01;
527 chip->frontend = 0x00;
529 data = chip->select | chip->frontend;
532 RIE (usb_low_write_reg (chip, reg_no, data));
540 usb_low_get_a6 (ma1017 * chip, SANE_Byte * value)
547 if (!chip->is_opened)
552 if (chip->is_rowing)
557 RIE (usb_low_read_reg (chip, 6, &pattern));
559 chip->asic_io_pins = pattern & 0xdc;
560 chip->rgb_sel_pin = pattern & 0x03;
571 usb_low_set_asic_io_pins (ma1017 * chip, SANE_Byte data)
578 if (!chip->is_opened)
583 if (chip->is_rowing)
589 chip->asic_io_pins = data & 0xdc;
591 data = chip->asic_io_pins | chip->rgb_sel_pin;
594 RIE (usb_low_write_reg (chip, reg_no, data));
601 usb_low_set_rgb_sel_pins (ma1017 * chip, SANE_Byte data)
608 if (!chip->is_opened)
613 if (chip->is_rowing)
618 chip->rgb_sel_pin = data & 0x03;
619 data = chip->asic_io_pins | chip->rgb_sel_pin;
622 RIE (usb_low_write_reg (chip, reg_no, data));
630 usb_low_get_a7 (ma1017 * chip, SANE_Byte * value)
636 if (!chip->is_opened)
641 if (chip->is_rowing)
646 RIE (usb_low_read_reg (chip, 7, &pattern));
651 chip->timing = pattern & 0xfc;
652 chip->sram_bank = pattern & 0x03;
660 usb_low_set_timing (ma1017 * chip, SANE_Byte data)
666 if (!chip->is_opened)
671 if (chip->is_rowing)
677 chip->timing = data & 0xfc;
678 data = chip->timing | chip->sram_bank;
681 RIE (usb_low_write_reg (chip, reg_no, data));
688 usb_low_set_sram_bank (ma1017 * chip, Banksize banksize)
694 if (!chip->is_opened)
699 if (chip->is_rowing)
708 chip->sram_bank = 0x00;
711 chip->sram_bank = 0x01;
714 chip->sram_bank = 0x02;
721 data = chip->timing | chip->sram_bank;
724 RIE (usb_low_write_reg (chip, reg_no, data));
732 usb_low_get_a8 (ma1017 * chip, SANE_Byte * value)
738 if (!chip->is_opened)
743 if (chip->is_rowing)
749 RIE (usb_low_read_reg (chip, 8, &pattern));
751 chip->dummy_msb = pattern & 0x40;
752 chip->ccd_width_msb = pattern & 0x20;
753 chip->cmt_table_length = pattern & 0x1f;
754 chip->ccd_width =
755 ((chip->ccd_width / 32) & 0x00ff) * 32 +
756 ((chip->ccd_width_msb == 0) ? 0 : 0x0100 * 32);
757 chip->dummy =
758 ((chip->dummy / 32) & 0x00ff) * 32 +
759 ((chip->dummy_msb == 0) ? 0 : 0x0100 * 32);
769 usb_low_set_cmt_table_length (ma1017 * chip, SANE_Byte table_length)
775 if (!chip->is_opened)
780 if (chip->is_rowing)
797 chip->cmt_table_length = table_length - 1;
798 chip->cmt_table_length_word = (SANE_Word) table_length;
799 data = chip->cmt_table_length | chip->ccd_width_msb | chip->dummy_msb;
802 RIE (usb_low_write_reg (chip, reg_no, data));
810 usb_low_get_a9 (ma1017 * chip, SANE_Byte * value)
817 if (!chip->is_opened)
822 if (chip->is_rowing)
827 RIE (usb_low_read_reg (chip, 9, &pattern));
829 chip->cmt_second_pos = pattern & 0x1f;
839 usb_low_set_cmt_second_position (ma1017 * chip, SANE_Byte position)
846 if (!chip->is_opened)
851 if (chip->is_rowing)
863 chip->cmt_second_pos = position;
864 chip->cmt_second_pos_word = (SANE_Word) (position);
865 data = chip->cmt_second_pos;
868 RIE (usb_low_write_reg (chip, reg_no, data));
877 usb_low_get_a10 (ma1017 * chip, SANE_Byte * value)
884 if (!chip->is_opened)
889 if (chip->is_rowing)
895 RIE (usb_low_read_reg (chip, 10, &pattern));
897 chip->ccd_width =
899 ((chip->ccd_width_msb == 0) ? 0 : 0x0100 * 32);
910 usb_low_set_ccd_width (ma1017 * chip, SANE_Word ccd_width)
917 if (!chip->is_opened)
922 if (chip->is_rowing)
933 chip->ccd_width = ccd_width;
936 chip->ccd_width_msb = 0x20;
938 chip->ccd_width_msb = 0x00;
940 data = chip->cmt_table_length | chip->ccd_width_msb | chip->dummy_msb;
942 RIE (usb_low_write_reg (chip, reg_no, data));
946 RIE (usb_low_write_reg (chip, reg_no, data));
954 usb_low_get_a11 (ma1017 * chip, SANE_Byte * value)
961 if (!chip->is_opened)
966 if (chip->is_rowing)
972 RIE (usb_low_read_reg (chip, 11, &pattern));
974 chip->dummy =
975 ((SANE_Word) (pattern)) * 32 + ((chip->dummy_msb == 0) ? 0 : 0x0100 * 32);
985 usb_low_set_dummy (ma1017 * chip, SANE_Word dummy)
992 if (!chip->is_opened)
997 if (chip->is_rowing)
1008 chip->dummy = dummy;
1012 chip->dummy_msb = 0x40;
1014 chip->dummy_msb = 0x00;
1015 data = chip->cmt_table_length | chip->ccd_width_msb | chip->dummy_msb;
1017 RIE (usb_low_write_reg (chip, reg_no, data));
1021 RIE (usb_low_write_reg (chip, reg_no, data));
1029 usb_low_get_a12 (ma1017 * chip, SANE_Byte * value)
1036 if (!chip->is_opened)
1041 if (chip->is_rowing)
1047 RIE (usb_low_read_reg (chip, 12, &pattern));
1049 chip->byte_width = (chip->byte_width & 0x3f00) + ((SANE_Word) pattern);
1050 chip->soft_resample = (chip->soft_resample == 0) ? 1 : chip->soft_resample;
1051 chip->get_row =
1052 (chip->soft_resample == 1)
1054 chip->row_size = chip->byte_width / chip->soft_resample;
1064 usb_low_get_a13 (ma1017 * chip, SANE_Byte * value)
1071 if (!chip->is_opened)
1076 if (chip->is_rowing)
1082 RIE (usb_low_read_reg (chip, 13, &pattern));
1084 chip->byte_width =
1085 (chip->byte_width & 0x00ff) + (((SANE_Word) (pattern & 0x3f)) << 8);
1086 chip->soft_resample = (chip->soft_resample == 0) ? 1 : chip->soft_resample;
1087 chip->get_row =
1088 (chip->soft_resample ==
1090 chip->row_size = chip->byte_width / chip->soft_resample;
1100 usb_low_set_image_byte_width (ma1017 * chip, SANE_Word row_size)
1107 if (!chip->is_opened)
1112 if (chip->is_rowing)
1118 chip->row_size = row_size;
1119 chip->soft_resample = (chip->soft_resample == 0) ? 1 : chip->soft_resample;
1120 chip->get_row = (chip->soft_resample == 1) ? &usb_low_get_row_direct
1122 chip->byte_width = chip->row_size * chip->soft_resample;
1123 if (chip->byte_width > 0x3fff)
1126 (int) chip->byte_width);
1130 data = LOBYTE (chip->byte_width);
1132 RIE (usb_low_write_reg (chip, reg_no, data));
1134 data = HIBYTE (chip->byte_width);
1136 RIE (usb_low_write_reg (chip, reg_no, data));
1144 usb_low_set_soft_resample (ma1017 * chip, SANE_Word soft_resample)
1151 if (!chip->is_opened)
1156 if (chip->is_rowing)
1167 chip->soft_resample = soft_resample;
1168 chip->get_row = (chip->soft_resample == 1) ? &usb_low_get_row_direct
1170 chip->byte_width = chip->row_size * chip->soft_resample;
1171 if (chip->byte_width > 0x3fff)
1174 (int) chip->byte_width);
1178 data = LOBYTE (chip->byte_width);
1180 RIE (usb_low_write_reg (chip, reg_no, data));
1182 data = HIBYTE (chip->byte_width);
1184 RIE (usb_low_write_reg (chip, reg_no, data));
1192 usb_low_set_cmt_loop_count (ma1017 * chip, SANE_Word loop_count)
1199 if (!chip->is_opened)
1204 if (chip->is_rowing)
1210 chip->loop_count = loop_count;
1214 RIE (usb_low_write_reg (chip, reg_no, data));
1218 RIE (usb_low_write_reg (chip, reg_no, data));
1226 usb_low_get_a15 (ma1017 * chip, SANE_Byte * value)
1233 if (!chip->is_opened)
1238 if (chip->is_rowing)
1244 RIE (usb_low_read_reg (chip, 15, &pattern));
1246 chip->motor_enable = pattern & 0x80;
1247 chip->motor_movement = pattern & 0x68;
1248 chip->motor_direction = pattern & 10;
1249 chip->motor_signal = pattern & 0x06;
1250 chip->motor_home = pattern & 0x01;
1260 usb_low_enable_motor (ma1017 * chip, SANE_Bool is_enable)
1266 if (!chip->is_opened)
1271 if (chip->is_rowing)
1277 chip->motor_enable = 0x00;
1279 chip->motor_enable |= 0x80;
1280 data = chip->motor_enable | chip->motor_movement
1281 | chip->motor_direction | chip->motor_signal | chip->motor_home;
1283 RIE (usb_low_write_reg (chip, reg_no, data));
1290 usb_low_set_motor_movement (ma1017 * chip, SANE_Bool is_full_step,
1297 if (!chip->is_opened)
1302 if (chip->is_rowing)
1308 chip->motor_movement = 0x00;
1310 chip->motor_movement |= 0x40;
1312 chip->motor_movement |= 0x20;
1314 chip->motor_movement |= 0x08;
1315 data = chip->motor_enable | chip->motor_movement
1316 | chip->motor_direction | chip->motor_signal | chip->motor_home;
1318 RIE (usb_low_write_reg (chip, reg_no, data));
1325 usb_low_set_motor_direction (ma1017 * chip, SANE_Bool is_backward)
1332 if (!chip->is_opened)
1337 if (chip->is_rowing)
1343 chip->motor_direction = 0x00;
1345 chip->motor_direction |= 0x10;
1346 data = chip->motor_enable | chip->motor_movement
1347 | chip->motor_direction | chip->motor_signal | chip->motor_home;
1349 RIE (usb_low_write_reg (chip, reg_no, data));
1356 usb_low_set_motor_signal (ma1017 * chip, SANE_Byte signal)
1363 if (!chip->is_opened)
1368 if (chip->is_rowing)
1374 chip->motor_signal = signal & 0x06;
1375 data = chip->motor_enable | chip->motor_movement
1376 | chip->motor_direction | chip->motor_signal | chip->motor_home;
1378 RIE (usb_low_write_reg (chip, reg_no, data));
1385 usb_low_move_motor_home (ma1017 * chip, SANE_Bool is_home,
1393 if (!chip->is_opened)
1398 if (chip->is_rowing)
1404 chip->motor_enable = 0x00;
1405 chip->motor_direction = 0x00;
1406 chip->motor_home = 0x00;
1408 chip->motor_direction |= 0x10;
1411 chip->motor_enable |= 0x80;
1412 chip->motor_home |= 0x01;
1414 data = chip->motor_enable | chip->motor_movement
1415 | chip->motor_direction | chip->motor_signal | chip->motor_home;
1417 RIE (usb_low_write_reg (chip, reg_no, data));
1425 usb_low_get_a16 (ma1017 * chip, SANE_Byte * value)
1432 if (!chip->is_opened)
1437 if (chip->is_rowing)
1443 RIE (usb_low_read_reg (chip, 16, &pattern));
1445 chip->pixel_depth = pattern & 0xe0;
1446 chip->image_invert = pattern & 0x10;
1447 chip->optical_600 = pattern & 0x08;
1448 chip->sample_way = pattern & 0x07;
1458 usb_low_set_image_dpi (ma1017 * chip, SANE_Bool is_optical600,
1466 if (!chip->is_opened)
1471 if (chip->is_rowing)
1477 chip->optical_600 = 0x00;
1478 chip->sample_way = 0x00;
1480 chip->optical_600 |= 0x08;
1484 chip->sample_way = 0x01;
1487 chip->sample_way = 0x02;
1490 chip->sample_way = 0x03;
1493 chip->sample_way = 0x04;
1496 chip->sample_way = 0x05;
1499 chip->sample_way = 0x06;
1506 data = chip->pixel_depth | chip->image_invert | chip->optical_600
1507 | chip->sample_way;
1509 RIE (usb_low_write_reg (chip, reg_no, data));
1516 usb_low_set_pixel_depth (ma1017 * chip, Pixeldepth pixeldepth)
1522 if (!chip->is_opened)
1527 if (chip->is_rowing)
1533 chip->pixel_depth = 0x00;
1537 chip->pixel_depth = 0x80;
1540 chip->pixel_depth = 0xc0;
1543 chip->pixel_depth = 0x00;
1546 chip->pixel_depth = 0x20;
1552 data = chip->pixel_depth | chip->image_invert | chip->optical_600
1553 | chip->sample_way;
1555 RIE (usb_low_write_reg (chip, reg_no, data));
1562 usb_low_invert_image (ma1017 * chip, SANE_Bool is_invert)
1568 if (!chip->is_opened)
1573 if (chip->is_rowing)
1579 chip->image_invert = 0x00;
1581 chip->image_invert |= 0x10;
1582 data = chip->pixel_depth | chip->image_invert | chip->optical_600
1583 | chip->sample_way;
1585 RIE (usb_low_write_reg (chip, reg_no, data));
1593 usb_low_get_a17 (ma1017 * chip, SANE_Byte * value)
1599 if (!chip->is_opened)
1604 if (chip->is_rowing)
1610 RIE (usb_low_read_reg (chip, 17, &pattern));
1612 chip->red_ref = pattern;
1622 usb_low_get_a18 (ma1017 * chip, SANE_Byte * value)
1628 if (!chip->is_opened)
1633 if (chip->is_rowing)
1639 RIE (usb_low_read_reg (chip, 18, &pattern));
1641 chip->green_ref = pattern;
1651 usb_low_get_a19 (ma1017 * chip, SANE_Byte * value)
1657 if (!chip->is_opened)
1662 if (chip->is_rowing)
1668 RIE (usb_low_read_reg (chip, 19, &pattern));
1670 chip->blue_ref = pattern;
1680 usb_low_set_red_ref (ma1017 * chip, SANE_Byte red_ref)
1687 if (!chip->is_opened)
1692 if (chip->is_rowing)
1698 chip->red_ref = red_ref;
1701 RIE (usb_low_write_reg (chip, reg_no, data));
1708 usb_low_set_green_ref (ma1017 * chip, SANE_Byte green_ref)
1716 if (!chip->is_opened)
1721 if (chip->is_rowing)
1727 chip->green_ref = green_ref;
1731 RIE (usb_low_write_reg (chip, reg_no, data));
1738 usb_low_set_blue_ref (ma1017 * chip, SANE_Byte blue_ref)
1745 if (!chip->is_opened)
1750 if (chip->is_rowing)
1756 chip->blue_ref = blue_ref;
1760 RIE (usb_low_write_reg (chip, reg_no, data));
1768 usb_low_get_a20 (ma1017 * chip, SANE_Byte * value)
1775 if (!chip->is_opened)
1780 if (chip->is_rowing)
1785 RIE (usb_low_read_reg (chip, 20, &pattern));
1787 chip->red_pd = pattern;
1797 usb_low_get_a21 (ma1017 * chip, SANE_Byte * value)
1804 if (!chip->is_opened)
1809 if (chip->is_rowing)
1815 RIE (usb_low_read_reg (chip, 21, &pattern));
1817 chip->green_pd = pattern;
1827 usb_low_get_a22 (ma1017 * chip, SANE_Byte * value)
1834 if (!chip->is_opened)
1839 if (chip->is_rowing)
1845 RIE (usb_low_read_reg (chip, 22, &pattern));
1847 chip->blue_pd = pattern;
1857 usb_low_set_red_pd (ma1017 * chip, SANE_Byte red_pd)
1864 if (!chip->is_opened)
1869 if (chip->is_rowing)
1875 chip->red_pd = red_pd;
1877 data = chip->red_pd;
1879 RIE (usb_low_write_reg (chip, reg_no, data));
1886 usb_low_set_green_pd (ma1017 * chip, SANE_Byte green_pd)
1893 if (!chip->is_opened)
1898 if (chip->is_rowing)
1904 chip->green_pd = green_pd;
1905 data = chip->green_pd;
1907 RIE (usb_low_write_reg (chip, reg_no, data));
1914 usb_low_set_blue_pd (ma1017 * chip, SANE_Byte blue_pd)
1921 if (!chip->is_opened)
1926 if (chip->is_rowing)
1932 chip->blue_pd = blue_pd;
1934 data = chip->blue_pd;
1936 RIE (usb_low_write_reg (chip, reg_no, data));
1944 usb_low_get_a23 (ma1017 * chip, SANE_Byte * value)
1950 if (!chip->is_opened)
1955 if (chip->is_rowing)
1961 RIE (usb_low_read_reg (chip, 23, &pattern));
1963 chip->a23 = pattern;
1973 usb_low_turn_peripheral_power (ma1017 * chip, SANE_Bool is_on)
1980 if (!chip->is_opened)
1985 if (chip->is_rowing)
1991 chip->a23 &= 0x7f;
1993 chip->a23 |= 0x80;
1994 data = chip->a23;
1996 RIE (usb_low_write_reg (chip, reg_no, data));
2003 usb_low_turn_lamp_power (ma1017 * chip, SANE_Bool is_on)
2010 if (!chip->is_opened)
2015 if (chip->is_rowing)
2021 chip->a23 &= 0xbf;
2023 chip->a23 |= 0x40;
2025 data = chip->a23;
2027 RIE (usb_low_write_reg (chip, reg_no, data));
2034 usb_low_set_io_3 (ma1017 * chip, SANE_Bool is_high)
2041 if (!chip->is_opened)
2046 if (chip->is_rowing)
2052 chip->a23 &= 0xf7;
2054 chip->a23 |= 0x08;
2056 data = chip->a23;
2058 RIE (usb_low_write_reg (chip, reg_no, data));
2065 usb_low_set_led_light_all (ma1017 * chip, SANE_Bool is_light_all)
2072 if (!chip->is_opened)
2077 if (chip->is_rowing)
2083 chip->a23 &= 0xfe;
2085 chip->a23 |= 0x01;
2087 data = chip->a23;
2089 RIE (usb_low_write_reg (chip, reg_no, data));
2097 usb_low_get_a24 (ma1017 * chip, SANE_Byte * value)
2104 if (!chip->is_opened)
2109 if (chip->is_rowing)
2115 RIE (usb_low_read_reg (chip, 24, &pattern));
2117 chip->fy1_delay = pattern & 0x01;
2118 chip->special_ad = pattern & 0x02;
2128 usb_low_set_ad_timing (ma1017 * chip, SANE_Byte data)
2135 if (!chip->is_opened)
2140 if (chip->is_rowing)
2146 chip->fy1_delay = data & 0x01;
2147 chip->special_ad = data & 0x02;
2149 data = chip->special_ad | chip->fy1_delay;
2151 RIE (usb_low_write_reg (chip, reg_no, data));
2159 usb_low_set_serial_byte1 (ma1017 * chip, SANE_Byte data)
2166 if (!chip->is_opened)
2171 if (chip->is_rowing)
2178 RIE (usb_low_write_reg (chip, reg_no, data));
2185 usb_low_set_serial_byte2 (ma1017 * chip, SANE_Byte data)
2192 if (!chip->is_opened)
2197 if (chip->is_rowing)
2204 RIE (usb_low_write_reg (chip, reg_no, data));
2212 usb_low_get_a27 (ma1017 * chip, SANE_Byte * value)
2219 if (!chip->is_opened)
2224 if (chip->is_rowing)
2230 RIE (usb_low_read_reg (chip, 27, &pattern));
2232 chip->sclk = pattern & 0x80;
2233 chip->sen = pattern & 0x40;
2234 chip->serial_length = pattern & 0x1f;
2244 usb_low_set_serial_format (ma1017 * chip, SANE_Byte data)
2251 if (!chip->is_opened)
2256 if (chip->is_rowing)
2263 chip->sclk = data & 0x80;
2264 chip->sen = data & 0x40;
2265 chip->serial_length = data & 0x1f;
2268 RIE (usb_low_write_reg (chip, reg_no, data));
2275 usb_low_get_home_sensor (ma1017 * chip)
2282 if (!chip->is_opened)
2287 if (chip->is_rowing)
2293 RIE (usb_low_read_reg (chip, 31, &data));
2304 usb_low_start_rowing (ma1017 * chip)
2313 if (chip->loop_count == 0)
2318 if (chip->cmt_table_length_word == 0)
2324 if (chip->cmt_table_length_word <= chip->cmt_second_pos_word)
2331 for (i = 0; i < (int) chip->cmt_second_pos_word; i++)
2333 if (chip->is_transfer_table[i])
2336 for (; i < (int) chip->cmt_table_length_word; i++)
2338 if (chip->is_transfer_table[i])
2345 chip->total_lines =
2346 ((SANE_Word) (chip->loop_count - 1)) * line_of_second + line_of_first;
2347 chip->lines_left = chip->total_lines;
2349 RIE (usb_low_start_cmt_table (chip));
2356 usb_low_stop_rowing (ma1017 * chip)
2362 RIE (usb_low_stop_cmt_table (chip));
2370 usb_low_wait_rowing_stop (ma1017 * chip)
2375 if (chip->total_lines != 0)
2381 RIE (usb_low_wait_rowing (chip));
2382 chip->is_rowing = SANE_FALSE;
2388 usb_low_read_all_registers (ma1017 * chip)
2394 RIE (usb_low_get_a2 (chip, 0));
2395 RIE (usb_low_get_a4 (chip, 0));
2396 RIE (usb_low_get_a6 (chip, 0));
2397 RIE (usb_low_get_a7 (chip, 0));
2398 RIE (usb_low_get_a8 (chip, 0));
2399 RIE (usb_low_get_a9 (chip, 0));
2400 RIE (usb_low_get_a10 (chip, 0));
2401 RIE (usb_low_get_a11 (chip, 0));
2402 RIE (usb_low_get_a12 (chip, 0));
2403 RIE (usb_low_get_a13 (chip, 0));
2404 RIE (usb_low_get_a15 (chip, 0));
2405 RIE (usb_low_get_a16 (chip, 0));
2406 RIE (usb_low_get_a17 (chip, 0));
2407 RIE (usb_low_get_a18 (chip, 0));
2408 RIE (usb_low_get_a19 (chip, 0));
2409 RIE (usb_low_get_a20 (chip, 0));
2410 RIE (usb_low_get_a21 (chip, 0));
2411 RIE (usb_low_get_a22 (chip, 0));
2412 RIE (usb_low_get_a23 (chip, 0));
2413 RIE (usb_low_get_a24 (chip, 0));
2414 RIE (usb_low_get_a27 (chip, 0));
2421 usb_low_get_row (ma1017 * chip, SANE_Byte * data, SANE_Word * lines_left)
2426 RIE ((*chip->get_row) (chip, data, lines_left));
2432 usb_low_get_row_direct (ma1017 * chip, SANE_Byte * data,
2438 if (chip->lines_left == 0)
2444 if (chip->lines_left <= 1)
2446 RIE (usb_low_read_rows (chip, data, chip->byte_width));
2447 RIE (usb_low_wait_rowing (chip));
2449 chip->lines_left = 0x00;
2450 chip->is_rowing = SANE_FALSE;
2455 RIE (usb_low_read_rows (chip, data, chip->byte_width));
2456 chip->lines_left--;
2457 *lines_left = chip->lines_left;
2464 usb_low_get_row_resample (ma1017 * chip, SANE_Byte * data,
2476 if (chip->lines_left == 0)
2482 if (chip->lines_left <= 1)
2484 RIE (usb_low_read_rows (chip, resample_buffer, chip->byte_width));
2486 if ((chip->sensor == ST_CANON600) && (chip->pixel_depth == 0x20))
2493 for (i = 0; i < chip->byte_width; i += 3)
2506 for (i = 0; i < j; i += chip->soft_resample * 2)
2520 for (i = 0; i < chip->byte_width; i += chip->soft_resample)
2523 RIE (usb_low_wait_rowing (chip));
2525 chip->lines_left = 0x00;
2526 chip->is_rowing = SANE_FALSE;
2531 RIE (usb_low_read_rows (chip, resample_buffer, chip->byte_width));
2533 if ((chip->sensor == ST_CANON600) && (chip->pixel_depth == 0x20))
2540 for (i = 0; i < chip->byte_width; i += 3)
2553 for (i = 0; i < j; i += chip->soft_resample * 2)
2567 for (i = 0; i < chip->byte_width; i += chip->soft_resample)
2570 chip->lines_left--;
2571 *lines_left = chip->lines_left;
2578 usb_low_wait_rowing (ma1017 * chip)
2586 if (!chip->is_opened)
2591 if (!chip->is_rowing)
2597 status = sanei_usb_read_bulk (chip->fd, (SANE_Byte *) & read_byte, &n);
2604 chip->total_read_urbs++;
2605 chip->is_rowing = SANE_FALSE;
2611 usb_low_read_rows (ma1017 * chip, SANE_Byte * data, SANE_Word byte_count)
2617 if (!(chip->is_opened))
2622 if (!(chip->is_rowing))
2628 n = MIN (byte_count, chip->max_block_size);
2634 sanei_usb_read_bulk (chip->fd, (SANE_Byte *) (data + bytes_total),
2644 chip->total_read_urbs += ((n + 63) / 64);
2652 n = MIN ((byte_count - (SANE_Word) bytes_total), chip->max_block_size);
2662 usb_low_write_reg (ma1017 * chip, SANE_Byte reg_no, SANE_Byte data)
2671 if (!chip->is_opened)
2676 if (chip->is_rowing)
2687 status = sanei_usb_write_bulk (chip->fd, data_field, &n);
2695 chip->total_write_urbs++;
2701 usb_low_read_reg (ma1017 * chip, SANE_Byte reg_no, SANE_Byte * data)
2711 if (!chip->is_opened)
2716 if (chip->is_rowing)
2729 status = sanei_usb_write_bulk (chip->fd, data_field, &n);
2737 chip->total_write_urbs++;
2740 status = sanei_usb_read_bulk (chip->fd, (SANE_Byte *) & read_byte, &n);
2748 chip->total_read_urbs++;
2816 usb_low_open (ma1017 * chip, SANE_String_Const devname)
2821 DBG (7, "usb_low_open: start: chip = %p\n", (void *) chip);
2823 if (chip->is_rowing)
2828 if (chip->is_opened)
2834 status = sanei_usb_open ((SANE_String_Const) devname, &chip->fd);
2839 chip->is_opened = SANE_TRUE;
2842 status = usb_low_identify_scanner (chip->fd, &scanner_type);
2847 sanei_usb_close (chip->fd);
2857 else if (scanner_type != chip->scanner_type)
2872 chip->is_opened = SANE_TRUE;
2874 RIE (usb_low_read_all_registers (chip));
2881 usb_low_close (ma1017 * chip)
2883 DBG (7, "usb_low_close: start, chip=%p\n", (void *) chip);
2884 if (!chip->is_opened)
2890 if (chip->fd >= 0)
2894 if (chip->is_rowing)
2895 usb_low_stop_rowing (chip);
2900 if ((chip->total_read_urbs % 2) == 1)
2901 usb_low_get_a4 (chip, &dummy);
2902 if ((chip->total_write_urbs % 2) == 1)
2903 usb_low_set_fix_pattern (chip, SANE_FALSE);
2904 sanei_usb_close (chip->fd);
2905 chip->fd = -1;
2907 chip->is_opened = SANE_FALSE;
2908 chip->is_rowing = SANE_FALSE;