From b11810decf848193ddde66ed512fa4fc98382b8b Mon Sep 17 00:00:00 2001 From: anschrammh Date: Fri, 5 Jan 2024 21:28:52 +0100 Subject: [PATCH] Reworked the BMA456's initialization routine --- .../watch_peripherals/watch_peripherals.c | 61 +++++++------------ 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c index 259c0e1..e3d05b9 100644 --- a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c +++ b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c @@ -9,6 +9,7 @@ #include "i2c.h" #include "BMP280.h" #include "bma456w.h" +#include "bma456_wrapper.h" #include "CST816D.h" #include "app_utils.h" #include "watch_settings.h" @@ -48,8 +49,8 @@ static BatteryControllerStatusChangeCb_t _BatteryControllerStatusChangeCb = NULL static bool _wakeup_is_io = false; static bool _wakeup_is_timer = false; -/* BMA456 strcture */ -struct +/* BMA456 structure */ +static struct { uint8_t dev_addr; struct bma4_dev bma; @@ -564,7 +565,7 @@ bool watch_peripherals_pressure_sensor_init(void) else APP_LOG_INFO("Inited BMP280"); - if(!BMP280_configure(BMP280_Forced, BMP280_Oversampling_x16, BMP280_Oversampling_x16, BMP280_Filter_x16, BMP280_Standby_4000MS)) + if(!BMP280_configure(BMP280_Forced, BMP280_Oversampling_x2, BMP280_Oversampling_x16, BMP280_Filter_x4, BMP280_Standby_4000MS)) { APP_LOG_ERROR("Failed to configure BMP280"); return false; @@ -584,38 +585,15 @@ float watch_peripherals_pressure_sensor_get_pressure(float * const temperature) return BMP280_get_pressure(temperature); } -static BMA4_INTF_RET_TYPE _bma4_i2c_read(uint8_t reg_addr, uint8_t *read_data, uint32_t len, void *intf_ptr) -{ - uint8_t dev_address = *(uint8_t*)intf_ptr; - - return !i2c_read(dev_address, reg_addr, read_data, len); -} - -static BMA4_INTF_RET_TYPE _bma4_i2c_write(uint8_t reg_addr, const uint8_t *read_data, uint32_t len, void *intf_ptr) -{ - uint8_t dev_address = *(uint8_t*)intf_ptr; - - return !i2c_write(dev_address, reg_addr, read_data, len); -} - - -static void _bma4_delay_us(uint32_t period, void *intf_ptr) -{ - (void) intf_ptr; - us_delay(period); -} - bool watch_peripherals_accelerometer_init(void) { - /* Init the BMA456 */ - _bma456.bma.intf = BMA4_I2C_INTF; - _bma456.bma.intf_ptr = &_bma456.dev_addr; - _bma456.bma.bus_read = &(_bma4_i2c_read); - _bma456.bma.bus_write = &(_bma4_i2c_write); - _bma456.bma.variant = BMA45X_VARIANT; - _bma456.bma.delay_us = &(_bma4_delay_us); - _bma456.bma.read_write_len = 46; - _bma456.bma.perf_mode_status = BMA4_DISABLE; + if(bma456_wrapper_interface_init(&_bma456.bma, &_bma456.dev_addr)) + APP_LOG_INFO("BMA456 interface init ok"); + else + { + APP_LOG_ERROR("Failed to init BMA456 interface"); + return false; + } if(bma456w_init(&_bma456.bma) == BMA4_OK) APP_LOG_INFO("BMA456 init"); @@ -624,6 +602,14 @@ bool watch_peripherals_accelerometer_init(void) APP_LOG_ERROR("Failed to init BMA456"); return false; } + + /* Before we do a soft reset of the sensor, let's check if the config file was not already loaded ... */ + if(bma456_wrapper_is_config_file_already_loaded(&_bma456.bma)) + { + APP_LOG_INFO("BMA456 config file already loaded"); + return true; + } + else APP_LOG_INFO("BMA456 config file needs loading"); if(bma4_soft_reset(&_bma456.bma) == BMA4_OK) APP_LOG_INFO("BMA456 soft reset"); @@ -754,10 +740,10 @@ bool watch_peripherals_accelerometer_step_counter_enable(bool enable) _bma456.step_counter_enable = enable; if(bma456w_feature_enable(BMA456W_STEP_CNTR, BMA4_ENABLE, &_bma456.bma) == BMA4_OK) - APP_LOG_INFO("BMA456 step cnter feature enable ok"); + APP_LOG_INFO("BMA456 step counter feature enable ok"); else { - APP_LOG_ERROR("BMA456 step cnter feature enable failed"); + APP_LOG_ERROR("BMA456 step counter feature enable failed"); return false; } @@ -791,11 +777,10 @@ bool watch_peripherals_accelerometer_step_count_reset(void) void watch_peripherals_watch_sleep(void) { extern LCDConfig_t LCDConfig; - // First, we disable the display backlight and we set all the peripherals in their low power mode + /* First, we disable the display backlight and we set all the peripherals in their low power mode */ lcd_set_backlight(&LCDConfig, 0); lcd_sleep(&LCDConfig, true); - // Set a restore function to apply the correct power mode when we leave sleep - //watch_peripherals_magnetometer_power_mode_set(QMC5883L_Mode_Control_Standby); + /* Set a restore function to apply the correct power mode when we leave sleep */ if(CST816D_sleep()) APP_LOG_DEBUG("CST816D Sleep cmd ok"); else