diff --git a/src/W800_SDK_v1.00.10/app/app_drivers/i2c/bma456_wrapper.c b/src/W800_SDK_v1.00.10/app/app_drivers/i2c/bma456_wrapper.c new file mode 100644 index 0000000..83d15d2 --- /dev/null +++ b/src/W800_SDK_v1.00.10/app/app_drivers/i2c/bma456_wrapper.c @@ -0,0 +1,71 @@ +/** + * @file bma456_wrapper.c + * @author Anatole SCHRAMM-HENRY + * @brief Source file containing custom helper functions that are not part of the Bosh official driver + * @version 0.1 + * @date 2024-01-05 + * + * @copyright MIT + * + */ + +#include "bma456_wrapper.h" +#include "i2c.h" +#include "app_utils.h" + +static BMA4_INTF_RET_TYPE _bma456_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 _bma456_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 _bma456_delay_us(uint32_t period, void *intf_ptr) +{ + (void) intf_ptr; + us_delay(period); +} + +bool bma456_wrapper_interface_init(struct bma4_dev *bma, uint8_t *dev_addr_ptr) +{ + if(!bma || !dev_addr_ptr) return false; + + /* Init the BMA456 */ + bma->intf = BMA4_I2C_INTF; + bma->intf_ptr = dev_addr_ptr; + bma->bus_read = &(_bma456_i2c_read); + bma->bus_write = &(_bma456_i2c_write); + bma->variant = BMA45X_VARIANT; + bma->delay_us = &(_bma456_delay_us); + bma->read_write_len = 500; // Default was 46 + bma->perf_mode_status = BMA4_DISABLE; + + return true; +} + +bool bma456_wrapper_is_config_file_already_loaded(struct bma4_dev *bma) +{ + uint8_t status = 0; + + if(!bma) return false; + + /* Read the status of BMA4 accelerometer to know if the ASIC is running or not */ + if(bma4_read_regs(BMA4_INTERNAL_STAT, &status, 1, bma) == BMA4_OK); + { + /* Only get the message bits */ + status &= BMA4_CONFIG_STREAM_MESSAGE_MSK; + + return status == BMA4_ASIC_INITIALIZED; + } + + /* If we failed to read the register, just say it is not loaded */ + return false; +} \ No newline at end of file diff --git a/src/W800_SDK_v1.00.10/app/app_drivers/i2c/bma456_wrapper.h b/src/W800_SDK_v1.00.10/app/app_drivers/i2c/bma456_wrapper.h new file mode 100644 index 0000000..c281438 --- /dev/null +++ b/src/W800_SDK_v1.00.10/app/app_drivers/i2c/bma456_wrapper.h @@ -0,0 +1,37 @@ +/** + * @file bma456_wrapper.h + * @author Anatole SCHRAMM-HENRY + * @brief Header file containing custom helper functions that are not part of the Bosh official driver + * @version 0.1 + * @date 2024-01-05 + * + * @copyright MIT + * + */ + +#ifndef BMA456_WRAPPER_H +#define BMA456_WRAPPER_H + +#include "wm_type_def.h" +#include "bma456w.h" + +/** + * @brief Helper function used to initialize the BMA456 driver interface (i2c read and write functions, us_delay functions and other settings). + * + * @param bma a pointer to a user allocated @ref bma4_dev object + * @param dev_addr_ptr a pointer to an uint8_t containing the device's i2c address + * @return true on initialization success + * @return false on failure + */ +bool bma456_wrapper_interface_init(struct bma4_dev *bma, uint8_t *dev_addr_ptr); + +/** + * @brief Helper function returning the state of the ASIC's config file loading. + * + * @param bma a pointer to a user allocated and initialized @ref bma4_dev object + * @return true if the config file was already loaded in the BMA456 + * @return false if a config file is not loaded in the BMA456 ie ASIC is not started + */ +bool bma456_wrapper_is_config_file_already_loaded(struct bma4_dev *bma); + +#endif //BMA456_WRAPPER_H \ No newline at end of file