van_BSP_Temp_mts01.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /******************************************************************************
  2. *Copyright(C),2024-2024,万众一芯生
  3. *van_BSP_Temp_mts01.h
  4. *mts01 温度相关驱动接口
  5. *修改历史
  6. author 范义东 新建 2024/01/27
  7. ******************************************************************************/
  8. #ifndef __VAN_BSP_TEMP_MTS01_H
  9. #define __VAN_BSP_TEMP_MTS01_H
  10. #ifndef bool
  11. typedef enum
  12. {
  13. false = 0,
  14. true = 1,
  15. False = 0,
  16. True = 1,
  17. } bool;
  18. #endif
  19. #define ARR_LEN(array)(sizeof(array) / sizeof(array[0]))
  20. typedef enum
  21. {
  22. CONVERT_T = 0xCC44, //Measure temperature
  23. BREAK = 0x3093, //Abort period measurement
  24. READ_STATUSCONFIG = 0xf32d, //Read status and configuration registers
  25. CLEAR_STATUS = 0x3041, //Clear status register
  26. WRITE_CONFIG = 0x5206, //Write configuration register
  27. READ_ALERT_HI_SET = 0xe11f, //Read the upper alarm thresholdvalue
  28. READ_ALERT_LO_SET = 0xe102, //Read the lower alarm threshold value
  29. WRITE_ALERT_HI_SET = 0x611d, //Set the upper alarm threshold value
  30. WRITE_ALERT_LO_SET = 0x6100, //Set the lower alarm threshold value
  31. WRITE_ALERT_LO_UNSET = 0x610b, //Set the alarm clear threshold lower threshold
  32. WRITE_ALERT_HI_UNSET = 0x6116, //Set the alarm clear threshold upper threshold
  33. READ_ALERT_HI_UNSET = 0xe114, //Read Alarm Clear Threshold Upper Threshold
  34. READ_ALERT_LO_UNSET = 0xe109, //Read Alarm Clear Threshold Lower Threshold
  35. COPY_PAGE0 = 0xcc48, //Save page0 to EEPROM
  36. RECALL_EE = 0xccb8, //Recall EEPROM area
  37. RECALL_PAGE0_RES = 0xccbb, //Restore the residual area of page0
  38. SOFT_RST = 0x30a2, //Software reset
  39. } I2C_CMD;
  40. /*Bit definition of config register*/
  41. #define CFG_MPS_Mask (0x1C)
  42. #define CFG_Repeatbility_Mask (0x03)
  43. #define CFG_MPS_Single (0x00)
  44. #define CFG_MPS_Half (0x04)
  45. #define CFG_MPS_1 (0x08)
  46. #define CFG_MPS_2 (0x0C)
  47. #define CFG_MPS_4 (0x10)
  48. #define CFG_MPS_10 (0x14)
  49. #define CFG_Repeatbility_Low (0x00)
  50. #define CFG_Repeatbility_Medium (0x01)
  51. #define CFG_Repeatbility_High (0x02)
  52. #define POLYNOMIAL 0x131 // 100110001
  53. /*Definition of conversion time corresponding to repeatability setting*/
  54. /*The default low/medium/high repeatability corresponds to the conversion time of 4/6/11ms respectively.
  55. Considering the delay deviation of different users of the microcontroller, reserve 2ms to ensure sufficient conversion time*/
  56. #define tConvert_LowRepeat (6) /* ms. */
  57. #define tConvert_MedRepeat (8) /* ms. */
  58. #define tConvert_HighRepeat (13) /* ms. */
  59. #define TEMP_MTS01_MAX_AVG_TIME 10 /*最多10次缓存用于求平均*/
  60. #define MTS01_ADDR0 (0x44<<1 ) /* Addr */
  61. #define MTS01_ADDR1 (0x45<<1 ) /* Addr */
  62. #define TEMP_MTS01NAMEANDID(chanle) .tempID = chanle, .Name = #chanle
  63. typedef enum
  64. {
  65. TEMP_BLOCK,
  66. } TEMP_MTS01_V1;
  67. typedef enum _EnmFuntionIdType {
  68. EnmFuntionIdType_IdNull = 0,
  69. EnmFuntionIdType_Idhost = 1, /* 主机 */
  70. } EnmFuntionIdType;
  71. typedef struct
  72. {
  73. unsigned int tempID; //温区编号
  74. unsigned char Name[16]; //温区名称
  75. void *I2C; /*IIC端口 端口*/
  76. unsigned int addr; /*CS 端口*/
  77. unsigned int maxlen; /*CS 端口*/
  78. unsigned int header; /*CS 端口*/
  79. float temp[TEMP_MTS01_MAX_AVG_TIME];
  80. unsigned int isload; /*CS 端口*/
  81. } VAN_TEMP_MTS01_CON_ST_Def, *P_VAN_TEMP_MTS01_CON_ST_Def;
  82. typedef struct
  83. {
  84. unsigned int id; //设备id
  85. unsigned int feed_channel; //测温通道
  86. float temp; //温度值
  87. } VAN_TEMP_CHANNEl_CON_ST_Def, *P_VAN_TEMP_CHANNEl_CON_ST_Def;
  88. bool MTS01_ReadTemp(unsigned char runMtsId, float *pTemp);
  89. bool MTS01_Temp_get(uint32_t runMtsId, float *Value);
  90. unsigned int loadTemp_mts01Cfg(void);
  91. #endif