Added overloaded constructor to config struct
This commit is contained in:
parent
62da810dbc
commit
aca0ee421d
18
BNO08x.cpp
18
BNO08x.cpp
|
|
@ -51,17 +51,24 @@ BNO08x::BNO08x(bno08x_config_t imu_config)
|
||||||
// SPI non-driver-controlled GPIO config
|
// SPI non-driver-controlled GPIO config
|
||||||
// configure outputs
|
// configure outputs
|
||||||
gpio_config_t outputs_config;
|
gpio_config_t outputs_config;
|
||||||
outputs_config.pin_bit_mask = (1ULL << imu_config.io_cs) | (1ULL << imu_config.io_rst) |
|
|
||||||
(1ULL << imu_config.io_wake); // configure CS, RST, and wake gpio pins
|
if (imu_config.io_wake != GPIO_NUM_NC)
|
||||||
|
outputs_config.pin_bit_mask = (1ULL << imu_config.io_cs) | (1ULL << imu_config.io_rst) |
|
||||||
|
(1ULL << imu_config.io_wake); // configure CS, RST, and wake gpio pins
|
||||||
|
else
|
||||||
|
outputs_config.pin_bit_mask = (1ULL << imu_config.io_cs) | (1ULL << imu_config.io_rst);
|
||||||
|
|
||||||
outputs_config.mode = GPIO_MODE_OUTPUT;
|
outputs_config.mode = GPIO_MODE_OUTPUT;
|
||||||
outputs_config.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
outputs_config.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
outputs_config.pull_up_en = GPIO_PULLUP_DISABLE;
|
outputs_config.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
outputs_config.intr_type = GPIO_INTR_DISABLE;
|
outputs_config.intr_type = GPIO_INTR_DISABLE;
|
||||||
gpio_config(&outputs_config);
|
gpio_config(&outputs_config);
|
||||||
gpio_set_level(imu_config.io_cs, 1);
|
gpio_set_level(imu_config.io_cs, 1);
|
||||||
gpio_set_level(imu_config.io_wake, 1);
|
|
||||||
gpio_set_level(imu_config.io_rst, 1);
|
gpio_set_level(imu_config.io_rst, 1);
|
||||||
|
|
||||||
|
if (imu_config.io_wake != GPIO_NUM_NC)
|
||||||
|
gpio_set_level(imu_config.io_wake, 1);
|
||||||
|
|
||||||
// configure input (HINT pin)
|
// configure input (HINT pin)
|
||||||
gpio_config_t inputs_config;
|
gpio_config_t inputs_config;
|
||||||
inputs_config.pin_bit_mask = (1ULL << imu_config.io_int);
|
inputs_config.pin_bit_mask = (1ULL << imu_config.io_int);
|
||||||
|
|
@ -208,7 +215,10 @@ bool BNO08x::wait_for_device_int() {
|
||||||
*/
|
*/
|
||||||
bool BNO08x::hard_reset() {
|
bool BNO08x::hard_reset() {
|
||||||
gpio_set_level(imu_config.io_cs, 1);
|
gpio_set_level(imu_config.io_cs, 1);
|
||||||
gpio_set_level(imu_config.io_wake, 1);
|
|
||||||
|
if (imu_config.io_wake != GPIO_NUM_NC)
|
||||||
|
gpio_set_level(imu_config.io_wake, 1);
|
||||||
|
|
||||||
gpio_set_level(imu_config.io_rst, 0); // set reset pin low
|
gpio_set_level(imu_config.io_rst, 0); // set reset pin low
|
||||||
vTaskDelay(50 / portTICK_PERIOD_MS); // 10ns min, set to 50ms to let things stabilize(Anton)
|
vTaskDelay(50 / portTICK_PERIOD_MS); // 10ns min, set to 50ms to let things stabilize(Anton)
|
||||||
gpio_set_level(imu_config.io_rst, 1); // bring out of reset
|
gpio_set_level(imu_config.io_rst, 1); // bring out of reset
|
||||||
|
|
|
||||||
43
BNO08x.hpp
43
BNO08x.hpp
|
|
@ -41,9 +41,9 @@ typedef struct bno08x_config_t {
|
||||||
uint64_t sclk_speed; ///<Desired SPI SCLK speed in Hz (max 3MHz)
|
uint64_t sclk_speed; ///<Desired SPI SCLK speed in Hz (max 3MHz)
|
||||||
bool debug_en; ///<Whether or not debugging print statements are enabled
|
bool debug_en; ///<Whether or not debugging print statements are enabled
|
||||||
|
|
||||||
/// @brief Default IMU configuration settings
|
#ifdef ESP32C3_IMU_CONFIG
|
||||||
#ifdef ESP32C3_IMU_CONFIG
|
/// @brief Default IMU configuration settings constructor for ESP32-C3, add
|
||||||
/// @brief Default IMU configuration settings for ESP32-C3
|
/// add_compile_definitions("ESP32C3_IMU_CONFIG") to CMakeList to use
|
||||||
bno08x_config_t()
|
bno08x_config_t()
|
||||||
: spi_peripheral(SPI2_HOST)
|
: spi_peripheral(SPI2_HOST)
|
||||||
, io_mosi(GPIO_NUM_4)
|
, io_mosi(GPIO_NUM_4)
|
||||||
|
|
@ -52,11 +52,11 @@ typedef struct bno08x_config_t {
|
||||||
, io_cs(GPIO_NUM_5)
|
, io_cs(GPIO_NUM_5)
|
||||||
, io_int(GPIO_NUM_6)
|
, io_int(GPIO_NUM_6)
|
||||||
, io_rst(GPIO_NUM_7)
|
, io_rst(GPIO_NUM_7)
|
||||||
, io_wake(GPIO_NUM_8)
|
, io_wake(GPIO_NUM_NC)
|
||||||
, sclk_speed(2000000UL) // 1MHz SCLK speed
|
, sclk_speed(2000000UL) // 2MHz SCLK speed
|
||||||
, debug_en(false)
|
, debug_en(false) {}
|
||||||
{}
|
#else
|
||||||
#else
|
/// @brief Default IMU configuration settings constructor for ESP32
|
||||||
bno08x_config_t()
|
bno08x_config_t()
|
||||||
: spi_peripheral(SPI3_HOST)
|
: spi_peripheral(SPI3_HOST)
|
||||||
, io_mosi(GPIO_NUM_23)
|
, io_mosi(GPIO_NUM_23)
|
||||||
|
|
@ -65,15 +65,28 @@ typedef struct bno08x_config_t {
|
||||||
, io_cs(GPIO_NUM_33)
|
, io_cs(GPIO_NUM_33)
|
||||||
, io_int(GPIO_NUM_26)
|
, io_int(GPIO_NUM_26)
|
||||||
, io_rst(GPIO_NUM_32)
|
, io_rst(GPIO_NUM_32)
|
||||||
, io_wake(GPIO_NUM_4)
|
, io_wake(GPIO_NUM_NC)
|
||||||
,
|
, sclk_speed(2000000UL) // 2MHz SCLK speed
|
||||||
// sclk_speed(10000U), //clock slowed to see on AD2
|
// , sclk_speed(10000U), //clock slowed to see on AD2
|
||||||
sclk_speed(2000000UL) // 1MHz SCLK speed
|
, debug_en(false)
|
||||||
,
|
|
||||||
debug_en(false)
|
{}
|
||||||
|
#endif
|
||||||
|
/// @brief Overloaded IMU configuration settings constructor for custom pin settings
|
||||||
|
bno08x_config_t(spi_host_device_t spi_peripheral, gpio_num_t io_mosi, gpio_num_t io_miso, gpio_num_t io_sclk,
|
||||||
|
gpio_num_t io_cs, gpio_num_t io_int, gpio_num_t io_rst, gpio_num_t io_wake, uint64_t sclk_speed, bool debug)
|
||||||
|
: spi_peripheral(spi_peripheral)
|
||||||
|
, io_mosi(io_mosi)
|
||||||
|
, io_miso(io_miso)
|
||||||
|
, io_sclk(io_sclk)
|
||||||
|
, io_cs(io_cs)
|
||||||
|
, io_int(io_int)
|
||||||
|
, io_rst(io_rst)
|
||||||
|
, io_wake(io_wake)
|
||||||
|
, sclk_speed(sclk_speed)
|
||||||
|
, debug_en(false)
|
||||||
|
|
||||||
{}
|
{}
|
||||||
#endif
|
|
||||||
} bno08x_config_t;
|
} bno08x_config_t;
|
||||||
|
|
||||||
class BNO08x {
|
class BNO08x {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue