HW_I2C_ATY.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @file HW_I2C_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2023 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief Familiar functions of I2C for all embedded device
  20. *
  21. * @version
  22. * - 1_01_220608 > ATY
  23. * -# Preliminary version, first Release
  24. ********************************************************************************
  25. */
  26. #ifndef __HW_I2C_ATY_H
  27. #define __HW_I2C_ATY_H
  28. #include "INCLUDE_ATY.h"
  29. #include "HW_TIMER_ATY.h"
  30. #include "HW_GPIO_ATY.h"
  31. /******************************* For user *************************************/
  32. #define I2C_WAIT_ACK_TIME 250 // us
  33. #define SHORT_DELAY 1
  34. #define LONG_DELAY 1
  35. /******************************************************************************/
  36. #ifndef __I2C_HARDWARE_ATY
  37. #define I2C_SCL_SET_H GPIO_SET_H(I2C_SCL_PORT, I2C_SCL_PIN)
  38. #define I2C_SCL_SET_L GPIO_SET_L(I2C_SCL_PORT, I2C_SCL_PIN)
  39. #define I2C_SDA_SET_OUT I2C_SDA_SetOut()
  40. #define I2C_SDA_SET_IN I2C_SDA_SetIn()
  41. #define I2C_SDA_SET_H GPIO_SET_H(I2C_SDA_PORT, I2C_SDA_PIN)
  42. #define I2C_SDA_SET_L GPIO_SET_L(I2C_SDA_PORT, I2C_SDA_PIN)
  43. #define I2C_SDA_GET_H GPIO_GET_H(I2C_SDA_PORT, I2C_SDA_PIN)
  44. #define I2C_SDA_GET_L GPIO_GET_L(I2C_SDA_PORT, I2C_SDA_PIN)
  45. void I2C_Start(void);
  46. void I2C_Stop(void);
  47. void I2C_Ack(void);
  48. void I2C_NoAck(void);
  49. uint8_t I2C_WaitAck(uint16_t maxErrTime);
  50. void I2C_WriteByte(uint8_t byte);
  51. uint8_t I2C_ReadByte(uint8_t ack);
  52. #endif /* __I2C_HARDWARE_ATY */
  53. uint8_t I2C_Write(uint8_t addr, uint8_t* data_t, uint8_t len);
  54. uint8_t I2C_Write_NoStop(uint8_t addr, uint8_t* data_t, uint8_t len);
  55. uint8_t I2C_Read(uint8_t addr, uint8_t* data_t, uint8_t len);
  56. uint8_t I2C_WriteReg(uint8_t addr, uint8_t reg, uint8_t* data_t, uint8_t len);
  57. uint8_t I2C_ReadReg(uint8_t addr, uint8_t reg, uint8_t* data_t, uint8_t len);
  58. #endif /* __HW_I2C_ATY_H */
  59. /******************************** End Of File *********************************/