bsp_i2c.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. I2C API, implementation depends on board specifics
  3. Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc.
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. * Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. * Neither the name of Trident Microsystems nor Hauppauge Computer Works
  13. nor the names of its contributors may be used to endorse or promote
  14. products derived from this software without specific prior written
  15. permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. POSSIBILITY OF SUCH DAMAGE.
  27. This module encapsulates I2C access.In some applications several devices
  28. share one I2C bus. If these devices have the same I2C address some kind
  29. off "switch" must be implemented to ensure error free communication with
  30. one device. In case such a "switch" is used, the device ID can be used
  31. to implement control over this "switch".
  32. */
  33. #ifndef __BSPI2C_H__
  34. #define __BSPI2C_H__
  35. #include "bsp_types.h"
  36. /*
  37. * This structure contains the I2C address, the device ID and a user_data pointer.
  38. * The user_data pointer can be used for application specific purposes.
  39. */
  40. struct i2c_device_addr {
  41. u16 i2c_addr; /* The I2C address of the device. */
  42. u16 i2c_dev_id; /* The device identifier. */
  43. void *user_data; /* User data pointer */
  44. };
  45. /**
  46. * \def IS_I2C_10BIT( addr )
  47. * \brief Determine if I2C address 'addr' is a 10 bits address or not.
  48. * \param addr The I2C address.
  49. * \return int.
  50. * \retval 0 if address is not a 10 bits I2C address.
  51. * \retval 1 if address is a 10 bits I2C address.
  52. */
  53. #define IS_I2C_10BIT(addr) \
  54. (((addr) & 0xF8) == 0xF0)
  55. /*------------------------------------------------------------------------------
  56. Exported FUNCTIONS
  57. ------------------------------------------------------------------------------*/
  58. /**
  59. * \fn drxbsp_i2c_init()
  60. * \brief Initialize I2C communication module.
  61. * \return drx_status_t Return status.
  62. * \retval 0 Initialization successful.
  63. * \retval -EIO Initialization failed.
  64. */
  65. drx_status_t drxbsp_i2c_init(void);
  66. /**
  67. * \fn drxbsp_i2c_term()
  68. * \brief Terminate I2C communication module.
  69. * \return drx_status_t Return status.
  70. * \retval 0 Termination successful.
  71. * \retval -EIO Termination failed.
  72. */
  73. drx_status_t drxbsp_i2c_term(void);
  74. /**
  75. * \fn drx_status_t drxbsp_i2c_write_read( struct i2c_device_addr *w_dev_addr,
  76. * u16 w_count,
  77. * u8 *wData,
  78. * struct i2c_device_addr *r_dev_addr,
  79. * u16 r_count,
  80. * u8 *r_data)
  81. * \brief Read and/or write count bytes from I2C bus, store them in data[].
  82. * \param w_dev_addr The device i2c address and the device ID to write to
  83. * \param w_count The number of bytes to write
  84. * \param wData The array to write the data to
  85. * \param r_dev_addr The device i2c address and the device ID to read from
  86. * \param r_count The number of bytes to read
  87. * \param r_data The array to read the data from
  88. * \return drx_status_t Return status.
  89. * \retval 0 Succes.
  90. * \retval -EIO Failure.
  91. * \retval -EINVAL Parameter 'wcount' is not zero but parameter
  92. * 'wdata' contains NULL.
  93. * Idem for 'rcount' and 'rdata'.
  94. * Both w_dev_addr and r_dev_addr are NULL.
  95. *
  96. * This function must implement an atomic write and/or read action on the I2C bus
  97. * No other process may use the I2C bus when this function is executing.
  98. * The critical section of this function runs from and including the I2C
  99. * write, up to and including the I2C read action.
  100. *
  101. * The device ID can be useful if several devices share an I2C address.
  102. * It can be used to control a "switch" on the I2C bus to the correct device.
  103. */
  104. drx_status_t drxbsp_i2c_write_read(struct i2c_device_addr *w_dev_addr,
  105. u16 w_count,
  106. u8 *w_data,
  107. struct i2c_device_addr *r_dev_addr,
  108. u16 r_count, u8 *r_data);
  109. /**
  110. * \fn drxbsp_i2c_error_text()
  111. * \brief Returns a human readable error.
  112. * Counter part of numerical drx_i2c_error_g.
  113. *
  114. * \return char* Pointer to human readable error text.
  115. */
  116. char *drxbsp_i2c_error_text(void);
  117. /**
  118. * \var drx_i2c_error_g;
  119. * \brief I2C specific error codes, platform dependent.
  120. */
  121. extern int drx_i2c_error_g;
  122. #endif /* __BSPI2C_H__ */