Skip to content

Commit ef010c6

Browse files
committed
rm reg_sizes
1 parent 3a6b716 commit ef010c6

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Make `generic.rs` generic
1011
- Change initial write value for registers with modifiedWriteValues
1112
- Update `clap` to 4.0, use `irx-config` instead of `clap_conf`
1213
- Add #[must_use] to prevent hanging field writers

src/generate/device.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::borrow::Cow;
77
use std::fs::File;
88
use std::io::Write;
99

10-
use crate::util::{self, Config, ToSanitizedCase, U32Ext};
10+
use crate::util::{self, Config, ToSanitizedCase};
1111
use crate::Target;
1212
use anyhow::{Context, Result};
1313

@@ -146,15 +146,10 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
146146
});
147147
}
148148

149-
let reg_sizes = util::get_register_sizes(d);
150-
151149
let generic_file = std::str::from_utf8(include_bytes!("generic.rs"))?;
152150
if config.generic_mod {
153151
let mut file = File::create(config.output_dir.join("generic.rs"))?;
154152
writeln!(file, "{}", generic_file)?;
155-
for ty in reg_sizes {
156-
writeln!(file, "impl_proxy!({});", ty.size_to_str()?)?;
157-
}
158153
if config.target == Target::Msp430 && config.nightly {
159154
let msp430_atomic_file =
160155
std::str::from_utf8(include_bytes!("generic_msp430_atomic.rs"))?;
@@ -175,10 +170,6 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
175170
}
176171
} else {
177172
let mut tokens = syn::parse_file(generic_file)?.into_token_stream();
178-
for ty in reg_sizes {
179-
let ty = Ident::new(ty.size_to_str()?, Span::call_site());
180-
tokens.extend(quote! { impl_proxy!(#ty); });
181-
}
182173
if config.target == Target::Msp430 && config.nightly {
183174
let msp430_atomic_file =
184175
std::str::from_utf8(include_bytes!("generic_msp430_atomic.rs"))?;

src/generate/generic.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::marker;
22

3+
/// Raw register type (`u8`, `u16`, `u32`, ...)
34
pub trait RawReg:
45
Copy
56
+ Default
@@ -8,7 +9,9 @@ pub trait RawReg:
89
+ core::ops::Not<Output = Self>
910
+ core::ops::Shl<u8, Output = Self>
1011
{
12+
/// Mask for bits of width `WI`
1113
fn mask<const WI: u8>() -> Self;
14+
/// Mask for bits of width 1
1215
fn one() -> Self;
1316
}
1417

@@ -549,6 +552,7 @@ where
549552
unsafe { self.bits(variant.into()) }
550553
}
551554
}
555+
552556
impl<'a, U, REG, N, FI, const WI: u8, const OF: u8> FieldWriterSafe<'a, U, REG, N, FI, WI, OF>
553557
where
554558
REG: Writable + RegisterSpec<Ux = U>,
@@ -569,13 +573,15 @@ where
569573
self.bits(variant.into())
570574
}
571575
}
576+
572577
impl_bit_proxy!(BitWriter);
573578
impl_bit_proxy!(BitWriter1S);
574579
impl_bit_proxy!(BitWriter0C);
575580
impl_bit_proxy!(BitWriter1C);
576581
impl_bit_proxy!(BitWriter0S);
577582
impl_bit_proxy!(BitWriter1T);
578583
impl_bit_proxy!(BitWriter0T);
584+
579585
impl<'a, U, REG, FI, const OF: u8> BitWriter<'a, U, REG, FI, OF>
580586
where
581587
REG: Writable + RegisterSpec<Ux = U>,
@@ -594,6 +600,7 @@ where
594600
self.bit(false)
595601
}
596602
}
603+
597604
impl<'a, U, REG, FI, const OF: u8> BitWriter1S<'a, U, REG, FI, OF>
598605
where
599606
REG: Writable + RegisterSpec<Ux = U>,
@@ -607,6 +614,7 @@ where
607614
self.bit(true)
608615
}
609616
}
617+
610618
impl<'a, U, REG, FI, const OF: u8> BitWriter0C<'a, U, REG, FI, OF>
611619
where
612620
REG: Writable + RegisterSpec<Ux = U>,
@@ -620,6 +628,7 @@ where
620628
self.bit(false)
621629
}
622630
}
631+
623632
impl<'a, U, REG, FI, const OF: u8> BitWriter1C<'a, U, REG, FI, OF>
624633
where
625634
REG: Writable + RegisterSpec<Ux = U>,
@@ -633,6 +642,7 @@ where
633642
self.bit(true)
634643
}
635644
}
645+
636646
impl<'a, U, REG, FI, const OF: u8> BitWriter0S<'a, U, REG, FI, OF>
637647
where
638648
REG: Writable + RegisterSpec<Ux = U>,
@@ -646,6 +656,7 @@ where
646656
self.bit(false)
647657
}
648658
}
659+
649660
impl<'a, U, REG, FI, const OF: u8> BitWriter1T<'a, U, REG, FI, OF>
650661
where
651662
REG: Writable + RegisterSpec<Ux = U>,
@@ -659,6 +670,7 @@ where
659670
self.bit(true)
660671
}
661672
}
673+
662674
impl<'a, U, REG, FI, const OF: u8> BitWriter0T<'a, U, REG, FI, OF>
663675
where
664676
REG: Writable + RegisterSpec<Ux = U>,

src/util.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -545,20 +545,6 @@ pub fn build_rs() -> TokenStream {
545545
}
546546
}
547547

548-
pub fn get_register_sizes(d: &Device) -> Vec<u32> {
549-
let mut reg_sizes = HashSet::new();
550-
for p in &d.peripherals {
551-
for r in p.all_registers() {
552-
if let Some(size) = r.properties.size {
553-
reg_sizes.insert(size);
554-
}
555-
}
556-
}
557-
let mut reg_sizes: Vec<_> = reg_sizes.into_iter().collect();
558-
reg_sizes.sort();
559-
reg_sizes
560-
}
561-
562548
pub trait FullName {
563549
fn fullname(&self, ignore_group: bool) -> Cow<str>;
564550
}

0 commit comments

Comments
 (0)