bmi160: Set the min_step_buf to 2 for sensitive mode am: ba7c07d3b0
am: 1fde474085

Change-Id: Id832c2b415f2bdda2e4d7bb8eb35fc7d09d475c4
diff --git a/firmware/src/algos/mag_cal.c b/firmware/src/algos/mag_cal.c
index e8b27ea..2059100 100644
--- a/firmware/src/algos/mag_cal.c
+++ b/firmware/src/algos/mag_cal.c
@@ -21,14 +21,14 @@
 #include <nanohub_math.h>
 #include <string.h>
 
-#define MAX_EIGEN_RATIO     25.0f
-#define MAX_EIGEN_MAG       80.0f   // uT
-#define MIN_EIGEN_MAG       10.0f   // uT
+#define MAX_EIGEN_RATIO     15.0f
+#define MAX_EIGEN_MAG       60.0f   // uT
+#define MIN_EIGEN_MAG       30.0f   // uT
 
-#define MAX_FIT_MAG         80.0f
-#define MIN_FIT_MAG         10.0f
+#define MAX_FIT_MAG         70.0f
+#define MIN_FIT_MAG         20.0f
 
-#define MIN_BATCH_WINDOW    1000000UL   // 1 sec
+#define MIN_BATCH_WINDOW    3000000UL   // 3 sec
 #define MAX_BATCH_WINDOW    15000000UL  // 15 sec
 #define MIN_BATCH_SIZE      25      // samples
 
diff --git a/firmware/src/drivers/synaptics_s3708/synaptics_s3708.c b/firmware/src/drivers/synaptics_s3708/synaptics_s3708.c
index 1706a66..af7c525 100644
--- a/firmware/src/drivers/synaptics_s3708/synaptics_s3708.c
+++ b/firmware/src/drivers/synaptics_s3708/synaptics_s3708.c
@@ -104,6 +104,7 @@
 {
     STATE_ENABLE_0,
     STATE_ENABLE_1,
+    STATE_ENABLE_2,
     STATE_DISABLE_0,
     STATE_INT_HANDLE_0,
     STATE_INT_HANDLE_1,
@@ -438,7 +439,17 @@
             if (mTask.retryCnt < HACK_RETRY_SKIP_COUNT) {
                 setRetryTimer();
             } else {
-                setReportingMode(S3708_REPORT_MODE_LPWG, STATE_IDLE);
+                setReportingMode(S3708_REPORT_MODE_LPWG, STATE_ENABLE_2);
+            }
+            break;
+
+        case STATE_ENABLE_2:
+            // Poll the GPIO line to see if it is low/active (it might have been
+            // low when we enabled the ISR, e.g. due to a pending touch event).
+            // Only do this after arming the LPWG, so it happens after we know
+            // that we can talk to the touch controller.
+            if (!gpioGet(mTask.pin)) {
+                osEnqueuePrivateEvt(EVT_SENSOR_TOUCH_INTERRUPT, NULL, NULL, mTask.id);
             }
             break;
 
diff --git a/firmware/src/hostIntf.c b/firmware/src/hostIntf.c
index a9a6cee..de74b5a 100644
--- a/firmware/src/hostIntf.c
+++ b/firmware/src/hostIntf.c
@@ -656,9 +656,11 @@
     const struct SensorInfo *si;
     uint32_t handle;
     static uint8_t errorCnt = 0;
+    uint32_t totalBlocks = 0;
+    uint8_t numSensors = 0;
+    ATOMIC_BITSET_DECL(sensorPresent, SENS_TYPE_LAST_USER - SENS_TYPE_INVALID,);
 
-    mTotalBlocks = 0;
-    mNumSensors = 0;
+    atomicBitsetInit(sensorPresent, SENS_TYPE_LAST_USER - SENS_TYPE_INVALID);
 
     for (i = SENS_TYPE_INVALID + 1; i <= SENS_TYPE_LAST_USER; i++) {
         for (j = 0, present = 0, error = 0; (si = sensorFind(i, j, &handle)) != NULL; j++) {
@@ -711,28 +713,31 @@
         }
 
         if (present && !error) {
-            mNumSensors++;
-            mTotalBlocks += maxBlocks;
+            atomicBitsetSetBit(sensorPresent, i - 1);
+            numSensors++;
+            totalBlocks += maxBlocks;
         }
     }
 
-    if (mTotalBlocks > MAX_NUM_BLOCKS) {
-        osLog(LOG_INFO, "initSensors: mTotalBlocks of %ld exceeds maximum of %d\n", mTotalBlocks, MAX_NUM_BLOCKS);
-        mTotalBlocks = MAX_NUM_BLOCKS;
-    } else if (mTotalBlocks < MIN_NUM_BLOCKS) {
-        mTotalBlocks = MIN_NUM_BLOCKS;
+    if (totalBlocks > MAX_NUM_BLOCKS) {
+        osLog(LOG_INFO, "initSensors: totalBlocks of %ld exceeds maximum of %d\n", totalBlocks, MAX_NUM_BLOCKS);
+        totalBlocks = MAX_NUM_BLOCKS;
+    } else if (totalBlocks < MIN_NUM_BLOCKS) {
+        totalBlocks = MIN_NUM_BLOCKS;
     }
 
-    mOutputQ = simpleQueueAlloc(mTotalBlocks, sizeof(struct HostIntfDataBuffer), queueDiscard);
-    mActiveSensorTable = heapAlloc(mNumSensors * sizeof(struct ActiveSensor));
-    memset(mActiveSensorTable, 0x00, mNumSensors * sizeof(struct ActiveSensor));
+    mOutputQ = simpleQueueAlloc(totalBlocks, sizeof(struct HostIntfDataBuffer), queueDiscard);
+    mActiveSensorTable = heapAlloc(numSensors * sizeof(struct ActiveSensor));
+    memset(mActiveSensorTable, 0x00, numSensors * sizeof(struct ActiveSensor));
 
     for (i = SENS_TYPE_INVALID; i < SENS_TYPE_LAST_USER; i++) {
         mSensorList[i] = MAX_REGISTERED_SENSORS;
     }
 
-    for (i = SENS_TYPE_INVALID + 1, j = 0; i <= SENS_TYPE_LAST_USER && j < mNumSensors; i++) {
-        if ((si = sensorFind(i, 0, &handle)) != NULL && !(si->flags1 & SENSOR_INFO_FLAGS1_LOCAL_ONLY)) {
+    for (i = SENS_TYPE_INVALID + 1, j = 0; i <= SENS_TYPE_LAST_USER && j < numSensors; i++) {
+        if (atomicBitsetGetBit(sensorPresent, i - 1)
+            && (si = sensorFind(i, 0, &handle)) != NULL
+            && !(si->flags1 & SENSOR_INFO_FLAGS1_LOCAL_ONLY)) {
             mSensorList[i - 1] = j;
             resetBuffer(mActiveSensorTable + j);
             mActiveSensorTable[j].buffer.sensType = i;
@@ -777,6 +782,9 @@
         }
     }
 
+    mTotalBlocks = totalBlocks;
+    mNumSensors = numSensors;
+
     return true;
 }
 
diff --git a/sensorhal/hubconnection.cpp b/sensorhal/hubconnection.cpp
index fbd2aa3..0ca99b7 100644
--- a/sensorhal/hubconnection.cpp
+++ b/sensorhal/hubconnection.cpp
@@ -794,7 +794,9 @@
             one = true;
             break;
         case SENS_TYPE_TO_EVENT(SENS_TYPE_TEMP):
-            type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
+            // nanohub only has one temperature sensor type, which is mapped to
+            // internal temp because we currently don't have ambient temp
+            type = SENSOR_TYPE_INTERNAL_TEMPERATURE;
             sensor = COMMS_SENSOR_TEMPERATURE;
             one = true;
             break;