SDMP_IOT / Mbed OS AdiSense1000_SmartBabySeat

Fork of Babyseat_NewFirmware_copy_sean by Ross O'Halloran

Branch:
v2.0
Revision:
30:119ff4f3aef6
Parent:
29:57edca10d78c
Child:
31:de49744b57a6
--- a/src/adi_sense_1000.c	Tue May 22 13:45:24 2018 +0100
+++ b/src/adi_sense_1000.c	Tue Jun 12 21:27:34 2018 +0100
@@ -248,7 +248,7 @@
 ADI_SENSE_RESULT adi_sense_GetGpioState(
     ADI_SENSE_DEVICE_HANDLE   const hDevice,
     ADI_SENSE_GPIO_PIN        const ePinId,
-    bool_t                  * const pbAsserted)
+    bool                  * const pbAsserted)
 {
     ADI_SENSE_DEVICE_CONTEXT *pCtx = hDevice;
 
@@ -420,12 +420,19 @@
             pStatus->diagnosticsStatus |= ADI_SENSE_DIAGNOSTICS_STATUS_CALIBRATION_ERROR;
     }
 
+    if (statusReg.Alert_Active || statusReg.Error)
+    {
+        ADI_ADISENSE_CORE_Debug_Code_t debugCodeReg;
+        READ_REG_U32(hDevice, debugCodeReg.VALUE32, CORE_DEBUG_CODE);
+        pStatus->debugCode = debugCodeReg.Debug_Code;
+    }
+
     return ADI_SENSE_SUCCESS;
 }
 
 ADI_SENSE_RESULT adi_sense_GetCommandRunningState(
     ADI_SENSE_DEVICE_HANDLE hDevice,
-    bool_t *pbCommandRunning)
+    bool *pbCommandRunning)
 {
     ADI_ADISENSE_CORE_Status_t statusReg;
 
@@ -443,10 +450,10 @@
 static ADI_SENSE_RESULT executeCommand(
     ADI_SENSE_DEVICE_HANDLE const hDevice,
     ADI_ADISENSE_CORE_Command_Special_Command const command,
-    bool_t const bWaitForCompletion)
+    bool const bWaitForCompletion)
 {
     ADI_ADISENSE_CORE_Command_t commandReg;
-    bool_t bCommandRunning;
+    bool bCommandRunning;
     ADI_SENSE_RESULT eRet;
 
     /*
@@ -663,7 +670,7 @@
     for (unsigned i = 0; i < nRequested; i++)
     {
         ADI_SENSE_1000_Sensor_Result_t sensorResult;
-        bool_t bHoldCs = true;
+        bool bHoldCs = true;
 
         /* Keep the CS signal asserted for all but the last sample */
         if ((i + 1) == nRequested)
@@ -805,7 +812,7 @@
     for (unsigned i = 0; i < nRequested; i++)
     {
         ADI_SENSE_1000_Sensor_Result_t sensorResult;
-        bool_t bHoldCs = true;
+        bool bHoldCs = true;
 
         /* Keep the CS signal asserted for all but the last sample */
         if ((i + 1) == nRequested)
@@ -848,11 +855,11 @@
         pSample->processedValue = sensorResult.Sensor_Result;
 
         nValidSamples++;
+
+        adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
     }
     *pnReturned = nValidSamples;
 
-    adi_sense_TimeDelayUsec(ADI_SENSE_1000_HOST_COMMS_XFER_DELAY);
-
     return eRet;
 }
 
@@ -959,7 +966,7 @@
 
 ADI_SENSE_RESULT adi_sense_GetDeviceReadyState(
     ADI_SENSE_DEVICE_HANDLE   const hDevice,
-    bool_t                  * const bReady)
+    bool                  * const bReady)
 {
     ADI_ADISENSE_SPI_Chip_Type_t chipTypeReg;
 
@@ -1037,6 +1044,15 @@
         *pnSamplesPerCycle = nSamplesPerChannel * nFftChannels;
 
         *peDataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE;
+
+        if (modeReg.FFT_Mode == ADISENSE_CORE_MODE_FFT_MODE_CONTINUOUS)
+        {
+            *peOperatingMode = ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS;
+        }
+        else
+        {
+            *peOperatingMode = ADI_SENSE_1000_OPERATING_MODE_SINGLECYCLE;
+        }
     }
     else
     {
@@ -2845,7 +2861,7 @@
     ADI_SENSE_1000_CHANNEL_ID eChannelId,
     float32_t fSensorParam)
 {
-    if (fSensorParam == 0.0)
+    if (fSensorParam == 0.0f)
         fSensorParam = NAN;
 
     WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId));
@@ -2892,12 +2908,9 @@
 
     if (! ADI_SENSE_1000_CHANNEL_IS_VIRTUAL(eChannelId))
     {
-        /* If the channel is not enabled, disable it and return */
-        if (! pChannelConfig->enableChannel)
-            return adi_sense_1000_SetChannelCount(hDevice, eChannelId, 0);
-
         eRet = adi_sense_1000_SetChannelCount(hDevice, eChannelId,
-                                              pChannelConfig->measurementsPerCycle);
+                                              pChannelConfig->enableChannel ?
+                                              pChannelConfig->measurementsPerCycle : 0);
         if (eRet != ADI_SENSE_SUCCESS)
         {
             ADI_SENSE_LOG_ERROR("Failed to set measurement count for channel %d",
@@ -2915,53 +2928,57 @@
             return eRet;
         }
 
-        eRet = adi_sense_1000_SetChannelSkipCount(hDevice, eChannelId,
-                                                  pChannelConfig->cycleSkipCount);
-        if (eRet != ADI_SENSE_SUCCESS)
-        {
-            ADI_SENSE_LOG_ERROR("Failed to set cycle skip count for channel %d",
-                                eChannelId);
-            return eRet;
-        }
-
-        switch (eChannelId)
+        /* If the channel is not enabled, we can skip the following steps */
+        if (pChannelConfig->enableChannel || pChannelConfig->enableFFT)
         {
-        case ADI_SENSE_1000_CHANNEL_ID_CJC_0:
-        case ADI_SENSE_1000_CHANNEL_ID_CJC_1:
-        case ADI_SENSE_1000_CHANNEL_ID_SENSOR_0:
-        case ADI_SENSE_1000_CHANNEL_ID_SENSOR_1:
-        case ADI_SENSE_1000_CHANNEL_ID_SENSOR_2:
-        case ADI_SENSE_1000_CHANNEL_ID_SENSOR_3:
-        case ADI_SENSE_1000_CHANNEL_ID_VOLTAGE_0:
-        case ADI_SENSE_1000_CHANNEL_ID_CURRENT_0:
-            eRet = adi_sense_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig);
-            break;
-        case ADI_SENSE_1000_CHANNEL_ID_I2C_0:
-        case ADI_SENSE_1000_CHANNEL_ID_I2C_1:
-            eRet = adi_sense_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig);
-            break;
-        case ADI_SENSE_1000_CHANNEL_ID_SPI_0:
-            eRet = adi_sense_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig);
-            break;
-        case ADI_SENSE_1000_CHANNEL_ID_UART:
-            eRet = adi_sense_SetUartChannelConfig(hDevice, eChannelId, pChannelConfig);
-            break;
-        default:
-            ADI_SENSE_LOG_ERROR("Invalid channel ID %d specified", eChannelId);
-            return ADI_SENSE_INVALID_PARAM;
-        }
-
-        eRet = adi_sense_1000_SetChannelSettlingTime(hDevice, eChannelId,
-                                                     pChannelConfig->extraSettlingTime);
-        if (eRet != ADI_SENSE_SUCCESS)
-        {
-            ADI_SENSE_LOG_ERROR("Failed to set settling time for channel %d",
-                                eChannelId);
-            return eRet;
+            eRet = adi_sense_1000_SetChannelSkipCount(hDevice, eChannelId,
+                                                      pChannelConfig->cycleSkipCount);
+            if (eRet != ADI_SENSE_SUCCESS)
+            {
+                ADI_SENSE_LOG_ERROR("Failed to set cycle skip count for channel %d",
+                                    eChannelId);
+                return eRet;
+            }
+
+            switch (eChannelId)
+            {
+            case ADI_SENSE_1000_CHANNEL_ID_CJC_0:
+            case ADI_SENSE_1000_CHANNEL_ID_CJC_1:
+            case ADI_SENSE_1000_CHANNEL_ID_SENSOR_0:
+            case ADI_SENSE_1000_CHANNEL_ID_SENSOR_1:
+            case ADI_SENSE_1000_CHANNEL_ID_SENSOR_2:
+            case ADI_SENSE_1000_CHANNEL_ID_SENSOR_3:
+            case ADI_SENSE_1000_CHANNEL_ID_VOLTAGE_0:
+            case ADI_SENSE_1000_CHANNEL_ID_CURRENT_0:
+                eRet = adi_sense_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig);
+                break;
+            case ADI_SENSE_1000_CHANNEL_ID_I2C_0:
+            case ADI_SENSE_1000_CHANNEL_ID_I2C_1:
+                eRet = adi_sense_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig);
+                break;
+            case ADI_SENSE_1000_CHANNEL_ID_SPI_0:
+                eRet = adi_sense_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig);
+                break;
+            case ADI_SENSE_1000_CHANNEL_ID_UART:
+                eRet = adi_sense_SetUartChannelConfig(hDevice, eChannelId, pChannelConfig);
+                break;
+            default:
+                ADI_SENSE_LOG_ERROR("Invalid channel ID %d specified", eChannelId);
+                return ADI_SENSE_INVALID_PARAM;
+            }
+
+            eRet = adi_sense_1000_SetChannelSettlingTime(hDevice, eChannelId,
+                                                         pChannelConfig->extraSettlingTime);
+            if (eRet != ADI_SENSE_SUCCESS)
+            {
+                ADI_SENSE_LOG_ERROR("Failed to set settling time for channel %d",
+                                    eChannelId);
+                return eRet;
+            }
         }
     }
 
-    if (pChannelConfig->enableChannel)
+    if (pChannelConfig->enableChannel || pChannelConfig->enableFFT)
     {
         /* Threshold limits can be configured individually for virtual channels */
         eRet = adi_sense_1000_SetChannelThresholdLimits(hDevice, eChannelId,
@@ -3106,7 +3123,6 @@
                 case ADI_SENSE_1000_LUT_EQUATION_QUADRATIC:
                 case ADI_SENSE_1000_LUT_EQUATION_STEINHART:
                 case ADI_SENSE_1000_LUT_EQUATION_LOGARITHMIC:
-                case ADI_SENSE_1000_LUT_EQUATION_EXPONENTIAL:
                 case ADI_SENSE_1000_LUT_EQUATION_BIVARIATE_POLYN:
                 break;
                 default: