wm_i2c.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**************************************************************************//**
  2. * @file wm_i2c.h
  3. * @author
  4. * @version
  5. * @date
  6. * @brief
  7. * @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __WM_I2C_H
  10. #define __WM_I2C_H
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #include "wm_regs.h"
  15. #include "wm_type_def.h"
  16. #include "wm_cpu.h"
  17. #include "wm_irq.h"
  18. typedef struct
  19. {
  20. __IO uint32_t PRER_LO;
  21. __IO uint32_t PRER_HI;
  22. __IO uint32_t CTRL;
  23. __O uint32_t TX_RX;
  24. __O uint32_t CR_SR;
  25. __I uint32_t TXR;
  26. __I uint32_t CR;
  27. }I2C_T;
  28. #define I2C ((I2C_T *)(HR_I2C_BASE_ADDR))
  29. /**
  30. * @defgroup Driver_APIs Driver APIs
  31. * @brief Driver APIs
  32. */
  33. /**
  34. * @addtogroup Driver_APIs
  35. * @{
  36. */
  37. /**
  38. * @defgroup I2C_Driver_APIs I2C Driver APIs
  39. * @brief I2C driver APIs
  40. */
  41. /**
  42. * @addtogroup I2C_Driver_APIs
  43. * @{
  44. */
  45. /**
  46. * @brief Init the I2C module
  47. * @param freq I2C reference clock frequency in Hz that will be used
  48. * @note
  49. * the value must be between 100k and 400k
  50. */
  51. void tls_i2c_init(u32 freq);
  52. /** I2C initialization mask */
  53. #define wm_i2c_int_mask(bl) do { tls_bitband_write(HR_I2C_CTRL, 6, bl);}while(0);
  54. /**
  55. * @brief send stop signal
  56. *
  57. */
  58. void tls_i2c_stop(void);
  59. /**
  60. * @brief Waiting for ack signal
  61. * @retval
  62. * - \ref WM_FAILED
  63. * - \ref WM_SUCCESS
  64. */
  65. int tls_i2c_wait_ack(void);
  66. /**
  67. * @brief Writes the data to data register of I2C module
  68. * when ifstart one the start signal will be sent followed by the data
  69. * when ifstart zero only the data will be send
  70. * @param[in] data the data will be write to the data register of I2C module
  71. * @param[in] ifstart when one send start signal, when zero don't
  72. * @retval
  73. *
  74. */
  75. void tls_i2c_write_byte(u8 data, u8 ifstart);
  76. /**
  77. * @brief Get the data stored in data register of I2C module
  78. * @param[in] ifack when one send ack after reading the data register,when zero don't
  79. * @param[in] ifstop when one send stop signal after read, when zero do not send stop
  80. * @retval
  81. * the received data
  82. */
  83. u8 tls_i2c_read_byte(u8 ifack, u8 ifstop);
  84. /**
  85. * @brief This function is used to register i2c transfer done callback function.
  86. * @param[in] done is the i2c transfer done callback function.
  87. * @retval None
  88. * @note None
  89. */
  90. void wm_i2c_transfer_done_register(void (*done)(void));
  91. /**
  92. * @brief Start writing through int mode
  93. * @param[in] devaddr the device address
  94. * @param[in] wordaddr when one send stop signal after read, when zero do not send stop
  95. * @param[in] buf the address point where data shoule be stored
  96. * @param[in] len the length of data will be received
  97. * @retval
  98. * - \ref WM_FAILED
  99. * - \ref WM_SUCCESS
  100. */
  101. int wm_i2c_start_write_it(uint8_t devaddr, uint8_t wordaddr, uint8_t * buf, uint16_t len);
  102. /**
  103. * @brief Get the data stored in data register of I2C module
  104. * @param[in] ifack when one send ack after reading the data register,when zero don't
  105. * @param[in] ifstop when one send stop signal after read, when zero do not send stop
  106. * @retval the received data
  107. */
  108. int wm_i2c_start_read_it(uint8_t devaddr, uint8_t wordaddr, uint8_t * buf, uint16_t len);
  109. /**
  110. * @}
  111. */
  112. /**
  113. * @}
  114. */
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif
  119. /*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/