我现在通过按键可以从CC2541板子往蓝牙模块发数据了,但是老板要求按下按键灯亮,松开按键灯灭。
if ( keys & HAL_KEY_SW_1 ) //UP 开始键
{
attWriteReq_t req;
BLE_DEV *p = &(gDev[simpleBLEScanIdx]);
req.handle = GUA_CHAR1_Hdl; //simpleBLECharHdl;
req.len = 3;
req.value[0] = 0x31;
req.value[1] = 0x0D;
req.value[2] = 0x0A;
req.sig = 0;
req.cmd = 0;
//simpleBLEConnHandle=0x0000;
p->simpleBLEConnHandle=0x0000;
simpleBLETaskId=0x0B;
status = GATT_WriteCharValue( p->simpleBLEConnHandle, &req, simpleBLETaskId );
HAL_TURN_OFF_LED1();
}
HAL_TURN_OFF_LED1();这个是灯亮,和官方板子接的方向不一致。
这个按键处理
// 按键处理
static void simpleBLECentral_HandleKeys( uint8 shift, uint16 keys )
在这个函数里面。
按键使用下降沿中断搞的。
现在按下键可以灯亮。
至于松开灯灭,我想这样实现。
再搞一个上升沿检测,检测到上升沿让灯灭。
还得搞一个函数,在函数里判断。
总觉得SDK里的很复杂,不知道具体怎么操作,谢谢!
ccb bcc:
我写一下操作步骤:
先定义宏定义
#define HAL_KEY_SW_1_EDGE1HAL_KEY_RISING_EDGE//上升沿
ccb bcc:
回复 ccb bcc:
定义这个函数:
/************************************************************************************************** * @fn HalKeyConfig * * @brief Configure the Key serivce * * @param interruptEnable – TRUE/FALSE, enable/disable interrupt * cback – pointer to the CallBack function * * @return None **************************************************************************************************/void HalKeyConfig1 (bool interruptEnable, halKeyCBack_t cback){ /* Enable/Disable Interrupt or */ Hal_KeyIntEnable = interruptEnable;
/* Register the callback fucntion */ pHalKeyProcessFunction = cback;
/* Determine if interrupt is enable or not */ if (Hal_KeyIntEnable) {
/* Rising/Falling edge configuratinn */ PICTL &= ~(HAL_KEY_SW_6_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_7_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_8_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_9_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_10_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_1_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_2_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_3_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_4_EDGEBIT); /* Clear the edge bit */ PICTL &= ~(HAL_KEY_SW_5_EDGEBIT); /* Clear the edge bit */ /* For rising edge, the bit must be set. */ #if (HAL_KEY_SW_6_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_6_EDGEBIT); #endif #if (HAL_KEY_SW_7_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_7_EDGEBIT); #endif #if (HAL_KEY_SW_8_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_8_EDGEBIT); #endif #if (HAL_KEY_SW_9_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_9_EDGEBIT); #endif #if (HAL_KEY_SW_10_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_10_EDGEBIT); #endif #if (HAL_KEY_SW_5_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_5_EDGEBIT); #endif #if (HAL_KEY_SW_1_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_1_EDGEBIT); #endif #if (HAL_KEY_SW_2_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_2_EDGEBIT); #endif #if (HAL_KEY_SW_3_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_3_EDGEBIT); #endif #if (HAL_KEY_SW_4_EDGE == HAL_KEY_RISING_EDGE) PICTL &=~( HAL_KEY_SW_4_EDGEBIT); #endif /* Interrupt configuration: * – Enable interrupt generation at the port * – Enable CPU interrupt * – Clear any pending interrupt */ HAL_KEY_SW_6_ICTL |= HAL_KEY_SW_6_ICTLBIT; HAL_KEY_SW_6_IEN |= HAL_KEY_SW_6_IENBIT; HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT); HAL_KEY_SW_7_ICTL |= HAL_KEY_SW_7_ICTLBIT; HAL_KEY_SW_7_IEN |= HAL_KEY_SW_7_IENBIT; HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); HAL_KEY_SW_8_ICTL |= HAL_KEY_SW_8_ICTLBIT; HAL_KEY_SW_8_IEN |= HAL_KEY_SW_8_IENBIT; HAL_KEY_SW_8_PXIFG = ~(HAL_KEY_SW_8_BIT); HAL_KEY_SW_9_ICTL |= HAL_KEY_SW_9_ICTLBIT; HAL_KEY_SW_9_IEN |= HAL_KEY_SW_9_IENBIT; HAL_KEY_SW_9_PXIFG = ~(HAL_KEY_SW_9_BIT); HAL_KEY_SW_10_ICTL |= HAL_KEY_SW_10_ICTLBIT; HAL_KEY_SW_10_IEN |= HAL_KEY_SW_10_IENBIT; HAL_KEY_SW_10_PXIFG = ~(HAL_KEY_SW_10_BIT); HAL_KEY_SW_5_ICTL |= HAL_KEY_SW_5_ICTLBIT; HAL_KEY_SW_5_IEN |= HAL_KEY_SW_5_IENBIT; HAL_KEY_SW_5_PXIFG = ~(HAL_KEY_SW_5_BIT); HAL_KEY_SW_1_ICTL |= HAL_KEY_SW_1_ICTLBIT; HAL_KEY_SW_1_IEN |= HAL_KEY_SW_1_IENBIT; HAL_KEY_SW_1_PXIFG = ~(HAL_KEY_SW_1_BIT); HAL_KEY_SW_2_ICTL |= HAL_KEY_SW_2_ICTLBIT; HAL_KEY_SW_2_IEN |= HAL_KEY_SW_2_IENBIT; HAL_KEY_SW_2_PXIFG = ~(HAL_KEY_SW_2_BIT); HAL_KEY_SW_3_ICTL |= HAL_KEY_SW_3_ICTLBIT; HAL_KEY_SW_3_IEN |= HAL_KEY_SW_3_IENBIT; HAL_KEY_SW_3_PXIFG = ~(HAL_KEY_SW_3_BIT); HAL_KEY_SW_4_ICTL |= HAL_KEY_SW_4_ICTLBIT; HAL_KEY_SW_4_IEN |= HAL_KEY_SW_4_IENBIT; HAL_KEY_SW_4_PXIFG = ~(HAL_KEY_SW_4_BIT); /* Rising/Falling edge configuratinn */
/* Interrupt configuration: * – Enable interrupt generation at the port * – Enable CPU interrupt * – Clear any pending interrupt */
/* Do this only after the hal_key is configured – to work with sleep stuff */ if (HalKeyConfigured == TRUE) { osal_stop_timerEx(Hal_TaskID, HAL_KEY_EVENT); /* Cancel polling if active */ } } else /* Interrupts NOT enabled */ {
HAL_KEY_SW_6_ICTL &= ~(HAL_KEY_SW_6_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_6_IEN &= ~(HAL_KEY_SW_6_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_7_ICTL &= ~(HAL_KEY_SW_7_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_7_IEN &= ~(HAL_KEY_SW_7_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_8_ICTL &= ~(HAL_KEY_SW_8_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_8_IEN &= ~(HAL_KEY_SW_8_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_9_ICTL &= ~(HAL_KEY_SW_9_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_9_IEN &= ~(HAL_KEY_SW_9_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_10_ICTL &= ~(HAL_KEY_SW_10_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_10_IEN &= ~(HAL_KEY_SW_10_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_5_ICTL &= ~(HAL_KEY_SW_5_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_5_IEN &= ~(HAL_KEY_SW_5_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_1_ICTL &= ~(HAL_KEY_SW_1_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_1_IEN &= ~(HAL_KEY_SW_1_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_2_ICTL &= ~(HAL_KEY_SW_2_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_2_IEN &= ~(HAL_KEY_SW_2_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_3_ICTL &= ~(HAL_KEY_SW_3_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_3_IEN &= ~(HAL_KEY_SW_3_IENBIT); /* Clear interrupt enable bit */ HAL_KEY_SW_4_ICTL &= ~(HAL_KEY_SW_4_ICTLBIT); /* don't generate interrupt */ HAL_KEY_SW_4_IEN &= ~(HAL_KEY_SW_4_IENBIT); /* Clear interrupt enable bit */ osal_set_event(Hal_TaskID, HAL_KEY_EVENT); }
/* Key now is configured */ HalKeyConfigured = TRUE;}
YiKai Chen:
回复 ccb bcc:
那你應該是去改HAL_TURN_OFF_LED1跟HAL_TURN_ON_LED1吧
ccb bcc:
回复 YiKai Chen:
不是啊。我现在按下可以灯亮了。
SDK里没有检测上升沿,所以没法灯灭。
ccb bcc:
回复 ccb bcc:
调用定义的那个函数:
if ( keys & HAL_KEY_SW_1 ) //UP 开始键 { attWriteReq_t req; BLE_DEV *p = &(gDev[simpleBLEScanIdx]); req.handle = GUA_CHAR1_Hdl; //simpleBLECharHdl; req.len = 3; req.value[0] = 0x31; req.value[1] = 0x0D; req.value[2] = 0x0A; req.sig = 0; req.cmd = 0; //simpleBLEConnHandle=0x0000; p->simpleBLEConnHandle=0x0000; simpleBLETaskId=0x0B; status = GATT_WriteCharValue( p->simpleBLEConnHandle, &req, simpleBLETaskId ); HAL_TURN_OFF_LED1(); HalKeyConfig1( HAL_KEY_INTERRUPT_ENABLE, OnBoard_KeyCallback); //灯亮马上重新配置上升沿中断 }
ccb bcc:
回复 ccb bcc:
uint16 HalKeyRead ( void )
void HalKeyPoll (void)
这个两个函数我不打算改了,感觉不用改。
那么在哪个中断函数里判断上升沿或者下降沿呢?谢谢
void halProcessKeyInterrupt (void)
HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )
HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
ccb bcc:
回复 YiKai Chen:
谢谢!我弄好了。开始侦测下降沿,判断按键按下;
侦测到下降沿马上配置侦测上升沿,判断按键抬起。
如此循环。