Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:f3a7def7a7e1, committed 2019-11-17
- Comitter:
- Arithemetica
- Date:
- Sun Nov 17 06:12:21 2019 +0000
- Parent:
- 1:8e31413068af
- Child:
- 3:8552e26cd162
- Commit message:
- Add class documentation
Changed in this revision
| imu_driver.hpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/imu_driver.hpp Sat Nov 16 16:24:03 2019 +0000
+++ b/imu_driver.hpp Sun Nov 17 06:12:21 2019 +0000
@@ -42,15 +42,22 @@
} ImuProcessedData;
/**
- * Imu Driver is used to handling the master side of openIMU300ZI module, the
- * default setups are:
+ * @brief ImuDriver is used to handle the SPI master side of openIMU300ZI module, the
+ * default setups are:
*
- * - Data frame: 16 bits
- * - CPOL: High (1)
- * - CPHA: 2 Edge (1)
- * - Frequency: 1.40625 MHz (Baudrate prescaler 32 for NUCLEO-F446RE under 180MHz)
- * - Endian: MSB first (Mbed only support MSB AFAIK)
+ * - Data frame: 16 bits
+ * - CPOL: High (1)
+ * - CPHA: 2 Edge (1)
+ * - Frequency: 1.40625 MHz (Baudrate prescaler 32 for NUCLEO-F446RE under 180MHz)
+ * - Endian: MSB first (Mbed only support MSB AFAIK)
*
+ * @tparam spi SPI comm instance, ImuDriver currently support only SPI framework
+ * @tparam rst Reset pin name, this is used to reset the openIMU300ZI module
+ * @tparam drdy Data ready pin name, this is used as indication of data readiness
+ * (@todo Attach to interrupt in the future, and make user able to choose)
+ * @tparam ss Slave select pin name, this is used as slave select, pull low to initiate
+ * communication process.
+ *
* Example of using ImuDriver:
*
* @code
@@ -75,14 +82,19 @@
*
* @endcode
*/
-template <SPI& spi, PinName rst, PinName drdy, PinName ss>
+template <SPI& Spi, PinName rst, PinName drdy, PinName ss>
class ImuDriver
{
private:
+ typedef ImuDriver<Spi, rst, drdy, ss> ImuDriverType;
+ typedef ImuDriverStatus (ImuDriver<Spi, rst, drdy, ss>::*DrdyCallback)();
+
+
SPI& m_spi;
DigitalOut m_rst, m_ss;
DigitalIn m_drdy;
-
+ InterruptIn m_drdyExti;
+
float m_gyroScaler[3];
float m_accelScaler[3];
float m_ahrsScaler[3];
@@ -134,6 +146,11 @@
ahrsProcessedData.attitude[i] = ahrsRawData.attitude[i] / m_ahrsScaler[i];
}
}
+
+ void m_receiveAhrsCallback()
+ {
+ receiveAhrsMsg();
+ }
public:
ImuRawData imuRawData;
ImuProcessedData imuProcessedData;
@@ -145,20 +162,21 @@
static const int DEFAULT_IMU_GYRO_SCALER = 200;
static const int DEFAULT_AHRS_ATTITUDE_SCALER = 90;
public:
- ImuDriver() : m_spi(spi), m_rst(rst), m_ss(ss), m_drdy(drdy)
+ ImuDriver() : m_spi(Spi), m_rst(rst), m_ss(ss), m_drdy(drdy), m_drdyExti(drdy)
{
for (int i = 0; i < 3; ++i) {
m_gyroScaler[i] = static_cast<float>(DEFAULT_IMU_GYRO_SCALER); // what an idiotic way of initialization LUL
- m_accelScaler[i] = static_cast<float>(DEFAULT_IMU_ACCEL_SCALER); // Oh, I forgot that mbed is still stuck at c++98,
+ m_accelScaler[i] = static_cast<float>(DEFAULT_IMU_ACCEL_SCALER); // Oh, I forgot that mbed os2 still stucks at c++98,
m_ahrsScaler[i] = static_cast<float>(DEFAULT_AHRS_ATTITUDE_SCALER); // how unfortunate LUL
}
+// m_drdyExti.rise(this, &ImuDriver<Spi, rst, drdy, ss>::m_receiveAhrsCallback);
m_spi.format(16, 3);
m_spi.frequency(1406250);
}
/**
- * @brief This function handles the receive of burst message function of openIMU
+ * @brief This function handles the receiving of burst message function
*
* @param t_extended bool to indicate the message type is extended or not, default false
*
@@ -220,7 +238,7 @@
}
/**
- * @brief This function handles the receive of AHRS burst message function
+ * @brief This function handles the receiving of AHRS burst message function
*
* @return ImuDriverStatus to indicate the result of the receive operation
*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Nov 17 06:12:21 2019 +0000
@@ -0,0 +1,16 @@
+#include "imu_driver.hpp"
+
+SPI spi3(PB_5, PB_4, PB_3);
+
+int main()
+{
+ ImuDriver<spi3, PA_10, PA_8, PA_9> imu;
+
+ while(true)
+ {
+// if (imu.receiveBurstMsg() == ImuDriverStatusOK)
+// {
+
+// }
+ }
+}