lt_fdc2214.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __LT_FDC2214_H__
  2. #define __LT_FDC2214_H__
  3. #include "lt_fdc2214_iic.h"
  4. #include <stdint.h>
  5. #include "cmsis_os.h"
  6. #define PI 3.1415926
  7. #define ClockFrequency 40000000 //时钟频率
  8. #define SWAP16(data) (uint32_t)((((uint16_t)(data) & (0xFF<<0 ))<<8)|(((uint32_t)(data) & (0xFF<<8))>>8))
  9. #define FDC2214_Addr (0x2A)
  10. #define FDC2214_DATA_CH0 (0x00)
  11. #define FDC2214_DATA_LSB_CH0 (0x01)
  12. #define FDC2214_DATA_CH1 (0x02)
  13. #define FDC2214_DATA_LSB_CH1 (0x03)
  14. #define FDC2214_DATA_CH2 (0x04)
  15. #define FDC2214_DATA_LSB_CH2 (0x05)
  16. #define FDC2214_DATA_CH3 (0x06)
  17. #define FDC2214_DATA_LSB_CH3 (0x07)
  18. #define FDC2214_RCOUNT_CH0 (0x08)
  19. #define FDC2214_RCOUNT_CH1 (0x09)
  20. #define FDC2214_RCOUNT_CH2 (0x0A)
  21. #define FDC2214_RCOUNT_CH3 (0x0B)
  22. #define FDC2214_SETTLECOUNT_CH0 (0x10)
  23. #define FDC2214_SETTLECOUNT_CH1 (0x11)
  24. #define FDC2214_SETTLECOUNT_CH2 (0x12)
  25. #define FDC2214_SETTLECOUNT_CH3 (0x13)
  26. #define FDC2214_CLOCK_DIVIDERS_CH0 (0x14)
  27. #define FDC2214_CLOCK_DIVIDERS_CH1 (0x15)
  28. #define FDC2214_CLOCK_DIVIDERS_CH2 (0x16)
  29. #define FDC2214_CLOCK_DIVIDERS_CH3 (0x17)
  30. #define FDC2214_STATUS (0x18)
  31. #define FDC2214_ERROR_CONFIG (0x19)
  32. #define FDC2214_CONFIG (0x1A)
  33. #define FDC2214_MUX_CONFIG (0x1B)
  34. #define FDC2214_RESET_DEV (0x1C)
  35. #define FDC2214_DRIVE_CURRENT_CH0 (0x1E)
  36. #define FDC2214_DRIVE_CURRENT_CH1 (0x1F)
  37. #define FDC2214_DRIVE_CURRENT_CH2 (0x20)
  38. #define FDC2214_DRIVE_CURRENT_CH3 (0x21)
  39. #define FDC2214_MANUFACTURER_ID (0x7E)
  40. #define FDC2214_DEVICE_ID (0x7F)
  41. #define FDC2214_ID (0x3055) // 0x3055
  42. typedef enum
  43. {
  44. FDC2214_Channel_0 = 0x00,
  45. FDC2214_Channel_1 = 0x01,
  46. FDC2214_Channel_2 = 0x02,
  47. FDC2214_Channel_3 = 0x03
  48. } FDC2214_channel_t;
  49. typedef enum
  50. {
  51. FDC2214_Channel_Sequence_0_1 = 0x00,
  52. FDC2214_Channel_Sequence_0_1_2 = 0x01,
  53. FDC2214_Channel_Sequence_0_1_2_3 = 0x02,
  54. } FDC2214_channel_sequence_t;
  55. typedef enum
  56. {
  57. FDC2214_Bandwidth_1M = 0x01, //1MHz
  58. FDC2214_Bandwidth_3_3M = 0x04, //3.3MHz
  59. FDC2214_Bandwidth_10M = 0x05, //10MHz
  60. FDC2214_Bandwidth_33M = 0x07 //33MHz
  61. } FDC2214_filter_bandwidth_t;
  62. typedef enum
  63. {
  64. FDC2214_Drive_Current_0_016 = 0x00, //0.016mA
  65. FDC2214_Drive_Current_0_018 = 0x01, //0.018mA
  66. FDC2214_Drive_Current_0_021 = 0x02, //0.021mA
  67. FDC2214_Drive_Current_0_025 = 0x03, //0.025mA
  68. FDC2214_Drive_Current_0_028 = 0x04, //0.028mA
  69. FDC2214_Drive_Current_0_033 = 0x05, //0.033mA
  70. FDC2214_Drive_Current_0_038 = 0x06, //0.038mA
  71. FDC2214_Drive_Current_0_044 = 0x07, //0.044mA
  72. FDC2214_Drive_Current_0_052 = 0x08, //0.052mA
  73. FDC2214_Drive_Current_0_060 = 0x09, //0.060mA
  74. FDC2214_Drive_Current_0_069 = 0x0A, //0.069mA
  75. FDC2214_Drive_Current_0_081 = 0x0B, //0.081mA
  76. FDC2214_Drive_Current_0_093 = 0x0C, //0.093mA
  77. FDC2214_Drive_Current_0_108 = 0x0D, //0.108mA
  78. FDC2214_Drive_Current_0_126 = 0x0E, //0.126mA
  79. FDC2214_Drive_Current_0_146 = 0x0F, //0.146mA
  80. FDC2214_Drive_Current_0_169 = 0x10, //0.169mA
  81. FDC2214_Drive_Current_0_196 = 0x11, //0.196mA
  82. FDC2214_Drive_Current_0_228 = 0x12, //0.228mA
  83. FDC2214_Drive_Current_0_264 = 0x13, //0.264mA
  84. FDC2214_Drive_Current_0_307 = 0x14, //0.307mA
  85. FDC2214_Drive_Current_0_356 = 0x15, //0.356mA
  86. FDC2214_Drive_Current_0_413 = 0x16, //0.413mA
  87. FDC2214_Drive_Current_0_479 = 0x17, //0.479mA
  88. FDC2214_Drive_Current_0_555 = 0x18, //0.555mA
  89. FDC2214_Drive_Current_0_644 = 0x19, //0.644mA
  90. FDC2214_Drive_Current_0_747 = 0x1A, //0.747mA
  91. FDC2214_Drive_Current_0_867 = 0x1B, //0.867mA
  92. FDC2214_Drive_Current_1_006 = 0x1C, //1.006mA
  93. FDC2214_Drive_Current_1_167 = 0x1D, //1.167mA
  94. FDC2214_Drive_Current_1_354 = 0x1E, //1.354mA
  95. FDC2214_Drive_Current_1_571 = 0x1F //1.571mA
  96. } FDC2214_drive_current_t;
  97. extern uint32_t ch0,ch1,ch2,ch3;
  98. void FDC2214_Write16(SoftI2C_HandleTypeDef *iic, uint8_t Slve_Addr, uint8_t reg, uint16_t data);
  99. uint16_t FDC2214_Read16(SoftI2C_HandleTypeDef *iic, uint8_t Slve_Addr, uint8_t reg);
  100. uint8_t FDC2214_GetChannelData(SoftI2C_HandleTypeDef *iic, FDC2214_channel_t channel, uint32_t *data);
  101. void FDC2214_SetRcount(SoftI2C_HandleTypeDef *iic, FDC2214_channel_t channel, uint16_t rcount);
  102. void FDC2214_SetSettleCount(SoftI2C_HandleTypeDef *iic, FDC2214_channel_t channel, uint16_t count);
  103. void FDC2214_SetChannelClock(SoftI2C_HandleTypeDef *iic, FDC2214_channel_t channel, uint8_t frequency_select, uint16_t divider);
  104. void FDC2214_SetINTB(SoftI2C_HandleTypeDef *iic, uint8_t mode);
  105. void FDC2214_SetActiveChannel(SoftI2C_HandleTypeDef *iic, FDC2214_channel_t channel);
  106. void FDC2214_SetSleepMode(SoftI2C_HandleTypeDef *iic, uint8_t mode);
  107. void FDC2214_SetCurrentMode(SoftI2C_HandleTypeDef *iic, uint8_t mode);
  108. void FDC2214_SetClockSource(SoftI2C_HandleTypeDef *iic, uint8_t src);
  109. void FDC2214_SetHighCurrentMode(SoftI2C_HandleTypeDef *iic, uint8_t mode);
  110. void FDC2214_SetMUX_CONFIG(SoftI2C_HandleTypeDef *iic, uint8_t autoscan, FDC2214_channel_sequence_t channels, FDC2214_filter_bandwidth_t bandwidth);
  111. void FDC2214_Reset(SoftI2C_HandleTypeDef *iic);
  112. void FDC2214_SetDriveCurrent(SoftI2C_HandleTypeDef *iic, FDC2214_channel_t channel, FDC2214_drive_current_t current);
  113. double FDC2214_CalculateFrequency(FDC2214_channel_t channel, uint32_t datax);
  114. double FDC2214_CalculateCapacitance(double frequency, float inductance, float capacitance);
  115. uint8_t FDC2214_Init(SoftI2C_HandleTypeDef *iic );
  116. long filterread(SoftI2C_HandleTypeDef *iic, FDC2214_channel_t channel, uint32_t *data);
  117. double getcap(SoftI2C_HandleTypeDef *iic, uint8_t channel,double dg,double dr);
  118. void ProcessFDC2214(SoftI2C_HandleTypeDef* iic, osMessageQueueId_t queue, uint8_t* ready_flag, uint8_t* valid_flag, uint8_t channel, uint8_t inductor, uint8_t par_capacitor, float zeroValue, uint8_t device_index);
  119. void CheckFDC2214_ID(SoftI2C_HandleTypeDef* iic, uint8_t device_index, uint8_t* deviceValid);
  120. #endif