Jacky Tseng
/
imu_driver
handle master side communication of openIMU300ZI module
Diff: imu_driver.hpp
- Revision:
- 2:f3a7def7a7e1
- Parent:
- 1:8e31413068af
- Child:
- 3:8552e26cd162
--- 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 *