summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/i2cdetect/main.cc18
-rw-r--r--src/driver/ccs811.cc72
2 files changed, 82 insertions, 8 deletions
diff --git a/src/app/i2cdetect/main.cc b/src/app/i2cdetect/main.cc
index 4d6ebe9..92c812c 100644
--- a/src/app/i2cdetect/main.cc
+++ b/src/app/i2cdetect/main.cc
@@ -125,7 +125,13 @@ void loop(void)
kout << "BME680 gas resistance " << data.gas_resistance << endl;
#endif
#ifdef DRIVER_CCS811
- kout << "CCS811 status is " << ccs811.check() << endl;
+ ccs811.read();
+ kout << "CCS811 eCO₂ : " << ccs811.eco2 << " ppm" << endl;
+ kout << "CCS811 tVOC : " << ccs811.tvoc << " ppb" << endl;
+ kout << bin;
+ kout << "CCS811 status: " << ccs811.status << endl;
+ kout << "CCS811 error: " << ccs811.error_id << endl;
+ kout << dec;
#endif
#ifdef DRIVER_HDC1080
/*
@@ -186,7 +192,17 @@ int main(void)
kout << "I2C setup OK" << endl;
#ifdef DRIVER_CCS811
+ kout << hex;
+ kout << "CCS811 HWID: " << ccs811.getManufacturerID() << endl;
+ arch.delay_ms(65);
+ kout << "CCS811 status: " << ccs811.getStatus() << endl;
+ arch.delay_ms(65);
ccs811.init();
+ arch.delay_ms(65);
+ kout << "CCS811 status: " << ccs811.getStatus() << endl;
+ kout << dec;
+ ccs811.setMode(1);
+ //arch.delay_ms(50);
#endif
#ifdef DRIVER_HDC1080
hdc1080.init();
diff --git a/src/driver/ccs811.cc b/src/driver/ccs811.cc
index ad0eabc..8c16b8a 100644
--- a/src/driver/ccs811.cc
+++ b/src/driver/ccs811.cc
@@ -17,18 +17,76 @@
void CCS811::init()
{
- gpio.output(nWAKE);
- gpio.write(nWAKE, 1);
+ startFirmware();
+ //setMode(1);
+ //setEnv(50, 0, 0, 0);
}
-short CCS811::check()
+// switch to Application mode
+void CCS811::startFirmware()
+{
+ if (getStatus() & 0x10) {
+ txbuf[0] = 0xf4;
+ i2c.xmit(address, 1, txbuf, 0, rxbuf);
+ }
+}
+
+unsigned char CCS811::getManufacturerID()
{
- 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);
+void CCS811::setMode(unsigned char mode)
+{
+ txbuf[0] = 0x01;
+ txbuf[1] = (mode & 0x07) << 4;
+ i2c.xmit(address, 2, txbuf, 0, rxbuf);
+}
+
+void CCS811::read()
+{
+ txbuf[0] = 0x02;
+ i2c.xmit(address, 1, txbuf, 8, rxbuf);
+ eco2 = (rxbuf[0] << 8) + rxbuf[1];
+ tvoc = (rxbuf[2] << 8) + rxbuf[3];
+ status = rxbuf[4];
+ error_id = rxbuf[5];
+}
+
+void CCS811::setEnv(unsigned char humi, unsigned char humi_fraction, unsigned char temp, unsigned char temp_fraction)
+{
+ txbuf[0] = 0x05;
+ txbuf[1] = humi;
+ txbuf[2] = humi_fraction;
+ txbuf[3] = temp; //((temp - 25) << 1) + (((temp - 25) & 0x80) >> 7);
+ txbuf[4] = temp_fraction; //(temp << 1) + ((temp & 0x80) >> 7);
+ i2c.xmit(address, 5, txbuf, 0, rxbuf);
+}
+
+unsigned char CCS811::getStatus()
+{
+ txbuf[0] = 0x00;
+ i2c.xmit(address, 1, txbuf, 1, rxbuf);
+ return rxbuf[0];
+}
+
+unsigned char CCS811::getError()
+{
+ txbuf[0] = 0xe0;
+ i2c.xmit(address, 1, txbuf, 1, rxbuf);
+ return rxbuf[0];
+}
+
+// switch to Bootloader mode
+void CCS811::reset()
+{
+ txbuf[0] = 0xff;
+ txbuf[1] = 0x11;
+ txbuf[2] = 0xe5;
+ txbuf[3] = 0x72;
+ txbuf[4] = 0x8a;
+}
+
+CCS811 ccs811;