blob: b7373696546dd42d00fe756663cd987c17e15689 [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.
#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.
// The values are converted from big-endian order to host byte order for write
// and vice versa for read.
zx::status<uint16_t> Read16();
zx::status<> Write16(uint16_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_;
};