@@ -15,9 +15,26 @@ pub enum EventType {
1515 Rise ,
1616 /// Falling edge event
1717 Fall ,
18+ /// Both levels event
19+ ///
20+ /// # Note
21+ ///
22+ /// In the methods that check if an interrupt is enabled or pending,
23+ /// this event type works like an **any** operator between `High` and `Low` events.
24+ BothLevels ,
1825 /// Both edges event
26+ ///
27+ /// # Note
28+ ///
29+ /// In the methods that check if an interrupt is enabled or pending,
30+ /// this event type works like an **any** operator between `Rise` and `Fall` events.
1931 BothEdges ,
2032 /// All events
33+ ///
34+ /// # Note
35+ ///
36+ /// In the methods that check if an interrupt is enabled or pending,
37+ /// this event type works like an **any** operator between all event types.
2138 All ,
2239}
2340
@@ -34,9 +51,9 @@ pub trait GpioExt {
3451 /// # Note
3552 ///
3653 /// This function does not enable the interrupts in the PLIC, it only sets the
37- /// interrupt enable bit in the GPIO peripheral. You must call
38- /// [`enable_exti()`](super::gpio::gpio0::Pin0::enable_exti) on the pin to enable its interrupt in
39- /// the PLIC.
54+ /// interrupt enable bits in the GPIO peripheral. You must call the
55+ /// [`enable_exti()`](super::gpio::gpio0::Pin0::enable_exti) method of every pin
56+ /// to enable their interrupt in the PLIC.
4057 fn enable_interrupts ( event : EventType ) ;
4158
4259 /// Disables the specified interrupt event for all the GPIO pins.
@@ -222,6 +239,12 @@ macro_rules! gpio {
222239 EventType :: Low => {
223240 unsafe { p. low_ie( ) . write( |w| w. bits( 0xFFFFFFFF ) ) } ;
224241 }
242+ EventType :: BothLevels => {
243+ unsafe {
244+ p. high_ie( ) . write( |w| w. bits( 0xFFFFFFFF ) ) ;
245+ p. low_ie( ) . write( |w| w. bits( 0xFFFFFFFF ) ) ;
246+ }
247+ }
225248 EventType :: Rise => {
226249 unsafe { p. rise_ie( ) . write( |w| w. bits( 0xFFFFFFFF ) ) } ;
227250 }
@@ -255,6 +278,12 @@ macro_rules! gpio {
255278 EventType :: Low => {
256279 unsafe { p. low_ie( ) . write( |w| w. bits( 0x00000000 ) ) ; }
257280 }
281+ EventType :: BothLevels => {
282+ unsafe {
283+ p. high_ie( ) . write( |w| w. bits( 0x00000000 ) ) ;
284+ p. low_ie( ) . write( |w| w. bits( 0x00000000 ) ) ;
285+ }
286+ }
258287 EventType :: Rise => {
259288 unsafe { p. rise_ie( ) . write( |w| w. bits( 0x00000000 ) ) ; }
260289 }
@@ -288,6 +317,12 @@ macro_rules! gpio {
288317 EventType :: Low => {
289318 unsafe { p. low_ip( ) . write( |w| w. bits( 0xFFFFFFFF ) ) ; }
290319 }
320+ EventType :: BothLevels => {
321+ unsafe {
322+ p. high_ip( ) . write( |w| w. bits( 0xFFFFFFFF ) ) ;
323+ p. low_ip( ) . write( |w| w. bits( 0xFFFFFFFF ) ) ;
324+ }
325+ }
291326 EventType :: Rise => {
292327 unsafe { p. rise_ip( ) . write( |w| w. bits( 0xFFFFFFFF ) ) ; }
293328 }
@@ -415,8 +450,8 @@ macro_rules! gpio {
415450 /// # Note
416451 ///
417452 /// This function enables the external interrupt source in the PLIC,
418- /// but does not enable the PLIC peripheral itself. To enable the plic peripheral
419- /// you must call [`Plic::enable()`](riscv-peripheral::plic::enables::ENABLES::enable) .
453+ /// but does not enable the PLIC peripheral itself. For more details,
454+ /// refer to the [`e310x::Plic`] documentation .
420455 ///
421456 /// # Safety
422457 ///
@@ -432,7 +467,7 @@ macro_rules! gpio {
432467 ctx. enables( ) . disable( ExternalInterrupt :: $handle) ;
433468 }
434469
435- /// Returns if the external interrupt source for the pin is enabled.
470+ /// Returns whether the external interrupt source for the pin is enabled.
436471 pub fn is_exti_enabled( & self , plic: & Plic ) -> bool {
437472 let ctx = plic. ctx0( ) ;
438473 ctx. enables( ) . is_enabled( ExternalInterrupt :: $handle)
@@ -473,6 +508,12 @@ macro_rules! gpio {
473508 EventType :: Low => {
474509 unsafe { gpio_block. low_ie( ) . modify( |r, w| w. bits( r. bits( ) | pin_mask) ) ; }
475510 }
511+ EventType :: BothLevels => {
512+ unsafe {
513+ gpio_block. high_ie( ) . modify( |r, w| w. bits( r. bits( ) | pin_mask) ) ;
514+ gpio_block. low_ie( ) . modify( |r, w| w. bits( r. bits( ) | pin_mask) ) ;
515+ }
516+ }
476517 EventType :: Rise => {
477518 unsafe { gpio_block. rise_ie( ) . modify( |r, w| w. bits( r. bits( ) | pin_mask) ) ; }
478519 }
@@ -508,6 +549,12 @@ macro_rules! gpio {
508549 EventType :: Low => {
509550 unsafe { gpio_block. low_ie( ) . modify( |r, w| w. bits( r. bits( ) & !pin_mask) ) ; }
510551 }
552+ EventType :: BothLevels => {
553+ unsafe {
554+ gpio_block. high_ie( ) . modify( |r, w| w. bits( r. bits( ) & !pin_mask) ) ;
555+ gpio_block. low_ie( ) . modify( |r, w| w. bits( r. bits( ) & !pin_mask) ) ;
556+ }
557+ }
511558 EventType :: Rise => {
512559 unsafe { gpio_block. rise_ie( ) . modify( |r, w| w. bits( r. bits( ) & !pin_mask) ) ; }
513560 }
@@ -543,6 +590,12 @@ macro_rules! gpio {
543590 EventType :: Low => {
544591 unsafe { gpio_block. low_ip( ) . write( |w| w. bits( pin_mask) ) ; }
545592 }
593+ EventType :: BothLevels => {
594+ unsafe {
595+ gpio_block. high_ip( ) . write( |w| w. bits( pin_mask) ) ;
596+ gpio_block. low_ip( ) . write( |w| w. bits( pin_mask) ) ;
597+ }
598+ }
546599 EventType :: Rise => {
547600 unsafe { gpio_block. rise_ip( ) . write( |w| w. bits( pin_mask) ) ; }
548601 }
@@ -570,9 +623,11 @@ macro_rules! gpio {
570623 ///
571624 /// # Note
572625 ///
573- /// Both Edges will return true if either the
574- /// rising or falling edge interrupts are enabled
575- /// and All will return true if any of the
626+ /// [EventType::BothEdges] will return true if either the
627+ /// rising or falling edge interrupts are enabled,
628+ /// [EventType::BothLevels] will return true if either the
629+ /// high or low level interrupts are enabled
630+ /// and [EventType::All] will return true if any of the
576631 /// interrupts are enabled.
577632 pub fn is_interrupt_enabled( & self , event: EventType ) -> bool {
578633 let gpio_block = $GPIOX:: peripheral( ) ;
@@ -581,6 +636,10 @@ macro_rules! gpio {
581636 match event {
582637 EventType :: High => gpio_block. high_ie( ) . read( ) . bits( ) & pin_mask != 0 ,
583638 EventType :: Low => gpio_block. low_ie( ) . read( ) . bits( ) & pin_mask != 0 ,
639+ EventType :: BothLevels => {
640+ ( gpio_block. high_ie( ) . read( ) . bits( ) & pin_mask != 0 ) ||
641+ ( gpio_block. low_ie( ) . read( ) . bits( ) & pin_mask != 0 )
642+ }
584643 EventType :: Rise => gpio_block. rise_ie( ) . read( ) . bits( ) & pin_mask != 0 ,
585644 EventType :: Fall => gpio_block. fall_ie( ) . read( ) . bits( ) & pin_mask != 0 ,
586645 EventType :: BothEdges => {
@@ -600,9 +659,11 @@ macro_rules! gpio {
600659 ///
601660 /// # Note
602661 ///
603- /// Both Edges will return true if either the
604- /// rising or falling edge interrupts are pending
605- /// and All will return true if any of the
662+ /// [EventType::BothEdges] will return true if either the
663+ /// rising or falling edge interrupts are pending,
664+ /// [EventType::BothLevels] will return true if either the
665+ /// high or low level interrupts are pending
666+ /// and [EventType::All] will return true if any of the
606667 /// interrupts are pending.
607668 pub fn is_interrupt_pending( & self , event: EventType ) -> bool {
608669 let gpio_block = $GPIOX:: peripheral( ) ;
@@ -611,6 +672,10 @@ macro_rules! gpio {
611672 match event {
612673 EventType :: High => gpio_block. high_ip( ) . read( ) . bits( ) & pin_mask != 0 ,
613674 EventType :: Low => gpio_block. low_ip( ) . read( ) . bits( ) & pin_mask != 0 ,
675+ EventType :: BothLevels => {
676+ ( gpio_block. high_ip( ) . read( ) . bits( ) & pin_mask != 0 ) ||
677+ ( gpio_block. low_ip( ) . read( ) . bits( ) & pin_mask != 0 )
678+ }
614679 EventType :: Rise => gpio_block. rise_ip( ) . read( ) . bits( ) & pin_mask != 0 ,
615680 EventType :: Fall => gpio_block. fall_ip( ) . read( ) . bits( ) & pin_mask != 0 ,
616681 EventType :: BothEdges => {
0 commit comments