hal_adc.dox 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @defgroup ADC ADC Driver
  15. * @brief Generic ADC Driver.
  16. * @details This module implements a generic ADC (Analog to Digital Converter)
  17. * driver supporting a variety of buffer and conversion modes.
  18. * @pre In order to use the ADC driver the @p HAL_USE_ADC option
  19. * must be enabled in @p halconf.h.
  20. *
  21. * @section adc_1 Driver State Machine
  22. * The driver implements a state machine internally, not all the driver
  23. * functionalities can be used in any moment, any transition not explicitly
  24. * shown in the following diagram has to be considered an error and shall
  25. * be captured by an assertion (if enabled).
  26. * @if LATEX_PDF
  27. * @dot
  28. digraph example {
  29. rankdir="LR";
  30. size="5, 7";
  31. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  32. edge [fontname=Helvetica, fontsize=8];
  33. stop [label="ADC_STOP\nLow Power"];
  34. uninit [label="ADC_UNINIT", style="bold"];
  35. ready [label="ADC_READY\nClock Enabled"];
  36. active [label="ADC_ACTIVE\nConverting"];
  37. error [label="ADC_ERROR\nError"];
  38. complete [label="ADC_COMPLETE\nComplete"];
  39. uninit -> stop [label="\n adcInit()", constraint=false];
  40. stop -> ready [label="\nadcStart()"];
  41. ready -> ready [label="\nadcStart()\nadcStopConversion()"];
  42. ready -> stop [label="\nadcStop()"];
  43. stop -> stop [label="\nadcStop()"];
  44. ready -> active [label="\nadcStartConversion() (async)\nadcConvert() (sync)"];
  45. active -> ready [label="\nadcStopConversion()\nsync return"];
  46. active -> active [label="\nasync callback (half buffer, circular)\nasync callback (full buffer)\n>acg_endcb<"];
  47. active -> complete [label="\n\nasync callback (full buffer)\n>end_cb<"];
  48. active -> error [label="\n\nasync callback (error)\n>error_cb<"];
  49. complete -> active [label="\nadcStartConversionI()\nthen\ncallback return"];
  50. complete -> ready [label="\ncallback return"];
  51. error -> active [label="\nadcStartConversionI()\nthen\ncallback return"];
  52. error -> ready [label="\ncallback return"];
  53. }
  54. * @enddot
  55. * @else
  56. * @dot
  57. digraph example {
  58. rankdir="LR";
  59. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  60. edge [fontname=Helvetica, fontsize=8];
  61. stop [label="ADC_STOP\nLow Power"];
  62. uninit [label="ADC_UNINIT", style="bold"];
  63. ready [label="ADC_READY\nClock Enabled"];
  64. active [label="ADC_ACTIVE\nConverting"];
  65. error [label="ADC_ERROR\nError"];
  66. complete [label="ADC_COMPLETE\nComplete"];
  67. uninit -> stop [label="\n adcInit()", constraint=false];
  68. stop -> ready [label="\nadcStart()"];
  69. ready -> ready [label="\nadcStart()\nadcStopConversion()"];
  70. ready -> stop [label="\nadcStop()"];
  71. stop -> stop [label="\nadcStop()"];
  72. ready -> active [label="\nadcStartConversion() (async)\nadcConvert() (sync)"];
  73. active -> ready [label="\nadcStopConversion()\nsync return"];
  74. active -> active [label="\nasync callback (half buffer, circular)\nasync callback (full buffer)\n>acg_endcb<"];
  75. active -> complete [label="\n\nasync callback (full buffer)\n>end_cb<"];
  76. active -> error [label="\n\nasync callback (error)\n>error_cb<"];
  77. complete -> active [label="\nadcStartConversionI()\nthen\ncallback return"];
  78. complete -> ready [label="\ncallback return"];
  79. error -> active [label="\nadcStartConversionI()\nthen\ncallback return"];
  80. error -> ready [label="\ncallback return"];
  81. }
  82. * @enddot
  83. * @endif
  84. *
  85. * @section adc_2 ADC Operations
  86. * The ADC driver is quite complex, an explanation of the terminology and of
  87. * the operational details follows.
  88. *
  89. * @subsection adc_2_1 ADC Conversion Groups
  90. * The @p ADCConversionGroup is the objects that specifies a physical
  91. * conversion operation. This structure contains some standard fields and
  92. * several implementation-dependent fields.<br>
  93. * The standard fields define the CG mode, the number of channels belonging
  94. * to the CG and the optional callbacks.<br>
  95. * The implementation-dependent fields specify the physical ADC operation
  96. * mode, the analog channels belonging to the group and any other
  97. * implementation-specific setting. Usually the extra fields just mirror
  98. * the physical ADC registers, please refer to the vendor's MCU Reference
  99. * Manual for details about the available settings. Details are also available
  100. * into the documentation of the ADC low level drivers and in the various
  101. * sample applications.
  102. *
  103. * @subsection adc_2_2 ADC Conversion Modes
  104. * The driver supports several conversion modes:
  105. * - <b>One Shot</b>, the driver performs a single group conversion then stops.
  106. * - <b>Linear Buffer</b>, the driver performs a series of group conversions
  107. * then stops. This mode is like a one shot conversion repeated N times,
  108. * the buffer pointer increases after each conversion. The buffer is
  109. * organized as an S(CG)*N samples matrix, when S(CG) is the conversion
  110. * group size (number of channels) and N is the buffer depth (number of
  111. * repeated conversions).
  112. * - <b>Circular Buffer</b>, much like the linear mode but the operation does
  113. * not stop when the buffer is filled, it is automatically restarted
  114. * with the buffer pointer wrapping back to the buffer base.
  115. * .
  116. * @subsection adc_2_3 ADC Callbacks
  117. * The driver is able to invoke callbacks during the conversion process. A
  118. * callback is invoked when the operation has been completed or, in circular
  119. * mode, when the buffer has been filled and the operation is restarted. In
  120. * circular mode a callback is also invoked when the buffer is half filled.<br>
  121. * The "half filled" and "filled" callbacks in circular mode allow to
  122. * implement "streaming processing" of the sampled data, while the driver is
  123. * busy filling one half of the buffer the application can process the
  124. * other half, this allows for continuous interleaved operations.
  125. *
  126. * The driver is not thread safe for performance reasons, if you need to access
  127. * the ADC bus from multiple threads then use the @p adcAcquireBus() and
  128. * @p adcReleaseBus() APIs in order to gain exclusive access.
  129. *
  130. * @ingroup HAL_NORMAL_DRIVERS
  131. */