Skip to content

Commit

Permalink
capsules: add screen_shared
Browse files Browse the repository at this point in the history
This gives multiple processes access to separate regions of a screen.
  • Loading branch information
bradjc committed Jan 19, 2024
1 parent 5c2680e commit b8ff9be
Show file tree
Hide file tree
Showing 3 changed files with 529 additions and 0 deletions.
70 changes: 70 additions & 0 deletions boards/components/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
//! ```

use capsules_extra::screen::Screen;
use capsules_extra::screen_shared::ScreenShared;
use core::mem::MaybeUninit;
use kernel::capabilities;
use kernel::component::Component;
use kernel::create_capability;
use kernel::hil;

#[macro_export]
macro_rules! screen_component_static {
Expand Down Expand Up @@ -97,3 +99,71 @@ impl<const SCREEN_BUF_LEN: usize> Component for ScreenComponent<SCREEN_BUF_LEN>
screen
}
}

#[macro_export]
macro_rules! screen_shared_component_static {
($s:literal, $S:ty $(,)?) => {{
let buffer = kernel::static_buf!([u8; $s]);
let screen = kernel::static_buf!(capsules_extra::screen_shared::ScreenShared<$S>);

(buffer, screen)
};};
}

pub type ScreenSharedComponentType<S> = capsules_extra::screen_shared::ScreenShared<'static, S>;

pub struct ScreenSharedComponent<
const SCREEN_BUF_LEN: usize,
S: hil::screen::Screen<'static> + 'static,
> {
board_kernel: &'static kernel::Kernel,
driver_num: usize,
screen: &'static S,
apps_regions: &'static [capsules_extra::screen_shared::AppScreenRegion],
}

impl<const SCREEN_BUF_LEN: usize, S: hil::screen::Screen<'static>>
ScreenSharedComponent<SCREEN_BUF_LEN, S>
{
pub fn new(
board_kernel: &'static kernel::Kernel,
driver_num: usize,
screen: &'static S,
apps_regions: &'static [capsules_extra::screen_shared::AppScreenRegion],
) -> ScreenSharedComponent<SCREEN_BUF_LEN, S> {
ScreenSharedComponent {
board_kernel,
driver_num,
screen,
apps_regions,
}
}
}

impl<const SCREEN_BUF_LEN: usize, S: hil::screen::Screen<'static>> Component
for ScreenSharedComponent<SCREEN_BUF_LEN, S>
{
type StaticInput = (
&'static mut MaybeUninit<[u8; SCREEN_BUF_LEN]>,
&'static mut MaybeUninit<ScreenShared<'static, S>>,
);
type Output = &'static ScreenShared<'static, S>;

fn finalize(self, static_input: Self::StaticInput) -> Self::Output {
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
let grant_screen = self.board_kernel.create_grant(self.driver_num, &grant_cap);

let buffer = static_input.0.write([0; SCREEN_BUF_LEN]);

let screen = static_input.1.write(ScreenShared::new(
self.screen,
grant_screen,
buffer,
self.apps_regions,
));

kernel::hil::screen::Screen::set_client(self.screen, screen);

screen
}
}
1 change: 1 addition & 0 deletions capsules/extra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub mod read_only_state;
pub mod rf233;
pub mod rf233_const;
pub mod screen;
pub mod screen_shared;
pub mod sdcard;
pub mod segger_rtt;
pub mod seven_segment;
Expand Down
Loading

0 comments on commit b8ff9be

Please sign in to comment.