I am working on the built-in Rust code for the NXP LPC82X series controllers. The exact toolchain does not matter for the question.
These controllers contain peripheral drivers in the ROM. I want to use these drivers, which means that I need to use unsafe Rust and FFI without binding the actual code.
ROM APIs expose pointers to functions packaged in C structures at specific addresses. If anyone wants the details of this API, chapter 29 of the LPC82X manual describes the API in question.
My drawing of the My Rust mannequin is similar to this one, which will be hidden from the application code, but with an as yet unwritten abstraction of I2C. It compiles.
#![feature(naked_functions)] const I2C_ROM_API_ADDRESS: usize = 0x1fff_200c; static mut ROM_I2C_API: Option<&RomI2cApi> = None; #[repr(C)] struct RomI2cApi {
I cannot declare struct pointer struct as non-mutable static, since statics have many limitations, including not dereferencing pointers in assignment. Is there a better workaround than Option ? Using Option with the api_table function at least ensures that initialization happens.
source share