use ehatrom::*;
fn main() {
println!("📝 Creating minimal EEPROM with basic vendor info...");
let vendor_atom = VendorInfoAtom::new(
0x5349, 0x4D50, 1, "Simple",
"MinimalHAT",
[
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD,
0xEE, 0xFF,
], );
let gpio_atom = GpioMapAtom {
flags: 0x0000,
pins: [0u8; 28], };
#[cfg(feature = "alloc")]
let mut eeprom = Eeprom {
header: EepromHeader::new(),
vendor_info: vendor_atom,
gpio_map_bank0: gpio_atom,
dt_blob: None,
gpio_map_bank1: None,
custom_atoms: Vec::new(),
};
#[cfg(not(feature = "alloc"))]
let mut eeprom = Eeprom {
header: EepromHeader::new(),
vendor_info: vendor_atom,
gpio_map_bank0: gpio_atom,
dt_blob: None,
gpio_map_bank1: None,
custom_atoms: &[],
};
eeprom.update_header();
#[cfg(feature = "alloc")]
let serialized = eeprom.serialize_with_crc();
#[cfg(not(feature = "alloc"))]
let serialized = {
let mut buffer = [0u8; 1024]; let size = eeprom
.serialize_with_crc_to_slice(&mut buffer)
.expect("Failed to serialize EEPROM");
&buffer[..size]
};
if std::fs::metadata("tests/data").is_err() {
std::fs::create_dir_all("tests/data").expect("Failed to create tests/data directory");
}
std::fs::write("tests/data/simple.bin", &serialized).expect("Failed to write simple file");
println!("Created tests/data/simple.bin ({} bytes)", serialized.len());
if Eeprom::verify_crc(&serialized) {
println!("✅ CRC verification passed");
} else {
println!("❌ CRC verification failed");
}
}