Skip to content

Commit c19ce32

Browse files
committed
generic REG
1 parent 4723dc9 commit c19ce32

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/generate/register.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pub fn render_register_mod(
273273

274274
mod_items.extend(w_impl_items);
275275

276-
/*
276+
/*
277277
// the writer can be safe if:
278278
// * there is a single field that covers the entire register
279279
// * that field can represent all values
@@ -923,7 +923,7 @@ pub fn fields(
923923
proxy_items.extend(quote! {
924924
#[doc = #doc]
925925
#inline
926-
pub fn #sc(self) -> &'a mut W {
926+
pub fn #sc(self) -> &'a mut crate::W<REG> {
927927
self.variant(#value_write_ty::#pc)
928928
}
929929
});
@@ -955,9 +955,9 @@ pub fn fields(
955955
span,
956956
);
957957
if value_write_ty == "bool" {
958-
quote! { crate::#wproxy<'a, #regspec_ident, O> }
958+
quote! { crate::#wproxy<'a, REG, O> }
959959
} else {
960-
quote! { crate::#wproxy<'a, #regspec_ident, O, #value_write_ty> }
960+
quote! { crate::#wproxy<'a, REG, O, #value_write_ty> }
961961
}
962962
} else {
963963
let wproxy = Ident::new(
@@ -970,22 +970,37 @@ pub fn fields(
970970
);
971971
let width = &util::unsuffixed(width as _);
972972
if value_write_ty == "u8" {
973-
quote! { crate::#wproxy<'a, #regspec_ident, #width, O> }
973+
quote! { crate::#wproxy<'a, REG, #width, O> }
974974
} else {
975-
quote! { crate::#wproxy<'a, #regspec_ident, #width, O, #value_write_ty> }
975+
quote! { crate::#wproxy<'a, REG, #width, O, #value_write_ty> }
976976
}
977977
};
978978
mod_items.extend(quote! {
979979
#[doc = #field_writer_brief]
980-
pub type #writer_ty<'a, const O: u8> = #proxy;
980+
pub type #writer_ty<'a, REG, const O: u8> = #proxy;
981981
});
982982
}
983983

984984
// generate proxy items from collected information
985985
if !proxy_items.is_empty() {
986-
mod_items.extend(quote! {
987-
impl<'a, const O: u8> #writer_ty<'a, O> {
988-
#proxy_items
986+
mod_items.extend(if width == 1 {
987+
quote! {
988+
impl<'a, REG, const O: u8> #writer_ty<'a, REG, O>
989+
where
990+
REG: crate::Writable + crate::RegisterSpec,
991+
{
992+
#proxy_items
993+
}
994+
}
995+
} else {
996+
quote! {
997+
impl<'a, REG, const O: u8> #writer_ty<'a, REG, O>
998+
where
999+
REG: crate::Writable + crate::RegisterSpec,
1000+
REG::Ux: From<#fty>
1001+
{
1002+
#proxy_items
1003+
}
9891004
}
9901005
});
9911006
}
@@ -1032,7 +1047,7 @@ pub fn fields(
10321047
#[doc = #doc]
10331048
#inline
10341049
#[must_use]
1035-
pub unsafe fn #name_snake_case<const O: u8>(&mut self) -> #writer_ty<O> {
1050+
pub unsafe fn #name_snake_case<const O: u8>(&mut self) -> #writer_ty<#regspec_ident, O> {
10361051
#writer_ty::new(self)
10371052
}
10381053
});
@@ -1051,7 +1066,7 @@ pub fn fields(
10511066
#[doc = #doc]
10521067
#inline
10531068
#[must_use]
1054-
pub fn #name_snake_case_n(&mut self) -> #writer_ty<#sub_offset> {
1069+
pub fn #name_snake_case_n(&mut self) -> #writer_ty<#regspec_ident, #sub_offset> {
10551070
#writer_ty::new(self)
10561071
}
10571072
});
@@ -1063,7 +1078,7 @@ pub fn fields(
10631078
#[doc = #doc]
10641079
#inline
10651080
#[must_use]
1066-
pub fn #name_snake_case(&mut self) -> #writer_ty<#offset> {
1081+
pub fn #name_snake_case(&mut self) -> #writer_ty<#regspec_ident, #offset> {
10671082
#writer_ty::new(self)
10681083
}
10691084
});

0 commit comments

Comments
 (0)