From 85a09a27446429d772005b7c1a5aba1bf03d9473 Mon Sep 17 00:00:00 2001
From: Arist <aristkojevnikov@gmail.com>
Date: Tue, 28 Jan 2020 10:55:27 +0100
Subject: [PATCH] add config_size

---
 epicardium/epicardium.h       | 23 ++++++++++-------------
 epicardium/modules/max86150.c |  9 +++++++--
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h
index 118522416..84071d042 100644
--- a/epicardium/epicardium.h
+++ b/epicardium/epicardium.h
@@ -133,8 +133,8 @@ typedef _Bool bool;
 #define API_MAX30001_ENABLE        0xf0
 #define API_MAX30001_DISABLE       0xf1
 
-#define API_MAX86150_ENABLE		   0x0100
-#define API_MAX86150_DISABLE	   0x0101
+#define API_MAX86150_ENABLE        0x0100
+#define API_MAX86150_DISABLE       0x0101
 
 #define API_USB_SHUTDOWN           0x110
 #define API_USB_STORAGE            0x111
@@ -897,8 +897,6 @@ struct max86150_sensor_config {
      * Possible values are 10, 20, 50, 84, 100, 200.
      */
     uint16_t ppg_sample_rate;
-    /** Always zero. Reserved for future parameters. */
-    uint8_t _padding[10];
 };
 
 /**
@@ -920,26 +918,25 @@ struct max86150_sensor_data {
  * data from the sensor.  You can then retrieve the samples using 
  * :c:func:`epic_stream_read`.
  *
+ * :param max86150_sensor_config* config: Configuration for this sensor.
+ * :param size_t config_size: Size of ``config``.
  * :returns: A sensor descriptor which can be used with
  *    :c:func:`epic_stream_read` or a negative error value:
  *
- *    - ``-EBUSY``:   The MAX86150 driver or I2C bus are currently busy with other tasks 
- *      and could not be acquired for enabling a sensor.
  *    - ``-ENOMEM``:  The MAX86150 driver failed to create a stream queue.
- *    - ``-ENODEV``:  The MAX86150 driver failed due to physical connectivity problem (broken wire, unpowered, etc).
- *    - ``-EINVAL``:  config->ppg_sample_rate is not one of 10, 20, 50, 84, 100, 200.
+ *    - ``-ENODEV``:  The MAX86150 driver failed due to physical connectivity problem
+ *      (broken wire, unpowered, etc).
+ *    - ``-EINVAL``:  config->ppg_sample_rate is not one of 10, 20, 50, 84, 100, 200
+ *      or config_size is not size of config.
  *
  * .. versionadded:: 1.13
  */
-API(API_MAX86150_ENABLE, int epic_max86150_enable_sensor(struct max86150_sensor_config *config));
+API(API_MAX86150_ENABLE, int epic_max86150_enable_sensor(struct max86150_sensor_config *config, size_t config_size));
 
 /**
  * Disable the MAX86150 sensor.
  *
- * :returns: 0 in case of success or a negative error value:
- *
- *    - ``-EBUSY``:  The MAX86150 driver or I2C bus are currently busy with other tasks and
- *      could not be acquired for enabling a sensor.
+ * :returns: 0 in case of success or forward negative error value from stream_deregister.
  *
  * .. versionadded:: 1.13
  */
diff --git a/epicardium/modules/max86150.c b/epicardium/modules/max86150.c
index f853783bc..3c8ab807f 100644
--- a/epicardium/modules/max86150.c
+++ b/epicardium/modules/max86150.c
@@ -32,10 +32,15 @@ static struct stream_info max86150_stream;
 /* Active */
 static bool max86150_sensor_active = false;
 
-int epic_max86150_enable_sensor(struct max86150_sensor_config *config)
-{
+int epic_max86150_enable_sensor(
+	struct max86150_sensor_config *config, size_t config_size
+) {
 	int result = 0;
 
+	// if (sizeof(struct max86150_sensor_config) != config_size) {
+	// 	return -EINVAL;
+	// }
+
 	mutex_lock(&max86150_mutex);
 	hwlock_acquire(HWLOCK_I2C);
 
-- 
GitLab