TM7707_ATY.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * @file TM7707_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2025 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 TM7707 for all embedded device
  20. *
  21. * @version
  22. * - 1_01_220601 > ATY
  23. * -# Preliminary version, first Release
  24. * - Undone
  25. ********************************************************************************
  26. */
  27. #ifndef __TM7707_ATY_H
  28. #define __TM7707_ATY_H
  29. #include "INCLUDE_ATY.h"
  30. /******************************* For user *************************************/
  31. #include "bt.h"
  32. #include "gpio.h"
  33. #include "flash.h"
  34. #define TM7707_MCLKIN_PORT GpioPortB
  35. #define TM7707_MCLKIN_PIN GpioPin14 // TIM3_CH1B / TIM0_CHA
  36. #define TM7707_SCLK_PORT GpioPortB
  37. #define TM7707_SCLK_PIN GpioPin15
  38. #define TM7707_CS_PORT GpioPortB
  39. #define TM7707_CS_PIN GpioPin13
  40. #define TM7707_RESET_PORT GpioPortB
  41. #define TM7707_RESET_PIN GpioPin12
  42. #define TM7707_DIN_PORT GpioPortA
  43. #define TM7707_DIN_PIN GpioPin10
  44. #define TM7707_DOUT_PORT GpioPortA
  45. #define TM7707_DOUT_PIN GpioPin9
  46. #define TM7707_DRDY_PORT GpioPortA
  47. #define TM7707_DRDY_PIN GpioPin8
  48. #define TM7707_REFEN_PORT GpioPortA
  49. #define TM7707_REFEN_PIN GpioPin11
  50. #define TM7707_DATA_GROUP_SIZE 12
  51. void TM7707_GPIO_Init(void);
  52. #define TIM_COUNT_WHOLE 0x0001 // 1MHz // 0x07d0 - 2000 1KHz
  53. #define TIM_COUNT_HALF 0x0000
  54. void TM7707_MCLK_Init(void);
  55. /******************************************************************************/
  56. #define TM7707_REFEN_SET_H GPIO_SET_H(TM7707_REFEN_PORT, TM7707_REFEN_PIN)
  57. #define TM7707_REFEN_SET_L GPIO_SET_L(TM7707_REFEN_PORT, TM7707_REFEN_PIN)
  58. #define TM7707_RESET_SET_H GPIO_SET_H(TM7707_RESET_PORT, TM7707_RESET_PIN)
  59. #define TM7707_RESET_SET_L GPIO_SET_L(TM7707_RESET_PORT, TM7707_RESET_PIN)
  60. #define TM7707_CS_SET_H GPIO_SET_H(TM7707_CS_PORT, TM7707_CS_PIN)
  61. #define TM7707_CS_SET_L GPIO_SET_L(TM7707_CS_PORT, TM7707_CS_PIN)
  62. #define TM7707_SCLK_SET_H GPIO_SET_H(TM7707_SCLK_PORT, TM7707_SCLK_PIN)
  63. #define TM7707_SCLK_SET_L GPIO_SET_L(TM7707_SCLK_PORT, TM7707_SCLK_PIN)
  64. #define TM7707_DIN_SET_H GPIO_SET_H(TM7707_DIN_PORT, TM7707_DIN_PIN)
  65. #define TM7707_DIN_SET_L GPIO_SET_L(TM7707_DIN_PORT, TM7707_DIN_PIN)
  66. #define TM7707_DRDY_GET_H GPIO_GET_H(TM7707_DRDY_PORT, TM7707_DRDY_PIN)
  67. #define TM7707_DRDY_GET_L GPIO_GET_L(TM7707_DRDY_PORT, TM7707_DRDY_PIN)
  68. #define TM7707_DOUT_GET_H GPIO_GET_H(TM7707_DOUT_PORT, TM7707_DOUT_PIN)
  69. #define TM7707_DOUT_GET_L GPIO_GET_L(TM7707_DOUT_PORT, TM7707_DOUT_PIN)
  70. // Communication register
  71. #define TM7707_REG_COMM (0<<4) // Communication register
  72. #define TM7707_REG_SETUP (1<<4) // Setting register
  73. #define TM7707_REG_FILTER_H (2<<4) // Filter(high) register
  74. #define TM7707_REG_DATA (3<<4) // Data register
  75. #define TM7707_REG_TEST (4<<4) // Test register
  76. #define TM7707_REG_FILTER_L (5<<4) // Filter(low) register
  77. #define TM7707_REG_ZERO_CAL (6<<4) // Zero cal register
  78. #define TM7707_REG_FULL_CAL (7<<4) // Full cal register
  79. #define TM7707_WRITE (0<<3) // Write in next
  80. #define TM7707_READ (1<<3) // Read in next
  81. #define TM7707_STBY_MODE (1<<2) // Stanby mode, Cannot write to device register.
  82. #define TM7707_WORK_MODE (0<<2) // Work mode, Cannot write to device register.
  83. #define TM7707_CH_1 (0<<0) // AIN1+ AIN1-
  84. #define TM7707_CH_2 (1<<0) // AIN2+ AIN2-
  85. #define TM7707_CH_3 (2<<0) // AIN1- AIN1-
  86. #define TM7707_CH_4 (3<<0) // AIN1- AIN2-
  87. // Setting register (Reset 0x01)
  88. #define TM7707_MD_NORMAL (0<<6) // Normal
  89. #define TM7707_MD_CAL_SELF (1<<6) // Self calibrate
  90. #define TM7707_MD_CAL_ZERO (2<<6) // Calibrate Zero
  91. #define TM7707_MD_CAL_FULL (3<<6) // Calibrate Full
  92. #define TM7707_GAIN_1 (0<<3) // Gain x1
  93. #define TM7707_GAIN_2 (1<<3) // Gain x2
  94. #define TM7707_GAIN_4 (2<<3) // Gain x4
  95. #define TM7707_GAIN_8 (3<<3) // Gain x8
  96. #define TM7707_GAIN_16 (4<<3) // Gain x16
  97. #define TM7707_GAIN_32 (5<<3) // Gain x32
  98. #define TM7707_GAIN_64 (6<<3) // Gain x64
  99. #define TM7707_GAIN_128 (7<<3) // Gain x128
  100. #define TM7707_BIPOLAR (0<<2) // Bipolar input
  101. #define TM7707_UNIPOLAR (1<<2) // Unipolar input
  102. #define TM7707_BUF_NO (0<<1) // Non-buffered input
  103. #define TM7707_BUF_EN (1<<1) // Buffered input
  104. #define TM7707_FSYNC_0 (0<<0) // Filter no sync
  105. #define TM7707_FSYNC_1 (1<<0) // Filter sync
  106. // Filter high register (Reset 0x05)
  107. #define TM7707_BST_0 (0<<5) // Front current low
  108. #define TM7707_BST_1 (1<<5) // Front current high
  109. #define TM7707_CLKDIS_OUT0 (0<<4) // Clock out disable (safe power)
  110. #define TM7707_CLKDIS_OUT1 (1<<4) // Clock out enable
  111. // Filter low register (Reset 0x00)
  112. // Data register
  113. // Test register (Reset 0x00)
  114. // Zero cal register (Reset 0x1F4000)
  115. // Full cal register register (Reset 0x5761AB)
  116. // Legacy info regester
  117. #define TM7707_CLK_2_4576M (0<<2) // 2.4576M
  118. #define TM7707_CLK_1M (1<<2) // 1M
  119. #define TM7707_CLK_4_9152M (2<<2) // 4.9152M
  120. #define TM7707_CLK_2M (3<<2) // 2M
  121. #define TM7707_ZERO_0 0x0000
  122. #define TM7707_ZERO_1 0x0080
  123. #define TM7707_FS_50HZ 0x0000
  124. #define TM7707_FS_60HZ 0x0100
  125. #define TM7707_FS_250HZ 0x0200
  126. #define TM7707_FS_500HZ 0x0400
  127. #define TM7707_FS_DEFAULT 0x0F00
  128. void TM7707_WriteByte(uint8_t data_t);
  129. uint8_t TM7707_ReadByte(void);
  130. uint32_t TM7707_ReadData(void);
  131. float TM7707_VoltageCalc(float refVoltage, uint32_t dataIn);
  132. void TM7707_Init(void);
  133. void TM7707_Test(void);
  134. #endif /* __TM7707_ATY_H */
  135. /******************************** End Of File *********************************/