1 /* sane - Scanner Access Now Easy.
3 Copyright (C) 2000 Adrian Perez Jorge
4 Copyright (C) 2001 Frank Zago
5 Copyright (C) 2001 Marcio Teixeira
7 This file is part of the SANE package.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 As a special exception, the authors of SANE give permission for
25 additional uses of the libraries contained in this release of SANE.
27 The exception is that, if you link a SANE library with other files
28 to produce an executable, this does not by itself cause the
29 resulting executable to be covered by the GNU General Public
30 License. Your use of that executable is in no way restricted on
31 account of linking the SANE library code into it.
33 This exception does not, however, invalidate any other reasons why
34 the executable file might be covered by the GNU General Public
37 If you submit changes to SANE to the maintainers to be included in
38 a subsequent release, you agree by submitting the changes that
39 those changes may be distributed with this exception intact.
41 If you write modifications of your own for SANE, it is your choice
42 whether to permit this exception to apply to your modifications.
43 If you do not wish that, delete this exception notice.
45 Interface files for the PowerVision 8630 chip, a USB to
46 parallel converter used in many scanners.
50 #include "../include/sane/config.h"
55 #define BACKEND_NAME sanei_pv8630
56 #include "../include/sane/sane.h"
57 #include "../include/sane/sanei_debug.h"
58 #include "../include/sane/sanei_usb.h"
59 #include "../include/sane/sanei_pv8630.h"
65 sanei_pv8630_init (void)
70 /* Write one control byte */
72 sanei_pv8630_write_byte (int fd
, SANEI_PV_Index index
, SANE_Byte byte
)
76 DBG(DBG_info
, "sanei_pv8630_write_byte - index=%d, byte=%d\n", index
, byte
);
78 sanei_usb_control_msg (fd
, 0x40, PV8630_REQ_WRITEBYTE
, byte
, index
, 0,
81 if (status
!= SANE_STATUS_GOOD
)
82 DBG (DBG_error
, "sanei_pv8630_write_byte error\n");
86 /* Read one control byte */
88 sanei_pv8630_read_byte (int fd
, SANEI_PV_Index index
, SANE_Byte
* byte
)
92 DBG(DBG_info
, "sanei_pv8630_read_byte - index=%d, byte=%p\n", index
, byte
);
95 sanei_usb_control_msg (fd
, 0xc0, PV8630_REQ_READBYTE
, 0, index
, 1, byte
);
97 if (status
!= SANE_STATUS_GOOD
)
98 DBG (DBG_error
, "sanei_pv8630_read_byte error\n");
102 /* Prepare a bulk read. len is the size of the data going to be
103 * read by pv8630_bulkread(). */
105 sanei_pv8630_prep_bulkread (int fd
, int len
)
110 sanei_usb_control_msg (fd
, 0x40, PV8630_REQ_EPPBULKREAD
, len
& 0xffff,
113 if (status
!= SANE_STATUS_GOOD
)
114 DBG (DBG_error
, "sanei_pv8630_prep_bulkread error\n");
118 /* Prepare a bulk write. len is the size of the data going to be
119 * written by pv8630_bulkwrite(). */
121 sanei_pv8630_prep_bulkwrite (int fd
, int len
)
126 sanei_usb_control_msg (fd
, 0x40, PV8630_REQ_EPPBULKWRITE
, len
& 0xffff,
129 if (status
!= SANE_STATUS_GOOD
)
130 DBG (DBG_error
, "sanei_pv8630_prep_bulkwrite error\n");
134 /* Flush the buffer. */
136 sanei_pv8630_flush_buffer (int fd
)
141 sanei_usb_control_msg (fd
, 0x40, PV8630_REQ_FLUSHBUFFER
, 0, 0, 0, NULL
);
143 if (status
!= SANE_STATUS_GOOD
)
144 DBG (DBG_error
, "sanei_pv8630_flush_buffer error\n");
148 /* Do a bulk write. The length must have previously been sent via
149 * pv8630_prep_bulkwrite(). */
151 sanei_pv8630_bulkwrite (int fd
, const void *data
, size_t * len
)
155 status
= sanei_usb_write_bulk (fd
, (const SANE_Byte
*) data
, len
);
157 if (status
!= SANE_STATUS_GOOD
)
158 DBG (DBG_error
, "sanei_pv8630_bulkwrite error\n");
162 /* Do a bulk read. The length must have previously been sent via
163 * pv8630_prep_bulkread(). */
165 sanei_pv8630_bulkread (int fd
, void *data
, size_t * len
)
169 status
= sanei_usb_read_bulk (fd
, data
, len
);
171 if (status
!= SANE_STATUS_GOOD
)
172 DBG (DBG_error
, "sanei_pv8630_bulkread error\n");
176 /* Expects a specific byte in a register */
178 sanei_pv8630_xpect_byte (int fd
, SANEI_PV_Index index
, SANE_Byte value
,
184 status
= sanei_pv8630_read_byte (fd
, index
, &s
);
185 if (status
!= SANE_STATUS_GOOD
)
188 if ((s
& mask
) != value
)
190 DBG (DBG_error
, "sanei_pv8630_xpect_byte: expected %x, got %x\n", value
,
192 return SANE_STATUS_IO_ERROR
;
194 return SANE_STATUS_GOOD
;
197 /* Wait for the status register to present a given status. A timeout value
198 is given in tenths of a second. */
200 sanei_pv8630_wait_byte (int fd
, SANEI_PV_Index index
, SANE_Byte value
,
201 SANE_Byte mask
, int timeout
)
207 for (n
= 0; n
< timeout
; n
++)
210 status
= sanei_pv8630_read_byte (fd
, index
, &s
);
211 if (status
!= SANE_STATUS_GOOD
)
214 if ((s
& mask
) == value
)
215 return SANE_STATUS_GOOD
;
220 DBG (DBG_error
, "sanei_pv8630_wait_byte: timeout waiting for %x (got %x)\n",
222 return SANE_STATUS_IO_ERROR
;