BH1750.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * BH1750.h
  3. *
  4. * The MIT License.
  5. * Created on: 06.11.2022
  6. * Author: Oleksii Kutuzov
  7. *
  8. * Ported from:
  9. * https://github.com/lamik/Light_Sensors_STM32
  10. */
  11. #include <furi.h>
  12. #include <furi_hal.h>
  13. #ifndef BH1750_H_
  14. #define BH1750_H_
  15. // I2C BUS
  16. #define I2C_BUS &furi_hal_i2c_handle_external
  17. #define I2C_TIMEOUT 10
  18. #define BH1750_ADDRESS (0x23 << 1)
  19. #define BH1750_POWER_DOWN 0x00
  20. #define BH1750_POWER_ON 0x01
  21. #define BH1750_RESET 0x07
  22. #define BH1750_DEFAULT_MTREG 69
  23. #define BH1750_DEFAULT_MODE ONETIME_HIGH_RES_MODE
  24. #define BH1750_CONVERSION_FACTOR 1.2
  25. typedef enum { BH1750_OK = 0, BH1750_ERROR = 1 } BH1750_STATUS;
  26. typedef enum {
  27. CONTINUOUS_HIGH_RES_MODE = 0x10,
  28. CONTINUOUS_HIGH_RES_MODE_2 = 0x11,
  29. CONTINUOUS_LOW_RES_MODE = 0x13,
  30. ONETIME_HIGH_RES_MODE = 0x20,
  31. ONETIME_HIGH_RES_MODE_2 = 0x21,
  32. ONETIME_LOW_RES_MODE = 0x23
  33. } BH1750_mode;
  34. BH1750_STATUS bh1750_init();
  35. BH1750_STATUS bh1750_reset();
  36. BH1750_STATUS bh1750_set_power_state(uint8_t PowerOn);
  37. BH1750_STATUS bh1750_set_mt_reg(uint8_t MTreg);
  38. BH1750_STATUS bh1750_set_mode(BH1750_mode Mode);
  39. BH1750_STATUS bh1750_trigger_manual_conversion();
  40. BH1750_STATUS bh1750_read_light(float* Result);
  41. #endif /* BH1750_H_ */