@@ -4,6 +4,7 @@ use crate::gpio::{
4
4
} ;
5
5
use crate :: pac;
6
6
use atsamd_hal_macros:: hal_cfg;
7
+ use core:: mem:: ManuallyDrop ;
7
8
8
9
use super :: EIC ;
9
10
@@ -18,13 +19,13 @@ pub trait EicPin {
18
19
type PullDown ;
19
20
20
21
/// Configure a pin as a floating external interrupt
21
- fn into_floating_ei ( self ) -> Self :: Floating ;
22
+ fn into_floating_ei ( self , eic : & mut EIC ) -> Self :: Floating ;
22
23
23
24
/// Configure a pin as pulled-up external interrupt
24
- fn into_pull_up_ei ( self ) -> Self :: PullUp ;
25
+ fn into_pull_up_ei ( self , eic : & mut EIC ) -> Self :: PullUp ;
25
26
26
27
/// Configure a pin as pulled-down external interrupt
27
- fn into_pull_down_ei ( self ) -> Self :: PullDown ;
28
+ fn into_pull_down_ei ( self , eic : & mut EIC ) -> Self :: PullDown ;
28
29
}
29
30
30
31
pub type Sense = pac:: eic:: config:: Sense0select ;
@@ -56,6 +57,7 @@ crate::paste::item! {
56
57
where
57
58
GPIO : AnyPin ,
58
59
{
60
+ eic: ManuallyDrop <EIC >,
59
61
_pin: Pin <GPIO :: Id , GPIO :: Mode >,
60
62
}
61
63
@@ -66,33 +68,38 @@ crate::paste::item! {
66
68
/// Construct pad from the appropriate pin in any mode.
67
69
/// You may find it more convenient to use the `into_pad` trait
68
70
/// and avoid referencing the pad type.
69
- pub fn new( pin: GPIO ) -> Self {
71
+ pub fn new( pin: GPIO , eic: & mut super :: EIC ) -> [ <$PadType $num>] <GPIO > {
72
+ let eic = unsafe {
73
+ ManuallyDrop :: new( core:: ptr:: read( eic as * const _) )
74
+ } ;
75
+
70
76
[ <$PadType $num>] {
71
- _pin: pin. into( )
77
+ _pin: pin. into( ) ,
78
+ eic,
72
79
}
73
80
}
74
81
75
82
/// Configure the eic with options for this external interrupt
76
- pub fn enable_event( & mut self , eic : & mut EIC ) {
77
- eic. eic. evctrl( ) . modify( |_, w| {
83
+ pub fn enable_event( & mut self ) {
84
+ self . eic. eic. evctrl( ) . modify( |_, w| {
78
85
w. [ <extinteo $num>] ( ) . set_bit( )
79
86
} ) ;
80
87
}
81
88
82
- pub fn enable_interrupt( & mut self , eic : & mut EIC ) {
83
- eic. eic. intenset( ) . write( |w| {
89
+ pub fn enable_interrupt( & mut self ) {
90
+ self . eic. eic. intenset( ) . write( |w| {
84
91
w. [ <extint $num>] ( ) . set_bit( )
85
92
} ) ;
86
93
}
87
94
88
- pub fn enable_interrupt_wake( & mut self , eic : & mut EIC ) {
89
- eic. eic. wakeup( ) . modify( |_, w| {
95
+ pub fn enable_interrupt_wake( & mut self ) {
96
+ self . eic. eic. wakeup( ) . modify( |_, w| {
90
97
w. [ <wakeupen $num>] ( ) . set_bit( )
91
98
} )
92
99
}
93
100
94
- pub fn disable_interrupt( & mut self , eic : & mut EIC ) {
95
- eic. eic. intenclr( ) . write( |w| {
101
+ pub fn disable_interrupt( & mut self ) {
102
+ self . eic. eic. intenclr( ) . write( |w| {
96
103
w. [ <extint $num>] ( ) . set_bit( )
97
104
} ) ;
98
105
}
@@ -107,10 +114,10 @@ crate::paste::item! {
107
114
} ) ;
108
115
}
109
116
110
- pub fn sense( & mut self , _eic : & mut EIC , sense: Sense ) {
117
+ pub fn sense( & mut self , sense: Sense ) {
111
118
// Which of the two config blocks this eic config is in
112
119
let offset = ( $num >> 3 ) & 0b0001 ;
113
- let config = unsafe { & ( * pac :: Eic :: ptr ( ) ) . config( offset) } ;
120
+ let config = & self . eic . eic . config( offset) ;
114
121
115
122
config. modify( |_, w| unsafe {
116
123
// Which of the eight eic configs in this config block
@@ -128,10 +135,10 @@ crate::paste::item! {
128
135
} ) ;
129
136
}
130
137
131
- pub fn filter( & mut self , _eic : & mut EIC , filter: bool ) {
138
+ pub fn filter( & mut self , filter: bool ) {
132
139
// Which of the two config blocks this eic config is in
133
140
let offset = ( $num >> 3 ) & 0b0001 ;
134
- let config = unsafe { & ( * pac :: Eic :: ptr ( ) ) . config( offset) } ;
141
+ let config = & self . eic . eic . config( offset) ;
135
142
136
143
config. modify( |_, w| {
137
144
// Which of the eight eic configs in this config block
@@ -179,16 +186,16 @@ crate::paste::item! {
179
186
type PullUp = [ <$PadType $num>] <Pin <gpio:: $PinType, PullUpInterrupt >>;
180
187
type PullDown = [ <$PadType $num>] <Pin <gpio:: $PinType, PullDownInterrupt >>;
181
188
182
- fn into_floating_ei( self ) -> Self :: Floating {
183
- [ <$PadType $num>] :: new( self . into_floating_interrupt( ) )
189
+ fn into_floating_ei( self , eic : & mut super :: EIC ) -> Self :: Floating {
190
+ [ <$PadType $num>] :: new( self . into_floating_interrupt( ) , eic )
184
191
}
185
192
186
- fn into_pull_up_ei( self ) -> Self :: PullUp {
187
- [ <$PadType $num>] :: new( self . into_pull_up_interrupt( ) )
193
+ fn into_pull_up_ei( self , eic : & mut super :: EIC ) -> Self :: PullUp {
194
+ [ <$PadType $num>] :: new( self . into_pull_up_interrupt( ) , eic )
188
195
}
189
196
190
- fn into_pull_down_ei( self ) -> Self :: PullDown {
191
- [ <$PadType $num>] :: new( self . into_pull_down_interrupt( ) )
197
+ fn into_pull_down_ei( self , eic : & mut super :: EIC ) -> Self :: PullDown {
198
+ [ <$PadType $num>] :: new( self . into_pull_down_interrupt( ) , eic )
192
199
}
193
200
}
194
201
0 commit comments