hal_i2c.dox 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 I2C I2C Driver
  15. * @brief Generic I2C Driver.
  16. * @details This module implements a generic I2C (Inter-Integrated Circuit)
  17. * driver.
  18. * @pre In order to use the I2C driver the @p HAL_USE_I2C option
  19. * must be enabled in @p halconf.h.
  20. *
  21. * @section i2c_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. size="5, 7";
  30. rankdir="LR";
  31. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true",
  32. width="0.9", height="0.9"];
  33. edge [fontname=Helvetica, fontsize=8];
  34. stop [label="I2C_STOP\nLow Power"];
  35. uninit [label="I2C_UNINIT", style="bold"];
  36. ready [label="I2C_READY\nClock Enabled"];
  37. active_tx [label="I2C_ACTIVE_TX\nBus TX Active"];
  38. active_rx [label="I2C_ACTIVE_RX\nBus RX Active"];
  39. locked [label="I2C_LOCKED\nBus Locked"];
  40. uninit -> stop [label="i2cInit()", constraint=false];
  41. stop -> stop [label="i2cStop()"];
  42. stop -> ready [label="i2cStart()"];
  43. ready -> ready [label="i2cStart()"];
  44. ready -> stop [label="i2cStop()"];
  45. ready -> active_tx [label="i2cMasterTransmit()"];
  46. ready -> active_rx [label="i2cMasterReceive()"];
  47. active_tx -> ready [label="completed"];
  48. active_rx -> ready [label="completed"];
  49. active_tx -> locked [label="RDY_TIMEOUT"];
  50. active_rx -> locked [label="RDY_TIMEOUT"];
  51. locked -> stop [label="i2cStop()"];
  52. locked -> ready [label="i2cStart()"];
  53. }
  54. * @else
  55. * @dot
  56. digraph example {
  57. rankdir="LR";
  58. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true",
  59. width="0.9", height="0.9"];
  60. edge [fontname=Helvetica, fontsize=8];
  61. stop [label="I2C_STOP\nLow Power"];
  62. uninit [label="I2C_UNINIT", style="bold"];
  63. ready [label="I2C_READY\nClock Enabled"];
  64. active_tx [label="I2C_ACTIVE_TX\nBus TX Active"];
  65. active_rx [label="I2C_ACTIVE_RX\nBus RX Active"];
  66. locked [label="I2C_LOCKED\nBus Locked"];
  67. uninit -> stop [label="i2cInit()", constraint=false];
  68. stop -> stop [label="i2cStop()"];
  69. stop -> ready [label="i2cStart()"];
  70. ready -> ready [label="i2cStart()"];
  71. ready -> stop [label="i2cStop()"];
  72. ready -> active_tx [label="i2cMasterTransmit()"];
  73. ready -> active_rx [label="i2cMasterReceive()"];
  74. active_tx -> ready [label="completed"];
  75. active_rx -> ready [label="completed"];
  76. active_tx -> locked [label="RDY_TIMEOUT"];
  77. active_rx -> locked [label="RDY_TIMEOUT"];
  78. locked -> stop [label="i2cStop()"];
  79. locked -> ready [label="i2cStart()"];
  80. }
  81. * @enddot
  82. * @endif
  83. * The driver is not thread safe for performance reasons, if you need to access
  84. * the I2C bus from multiple threads then use the @p i2cAcquireBus() and
  85. * @p i2cReleaseBus() APIs in order to gain exclusive access.
  86. *
  87. * @ingroup HAL_NORMAL_DRIVERS
  88. */