drv_wakeup.c 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include <stm32F4xx.h>
  13. #include "board.h"
  14. #include "drv_gpio.h"
  15. #define USER_WAKEUP_PIN GET_PIN(C, 5)
  16. #define DRV_WKUP_PIN_IRQ_MODE PIN_IRQ_MODE_FALLING
  17. static void (*_wakeup_hook)(void);
  18. void bsp_register_wakeup(void (*hook)(void))
  19. {
  20. RT_ASSERT(hook != RT_NULL);
  21. _wakeup_hook = hook;
  22. }
  23. static void _wakeup_callback(void *args)
  24. {
  25. extern void pm_wk_up();
  26. pm_wk_up(); /* wakeup from deep sleep */
  27. if (_wakeup_hook)
  28. _wakeup_hook();
  29. }
  30. static int rt_hw_wakeup_init(void)
  31. {
  32. rt_pin_mode(USER_WAKEUP_PIN, PIN_MODE_INPUT_PULLUP);
  33. rt_pin_attach_irq(USER_WAKEUP_PIN, DRV_WKUP_PIN_IRQ_MODE, _wakeup_callback, RT_NULL);
  34. rt_pin_irq_enable(USER_WAKEUP_PIN, 1);
  35. return 0;
  36. }
  37. INIT_BOARD_EXPORT(rt_hw_wakeup_init);