From 4c8cdbd386e229458bafd1a3d8e8b3a594b1605f Mon Sep 17 00:00:00 2001 From: Paul D'Angio <pcdangio@gmail.com> Date: Sun, 25 Oct 2020 18:07:26 -0400 Subject: [PATCH] updated driver documentation --- src/driver.cpp | 4 +++ src/driver.h | 93 ++++++++++++-------------------------------------- 2 files changed, 25 insertions(+), 72 deletions(-) diff --git a/src/driver.cpp b/src/driver.cpp index 6889f08..6117ad3 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -6,6 +6,7 @@ #include <cmath> #include <limits> +// CONSTRUCTORS driver::driver() { @@ -21,6 +22,7 @@ void driver::set_data_callback(std::function<void (data)> callback) driver::m_data_callback = callback; } +// INITIALIZATION void driver::initialize(unsigned int i2c_bus, unsigned int i2c_address, unsigned int interrupt_gpio_pin) { // Initialize I2C: @@ -91,6 +93,7 @@ void driver::deinitialize() deinitialize_i2c(); } +// PROPERTIES float driver::p_dlpf_frequencies(gyro_dlpf_frequency_type gyro_frequency, accel_dlpf_frequency_type accel_frequency, float max_sample_rate) { // Read the current configuration for gyro/temp. @@ -288,6 +291,7 @@ void driver::p_accel_fsr(accel_fsr_type fsr) } } +// METHODS void driver::read_data() { // Create data storage structure. diff --git a/src/driver.h b/src/driver.h index 11d2ac2..8b28595 100644 --- a/src/driver.h +++ b/src/driver.h @@ -5,16 +5,12 @@ #include <functional> -/// /// \brief The base driver class for the MPU9250. -/// class driver { public: // ENUMERATIONS - /// /// \brief Enumerates the digital low-pass filter (DLPF) cutoff frequencies for the accelerometers. - /// enum class accel_dlpf_frequency_type { F_460HZ = 0x00, @@ -25,9 +21,7 @@ public: F_10HZ = 0x05, F_5HZ = 0x06 }; - /// /// \brief Enumerates the digital low-pass filter (DLPF) cutoff frequencies for the gyros. - /// enum class gyro_dlpf_frequency_type { F_250HZ = 0x00, @@ -38,9 +32,7 @@ public: F_10Hz = 0x05, F_5HZ = 0x06 }; - /// /// \brief Enumerates the full scale ranges (FSR) available for the accelerometers in g. - /// enum class accel_fsr_type { G_2 = 0x00, @@ -48,9 +40,7 @@ public: G_8 = 0x02, G_16 = 0x03 }; - /// /// \brief Enumerates the full scale ranges (FSR) available for the gyros in degress/second. - /// enum class gyro_fsr_type { DPS_250 = 0x00, @@ -60,9 +50,7 @@ public: }; // CLASSES - /// /// \brief A structure for storing IMU data. - /// struct data { float accel_x, accel_y, accel_z; @@ -72,61 +60,46 @@ public: }; // CONSTRUCTORS - /// - /// \brief driver Initializes a new driver instance. - /// + /// \brief Initializes a new driver instance. driver(); virtual ~driver() = 0; - // METHODS - /// - /// \brief set_data_callback Attaches a callback to handle data when it becomes available. + // CONFIGURATION + /// \brief Attaches a callback to handle data when it becomes available. /// \param callback The callback function to execute. - /// void set_data_callback(std::function<void(driver::data)> callback); - /// - /// \brief initialize Initializes the MPU9250. + // INITIALIZATION + /// \brief Initializes the MPU9250. /// \param i2c_bus The I2C bus to communicate with the MPU9250 over. /// \param i2c_address The I2C address of the MPU9250. /// \param interrupt_gpio_pin The GPIO pin connected to the MPU9250's interrupt pin. - /// void initialize(unsigned int i2c_bus, unsigned int i2c_address, unsigned int interrupt_gpio_pin); - /// - /// \brief deinitialize Deinitializes the MPU9250. - /// + /// \brief Deinitializes the MPU9250. void deinitialize(); - /// - /// \brief p_dlpf_frequencies Sets the digital low-pass filter (DLPF) cutoff frequencies for the accelerometers and gyroscopes. + // PROPERTIES + /// \brief Sets the digital low-pass filter (DLPF) cutoff frequencies for the accelerometers and gyroscopes. /// \param gyro_frequency The cut-off frequency for the gyroscopes and temperature sensor. /// \param accel_frequency The cut-off frequency for the accelerometers. /// \param max_sample_rate The maximum sample rate to use. Defaults to unlimited. /// \returns The configured data sample rate (Hz) /// \note The data rate is set to the nearest minimum value of lpf/2.5 or max_sample_rate. - /// float p_dlpf_frequencies(gyro_dlpf_frequency_type gyro_frequency, accel_dlpf_frequency_type accel_frequency, float max_sample_rate = 8000.0F); - /// - /// \brief p_gyro_fsr Sets the full scale range (FSR) of the gyroscopes. + /// \brief Sets the full scale range (FSR) of the gyroscopes. /// \param fsr The FSR to set. - /// void p_gyro_fsr(gyro_fsr_type fsr); - /// - /// \brief p_accel_fsr Sets the full scale range (FSR) of the accelerometers. + /// \brief Sets the full scale range (FSR) of the accelerometers. /// \param fsr The FSR to set. - /// void p_accel_fsr(accel_fsr_type fsr); - /// - /// \brief read_data Reads all IMU data directly from the MPU9250 and AK8963 and raises the data callback. - /// + // METHODS + /// \brief Reads all IMU data directly from the MPU9250 and AK8963 and raises the data callback. void read_data(); protected: // ENUMERATIONS - /// /// \brief Enumerates the MPU9250 register addresses. - /// enum class register_mpu9250_type { SAMPLE_RATE_DIVIDER = 0x19, @@ -154,9 +127,7 @@ protected: PWR_MGMT_1 = 0x6B, WHO_AM_I = 0x75 }; - /// /// \brief Enumerates the AK8963 register addresses. - /// enum class register_ak8963_type { WHO_AM_I = 0x00, @@ -171,73 +142,51 @@ protected: }; // METHODS - /// - /// \brief initialize_i2c Initializes the I2C and GPIO interface of the driver. + /// \brief Initializes the I2C and GPIO interface of the driver. /// \param i2c_bus The I2C bus to interface with the MPU9250 over. /// \param i2c_address The I2C address of the MPU9250. /// \param interrupt_gpio_pin The GPIO input pin that is connected to the MPU9250 interrupt pin. - /// virtual void initialize_i2c(unsigned int i2c_bus, unsigned int i2c_address, unsigned int interrupt_gpio_pin) = 0; - /// - /// \brief deinitialize_i2c Deinitialies the I2C interface of the driver. - /// + /// \brief Deinitialies the I2C interface of the driver. virtual void deinitialize_i2c() = 0; - /// - /// \brief write_mpu9250_register Writes data to a register on the MPU9250. + /// \brief Writes data to a register on the MPU9250. /// \param address The address of the register to write to. /// \param value The data to write to the register. - /// virtual void write_mpu9250_register(register_mpu9250_type address, unsigned char value) = 0; - /// - /// \brief read_mpu9250_register Reads data from a register on the MPU9250. + /// \brief Reads data from a register on the MPU9250. /// \param address The address of the register to read from. /// \return The data from the register. - /// virtual unsigned char read_mpu9250_register(register_mpu9250_type address) = 0; - /// - /// \brief read_mpu9250_registers Block reads data from several registers on the MPU9250. + /// \brief Block reads data from several registers on the MPU9250. /// \param address The starting register address of the block read. /// \param n_bytes The number of bytes/registers to block read. /// \param buffer The buffer to store the read data in. - /// virtual void read_mpu9250_registers(register_mpu9250_type address, unsigned int n_bytes, char* buffer) = 0; - /// - /// \brief write_ak8963_register Writes data to a register on the AK8963. + /// \brief Writes data to a register on the AK8963. /// \param address The address of the register to write to. /// \param value The data to write to the register. - /// virtual void write_ak8963_register(register_ak8963_type address, unsigned char value) = 0; - /// - /// \brief read_ak8963_register Reads data from a register on the AK8963. + /// \brief Reads data from a register on the AK8963. /// \param address The address of the register to read from. /// \return The data from the register. - /// virtual unsigned char read_ak8963_register(register_ak8963_type address) = 0; - /// - /// \brief read_ak8963_registers Block reads data from several registers on the AK8963. + /// \brief Block reads data from several registers on the AK8963. /// \param address The starting register address of the block read. /// \param n_bytes The number of bytes/registers to block read. /// \param buffer The buffer to store the read data in. - /// virtual void read_ak8963_registers(register_ak8963_type address, unsigned int n_bytes, char* buffer) = 0; private: - // VARIABLES - /// + // FULL SCALE RANGE /// \brief m_gyro_fsr Stores the full scale range of the gyroscopes for ADC conversion. - /// float m_gyro_fsr; - /// /// \brief m_accel_fsr Stores the full scale range of the accelerometers for ADC conversion. - /// float m_accel_fsr; // CALLBACKS - /// /// \brief m_data_callback The callback function to execute when IMU data is read. - /// std::function<void(driver::data)> m_data_callback; }; -- GitLab