I want add a new key on port p1_6
cc2530EB, zstack2.3.0
#define HAL_KEY_SW_7_PORT P1
#define HAL_KEY_SW_7_BIT BV(6)
#define HAL_KEY_SW_7_SEL P1SEL
#define HAL_KEY_SW_7_DIR P1DIR
#define HAL_KEY_SW_7_EDGEBIT BV(2)
#define HAL_KEY_SW_7_EDGE HAL_KEY_FALLING_EDGE
#define HAL_KEY_SW_7_IEN IEN2 /* CPU interrupt mask register */
#define HAL_KEY_SW_7_IENBIT BV(4) /* Mask bit for all of Port_1 */
#define HAL_KEY_SW_7_ICTL P1IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_7_ICTLBIT BV(6) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_7_PXIFG P1IFG /* Interrupt flag at source */
actually , I copied the #defines from HAL_KEY_SW_6
but something changed
like #define HAL_KEY_SW_7_EDGEBIT BV(2) and #define HAL_KEY_SW_7_IENBIT BV(4)
I dont know why HAL_KEY_SW_7_IENBIT is BV(4) and HAL_KEY_SW_6_IENBIT is BV(5)
actually , I could not change these two defines, If I changed, the sw1 key (p0_1) and p1_6 wont work
anybody know why?
Now
in void HalKeyInit( void )
I also add
HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT); /* Set pin function to GPIO */
HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT); /* Set pin direction to Input */
in HalKeyConfig
PICTL &= ~(HAL_KEY_SW_7_EDGEBIT); /* Clear the edge bit */
/* For falling edge, the bit must be set. */
#if (HAL_KEY_SW_7_EDGE == HAL_KEY_FALLING_EDGE)
PICTL |= HAL_KEY_SW_7_EDGEBIT;
#endif
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);
in HalKeyRead
//if (HAL_PUSH_BUTTON1())
if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
keys |= HAL_KEY_SW_6;
}
if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
{
keys |= HAL_KEY_SW_7;
}
as you can see, I change HAL_KEY_SW_6 , from HAL_PUSH_BUTTON1 to !.....
in HalKeyPoll
//if (HAL_PUSH_BUTTON1())
if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
keys |= HAL_KEY_SW_6;
}
if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
// if( (!(P1_6)))
{
keys |= HAL_KEY_SW_7;
}
nearly, I copied the process way as HAL_KEY_SW_6
in void halProcessKeyInterrupt (void)
if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) /* Interrupt Flag has been set */
{
HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); /* Clear Interrupt Flag */
valid = TRUE;
}
then add a interrupt
HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
{
if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
{
halProcessKeyInterrupt();
}
/*
Clear the CPU interrupt flag for Port_0
PxIFG has to be cleared before PxIF
*/
HAL_KEY_SW_7_PXIFG = 0;
HAL_KEY_CPU_PORT_1_IF = 0;
}