summaryrefslogtreecommitdiff
path: root/src/camera/veye_i2c.h
blob: 24ef10bb3e253830edb28917afa6f40686d45660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <cstdint>
#include <optional>
#include <string>

namespace veye {
namespace imx287m {
class i2c
{
public:
    i2c(const std::string &name = "/dev/i2c-2", const int address = 0x3b);
    ~i2c();

public:
    /*!
     * \brief open - open i2c device with `name` passed to constructor
     * \return - true on success or if already open, false otherwise
     */
    bool open();

    std::optional<uint32_t> read(uint16_t reg);
    bool write(uint16_t reg, const uint32_t value);

private:
    int m_fd{-1};
    std::string m_name;
    int m_address{-1};
};

/*!
 * \brief i2c_read - read device registers using i2c
 * \param fd - device file descriptor
 * \param i2c_addr - i2c adderr
 * \param reg - register
 * \param value - value to set
 * \return non-empty register value on success, empty value on failure
 */
std::optional<uint32_t> i2c_read(int fd, uint8_t i2c_addr, uint16_t reg);
bool i2c_write(int fd, uint16_t reg, const uint32_t value);
} // namespace imx287m
} // namespace veye