1
1
//! General Purpose Input/Output.
2
2
3
- use crate :: {
4
- pad:: { GpioFunc , Pad , PullUp } ,
5
- GPIO ,
6
- } ;
7
- use base_address:: BaseAddress ;
3
+ use crate :: pad:: { self , GpioFunc , Pad , PullUp } ;
8
4
use core:: marker:: PhantomData ;
9
5
use embedded_hal:: digital:: { ErrorType , OutputPin } ;
10
6
use volatile_register:: { RO , RW , WO } ;
@@ -69,8 +65,8 @@ impl Direction {
69
65
}
70
66
71
67
/// Owned GPIO peripheral signal with mode type state.
72
- pub struct Gpio < A : BaseAddress , const I : u8 , M > {
73
- base : GPIO < A > ,
68
+ pub struct Gpio < T , const I : u8 , M > {
69
+ inner : T ,
74
70
_mode : PhantomData < M > ,
75
71
}
76
72
@@ -80,7 +76,7 @@ pub struct Input;
80
76
/// Output mode (type state).
81
77
pub struct Output ;
82
78
83
- impl < A : BaseAddress , const I : u8 , M > Gpio < A , I , M > {
79
+ impl < T : AsRef < RegisterBlock > , const I : u8 , M > Gpio < T , I , M > {
84
80
/// Configures the GPIO signal as a `GpioPad` operating as a pull up output.
85
81
///
86
82
/// # Examples
@@ -93,16 +89,16 @@ impl<A: BaseAddress, const I: u8, M> Gpio<A, I, M> {
93
89
/// let mut led = p.pwr_gpio.a2.into_pull_up_output(pad_led);
94
90
/// ```
95
91
#[ inline]
96
- pub fn into_pull_up_output < A2 : BaseAddress , const N : usize > (
92
+ pub fn into_pull_up_output < U , const N : usize > (
97
93
self ,
98
- pad : Pad < A2 , N , GpioFunc < PullUp > > ,
99
- ) -> GpioPad < Gpio < A , I , Output > , Pad < A2 , N , GpioFunc < PullUp > > > {
94
+ pad : Pad < U , N , GpioFunc < PullUp > > ,
95
+ ) -> GpioPad < Gpio < T , I , Output > , Pad < U , N , GpioFunc < PullUp > > > {
100
96
unsafe {
101
- self . base . direction . modify ( |w| w. set_output ( I ) ) ;
97
+ self . inner . as_ref ( ) . direction . modify ( |w| w. set_output ( I ) ) ;
102
98
}
103
99
GpioPad {
104
100
gpio : Gpio {
105
- base : self . base ,
101
+ inner : self . inner ,
106
102
_mode : PhantomData ,
107
103
} ,
108
104
pad,
@@ -116,12 +112,12 @@ pub struct GpioPad<T, U> {
116
112
pad : U ,
117
113
}
118
114
119
- impl < A : BaseAddress , A2 : BaseAddress , const I : u8 , const N : usize , M , T >
120
- GpioPad < Gpio < A , I , M > , Pad < A2 , N , GpioFunc < T > > >
115
+ impl < T : AsRef < RegisterBlock > , U : AsRef < pad :: PadConfigs > , const I : u8 , const N : usize , M >
116
+ GpioPad < Gpio < T , I , M > , Pad < U , N , GpioFunc < T > > >
121
117
{
122
118
/// Reconfigures the `GpioPad` to operate as a pull up output.
123
119
#[ inline]
124
- pub fn into_pull_up_output ( self ) -> GpioPad < Gpio < A , I , Output > , Pad < A2 , N , GpioFunc < PullUp > > > {
120
+ pub fn into_pull_up_output ( self ) -> GpioPad < Gpio < T , I , Output > , Pad < U , N , GpioFunc < PullUp > > > {
125
121
let ( gpio, pad) = self . into_inner ( ) ;
126
122
gpio. into_pull_up_output ( pad. into_gpio_pull_up ( ) )
127
123
}
@@ -139,19 +135,19 @@ impl<T, U> ErrorType for GpioPad<T, U> {
139
135
type Error = core:: convert:: Infallible ;
140
136
}
141
137
142
- impl < A : BaseAddress , const I : u8 , U > OutputPin for GpioPad < Gpio < A , I , Output > , U > {
138
+ impl < T : AsRef < RegisterBlock > , const I : u8 , U > OutputPin for GpioPad < Gpio < T , I , Output > , U > {
143
139
#[ inline]
144
140
fn set_low ( & mut self ) -> Result < ( ) , Self :: Error > {
145
141
unsafe {
146
- self . gpio . base . data . modify ( |w| w & !( 1 << I ) ) ;
142
+ self . gpio . inner . as_ref ( ) . data . modify ( |w| w & !( 1 << I ) ) ;
147
143
}
148
144
Ok ( ( ) )
149
145
}
150
146
151
147
#[ inline]
152
148
fn set_high ( & mut self ) -> Result < ( ) , Self :: Error > {
153
149
unsafe {
154
- self . gpio . base . data . modify ( |w| w | ( 1 << I ) ) ;
150
+ self . gpio . inner . as_ref ( ) . data . modify ( |w| w | ( 1 << I ) ) ;
155
151
}
156
152
Ok ( ( ) )
157
153
}
0 commit comments