platform: add chip_id function to board api

This commit is contained in:
Victoria Fischer 2024-12-14 11:07:34 +01:00
parent e57ceeb149
commit b6e34111ff
2 changed files with 11 additions and 2 deletions

View File

@ -104,6 +104,14 @@ impl Board for Esp32Board {
type Surfaces = BufferedSurfacePool; type Surfaces = BufferedSurfacePool;
type Scheduler = FixedSizeScheduler<4>; type Scheduler = FixedSizeScheduler<4>;
fn chip_id() -> u64 {
let mut chip_id: [u8; 8] = [0; 8];
unsafe {
esp_efuse_mac_get_default(&mut chip_id as *mut u8);
}
return u64::from_be_bytes(chip_id);
}
fn take() -> Self { fn take() -> Self {
// It is necessary to call this function once. Otherwise some patches to the runtime // It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
@ -120,7 +128,7 @@ impl Board for Esp32Board {
esp_efuse_mac_get_default(&mut chip_id as *mut u8); esp_efuse_mac_get_default(&mut chip_id as *mut u8);
} }
log::info!("Setting up output for chip ID {:x?}", 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;
@ -135,7 +143,7 @@ impl Board for Esp32Board {
// But the implementation spawns a thread based on the core the driver was created in, // But the implementation spawns a thread based on the core the driver was created in,
// so we create the driver in another thread briefly. // so we create the driver in another thread briefly.
// Fun stuff. // Fun stuff.
let output = match chip_id { // panel test board let output = match Self::chip_id().to_be_bytes() { // panel test board
[72, 202, 67, 89, 145, 204, 0, 0] => { [72, 202, 67, 89, 145, 204, 0, 0] => {
StrideOutput::new( StrideOutput::new(
Pixbuf::new(), Pixbuf::new(),

View File

@ -20,4 +20,5 @@ pub trait Board {
fn output(&mut self) -> Self::Output; fn output(&mut self) -> Self::Output;
fn surfaces(&mut self) -> Self::Surfaces; fn surfaces(&mut self) -> Self::Surfaces;
fn system_tasks(&mut self) -> Self::Scheduler; fn system_tasks(&mut self) -> Self::Scheduler;
fn chip_id() -> u64;
} }