/** * @file BNO08x.hpp * @author Myles Parfeniuk */ #pragma once // standard library includes #include #include #include #include // esp-idf includes #include #include #include #include #include // in-house includes #include "BNO08x_global_types.hpp" #include "BNO08xSH2HAL.hpp" #include "BNO08xRptAcceleration.hpp" #include "BNO08xRptLinearAcceleration.hpp" #include "BNO08xRptGravity.hpp" #include "BNO08xRptCalMagnetometer.hpp" #include "BNO08xRptUncalMagnetometer.hpp" #include "BNO08xRptCalGyro.hpp" #include "BNO08xRptUncalGyro.hpp" #include "BNO08xRptRV.hpp" #include "BNO08xRptGameRV.hpp" #include "BNO08xRptARVRStabilizedRV.hpp" #include "BNO08xRptARVRStabilizedGameRV.hpp" #include "BNO08xRptIGyroRV.hpp" #include "BNO08xRptRVGeomag.hpp" #include "BNO08xRptRawMEMSGyro.hpp" #include "BNO08xRptRawMEMSAccelerometer.hpp" #include "BNO08xRptRawMEMSMagnetometer.hpp" #include "BNO08xRptStepCounter.hpp" #include "BNO08xRptActivityClassifier.hpp" #include "BNO08xStabilityClassifier.hpp" #include "BNO08xShakeDetector.hpp" #include "BNO08xTapDetector.hpp" /** * @class BNO08x * * @brief BNO08x IMU driver class. * */ class BNO08x { public: inline static sh2_SensorConfig default_sensor_cfg = {.changeSensitivityEnabled = false, /// cb_fxn); void register_cb(std::function cb_fxn); void print_product_ids(); // enum helper fxns static const char* activity_to_str(BNO08xActivity activity); static const char* stability_to_str(BNO08xStability stability); static const char* accuracy_to_str(BNO08xAccuracy accuracy); BNO08xRptAcceleration accelerometer; BNO08xRptLinearAcceleration linear_accelerometer; BNO08xRptGravity gravity; BNO08xRptCalMagnetometer cal_magnetometer; BNO08xRptUncalMagnetometer uncal_magnetometer; BNO08xRptCalGyro cal_gyro; BNO08xRptUncalGyro uncal_gyro; BNO08xRptRV rv; BNO08xRptGameRV rv_game; BNO08xRptARVRStabilizedRV rv_ARVR_stabilized; BNO08xRptARVRStabilizedGameRV rv_ARVR_stabilized_game; BNO08xRptIGyroRV rv_gyro_integrated; BNO08xRptRVGeomag rv_geomagnetic; BNO08xRptRawMEMSGyro raw_gyro; BNO08xRptRawMEMSAccelerometer raw_accelerometer; BNO08xRptRawMEMSMagnetometer raw_magnetometer; BNO08xRptStepCounter step_counter; BNO08xRptActivityClassifier activity_classifier; BNO08xStabilityClassifier stability_classifier; BNO08xShakeDetector shake_detector; BNO08xTapDetector tap_detector; private: /// @brief Holds info about which functionality has been successfully initialized (used by deconstructor during cleanup). typedef struct bno08x_init_status_t { bool gpio_outputs; ///< True if GPIO outputs have been initialized. bool gpio_inputs; ///< True if GPIO inputs have been initialized. bool isr_service; ///< True if global ISR service has been initialized. bool isr_handler; ///< True if HINT ISR handler has been initialized. bool spi_bus; ///< True if spi_bus_initialize() has been called successfully. bool spi_device; ///< True if spi_bus_add_device() has been called successfully. bool sh2_HAL; ///< True if sh2_open() has been called successfully. bool data_proc_task; ///< True if xTaskCreate has been called successfully for data_proc_task. bool sh2_HAL_service_task; ///< True if xTaskCreate has been called successfully for sh2_HAL_service_task. bool cb_task; ///< True if xTaskCreate has been called successfully for cb_task. uint8_t task_init_cnt; ///< Amount of tasks that have been successfully initialized. bno08x_init_status_t() : gpio_outputs(false) , gpio_inputs(false) , isr_service(false) , isr_handler(false) , spi_bus(false) , spi_device(false) , data_proc_task(false) , sh2_HAL_service_task(false) , cb_task(false) , task_init_cnt(0) { } } bno08x_init_status_t; using bno08x_cb_t = std::variant, std::function>; /// @brief Holds registered callback info. typedef struct bno08x_cb_data_t { uint8_t report_ID; ///< Report this callback is registered to (0 if to execute on any new report). bno08x_cb_t cb; ///< Callback function pointer. } bno08x_cb_data_t; // data processing task static const constexpr configSTACK_DEPTH_TYPE DATA_PROC_TASK_SZ = 2048UL; ///< Size of data_proc_task() stack in bytes TaskHandle_t data_proc_task_hdl; /// cb_list; // Vector for storing any call-back functions added with register_cb() bno08x_config_t imu_config{}; /// usr_reports = {{SH2_ACCELEROMETER, &accelerometer}, {SH2_LINEAR_ACCELERATION, &linear_accelerometer}, {SH2_GRAVITY, &gravity}, {SH2_MAGNETIC_FIELD_CALIBRATED, &cal_magnetometer}, {SH2_MAGNETIC_FIELD_UNCALIBRATED, &uncal_magnetometer}, {SH2_GYROSCOPE_CALIBRATED, &cal_gyro}, {SH2_GYROSCOPE_UNCALIBRATED, &uncal_gyro}, {SH2_ROTATION_VECTOR, &rv}, {SH2_GAME_ROTATION_VECTOR, &rv_game}, {SH2_ARVR_STABILIZED_RV, &rv_ARVR_stabilized}, {SH2_ARVR_STABILIZED_GRV, &rv_ARVR_stabilized_game}, {SH2_GYRO_INTEGRATED_RV, &rv_gyro_integrated}, {SH2_GEOMAGNETIC_ROTATION_VECTOR, &rv_geomagnetic}, {SH2_RAW_GYROSCOPE, &raw_gyro}, {SH2_RAW_ACCELEROMETER, &raw_accelerometer}, {SH2_RAW_MAGNETOMETER, &raw_magnetometer}, {SH2_STEP_COUNTER, &step_counter}, {SH2_PERSONAL_ACTIVITY_CLASSIFIER, &activity_classifier}, {SH2_STABILITY_CLASSIFIER, &stability_classifier}, {SH2_SHAKE_DETECTOR, &shake_detector}, {SH2_TAP_DETECTOR, &tap_detector}}; static void IRAM_ATTR hint_handler(void* arg); static const constexpr uint16_t RX_DATA_LENGTH = 300U; ///