hal_comp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file hal_comp.h
  3. /// @author AE TEAM
  4. /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE COMP
  5. /// FIRMWARE LIBRARY.
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /// @attention
  8. ///
  9. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  10. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  11. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  12. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  13. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  14. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  15. ///
  16. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Define to prevent recursive inclusion
  19. #ifndef __HAL_COMP_H
  20. #define __HAL_COMP_H
  21. // Files includes
  22. #include "reg_common.h"
  23. #include "reg_comp.h"
  24. ////////////////////////////////////////////////////////////////////////////////
  25. /// @addtogroup MM32_Hardware_Abstract_Layer
  26. /// @{
  27. ////////////////////////////////////////////////////////////////////////////////
  28. /// @defgroup COMP_HAL
  29. /// @brief COMP HAL modules
  30. /// @{
  31. ////////////////////////////////////////////////////////////////////////////////
  32. /// @defgroup COMP_Exported_Types
  33. /// @{
  34. ////////////////////////////////////////////////////////////////////////////////
  35. /// @brief COMP_InvertingInput
  36. ////////////////////////////////////////////////////////////////////////////////
  37. typedef enum {
  38. COMP_InvertingInput_IO0 = COMP_CSR_INM_0, ///< INM0 as COMP inverting input
  39. COMP_InvertingInput_IO1 = COMP_CSR_INM_1, ///< INM1 as COMP inverting input
  40. COMP_InvertingInput_IO2 = COMP_CSR_INM_2, ///< INM2 as COMP inverting input
  41. COMP_InvertingInput_CRV = COMP_CSR_INM_3, ///< INM3 as COMP inverting input
  42. COMP_InvertingInput_IO3 = COMP_CSR_INM_3, ///< INM3 as COMP inverting input
  43. } EM_COMP_InvertingInput;
  44. ////////////////////////////////////////////////////////////////////////////////
  45. /// @brief COMP_NonInvertingInput
  46. ////////////////////////////////////////////////////////////////////////////////
  47. typedef enum {
  48. COMP_NonInvertingInput_IO0 = COMP_CSR_INP_INP0, ///< INP0 as COMP non-inverting input
  49. COMP_NonInvertingInput_IO1 = COMP_CSR_INP_INP1, ///< INP1 as COMP non-inverting input
  50. COMP_NonInvertingInput_IO2 = COMP_CSR_INP_INP2, ///< INP2 as COMP non-inverting input
  51. COMP_NonInvertingInput_IO3 = COMP_CSR_INP_INP3, ///< INP3 as COMP non-inverting input
  52. } EM_COMP_NonInvertingInput;
  53. ////////////////////////////////////////////////////////////////////////////////
  54. /// @brief COMP_Output
  55. ////////////////////////////////////////////////////////////////////////////////
  56. typedef enum {
  57. COMP_Output_None = 0x00000000, ///< No output
  58. COMP_Output_TIM1BKIN = COMP_CSR_OUT_TIM1_BRAKE, ///< Timer1 brake input
  59. COMP_Output_TIM1OCREFCLR = COMP_CSR_OUT_TIM1_OCREFCLR, ///< Timer1 ocrefclear input
  60. COMP_Output_TIM1IC1 = COMP_CSR_OUT_TIM1_CAPTURE1, ///< Timer1 input capture 1
  61. COMP_Output_TIM2IC4 = COMP_CSR_OUT_TIM2_CAPTURE4, ///< Timer2 input capture 4
  62. COMP_Output_TIM2OCREFCLR = COMP_CSR_OUT_TIM2_OCREFCLR, ///< Timer2 ocrefclear input
  63. COMP_Output_TIM3IC1 = COMP_CSR_OUT_TIM3_CAPTURE1, ///< Timer3 input capture 1
  64. COMP_Output_TIM3OCREFCLR = COMP_CSR_OUT_TIM3_OCREFCLR ///< Timer3 ocrefclear input
  65. } EM_COMP_Output;
  66. ////////////////////////////////////////////////////////////////////////////////
  67. /// @brief COMP_OutputPoloarity
  68. ////////////////////////////////////////////////////////////////////////////////
  69. typedef enum {
  70. COMP_NonInverted = 0x00000000, ///< COMP non-inverting output
  71. COMP_OutputPol_NonInverted = 0x00000000,
  72. COMP_Inverted = 0x00008000, ///< COMP inverting output
  73. COMP_OutputPol_Inverted = 0x00008000
  74. } EM_COMP_OutputPol;
  75. ////////////////////////////////////////////////////////////////////////////////
  76. /// @brief COMP_Hysteresis
  77. ////////////////////////////////////////////////////////////////////////////////
  78. typedef enum {
  79. COMP_Hysteresis_No = COMP_CSR_HYST_0, ///< Hysteresis Voltage: 0mV
  80. COMP_Hysteresis_Low = COMP_CSR_HYST_15, ///< Hysteresis Voltage: 15mV
  81. COMP_Hysteresis_Medium = COMP_CSR_HYST_30, ///< Hysteresis Voltage: 30mV
  82. COMP_Hysteresis_High = COMP_CSR_HYST_90 ///< Hysteresis Voltage: 90mV
  83. } EM_COMP_Hysteresis;
  84. typedef enum {
  85. COMP_Filter_0_Period = COMP_CSR_OFLT_0, ///< filter is ((u32)0x00000000)
  86. COMP_Filter_2_Period = COMP_CSR_OFLT_1, ///< filter is ((u32)0x00040000)
  87. COMP_Filter_4_Period = COMP_CSR_OFLT_2, ///< filter is ((u32)0x00080000)
  88. COMP_Filter_8_Period = COMP_CSR_OFLT_3, ///< filter is ((u32)0x000C0000)
  89. COMP_Filter_16_Period = COMP_CSR_OFLT_4, ///< filter is ((u32)0x00100000)
  90. COMP_Filter_32_Period = COMP_CSR_OFLT_5, ///< filter is ((u32)0x00140000)
  91. COMP_Filter_64_Period = COMP_CSR_OFLT_6, ///< filter is ((u32)0x00180000)
  92. COMP_Filter_128_Period = COMP_CSR_OFLT_7, ///< filter is ((u32)0x001C0000)
  93. } EM_COMP_FILT;
  94. ////////////////////////////////////////////////////////////////////////////////
  95. /// @brief COMP_Mode
  96. ////////////////////////////////////////////////////////////////////////////////
  97. typedef enum {
  98. COMP_Mode_HighSpeed = COMP_CSR_MODE_HIGHRATE, ///< Comparator high rate mode
  99. COMP_Mode_MediumSpeed = COMP_CSR_MODE_MEDIUMRATE, ///< Comparator medium rate mode
  100. COMP_Mode_LowPower = COMP_CSR_MODE_LOWPOWER, ///< Comparator low power mode
  101. COMP_Mode_UltraLowPower = COMP_CSR_MODE_LOWESTPOWER ///< Comparator lowest power mode
  102. } EM_COMP_Mode;
  103. ////////////////////////////////////////////////////////////////////////////////
  104. /// @brief COMP_OutputLevel
  105. ////////////////////////////////////////////////////////////////////////////////
  106. typedef enum {
  107. COMP_OutputLevel_High = COMP_CSR_OUT, ///< High output
  108. COMP_OutputLevel_Low = 0x00000000 ///< Low output
  109. } EM_COMP_OutputLevel;
  110. ////////////////////////////////////////////////////////////////////////////////
  111. /// @brief COMP Init structure definition
  112. ////////////////////////////////////////////////////////////////////////////////
  113. typedef struct {
  114. union {
  115. u32 COMP_InvertingInput;
  116. u32 Invert; ///< Selects the inverting input of the comparator.
  117. };
  118. union {
  119. u32 COMP_NonInvertingInput;
  120. u32 NonInvert; ///< Selects the non inverting input of the comparator.
  121. };
  122. union {
  123. u32 COMP_Output;
  124. u32 Output; ///< Selects the output redirection of the comparator.
  125. u32 BlankingSrce; ///< Selects the output blanking source of the comparator.
  126. };
  127. union {
  128. u32 COMP_OutputPol;
  129. u32 OutputPol; ///< Selects the output polarity of the comparator.
  130. };
  131. union {
  132. u32 COMP_Hysteresis;
  133. u32 Hysteresis; ///< Selects the hysteresis voltage of the comparator.
  134. };
  135. union {
  136. u32 COMP_Mode;
  137. u32 Mode; ///< Selects the operating mode of the comparator and allows
  138. };
  139. union {
  140. u32 COMP_Filter;
  141. u32 OFLT; ///< to adjust the speed/consumption.
  142. };
  143. } COMP_InitTypeDef;
  144. typedef struct {
  145. FunctionalState COMP_Poll_En; ///< Selects the inverting input of the comparator.
  146. u32 COMP_Poll_Ch; ///< Selects the non inverting input of the comparator.
  147. u32 COMP_Poll_Fixn; ///< Selects the output redirection of the comparator.
  148. u32 COMP_Poll_Period; ///< Selects the output polarity of the comparator.
  149. u32 COMP_Poll_Pout; ///< Selects the hysteresis voltage of the comparator.
  150. } COMP_POLL_InitTypeDef;
  151. /// @}
  152. ////////////////////////////////////////////////////////////////////////////////
  153. /// @defgroup COMP_Exported_Constants
  154. /// @{
  155. ////////////////////////////////////////////////////////////////////////////////
  156. /// @brief COMP Init structure definition
  157. ////////////////////////////////////////////////////////////////////////////////
  158. typedef enum {
  159. COMP1 = (0x00000C), ///< Select comparator 1
  160. COMP2 = (0x000010), ///< Select comparator 2
  161. } COMP_Selection_TypeDef;
  162. #define COMP_BlankingSrce_None ((u32)0x00000000)
  163. #define COMP_CSR_CLEAR_MASK ((u32)0x00000003)
  164. #define COMP_CSR_COMPSW1 ((u32)0x00000002)
  165. /// @}
  166. ////////////////////////////////////////////////////////////////////////////////
  167. ///@defgroup COMP_Exported_Variables
  168. /// @{
  169. #ifdef _HAL_COMP_C_
  170. #define GLOBAL
  171. #else
  172. #define GLOBAL extern
  173. #endif
  174. #undef GLOBAL
  175. /// @}
  176. ////////////////////////////////////////////////////////////////////////////////
  177. /// @defgroup COMP_Exported_Functions
  178. /// @{
  179. void COMP_DeInit(COMP_Selection_TypeDef selection);
  180. void COMP_Init(COMP_Selection_TypeDef selection, COMP_InitTypeDef* init_struct);
  181. void COMP_StructInit(COMP_InitTypeDef* init_struct);
  182. void COMP_Cmd(COMP_Selection_TypeDef selection, FunctionalState state);
  183. void COMP_SwitchCmd(COMP_Selection_TypeDef selection, FunctionalState state);
  184. void COMP_LockConfig(COMP_Selection_TypeDef selection);
  185. u32 COMP_GetOutputLevel(COMP_Selection_TypeDef selection);
  186. void COMP_SetCrv(u8 crv_select, u8 crv_level);
  187. #define SET_COMP_CRV COMP_SetCrv
  188. /// @}
  189. /// @}
  190. /// @}
  191. ////////////////////////////////////////////////////////////////////////////////
  192. #endif //__HAL_COMP_H
  193. ////////////////////////////////////////////////////////////////////////////////