stm8l15x_irtim.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_irtim.c
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file provides firmware functions to configure the IRTIM peripheral.
  8. *
  9. * @verbatim
  10. *
  11. * ===================================================================
  12. * How to use this driver
  13. * ===================================================================
  14. * This driver provides functions to:
  15. * 1. Enable the IRTIM peripheral
  16. * 2. Enable the high sink mode on the IRTIM pin
  17. *
  18. * @endverbatim
  19. *
  20. ******************************************************************************
  21. * @attention
  22. *
  23. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  24. *
  25. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  26. * You may not use this file except in compliance with the License.
  27. * You may obtain a copy of the License at:
  28. *
  29. * http://www.st.com/software_license_agreement_liberty_v2
  30. *
  31. * Unless required by applicable law or agreed to in writing, software
  32. * distributed under the License is distributed on an "AS IS" BASIS,
  33. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. * See the License for the specific language governing permissions and
  35. * limitations under the License.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "stm8l15x_irtim.h"
  41. /** @addtogroup STM8L15x_StdPeriph_Driver
  42. * @{
  43. */
  44. /** @defgroup IRTIM
  45. * @brief IRTIM driver modules
  46. * @{
  47. */
  48. /* Private typedef -----------------------------------------------------------*/
  49. /* Private define ------------------------------------------------------------*/
  50. /* Private macro -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private function prototypes -----------------------------------------------*/
  53. /** @defgroup IRTIM_Private_Functions
  54. * @{
  55. */
  56. /** @defgroup IRTIM_Group1 IRTIM configuration functions
  57. * @brief IRTIM configuration functions
  58. *
  59. @verbatim
  60. ===============================================================================
  61. IRTIM configuration functions
  62. ===============================================================================
  63. ===================================================================
  64. IRTIM Driver: how to use it
  65. ===================================================================
  66. To generate the infrared remote control signal, perform the following steps:
  67. 1. Use TIM2 channel 1 to generate the high frequency carrier signal
  68. by calling TIM2_OC1Init()
  69. 2. Use TIM3 channel 1 to generate the modulation envelope by
  70. calling TIM3_OC1Init()
  71. 3. Enable the IRTIM peripheral using IRTIM_Cmd()
  72. Note1: When IRTIM peripheral is enabled, TIM2 channel 1 and TIM3 channel 1
  73. become inactive (no signal on output) and can be used as GPIO.
  74. Note2: The high sink LED driver capability (only available on the IRTIM pin)
  75. can be activated using IRTIM_HighSinkODCmd() to sink the high
  76. current needed to directly control an infrared LED
  77. @endverbatim
  78. * @{
  79. */
  80. /**
  81. * @brief Deinitializes the IRTIM peripheral registers to their default reset values.
  82. * @param None
  83. * @retval None
  84. */
  85. void IRTIM_DeInit(void)
  86. {
  87. IRTIM->CR = IRTIM_CR_RESET_VALUE;
  88. }
  89. /**
  90. * @brief Enables or disables the IRTIM peripheral.
  91. * @param NewState : The new state of the IRTIM peripheral.
  92. * This parameter can be: ENABLE or DISABLE.
  93. * @retval None
  94. */
  95. void IRTIM_Cmd(FunctionalState NewState)
  96. {
  97. /* Check the parameters */
  98. assert_param(IS_FUNCTIONAL_STATE(NewState));
  99. /* set or Reset the EN Bit */
  100. if (NewState == DISABLE)
  101. {
  102. IRTIM->CR &= (uint8_t)(~IRTIM_CR_EN) ;
  103. }
  104. else
  105. {
  106. IRTIM->CR |= IRTIM_CR_EN ;
  107. }
  108. }
  109. /**
  110. * @brief Enables or disables the High sink open drain buffer of the IRTIM peripheral.
  111. * @param NewState : The new state of the High sink open drain buffer.
  112. * This parameter can be: ENABLE or DISABLE.
  113. * @retval None
  114. */
  115. void IRTIM_HighSinkODCmd(FunctionalState NewState)
  116. {
  117. /* Check the parameters */
  118. assert_param(IS_FUNCTIONAL_STATE(NewState));
  119. /* set or Reset the EN Bit */
  120. if (NewState == DISABLE)
  121. {
  122. IRTIM->CR &= (uint8_t)(~IRTIM_CR_HSEN) ;
  123. }
  124. else
  125. {
  126. IRTIM->CR |= IRTIM_CR_HSEN ;
  127. }
  128. }
  129. /**
  130. * @}
  131. */
  132. /** @defgroup IRTIM_Group2 IRITM status management functions
  133. * @brief IRITM status management functions
  134. *
  135. @verbatim
  136. ===============================================================================
  137. IRITM status management functions
  138. ===============================================================================
  139. @endverbatim
  140. * @{
  141. */
  142. /**
  143. * @brief Checks whether the IRTIM device is enabled or not.
  144. * @param None
  145. * @retval state of the IRTIM device.
  146. */
  147. FunctionalState IRTIM_GetStatus(void)
  148. {
  149. return ((FunctionalState) (IRTIM->CR & IRTIM_CR_EN));
  150. }
  151. /**
  152. * @brief Checks whether the IRTIM High Sink Open Drain buffer is Enabled or not.
  153. * @param None
  154. * @retval state of High Sink Open Drain buffer.
  155. */
  156. FunctionalState IRTIM_GetHighSinkODStatus(void)
  157. {
  158. return ((FunctionalState)(IRTIM->CR & IRTIM_CR_HSEN));
  159. }
  160. /**
  161. * @}
  162. */
  163. /**
  164. * @}
  165. */
  166. /**
  167. * @}
  168. */
  169. /**
  170. * @}
  171. */
  172. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/