1 /* sane - Scanner Access Now Easy.
2
3 Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4
5 This file is part of the SANE package.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 As a special exception, the authors of SANE give permission for
21 additional uses of the libraries contained in this release of SANE.
22
23 The exception is that, if you link a SANE library with other files
24 to produce an executable, this does not by itself cause the
25 resulting executable to be covered by the GNU General Public
26 License. Your use of that executable is in no way restricted on
27 account of linking the SANE library code into it.
28
29 This exception does not, however, invalidate any other reasons why
30 the executable file might be covered by the GNU General Public
31 License.
32
33 If you submit changes to SANE to the maintainers to be included in
34 a subsequent release, you agree by submitting the changes that
35 those changes may be distributed with this exception intact.
36
37 If you write modifications of your own for SANE, it is your choice
38 whether to permit this exception to apply to your modifications.
39 If you do not wish that, delete this exception notice.
40 */
41
42 #define DEBUG_DECLARE_ONLY
43
44 #include "test_scanner_interface.h"
45 #include "device.h"
46 #include <cstring>
47
48 namespace genesys {
49
TestScannerInterface(Genesys_Device * dev,uint16_t vendor_id,uint16_t product_id,uint16_t bcd_device)50 TestScannerInterface::TestScannerInterface(Genesys_Device* dev, uint16_t vendor_id,
51 uint16_t product_id, uint16_t bcd_device) :
52 dev_{dev},
53 usb_dev_{vendor_id, product_id, bcd_device}
54 {
55 // initialize status registers
56 if (dev_->model->asic_type == AsicType::GL124) {
57 write_register(0x101, 0x00);
58 } else {
59 write_register(0x41, 0x00);
60 }
61 if (dev_->model->asic_type == AsicType::GL841 ||
62 dev_->model->asic_type == AsicType::GL842 ||
63 dev_->model->asic_type == AsicType::GL843 ||
64 dev_->model->asic_type == AsicType::GL845 ||
65 dev_->model->asic_type == AsicType::GL846 ||
66 dev_->model->asic_type == AsicType::GL847)
67 {
68 write_register(0x40, 0x00);
69 }
70
71 // initialize other registers that we read on init
72 if (dev_->model->asic_type == AsicType::GL124) {
73 write_register(0x33, 0x00);
74 write_register(0xbd, 0x00);
75 write_register(0xbe, 0x00);
76 write_register(0x100, 0x00);
77 }
78
79 if (dev_->model->asic_type == AsicType::GL845 ||
80 dev_->model->asic_type == AsicType::GL846 ||
81 dev_->model->asic_type == AsicType::GL847)
82 {
83 write_register(0xbd, 0x00);
84 write_register(0xbe, 0x00);
85
86 write_register(0xd0, 0x00);
87 write_register(0xd1, 0x01);
88 write_register(0xd2, 0x02);
89 write_register(0xd3, 0x03);
90 write_register(0xd4, 0x04);
91 write_register(0xd5, 0x05);
92 write_register(0xd6, 0x06);
93 write_register(0xd7, 0x07);
94 write_register(0xd8, 0x08);
95 write_register(0xd9, 0x09);
96 }
97 }
98
99 TestScannerInterface::~TestScannerInterface() = default;
100
is_mock() const101 bool TestScannerInterface::is_mock() const
102 {
103 return true;
104 }
105
read_register(std::uint16_t address)106 std::uint8_t TestScannerInterface::read_register(std::uint16_t address)
107 {
108 return cached_regs_.get(address);
109 }
110
write_register(std::uint16_t address,std::uint8_t value)111 void TestScannerInterface::write_register(std::uint16_t address, std::uint8_t value)
112 {
113 cached_regs_.update(address, value);
114 }
115
write_registers(const Genesys_Register_Set & regs)116 void TestScannerInterface::write_registers(const Genesys_Register_Set& regs)
117 {
118 cached_regs_.update(regs);
119 }
120
121
write_0x8c(std::uint8_t index,std::uint8_t value)122 void TestScannerInterface::write_0x8c(std::uint8_t index, std::uint8_t value)
123 {
124 (void) index;
125 (void) value;
126 }
127
bulk_read_data(std::uint8_t addr,std::uint8_t * data,std::size_t size)128 void TestScannerInterface::bulk_read_data(std::uint8_t addr, std::uint8_t* data, std::size_t size)
129 {
130 (void) addr;
131 std::memset(data, 0, size);
132 }
133
bulk_write_data(std::uint8_t addr,std::uint8_t * data,std::size_t size)134 void TestScannerInterface::bulk_write_data(std::uint8_t addr, std::uint8_t* data, std::size_t size)
135 {
136 (void) addr;
137 (void) data;
138 (void) size;
139 }
140
write_buffer(std::uint8_t type,std::uint32_t addr,std::uint8_t * data,std::size_t size)141 void TestScannerInterface::write_buffer(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
142 std::size_t size)
143 {
144 (void) type;
145 (void) addr;
146 (void) data;
147 (void) size;
148 }
149
write_gamma(std::uint8_t type,std::uint32_t addr,std::uint8_t * data,std::size_t size)150 void TestScannerInterface::write_gamma(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
151 std::size_t size)
152 {
153 (void) type;
154 (void) addr;
155 (void) data;
156 (void) size;
157 }
158
write_ahb(std::uint32_t addr,std::uint32_t size,std::uint8_t * data)159 void TestScannerInterface::write_ahb(std::uint32_t addr, std::uint32_t size, std::uint8_t* data)
160 {
161 (void) addr;
162 (void) size;
163 (void) data;
164 }
165
read_fe_register(std::uint8_t address)166 std::uint16_t TestScannerInterface::read_fe_register(std::uint8_t address)
167 {
168 return cached_fe_regs_.get(address);
169 }
170
write_fe_register(std::uint8_t address,std::uint16_t value)171 void TestScannerInterface::write_fe_register(std::uint8_t address, std::uint16_t value)
172 {
173 cached_fe_regs_.update(address, value);
174 }
175
get_usb_device()176 IUsbDevice& TestScannerInterface::get_usb_device()
177 {
178 return usb_dev_;
179 }
180
sleep_us(unsigned microseconds)181 void TestScannerInterface::sleep_us(unsigned microseconds)
182 {
183 (void) microseconds;
184 }
185
record_slope_table(unsigned table_nr,const std::vector<std::uint16_t> & steps)186 void TestScannerInterface::record_slope_table(unsigned table_nr,
187 const std::vector<std::uint16_t>& steps)
188 {
189 slope_tables_[table_nr] = steps;
190 }
191
recorded_slope_tables()192 std::map<unsigned, std::vector<std::uint16_t>>& TestScannerInterface::recorded_slope_tables()
193 {
194 return slope_tables_;
195 }
196
record_progress_message(const char * msg)197 void TestScannerInterface::record_progress_message(const char* msg)
198 {
199 last_progress_message_ = msg;
200 }
201
last_progress_message() const202 const std::string& TestScannerInterface::last_progress_message() const
203 {
204 return last_progress_message_;
205 }
206
record_key_value(const std::string & key,const std::string & value)207 void TestScannerInterface::record_key_value(const std::string& key, const std::string& value)
208 {
209 key_values_[key] = value;
210 }
211
recorded_key_values()212 std::map<std::string, std::string>& TestScannerInterface::recorded_key_values()
213 {
214 return key_values_;
215 }
216
test_checkpoint(const std::string & name)217 void TestScannerInterface::test_checkpoint(const std::string& name)
218 {
219 if (checkpoint_callback_) {
220 checkpoint_callback_(*dev_, *this, name);
221 }
222 }
223
set_checkpoint_callback(TestCheckpointCallback callback)224 void TestScannerInterface::set_checkpoint_callback(TestCheckpointCallback callback)
225 {
226 checkpoint_callback_ = callback;
227 }
228
229 } // namespace genesys
230