blob: 5a53c00edd94fefbd9ef3c39316c661ca8c01fbf [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 FUCHSIA_SDK_EXAMPLES_SRC_DA7219_DRIVER_DA7219_H_
#define FUCHSIA_SDK_EXAMPLES_SRC_DA7219_DRIVER_DA7219_H_
#include <fidl/fuchsia.driver.framework/cpp/wire.h>
#include <fidl/fuchsia.hardware.audio/cpp/wire.h>
#include <fidl/fuchsia.hardware.i2c/cpp/wire.h>
#include <lib/driver2/namespace.h>
#include <lib/driver2/record_cpp.h>
#include <lib/driver2/structured_logger.h>
#include <lib/fdf/cpp/dispatcher.h>
#include <lib/sys/component/cpp/outgoing_directory.h>
#include <lib/zx/status.h>
#include "i2c_channel.h"
namespace audio {
class Da7219Driver {
public:
Da7219Driver(async_dispatcher_t* dispatcher,
fidl::WireSharedClient<fuchsia_driver_framework::Node> node, driver::Namespace ns,
driver::Logger logger)
: dispatcher_(dispatcher),
outgoing_(component::OutgoingDirectory::Create(dispatcher)),
node_(std::move(node)),
ns_(std::move(ns)),
logger_(std::move(logger)) {}
virtual ~Da7219Driver() = default;
static constexpr const char* Name() { return "da7219"; }
static zx::status<std::unique_ptr<Da7219Driver>> Start(
fuchsia_driver_framework::wire::DriverStartArgs& start_args,
fdf::UnownedDispatcher dispatcher,
fidl::WireSharedClient<fuchsia_driver_framework::Node> node, driver::Namespace ns,
driver::Logger logger);
private:
zx::status<> Run(fidl::ServerEnd<fuchsia_io::Directory> outgoing_dir);
zx::status<> SetupI2cChannel();
async_dispatcher_t* const dispatcher_;
component::OutgoingDirectory outgoing_;
fidl::WireSharedClient<fuchsia_driver_framework::Node> node_;
driver::Namespace ns_;
driver::Logger logger_;
std::shared_ptr<I2cChannel> i2c_channel_;
};
} // namespace audio
#endif // FUCHSIA_SDK_EXAMPLES_SRC_DA7219_DRIVER_DA7219_H_