由TI 标准例程\simplelink_cc2640r2_sdk_2_20_00_49\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral修改而来。
删除了CC2640R2_LAUNCHXL,增加了CC2640R2DK_4XS,Display_DISABLE_ALL。按键驱动程序改为如下:
#define Board_BTN1 CC2640R2DK_4XS_KEY_UP
#define Board_BTN2 CC2640R2DK_4XS_KEY_DOWN
/*********************************************************************
* 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_BTN1 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP,
Board_BTN2 | 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_BTN1 | PIN_IRQ_BOTHEDGES);
PIN_setConfig(hKeyPins, PIN_BM_IRQ, Board_BTN2 | PIN_IRQ_BOTHEDGES);
#ifdef POWER_SAVING
//Enable wakeup
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN1 | PINCC26XX_WAKEUP_NEGEDGE);
PIN_setConfig(hKeyPins, PINCC26XX_BM_WAKEUP, Board_BTN2 | PINCC26XX_WAKEUP_NEGEDGE);
#endif //POWER_SAVING
// 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_BTN1) == 0 )
{
keysPressed |= KEY_UP;
}
if ( PIN_getInputValue(Board_BTN2) == 0 )
{
keysPressed |= KEY_DOWN;
}
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);
}
}
/*********************************************************************
*********************************************************************/
应用层调用函数如下:
/*********************************************************************
* @fn SimpleBLEPeripheral_handleKeys
*
* @brief Handles all key events for this device.
*
* @param keys – bit field for key events. Valid entries:
* KEY_LEFT
* KEY_RIGHT
*
* @return none
*/
static void SimpleBLEPeripheral_handleKeys(uint8_t keys)
{
uint8_t initialAdvertEnable;
if (keys & KEY_UP)
{
if (PIN_getInputValue(Board_PIN_BUTTON0) == 0)
{
initialAdvertEnable = TRUE;
// Set the Peripheral GAPRole Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&initialAdvertEnable);
}
}
else if (keys & KEY_DOWN)
{
if (PIN_getInputValue(Board_PIN_BUTTON1) == 0)
{
initialAdvertEnable = FALSE;
// Set the Peripheral GAPRole Parameters
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
&initialAdvertEnable);
}
}
}
问题如下;
刚烧录完这两个按键可以正常启动和关闭蓝牙。
按下复位键之后,两个按键就不能正常工作了。不能唤醒。
请问下这是怎么回事呢?谢谢!
Susan Yang:
请发帖至 无线连接 板块,谢谢
,
user6328081:
好,谢谢!