api_rt_i2c.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef _API_I2C_LOW_H_
  2. #define _API_I2C_LOW_H_
  3. #include <stdint.h>
  4. #include "api_i2c.h"
  5. #include "api_rt_common.h"
  6. #include "gd32f30x.h"
  7. #define I2C_TIME_OUT (uint16_t)(10000)
  8. typedef struct
  9. {
  10. uint32_t I2CBase;
  11. } ApiRtI2C_Handle;
  12. extern ApiRtI2C_Handle I2Cs[1];
  13. typedef enum
  14. {
  15. I2C_START = 0,
  16. I2C_SEND_ADDRESS,
  17. I2C_CLEAR_ADDRESS_FLAG,
  18. I2C_TRANSMIT_DATA,
  19. I2C_STOP,
  20. I2C_COMPLETE
  21. } ApiRtI2C_Process;
  22. /**
  23. * @brief I2C初始化
  24. */
  25. void iRtI2C_Init();
  26. /**
  27. * @brief I2C等待EE可写入
  28. */
  29. void iRtI2C_WaitEEReady();
  30. /**
  31. * @brief I2C总线复位
  32. *
  33. * @return 总线复位次数
  34. */
  35. int iRtI2C_BusReset(uint8_t devIndex);
  36. /**
  37. * @brief I2C同步页写入EE
  38. *
  39. * @param devIndex 外设序号
  40. * @param devAddr 设备地址
  41. * @param memAddr 内存地址
  42. * @param memAddrSize 内存地址宽度
  43. * @param data 写入数据Buffer
  44. * @param count 写入数据长度
  45. * @return 写入结果
  46. */
  47. int iRtI2C_PageWrite2EE(uint8_t devIndex, uint16_t devAddr, uint16_t memAddr, uint8_t *data, uint8_t count);
  48. #endif