void accel_gpio_init(void) { //gpio_pull_set(ACCEL_INT_PIN, GPIO_PULL_DOWN); gpio_set_direction_field(ACCEL_INT_PIN, GPIO_INPUT); gpio_set_interrupt(ACCEL_INT_PIN, GPIO_INT_RISING_EDGE); gpio_enable_interrupt(ACCEL_INT_PIN); //Accelerometer interrupt //wakeup_by_gpio(ACCEL_INT_PIN, GPIO_WKUP_BY_HIGH); // does gpio_wakeup_config automatically gpio_wakeup_config(ACCEL_INT_PIN, GPIO_WKUP_BY_HIGH); //sets direction to input automatically }
/** **************************************************************************************** * @brief Set GPIO wakeup * @param[in] pin wakeup pin: P0 and P1 * @param[in] type Wakeup type: high, low, change * @description * This function is used to set MCU wakeup by gpio pin. ***************************************************************************************** */ void wakeup_by_gpio(enum gpio_pin pin, enum gpio_wakeup_type type) { if (sleep_env.wakeup_by_sleeptimer == 0) { // Disable sleep timer wakeup syscon_SetPGCR2WithMask(QN_SYSCON, SYSCON_MASK_OSC_WAKEUP_EN, MASK_DISABLE); } // configure gpio wakeup pin gpio_wakeup_config(pin, type); gpio_enable_interrupt(pin); // Ensure gpio interrupt is not pending before the test NVIC_ClearPendingIRQ(GPIO_IRQn); // Enable Interrupts NVIC_EnableIRQ(GPIO_IRQn); }
/* **************************************************************************************** * @brief com_gpio_init * @param[in] None * @response None * @return None * @description Init GPIO and Init the event and it's callback function *****************************************************************************************/ void com_gpio_init(void) { //set wakeup config,when GPIO low and trigger interrupt gpio_wakeup_config(COM_AT_ENABLE,GPIO_WKUP_BY_LOW); gpio_enable_interrupt(COM_AT_ENABLE); if(KE_EVENT_OK != ke_evt_callback_set(EVENT_AT_ENABLE_PRESS_ID, app_event_at_enable_press_handler)) { ASSERT_ERR(0); } if(KE_EVENT_OK != ke_evt_callback_set(EVENT_AT_COMMAND_PROC_ID, app_com_at_command_handler)) { ASSERT_ERR(0); } }