1
0

lux.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef __TSL_2561__
  2. #define __TSL_2561__
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/queue.h"
  5. #include <stdint.h>
  6. void init_tsl2561();
  7. typedef enum
  8. {
  9. TSL2561_INTEGRATIONTIME_13MS = 0x00, // 13.7ms
  10. TSL2561_INTEGRATIONTIME_101MS = 0x01, // 101ms
  11. TSL2561_INTEGRATIONTIME_402MS = 0x02 // 402ms
  12. }
  13. tsl2561IntegrationTime_t;
  14. typedef enum
  15. {
  16. TSL2561_GAIN_1X = 0x00, // No gain
  17. TSL2561_GAIN_16X = 0x10, // 16x gain
  18. }
  19. tsl2561Gain_t;
  20. #define TSL2561_COMMAND_BIT (0x80) // Must be 1
  21. #define TSL2561_CLEAR_BIT (0x40) // Clears any pending interrupt (write 1 to clear)
  22. #define TSL2561_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
  23. #define TSL2561_BLOCK_BIT (0x10) // 1 = using block read/write
  24. #define TSL2561_CONTROL_POWERON (0x03)
  25. #define TSL2561_CONTROL_POWEROFF (0x00)
  26. // Auto-gain thresholds
  27. #define TSL2561_AGC_THI_13MS (4850) // Max value at Ti 13ms = 5047
  28. #define TSL2561_AGC_TLO_13MS (100)
  29. #define TSL2561_AGC_THI_101MS (36000) // Max value at Ti 101ms = 37177
  30. #define TSL2561_AGC_TLO_101MS (200)
  31. #define TSL2561_AGC_THI_402MS (63000) // Max value at Ti 402ms = 65535
  32. #define TSL2561_AGC_TLO_402MS (500)
  33. #define TSL2561_DELAY_INTTIME_13MS (15)
  34. #define TSL2561_DELAY_INTTIME_101MS (120)
  35. #define TSL2561_DELAY_INTTIME_402MS (450)
  36. #define TSL2561_CLIPPING_13MS (4900)
  37. #define TSL2561_CLIPPING_101MS (37000)
  38. #define TSL2561_CLIPPING_402MS (65000)
  39. #define TSL2561_LUX_LUXSCALE (14) // Scale by 2^14
  40. #define TSL2561_LUX_RATIOSCALE (9) // Scale ratio by 2^9
  41. #define TSL2561_LUX_CHSCALE (10) // Scale channel values by 2^10
  42. #define TSL2561_LUX_CHSCALE_TINT0 (0x7517) // 322/11 * 2^TSL2561_LUX_CHSCALE
  43. #define TSL2561_LUX_CHSCALE_TINT1 (0x0FE7) // 322/81 * 2^TSL2561_LUX_CHSCALE
  44. // T, FN and CL package values
  45. #define TSL2561_LUX_K1T (0x0040) // 0.125 * 2^RATIO_SCALE
  46. #define TSL2561_LUX_B1T (0x01f2) // 0.0304 * 2^LUX_SCALE
  47. #define TSL2561_LUX_M1T (0x01be) // 0.0272 * 2^LUX_SCALE
  48. #define TSL2561_LUX_K2T (0x0080) // 0.250 * 2^RATIO_SCALE
  49. #define TSL2561_LUX_B2T (0x0214) // 0.0325 * 2^LUX_SCALE
  50. #define TSL2561_LUX_M2T (0x02d1) // 0.0440 * 2^LUX_SCALE
  51. #define TSL2561_LUX_K3T (0x00c0) // 0.375 * 2^RATIO_SCALE
  52. #define TSL2561_LUX_B3T (0x023f) // 0.0351 * 2^LUX_SCALE
  53. #define TSL2561_LUX_M3T (0x037b) // 0.0544 * 2^LUX_SCALE
  54. #define TSL2561_LUX_K4T (0x0100) // 0.50 * 2^RATIO_SCALE
  55. #define TSL2561_LUX_B4T (0x0270) // 0.0381 * 2^LUX_SCALE
  56. #define TSL2561_LUX_M4T (0x03fe) // 0.0624 * 2^LUX_SCALE
  57. #define TSL2561_LUX_K5T (0x0138) // 0.61 * 2^RATIO_SCALE
  58. #define TSL2561_LUX_B5T (0x016f) // 0.0224 * 2^LUX_SCALE
  59. #define TSL2561_LUX_M5T (0x01fc) // 0.0310 * 2^LUX_SCALE
  60. #define TSL2561_LUX_K6T (0x019a) // 0.80 * 2^RATIO_SCALE
  61. #define TSL2561_LUX_B6T (0x00d2) // 0.0128 * 2^LUX_SCALE
  62. #define TSL2561_LUX_M6T (0x00fb) // 0.0153 * 2^LUX_SCALE
  63. #define TSL2561_LUX_K7T (0x029a) // 1.3 * 2^RATIO_SCALE
  64. #define TSL2561_LUX_B7T (0x0018) // 0.00146 * 2^LUX_SCALE
  65. #define TSL2561_LUX_M7T (0x0012) // 0.00112 * 2^LUX_SCALE
  66. #define TSL2561_LUX_K8T (0x029a) // 1.3 * 2^RATIO_SCALE
  67. #define TSL2561_LUX_B8T (0x0000) // 0.000 * 2^LUX_SCALE
  68. #define TSL2561_LUX_M8T (0x0000) // 0.000 * 2^LUX_SCALE
  69. #endif