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 chrono::Utc;
|
||||||
|
|
||||||
use esp_idf_svc::eventloop::{EspSubscription, EspSystemEventLoop, System};
|
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::modem::Modem;
|
||||||
use esp_idf_svc::hal::prelude::Peripherals;
|
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::hal::task::thread::ThreadSpawnConfiguration;
|
||||||
use esp_idf_svc::mqtt::client::EspMqttClient;
|
use esp_idf_svc::mqtt::client::EspMqttClient;
|
||||||
use esp_idf_svc::mqtt::client::EspMqttConnection;
|
use esp_idf_svc::mqtt::client::EspMqttConnection;
|
||||||
@ -95,8 +97,9 @@ pub mod i2s {
|
|||||||
pub struct Esp32Board {
|
pub struct Esp32Board {
|
||||||
sys_loop: EspSystemEventLoop,
|
sys_loop: EspSystemEventLoop,
|
||||||
modem: Option<Modem>,
|
modem: Option<Modem>,
|
||||||
|
pins: Option<Pins>,
|
||||||
|
rmt: Option<RMT>,
|
||||||
surfaces: BufferedSurfacePool,
|
surfaces: BufferedSurfacePool,
|
||||||
output: Option<<Self as Board>::Output>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Board for Esp32Board {
|
impl Board for Esp32Board {
|
||||||
@ -123,18 +126,25 @@ impl Board for Esp32Board {
|
|||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
let sys_loop = EspSystemEventLoop::take().unwrap();
|
let sys_loop = EspSystemEventLoop::take().unwrap();
|
||||||
|
|
||||||
let mut chip_id: [u8; 8] = [0; 8];
|
Esp32Board {
|
||||||
unsafe {
|
modem: Some(peripherals.modem),
|
||||||
esp_efuse_mac_get_default(&mut chip_id as *mut u8);
|
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());
|
log::info!("Setting up output for chip ID {:x?}", Self::chip_id());
|
||||||
|
|
||||||
const POWER_VOLTS : u32 = 5;
|
const POWER_VOLTS : u32 = 5;
|
||||||
const POWER_MA : u32 = 500;
|
const POWER_MA : u32 = 500;
|
||||||
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
|
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 {
|
ThreadSpawnConfiguration {
|
||||||
pin_to_core: Some(esp_idf_svc::hal::cpu::Core::Core1),
|
pin_to_core: Some(esp_idf_svc::hal::cpu::Core::Core1),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -148,7 +158,7 @@ impl Board for Esp32Board {
|
|||||||
StrideOutput::new(
|
StrideOutput::new(
|
||||||
Pixbuf::new(),
|
Pixbuf::new(),
|
||||||
StrideMapping::new_panel(),
|
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
|
MAX_POWER_MW
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -156,7 +166,7 @@ impl Board for Esp32Board {
|
|||||||
StrideOutput::new(
|
StrideOutput::new(
|
||||||
Pixbuf::new(),
|
Pixbuf::new(),
|
||||||
StrideMapping::new_jar(),
|
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
|
MAX_POWER_MW
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -164,7 +174,7 @@ impl Board for Esp32Board {
|
|||||||
StrideOutput::new(
|
StrideOutput::new(
|
||||||
Pixbuf::new(),
|
Pixbuf::new(),
|
||||||
StrideMapping::new_jar(),
|
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
|
MAX_POWER_MW
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -172,7 +182,7 @@ impl Board for Esp32Board {
|
|||||||
StrideOutput::new(
|
StrideOutput::new(
|
||||||
Pixbuf::new(),
|
Pixbuf::new(),
|
||||||
StrideMapping::new_fairylights(),
|
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
|
MAX_POWER_MW
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -180,7 +190,7 @@ impl Board for Esp32Board {
|
|||||||
StrideOutput::new(
|
StrideOutput::new(
|
||||||
Pixbuf::new(),
|
Pixbuf::new(),
|
||||||
StrideMapping::new_fairylights(),
|
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
|
MAX_POWER_MW
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -188,7 +198,7 @@ impl Board for Esp32Board {
|
|||||||
StrideOutput::new(
|
StrideOutput::new(
|
||||||
Pixbuf::new(),
|
Pixbuf::new(),
|
||||||
StrideMapping::new_cyberplague(),
|
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
|
MAX_POWER_MW
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -196,7 +206,7 @@ impl Board for Esp32Board {
|
|||||||
StrideOutput::new(
|
StrideOutput::new(
|
||||||
Pixbuf::new(),
|
Pixbuf::new(),
|
||||||
StrideMapping::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
|
MAX_POWER_MW
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -205,16 +215,7 @@ impl Board for Esp32Board {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}.set().unwrap();
|
}.set().unwrap();
|
||||||
|
|
||||||
Esp32Board {
|
output
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn surfaces(&mut self) -> Self::Surfaces {
|
fn surfaces(&mut self) -> Self::Surfaces {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user