/** * @file BNO08x.hpp * @author Myles Parfeniuk */ #pragma once // standard library includes #include #include #include #include #include #include #include // esp-idf includes #include #include #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 "BNO08xRptRV.hpp" #include "BNO08xRptGameRV.hpp" #include "BNO08xRptARVRStabilizedRV.hpp" #include "BNO08xRptARVRStabilizedGameRV.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 register_report_cb(uint8_t report_ID, std::function cb_fxn); void print_product_ids(); BNO08xRptAcceleration accelerometer; BNO08xRptLinearAcceleration linear_accelerometer; BNO08xRptGravity gravity; BNO08xRptCalMagnetometer calibrated_magnetometer; BNO08xRptRV rotation_vector; BNO08xRptGameRV game_rotation_vector; BNO08xRptARVRStabilizedRV ARVR_stabilized_rotation_vector; BNO08xRptARVRStabilizedGameRV ARVR_stabilized_game_rotation_vector; 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; /// @brief Holds data returned from sensor reports. typedef struct bno08x_data_t { bno08x_step_counter_data_t step_counter; bno08x_activity_classifier_data_t activity_classifier; bno08x_gyro_data_t cal_gyro; bno08x_raw_gyro_data_t mems_raw_gyro; bno08x_raw_accel_data_t mems_raw_accel; bno08x_raw_magf_data_t mems_raw_magnetometer; bno08x_quat_t rv; bno08x_quat_t game_rv; bno08x_quat_t arvr_s_rv; bno08x_quat_t arvr_s_game_rv; bno08x_data_t() : step_counter({0UL, 0U}) , activity_classifier(bno08x_activity_classifier_data_t()) , cal_gyro({0.0f, 0.0f, 0.0f}) , mems_raw_gyro({0, 0, 0, 0, 0UL}) , mems_raw_accel({0, 0, 0, 0UL}) , mems_raw_magnetometer({0, 0, 0, 0UL}) , rv(bno08x_quat_t()) , game_rv(bno08x_quat_t()) , arvr_s_rv(bno08x_quat_t()) , arvr_s_game_rv(bno08x_quat_t()) { } } bno08x_data_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 = 2048; ///< 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, &calibrated_magnetometer}, {SH2_ROTATION_VECTOR, &rotation_vector}, {SH2_GAME_ROTATION_VECTOR, &game_rotation_vector}, {SH2_ARVR_STABILIZED_RV, &ARVR_stabilized_rotation_vector}, {SH2_ARVR_STABILIZED_GRV, &ARVR_stabilized_game_rotation_vector}}; static void IRAM_ATTR hint_handler(void* arg); static const constexpr uint16_t RX_DATA_LENGTH = 300U; ///