微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > 请教各路大神!cc2640进去shutdown模式后,分别两个按键唤醒。唤醒后怎么知道是那个按键触发的?

请教各路大神!cc2640进去shutdown模式后,分别两个按键唤醒。唤醒后怎么知道是那个按键触发的?

时间:10-02 整理:3721RD 点击:

rt!

参考board_key.c 的回调函数Board_keyCallback

/*******************************************************************************
Filename: board_key.c
Revised: $Date: 2014-03-10 07:29:12 -0700 (Mon, 10 Mar 2014) $
Revision: $Revision: 37597 $

Description: This file contains the interface to the SRF06EB Key Service.

Copyright 2014 - 2015 Texas Instruments Incorporated. All rights reserved.

IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.

YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
*******************************************************************************/

/*********************************************************************
* INCLUDES
*/
#include <stdbool.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Queue.h>

#include <ti/drivers/pin/PINCC26XX.h>

#ifdef USE_ICALL
#include <ICall.h>
#endif

#include <inc/hw_ints.h>
#include "bcomdef.h"

#include "util.h"
#include "board_key.h"
#include "Board.h"

/*********************************************************************
* TYPEDEFS
*/

/*********************************************************************
* LOCAL FUNCTIONS
*/
static void Board_keyChangeHandler(UArg a0);
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId);

/*******************************************************************************
* EXTERNAL VARIABLES
*/

/*********************************************************************
* LOCAL VARIABLES
*/

// Value of keys Pressed
static uint8_t keysPressed;

// Key debounce clock
static Clock_Struct keyChangeClock;

// Pointer to application callback
keysPressedCB_t appKeyChangeHandler = NULL;

// Memory for the GPIO module to construct a Hwi
Hwi_Struct callbackHwiKeys;

// PIN configuration structure to set all KEY pins as inputs with pullups enabled
PIN_Config keyPinsCfg[] =
{
Board_KEY_SELECT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_UP | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_DOWN | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_LEFT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_RIGHT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
PIN_TERMINATE
};

PIN_State keyPins;
PIN_Handle hKeyPins;

/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn Board_initKeys
*
* @brief Enable interrupts for keys on GPIOs.
*
* @param appKeyCB - application key pressed callback
*
* @return none
*/
void Board_initKeys(keysPressedCB_t appKeyCB)
{
// Initialize KEY pins. Enable int after callback registered
hKeyPins = PIN_open(&keyPins, keyPinsCfg);
PIN_registerIntCb(hKeyPins, Board_keyCallback);

PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_SELECT | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_UP | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_DOWN | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_LEFT | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_RIGHT | PIN_IRQ_NEGEDGE);

#ifdef POWER_SAVING
//Enable wakeup
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_SELECT | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_UP | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_DOWN | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_LEFT | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_RIGHT | PINCC26XX_WAKEUP_NEGEDGE);
#endif

// Setup keycallback for keys
Util_constructClock(&keyChangeClock, Board_keyChangeHandler,
KEY_DEBOUNCE_TIMEOUT, 0, false, 0);

// Set the application callback
appKeyChangeHandler = appKeyCB;
}

/*********************************************************************
* @fn Board_keyCallback
*
* @brief Interrupt handler for Keys
*
* @param none
*
* @return none
*/
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId)
{
keysPressed = 0;

if ( PIN_getInputValue(Board_KEY_SELECT) == 0 )
{
keysPressed |= KEY_SELECT;
}

if ( PIN_getInputValue(Board_KEY_UP) == 0 )
{
keysPressed |= KEY_UP;
}

if ( PIN_getInputValue(Board_KEY_DOWN) == 0 )
{
keysPressed |= KEY_DOWN;
}

if ( PIN_getInputValue(Board_KEY_LEFT) == 0 )
{
keysPressed |= KEY_LEFT;
}

if ( PIN_getInputValue(Board_KEY_RIGHT) == 0 )
{
keysPressed |= KEY_RIGHT;
}

Util_startClock(&keyChangeClock);
}

/*********************************************************************
* @fn Board_keyChangeHandler
*
* @brief Handler for key change
*
* @param UArg a0 - ignored
*
* @return none
*/
static void Board_keyChangeHandler(UArg a0)
{
if (appKeyChangeHandler != NULL)
{
// Notify the application
(*appKeyChangeHandler)(keysPressed);
}
}
/*********************************************************************
*********************************************************************/

非常感谢

TY

参考board_key.c 的回调函数Board_keyCallback

/*******************************************************************************
Filename: board_key.c
Revised: $Date: 2014-03-10 07:29:12 -0700 (Mon, 10 Mar 2014) $
Revision: $Revision: 37597 $

Description: This file contains the interface to the SRF06EB Key Service.

Copyright 2014 - 2015 Texas Instruments Incorporated. All rights reserved.

IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.

YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
*******************************************************************************/

/*********************************************************************
* INCLUDES
*/
#include <stdbool.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Queue.h>

#include <ti/drivers/pin/PINCC26XX.h>

#ifdef USE_ICALL
#include <ICall.h>
#endif

#include <inc/hw_ints.h>
#include "bcomdef.h"

#include "util.h"
#include "board_key.h"
#include "Board.h"

/*********************************************************************
* TYPEDEFS
*/

/*********************************************************************
* LOCAL FUNCTIONS
*/
static void Board_keyChangeHandler(UArg a0);
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId);

/*******************************************************************************
* EXTERNAL VARIABLES
*/

/*********************************************************************
* LOCAL VARIABLES
*/

// Value of keys Pressed
static uint8_t keysPressed;

// Key debounce clock
static Clock_Struct keyChangeClock;

// Pointer to application callback
keysPressedCB_t appKeyChangeHandler = NULL;

// Memory for the GPIO module to construct a Hwi
Hwi_Struct callbackHwiKeys;

// PIN configuration structure to set all KEY pins as inputs with pullups enabled
PIN_Config keyPinsCfg[] =
{
Board_KEY_SELECT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_UP | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_DOWN | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_LEFT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_KEY_RIGHT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
PIN_TERMINATE
};

PIN_State keyPins;
PIN_Handle hKeyPins;

/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn Board_initKeys
*
* @brief Enable interrupts for keys on GPIOs.
*
* @param appKeyCB - application key pressed callback
*
* @return none
*/
void Board_initKeys(keysPressedCB_t appKeyCB)
{
// Initialize KEY pins. Enable int after callback registered
hKeyPins = PIN_open(&keyPins, keyPinsCfg);
PIN_registerIntCb(hKeyPins, Board_keyCallback);

PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_SELECT | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_UP | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_DOWN | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_LEFT | PIN_IRQ_NEGEDGE);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_KEY_RIGHT | PIN_IRQ_NEGEDGE);

#ifdef POWER_SAVING
//Enable wakeup
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_SELECT | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_UP | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_DOWN | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_LEFT | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_KEY_RIGHT | PINCC26XX_WAKEUP_NEGEDGE);
#endif

// Setup keycallback for keys
Util_constructClock(&keyChangeClock, Board_keyChangeHandler,
KEY_DEBOUNCE_TIMEOUT, 0, false, 0);

// Set the application callback
appKeyChangeHandler = appKeyCB;
}

/*********************************************************************
* @fn Board_keyCallback
*
* @brief Interrupt handler for Keys
*
* @param none
*
* @return none
*/
static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId)
{
keysPressed = 0;

if ( PIN_getInputValue(Board_KEY_SELECT) == 0 )
{
keysPressed |= KEY_SELECT;
}

if ( PIN_getInputValue(Board_KEY_UP) == 0 )
{
keysPressed |= KEY_UP;
}

if ( PIN_getInputValue(Board_KEY_DOWN) == 0 )
{
keysPressed |= KEY_DOWN;
}

if ( PIN_getInputValue(Board_KEY_LEFT) == 0 )
{
keysPressed |= KEY_LEFT;
}

if ( PIN_getInputValue(Board_KEY_RIGHT) == 0 )
{
keysPressed |= KEY_RIGHT;
}

Util_startClock(&keyChangeClock);
}

/*********************************************************************
* @fn Board_keyChangeHandler
*
* @brief Handler for key change
*
* @param UArg a0 - ignored
*
* @return none
*/
static void Board_keyChangeHandler(UArg a0)
{
if (appKeyChangeHandler != NULL)
{
// Notify the application
(*appKeyChangeHandler)(keysPressed);
}
}
/*********************************************************************
*********************************************************************/

在SimpleBLEPeripheral按照上面的代码修改了程序,发现在rtos中进入shutdown模式按键唤醒后,没有回调

static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId)函数,参考了BloodPressure的demo修改,还是没有回调!我猜应该是不是进入shutdown模式之后命令已经不执行了!最后参考了CC26xx/CC13xx Power Management Software Developer's Reference Guide第15页

When wakingup froma shutdown,the device reboots.The inputand output state is retained through shutdownto avoid glitches.Software usingthe shutdown-power mode calls SysCtrlResetSourceGet()early in the application to check the wake-up source.If the device wakes up from a shutdown,the application restores the configuration of the input and output registers before opening to latches to avoid glitches.Write AON_SYSCTL:SLEEPCTL[0]to 1 to unlatchthe inputsand outputs.

在SimpleBLEPeripheral_init(void)调用下面代码即可判断

/* Get the reason for reset */

uint32_t rSrc = SysCtrlResetSourceGet();
isWakeupPin = 0;
/* Do pin init before starting BIOS */
/* If coming from shutdown, use special gpio table.*/
if(rSrc == RSTSRC_WAKEUP_FROM_SHUTDOWN)

if ( PIN_getInputValue(IOID_12) == 0 )
{
isWakeupPin = 1;
}
if ( PIN_getInputValue(IOID_14) == 0 )
{
isWakeupPin = 2;
}
}

有帮助请确认结贴

新手,不会怎么结贴!可以给个步骤不?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top