From ef21ef02691c3ebdaa44d3c1ad78c6b0297ea562 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Thu, 15 Oct 2020 01:38:15 +0200
Subject: [PATCH] fix(max86150): Turn off sensor at boot

---
 epicardium/modules/hardware.c |  3 +++
 epicardium/modules/max86150.c | 19 ++++++-------------
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/epicardium/modules/hardware.c b/epicardium/modules/hardware.c
index 055ae486b..a05c65f38 100644
--- a/epicardium/modules/hardware.c
+++ b/epicardium/modules/hardware.c
@@ -13,6 +13,7 @@
 #include "pb.h"
 #include "pmic.h"
 #include "portexpander.h"
+#include "max86150.h"
 
 #include "gpio.h"
 #include "i2c.h"
@@ -191,6 +192,8 @@ int hardware_early_init(void)
 	 */
 	max86150_mutex_init();
 
+	max86150_shut_down();
+
 	/* Allow user space to trigger interrupts.
 	 * Used for BLE, not sure if needed. */
 	SCB->CCR |= SCB_CCR_USERSETMPEND_Msk;
diff --git a/epicardium/modules/max86150.c b/epicardium/modules/max86150.c
index fac9fbc51..0ed8367e0 100644
--- a/epicardium/modules/max86150.c
+++ b/epicardium/modules/max86150.c
@@ -106,23 +106,16 @@ int epic_max86150_disable_sensor(void)
 	mutex_lock(&max86150_mutex);
 	hwlock_acquire(HWLOCK_I2C);
 
+	max86150_shut_down();
+	max86150_sensor_active = false;
+
 	struct stream_info *stream = &max86150_stream;
 	result                     = stream_deregister(SD_MAX86150, stream);
-	if (result < 0) {
-		goto out_free;
+	if (result == 0) {
+		vQueueDelete(stream->queue);
+		stream->queue = NULL;
 	}
 
-	vQueueDelete(stream->queue);
-	stream->queue = NULL;
-
-	// disable max86150 leds
-	max86150_set_led_red_amplitude(0);
-	max86150_set_led_ir_amplitude(0);
-
-	max86150_sensor_active = false;
-
-	result = 0;
-out_free:
 	hwlock_release(HWLOCK_I2C);
 	mutex_unlock(&max86150_mutex);
 	return result;
-- 
GitLab