Update da7219 audio driver to the latest sdk
In addition to rolling a new SDK, this CL updates the driver and all the
surrounding code and build rules to the changes since the last SDK roll.
Test: tools/bazel build --config=fuchsia_x64 //src/da7219/driver:pkg //src/da7219/controller:pkg
Fixed: 120182
Change-Id: Iefe9319b6499535c8a573669e2a7e328f525837b
diff --git a/README.md b/README.md
index 0ceecbc..165d641 100644
--- a/README.md
+++ b/README.md
@@ -11,28 +11,8 @@
scripts/bootstrap.sh
```
-2. To verify that you can use the ffx tool in your environment, run the following command:
-
-```
-tools/ffx sdk version
-```
-
-This command prints output similar to the following:
-```
-andresoportus@andresoportus:~/src/dialog$ tools/ffx sdk version
-INFO: Cannot find the Fuchsia SDK toolchain, attempting to fetch it...
-Starting local Bazel server and connecting to it...
-INFO: Analyzed target @fuchsia_sdk//:fuchsia_toolchain_sdk (2 packages loaded, 2 targets configured).
-INFO: Found 1 target...
-Target @fuchsia_sdk//:fuchsia_toolchain_sdk up-to-date (nothing to build)
-INFO: Elapsed time: 46.731s, Critical Path: 0.02s
-INFO: 1 process: 1 internal.
-INFO: Build completed successfully, 1 total action
-9.20221004.1.1
-```
-
-3. To load the driver components on Qemu, first start the Qemu as specified in
+2. To load the driver components on Qemu, first start the Qemu as specified in
https://fuchsia.dev/fuchsia-src/get-started/sdk/get-started-with-driver?hl=en#start-the-emulator
-4. Follow the README.md for the specific driver, for instance da7219/README.md.
+3. Follow the README.md for the specific driver, for instance [da7219](src/da7219/README.md).
diff --git a/src/da7219/controller/BUILD.bazel b/src/da7219/controller/BUILD.bazel
index ae80447..3b632b2 100644
--- a/src/da7219/controller/BUILD.bazel
+++ b/src/da7219/controller/BUILD.bazel
@@ -31,7 +31,8 @@
deps = [
"@fuchsia_sdk//fidl/fuchsia.hardware.i2c:fuchsia.hardware.i2c_bindlib_cc",
"@fuchsia_sdk//fidl/fuchsia.hardware.i2c:fuchsia.hardware.i2c_llcpp_cc",
- "@fuchsia_sdk//pkg/driver2_cpp",
+ "@fuchsia_sdk//pkg/driver_component_cpp",
+ "@fuchsia_sdk//pkg/driver_runtime_cpp",
],
)
@@ -53,8 +54,8 @@
fuchsia_package(
name = "pkg",
package_name = "i2c_controller",
- visibility = ["//visibility:public"],
- deps = [
+ components = [
":component",
],
+ visibility = ["//visibility:public"],
)
diff --git a/src/da7219/controller/i2c_controller.cc b/src/da7219/controller/i2c_controller.cc
index edf12f2..a9a5af2 100644
--- a/src/da7219/controller/i2c_controller.cc
+++ b/src/da7219/controller/i2c_controller.cc
@@ -10,22 +10,22 @@
zx::result<> TestDa7219I2cController::Start() {
node_.Bind(std::move(node()), dispatcher());
- i2c_server_ = std::make_shared<I2cDeviceServer>(logger_);
+ i2c_server_ = std::make_shared<I2cDeviceServer>(&logger());
// Serve the fuchsia.hardware.i2c/Device protocol to clients through the
// fuchsia.hardware.i2c/Service wrapper.
- driver::ServiceInstanceHandler handler;
- fuchsia_hardware_i2c::Service::Handler service(&handler);
- auto result =
- service.add_device([this](fidl::ServerEnd<fuchsia_hardware_i2c::Device> request) -> void {
- I2cDeviceServer::BindDeviceClient(i2c_server_, dispatcher(), std::move(request));
- });
+ fuchsia_hardware_i2c::Service::InstanceHandler handler(
+ {.device = [this](fidl::ServerEnd<fuchsia_hardware_i2c::Device> request)
+ -> void {
+ I2cDeviceServer::BindDeviceClient(i2c_server_, dispatcher(),
+ std::move(request));
+ }});
+
+ auto result = context().outgoing()->AddService<fuchsia_hardware_i2c::Service>(
+ std::move(handler));
if (result.is_error()) {
- return result.take_error();
- }
- result = context().outgoing()->AddService<fuchsia_hardware_i2c::Service>(std::move(handler));
- if (result.is_error()) {
- FDF_SLOG(ERROR, "Failed to add service", KV("status", result.status_string()));
+ FDF_SLOG(ERROR, "Failed to add service",
+ KV("status", result.status_string()));
return result.take_error();
}
@@ -42,14 +42,17 @@
// Offer `fuchsia.hardware.i2c.Service` to the driver that binds to the node.
auto offers = fidl::VectorView<fuchsia_component_decl::wire::Offer>(arena, 1);
- offers[0] = driver::MakeOffer<fuchsia_hardware_i2c::Service>(arena, "default");
+ offers[0] = fdf::MakeOffer<fuchsia_hardware_i2c::Service>(arena, "default");
// Set the properties of the node that a driver will bind to.
- auto properties = fidl::VectorView<fuchsia_driver_framework::wire::NodeProperty>(arena, 2);
- properties[0] = driver::MakeEnumProperty(arena, bind_fuchsia_hardware_i2c::SERVICE,
- bind_fuchsia_hardware_i2c::SERVICE_ZIRCONTRANSPORT);
- properties[1] = driver::MakeProperty(arena, 0x0A02 /* BIND_I2C_ADDRESS */,
- 0x1a /* I2C address used by the DA7219 codec */);
+ auto properties =
+ fidl::VectorView<fuchsia_driver_framework::wire::NodeProperty>(arena, 2);
+ properties[0] =
+ fdf::MakeProperty(arena, bind_fuchsia_hardware_i2c::SERVICE,
+ bind_fuchsia_hardware_i2c::SERVICE_ZIRCONTRANSPORT);
+ properties[1] =
+ fdf::MakeProperty(arena, 0x0A02 /* BIND_I2C_ADDRESS */,
+ 0x1a /* I2C address used by the DA7219 codec */);
auto args = fuchsia_driver_framework::wire::NodeAddArgs::Builder(arena)
.name(arena, "i2c-child")
@@ -58,15 +61,18 @@
.Build();
// Create endpoints of the `NodeController` for the node.
- auto endpoints = fidl::CreateEndpoints<fuchsia_driver_framework::NodeController>();
+ auto endpoints =
+ fidl::CreateEndpoints<fuchsia_driver_framework::NodeController>();
if (endpoints.is_error()) {
- FDF_SLOG(ERROR, "Failed to create endpoint", KV("status", endpoints.status_string()));
+ FDF_SLOG(ERROR, "Failed to create endpoint",
+ KV("status", endpoints.status_string()));
return zx::error(endpoints.status_value());
}
auto result = node_.sync()->AddChild(args, std::move(endpoints->server), {});
if (!result.ok()) {
- FDF_SLOG(ERROR, "Failed to add child", KV("status", result.status_string()));
+ FDF_SLOG(ERROR, "Failed to add child",
+ KV("status", result.status_string()));
return zx::error(result.status());
}
@@ -77,4 +83,5 @@
} // namespace test_i2c_controller
-FUCHSIA_DRIVER_RECORD_CPP_V2(driver::Record<test_i2c_controller::TestDa7219I2cController>);
+FUCHSIA_DRIVER_RECORD_CPP_V2(
+ fdf::Record<test_i2c_controller::TestDa7219I2cController>);
diff --git a/src/da7219/controller/i2c_controller.h b/src/da7219/controller/i2c_controller.h
index f843064..49bfdd0 100644
--- a/src/da7219/controller/i2c_controller.h
+++ b/src/da7219/controller/i2c_controller.h
@@ -5,20 +5,22 @@
#ifndef SRC_DA7219_CONTROLLER_I2C_CONTROLLER_H_
#define SRC_DA7219_CONTROLLER_I2C_CONTROLLER_H_
-#include <lib/driver2/driver2_cpp.h>
+#include <lib/driver/component/cpp/driver_cpp.h>
+#include <lib/driver/component/cpp/service_client.h>
#include "i2c_server.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 driver::DriverBase {
+// 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 fdf::DriverBase {
public:
- TestDa7219I2cController(driver::DriverStartArgs start_args,
- fdf::UnownedDispatcher driver_dispatcher)
- : driver::DriverBase("test-da7219-i2c-controller", std::move(start_args),
- std::move(driver_dispatcher)) {}
+ TestDa7219I2cController(fdf::DriverStartArgs start_args,
+ fdf::UnownedSynchronizedDispatcher driver_dispatcher)
+ : fdf::DriverBase("test-da7219-i2c-controller", std::move(start_args),
+ std::move(driver_dispatcher)) {}
virtual ~TestDa7219I2cController() = default;
diff --git a/src/da7219/controller/i2c_server.cc b/src/da7219/controller/i2c_server.cc
index ca3c0a3..60469c6 100644
--- a/src/da7219/controller/i2c_server.cc
+++ b/src/da7219/controller/i2c_server.cc
@@ -4,14 +4,16 @@
#include "i2c_server.h"
-#include <lib/driver2/structured_logger.h>
+#include <lib/driver/component/cpp/structured_logger.h>
namespace test_i2c_controller {
// Static
// Handle incoming connection requests from FIDL clients
-fidl::ServerBindingRef<fuchsia_hardware_i2c::Device> I2cDeviceServer::BindDeviceClient(
- std::shared_ptr<I2cDeviceServer> server_impl, async_dispatcher_t* dispatcher,
+fidl::ServerBindingRef<fuchsia_hardware_i2c::Device>
+I2cDeviceServer::BindDeviceClient(
+ std::shared_ptr<I2cDeviceServer> server_impl,
+ async_dispatcher_t* dispatcher,
fidl::ServerEnd<fuchsia_hardware_i2c::Device> request) {
// Bind each connection request to the shared instance.
return fidl::BindServer(dispatcher, std::move(request), server_impl,
@@ -19,8 +21,9 @@
}
// This method is called when a server connection is torn down.
-void I2cDeviceServer::OnUnbound(fidl::UnbindInfo info,
- fidl::ServerEnd<fuchsia_hardware_i2c::Device> server_end) {
+void I2cDeviceServer::OnUnbound(
+ fidl::UnbindInfo info,
+ fidl::ServerEnd<fuchsia_hardware_i2c::Device> server_end) {
if (info.is_peer_closed()) {
FDF_LOG(DEBUG, "Client disconnected");
} else if (!info.is_user_initiated()) {
@@ -28,8 +31,10 @@
}
}
-// Protocol method of `fuchsia.hardware.i2c.Device` to handle data transfer requests.
-void I2cDeviceServer::Transfer(TransferRequestView request, TransferCompleter::Sync& completer) {
+// Protocol method of `fuchsia.hardware.i2c.Device` to handle data transfer
+// requests.
+void I2cDeviceServer::Transfer(TransferRequestView request,
+ TransferCompleter::Sync& completer) {
FDF_SLOG(DEBUG, "Received transfer request");
// Must be either a write transfer (2 bytes write) or
@@ -39,15 +44,18 @@
const auto& transfer = request->transactions[0].data_transfer();
ZX_ASSERT(transfer.is_write_data() && !transfer.is_read_size());
ZX_ASSERT(transfer.write_data().count() == 2);
- FDF_SLOG(INFO, "Received write", KV("address", static_cast<int>(transfer.write_data()[0])));
- FDF_SLOG(INFO, "Received write", KV("data", static_cast<int>(transfer.write_data()[1])));
+ FDF_SLOG(INFO, "Received write",
+ KV("address", static_cast<int>(transfer.write_data()[0])));
+ FDF_SLOG(INFO, "Received write",
+ KV("data", static_cast<int>(transfer.write_data()[1])));
completer.ReplySuccess({});
} else if (request->transactions.count() == 2) { // Read transfer.
ZX_ASSERT(request->transactions[0].has_data_transfer());
const auto& transfer0 = request->transactions[0].data_transfer();
ZX_ASSERT(transfer0.is_write_data() && !transfer0.is_read_size());
ZX_ASSERT(transfer0.write_data().count() == 1);
- FDF_SLOG(INFO, "Received write", KV("address", static_cast<int>(transfer0.write_data()[0])));
+ FDF_SLOG(INFO, "Received write",
+ KV("address", static_cast<int>(transfer0.write_data()[0])));
const auto& transfer1 = request->transactions[1].data_transfer();
ZX_ASSERT(!transfer1.is_write_data() && transfer1.is_read_size());
ZX_ASSERT(transfer1.read_size() == 1);
@@ -56,8 +64,10 @@
// Test read by sending arbitrary values.
constexpr uint8_t kTestArbitraryDataToRead = 12;
read_bytes[0] = kTestArbitraryDataToRead;
- FDF_SLOG(INFO, "Read data to send", KV("data", static_cast<int>(read_bytes[0])));
- auto read_results = fidl::VectorView<fidl::VectorView<uint8_t>>(allocator, 1);
+ FDF_SLOG(INFO, "Read data to send",
+ KV("data", static_cast<int>(read_bytes[0])));
+ auto read_results =
+ fidl::VectorView<fidl::VectorView<uint8_t>>(allocator, 1);
read_results[0] = read_bytes;
completer.ReplySuccess(read_results);
} else {
@@ -65,4 +75,8 @@
}
}
+void I2cDeviceServer::GetName(GetNameCompleter::Sync& completer) {
+ completer.ReplySuccess("test-i2c-server");
+}
+
} // namespace test_i2c_controller
diff --git a/src/da7219/controller/i2c_server.h b/src/da7219/controller/i2c_server.h
index 87c4151..27db03c 100644
--- a/src/da7219/controller/i2c_server.h
+++ b/src/da7219/controller/i2c_server.h
@@ -6,24 +6,28 @@
#define SRC_DA7219_CONTROLLER_I2C_SERVER_H_
#include <fidl/fuchsia.hardware.i2c/cpp/wire.h>
-#include <lib/driver2/logger.h>
+#include <lib/driver/component/cpp/logger.h>
namespace test_i2c_controller {
// FIDL server implementation for the `fuchsia.hardware.i2c/Device` protocol
class I2cDeviceServer : public fidl::WireServer<fuchsia_hardware_i2c::Device> {
public:
- I2cDeviceServer(driver::Logger& logger) : logger_(logger) {}
+ I2cDeviceServer(fdf::Logger* logger) : logger_(logger) {}
static fidl::ServerBindingRef<fuchsia_hardware_i2c::Device> BindDeviceClient(
- std::shared_ptr<I2cDeviceServer> server_impl, async_dispatcher_t* dispatcher,
+ std::shared_ptr<I2cDeviceServer> server_impl,
+ async_dispatcher_t* dispatcher,
fidl::ServerEnd<fuchsia_hardware_i2c::Device> request);
- void OnUnbound(fidl::UnbindInfo info, fidl::ServerEnd<fuchsia_hardware_i2c::Device> server_end);
+ void OnUnbound(fidl::UnbindInfo info,
+ fidl::ServerEnd<fuchsia_hardware_i2c::Device> server_end);
- void Transfer(TransferRequestView request, TransferCompleter::Sync& completer) override;
+ void Transfer(TransferRequestView request,
+ TransferCompleter::Sync& completer) override;
+ void GetName(GetNameCompleter::Sync& completer) override;
private:
- driver::Logger& logger_;
+ fdf::Logger* logger_;
};
} // namespace test_i2c_controller
diff --git a/src/da7219/controller/meta/i2c_controller.cml b/src/da7219/controller/meta/i2c_controller.cml
index ba27447..5f95399 100644
--- a/src/da7219/controller/meta/i2c_controller.cml
+++ b/src/da7219/controller/meta/i2c_controller.cml
@@ -5,7 +5,7 @@
include: [ 'syslog/client.shard.cml' ],
program: {
runner: 'driver',
- binary: 'lib/libi2c_controller.so',
+ binary: 'driver/libi2c_controller.so',
bind: 'meta/bind/i2c_controller.bindbc',
},
capabilities: [
diff --git a/src/da7219/driver/BUILD.bazel b/src/da7219/driver/BUILD.bazel
index f5183bf..ad017a1 100644
--- a/src/da7219/driver/BUILD.bazel
+++ b/src/da7219/driver/BUILD.bazel
@@ -39,7 +39,8 @@
deps = [
"@fuchsia_sdk//fidl/fuchsia.hardware.audio:fuchsia.hardware.audio_llcpp_cc",
"@fuchsia_sdk//fidl/fuchsia.hardware.i2c:fuchsia.hardware.i2c_llcpp_cc",
- "@fuchsia_sdk//pkg/driver2_cpp",
+ "@fuchsia_sdk//pkg/driver_component_cpp",
+ "@fuchsia_sdk//pkg/driver_runtime_cpp",
],
)
@@ -53,8 +54,8 @@
fuchsia_package(
name = "pkg",
package_name = "da7219",
- visibility = ["//visibility:public"],
- deps = [
+ components = [
":component",
],
+ visibility = ["//visibility:public"],
)
diff --git a/src/da7219/driver/da7219.cc b/src/da7219/driver/da7219.cc
index f6ffbfe..035d380 100644
--- a/src/da7219/driver/da7219.cc
+++ b/src/da7219/driver/da7219.cc
@@ -6,28 +6,31 @@
#include <fidl/fuchsia.hardware.audio/cpp/wire.h>
#include <fidl/fuchsia.hardware.i2c/cpp/wire.h>
-#include <lib/driver2/service_client.h>
+#include <lib/driver/component/cpp/service_client.h>
namespace {
// FIDL server implementation for the `fuchsia.examples.audio/Codec` protocol
class Da7219Server : public fidl::WireServer<fuchsia_hardware_audio::Codec> {
public:
- Da7219Server(driver::Logger& logger, std::weak_ptr<I2cChannel> i2c_channel)
+ Da7219Server(fdf::Logger* logger, std::weak_ptr<I2cChannel> i2c_channel)
: logger_(logger), i2c_channel_(i2c_channel) {}
// Handle incoming connection requests from FIDL clients
static fidl::ServerBindingRef<fuchsia_hardware_audio::Codec> BindDeviceClient(
- async_dispatcher_t* dispatcher, driver::Logger& logger, std::weak_ptr<I2cChannel> i2c_channel,
+ async_dispatcher_t* dispatcher, fdf::Logger* logger,
+ std::weak_ptr<I2cChannel> i2c_channel,
fidl::ServerEnd<fuchsia_hardware_audio::Codec> request) {
// Bind each connection request to a unique FIDL server instance
auto server_impl = std::make_unique<Da7219Server>(logger, i2c_channel);
- return fidl::BindServer(dispatcher, std::move(request), std::move(server_impl),
+ return fidl::BindServer(dispatcher, std::move(request),
+ std::move(server_impl),
std::mem_fn(&Da7219Server::OnUnbound));
}
// This method is called when a server connection is torn down.
- void OnUnbound(fidl::UnbindInfo info, fidl::ServerEnd<fuchsia_hardware_audio::Codec> server_end) {
+ void OnUnbound(fidl::UnbindInfo info,
+ fidl::ServerEnd<fuchsia_hardware_audio::Codec> server_end) {
if (info.is_peer_closed()) {
FDF_LOG(DEBUG, "Client disconnected");
} else if (!info.is_user_initiated()) {
@@ -47,13 +50,15 @@
void GetDaiFormats(GetDaiFormatsCompleter::Sync& completer) override {}
void SetDaiFormat(SetDaiFormatRequestView request,
SetDaiFormatCompleter::Sync& completer) override {}
- void GetPlugDetectCapabilities(GetPlugDetectCapabilitiesCompleter::Sync& completer) override {}
+ void GetPlugDetectCapabilities(
+ GetPlugDetectCapabilitiesCompleter::Sync& completer) override {}
void WatchPlugState(WatchPlugStateCompleter::Sync& completer) override {}
- void SignalProcessingConnect(SignalProcessingConnectRequestView request,
- SignalProcessingConnectCompleter::Sync& completer) override {}
+ void SignalProcessingConnect(
+ SignalProcessingConnectRequestView request,
+ SignalProcessingConnectCompleter::Sync& completer) override {}
private:
- driver::Logger& logger_;
+ fdf::Logger* logger_;
std::weak_ptr<I2cChannel> i2c_channel_;
};
@@ -69,19 +74,16 @@
// Serve the fuchsia.hardware.audio/Codec protocol to clients through the
// fuchsia.hardware.audio/CodecService wrapper.
- driver::ServiceInstanceHandler handler;
- fuchsia_hardware_audio::CodecService::Handler service(&handler);
+ fuchsia_hardware_audio::CodecService::InstanceHandler handler({
+ .codec = fit::bind_member<&Da7219Driver::Serve>(this),
+ });
auto result =
- service.add_codec([this](fidl::ServerEnd<fuchsia_hardware_audio::Codec> request) -> void {
- Da7219Server::BindDeviceClient(dispatcher(), logger_, i2c_channel_, std::move(request));
- });
- ZX_ASSERT(result.is_ok());
-
- result =
- context().outgoing()->AddService<fuchsia_hardware_audio::CodecService>(std::move(handler));
+ context().outgoing()->AddService<fuchsia_hardware_audio::CodecService>(
+ std::move(handler));
if (result.is_error()) {
- FDF_SLOG(ERROR, "Failed to add service", KV("status", result.status_string()));
+ FDF_SLOG(ERROR, "Failed to add service",
+ KV("status", result.status_string()));
return result.take_error();
}
@@ -89,14 +91,17 @@
constexpr uint8_t kTestArbitraryAddress0 = 34;
constexpr uint8_t kTestArbitraryDataToWrite0 = 56;
constexpr uint8_t kTestArbitraryAddress1 = 78;
- auto write_status = i2c_channel_->Write(kTestArbitraryAddress0, kTestArbitraryDataToWrite0);
+ auto write_status =
+ i2c_channel_->Write(kTestArbitraryAddress0, kTestArbitraryDataToWrite0);
if (write_status.is_error()) {
- FDF_SLOG(ERROR, "Failed to write to I2C", KV("status", write_status.status_string()));
+ FDF_SLOG(ERROR, "Failed to write to I2C",
+ KV("status", write_status.status_string()));
return write_status.take_error();
}
auto i2c_read = i2c_channel_->Read(kTestArbitraryAddress1);
if (i2c_read.is_error()) {
- FDF_SLOG(ERROR, "Failed to read from I2C", KV("status", i2c_read.status_string()));
+ FDF_SLOG(ERROR, "Failed to read from I2C",
+ KV("status", i2c_read.status_string()));
return i2c_read.take_error();
}
FDF_SLOG(INFO, "Read", KV("byte", static_cast<int>(i2c_read.value())));
@@ -106,12 +111,14 @@
return zx::ok();
}
-// Connect to the `fuchsia.hardware.i2c/Device` protocol offered by the parent device node.
+// Connect to the `fuchsia.hardware.i2c/Device` protocol offered by the parent
+// device node.
zx::result<> Da7219Driver::SetupI2cChannel() {
- auto client_endpoint =
- driver::Connect<fuchsia_hardware_i2c::Service::Device>(*context().incoming(), "default");
+ auto client_endpoint = fdf::Connect<fuchsia_hardware_i2c::Service::Device>(
+ *context().incoming(), "default");
if (client_endpoint.status_value() != ZX_OK) {
- FDF_SLOG(ERROR, "Failed to setup I2cChannel", KV("status", client_endpoint.status_string()));
+ FDF_SLOG(ERROR, "Failed to setup I2cChannel",
+ KV("status", client_endpoint.status_string()));
return client_endpoint.take_error();
}
@@ -120,6 +127,12 @@
return zx::ok();
}
+void Da7219Driver::Serve(
+ fidl::ServerEnd<fuchsia_hardware_audio::Codec> request) {
+ Da7219Server::BindDeviceClient(dispatcher(), &logger(), i2c_channel_,
+ std::move(request));
+}
+
} // namespace audio
-FUCHSIA_DRIVER_RECORD_CPP_V2(driver::Record<audio::Da7219Driver>);
+FUCHSIA_DRIVER_RECORD_CPP_V2(fdf::Record<audio::Da7219Driver>);
diff --git a/src/da7219/driver/da7219.h b/src/da7219/driver/da7219.h
index 8afd6ec..efb55d2 100644
--- a/src/da7219/driver/da7219.h
+++ b/src/da7219/driver/da7219.h
@@ -5,16 +5,19 @@
#ifndef SRC_DA7219_DRIVER_DA7219_H_
#define SRC_DA7219_DRIVER_DA7219_H_
-#include <lib/driver2/driver2_cpp.h>
+#include <fidl/fuchsia.hardware.audio/cpp/wire.h>
+#include <lib/driver/component/cpp/driver_cpp.h>
#include "i2c_channel.h"
namespace audio {
-class Da7219Driver : public driver::DriverBase {
+class Da7219Driver : public fdf::DriverBase {
public:
- Da7219Driver(driver::DriverStartArgs start_args, fdf::UnownedDispatcher driver_dispatcher)
- : driver::DriverBase("da7219", std::move(start_args), std::move(driver_dispatcher)) {}
+ Da7219Driver(fdf::DriverStartArgs start_args,
+ fdf::UnownedSynchronizedDispatcher driver_dispatcher)
+ : fdf::DriverBase("da7219", std::move(start_args),
+ std::move(driver_dispatcher)) {}
virtual ~Da7219Driver() = default;
@@ -22,6 +25,7 @@
private:
zx::result<> SetupI2cChannel();
+ void Serve(fidl::ServerEnd<fuchsia_hardware_audio::Codec> request);
std::shared_ptr<I2cChannel> i2c_channel_;
};
diff --git a/src/da7219/driver/i2c_channel.cc b/src/da7219/driver/i2c_channel.cc
index 2b2e7ec..2346671 100644
--- a/src/da7219/driver/i2c_channel.cc
+++ b/src/da7219/driver/i2c_channel.cc
@@ -6,7 +6,7 @@
#include <endian.h>
-zx::status<uint8_t> I2cChannel::Read(uint8_t address) {
+zx::result<uint8_t> I2cChannel::Read(uint8_t address) {
uint8_t value;
auto status = WriteReadSync(&address, sizeof(address), &value, sizeof(value));
@@ -17,15 +17,16 @@
return zx::ok(value);
}
-zx::status<> I2cChannel::Write(uint8_t address, uint8_t value) {
+zx::result<> I2cChannel::Write(uint8_t address, uint8_t value) {
uint8_t data[2];
data[0] = address;
data[1] = value;
- return WriteReadSync(reinterpret_cast<uint8_t*>(&data), sizeof(data), nullptr, 0);
+ return WriteReadSync(reinterpret_cast<uint8_t*>(&data), sizeof(data), nullptr,
+ 0);
}
-zx::status<> I2cChannel::WriteReadSync(const uint8_t* tx_buf, size_t tx_len, uint8_t* rx_buf,
- size_t rx_len) {
+zx::result<> I2cChannel::WriteReadSync(const uint8_t* tx_buf, size_t tx_len,
+ uint8_t* rx_buf, size_t rx_len) {
if (tx_len > fuchsia_hardware_i2c::wire::kMaxTransferSize ||
rx_len > fuchsia_hardware_i2c::wire::kMaxTransferSize) {
return zx::error(ZX_ERR_OUT_OF_RANGE);
@@ -37,22 +38,25 @@
memcpy(write_data.data(), tx_buf, tx_len);
}
- auto write_transfer = fuchsia_hardware_i2c::wire::DataTransfer::WithWriteData(arena, write_data);
- auto read_transfer =
- fuchsia_hardware_i2c::wire::DataTransfer::WithReadSize(static_cast<uint32_t>(rx_len));
+ auto write_transfer = fuchsia_hardware_i2c::wire::DataTransfer::WithWriteData(
+ arena, write_data);
+ auto read_transfer = fuchsia_hardware_i2c::wire::DataTransfer::WithReadSize(
+ static_cast<uint32_t>(rx_len));
fuchsia_hardware_i2c::wire::Transaction transactions[2];
size_t index = 0;
if (tx_len > 0) {
- transactions[index++] = fuchsia_hardware_i2c::wire::Transaction::Builder(arena)
- .data_transfer(write_transfer)
- .Build();
+ transactions[index++] =
+ fuchsia_hardware_i2c::wire::Transaction::Builder(arena)
+ .data_transfer(write_transfer)
+ .Build();
}
if (rx_len > 0) {
- transactions[index++] = fuchsia_hardware_i2c::wire::Transaction::Builder(arena)
- .data_transfer(read_transfer)
- .Build();
+ transactions[index++] =
+ fuchsia_hardware_i2c::wire::Transaction::Builder(arena)
+ .data_transfer(read_transfer)
+ .Build();
}
if (index == 0) {
@@ -60,7 +64,8 @@
}
const auto reply = fidl_client_.sync()->Transfer(
- fidl::VectorView<fuchsia_hardware_i2c::wire::Transaction>::FromExternal(transactions, index));
+ fidl::VectorView<fuchsia_hardware_i2c::wire::Transaction>::FromExternal(
+ transactions, index));
if (!reply.ok()) {
return zx::error(reply.status());
}
diff --git a/src/da7219/driver/i2c_channel.h b/src/da7219/driver/i2c_channel.h
index f604155..d4282c1 100644
--- a/src/da7219/driver/i2c_channel.h
+++ b/src/da7219/driver/i2c_channel.h
@@ -19,11 +19,12 @@
~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);
+ zx::result<uint8_t> Read(uint8_t address);
+ zx::result<> 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);
+ zx::result<> 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_;
};
diff --git a/src/da7219/driver/meta/da7219.cml b/src/da7219/driver/meta/da7219.cml
index 92d6467..cc743bd 100644
--- a/src/da7219/driver/meta/da7219.cml
+++ b/src/da7219/driver/meta/da7219.cml
@@ -5,7 +5,7 @@
include: [ 'syslog/client.shard.cml' ],
program: {
runner: 'driver',
- binary: 'lib/libda7219.so',
+ binary: 'driver/libda7219.so',
bind: 'meta/bind/da7219.bindbc',
},
capabilities: [
diff --git a/third_party/sdk-integration b/third_party/sdk-integration
index 7bb163a..e677751 160000
--- a/third_party/sdk-integration
+++ b/third_party/sdk-integration
@@ -1 +1 @@
-Subproject commit 7bb163ac908f161e813bdabb3f904884d1c6d1a9
+Subproject commit e6777517790fbf8da2eae6f5580b0289573bf7aa