lib_comp.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. ******************************************************************************
  3. * @file lib_comp.h
  4. * @author Application Team
  5. * @version V4.4.0
  6. * @date 2018-09-27
  7. * @brief COMP library.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. ******************************************************************************
  12. */
  13. #ifndef __LIB_COMP_H
  14. #define __LIB_COMP_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "target.h"
  19. /* Macros --------------------------------------------------------------------*/
  20. /***** COMP_DEBConfig *****/
  21. //COMPx
  22. #define COMP_1 (0x00U)
  23. #define COMP_2 (0x02U)
  24. #define IS_COMP(__COMP__) (((__COMP__) == COMP_1) || ((__COMP__) == COMP_2))
  25. //Debounce
  26. #define COMP_DEB_0 ANA_CTRL_CMP1DEB_0
  27. #define COMP_DEB_1 ANA_CTRL_CMP1DEB_1
  28. #define COMP_DEB_2 ANA_CTRL_CMP1DEB_2
  29. #define COMP_DEB_3 ANA_CTRL_CMP1DEB_3
  30. #define IS_COMP_DEB(__DEB__) (((__DEB__) == COMP_DEB_0) ||\
  31. ((__DEB__) == COMP_DEB_1) ||\
  32. ((__DEB__) == COMP_DEB_2) ||\
  33. ((__DEB__) == COMP_DEB_3))
  34. /***** Mode (COMP_ModeConfig) *****/
  35. #define COMP_MODE_OFF ANA_CTRL_COMP1_SEL_0
  36. #define COMP_MODE_RISING ANA_CTRL_COMP1_SEL_1
  37. #define COMP_MODE_FALLING ANA_CTRL_COMP1_SEL_2
  38. #define COMP_MODE_BOTH ANA_CTRL_COMP1_SEL_3
  39. #define IS_COMP_MODE(__MODE__) (((__MODE__) == COMP_MODE_OFF) ||\
  40. ((__MODE__) == COMP_MODE_RISING) ||\
  41. ((__MODE__) == COMP_MODE_FALLING) ||\
  42. ((__MODE__) == COMP_MODE_BOTH))
  43. /***** SourceSelect (COMP_ConfigSignalSource) *****/
  44. #define COMP_SIGNALSRC_P_TO_REF ANA_REG2_CMP1_SEL_0
  45. #define COMP_SIGNALSRC_N_TO_REF ANA_REG2_CMP1_SEL_1
  46. #define COMP_SIGNALSRC_P_TO_N ANA_REG2_CMP1_SEL_2
  47. #define IS_COMP_SIGNALSRC(__SIGNALSRC__) (((__SIGNALSRC__) == COMP_SIGNALSRC_P_TO_REF) ||\
  48. ((__SIGNALSRC__) == COMP_SIGNALSRC_N_TO_REF) ||\
  49. ((__SIGNALSRC__) == COMP_SIGNALSRC_P_TO_N))
  50. /***** REFSelect (COMP_ConfigREF) *****/
  51. #define COMP_REF_VREF (0)
  52. #define COMP_REF_BGPREF ANA_REG2_REFSEL_CMP1
  53. #define IS_COMP_REF(__REF__) (((__REF__) == COMP_REF_VREF) ||\
  54. ((__REF__) == COMP_REF_BGPREF))
  55. /***** BiasSel (COMP_BiasConfig) *****/
  56. #define COMP_BIAS_20nA ANA_REG5_IT_CMP1_0
  57. #define COMP_BIAS_100nA ANA_REG5_IT_CMP1_1
  58. #define COMP_BIAS_500nA ANA_REG5_IT_CMP1_2
  59. #define IS_COMP_BIAS(__BIAS__) (((__BIAS__) == COMP_BIAS_20nA) ||\
  60. ((__BIAS__) == COMP_BIAS_100nA)||\
  61. ((__BIAS__) == COMP_BIAS_500nA))
  62. /* Exported Functions ------------------------------------------------------- */
  63. void COMP_DEBConfig(uint32_t COMPx, uint32_t Debounce);
  64. void COMP_ModeConfig(uint32_t COMPx, uint32_t Mode);
  65. void COMP_SignalSourceConfig(uint32_t COMPx, uint32_t SourceSelect);
  66. void COMP_REFConfig(uint32_t COMPx, uint32_t REFSelect);
  67. void COMP_BiasConfig(uint32_t COMPx, uint32_t BiasSel);
  68. void COMP_INTConfig(uint32_t COMPx, uint32_t NewState);
  69. uint8_t COMP_GetINTStatus(uint32_t COMPx);
  70. void COMP_ClearINTStatus(uint32_t COMPx);
  71. void COMP_Output_Cmd(uint32_t COMPx, uint32_t NewState);
  72. void COMP_Cmd(uint32_t COMPx, uint32_t NewState);
  73. uint32_t COMP_GetCNTValue(uint32_t COMPx);
  74. void COMP_ClearCNTValue(uint32_t COMPx);
  75. uint8_t COMP1_GetOutputLevel(void);
  76. uint8_t COMP2_GetOutputLevel(void);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* __LIB_COMP_H */
  81. /*********************************** END OF FILE ******************************/