summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-05-15 19:45:57 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-05-15 19:45:57 +0200
commit71e891f2284e5afb47ab6d24383058dd97230355 (patch)
tree047c5649e25abc0eb1956e7081af35fdfdd9656a /src/driver
parent14e405f5152c99e3e2db9948a8cee780e1af04a3 (diff)
add driver stub for Sensirion SEN5x PM sensor
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/Kconfig4
-rw-r--r--src/driver/sen5x.cc51
2 files changed, 55 insertions, 0 deletions
diff --git a/src/driver/Kconfig b/src/driver/Kconfig
index 5f544ac..581ef10 100644
--- a/src/driver/Kconfig
+++ b/src/driver/Kconfig
@@ -119,6 +119,10 @@ config driver_scd4x
bool "Sensirion SCD4x CO2 Sensor"
depends on meta_driver_i2c
+config driver_sen5x
+bool "Sensirion SEN5x PM Sensor"
+depends on meta_driver_i2c
+
config driver_veml6075
bool "VEML6075 UV Sensor"
depends on meta_driver_i2c
diff --git a/src/driver/sen5x.cc b/src/driver/sen5x.cc
new file mode 100644
index 0000000..2a5d6b8
--- /dev/null
+++ b/src/driver/sen5x.cc
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2021 Daniel Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "arch.h"
+#include "driver/sen5x.h"
+#if defined(CONFIG_meta_driver_hardware_i2c)
+#include "driver/i2c.h"
+#elif defined(CONFIG_driver_softi2c)
+#include "driver/soft_i2c.h"
+#endif
+
+void SEN5x::start()
+{
+ txbuf[0] = 0x00;
+ txbuf[1] = 0x21;
+ i2c.xmit(address, 2, txbuf, 0, rxbuf);
+}
+
+void SEN5x::stop()
+{
+ txbuf[0] = 0x01;
+ txbuf[1] = 0x04;
+ i2c.xmit(address, 2, txbuf, 0, rxbuf);
+}
+
+bool SEN5x::read()
+{
+ txbuf[0] = 0x03;
+ txbuf[1] = 0xc4;
+
+ if (i2c.xmit(address, 2, txbuf, 0, rxbuf)) {
+ return false;
+ }
+ arch.delay_ms(20);
+ if (i2c.xmit(address, 0, txbuf, 24, rxbuf)) {
+ return false;
+ }
+ pm1 = (rxbuf[0] << 8) + rxbuf[1];
+ pm2_5 = (rxbuf[3] << 8) + rxbuf[4];
+ pm4 = (rxbuf[6] << 8) + rxbuf[7];
+ pm10 = (rxbuf[9] << 8) + rxbuf[10];
+ humidity = (rxbuf[12] << 8) + rxbuf[13];
+ temperature = (rxbuf[15] << 8) + rxbuf[16];
+ voc = (rxbuf[18] << 8) + rxbuf[19];
+ nox = (rxbuf[21] << 8) + rxbuf[22];
+ return true;
+}
+
+SEN5x sen5x;