Skip to content

Commit

Permalink
Merge pull request tock#4215 from alevy/stm32f412-disco
Browse files Browse the repository at this point in the history
Small updates for better performance in screen driver
  • Loading branch information
alevy authored Oct 29, 2024
2 parents 40e0422 + c35c1ec commit 0f18df1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
25 changes: 21 additions & 4 deletions boards/stm32f412gdiscovery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use kernel::{create_capability, debug, static_init};
use stm32f412g::chip_specs::Stm32f412Specs;
use stm32f412g::clocks::hsi::HSI_FREQUENCY_MHZ;
use stm32f412g::interrupt_service::Stm32f412gDefaultPeripherals;
use stm32f412g::rcc::PllSource;

/// Support routines for debugging I/O.
pub mod io;
Expand Down Expand Up @@ -179,6 +180,7 @@ unsafe fn set_pin_primary_functions(
syscfg: &stm32f412g::syscfg::Syscfg,
i2c1: &stm32f412g::i2c::I2C,
gpio_ports: &'static stm32f412g::gpio::GpioPorts<'static>,
peripheral_clock_frequency: usize,
) {
use kernel::hil::gpio::Configure;
use stm32f412g::gpio::{AlternateFunction, Mode, PinId, PortId};
Expand Down Expand Up @@ -269,7 +271,10 @@ unsafe fn set_pin_primary_functions(
});

i2c1.enable_clock();
i2c1.set_speed(stm32f412g::i2c::I2CSpeed::Speed100k, 16);
i2c1.set_speed(
stm32f412g::i2c::I2CSpeed::Speed400k,
peripheral_clock_frequency,
);

// FT6206 interrupt
gpio_ports.get_pin(PinId::PG05).map(|pin| {
Expand Down Expand Up @@ -414,15 +419,27 @@ unsafe fn start() -> (
);

peripherals.init();

let _ = clocks.set_ahb_prescaler(stm32f412g::rcc::AHBPrescaler::DivideBy1);
let _ = clocks.set_apb1_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy4);
let _ = clocks.set_apb2_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy2);
let _ = clocks.set_pll_frequency_mhz(PllSource::HSI, 100);
let _ = clocks.pll.enable();
let _ = clocks.set_sys_clock_source(stm32f412g::rcc::SysClockSource::PLL);

let base_peripherals = &peripherals.stm32f4;
setup_peripherals(
&base_peripherals.tim2,
&base_peripherals.fsmc,
&peripherals.trng,
);

// We use the default HSI 16Mhz clock
set_pin_primary_functions(syscfg, &base_peripherals.i2c1, &base_peripherals.gpio_ports);
set_pin_primary_functions(
syscfg,
&base_peripherals.i2c1,
&base_peripherals.gpio_ports,
clocks.get_apb1_frequency_mhz(),
);

setup_dma(
dma1,
Expand Down Expand Up @@ -653,7 +670,7 @@ unsafe fn start() -> (
tft,
Some(tft),
)
.finalize(components::screen_component_static!(57600));
.finalize(components::screen_component_static!(1024));

let touch = components::touch::MultiTouchComponent::new(
board_kernel,
Expand Down
6 changes: 4 additions & 2 deletions capsules/extra/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,19 @@ impl<'a> Screen<'a> {
.get_readonly_processbuffer(ro_allow::SHARED)
.and_then(|shared| {
shared.enter(|s| {
let mut count = 0;
let mut chunks = s.chunks(buffer_size);
if let Some(chunk) = chunks.nth(chunk_number) {
for (i, byte) in chunk.iter().enumerate() {
if pos < len {
buffer[i] = byte.get();
pos += 1
count += 1;
pos += 1;
} else {
break;
}
}
app.write_len - initial_pos
count
} else {
// stop writing
0
Expand Down

0 comments on commit 0f18df1

Please sign in to comment.