use core::mem::MaybeUninit;
use kernel::component::Component;
use kernel::hil;
#[macro_export]
macro_rules! sh1106_component_static {
($I: ty $(,)?) => {{
let buffer = kernel::static_buf!([u8; capsules_extra::sh1106::BUFFER_SIZE]);
let sh1106 = kernel::static_buf!(
capsules_extra::sh1106::Sh1106<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, $I>,
>
);
(buffer, sh1106)
};};
}
pub type Sh1106ComponentType<I> = capsules_extra::sh1106::Sh1106<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
>;
pub struct Sh1106Component<I: hil::i2c::I2CMaster<'static> + 'static> {
i2c_device: &'static capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
use_charge_pump: bool,
}
impl<I: hil::i2c::I2CMaster<'static> + 'static> Sh1106Component<I> {
pub fn new(
i2c_device: &'static capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
use_charge_pump: bool,
) -> Sh1106Component<I> {
Sh1106Component {
i2c_device,
use_charge_pump,
}
}
}
impl<I: hil::i2c::I2CMaster<'static> + 'static> Component for Sh1106Component<I> {
type StaticInput = (
&'static mut MaybeUninit<[u8; capsules_extra::sh1106::BUFFER_SIZE]>,
&'static mut MaybeUninit<
capsules_extra::sh1106::Sh1106<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
>,
>,
);
type Output = &'static capsules_extra::sh1106::Sh1106<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
>;
fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
let buffer = static_buffer
.0
.write([0; capsules_extra::sh1106::BUFFER_SIZE]);
let sh1106 = static_buffer.1.write(capsules_extra::sh1106::Sh1106::new(
self.i2c_device,
buffer,
self.use_charge_pump,
));
self.i2c_device.set_client(sh1106);
sh1106
}
}