#![cfg(any(
feature = "esp32",
feature = "esp32c3",
feature = "esp32c6",
feature = "esp32s3",
feature = "esp32p4",
feature = "esp32s31"
))]
use crate::backend::EspChip;
use esp_soc::{Soc, SocBus};
use std::path::Path;
impl<S: Soc> EspChip<S> {
pub fn has_display(&self) -> bool {
let board = self.machine_ref().bus.board_ref();
board.display().is_some() || board.gram().is_some()
}
pub fn save_display(&self, path: &Path) -> Result<(), String> {
let Some(path_text) = path.to_str() else {
return Err(format!(
"{}: a screenshot path must be valid UTF-8",
path.display()
));
};
let machine = self.machine_ref();
if machine.bus.board_ref().display().is_some() {
return machine
.write_tft_png(path_text, 2)
.map_err(|e| format!("{}: {e}", path.display()));
}
if machine.bus.board_ref().gram().is_some() {
return machine
.write_gram_png(path_text)
.map_err(|e| format!("{}: {e}", path.display()));
}
Err(format!(
"{}: this board has no display or TFT memory to capture",
path.display()
))
}
}
pub(crate) fn capture<S: Soc>(chip: &EspChip<S>, path: &Path) -> Result<(), String> {
chip.save_display(path)
}