1#![deny(missing_docs)]
6use fdf_component::{DriverContext, DriverError};
9use fidl_next::Client;
10use fidl_next_fuchsia_hardware_clock as fclock;
11use fidl_next_fuchsia_hardware_gpio as fgpio;
12use fidl_next_fuchsia_hardware_i2c as fi2c;
13use fidl_next_fuchsia_hardware_mailbox as fmailbox;
14use fidl_next_fuchsia_hardware_pci as fpci;
15use fidl_next_fuchsia_hardware_reset as freset;
16use fidl_next_fuchsia_hardware_spi as fspi;
17
18pub trait ClockExt {
20 fn connect_to_clock(&self, instance: &str) -> Result<Client<fclock::Clock>, DriverError>;
22}
23
24impl ClockExt for DriverContext {
25 fn connect_to_clock(&self, instance: &str) -> Result<Client<fclock::Clock>, DriverError> {
26 let service = self
27 .incoming
28 .service::<fdf_component::ServiceInstance<fclock::Service>>()
29 .instance(instance)
30 .connect_next()?;
31 let (client, server) = fidl_next::fuchsia::create_channel();
32 service.clock(server)?;
33 Ok(client.spawn())
34 }
35}
36
37pub trait GpioExt {
39 fn connect_to_gpio(&self, instance: &str) -> Result<Client<fgpio::Gpio>, DriverError>;
41}
42
43impl GpioExt for DriverContext {
44 fn connect_to_gpio(&self, instance: &str) -> Result<Client<fgpio::Gpio>, DriverError> {
45 let service = self
46 .incoming
47 .service::<fdf_component::ServiceInstance<fgpio::Service>>()
48 .instance(instance)
49 .connect_next()?;
50 let (client, server) = fidl_next::fuchsia::create_channel();
51 service.device(server)?;
52 Ok(client.spawn())
53 }
54}
55
56pub trait I2cExt {
58 fn connect_to_i2c(&self, instance: &str) -> Result<Client<fi2c::Device>, DriverError>;
60}
61
62impl I2cExt for DriverContext {
63 fn connect_to_i2c(&self, instance: &str) -> Result<Client<fi2c::Device>, DriverError> {
64 let service = self
65 .incoming
66 .service::<fdf_component::ServiceInstance<fi2c::Service>>()
67 .instance(instance)
68 .connect_next()?;
69 let (client, server) = fidl_next::fuchsia::create_channel();
70 service.device(server)?;
71 Ok(client.spawn())
72 }
73}
74
75pub trait MailboxExt {
77 fn connect_to_mailbox(&self, instance: &str) -> Result<Client<fmailbox::Channel>, DriverError>;
79}
80
81impl MailboxExt for DriverContext {
82 fn connect_to_mailbox(&self, instance: &str) -> Result<Client<fmailbox::Channel>, DriverError> {
83 let service = self
84 .incoming
85 .service::<fdf_component::ServiceInstance<fmailbox::Service>>()
86 .instance(instance)
87 .connect_next()?;
88 let (client, server) = fidl_next::fuchsia::create_channel();
89 service.channel(server)?;
90 Ok(client.spawn())
91 }
92}
93
94pub trait ResetExt {
96 fn connect_to_reset(&self, instance: &str) -> Result<Client<freset::Reset>, DriverError>;
98}
99
100impl ResetExt for DriverContext {
101 fn connect_to_reset(&self, instance: &str) -> Result<Client<freset::Reset>, DriverError> {
102 let service = self
103 .incoming
104 .service::<fdf_component::ServiceInstance<freset::Service>>()
105 .instance(instance)
106 .connect_next()?;
107 let (client, server) = fidl_next::fuchsia::create_channel();
108 service.reset(server)?;
109 Ok(client.spawn())
110 }
111}
112
113pub trait SpiExt {
115 fn connect_to_spi(&self, instance: &str) -> Result<Client<fspi::Device>, DriverError>;
117}
118
119impl SpiExt for DriverContext {
120 fn connect_to_spi(&self, instance: &str) -> Result<Client<fspi::Device>, DriverError> {
121 let service = self
122 .incoming
123 .service::<fdf_component::ServiceInstance<fspi::Service>>()
124 .instance(instance)
125 .connect_next()?;
126 let (client, server) = fidl_next::fuchsia::create_channel();
127 service.device(server)?;
128 Ok(client.spawn())
129 }
130}
131
132pub trait PciExt {
135 fn connect_to_pci(&self, instance: &str) -> Result<Client<fpci::Device>, DriverError>;
137}
138
139impl PciExt for DriverContext {
140 fn connect_to_pci(&self, instance: &str) -> Result<Client<fpci::Device>, DriverError> {
141 let service = self
142 .incoming
143 .service::<fdf_component::ServiceInstance<fpci::Service>>()
144 .instance(instance)
145 .connect_next()?;
146 let (client, server) = fidl_next::fuchsia::create_channel();
147 service.device(server)?;
148 Ok(client.spawn())
149 }
150}