nrf21540.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**
  2. * Copyright (c) 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF21540_H_
  41. #define NRF21540_H_
  42. #include <stdbool.h>
  43. #include <stdint.h>
  44. #include "nrf21540_spi.h"
  45. #include "nrf21540_gpio.h"
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /** @file
  50. * @brief nRF21540 front-end Bluetooth range extender.
  51. *
  52. *
  53. * @defgroup nrf21540 nRF21540 front-end Bluetooth range extender.
  54. * @{
  55. * @ingroup ext_drivers
  56. * @brief nRF21540 front-end Bluetooth range extender.
  57. */
  58. #if NRF21540_USE_SPI_MANAGEMENT
  59. #if NRF21540_USE_GPIO_MANAGEMENT
  60. #error Only one management manner can be active
  61. #endif
  62. #elif !NRF21540_USE_GPIO_MANAGEMENT
  63. #error At least one management manner must be active
  64. #endif // NRF21540_USE_SPI_MANAGEMENT
  65. /**@brief Initialization of modules needed by nRF21540:
  66. * - SPI
  67. * - GPIO
  68. * - GPIOTE
  69. * - PPI
  70. * - RADIO
  71. * - NVIC
  72. *
  73. * @return NRF based error code.
  74. * NRF_ERROR_INTERNAL when driver is in error state,
  75. * or SPI initialization has failed. Reinitialization is required.
  76. * NRF_ERROR_INVALID_STATE when nRF21540's state isn't proper
  77. * to perform the operation (@sa nrf21540_state_t).
  78. * NRF_SUCCESS on success.
  79. */
  80. ret_code_t nrf21540_init(void);
  81. /**@brief Set nRF21540 to TX mode.
  82. *
  83. * @note Dependently on configuration GPIO or SPI interface will be used.
  84. *
  85. * @param[in] user_trigger_event event that triggers start of procedure - this event
  86. * will be connected to appropriate PPI channel.
  87. * @ref NRF21540_EXECUTE_NOW value causes start procedure
  88. * immediately.
  89. * @param[in] mode @ref NRF21540_EXEC_MODE_BLOCKING - function will wait for
  90. * finishing configuration including settling times required
  91. * by nRF21540 (waits till all procedure has finished).
  92. * @ref NRF21540_EXEC_MODE_NON_BLOCKING - function will start
  93. * procedure and set busy flag. User code can be executed
  94. * at this time and busy flag will be unset when done.
  95. * @return NRF based error code.
  96. * NRF_ERROR_INTERNAL when driver is in error state.
  97. * Reinitialization is required.
  98. * NRF_ERROR_INVALID_STATE when nRF21540's state isn't proper
  99. * to perform the operation (@sa nrf21540_state_t).
  100. * NRF_SUCCESS on success.
  101. */
  102. ret_code_t nrf21540_tx_set(uint32_t user_trigger_event, nrf21540_execution_mode_t mode);
  103. /**@brief Set nRF21540 to TX mode.
  104. *
  105. * @note Dependently on configuration GPIO or SPI interface will be used
  106. * (NRF21540_USE_SPI_MANAGEMENT/NRF21540_USE_GPIO_MANAGEMENT).
  107. *
  108. * @param[in] user_trigger_event event that triggers start of procedure - this event
  109. * will be connected to appropriate PPI channel.
  110. * @ref NRF21540_EXECUTE_NOW value causes start procedure
  111. * immediately.
  112. * @param[in] mode @ref NRF21540_EXEC_MODE_BLOCKING - function will wait for
  113. * finishing configuration including settling times required
  114. * by nRF21540 (waits till all procedure has finished).
  115. * @ref NRF21540_EXEC_MODE_NON_BLOCKING - function will start
  116. * procedure and set busy flag. User code can be executed
  117. * at this time and busy flag will be unset when done.
  118. * @return NRF based error code.
  119. * NRF_ERROR_INTERNAL when driver is in error state.
  120. * Reinitialization is required.
  121. * NRF_ERROR_INVALID_STATE when nRF21540's state isn't proper
  122. * to perform the operation (@sa nrf21540_state_t).
  123. * NRF_SUCCESS on success.
  124. */
  125. ret_code_t nrf21540_rx_set(uint32_t user_trigger_event, nrf21540_execution_mode_t mode);
  126. /**@brief Function choses one of two physical antenna outputs.
  127. *
  128. * @param[in] antenna One of antenna outputs. See @ref nrf21540_antenna_t.
  129. * @return NRF based error code.
  130. * NRF_ERROR_BUSY when driver performs another operation at
  131. * the moment.
  132. * NRF_SUCCESS on success.
  133. */
  134. ret_code_t nrf21540_ant_set(nrf21540_antenna_t antenna);
  135. /**@brief Function choses one of two predefined power modes in nRF21540.
  136. *
  137. * @details Refer to nRF21540 Objective Product Specification, section: TX power control.
  138. *
  139. * @param[in] mode Power mode. See @ref nrf21540_pwr_mode_t.
  140. * @return NRF based error code.
  141. * NRF_ERROR_BUSY when driver performs another operation at
  142. * the moment.
  143. * NRF_SUCCESS on success.
  144. */
  145. ret_code_t nrf21540_pwr_mode_set(nrf21540_pwr_mode_t mode);
  146. /**@brief nRF21540 power down.
  147. *
  148. * @details Disables chip functionality and enter power save mode.
  149. *
  150. * @note Dependently on configuration GPIO or SPI interface will be used.
  151. *
  152. * @param[in] user_trigger_event event that triggers start of procedure - this event
  153. * will be connected to appropriate PPI channel.
  154. * @ref NRF21540_EXECUTE_NOW value causes start procedure
  155. * immediately.
  156. * @param[in] mode @ref NRF21540_EXEC_MODE_BLOCKING - function will wait for
  157. * finishing configuration including settling times required
  158. * by nRF21540 (waits till all procedure has finished).
  159. * @ref NRF21540_EXEC_MODE_NON_BLOCKING - function will start
  160. * procedure and set busy flag. User code can be executed
  161. * at this time and busy flag will be unset when done.
  162. * @return NRF_ERROR_INTERNAL when driver is in error state.
  163. * Reinitialization is required then.
  164. * NRF_ERROR_INVALID_STATE when nRF21540's state isn't proper
  165. * to perform the operation (@sa nrf21540_state_t).
  166. * NRF_ERROR_BUSY when driver performs another operation at
  167. * the moment.
  168. * NRF_SUCCESS on success.
  169. */
  170. ret_code_t nrf21540_power_down(uint32_t user_trigger_event, nrf21540_execution_mode_t mode);
  171. /**@brief Checks if nRF21540 driver is in error state.
  172. *
  173. * @return true if driver is in error state and should be reinitialized.
  174. */
  175. bool nrf21540_is_error(void);
  176. /** @} */
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. #endif // NRF21540_H_