diff --git a/examples/mcu-board-support/pico2_st7789.rs b/examples/mcu-board-support/pico2_st7789.rs index 8a465cd2c..7915fcfcc 100644 --- a/examples/mcu-board-support/pico2_st7789.rs +++ b/examples/mcu-board-support/pico2_st7789.rs @@ -128,7 +128,7 @@ pub fn init() { }); let rst = pins.gpio15.into_push_pull_output(); - let mut backlight = pins.gpio13.into_push_pull_output(); + let backlight = pins.gpio13.into_push_pull_output(); let dc = pins.gpio8.into_push_pull_output(); let cs = pins.gpio9.into_push_pull_output(); @@ -162,7 +162,6 @@ pub fn init() { .invert_colors(mipidsi::options::ColorInversion::Inverted) .init(&mut timer) .unwrap(); - backlight.set_high().unwrap(); let touch = xpt2046::XPT2046::new( &IRQ_PIN, @@ -200,14 +199,16 @@ pub fn init() { window: Default::default(), buffer_provider: buffer_provider.into(), touch: touch.into(), + backlight: Some(backlight).into(), })) .expect("backend already initialized"); } -struct PicoBackend { +struct PicoBackend { window: RefCell>>, buffer_provider: RefCell, touch: RefCell, + backlight: RefCell>, } impl< @@ -219,10 +220,12 @@ impl< CS_: OutputPin, IRQ: InputPin, SPI: SpiDevice, + BL: OutputPin, > slint::platform::Platform for PicoBackend< DrawBuffer, PioTransfer, (DC_, CS_)>, xpt2046::XPT2046, + BL, > { fn create_window_adapter( @@ -254,6 +257,9 @@ impl< let mut buffer_provider = self.buffer_provider.borrow_mut(); renderer.render_by_line(&mut *buffer_provider); buffer_provider.flush_frame(); + if let Some(mut backlight) = self.backlight.take() { + backlight.set_high().unwrap(); + } }); // handle touch event