summaryrefslogtreecommitdiff
path: root/src/driver/tsl2591.cc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-02-25 23:09:34 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-02-25 23:09:34 +0100
commit9a3d3bcc93f8cefea74af2a86b5834a57738e2c3 (patch)
tree6684318cfae0f6761b657a263db96472e78ec8d6 /src/driver/tsl2591.cc
parent4e70dc99f2fe61235c7e23739f91e3f7e2fff837 (diff)
add simple TSL2591 illuminance / IR sensor driver
Diffstat (limited to 'src/driver/tsl2591.cc')
-rw-r--r--src/driver/tsl2591.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/driver/tsl2591.cc b/src/driver/tsl2591.cc
new file mode 100644
index 0000000..6356477
--- /dev/null
+++ b/src/driver/tsl2591.cc
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2020 Daniel Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/tsl2591.h"
+#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
+#include "driver/i2c.h"
+#else
+#include "driver/soft_i2c.h"
+#endif
+
+void TSL2591::init()
+{
+ txbuf[0] = 0xa0;
+ txbuf[1] = 0x03;
+ i2c.xmit(address, 2, txbuf, 0, rxbuf);
+ txbuf[0] = 0xa1;
+ txbuf[1] = 0x01; // 200ms integration time
+ i2c.xmit(address, 2, txbuf, 0, rxbuf);
+}
+
+void TSL2591::read()
+{
+ txbuf[0] = 0xb4;
+ i2c.xmit(address, 1, txbuf, 4, rxbuf);
+ ch0 = (rxbuf[1] << 8) + rxbuf[0];
+ ch1 = (rxbuf[3] << 8) + rxbuf[2];
+}
+
+unsigned char TSL2591::getStatus()
+{
+ txbuf[0] = 0xb3;
+ i2c.xmit(address, 1, txbuf, 1, rxbuf);
+ return rxbuf[0];
+}
+
+TSL2591 tsl2591;