#ifndef __KEY_IT_H__
#define __KEY_IT_H__
#include"stm32mp1xx_gpio.h"
#include"stm32mp1xx_gic.h"
#include"stm32mp1xx_exti.h"
#include"stm32mp1xx_rcc.h"
#include"led.h"
void key1_it_config();
void key2_it_config();
void key3_it_config();
void delay(int ms);
#endif
#include "led.h"
void all_led_init()
{
RCC_GPIO |= (0X3<<4);//时钟使能
GPIOE_MODER &=(~(0X3<<20));//设置PE10输出
GPIOE_MODER |= (0X1<<20);
//设置PE10为推挽输出
GPIOE_OTYPER &=(~(0x1<<10));
//PE10为低速输出
GPIOE_OSPEEDR &= (~(0x3<<20));
//设置无上拉下拉
GPIOE_PUPDR &= (~(0x3<<20));
//LED2
GPIOF_MODER &=(~(0X3<<20));//设置Pf10输出
GPIOF_MODER |= (0X1<<20);
//设置Pf10为推挽输出
GPIOF_OTYPER &=(~(0x1<<10));
//Pf10为低速输出
GPIOF_OSPEEDR &= (~(0x3<<20));
//设置无上拉下拉
GPIOF_PUPDR &= (~(0x3<<20));
//LED3
GPIOE_MODER &=(~(0X3<<16));//设置PE8输出
GPIOE_MODER |= (0X1<<16);
//设置PE8为推挽输出
GPIOE_OTYPER &=(~(0x1<<8));
//PE8为低速输出
GPIOE_OSPEEDR &= (~(0x3<16));
//设置无上拉下拉
GPIOE_PUPDR &= (~(0x3<<16));
}
void led1_on()
{
GPIOE_ODR |= (0x1<<10);
}
void led1_off()
{
GPIOE_ODR &= (~(0x1<<10));
}
void led2_on()
{
GPIOF_ODR |= (0x1<<10);
}
void led2_off()
{
GPIOF_ODR &= (~(0x1<<10));
}
void led3_on()
{
GPIOE_ODR |= (0x1<<8);
}
void led3_off()
{
GPIOE_ODR &= (~(0x1<<8));
}
#include "key_it.h"
void delay(int ms)
{
int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<2000;j++);
}
}
int main()
{
key1_it_config();
key2_it_config();
key3_it_config();
while (1)
{
printf("do main...\n");
delay(2000);
}
}
#include "key_it.h"
extern void printf(const char *fmt, ...);
unsigned int i = 0;
void do_irq(void)
{
all_led_init();
int irqno = (GICC->IAR & 0x3ff);
switch (irqno)
{
case 99: // key1
printf("KEY1_INT\n");
led1_on();
delay(2000);
led1_off();
// 清除GICD的中断排队标志
GICD->ICPENDR[3] |= (0x1<<3);
// 清除exti的事件触发标志
EXTI->FPR1 |= (0x1<<9);
break;
case 97: // KEY2
printf("KEY2_INT\n");
led2_on();
delay(2000);
led2_off();
// 清除GICD的中断排队标志
GICD->ICPENDR[1] |= (0x1<<1);
// 清除exti的事件触发标志
EXTI->FPR1 |= (0x1<<7);
break;
case 98: // key3
printf("KEY3_INT\n");
led3_on();
delay(2000);
led3_off();
// 清除GICD的中断排队标志
GICD->ICPENDR[2] |= (0x1<<2);
// 清除exti的事件触发标志
EXTI->FPR1 |= (0x1<<8);
break;
}
// 清除中断号
GICC->EOIR = irqno;
}