Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions boards/components/src/graphic_display.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

//! Components for the Screen.
//!
//! Buffer Size
//! -----------
//!
//! Displays can receive a large amount of data and having larger transfer buffers
//! optimizes the number of bus writes.
//!
//! As memory is limited on some MCUs, the `components::screen_buffer_size``
//! macro allows users to define the size of the screen buffer.
//!
//! Usage
//! -----
//!
//! // Screen
//! ```rust
//! let screen =
//! components::screen::GraphicDisplayComponent::new(board_kernel, tft, None)
//! .finalize(components::graphic_display_component_static!(40960));
//! ```
//!
//! // Screen with Setup
//! ```rust
//! let screen =
//! components::screen::GraphicDisplayComponent::new(board_kernel, tft, Some(tft))
//! .finalize(components::graphic_display_component_static!(40960));
//! ```

use capsules_extra::graphic_display::GraphicDisplay;
use core::mem::MaybeUninit;
use kernel::capabilities;
use kernel::component::Component;
use kernel::create_capability;
use kernel::hil::display;

#[macro_export]
macro_rules! graphic_display_component_static {
($s:literal $(,)?) => {{
let buffer = kernel::static_buf!([u8; $s]);
let screen = kernel::static_buf!(capsules_extra::graphic_display::GraphicDisplay);

(buffer, screen)
};};
}

pub struct GraphicDisplayComponent<const SCREEN_BUF_LEN: usize> {
board_kernel: &'static kernel::Kernel,
driver_num: usize,
display: &'static dyn display::GraphicDisplay<'static>,
display_setup: Option<&'static dyn display::FrameBufferSetup<'static>>,
}

impl<const SCREEN_BUF_LEN: usize> GraphicDisplayComponent<SCREEN_BUF_LEN> {
pub fn new(
board_kernel: &'static kernel::Kernel,
driver_num: usize,
display: &'static dyn display::GraphicDisplay<'static>,
display_setup: Option<&'static dyn display::FrameBufferSetup<'static>>,
) -> GraphicDisplayComponent<SCREEN_BUF_LEN> {
GraphicDisplayComponent {
board_kernel,
driver_num,
display,
display_setup,
}
}
}

impl<const SCREEN_BUF_LEN: usize> Component for GraphicDisplayComponent<SCREEN_BUF_LEN> {
type StaticInput = (
&'static mut MaybeUninit<[u8; SCREEN_BUF_LEN]>,
&'static mut MaybeUninit<GraphicDisplay<'static>>,
);
type Output = &'static GraphicDisplay<'static>;

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 display = static_input.1.write(GraphicDisplay::new(
self.display,
self.display_setup,
buffer,
grant_screen,
));

display::Screen::set_client(self.display, Some(display));
display::FrameBuffer::set_client(self.display, Some(display));
if let Some(display_setup) = self.display_setup {
display::FrameBuffer::set_client(display_setup, Some(display));
}

display
}
}
2 changes: 2 additions & 0 deletions boards/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub mod fm25cl;
pub mod ft6x06;
pub mod fxos8700;
pub mod gpio;
pub mod graphic_display;
pub mod hd44780;
pub mod hmac;
pub mod hs3003;
Expand Down Expand Up @@ -77,6 +78,7 @@ pub mod si7021;
pub mod siphash;
pub mod sound_pressure;
pub mod spi;
pub mod ssd1306;
pub mod st77xx;
pub mod temperature;
pub mod temperature_rp2040;
Expand Down
109 changes: 109 additions & 0 deletions boards/components/src/ssd1306.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use capsules_extra::bus;
use capsules_extra::ssd1306;
use core::mem::MaybeUninit;
use kernel::component::Component;
use kernel::deferred_call::DeferredCall;
use kernel::deferred_call::DeferredCallClient;

#[macro_export]
macro_rules! ssd1306_component_static {
($B: ty, $(,)?) => {{
let buffer = kernel::static_buf!([u8; capsules_extra::ssd1306::BUFFER_SIZE]);
let app_write_buffer = kernel::static_buf!(
[u8; capsules_extra::ssd1306::WIDTH * capsules_extra::ssd1306::HEIGHT / 8
+ capsules_extra::ssd1306::BUFFER_PADDING]
);
let bus_write_buffer = kernel::static_buf!(
[u8; capsules_extra::ssd1306::WIDTH * capsules_extra::ssd1306::HEIGHT / 8
+ capsules_extra::ssd1306::BUFFER_PADDING]
);
let aux_write_buffer = kernel::static_buf!(
[u8; capsules_extra::ssd1306::WIDTH * capsules_extra::ssd1306::HEIGHT / 8
+ capsules_extra::ssd1306::BUFFER_PADDING]
);
let command_sequence = kernel::static_buf!(
[capsules_extra::ssd1306::ScreenCommand; capsules_extra::ssd1306::SEQUENCE_BUFFER_SIZE]
);
let ssd1306 = kernel::static_buf!(capsules_extra::ssd1306::SSD1306<'static, $B>);
(
ssd1306,
command_sequence,
buffer,
app_write_buffer,
bus_write_buffer,
aux_write_buffer,
)
};};
}

pub struct SSD1306Component<B: 'static + bus::Bus<'static>> {
bus: &'static B,
deferred_caller: DeferredCall,
}

impl<B: 'static + bus::Bus<'static>> SSD1306Component<B> {
pub fn new(bus: &'static B) -> SSD1306Component<B> {
SSD1306Component {
bus,
deferred_caller: DeferredCall::new(),
}
}
}

impl<B: 'static + bus::Bus<'static>> Component for SSD1306Component<B> {
type StaticInput = (
&'static mut MaybeUninit<ssd1306::SSD1306<'static, B>>,
&'static mut MaybeUninit<[ssd1306::ScreenCommand; ssd1306::SEQUENCE_BUFFER_SIZE]>,
&'static mut MaybeUninit<[u8; ssd1306::BUFFER_SIZE]>,
&'static mut MaybeUninit<
[u8; ssd1306::HEIGHT * ssd1306::WIDTH / 8 + ssd1306::BUFFER_PADDING],
>,
&'static mut MaybeUninit<
[u8; ssd1306::HEIGHT * ssd1306::WIDTH / 8 + ssd1306::BUFFER_PADDING],
>,
&'static mut MaybeUninit<
[u8; ssd1306::HEIGHT * ssd1306::WIDTH / 8 + ssd1306::BUFFER_PADDING],
>,
);

type Output = &'static ssd1306::SSD1306<'static, B>;

fn finalize(self, static_memory: Self::StaticInput) -> Self::Output {
let command_sequence = static_memory.1.write(
[ssd1306::ScreenCommand {
id: ssd1306::CommandId::Nop,
parameters: None,
}; ssd1306::SEQUENCE_BUFFER_SIZE],
);
let command_arguments = static_memory.2.write([0; ssd1306::BUFFER_SIZE]);
let app_write_buffer = static_memory
.3
.write([0; ssd1306::HEIGHT * ssd1306::WIDTH / 8 + ssd1306::BUFFER_PADDING]);
let bus_write_buffer = static_memory
.4
.write([0; ssd1306::HEIGHT * ssd1306::WIDTH / 8 + ssd1306::BUFFER_PADDING]);
let aux_write_buffer = static_memory
.5
.write([0; ssd1306::HEIGHT * ssd1306::WIDTH / 8 + ssd1306::BUFFER_PADDING]);

let ssd1306 = static_memory.0.write(ssd1306::SSD1306::new(
self.bus,
command_sequence,
command_arguments,
app_write_buffer,
bus_write_buffer,
aux_write_buffer,
self.deferred_caller,
));
self.bus.set_client(ssd1306);

// todo remove ssd1306.initialize_callback_handle(self.deferred_caller.register(ssd1306).unwrap());

ssd1306.register();
ssd1306
}
}
1 change: 1 addition & 0 deletions boards/nucleo_f429zi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ components = { path = "../components" }
cortexm4 = { path = "../../arch/cortex-m4" }
kernel = { path = "../../kernel" }
stm32f429zi = { path = "../../chips/stm32f429zi" }
stm32f4xx = { path = "../../chips/stm32f4xx" }

capsules-core = { path = "../../capsules/core" }
capsules-extra = { path = "../../capsules/extra" }
37 changes: 37 additions & 0 deletions boards/nucleo_f429zi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct NucleoF429ZI {
'static,
stm32f429zi::rtc::Rtc<'static>,
>,
//todo uncomment: display: &'static capsules_extra::graphic_display::GraphicDisplay<'static>,
}

/// Mapping of integer syscalls to objects that implement syscalls.
Expand Down Expand Up @@ -636,6 +637,41 @@ pub unsafe fn main() {
stm32f429zi::rtc::Rtc<'static>
));

// I2C SSD1306 screen
let i2c_mux = components::i2c::I2CMuxComponent::new(&peripherals.stm32f4.i2c1, None).finalize(
components::i2c_mux_component_static!(stm32f4xx::i2c::I2C<'static>),
);
kernel::deferred_call::DeferredCallClient::register(i2c_mux);

//todo: bus initialization + uncomment
// let bus = components::bus::I2CMasterBusComponent::new(
// i2c_mux,
// capsules_extra::ssd1306::SLAVE_ADDRESS_WRITE,
// )
// .finalize(components::i2c_master_bus_component_static!());

// let ssd1306_screen = components::ssd1306::SSD1306Component::new(bus).finalize(
// components::ssd1306_component_static!(
// capsules_extra::bus::I2CMasterBus<
// 'static,
// capsules_core::virtualizers::virtual_i2c::I2CDevice<
// 'static,
// stm32f4xx::i2c::I2C<'static>,
// >,
// >,
// ),
// );

// let _ = ssd1306_screen.init();

// let display = components::graphic_display::GraphicDisplayComponent::new(
// board_kernel,
// capsules_extra::graphic_display::DRIVER_NUM,
// ssd1306_screen,
// Some(ssd1306_screen),
// )
// .finalize(components::graphic_display_component_static!(1025));

// PROCESS CONSOLE
let process_console = components::process_console::ProcessConsoleComponent::new(
board_kernel,
Expand Down Expand Up @@ -672,6 +708,7 @@ pub unsafe fn main() {
systick: cortexm4::systick::SysTick::new(),
can: can,
date_time,
//todo uncomment: display,
};

// // Optional kernel tests
Expand Down
Loading