yc11xx_iic.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright 2016, yichip Semiconductor(shenzhen office)
  3. * All Rights Reserved.
  4. *
  5. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
  6. * the contents of this file may not be disclosed to third parties, copied
  7. * or duplicated in any form, in whole or in part, without the prior
  8. * written permission of Yichip Semiconductor.
  9. */
  10. /**
  11. *@file iic.h
  12. *@brief IIC support for application.
  13. */
  14. #ifndef _IIC_H_
  15. #define _IIC_H_
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include "yc11xx.h"
  20. #include "yc_drv_common.h"
  21. /**
  22. *@brief I2C_ClockSpeed.
  23. */
  24. #define IICD_CLOCKSPEED200KHZ 26
  25. #define IICD_CLOCKSPEED400KHZ 11
  26. #define IICD_CLOCKSPEED800KHZ 4
  27. #define IICD_CLOCKSPEED1MHZ 2
  28. /**
  29. *@brief I2C initialized structure definition.
  30. */
  31. typedef struct
  32. {
  33. uint32_t I2C_ClockSpeed; /*!< Specifies the clock frequency.
  34. This parameter must be set to a value lower than 400kHz */
  35. uint16_t I2C_TXLen; /*!< Specifies Tx DMA buff length */
  36. uint16_t I2C_RXLen; /*!< Specifies Rx DMA buff length */
  37. }I2C_InitTypeDef;
  38. /**
  39. *@brief I2C_RegAddr.
  40. */
  41. #define I2C_REGADDR8BITS(x) (0x01000000|x)
  42. #define I2C_REGADDR16BITS(x) (0x10000000|x)
  43. /**
  44. *@brief I2C_RegAddr.
  45. */
  46. #define IS_I2C_REGADDR(x) (0x11000000&x)
  47. #define IS_I2C_REGADDR8BITS(x) (0x01000000&x)
  48. #define IS_I2C_REGADDR16BITS(x) (0x10000000&x)
  49. /**
  50. *@brief cancel IIC initialization.
  51. *@param None.
  52. *@return None.
  53. */
  54. void I2C_DeInit(void);
  55. /**
  56. *@brief IIC initialization.
  57. *@param I2C_InitStruct IIC initializing structure.@ref I2C_InitTypeDef
  58. *@return None.
  59. */
  60. void I2C_Init(I2C_InitTypeDef* I2C_InitStruct);
  61. /**
  62. *@brief This function can send a byte data through IIC bus.
  63. *@param DevAddr target device address.
  64. *@param RegAddr target register address.
  65. *@param Data the data will be send.
  66. *@return None.
  67. */
  68. void I2C_SendData(uint32_t DevAddr, uint32_t RegAddr, uint16_t Data);
  69. /**
  70. *@brief This function can receive a byte data from IIC bus.
  71. *@param DevAddr target device address.
  72. *@param RegAddr target register address.
  73. *@return a byte data that read from IIC.
  74. */
  75. uint32_t I2C_ReceiveData(uint32_t DevAddr, uint32_t RegAddr);
  76. /**
  77. *@brief This function can receive a set of data through IIC bus.
  78. *@param DevAddr target device address.
  79. *@param RegAddr target register address.
  80. *@param RxBuff The buffer that the read data is stored.
  81. *@param RxLen the number of byte received.
  82. *@return None.
  83. */
  84. void I2C_ReadDatatoBuff(uint32_t DevAddr, uint32_t RegAddr, uint8_t* RxBuff, uint16_t RxLen);
  85. /**
  86. *@brief This function can send a set of data through IIC bus.
  87. *@param DevAddr target device address.
  88. *@param RegAddr target register address.
  89. *@param TxBuff the data will be send.
  90. *@param RxLen the number of byte to be send.
  91. *@return None.
  92. */
  93. void I2C_SendDataFromBuff(uint32_t DevAddr, uint32_t RegAddr, uint8_t* TxBuff, uint16_t TxLen);
  94. #endif