summaryrefslogtreecommitdiffstats
path: root/apps/Light Meter/tsl2591.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/Light Meter/tsl2591.h')
-rw-r--r--apps/Light Meter/tsl2591.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/apps/Light Meter/tsl2591.h b/apps/Light Meter/tsl2591.h
new file mode 100644
index 00000000..feecd99c
--- /dev/null
+++ b/apps/Light Meter/tsl2591.h
@@ -0,0 +1,46 @@
+#ifndef TSL2591_H_INCLUDED
+#define TSL2591_H_INCLUDED
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#define TSL2591_ADDRESS (0x29)
+#define TSL2591_COMMAND_BIT (0xA0)
+
+typedef enum TSL2591Register {
+ TSL2591_REGISTER_ENABLE = 0x00,
+ TSL2591_REGISTER_CONTROL = 0x01,
+ TSL2591_REGISTER_DEVICE_ID = 0x12,
+ TSL2591_REGISTER_CHAN0_LOW = 0x14,
+ TSL2591_REGISTER_CHAN1_LOW = 0x16,
+} TSL2591Register;
+
+typedef enum TSL2591Control {
+ TSL2591_CONTROL_INTEGRATIONTIME_100MS = 0x00,
+ TSL2591_CONTROL_INTEGRATIONTIME_200MS = 0x01,
+ TSL2591_CONTROL_INTEGRATIONTIME_300MS = 0x02,
+ TSL2591_CONTROL_INTEGRATIONTIME_400MS = 0x03,
+ TSL2591_CONTROL_INTEGRATIONTIME_500MS = 0x04,
+ TSL2591_CONTROL_INTEGRATIONTIME_600MS = 0x05,
+ TSL2591_CONTROL_GAIN_LOW = 0x00,
+ TSL2591_CONTROL_GAIN_MEDIUM = 0x10,
+ TSL2591_CONTROL_GAIN_HIGH = 0x20,
+ TSL2591_CONTROL_GAIN_MAX = 0x30
+} TSL2591Control;
+
+typedef enum TSL2591Enable {
+ TSL2591_ENABLE_POWEROFF = 0x00,
+ TSL2591_ENABLE_POWERON = 0x01,
+ TSL2591_ENABLE_AEN = 0x02,
+ TSL2591_ENABLE_AIEN = 0x10,
+ TSL2591_ENABLE_NPIEN = 0x80,
+} TSL2591Enable;
+
+inline uint16_t make_le_16(uint16_t val) { return (val >> 8) | (val << 8); }
+
+bool tsl2591_init();
+void tsl2591_set_gain(TSL2591Control gain);
+void tsl2591_set_integration_time(TSL2591Control integration_time);
+uint16_t tsl2591_get_visible_light_reading();
+
+#endif // TSL2591_H_INCLUDED