nrf_sht30_simulate.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef SHT30_SIM_H__
  2. #define SHT30_SIM_H__
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include "define.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define SHT30_DATA_MAXIDX 3
  10. #ifdef SHT30_RST
  11. #define SHT30_RST_LOW nrf_gpio_pin_write(SHT30_RST, 0);
  12. #define SHT30_RST_HIGH nrf_gpio_pin_write(SHT30_RST, 1);
  13. #endif
  14. typedef enum
  15. {
  16. SHT30_QUEUE_TIME=0,
  17. SHT30_QUEUE_INT=1,
  18. SHT30_QUEUE_TIMEOUT=2,
  19. }SHT30_QUEUE_TYPE;
  20. typedef enum{
  21. SHT30_NULL,
  22. SHT30_WR,
  23. SHT30_RD,
  24. SHT30_DATA,
  25. }sht30_work_stat;
  26. #define SHT30_ADDR0 (uint8_t)(0x45<<1) //sht30 i2c地址,ADDR管脚接低电平时为0x44,接高电平为0x45
  27. #define SHT30_ADDR1 (uint8_t)(0x44<<1) //sht30 i2c地址,ADDR管脚接低电平时为0x44,接高电平为0x45
  28. //SHT30命令
  29. #define SHT30_READ_HUMITURE (uint16_t)0x2c06 //读温湿度
  30. //CRC多项式
  31. #define POLYNOMIAL_CXDZ 0x31 // X^8 + X^5 + X^4 + 1
  32. typedef void (*sht30_finish_func)(bool stat);
  33. typedef struct SHT30_STRUCT_t{
  34. sht30_finish_func finish_func;
  35. sht30_work_stat sht30_stat;
  36. bool addr_pin;
  37. uint8_t sht30_timeout;
  38. uint8_t idx;
  39. uint8_t buff[6];
  40. int16_t temperature[SHT30_DATA_MAXIDX];
  41. int16_t humi[SHT30_DATA_MAXIDX];
  42. }sht30_work_s;
  43. typedef struct{
  44. bool sht30_stat;
  45. int16_t temperature_value;
  46. int16_t humi_value;
  47. }sht30_data_s;
  48. void sht30_timers_init(void);
  49. void Sht30_Start(void);
  50. void sht30_i2c_init(void);
  51. void sht30_i2c_uinit(void);
  52. void set_Sht30_finish_func(sht30_finish_func func);
  53. void Set_Sht30_Queue(SHT30_QUEUE_TYPE type);
  54. void Sht30_Switch_Addr(bool stat);
  55. #ifdef SHT30_RST
  56. void Sht30_Gpio_Init(void);
  57. void Sht30_Reset(void);
  58. #endif
  59. extern sht30_data_s sht30_data;
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif // SHT30_H__
  64. /** @} */