Added overloaded constructor to config struct

This commit is contained in:
myles-parfeniuk 2024-02-28 19:54:57 -08:00
parent 62da810dbc
commit aca0ee421d
2 changed files with 42 additions and 19 deletions

View File

@ -51,17 +51,24 @@ BNO08x::BNO08x(bno08x_config_t imu_config)
// SPI non-driver-controlled GPIO config
// configure outputs
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.pull_down_en = GPIO_PULLDOWN_DISABLE;
outputs_config.pull_up_en = GPIO_PULLUP_DISABLE;
outputs_config.intr_type = GPIO_INTR_DISABLE;
gpio_config(&outputs_config);
gpio_set_level(imu_config.io_cs, 1);
gpio_set_level(imu_config.io_wake, 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)
gpio_config_t inputs_config;
inputs_config.pin_bit_mask = (1ULL << imu_config.io_int);
@ -208,7 +215,10 @@ bool BNO08x::wait_for_device_int() {
*/
bool BNO08x::hard_reset() {
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
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

View File

@ -41,9 +41,9 @@ typedef struct bno08x_config_t {
uint64_t sclk_speed; ///<Desired SPI SCLK speed in Hz (max 3MHz)
bool debug_en; ///<Whether or not debugging print statements are enabled
/// @brief Default IMU configuration settings
#ifdef ESP32C3_IMU_CONFIG
/// @brief Default IMU configuration settings for ESP32-C3
#ifdef ESP32C3_IMU_CONFIG
/// @brief Default IMU configuration settings constructor for ESP32-C3, add
/// add_compile_definitions("ESP32C3_IMU_CONFIG") to CMakeList to use
bno08x_config_t()
: spi_peripheral(SPI2_HOST)
, io_mosi(GPIO_NUM_4)
@ -52,11 +52,11 @@ typedef struct bno08x_config_t {
, io_cs(GPIO_NUM_5)
, io_int(GPIO_NUM_6)
, io_rst(GPIO_NUM_7)
, io_wake(GPIO_NUM_8)
, sclk_speed(2000000UL) // 1MHz SCLK speed
, debug_en(false)
{}
#else
, io_wake(GPIO_NUM_NC)
, sclk_speed(2000000UL) // 2MHz SCLK speed
, debug_en(false) {}
#else
/// @brief Default IMU configuration settings constructor for ESP32
bno08x_config_t()
: spi_peripheral(SPI3_HOST)
, io_mosi(GPIO_NUM_23)
@ -65,15 +65,28 @@ typedef struct bno08x_config_t {
, io_cs(GPIO_NUM_33)
, io_int(GPIO_NUM_26)
, io_rst(GPIO_NUM_32)
, io_wake(GPIO_NUM_4)
,
// sclk_speed(10000U), //clock slowed to see on AD2
sclk_speed(2000000UL) // 1MHz SCLK speed
,
debug_en(false)
, io_wake(GPIO_NUM_NC)
, sclk_speed(2000000UL) // 2MHz SCLK speed
// , sclk_speed(10000U), //clock slowed to see on AD2
, 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;
class BNO08x {