gd32f4xx_iref.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*!
  2. \file gd32f4xx_iref.c
  3. \brief IREF driver
  4. \version 2016-08-15, V1.0.0, firmware for GD32F4xx
  5. \version 2018-12-12, V2.0.0, firmware for GD32F4xx
  6. \version 2020-09-30, V2.1.0, firmware for GD32F4xx
  7. */
  8. /*
  9. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. 1. Redistributions of source code must retain the above copyright notice, this
  13. list of conditions and the following disclaimer.
  14. 2. Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. 3. Neither the name of the copyright holder nor the names of its contributors
  18. may be used to endorse or promote products derived from this software without
  19. specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. OF SUCH DAMAGE.
  30. */
  31. #include "gd32f4xx_iref.h"
  32. /*!
  33. \brief deinit IREF
  34. \param[in] none
  35. \param[out] none
  36. \retval none
  37. */
  38. void iref_deinit(void)
  39. {
  40. rcu_periph_reset_enable(RCU_IREFRST);
  41. rcu_periph_reset_disable(RCU_IREFRST);
  42. }
  43. /*!
  44. \brief enable IREF
  45. \param[in] none
  46. \param[out] none
  47. \retval none
  48. */
  49. void iref_enable(void)
  50. {
  51. IREF_CTL |= IREF_CTL_CREN;
  52. }
  53. /*!
  54. \brief disable IREF
  55. \param[in] none
  56. \param[out] none
  57. \retval none
  58. */
  59. void iref_disable(void)
  60. {
  61. IREF_CTL &= ~IREF_CTL_CREN;
  62. }
  63. /*!
  64. \brief set IREF mode
  65. \param[in] step
  66. \arg IREF_MODE_LOW_POWER: 1uA step
  67. \arg IREF_MODE_HIGH_CURRENT: 8uA step
  68. \param[out] none
  69. \retval none
  70. */
  71. void iref_mode_set(uint32_t step)
  72. {
  73. IREF_CTL &= ~IREF_CTL_SSEL;
  74. IREF_CTL |= step;
  75. }
  76. /*!
  77. \brief set IREF precision_trim_value
  78. \param[in] precisiontrim
  79. \arg IREF_CUR_PRECISION_TRIM_X(x=0..31): (-15+ x)%
  80. \param[out] none
  81. \retval none
  82. */
  83. void iref_precision_trim_value_set(uint32_t precisiontrim)
  84. {
  85. IREF_CTL &= ~IREF_CTL_CPT;
  86. IREF_CTL |= precisiontrim;
  87. }
  88. /*!
  89. \brief set IREF sink mode
  90. \param[in] sinkmode
  91. \arg IREF_SOURCE_CURRENT : source current.
  92. \arg IREF_SINK_CURRENT: sink current
  93. \param[out] none
  94. \retval none
  95. */
  96. void iref_sink_set(uint32_t sinkmode)
  97. {
  98. IREF_CTL &= ~IREF_CTL_SCMOD;
  99. IREF_CTL |= sinkmode;
  100. }
  101. /*!
  102. \brief set IREF step data
  103. \param[in] stepdata
  104. \arg IREF_CUR_STEP_DATA_X:(x=0..63): step*x
  105. \param[out] none
  106. \retval none
  107. */
  108. void iref_step_data_config(uint32_t stepdata)
  109. {
  110. IREF_CTL &= ~IREF_CTL_CSDT;
  111. IREF_CTL |= stepdata;
  112. }