按键配置
# include "key_it.h"
# include "stm32mp1xx_gpio.h"
# include "stm32mp1xx_gic.h"
# include "stm32mp1xx_exti.h"
# include "stm32mp1xx_rcc.h" void key_it_config ( )
{ RCC-> MP_AHB4ENSETR |= ( 1 << 5 ) ; GPIOF-> MODER &= ( ~ ( 0x3 << 14 ) ) ; GPIOF-> MODER &= ( ~ ( 0x3 << 16 ) ) ; GPIOF-> MODER &= ( ~ ( 0x3 << 18 ) ) ; EXTI-> EXTICR2 &= ~ ( 0xff << 24 ) ; EXTI-> EXTICR2 |= ( 0x05 << 24 ) ; EXTI-> EXTICR3 &= ~ ( 0xff ) ; EXTI-> EXTICR3 |= ( 0x05 ) ; EXTI-> EXTICR3 &= ~ ( 0xff << 8 ) ; EXTI-> EXTICR3 |= ( 0x05 << 8 ) ; EXTI-> FTSR1 |= ( 1 << 7 ) ; EXTI-> FTSR1 |= ( 1 << 8 ) ; EXTI-> FTSR1 |= ( 1 << 9 ) ; EXTI-> C1IMR1 |= ( 1 << 7 ) ; EXTI-> C1IMR1 |= ( 1 << 8 ) ; EXTI-> C1IMR1 |= ( 1 << 9 ) ; GICD-> ISENABLER[ 3 ] |= ( 1 << 3 ) ; GICD-> ISENABLER[ 3 ] |= ( 1 << 2 ) ; GICD-> ISENABLER[ 3 ] |= ( 1 << 1 ) ; GICD-> IPRIORITYR[ 24 ] &= ~ ( 0x1f << 27 ) ; GICD-> IPRIORITYR[ 24 ] &= ~ ( 0x1f << 19 ) ; GICD-> IPRIORITYR[ 24 ] &= ~ ( 0x1f << 11 ) ; GICD-> ITARGETSR[ 24 ] &= ~ ( 0x03 << 24 ) ; GICD-> ITARGETSR[ 24 ] |= ( 0x01 << 24 ) ; GICD-> ITARGETSR[ 24 ] &= ~ ( 0x03 << 16 ) ; GICD-> ITARGETSR[ 24 ] |= ( 0x01 << 16 ) ; GICD-> ITARGETSR[ 24 ] &= ~ ( 0x03 << 8 ) ; GICD-> ITARGETSR[ 24 ] |= ( 0x01 << 8 ) ; GICD-> CTRL |= 0x1 ; GICC-> PMR |= ( 0x1f << 3 ) ; GICC-> CTRL |= 0x1 ; }
中断实现
# include "stm32mp1xx_gic.h"
# include "stm32mp1xx_exti.h"
# include "beep.h" # define EXTI9_IRQ 99
# define EXTI8_IRQ 98
# define EXTI7_IRQ 97 extern void printf ( const char * fmt, . . . ) ;
unsigned int i = 0 ;
void do_irq ( void )
{ int irqno; irqno = GICC-> IAR & 0x3ff ; if ( irqno == EXTI9_IRQ) { delay ( 1000 ) ; if ( irqno == EXTI9_IRQ) { printf ( "KEY1 pressed!\n\r" ) ; hal_gpio_write ( GPIOB, 6 , ! hal_gpio_read ( GPIOB, 6 ) ) ; GICD-> ICPENDR[ 3 ] |= ( 1 << 3 ) ; EXTI-> FPR1 |= ( 1 << 9 ) ; } } else if ( irqno == EXTI8_IRQ) { delay ( 1000 ) ; if ( irqno == EXTI8_IRQ) { printf ( "KEY3 pressed!\n\r" ) ; hal_gpio_write ( GPIOE, 8 , ! hal_gpio_read ( GPIOE, 8 ) ) ; GICD-> ICPENDR[ 3 ] |= ( 1 << 2 ) ; EXTI-> FPR1 |= ( 1 << 8 ) ; } } else if ( irqno == EXTI7_IRQ) { delay ( 1000 ) ; if ( irqno == EXTI7_IRQ) { printf ( "KEY2 pressed!\n\r" ) ; hal_gpio_write ( GPIOE, 9 , ! hal_gpio_read ( GPIOE, 9 ) ) ; GICD-> ICPENDR[ 3 ] |= ( 1 << 1 ) ; EXTI-> FPR1 |= ( 1 << 7 ) ; } } GICC-> EOIR = irqno; }