| // 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 FUCHSIA_SDK_EXAMPLES_SRC_DA7219_CONTROLLER_I2C_CONTROLLER_H_ |
| #define FUCHSIA_SDK_EXAMPLES_SRC_DA7219_CONTROLLER_I2C_CONTROLLER_H_ |
| |
| #include <fidl/fuchsia.driver.framework/cpp/wire.h> |
| #include <fidl/fuchsia.hardware.i2c/cpp/wire.h> |
| #include <lib/async/cpp/executor.h> |
| #include <lib/driver2/namespace.h> |
| #include <lib/driver2/structured_logger.h> |
| #include <lib/fdf/cpp/dispatcher.h> |
| #include <lib/sys/component/cpp/outgoing_directory.h> |
| |
| namespace test_i2c_controller { |
| |
| // Sample driver that implements a `fuchsia.hardware.i2c` bus controller and emulates the |
| // behavior of an audio hardware codec device to interact with the da7219 driver. |
| class TestDa7219I2cController : public fidl::WireServer<fuchsia_hardware_i2c::Device> { |
| public: |
| TestDa7219I2cController(async_dispatcher_t* dispatcher, |
| fidl::WireSharedClient<fuchsia_driver_framework::Node> node, |
| driver::Namespace ns, driver::Logger logger) |
| : dispatcher_(dispatcher), |
| outgoing_(component::OutgoingDirectory::Create(dispatcher)), |
| ns_(std::move(ns)), |
| logger_(std::move(logger)), |
| node_(std::move(node)) {} |
| |
| virtual ~TestDa7219I2cController() = default; |
| |
| static constexpr const char* Name() { return "test-da7219-i2c-controller"; } |
| |
| static zx::status<std::unique_ptr<TestDa7219I2cController>> Start( |
| fuchsia_driver_framework::wire::DriverStartArgs& start_args, |
| fdf::UnownedDispatcher dispatcher, |
| fidl::WireSharedClient<fuchsia_driver_framework::Node> node, driver::Namespace ns, |
| driver::Logger logger); |
| |
| // fuchsia.hardware.i2c/Device: |
| void Transfer(TransferRequestView request, TransferCompleter::Sync& completer); |
| |
| private: |
| zx::status<> Run(fidl::ServerEnd<fuchsia_io::Directory> outgoing_dir); |
| zx::status<> AddChild(); |
| |
| async_dispatcher_t* const dispatcher_; |
| |
| component::OutgoingDirectory outgoing_; |
| driver::Namespace ns_; |
| driver::Logger logger_; |
| |
| fidl::WireSharedClient<fuchsia_driver_framework::Node> node_; |
| fidl::WireSharedClient<fuchsia_driver_framework::NodeController> controller_; |
| }; |
| |
| } // namespace test_i2c_controller |
| |
| #endif // FUCHSIA_SDK_EXAMPLES_SRC_DA7219_CONTROLLER_I2C_CONTROLLER_H_ |