led_manager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright (c) 2018 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file led manager interface
  8. */
  9. #ifndef __LED_MANGER_H__
  10. #define __LED_MANGER_H__
  11. #include <drivers/pwm.h>
  12. /**
  13. * @defgroup led_manager_apis App Led Manager APIs
  14. * @ingroup system_apis
  15. * @{
  16. */
  17. /**
  18. * @cond INTERNAL_HIDDEN
  19. */
  20. #define DISPLAY_FOREVER 0xFFFF
  21. /**
  22. * INTERNAL_HIDDEN @endcond
  23. */
  24. /** led status */
  25. enum
  26. {
  27. /** led status on */
  28. LED_ON = 1,
  29. /** led status of */
  30. LED_OFF,
  31. /** led status blink */
  32. LED_BLINK,
  33. /** led status breath*/
  34. LED_BREATH,
  35. /** led status do nothing */
  36. LED_NONE,
  37. };
  38. enum {
  39. /**start state off */
  40. LED_START_STATE_OFF = 0,
  41. /**start state on */
  42. LED_START_STATE_ON,
  43. };
  44. typedef void (*led_display_callback)(void);
  45. typedef int (*led_timeout_callback)(void);
  46. /**
  47. * @brief led manager init funcion
  48. *
  49. * This routine calls init led manager ,called by main
  50. *
  51. * @return 0 if invoked succsess.
  52. * @return others if invoked failed.
  53. */
  54. int led_manager_init(void);
  55. /**
  56. * @brief led manager deinit funcion
  57. *
  58. * This routine calls deinit led manager ,called by main
  59. *
  60. * @return 0 if invoked succsess.
  61. * @return others if invoked failed.
  62. */
  63. int led_manager_deinit(void);
  64. /**
  65. * @brief set led index display state
  66. *
  67. * This routine set led index display state , on or off
  68. *
  69. * @param led_index index of led
  70. * @param onoff onoff state of led
  71. * @param timeout timeout of current state
  72. * @param cb callback when timeout occur.
  73. *
  74. * @return 0 if invoked succsess.
  75. * @return others if invoked failed.
  76. */
  77. int led_manager_set_display(uint16_t led_index, uint8_t onoff, uint32_t timeout, led_display_callback cb);
  78. /**
  79. * @brief set led breath mode
  80. *
  81. * @param led_index index of led
  82. * @param breath param
  83. * @param timeout timeout of current state
  84. * @param cb callback when timeout occur.
  85. *
  86. * @return 0 if invoked succsess.
  87. * @return others if invoked failed.
  88. */
  89. int led_manager_set_breath(uint16_t led_index, pwm_breath_ctrl_t *ctrl, uint32_t timeout, led_display_callback cb);
  90. /**
  91. * @brief set led blink mode
  92. *
  93. * @param led_index index of led
  94. * @param blink_period period of blink
  95. * @param blink_pulse pulse of blink
  96. * @param timeout timeout of current state
  97. * @param start_state set high or low voltage level active
  98. * @param cb callback when blink cnt overflow occur.
  99. *
  100. * @return 0 if invoked succsess.
  101. * @return others if invoked failed.
  102. */
  103. int led_manager_set_blink(uint8_t led_index, uint16_t blink_period, uint16_t blink_pulse, uint32_t timeout, uint8_t start_state, led_display_callback cb);
  104. /**
  105. * @brief set all led on or off mode
  106. *
  107. * @param onoff state of all led
  108. *
  109. * @return 0 if invoked succsess.
  110. * @return others if invoked failed.
  111. */
  112. int led_manager_set_all(uint8_t onoff);
  113. /**
  114. * @brief set led mamager to sleep mode, when sleep mode all led will off
  115. *
  116. * @return 0 if invoked succsess.
  117. * @return others if invoked failed.
  118. */
  119. int led_manager_sleep(void);
  120. /**
  121. * @brief set led mamager to wakeup mode, when sleep mode all led will restore history state before sleep
  122. *
  123. * @return 0 if invoked succsess.
  124. * @return others if invoked failed.
  125. */
  126. int led_manager_wake_up(void);
  127. /**
  128. * @brief save current led state
  129. *
  130. * @return 0 if invoked succsess.
  131. * @return others if invoked failed.
  132. */
  133. int led_manager_store(void);
  134. /**
  135. * @brief restore led state from history
  136. *
  137. * @return 0 if invoked succsess.
  138. * @return others if invoked failed.
  139. */
  140. int led_manager_restore(void);
  141. /**
  142. * @brief set timeout event lock
  143. *
  144. * @return 0 if invoked succsess.
  145. * @return others if invoked failed.
  146. */
  147. int led_manager_set_timeout_event_start(void);
  148. /**
  149. * @brief set timeout event
  150. * @param timeout of current state
  151. * @param cb callback when timeout overflow occur.
  152. * @return 0 if invoked succsess.
  153. * @return others if invoked failed.
  154. */
  155. int led_manager_set_timeout_event(int timeout, led_timeout_callback cb);
  156. /**
  157. * @} end defgroup led_manager_apis
  158. */
  159. #endif