/** * @file BNO08x.hpp * @author Myles Parfeniuk */ #pragma once // standard library includes #include #include #include #include #include #include // hill-crest labs includes (apache 2.0 license, compatible with MIT) #include "sh2.h" #include "sh2_SensorValue.h" #include "sh2_err.h" // esp-idf includes #include #include #include #include #include #include #include #include #include // in-house includes #include "BNO08x_global_types.hpp" /** * @class BNO08x * * @brief BNO08x IMU driver class. * */ class BNO08x { public: BNO08x(bno08x_config_t imu_config = bno08x_config_t()); ~BNO08x(); bool initialize(); bool hard_reset(); void register_cb(std::function cb_fxn); private: /// @brief Holds data that is sent and received over spi. typedef struct sh2_packet_t { uint8_t header[4]; ///< Header of SHTP packet. uint8_t body[300]; /// Body of SHTP packet. uint16_t length; ///< Packet length in bytes. } sh2_packet_t; /// @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. uint8_t task_count; ///< How many successfully initialized tasks (max of TSK_CNT) bool data_proc_task; ///< True if xTaskCreate has been called successfully for data_proc_task. bool spi_task; ///< True if xTaskCreate has been called successfully for spi_task. 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. bno08x_init_status_t() : gpio_outputs(false) , gpio_inputs(false) , isr_service(false) , isr_handler(false) , task_count(0) , data_proc_task(false) , spi_task(false) , spi_bus(false) , spi_device(false) { } } bno08x_init_status_t; esp_err_t init_config_args(); esp_err_t init_gpio(); esp_err_t init_gpio_inputs(); esp_err_t init_gpio_outputs(); esp_err_t init_hint_isr(); esp_err_t init_spi(); esp_err_t deinit_gpio(); esp_err_t deinit_gpio_inputs(); esp_err_t deinit_gpio_outputs(); esp_err_t deinit_hint_isr(); esp_err_t deinit_spi(); esp_err_t transmit_packet(); esp_err_t transmit_packet_header(sh2_packet_t* rx_packet, sh2_packet_t* tx_packet); esp_err_t transmit_packet_body(sh2_packet_t* rx_packet, sh2_packet_t* tx_packet); // for debug void print_header(sh2_packet_t* packet); void print_packet(sh2_packet_t* packet); bool first_boot = true; ///< true only for first execution of hard_reset(), used to suppress the printing of product ID report. // spi task TaskHandle_t spi_task_hdl; ///> cb_list; // Vector for storing any call-back functions added with register_cb() bno08x_config_t imu_config{}; ///