Skip to content

Commit d00655b

Browse files
authored
Update MCU dependencies (#6682)
1 parent 7b1e8b4 commit d00655b

File tree

6 files changed

+56
-58
lines changed

6 files changed

+56
-58
lines changed

api/cpp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ raw-window-handle = { version = "0.6", optional = true }
6161
image = { workspace = true, optional = true, features = ["default"] }
6262

6363
esp-backtrace = { version = "0.14.0", features = ["panic-handler", "println"], optional = true }
64-
esp-println = { version = "0.11.0", default-features = false, features = ["uart"], optional = true }
64+
esp-println = { version = "0.12.0", default-features = false, features = ["uart"], optional = true }
6565

6666
[build-dependencies]
6767
anyhow = "1.0"

examples/mcu-board-support/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ path = "lib.rs"
2121
pico-st7789 = ["slint/unsafe-single-threaded", "rp-pico", "embedded-hal", "embedded-hal-nb", "cortex-m-rt", "embedded-alloc", "fugit", "cortex-m", "display-interface", "display-interface-spi", "mipidsi", "defmt", "defmt-rtt", "slint/libm", "embedded-dma", "embedded-graphics", "euclid/libm"]
2222
stm32h735g = ["slint/unsafe-single-threaded", "cortex-m/critical-section-single-core", "cortex-m-rt","embedded-alloc", "embedded-time", "stm32h7xx-hal/stm32h735", "defmt", "defmt-rtt", "embedded-display-controller", "ft5336", "panic-probe", "slint/libm", "getrandom"]
2323
esp32-s2-kaluga-1 = ["slint/unsafe-single-threaded", "esp-hal/esp32s2", "embedded-hal", "embedded-hal-bus", "esp-alloc", "esp-println/esp32s2", "display-interface", "display-interface-spi", "mipidsi", "embedded-graphics-core", "slint/libm"]
24-
esp32-s3-box = ["slint/unsafe-single-threaded", "esp-hal/esp32s3", "esp-hal/embedded-hal-02", "embedded-hal", "embedded-hal-bus", "esp-alloc", "esp-println/esp32s3", "esp-backtrace/esp32s3", "display-interface", "display-interface-spi", "mipidsi", "embedded-graphics-core", "slint/libm", "tt21100"]
24+
esp32-s3-box = ["slint/unsafe-single-threaded", "esp-hal/esp32s3", "embedded-hal", "embedded-hal-bus", "esp-alloc", "esp-println/esp32s3", "esp-backtrace/esp32s3", "display-interface", "display-interface-spi", "mipidsi", "embedded-graphics-core", "slint/libm", "tt21100"]
2525

2626
[dependencies]
2727
slint = { version = "=1.9.0", path = "../../api/rs/slint", default-features = false, features = ["compat-1-2", "renderer-software"] }
2828
i-slint-core-macros = { version = "=1.9.0", path = "../../internal/core-macros" }
2929

30-
derive_more = "0.99.5"
30+
derive_more = { workspace = true }
3131
embedded-graphics = { version = "0.8", optional = true }
3232
once_cell = { version = "1.9", default-features = false, features = ["alloc"] }
3333
pin-weak = { version = "1", default-features = false }
3434
rgb = "0.8.27"
3535
cfg-if = "1"
3636

37-
embedded-alloc = { version = "0.5", optional = true }
37+
embedded-alloc = { version = "0.6", optional = true }
3838
cortex-m-rt = { version = "0.7", optional = true }
3939
cortex-m = { version = "0.7.2", optional = true }
4040
display-interface = { version = "0.5.0", optional = true }
@@ -52,10 +52,10 @@ embedded-time = { version = "0.12.0", optional = true }
5252
embedded-display-controller = { version = "0.2.0", optional = true }
5353
ft5336 = { version = "0.2", optional = true }
5454

55-
esp-hal = { version = "0.19", optional = true }
55+
esp-hal = { version = "0.21", optional = true }
5656
display-interface-spi = { version = "0.5", optional = true }
57-
esp-alloc = { version = "0.4", optional = true }
58-
esp-println = { version = "0.11.0", optional = true }
57+
esp-alloc = { version = "0.5", optional = true }
58+
esp-println = { version = "0.12.0", optional = true }
5959
esp-backtrace = { version = "0.14.0", optional = true, features = ["panic-handler", "println"] }
6060
tt21100 = { version = "0.1", optional = true }
6161

examples/mcu-board-support/esp32_s2_kaluga_1.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33

44
use alloc::boxed::Box;
55
use alloc::rc::Rc;
6-
use core::{cell::RefCell, convert::Infallible};
6+
use core::{cell::RefCell, convert::Infallible, mem::MaybeUninit};
77
use display_interface_spi::SPIInterface;
88
use embedded_hal::digital::OutputPin;
9-
use esp_alloc::EspHeap;
9+
use esp_alloc as _;
1010
pub use esp_hal::entry;
1111
use esp_hal::gpio::{Io, Level, Output};
1212
use esp_hal::spi::{master::Spi, SpiMode};
13-
use esp_hal::system::SystemControl;
1413
use esp_hal::timer::{systimer::SystemTimer, timg::TimerGroup};
15-
use esp_hal::{
16-
clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*, rtc_cntl::Rtc,
17-
};
14+
use esp_hal::{delay::Delay, prelude::*, rtc_cntl::Rtc};
1815
use esp_println::println;
1916

2017
type Display<DI, RST> = mipidsi::Display<DI, mipidsi::models::ST7789, RST>;
@@ -28,13 +25,16 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
2825
}
2926
}
3027

31-
#[global_allocator]
32-
static ALLOCATOR: EspHeap = EspHeap::empty();
33-
3428
pub fn init() {
3529
const HEAP_SIZE: usize = 160 * 1024;
36-
static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE];
37-
unsafe { ALLOCATOR.init(core::ptr::addr_of_mut!(HEAP) as *mut u8, HEAP_SIZE) }
30+
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();
31+
unsafe {
32+
esp_alloc::HEAP.add_region(esp_alloc::HeapRegion::new(
33+
HEAP.as_mut_ptr() as *mut u8,
34+
HEAP_SIZE,
35+
esp_alloc::MemoryCapability::Internal.into(),
36+
));
37+
}
3838
slint::platform::set_platform(Box::new(EspBackend::default()))
3939
.expect("backend already initialized");
4040
}
@@ -57,24 +57,22 @@ impl slint::platform::Platform for EspBackend {
5757

5858
fn duration_since_start(&self) -> core::time::Duration {
5959
core::time::Duration::from_millis(
60-
SystemTimer::now() / (SystemTimer::TICKS_PER_SECOND / 1000),
60+
SystemTimer::now() / (SystemTimer::ticks_per_second() / 1000),
6161
)
6262
}
6363

6464
fn run_event_loop(&self) -> Result<(), slint::PlatformError> {
65-
let peripherals = Peripherals::take();
66-
let system = SystemControl::new(peripherals.SYSTEM);
67-
let mut clocks = ClockControl::max(system.clock_control).freeze();
65+
let peripherals = esp_hal::init(esp_hal::Config::default());
6866

6967
// Disable the RTC and TIMG watchdog timers
70-
let mut rtc = Rtc::new(peripherals.LPWR, None);
68+
let mut rtc = Rtc::new(peripherals.LPWR);
7169
rtc.rwdt.disable();
72-
let mut timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, None);
70+
let mut timer_group0 = TimerGroup::new(peripherals.TIMG0);
7371
timer_group0.wdt.disable();
74-
let mut timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks, None);
72+
let mut timer_group1 = TimerGroup::new(peripherals.TIMG1);
7573
timer_group1.wdt.disable();
7674

77-
let mut delay = Delay::new(&clocks);
75+
let mut delay = Delay::new();
7876
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
7977

8078
let mut backlight = Output::new(io.pins.gpio6, Level::High);
@@ -87,11 +85,11 @@ impl slint::platform::Platform for EspBackend {
8785
let sck = io.pins.gpio15;
8886
let miso = io.pins.gpio8;
8987

90-
let spi = Spi::new(peripherals.SPI3, 80u32.MHz(), SpiMode::Mode0, &mut clocks).with_pins(
91-
Some(sck),
92-
Some(mosi),
93-
Some(miso),
94-
esp_hal::gpio::NO_PIN,
88+
let spi = Spi::new(peripherals.SPI3, 80u32.MHz(), SpiMode::Mode0).with_pins(
89+
sck,
90+
mosi,
91+
miso,
92+
esp_hal::gpio::NoPin,
9593
);
9694
let spi = embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, cs).unwrap();
9795
let di = SPIInterface::new(spi, Output::new(dc, Level::Low));

examples/mcu-board-support/esp32_s3_box.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@
44
use alloc::boxed::Box;
55
use alloc::rc::Rc;
66
use core::cell::RefCell;
7+
use core::mem::MaybeUninit;
78
use display_interface_spi::SPIInterface;
89
use embedded_graphics_core::geometry::OriginDimensions;
910
use embedded_hal::digital::OutputPin;
10-
use esp_alloc::EspHeap;
11+
use esp_alloc as _;
1112
use esp_backtrace as _;
12-
use esp_hal::clock::ClockControl;
1313
use esp_hal::delay::Delay;
1414
pub use esp_hal::entry;
1515
use esp_hal::gpio::{Input, Io, Level, Output, Pull};
1616
use esp_hal::rtc_cntl::Rtc;
1717
use esp_hal::spi::{master::Spi, SpiMode};
18-
use esp_hal::system::SystemControl;
1918
use esp_hal::timer::{systimer::SystemTimer, timg::TimerGroup};
20-
use esp_hal::{i2c::I2C, peripherals::Peripherals, prelude::*};
19+
use esp_hal::{i2c::I2c, prelude::*};
2120
use mipidsi::{options::Orientation, Display};
2221
use slint::platform::WindowEvent;
2322

24-
#[global_allocator]
25-
static ALLOCATOR: EspHeap = EspHeap::empty();
26-
2723
pub fn init() {
2824
const HEAP_SIZE: usize = 250 * 1024;
29-
static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE];
30-
unsafe { ALLOCATOR.init(core::ptr::addr_of_mut!(HEAP) as *mut u8, HEAP_SIZE) }
25+
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();
26+
unsafe {
27+
esp_alloc::HEAP.add_region(esp_alloc::HeapRegion::new(
28+
HEAP.as_mut_ptr() as *mut u8,
29+
HEAP_SIZE,
30+
esp_alloc::MemoryCapability::Internal.into(),
31+
));
32+
}
3133
slint::platform::set_platform(Box::new(EspBackend::default()))
3234
.expect("backend already initialized");
3335
}
@@ -50,39 +52,36 @@ impl slint::platform::Platform for EspBackend {
5052

5153
fn duration_since_start(&self) -> core::time::Duration {
5254
core::time::Duration::from_millis(
53-
SystemTimer::now() / (SystemTimer::TICKS_PER_SECOND / 1000),
55+
SystemTimer::now() / (SystemTimer::ticks_per_second() / 1000),
5456
)
5557
}
5658

5759
fn run_event_loop(&self) -> Result<(), slint::PlatformError> {
58-
let peripherals = Peripherals::take();
59-
let system = SystemControl::new(peripherals.SYSTEM);
60-
let clocks = ClockControl::max(system.clock_control).freeze();
60+
let peripherals = esp_hal::init(esp_hal::Config::default());
6161

62-
let mut rtc = Rtc::new(peripherals.LPWR, None);
62+
let mut rtc = Rtc::new(peripherals.LPWR);
6363
rtc.rwdt.disable();
64-
let mut timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, None);
64+
let mut timer_group0 = TimerGroup::new(peripherals.TIMG0);
6565
timer_group0.wdt.disable();
66-
let mut timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks, None);
66+
let mut timer_group1 = TimerGroup::new(peripherals.TIMG1);
6767
timer_group1.wdt.disable();
6868

69-
let mut delay = Delay::new(&clocks);
69+
let mut delay = Delay::new();
7070
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
7171

72-
let i2c =
73-
I2C::new(peripherals.I2C0, io.pins.gpio8, io.pins.gpio18, 400u32.kHz(), &clocks, None);
72+
let i2c = I2c::new(peripherals.I2C0, io.pins.gpio8, io.pins.gpio18, 400u32.kHz());
7473

7574
let mut touch = tt21100::TT21100::new(i2c, Input::new(io.pins.gpio3, Pull::Up))
7675
.expect("Initialize the touch device");
7776

7877
let sclk = io.pins.gpio7;
7978
let mosi = io.pins.gpio6;
8079

81-
let spi = Spi::new(peripherals.SPI2, 60u32.MHz(), SpiMode::Mode0, &clocks).with_pins(
82-
Some(sclk),
83-
Some(mosi),
84-
esp_hal::gpio::NO_PIN,
85-
esp_hal::gpio::NO_PIN,
80+
let spi = Spi::new(peripherals.SPI2, 60u32.MHz(), SpiMode::Mode0).with_pins(
81+
sclk,
82+
mosi,
83+
Level::Low,
84+
esp_hal::gpio::NoPin,
8685
);
8786

8887
let dc = Output::new(io.pins.gpio4, Level::Low);

examples/mcu-board-support/pico_st7789.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use cortex_m::interrupt::Mutex;
1212
use cortex_m::singleton;
1313
pub use cortex_m_rt::entry;
1414
use defmt_rtt as _;
15-
use embedded_alloc::Heap;
15+
use embedded_alloc::LlffHeap as Heap;
1616
use embedded_hal::digital::{InputPin, OutputPin};
1717
use embedded_hal::spi::{ErrorType, Operation, SpiBus, SpiDevice};
1818
use fugit::{Hertz, RateExtU32};

examples/mcu-board-support/stm32h735g.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use stm32h7xx_hal as hal; // global logger
1919
#[cfg(feature = "panic-probe")]
2020
use panic_probe as _;
2121

22-
use embedded_alloc::Heap;
22+
use embedded_alloc::LlffHeap as Heap;
2323

2424
const HEAP_SIZE: usize = 200 * 1024;
2525
static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE];
@@ -205,7 +205,8 @@ impl Default for StmBackend {
205205
led_green.set_low();
206206
*/
207207

208-
let (fb1, fb2) = (core::ptr::addr_of!(FB1), core::ptr::addr_of!(FB2));
208+
#[allow(unused_unsafe)] //(unsafe required for Rust <= 1.81)
209+
let (fb1, fb2) = unsafe { (core::ptr::addr_of!(FB1), core::ptr::addr_of!(FB2)) };
209210
assert!((hyperram_ptr as usize..hyperram_ptr as usize + hyperram_size)
210211
.contains(&(fb1 as usize)));
211212
assert!((hyperram_ptr as usize..hyperram_ptr as usize + hyperram_size)

0 commit comments

Comments
 (0)