drv_hard_i2c.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-07-31 shelton first version
  9. */
  10. #ifndef __DRV_HARD_I2C_H__
  11. #define __DRV_HARD_I2C_H__
  12. #include <rtthread.h>
  13. #include <drivers/dev_i2c.h>
  14. #include "drv_common.h"
  15. #include "drv_dma.h"
  16. #define I2C_START 0
  17. #define I2C_END 1
  18. #define I2C_EVENT_CHECK_NONE ((uint32_t)0x00000000)
  19. #define I2C_EVENT_CHECK_ACKFAIL ((uint32_t)0x00000001)
  20. #define I2C_EVENT_CHECK_STOP ((uint32_t)0x00000002)
  21. typedef enum
  22. {
  23. I2C_INT_MA_TX = 0,
  24. I2C_INT_MA_RX,
  25. I2C_INT_SLA_TX,
  26. I2C_INT_SLA_RX,
  27. I2C_DMA_MA_TX,
  28. I2C_DMA_MA_RX,
  29. I2C_DMA_SLA_TX,
  30. I2C_DMA_SLA_RX,
  31. } i2c_mode_type;
  32. typedef enum
  33. {
  34. I2C_OK = 0,
  35. I2C_ERR_STEP_1,
  36. I2C_ERR_STEP_2,
  37. I2C_ERR_STEP_3,
  38. I2C_ERR_STEP_4,
  39. I2C_ERR_STEP_5,
  40. I2C_ERR_STEP_6,
  41. I2C_ERR_STEP_7,
  42. I2C_ERR_STEP_8,
  43. I2C_ERR_STEP_9,
  44. I2C_ERR_STEP_10,
  45. I2C_ERR_STEP_11,
  46. I2C_ERR_STEP_12,
  47. I2C_ERR_START,
  48. I2C_ERR_ADDR10,
  49. I2C_ERR_TCRLD,
  50. I2C_ERR_TDC,
  51. I2C_ERR_ADDR,
  52. I2C_ERR_STOP,
  53. I2C_ERR_ACKFAIL,
  54. I2C_ERR_TIMEOUT,
  55. I2C_ERR_INTERRUPT,
  56. } i2c_status_type;
  57. struct i2c_comm_type
  58. {
  59. rt_uint8_t *pbuff;
  60. rt_uint16_t psize;
  61. rt_uint16_t pcount;
  62. i2c_mode_type mode;
  63. rt_uint32_t timeout;
  64. rt_uint32_t status;
  65. i2c_status_type error_code;
  66. };
  67. struct at32_i2c_handle
  68. {
  69. i2c_type *i2c_x;
  70. const char *i2c_name;
  71. rt_uint32_t timing;
  72. IRQn_Type ev_irqn;
  73. IRQn_Type er_irqn;
  74. struct dma_config *dma_rx;
  75. struct dma_config *dma_tx;
  76. struct i2c_comm_type comm;
  77. rt_uint16_t i2c_dma_flag;
  78. struct rt_completion completion;
  79. };
  80. struct at32_i2c
  81. {
  82. struct at32_i2c_handle *handle;
  83. struct rt_i2c_bus_device i2c_bus;
  84. };
  85. #endif