// Copyright 2019 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_DEVICES_I2C_DRIVERS_I2C_I2C_CHILD_H_
#define SRC_DEVICES_I2C_DRIVERS_I2C_I2C_CHILD_H_

#include <fuchsia/hardware/i2c/llcpp/fidl.h>

#include <ddk/metadata/i2c.h>
#include <ddk/platform-defs.h>
#include <ddktl/device.h>
#include <ddktl/fidl.h>
#include <ddktl/protocol/i2c.h>
#include <ddktl/protocol/i2cimpl.h>
#include <fbl/ref_ptr.h>
#include <fbl/vector.h>

#include "i2c-bus.h"

namespace i2c {

class I2cChild;

using I2cChildType = ddk::Device<I2cChild, ddk::UnbindableNew, ddk::Messageable>;

namespace fidl_i2c = llcpp::fuchsia::hardware::i2c;

class I2cChild : public I2cChildType,
                 public ddk::I2cProtocol<I2cChild, ddk::base_protocol>,
                 public fidl_i2c::Device2::Interface {
 public:
  I2cChild(zx_device_t* parent, fbl::RefPtr<I2cBus> bus, uint16_t address)
      : I2cChildType(parent), bus_(bus), address_(address) {}

  static zx_status_t Create(void* ctx, zx_device_t* parent);

  void DdkUnbindNew(ddk::UnbindTxn txn);
  void DdkRelease();
  zx_status_t DdkMessage(fidl_msg_t* msg, fidl_txn_t* txn) {
    DdkTransaction transaction(txn);
    llcpp::fuchsia::hardware::i2c::Device2::Dispatch(this, msg, &transaction);
    return transaction.Status();
  }

  // FIDL methods.
  void Transfer(fidl::VectorView<bool> input_segments,
                fidl::VectorView<fidl::VectorView<uint8_t>> input_segments_data,
                fidl::VectorView<uint8_t> output_segments_length,
                TransferCompleter::Sync completer) override;

  void I2cTransact(const i2c_op_t* op_list, size_t op_count, i2c_transact_callback callback,
                   void* cookie);
  zx_status_t I2cGetMaxTransferSize(size_t* out_size);
  zx_status_t I2cGetInterrupt(uint32_t flags, zx::interrupt* out_irq);

 private:
  fbl::RefPtr<I2cBus> bus_;
  const uint16_t address_;
};

}  // namespace i2c

#endif  // SRC_DEVICES_I2C_DRIVERS_I2C_I2C_CHILD_H_
