DA14580睡眠外部唤醒支持多个按键

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DA14580睡眠外部唤醒支持多个按键相关的知识,希望对你有一定的参考价值。

本人用的5.0.4版本SDK进行开发,有单个例程睡眠唤醒,只能是一个按键,官方也没说只能支持一个,但是当时也没有要用到两个按键同事唤醒的地方,所以没去搞,后面方案改动,使得功能变动,需要达到此功能,跟朋友交流,研究了技术手册发现可以配置,改底层,废话不多说,看代码

这是官方代码,只支持一个外部唤醒就是这里有覆盖问题,修改就行了

void my_wkupct_enable_irq( uint16_t events_num, uint16_t deb_time)
{
    uint8_t temp,i;
    uint32_t sel_pins,pol_pins;
    
    #ifdef USE_ARCH_WKUPCT_DEB_TIME
    arch_wkupct_deb_time = deb_time;                                // Store value in retention memory
    #endif
    
    SetBits16(CLK_PER_REG, WAKEUPCT_ENABLE, 1);                     // enable clock of Wakeup Controller

    SetWord16(WKUP_RESET_CNTR_REG, 0);                              // Clear event counter (for safety...)
    SetWord16(WKUP_COMPARE_REG, (events_num & 0xFF));               // Wait for 1 event and wakeup

//    sel_pins = (1U << (8+3));
//    pol_pins = (0 << (8+3));
    
    sel_pins = WKUPCT_PIN_SELECT(FACTORY_BUTTON_PORT, FACTORY_BUTTON_PIN);
    pol_pins = WKUPCT_PIN_POLARITY(FACTORY_BUTTON_PORT, FACTORY_BUTTON_PIN, WKUPCT_PIN_POLARITY_LOW);
    
    i=0;//P0
    temp = (uint8_t)((sel_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_SELECT_P0_REG + (2 * i), temp);
    temp = (uint8_t)((pol_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_POL_P0_REG + (2 * i), temp);

    i=1;//P1
    temp = (uint8_t)((sel_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_SELECT_P0_REG + (2 * i), temp);
    temp = (uint8_t)((pol_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_POL_P0_REG + (2 * i), temp);    
    
//    sel_pins = (1U << (16+0));
//    pol_pins = (1 << (16+0));
    
    sel_pins = WKUPCT_PIN_SELECT(FUNCTION_BUTTON_PORT, FUNCTION_BUTTON_PIN);
    pol_pins = WKUPCT_PIN_POLARITY(FUNCTION_BUTTON_PORT, FUNCTION_BUTTON_PIN, WKUPCT_PIN_POLARITY_LOW);    
    
    i=2;//P2
    temp = (uint8_t)((sel_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_SELECT_P0_REG + (2 * i), temp);
    temp = (uint8_t)((pol_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_POL_P0_REG + (2 * i), temp);    
    
    i=3;//P3
    temp = (uint8_t)((sel_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_SELECT_P0_REG + (2 * i), temp);
    temp = (uint8_t)((pol_pins >> (8 * i)) & 0xFF);
    SetWord16(WKUP_POL_P0_REG + (2 * i), temp);    

    // Set P28, P29 configuration
//    SetBits16(WKUP_SELECT_P2_REG, (3<<8), (sel_pins>>14)&3);
//    SetBits16(WKUP_POL_P2_REG, (3<<8), (pol_pins>>14)&3);

    SetWord16(WKUP_RESET_IRQ_REG, 1);                               // clear any garbagge
    NVIC_ClearPendingIRQ(WKUP_QUADEC_IRQn);                         // clear it to be on the safe side...

    SetWord16(WKUP_CTRL_REG, 0x80 | (deb_time & 0x3F));             // Setup IRQ: Enable IRQ, T ms debounce
    NVIC_SetPriority(WKUP_QUADEC_IRQn, 1);                          // Set irq Priority to 1
    wkupct_quad_IRQ_status.reservations.reserved_by_wkupct = true;  // Wakeup Timer registers IRQ use
    NVIC_EnableIRQ(WKUP_QUADEC_IRQn);
}

 

以上是关于DA14580睡眠外部唤醒支持多个按键的主要内容,如果未能解决你的问题,请参考以下文章

全球最低功耗蓝牙单芯片DA14580的硬件架构和低功耗

全球最低功耗蓝牙单芯片DA14580的硬件架构和低功耗

nanoFramework ESP32 使用键盘睡眠后无法唤醒

DA14580之GPIO口的使用

全球最低功耗蓝牙单芯片DA14580的软件体系 -层次架构和BLE消息事件处理过程

全球最低功耗蓝牙单芯片DA14580的软件体系 -RW内核和消息处理机制