AD7124_ATY.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /**
  2. * @file AD7124_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 AD7124 for all embedded device
  20. *
  21. * @version
  22. * - 1_01_230828 > ATY
  23. * -# Preliminary version, first Release
  24. * - Undone
  25. ********************************************************************************
  26. */
  27. #ifndef __AD7124_ATY_H
  28. #define __AD7124_ATY_H
  29. #include "INCLUDE_ATY.h"
  30. /******************************* For user *************************************/
  31. /******************************************************************************/
  32. /******************* Register map and register definitions ********************/
  33. #define AD7124_RW 1 /* Read and Write */
  34. #define AD7124_R 2 /* Read only */
  35. #define AD7124_W 3 /* Write only */
  36. /* AD7124 Register Map */
  37. #define AD7124_COMM_REG 0x00
  38. #define AD7124_STATUS_REG 0x00
  39. #define AD7124_ADC_CTRL_REG 0x01
  40. #define AD7124_DATA_REG 0x02
  41. #define AD7124_IO_CTRL1_REG 0x03
  42. #define AD7124_IO_CTRL2_REG 0x04
  43. #define AD7124_ID_REG 0x05
  44. #define AD7124_ERR_REG 0x06
  45. #define AD7124_ERREN_REG 0x07
  46. #define AD7124_CH0_MAP_REG 0x09
  47. #define AD7124_CH1_MAP_REG 0x0A
  48. #define AD7124_CH2_MAP_REG 0x0B
  49. #define AD7124_CH3_MAP_REG 0x0C
  50. #define AD7124_CH4_MAP_REG 0x0D
  51. #define AD7124_CH5_MAP_REG 0x0E
  52. #define AD7124_CH6_MAP_REG 0x0F
  53. #define AD7124_CH7_MAP_REG 0x10
  54. #define AD7124_CH8_MAP_REG 0x11
  55. #define AD7124_CH9_MAP_REG 0x12
  56. #define AD7124_CH10_MAP_REG 0x13
  57. #define AD7124_CH11_MAP_REG 0x14
  58. #define AD7124_CH12_MAP_REG 0x15
  59. #define AD7124_CH13_MAP_REG 0x16
  60. #define AD7124_CH14_MAP_REG 0x17
  61. #define AD7124_CH15_MAP_REG 0x18
  62. #define AD7124_CFG0_REG 0x19
  63. #define AD7124_CFG1_REG 0x1A
  64. #define AD7124_CFG2_REG 0x1B
  65. #define AD7124_CFG3_REG 0x1C
  66. #define AD7124_CFG4_REG 0x1D
  67. #define AD7124_CFG5_REG 0x1E
  68. #define AD7124_CFG6_REG 0x1F
  69. #define AD7124_CFG7_REG 0x20
  70. #define AD7124_FILT0_REG 0x21
  71. #define AD7124_FILT1_REG 0x22
  72. #define AD7124_FILT2_REG 0x23
  73. #define AD7124_FILT3_REG 0x24
  74. #define AD7124_FILT4_REG 0x25
  75. #define AD7124_FILT5_REG 0x26
  76. #define AD7124_FILT6_REG 0x27
  77. #define AD7124_FILT7_REG 0x28
  78. #define AD7124_OFFS0_REG 0x29
  79. #define AD7124_OFFS1_REG 0x2A
  80. #define AD7124_OFFS2_REG 0x2B
  81. #define AD7124_OFFS3_REG 0x2C
  82. #define AD7124_OFFS4_REG 0x2D
  83. #define AD7124_OFFS5_REG 0x2E
  84. #define AD7124_OFFS6_REG 0x2F
  85. #define AD7124_OFFS7_REG 0x30
  86. #define AD7124_GAIN0_REG 0x31
  87. #define AD7124_GAIN1_REG 0x32
  88. #define AD7124_GAIN2_REG 0x33
  89. #define AD7124_GAIN3_REG 0x34
  90. #define AD7124_GAIN4_REG 0x35
  91. #define AD7124_GAIN5_REG 0x36
  92. #define AD7124_GAIN6_REG 0x37
  93. #define AD7124_GAIN7_REG 0x38
  94. /* Communication Register bits */
  95. #define AD7124_COMM_REG_WEN (0 << 7)
  96. #define AD7124_COMM_REG_WR (0 << 6)
  97. #define AD7124_COMM_REG_RD (1 << 6)
  98. #define AD7124_COMM_REG_RA(x) ((x) | 0x40) // read reg at address (x)
  99. #define AD7124_COMM_REG_WA(x) ((x) & 0x3F) // write reg at address (x)
  100. /* Status Register bits */
  101. #define AD7124_STATUS_REG_RDY (1 << 7)
  102. #define AD7124_STATUS_REG_ERROR_FLAG (1 << 6)
  103. #define AD7124_STATUS_REG_POR_FLAG (1 << 4)
  104. #define AD7124_STATUS_REG_CH_ACTIVE(x) ((x) & 0xF)
  105. /* ADC_Control Register bits */
  106. #define AD7124_ADC_CTRL_REG_DOUT_RDY_DEL (1 << 12)
  107. #define AD7124_ADC_CTRL_REG_CONT_READ (1 << 11)
  108. #define AD7124_ADC_CTRL_REG_DATA_STATUS (1 << 10)
  109. #define AD7124_ADC_CTRL_REG_CS_EN (1 << 9)
  110. #define AD7124_ADC_CTRL_REG_REF_EN (1 << 8)
  111. #define AD7124_ADC_CTRL_REG_POWER_MODE(x) (((x) & 0x3) << 6)
  112. #define AD7124_ADC_CTRL_REG_MODE(x) (((x) & 0xF) << 2)
  113. #define AD7124_ADC_CTRL_REG_CLK_SEL(x) (((x) & 0x3) << 0)
  114. /* IO_Control_1 Register bits */
  115. #define AD7124_IO_CTRL1_REG_GPIO_DAT2 (1 << 23)
  116. #define AD7124_IO_CTRL1_REG_GPIO_DAT1 (1 << 22)
  117. #define AD7124_IO_CTRL1_REG_GPIO_CTRL2 (1 << 19)
  118. #define AD7124_IO_CTRL1_REG_GPIO_CTRL1 (1 << 18)
  119. #define AD7124_IO_CTRL1_REG_PDSW (1 << 15)
  120. #define AD7124_IO_CTRL1_REG_IOUT1(x) (((x) & 0x7) << 11)
  121. #define AD7124_IO_CTRL1_REG_IOUT0(x) (((x) & 0x7) << 8)
  122. #define AD7124_IO_CTRL1_REG_IOUT_CH1(x) (((x) & 0xF) << 4)
  123. #define AD7124_IO_CTRL1_REG_IOUT_CH0(x) (((x) & 0xF) << 0)
  124. /* IO_Control_1 AD7124-8 specific bits */
  125. #define AD7124_8_IO_CTRL1_REG_GPIO_DAT4 (1 << 23)
  126. #define AD7124_8_IO_CTRL1_REG_GPIO_DAT3 (1 << 22)
  127. #define AD7124_8_IO_CTRL1_REG_GPIO_DAT2 (1 << 21)
  128. #define AD7124_8_IO_CTRL1_REG_GPIO_DAT1 (1 << 20)
  129. #define AD7124_8_IO_CTRL1_REG_GPIO_CTRL4 (1 << 19)
  130. #define AD7124_8_IO_CTRL1_REG_GPIO_CTRL3 (1 << 18)
  131. #define AD7124_8_IO_CTRL1_REG_GPIO_CTRL2 (1 << 17)
  132. #define AD7124_8_IO_CTRL1_REG_GPIO_CTRL1 (1 << 16)
  133. /* IO_Control_2 Register bits */
  134. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS7 (1 << 15)
  135. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS6 (1 << 14)
  136. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS5 (1 << 11)
  137. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS4 (1 << 10)
  138. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS3 (1 << 5)
  139. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS2 (1 << 4)
  140. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS1 (1 << 1)
  141. #define AD7124_IO_CTRL2_REG_GPIO_VBIAS0 (1 << 0)
  142. /* IO_Control_2 AD7124-8 specific bits */
  143. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS15 (1 << 15)
  144. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS14 (1 << 14)
  145. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS13 (1 << 13)
  146. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS12 (1 << 12)
  147. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS11 (1 << 11)
  148. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS10 (1 << 10)
  149. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS9 (1 << 9)
  150. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS8 (1 << 8)
  151. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS7 (1 << 7)
  152. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS6 (1 << 6)
  153. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS5 (1 << 5)
  154. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS4 (1 << 4)
  155. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS3 (1 << 3)
  156. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS2 (1 << 2)
  157. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS1 (1 << 1)
  158. #define AD7124_8_IO_CTRL2_REG_GPIO_VBIAS0 (1 << 0)
  159. /* ID Register bits */
  160. #define AD7124_ID_REG_DEVICE_ID(x) (((x) & 0xF) << 4)
  161. #define AD7124_ID_REG_SILICON_REV(x) (((x) & 0xF) << 0)
  162. /* Error Register bits */
  163. #define AD7124_ERR_REG_LDO_CAP_ERR (1 << 19)
  164. #define AD7124_ERR_REG_ADC_CAL_ERR (1 << 18)
  165. #define AD7124_ERR_REG_ADC_CONV_ERR (1 << 17)
  166. #define AD7124_ERR_REG_ADC_SAT_ERR (1 << 16)
  167. #define AD7124_ERR_REG_AINP_OV_ERR (1 << 15)
  168. #define AD7124_ERR_REG_AINP_UV_ERR (1 << 14)
  169. #define AD7124_ERR_REG_AINM_OV_ERR (1 << 13)
  170. #define AD7124_ERR_REG_AINM_UV_ERR (1 << 12)
  171. #define AD7124_ERR_REG_REF_DET_ERR (1 << 11)
  172. #define AD7124_ERR_REG_DLDO_PSM_ERR (1 << 9)
  173. #define AD7124_ERR_REG_ALDO_PSM_ERR (1 << 7)
  174. #define AD7124_ERR_REG_SPI_IGNORE_ERR (1 << 6)
  175. #define AD7124_ERR_REG_SPI_SLCK_CNT_ERR (1 << 5)
  176. #define AD7124_ERR_REG_SPI_READ_ERR (1 << 4)
  177. #define AD7124_ERR_REG_SPI_WRITE_ERR (1 << 3)
  178. #define AD7124_ERR_REG_SPI_CRC_ERR (1 << 2)
  179. #define AD7124_ERR_REG_MM_CRC_ERR (1 << 1)
  180. #define AD7124_ERR_REG_ROM_CRC_ERR (1 << 0)
  181. /* Error_En Register bits */
  182. #define AD7124_ERREN_REG_MCLK_CNT_EN (1 << 22)
  183. #define AD7124_ERREN_REG_LDO_CAP_CHK_TEST_EN (1 << 21)
  184. #define AD7124_ERREN_REG_LDO_CAP_CHK(x) (((x) & 0x3) << 19)
  185. #define AD7124_ERREN_REG_ADC_CAL_ERR_EN (1 << 18)
  186. #define AD7124_ERREN_REG_ADC_CONV_ERR_EN (1 << 17)
  187. #define AD7124_ERREN_REG_ADC_SAT_ERR_EN (1 << 16)
  188. #define AD7124_ERREN_REG_AINP_OV_ERR_EN (1 << 15)
  189. #define AD7124_ERREN_REG_AINP_UV_ERR_EN (1 << 14)
  190. #define AD7124_ERREN_REG_AINM_OV_ERR_EN (1 << 13)
  191. #define AD7124_ERREN_REG_AINM_UV_ERR_EN (1 << 12)
  192. #define AD7124_ERREN_REG_REF_DET_ERR_EN (1 << 11)
  193. #define AD7124_ERREN_REG_DLDO_PSM_TRIP_TEST_EN (1 << 10)
  194. #define AD7124_ERREN_REG_DLDO_PSM_ERR_ERR (1 << 9)
  195. #define AD7124_ERREN_REG_ALDO_PSM_TRIP_TEST_EN (1 << 8)
  196. #define AD7124_ERREN_REG_ALDO_PSM_ERR_EN (1 << 7)
  197. #define AD7124_ERREN_REG_SPI_IGNORE_ERR_EN (1 << 6)
  198. #define AD7124_ERREN_REG_SPI_SCLK_CNT_ERR_EN (1 << 5)
  199. #define AD7124_ERREN_REG_SPI_READ_ERR_EN (1 << 4)
  200. #define AD7124_ERREN_REG_SPI_WRITE_ERR_EN (1 << 3)
  201. #define AD7124_ERREN_REG_SPI_CRC_ERR_EN (1 << 2)
  202. #define AD7124_ERREN_REG_MM_CRC_ERR_EN (1 << 1)
  203. #define AD7124_ERREN_REG_ROM_CRC_ERR_EN (1 << 0)
  204. /* Channel Registers 0-15 bits */
  205. #define AD7124_CH_MAP_REG_CH_ENABLE (1 << 15)
  206. #define AD7124_CH_MAP_REG_SETUP(x) (((x) & 0x7) << 12)
  207. #define AD7124_CH_MAP_REG_AINP(x) (((x) & 0x1F) << 5)
  208. #define AD7124_CH_MAP_REG_AINM(x) (((x) & 0x1F) << 0)
  209. /* Configuration Registers 0-7 bits */
  210. #define AD7124_CFG_REG_BIPOLAR (1 << 11)
  211. #define AD7124_CFG_REG_BURNOUT(x) (((x) & 0x3) << 9)
  212. #define AD7124_CFG_REG_REF_BUFP (1 << 8)
  213. #define AD7124_CFG_REG_REF_BUFM (1 << 7)
  214. #define AD7124_CFG_REG_AIN_BUFP (1 << 6)
  215. #define AD7124_CFG_REG_AINN_BUFM (1 << 5)
  216. #define AD7124_CFG_REG_REF_SEL(x) ((x) & 0x3) << 3
  217. #define AD7124_CFG_REG_PGA(x) (((x) & 0x7) << 0)
  218. /* Filter Register 0-7 bits */
  219. #define AD7124_FILT_REG_FILTER(x) (((x) & 0x7) << 21)
  220. #define AD7124_FILT_REG_REJ60 (1 << 20)
  221. #define AD7124_FILT_REG_POST_FILTER(x) (((x) & 0x7) << 17)
  222. #define AD7124_FILT_REG_SINGLE_CYCLE (1 << 16)
  223. #define AD7124_FILT_REG_FS(x) (((x) & 0x7FF) << 0)
  224. /*************************** Types Declarations *******************************/
  225. /*! Device register info */
  226. struct ad7124_st_reg {
  227. int32_t addr;
  228. int32_t value;
  229. int32_t size;
  230. int32_t rw;
  231. };
  232. /*! AD7124 registers list*/
  233. enum ad7124_registers {
  234. AD7124_Status = 0x00,
  235. AD7124_ADC_Control,
  236. AD7124_Data,
  237. AD7124_IOCon1,
  238. AD7124_IOCon2,
  239. AD7124_ID,
  240. AD7124_Error,
  241. AD7124_Error_En,
  242. AD7124_Mclk_Count,
  243. AD7124_Channel_0,
  244. AD7124_Channel_1,
  245. AD7124_Channel_2,
  246. AD7124_Channel_3,
  247. AD7124_Channel_4,
  248. AD7124_Channel_5,
  249. AD7124_Channel_6,
  250. AD7124_Channel_7,
  251. AD7124_Channel_8,
  252. AD7124_Channel_9,
  253. AD7124_Channel_10,
  254. AD7124_Channel_11,
  255. AD7124_Channel_12,
  256. AD7124_Channel_13,
  257. AD7124_Channel_14,
  258. AD7124_Channel_15,
  259. AD7124_Config_0,
  260. AD7124_Config_1,
  261. AD7124_Config_2,
  262. AD7124_Config_3,
  263. AD7124_Config_4,
  264. AD7124_Config_5,
  265. AD7124_Config_6,
  266. AD7124_Config_7,
  267. AD7124_Filter_0,
  268. AD7124_Filter_1,
  269. AD7124_Filter_2,
  270. AD7124_Filter_3,
  271. AD7124_Filter_4,
  272. AD7124_Filter_5,
  273. AD7124_Filter_6,
  274. AD7124_Filter_7,
  275. AD7124_Offset_0,
  276. AD7124_Offset_1,
  277. AD7124_Offset_2,
  278. AD7124_Offset_3,
  279. AD7124_Offset_4,
  280. AD7124_Offset_5,
  281. AD7124_Offset_6,
  282. AD7124_Offset_7,
  283. AD7124_Gain_0,
  284. AD7124_Gain_1,
  285. AD7124_Gain_2,
  286. AD7124_Gain_3,
  287. AD7124_Gain_4,
  288. AD7124_Gain_5,
  289. AD7124_Gain_6,
  290. AD7124_Gain_7,
  291. AD7124_REG_NO
  292. };
  293. /******************* AD7124 Constants *****************************************/
  294. #define AD7124_CRC8_POLYNOMIAL_REPRESENTATION 0x07 /* x8 + x2 + x + 1 */
  295. #define AD7124_DISABLE_CRC 0
  296. #define AD7124_USE_CRC 1
  297. #endif /* __AD7124_ATY_H */
  298. /******************************** End Of File *********************************/