中级会员
- 积分
- 354
- 金钱
- 354
- 注册时间
- 2018-9-14
- 在线时间
- 157 小时
|
楼主 |
发表于 2020-12-11 17:55:52
|
显示全部楼层
本帖最后由 sppz 于 2020-12-11 19:30 编辑
根据157硬件手册,三个按钮连接的引脚为PA.0, PG.3, PH.7GPIO配置更新如下
- static void initialize_gpio() noexcept
- {
- // open GPIO[A, B, F, G, H, I]
- {
- auto mp_ahb4ensetr(RCC::MP_AHB4ENSETR());
- mp_ahb4ensetr.GPIOAEN() = 1;
- mp_ahb4ensetr.GPIOBEN() = 1;
- mp_ahb4ensetr.GPIOFEN() = 1;
- mp_ahb4ensetr.GPIOGEN() = 1;
- mp_ahb4ensetr.GPIOHEN() = 1;
- mp_ahb4ensetr.GPIOIEN() = 1;
- mp_ahb4ensetr.push();
- }
- { // A.0 WK_UP
- auto moder(GPIOA::MODER(0)); moder.MODE() = 0;
- moder.push();
- auto otyper(GPIOA::OTYPER(0)); otyper.OT() = 0;
- otyper.push();
- auto ospeedr(GPIOA::OSPEEDR(0)); ospeedr.OS() = 0;
- ospeedr.push();
- auto pupdr(GPIOA::PUPDR(0)); pupdr.PUPD() = 2;
- pupdr.push();
- auto afr(GPIOA::AFR(0)); afr.AF() = 0;
- afr.push();
- }
- { // B.2 UART4_RX
- auto moder(GPIOB::MODER(2)); moder.MODE() = 2;
- moder.push();
- auto otyper(GPIOB::OTYPER(2)); otyper.OT() = 0;
- otyper.push();
- auto ospeedr(GPIOB::OSPEEDR(2)); ospeedr.OS() = 3;
- ospeedr.push();
- auto pupdr(GPIOB::PUPDR(2)); pupdr.PUPD() = 1;
- pupdr.push();
- auto afr(GPIOB::AFR(2)); afr.AF() = 8;
- afr.push();
- }
- { // F.3 led
- auto moder(GPIOF::MODER(3)); moder.MODE() = 1;
- moder.push();
- auto otyper(GPIOF::OTYPER(3)); otyper.OT() = 0;
- otyper.push();
- auto ospeedr(GPIOF::OSPEEDR(3)); ospeedr.OS() = 0;
- ospeedr.push();
- auto pupdr(GPIOF::PUPDR(3)); pupdr.PUPD() = 1;
- pupdr.push();
- auto odr(GPIOF::ODR(3)); odr.OD() = 1;
- odr.push();
- }
- { // G.3 KEY0, G.11 UART4_TX
- auto moder(GPIOG::MODER(3)); moder.MODE() = 0;
- moder.index(11); moder.MODE() = 2;
- moder.push();
- auto otyper(GPIOG::OTYPER(3)); otyper.OT() = 0;
- otyper.index(11); otyper.OT() = 0;
- otyper.push();
- auto ospeedr(GPIOG::OSPEEDR(3)); ospeedr.OS() = 0;
- ospeedr.index(11); ospeedr.OS() = 3;
- ospeedr.push();
- auto pupdr(GPIOG::PUPDR(3)); pupdr.PUPD() = 1;
- pupdr.index(11); pupdr.PUPD() = 1;
- pupdr.push();
- auto afr(GPIOG::AFR(3)); afr.AF() = 0;
- afr.index(11); afr.AF() = 6;
- afr.push();
- }
- { // H.7 KEY1
- auto moder(GPIOH::MODER(7)); moder.MODE() = 0;
- moder.push();
- auto otyper(GPIOH::OTYPER(7)); otyper.OT() = 0;
- otyper.push();
- auto ospeedr(GPIOH::OSPEEDR(7)); ospeedr.OS() = 0;
- ospeedr.push();
- auto pupdr(GPIOH::PUPDR(7)); pupdr.PUPD() = 1;
- pupdr.push();
- auto afr(GPIOH::AFR(7)); afr.AF() = 0;
- afr.push();
- }
- { // I.0 led
- auto moder(GPIOI::MODER(0)); moder.MODE() = 1;
- moder.push();
- auto otyper(GPIOI::OTYPER(0)); otyper.OT() = 0;
- otyper.push();
- auto ospeedr(GPIOI::OSPEEDR(0)); ospeedr.OS() = 0;
- ospeedr.push();
- auto pupdr(GPIOI::PUPDR(0)); pupdr.PUPD() = 1;
- pupdr.push();
- auto odr(GPIOI::ODR(0)); odr.OD() = 0;
- odr.push();
- }
- }
复制代码 根据参考手册EXTI0, EXTI3, EXTI7,GIC号依次为38, 41, 97,更新配置如下
- static void initialize_gic() noexcept
- {
- //38 EXTI0, 41 EXTI3, 84 uart4, 86 tim6, 97 EXTI7
- auto igroupr(GICD::IGROUPR(38)); igroupr.GROUP_STATUS() = 1;
- igroupr.index(41); igroupr.GROUP_STATUS() = 1;
- igroupr.index(84); igroupr.GROUP_STATUS() = 1;
- igroupr.index(86); igroupr.GROUP_STATUS() = 1;
- igroupr.index(97); igroupr.GROUP_STATUS() = 1;
- igroupr.push();
- auto isenabler(GICD::ISENABLER(38)); isenabler.SET_ENABLE() = 1;
- isenabler.index(41); isenabler.SET_ENABLE() = 1;
- isenabler.index(84); isenabler.SET_ENABLE() = 1;
- isenabler.index(86); isenabler.SET_ENABLE() = 1;
- isenabler.index(97); isenabler.SET_ENABLE() = 1;
- isenabler.push();
- auto ipriorityr(GICD::IPRIORITYR(38)); ipriorityr.PRIORITY() = 0;
- ipriorityr.index(41); ipriorityr.PRIORITY() = 0;
- ipriorityr.index(84); ipriorityr.PRIORITY() = 0;
- ipriorityr.index(86); ipriorityr.PRIORITY() = 0;
- ipriorityr.index(97); ipriorityr.PRIORITY() = 0;
- ipriorityr.push();
- auto itargetsr(GICD::ITARGETSR(38)); itargetsr.CPU_TARGETS() = 1;
- itargetsr.index(41); itargetsr.CPU_TARGETS() = 1;
- itargetsr.index(84); itargetsr.CPU_TARGETS() = 1;
- itargetsr.index(86); itargetsr.CPU_TARGETS() = 1;
- itargetsr.index(97); itargetsr.CPU_TARGETS() = 1;
- itargetsr.push();
- auto icfgr(GICD::ICFGR(38)); icfgr.INT_CONFIG() = 3;
- icfgr.index(41); icfgr.INT_CONFIG() = 3;
- icfgr.index(84); icfgr.INT_CONFIG() = 1;
- icfgr.index(86); icfgr.INT_CONFIG() = 1;
- icfgr.index(97); icfgr.INT_CONFIG() = 3;
- icfgr.push();
- }
复制代码 然后是EXTI配置
- void initialize_exti() noexcept
- {
- // PA.0 WK_UP, PG.3 KEY0, PH.7 KEY1
- auto rtsr(EXTI::RTSR(0)); rtsr.RT() = 1;
- rtsr.index(3); rtsr.RT() = 1;
- rtsr.index(7); rtsr.RT() = 1;
- rtsr.push();
- auto ftsr(EXTI::FTSR(0)); ftsr.FT() = 1;
- ftsr.index(3); ftsr.FT() = 1;
- ftsr.index(7); ftsr.FT() = 1;
- ftsr.push();
- auto exticr(EXTI::EXTICR(0)); exticr.EXTI() = 0;
- exticr.index(3); exticr.EXTI() = 6;
- exticr.index(7); exticr.EXTI() = 7;
- exticr.push();
- auto imr(EXTI::IMR(0)); imr.IM() = 1;
- imr.index(3); imr.IM() = 1;
- imr.index(7); imr.IM() = 1;
- imr.push();
- auto emr(EXTI::EMR(0)); emr.EM() = 1;
- emr.index(3); emr.EM() = 1;
- emr.index(7); emr.EM() = 1;
- emr.push();
- }
复制代码 然后是三个EXTI中断的回调, 同时更新了下TIM6的回调,显示了三个引脚的状态和毫秒数,如下
- size systick_count(0);
- void px_GIC_TIM6() noexcept //
- {
- auto sr(TIM6::SR());
- sr.UIF() = 0;
- sr.push();
- ++systick_count;
- if (systick_count % 1000 == 0)
- {
- put_string("millisecond=");
- put_size(systick_count);
- {
- auto odr(GPIOF::ODR(3)); odr.OD() ^= 1;
- odr.push();
- }
- auto aidr(GPIOA::IDR(0));
- auto gidr(GPIOG::IDR(3));
- auto hidr(GPIOH::IDR(7));
- put_string(" WK_UP="); put_size(aidr.ID());
- put_string(" KEY0="); put_size(gidr.ID());
- put_string(" KEY1="); put_size(hidr.ID());
- put_string(".\r\n");
- }
- }
- void px_GIC_EXTI0() noexcept // WK_UP
- {
- auto rpr(EXTI::RPR(0));
- if (rpr.RPIF() == 1)
- {
- rpr.value() = 0;
- rpr.RPIF() = 1;
- rpr.push();
- }
- auto fpr(EXTI::FPR(0));
- if (fpr.FPIF() == 1)
- {
- fpr.value() = 0;
- fpr.FPIF() = 1;
- fpr.push();
- }
- put_string("WK_UP.\r\n");
- }
- void px_GIC_EXTI3() noexcept // KEY0
- {
- auto rpr(EXTI::RPR(3));
- if (rpr.RPIF() == 1)
- {
- rpr.value() = 0;
- rpr.RPIF() = 1;
- rpr.push();
- }
- auto fpr(EXTI::FPR(3));
- if (fpr.FPIF() == 1)
- {
- fpr.value() = 0;
- fpr.FPIF() = 1;
- fpr.push();
- }
- put_string("KEY0.\r\n");
- }
- void px_GIC_EXTI7() noexcept // KEY1
- {
- auto rpr(EXTI::RPR(7));
- if (rpr.RPIF() == 1)
- {
- rpr.value() = 0;
- rpr.RPIF() = 1;
- rpr.push();
- }
- auto fpr(EXTI::FPR(7));
- if (fpr.FPIF() == 1)
- {
- fpr.value() = 0;
- fpr.FPIF() = 1;
- fpr.push();
- }
- put_string("KEY1.\r\n");
- }
- void px_GIC_default() noexcept
- {
- put_string("GIC_default\r\n");
- }
复制代码
|
|