platform: esp32: move output creation into output() method
This commit is contained in:
parent
bfdf7c3230
commit
2af9918239
@ -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<Modem>,
|
||||
pins: Option<Pins>,
|
||||
rmt: Option<RMT>,
|
||||
surfaces: BufferedSurfacePool,
|
||||
output: Option<<Self as Board>::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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user