/* 1 - Green */
#define LED1_BV BV(1)
#define LED1_SBIT P1_1
#define LED1_DDR P1DIR
#define LED1_POLARITY ACTIVE_LOW
#if defined (HAL_BOARD_CC2530EB_REV17)
/* 2 - Red */
#define LED2_BV BV(2)
#define LED2_SBIT P1_2
#define LED2_DDR P1DIR
#define LED2_POLARITY ACTIVE_LOW
/* 3 - Yellow */
#define LED3_BV BV(3)
#define LED3_SBIT P1_3
#define LED3_DDR P1DIR
#define LED3_POLARITY ACTIVE_LOW #endif
/* S7 */
#define PUSH1_BV BV(1)
#define PUSH1_SBIT P0_7
/* S6 */
#define PUSH6_BV BV(1)
#define PUSH6_SBIT P0_6
#define HAL_PUSH_BUTTON1() (PUSH1_POLARITY (PUSH1_SBIT))
#define HAL_PUSH_BUTTON2() (PUSH2_POLARITY (PUSH2_SBIT)) #define HAL_PUSH_BUTTON3() (0)
#define HAL_PUSH_BUTTON4() (0)
#define HAL_PUSH_BUTTON5() (0)
#define HAL_PUSH_BUTTON6() (PUSH1_POLARITY (PUSH6_SBIT))
Hal_key.c
/* SW_7 is at P0.7 */
#define HAL_KEY_SW_6_PORT P0
#define HAL_KEY_SW_6_BIT BV(7)
#define HAL_KEY_SW_6_SEL P0SEL
#define HAL_KEY_SW_6_DIR P0DIR
/* SW_6 is at P0.6 */
#define HAL_KEY_SW_7_PORT P0
#define HAL_KEY_SW_7_BIT BV(6)
#define HAL_KEY_SW_7_SEL P0SEL
#define HAL_KEY_SW_7_DIR P0DIR
/* SW_6 interrupts */
#define HAL_KEY_SW_6_IEN IEN1 /* CPU interrupt mask register */ #define HAL_KEY_SW_6_IENBIT BV(5) /* Mask bit for all of Port_0 */
#define HAL_KEY_SW_6_ICTL P0IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_6_ICTLBIT BV(1) /* P0IEN - P0.1 enable/disable bit */ #define HAL_KEY_SW_6_PXIFG P0IFG /* Interrupt flag at source */
/* SW_7 interrupts */
#define HAL_KEY_SW_7_IEN IEN1 /* CPU interrupt mask register */ #define HAL_KEY_SW_7_IENBIT BV(5) /* Mask bit for all of Port_0 */
#define HAL_KEY_SW_7_ICTL P0IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_7_ICTLBIT BV(1) /* P0IEN - P0.1 enable/disable bit */ #define HAL_KEY_SW_7_PXIFG P0IFG /* Interrupt flag at source */
void HalKeyInit( void )
{
/* Initialize previous key to 0 */
halKeySavedKeys = 0;
HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT); /* Set pin function to GPIO */ HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT); /* Set pin direction to Input */
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 */
……
void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
{
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 */ ……
void HalKeyPoll (void)
{
uint8 keys = 0;
if ((HAL_KEY_JOY_MOVE_PORT & HAL_KEY_JOY_MOVE_BIT)) /* Key is active HIGH */ {
// keys = halGetJoyKeyInput();
}
if (HAL_PUSH_BUTTON1())
{
keys |= HAL_KEY_SW_7;
}
if (HAL_PUSH_BUTTON6())
{
keys |= HAL_KEY_SW_6;
}
/* If interrupts are not enabled, previous key status and current key status
* are compared to find out if a key has changed status.
*/
if (!Hal_KeyIntEnable)
{
if (keys == halKeySavedKeys)
{
/* Exit - since no keys have changed */
return;
}
/* Store the current keys for comparation next time */
halKeySavedKeys = keys;
}
else
{
/* Key interrupt handled here */
}
/* Invoke Callback if new keys were depressed */
if (keys && (pHalKeyProcessFunction))
{
(pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL); }
}