|
本帖最后由 reliXQ 于 2018-11-14 12:22 编辑
本人才疏学浅 刚接触52832 一个按键回调都调不出来 再此请教大神帮忙解答一下疑惑
程序文件片段:
/**********************************************************************************/
文件pac10040.h
引脚定义如下:
#define BUTTON_START 9
#define BUTTON_1 9
#define BUTTON_2 10
#define BUTTON_3 11
#define BUTTON_STOP 11
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
#define BUTTONS_ACTIVE_STATE 0
#define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3 }
#define BSP_BUTTON_0 BUTTON_1
#define BSP_BUTTON_1 BUTTON_2
#define BSP_BUTTON_2 BUTTON_3
main.c
按钮/LED初始化
static void buttons_leds_init(bool * p_erase_bonds)
{
bsp_event_t startup_event;
uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, bsp_event_handler);
APP_ERROR_CHECK(err_code);
err_code = bsp_btn_ble_init(NULL, &startup_event);
APP_ERROR_CHECK(err_code);
*p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
}
//Function for initializing the BLE Button Module
uint32_t bsp_btn_ble_init(bsp_btn_ble_error_handler_t error_handler, bsp_event_t * p_startup_bsp_evt)
{
uint32_t err_code = NRF_SUCCESS;
m_error_handler = error_handler;
if (p_startup_bsp_evt != NULL)
{
startup_event_extract(p_startup_bsp_evt);
}
if (m_num_connections == 0)
{
err_code = advertising_buttons_configure();
}
return err_code;
}
/**@brief Function for extracting the BSP event valid at startup.
*
* @details When a button was used to wake up the device, the button press will not generate an
* interrupt. This function reads which button was pressed at startup, and returns the
* appropriate BSP event.
* @param[out] p_startup_event Where to put the extracted BSP event.
*/
static void startup_event_extract(bsp_event_t * p_startup_event)
{
// React to button states
if (bsp_button_is_pressed(BTN_ID_WAKEUP_BOND_DELETE))
{
*p_startup_event = BSP_EVENT_CLEAR_BONDING_DATA;
}
else if (bsp_button_is_pressed(BTN_ID_WAKEUP))
{
*p_startup_event = BSP_EVENT_WAKEUP;
}
else
{
*p_startup_event = BSP_EVENT_NOTHING;
}
}
/**@brief Function for configuring the buttons for advertisement.
*
* @retval NRF_SUCCESS Configured successfully.
* @return A propagated error code.
*/
static uint32_t advertising_buttons_configure()
{
uint32_t err_code;
err_code = bsp_event_to_button_action_assign(BTN_ID_DISCONNECT, //才疏学浅 没错的话这个应该是按键回调函数
BTN_ACTION_DISCONNECT, //不知道是不是应该改这个 在没改动的情况下 main.c中bsp_event_handler 捕捉不到事件
BSP_EVENT_DEFAULT);
RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
err_code = bsp_event_to_button_action_assign(BTN_ID_WHITELIST_OFF,
BTN_ACTION_WHITELIST_OFF,
BSP_EVENT_WHITELIST_OFF);
RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
BTN_ACTION_SLEEP,
BSP_EVENT_SLEEP);
RETURN_ON_ERROR_NOT_INVALID_PARAM(err_code);
return NRF_SUCCESS;
}
/****************************************************************************/
下面是main.c中的事件处理函数
void bsp_event_handler(bsp_event_t event)
{
uint32_t err_code;
switch (event)
{
case BSP_EVENT_SLEEP:
printf("BSP_EVENT_SLEEP\r\n");
sleep_mode_enter();
break;
case BSP_EVENT_DISCONNECT:
printf("BSP_EVENT_DISCONNECT\r\n");
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
break;
case BSP_EVENT_WHITELIST_OFF:
printf("BSP_EVENT_WHITELIST_OFF\r\n");
if (m_conn_handle == BLE_CONN_HANDLE_INVALID)
{
err_code = ble_advertising_restart_without_whitelist(&m_advertising);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
}
break;
case BSP_EVENT_KEY_0:
printf("B0\r\n");
break;
case BSP_EVENT_KEY_1:
printf("B1\r\n");
break;
case BSP_EVENT_KEY_2:
printf("B2\r\n");
break;
case BSP_EVENT_KEY_3: //为了想知道按键按下到底会出现进入哪个回调函数 我把所有事件都printf打印东西
case BSP_EVENT_KEY_4:
case BSP_EVENT_KEY_5:
case BSP_EVENT_KEY_6:
case BSP_EVENT_KEY_7:
printf("B3\r\n");
break;
case BSP_EVENT_NOTHING: //测试 看会进入哪个回调
case BSP_EVENT_DEFAULT:
case BSP_EVENT_CLEAR_BONDING_DATA:
case BSP_EVENT_CLEAR_ALERT:
case BSP_EVENT_ADVERTISING_START:
case BSP_EVENT_ADVERTISING_STOP:
case BSP_EVENT_BOND:
case BSP_EVENT_RESET:
case BSP_EVENT_WAKEUP:
case BSP_EVENT_SYSOFF:
case BSP_EVENT_DFU:
printf("1\r\n");
break;
default:
break;
}
}
/****************************************************************************/
遗憾的是 我按下按键后 并没有触发任何回调函数. 没有任何printf打印
再次求教大神 是哪里的问题?
|
|