use core::mem::MaybeUninit;
use kernel::component::Component;
use kernel::hil;
#[macro_export]
macro_rules! ssd1306_component_static {
($I: ty $(,)?) => {{
let buffer = kernel::static_buf!([u8; capsules_extra::ssd1306::BUFFER_SIZE]);
let ssd1306 = kernel::static_buf!(
capsules_extra::ssd1306::Ssd1306<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, $I>,
>
);
(buffer, ssd1306)
};};
}
pub type Ssd1306ComponentType<I> = capsules_extra::ssd1306::Ssd1306<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
>;
pub struct Ssd1306Component<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> Ssd1306Component<I> {
pub fn new(
i2c_device: &'static capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
use_charge_pump: bool,
) -> Ssd1306Component<I> {
Ssd1306Component {
i2c_device,
use_charge_pump,
}
}
}
impl<I: hil::i2c::I2CMaster<'static> + 'static> Component for Ssd1306Component<I> {
type StaticInput = (
&'static mut MaybeUninit<[u8; capsules_extra::ssd1306::BUFFER_SIZE]>,
&'static mut MaybeUninit<
capsules_extra::ssd1306::Ssd1306<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, I>,
>,
>,
);
type Output = &'static capsules_extra::ssd1306::Ssd1306<
'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::ssd1306::BUFFER_SIZE]);
let ssd1306 = static_buffer.1.write(capsules_extra::ssd1306::Ssd1306::new(
self.i2c_device,
buffer,
self.use_charge_pump,
));
self.i2c_device.set_client(ssd1306);
ssd1306
}
}