From 2af9918239bf79f54f7da9f9d7b3c31af0c7f354 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sat, 14 Dec 2024 11:09:34 +0100 Subject: [PATCH] platform: esp32: move output creation into output() method --- src/platform/esp32.rs | 45 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/platform/esp32.rs b/src/platform/esp32.rs index b2a551c..3c1784f 100644 --- a/src/platform/esp32.rs +++ b/src/platform/esp32.rs @@ -10,8 +10,10 @@ use chrono::Timelike; use chrono::Utc; use esp_idf_svc::eventloop::{EspSubscription, EspSystemEventLoop, System}; +use esp_idf_svc::hal::gpio::Pins; use esp_idf_svc::hal::modem::Modem; use esp_idf_svc::hal::prelude::Peripherals; +use esp_idf_svc::hal::rmt::RMT; use esp_idf_svc::hal::task::thread::ThreadSpawnConfiguration; use esp_idf_svc::mqtt::client::EspMqttClient; use esp_idf_svc::mqtt::client::EspMqttConnection; @@ -95,8 +97,9 @@ pub mod i2s { pub struct Esp32Board { sys_loop: EspSystemEventLoop, modem: Option, + pins: Option, + rmt: Option, surfaces: BufferedSurfacePool, - output: Option<::Output> } impl Board for Esp32Board { @@ -123,18 +126,25 @@ impl Board for Esp32Board { let peripherals = Peripherals::take().unwrap(); let sys_loop = EspSystemEventLoop::take().unwrap(); - let mut chip_id: [u8; 8] = [0; 8]; - unsafe { - esp_efuse_mac_get_default(&mut chip_id as *mut u8); + Esp32Board { + modem: Some(peripherals.modem), + sys_loop: sys_loop.clone(), + surfaces: BufferedSurfacePool::new(), + pins: Some(peripherals.pins), + rmt: Some(peripherals.rmt) } + } + + fn output(&mut self) -> Self::Output { log::info!("Setting up output for chip ID {:x?}", Self::chip_id()); const POWER_VOLTS : u32 = 5; const POWER_MA : u32 = 500; const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA; - let pins = peripherals.pins; + let pins = self.pins.take().unwrap(); + let rmt = self.rmt.take().unwrap(); ThreadSpawnConfiguration { pin_to_core: Some(esp_idf_svc::hal::cpu::Core::Core1), ..Default::default() @@ -148,7 +158,7 @@ impl Board for Esp32Board { StrideOutput::new( Pixbuf::new(), StrideMapping::new_panel(), - std::thread::spawn(move || { FastWs2812Esp32Rmt::new(peripherals.rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), + std::thread::spawn(move || { FastWs2812Esp32Rmt::new(rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), MAX_POWER_MW ) }, @@ -156,7 +166,7 @@ impl Board for Esp32Board { StrideOutput::new( Pixbuf::new(), StrideMapping::new_jar(), - std::thread::spawn(move || { FastWs2812Esp32Rmt::new(peripherals.rmt.channel0, pins.gpio14).unwrap() }).join().unwrap(), + std::thread::spawn(move || { FastWs2812Esp32Rmt::new(rmt.channel0, pins.gpio14).unwrap() }).join().unwrap(), MAX_POWER_MW ) }, @@ -164,7 +174,7 @@ impl Board for Esp32Board { StrideOutput::new( Pixbuf::new(), StrideMapping::new_jar(), - std::thread::spawn(move || { FastWs2812Esp32Rmt::new(peripherals.rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), + std::thread::spawn(move || { FastWs2812Esp32Rmt::new(rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), MAX_POWER_MW ) }, @@ -172,7 +182,7 @@ impl Board for Esp32Board { StrideOutput::new( Pixbuf::new(), StrideMapping::new_fairylights(), - std::thread::spawn(move || { FastWs2812Esp32Rmt::new(peripherals.rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), + std::thread::spawn(move || { FastWs2812Esp32Rmt::new(rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), MAX_POWER_MW ) }, @@ -180,7 +190,7 @@ impl Board for Esp32Board { StrideOutput::new( Pixbuf::new(), StrideMapping::new_fairylights(), - std::thread::spawn(move || { FastWs2812Esp32Rmt::new(peripherals.rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), + std::thread::spawn(move || { FastWs2812Esp32Rmt::new(rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), MAX_POWER_MW ) }, @@ -188,7 +198,7 @@ impl Board for Esp32Board { StrideOutput::new( Pixbuf::new(), StrideMapping::new_cyberplague(), - std::thread::spawn(move || { FastWs2812Esp32Rmt::new(peripherals.rmt.channel0, pins.gpio13).unwrap() }).join().unwrap(), + std::thread::spawn(move || { FastWs2812Esp32Rmt::new(rmt.channel0, pins.gpio13).unwrap() }).join().unwrap(), MAX_POWER_MW ) }, @@ -196,7 +206,7 @@ impl Board for Esp32Board { StrideOutput::new( Pixbuf::new(), StrideMapping::new(), - std::thread::spawn(move || { FastWs2812Esp32Rmt::new(peripherals.rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), + std::thread::spawn(move || { FastWs2812Esp32Rmt::new(rmt.channel0, pins.gpio5).unwrap() }).join().unwrap(), MAX_POWER_MW ) } @@ -205,16 +215,7 @@ impl Board for Esp32Board { ..Default::default() }.set().unwrap(); - Esp32Board { - modem: Some(peripherals.modem), - sys_loop: sys_loop.clone(), - surfaces: BufferedSurfacePool::new(), - output: Some(output) - } - } - - fn output(&mut self) -> Self::Output { - self.output.take().unwrap() + output } fn surfaces(&mut self) -> Self::Surfaces {