hal_i2c_lld.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. * @file hal_i2c_lld.c
  15. * @brief PLATFORM I2C subsystem low level driver source.
  16. *
  17. * @addtogroup I2C
  18. * @{
  19. */
  20. #include "hal.h"
  21. #if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__)
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Driver exported variables. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief I2C1 driver identifier.
  30. */
  31. #if (PLATFORM_I2C_USE_I2C1 == TRUE) || defined(__DOXYGEN__)
  32. I2CDriver I2CD1;
  33. #endif
  34. /*===========================================================================*/
  35. /* Driver local variables and types. */
  36. /*===========================================================================*/
  37. /*===========================================================================*/
  38. /* Driver local functions. */
  39. /*===========================================================================*/
  40. /*===========================================================================*/
  41. /* Driver interrupt handlers. */
  42. /*===========================================================================*/
  43. /*===========================================================================*/
  44. /* Driver exported functions. */
  45. /*===========================================================================*/
  46. /**
  47. * @brief Low level I2C driver initialization.
  48. *
  49. * @notapi
  50. */
  51. void i2c_lld_init(void) {
  52. #if PLATFORM_I2C_USE_I2C1 == TRUE
  53. i2cObjectInit(&I2CD1);
  54. #endif
  55. }
  56. /**
  57. * @brief Configures and activates the I2C peripheral.
  58. *
  59. * @param[in] i2cp pointer to the @p I2CDriver object
  60. *
  61. * @notapi
  62. */
  63. void i2c_lld_start(I2CDriver *i2cp) {
  64. if (i2cp->state == I2C_STOP) {
  65. /* Enables the peripheral.*/
  66. #if PLATFORM_I2C_USE_I2C1 == TRUE
  67. if (&I2CD1 == i2cp) {
  68. }
  69. #endif
  70. }
  71. }
  72. /**
  73. * @brief Deactivates the I2C peripheral.
  74. *
  75. * @param[in] i2cp pointer to the @p I2CDriver object
  76. *
  77. * @notapi
  78. */
  79. void i2c_lld_stop(I2CDriver *i2cp) {
  80. if (i2cp->state != I2C_STOP) {
  81. /* Disables the peripheral.*/
  82. #if PLATFORM_I2C_USE_I2C1 == TRUE
  83. if (&I2CD1 == i2cp) {
  84. }
  85. #endif
  86. }
  87. }
  88. /**
  89. * @brief Receives data via the I2C bus as master.
  90. *
  91. * @param[in] i2cp pointer to the @p I2CDriver object
  92. * @param[in] addr slave device address
  93. * @param[out] rxbuf pointer to the receive buffer
  94. * @param[in] rxbytes number of bytes to be received
  95. * @param[in] timeout the number of ticks before the operation timeouts,
  96. * the following special values are allowed:
  97. * - @a TIME_INFINITE no timeout.
  98. * .
  99. * @return The operation status.
  100. * @retval MSG_OK if the function succeeded.
  101. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  102. * be retrieved using @p i2cGetErrors().
  103. * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a
  104. * timeout the driver must be stopped and restarted
  105. * because the bus is in an uncertain state</b>.
  106. *
  107. * @notapi
  108. */
  109. msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
  110. uint8_t *rxbuf, size_t rxbytes,
  111. sysinterval_t timeout) {
  112. (void)i2cp;
  113. (void)addr;
  114. (void)rxbuf;
  115. (void)rxbytes;
  116. (void)timeout;
  117. return MSG_OK;
  118. }
  119. /**
  120. * @brief Transmits data via the I2C bus as master.
  121. *
  122. * @param[in] i2cp pointer to the @p I2CDriver object
  123. * @param[in] addr slave device address
  124. * @param[in] txbuf pointer to the transmit buffer
  125. * @param[in] txbytes number of bytes to be transmitted
  126. * @param[out] rxbuf pointer to the receive buffer
  127. * @param[in] rxbytes number of bytes to be received
  128. * @param[in] timeout the number of ticks before the operation timeouts,
  129. * the following special values are allowed:
  130. * - @a TIME_INFINITE no timeout.
  131. * .
  132. * @return The operation status.
  133. * @retval MSG_OK if the function succeeded.
  134. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  135. * be retrieved using @p i2cGetErrors().
  136. * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a
  137. * timeout the driver must be stopped and restarted
  138. * because the bus is in an uncertain state</b>.
  139. *
  140. * @notapi
  141. */
  142. msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
  143. const uint8_t *txbuf, size_t txbytes,
  144. uint8_t *rxbuf, size_t rxbytes,
  145. sysinterval_t timeout) {
  146. (void)i2cp;
  147. (void)addr;
  148. (void)txbuf;
  149. (void)txbytes;
  150. (void)rxbuf;
  151. (void)rxbytes;
  152. (void)timeout;
  153. return MSG_OK;
  154. }
  155. #endif /* HAL_USE_I2C == TRUE */
  156. /** @} */