handle master side communication of openIMU300ZI module

Dependencies:   mbed

Dependents:   VDU_2021

Revision:
17:629b2f317d0a
Parent:
16:6583ad08d0d0
Child:
19:3ee54f9a56f3
--- a/imu_driver.hpp	Tue Dec 03 14:38:15 2019 +0000
+++ b/imu_driver.hpp	Tue Dec 17 14:30:08 2019 +0000
@@ -16,6 +16,9 @@
     ImuExtiRcvAhrsMsg = 0b10
 } ImuExtiConfig;
 
+/**
+ *  @brief  ImuDriverStatus
+ */
 typedef enum ImuDriverStatus {
     ImuDriverStatusOK,
     ImuDriverStatusDataNotReady,
@@ -78,7 +81,7 @@
  *           - Data frame: 16 bits
  *           - CPOL: High (1)
  *           - CPHA: 2 Edge (1)
- *           - Frequency: 1.40625 MHz (Baudrate prescaler 32 for NUCLEO-F446RE under 180MHz)
+ *           - Frequency: 1 MHz (Default frequency of spi)
  *           - Endian: MSB first (Mbed only support MSB AFAIK)
  *
  *         According to <A HREF="https://openimu.readthedocs.io/en/latest/software/SPImessaging.html">openIMU300ZI SPI framework</A>:
@@ -106,14 +109,11 @@
  *  int main()
  *  {
  *      // SPI instance, reset, data ready, slave select
- *      ImuDriver<spi3, PA_10, PA_8, PA_9> imu;
+ *      ImuDriver<spi3, PA_10, PA_8, PA_9> imu(ImuExtiRcvNormalMsg);
  *
  *      while(true)
  *      {
- *          if (imu.receiveBurstMsg() == ImuDriverStatusOK)
- *          {
- *              pc.printf("%.3f, %.3f, %.3f\n\r", imu.imuProcessedData.rate[0], imu.imuProcessedData.rate[1], imu.imuProcessedData.rate[2]);
- *          }
+ *          pc.printf("%.3f, %.3f, %.3f\n\r", imu.imuProcessedData.rate[0], imu.imuProcessedData.rate[1], imu.imuProcessedData.rate[2]);
  *      }
  *  }
  *
@@ -279,6 +279,7 @@
                 }
 
                 ++data_rcved;
+
             }
 
             data_rcved = 0U;
@@ -325,10 +326,11 @@
 
         if (t_exti_config != ImuExtiRcvNotUsed) {
             m_drdyExti.fall(this, &ImuDriver<Spi, rst, drdy, ss>::m_dataReadyExtiCallback);
+            m_drdyExti.enable_irq();
         }
 
         m_spi.format(16, 3);
-        m_spi.frequency(1406250);
+        m_spi.frequency();
     }
 
     /**
@@ -358,9 +360,25 @@
         return (m_extiConfig & ImuExtiRcvAhrsMsg ? ImuDriverStatusInvalidCall : receiveAhrsMsgImpl());
     }
 
-    ImuDriverStatus configExti(const ImuExtiConfig t_exti_config)
+    /**
+     *  @brief  This function handles the external interrupt option, whether receive AHRS 
+     *          burst message or normal imu message.
+     *
+     *  @return ImuDriverStatus to indicate the result of the receive operation
+     *
+     *  @note   Never try receiving two messages at the same time
+     */
+    ImuDriverStatus configExti(const ImuExtiConfig t_exti_config) const
     {
         m_extiConfig = t_exti_config;
+
+        if (m_extoConfig == ImuExtiRcvNotUsed) {
+            m_drdyExti.disable_irq();
+        } else {
+            m_drdyExti.enable_irq();
+        }
+
+        return ImuDriverStatusOK;
     }
 };