firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

fw16-epd-main: read flash serial number

+27
+1
Cargo.toml
··· 10 10 11 11 [workspace.dependencies] 12 12 rp2040-hal = "0.11" 13 + rp2040-flash = { path = "/home/arthomnix/git/rp2040-flash" } 13 14 cortex-m = "0.7" 14 15 cortex-m-rt = "0.7" 15 16 embedded-hal = "1.0"
+1
fw16-epd-main/Cargo.toml
··· 9 9 tp370pgh01 = { path = "../tp370pgh01", features = ["rp2040"] } 10 10 cortex-m.workspace = true 11 11 cortex-m-rt.workspace = true 12 + rp2040-flash.workspace = true 12 13 embedded-hal.workspace = true 13 14 embedded-hal-bus.workspace = true 14 15 defmt.workspace = true
+25
fw16-epd-main/src/main.rs
··· 90 90 &mut watchdog, 91 91 ).unwrap(); 92 92 93 + // Read flash unique ID 94 + cortex_m::interrupt::disable(); 95 + let mut id = [0u8; 8]; 96 + unsafe { rp2040_flash::flash::flash_unique_id(&mut id, true) }; 97 + let mut id = u64::from_be_bytes(id); 98 + info!("Framework 16 EPD firmware version {}, serial no. {:x}", env!("CARGO_PKG_VERSION"), id); 99 + let mut serial_no = [0u8; 16]; 100 + for c in serial_no.iter_mut().rev() { 101 + let nibble = (id & 0x0f) as u8; 102 + *c = match nibble { 103 + 0x0..=0x9 => b'0' + nibble, 104 + 0xa..=0xf => b'A' + nibble - 0xa, 105 + _ => unreachable!(), 106 + }; 107 + id >>= 4; 108 + } 109 + // Safety: this function never returns, so we should be fine right? 110 + let serial_no: &'static str = unsafe { &*&raw const *core::str::from_utf8(&serial_no).unwrap() }; 111 + unsafe { cortex_m::interrupt::enable() }; 112 + 93 113 let mut sio = Sio::new(pac.SIO); 94 114 let pins = Pins::new( 95 115 pac.IO_BANK0, ··· 139 159 GLOBAL_USB_BUS = Some(usb_bus); 140 160 } 141 161 162 + // Safety: These are only accessed within this interrupt handler, or in main() before the 163 + // interrupt is enabled. 142 164 #[allow(static_mut_refs)] 143 165 let bus_ref = unsafe { GLOBAL_USB_BUS.as_ref().unwrap() }; 144 166 ··· 147 169 .strings(&[StringDescriptors::default() 148 170 .manufacturer("arthomnix") 149 171 .product("Touchscreen EPD Input Module for Framework 16") 172 + .serial_number(serial_no) 150 173 ]) 151 174 .unwrap() 152 175 .device_class(usbd_serial::USB_CLASS_CDC) ··· 267 290 268 291 trace!("USBCTRL_IRQ"); 269 292 293 + // Safety: These are only accessed within this interrupt handler, or in main() before the 294 + // interrupt is enabled. 270 295 #[allow(static_mut_refs)] 271 296 let usb_dev = unsafe { GLOBAL_USB_DEVICE.as_mut().unwrap() }; 272 297 #[allow(static_mut_refs)]