Skip to content

Commit 5d6c2e7

Browse files
committed
Remove Reg<..> marker traits
1 parent 04cab1a commit 5d6c2e7

File tree

1 file changed

+11
-47
lines changed

1 file changed

+11
-47
lines changed

src/generate/generic.rs

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
use core::marker;
22

3+
/// Raw register type
34
pub trait Register {
5+
/// Raw register type (`u8`, `u16`, `u32`, ...).
46
type Ux: Copy;
57
}
68

7-
pub trait ReadableRegister: Register {}
8-
pub trait WritableRegister: Register {}
9-
pub trait ResettableRegister: Register {
10-
fn reset_value() -> Self::Ux;
11-
}
12-
139
/// Trait implemented by readable registers to enable the `read` method.
1410
///
1511
/// Registers marked with `Writable` can be also `modify`'ed.
16-
pub trait Readable {}
12+
pub trait ReadableRegister: Register {}
1713

1814
/// Trait implemented by writeable registers.
1915
///
2016
/// This enables the `write`, `write_with_zero` and `reset` methods.
2117
///
2218
/// Registers marked with `Readable` can be also `modify`'ed.
23-
pub trait Writable {}
24-
19+
pub trait WritableRegister: Register {}
2520

26-
/// Raw register type (autoimplemented for `Reg` type)
27-
pub trait RawType {
28-
/// Raw register type (`u8`, `u16`, `u32`, ...).
29-
type Ux: Copy;
30-
}
3121
/// Reset value of the register.
3222
///
3323
/// This value is the initial value for the `write` method. It can also be directly written to the
3424
/// register by using the `reset` method.
35-
pub trait ResetValue: RawType {
25+
pub trait ResettableRegister: Register {
3626
/// Reset value of the register.
3727
fn reset_value() -> Self::Ux;
3828
}
@@ -43,15 +33,6 @@ pub struct Reg<REG: Register> {
4333
_marker: marker::PhantomData<REG>,
4434
}
4535

46-
impl<REG: ReadableRegister> Readable for Reg<REG> {}
47-
impl<REG: WritableRegister> Writable for Reg<REG> {}
48-
impl<REG: ResettableRegister> ResetValue for Reg<REG> {
49-
#[inline(always)]
50-
fn reset_value() -> Self::Ux {
51-
REG::reset_value()
52-
}
53-
}
54-
5536
unsafe impl<REG: Register> Send for Reg<REG> where REG::Ux: Send {}
5637

5738
impl<REG: Register> Reg<REG>
@@ -69,9 +50,8 @@ where
6950
}
7051
}
7152

72-
impl<REG: Register> Reg<REG>
53+
impl<REG: ReadableRegister> Reg<REG>
7354
where
74-
Self: Readable,
7555
REG::Ux: Copy,
7656
{
7757
/// Reads the contents of a `Readable` register.
@@ -95,32 +75,18 @@ where
9575
}
9676
}
9777

98-
impl<REG: Register> RawType for Reg<REG>
78+
impl<REG: ResettableRegister + WritableRegister> Reg<REG>
9979
where
10080
REG::Ux: Copy,
101-
{
102-
type Ux = REG::Ux;
103-
}
104-
105-
impl<REG: Register> Reg<REG>
106-
where
107-
Self: ResetValue + RawType<Ux = REG::Ux> + Writable,
108-
REG::Ux: Copy,
10981
{
11082
/// Writes the reset value to `Writable` register.
11183
///
11284
/// Resets the register to its initial state.
11385
#[inline(always)]
11486
pub fn reset(&self) {
115-
self.register.set(Self::reset_value())
87+
self.register.set(REG::reset_value())
11688
}
117-
}
11889

119-
impl<REG: Register> Reg<REG>
120-
where
121-
Self: ResetValue + RawType<Ux = REG::Ux> + Writable,
122-
REG::Ux: Copy
123-
{
12490
/// Writes bits to a `Writable` register.
12591
///
12692
/// You can write raw bits into a register:
@@ -143,17 +109,16 @@ where
143109
{
144110
self.register.set(
145111
f(&mut W {
146-
bits: Self::reset_value(),
112+
bits: REG::reset_value(),
147113
_reg: marker::PhantomData,
148114
})
149115
.bits,
150116
);
151117
}
152118
}
153119

154-
impl<REG: Register> Reg<REG>
120+
impl<REG: WritableRegister> Reg<REG>
155121
where
156-
Self: Writable,
157122
REG::Ux: Copy + Default,
158123
{
159124
/// Writes 0 to a `Writable` register.
@@ -174,9 +139,8 @@ where
174139
}
175140
}
176141

177-
impl<REG: Register> Reg<REG>
142+
impl<REG: ReadableRegister + WritableRegister> Reg<REG>
178143
where
179-
Self: Readable + Writable,
180144
REG::Ux: Copy,
181145
{
182146
/// Modifies the contents of the register by reading and then writing it.

0 commit comments

Comments
 (0)