@@ -41,7 +41,8 @@ impl<T> Spis<T>
41
41
where
42
42
T : Instance ,
43
43
{
44
- /// Takes ownership of the raw SPIS peripheral, returning a safe wrapper.
44
+ /// Takes ownership of the raw SPIS peripheral and relevant pins,
45
+ /// returning a safe wrapper.
45
46
pub fn new ( spis : T , pins : Pins ) -> Self {
46
47
spis. psel . sck . write ( |w| {
47
48
unsafe { w. pin ( ) . bits ( pins. sck . pin ( ) ) } ;
@@ -166,11 +167,20 @@ where
166
167
self
167
168
}
168
169
169
- /// Requests acquiring the SPIS semaphore.
170
+ /// Requests acquiring the SPIS semaphore, returning an error if not
171
+ /// possible.
172
+ ///
173
+ /// Note: The semaphore will still be requested, and will be made
174
+ /// available at a later point.
170
175
#[ inline( always) ]
171
- pub fn try_acquire ( & self ) -> & Self {
176
+ pub fn try_acquire ( & self ) -> Result < & Self , Error > {
177
+ compiler_fence ( Ordering :: SeqCst ) ;
172
178
self . spis . tasks_acquire . write ( |w| unsafe { w. bits ( 1 ) } ) ;
173
- self
179
+ if self . spis . events_acquired . read ( ) . bits ( ) != 0 {
180
+ Ok ( self )
181
+ } else {
182
+ Err ( Error :: SemaphoreNotAvailable )
183
+ }
174
184
}
175
185
176
186
/// Releases the SPIS semaphore, enabling the SPIS to acquire it.
@@ -566,6 +576,7 @@ pub enum Mode {
566
576
pub enum Error {
567
577
DMABufferNotInDataMemory ,
568
578
BufferTooLong ,
579
+ SemaphoreNotAvailable ,
569
580
}
570
581
571
582
/// GPIO pins for SPIS interface.
0 commit comments