1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2018-08-07 Tanek first implementation 9 */ 10 11 #include <rtthread.h> 12 #include <rtdevice.h> 13 #include <stm32F4xx.h> 14 #include "board.h" 15 #include "drv_gpio.h" 16 17 #define USER_WAKEUP_PIN GET_PIN(C, 5) 18 #define DRV_WKUP_PIN_IRQ_MODE PIN_IRQ_MODE_FALLING 19 20 static void (*_wakeup_hook)(void); 21 bsp_register_wakeup(void (* hook)(void))22void bsp_register_wakeup(void (*hook)(void)) 23 { 24 RT_ASSERT(hook != RT_NULL); 25 26 _wakeup_hook = hook; 27 } 28 _wakeup_callback(void * args)29static void _wakeup_callback(void *args) 30 { 31 extern void pm_wk_up(); 32 pm_wk_up(); /* wakeup from deep sleep */ 33 if (_wakeup_hook) 34 _wakeup_hook(); 35 } 36 rt_hw_wakeup_init(void)37static int rt_hw_wakeup_init(void) 38 { 39 rt_pin_mode(USER_WAKEUP_PIN, PIN_MODE_INPUT_PULLUP); 40 rt_pin_attach_irq(USER_WAKEUP_PIN, DRV_WKUP_PIN_IRQ_MODE, _wakeup_callback, RT_NULL); 41 rt_pin_irq_enable(USER_WAKEUP_PIN, 1); 42 return 0; 43 } 44 INIT_BOARD_EXPORT(rt_hw_wakeup_init); 45