Skip to content

Commit 74f1c3e

Browse files
author
Jorge Aparicio
committed
generate a different type for each peripheral instance
closes #65
1 parent 0337b61 commit 74f1c3e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/generate.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub fn device(d: &Device, items: &mut Vec<Tokens>) -> Result<()> {
2727
extern crate cortex_m;
2828
extern crate vcell;
2929

30+
use core::ops::Deref;
31+
3032
use cortex_m::peripheral::Peripheral;
3133
});
3234

@@ -180,10 +182,18 @@ pub fn peripheral(
180182

181183
if let Some(base) = p.derived_from.as_ref() {
182184
// TODO Verify that base exists
183-
let base_pc = Ident::new(&*base.to_sanitized_pascal_case());
185+
let base_sc = Ident::new(&*base.to_sanitized_snake_case());
184186
items.push(quote! {
185187
/// Register block
186-
pub type #name_pc = #base_pc;
188+
pub struct #name_pc { register_block: #base_sc::RegisterBlock }
189+
190+
impl Deref for #name_pc {
191+
type Target = #base_sc::RegisterBlock;
192+
193+
fn deref(&self) -> &#base_sc::RegisterBlock {
194+
&self.register_block
195+
}
196+
}
187197
});
188198

189199
// TODO We don't handle inheritance style `derivedFrom`, we should raise
@@ -223,7 +233,16 @@ pub fn peripheral(
223233
#(#mod_items)*
224234
}
225235

226-
pub use #name_sc::RegisterBlock as #name_pc;
236+
#[doc = #description]
237+
pub struct #name_pc { register_block: #name_sc::RegisterBlock }
238+
239+
impl Deref for #name_pc {
240+
type Target = #name_sc::RegisterBlock;
241+
242+
fn deref(&self) -> &#name_sc::RegisterBlock {
243+
&self.register_block
244+
}
245+
}
227246
});
228247

229248
Ok(())

0 commit comments

Comments
 (0)