summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/driver/ccs811.h20
-rw-r--r--include/driver/max44006.h21
-rw-r--r--include/driver/max44009.h19
-rw-r--r--src/driver/ccs811.cc29
-rw-r--r--src/driver/max44006.cc71
-rw-r--r--src/driver/max44009.cc40
6 files changed, 200 insertions, 0 deletions
diff --git a/include/driver/ccs811.h b/include/driver/ccs811.h
new file mode 100644
index 0000000..27d7e41
--- /dev/null
+++ b/include/driver/ccs811.h
@@ -0,0 +1,20 @@
+#ifndef CCS811_H
+#define CCS811_H
+
+class CCS811 {
+ private:
+ CCS811(const CCS811 &copy);
+ unsigned char const address;
+ unsigned char txbuf[3];
+ unsigned char rxbuf[2];
+
+ public:
+ CCS811(unsigned char const addr) : address(addr) {}
+
+ void init();
+ short check();
+};
+
+extern CCS811 ccs811;
+
+#endif
diff --git a/include/driver/max44006.h b/include/driver/max44006.h
new file mode 100644
index 0000000..e357574
--- /dev/null
+++ b/include/driver/max44006.h
@@ -0,0 +1,21 @@
+#ifndef LM75_H
+#define LM75_H
+
+class LM75 {
+ private:
+ LM75(const LM75 &copy);
+ unsigned char const address;
+ unsigned char txbuf[3];
+ unsigned char rxbuf[2];
+
+ public:
+ LM75(unsigned char const addr) : address(addr) {}
+
+ float getTemp();
+ void setOS(unsigned char os);
+ void setHyst(unsigned char hyst);
+};
+
+extern LM75 lm75;
+
+#endif
diff --git a/include/driver/max44009.h b/include/driver/max44009.h
new file mode 100644
index 0000000..6bedd3c
--- /dev/null
+++ b/include/driver/max44009.h
@@ -0,0 +1,19 @@
+#ifndef MAX44009_H
+#define MAX44009_H
+
+class MAX44009 {
+ private:
+ MAX44009(const MAX44009 &copy);
+ unsigned char const address;
+ unsigned char txbuf[2];
+ unsigned char rxbuf[2];
+
+ public:
+ MAX44009(unsigned char const addr) : address(addr) {}
+
+ float getLux();
+};
+
+extern MAX44009 max44009;
+
+#endif
diff --git a/src/driver/ccs811.cc b/src/driver/ccs811.cc
new file mode 100644
index 0000000..a2b3940
--- /dev/null
+++ b/src/driver/ccs811.cc
@@ -0,0 +1,29 @@
+#include "driver/ccs811.h"
+#include "driver/gpio.h"
+#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
+#include "driver/i2c.h"
+#else
+#include "driver/soft_i2c.h"
+#endif
+
+#ifdef MULTIPASS_ARCH_esp8266
+#define nWAKE GPIO::d5
+#endif
+
+void CCS811::init()
+{
+ gpio.output(nWAKE);
+ gpio.write(nWAKE, 1);
+}
+
+short CCS811::check()
+{
+ gpio.write(nWAKE, 0);
+ txbuf[0] = 0x20;
+ rxbuf[0] = 0;
+ i2c.xmit(address, 1, txbuf, 1, rxbuf);
+ gpio.write(nWAKE, 1);
+ return rxbuf[0];
+}
+
+CCS811 ccs811(0x5a);
diff --git a/src/driver/max44006.cc b/src/driver/max44006.cc
new file mode 100644
index 0000000..a61e7df
--- /dev/null
+++ b/src/driver/max44006.cc
@@ -0,0 +1,71 @@
+#include "driver/max44006.h"
+#include "arch.h"
+#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
+#include "driver/i2c.h"
+#else
+#include "driver/soft_i2c.h"
+#endif
+
+signed char MAX44006::setup()
+{
+ txbuf[0] = 0;
+ txbuf[1] = 0;
+ i2c.xmit(2, txbuf, 0, rxbuf);
+
+ arch.delay_us(10);
+
+ txbuf[0] = 0x01;
+ txbuf[1] = 0x20;
+ i2c.xmit(2, txbuf, 0, rxbuf);
+
+ arch.delay_us(10);
+
+ txbuf[0] = 0x02;
+ txbuf[1] = 0x02;
+ i2c.xmit(2, txbuf, 0, rxbuf);
+
+ return 0;
+}
+
+void MAX44006::wakeup()
+{
+ txbuf[0] = 0;
+ txbuf[1] = 0;
+ i2c.xmit(2, txbuf, 0, rxbuf);
+}
+
+void MAX44006::sleep()
+{
+ txbuf[0] = 0x00;
+ txbuf[1] = 0x08;
+
+ i2c.xmit(2, txbuf, 0, rxbuf);
+}
+
+float LM75::getTemp()
+{
+ txbuf[0] = 0;
+ rxbuf[0] = 0;
+ rxbuf[1] = 0;
+ i2c.xmit(address, 1, txbuf, 2, rxbuf);
+
+ return rxbuf[0] + (rxbuf[1] / 256.0);
+}
+
+void LM75::setOS(unsigned char os)
+{
+ txbuf[0] = 0x03;
+ txbuf[1] = os;
+ txbuf[2] = 0;
+ i2c.xmit(address, 3, txbuf, 0, rxbuf);
+}
+
+void LM75::setHyst(unsigned char hyst)
+{
+ txbuf[0] = 0x02;
+ txbuf[1] = hyst;
+ txbuf[2] = 0;
+ i2c.xmit(address, 3, txbuf, 0, rxbuf);
+}
+
+MAX44006 max44006(0x45);
diff --git a/src/driver/max44009.cc b/src/driver/max44009.cc
new file mode 100644
index 0000000..3981e79
--- /dev/null
+++ b/src/driver/max44009.cc
@@ -0,0 +1,40 @@
+#include "driver/max44009.h"
+#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
+#include "driver/i2c.h"
+#else
+#include "driver/soft_i2c.h"
+#endif
+
+float MAX44009::getLux()
+{
+ unsigned char luxHigh;
+ unsigned char luxLow;
+ unsigned int mantissa, exponent;
+
+ txbuf[0] = 0x03;
+ txbuf[1] = 0x04;
+
+ i2c.xmit(address, 2, txbuf, 2, rxbuf);
+
+ luxHigh = rxbuf[0];
+ luxLow = rxbuf[1];
+
+ /*
+ * The lowest 4 bit of luxLow are the lowest 4 bit of the mantissa.
+ * The lowest 4 bit of luxHigh are the highest 4 bit of the mantissa.
+ */
+ mantissa = (luxLow & 0x0F) + ((luxHigh & 0x0F) << 4);
+
+ /*
+ * The highest 4 bit of luxHigh are the 4 bit exponent
+ */
+ exponent = (luxHigh & 0xF0) >> 4;
+
+ /*
+ * Cast base and mantissa to float to avoid calculation errors
+ * because of 16bit integer overflows.
+ */
+ return (float)(1 << exponent) * (float)mantissa * 0.045;
+}
+
+MAX44009 max44009(0x4a);