hpm_butn_drv.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_BUTN_DRV_H
  8. #define HPM_BUTN_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_butn_regs.h"
  11. /**
  12. *
  13. * @brief BUTN driver APIs
  14. * @defgroup butn_interface BUTN driver APIs
  15. * @ingroup io_interfaces
  16. * @{
  17. *
  18. */
  19. #define BUTN_EVENT_POWER_PRESSED (BUTN_BTN_STATUS_PBTN_SET(1))
  20. #define BUTN_EVENT_POWER_PRESSED_HOLD_0_5_S (BUTN_BTN_STATUS_PBTN_SET(2))
  21. #define BUTN_EVENT_POWER_PRESSED_HOLD_8_S (BUTN_BTN_STATUS_PBTN_SET(4))
  22. #define BUTN_EVENT_POWER_PRESSED_HOLD_16_S (BUTN_BTN_STATUS_PBTN_SET(8))
  23. #define BUTN_EVENT_WAKE_PRESSED (BUTN_BTN_STATUS_WBTN_SET(1))
  24. #define BUTN_EVENT_WAKE_PRESSED_HOLD_0_5_S (BUTN_BTN_STATUS_WBTN_SET(2))
  25. #define BUTN_EVENT_WAKE_PRESSED_HOLD_8_S (BUTN_BTN_STATUS_WBTN_SET(4))
  26. #define BUTN_EVENT_WAKE_PRESSED_HOLD_16_S (BUTN_BTN_STATUS_WBTN_SET(8))
  27. #define BUTN_EVENT_WAKE_POWER_PRESSED (BUTN_BTN_STATUS_DBTN_SET(1))
  28. #define BUTN_EVENT_WAKE_POWER_PRESSED_HOLD_0_5_S (BUTN_BTN_STATUS_DBTN_SET(2))
  29. #define BUTN_EVENT_WAKE_POWER_PRESSED_HOLD_8_S (BUTN_BTN_STATUS_DBTN_SET(4))
  30. #define BUTN_EVENT_WAKE_POWER_PRESSED_HOLD_16_S (BUTN_BTN_STATUS_DBTN_SET(8))
  31. #define BUTN_EVENT_POWER_CLICKED (BUTN_BTN_STATUS_PCLICK_SET(1))
  32. #define BUTN_EVENT_POWER_CLICKED_X2 (BUTN_BTN_STATUS_PCLICK_SET(2))
  33. #define BUTN_EVENT_POWER_CLICKED_X3 (BUTN_BTN_STATUS_PCLICK_SET(4))
  34. #define BUTN_EVENT_POWER_CLICKED_WAKE_HELD (BUTN_BTN_STATUS_XPCLICK_SET(1))
  35. #define BUTN_EVENT_POWER_CLICKED_X2_WAKE_HELD (BUTN_BTN_STATUS_XPCLICK_SET(2))
  36. #define BUTN_EVENT_POWER_CLICKED_X3_WAKE_HELD (BUTN_BTN_STATUS_XPCLICK_SET(4))
  37. #define BUTN_EVENT_WAKE_CLICKED (BUTN_BTN_STATUS_WCLICK_SET(1))
  38. #define BUTN_EVENT_WAKE_CLICKED_X2 (BUTN_BTN_STATUS_WCLICK_SET(2))
  39. #define BUTN_EVENT_WAKE_CLICKED_X3 (BUTN_BTN_STATUS_WCLICK_SET(4))
  40. #define BUTN_EVENT_WAKE_CLICKED_POWER_HELD (BUTN_BTN_STATUS_XWCLICK_SET(1))
  41. #define BUTN_EVENT_WAKE_CLICKED_X2_POWER_HELD (BUTN_BTN_STATUS_XWCLICK_SET(2))
  42. #define BUTN_EVENT_WAKE_CLICKED_X3_POWER_HELD (BUTN_BTN_STATUS_XWCLICK_SET(4))
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @brief Get status
  48. *
  49. * @param[in] ptr BUTN base address
  50. * @retval status mask in 32 bits, please refer to BUTN_EVENT_* macros
  51. */
  52. static inline uint32_t butn_get_status(BUTN_Type *ptr)
  53. {
  54. return ptr->BTN_STATUS;
  55. }
  56. /**
  57. * @brief Enable interrupt with mask
  58. *
  59. * @param[in] ptr BUTN base address
  60. * @param[in] mask Mask of interrupts to be enabled, please refer to BUTN_EVENT_* macros
  61. */
  62. static inline void butn_enable_irq(BUTN_Type *ptr, uint32_t mask)
  63. {
  64. ptr->BTN_IRQ_MASK |= mask;
  65. }
  66. /**
  67. * @brief Disable interrupt with mask
  68. *
  69. * @param[in] ptr BUTN base address
  70. * @param[in] mask Mask of interrupts to be disabled, please refer to BUTN_EVENT_* macros
  71. */
  72. static inline void butn_disable_irq(BUTN_Type *ptr, uint32_t mask)
  73. {
  74. ptr->BTN_IRQ_MASK &= ~mask;
  75. }
  76. /**
  77. * @brief Set intense of PLED and RLED/WLED
  78. *
  79. * @param[in] ptr BUTN base address
  80. * @param[in] intense Intense value (0~15)
  81. */
  82. static inline void butn_set_intense(BUTN_Type *ptr, uint8_t intense)
  83. {
  84. ptr->LED_INTENSE = BUTN_LED_INTENSE_PLED_SET(intense)
  85. | BUTN_LED_INTENSE_RLED_SET(intense);
  86. }
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. /**
  91. * @}
  92. */
  93. #endif /* HPM_BUTN_DRV_H */