• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 #define DEBUG_DECLARE_ONLY
22 
23 #include "test_scanner_interface.h"
24 #include "device.h"
25 #include <cstring>
26 
27 namespace genesys {
28 
TestScannerInterface(Genesys_Device * dev,std::uint16_t vendor_id,std::uint16_t product_id,std::uint16_t bcd_device)29 TestScannerInterface::TestScannerInterface(Genesys_Device* dev, std::uint16_t vendor_id,
30                                            std::uint16_t product_id, std::uint16_t bcd_device) :
31     dev_{dev},
32     usb_dev_{vendor_id, product_id, bcd_device}
33 {
34     // initialize status registers
35     if (dev_->model->asic_type == AsicType::GL124) {
36         write_register(0x101, 0x00);
37     } else {
38         write_register(0x41, 0x00);
39     }
40     if (dev_->model->asic_type == AsicType::GL841 ||
41         dev_->model->asic_type == AsicType::GL842 ||
42         dev_->model->asic_type == AsicType::GL843 ||
43         dev_->model->asic_type == AsicType::GL845 ||
44         dev_->model->asic_type == AsicType::GL846 ||
45         dev_->model->asic_type == AsicType::GL847)
46     {
47         write_register(0x40, 0x00);
48     }
49 
50     // initialize other registers that we read on init
51     if (dev_->model->asic_type == AsicType::GL124) {
52         write_register(0x33, 0x00);
53         write_register(0xbd, 0x00);
54         write_register(0xbe, 0x00);
55         write_register(0x100, 0x00);
56     }
57 
58     if (dev_->model->asic_type == AsicType::GL845 ||
59         dev_->model->asic_type == AsicType::GL846 ||
60         dev_->model->asic_type == AsicType::GL847)
61     {
62         write_register(0xbd, 0x00);
63         write_register(0xbe, 0x00);
64 
65         write_register(0xd0, 0x00);
66         write_register(0xd1, 0x01);
67         write_register(0xd2, 0x02);
68         write_register(0xd3, 0x03);
69         write_register(0xd4, 0x04);
70         write_register(0xd5, 0x05);
71         write_register(0xd6, 0x06);
72         write_register(0xd7, 0x07);
73         write_register(0xd8, 0x08);
74         write_register(0xd9, 0x09);
75     }
76 }
77 
78 TestScannerInterface::~TestScannerInterface() = default;
79 
is_mock() const80 bool TestScannerInterface::is_mock() const
81 {
82     return true;
83 }
84 
read_register(std::uint16_t address)85 std::uint8_t TestScannerInterface::read_register(std::uint16_t address)
86 {
87     return cached_regs_.get(address);
88 }
89 
write_register(std::uint16_t address,std::uint8_t value)90 void TestScannerInterface::write_register(std::uint16_t address, std::uint8_t value)
91 {
92     cached_regs_.update(address, value);
93 }
94 
write_registers(const Genesys_Register_Set & regs)95 void TestScannerInterface::write_registers(const Genesys_Register_Set& regs)
96 {
97     cached_regs_.update(regs);
98 }
99 
100 
write_0x8c(std::uint8_t index,std::uint8_t value)101 void TestScannerInterface::write_0x8c(std::uint8_t index, std::uint8_t value)
102 {
103     (void) index;
104     (void) value;
105 }
106 
bulk_read_data(std::uint8_t addr,std::uint8_t * data,std::size_t size)107 void TestScannerInterface::bulk_read_data(std::uint8_t addr, std::uint8_t* data, std::size_t size)
108 {
109     (void) addr;
110     std::memset(data, 0, size);
111 }
112 
bulk_write_data(std::uint8_t addr,std::uint8_t * data,std::size_t size)113 void TestScannerInterface::bulk_write_data(std::uint8_t addr, std::uint8_t* data, std::size_t size)
114 {
115     (void) addr;
116     (void) data;
117     (void) size;
118 }
119 
write_buffer(std::uint8_t type,std::uint32_t addr,std::uint8_t * data,std::size_t size)120 void TestScannerInterface::write_buffer(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
121                                         std::size_t size)
122 {
123     (void) type;
124     (void) addr;
125     (void) data;
126     (void) size;
127 }
128 
write_gamma(std::uint8_t type,std::uint32_t addr,std::uint8_t * data,std::size_t size)129 void TestScannerInterface::write_gamma(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
130                                        std::size_t size)
131 {
132     (void) type;
133     (void) addr;
134     (void) data;
135     (void) size;
136 }
137 
write_ahb(std::uint32_t addr,std::uint32_t size,std::uint8_t * data)138 void TestScannerInterface::write_ahb(std::uint32_t addr, std::uint32_t size, std::uint8_t* data)
139 {
140     (void) addr;
141     (void) size;
142     (void) data;
143 }
144 
read_fe_register(std::uint8_t address)145 std::uint16_t TestScannerInterface::read_fe_register(std::uint8_t address)
146 {
147     return cached_fe_regs_.get(address);
148 }
149 
write_fe_register(std::uint8_t address,std::uint16_t value)150 void TestScannerInterface::write_fe_register(std::uint8_t address, std::uint16_t value)
151 {
152     cached_fe_regs_.update(address, value);
153 }
154 
get_usb_device()155 IUsbDevice& TestScannerInterface::get_usb_device()
156 {
157     return usb_dev_;
158 }
159 
sleep_us(unsigned microseconds)160 void TestScannerInterface::sleep_us(unsigned microseconds)
161 {
162     (void) microseconds;
163 }
164 
record_slope_table(unsigned table_nr,const std::vector<std::uint16_t> & steps)165 void TestScannerInterface::record_slope_table(unsigned table_nr,
166                                               const std::vector<std::uint16_t>& steps)
167 {
168     slope_tables_[table_nr] = steps;
169 }
170 
recorded_slope_tables()171 std::map<unsigned, std::vector<std::uint16_t>>& TestScannerInterface::recorded_slope_tables()
172 {
173     return slope_tables_;
174 }
175 
record_progress_message(const char * msg)176 void TestScannerInterface::record_progress_message(const char* msg)
177 {
178     last_progress_message_ = msg;
179 }
180 
last_progress_message() const181 const std::string& TestScannerInterface::last_progress_message() const
182 {
183     return last_progress_message_;
184 }
185 
record_key_value(const std::string & key,const std::string & value)186 void TestScannerInterface::record_key_value(const std::string& key, const std::string& value)
187 {
188     key_values_[key] = value;
189 }
190 
recorded_key_values()191 std::map<std::string, std::string>& TestScannerInterface::recorded_key_values()
192 {
193     return key_values_;
194 }
195 
test_checkpoint(const std::string & name)196 void TestScannerInterface::test_checkpoint(const std::string& name)
197 {
198     if (checkpoint_callback_) {
199         checkpoint_callback_(*dev_, *this, name);
200     }
201 }
202 
set_checkpoint_callback(TestCheckpointCallback callback)203 void TestScannerInterface::set_checkpoint_callback(TestCheckpointCallback callback)
204 {
205     checkpoint_callback_ = callback;
206 }
207 
208 } // namespace genesys
209