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#ifndef BACKEND_GENESYS_SCANNER_INTERFACE_H
22#define BACKEND_GENESYS_SCANNER_INTERFACE_H
23
24#include "fwd.h"
25#include <cstddef>
26#include <cstdint>
27#include <string>
28#include <vector>
29
30namespace genesys {
31
32// Represents an interface through which all low level operations are performed.
33class ScannerInterface
34{
35public:
36
37    virtual ~ScannerInterface();
38
39    virtual bool is_mock() const = 0;
40
41    virtual std::uint8_t read_register(std::uint16_t address) = 0;
42    virtual void write_register(std::uint16_t address, std::uint8_t value) = 0;
43    virtual void write_registers(const Genesys_Register_Set& regs) = 0;
44
45    virtual void write_0x8c(std::uint8_t index, std::uint8_t value) = 0;
46    virtual void bulk_read_data(std::uint8_t addr, std::uint8_t* data, std::size_t size) = 0;
47    virtual void bulk_write_data(std::uint8_t addr, std::uint8_t* data, std::size_t size) = 0;
48
49    // GL646, GL841, GL843 have different ways to write to RAM and to gamma tables
50    virtual void write_buffer(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
51                              std::size_t size) = 0;
52
53    virtual void write_gamma(std::uint8_t type, std::uint32_t addr, std::uint8_t* data,
54                             std::size_t size) = 0;
55
56    // GL845, GL846, GL847 and GL124 have a uniform way to write to RAM tables
57    virtual void write_ahb(std::uint32_t addr, std::uint32_t size, std::uint8_t* data) = 0;
58
59    virtual std::uint16_t read_fe_register(std::uint8_t address) = 0;
60    virtual void write_fe_register(std::uint8_t address, std::uint16_t value) = 0;
61
62    virtual IUsbDevice& get_usb_device() = 0;
63
64    // sleeps the specified number of microseconds. Will not sleep if testing mode is enabled.
65    virtual void sleep_us(unsigned microseconds) = 0;
66
67    void sleep_ms(unsigned milliseconds)
68    {
69        sleep_us(milliseconds * 1000);
70    }
71
72    virtual void record_progress_message(const char* msg) = 0;
73
74    virtual void record_slope_table(unsigned table_nr, const std::vector<std::uint16_t>& steps) = 0;
75
76    virtual void record_key_value(const std::string& key, const std::string& value) = 0;
77
78    virtual void test_checkpoint(const std::string& name) = 0;
79};
80
81} // namespace genesys
82
83#endif
84