sht20.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-08-08 Ernest Chen the first version
  9. */
  10. #ifndef __SHT20_H__
  11. #define __SHT20_H__
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include <rthw.h>
  15. #include <rtdevice.h>
  16. #ifdef SHT20_USING_SOFT_FILTER
  17. typedef struct filter_data
  18. {
  19. float buf[SHT20_AVERAGE_TIMES];
  20. float average;
  21. rt_off_t index;
  22. rt_bool_t is_full;
  23. } filter_data_t;
  24. #endif /* SHT20_USING_SOFT_FILTER */
  25. struct sht20_device
  26. {
  27. struct rt_i2c_bus_device *i2c;
  28. #ifdef SHT20_USING_SOFT_FILTER
  29. filter_data_t temp_filter;
  30. filter_data_t humi_filter;
  31. rt_thread_t thread;
  32. rt_uint32_t period;
  33. #endif /* SHT20_USING_SOFT_FILTER */
  34. rt_mutex_t lock;
  35. };
  36. typedef struct sht20_device *sht20_device_t;
  37. enum sht20_param_type
  38. {
  39. SHT20_PARAM_PRECISION,
  40. SHT20_PARAM_BATTERY_STATUS,
  41. SHT20_PARAM_HEATING,
  42. };
  43. typedef enum sht20_param_type sht20_param_type_t;
  44. /**
  45. * This function resets all parameter with default
  46. *
  47. * @param dev the pointer of device driver structure
  48. *
  49. * @return the softreset status,RT_EOK reprensents setting successfully.
  50. */
  51. rt_err_t sht20_softreset(sht20_device_t dev);
  52. /**
  53. * This function initializes sht20 registered device driver
  54. *
  55. * @param dev the name of sht20 device
  56. *
  57. * @return the sht20 device.
  58. */
  59. sht20_device_t sht20_init(const char *i2c_bus_name);
  60. /**
  61. * This function releases memory and deletes mutex lock
  62. *
  63. * @param dev the pointer of device driver structure
  64. */
  65. void sht20_deinit(sht20_device_t dev);
  66. /**
  67. * This function reads temperature by sht20 sensor measurement
  68. *
  69. * @param dev the pointer of device driver structure
  70. *
  71. * @return the relative temperature converted to float data.
  72. */
  73. float sht20_read_temperature(sht20_device_t dev);
  74. /**
  75. * This function reads relative humidity by sht20 sensor measurement
  76. *
  77. * @param dev the pointer of device driver structure
  78. *
  79. * @return the relative humidity converted to float data.
  80. */
  81. float sht20_read_humidity(sht20_device_t dev);
  82. /**
  83. * This function sets parameter of sht20 sensor
  84. *
  85. * @param dev the pointer of device driver structure
  86. * @param type the parameter type of device
  87. * @param value the pointer value of type
  88. *
  89. * @return the setting parameter status,RT_EOK reprensents setting successfully.
  90. */
  91. rt_err_t sht20_set_param(sht20_device_t dev, sht20_param_type_t type, rt_uint8_t value);
  92. /**
  93. * This function gest parameter of sht20 sensor
  94. *
  95. * @param dev the pointer of device driver structure
  96. * @param type the parameter type of device
  97. * @param value the pointer value of type
  98. *
  99. * @return the getting parameter status,RT_EOK reprensents getting successfully.
  100. */
  101. rt_err_t sht20_get_param(sht20_device_t dev, sht20_param_type_t type, rt_uint8_t *value);
  102. #endif /* _SHT20_H__ */