blob: f604155db4cbdd41f2df8cf363c7c0bb13eff27d [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::status<uint8_t> Read(uint8_t address);
zx::status<> Write(uint8_t address, uint8_t value);
private:
zx::status<> 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_