blob: d4282c18a2e3b976067cfa2f6f694f1722b8c1e3 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DA7219_DRIVER_I2C_CHANNEL_H_
#define SRC_DA7219_DRIVER_I2C_CHANNEL_H_
#include <fidl/fuchsia.hardware.i2c/cpp/wire.h>
// Sends read and write transactions through a fuchsia.hardware.i2c client.
class I2cChannel {
public:
explicit I2cChannel(fidl::WireClient<fuchsia_hardware_i2c::Device> client_end)
: fidl_client_(std::move(client_end)) {}
I2cChannel(I2cChannel&& other) noexcept = default;
I2cChannel& operator=(I2cChannel&& other) noexcept = default;
~I2cChannel() = default;
// Functions that perform read/write transactions through the client.
zx::result<uint8_t> Read(uint8_t address);
zx::result<> Write(uint8_t address, uint8_t value);
private:
zx::result<> WriteReadSync(const uint8_t* tx_buf, size_t tx_len,
uint8_t* rx_buf, size_t rx_len);
fidl::WireClient<fuchsia_hardware_i2c::Device> fidl_client_;
};
#endif // SRC_DA7219_DRIVER_I2C_CHANNEL_H_