I try to write hw abstraction layer, interfaces to be hardware agnostic. Its developed for embedded target without memory management and std library.
Common Abstraction Layer:
pub struct DioPin {
pub inst: DioInstance,
pub port: DioPort,
pub num: DioPinNum,
}
blah blah..
pub struct Dio{
/* what goes here should be a handle to mcu specific implementation*/?
}
impl Dio {
pub fn setup(s: &self, p: DioPin) {
/* Plan to hook the mcu specific handle here to Dio */
}
pub fn configure(&self, c: DioConfig){}
pub fn enable_pin_input(&self, p: DioPin) {}
pub fn enable_input_pullup(&self, p: DioPin) {}
pub fn enable_pin_output(&self, p: DioPin) {}
EX MCU specific implementation handle :
pub struct Gpio( *mut GpioMmapRegs ); => sometimes tuple struct and sometimes named struct
How to keep the common interface and mcu specific implementation as separate, without exposing lower layer implementation to caller of hal layer? What other ways to do this efficiently?
Following is what I able to do so far. Made the lower mcu specific struct Gpio
public and created a item named lower in pub struct Dio. But the problem here is that this item lower should also be made public.
pub struct Dio{
lower: mcu handle
}