led_softblink.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /** @file
  13. *
  14. * @defgroup led_softblink LED softblink
  15. * @{
  16. * @ingroup app_common
  17. *
  18. * @brief Module for generating a changing pulse-width modulated output signal that is used to smoothly blink LEDs.
  19. *
  20. * @details This module provides an LED softblink implementation using timers and GPIO.
  21. *
  22. * LED softblink needs one timer. It can use any number of output channels that are available.
  23. *
  24. * Only one instance of LED softblink can run at a time.
  25. */
  26. #ifndef LED_SOFTBLINK_H__
  27. #define LED_SOFTBLINK_H__
  28. #include <stdbool.h>
  29. #include <stdint.h>
  30. #include "sdk_errors.h"
  31. /**
  32. * @brief Structure holding the initialization parameters.
  33. */
  34. typedef struct
  35. {
  36. bool active_high; /**< Activate negative polarity. */
  37. uint8_t duty_cycle_max; /**< Maximum impulse width. */
  38. uint8_t duty_cycle_min; /**< Minimum impulse width. */
  39. uint8_t duty_cycle_step; /**< Cycle step. */
  40. uint32_t off_time_ticks; /**< Ticks to stay in low impulse state. */
  41. uint32_t on_time_ticks; /**< Ticks to stay in high impulse state. */
  42. uint32_t leds_pin_bm; /**< Mask of used LEDs. */
  43. }led_sb_init_params_t;
  44. /**
  45. * @name Default settings
  46. * @brief Default settings for LED softblink.
  47. * @{
  48. */
  49. #define LED_SB_INIT_PARAMS_ACTIVE_HIGH false
  50. #define LED_SB_INIT_PARAMS_DUTY_CYCLE_MAX 220
  51. #define LED_SB_INIT_PARAMS_DUTY_CYCLE_MIN 0
  52. #define LED_SB_INIT_PARAMS_DUTY_CYCLE_STEP 5
  53. #define LED_SB_INIT_PARAMS_OFF_TIME_TICKS 65536
  54. #define LED_SB_INIT_PARAMS_ON_TIME_TICKS 0
  55. #define LED_SB_INIT_PARAMS_LEDS_PIN_BM(mask) (mask)
  56. /** @} */
  57. /**
  58. * @brief LED softblink default configuration.
  59. */
  60. #define LED_SB_INIT_DEFAULT_PARAMS(mask) \
  61. { \
  62. .active_high = LED_SB_INIT_PARAMS_ACTIVE_HIGH, \
  63. .duty_cycle_max = LED_SB_INIT_PARAMS_DUTY_CYCLE_MAX, \
  64. .duty_cycle_min = LED_SB_INIT_PARAMS_DUTY_CYCLE_MIN, \
  65. .duty_cycle_step = LED_SB_INIT_PARAMS_DUTY_CYCLE_STEP, \
  66. .off_time_ticks = LED_SB_INIT_PARAMS_OFF_TIME_TICKS, \
  67. .on_time_ticks = LED_SB_INIT_PARAMS_ON_TIME_TICKS, \
  68. .leds_pin_bm = LED_SB_INIT_PARAMS_LEDS_PIN_BM(mask) \
  69. }
  70. /**
  71. * @brief Function for initializing LED softblink.
  72. *
  73. * @param[in] p_init_params Pointer to the initialization structure.
  74. *
  75. * @return Values returned by @ref app_timer_create.
  76. */
  77. ret_code_t led_softblink_init(led_sb_init_params_t * p_init_params);
  78. /**
  79. * @brief Function for starting to blink LEDs.
  80. *
  81. * @param[in] leds_pin_bit_mask Bit mask containing the pins for the LEDs to be blinked.
  82. *
  83. * @return Values returned by @ref app_timer_start.
  84. */
  85. ret_code_t led_softblink_start(uint32_t leds_pin_bit_mask);
  86. /**
  87. * @brief Function for stopping to blink LEDs.
  88. *
  89. * @return Values returned by @ref app_timer_stop.
  90. */
  91. ret_code_t led_softblink_stop(void);
  92. /**
  93. * @brief Function for setting the off time.
  94. *
  95. * This function configures the time that the LEDs will be off between each blink.
  96. *
  97. * @param[in] off_time_ticks Off time in ticks.
  98. *
  99. */
  100. void led_softblink_off_time_set(uint32_t off_time_ticks);
  101. /**
  102. * @brief Function for setting the on time.
  103. *
  104. * This function configures the time that the LEDs will be on between each blink.
  105. *
  106. * @param[in] on_time_ticks On time in ticks.
  107. *
  108. */
  109. void led_softblink_on_time_set(uint32_t on_time_ticks);
  110. /**
  111. * @brief Function for uninitializing LED softblink.
  112. *
  113. * @retval NRF_SUCCESS If LED softblink was uninitialized successfully.
  114. */
  115. ret_code_t led_softblink_uninit(void);
  116. #endif // LED_SOFTBLINK_H__
  117. /** @} */