Skip to content

Commit

Permalink
revert #465
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jun 5, 2023
1 parent 615f093 commit 4723dc9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- { rust: stable, vendor: Spansion, options: "--atomics" }
- { rust: stable, vendor: STMicro, options: "" }
- { rust: stable, vendor: STMicro, options: "--atomics" }
- { rust: stable, vendor: STM32-patched, options: "--strict --const_generic --derive_more --pascal_enum_values --max_cluster_size --atomics" }
- { rust: stable, vendor: STM32-patched, options: "--strict --const_generic --pascal_enum_values --max_cluster_size --atomics" }
- { rust: stable, vendor: Toshiba, options: all }
- { rust: stable, vendor: Toshiba, options: "" }
# Test MSRV
Expand Down
5 changes: 1 addition & 4 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main() {

case $OPTIONS in
all)
options="--const_generic --strict --derive_more --atomics"
options="--const_generic --strict --atomics"
;;
*)
options=$OPTIONS
Expand All @@ -43,9 +43,6 @@ main() {
echo 'cortex-m = "0.7.4"' >> $td/Cargo.toml
echo 'cortex-m-rt = "0.7.1"' >> $td/Cargo.toml
echo 'vcell = "0.1.3"' >> $td/Cargo.toml
if [[ "$options" == *"--derive_more"* ]]; then
echo 'derive_more = "0.99"' >> $td/Cargo.toml
fi
if [[ "$options" == *"--atomics"* ]]; then
echo 'portable-atomic = { version = "0.3.16", default-features = false }' >> $td/Cargo.toml
fi
Expand Down
72 changes: 33 additions & 39 deletions src/generate/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,14 @@ pub trait FieldSpec: Sized {
/// Trait implemented by readable registers to enable the `read` method.
///
/// Registers marked with `Writable` can be also be `modify`'ed.
pub trait Readable: RegisterSpec {
/// Result from a call to `read` and argument to `modify`.
type Reader: From<R<Self>> + core::ops::Deref<Target = R<Self>>;
}
pub trait Readable: RegisterSpec {}

/// Trait implemented by writeable registers.
///
/// This enables the `write`, `write_with_zero` and `reset` methods.
///
/// Registers marked with `Readable` can be also be `modify`'ed.
pub trait Writable: RegisterSpec {
/// Writer type argument to `write`, et al.
type Writer: From<W<Self>> + core::ops::DerefMut<Target = W<Self>>;

/// Specifies the register bits that are not changed if you pass `1` and are changed if you pass `0`
const ZERO_TO_MODIFY_FIELDS_BITMAP: Self::Ux;

Expand Down Expand Up @@ -130,11 +124,11 @@ impl<REG: Readable> Reg<REG> {
/// let flag = reader.field2().bit_is_set();
/// ```
#[inline(always)]
pub fn read(&self) -> REG::Reader {
REG::Reader::from(R {
pub fn read(&self) -> R<REG> {
R {
bits: self.register.get(),
_reg: marker::PhantomData,
})
}
}
}

Expand Down Expand Up @@ -173,14 +167,14 @@ impl<REG: Resettable + Writable> Reg<REG> {
#[inline(always)]
pub fn write<F>(&self, f: F)
where
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
self.register.set(
f(&mut REG::Writer::from(W {
f(&mut W {
bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
_reg: marker::PhantomData,
}))
})
.bits,
);
}
Expand All @@ -197,13 +191,13 @@ impl<REG: Writable> Reg<REG> {
#[inline(always)]
pub unsafe fn write_with_zero<F>(&self, f: F)
where
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
self.register.set(
f(&mut REG::Writer::from(W {
f(&mut W {
bits: REG::Ux::default(),
_reg: marker::PhantomData,
}))
})
.bits,
);
}
Expand Down Expand Up @@ -238,20 +232,20 @@ impl<REG: Readable + Writable> Reg<REG> {
#[inline(always)]
pub fn modify<F>(&self, f: F)
where
for<'w> F: FnOnce(&REG::Reader, &'w mut REG::Writer) -> &'w mut W<REG>,
for<'w> F: FnOnce(&R<REG>, &'w mut W<REG>) -> &'w mut W<REG>,
{
let bits = self.register.get();
self.register.set(
f(
&REG::Reader::from(R {
&R {
bits,
_reg: marker::PhantomData,
}),
&mut REG::Writer::from(W {
},
&mut W {
bits: bits & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
_reg: marker::PhantomData,
}),
},
)
.bits,
);
Expand Down Expand Up @@ -414,7 +408,7 @@ where
REG: Writable + RegisterSpec,
FI: FieldSpec,
{
pub(crate) w: &'a mut REG::Writer,
pub(crate) w: &'a mut W<REG>,
_field: marker::PhantomData<(FI, Safety)>,
}

Expand All @@ -427,7 +421,7 @@ where
/// Creates a new instance of the writer
#[allow(unused)]
#[inline(always)]
pub(crate) fn new(w: &'a mut REG::Writer) -> Self {
pub(crate) fn new(w: &'a mut W<REG>) -> Self {
Self {
w,
_field: marker::PhantomData,
Expand All @@ -441,7 +435,7 @@ where
REG: Writable + RegisterSpec,
bool: From<FI>,
{
pub(crate) w: &'a mut REG::Writer,
pub(crate) w: &'a mut W<REG>,
_field: marker::PhantomData<(FI, M)>,
}

Expand All @@ -453,7 +447,7 @@ where
/// Creates a new instance of the writer
#[allow(unused)]
#[inline(always)]
pub(crate) fn new(w: &'a mut REG::Writer) -> Self {
pub(crate) fn new(w: &'a mut W<REG>) -> Self {
Self {
w,
_field: marker::PhantomData,
Expand Down Expand Up @@ -514,14 +508,14 @@ macro_rules! impl_bit_proxy {
{
/// Writes bit to the field
#[inline(always)]
pub fn bit(self, value: bool) -> &'a mut REG::Writer {
pub fn bit(self, value: bool) -> &'a mut W<REG> {
self.w.bits &= !(REG::Ux::one() << OF);
self.w.bits |= (REG::Ux::from(value) & REG::Ux::one()) << OF;
self.w
}
/// Writes `variant` to the field
#[inline(always)]
pub fn variant(self, variant: FI) -> &'a mut REG::Writer {
pub fn variant(self, variant: FI) -> &'a mut W<REG> {
self.bit(bool::from(variant))
}
}
Expand All @@ -548,14 +542,14 @@ where
///
/// Passing incorrect value can cause undefined behaviour. See reference manual
#[inline(always)]
pub unsafe fn bits(self, value: FI::Ux) -> &'a mut REG::Writer {
pub unsafe fn bits(self, value: FI::Ux) -> &'a mut W<REG> {
self.w.bits &= !(REG::Ux::mask::<WI>() << OF);
self.w.bits |= (REG::Ux::from(value) & REG::Ux::mask::<WI>()) << OF;
self.w
}
/// Writes `variant` to the field
#[inline(always)]
pub fn variant(self, variant: FI) -> &'a mut REG::Writer {
pub fn variant(self, variant: FI) -> &'a mut W<REG> {
unsafe { self.bits(FI::Ux::from(variant)) }
}
}
Expand All @@ -567,14 +561,14 @@ where
{
/// Writes raw bits to the field
#[inline(always)]
pub fn bits(self, value: FI::Ux) -> &'a mut REG::Writer {
pub fn bits(self, value: FI::Ux) -> &'a mut W<REG> {
self.w.bits &= !(REG::Ux::mask::<WI>() << OF);
self.w.bits |= (REG::Ux::from(value) & REG::Ux::mask::<WI>()) << OF;
self.w
}
/// Writes `variant` to the field
#[inline(always)]
pub fn variant(self, variant: FI) -> &'a mut REG::Writer {
pub fn variant(self, variant: FI) -> &'a mut W<REG> {
self.bits(FI::Ux::from(variant))
}
}
Expand All @@ -594,13 +588,13 @@ where
{
/// Sets the field bit
#[inline(always)]
pub fn set_bit(self) -> &'a mut REG::Writer {
pub fn set_bit(self) -> &'a mut W<REG> {
self.w.bits |= REG::Ux::one() << OF;
self.w
}
/// Clears the field bit
#[inline(always)]
pub fn clear_bit(self) -> &'a mut REG::Writer {
pub fn clear_bit(self) -> &'a mut W<REG> {
self.w.bits &= !(REG::Ux::one() << OF);
self.w
}
Expand All @@ -613,7 +607,7 @@ where
{
/// Sets the field bit
#[inline(always)]
pub fn set_bit(self) -> &'a mut REG::Writer {
pub fn set_bit(self) -> &'a mut W<REG> {
self.w.bits |= REG::Ux::one() << OF;
self.w
}
Expand All @@ -626,7 +620,7 @@ where
{
/// Clears the field bit
#[inline(always)]
pub fn clear_bit(self) -> &'a mut REG::Writer {
pub fn clear_bit(self) -> &'a mut W<REG> {
self.w.bits &= !(REG::Ux::one() << OF);
self.w
}
Expand All @@ -639,7 +633,7 @@ where
{
///Clears the field bit by passing one
#[inline(always)]
pub fn clear_bit_by_one(self) -> &'a mut REG::Writer {
pub fn clear_bit_by_one(self) -> &'a mut W<REG> {
self.w.bits |= REG::Ux::one() << OF;
self.w
}
Expand All @@ -652,7 +646,7 @@ where
{
///Sets the field bit by passing zero
#[inline(always)]
pub fn set_bit_by_zero(self) -> &'a mut REG::Writer {
pub fn set_bit_by_zero(self) -> &'a mut W<REG> {
self.w.bits &= !(REG::Ux::one() << OF);
self.w
}
Expand All @@ -665,7 +659,7 @@ where
{
///Toggle the field bit by passing one
#[inline(always)]
pub fn toggle_bit(self) -> &'a mut REG::Writer {
pub fn toggle_bit(self) -> &'a mut W<REG> {
self.w.bits |= REG::Ux::one() << OF;
self.w
}
Expand All @@ -678,7 +672,7 @@ where
{
///Toggle the field bit by passing zero
#[inline(always)]
pub fn toggle_bit(self) -> &'a mut REG::Writer {
pub fn toggle_bit(self) -> &'a mut W<REG> {
self.w.bits &= !(REG::Ux::one() << OF);
self.w
}
Expand Down
18 changes: 9 additions & 9 deletions src/generate/generic_atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ where
#[inline(always)]
pub unsafe fn set_bits<F>(&self, f: F)
where
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
let bits = f(&mut REG::Writer::from(W {
let bits = f(&mut W {
bits: Default::default(),
_reg: marker::PhantomData,
}))
})
.bits;
REG::Ux::atomic_or(self.register.as_ptr(), bits);
}
Expand All @@ -70,12 +70,12 @@ where
#[inline(always)]
pub unsafe fn clear_bits<F>(&self, f: F)
where
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
let bits = f(&mut REG::Writer::from(W {
let bits = f(&mut W {
bits: !REG::Ux::default(),
_reg: marker::PhantomData,
}))
})
.bits;
REG::Ux::atomic_and(self.register.as_ptr(), bits);
}
Expand All @@ -89,12 +89,12 @@ where
#[inline(always)]
pub unsafe fn toggle_bits<F>(&self, f: F)
where
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
{
let bits = f(&mut REG::Writer::from(W {
let bits = f(&mut W {
bits: Default::default(),
_reg: marker::PhantomData,
}))
})
.bits;
REG::Ux::atomic_xor(self.register.as_ptr(), bits);
}
Expand Down
Loading

0 comments on commit 4723dc9

Please sign in to comment.