diff options
| author | Bosch Sensortec <github@bosch-sensortec.com> | 2018-07-26 08:45:20 +0200 |
|---|---|---|
| committer | Kevin Goveas <kevin.goveas@bosch-sensortec.com> | 2018-07-26 08:45:35 +0200 |
| commit | 5902c8af798ef1a12fb84097320a03642c7f3eaa (patch) | |
| tree | 556717e1b6c92c1e930b7167d124d1617a817e55 | |
Finalized disclaimer information.
| -rw-r--r-- | Kconfig | 115 | ||||
| -rw-r--r-- | Makefile | 36 | ||||
| -rw-r--r-- | boschclass.c | 341 | ||||
| -rw-r--r-- | boschclass.h | 81 | ||||
| -rw-r--r-- | bs_log.c | 53 | ||||
| -rw-r--r-- | bs_log.h | 174 | ||||
| -rw-r--r-- | readme.md | 148 | ||||
| -rw-r--r-- | smi130.c | 18788 | ||||
| -rw-r--r-- | smi130.h | 11848 | ||||
| -rw-r--r-- | smi130_driver.c | 4021 | ||||
| -rw-r--r-- | smi130_driver.h | 411 | ||||
| -rw-r--r-- | smi130_i2c.c | 372 | ||||
| -rw-r--r-- | smi130_spi.c | 402 |
13 files changed, 36790 insertions, 0 deletions
diff --git a/Kconfig b/Kconfig new file mode 100644 index 000000000000..06e39ddc1159 --- /dev/null +++ b/Kconfig @@ -0,0 +1,115 @@ +# +# Makefile for Bosch sensors driver. +# +config BOSCH_DRIVER_LOG_FUNC + tristate "Bosch Sensortec driver smart log function support" + depends on (I2C || SPI_MASTER) && SYSFS + help + If you say yes here, you get support for smart log function in Bosch Sensortec driver. + +config SENSORS_BMA2X2 + tristate "BMA2x2 acceleration sensor support" + depends on I2C + help + If you say yes here, you get support for Bosch Sensortec's + acceleration sensors BMA255/BMA254/BMA355/BMA250E/BMA222E/BMA280. + +config SENSORS_BMA2X2_ENABLE_INT1 + tristate "BMA2X2 acceleration sensor interrupt INT1 support" + depends on SENSORS_BMA2X2 + help + If you say yes here, you get INT1 support for Bosch Sensortec + acceleration sensors BMA255/BMA250E/BMA222E/BMA280. + Select it will disable interrupt INT2 support + +config SENSORS_BMA2X2_ENABLE_INT2 + tristate "BMA2X2 acceleration sensor interrupt INT2 support" + depends on SENSORS_BMA2X2 && !SENSORS_BMA2X2_ENABLE_INT1 + help + If you say yes here, you get INT2 support for Bosch Sensortec + acceleration sensors BMA255/BMA250E/BMA222E/BMA280. + Can only open if you do NOT open interrupt INT1 support + +config SIG_MOTION + tristate "support significant motion sensor function" + depends on SENSORS_BMA2X2 && ( SENSORS_BMA2X2_ENABLE_INT1 || SENSORS_BMA2X2_ENABLE_INT2) + help + If you say yes here, if you want to support Bosch significant motion sensor function + +config DOUBLE_TAP + tristate "support double tap sensor function" + depends on SENSORS_BMA2X2 && ( SENSORS_BMA2X2_ENABLE_INT1 || SENSORS_BMA2X2_ENABLE_INT2) + help + If you say yes here, you get support Bosch double tap sensor function + +config SENSORS_BMG + tristate "Bosch Gyroscope Sensor Driver" + depends on I2C + help + If you say yes here, you get support for Bosch Sensortec's + gyroscope sensor drivers of BMG160/SMI055/BMI058 e.t.c. + + +config SENSORS_BMI058 + tristate "BMI058 Sensor Support" + depends on (SENSORS_BMG || SENSORS_BMA2X2) + help + If you say yes here, you get support for Bosch Sensortec's + sensor driver of BMI058. + +config SENSORS_YAS537 + tristate "YAS537 Magnetic Sensor Driver" + depends on I2C + help + If you say yes here, you get support for YAMAHA + sensor YAS537 Magnetic Sensor + +config SENSORS_BMM050 + tristate "BMM050 Magnetic Sensor Driver" + depends on I2C + help + If you say yes here, you get support for Bosch Sensortec's + sensor BMM050 Magnetic Sensor + +config SENSORS_AKM09911 + tristate "AKM09911 Mag Sensor Driver" + depends on I2C + help + If you say yes here, you get support AKM09911 Sensor support. + +config SENSORS_AKM09912 + tristate "AKM09912 Mag Sensor Driver" + depends on I2C + help + If you say yes here, you get support AKM09912 Sensor support. + +config SENSORS_BMA420 + tristate "BMA4XY Sensor Support" + depends on I2C || SPI_MASTER + help + If you say yes here, you get support for Bosch Sensortec's sensor driver of BMA420. +config SENSORS_BMA421 + tristate "BMA4XY Sensor Support" + depends on I2C || SPI_MASTER + help + If you say yes here, you get support for Bosch Sensortec's sensor driver of BMA421. +config SENSORS_BMA422 + tristate "BMA4XY Sensor Support" + depends on I2C || SPI_MASTER + help + If you say yes here, you get support for Bosch Sensortec's sensor driver of BMA422. +config SENSORS_BMA455 + tristate "BMA4XY Sensor Support" + depends on I2C || SPI_MASTER + help + If you say yes here, you get support for Bosch Sensortec's sensor driver of BMA455. + +config BMA4XY_MAG_INTERFACE_SUPPORT +tristate "BMA4XY Sensor mag interface support" +depends on SENSORS_BMA4XY + help + If you say yes here, you get support for Bosch Sensortec's + sensor driver of BMA4XY with mag sensor support. + + + diff --git a/Makefile b/Makefile new file mode 100644 index 000000000000..b374e00dc5bc --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +# +# Makefile for Bosch sensor driver. +# + +obj-$(CONFIG_BOSCH_DRIVER_LOG_FUNC) += bs_log.o +obj-y += boschclass.o +ifeq ($(CONFIG_BOSCH_DRIVER_LOG_FUNC),y) + EXTRA_CFLAGS += -DBOSCH_DRIVER_LOG_FUNC +endif + + + +obj-y += smi130_driver.o smi130.o +ifeq ($(CONFIG_SMI130_MAG_INTERFACE_SUPPORT),y) + EXTRA_CFLAGS += -DSMI130_MAG_INTERFACE_SUPPORT +endif +ifeq ($(CONFIG_SENSORS_SMI130_ENABLE_INT1),y) + EXTRA_CFLAGS += -DSMI130_ENABLE_INT1 +endif + +ifeq ($(CONFIG_SENSORS_SMI130_ENABLE_INT2),y) + EXTRA_CFLAGS += -DSMI130_ENABLE_INT2 +endif + +obj-y += smi130_i2c.o + +EXTRA_CFLAGS += -DSMI_USE_BASIC_I2C_FUNC + +obj-$(CONFIG_SENSORS_SMI130_SPI) += smi130_spi.o + + + + + + + diff --git a/boschclass.c b/boschclass.c new file mode 100644 index 000000000000..cf2e496ece27 --- /dev/null +++ b/boschclass.c @@ -0,0 +1,341 @@ +/*! + * @section LICENSE + * (C) Copyright 2011~2016 Bosch Sensortec GmbH All Rights Reserved + * + * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved + * + * This software program is licensed subject to the GNU General + * Public License (GPL).Version 2,June 1991, + * available at http://www.fsf.org/copyleft/gpl.html + * + * Special: Description of the Software: + * + * This software module (hereinafter called "Software") and any + * information on application-sheets (hereinafter called "Information") is + * provided free of charge for the sole purpose to support your application + * work. + * + * As such, the Software is merely an experimental software, not tested for + * safety in the field and only intended for inspiration for further development + * and testing. Any usage in a safety-relevant field of use (like automotive, + * seafaring, spacefaring, industrial plants etc.) was not intended, so there are + * no precautions for such usage incorporated in the Software. + * + * The Software is specifically designed for the exclusive use for Bosch + * Sensortec products by personnel who have special experience and training. Do + * not use this Software if you do not have the proper experience or training. + * + * This Software package is provided as is and without any expressed or + * implied warranties, including without limitation, the implied warranties of + * merchantability and fitness for a particular purpose. + * + * Bosch Sensortec and their representatives and agents deny any liability for + * the functional impairment of this Software in terms of fitness, performance + * and safety. Bosch Sensortec and their representatives and agents shall not be + * liable for any direct or indirect damages or injury, except as otherwise + * stipulated in mandatory applicable law. + * The Information provided is believed to be accurate and reliable. Bosch + * Sensortec assumes no responsibility for the consequences of use of such + * Information nor for any infringement of patents or other rights of third + * parties which may result from its use. + * + *------------------------------------------------------------------------------ + * The following Product Disclaimer does not apply to the BSX4-HAL-4.1NoFusion Software + * which is licensed under the Apache License, Version 2.0 as stated above. + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Product Disclaimer + * + * Common: + * + * Assessment of Products Returned from Field + * + * Returned products are considered good if they fulfill the specifications / + * test data for 0-mileage and field listed in this document. + * + * Engineering Samples + * + * Engineering samples are marked with (e) or (E). Samples may vary from the + * valid technical specifications of the series product contained in this + * data sheet. Therefore, they are not intended or fit for resale to + * third parties or for use in end products. Their sole purpose is internal + * client testing. The testing of an engineering sample may in no way replace + * the testing of a series product. Bosch assumes no liability for the use + * of engineering samples. The purchaser shall indemnify Bosch from all claims + * arising from the use of engineering samples. + * + * Intended use + * + * Provided that SMI130 is used within the conditions (environment, application, + * installation, loads) as described in this TCD and the corresponding + * agreed upon documents, Bosch ensures that the product complies with + * the agreed properties. Agreements beyond this require + * the written approval by Bosch. The product is considered fit for the intended + * use when the product successfully has passed the tests + * in accordance with the TCD and agreed upon documents. + * + * It is the responsibility of the customer to ensure the proper application + * of the product in the overall system/vehicle. + * + * Bosch does not assume any responsibility for changes to the environment + * of the product that deviate from the TCD and the agreed upon documents + * as well as all applications not released by Bosch + * + * The resale and/or use of products are at the purchaser’s own risk and + * responsibility. The examination and testing of the SMI130 + * is the sole responsibility of the purchaser. + * + * The purchaser shall indemnify Bosch from all third party claims + * arising from any product use not covered by the parameters of + * this product data sheet or not approved by Bosch and reimburse Bosch + * for all costs and damages in connection with such claims. + * + * The purchaser must monitor the market for the purchased products, + * particularly with regard to product safety, and inform Bosch without delay + * of all security relevant incidents. + * + * Application Examples and Hints + * + * With respect to any application examples, advice, normal values + * and/or any information regarding the application of the device, + * Bosch hereby disclaims any and all warranties and liabilities of any kind, + * including without limitation warranties of + * non-infringement of intellectual property rights or copyrights + * of any third party. + * The information given in this document shall in no event be regarded + * as a guarantee of conditions or characteristics. They are provided + * for illustrative purposes only and no evaluation regarding infringement + * of intellectual property rights or copyrights or regarding functionality, + * performance or error has been made. + * + * @filename boschclass.c + * @date 2015/11/17 13:44 + * @Modification Date 2018/06/21 15:03 + * @id "836294d" + * @version 1.5.9 + * + * @brief + */ +#include <linux/init.h> +#include <linux/types.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/random.h> +#include <linux/sched.h> +#include <linux/seq_file.h> +#include <linux/poll.h> +#include <linux/mutex.h> +#include <linux/rcupdate.h> +#include <linux/compiler.h> +#include <linux/compat.h> +#include "boschclass.h" +#include "bs_log.h" + +static LIST_HEAD(bosch_dev_list); + +/* + * bosch_mutex protects access to both bosch_dev_list and input_handler_list. + * This also causes bosch_[un]register_device and bosch_[un]register_handler + * be mutually exclusive which simplifies locking in drivers implementing + * input handlers. + */ +static DEFINE_MUTEX(bosch_mutex); + + +static void bosch_dev_release(struct device *device) +{ + struct bosch_dev *dev = to_bosch_dev(device); + if (NULL != dev) + kfree(dev); + module_put(THIS_MODULE); +} + + +#ifdef CONFIG_PM +static int bosch_dev_suspend(struct device *dev) +{ + return 0; +} + +static int bosch_dev_resume(struct device *dev) +{ + return 0; +} + +static const struct dev_pm_ops bosch_dev_pm_ops = { + .suspend = bosch_dev_suspend, + .resume = bosch_dev_resume, + .poweroff = bosch_dev_suspend, + .restore = bosch_dev_resume, +}; +#endif /* CONFIG_PM */ + +static const struct attribute_group *bosch_dev_attr_groups[] = { + NULL +}; + +static struct device_type bosch_dev_type = { + .groups = bosch_dev_attr_groups, + .release = bosch_dev_release, +#ifdef CONFIG_PM + .pm = &bosch_dev_pm_ops, +#endif +}; + + + +static char *bosch_devnode(struct device *dev, mode_t *mode) +{ + return kasprintf(GFP_KERNEL, "%s", dev_name(dev)); +} + +struct class bosch_class = { + .name = "bosch", + .owner = THIS_MODULE, + .devnode = (void*)bosch_devnode, + .dev_release = bosch_dev_release, +}; +EXPORT_SYMBOL_GPL(bosch_class); + +/** + * bosch_allocate_device - allocate memory for new input device + * + * Returns prepared struct bosch_dev or NULL. + * + * NOTE: Use bosch_free_device() to free devices that have not been + * registered; bosch_unregister_device() should be used for already + * registered devices. + */ +struct bosch_dev *bosch_allocate_device(void) +{ + struct bosch_dev *dev; + + dev = kzalloc(sizeof(struct bosch_dev), GFP_KERNEL); + if (dev) { + dev->dev.type = &bosch_dev_type; + dev->dev.class = &bosch_class; + device_initialize(&dev->dev); + mutex_init(&dev->mutex); + INIT_LIST_HEAD(&dev->node); + __module_get(THIS_MODULE); + } + return dev; +} +EXPORT_SYMBOL(bosch_allocate_device); + + + +/** + * bosch_free_device - free memory occupied by bosch_dev structure + * @dev: input device to free + * + * This function should only be used if bosch_register_device() + * was not called yet or if it failed. Once device was registered + * use bosch_unregister_device() and memory will be freed once last + * reference to the device is dropped. + * + * Device should be allocated by bosch_allocate_device(). + * + * NOTE: If there are references to the input device then memory + * will not be freed until last reference is dropped. + */ +void bosch_free_device(struct bosch_dev *dev) +{ + if (dev) + bosch_put_device(dev); +} +EXPORT_SYMBOL(bosch_free_device); + +/** + * bosch_register_device - register device with input core + * @dev: device to be registered + * + * This function registers device with input core. The device must be + * allocated with bosch_allocate_device() and all it's capabilities + * set up before registering. + * If function fails the device must be freed with bosch_free_device(). + * Once device has been successfully registered it can be unregistered + * with bosch_unregister_device(); bosch_free_device() should not be + * called in this case. + */ +int bosch_register_device(struct bosch_dev *dev) +{ + const char *path; + int error; + + + /* + * If delay and period are pre-set by the driver, then autorepeating + * is handled by the driver itself and we don't do it in input.c. + */ + dev_set_name(&dev->dev, dev->name); + + error = device_add(&dev->dev); + if (error) + return error; + + path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); + PINFO("%s as %s\n", + dev->name ? dev->name : "Unspecified device", + path ? path : "N/A"); + kfree(path); + error = mutex_lock_interruptible(&bosch_mutex); + if (error) { + device_del(&dev->dev); + return error; + } + + list_add_tail(&dev->node, &bosch_dev_list); + + mutex_unlock(&bosch_mutex); + return 0; +} +EXPORT_SYMBOL(bosch_register_device); + +/** + * bosch_unregister_device - unregister previously registered device + * @dev: device to be unregistered + * + * This function unregisters an input device. Once device is unregistered + * the caller should not try to access it as it may get freed at any moment. + */ +void bosch_unregister_device(struct bosch_dev *dev) +{ + int ret = 0; + ret = mutex_lock_interruptible(&bosch_mutex); + if(ret){ + return; + } + + list_del_init(&dev->node); + mutex_unlock(&bosch_mutex); + device_unregister(&dev->dev); +} +EXPORT_SYMBOL(bosch_unregister_device); + +static int __init bosch_init(void) +{ + int err; + /*bosch class register*/ + err = class_register(&bosch_class); + if (err) { + pr_err("unable to register bosch_dev class\n"); + return err; + } + return err; +} + +static void __exit bosch_exit(void) +{ + /*bosch class*/ + class_unregister(&bosch_class); +} + +/*subsys_initcall(bosch_init);*/ + +MODULE_AUTHOR("contact@bosch-sensortec.com"); +MODULE_DESCRIPTION("BST CLASS CORE"); +MODULE_LICENSE("GPL V2"); + +module_init(bosch_init); +module_exit(bosch_exit); diff --git a/boschclass.h b/boschclass.h new file mode 100644 index 000000000000..505f1556f717 --- /dev/null +++ b/boschclass.h @@ -0,0 +1,81 @@ +/*! + * @section LICENSE + * (C) Copyright 2011~2016 Bosch Sensortec GmbH All Rights Reserved + * + * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved + * + * This software program is licensed subject to the GNU General + * Public License (GPL).Version 2,June 1991, + * available at http://www.fsf.org/copyleft/gpl.html + * + * @filename boschcalss.h + * @date 2015/11/17 13:44 + * @Modification Date 2018/06/21 15:03 + * @id "836294d" + * @version 1.5.9 + * + * @brief + */ + +#ifndef _BSTCLASS_H +#define _BSTCLASS_H + +#ifdef __KERNEL__ +#include <linux/time.h> +#include <linux/list.h> +#else +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <linux/types.h> +#endif + +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/mod_devicetable.h> + +struct bosch_dev { + const char *name; + + int (*open)(struct bosch_dev *dev); + void (*close)(struct bosch_dev *dev); + struct mutex mutex; + struct device dev; + struct list_head node; +}; + +#define to_bosch_dev(d) container_of(d, struct bosch_dev, dev) + +struct bosch_dev *bosch_allocate_device(void); +void bosch_free_device(struct bosch_dev *dev); + +static inline struct bosch_dev *bosch_get_device(struct bosch_dev *dev) +{ + return dev ? to_bosch_dev(get_device(&dev->dev)) : NULL; +} + +static inline void bosch_put_device(struct bosch_dev *dev) +{ + if (dev) + put_device(&dev->dev); +} + +static inline void *bosch_get_drvdata(struct bosch_dev *dev) +{ + return dev_get_drvdata(&dev->dev); +} + +static inline void bosch_set_drvdata(struct bosch_dev *dev, void *data) +{ + dev_set_drvdata(&dev->dev, data); +} + +int __must_check bosch_register_device(struct bosch_dev *); +void bosch_unregister_device(struct bosch_dev *); + +void bosch_reset_device(struct bosch_dev *); + + +extern struct class bosch_class; + +#endif diff --git a/bs_log.c b/bs_log.c new file mode 100644 index 000000000000..c0dbc22fb117 --- /dev/null +++ b/bs_log.c @@ -0,0 +1,53 @@ +/*! + * @section LICENSE + * (C) Copyright 2011~2016 Bosch Sensortec GmbH All Rights Reserved + * + * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved + * + * This software program is licensed subject to the GNU General + * Public License (GPL).Version 2,June 1991, + * available at http://www.fsf.org/copyleft/gpl.html + * + * @filename bs_log.c + * @date "Wed Sep 24 15:27:12 2014 +0800" + * @Modification Date "Thu June 21 15:03 2018 +0100" + * @id "e416c14" + * + * @brief + * The source file of BOSCH SENSOR LOG +*/ + + +#ifdef __KERNEL__ +#include <linux/kernel.h> +#include <linux/unistd.h> +#include <linux/types.h> +#else +#include <unistd.h> +#include <sys/types.h> +#endif + +#include <linux/time.h> +#include <linux/version.h> +#include <linux/module.h> +#include <linux/init.h> + +#ifdef BOSCH_DRIVER_LOG_FUNC +#define BSLOG_VAR_DEF +#include "bs_log.h" + +void set_debug_log_level(uint8_t level) +{ + debug_log_level = level; +} + +uint8_t get_debug_log_level(void) +{ + return debug_log_level; +} + +EXPORT_SYMBOL(set_debug_log_level); +EXPORT_SYMBOL(get_debug_log_level); + +#endif/*BOSCH_DRIVER_LOG_FUNC*/
+/*@}*/ diff --git a/bs_log.h b/bs_log.h new file mode 100644 index 000000000000..758ea0b8cbb8 --- /dev/null +++ b/bs_log.h @@ -0,0 +1,174 @@ +/*! + * @section LICENSE + * (C) Copyright 2011~2016 Bosch Sensortec GmbH All Rights Reserved + * + * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved + * + * This software program is licensed subject to the GNU General + * Public License (GPL).Version 2,June 1991, + * available at http://www.fsf.org/copyleft/gpl.html + * + * @filename bs_log.h + * @date "Sat Oct 11 16:12:16 2014 +0800" + * @Modification Date "Thu June 21 15:03 2018 +0100" + * @id "762cc9e" + * + * @brief + * The head file of BOSCH SENSOR LOG +*/ + +#ifndef __BS_LOG_H +#define __BS_LOG_H + +#include <linux/kernel.h> + +/*! @ trace functions + @{*/ +/*! ERROR LOG LEVEL */ +#define LOG_LEVEL_E 3 +/*! NOTICE LOG LEVEL */ +#define LOG_LEVEL_N 5 +/*! INFORMATION LOG LEVEL */ +#define LOG_LEVEL_I 6 +/*! DEBUG LOG LEVEL */ +#define LOG_LEVEL_D 7 +/*! DEBUG_FWDL LOG LEVEL */ +#define LOG_LEVEL_DF 10 +/*! DEBUG_DATA LOG LEVEL */ +#define LOG_LEVEL_DA 15 +/*! ALL LOG LEVEL */ +#define LOG_LEVEL_A 20 + +#ifndef MODULE_TAG +/*! MODULE TAG DEFINATION */ +#define MODULE_TAG "<BS_LOG>" +#endif + +#ifndef LOG_LEVEL +/*! LOG LEVEL DEFINATION */ +#define LOG_LEVEL LOG_LEVEL_I +#endif + +#ifdef BOSCH_DRIVER_LOG_FUNC + #ifdef BSLOG_VAR_DEF + uint8_t debug_log_level = LOG_LEVEL; + #else + extern uint8_t debug_log_level; + #endif + + /*! print error message */ + #define PERR(fmt, args...) do\ + {\ + if (debug_log_level >= LOG_LEVEL_E)\ + printk(KERN_INFO "\n" "[E]" KERN_ERR MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args);\ + } while (0) + + /*! print notice message */ + #define PNOTICE(fmt, args...) do\ + {\ + if (debug_log_level >= LOG_LEVEL_N)\ + printk(KERN_INFO "\n" "[N]" KERN_NOTICE MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args);\ + } while (0) + + /*! print information message */ + #define PINFO(fmt, args...) do\ + {\ + if (debug_log_level >= LOG_LEVEL_I)\ + printk(KERN_INFO "\n" "[I]" KERN_INFO MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args);\ + } while (0) + + /*! print debug message */ + #define PDEBUG(fmt, args...) do\ + {\ + if (debug_log_level >= LOG_LEVEL_D)\ + printk(KERN_INFO "\n" "[D]" KERN_DEBUG MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args);\ + } while (0) + + /*! print debug fw download message */ + #define PDEBUG_FWDL(fmt, args...) do\ + {\ + if (debug_log_level >= LOG_LEVEL_DF)\ + printk(KERN_INFO "\n" "[DF]" KERN_DEBUG MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args);\ + } while (0) + + /*! print debug data log message */ + #define PDEBUG_DLOG(fmt, args...) do\ + {\ + if (debug_log_level >= LOG_LEVEL_DA)\ + printk(KERN_INFO "\n" "[DA]" KERN_DEBUG MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args);\ + } while (0) + + void set_debug_log_level(uint8_t level); + uint8_t get_debug_log_level(void); + +#else + + #if (LOG_LEVEL >= LOG_LEVEL_E) + /*! print error message */ + #define PERR(fmt, args...) \ + printk(KERN_INFO "\n" "[E]" KERN_ERR MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args) + #else + /*! invalid message */ + #define PERR(fmt, args...) + #endif + + #if (LOG_LEVEL >= LOG_LEVEL_N) + /*! print notice message */ + #define PNOTICE(fmt, args...) \ + printk(KERN_INFO "\n" "[N]" KERN_NOTICE MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args) + #else + /*! invalid message */ + #define PNOTICE(fmt, args...) + #endif + + #if (LOG_LEVEL >= LOG_LEVEL_I) + /*! print information message */ + #define PINFO(fmt, args...) printk(KERN_INFO "\n" "[I]" KERN_INFO MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args) + #else + /*! invalid message */ + #define PINFO(fmt, args...) + #endif + + #if (LOG_LEVEL >= LOG_LEVEL_D) + /*! print debug message */ + #define PDEBUG(fmt, args...) printk(KERN_INFO "\n" "[D]" KERN_DEBUG MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args) + #else + /*! invalid message */ + #define PDEBUG(fmt, args...) + #endif + + #if (LOG_LEVEL >= LOG_LEVEL_DF) + /*! print debug fw download message */ + #define PDEBUG_FWDL(fmt, args...) printk(KERN_INFO "\n" "[DF]" KERN_DEBUG MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args) + #else + /*! invalid message */ + #define PDEBUG_FWDL(fmt, args...) + #endif + + #if (LOG_LEVEL >= LOG_LEVEL_DA) + /*! print debug data log message */ + #define PDEBUG_DLOG(fmt, args...) printk(KERN_INFO "\n" "[DA]" KERN_DEBUG MODULE_TAG \ + "<%s><%d>" fmt "\n", __func__, __LINE__, ##args) + #else + /*! invalid message */ + #define PDEBUG_DLOG(fmt, args...) + #endif + + #define set_debug_log_level(level) {} + #define get_debug_log_level() (LOG_LEVEL) + +#endif + +#endif/*__BS_LOG_H*/ +/*@}*/ diff --git a/readme.md b/readme.md new file mode 100644 index 000000000000..50b45a7e5de3 --- /dev/null +++ b/readme.md @@ -0,0 +1,148 @@ +# SMI130 sensor API
+
+## Introduction
+
+This package contains the Robert Bosch GmbH's SMI130 sensor driver (sensor API)
+
+## Version
+
+File | Version | Date
+----------------|---------|---------------
+smi130.h | 2.0.9 | 2018/06/21
+smi130.c | 2.0.9 | 2018/06/21
+smi130_spi.c | 1.3 | 2018/06/21
+smi130_i2c.c | 1.3 | 2018/06/21
+smi130_driver.h | 1.3 | 2018/06/21
+smi130_driver.c | 1.3 | 2018/06/21
+bs_log.h | | 2018/06/21
+bs_log.c | | 2018/06/21
+boschclass.h | 1.5.9 | 2018/06/21
+boschclass.c | 1.5.9 | 2018/06/21
+
+## File information
+
+* smi130.h : The head file of SMI130API
+* smi130.c : Sensor Driver for SMI130 sensor
+* smi130_spi.c : This file implements moudle function, which add the driver to SPI core.
+* smi130_i2c.c : This file implements moudle function, which add the driver to I2C core.
+* smi130_driver.h : The head file of SMI130 device driver core code
+* smi130_driver.c : This file implements the core code of SMI130 device driver
+* bs_log.h : The head file of BOSCH SENSOR LOG
+* bs_log.c : The source file of BOSCH SENSOR LOG
+* boschclass.h :
+* boschclass.c :
+
+## Supported sensor interface
+
+* SPI 4-wire
+* I2C
+
+## Copyright
+
+Copyright (C) 2016 - 2017 Bosch Sensortec GmbH
+Modification Copyright (C) 2018 Robert Bosch Kft All Rights Reserved
+
+This software program is licensed subject to the GNU General
+Public License (GPL).Version 2,June 1991,
+available at http://www.fsf.org/copyleft/gpl.html
+
+Special: Description of the Software:
+
+This software module (hereinafter called "Software") and any
+information on application-sheets (hereinafter called "Information") is
+provided free of charge for the sole purpose to support your application
+work.
+
+As such, the Software is merely an experimental software, not tested for
+safety in the field and only intended for inspiration for further development
+and testing. Any usage in a safety-relevant field of use (like automotive,
+seafaring, spacefaring, industrial plants etc.) was not intended, so there are
+no precautions for such usage incorporated in the Software.
+
+The Software is specifically designed for the exclusive use for Bosch
+Sensortec products by personnel who have special experience and training. Do
+not use this Software if you do not have the proper experience or training.
+
+This Software package is provided as is and without any expressed or
+implied warranties, including without limitation, the implied warranties of
+merchantability and fitness for a particular purpose.
+
+Bosch Sensortec and their representatives and agents deny any liability for
+the functional impairment of this Software in terms of fitness, performance
+and safety. Bosch Sensortec and their representatives and agents shall not be
+liable for any direct or indirect damages or injury, except as otherwise
+stipulated in mandatory applicable law.
+The Information provided is believed to be accurate and reliable. Bosch
+Sensortec assumes no responsibility for the consequences of use of such
+Information nor for any infringement of patents or other rights of third
+parties which may result from its use.
+
+------------------------------------------------------------------------------
+The following Product Disclaimer does not apply to the Kernel Driver
+This software program is licensed subject to the GNU General
+Public License (GPL).Version 2,June 1991,
+available at http://www.fsf.org/copyleft/gpl.html
+
+Product Disclaimer
+
+Common:
+
+Assessment of Products Returned from Field
+
+Returned products are considered good if they fulfill the specifications /
+test data for 0-mileage and field listed in this document.
+
+Engineering Samples
+
+Engineering samples are marked with (e) or (E). Samples may vary from the
+valid technical specifications of the series product contained in this
+data sheet. Therefore, they are not intended or fit for resale to
+third parties or for use in end products. Their sole purpose is internal
+client testing. The testing of an engineering sample may in no way replace
+the testing of a series product. Bosch assumes no liability for the use
+of engineering samples. The purchaser shall indemnify Bosch from all claims
+arising from the use of engineering samples.
+
+Intended use
+
+Provided that SMI130 is used within the conditions (environment, application,
+installation, loads) as described in this TCD and the corresponding
+agreed upon documents, Bosch ensures that the product complies with
+the agreed properties. Agreements beyond this require
+the written approval by Bosch. The product is considered fit for the intended
+use when the product successfully has passed the tests
+in accordance with the TCD and agreed upon documents.
+
+It is the responsibility of the customer to ensure the proper application
+of the product in the overall system/vehicle.
+
+Bosch does not assume any responsibility for changes to the environment
+of the product that deviate from the TCD and the agreed upon documents
+as well as all applications not released by Bosch
+
+The resale and/or use of products are at the purchaser’s own risk and
+responsibility. The examination and testing of the SMI130
+is the sole responsibility of the purchaser.
+
+The purchaser shall indemnify Bosch from all third party claims
+arising from any product use not covered by the parameters of
+this product data sheet or not approved by Bosch and reimburse Bosch
+for all costs and damages in connection with such claims.
+
+The purchaser must monitor the market for the purchased products,
+particularly with regard to product safety, and inform Bosch without delay
+of all security relevant incidents.
+
+Application Examples and Hints
+
+With respect to any application examples, advice, normal values
+and/or any information regarding the application of the device,
+Bosch hereby disclaims any and all warranties and liabilities of any kind,
+including without limitation warranties of
+non-infringement of intellectual property rights or copyrights
+of any third party.
+The information given in this document shall in no event be regarded
+as a guarantee of conditions or characteristics. They are provided
+for illustrative purposes only and no evaluation regarding infringement
+of intellectual property rights or copyrights or regarding functionality,
+performance or error has been made.
\ No newline at end of file diff --git a/smi130.c b/smi130.c new file mode 100644 index 000000000000..995b7d699da5 --- /dev/null +++ b/smi130.c @@ -0,0 +1,18788 @@ +/* +* @section LICENSE +* (C) Copyright 2011~2018 Bosch Sensortec GmbH All Rights Reserved +* +* (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved +* +* This software program is licensed subject to the GNU General +* Public License (GPL).Version 2,June 1991, +* available at http://www.fsf.org/copyleft/gpl.html + +* +* @filename smi130.c +* @Date: 2015/04/02 +* @Modification Date 2018/06/21 15:03 +* @id 836294d +* @Revision: 2.0.9 $ +* +* Usage: Sensor Driver for SMI130 sensor +* +* Special: Description of the Software: +* +* This software module (hereinafter called "Software") and any +* information on application-sheets (hereinafter called "Information") is +* provided free of charge for the sole purpose to support your application +* work. +* +* As such, the Software is merely an experimental software, not tested for +* safety in the field and only intended for inspiration for further development +* and testing. Any usage in a safety-relevant field of use (like automotive, +* seafaring, spacefaring, industrial plants etc.) was not intended, so there are +* no precautions for such usage incorporated in the Software. +* +* The Software is specifically designed for the exclusive use for Bosch +* Sensortec products by personnel who have special experience and training. Do +* not use this Software if you do not have the proper experience or training. +* +* This Software package is provided as is and without any expressed or +* implied warranties, including without limitation, the implied warranties of +* merchantability and fitness for a particular purpose. +* +* Bosch Sensortec and their representatives and agents deny any liability for +* the functional impairment of this Software in terms of fitness, performance +* and safety. Bosch Sensortec and their representatives and agents shall not be +* liable for any direct or indirect damages or injury, except as otherwise +* stipulated in mandatory applicable law. +* The Information provided is believed to be accurate and reliable. Bosch +* Sensortec assumes no responsibility for the consequences of use of such +* Information nor for any infringement of patents or other rights of third +* parties which may result from its use. +* +*------------------------------------------------------------------------------ +* The following Product Disclaimer does not apply to the BSX4-HAL-4.1NoFusion Software +* which is licensed under the Apache License, Version 2.0 as stated above. +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Product Disclaimer +* +* Common: +* +* Assessment of Products Returned from Field +* +* Returned products are considered good if they fulfill the specifications / +* test data for 0-mileage and field listed in this document. +* +* Engineering Samples +* +* Engineering samples are marked with (e) or (E). Samples may vary from the +* valid technical specifications of the series product contained in this +* data sheet. Therefore, they are not intended or fit for resale to +* third parties or for use in end products. Their sole purpose is internal +* client testing. The testing of an engineering sample may in no way replace +* the testing of a series product. Bosch assumes no liability for the use +* of engineering samples. The purchaser shall indemnify Bosch from all claims +* arising from the use of engineering samples. +* +* Intended use +* +* Provided that SMI130 is used within the conditions (environment, application, +* installation, loads) as described in this TCD and the corresponding +* agreed upon documents, Bosch ensures that the product complies with +* the agreed properties. Agreements beyond this require +* the written approval by Bosch. The product is considered fit for the intended +* use when the product successfully has passed the tests +* in accordance with the TCD and agreed upon documents. +* +* It is the responsibility of the customer to ensure the proper application +* of the product in the overall system/vehicle. +* +* Bosch does not assume any responsibility for changes to the environment +* of the product that deviate from the TCD and the agreed upon documents +* as well as all applications not released by Bosch +* +* The resale and/or use of products are at the purchaser’s own risk and +* responsibility. The examination and testing of the SMI130 +* is the sole responsibility of the purchaser. +* +* The purchaser shall indemnify Bosch from all third party claims +* arising from any product use not covered by the parameters of +* this product data sheet or not approved by Bosch and reimburse Bosch +* for all costs and damages in connection with such claims. +* +* The purchaser must monitor the market for the purchased products, +* particularly with regard to product safety, and inform Bosch without delay +* of all security relevant incidents. +* +* Application Examples and Hints +* +* With respect to any application examples, advice, normal values +* and/or any information regarding the application of the device, +* Bosch hereby disclaims any and all warranties and liabilities of any kind, +* including without limitation warranties of +* non-infringement of intellectual property rights or copyrights +* of any third party. +* The information given in this document shall in no event be regarded +* as a guarantee of conditions or characteristics. They are provided +* for illustrative purposes only and no evaluation regarding infringement +* of intellectual property rights or copyrights or regarding functionality, +* performance or error has been made. +* +* +**************************************************************************/ +/*! file <SMI130 > + brief <Sensor driver for SMI130>*/ +#include "smi130.h" +#include <linux/kernel.h> + +/* user defined code to be added here ...*/ +struct smi130_t*p_smi130; +/* used for reading the mag trim values for compensation*/ +struct trim_data_t mag_trim; +/* the following variable used for avoiding the selecting of auto mode +when it is running in the manual mode of BMM150 mag interface*/ +u8 V_bmm150_maual_auto_condition_u8 = SMI130_INIT_VALUE; +/* used for reading the AKM compensating data*/ +struct bosch_akm_sensitivity_data_t akm_asa_data; +/* Assign the fifo time*/ +u32 V_fifo_time_U32 = SMI130_INIT_VALUE; + +/* FIFO data read for 1024 bytes of data*/ +u8 v_fifo_data_u8[FIFO_FRAME] = {SMI130_INIT_VALUE}; +/* YAMAHA-YAS532*/ +/* value of coeff*/ +static const int yas532_version_ac_coef[] = {YAS532_VERSION_AC_COEF_X, +YAS532_VERSION_AC_COEF_Y1, YAS532_VERSION_AC_COEF_Y2}; +/* used for reading the yas532 calibration data*/ +struct yas532_t yas532_data; +/* used for reading the yas537 calibration data*/ +struct yas537_t yas537_data; +/*! +* @brief +* This function is used for initialize +* bus read and bus write functions +* assign the chip id and device address +* chip id is read in the register 0x00 bit from 0 to 7 +* +* @param smi130 : structure pointer +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* @note +* While changing the parameter of the smi130_t +* consider the following point: +* Changing the reference value of the parameter +* will changes the local copy or local reference +* make sure your changes will not +* affect the reference value of the parameter +* (Better case don't change the reference value of the parameter) +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_init(struct smi130_t*smi130) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + u8 v_pmu_data_u8 = SMI130_INIT_VALUE; + /* assign smi130 ptr*/ + p_smi130 = smi130; + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_CHIP_ID__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* read Chip Id*/ + p_smi130->chip_id = v_data_u8; + /* To avoid gyro wakeup it is required to write 0x00 to 0x6C*/ + com_rslt += smi130_write_reg(SMI130_USER_PMU_TRIGGER_ADDR, + &v_pmu_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + return com_rslt; +} +/*! +* @brief +* This API write the data to +* the given register +* +* +* @param v_addr_u8 -> Address of the register +* @param v_data_u8 -> The data from the register +* @param v_len_u8 -> no of bytes to read +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_write_reg(u8 v_addr_u8, +u8*v_data_u8, u8 v_len_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write data from register*/ + com_rslt = + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130->dev_addr, + v_addr_u8, v_data_u8, v_len_u8); + } + return com_rslt; +} +/*! +* @brief +* This API reads the data from +* the given register +* +* +* @param v_addr_u8 -> Address of the register +* @param v_data_u8 -> The data from the register +* @param v_len_u8 -> no of bytes to read +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_reg(u8 v_addr_u8, +u8*v_data_u8, u8 v_len_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* Read data from register*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + v_addr_u8, v_data_u8, v_len_u8); + } + return com_rslt; +} +/*! +* @brief This API used to reads the fatal error +* from the Register 0x02 bit 0 +* This flag will be reset only by power-on-reset and soft reset +* +* +* @param v_fatal_err_u8 : The status of fatal error +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fatal_err(u8 +*v_fatal_err_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* reading the fatal error status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FATAL_ERR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fatal_err_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FATAL_ERR); + } + return com_rslt; +} +/*! +* @brief This API used to read the error code +* from register 0x02 bit 1 to 4 +* +* +* @param v_err_code_u8 : The status of error codes +* error_code | description +* ------------|--------------- +* 0x00 |no error +* 0x01 |ACC_CONF error (accel ODR and bandwidth not compatible) +* 0x02 |GYR_CONF error (Gyroscope ODR and bandwidth not compatible) +* 0x03 |Under sampling mode and interrupt uses pre filtered data +* 0x04 |reserved +* 0x05 |Selected trigger-readout offset in +* - |MAG_IF greater than selected ODR +* 0x06 |FIFO configuration error for header less mode +* 0x07 |Under sampling mode and pre filtered data as FIFO source +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_err_code(u8 +*v_err_code_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ERR_CODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_err_code_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_ERR_CODE); + } + return com_rslt; +} +/*! +* @brief This API Reads the i2c error code from the +* Register 0x02 bit 5. +* This error occurred in I2C master detected +* +* @param v_i2c_err_code_u8 : The status of i2c fail error +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_fail_err(u8 +*v_i2c_err_code_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_I2C_FAIL_ERR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_err_code_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_I2C_FAIL_ERR); + } + return com_rslt; +} + /*! +* @brief This API Reads the dropped command error +* from the register 0x02 bit 6 +* +* +* @param v_drop_cmd_err_u8 : The status of drop command error +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_drop_cmd_err(u8 +*v_drop_cmd_err_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_DROP_CMD_ERR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_drop_cmd_err_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_DROP_CMD_ERR); + } + return com_rslt; +} +/*! +* @brief This API reads the magnetometer data ready +* interrupt not active. +* It reads from the error register 0x0x2 bit 7 +* +* +* +* +* @param v_mag_data_rdy_err_u8 : The status of mag data ready interrupt +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_dada_rdy_err( +u8*v_mag_data_rdy_err_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_MAG_DADA_RDY_ERR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_data_rdy_err_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_MAG_DADA_RDY_ERR); + } + return com_rslt; +} +/*! +* @brief This API reads the error status +* from the error register 0x02 bit 0 to 7 +* +* @param v_mag_data_rdy_err_u8 : The status of mag data ready interrupt +* @param v_fatal_er_u8r : The status of fatal error +* @param v_err_code_u8 : The status of error code +* @param v_i2c_fail_err_u8 : The status of I2C fail error +* @param v_drop_cmd_err_u8 : The status of drop command error +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_error_status(u8*v_fatal_er_u8r, +u8*v_err_code_u8, u8*v_i2c_fail_err_u8, +u8*v_drop_cmd_err_u8, u8*v_mag_data_rdy_err_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the error codes*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_ERR_STAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* fatal error*/ + *v_fatal_er_u8r = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FATAL_ERR); + /* user error*/ + *v_err_code_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_ERR_CODE); + /* i2c fail error*/ + *v_i2c_fail_err_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_I2C_FAIL_ERR); + /* drop command error*/ + *v_drop_cmd_err_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_DROP_CMD_ERR); + /* mag data ready error*/ + *v_mag_data_rdy_err_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_MAG_DADA_RDY_ERR); + } + return com_rslt; +} +/*! +* @brief This API reads the magnetometer power mode from +* PMU status register 0x03 bit 0 and 1 +* +* @param v_mag_power_mode_stat_u8 : The value of mag power mode +* mag_powermode | value +* ------------------|---------- +* SUSPEND | 0x00 +* NORMAL | 0x01 +* LOW POWER | 0x02 +* +* +* @note The power mode of mag set by the 0x7E command register +* @note using the function "smi130_set_command_register()" +* value | mode +* ---------|---------------- +* 0x18 | MAG_MODE_SUSPEND +* 0x19 | MAG_MODE_NORMAL +* 0x1A | MAG_MODE_LOWPOWER +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_power_mode_stat(u8 +*v_mag_power_mode_stat_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_POWER_MODE_STAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_power_mode_stat_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_MAG_POWER_MODE_STAT); + } + return com_rslt; +} +/*! +* @brief This API reads the gyroscope power mode from +* PMU status register 0x03 bit 2 and 3 +* +* @param v_gyro_power_mode_stat_u8 : The value of gyro power mode +* gyro_powermode | value +* ------------------|---------- +* SUSPEND | 0x00 +* NORMAL | 0x01 +* FAST POWER UP | 0x03 +* +* @note The power mode of gyro set by the 0x7E command register +* @note using the function "smi130_set_command_register()" +* value | mode +* ---------|---------------- +* 0x14 | GYRO_MODE_SUSPEND +* 0x15 | GYRO_MODE_NORMAL +* 0x17 | GYRO_MODE_FASTSTARTUP +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_power_mode_stat(u8 +*v_gyro_power_mode_stat_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_GYRO_POWER_MODE_STAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_power_mode_stat_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_POWER_MODE_STAT); + } + return com_rslt; +} +/*! +* @brief This API reads the accelerometer power mode from +* PMU status register 0x03 bit 4 and 5 +* +* +* @param v_accel_power_mode_stat_u8 : The value of accel power mode +* accel_powermode | value +* ------------------|---------- +* SUSPEND | 0x00 +* NORMAL | 0x01 +* LOW POWER | 0x02 +* +* @note The power mode of accel set by the 0x7E command register +* @note using the function "smi130_set_command_register()" +* value | mode +* ---------|---------------- +* 0x11 | ACCEL_MODE_NORMAL +* 0x12 | ACCEL_LOWPOWER +* 0x10 | ACCEL_SUSPEND +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_power_mode_stat(u8 +*v_accel_power_mode_stat_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_POWER_MODE_STAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_power_mode_stat_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_POWER_MODE_STAT); + } + return com_rslt; +} +/*! +* @brief This API switch mag interface to normal mode +* and confirm whether the mode switching done successfully or not +* +* @return results of bus communication function and current MAG_PMU result +* @retval 0 -> Success +* @retval -1 -> Error +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_interface_normal(void) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + /* aim to check the result of switching mag normal*/ + u8 v_try_times_u8 = SMI130_MAG_NOAMRL_SWITCH_TIMES; + u8 v_mag_pum_status_u8 = SMI130_INIT_VALUE; + + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt = smi130_set_command_register(MAG_MODE_NORMAL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + while (v_try_times_u8) { + com_rslt = smi130_get_mag_power_mode_stat(&v_mag_pum_status_u8); + if (v_mag_pum_status_u8 == MAG_INTERFACE_PMU_ENABLE) + break; + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + v_try_times_u8--; + } + if (v_mag_pum_status_u8 == MAG_INTERFACE_PMU_ENABLE) + com_rslt += SUCCESS; + else + com_rslt += E_SMI130_COMM_RES; + + return com_rslt; +} +/*! +* @brief This API reads magnetometer data X values +* from the register 0x04 and 0x05 +* @brief The mag sensor data read form auxiliary mag +* +* @param v_mag_x_s16 : The value of mag x +* @param v_sensor_select_u8 : Mag selection value +* value | sensor +* ---------|---------------- +* 0 | BMM150 +* 1 | AKM09911 or AKM09912 +* +* @note For mag data output rate configuration use the following function +* @note smi130_set_mag_output_data_rate() +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_x(s16*v_mag_x_s16, +u8 v_sensor_select_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the mag X lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[SMI130_MAG_X_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_DATA_MAG_X_LSB__REG, + v_data_u8, SMI130_MAG_X_DATA_LENGTH); + /* X axis*/ + v_data_u8[SMI130_MAG_X_LSB_BYTE] = + SMI130_GET_BITSLICE(v_data_u8[SMI130_MAG_X_LSB_BYTE], + SMI130_USER_DATA_MAG_X_LSB); + *v_mag_x_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_MAG_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[SMI130_MAG_X_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_0_MAG_X_LSB__REG, + v_data_u8, SMI130_MAG_X_DATA_LENGTH); + *v_mag_x_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_MAG_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_MAG_X_LSB_BYTE])); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API reads magnetometer data Y values +* from the register 0x06 and 0x07 +* @brief The mag sensor data read form auxiliary mag +* +* @param v_mag_y_s16 : The value of mag y +* @param v_sensor_select_u8 : Mag selection value +* value | sensor +* ---------|---------------- +* 0 | BMM150 +* 1 | AKM09911 or AKM09912 +* +* @note For mag data output rate configuration use the following function +* @note smi130_set_mag_output_data_rate() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_y(s16*v_mag_y_s16, +u8 v_sensor_select_u8) +{ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_OUT_OF_RANGE; + /* Array contains the mag Y lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[SMI130_MAG_Y_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_DATA_MAG_Y_LSB__REG, + v_data_u8, SMI130_MAG_Y_DATA_LENGTH); + /*Y-axis lsb value shifting*/ + v_data_u8[SMI130_MAG_Y_LSB_BYTE] = + SMI130_GET_BITSLICE(v_data_u8[SMI130_MAG_Y_LSB_BYTE], + SMI130_USER_DATA_MAG_Y_LSB); + *v_mag_y_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_MAG_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[SMI130_MAG_Y_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_DATA_2_MAG_Y_LSB__REG, + v_data_u8, SMI130_MAG_Y_DATA_LENGTH); + *v_mag_y_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_MAG_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_MAG_Y_LSB_BYTE])); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API reads magnetometer data Z values +* from the register 0x08 and 0x09 +* @brief The mag sensor data read form auxiliary mag +* +* @param v_mag_z_s16 : The value of mag z +* @param v_sensor_select_u8 : Mag selection value +* value | sensor +* ---------|---------------- +* 0 | BMM150 +* 1 | AKM09911 or AKM09912 +* +* @note For mag data output rate configuration use the following function +* @note smi130_set_mag_output_data_rate() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_z(s16*v_mag_z_s16, +u8 v_sensor_select_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the mag Z lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[SMI130_MAG_Z_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_DATA_MAG_Z_LSB__REG, + v_data_u8, SMI130_MAG_Z_DATA_LENGTH); + /*Z-axis lsb value shifting*/ + v_data_u8[SMI130_MAG_Z_LSB_BYTE] = + SMI130_GET_BITSLICE(v_data_u8[SMI130_MAG_Z_LSB_BYTE], + SMI130_USER_DATA_MAG_Z_LSB); + *v_mag_z_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_MAG_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_07_BITS) | + (v_data_u8[SMI130_MAG_Z_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_DATA_4_MAG_Z_LSB__REG, + v_data_u8, SMI130_MAG_Z_DATA_LENGTH); + *v_mag_z_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_MAG_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | ( + v_data_u8[SMI130_MAG_Z_LSB_BYTE])); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API reads magnetometer data RHALL values +* from the register 0x0A and 0x0B +* +* +* @param v_mag_r_s16 : The value of BMM150 r data +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_r(s16*v_mag_r_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the mag R lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[SMI130_MAG_R_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_6_RHALL_LSB__REG, + v_data_u8, SMI130_MAG_R_DATA_LENGTH); + /*R-axis lsb value shifting*/ + v_data_u8[SMI130_MAG_R_LSB_BYTE] = + SMI130_GET_BITSLICE(v_data_u8[SMI130_MAG_R_LSB_BYTE], + SMI130_USER_DATA_MAG_R_LSB); + *v_mag_r_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_MAG_R_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS) | + (v_data_u8[SMI130_MAG_R_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads magnetometer data X,Y,Z values +* from the register 0x04 to 0x09 +* +* @brief The mag sensor data read form auxiliary mag +* +* @param mag : The value of mag xyz data +* @param v_sensor_select_u8 : Mag selection value +* value | sensor +* ---------|---------------- +* 0 | BMM150 +* 1 | AKM09911 or AKM09912 +* +* @note For mag data output rate configuration use the following function +* @note smi130_set_mag_output_data_rate() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_xyz( +struct smi130_mag_t*mag, u8 v_sensor_select_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the mag XYZ lSB and MSB data + v_data_u8[0] - X-LSB + v_data_u8[1] - X-MSB + v_data_u8[0] - Y-LSB + v_data_u8[1] - Y-MSB + v_data_u8[0] - Z-LSB + v_data_u8[1] - Z-MSB + */ + u8 v_data_u8[SMI130_MAG_XYZ_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_DATA_MAG_X_LSB__REG, + v_data_u8, SMI130_MAG_XYZ_DATA_LENGTH); + /*X-axis lsb value shifting*/ + v_data_u8[SMI130_DATA_FRAME_MAG_X_LSB_BYTE] = + SMI130_GET_BITSLICE( + v_data_u8[SMI130_DATA_FRAME_MAG_X_LSB_BYTE], + SMI130_USER_DATA_MAG_X_LSB); + /* Data X*/ + mag->x = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[SMI130_DATA_FRAME_MAG_X_LSB_BYTE])); + /* Data Y*/ + /*Y-axis lsb value shifting*/ + v_data_u8[SMI130_DATA_FRAME_MAG_Y_LSB_BYTE] = + SMI130_GET_BITSLICE( + v_data_u8[SMI130_DATA_FRAME_MAG_Y_LSB_BYTE], + SMI130_USER_DATA_MAG_Y_LSB); + mag->y = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[SMI130_DATA_FRAME_MAG_Y_LSB_BYTE])); + + /* Data Z*/ + /*Z-axis lsb value shifting*/ + v_data_u8[SMI130_DATA_FRAME_MAG_Z_LSB_BYTE] + = SMI130_GET_BITSLICE( + v_data_u8[SMI130_DATA_FRAME_MAG_Z_LSB_BYTE], + SMI130_USER_DATA_MAG_Z_LSB); + mag->z = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_07_BITS) | + (v_data_u8[SMI130_DATA_FRAME_MAG_Z_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_0_MAG_X_LSB__REG, + v_data_u8, SMI130_MAG_XYZ_DATA_LENGTH); + /* Data X*/ + mag->x = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_DATA_FRAME_MAG_X_LSB_BYTE])); + /* Data Y*/ + mag->y = ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_DATA_FRAME_MAG_Y_LSB_BYTE])); + /* Data Z*/ + mag->z = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_DATA_FRAME_MAG_Z_LSB_BYTE])); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} + /*!* +* @brief This API reads magnetometer data X,Y,Z,r +* values from the register 0x04 to 0x0B +* +* @brief The mag sensor data read form auxiliary mag +* +* @param mag : The value of mag-BMM150 xyzr data +* +* @note For mag data output rate configuration use the following function +* @note smi130_set_mag_output_data_rate() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_xyzr( +struct smi130_mag_xyzr_t*mag) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8[SMI130_MAG_XYZR_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_MAG_X_LSB__REG, + v_data_u8, SMI130_MAG_XYZR_DATA_LENGTH); + + /* Data X*/ + /*X-axis lsb value shifting*/ + v_data_u8[SMI130_DATA_FRAME_MAG_X_LSB_BYTE] + = SMI130_GET_BITSLICE( + v_data_u8[SMI130_DATA_FRAME_MAG_X_LSB_BYTE], + SMI130_USER_DATA_MAG_X_LSB); + mag->x = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_05_BITS) + | (v_data_u8[SMI130_DATA_FRAME_MAG_X_LSB_BYTE])); + /* Data Y*/ + /*Y-axis lsb value shifting*/ + v_data_u8[SMI130_DATA_FRAME_MAG_Y_LSB_BYTE] + = SMI130_GET_BITSLICE( + v_data_u8[SMI130_DATA_FRAME_MAG_Y_LSB_BYTE], + SMI130_USER_DATA_MAG_Y_LSB); + mag->y = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_05_BITS) + | (v_data_u8[ + SMI130_DATA_FRAME_MAG_Y_LSB_BYTE])); + + /* Data Z*/ + /*Z-axis lsb value shifting*/ + v_data_u8[SMI130_DATA_FRAME_MAG_Z_LSB_BYTE] + = SMI130_GET_BITSLICE( + v_data_u8[SMI130_DATA_FRAME_MAG_Z_LSB_BYTE], + SMI130_USER_DATA_MAG_Z_LSB); + mag->z = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_07_BITS) + | (v_data_u8[SMI130_DATA_FRAME_MAG_Z_LSB_BYTE])); + + /* RHall*/ + /*R-axis lsb value shifting*/ + v_data_u8[SMI130_DATA_FRAME_MAG_R_LSB_BYTE] + = SMI130_GET_BITSLICE( + v_data_u8[SMI130_DATA_FRAME_MAG_R_LSB_BYTE], + SMI130_USER_DATA_MAG_R_LSB); + mag->r = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_MAG_R_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS) + | (v_data_u8[SMI130_DATA_FRAME_MAG_R_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads gyro data X values +* form the register 0x0C and 0x0D +* +* +* +* +* @param v_gyro_x_s16 : The value of gyro x data +* +* @note Gyro Configuration use the following function +* @note smi130_set_gyro_output_data_rate() +* @note smi130_set_gyro_bw() +* @note smi130_set_gyro_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_x(s16*v_gyro_x_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the gyro X lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[MSB_ONE] - MSB*/ + u8 v_data_u8[SMI130_GYRO_X_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_8_GYRO_X_LSB__REG, + v_data_u8, SMI130_GYRO_DATA_LENGTH); + + *v_gyro_x_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_GYRO_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_GYRO_X_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads gyro data Y values +* form the register 0x0E and 0x0F +* +* +* +* +* @param v_gyro_y_s16 : The value of gyro y data +* +* @note Gyro Configuration use the following function +* @note smi130_set_gyro_output_data_rate() +* @note smi130_set_gyro_bw() +* @note smi130_set_gyro_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error result of communication routines +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_y(s16*v_gyro_y_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the gyro Y lSB and MSB data + v_data_u8[LSB_ZERO] - LSB + v_data_u8[MSB_ONE] - MSB*/ + u8 v_data_u8[SMI130_GYRO_Y_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro y data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_10_GYRO_Y_LSB__REG, + v_data_u8, SMI130_GYRO_DATA_LENGTH); + + *v_gyro_y_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_GYRO_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_GYRO_Y_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads gyro data Z values +* form the register 0x10 and 0x11 +* +* +* +* +* @param v_gyro_z_s16 : The value of gyro z data +* +* @note Gyro Configuration use the following function +* @note smi130_set_gyro_output_data_rate() +* @note smi130_set_gyro_bw() +* @note smi130_set_gyro_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_z(s16*v_gyro_z_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the gyro Z lSB and MSB data + v_data_u8[LSB_ZERO] - LSB + v_data_u8[MSB_ONE] - MSB*/ + u8 v_data_u8[SMI130_GYRO_Z_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro z data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_12_GYRO_Z_LSB__REG, + v_data_u8, SMI130_GYRO_DATA_LENGTH); + + *v_gyro_z_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_GYRO_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_GYRO_Z_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads gyro data X,Y,Z values +* from the register 0x0C to 0x11 +* +* +* +* +* @param gyro : The value of gyro xyz +* +* @note Gyro Configuration use the following function +* @note smi130_set_gyro_output_data_rate() +* @note smi130_set_gyro_bw() +* @note smi130_set_gyro_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_xyz(struct smi130_gyro_t*gyro) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the mag XYZ lSB and MSB data + v_data_u8[0] - X-LSB + v_data_u8[1] - X-MSB + v_data_u8[0] - Y-LSB + v_data_u8[1] - Y-MSB + v_data_u8[0] - Z-LSB + v_data_u8[1] - Z-MSB + */ + u8 v_data_u8[SMI130_GYRO_XYZ_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the gyro xyz data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_8_GYRO_X_LSB__REG, + v_data_u8, SMI130_GYRO_XYZ_DATA_LENGTH); + + /* Data X*/ + gyro->x = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_GYRO_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_DATA_FRAME_GYRO_X_LSB_BYTE])); + /* Data Y*/ + gyro->y = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_GYRO_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_DATA_FRAME_GYRO_Y_LSB_BYTE])); + + /* Data Z*/ + gyro->z = (s16) + ((((s32)((s8)v_data_u8[ + SMI130_DATA_FRAME_GYRO_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_DATA_FRAME_GYRO_Z_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads accelerometer data X values +* form the register 0x12 and 0x13 +* +* +* +* +* @param v_accel_x_s16 : The value of accel x +* +* @note For accel configuration use the following functions +* @note smi130_set_accel_output_data_rate() +* @note smi130_set_accel_bw() +* @note smi130_set_accel_under_sampling_parameter() +* @note smi130_set_accel_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_x(s16*v_accel_x_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the accel X lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[SMI130_ACCEL_X_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_14_ACCEL_X_LSB__REG, + v_data_u8, SMI130_ACCEL_DATA_LENGTH); + + *v_accel_x_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_ACCEL_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_ACCEL_X_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads accelerometer data Y values +* form the register 0x14 and 0x15 +* +* +* +* +* @param v_accel_y_s16 : The value of accel y +* +* @note For accel configuration use the following functions +* @note smi130_set_accel_output_data_rate() +* @note smi130_set_accel_bw() +* @note smi130_set_accel_under_sampling_parameter() +* @note smi130_set_accel_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_y(s16*v_accel_y_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the accel Y lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[SMI130_ACCEL_Y_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_16_ACCEL_Y_LSB__REG, + v_data_u8, SMI130_ACCEL_DATA_LENGTH); + + *v_accel_y_s16 = (s16) + ((((s32)((s8)v_data_u8[SMI130_ACCEL_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[SMI130_ACCEL_Y_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads accelerometer data Z values +* form the register 0x16 and 0x17 +* +* +* +* +* @param v_accel_z_s16 : The value of accel z +* +* @note For accel configuration use the following functions +* @note smi130_set_accel_output_data_rate() +* @note smi130_set_accel_bw() +* @note smi130_set_accel_under_sampling_parameter() +* @note smi130_set_accel_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_z(s16*v_accel_z_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the accel Z lSB and MSB data + a_data_u8r[LSB_ZERO] - LSB + a_data_u8r[MSB_ONE] - MSB*/ + u8 a_data_u8r[SMI130_ACCEL_Z_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_18_ACCEL_Z_LSB__REG, + a_data_u8r, SMI130_ACCEL_DATA_LENGTH); + + *v_accel_z_s16 = (s16) + ((((s32)((s8)a_data_u8r[SMI130_ACCEL_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[SMI130_ACCEL_Z_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads accelerometer data X,Y,Z values +* from the register 0x12 to 0x17 +* +* +* +* +* @param accel :The value of accel xyz +* +* @note For accel configuration use the following functions +* @note smi130_set_accel_output_data_rate() +* @note smi130_set_accel_bw() +* @note smi130_set_accel_under_sampling_parameter() +* @note smi130_set_accel_range() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_xyz( +struct smi130_accel_t*accel) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the accel XYZ lSB and MSB data + a_data_u8r[0] - X-LSB + a_data_u8r[1] - X-MSB + a_data_u8r[0] - Y-LSB + a_data_u8r[1] - Y-MSB + a_data_u8r[0] - Z-LSB + a_data_u8r[1] - Z-MSB + */ + u8 a_data_u8r[SMI130_ACCEL_XYZ_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_14_ACCEL_X_LSB__REG, + a_data_u8r, SMI130_ACCEL_XYZ_DATA_LENGTH); + + /* Data X*/ + accel->x = (s16) + ((((s32)((s8)a_data_u8r[ + SMI130_DATA_FRAME_ACCEL_X_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[SMI130_DATA_FRAME_ACCEL_X_LSB_BYTE])); + /* Data Y*/ + accel->y = (s16) + ((((s32)((s8)a_data_u8r[ + SMI130_DATA_FRAME_ACCEL_Y_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[SMI130_DATA_FRAME_ACCEL_Y_LSB_BYTE])); + + /* Data Z*/ + accel->z = (s16) + ((((s32)((s8)a_data_u8r[ + SMI130_DATA_FRAME_ACCEL_Z_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[SMI130_DATA_FRAME_ACCEL_Z_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads sensor_time from the register +* 0x18 to 0x1A +* +* +* @param v_sensor_time_u32 : The value of sensor time +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_sensor_time(u32*v_sensor_time_u32) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the sensor time it is 32 bit data + a_data_u8r[0] - sensor time + a_data_u8r[1] - sensor time + a_data_u8r[0] - sensor time + */ + u8 a_data_u8r[SMI130_SENSOR_TIME_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_SENSORTIME_0_SENSOR_TIME_LSB__REG, + a_data_u8r, SMI130_SENSOR_TIME_LENGTH); + + *v_sensor_time_u32 = (u32) + ((((u32)a_data_u8r[SMI130_SENSOR_TIME_MSB_BYTE]) + << SMI130_SHIFT_BIT_POSITION_BY_16_BITS) + |(((u32)a_data_u8r[SMI130_SENSOR_TIME_XLSB_BYTE]) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[SMI130_SENSOR_TIME_LSB_BYTE])); + } + return com_rslt; +} +/*! +* @brief This API reads the Gyroscope self test +* status from the register 0x1B bit 1 +* +* +* @param v_gyro_selftest_u8 : The value of gyro self test status +* value | status +* ---------|---------------- +* 0 | Gyroscope self test is running or failed +* 1 | Gyroscope self test completed successfully +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_selftest(u8 +*v_gyro_selftest_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STAT_GYRO_SELFTEST_OK__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_selftest_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STAT_GYRO_SELFTEST_OK); + } + return com_rslt; +} +/*! +* @brief This API reads the status of +* mag manual interface operation form the register 0x1B bit 2 +* +* +* +* @param v_mag_manual_stat_u8 : The value of mag manual operation status +* value | status +* ---------|---------------- +* 0 | Indicates no manual magnetometer +* - | interface operation is ongoing +* 1 | Indicates manual magnetometer +* - | interface operation is ongoing +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_manual_operation_stat(u8 +*v_mag_manual_stat_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read manual operation*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STAT_MAG_MANUAL_OPERATION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_manual_stat_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STAT_MAG_MANUAL_OPERATION); + } + return com_rslt; +} +/*! +* @brief This API reads the fast offset compensation +* status form the register 0x1B bit 3 +* +* +* @param v_foc_rdy_u8 : The status of fast compensation +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_rdy(u8 +*v_foc_rdy_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the FOC status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STAT_FOC_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_rdy_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STAT_FOC_RDY); + } + return com_rslt; +} +/*! +* @brief This API Reads the nvm_rdy status from the +* resister 0x1B bit 4 +* +* +* @param v_nvm_rdy_u8 : The value of NVM ready status +* value | status +* ---------|---------------- +* 0 | NVM write operation in progress +* 1 | NVM is ready to accept a new write trigger +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_nvm_rdy(u8 +*v_nvm_rdy_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the nvm ready status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STAT_NVM_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_nvm_rdy_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STAT_NVM_RDY); + } + return com_rslt; +} +/*! +* @brief This API reads the status of mag data ready +* from the register 0x1B bit 5 +* The status get reset when one mag data register is read out +* +* @param v_data_rdy_u8 : The value of mag data ready status +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_data_rdy_mag(u8 +*v_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STAT_DATA_RDY_MAG__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STAT_DATA_RDY_MAG); + } + return com_rslt; +} +/*! +* @brief This API reads the status of gyro data ready form the +* register 0x1B bit 6 +* The status get reset when gyro data register read out +* +* +* @param v_data_rdy_u8 : The value of gyro data ready +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_data_rdy(u8 +*v_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STAT_DATA_RDY_GYRO__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STAT_DATA_RDY_GYRO); + } + return com_rslt; +} +/*! +* @brief This API reads the status of accel data ready form the +* register 0x1B bit 7 +* The status get reset when accel data register read out +* +* +* @param v_data_rdy_u8 : The value of accel data ready status +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_data_rdy(u8 +*v_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /*reads the status of accel data ready*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STAT_DATA_RDY_ACCEL__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STAT_DATA_RDY_ACCEL); + } + return com_rslt; +} +/*! +* @brief This API reads the step detector interrupt status +* from the register 0x1C bit 0 +* flag is associated with a specific interrupt function. +* It is set when the single tab interrupt triggers. The +* setting of INT_LATCH controls if the interrupt +* signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_step_intr_u8 : The status of step detector interrupt +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_step_intr(u8 +*v_step_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_STEP_INTR__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_step_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_STEP_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads the +* significant motion interrupt status +* from the register 0x1C bit 1 +* flag is associated with a specific interrupt function. +* It is set when the single tab interrupt triggers. The +* setting of INT_LATCH controls if the interrupt +* signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* +* @param v_significant_intr_u8 : The status of step +* motion interrupt +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_significant_intr(u8 +*v_significant_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_significant_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR); + } + return com_rslt; +} + /*! +* @brief This API reads the any motion interrupt status +* from the register 0x1C bit 2 +* flag is associated with a specific interrupt function. +* It is set when the single tab interrupt triggers. The +* setting of INT_LATCH controls if the interrupt +* signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* @param v_any_motion_intr_u8 : The status of any-motion interrupt +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_any_motion_intr(u8 +*v_any_motion_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_ANY_MOTION__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_ANY_MOTION); + } + return com_rslt; +} +/*! +* @brief This API reads the power mode trigger interrupt status +* from the register 0x1C bit 3 +* flag is associated with a specific interrupt function. +* It is set when the single tab interrupt triggers. The +* setting of INT_LATCH controls if the interrupt +* signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* +* @param v_pmu_trigger_intr_u8 : The status of power mode trigger interrupt +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_pmu_trigger_intr(u8 +*v_pmu_trigger_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_PMU_TRIGGER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_pmu_trigger_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_PMU_TRIGGER); + } + return com_rslt; +} +/*! +* @brief This API reads the double tab status +* from the register 0x1C bit 4 +* flag is associated with a specific interrupt function. +* It is set when the single tab interrupt triggers. The +* setting of INT_LATCH controls if the interrupt +* signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_double_tap_intr_u8 :The status of double tab interrupt +* +* @note Double tap interrupt can be configured by the following functions +* @note INTERRUPT MAPPING +* @note smi130_set_intr_double_tap() +* @note AXIS MAPPING +* @note smi130_get_stat2_tap_first_x() +* @note smi130_get_stat2_tap_first_y() +* @note smi130_get_stat2_tap_first_z() +* @note DURATION +* @note smi130_set_intr_tap_durn() +* @note THRESHOLD +* @note smi130_set_intr_tap_thres() +* @note TAP QUIET +* @note smi130_set_intr_tap_quiet() +* @note TAP SHOCK +* @note smi130_set_intr_tap_shock() +* @note TAP SOURCE +* @note smi130_set_intr_tap_source() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_double_tap_intr(u8 +*v_double_tap_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_DOUBLE_TAP_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_double_tap_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_DOUBLE_TAP_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads the single tab status +* from the register 0x1C bit 5 +* flag is associated with a specific interrupt function. +* It is set when the single tab interrupt triggers. The +* setting of INT_LATCH controls if the interrupt +* signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_single_tap_intr_u8 :The status of single tap interrupt +* +* @note Single tap interrupt can be configured by the following functions +* @note INTERRUPT MAPPING +* @note smi130_set_intr_single_tap() +* @note AXIS MAPPING +* @note smi130_get_stat2_tap_first_x() +* @note smi130_get_stat2_tap_first_y() +* @note smi130_get_stat2_tap_first_z() +* @note DURATION +* @note smi130_set_intr_tap_durn() +* @note THRESHOLD +* @note smi130_set_intr_tap_thres() +* @note TAP QUIET +* @note smi130_set_intr_tap_quiet() +* @note TAP SHOCK +* @note smi130_set_intr_tap_shock() +* @note TAP SOURCE +* @note smi130_set_intr_tap_source() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_single_tap_intr(u8 +*v_single_tap_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_SINGLE_TAP_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_single_tap_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_SINGLE_TAP_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads the orient status +* from the register 0x1C bit 6 +* flag is associated with a specific interrupt function. +* It is set when the orient interrupt triggers. The +* setting of INT_LATCH controls if the +* interrupt signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_orient_intr_u8 : The status of orient interrupt +* +* @note For orient interrupt configuration use the following functions +* @note STATUS +* @note smi130_get_stat0_orient_intr() +* @note AXIS MAPPING +* @note smi130_get_stat3_orient_xy() +* @note smi130_get_stat3_orient_z() +* @note smi130_set_intr_orient_axes_enable() +* @note INTERRUPT MAPPING +* @note smi130_set_intr_orient() +* @note INTERRUPT OUTPUT +* @note smi130_set_intr_orient_ud_enable() +* @note THETA +* @note smi130_set_intr_orient_theta() +* @note HYSTERESIS +* @note smi130_set_intr_orient_hyst() +* @note BLOCKING +* @note smi130_set_intr_orient_blocking() +* @note MODE +* @note smi130_set_intr_orient_mode() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_orient_intr(u8 +*v_orient_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_ORIENT__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_ORIENT); + } + return com_rslt; +} +/*! +* @brief This API reads the flat interrupt status +* from the register 0x1C bit 7 +* flag is associated with a specific interrupt function. +* It is set when the flat interrupt triggers. The +* setting of INT_LATCH controls if the +* interrupt signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_flat_intr_u8 : The status of flat interrupt +* +* @note For flat configuration use the following functions +* @note STATS +* @note smi130_get_stat0_flat_intr() +* @note smi130_get_stat3_flat() +* @note INTERRUPT MAPPING +* @note smi130_set_intr_flat() +* @note THETA +* @note smi130_set_intr_flat_theta() +* @note HOLD TIME +* @note smi130_set_intr_flat_hold() +* @note HYSTERESIS +* @note smi130_set_intr_flat_hyst() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_flat_intr(u8 +*v_flat_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_0_FLAT__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_0_FLAT); + } + return com_rslt; +} +/*! +* @brief This API reads the high_g interrupt status +* from the register 0x1D bit 2 +* flag is associated with a specific interrupt function. +* It is set when the high g interrupt triggers. The +* setting of INT_LATCH controls if the interrupt signal and hence the +* respective interrupt flag will be permanently +* latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_high_g_intr_u8 : The status of high_g interrupt +* +* @note High_g interrupt configured by following functions +* @note STATUS +* @note smi130_get_stat1_high_g_intr() +* @note AXIS MAPPING +* @note smi130_get_stat3_high_g_first_x() +* @note smi130_get_stat3_high_g_first_y() +* @note smi130_get_stat3_high_g_first_z() +* @note SIGN MAPPING +* @note smi130_get_stat3_high_g_first_sign() +* @note INTERRUPT MAPPING +* @note smi130_set_intr_high_g() + * @note HYSTERESIS +* @note smi130_set_intr_high_g_hyst() +* @note DURATION +* @note smi130_set_intr_high_g_durn() +* @note THRESHOLD +* @note smi130_set_intr_high_g_thres() +* @note SOURCE +* @note smi130_set_intr_low_high_source() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_high_g_intr(u8 +*v_high_g_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_1_HIGH_G_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_1_HIGH_G_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads the low g interrupt status +* from the register 0x1D bit 3 +* flag is associated with a specific interrupt function. +* It is set when the low g interrupt triggers. The +* setting of INT_LATCH controls if the interrupt signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_low_g_intr_u8 : The status of low_g interrupt +* +* @note Low_g interrupt configured by following functions +* @note STATUS +* @note smi130_get_stat1_low_g_intr() +* @note INTERRUPT MAPPING +* @note smi130_set_intr_low_g() +* @note SOURCE +* @note smi130_set_intr_low_high_source() +* @note DURATION +* @note smi130_set_intr_low_g_durn() +* @note THRESHOLD +* @note smi130_set_intr_low_g_thres() +* @note HYSTERESIS +* @note smi130_set_intr_low_g_hyst() +* @note MODE +* @note smi130_set_intr_low_g_mode() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_low_g_intr(u8 +*v_low_g_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_1_LOW_G_INTR__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_1_LOW_G_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads data ready interrupt status +* from the register 0x1D bit 4 +* flag is associated with a specific interrupt function. +* It is set when the data ready interrupt triggers. The +* setting of INT_LATCH controls if the interrupt signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_data_rdy_intr_u8 : The status of data ready interrupt +* +* @note Data ready interrupt configured by following functions +* @note STATUS +* @note smi130_get_stat1_data_rdy_intr() +* @note INTERRUPT MAPPING +* @note smi130_set_intr_data_rdy() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_data_rdy_intr(u8 +*v_data_rdy_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_1_DATA_RDY_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_1_DATA_RDY_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads data ready FIFO full interrupt status +* from the register 0x1D bit 5 +* flag is associated with a specific interrupt function. +* It is set when the FIFO full interrupt triggers. The +* setting of INT_LATCH controls if the +* interrupt signal and hence the +* respective interrupt flag will +* be permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_fifo_full_intr_u8 : The status of fifo full interrupt +* +* @note FIFO full interrupt can be configured by following functions +* @note smi130_set_intr_fifo_full() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_fifo_full_intr(u8 +*v_fifo_full_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_1_FIFO_FULL_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_full_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_1_FIFO_FULL_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads data +* ready FIFO watermark interrupt status +* from the register 0x1D bit 6 +* flag is associated with a specific interrupt function. +* It is set when the FIFO watermark interrupt triggers. The +* setting of INT_LATCH controls if the +* interrupt signal and hence the +* respective interrupt flag will be +* permanently latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_fifo_wm_intr_u8 : The status of fifo water mark interrupt +* +* @note FIFO full interrupt can be configured by following functions +* @note smi130_set_intr_fifo_wm() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_fifo_wm_intr(u8 +*v_fifo_wm_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_1_FIFO_WM_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_wm_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_1_FIFO_WM_INTR); + } + return com_rslt; +} +/*! +* @brief This API reads data ready no motion interrupt status +* from the register 0x1D bit 7 +* flag is associated with a specific interrupt function. +* It is set when the no motion interrupt triggers. The +* setting of INT_LATCH controls if the interrupt signal and hence the +* respective interrupt flag will be permanently +* latched, temporarily latched +* or not latched. +* +* +* +* +* @param v_nomotion_intr_u8 : The status of no motion interrupt +* +* @note No motion interrupt can be configured by following function +* @note STATUS +* @note smi130_get_stat1_nomotion_intr() +* @note INTERRUPT MAPPING +* @note smi130_set_intr_nomotion() +* @note DURATION +* @note smi130_set_intr_slow_no_motion_durn() +* @note THRESHOLD +* @note smi130_set_intr_slow_no_motion_thres() +* @note SLOW/NO MOTION SELECT +* @note smi130_set_intr_slow_no_motion_select() +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_nomotion_intr(u8 +*v_nomotion_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the no motion interrupt*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_1_NOMOTION_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_nomotion_intr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_1_NOMOTION_INTR); + } + return com_rslt; +} +/*! +*@brief This API reads the status of any motion first x +* from the register 0x1E bit 0 +* +* +*@param v_anymotion_first_x_u8 : The status of any motion first x interrupt +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by x axis +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_first_x(u8 +*v_anymotion_first_x_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the any motion first x interrupt*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_anymotion_first_x_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_X); + } + return com_rslt; +} +/*! +* @brief This API reads the status of any motion first y interrupt +* from the register 0x1E bit 1 +* +* +* +*@param v_any_motion_first_y_u8 : The status of any motion first y interrupt +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_first_y(u8 +*v_any_motion_first_y_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the any motion first y interrupt*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_first_y_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y); + } + return com_rslt; +} +/*! +* @brief This API reads the status of any motion first z interrupt +* from the register 0x1E bit 2 +* +* +* +* +*@param v_any_motion_first_z_u8 : The status of any motion first z interrupt +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_first_z(u8 +*v_any_motion_first_z_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the any motion first z interrupt*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_first_z_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z); + } + return com_rslt; +} +/*! +* @brief This API reads the any motion sign status from the +* register 0x1E bit 3 +* +* +* +* +* @param v_anymotion_sign_u8 : The status of any motion sign +* value | sign +* -----------|------------- +* 0 | positive +* 1 | negative +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_sign(u8 +*v_anymotion_sign_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read any motion sign interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_ANY_MOTION_SIGN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_anymotion_sign_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_ANY_MOTION_SIGN); + } + return com_rslt; +} +/*! +* @brief This API reads the any motion tap first x status from the +* register 0x1E bit 4 +* +* +* +* +* @param v_tap_first_x_u8 :The status of any motion tap first x +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by x axis +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_first_x(u8 +*v_tap_first_x_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap first x interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_TAP_FIRST_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_first_x_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_TAP_FIRST_X); + } + return com_rslt; +} +/*! +* @brief This API reads the tap first y interrupt status from the +* register 0x1E bit 5 +* +* +* +* +* @param v_tap_first_y_u8 :The status of tap first y interrupt +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_first_y(u8 +*v_tap_first_y_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap first y interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_TAP_FIRST_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_first_y_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_TAP_FIRST_Y); + } + return com_rslt; +} +/*! +* @brief This API reads the tap first z interrupt status from the +* register 0x1E bit 6 +* +* +* +* +* @param v_tap_first_z_u8 :The status of tap first z interrupt +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by z axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_first_z(u8 +*v_tap_first_z_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap first z interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_TAP_FIRST_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_first_z_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_TAP_FIRST_Z); + } + return com_rslt; +} +/*! +* @brief This API reads the tap sign status from the +* register 0x1E bit 7 +* +* +* +* +* @param v_tap_sign_u8 : The status of tap sign +* value | sign +* -----------|------------- +* 0 | positive +* 1 | negative +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_sign(u8 +*v_tap_sign_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap_sign interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_2_TAP_SIGN__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_sign_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_2_TAP_SIGN); + } + return com_rslt; +} +/*! +* @brief This API reads the high_g first x status from the +* register 0x1F bit 0 +* +* +* +* +* @param v_high_g_first_x_u8 :The status of high_g first x +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by x axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_first_x(u8 +*v_high_g_first_x_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read highg_x interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_first_x_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_X); + } + return com_rslt; +} +/*! +* @brief This API reads the high_g first y status from the +* register 0x1F bit 1 +* +* +* +* +* @param v_high_g_first_y_u8 : The status of high_g first y +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_first_y(u8 +*v_high_g_first_y_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read highg_y interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_first_y_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Y); + } + return com_rslt; +} +/*! +* @brief This API reads the high_g first z status from the +* register 0x1F bit 3 +* +* +* +* +* @param v_high_g_first_z_u8 : The status of high_g first z +* value | status +* -----------|------------- +* 0 | not triggered +* 1 | triggered by z axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_first_z(u8 +*v_high_g_first_z_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read highg_z interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_first_z_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Z); + } + return com_rslt; +} +/*! +* @brief This API reads the high sign status from the +* register 0x1F bit 3 +* +* +* +* +* @param v_high_g_sign_u8 :The status of high sign +* value | sign +* -----------|------------- +* 0 | positive +* 1 | negative +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_sign(u8 +*v_high_g_sign_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read highg_sign interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_3_HIGH_G_SIGN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_sign_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_3_HIGH_G_SIGN); + } + return com_rslt; +} +/*! +* @brief This API reads the status of orient_xy plane +* from the register 0x1F bit 4 and 5 +* +* +* @param v_orient_xy_u8 :The status of orient_xy plane +* value | status +* -----------|------------- +* 0x00 | portrait upright +* 0x01 | portrait upside down +* 0x02 | landscape left +* 0x03 | landscape right +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_orient_xy(u8 +*v_orient_xy_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read orient plane xy interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_3_ORIENT_XY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_xy_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_3_ORIENT_XY); + } + return com_rslt; +} +/*! +* @brief This API reads the status of orient z plane +* from the register 0x1F bit 6 +* +* +* @param v_orient_z_u8 :The status of orient z +* value | status +* -----------|------------- +* 0x00 | upward looking +* 0x01 | downward looking +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_orient_z(u8 +*v_orient_z_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read orient z plane interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_3_ORIENT_Z__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_z_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_3_ORIENT_Z); + } + return com_rslt; +} +/*! +* @brief This API reads the flat status from the register +* 0x1F bit 7 +* +* +* @param v_flat_u8 : The status of flat interrupt +* value | status +* -----------|------------- +* 0x00 | non flat +* 0x01 | flat position +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_flat(u8 +*v_flat_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read flat interrupt status*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_INTR_STAT_3_FLAT__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_STAT_3_FLAT); + } + return com_rslt; +} +/*! +* @brief This API reads the temperature of the sensor +* from the register 0x21 bit 0 to 7 +* +* +* +* @param v_temp_s16 : The value of temperature +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_temp(s16 +*v_temp_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the temperature lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[SMI130_TEMP_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read temperature data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_TEMP_LSB_VALUE__REG, v_data_u8, + SMI130_TEMP_DATA_LENGTH); + *v_temp_s16 = + (s16)(((s32)((s8) (v_data_u8[SMI130_TEMP_MSB_BYTE]) << + SMI130_SHIFT_BIT_POSITION_BY_08_BITS)) + | v_data_u8[SMI130_TEMP_LSB_BYTE]); + } + return com_rslt; +} +/*! +* @brief This API reads the of the sensor +* form the register 0x23 and 0x24 bit 0 to 7 and 0 to 2 +* @brief this byte counter is updated each time a complete frame +* was read or writtern +* +* +* @param v_fifo_length_u32 : The value of fifo byte counter +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_fifo_length(u32*v_fifo_length_u32) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array contains the fifo length data + v_data_u8[0] - fifo length + v_data_u8[1] - fifo length*/ + u8 a_data_u8r[SMI130_FIFO_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read fifo length*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_BYTE_COUNTER_LSB__REG, a_data_u8r, + SMI130_FIFO_DATA_LENGTH); + + a_data_u8r[SMI130_FIFO_LENGTH_MSB_BYTE] = + SMI130_GET_BITSLICE( + a_data_u8r[SMI130_FIFO_LENGTH_MSB_BYTE], + SMI130_USER_FIFO_BYTE_COUNTER_MSB); + + *v_fifo_length_u32 = + (u32)(((u32)((u8) ( + a_data_u8r[SMI130_FIFO_LENGTH_MSB_BYTE]) << + SMI130_SHIFT_BIT_POSITION_BY_08_BITS)) + | a_data_u8r[SMI130_FIFO_LENGTH_LSB_BYTE]); + } + return com_rslt; +} +/*! +* @brief This API reads the fifo data of the sensor +* from the register 0x24 +* @brief Data format depends on the setting of register FIFO_CONFIG +* +* +* +* @param v_fifodata_u8 : Pointer holding the fifo data +* @param fifo_length_u16 : The value of fifo length maximum +* 1024 +* +* @note For reading FIFO data use the following functions +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_fifo_data( +u8*v_fifodata_u8, u16 v_fifo_length_u16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read fifo data*/ + com_rslt = + p_smi130->SMI130_BURST_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_DATA__REG, + v_fifodata_u8, v_fifo_length_u16); + + } + return com_rslt; +} +/*! +* @brief This API is used to get the +* accel output date rate form the register 0x40 bit 0 to 3 +* +* +* @param v_output_data_rate_u8 :The value of accel output date rate +* value | output data rate +* -------|-------------------------- +* 0 | SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED +* 1 | SMI130_ACCEL_OUTPUT_DATA_RATE_0_78HZ +* 2 | SMI130_ACCEL_OUTPUT_DATA_RATE_1_56HZ +* 3 | SMI130_ACCEL_OUTPUT_DATA_RATE_3_12HZ +* 4 | SMI130_ACCEL_OUTPUT_DATA_RATE_6_25HZ +* 5 | SMI130_ACCEL_OUTPUT_DATA_RATE_12_5HZ +* 6 | SMI130_ACCEL_OUTPUT_DATA_RATE_25HZ +* 7 | SMI130_ACCEL_OUTPUT_DATA_RATE_50HZ +* 8 | SMI130_ACCEL_OUTPUT_DATA_RATE_100HZ +* 9 | SMI130_ACCEL_OUTPUT_DATA_RATE_200HZ +* 10 | SMI130_ACCEL_OUTPUT_DATA_RATE_400HZ +* 11 | SMI130_ACCEL_OUTPUT_DATA_RATE_800HZ +* 12 | SMI130_ACCEL_OUTPUT_DATA_RATE_1600HZ +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_output_data_rate( +u8*v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel output data rate*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_output_data_rate_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE); + } + return com_rslt; +} +/*! +* @brief This API is used to set the +* accel output date rate form the register 0x40 bit 0 to 3 +* +* +* @param v_output_data_rate_u8 :The value of accel output date rate +* value | output data rate +* -------|-------------------------- +* 0 | SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED +* 1 | SMI130_ACCEL_OUTPUT_DATA_RATE_0_78HZ +* 2 | SMI130_ACCEL_OUTPUT_DATA_RATE_1_56HZ +* 3 | SMI130_ACCEL_OUTPUT_DATA_RATE_3_12HZ +* 4 | SMI130_ACCEL_OUTPUT_DATA_RATE_6_25HZ +* 5 | SMI130_ACCEL_OUTPUT_DATA_RATE_12_5HZ +* 6 | SMI130_ACCEL_OUTPUT_DATA_RATE_25HZ +* 7 | SMI130_ACCEL_OUTPUT_DATA_RATE_50HZ +* 8 | SMI130_ACCEL_OUTPUT_DATA_RATE_100HZ +* 9 | SMI130_ACCEL_OUTPUT_DATA_RATE_200HZ +* 10 | SMI130_ACCEL_OUTPUT_DATA_RATE_400HZ +* 11 | SMI130_ACCEL_OUTPUT_DATA_RATE_800HZ +* 12 | SMI130_ACCEL_OUTPUT_DATA_RATE_1600HZ +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_output_data_rate( +u8 v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* accel output data rate selection*/ + if ((v_output_data_rate_u8 != SMI130_INIT_VALUE) && + (v_output_data_rate_u8 <= SMI130_MAX_ACCEL_OUTPUT_DATA_RATE)) { + /* write accel output data rate*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE, + v_output_data_rate_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to get the +* accel bandwidth from the register 0x40 bit 4 to 6 +* @brief bandwidth parameter determines filter configuration(acc_us=0) +* and averaging for under sampling mode(acc_us=1) +* +* +* @param v_bw_u8 : The value of accel bandwidth +* +* @note accel bandwidth depends on under sampling parameter +* @note under sampling parameter cab be set by the function +* "SMI130_SET_ACCEL_UNDER_SAMPLING_PARAMETER" +* +* @note Filter configuration +* accel_us | Filter configuration +* -----------|--------------------- +* 0x00 | OSR4 mode +* 0x01 | OSR2 mode +* 0x02 | normal mode +* 0x03 | CIC mode +* 0x04 | Reserved +* 0x05 | Reserved +* 0x06 | Reserved +* 0x07 | Reserved +* +* @note accel under sampling mode +* accel_us | Under sampling mode +* -----------|--------------------- +* 0x00 | no averaging +* 0x01 | average 2 samples +* 0x02 | average 4 samples +* 0x03 | average 8 samples +* 0x04 | average 16 samples +* 0x05 | average 32 samples +* 0x06 | average 64 samples +* 0x07 | average 128 samples +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_bw(u8*v_bw_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel bandwidth*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_bw_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_CONFIG_ACCEL_BW); + } + return com_rslt; +} +/*! +* @brief This API is used to set the +* accel bandwidth from the register 0x40 bit 4 to 6 +* @brief bandwidth parameter determines filter configuration(acc_us=0) +* and averaging for under sampling mode(acc_us=1) +* +* +* @param v_bw_u8 : The value of accel bandwidth +* +* @note accel bandwidth depends on under sampling parameter +* @note under sampling parameter cab be set by the function +* "SMI130_SET_ACCEL_UNDER_SAMPLING_PARAMETER" +* +* @note Filter configuration +* accel_us | Filter configuration +* -----------|--------------------- +* 0x00 | OSR4 mode +* 0x01 | OSR2 mode +* 0x02 | normal mode +* 0x03 | CIC mode +* 0x04 | Reserved +* 0x05 | Reserved +* 0x06 | Reserved +* 0x07 | Reserved +* +* @note accel under sampling mode +* accel_us | Under sampling mode +* -----------|--------------------- +* 0x00 | no averaging +* 0x01 | average 2 samples +* 0x02 | average 4 samples +* 0x03 | average 8 samples +* 0x04 | average 16 samples +* 0x05 | average 32 samples +* 0x06 | average 64 samples +* 0x07 | average 128 samples +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_bw(u8 v_bw_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* select accel bandwidth*/ + if (v_bw_u8 <= SMI130_MAX_ACCEL_BW) { + /* write accel bandwidth*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_CONFIG_ACCEL_BW, + v_bw_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_ACCEL_BW__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to get the accel +* under sampling parameter form the register 0x40 bit 7 +* +* +* +* +* @param v_accel_under_sampling_u8 : The value of accel under sampling +* value | under_sampling +* ----------|--------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_under_sampling_parameter( +u8*v_accel_under_sampling_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel under sampling parameter*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_under_sampling_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING); + } + return com_rslt; +} +/*! +* @brief This API is used to set the accel +* under sampling parameter form the register 0x40 bit 7 +* +* +* +* +* @param v_accel_under_sampling_u8 : The value of accel under sampling +* value | under_sampling +* ----------|--------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_under_sampling_parameter( +u8 v_accel_under_sampling_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_accel_under_sampling_u8 <= SMI130_MAX_UNDER_SAMPLING) { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + /* write the accel under sampling parameter*/ + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING, + v_accel_under_sampling_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} +return com_rslt; +} +/*! +* @brief This API is used to get the ranges +* (g values) of the accel from the register 0x41 bit 0 to 3 +* +* +* +* +* @param v_range_u8 : The value of accel g range +* value | g_range +* ----------|----------- +* 0x03 | SMI130_ACCEL_RANGE_2G +* 0x05 | SMI130_ACCEL_RANGE_4G +* 0x08 | SMI130_ACCEL_RANGE_8G +* 0x0C | SMI130_ACCEL_RANGE_16G +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_range( +u8*v_range_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel range*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_RANGE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_range_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_RANGE); + } + return com_rslt; +} +/*! +* @brief This API is used to set the ranges +* (g values) of the accel from the register 0x41 bit 0 to 3 +* +* +* +* +* @param v_range_u8 : The value of accel g range +* value | g_range +* ----------|----------- +* 0x03 | SMI130_ACCEL_RANGE_2G +* 0x05 | SMI130_ACCEL_RANGE_4G +* 0x08 | SMI130_ACCEL_RANGE_8G +* 0x0C | SMI130_ACCEL_RANGE_16G +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_range(u8 v_range_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if ((v_range_u8 == SMI130_ACCEL_RANGE0) || + (v_range_u8 == SMI130_ACCEL_RANGE1) || + (v_range_u8 == SMI130_ACCEL_RANGE3) || + (v_range_u8 == SMI130_ACCEL_RANGE4)) { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_ACCEL_RANGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE( + v_data_u8, SMI130_USER_ACCEL_RANGE, + v_range_u8); + /* write the accel range*/ + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_RANGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to get the +* gyroscope output data rate from the register 0x42 bit 0 to 3 +* +* +* +* +* @param v_output_data_rate_u8 :The value of gyro output data rate +* value | gyro output data rate +* -----------|----------------------------- +* 0x00 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x01 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x02 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x03 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x04 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x05 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x06 | SMI130_GYRO_OUTPUT_DATA_RATE_25HZ +* 0x07 | SMI130_GYRO_OUTPUT_DATA_RATE_50HZ +* 0x08 | SMI130_GYRO_OUTPUT_DATA_RATE_100HZ +* 0x09 | SMI130_GYRO_OUTPUT_DATA_RATE_200HZ +* 0x0A | SMI130_GYRO_OUTPUT_DATA_RATE_400HZ +* 0x0B | SMI130_GYRO_OUTPUT_DATA_RATE_800HZ +* 0x0C | SMI130_GYRO_OUTPUT_DATA_RATE_1600HZ +* 0x0D | SMI130_GYRO_OUTPUT_DATA_RATE_3200HZ +* 0x0E | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x0F | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_output_data_rate( +u8*v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the gyro output data rate*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_output_data_rate_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE); + } + return com_rslt; +} +/*! +* @brief This API is used to set the +* gyroscope output data rate from the register 0x42 bit 0 to 3 +* +* +* +* +* @param v_output_data_rate_u8 :The value of gyro output data rate +* value | gyro output data rate +* -----------|----------------------------- +* 0x00 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x01 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x02 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x03 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x04 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x05 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x06 | SMI130_GYRO_OUTPUT_DATA_RATE_25HZ +* 0x07 | SMI130_GYRO_OUTPUT_DATA_RATE_50HZ +* 0x08 | SMI130_GYRO_OUTPUT_DATA_RATE_100HZ +* 0x09 | SMI130_GYRO_OUTPUT_DATA_RATE_200HZ +* 0x0A | SMI130_GYRO_OUTPUT_DATA_RATE_400HZ +* 0x0B | SMI130_GYRO_OUTPUT_DATA_RATE_800HZ +* 0x0C | SMI130_GYRO_OUTPUT_DATA_RATE_1600HZ +* 0x0D | SMI130_GYRO_OUTPUT_DATA_RATE_3200HZ +* 0x0E | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* 0x0F | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_output_data_rate( +u8 v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* select the gyro output data rate*/ + if ((v_output_data_rate_u8 < SMI130_OUTPUT_DATA_RATE6) && + (v_output_data_rate_u8 != SMI130_INIT_VALUE) + && (v_output_data_rate_u8 != SMI130_OUTPUT_DATA_RATE1) + && (v_output_data_rate_u8 != SMI130_OUTPUT_DATA_RATE2) + && (v_output_data_rate_u8 != SMI130_OUTPUT_DATA_RATE3) + && (v_output_data_rate_u8 != SMI130_OUTPUT_DATA_RATE4) + && (v_output_data_rate_u8 != SMI130_OUTPUT_DATA_RATE5) + && (v_output_data_rate_u8 != SMI130_OUTPUT_DATA_RATE6) + && (v_output_data_rate_u8 != SMI130_OUTPUT_DATA_RATE7)) { + /* write the gyro output data rate*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE, + v_output_data_rate_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to get the +* data of gyro from the register 0x42 bit 4 to 5 +* +* +* +* +* @param v_bw_u8 : The value of gyro bandwidth +* value | gyro bandwidth +* ----------|---------------- +* 0x00 | SMI130_GYRO_OSR4_MODE +* 0x01 | SMI130_GYRO_OSR2_MODE +* 0x02 | SMI130_GYRO_NORMAL_MODE +* 0x03 | SMI130_GYRO_CIC_MODE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_bw(u8*v_bw_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro bandwidth*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_GYRO_CONFIG_BW__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_bw_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_CONFIG_BW); + } + return com_rslt; +} +/*! +* @brief This API is used to set the +* data of gyro from the register 0x42 bit 4 to 5 +* +* +* +* +* @param v_bw_u8 : The value of gyro bandwidth +* value | gyro bandwidth +* ----------|---------------- +* 0x00 | SMI130_GYRO_OSR4_MODE +* 0x01 | SMI130_GYRO_OSR2_MODE +* 0x02 | SMI130_GYRO_NORMAL_MODE +* 0x03 | SMI130_GYRO_CIC_MODE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_bw(u8 v_bw_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_bw_u8 <= SMI130_MAX_GYRO_BW) { + /* write the gyro bandwidth*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_GYRO_CONFIG_BW__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_CONFIG_BW, v_bw_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_CONFIG_BW__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API reads the range +* of gyro from the register 0x43 bit 0 to 2 +* +* @param v_range_u8 : The value of gyro range +* value | range +* ----------|------------------------------- +* 0x00 | SMI130_GYRO_RANGE_2000_DEG_SEC +* 0x01 | SMI130_GYRO_RANGE_1000_DEG_SEC +* 0x02 | SMI130_GYRO_RANGE_500_DEG_SEC +* 0x03 | SMI130_GYRO_RANGE_250_DEG_SEC +* 0x04 | SMI130_GYRO_RANGE_125_DEG_SEC +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_range(u8*v_range_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the gyro range*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_GYRO_RANGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_range_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_RANGE); + } + return com_rslt; +} +/*! +* @brief This API set the range +* of gyro from the register 0x43 bit 0 to 2 +* +* @param v_range_u8 : The value of gyro range +* value | range +* ----------|------------------------------- +* 0x00 | SMI130_GYRO_RANGE_2000_DEG_SEC +* 0x01 | SMI130_GYRO_RANGE_1000_DEG_SEC +* 0x02 | SMI130_GYRO_RANGE_500_DEG_SEC +* 0x03 | SMI130_GYRO_RANGE_250_DEG_SEC +* 0x04 | SMI130_GYRO_RANGE_125_DEG_SEC +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_range(u8 v_range_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_range_u8 <= SMI130_MAX_GYRO_RANGE) { + /* write the gyro range value*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_GYRO_RANGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_RANGE, + v_range_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_GYRO_RANGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to get the +* output data rate of magnetometer from the register 0x44 bit 0 to 3 +* +* +* +* +* @param v_output_data_rat_u8e : The value of mag output data rate +* value | mag output data rate +* ---------|--------------------------- +* 0x00 |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED +* 0x01 |SMI130_MAG_OUTPUT_DATA_RATE_0_78HZ +* 0x02 |SMI130_MAG_OUTPUT_DATA_RATE_1_56HZ +* 0x03 |SMI130_MAG_OUTPUT_DATA_RATE_3_12HZ +* 0x04 |SMI130_MAG_OUTPUT_DATA_RATE_6_25HZ +* 0x05 |SMI130_MAG_OUTPUT_DATA_RATE_12_5HZ +* 0x06 |SMI130_MAG_OUTPUT_DATA_RATE_25HZ +* 0x07 |SMI130_MAG_OUTPUT_DATA_RATE_50HZ +* 0x08 |SMI130_MAG_OUTPUT_DATA_RATE_100HZ +* 0x09 |SMI130_MAG_OUTPUT_DATA_RATE_200HZ +* 0x0A |SMI130_MAG_OUTPUT_DATA_RATE_400HZ +* 0x0B |SMI130_MAG_OUTPUT_DATA_RATE_800HZ +* 0x0C |SMI130_MAG_OUTPUT_DATA_RATE_1600HZ +* 0x0D |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED0 +* 0x0E |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED1 +* 0x0F |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED2 +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_output_data_rate( +u8*v_output_data_rat_u8e) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the mag data output rate*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_output_data_rat_u8e = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE); + } + return com_rslt; +} +/*! +* @brief This API is used to set the +* output data rate of magnetometer from the register 0x44 bit 0 to 3 +* +* +* +* +* @param v_output_data_rat_u8e : The value of mag output data rate +* value | mag output data rate +* ---------|--------------------------- +* 0x00 |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED +* 0x01 |SMI130_MAG_OUTPUT_DATA_RATE_0_78HZ +* 0x02 |SMI130_MAG_OUTPUT_DATA_RATE_1_56HZ +* 0x03 |SMI130_MAG_OUTPUT_DATA_RATE_3_12HZ +* 0x04 |SMI130_MAG_OUTPUT_DATA_RATE_6_25HZ +* 0x05 |SMI130_MAG_OUTPUT_DATA_RATE_12_5HZ +* 0x06 |SMI130_MAG_OUTPUT_DATA_RATE_25HZ +* 0x07 |SMI130_MAG_OUTPUT_DATA_RATE_50HZ +* 0x08 |SMI130_MAG_OUTPUT_DATA_RATE_100HZ +* 0x09 |SMI130_MAG_OUTPUT_DATA_RATE_200HZ +* 0x0A |SMI130_MAG_OUTPUT_DATA_RATE_400HZ +* 0x0B |SMI130_MAG_OUTPUT_DATA_RATE_800HZ +* 0x0C |SMI130_MAG_OUTPUT_DATA_RATE_1600HZ +* 0x0D |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED0 +* 0x0E |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED1 +* 0x0F |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED2 +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_output_data_rate( +u8 v_output_data_rat_u8e) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* select the mag data output rate*/ + if ((v_output_data_rat_u8e + <= SMI130_MAX_ACCEL_OUTPUT_DATA_RATE) + && (v_output_data_rat_u8e + != SMI130_OUTPUT_DATA_RATE0) + && (v_output_data_rat_u8e + != SMI130_OUTPUT_DATA_RATE6) + && (v_output_data_rat_u8e + != SMI130_OUTPUT_DATA_RATE7)) { + /* write the mag data output rate*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE, + v_output_data_rat_u8e); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API is used to read Down sampling +* for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2 +* +* +* +* +* @param v_fifo_down_gyro_u8 :The value of gyro fifo down +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_down_gyro( +u8*v_fifo_down_gyro_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the gyro fifo down*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_DOWN_GYRO__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_down_gyro_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_DOWN_GYRO); + } + return com_rslt; +} + /*! +* @brief This API is used to set Down sampling +* for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2 +* +* +* +* +* @param v_fifo_down_gyro_u8 :The value of gyro fifo down +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_down_gyro( +u8 v_fifo_down_gyro_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the gyro fifo down*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_DOWN_GYRO__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE( + v_data_u8, + SMI130_USER_FIFO_DOWN_GYRO, + v_fifo_down_gyro_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_DOWN_GYRO__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API is used to read gyro fifo filter data +* from the register 0x45 bit 3 +* +* +* +* @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data +* value | gyro_fifo_filter_data +* ------------|------------------------- +* 0x00 | Unfiltered data +* 0x01 | Filtered data +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_fifo_filter_data( +u8*v_gyro_fifo_filter_data_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the gyro fifo filter data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_FILTER_GYRO__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_fifo_filter_data_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_FILTER_GYRO); + } + return com_rslt; +} +/*! +* @brief This API is used to set gyro fifo filter data +* from the register 0x45 bit 3 +* +* +* +* @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data +* value | gyro_fifo_filter_data +* ------------|------------------------- +* 0x00 | Unfiltered data +* 0x01 | Filtered data +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_fifo_filter_data( +u8 v_gyro_fifo_filter_data_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_gyro_fifo_filter_data_u8 + <= SMI130_MAX_VALUE_FIFO_FILTER) { + /* write the gyro fifo filter data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_FILTER_GYRO__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE( + v_data_u8, + SMI130_USER_FIFO_FILTER_GYRO, + v_gyro_fifo_filter_data_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_FILTER_GYRO__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to read Down sampling +* for accel (2*downs_accel) from the register 0x45 bit 4 to 6 +* +* +* +* +* @param v_fifo_down_u8 :The value of accel fifo down +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_down_accel( +u8*v_fifo_down_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel fifo down data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_down_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_DOWN_ACCEL); + } + return com_rslt; +} + /*! +* @brief This API is used to set Down sampling +* for accel (2*downs_accel) from the register 0x45 bit 4 to 6 +* +* +* +* +* @param v_fifo_down_u8 :The value of accel fifo down +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_down_accel( +u8 v_fifo_down_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the accel fifo down data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_DOWN_ACCEL, v_fifo_down_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_DOWN_ACCEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API is used to read accel fifo filter data +* from the register 0x45 bit 7 +* +* +* +* @param v_accel_fifo_filter_u8 :The value of accel filter data +* value | accel_fifo_filter_data +* ------------|------------------------- +* 0x00 | Unfiltered data +* 0x01 | Filtered data +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_fifo_filter_data( +u8*v_accel_fifo_filter_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel fifo filter data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_FILTER_ACCEL__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_fifo_filter_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_FILTER_ACCEL); + } + return com_rslt; +} +/*! +* @brief This API is used to set accel fifo filter data +* from the register 0x45 bit 7 +* +* +* +* @param v_accel_fifo_filter_u8 :The value of accel filter data +* value | accel_fifo_filter_data +* ------------|------------------------- +* 0x00 | Unfiltered data +* 0x01 | Filtered data +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_fifo_filter_data( +u8 v_accel_fifo_filter_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_accel_fifo_filter_u8 <= SMI130_MAX_VALUE_FIFO_FILTER) { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_FILTER_ACCEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + /* write accel fifo filter data*/ + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_FILTER_ACCEL, + v_accel_fifo_filter_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_FILTER_ACCEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to Trigger an interrupt +* when FIFO contains water mark level from the register 0x46 bit 0 to 7 +* +* +* +* @param v_fifo_wm_u8 : The value of fifo water mark level +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_wm( +u8*v_fifo_wm_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the fifo water mark level*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_WM__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_wm_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_WM); + } + return com_rslt; +} +/*! +* @brief This API is used to Trigger an interrupt +* when FIFO contains water mark level from the register 0x46 bit 0 to 7 +* +* +* +* @param v_fifo_wm_u8 : The value of fifo water mark level +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_wm( +u8 v_fifo_wm_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the fifo water mark level*/ + com_rslt = + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_WM__REG, + &v_fifo_wm_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! +* @brief This API reads fifo sensor time +* frame after the last valid data frame form the register 0x47 bit 1 +* +* +* +* +* @param v_fifo_time_enable_u8 : The value of sensor time +* value | fifo sensor time +* ------------|------------------------- +* 0x00 | do not return sensortime frame +* 0x01 | return sensortime frame +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_time_enable( +u8*v_fifo_time_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the fifo sensor time*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_TIME_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_time_enable_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_TIME_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API set fifo sensor time +* frame after the last valid data frame form the register 0x47 bit 1 +* +* +* +* +* @param v_fifo_time_enable_u8 : The value of sensor time +* value | fifo sensor time +* ------------|------------------------- +* 0x00 | do not return sensortime frame +* 0x01 | return sensortime frame +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_time_enable( +u8 v_fifo_time_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_fifo_time_enable_u8 <= SMI130_MAX_VALUE_FIFO_TIME) { + /* write the fifo sensor time*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_TIME_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_TIME_ENABLE, + v_fifo_time_enable_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_TIME_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API reads FIFO tag interrupt2 enable status +* from the resister 0x47 bit 2 +* +* @param v_fifo_tag_intr2_u8 : The value of fifo tag interrupt +* value | fifo tag interrupt +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_tag_intr2_enable( +u8*v_fifo_tag_intr2_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the fifo tag interrupt2*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_tag_intr2_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_TAG_INTR2_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API set FIFO tag interrupt2 enable status +* from the resister 0x47 bit 2 +* +* @param v_fifo_tag_intr2_u8 : The value of fifo tag interrupt +* value | fifo tag interrupt +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_tag_intr2_enable( +u8 v_fifo_tag_intr2_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_fifo_tag_intr2_u8 <= SMI130_MAX_VALUE_FIFO_INTR) { + /* write the fifo tag interrupt2*/ + com_rslt = smi130_set_input_enable(1, + v_fifo_tag_intr2_u8); + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_TAG_INTR2_ENABLE, + v_fifo_tag_intr2_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_TAG_INTR2_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API get FIFO tag interrupt1 enable status +* from the resister 0x47 bit 3 +* +* @param v_fifo_tag_intr1_u8 :The value of fifo tag interrupt1 +* value | fifo tag interrupt +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_tag_intr1_enable( +u8*v_fifo_tag_intr1_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read fifo tag interrupt*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_tag_intr1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_TAG_INTR1_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API set FIFO tag interrupt1 enable status +* from the resister 0x47 bit 3 +* +* @param v_fifo_tag_intr1_u8 :The value of fifo tag interrupt1 +* value | fifo tag interrupt +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_tag_intr1_enable( +u8 v_fifo_tag_intr1_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_fifo_tag_intr1_u8 <= SMI130_MAX_VALUE_FIFO_INTR) { + /* write the fifo tag interrupt*/ + com_rslt = smi130_set_input_enable(SMI130_INIT_VALUE, + v_fifo_tag_intr1_u8); + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_TAG_INTR1_ENABLE, + v_fifo_tag_intr1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_TAG_INTR1_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API reads FIFO frame +* header enable from the register 0x47 bit 4 +* +* @param v_fifo_header_u8 :The value of fifo header +* value | fifo header +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_header_enable( +u8*v_fifo_header_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read fifo header*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_header_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_HEADER_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API set FIFO frame +* header enable from the register 0x47 bit 4 +* +* @param v_fifo_header_u8 :The value of fifo header +* value | fifo header +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_header_enable( +u8 v_fifo_header_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_fifo_header_u8 <= SMI130_MAX_VALUE_FIFO_HEADER) { + /* write the fifo header*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_HEADER_ENABLE, + v_fifo_header_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_HEADER_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to read stored +* magnetometer data in FIFO (all 3 axes) from the register 0x47 bit 5 +* +* @param v_fifo_mag_u8 : The value of fifo mag enble +* value | fifo mag +* ----------|------------------- +* 0x00 | no magnetometer data is stored +* 0x01 | magnetometer data is stored +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_mag_enable( +u8*v_fifo_mag_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the fifo mag enable*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_MAG_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_mag_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_MAG_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API is used to set stored +* magnetometer data in FIFO (all 3 axes) from the register 0x47 bit 5 +* +* @param v_fifo_mag_u8 : The value of fifo mag enble +* value | fifo mag +* ----------|------------------- +* 0x00 | no magnetometer data is stored +* 0x01 | magnetometer data is stored +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_mag_enable( +u8 v_fifo_mag_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_fifo_mag_u8 <= SMI130_MAX_VALUE_FIFO_MAG) { + /* write the fifo mag enable*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_FIFO_MAG_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_MAG_ENABLE, + v_fifo_mag_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_FIFO_MAG_ENABLE__REG, + &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to read stored +* accel data in FIFO (all 3 axes) from the register 0x47 bit 6 +* +* @param v_fifo_accel_u8 : The value of fifo accel enble +* value | fifo accel +* ----------|------------------- +* 0x00 | no accel data is stored +* 0x01 | accel data is stored +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_accel_enable( +u8*v_fifo_accel_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel fifo enable*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_accel_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_ACCEL_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API is used to set stored +* accel data in FIFO (all 3 axes) from the register 0x47 bit 6 +* +* @param v_fifo_accel_u8 : The value of fifo accel enble +* value | fifo accel +* ----------|------------------- +* 0x00 | no accel data is stored +* 0x01 | accel data is stored +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_accel_enable( +u8 v_fifo_accel_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_fifo_accel_u8 <= SMI130_MAX_VALUE_FIFO_ACCEL) { + /* write the fifo mag enables*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_ACCEL_ENABLE, v_fifo_accel_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_ACCEL_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to read stored +* gyro data in FIFO (all 3 axes) from the resister 0x47 bit 7 +* +* +* @param v_fifo_gyro_u8 : The value of fifo gyro enble +* value | fifo gyro +* ----------|------------------- +* 0x00 | no gyro data is stored +* 0x01 | gyro data is stored +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_gyro_enable( +u8*v_fifo_gyro_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read fifo gyro enable*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_gyro_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_GYRO_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API is used to set stored +* gyro data in FIFO (all 3 axes) from the resister 0x47 bit 7 +* +* +* @param v_fifo_gyro_u8 : The value of fifo gyro enble +* value | fifo gyro +* ----------|------------------- +* 0x00 | no gyro data is stored +* 0x01 | gyro data is stored +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_gyro_enable( +u8 v_fifo_gyro_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_fifo_gyro_u8 <= SMI130_MAX_VALUE_FIFO_GYRO) { + /* write fifo gyro enable*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FIFO_GYRO_ENABLE, v_fifo_gyro_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FIFO_GYRO_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to read +* I2C device address of auxiliary mag from the register 0x4B bit 1 to 7 +* +* +* +* +* @param v_i2c_device_addr_u8 : The value of mag I2C device address +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_device_addr( +u8*v_i2c_device_addr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the mag I2C device address*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_I2C_DEVICE_ADDR__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_device_addr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_I2C_DEVICE_ADDR); + } + return com_rslt; +} +/*! +* @brief This API is used to set +* I2C device address of auxiliary mag from the register 0x4B bit 1 to 7 +* +* +* +* +* @param v_i2c_device_addr_u8 : The value of mag I2C device address +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_i2c_device_addr( +u8 v_i2c_device_addr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the mag I2C device address*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_I2C_DEVICE_ADDR__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_I2C_DEVICE_ADDR, + v_i2c_device_addr_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_I2C_DEVICE_ADDR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API is used to read +* Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1 +* +* +* +* +* @param v_mag_burst_u8 : The data of mag burst read lenth +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_burst( +u8*v_mag_burst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read mag burst mode length*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_BURST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_burst_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_MAG_BURST); + } + return com_rslt; +} +/*! +* @brief This API is used to set +* Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1 +* +* +* +* +* @param v_mag_burst_u8 : The data of mag burst read lenth +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_burst( +u8 v_mag_burst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write mag burst mode length*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_BURST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_MAG_BURST, v_mag_burst_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_MAG_BURST__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API is used to read +* trigger-readout offset in units of 2.5 ms. If set to zero, +* the offset is maximum, i.e. after readout a trigger +* is issued immediately. from the register 0x4C bit 2 to 5 +* +* +* +* +* @param v_mag_offset_u8 : The value of mag offset +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_offset( +u8*v_mag_offset_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_OFFSET__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_offset_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_MAG_OFFSET); + } + return com_rslt; +} +/*! +* @brief This API is used to set +* trigger-readout offset in units of 2.5 ms. If set to zero, +* the offset is maximum, i.e. after readout a trigger +* is issued immediately. from the register 0x4C bit 2 to 5 +* +* +* +* +* @param v_mag_offset_u8 : The value of mag offset +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_offset( +u8 v_mag_offset_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_OFFSET__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_MAG_OFFSET, v_mag_offset_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_OFFSET__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } +return com_rslt; +} +/*! +* @brief This API is used to read +* Enable register access on MAG_IF[2] or MAG_IF[3] writes. +* This implies that the DATA registers are not updated with +* magnetometer values. Accessing magnetometer requires +* the magnetometer in normal mode in PMU_STATUS. +* from the register 0x4C bit 7 +* +* +* +* @param v_mag_manual_u8 : The value of mag manual enable +* value | mag manual +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_manual_enable( +u8*v_mag_manual_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read mag manual*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_manual_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_MAG_MANUAL_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API is used to set +* Enable register access on MAG_IF[2] or MAG_IF[3] writes. +* This implies that the DATA registers are not updated with +* magnetometer values. Accessing magnetometer requires +* the magnetometer in normal mode in PMU_STATUS. +* from the register 0x4C bit 7 +* +* +* +* @param v_mag_manual_u8 : The value of mag manual enable +* value | mag manual +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_manual_enable( +u8 v_mag_manual_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the mag manual*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + if (com_rslt == SUCCESS) { + /* set the bit of mag manual enable*/ + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_MAG_MANUAL_ENABLE, v_mag_manual_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130->dev_addr, + SMI130_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + if (com_rslt == SUCCESS) + p_smi130->mag_manual_enable = v_mag_manual_u8; + else + p_smi130->mag_manual_enable = E_SMI130_COMM_RES; + } +return com_rslt; +} +/*! +* @brief This API is used to read data +* magnetometer address to read from the register 0x4D bit 0 to 7 +* @brief It used to provide mag read address of auxiliary mag +* +* +* +* +* @param v_mag_read_addr_u8 : The value of address need to be read +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_read_addr( +u8*v_mag_read_addr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the written address*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_READ_ADDR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_read_addr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_READ_ADDR); + } + return com_rslt; +} +/*! +* @brief This API is used to set +* magnetometer write address from the register 0x4D bit 0 to 7 +* @brief mag write address writes the address of auxiliary mag to write +* +* +* +* @param v_mag_read_addr_u8: +* The data of auxiliary mag address to write data +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_read_addr( +u8 v_mag_read_addr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the mag read address*/ + com_rslt = + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130->dev_addr, + SMI130_USER_READ_ADDR__REG, &v_mag_read_addr_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! +* @brief This API is used to read +* magnetometer write address from the register 0x4E bit 0 to 7 +* @brief mag write address writes the address of auxiliary mag to write +* +* +* +* @param v_mag_write_addr_u8: +* The data of auxiliary mag address to write data +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_write_addr( +u8*v_mag_write_addr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the address of last written*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_WRITE_ADDR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_write_addr_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_WRITE_ADDR); + } + return com_rslt; +} +/*! +* @brief This API is used to set +* magnetometer write address from the register 0x4E bit 0 to 7 +* @brief mag write address writes the address of auxiliary mag to write +* +* +* +* @param v_mag_write_addr_u8: +* The data of auxiliary mag address to write data +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_write_addr( +u8 v_mag_write_addr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the data of mag address to write data*/ + com_rslt = + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130->dev_addr, + SMI130_USER_WRITE_ADDR__REG, &v_mag_write_addr_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! +* @brief This API is used to read magnetometer write data +* form the resister 0x4F bit 0 to 7 +* @brief This writes the data will be wrote to mag +* +* +* +* @param v_mag_write_data_u8: The value of mag data +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_write_data( +u8*v_mag_write_data_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_WRITE_DATA__REG, &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_write_data_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_WRITE_DATA); + } + return com_rslt; +} +/*! +* @brief This API is used to set magnetometer write data +* form the resister 0x4F bit 0 to 7 +* @brief This writes the data will be wrote to mag +* +* +* +* @param v_mag_write_data_u8: The value of mag data +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_write_data( +u8 v_mag_write_data_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130->dev_addr, + SMI130_USER_WRITE_DATA__REG, &v_mag_write_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! +* @brief This API is used to read +* interrupt enable from the register 0x50 bit 0 to 7 +* +* +* +* +* @param v_enable_u8 : Value to decided to select interrupt +* v_enable_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_ANY_MOTION_X_ENABLE +* 1 | SMI130_ANY_MOTION_Y_ENABLE +* 2 | SMI130_ANY_MOTION_Z_ENABLE +* 3 | SMI130_DOUBLE_TAP_ENABLE +* 4 | SMI130_SINGLE_TAP_ENABLE +* 5 | SMI130_ORIENT_ENABLE +* 6 | SMI130_FLAT_ENABLE +* +* @param v_intr_enable_zero_u8 : The interrupt enable value +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_enable_0( +u8 v_enable_u8, u8*v_intr_enable_zero_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* select interrupt to read*/ + switch (v_enable_u8) { + case SMI130_ANY_MOTION_X_ENABLE: + /* read the any motion interrupt x data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE); + break; + case SMI130_ANY_MOTION_Y_ENABLE: + /* read the any motion interrupt y data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE); + break; + case SMI130_ANY_MOTION_Z_ENABLE: + /* read the any motion interrupt z data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE); + break; + case SMI130_DOUBLE_TAP_ENABLE: + /* read the double tap interrupt data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE); + break; + case SMI130_SINGLE_TAP_ENABLE: + /* read the single tap interrupt data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE); + break; + case SMI130_ORIENT_ENABLE: + /* read the orient interrupt data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE); + break; + case SMI130_FLAT_ENABLE: + /* read the flat interrupt data*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API is used to set +* interrupt enable from the register 0x50 bit 0 to 7 +* +* +* +* +* @param v_enable_u8 : Value to decided to select interrupt +* v_enable_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_ANY_MOTION_X_ENABLE +* 1 | SMI130_ANY_MOTION_Y_ENABLE +* 2 | SMI130_ANY_MOTION_Z_ENABLE +* 3 | SMI130_DOUBLE_TAP_ENABLE +* 4 | SMI130_SINGLE_TAP_ENABLE +* 5 | SMI130_ORIENT_ENABLE +* 6 | SMI130_FLAT_ENABLE +* +* @param v_intr_enable_zero_u8 : The interrupt enable value +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_enable_0( +u8 v_enable_u8, u8 v_intr_enable_zero_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_enable_u8) { + case SMI130_ANY_MOTION_X_ENABLE: + /* write any motion x*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_ANY_MOTION_Y_ENABLE: + /* write any motion y*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_ANY_MOTION_Z_ENABLE: + /* write any motion z*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_DOUBLE_TAP_ENABLE: + /* write double tap*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_SINGLE_TAP_ENABLE: + /* write single tap*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_ORIENT_ENABLE: + /* write orient interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_FLAT_ENABLE: + /* write flat interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief This API is used to read +* interrupt enable byte1 from the register 0x51 bit 0 to 6 +* @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable +* data ready, fifo full and fifo water mark. +* +* +* +* @param v_enable_u8 : The value of interrupt enable +* @param v_enable_u8 : Value to decided to select interrupt +* v_enable_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_HIGH_G_X_ENABLE +* 1 | SMI130_HIGH_G_Y_ENABLE +* 2 | SMI130_HIGH_G_Z_ENABLE +* 3 | SMI130_LOW_G_ENABLE +* 4 | SMI130_DATA_RDY_ENABLE +* 5 | SMI130_FIFO_FULL_ENABLE +* 6 | SMI130_FIFO_WM_ENABLE +* +* @param v_intr_enable_1_u8 : The interrupt enable value +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_enable_1( +u8 v_enable_u8, u8*v_intr_enable_1_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_enable_u8) { + case SMI130_HIGH_G_X_ENABLE: + /* read high_g_x interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE); + break; + case SMI130_HIGH_G_Y_ENABLE: + /* read high_g_y interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE); + break; + case SMI130_HIGH_G_Z_ENABLE: + /* read high_g_z interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE); + break; + case SMI130_LOW_G_ENABLE: + /* read low_g interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE); + break; + case SMI130_DATA_RDY_ENABLE: + /* read data ready interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE); + break; + case SMI130_FIFO_FULL_ENABLE: + /* read fifo full interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE); + break; + case SMI130_FIFO_WM_ENABLE: + /* read fifo water mark interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API is used to set +* interrupt enable byte1 from the register 0x51 bit 0 to 6 +* @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable +* data ready, fifo full and fifo water mark. +* +* +* +* @param v_enable_u8 : The value of interrupt enable +* @param v_enable_u8 : Value to decided to select interrupt +* v_enable_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_HIGH_G_X_ENABLE +* 1 | SMI130_HIGH_G_Y_ENABLE +* 2 | SMI130_HIGH_G_Z_ENABLE +* 3 | SMI130_LOW_G_ENABLE +* 4 | SMI130_DATA_RDY_ENABLE +* 5 | SMI130_FIFO_FULL_ENABLE +* 6 | SMI130_FIFO_WM_ENABLE +* +* @param v_intr_enable_1_u8 : The interrupt enable value +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_enable_1( +u8 v_enable_u8, u8 v_intr_enable_1_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_enable_u8) { + case SMI130_HIGH_G_X_ENABLE: + /* write high_g_x interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_HIGH_G_Y_ENABLE: + /* write high_g_y interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_HIGH_G_Z_ENABLE: + /* write high_g_z interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_LOW_G_ENABLE: + /* write low_g interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_DATA_RDY_ENABLE: + /* write data ready interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_FIFO_FULL_ENABLE: + /* write fifo full interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_FIFO_WM_ENABLE: + /* write fifo water mark interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API is used to read +* interrupt enable byte2 from the register bit 0x52 bit 0 to 3 +* @brief It reads no motion x,y and z +* +* +* +* @param v_enable_u8: The value of interrupt enable +* v_enable_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_NOMOTION_X_ENABLE +* 1 | SMI130_NOMOTION_Y_ENABLE +* 2 | SMI130_NOMOTION_Z_ENABLE +* +* @param v_intr_enable_2_u8 : The interrupt enable value +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_enable_2( +u8 v_enable_u8, u8*v_intr_enable_2_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_enable_u8) { + case SMI130_NOMOTION_X_ENABLE: + /* read no motion x*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_2_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE); + break; + case SMI130_NOMOTION_Y_ENABLE: + /* read no motion y*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_2_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE); + break; + case SMI130_NOMOTION_Z_ENABLE: + /* read no motion z*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_2_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API is used to set +* interrupt enable byte2 from the register bit 0x52 bit 0 to 3 +* @brief It reads no motion x,y and z +* +* +* +* @param v_enable_u8: The value of interrupt enable +* v_enable_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_NOMOTION_X_ENABLE +* 1 | SMI130_NOMOTION_Y_ENABLE +* 2 | SMI130_NOMOTION_Z_ENABLE +* +* @param v_intr_enable_2_u8 : The interrupt enable value +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_enable_2( +u8 v_enable_u8, u8 v_intr_enable_2_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_enable_u8) { + case SMI130_NOMOTION_X_ENABLE: + /* write no motion x*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE, + v_intr_enable_2_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_NOMOTION_Y_ENABLE: + /* write no motion y*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE, + v_intr_enable_2_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_NOMOTION_Z_ENABLE: + /* write no motion z*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE, + v_intr_enable_2_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} + /*! +* @brief This API is used to read +* interrupt enable step detector interrupt from +* the register bit 0x52 bit 3 +* +* +* +* +* @param v_step_intr_u8 : The value of step detector interrupt enable +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_step_detector_enable( +u8*v_step_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the step detector interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_step_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE); + } + return com_rslt; +} + /*! +* @brief This API is used to set +* interrupt enable step detector interrupt from +* the register bit 0x52 bit 3 +* +* +* +* +* @param v_step_intr_u8 : The value of step detector interrupt enable +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_detector_enable( +u8 v_step_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE, + v_step_intr_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief Configure trigger condition of interrupt1 +* and interrupt2 pin from the register 0x53 +* @brief interrupt1 - bit 0 +* @brief interrupt2 - bit 4 +* +* @param v_channel_u8: The value of edge trigger selection +* v_channel_u8 | Edge trigger +* ---------------|--------------- +* 0 | SMI130_INTR1_EDGE_CTRL +* 1 | SMI130_INTR2_EDGE_CTRL +* +* @param v_intr_edge_ctrl_u8 : The value of edge trigger enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_EDGE +* 0x00 | SMI130_LEVEL +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_edge_ctrl( +u8 v_channel_u8, u8*v_intr_edge_ctrl_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_EDGE_CTRL: + /* read the edge trigger interrupt1*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_EDGE_CTRL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_edge_ctrl_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_EDGE_CTRL); + break; + case SMI130_INTR2_EDGE_CTRL: + /* read the edge trigger interrupt2*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_EDGE_CTRL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_edge_ctrl_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_EDGE_CTRL); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Configure trigger condition of interrupt1 +* and interrupt2 pin from the register 0x53 +* @brief interrupt1 - bit 0 +* @brief interrupt2 - bit 4 +* +* @param v_channel_u8: The value of edge trigger selection +* v_channel_u8 | Edge trigger +* ---------------|--------------- +* 0 | SMI130_INTR1_EDGE_CTRL +* 1 | SMI130_INTR2_EDGE_CTRL +* +* @param v_intr_edge_ctrl_u8 : The value of edge trigger enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_EDGE +* 0x00 | SMI130_LEVEL +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_edge_ctrl( +u8 v_channel_u8, u8 v_intr_edge_ctrl_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_EDGE_CTRL: + /* write the edge trigger interrupt1*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_EDGE_CTRL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_EDGE_CTRL, + v_intr_edge_ctrl_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_EDGE_CTRL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_EDGE_CTRL: + /* write the edge trigger interrupt2*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_EDGE_CTRL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_EDGE_CTRL, + v_intr_edge_ctrl_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_EDGE_CTRL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief API used for get the Configure level condition of interrupt1 +* and interrupt2 pin form the register 0x53 +* @brief interrupt1 - bit 1 +* @brief interrupt2 - bit 5 +* +* @param v_channel_u8: The value of level condition selection +* v_channel_u8 | level selection +* ---------------|--------------- +* 0 | SMI130_INTR1_LEVEL +* 1 | SMI130_INTR2_LEVEL +* +* @param v_intr_level_u8 : The value of level of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_LEVEL_HIGH +* 0x00 | SMI130_LEVEL_LOW +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_level( +u8 v_channel_u8, u8*v_intr_level_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_LEVEL: + /* read the interrupt1 level*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_LEVEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_level_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_LEVEL); + break; + case SMI130_INTR2_LEVEL: + /* read the interrupt2 level*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_LEVEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_level_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_LEVEL); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief API used for set the Configure level condition of interrupt1 +* and interrupt2 pin form the register 0x53 +* @brief interrupt1 - bit 1 +* @brief interrupt2 - bit 5 +* +* @param v_channel_u8: The value of level condition selection +* v_channel_u8 | level selection +* ---------------|--------------- +* 0 | SMI130_INTR1_LEVEL +* 1 | SMI130_INTR2_LEVEL +* +* @param v_intr_level_u8 : The value of level of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_LEVEL_HIGH +* 0x00 | SMI130_LEVEL_LOW +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_level( +u8 v_channel_u8, u8 v_intr_level_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_LEVEL: + /* write the interrupt1 level*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_LEVEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_LEVEL, v_intr_level_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_LEVEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_LEVEL: + /* write the interrupt2 level*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_LEVEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_LEVEL, v_intr_level_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_LEVEL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief API used to get configured output enable of interrupt1 +* and interrupt2 from the register 0x53 +* @brief interrupt1 - bit 2 +* @brief interrupt2 - bit 6 +* +* +* @param v_channel_u8: The value of output type enable selection +* v_channel_u8 | level selection +* ---------------|--------------- +* 0 | SMI130_INTR1_OUTPUT_TYPE +* 1 | SMI130_INTR2_OUTPUT_TYPE +* +* @param v_intr_output_type_u8 : +* The value of output type of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_OPEN_DRAIN +* 0x00 | SMI130_PUSH_PULL +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_output_type( +u8 v_channel_u8, u8*v_intr_output_type_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_OUTPUT_TYPE: + /* read the output type of interrupt1*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_OUTPUT_TYPE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_output_type_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_OUTPUT_TYPE); + break; + case SMI130_INTR2_OUTPUT_TYPE: + /* read the output type of interrupt2*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_OUTPUT_TYPE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_output_type_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_OUTPUT_TYPE); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief API used to set output enable of interrupt1 +* and interrupt2 from the register 0x53 +* @brief interrupt1 - bit 2 +* @brief interrupt2 - bit 6 +* +* +* @param v_channel_u8: The value of output type enable selection +* v_channel_u8 | level selection +* ---------------|--------------- +* 0 | SMI130_INTR1_OUTPUT_TYPE +* 1 | SMI130_INTR2_OUTPUT_TYPE +* +* @param v_intr_output_type_u8 : +* The value of output type of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_OPEN_DRAIN +* 0x00 | SMI130_PUSH_PULL +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_output_type( +u8 v_channel_u8, u8 v_intr_output_type_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_OUTPUT_TYPE: + /* write the output type of interrupt1*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_OUTPUT_TYPE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_OUTPUT_TYPE, + v_intr_output_type_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_OUTPUT_TYPE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_OUTPUT_TYPE: + /* write the output type of interrupt2*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_OUTPUT_TYPE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_OUTPUT_TYPE, + v_intr_output_type_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_OUTPUT_TYPE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} + /*! +* @brief API used to get the Output enable for interrupt1 +* and interrupt1 pin from the register 0x53 +* @brief interrupt1 - bit 3 +* @brief interrupt2 - bit 7 +* +* @param v_channel_u8: The value of output enable selection +* v_channel_u8 | level selection +* ---------------|--------------- +* 0 | SMI130_INTR1_OUTPUT_TYPE +* 1 | SMI130_INTR2_OUTPUT_TYPE +* +* @param v_output_enable_u8 : +* The value of output enable of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_INPUT +* 0x00 | SMI130_OUTPUT +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_output_enable( +u8 v_channel_u8, u8*v_output_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_OUTPUT_ENABLE: + /* read the output enable of interrupt1*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_OUTPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_output_enable_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_OUTPUT_ENABLE); + break; + case SMI130_INTR2_OUTPUT_ENABLE: + /* read the output enable of interrupt2*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_OUTPUT_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_output_enable_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_OUTPUT_EN); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} + /*! +* @brief API used to set the Output enable for interrupt1 +* and interrupt1 pin from the register 0x53 +* @brief interrupt1 - bit 3 +* @brief interrupt2 - bit 7 +* +* @param v_channel_u8: The value of output enable selection +* v_channel_u8 | level selection +* ---------------|--------------- +* 0 | SMI130_INTR1_OUTPUT_TYPE +* 1 | SMI130_INTR2_OUTPUT_TYPE +* +* @param v_output_enable_u8 : +* The value of output enable of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_INPUT +* 0x00 | SMI130_OUTPUT +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_output_enable( +u8 v_channel_u8, u8 v_output_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_OUTPUT_ENABLE: + /* write the output enable of interrupt1*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_OUTPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_OUTPUT_ENABLE, + v_output_enable_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_OUTPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_OUTPUT_ENABLE: + /* write the output enable of interrupt2*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_OUTPUT_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_OUTPUT_EN, + v_output_enable_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_OUTPUT_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief This API is used to get the latch duration +* from the register 0x54 bit 0 to 3 +* @brief This latch selection is not applicable for data ready, +* orientation and flat interrupts. +* +* +* +* @param v_latch_intr_u8 : The value of latch duration +* Latch Duration | value +* --------------------------------------|------------------ +* SMI130_LATCH_DUR_NONE | 0x00 +* SMI130_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* SMI130_LATCH_DUR_625_MICRO_SEC | 0x02 +* SMI130_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* SMI130_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* SMI130_LATCH_DUR_5_MILLI_SEC | 0x05 +* SMI130_LATCH_DUR_10_MILLI_SEC | 0x06 +* SMI130_LATCH_DUR_20_MILLI_SEC | 0x07 +* SMI130_LATCH_DUR_40_MILLI_SEC | 0x08 +* SMI130_LATCH_DUR_80_MILLI_SEC | 0x09 +* SMI130_LATCH_DUR_160_MILLI_SEC | 0x0A +* SMI130_LATCH_DUR_320_MILLI_SEC | 0x0B +* SMI130_LATCH_DUR_640_MILLI_SEC | 0x0C +* SMI130_LATCH_DUR_1_28_SEC | 0x0D +* SMI130_LATCH_DUR_2_56_SEC | 0x0E +* SMI130_LATCHED | 0x0F +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_latch_intr( +u8*v_latch_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the latch duration value*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_LATCH__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_latch_intr_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LATCH); + } + return com_rslt; +} +/*! +* @brief This API is used to set the latch duration +* from the register 0x54 bit 0 to 3 +* @brief This latch selection is not applicable for data ready, +* orientation and flat interrupts. +* +* +* +* @param v_latch_intr_u8 : The value of latch duration +* Latch Duration | value +* --------------------------------------|------------------ +* SMI130_LATCH_DUR_NONE | 0x00 +* SMI130_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* SMI130_LATCH_DUR_625_MICRO_SEC | 0x02 +* SMI130_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* SMI130_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* SMI130_LATCH_DUR_5_MILLI_SEC | 0x05 +* SMI130_LATCH_DUR_10_MILLI_SEC | 0x06 +* SMI130_LATCH_DUR_20_MILLI_SEC | 0x07 +* SMI130_LATCH_DUR_40_MILLI_SEC | 0x08 +* SMI130_LATCH_DUR_80_MILLI_SEC | 0x09 +* SMI130_LATCH_DUR_160_MILLI_SEC | 0x0A +* SMI130_LATCH_DUR_320_MILLI_SEC | 0x0B +* SMI130_LATCH_DUR_640_MILLI_SEC | 0x0C +* SMI130_LATCH_DUR_1_28_SEC | 0x0D +* SMI130_LATCH_DUR_2_56_SEC | 0x0E +* SMI130_LATCHED | 0x0F +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_latch_intr(u8 v_latch_intr_u8) +{ + u8 v_data_u8 = SMI130_INIT_VALUE; + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_latch_intr_u8 <= SMI130_MAX_LATCH_INTR) { + /* write the latch duration value*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_LATCH__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LATCH, v_latch_intr_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_LATCH__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief API used to get input enable for interrupt1 +* and interrupt2 pin from the register 0x54 +* @brief interrupt1 - bit 4 +* @brief interrupt2 - bit 5 +* +* @param v_channel_u8: The value of input enable selection +* v_channel_u8 | input selection +* ---------------|--------------- +* 0 | SMI130_INTR1_INPUT_ENABLE +* 1 | SMI130_INTR2_INPUT_ENABLE +* +* @param v_input_en_u8 : +* The value of input enable of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_INPUT +* 0x00 | SMI130_OUTPUT +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_input_enable( +u8 v_channel_u8, u8*v_input_en_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read input enable of interrup1 and interrupt2*/ + case SMI130_INTR1_INPUT_ENABLE: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_INPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_input_en_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_INPUT_ENABLE); + break; + case SMI130_INTR2_INPUT_ENABLE: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_INPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_input_en_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_INPUT_ENABLE); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief API used to set input enable for interrupt1 +* and interrupt2 pin from the register 0x54 +* @brief interrupt1 - bit 4 +* @brief interrupt2 - bit 5 +* +* @param v_channel_u8: The value of input enable selection +* v_channel_u8 | input selection +* ---------------|--------------- +* 0 | SMI130_INTR1_INPUT_ENABLE +* 1 | SMI130_INTR2_INPUT_ENABLE +* +* @param v_input_en_u8 : +* The value of input enable of interrupt enable +* value | Behaviour +* ----------|------------------- +* 0x01 | SMI130_INPUT +* 0x00 | SMI130_OUTPUT +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_input_enable( +u8 v_channel_u8, u8 v_input_en_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write input enable of interrup1 and interrupt2*/ + case SMI130_INTR1_INPUT_ENABLE: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_INPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR1_INPUT_ENABLE, v_input_en_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR1_INPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_INPUT_ENABLE: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_INPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR2_INPUT_ENABLE, v_input_en_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR2_INPUT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} + /*! +* @brief reads the Low g interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 0 in the register 0x55 +* @brief interrupt2 bit 0 in the register 0x57 +* +* +* @param v_channel_u8: The value of low_g selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_LOW_G +* 1 | SMI130_INTR2_MAP_LOW_G +* +* @param v_intr_low_g_u8 : The value of low_g enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g( +u8 v_channel_u8, u8*v_intr_low_g_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the low_g interrupt*/ + case SMI130_INTR1_MAP_LOW_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_low_g_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_LOW_G); + break; + case SMI130_INTR2_MAP_LOW_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_low_g_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_LOW_G); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} + /*! +* @brief set the Low g interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 0 in the register 0x55 +* @brief interrupt2 bit 0 in the register 0x57 +* +* +* @param v_channel_u8: The value of low_g selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_LOW_G +* 1 | SMI130_INTR2_MAP_LOW_G +* +* @param v_intr_low_g_u8 : The value of low_g enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g( +u8 v_channel_u8, u8 v_intr_low_g_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +u8 v_step_cnt_stat_u8 = SMI130_INIT_VALUE; +u8 v_step_det_stat_u8 = SMI130_INIT_VALUE; + +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* check the step detector interrupt enable status*/ + com_rslt = smi130_get_step_detector_enable(&v_step_det_stat_u8); + /* disable the step detector interrupt*/ + if (v_step_det_stat_u8 != SMI130_INIT_VALUE) + com_rslt += smi130_set_step_detector_enable(SMI130_INIT_VALUE); + /* check the step counter interrupt enable status*/ + com_rslt += smi130_get_step_counter_enable(&v_step_cnt_stat_u8); + /* disable the step counter interrupt*/ + if (v_step_cnt_stat_u8 != SMI130_INIT_VALUE) + com_rslt += smi130_set_step_counter_enable( + SMI130_INIT_VALUE); + switch (v_channel_u8) { + /* write the low_g interrupt*/ + case SMI130_INTR1_MAP_LOW_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_LOW_G, v_intr_low_g_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_LOW_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_LOW_G, v_intr_low_g_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief Reads the HIGH g interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 1 in the register 0x55 +* @brief interrupt2 bit 1 in the register 0x57 +* +* +* @param v_channel_u8: The value of high_g selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_HIGH_G +* 1 | SMI130_INTR2_MAP_HIGH_G +* +* @param v_intr_high_g_u8 : The value of high_g enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g( +u8 v_channel_u8, u8*v_intr_high_g_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the high_g interrupt*/ + switch (v_channel_u8) { + case SMI130_INTR1_MAP_HIGH_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_HIGH_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_high_g_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_HIGH_G); + break; + case SMI130_INTR2_MAP_HIGH_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_HIGH_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_high_g_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_HIGH_G); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write the HIGH g interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 1 in the register 0x55 +* @brief interrupt2 bit 1 in the register 0x57 +* +* +* @param v_channel_u8: The value of high_g selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_HIGH_G +* 1 | SMI130_INTR2_MAP_HIGH_G +* +* @param v_intr_high_g_u8 : The value of high_g enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g( +u8 v_channel_u8, u8 v_intr_high_g_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the high_g interrupt*/ + case SMI130_INTR1_MAP_HIGH_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_HIGH_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_HIGH_G, v_intr_high_g_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_HIGH_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_HIGH_G: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_HIGH_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_HIGH_G, v_intr_high_g_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_HIGH_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief Reads the Any motion interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 2 in the register 0x55 +* @brief interrupt2 bit 2 in the register 0x57 +* +* +* @param v_channel_u8: The value of any motion selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_ANY_MOTION +* 1 | SMI130_INTR2_MAP_ANY_MOTION +* +* @param v_intr_any_motion_u8 : The value of any motion enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_any_motion( +u8 v_channel_u8, u8*v_intr_any_motion_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the any motion interrupt*/ + case SMI130_INTR1_MAP_ANY_MOTION: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_any_motion_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION); + break; + case SMI130_INTR2_MAP_ANY_MOTION: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_any_motion_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write the Any motion interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 2 in the register 0x55 +* @brief interrupt2 bit 2 in the register 0x57 +* +* +* @param v_channel_u8: The value of any motion selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_ANY_MOTION +* 1 | SMI130_INTR2_MAP_ANY_MOTION +* +* @param v_intr_any_motion_u8 : The value of any motion enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_any_motion( +u8 v_channel_u8, u8 v_intr_any_motion_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +u8 sig_mot_stat = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the status of significant motion interrupt*/ + com_rslt = smi130_get_intr_significant_motion_select(&sig_mot_stat); + /* disable the significant motion interrupt*/ + if (sig_mot_stat != SMI130_INIT_VALUE) + com_rslt += smi130_set_intr_significant_motion_select( + SMI130_INIT_VALUE); + switch (v_channel_u8) { + /* write the any motion interrupt*/ + case SMI130_INTR1_MAP_ANY_MOTION: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION, + v_intr_any_motion_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_ANY_MOTION: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION, + v_intr_any_motion_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief Reads the No motion interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 3 in the register 0x55 +* @brief interrupt2 bit 3 in the register 0x57 +* +* +* @param v_channel_u8: The value of no motion selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_NOMO +* 1 | SMI130_INTR2_MAP_NOMO +* +* @param v_intr_nomotion_u8 : The value of no motion enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_nomotion( +u8 v_channel_u8, u8*v_intr_nomotion_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the no motion interrupt*/ + case SMI130_INTR1_MAP_NOMO: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_NOMOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_nomotion_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_NOMOTION); + break; + case SMI130_INTR2_MAP_NOMO: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_NOMOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_nomotion_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_NOMOTION); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write the No motion interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 3 in the register 0x55 +* @brief interrupt2 bit 3 in the register 0x57 +* +* +* @param v_channel_u8: The value of no motion selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_NOMO +* 1 | SMI130_INTR2_MAP_NOMO +* +* @param v_intr_nomotion_u8 : The value of no motion enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_nomotion( +u8 v_channel_u8, u8 v_intr_nomotion_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the no motion interrupt*/ + case SMI130_INTR1_MAP_NOMO: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_NOMOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_NOMOTION, + v_intr_nomotion_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_NOMOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_NOMO: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_NOMOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_NOMOTION, + v_intr_nomotion_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_NOMOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief Reads the Double Tap interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 4 in the register 0x55 +* @brief interrupt2 bit 4 in the register 0x57 +* +* +* @param v_channel_u8: The value of double tap interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_DOUBLE_TAP +* 1 | SMI130_INTR2_MAP_DOUBLE_TAP +* +* @param v_intr_double_tap_u8 : The value of double tap enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_double_tap( +u8 v_channel_u8, u8*v_intr_double_tap_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + case SMI130_INTR1_MAP_DOUBLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_double_tap_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP); + break; + case SMI130_INTR2_MAP_DOUBLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_double_tap_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write the Double Tap interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 4 in the register 0x55 +* @brief interrupt2 bit 4 in the register 0x57 +* +* +* @param v_channel_u8: The value of double tap interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_DOUBLE_TAP +* 1 | SMI130_INTR2_MAP_DOUBLE_TAP +* +* @param v_intr_double_tap_u8 : The value of double tap enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_double_tap( +u8 v_channel_u8, u8 v_intr_double_tap_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* set the double tap interrupt*/ + case SMI130_INTR1_MAP_DOUBLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP, + v_intr_double_tap_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_DOUBLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP, + v_intr_double_tap_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief Reads the Single Tap interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 5 in the register 0x55 +* @brief interrupt2 bit 5 in the register 0x57 +* +* +* @param v_channel_u8: The value of single tap interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_SINGLE_TAP +* 1 | SMI130_INTR2_MAP_SINGLE_TAP +* +* @param v_intr_single_tap_u8 : The value of single tap enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_single_tap( +u8 v_channel_u8, u8*v_intr_single_tap_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* reads the single tap interrupt*/ + case SMI130_INTR1_MAP_SINGLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_single_tap_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP); + break; + case SMI130_INTR2_MAP_SINGLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_single_tap_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write the Single Tap interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 5 in the register 0x55 +* @brief interrupt2 bit 5 in the register 0x57 +* +* +* @param v_channel_u8: The value of single tap interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_SINGLE_TAP +* 1 | SMI130_INTR2_MAP_SINGLE_TAP +* +* @param v_intr_single_tap_u8 : The value of single tap enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_single_tap( +u8 v_channel_u8, u8 v_intr_single_tap_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the single tap interrupt*/ + case SMI130_INTR1_MAP_SINGLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP, + v_intr_single_tap_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_SINGLE_TAP: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP, + v_intr_single_tap_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief Reads the Orient interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 6 in the register 0x55 +* @brief interrupt2 bit 6 in the register 0x57 +* +* +* @param v_channel_u8: The value of orient interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_ORIENT +* 1 | SMI130_INTR2_MAP_ORIENT +* +* @param v_intr_orient_u8 : The value of orient enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient( +u8 v_channel_u8, u8*v_intr_orient_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the orientation interrupt*/ + case SMI130_INTR1_MAP_ORIENT: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_ORIENT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_orient_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_ORIENT); + break; + case SMI130_INTR2_MAP_ORIENT: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_ORIENT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_orient_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_ORIENT); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write the Orient interrupt +* interrupt mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 6 in the register 0x55 +* @brief interrupt2 bit 6 in the register 0x57 +* +* +* @param v_channel_u8: The value of orient interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_ORIENT +* 1 | SMI130_INTR2_MAP_ORIENT +* +* @param v_intr_orient_u8 : The value of orient enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient( +u8 v_channel_u8, u8 v_intr_orient_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the orientation interrupt*/ + case SMI130_INTR1_MAP_ORIENT: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_ORIENT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_ORIENT, v_intr_orient_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_ORIENT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_ORIENT: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_ORIENT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_ORIENT, v_intr_orient_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_ORIENT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} + /*! +* @brief Reads the Flat interrupt +* mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 7 in the register 0x55 +* @brief interrupt2 bit 7 in the register 0x57 +* +* +* @param v_channel_u8: The value of flat interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_FLAT +* 1 | SMI130_INTR2_MAP_FLAT +* +* @param v_intr_flat_u8 : The value of flat enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat( +u8 v_channel_u8, u8*v_intr_flat_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the flat interrupt*/ + case SMI130_INTR1_MAP_FLAT: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_FLAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_flat_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_FLAT); + break; + case SMI130_INTR2_MAP_FLAT: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_FLAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_flat_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_FLAT); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} + /*! +* @brief Write the Flat interrupt +* mapped to interrupt1 +* and interrupt2 from the register 0x55 and 0x57 +* @brief interrupt1 bit 7 in the register 0x55 +* @brief interrupt2 bit 7 in the register 0x57 +* +* +* @param v_channel_u8: The value of flat interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_FLAT +* 1 | SMI130_INTR2_MAP_FLAT +* +* @param v_intr_flat_u8 : The value of flat enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat( +u8 v_channel_u8, u8 v_intr_flat_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the flat interrupt*/ + case SMI130_INTR1_MAP_FLAT: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_0_INTR1_FLAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_0_INTR1_FLAT, + v_intr_flat_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_MAP_0_INTR1_FLAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_FLAT: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_2_INTR2_FLAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_2_INTR2_FLAT, + v_intr_flat_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_MAP_2_INTR2_FLAT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Reads PMU trigger interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 bit 0 and 4 +* @brief interrupt1 bit 0 in the register 0x56 +* @brief interrupt2 bit 4 in the register 0x56 +* +* +* @param v_channel_u8: The value of pmu trigger selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_PMUTRIG +* 1 | SMI130_INTR2_MAP_PMUTRIG +* +* @param v_intr_pmu_trig_u8 : The value of pmu trigger enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_pmu_trig( +u8 v_channel_u8, u8*v_intr_pmu_trig_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the pmu trigger interrupt*/ + case SMI130_INTR1_MAP_PMUTRIG: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_pmu_trig_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG); + break; + case SMI130_INTR2_MAP_PMUTRIG: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_pmu_trig_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write PMU trigger interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 bit 0 and 4 +* @brief interrupt1 bit 0 in the register 0x56 +* @brief interrupt2 bit 4 in the register 0x56 +* +* +* @param v_channel_u8: The value of pmu trigger selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_PMUTRIG +* 1 | SMI130_INTR2_MAP_PMUTRIG +* +* @param v_intr_pmu_trig_u8 : The value of pmu trigger enable +* value | trigger enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_pmu_trig( +u8 v_channel_u8, u8 v_intr_pmu_trig_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the pmu trigger interrupt*/ + case SMI130_INTR1_MAP_PMUTRIG: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG, + v_intr_pmu_trig_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_PMUTRIG: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG, + v_intr_pmu_trig_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} +/*! +* @brief Reads FIFO Full interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 bit 5 and 1 +* @brief interrupt1 bit 5 in the register 0x56 +* @brief interrupt2 bit 1 in the register 0x56 +* +* +* @param v_channel_u8: The value of fifo full interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_FIFO_FULL +* 1 | SMI130_INTR2_MAP_FIFO_FULL +* +* @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_fifo_full( +u8 v_channel_u8, u8*v_intr_fifo_full_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the fifo full interrupt*/ + case SMI130_INTR1_MAP_FIFO_FULL: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_full_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL); + break; + case SMI130_INTR2_MAP_FIFO_FULL: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_full_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write FIFO Full interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 bit 5 and 1 +* @brief interrupt1 bit 5 in the register 0x56 +* @brief interrupt2 bit 1 in the register 0x56 +* +* +* @param v_channel_u8: The value of fifo full interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_FIFO_FULL +* 1 | SMI130_INTR2_MAP_FIFO_FULL +* +* @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_fifo_full( +u8 v_channel_u8, u8 v_intr_fifo_full_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the fifo full interrupt*/ + case SMI130_INTR1_MAP_FIFO_FULL: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL, + v_intr_fifo_full_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_FIFO_FULL: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL, + v_intr_fifo_full_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Reads FIFO Watermark interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 bit 6 and 2 +* @brief interrupt1 bit 6 in the register 0x56 +* @brief interrupt2 bit 2 in the register 0x56 +* +* +* @param v_channel_u8: The value of fifo Watermark interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_FIFO_WM +* 1 | SMI130_INTR2_MAP_FIFO_WM +* +* @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_fifo_wm( +u8 v_channel_u8, u8*v_intr_fifo_wm_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the fifo water mark interrupt*/ + case SMI130_INTR1_MAP_FIFO_WM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_wm_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM); + break; + case SMI130_INTR2_MAP_FIFO_WM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_wm_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write FIFO Watermark interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 bit 6 and 2 +* @brief interrupt1 bit 6 in the register 0x56 +* @brief interrupt2 bit 2 in the register 0x56 +* +* +* @param v_channel_u8: The value of fifo Watermark interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_FIFO_WM +* 1 | SMI130_INTR2_MAP_FIFO_WM +* +* @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_fifo_wm( +u8 v_channel_u8, u8 v_intr_fifo_wm_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the fifo water mark interrupt*/ + case SMI130_INTR1_MAP_FIFO_WM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM, + v_intr_fifo_wm_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_FIFO_WM: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM, + v_intr_fifo_wm_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, + SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Reads Data Ready interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 +* @brief interrupt1 bit 7 in the register 0x56 +* @brief interrupt2 bit 3 in the register 0x56 +* +* +* @param v_channel_u8: The value of data ready interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_DATA_RDY +* 1 | SMI130_INTR2_MAP_DATA_RDY +* +* @param v_intr_data_rdy_u8 : The value of data ready interrupt enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_data_rdy( +u8 v_channel_u8, u8*v_intr_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /*Read Data Ready interrupt*/ + case SMI130_INTR1_MAP_DATA_RDY: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_data_rdy_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY); + break; + case SMI130_INTR2_MAP_DATA_RDY: + com_rslt = p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_data_rdy_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + } + return com_rslt; +} +/*! +* @brief Write Data Ready interrupt mapped to interrupt1 +* and interrupt2 form the register 0x56 +* @brief interrupt1 bit 7 in the register 0x56 +* @brief interrupt2 bit 3 in the register 0x56 +* +* +* @param v_channel_u8: The value of data ready interrupt selection +* v_channel_u8 | interrupt +* ---------------|--------------- +* 0 | SMI130_INTR1_MAP_DATA_RDY +* 1 | SMI130_INTR2_MAP_DATA_RDY +* +* @param v_intr_data_rdy_u8 : The value of data ready interrupt enable +* value | interrupt enable +* ----------|------------------- +* 0x01 | SMI130_ENABLE +* 0x00 | SMI130_DISABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_data_rdy( +u8 v_channel_u8, u8 v_intr_data_rdy_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + switch (v_channel_u8) { + /*Write Data Ready interrupt*/ + case SMI130_INTR1_MAP_DATA_RDY: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY, + v_intr_data_rdy_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case SMI130_INTR2_MAP_DATA_RDY: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY, + v_intr_data_rdy_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC(p_smi130-> + dev_addr, SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } +} +return com_rslt; +} + /*! +* @brief This API reads data source for the interrupt +* engine for the single and double tap interrupts from the register +* 0x58 bit 3 +* +* +* @param v_tap_source_u8 : The value of the tap source +* value | Description +* ----------|------------------- +* 0x01 | UNFILTER_DATA +* 0x00 | FILTER_DATA +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_source(u8*v_tap_source_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the tap source interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_source_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE); + } + return com_rslt; +} + /*! +* @brief This API write data source for the interrupt +* engine for the single and double tap interrupts from the register +* 0x58 bit 3 +* +* +* @param v_tap_source_u8 : The value of the tap source +* value | Description +* ----------|------------------- +* 0x01 | UNFILTER_DATA +* 0x00 | FILTER_DATA +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_source( +u8 v_tap_source_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_tap_source_u8 <= SMI130_MAX_VALUE_SOURCE_INTR) { + /* write the tap source interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE, + v_tap_source_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API Reads Data source for the +* interrupt engine for the low and high g interrupts +* from the register 0x58 bit 7 +* +* @param v_low_high_source_u8 : The value of the tap source +* value | Description +* ----------|------------------- +* 0x01 | UNFILTER_DATA +* 0x00 | FILTER_DATA +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_high_source( +u8*v_low_high_source_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the high_low_g source interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_low_high_source_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE); + } + return com_rslt; +} +/*! +* @brief This API write Data source for the +* interrupt engine for the low and high g interrupts +* from the register 0x58 bit 7 +* +* @param v_low_high_source_u8 : The value of the tap source +* value | Description +* ----------|------------------- +* 0x01 | UNFILTER_DATA +* 0x00 | FILTER_DATA +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_high_source( +u8 v_low_high_source_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_low_high_source_u8 <= SMI130_MAX_VALUE_SOURCE_INTR) { + /* write the high_low_g source interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE, + v_low_high_source_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} +return com_rslt; +} + /*! +* @brief This API reads Data source for the +* interrupt engine for the nomotion and anymotion interrupts +* from the register 0x59 bit 7 +* +* @param v_motion_source_u8 : +* The value of the any/no motion interrupt source +* value | Description +* ----------|------------------- +* 0x01 | UNFILTER_DATA +* 0x00 | FILTER_DATA +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_motion_source( +u8*v_motion_source_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the any/no motion interrupt */ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_motion_source_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE); + } + return com_rslt; +} + /*! +* @brief This API write Data source for the +* interrupt engine for the nomotion and anymotion interrupts +* from the register 0x59 bit 7 +* +* @param v_motion_source_u8 : +* The value of the any/no motion interrupt source +* value | Description +* ----------|------------------- +* 0x01 | UNFILTER_DATA +* 0x00 | FILTER_DATA +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_motion_source( +u8 v_motion_source_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_motion_source_u8 <= SMI130_MAX_VALUE_SOURCE_INTR) { + /* write the any/no motion interrupt */ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE, + v_motion_source_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API is used to read the low_g duration from register +* 0x5A bit 0 to 7 +* +* +* +* +* @param v_low_g_durn_u8 : The value of low_g duration +* +* @note Low_g duration trigger trigger delay according to +* "(v_low_g_durn_u8* 2.5)ms" in a range from 2.5ms to 640ms. +* the default corresponds delay is 20ms +* @note When low_g data source of interrupt is unfiltered +* the sensor must not be in low power mode +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_durn( +u8*v_low_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the low_g interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_durn_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_0_INTR_LOW_DURN); + } + return com_rslt; +} + /*! +* @brief This API is used to write the low_g duration from register +* 0x5A bit 0 to 7 +* +* +* +* +* @param v_low_g_durn_u8 : The value of low_g duration +* +* @note Low_g duration trigger trigger delay according to +* "(v_low_g_durn_u8* 2.5)ms" in a range from 2.5ms to 640ms. +* the default corresponds delay is 20ms +* @note When low_g data source of interrupt is unfiltered +* the sensor must not be in low power mode +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_durn(u8 v_low_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the low_g interrupt*/ + com_rslt = p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG, + &v_low_g_durn_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! +* @brief This API is used to read Threshold +* definition for the low-g interrupt from the register 0x5B bit 0 to 7 +* +* +* +* +* @param v_low_g_thres_u8 : The value of low_g threshold +* +* @note Low_g interrupt trigger threshold according to +* (v_low_g_thres_u8* 7.81)mg for v_low_g_thres_u8 > 0 +* 3.91 mg for v_low_g_thres_u8 = 0 +* The threshold range is form 3.91mg to 2.000mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_thres( +u8*v_low_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read low_g threshold*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_thres_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_1_INTR_LOW_THRES); + } + return com_rslt; +} +/*! +* @brief This API is used to write Threshold +* definition for the low-g interrupt from the register 0x5B bit 0 to 7 +* +* +* +* +* @param v_low_g_thres_u8 : The value of low_g threshold +* +* @note Low_g interrupt trigger threshold according to +* (v_low_g_thres_u8* 7.81)mg for v_low_g_thres_u8 > 0 +* 3.91 mg for v_low_g_thres_u8 = 0 +* The threshold range is form 3.91mg to 2.000mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_thres( +u8 v_low_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write low_g threshold*/ + com_rslt = p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG, + &v_low_g_thres_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} + /*! +* @brief This API Reads Low-g interrupt hysteresis +* from the register 0x5C bit 0 to 1 +* +* @param v_low_hyst_u8 :The value of low_g hysteresis +* +* @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_hyst( +u8*v_low_hyst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read low_g hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_low_hyst_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST); + } + return com_rslt; +} + /*! +* @brief This API write Low-g interrupt hysteresis +* from the register 0x5C bit 0 to 1 +* +* @param v_low_hyst_u8 :The value of low_g hysteresis +* +* @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_hyst( +u8 v_low_hyst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write low_g hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST, + v_low_hyst_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API reads Low-g interrupt mode +* from the register 0x5C bit 2 +* +* @param v_low_g_mode_u8 : The value of low_g mode +* Value | Description +* ----------|----------------- +* 0 | single-axis +* 1 | axis-summing +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_mode(u8*v_low_g_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /*read Low-g interrupt mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_mode_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE); + } + return com_rslt; +} +/*! +* @brief This API write Low-g interrupt mode +* from the register 0x5C bit 2 +* +* @param v_low_g_mode_u8 : The value of low_g mode +* Value | Description +* ----------|----------------- +* 0 | single-axis +* 1 | axis-summing +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_mode( +u8 v_low_g_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_low_g_mode_u8 <= SMI130_MAX_VALUE_LOW_G_MODE) { + /*write Low-g interrupt mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE, + v_low_g_mode_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API reads High-g interrupt hysteresis +* from the register 0x5C bit 6 and 7 +* +* @param v_high_g_hyst_u8 : The value of high hysteresis +* +* @note High_g hysteresis changes according to accel g range +* accel g range can be set by the function "" +* accel_range | high_g hysteresis +* ----------------|--------------------- +* 2g | high_hy*125 mg +* 4g | high_hy*250 mg +* 8g | high_hy*500 mg +* 16g | high_hy*1000 mg +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g_hyst( +u8*v_high_g_hyst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read high_g hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_hyst_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST); + } + return com_rslt; +} +/*! +* @brief This API write High-g interrupt hysteresis +* from the register 0x5C bit 6 and 7 +* +* @param v_high_g_hyst_u8 : The value of high hysteresis +* +* @note High_g hysteresis changes according to accel g range +* accel g range can be set by the function "" +* accel_range | high_g hysteresis +* ----------------|--------------------- +* 2g | high_hy*125 mg +* 4g | high_hy*250 mg +* 8g | high_hy*500 mg +* 16g | high_hy*1000 mg +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g_hyst( +u8 v_high_g_hyst_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write high_g hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST, + v_high_g_hyst_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } +return com_rslt; +} +/*! +* @brief This API is used to read Delay +* time definition for the high-g interrupt from the register +* 0x5D bit 0 to 7 +* +* +* +* @param v_high_g_durn_u8 : The value of high duration +* +* @note High_g interrupt delay triggered according to +* v_high_g_durn_u8* 2.5ms in a range from 2.5ms to 640ms +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g_durn( +u8*v_high_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read high_g duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_durn_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN); + } + return com_rslt; +} +/*! +* @brief This API is used to write Delay +* time definition for the high-g interrupt from the register +* 0x5D bit 0 to 7 +* +* +* +* @param v_high_g_durn_u8 : The value of high duration +* +* @note High_g interrupt delay triggered according to +* v_high_g_durn_u8* 2.5ms in a range from 2.5ms to 640ms +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g_durn( +u8 v_high_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write high_g duration*/ + com_rslt = p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG, + &v_high_g_durn_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! +* @brief This API is used to read Threshold +* definition for the high-g interrupt from the register 0x5E 0 to 7 +* +* +* +* +* @param v_high_g_thres_u8 : Pointer holding the value of Threshold +* @note High_g threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | high_g threshold +* ----------------|--------------------- +* 2g | v_high_g_thres_u8*7.81 mg +* 4g | v_high_g_thres_u8*15.63 mg +* 8g | v_high_g_thres_u8*31.25 mg +* 16g | v_high_g_thres_u8*62.5 mg +* @note when v_high_g_thres_u8 = 0 +* accel_range | high_g threshold +* ----------------|--------------------- +* 2g | 3.91 mg +* 4g | 7.81 mg +* 8g | 15.63 mg +* 16g | 31.25 mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g_thres( +u8*v_high_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_thres_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES); + } + return com_rslt; +} +/*! +* @brief This API is used to write Threshold +* definition for the high-g interrupt from the register 0x5E 0 to 7 +* +* +* +* +* @param v_high_g_thres_u8 : Pointer holding the value of Threshold +* @note High_g threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | high_g threshold +* ----------------|--------------------- +* 2g | v_high_g_thres_u8*7.81 mg +* 4g | v_high_g_thres_u8*15.63 mg +* 8g | v_high_g_thres_u8*31.25 mg +* 16g | v_high_g_thres_u8*62.5 mg +* @note when v_high_g_thres_u8 = 0 +* accel_range | high_g threshold +* ----------------|--------------------- +* 2g | 3.91 mg +* 4g | 7.81 mg +* 8g | 15.63 mg +* 16g | 31.25 mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g_thres( +u8 v_high_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + com_rslt = p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG, + &v_high_g_thres_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} +/*! +* @brief This API reads any motion duration +* from the register 0x5F bit 0 and 1 +* +* @param v_any_motion_durn_u8 : The value of any motion duration +* +* @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1" +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_any_motion_durn( +u8*v_any_motion_durn_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read any motion duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_durn_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN); + } + return com_rslt; +} +/*! +* @brief This API write any motion duration +* from the register 0x5F bit 0 and 1 +* +* @param v_any_motion_durn_u8 : The value of any motion duration +* +* @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1" +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_any_motion_durn( +u8 v_any_motion_durn_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write any motion duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN, + v_any_motion_durn_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} + /*! +* @brief This API read Slow/no-motion +* interrupt trigger delay duration from the register 0x5F bit 2 to 7 +* +* @param v_slow_no_motion_u8 :The value of slow no motion duration +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* @note +* @note v_slow_no_motion_u8(5:4)=0b00 -> +* [v_slow_no_motion_u8(3:0) + 1]* 1.28s (1.28s-20.48s) +* @note v_slow_no_motion_u8(5:4)=1 -> +* [v_slow_no_motion_u8(3:0)+5]* 5.12s (25.6s-102.4s) +* @note v_slow_no_motion_u8(5)='1' -> +* [(v_slow_no_motion_u8:0)+11]* 10.24s (112.64s-430.08s); +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_slow_no_motion_durn( +u8*v_slow_no_motion_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read slow no motion duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_slow_no_motion_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN); + } +return com_rslt; +} + /*! +* @brief This API write Slow/no-motion +* interrupt trigger delay duration from the register 0x5F bit 2 to 7 +* +* @param v_slow_no_motion_u8 :The value of slow no motion duration +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* @note +* @note v_slow_no_motion_u8(5:4)=0b00 -> +* [v_slow_no_motion_u8(3:0) + 1]* 1.28s (1.28s-20.48s) +* @note v_slow_no_motion_u8(5:4)=1 -> +* [v_slow_no_motion_u8(3:0)+5]* 5.12s (25.6s-102.4s) +* @note v_slow_no_motion_u8(5)='1' -> +* [(v_slow_no_motion_u8:0)+11]* 10.24s (112.64s-430.08s); +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_slow_no_motion_durn( +u8 v_slow_no_motion_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write slow no motion duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN, + v_slow_no_motion_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } +} +return com_rslt; +} +/*! +* @brief This API is used to read threshold +* definition for the any-motion interrupt +* from the register 0x60 bit 0 to 7 +* +* +* @param v_any_motion_thres_u8 : The value of any motion threshold +* +* @note any motion threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | any motion threshold +* ----------------|--------------------- +* 2g | v_any_motion_thres_u8*3.91 mg +* 4g | v_any_motion_thres_u8*7.81 mg +* 8g | v_any_motion_thres_u8*15.63 mg +* 16g | v_any_motion_thres_u8*31.25 mg +* @note when v_any_motion_thres_u8 = 0 +* accel_range | any motion threshold +* ----------------|--------------------- +* 2g | 1.95 mg +* 4g | 3.91 mg +* 8g | 7.81 mg +* 16g | 15.63 mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_any_motion_thres( +u8*v_any_motion_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read any motion threshold*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_thres_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES); + } + return com_rslt; +} +/*! +* @brief This API is used to write threshold +* definition for the any-motion interrupt +* from the register 0x60 bit 0 to 7 +* +* +* @param v_any_motion_thres_u8 : The value of any motion threshold +* +* @note any motion threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | any motion threshold +* ----------------|--------------------- +* 2g | v_any_motion_thres_u8*3.91 mg +* 4g | v_any_motion_thres_u8*7.81 mg +* 8g | v_any_motion_thres_u8*15.63 mg +* 16g | v_any_motion_thres_u8*31.25 mg +* @note when v_any_motion_thres_u8 = 0 +* accel_range | any motion threshold +* ----------------|--------------------- +* 2g | 1.95 mg +* 4g | 3.91 mg +* 8g | 7.81 mg +* 16g | 15.63 mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_any_motion_thres( +u8 v_any_motion_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write any motion threshold*/ + com_rslt = p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG, + &v_any_motion_thres_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} + /*! +* @brief This API is used to read threshold +* for the slow/no-motion interrupt +* from the register 0x61 bit 0 to 7 +* +* +* +* +* @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold +* @note slow no motion threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | slow no motion threshold +* ----------------|--------------------- +* 2g | v_slow_no_motion_thres_u8*3.91 mg +* 4g | v_slow_no_motion_thres_u8*7.81 mg +* 8g | v_slow_no_motion_thres_u8*15.63 mg +* 16g | v_slow_no_motion_thres_u8*31.25 mg +* @note when v_slow_no_motion_thres_u8 = 0 +* accel_range | slow no motion threshold +* ----------------|--------------------- +* 2g | 1.95 mg +* 4g | 3.91 mg +* 8g | 7.81 mg +* 16g | 15.63 mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_slow_no_motion_thres( +u8*v_slow_no_motion_thres_u8) +{ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read slow no motion threshold*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_slow_no_motion_thres_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES); + } +return com_rslt; +} + /*! +* @brief This API is used to write threshold +* for the slow/no-motion interrupt +* from the register 0x61 bit 0 to 7 +* +* +* +* +* @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold +* @note slow no motion threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | slow no motion threshold +* ----------------|--------------------- +* 2g | v_slow_no_motion_thres_u8*3.91 mg +* 4g | v_slow_no_motion_thres_u8*7.81 mg +* 8g | v_slow_no_motion_thres_u8*15.63 mg +* 16g | v_slow_no_motion_thres_u8*31.25 mg +* @note when v_slow_no_motion_thres_u8 = 0 +* accel_range | slow no motion threshold +* ----------------|--------------------- +* 2g | 1.95 mg +* 4g | 3.91 mg +* 8g | 7.81 mg +* 16g | 15.63 mg +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_slow_no_motion_thres( +u8 v_slow_no_motion_thres_u8) +{ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write slow no motion threshold*/ + com_rslt = p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG, + &v_slow_no_motion_thres_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } +return com_rslt; +} + /*! +* @brief This API is used to read +* the slow/no-motion selection from the register 0x62 bit 0 +* +* +* +* +* @param v_intr_slow_no_motion_select_u8 : +* The value of slow/no-motion select +* value | Behaviour +* ----------|------------------- +* 0x00 | SLOW_MOTION +* 0x01 | NO_MOTION +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_slow_no_motion_select( +u8*v_intr_slow_no_motion_select_u8) +{ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read slow no motion select*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_slow_no_motion_select_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT); + } +return com_rslt; +} + /*! +* @brief This API is used to write +* the slow/no-motion selection from the register 0x62 bit 0 +* +* +* +* +* @param v_intr_slow_no_motion_select_u8 : +* The value of slow/no-motion select +* value | Behaviour +* ----------|------------------- +* 0x00 | SLOW_MOTION +* 0x01 | NO_MOTION +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_slow_no_motion_select( +u8 v_intr_slow_no_motion_select_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; +} else { +if (v_intr_slow_no_motion_select_u8 <= SMI130_MAX_VALUE_NO_MOTION) { + /* write slow no motion select*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT, + v_intr_slow_no_motion_select_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } +} else { +com_rslt = E_SMI130_OUT_OF_RANGE; +} +} +return com_rslt; +} + /*! +* @brief This API is used to select +* the significant or any motion interrupt from the register 0x62 bit 1 +* +* +* +* +* @param v_intr_significant_motion_select_u8 : +* the value of significant or any motion interrupt selection +* value | Behaviour +* ----------|------------------- +* 0x00 | ANY_MOTION +* 0x01 | SIGNIFICANT_MOTION +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_significant_motion_select( +u8*v_intr_significant_motion_select_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the significant or any motion interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_significant_motion_select_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT); + } + return com_rslt; +} + /*! +* @brief This API is used to write, select +* the significant or any motion interrupt from the register 0x62 bit 1 +* +* +* +* +* @param v_intr_significant_motion_select_u8 : +* the value of significant or any motion interrupt selection +* value | Behaviour +* ----------|------------------- +* 0x00 | ANY_MOTION +* 0x01 | SIGNIFICANT_MOTION +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_significant_motion_select( +u8 v_intr_significant_motion_select_u8) +{ +/* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_intr_significant_motion_select_u8 <= + SMI130_MAX_VALUE_SIGNIFICANT_MOTION) { + /* write the significant or any motion interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT, + v_intr_significant_motion_select_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} +return com_rslt; +} + /*! +* @brief This API is used to read +* the significant skip time from the register 0x62 bit 2 and 3 +* +* +* +* +* @param v_int_sig_mot_skip_u8 : the value of significant skip time +* value | Behaviour +* ----------|------------------- +* 0x00 | skip time 1.5 seconds +* 0x01 | skip time 3 seconds +* 0x02 | skip time 6 seconds +* 0x03 | skip time 12 seconds +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_significant_motion_skip( +u8*v_int_sig_mot_skip_u8) +{ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read significant skip time*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_int_sig_mot_skip_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP); + } + return com_rslt; +} + /*! +* @brief This API is used to write +* the significant skip time from the register 0x62 bit 2 and 3 +* +* +* +* +* @param v_int_sig_mot_skip_u8 : the value of significant skip time +* value | Behaviour +* ----------|------------------- +* 0x00 | skip time 1.5 seconds +* 0x01 | skip time 3 seconds +* 0x02 | skip time 6 seconds +* 0x03 | skip time 12 seconds +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_significant_motion_skip( +u8 v_int_sig_mot_skip_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_int_sig_mot_skip_u8 <= SMI130_MAX_UNDER_SIG_MOTION) { + /* write significant skip time*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP, + v_int_sig_mot_skip_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API is used to read +* the significant proof time from the register 0x62 bit 4 and 5 +* +* +* +* +* @param v_significant_motion_proof_u8 : +* the value of significant proof time +* value | Behaviour +* ----------|------------------- +* 0x00 | proof time 0.25 seconds +* 0x01 | proof time 0.5 seconds +* 0x02 | proof time 1 seconds +* 0x03 | proof time 2 seconds +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_significant_motion_proof( +u8*v_significant_motion_proof_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read significant proof time*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_significant_motion_proof_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF); + } + return com_rslt; +} + /*! +* @brief This API is used to write +* the significant proof time from the register 0x62 bit 4 and 5 +* +* +* +* +* @param v_significant_motion_proof_u8 : +* the value of significant proof time +* value | Behaviour +* ----------|------------------- +* 0x00 | proof time 0.25 seconds +* 0x01 | proof time 0.5 seconds +* 0x02 | proof time 1 seconds +* 0x03 | proof time 2 seconds +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_significant_motion_proof( +u8 v_significant_motion_proof_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_significant_motion_proof_u8 + <= SMI130_MAX_UNDER_SIG_MOTION) { + /* write significant proof time*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF, + v_significant_motion_proof_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API is used to get the tap duration +* from the register 0x63 bit 0 to 2 +* +* +* +* @param v_tap_durn_u8 : The value of tap duration +* value | Behaviour +* ----------|------------------- +* 0x00 | SMI130_TAP_DURN_50MS +* 0x01 | SMI130_TAP_DURN_100MS +* 0x03 | SMI130_TAP_DURN_150MS +* 0x04 | SMI130_TAP_DURN_200MS +* 0x05 | SMI130_TAP_DURN_250MS +* 0x06 | SMI130_TAP_DURN_375MS +* 0x07 | SMI130_TAP_DURN_700MS +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_durn( +u8*v_tap_durn_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_durn_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_INTR_TAP_0_INTR_TAP_DURN); + } + return com_rslt; +} +/*! +* @brief This API is used to write the tap duration +* from the register 0x63 bit 0 to 2 +* +* +* +* @param v_tap_durn_u8 : The value of tap duration +* value | Behaviour +* ----------|------------------- +* 0x00 | SMI130_TAP_DURN_50MS +* 0x01 | SMI130_TAP_DURN_100MS +* 0x03 | SMI130_TAP_DURN_150MS +* 0x04 | SMI130_TAP_DURN_200MS +* 0x05 | SMI130_TAP_DURN_250MS +* 0x06 | SMI130_TAP_DURN_375MS +* 0x07 | SMI130_TAP_DURN_700MS +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_durn( +u8 v_tap_durn_u8) +{ + u8 v_data_u8 = SMI130_INIT_VALUE; + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_tap_durn_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_tap_durn_u8 <= SMI130_MAX_TAP_TURN) { + switch (v_tap_durn_u8) { + case SMI130_TAP_DURN_50MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_50MS; + break; + case SMI130_TAP_DURN_100MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_100MS; + break; + case SMI130_TAP_DURN_150MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_150MS; + break; + case SMI130_TAP_DURN_200MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_200MS; + break; + case SMI130_TAP_DURN_250MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_250MS; + break; + case SMI130_TAP_DURN_375MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_375MS; + break; + case SMI130_TAP_DURN_500MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_500MS; + break; + case SMI130_TAP_DURN_700MS: + v_data_tap_durn_u8 = SMI130_TAP_DURN_700MS; + break; + default: + break; + } + /* write tap duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_TAP_0_INTR_TAP_DURN, + v_data_tap_durn_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_DURN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API read the +* tap shock duration from the register 0x63 bit 2 +* +* @param v_tap_shock_u8 :The value of tap shock +* value | Behaviour +* ----------|------------------- +* 0x00 | SMI130_TAP_SHOCK_50MS +* 0x01 | SMI130_TAP_SHOCK_75MS +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_shock( +u8*v_tap_shock_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap shock duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_shock_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK); + } + return com_rslt; +} + /*! +* @brief This API write the +* tap shock duration from the register 0x63 bit 2 +* +* @param v_tap_shock_u8 :The value of tap shock +* value | Behaviour +* ----------|------------------- +* 0x00 | SMI130_TAP_SHOCK_50MS +* 0x01 | SMI130_TAP_SHOCK_75MS +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_shock(u8 v_tap_shock_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_tap_shock_u8 <= SMI130_MAX_VALUE_TAP_SHOCK) { + /* write tap shock duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK, + v_tap_shock_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read +* tap quiet duration from the register 0x63 bit 7 +* +* +* @param v_tap_quiet_u8 : The value of tap quiet +* value | Behaviour +* ----------|------------------- +* 0x00 | SMI130_TAP_QUIET_30MS +* 0x01 | SMI130_TAP_QUIET_20MS +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_quiet( +u8*v_tap_quiet_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap quiet duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_quiet_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET); + } + return com_rslt; +} +/*! +* @brief This API write +* tap quiet duration from the register 0x63 bit 7 +* +* +* @param v_tap_quiet_u8 : The value of tap quiet +* value | Behaviour +* ----------|------------------- +* 0x00 | SMI130_TAP_QUIET_30MS +* 0x01 | SMI130_TAP_QUIET_20MS +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_quiet(u8 v_tap_quiet_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_tap_quiet_u8 <= SMI130_MAX_VALUE_TAP_QUIET) { + /* write tap quiet duration*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET, + v_tap_quiet_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API read Threshold of the +* single/double tap interrupt from the register 0x64 bit 0 to 4 +* +* +* @param v_tap_thres_u8 : The value of single/double tap threshold +* +* @note single/double tap threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | single/double tap threshold +* ----------------|--------------------- +* 2g | ((v_tap_thres_u8 + 1)* 62.5)mg +* 4g | ((v_tap_thres_u8 + 1)* 125)mg +* 8g | ((v_tap_thres_u8 + 1)* 250)mg +* 16g | ((v_tap_thres_u8 + 1)* 500)mg +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_thres( +u8*v_tap_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read tap threshold*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_TAP_1_INTR_TAP_THRES__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_thres_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_TAP_1_INTR_TAP_THRES); + } + return com_rslt; +} + /*! +* @brief This API write Threshold of the +* single/double tap interrupt from the register 0x64 bit 0 to 4 +* +* +* @param v_tap_thres_u8 : The value of single/double tap threshold +* +* @note single/double tap threshold changes according to accel g range +* accel g range can be set by the function "" +* accel_range | single/double tap threshold +* ----------------|--------------------- +* 2g | ((v_tap_thres_u8 + 1)* 62.5)mg +* 4g | ((v_tap_thres_u8 + 1)* 125)mg +* 8g | ((v_tap_thres_u8 + 1)* 250)mg +* 16g | ((v_tap_thres_u8 + 1)* 500)mg +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_thres( +u8 v_tap_thres_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write tap threshold*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_1_INTR_TAP_THRES__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_TAP_1_INTR_TAP_THRES, + v_tap_thres_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_TAP_1_INTR_TAP_THRES__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} + /*! +* @brief This API read the threshold for orientation interrupt +* from the register 0x65 bit 0 and 1 +* +* @param v_orient_mode_u8 : The value of threshold for orientation +* value | Behaviour +* ----------|------------------- +* 0x00 | symmetrical +* 0x01 | high-asymmetrical +* 0x02 | low-asymmetrical +* 0x03 | symmetrical +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_mode( +u8*v_orient_mode_u8) +{ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read orientation threshold*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_mode_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE); + } + return com_rslt; +} + /*! +* @brief This API write the threshold for orientation interrupt +* from the register 0x65 bit 0 and 1 +* +* @param v_orient_mode_u8 : The value of threshold for orientation +* value | Behaviour +* ----------|------------------- +* 0x00 | symmetrical +* 0x01 | high-asymmetrical +* 0x02 | low-asymmetrical +* 0x03 | symmetrical +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_mode( +u8 v_orient_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_orient_mode_u8 <= SMI130_MAX_ORIENT_MODE) { + /* write orientation threshold*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE, + v_orient_mode_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read the orient blocking mode +* that is used for the generation of the orientation interrupt. +* from the register 0x65 bit 2 and 3 +* +* @param v_orient_blocking_u8 : The value of orient blocking mode +* value | Behaviour +* ----------|------------------- +* 0x00 | No blocking +* 0x01 | Theta blocking or acceleration in any axis > 1.5g +* 0x02 | Theta blocking or acceleration slope in any axis > +* - | 0.2g or acceleration in any axis > 1.5g +* 0x03 | Theta blocking or acceleration slope in any axis > +* - | 0.4g or acceleration in any axis > +* - | 1.5g and value of orient is not stable +* - | for at least 100 ms +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_blocking( +u8*v_orient_blocking_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read orient blocking mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_blocking_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING); + } + return com_rslt; +} +/*! +* @brief This API write the orient blocking mode +* that is used for the generation of the orientation interrupt. +* from the register 0x65 bit 2 and 3 +* +* @param v_orient_blocking_u8 : The value of orient blocking mode +* value | Behaviour +* ----------|------------------- +* 0x00 | No blocking +* 0x01 | Theta blocking or acceleration in any axis > 1.5g +* 0x02 | Theta blocking or acceleration slope in any axis > +* - | 0.2g or acceleration in any axis > 1.5g +* 0x03 | Theta blocking or acceleration slope in any axis > +* - | 0.4g or acceleration in any axis > +* - | 1.5g and value of orient is not stable +* - | for at least 100 ms +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_blocking( +u8 v_orient_blocking_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_orient_blocking_u8 <= SMI130_MAX_ORIENT_BLOCKING) { + /* write orient blocking mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING, + v_orient_blocking_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} +return com_rslt; +} +/*! +* @brief This API read Orient interrupt +* hysteresis, from the register 0x64 bit 4 to 7 +* +* +* +* @param v_orient_hyst_u8 : The value of orient hysteresis +* +* @note 1 LSB corresponds to 62.5 mg, +* irrespective of the selected accel range +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_hyst( +u8*v_orient_hyst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read orient hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_hyst_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST); + } + return com_rslt; +} +/*! +* @brief This API write Orient interrupt +* hysteresis, from the register 0x64 bit 4 to 7 +* +* +* +* @param v_orient_hyst_u8 : The value of orient hysteresis +* +* @note 1 LSB corresponds to 62.5 mg, +* irrespective of the selected accel range +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_hyst( +u8 v_orient_hyst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write orient hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST, + v_orient_hyst_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} + /*! +* @brief This API read Orient +* blocking angle (0 to 44.8) from the register 0x66 bit 0 to 5 +* +* @param v_orient_theta_u8 : The value of Orient blocking angle +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_theta( +u8*v_orient_theta_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read Orient blocking angle*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_theta_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA); + } + return com_rslt; +} + /*! +* @brief This API write Orient +* blocking angle (0 to 44.8) from the register 0x66 bit 0 to 5 +* +* @param v_orient_theta_u8 : The value of Orient blocking angle +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_theta( +u8 v_orient_theta_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_orient_theta_u8 <= SMI130_MAX_ORIENT_THETA) { + /* write Orient blocking angle*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA, + v_orient_theta_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} +return com_rslt; +} +/*! +* @brief This API read orient change +* of up/down bit from the register 0x66 bit 6 +* +* @param v_orient_ud_u8 : The value of orient change of up/down +* value | Behaviour +* ----------|------------------- +* 0x00 | Is ignored +* 0x01 | Generates orientation interrupt +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_ud_enable( +u8*v_orient_ud_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read orient up/down enable*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_ud_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API write orient change +* of up/down bit from the register 0x66 bit 6 +* +* @param v_orient_ud_u8 : The value of orient change of up/down +* value | Behaviour +* ----------|------------------- +* 0x00 | Is ignored +* 0x01 | Generates orientation interrupt +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_ud_enable( +u8 v_orient_ud_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_orient_ud_u8 <= SMI130_MAX_VALUE_ORIENT_UD) { + /* write orient up/down enable*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE, + v_orient_ud_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} +return com_rslt; +} + /*! +* @brief This API read orientation axes changes +* from the register 0x66 bit 7 +* +* @param v_orient_axes_u8 : The value of orient axes assignment +* value | Behaviour | Name +* ----------|--------------------|------ +* 0x00 | x = x, y = y, z = z|orient_ax_noex +* 0x01 | x = y, y = z, z = x|orient_ax_ex +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_axes_enable( +u8*v_orient_axes_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read orientation axes changes */ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_axes_u8 = SMI130_GET_BITSLICE + (v_data_u8, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX); + } + return com_rslt; +} + /*! +* @brief This API write orientation axes changes +* from the register 0x66 bit 7 +* +* @param v_orient_axes_u8 : The value of orient axes assignment +* value | Behaviour | Name +* ----------|--------------------|------ +* 0x00 | x = x, y = y, z = z|orient_ax_noex +* 0x01 | x = y, y = z, z = x|orient_ax_ex +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_axes_enable( +u8 v_orient_axes_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_orient_axes_u8 <= SMI130_MAX_VALUE_ORIENT_AXES) { + /*write orientation axes changes */ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX, + v_orient_axes_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} +return com_rslt; +} + /*! +* @brief This API read Flat angle (0 to 44.8) for flat interrupt +* from the register 0x67 bit 0 to 5 +* +* @param v_flat_theta_u8 : The value of flat angle +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat_theta( +u8*v_flat_theta_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read Flat angle*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_theta_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA); + } + return com_rslt; +} + /*! +* @brief This API write Flat angle (0 to 44.8) for flat interrupt +* from the register 0x67 bit 0 to 5 +* +* @param v_flat_theta_u8 : The value of flat angle +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat_theta( +u8 v_flat_theta_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_flat_theta_u8 <= SMI130_MAX_FLAT_THETA) { + /* write Flat angle*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA, + v_flat_theta_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read Flat interrupt hold time; +* from the register 0x68 bit 4 and 5 +* +* @param v_flat_hold_u8 : The value of flat hold time +* value | Behaviour +* ----------|------------------- +* 0x00 | 0ms +* 0x01 | 512ms +* 0x01 | 1024ms +* 0x01 | 2048ms +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat_hold( +u8*v_flat_hold_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read flat hold time*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_hold_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD); + } + return com_rslt; +} +/*! +* @brief This API write Flat interrupt hold time; +* from the register 0x68 bit 4 and 5 +* +* @param v_flat_hold_u8 : The value of flat hold time +* value | Behaviour +* ----------|------------------- +* 0x00 | 0ms +* 0x01 | 512ms +* 0x01 | 1024ms +* 0x01 | 2048ms +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat_hold( +u8 v_flat_hold_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_flat_hold_u8 <= SMI130_MAX_FLAT_HOLD) { + /* write flat hold time*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD, + v_flat_hold_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read flat interrupt hysteresis +* from the register 0x68 bit 0 to 3 +* +* @param v_flat_hyst_u8 : The value of flat hysteresis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat_hyst( +u8*v_flat_hyst_u8) +{ + /* variable used to return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the flat hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_hyst_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST); + } + return com_rslt; +} +/*! +* @brief This API write flat interrupt hysteresis +* from the register 0x68 bit 0 to 3 +* +* @param v_flat_hyst_u8 : The value of flat hysteresis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat_hyst( +u8 v_flat_hyst_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_flat_hyst_u8 <= SMI130_MAX_FLAT_HYST) { + /* read the flat hysteresis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST, + v_flat_hyst_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API read accel offset compensation +* target value for z-axis from the register 0x69 bit 0 and 1 +* +* @param v_foc_accel_z_u8 : the value of accel offset compensation z axis +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_accel_z(u8*v_foc_accel_z_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel offset compensation for z axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_accel_z_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_Z); + } + return com_rslt; +} + /*! +* @brief This API write accel offset compensation +* target value for z-axis from the register 0x69 bit 0 and 1 +* +* @param v_foc_accel_z_u8 : the value of accel offset compensation z axis +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_accel_z( +u8 v_foc_accel_z_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write the accel offset compensation for z axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_Z, + v_foc_accel_z_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API read accel offset compensation +* target value for y-axis +* from the register 0x69 bit 2 and 3 +* +* @param v_foc_accel_y_u8 : the value of accel offset compensation y axis +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_accel_y(u8*v_foc_accel_y_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel offset compensation for y axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_accel_y_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_Y); + } + return com_rslt; +} +/*! +* @brief This API write accel offset compensation +* target value for y-axis +* from the register 0x69 bit 2 and 3 +* +* @param v_foc_accel_y_u8 : the value of accel offset compensation y axis +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x02 | -1g +* 0x03 | 0g +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_accel_y(u8 v_foc_accel_y_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_foc_accel_y_u8 <= SMI130_MAX_ACCEL_FOC) { + /* write the accel offset compensation for y axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_Y, + v_foc_accel_y_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read accel offset compensation +* target value for x-axis is +* from the register 0x69 bit 4 and 5 +* +* @param v_foc_accel_x_u8 : the value of accel offset compensation x axis +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x02 | -1g +* 0x03 | 0g +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_accel_x(u8*v_foc_accel_x_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the accel offset compensation for x axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_accel_x_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_X); + } + return com_rslt; +} +/*! +* @brief This API write accel offset compensation +* target value for x-axis is +* from the register 0x69 bit 4 and 5 +* +* @param v_foc_accel_x_u8 : the value of accel offset compensation x axis +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_accel_x(u8 v_foc_accel_x_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_foc_accel_x_u8 <= SMI130_MAX_ACCEL_FOC) { + /* write the accel offset compensation for x axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_X, + v_foc_accel_x_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API writes accel fast offset compensation +* from the register 0x69 bit 0 to 5 +* @brief This API writes each axis individually +* FOC_X_AXIS - bit 4 and 5 +* FOC_Y_AXIS - bit 2 and 3 +* FOC_Z_AXIS - bit 0 and 1 +* +* @param v_foc_accel_u8: The value of accel offset compensation +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* @param v_axis_u8: The value of accel offset axis selection + * value | axis +* ----------|------------------- +* 0 | FOC_X_AXIS +* 1 | FOC_Y_AXIS +* 2 | FOC_Z_AXIS +* +* @param v_accel_offset_s8: The accel offset value +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_foc_trigger(u8 v_axis_u8, +u8 v_foc_accel_u8, s8*v_accel_offset_s8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +s8 v_status_s8 = SUCCESS; +u8 v_timeout_u8 = SMI130_INIT_VALUE; +s8 v_foc_accel_offset_x_s8 = SMI130_INIT_VALUE; +s8 v_foc_accel_offset_y_s8 = SMI130_INIT_VALUE; +s8 v_foc_accel_offset_z_s8 = SMI130_INIT_VALUE; +u8 focstatus = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; +} else { + v_status_s8 = smi130_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + switch (v_axis_u8) { + case FOC_X_AXIS: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_X, + v_foc_accel_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the + FOC need to write + 0x03 in the register 0x7e*/ + com_rslt += + smi130_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += + smi130_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH + && v_timeout_u8 < + SMI130_MAXIMUM_TIMEOUT)) { + p_smi130->delay_msec( + SMI130_DELAY_SETTLING_TIME); + com_rslt = smi130_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == SMI130_FOC_STAT_HIGH)) { + com_rslt += + smi130_get_accel_offset_compensation_xaxis( + &v_foc_accel_offset_x_s8); + *v_accel_offset_s8 = + v_foc_accel_offset_x_s8; + } + break; + case FOC_Y_AXIS: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_Y, + v_foc_accel_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC + need to write 0x03 + in the register 0x7e*/ + com_rslt += + smi130_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += + smi130_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH + && v_timeout_u8 < + SMI130_MAXIMUM_TIMEOUT)) { + p_smi130->delay_msec( + SMI130_DELAY_SETTLING_TIME); + com_rslt = smi130_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == SMI130_FOC_STAT_HIGH)) { + com_rslt += + smi130_get_accel_offset_compensation_yaxis( + &v_foc_accel_offset_y_s8); + *v_accel_offset_s8 = + v_foc_accel_offset_y_s8; + } + break; + case FOC_Z_AXIS: + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FOC_ACCEL_Z, + v_foc_accel_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC need to write + 0x03 in the register 0x7e*/ + com_rslt += + smi130_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += + smi130_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH + && v_timeout_u8 < + SMI130_MAXIMUM_TIMEOUT)) { + p_smi130->delay_msec( + SMI130_DELAY_SETTLING_TIME); + com_rslt = smi130_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == SMI130_FOC_STAT_HIGH)) { + com_rslt += + smi130_get_accel_offset_compensation_zaxis( + &v_foc_accel_offset_z_s8); + *v_accel_offset_s8 = + v_foc_accel_offset_z_s8; + } + break; + default: + break; + } + } else { + com_rslt = ERROR; + } +} +return com_rslt; +} +/*! +* @brief This API write fast accel offset compensation +* it writes all axis together.To the register 0x69 bit 0 to 5 +* FOC_X_AXIS - bit 4 and 5 +* FOC_Y_AXIS - bit 2 and 3 +* FOC_Z_AXIS - bit 0 and 1 +* +* @param v_foc_accel_x_u8: The value of accel offset x compensation +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* @param v_foc_accel_y_u8: The value of accel offset y compensation +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* @param v_foc_accel_z_u8: The value of accel offset z compensation +* value | Behaviour +* ----------|------------------- +* 0x00 | disable +* 0x01 | +1g +* 0x01 | -1g +* 0x01 | 0g +* +* @param v_accel_off_x_s8: The value of accel offset x axis +* @param v_accel_off_y_s8: The value of accel offset y axis +* @param v_accel_off_z_s8: The value of accel offset z axis +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_accel_foc_trigger_xyz(u8 v_foc_accel_x_u8, +u8 v_foc_accel_y_u8, u8 v_foc_accel_z_u8, s8*v_accel_off_x_s8, +s8*v_accel_off_y_s8, s8*v_accel_off_z_s8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 focx = SMI130_INIT_VALUE; +u8 focy = SMI130_INIT_VALUE; +u8 focz = SMI130_INIT_VALUE; +s8 v_foc_accel_offset_x_s8 = SMI130_INIT_VALUE; +s8 v_foc_accel_offset_y_s8 = SMI130_INIT_VALUE; +s8 v_foc_accel_offset_z_s8 = SMI130_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +u8 v_timeout_u8 = SMI130_INIT_VALUE; +u8 focstatus = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + v_status_s8 = smi130_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* foc x axis*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_X__REG, + &focx, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + focx = SMI130_SET_BITSLICE(focx, + SMI130_USER_FOC_ACCEL_X, + v_foc_accel_x_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_X__REG, + &focx, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + /* foc y axis*/ + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Y__REG, + &focy, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + focy = SMI130_SET_BITSLICE(focy, + SMI130_USER_FOC_ACCEL_Y, + v_foc_accel_y_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Y__REG, + &focy, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + /* foc z axis*/ + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Z__REG, + &focz, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + focz = SMI130_SET_BITSLICE(focz, + SMI130_USER_FOC_ACCEL_Z, + v_foc_accel_z_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_ACCEL_Z__REG, + &focz, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC need to + write 0x03 in the register 0x7e*/ + com_rslt += smi130_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += smi130_get_foc_rdy( + &focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH + && v_timeout_u8 < + SMI130_MAXIMUM_TIMEOUT)) { + p_smi130->delay_msec( + SMI130_DELAY_SETTLING_TIME); + com_rslt = smi130_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == SMI130_GEN_READ_WRITE_DATA_LENGTH)) { + com_rslt += + smi130_get_accel_offset_compensation_xaxis( + &v_foc_accel_offset_x_s8); + *v_accel_off_x_s8 = + v_foc_accel_offset_x_s8; + com_rslt += + smi130_get_accel_offset_compensation_yaxis( + &v_foc_accel_offset_y_s8); + *v_accel_off_y_s8 = + v_foc_accel_offset_y_s8; + com_rslt += + smi130_get_accel_offset_compensation_zaxis( + &v_foc_accel_offset_z_s8); + *v_accel_off_z_s8 = + v_foc_accel_offset_z_s8; + } + } else { + com_rslt = ERROR; + } + } +return com_rslt; +} +/*! +* @brief This API read gyro fast offset enable +* from the register 0x69 bit 6 +* +* @param v_foc_gyro_u8 : The value of gyro fast offset enable +* value | Description +* ----------|------------- +* 0 | fast offset compensation disabled +* 1 | fast offset compensation enabled +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_gyro_enable( +u8*v_foc_gyro_u8) +{ + /* used for return the status of bus communication*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the gyro fast offset enable*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_FOC_GYRO_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_gyro_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_FOC_GYRO_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API write gyro fast offset enable +* from the register 0x69 bit 6 +* +* @param v_foc_gyro_u8 : The value of gyro fast offset enable +* value | Description +* ----------|------------- +* 0 | fast offset compensation disabled +* 1 | fast offset compensation enabled +* +* @param v_gyro_off_x_s16 : The value of gyro fast offset x axis data +* @param v_gyro_off_y_s16 : The value of gyro fast offset y axis data +* @param v_gyro_off_z_s16 : The value of gyro fast offset z axis data +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_gyro_enable( +u8 v_foc_gyro_u8, s16*v_gyro_off_x_s16, +s16*v_gyro_off_y_s16, s16*v_gyro_off_z_s16) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +u8 v_timeout_u8 = SMI130_INIT_VALUE; +s16 offsetx = SMI130_INIT_VALUE; +s16 offsety = SMI130_INIT_VALUE; +s16 offsetz = SMI130_INIT_VALUE; +u8 focstatus = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + v_status_s8 = smi130_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_FOC_GYRO_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_FOC_GYRO_ENABLE, + v_foc_gyro_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_FOC_GYRO_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC need to write 0x03 + in the register 0x7e*/ + com_rslt += smi130_set_command_register + (START_FOC_ACCEL_GYRO); + + com_rslt += smi130_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != SMI130_FOC_STAT_HIGH + && v_timeout_u8 < + SMI130_MAXIMUM_TIMEOUT)) { + p_smi130->delay_msec( + SMI130_DELAY_SETTLING_TIME); + com_rslt = smi130_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == SMI130_FOC_STAT_HIGH)) { + com_rslt += + smi130_get_gyro_offset_compensation_xaxis + (&offsetx); + *v_gyro_off_x_s16 = offsetx; + + com_rslt += + smi130_get_gyro_offset_compensation_yaxis + (&offsety); + *v_gyro_off_y_s16 = offsety; + + com_rslt += + smi130_get_gyro_offset_compensation_zaxis( + &offsetz); + *v_gyro_off_z_s16 = offsetz; + } + } else { + com_rslt = ERROR; + } + } +return com_rslt; +} + /*! +* @brief This API read NVM program enable +* from the register 0x6A bit 1 +* +* @param v_nvm_prog_u8 : The value of NVM program enable +* Value | Description +* --------|------------- +* 0 | DISABLE +* 1 | ENABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_nvm_prog_enable( +u8*v_nvm_prog_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read NVM program*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_CONFIG_NVM_PROG_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_nvm_prog_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_CONFIG_NVM_PROG_ENABLE); + } + return com_rslt; +} + /*! +* @brief This API write NVM program enable +* from the register 0x6A bit 1 +* +* @param v_nvm_prog_u8 : The value of NVM program enable +* Value | Description +* --------|------------- +* 0 | DISABLE +* 1 | ENABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_nvm_prog_enable( +u8 v_nvm_prog_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_nvm_prog_u8 <= SMI130_MAX_VALUE_NVM_PROG) { + /* write the NVM program*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_CONFIG_NVM_PROG_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_CONFIG_NVM_PROG_ENABLE, + v_nvm_prog_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_CONFIG_NVM_PROG_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read to configure SPI +* Interface Mode for primary and OIS interface +* from the register 0x6B bit 0 +* +* @param v_spi3_u8 : The value of SPI mode selection +* Value | Description +* --------|------------- +* 0 | SPI 4-wire mode +* 1 | SPI 3-wire mode +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_spi3( +u8*v_spi3_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read SPI mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_SPI3__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_spi3_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_SPI3); + } + return com_rslt; +} +/*! +* @brief This API write to configure SPI +* Interface Mode for primary and OIS interface +* from the register 0x6B bit 0 +* +* @param v_spi3_u8 : The value of SPI mode selection +* Value | Description +* --------|------------- +* 0 | SPI 4-wire mode +* 1 | SPI 3-wire mode +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_spi3( +u8 v_spi3_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_spi3_u8 <= SMI130_MAX_VALUE_SPI3) { + /* write SPI mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_SPI3__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_SPI3, + v_spi3_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_SPI3__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read I2C Watchdog timer +* from the register 0x70 bit 1 +* +* @param v_i2c_wdt_u8 : The value of I2C watch dog timer +* Value | Description +* --------|------------- +* 0 | I2C watchdog v_timeout_u8 after 1 ms +* 1 | I2C watchdog v_timeout_u8 after 50 ms +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_wdt_select( +u8*v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read I2C watch dog timer*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_I2C_WDT_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_wdt_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_I2C_WDT_SELECT); + } + return com_rslt; +} +/*! +* @brief This API write I2C Watchdog timer +* from the register 0x70 bit 1 +* +* @param v_i2c_wdt_u8 : The value of I2C watch dog timer +* Value | Description +* --------|------------- +* 0 | I2C watchdog v_timeout_u8 after 1 ms +* 1 | I2C watchdog v_timeout_u8 after 50 ms +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_i2c_wdt_select( +u8 v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_i2c_wdt_u8 <= SMI130_MAX_VALUE_I2C_WDT) { + /* write I2C watch dog timer*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_I2C_WDT_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_I2C_WDT_SELECT, + v_i2c_wdt_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_I2C_WDT_SELECT__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read I2C watchdog enable +* from the register 0x70 bit 2 +* +* @param v_i2c_wdt_u8 : The value of I2C watchdog enable +* Value | Description +* --------|------------- +* 0 | DISABLE +* 1 | ENABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_wdt_enable( +u8*v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read i2c watch dog eneble*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_wdt_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API write I2C watchdog enable +* from the register 0x70 bit 2 +* +* @param v_i2c_wdt_u8 : The value of I2C watchdog enable +* Value | Description +* --------|------------- +* 0 | DISABLE +* 1 | ENABLE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_i2c_wdt_enable( +u8 v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_i2c_wdt_u8 <= SMI130_MAX_VALUE_I2C_WDT) { + /* write i2c watch dog eneble*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE, + v_i2c_wdt_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read I2C interface configuration(if) moe +* from the register 0x6B bit 4 and 5 +* +* @param v_if_mode_u8 : The value of interface configuration mode +* Value | Description +* --------|------------- +* 0x00 | Primary interface:autoconfig / secondary interface:off +* 0x01 | Primary interface:I2C / secondary interface:OIS +* 0x02 | Primary interface:autoconfig/secondary interface:Magnetometer +* 0x03 | Reserved +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_if_mode( +u8*v_if_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read if mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_IF_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_if_mode_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_IF_MODE); + } + return com_rslt; +} +/*! +* @brief This API write I2C interface configuration(if) moe +* from the register 0x6B bit 4 and 5 +* +* @param v_if_mode_u8 : The value of interface configuration mode +* Value | Description +* --------|------------- +* 0x00 | Primary interface:autoconfig / secondary interface:off +* 0x01 | Primary interface:I2C / secondary interface:OIS +* 0x02 | Primary interface:autoconfig/secondary interface:Magnetometer +* 0x03 | Reserved +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_if_mode( +u8 v_if_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_if_mode_u8 <= SMI130_MAX_IF_MODE) { + /* write if mode*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_IF_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_IF_CONFIG_IF_MODE, + v_if_mode_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_IF_CONFIG_IF_MODE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read gyro sleep trigger +* from the register 0x6C bit 0 to 2 +* +* @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger +* Value | Description +* --------|------------- +* 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no +* 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes +* 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no +* 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes +* 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no +* 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes +* 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no +* 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_sleep_trigger( +u8*v_gyro_sleep_trigger_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro sleep trigger*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SLEEP_TRIGGER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_sleep_trigger_u8 = + SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_SLEEP_TRIGGER); + } + return com_rslt; +} +/*! +* @brief This API write gyro sleep trigger +* from the register 0x6C bit 0 to 2 +* +* @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger +* Value | Description +* --------|------------- +* 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no +* 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes +* 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no +* 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes +* 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no +* 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes +* 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no +* 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_sleep_trigger( +u8 v_gyro_sleep_trigger_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_gyro_sleep_trigger_u8 <= SMI130_MAX_GYRO_SLEEP_TIGGER) { + /* write gyro sleep trigger*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SLEEP_TRIGGER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_SLEEP_TRIGGER, + v_gyro_sleep_trigger_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SLEEP_TRIGGER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read gyro wakeup trigger +* from the register 0x6C bit 3 and 4 +* +* @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger +* Value | Description +* --------|------------- +* 0x00 | anymotion: no / INT1 pin: no +* 0x01 | anymotion: no / INT1 pin: yes +* 0x02 | anymotion: yes / INT1 pin: no +* 0x03 | anymotion: yes / INT1 pin: yes +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_wakeup_trigger( +u8*v_gyro_wakeup_trigger_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro wakeup trigger*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_WAKEUP_TRIGGER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_wakeup_trigger_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_GYRO_WAKEUP_TRIGGER); + } + return com_rslt; +} +/*! +* @brief This API write gyro wakeup trigger +* from the register 0x6C bit 3 and 4 +* +* @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger +* Value | Description +* --------|------------- +* 0x00 | anymotion: no / INT1 pin: no +* 0x01 | anymotion: no / INT1 pin: yes +* 0x02 | anymotion: yes / INT1 pin: no +* 0x03 | anymotion: yes / INT1 pin: yes +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_wakeup_trigger( +u8 v_gyro_wakeup_trigger_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_gyro_wakeup_trigger_u8 + <= SMI130_MAX_GYRO_WAKEUP_TRIGGER) { + /* write gyro wakeup trigger*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_WAKEUP_TRIGGER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_WAKEUP_TRIGGER, + v_gyro_wakeup_trigger_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_WAKEUP_TRIGGER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read Target state for gyro sleep mode +* from the register 0x6C bit 5 +* +* @param v_gyro_sleep_state_u8 : The value of gyro sleep mode +* Value | Description +* --------|------------- +* 0x00 | Sleep transition to fast wake up state +* 0x01 | Sleep transition to suspend state +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_sleep_state( +u8*v_gyro_sleep_state_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro sleep state*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SLEEP_STATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_sleep_state_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_GYRO_SLEEP_STATE); + } + return com_rslt; +} +/*! +* @brief This API write Target state for gyro sleep mode +* from the register 0x6C bit 5 +* +* @param v_gyro_sleep_state_u8 : The value of gyro sleep mode +* Value | Description +* --------|------------- +* 0x00 | Sleep transition to fast wake up state +* 0x01 | Sleep transition to suspend state +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_sleep_state( +u8 v_gyro_sleep_state_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_gyro_sleep_state_u8 <= SMI130_MAX_VALUE_SLEEP_STATE) { + /* write gyro sleep state*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SLEEP_STATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_SLEEP_STATE, + v_gyro_sleep_state_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SLEEP_STATE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read gyro wakeup interrupt +* from the register 0x6C bit 6 +* +* @param v_gyro_wakeup_intr_u8 : The valeu of gyro wakeup interrupt +* Value | Description +* --------|------------- +* 0x00 | DISABLE +* 0x01 | ENABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_wakeup_intr( +u8*v_gyro_wakeup_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro wakeup interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_WAKEUP_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_wakeup_intr_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_GYRO_WAKEUP_INTR); + } + return com_rslt; +} +/*! +* @brief This API write gyro wakeup interrupt +* from the register 0x6C bit 6 +* +* @param v_gyro_wakeup_intr_u8 : The valeu of gyro wakeup interrupt +* Value | Description +* --------|------------- +* 0x00 | DISABLE +* 0x01 | ENABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_wakeup_intr( +u8 v_gyro_wakeup_intr_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_gyro_wakeup_intr_u8 <= SMI130_MAX_VALUE_WAKEUP_INTR) { + /* write gyro wakeup interrupt*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_WAKEUP_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_WAKEUP_INTR, + v_gyro_wakeup_intr_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_WAKEUP_INTR__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read accel select axis to be self-test +* +* @param v_accel_selftest_axis_u8 : +* The value of accel self test axis selection +* Value | Description +* --------|------------- +* 0x00 | disabled +* 0x01 | x-axis +* 0x02 | y-axis +* 0x03 | z-axis +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_selftest_axis( +u8*v_accel_selftest_axis_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read accel self test axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_SELFTEST_AXIS__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_selftest_axis_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_ACCEL_SELFTEST_AXIS); + } + return com_rslt; +} +/*! +* @brief This API write accel select axis to be self-test +* +* @param v_accel_selftest_axis_u8 : +* The value of accel self test axis selection +* Value | Description +* --------|------------- +* 0x00 | disabled +* 0x01 | x-axis +* 0x02 | y-axis +* 0x03 | z-axis +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_selftest_axis( +u8 v_accel_selftest_axis_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_accel_selftest_axis_u8 + <= SMI130_MAX_ACCEL_SELFTEST_AXIS) { + /* write accel self test axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_SELFTEST_AXIS__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_SELFTEST_AXIS, + v_accel_selftest_axis_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_SELFTEST_AXIS__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read accel self test axis sign +* from the register 0x6D bit 2 +* +* @param v_accel_selftest_sign_u8: The value of accel self test axis sign +* Value | Description +* --------|------------- +* 0x00 | negative +* 0x01 | positive +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_selftest_sign( +u8*v_accel_selftest_sign_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read accel self test axis sign*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_SELFTEST_SIGN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_selftest_sign_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_ACCEL_SELFTEST_SIGN); + } + return com_rslt; +} +/*! +* @brief This API write accel self test axis sign +* from the register 0x6D bit 2 +* +* @param v_accel_selftest_sign_u8: The value of accel self test axis sign +* Value | Description +* --------|------------- +* 0x00 | negative +* 0x01 | positive +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_selftest_sign( +u8 v_accel_selftest_sign_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_accel_selftest_sign_u8 <= + SMI130_MAX_VALUE_SELFTEST_SIGN) { + /* write accel self test axis sign*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_SELFTEST_SIGN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_ACCEL_SELFTEST_SIGN, + v_accel_selftest_sign_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_ACCEL_SELFTEST_SIGN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read accel self test amplitude +* from the register 0x6D bit 3 +* select amplitude of the selftest deflection: +* +* @param v_accel_selftest_amp_u8 : The value of accel self test amplitude +* Value | Description +* --------|------------- +* 0x00 | LOW +* 0x01 | HIGH +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_selftest_amp( +u8*v_accel_selftest_amp_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read self test amplitude*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_SELFTEST_AMP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_selftest_amp_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_SELFTEST_AMP); + } + return com_rslt; +} +/*! +* @brief This API write accel self test amplitude +* from the register 0x6D bit 3 +* select amplitude of the selftest deflection: +* +* @param v_accel_selftest_amp_u8 : The value of accel self test amplitude +* Value | Description +* --------|------------- +* 0x00 | LOW +* 0x01 | HIGH +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_selftest_amp( +u8 v_accel_selftest_amp_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_accel_selftest_amp_u8 <= + SMI130_MAX_VALUE_SELFTEST_AMP) { + /* write self test amplitude*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_SELFTEST_AMP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_SELFTEST_AMP, + v_accel_selftest_amp_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_SELFTEST_AMP__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} +/*! +* @brief This API read gyro self test trigger +* +* @param v_gyro_selftest_start_u8: The value of gyro self test start +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_selftest_start( +u8*v_gyro_selftest_start_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro self test start*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SELFTEST_START__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_selftest_start_u8 = SMI130_GET_BITSLICE( + v_data_u8, + SMI130_USER_GYRO_SELFTEST_START); + } + return com_rslt; +} +/*! +* @brief This API write gyro self test trigger +* +* @param v_gyro_selftest_start_u8: The value of gyro self test start +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_selftest_start( +u8 v_gyro_selftest_start_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_gyro_selftest_start_u8 <= + SMI130_MAX_VALUE_SELFTEST_START) { + /* write gyro self test start*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SELFTEST_START__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_GYRO_SELFTEST_START, + v_gyro_selftest_start_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_GYRO_SELFTEST_START__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API read primary interface selection I2C or SPI +* from the register 0x70 bit 0 +* +* @param v_spi_enable_u8: The value of Interface selection +* Value | Description +* --------|------------- +* 0x00 | I2C Enable +* 0x01 | I2C DISBALE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_spi_enable(u8*v_spi_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read interface section*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_SPI_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_spi_enable_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_NV_CONFIG_SPI_ENABLE); + } + return com_rslt; +} + /*! +* @brief This API write primary interface selection I2C or SPI +* from the register 0x70 bit 0 +* +* @param v_spi_enable_u8: The value of Interface selection +* Value | Description +* --------|------------- +* 0x00 | I2C Enable +* 0x01 | I2C DISBALE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_spi_enable(u8 v_spi_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write interface section*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_SPI_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_NV_CONFIG_SPI_ENABLE, + v_spi_enable_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_SPI_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} + /*! +* @brief This API read the spare zero +* form register 0x70 bit 3 +* +* +* @param v_spare0_trim_u8: The value of spare zero +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_spare0_trim(u8*v_spare0_trim_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read spare zero*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_SPARE0__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_spare0_trim_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_NV_CONFIG_SPARE0); + } + return com_rslt; +} + /*! +* @brief This API write the spare zero +* form register 0x70 bit 3 +* +* +* @param v_spare0_trim_u8: The value of spare zero +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_spare0_trim(u8 v_spare0_trim_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write spare zero*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_SPARE0__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_NV_CONFIG_SPARE0, + v_spare0_trim_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_SPARE0__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} + /*! +* @brief This API read the NVM counter +* form register 0x70 bit 4 to 7 +* +* +* @param v_nvm_counter_u8: The value of NVM counter +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_nvm_counter(u8*v_nvm_counter_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read NVM counter*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_NVM_COUNTER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_nvm_counter_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_NV_CONFIG_NVM_COUNTER); + } + return com_rslt; +} + /*! +* @brief This API write the NVM counter +* form register 0x70 bit 4 to 7 +* +* +* @param v_nvm_counter_u8: The value of NVM counter +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_nvm_counter( +u8 v_nvm_counter_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write NVM counter*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_NVM_COUNTER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_NV_CONFIG_NVM_COUNTER, + v_nvm_counter_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_NV_CONFIG_NVM_COUNTER__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API read accel manual offset compensation of x axis +* from the register 0x71 bit 0 to 7 +* +* +* +* @param v_accel_off_x_s8: +* The value of accel manual offset compensation of x axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_compensation_xaxis( +s8*v_accel_off_x_s8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read accel manual offset compensation of x axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_0_ACCEL_OFF_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_x_s8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_0_ACCEL_OFF_X); + } + return com_rslt; +} +/*! +* @brief This API write accel manual offset compensation of x axis +* from the register 0x71 bit 0 to 7 +* +* +* +* @param v_accel_off_x_s8: +* The value of accel manual offset compensation of x axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_compensation_xaxis( +s8 v_accel_off_x_s8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* enable accel offset*/ + v_status_s8 = smi130_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* write accel manual offset compensation of x axis*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_0_ACCEL_OFF_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE( + v_data_u8, + SMI130_USER_OFFSET_0_ACCEL_OFF_X, + v_accel_off_x_s8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_0_ACCEL_OFF_X__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = ERROR; + } + } + return com_rslt; +} +/*! +* @brief This API read accel manual offset compensation of y axis +* from the register 0x72 bit 0 to 7 +* +* +* +* @param v_accel_off_y_s8: +* The value of accel manual offset compensation of y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_compensation_yaxis( +s8*v_accel_off_y_s8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read accel manual offset compensation of y axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_1_ACCEL_OFF_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_y_s8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_1_ACCEL_OFF_Y); + } + return com_rslt; +} +/*! +* @brief This API write accel manual offset compensation of y axis +* from the register 0x72 bit 0 to 7 +* +* +* +* @param v_accel_off_y_s8: +* The value of accel manual offset compensation of y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_compensation_yaxis( +s8 v_accel_off_y_s8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* enable accel offset*/ + v_status_s8 = smi130_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* write accel manual offset compensation of y axis*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_1_ACCEL_OFF_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE( + v_data_u8, + SMI130_USER_OFFSET_1_ACCEL_OFF_Y, + v_accel_off_y_s8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_1_ACCEL_OFF_Y__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = ERROR; + } + } + return com_rslt; +} +/*! +* @brief This API read accel manual offset compensation of z axis +* from the register 0x73 bit 0 to 7 +* +* +* +* @param v_accel_off_z_s8: +* The value of accel manual offset compensation of z axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_compensation_zaxis( +s8*v_accel_off_z_s8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read accel manual offset compensation of z axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_2_ACCEL_OFF_Z__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_z_s8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_2_ACCEL_OFF_Z); + } + return com_rslt; +} +/*! +* @brief This API write accel manual offset compensation of z axis +* from the register 0x73 bit 0 to 7 +* +* +* +* @param v_accel_off_z_s8: +* The value of accel manual offset compensation of z axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_compensation_zaxis( +s8 v_accel_off_z_s8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + u8 v_status_s8 = SUCCESS; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* enable accel offset*/ + v_status_s8 = smi130_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* write accel manual offset + compensation of z axis*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_2_ACCEL_OFF_Z__REG, + &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_2_ACCEL_OFF_Z, + v_accel_off_z_s8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_2_ACCEL_OFF_Z__REG, + &v_data_u8, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = ERROR; + } + } + return com_rslt; +} +/*! +* @brief This API read gyro manual offset compensation of x axis +* from the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1 +* +* +* +* @param v_gyro_off_x_s16: +* The value of gyro manual offset compensation of x axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_compensation_xaxis( +s16*v_gyro_off_x_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data1_u8r = SMI130_INIT_VALUE; + u8 v_data2_u8r = SMI130_INIT_VALUE; + s16 v_data3_u8r, v_data4_u8r = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro offset x*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_3_GYRO_OFF_X__REG, + &v_data1_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = SMI130_GET_BITSLICE(v_data1_u8r, + SMI130_USER_OFFSET_3_GYRO_OFF_X); + com_rslt += p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_X__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = SMI130_GET_BITSLICE(v_data2_u8r, + SMI130_USER_OFFSET_6_GYRO_OFF_X); + v_data3_u8r = v_data2_u8r + << SMI130_SHIFT_BIT_POSITION_BY_14_BITS; + v_data4_u8r = v_data1_u8r + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS; + v_data3_u8r = v_data3_u8r | v_data4_u8r; + *v_gyro_off_x_s16 = v_data3_u8r + >> SMI130_SHIFT_BIT_POSITION_BY_06_BITS; + } + return com_rslt; +} +/*! +* @brief This API write gyro manual offset compensation of x axis +* from the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1 +* +* +* +* @param v_gyro_off_x_s16: +* The value of gyro manual offset compensation of x axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_compensation_xaxis( +s16 v_gyro_off_x_s16) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data1_u8r, v_data2_u8r = SMI130_INIT_VALUE; +u16 v_data3_u8r = SMI130_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write gyro offset x*/ + v_status_s8 = smi130_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_3_GYRO_OFF_X__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data1_u8r = + ((s8) (v_gyro_off_x_s16 & + SMI130_GYRO_MANUAL_OFFSET_0_7)); + v_data2_u8r = SMI130_SET_BITSLICE( + v_data2_u8r, + SMI130_USER_OFFSET_3_GYRO_OFF_X, + v_data1_u8r); + /* write 0x74 bit 0 to 7*/ + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_3_GYRO_OFF_X__REG, + &v_data2_u8r, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + com_rslt += p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_X__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u8r = + (u16) (v_gyro_off_x_s16 & + SMI130_GYRO_MANUAL_OFFSET_8_9); + v_data1_u8r = (u8)(v_data3_u8r + >> SMI130_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = SMI130_SET_BITSLICE( + v_data2_u8r, + SMI130_USER_OFFSET_6_GYRO_OFF_X, + v_data1_u8r); + /* write 0x77 bit 0 and 1*/ + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_X__REG, + &v_data2_u8r, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + return ERROR; + } + } +return com_rslt; +} +/*! +* @brief This API read gyro manual offset compensation of y axis +* from the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3 +* +* +* +* @param v_gyro_off_y_s16: +* The value of gyro manual offset compensation of y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_compensation_yaxis( +s16*v_gyro_off_y_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data1_u8r = SMI130_INIT_VALUE; + u8 v_data2_u8r = SMI130_INIT_VALUE; + s16 v_data3_u8r, v_data4_u8r = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro offset y*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_4_GYRO_OFF_Y__REG, + &v_data1_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = SMI130_GET_BITSLICE(v_data1_u8r, + SMI130_USER_OFFSET_4_GYRO_OFF_Y); + com_rslt += p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_Y__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = SMI130_GET_BITSLICE(v_data2_u8r, + SMI130_USER_OFFSET_6_GYRO_OFF_Y); + v_data3_u8r = v_data2_u8r + << SMI130_SHIFT_BIT_POSITION_BY_14_BITS; + v_data4_u8r = v_data1_u8r + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS; + v_data3_u8r = v_data3_u8r | v_data4_u8r; + *v_gyro_off_y_s16 = v_data3_u8r + >> SMI130_SHIFT_BIT_POSITION_BY_06_BITS; + } + return com_rslt; +} +/*! +* @brief This API write gyro manual offset compensation of y axis +* from the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3 +* +* +* +* @param v_gyro_off_y_s16: +* The value of gyro manual offset compensation of y axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_compensation_yaxis( +s16 v_gyro_off_y_s16) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data1_u8r, v_data2_u8r = SMI130_INIT_VALUE; +u16 v_data3_u8r = SMI130_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* enable gyro offset bit*/ + v_status_s8 = smi130_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + /* write gyro offset y*/ + if (v_status_s8 == SUCCESS) { + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_4_GYRO_OFF_Y__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data1_u8r = + ((s8) (v_gyro_off_y_s16 & + SMI130_GYRO_MANUAL_OFFSET_0_7)); + v_data2_u8r = SMI130_SET_BITSLICE( + v_data2_u8r, + SMI130_USER_OFFSET_4_GYRO_OFF_Y, + v_data1_u8r); + /* write 0x75 bit 0 to 7*/ + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_4_GYRO_OFF_Y__REG, + &v_data2_u8r, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + com_rslt += p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_Y__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u8r = + (u16) (v_gyro_off_y_s16 & + SMI130_GYRO_MANUAL_OFFSET_8_9); + v_data1_u8r = (u8)(v_data3_u8r + >> SMI130_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = SMI130_SET_BITSLICE( + v_data2_u8r, + SMI130_USER_OFFSET_6_GYRO_OFF_Y, + v_data1_u8r); + /* write 0x77 bit 2 and 3*/ + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_Y__REG, + &v_data2_u8r, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + return ERROR; + } + } +return com_rslt; +} +/*! +* @brief This API read gyro manual offset compensation of z axis +* from the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5 +* +* +* +* @param v_gyro_off_z_s16: +* The value of gyro manual offset compensation of z axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_compensation_zaxis( +s16*v_gyro_off_z_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data1_u8r = SMI130_INIT_VALUE; + u8 v_data2_u8r = SMI130_INIT_VALUE; + s16 v_data3_u8r, v_data4_u8r = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro manual offset z axis*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_5_GYRO_OFF_Z__REG, + &v_data1_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = SMI130_GET_BITSLICE + (v_data1_u8r, + SMI130_USER_OFFSET_5_GYRO_OFF_Z); + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_Z__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = SMI130_GET_BITSLICE( + v_data2_u8r, + SMI130_USER_OFFSET_6_GYRO_OFF_Z); + v_data3_u8r = v_data2_u8r + << SMI130_SHIFT_BIT_POSITION_BY_14_BITS; + v_data4_u8r = v_data1_u8r + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS; + v_data3_u8r = v_data3_u8r | v_data4_u8r; + *v_gyro_off_z_s16 = v_data3_u8r + >> SMI130_SHIFT_BIT_POSITION_BY_06_BITS; + } + return com_rslt; +} +/*! +* @brief This API write gyro manual offset compensation of z axis +* from the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5 +* +* +* +* @param v_gyro_off_z_s16: +* The value of gyro manual offset compensation of z axis +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_compensation_zaxis( +s16 v_gyro_off_z_s16) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data1_u8r, v_data2_u8r = SMI130_INIT_VALUE; +u16 v_data3_u8r = SMI130_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* enable gyro offset*/ + v_status_s8 = smi130_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + /* write gyro manual offset z axis*/ + if (v_status_s8 == SUCCESS) { + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_5_GYRO_OFF_Z__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data1_u8r = + ((u8) (v_gyro_off_z_s16 & + SMI130_GYRO_MANUAL_OFFSET_0_7)); + v_data2_u8r = SMI130_SET_BITSLICE( + v_data2_u8r, + SMI130_USER_OFFSET_5_GYRO_OFF_Z, + v_data1_u8r); + /* write 0x76 bit 0 to 7*/ + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_5_GYRO_OFF_Z__REG, + &v_data2_u8r, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + com_rslt += p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_Z__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u8r = + (u16) (v_gyro_off_z_s16 & + SMI130_GYRO_MANUAL_OFFSET_8_9); + v_data1_u8r = (u8)(v_data3_u8r + >> SMI130_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = SMI130_SET_BITSLICE( + v_data2_u8r, + SMI130_USER_OFFSET_6_GYRO_OFF_Z, + v_data1_u8r); + /* write 0x77 bit 4 and 5*/ + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_Z__REG, + &v_data2_u8r, + SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + return ERROR; + } + } +return com_rslt; +} +/*! +* @brief This API read the accel offset enable bit +* from the register 0x77 bit 6 +* +* +* +* @param v_accel_off_enable_u8: The value of accel offset enable +* value | Description +* ----------|-------------- +* 0x01 | ENABLE +* 0x00 | DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_enable( +u8*v_accel_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read accel offset enable*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_enable_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE); + } + return com_rslt; +} +/*! +* @brief This API write the accel offset enable bit +* from the register 0x77 bit 6 +* +* +* +* @param v_accel_off_enable_u8: The value of accel offset enable +* value | Description +* ----------|-------------- +* 0x01 | ENABLE +* 0x00 | DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_enable( +u8 v_accel_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write accel offset enable*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE, + v_accel_off_enable_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API read the accel offset enable bit +* from the register 0x77 bit 7 +* +* +* +* @param v_gyro_off_enable_u8: The value of gyro offset enable +* value | Description +* ----------|-------------- +* 0x01 | ENABLE +* 0x00 | DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_enable( +u8*v_gyro_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read gyro offset*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_off_enable_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_6_GYRO_OFF_EN); + } + return com_rslt; +} +/*! +* @brief This API write the accel offset enable bit +* from the register 0x77 bit 7 +* +* +* +* @param v_gyro_off_enable_u8: The value of gyro offset enable +* value | Description +* ----------|-------------- +* 0x01 | ENABLE +* 0x00 | DISABLE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_enable( +u8 v_gyro_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write gyro offset*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_OFFSET_6_GYRO_OFF_EN, + v_gyro_off_enable_u8); + com_rslt += p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_USER_OFFSET_6_GYRO_OFF_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} +/*! +* @brief This API reads step counter value +* form the register 0x78 and 0x79 +* +* +* +* +* @param v_step_cnt_s16 : The value of step counter +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_step_count(u16*v_step_cnt_s16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* array having the step counter LSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 a_data_u8r[SMI130_STEP_COUNT_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read step counter*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STEP_COUNT_LSB__REG, + a_data_u8r, SMI130_STEP_COUNTER_LENGTH); + + *v_step_cnt_s16 = (s16) + ((((s32)((s8)a_data_u8r[SMI130_STEP_COUNT_MSB_BYTE])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[SMI130_STEP_COUNT_LSB_BYTE])); + } + return com_rslt; +} + /*! +* @brief This API Reads +* step counter configuration +* from the register 0x7A bit 0 to 7 +* and from the register 0x7B bit 0 to 2 and 4 to 7 +* +* +* @param v_step_config_u16 : The value of step configuration +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_step_config( +u16*v_step_config_u16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data1_u8r = SMI130_INIT_VALUE; + u8 v_data2_u8r = SMI130_INIT_VALUE; + u16 v_data3_u8r = SMI130_INIT_VALUE; + /* Read the 0 to 7 bit*/ + com_rslt = + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ZERO__REG, + &v_data1_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* Read the 8 to 10 bit*/ + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ONE_CNF1__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = SMI130_GET_BITSLICE(v_data2_u8r, + SMI130_USER_STEP_CONFIG_ONE_CNF1); + v_data3_u8r = ((u16)((((u32) + ((u8)v_data2_u8r)) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (v_data1_u8r))); + /* Read the 11 to 14 bit*/ + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ONE_CNF2__REG, + &v_data1_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = SMI130_GET_BITSLICE(v_data1_u8r, + SMI130_USER_STEP_CONFIG_ONE_CNF2); + *v_step_config_u16 = ((u16)((((u32) + ((u8)v_data1_u8r)) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (v_data3_u8r))); + + return com_rslt; +} + /*! +* @brief This API write +* step counter configuration +* from the register 0x7A bit 0 to 7 +* and from the register 0x7B bit 0 to 2 and 4 to 7 +* +* +* @param v_step_config_u16 : +* the value of Enable step configuration +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_config( +u16 v_step_config_u16) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data1_u8r = SMI130_INIT_VALUE; + u8 v_data2_u8r = SMI130_INIT_VALUE; + u16 v_data3_u16 = SMI130_INIT_VALUE; + + /* write the 0 to 7 bit*/ + v_data1_u8r = (u8)(v_step_config_u16 & + SMI130_STEP_CONFIG_0_7); + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ZERO__REG, + &v_data1_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* write the 8 to 10 bit*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ONE_CNF1__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u16 = (u16) (v_step_config_u16 & + SMI130_STEP_CONFIG_8_10); + v_data1_u8r = (u8)(v_data3_u16 + >> SMI130_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = SMI130_SET_BITSLICE(v_data2_u8r, + SMI130_USER_STEP_CONFIG_ONE_CNF1, v_data1_u8r); + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ONE_CNF1__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + /* write the 11 to 14 bit*/ + com_rslt += p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ONE_CNF2__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u16 = (u16) (v_step_config_u16 & + SMI130_STEP_CONFIG_11_14); + v_data1_u8r = (u8)(v_data3_u16 + >> SMI130_SHIFT_BIT_POSITION_BY_12_BITS); + v_data2_u8r = SMI130_SET_BITSLICE(v_data2_u8r, + SMI130_USER_STEP_CONFIG_ONE_CNF2, v_data1_u8r); + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_ONE_CNF2__REG, + &v_data2_u8r, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + + return com_rslt; +} + /*! +* @brief This API read enable step counter +* from the register 0x7B bit 3 +* +* +* @param v_step_counter_u8 : The value of step counter enable +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_step_counter_enable( +u8*v_step_counter_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the step counter*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_step_counter_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE); + } + return com_rslt; +} + /*! +* @brief This API write enable step counter +* from the register 0x7B bit 3 +* +* +* @param v_step_counter_u8 : The value of step counter enable +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_counter_enable(u8 v_step_counter_u8) +{ +/* variable used for return the status of communication result*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_data_u8 = SMI130_INIT_VALUE; +/* check the p_smi130 structure as NULL*/ +if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; +} else { + if (v_step_counter_u8 <= SMI130_MAX_GYRO_STEP_COUNTER) { + /* write the step counter*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE, + v_step_counter_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } +} + return com_rslt; +} + /*! +* @brief This API set Step counter modes +* +* +* @param v_step_mode_u8 : The value of step counter mode +* value | mode +* ----------|----------- +* 0 | SMI130_STEP_NORMAL_MODE +* 1 | SMI130_STEP_SENSITIVE_MODE +* 2 | SMI130_STEP_ROBUST_MODE +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_mode(u8 v_step_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + + switch (v_step_mode_u8) { + case SMI130_STEP_NORMAL_MODE: + com_rslt = smi130_set_step_config( + STEP_CONFIG_NORMAL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_STEP_SENSITIVE_MODE: + com_rslt = smi130_set_step_config( + STEP_CONFIG_SENSITIVE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_STEP_ROBUST_MODE: + com_rslt = smi130_set_step_config( + STEP_CONFIG_ROBUST); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + + return com_rslt; +} +/*! +* @brief This API used to trigger the signification motion +* interrupt +* +* +* @param v_significant_u8 : The value of interrupt selection +* value | interrupt +* ----------|----------- +* 0 | SMI130_MAP_INTR1 +* 1 | SMI130_MAP_INTR2 +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_map_significant_motion_intr( +u8 v_significant_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_sig_motion_u8 = SMI130_INIT_VALUE; + u8 v_data_u8 = SMI130_INIT_VALUE; + u8 v_any_motion_intr1_stat_u8 = SMI130_ENABLE_ANY_MOTION_INTR1; + u8 v_any_motion_intr2_stat_u8 = SMI130_ENABLE_ANY_MOTION_INTR2; + u8 v_any_motion_axis_stat_u8 = SMI130_ENABLE_ANY_MOTION_AXIS; + /* enable the significant motion interrupt*/ + com_rslt = smi130_get_intr_significant_motion_select(&v_sig_motion_u8); + if (v_sig_motion_u8 != SMI130_SIG_MOTION_STAT_HIGH) + com_rslt += smi130_set_intr_significant_motion_select( + SMI130_SIG_MOTION_INTR_ENABLE); + switch (v_significant_u8) { + case SMI130_MAP_INTR1: + /* interrupt*/ + com_rslt += smi130_read_reg( + SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_intr1_stat_u8; + /* map the signification interrupt to any-motion interrupt1*/ + com_rslt += smi130_write_reg( + SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* axis*/ + com_rslt = smi130_read_reg(SMI130_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_axis_stat_u8; + com_rslt += smi130_write_reg( + SMI130_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + + case SMI130_MAP_INTR2: + /* map the signification interrupt to any-motion interrupt2*/ + com_rslt += smi130_read_reg( + SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_intr2_stat_u8; + com_rslt += smi130_write_reg( + SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* axis*/ + com_rslt = smi130_read_reg(SMI130_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_axis_stat_u8; + com_rslt += smi130_write_reg( + SMI130_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + + } + return com_rslt; +} +/*! +* @brief This API used to trigger the step detector +* interrupt +* +* +* @param v_step_detector_u8 : The value of interrupt selection +* value | interrupt +* ----------|----------- +* 0 | SMI130_MAP_INTR1 +* 1 | SMI130_MAP_INTR2 +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_map_step_detector_intr( +u8 v_step_detector_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_step_det_u8 = SMI130_INIT_VALUE; + u8 v_data_u8 = SMI130_INIT_VALUE; + u8 v_low_g_intr_u81_stat_u8 = SMI130_LOW_G_INTR_STAT; + u8 v_low_g_intr_u82_stat_u8 = SMI130_LOW_G_INTR_STAT; + u8 v_low_g_enable_u8 = SMI130_ENABLE_LOW_G; + /* read the v_status_s8 of step detector interrupt*/ + com_rslt = smi130_get_step_detector_enable(&v_step_det_u8); + if (v_step_det_u8 != SMI130_STEP_DET_STAT_HIGH) + com_rslt += smi130_set_step_detector_enable( + SMI130_STEP_DETECT_INTR_ENABLE); + switch (v_step_detector_u8) { + case SMI130_MAP_INTR1: + com_rslt += smi130_read_reg( + SMI130_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_low_g_intr_u81_stat_u8; + /* map the step detector interrupt + to Low-g interrupt 1*/ + com_rslt += smi130_write_reg( + SMI130_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Enable the Low-g interrupt*/ + com_rslt = smi130_read_reg( + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_low_g_enable_u8; + com_rslt += smi130_write_reg( + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_MAP_INTR2: + /* map the step detector interrupt + to Low-g interrupt 1*/ + com_rslt += smi130_read_reg( + SMI130_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_low_g_intr_u82_stat_u8; + + com_rslt += smi130_write_reg( + SMI130_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Enable the Low-g interrupt*/ + com_rslt = smi130_read_reg( + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_low_g_enable_u8; + com_rslt += smi130_write_reg( + SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + return com_rslt; +} + /*! +* @brief This API used to clear the step counter interrupt +* interrupt +* +* +* @param : None +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_clear_step_counter(void) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* clear the step counter*/ + com_rslt = smi130_set_command_register(RESET_STEP_COUNTER); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + + return com_rslt; + +} + /*! +* @brief This API writes value to the register 0x7E bit 0 to 7 +* +* +* @param v_command_reg_u8 : The value to write command register +* value | Description +* ---------|-------------------------------------------------------- +* 0x00 | Reserved +* 0x03 | Starts fast offset calibration for the accel and gyro +* 0x10 | Sets the PMU mode for the Accelerometer to suspend +* 0x11 | Sets the PMU mode for the Accelerometer to normal +* 0x12 | Sets the PMU mode for the Accelerometer Lowpower +* 0x14 | Sets the PMU mode for the Gyroscope to suspend +* 0x15 | Sets the PMU mode for the Gyroscope to normal +* 0x16 | Reserved +* 0x17 | Sets the PMU mode for the Gyroscope to fast start-up +* 0x18 | Sets the PMU mode for the Magnetometer to suspend +* 0x19 | Sets the PMU mode for the Magnetometer to normal +* 0x1A | Sets the PMU mode for the Magnetometer to Lowpower +* 0xB0 | Clears all data in the FIFO +* 0xB1 | Resets the interrupt engine +* 0xB2 | step_cnt_clr Clears the step counter +* 0xB6 | Triggers a reset +* 0x37 | See extmode_en_last +* 0x9A | See extmode_en_last +* 0xC0 | Enable the extended mode +* 0xC4 | Erase NVM cell +* 0xC8 | Load NVM cell +* 0xF0 | Reset acceleration data path +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_command_register(u8 v_command_reg_u8) +{ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write command register*/ + com_rslt = p_smi130->SMI130_BUS_WRITE_FUNC( + p_smi130->dev_addr, + SMI130_CMD_COMMANDS__REG, + &v_command_reg_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + return com_rslt; +} + /*! +* @brief This API read target page from the register 0x7F bit 4 and 5 +* +* @param v_target_page_u8: The value of target page +* value | page +* ---------|----------- +* 0 | User data/configure page +* 1 | Chip level trim/test page +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_target_page(u8*v_target_page_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the page*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_CMD_TARGET_PAGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_target_page_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_CMD_TARGET_PAGE); + } + return com_rslt; +} + /*! +* @brief This API write target page from the register 0x7F bit 4 and 5 +* +* @param v_target_page_u8: The value of target page +* value | page +* ---------|----------- +* 0 | User data/configure page +* 1 | Chip level trim/test page +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_target_page(u8 v_target_page_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_target_page_u8 <= SMI130_MAX_TARGET_PAGE) { + /* write the page*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_CMD_TARGET_PAGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_CMD_TARGET_PAGE, + v_target_page_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_CMD_TARGET_PAGE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API read page enable from the register 0x7F bit 7 +* +* +* +* @param v_page_enable_u8: The value of page enable +* value | page +* ---------|----------- +* 0 | DISABLE +* 1 | ENABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_paging_enable(u8*v_page_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the page enable*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_CMD_PAGING_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_page_enable_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_CMD_PAGING_EN); + } + return com_rslt; +} + /*! +* @brief This API write page enable from the register 0x7F bit 7 +* +* +* +* @param v_page_enable_u8: The value of page enable +* value | page +* ---------|----------- +* 0 | DISABLE +* 1 | ENABLE +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_paging_enable( +u8 v_page_enable_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + if (v_page_enable_u8 <= SMI130_MAX_VALUE_PAGE) { + /* write the page enable*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_CMD_PAGING_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_CMD_PAGING_EN, + v_page_enable_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_CMD_PAGING_EN__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_SMI130_OUT_OF_RANGE; + } + } + return com_rslt; +} + /*! +* @brief This API read +* pull up configuration from the register 0X85 bit 4 an 5 +* +* +* +* @param v_control_pullup_u8: The value of pull up register +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_pullup_configuration( +u8*v_control_pullup_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read pull up value*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC( + p_smi130->dev_addr, + SMI130_COM_C_TRIM_FIVE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + *v_control_pullup_u8 = SMI130_GET_BITSLICE(v_data_u8, + SMI130_COM_C_TRIM_FIVE); + } + return com_rslt; + +} + /*! +* @brief This API write +* pull up configuration from the register 0X85 bit 4 an 5 +* +* +* +* @param v_control_pullup_u8: The value of pull up register +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_pullup_configuration( +u8 v_control_pullup_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* write pull up value*/ + com_rslt = p_smi130->SMI130_BUS_READ_FUNC + (p_smi130->dev_addr, + SMI130_COM_C_TRIM_FIVE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + SMI130_SET_BITSLICE(v_data_u8, + SMI130_COM_C_TRIM_FIVE, + v_control_pullup_u8); + com_rslt += + p_smi130->SMI130_BUS_WRITE_FUNC + (p_smi130->dev_addr, + SMI130_COM_C_TRIM_FIVE__REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + } + } + return com_rslt; +} + +/*! +* @brief This function used for read the compensated value of mag +* Before start reading the mag compensated data's +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_compensate_xyz( +struct smi130_mag_xyz_s32_t*mag_comp_xyz) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + struct smi130_mag_xyzr_t mag_xyzr; + com_rslt = smi130_read_mag_xyzr(&mag_xyzr); + if (com_rslt) + return com_rslt; + /* Compensation for X axis*/ + mag_comp_xyz->x = smi130_bmm150_mag_compensate_X( + mag_xyzr.x, mag_xyzr.r); + + /* Compensation for Y axis*/ + mag_comp_xyz->y = smi130_bmm150_mag_compensate_Y( + mag_xyzr.y, mag_xyzr.r); + + /* Compensation for Z axis*/ + mag_comp_xyz->z = smi130_bmm150_mag_compensate_Z( + mag_xyzr.z, mag_xyzr.r); + + return com_rslt; +} + +/*! +* @brief This function used for read the compensated value of mag +* Before start reading the mag compensated data's +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_compensate_xyz_raw( +struct smi130_mag_xyz_s32_t*mag_comp_xyz, struct smi130_mag_xyzr_t mag_xyzr) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + + /* Compensation for X axis*/ + mag_comp_xyz->x = smi130_bmm150_mag_compensate_X( + mag_xyzr.x, mag_xyzr.r); + + /* Compensation for Y axis*/ + mag_comp_xyz->y = smi130_bmm150_mag_compensate_Y( + mag_xyzr.y, mag_xyzr.r); + + /* Compensation for Z axis*/ + mag_comp_xyz->z = smi130_bmm150_mag_compensate_Z( + mag_xyzr.z, mag_xyzr.r); + + return com_rslt; +} +/*! +* @brief This API used to get the compensated BMM150-X data +* the out put of X as s32 +* Before start reading the mag compensated X data +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* +* @param v_mag_data_x_s16 : The value of mag raw X data +* @param v_data_r_u16 : The value of mag R data +* +* @return results of compensated X data value output as s32 +* +*/ +s32 smi130_bmm150_mag_compensate_X(s16 v_mag_data_x_s16, u16 v_data_r_u16) +{ +s32 inter_retval = SMI130_INIT_VALUE; +/* no overflow*/ +if (v_mag_data_x_s16 != SMI130_MAG_FLIP_OVERFLOW_ADCVAL) { + if ((v_data_r_u16 != 0) + && (mag_trim.dig_xyz1 != 0)) { + inter_retval = ((s32)(((u16) + ((((s32)mag_trim.dig_xyz1) + << SMI130_SHIFT_BIT_POSITION_BY_14_BITS)/ + (v_data_r_u16 != 0 ? + v_data_r_u16 : mag_trim.dig_xyz1))) - + ((u16)0x4000))); + } else { + inter_retval = SMI130_MAG_OVERFLOW_OUTPUT; + return inter_retval; + } + inter_retval = ((s32)((((s32)v_mag_data_x_s16)* + ((((((((s32)mag_trim.dig_xy2)* + ((((s32)inter_retval)* + ((s32)inter_retval)) + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS)) + + (((s32)inter_retval)* + ((s32)(((s16)mag_trim.dig_xy1) + << SMI130_SHIFT_BIT_POSITION_BY_07_BITS)))) + >> SMI130_SHIFT_BIT_POSITION_BY_09_BITS) + + ((s32)0x100000))* + ((s32)(((s16)mag_trim.dig_x2) + + ((s16)0xA0)))) + >> SMI130_SHIFT_BIT_POSITION_BY_12_BITS)) + >> SMI130_SHIFT_BIT_POSITION_BY_13_BITS)) + + (((s16)mag_trim.dig_x1) + << SMI130_SHIFT_BIT_POSITION_BY_03_BITS); + /* check the overflow output*/ + if (inter_retval == (s32)SMI130_MAG_OVERFLOW_OUTPUT) + inter_retval = SMI130_MAG_OVERFLOW_OUTPUT_S32; +} else { + /* overflow*/ + inter_retval = SMI130_MAG_OVERFLOW_OUTPUT; +} +return inter_retval; +} +/*! +* @brief This API used to get the compensated BMM150-Y data +* the out put of Y as s32 +* Before start reading the mag compensated Y data +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* +* @param v_mag_data_y_s16 : The value of mag raw Y data +* @param v_data_r_u16 : The value of mag R data +* +* @return results of compensated Y data value output as s32 +*/ +s32 smi130_bmm150_mag_compensate_Y(s16 v_mag_data_y_s16, u16 v_data_r_u16) +{ +s32 inter_retval = SMI130_INIT_VALUE; +/* no overflow*/ +if (v_mag_data_y_s16 != SMI130_MAG_FLIP_OVERFLOW_ADCVAL) { + if ((v_data_r_u16 != 0) + && (mag_trim.dig_xyz1 != 0)) { + inter_retval = ((s32)(((u16)((( + (s32)mag_trim.dig_xyz1) + << SMI130_SHIFT_BIT_POSITION_BY_14_BITS) / + (v_data_r_u16 != 0 ? + v_data_r_u16 : mag_trim.dig_xyz1))) - + ((u16)0x4000))); + } else { + inter_retval = SMI130_MAG_OVERFLOW_OUTPUT; + return inter_retval; + } + inter_retval = ((s32)((((s32)v_mag_data_y_s16)* ((((((((s32) + mag_trim.dig_xy2)* ((((s32) inter_retval)* + ((s32)inter_retval)) >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS)) + + (((s32)inter_retval)* + ((s32)(((s16)mag_trim.dig_xy1) + << SMI130_SHIFT_BIT_POSITION_BY_07_BITS)))) + >> SMI130_SHIFT_BIT_POSITION_BY_09_BITS) + + ((s32)0x100000)) + * ((s32)(((s16)mag_trim.dig_y2) + + ((s16)0xA0)))) + >> SMI130_SHIFT_BIT_POSITION_BY_12_BITS)) + >> SMI130_SHIFT_BIT_POSITION_BY_13_BITS)) + + (((s16)mag_trim.dig_y1) + << SMI130_SHIFT_BIT_POSITION_BY_03_BITS); + /* check the overflow output*/ + if (inter_retval == (s32)SMI130_MAG_OVERFLOW_OUTPUT) + inter_retval = SMI130_MAG_OVERFLOW_OUTPUT_S32; +} else { + /* overflow*/ + inter_retval = SMI130_MAG_OVERFLOW_OUTPUT; +} +return inter_retval; +} +/*! +* @brief This API used to get the compensated BMM150-Z data +* the out put of Z as s32 +* Before start reading the mag compensated Z data +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* +* @param v_mag_data_z_s16 : The value of mag raw Z data +* @param v_data_r_u16 : The value of mag R data +* +* @return results of compensated Z data value output as s32 +*/ +s32 smi130_bmm150_mag_compensate_Z(s16 v_mag_data_z_s16, u16 v_data_r_u16) +{ + s32 retval = SMI130_INIT_VALUE; + + if (v_mag_data_z_s16 != SMI130_MAG_HALL_OVERFLOW_ADCVAL) { + if ((v_data_r_u16 != 0) + && (mag_trim.dig_z2 != 0) + /* && (mag_trim.dig_z3 != 0)*/ + && (mag_trim.dig_z1 != 0) + && (mag_trim.dig_xyz1 != 0)) { + retval = (((((s32)(v_mag_data_z_s16 - mag_trim.dig_z4)) + << SMI130_SHIFT_BIT_POSITION_BY_15_BITS) - + ((((s32)mag_trim.dig_z3)* + ((s32)(((s16)v_data_r_u16) - + ((s16)mag_trim.dig_xyz1)))) + >> SMI130_SHIFT_BIT_POSITION_BY_02_BITS))/ + (mag_trim.dig_z2 + + ((s16)(((((s32)mag_trim.dig_z1)* + ((((s16)v_data_r_u16) + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT))) + + (1 << SMI130_SHIFT_BIT_POSITION_BY_15_BITS)) + >> SMI130_SHIFT_BIT_POSITION_BY_16_BITS)))); + } + } else { + retval = SMI130_MAG_OVERFLOW_OUTPUT; + } + return retval; +} + /*! +* @brief This function used for initialize the bmm150 sensor +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_interface_init(void) +{ + /* This variable used for provide the communication + results*/ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + u8 v_pull_value_u8 = SMI130_INIT_VALUE; + u8 v_data_u8 = SMI130_INIT_VALUE; + /* accel operation mode to normal*/ + com_rslt = smi130_set_command_register(ACCEL_MODE_NORMAL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* write the mag power mode as NORMAL*/ + com_rslt += smi130_set_mag_interface_normal(); + + /* register 0x7E write the 0x37, 0x9A and 0x30*/ + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_ONE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_TWO); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_THREE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /*switch the page1*/ + com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_target_page(&v_data_u8); + com_rslt += smi130_set_paging_enable(SMI130_WRITE_ENABLE_PAGE1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_paging_enable(&v_data_u8); + /* enable the pullup configuration from + the register 0x05 bit 4 and 5 as 10*/ + smi130_get_pullup_configuration(&v_pull_value_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + v_pull_value_u8 = v_pull_value_u8 | SMI130_PULL_UP_DATA; + com_rslt += smi130_set_pullup_configuration(v_pull_value_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /*switch the page0*/ + com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE0); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_target_page(&v_data_u8); + /* Write the BMM150 i2c address*/ + com_rslt += smi130_set_i2c_device_addr(SMI130_AUX_BMM150_I2C_ADDRESS); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* enable the mag interface to manual mode*/ + com_rslt += smi130_set_mag_manual_enable(SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_mag_manual_enable(&v_data_u8); + /*Enable the MAG interface*/ + com_rslt += smi130_set_if_mode(SMI130_ENABLE_MAG_IF_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_if_mode(&v_data_u8); + /* Mag normal mode*/ + com_rslt += smi130_bmm150_mag_wakeup(); + printk(KERN_INFO "com_rslt:%d, <%s><%d>\n", + com_rslt, __func__, __LINE__); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Read the BMM150 device id is 0x32*/ + /*com_rslt += smi130_set_mag_read_addr(SMI130_BMM150_CHIP_ID);*/ + /*p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY);*/ + /*com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH);*/ + /**v_chip_id_u8 = v_data_u8;*/ + /*p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY);*/ + /* write the power mode register*/ + com_rslt += smi130_set_mag_write_data(SMI130_BMM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /*write 0x4C register to write set power mode to normal*/ + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_MODE_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* read the mag trim values*/ + com_rslt += smi130_read_bmm150_mag_trim(); + printk(KERN_INFO "com_rslt:%d, <%s><%d>\n", + com_rslt, __func__, __LINE__); + /* To avoid the auto mode enable when manual mode operation running*/ + V_bmm150_maual_auto_condition_u8 = SMI130_MANUAL_ENABLE; + /* write the XY and Z repetitions*/ + com_rslt += smi130_set_bmm150_mag_presetmode( + SMI130_MAG_PRESETMODE_REGULAR); + printk(KERN_INFO "com_rslt:%d, <%s><%d>\n", + com_rslt, __func__, __LINE__); + /* To avoid the auto mode enable when manual mode operation running*/ + V_bmm150_maual_auto_condition_u8 = SMI130_MANUAL_DISABLE; + /* Set the power mode of mag as force mode*/ + /* The data have to write for the register + It write the value in the register 0x4F*/ + com_rslt += smi130_set_mag_write_data(SMI130_BMM150_FORCE_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + printk(KERN_INFO "com_rslt:%d, <%s><%d>\n", + com_rslt, __func__, __LINE__); + /* write into power mode register*/ + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_MODE_REG); + /* write the mag v_data_bw_u8 as 25Hz*/ + com_rslt += smi130_set_mag_output_data_rate( + SMI130_MAG_OUTPUT_DATA_RATE_25HZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + /* When mag interface is auto mode - The mag read address + starts the register 0x42*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_BMM150_DATA_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* enable mag interface to auto mode*/ + com_rslt += smi130_set_mag_manual_enable(SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_mag_manual_enable(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + return com_rslt; +} + /*! +* @brief This function used for set the mag power control +* bit enable +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_wakeup(void) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + u8 v_try_times_u8 = SMI130_BMM150_MAX_RETRY_WAKEUP; + u8 v_power_control_bit_u8 = SMI130_INIT_VALUE; + u8 i = SMI130_INIT_VALUE; + + for (i = SMI130_INIT_VALUE; i < v_try_times_u8; i++) { + com_rslt = smi130_set_mag_write_data(SMI130_BMM150_POWER_ON); + p_smi130->delay_msec(SMI130_BMM150_WAKEUP_DELAY1); + /*write 0x4B register to enable power control bit*/ + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_CONTROL_REG); + p_smi130->delay_msec(SMI130_BMM150_WAKEUP_DELAY2); + com_rslt += smi130_set_mag_read_addr( + SMI130_BMM150_POWE_CONTROL_REG); + /* 0x04 is secondary read mag x lsb register*/ + p_smi130->delay_msec(SMI130_BMM150_WAKEUP_DELAY3); + com_rslt += smi130_read_reg(SMI130_USER_DATA_0_ADDR, + &v_power_control_bit_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + v_power_control_bit_u8 = SMI130_BMM150_SET_POWER_CONTROL + & v_power_control_bit_u8; + if (v_power_control_bit_u8 == SMI130_BMM150_POWER_ON) + break; + } + com_rslt = (i >= v_try_times_u8) ? + SMI130_BMM150_POWER_ON_FAIL : SMI130_BMM150_POWER_ON_SUCCESS; + return com_rslt; +} + /*! +* @brief This function used for set the magnetometer +* power mode. +* @note +* Before set the mag power mode +* make sure the following two point is addressed +* Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* +* @param v_mag_sec_if_pow_mode_u8 : The value of mag power mode +* value | mode +* ----------|------------ +* 0 | SMI130_MAG_FORCE_MODE +* 1 | SMI130_MAG_SUSPEND_MODE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_bmm150_mag_and_secondary_if_power_mode( +u8 v_mag_sec_if_pow_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + /* set the accel power mode to NORMAL*/ + com_rslt = smi130_set_command_register(ACCEL_MODE_NORMAL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + /* set mag interface manual mode*/ + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) { + com_rslt += smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + + switch (v_mag_sec_if_pow_mode_u8) { + case SMI130_MAG_FORCE_MODE: + /* set the secondary mag power mode as NORMAL*/ + com_rslt += smi130_set_mag_interface_normal(); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + /* set the mag power mode as FORCE mode*/ + com_rslt += smi130_bmm150_mag_set_power_mode(FORCE_MODE); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_MAG_SUSPEND_MODE: + /* set the mag power mode as SUSPEND mode*/ + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + com_rslt += smi130_bmm150_mag_set_power_mode(SUSPEND_MODE); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* set the secondary mag power mode as SUSPEND*/ + com_rslt += smi130_set_command_register(MAG_MODE_SUSPEND); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) { + /* set mag interface auto mode*/ + com_rslt += smi130_set_mag_manual_enable( + SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + return com_rslt; +} +/*! +* @brief This function used for set the magnetometer +* power mode. +* @note +* Before set the mag power mode +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* @param v_mag_pow_mode_u8 : The value of mag power mode +* value | mode +* ----------|------------ +* 0 | FORCE_MODE +* 1 | SUSPEND_MODE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_set_power_mode( +u8 v_mag_pow_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + u8 manual_enable_status = 0; + /* set mag interface manual mode*/ + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) { + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_get_mag_manual_enable(&manual_enable_status); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + printk(KERN_INFO "1com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_smi130->mag_manual_enable, manual_enable_status); + } + printk(KERN_INFO "2com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_smi130->mag_manual_enable, manual_enable_status); + + switch (v_mag_pow_mode_u8) { + case FORCE_MODE: + /* Set the power control bit enabled*/ + com_rslt = smi130_bmm150_mag_wakeup(); + /* write the mag power mode as FORCE mode*/ + com_rslt += smi130_set_mag_write_data( + SMI130_BMM150_FORCE_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* To avoid the auto mode enable when manual + mode operation running*/ + V_bmm150_maual_auto_condition_u8 = SMI130_MANUAL_ENABLE; + /* set the preset mode*/ + com_rslt += smi130_set_bmm150_mag_presetmode( + SMI130_MAG_PRESETMODE_REGULAR); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* To avoid the auto mode enable when manual + mode operation running*/ + V_bmm150_maual_auto_condition_u8 = SMI130_MANUAL_DISABLE; + /* set the mag read address to data registers*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_BMM150_DATA_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SUSPEND_MODE: + printk(KERN_INFO "3com_rslt:%d, manual:%d, read_manual:%d\n", + com_rslt, p_smi130->mag_manual_enable, manual_enable_status); + /* Set the power mode of mag as suspend mode*/ + com_rslt += smi130_set_mag_write_data( + SMI130_BMM150_POWER_OFF); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_CONTROL_REG); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + printk(KERN_INFO "4com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_smi130->mag_manual_enable, manual_enable_status); + /* set mag interface auto mode*/ + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) { + com_rslt += smi130_set_mag_manual_enable( + SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_get_mag_manual_enable(&manual_enable_status); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "5com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_smi130->mag_manual_enable, manual_enable_status); + return com_rslt; +} +/*! +* @brief This API used to set the pre-set modes of bmm150 +* The pre-set mode setting is depend on data rate and xy and z repetitions +* +* @note +* Before set the mag preset mode +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* @param v_mode_u8: The value of pre-set mode selection value +* value | pre_set mode +* ----------|------------ +* 1 | SMI130_MAG_PRESETMODE_LOWPOWER +* 2 | SMI130_MAG_PRESETMODE_REGULAR +* 3 | SMI130_MAG_PRESETMODE_HIGHACCURACY +* 4 | SMI130_MAG_PRESETMODE_ENHANCED +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_bmm150_mag_presetmode(u8 v_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + switch (v_mode_u8) { + case SMI130_MAG_PRESETMODE_LOWPOWER: + /* write the XY and Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt = smi130_set_mag_write_data( + SMI130_MAG_LOWPOWER_REPXY); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_XY_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* write the Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_LOWPOWER_REPZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_Z_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 10 to the register 0x4C*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_LOWPOWER_DR); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_MODE_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_MAG_PRESETMODE_REGULAR: + /* write the XY and Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt = smi130_set_mag_write_data( + SMI130_MAG_REGULAR_REPXY); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_XY_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* write the Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_REGULAR_REPZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_Z_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 10 to the register 0x4C*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_REGULAR_DR); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_MODE_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_MAG_PRESETMODE_HIGHACCURACY: + /* write the XY and Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt = smi130_set_mag_write_data( + SMI130_MAG_HIGHACCURACY_REPXY); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_XY_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* write the Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_HIGHACCURACY_REPZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_Z_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 20 to the register 0x4C*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_HIGHACCURACY_DR); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_MODE_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_MAG_PRESETMODE_ENHANCED: + /* write the XY and Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt = smi130_set_mag_write_data( + SMI130_MAG_ENHANCED_REPXY); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_XY_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* write the Z repetitions*/ + /* The v_data_u8 have to write for the register + It write the value in the register 0x4F*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_ENHANCED_REPZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_Z_REP); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 10 to the register 0x4C*/ + com_rslt += smi130_set_mag_write_data( + SMI130_MAG_ENHANCED_DR); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + SMI130_BMM150_POWE_MODE_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + + return com_rslt; +} + /*! +* @brief This function used for read the trim values of magnetometer +* +* @note +* Before reading the mag trimming values +* make sure the following two points are addressed +* @note +* 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note +* 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_bmm150_mag_trim(void) +{ + /* This variable used for provide the communication + results*/ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array holding the bmm150 trim data + */ + u8 v_data_u8[SMI130_MAG_TRIM_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE}; + /* read dig_x1 value*/ + com_rslt = smi130_set_mag_read_addr( + SMI130_MAG_DIG_X1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_X1], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_x1 = v_data_u8[SMI130_BMM150_DIG_X1]; + /* read dig_y1 value*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_MAG_DIG_Y1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_Y1], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_y1 = v_data_u8[SMI130_BMM150_DIG_Y1]; + + /* read dig_x2 value*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_MAG_DIG_X2); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_X2], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_x2 = v_data_u8[SMI130_BMM150_DIG_X2]; + /* read dig_y2 value*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_MAG_DIG_Y2); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_Y3], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_y2 = v_data_u8[SMI130_BMM150_DIG_Y3]; + + /* read dig_xy1 value*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_MAG_DIG_XY1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_XY1], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_xy1 = v_data_u8[SMI130_BMM150_DIG_XY1]; + /* read dig_xy2 value*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_MAG_DIG_XY2); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 ls register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_XY2], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_xy2 = v_data_u8[SMI130_BMM150_DIG_XY2]; + + /* read dig_z1 lsb value*/ + com_rslt += smi130_set_mag_read_addr( + SMI130_MAG_DIG_Z1_LSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_Z1_LSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* read dig_z1 msb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_Z1_MSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_Z1_MSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_z1 = + (u16)((((u32)((u8)v_data_u8[SMI130_BMM150_DIG_Z1_MSB])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_BMM150_DIG_Z1_LSB])); + + /* read dig_z2 lsb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_Z2_LSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_Z2_LSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* read dig_z2 msb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_Z2_MSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_Z2_MSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_z2 = + (s16)((((s32)((s8)v_data_u8[SMI130_BMM150_DIG_Z2_MSB])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_BMM150_DIG_Z2_LSB])); + + /* read dig_z3 lsb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_Z3_LSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_DIG_Z3_LSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* read dig_z3 msb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_Z3_MSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_DIG_Z3_MSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_z3 = + (s16)((((s32)((s8)v_data_u8[SMI130_BMM150_DIG_DIG_Z3_MSB])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_BMM150_DIG_DIG_Z3_LSB])); + + /* read dig_z4 lsb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_Z4_LSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_DIG_Z4_LSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* read dig_z4 msb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_Z4_MSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_DIG_Z4_MSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_z4 = + (s16)((((s32)((s8)v_data_u8[SMI130_BMM150_DIG_DIG_Z4_MSB])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_BMM150_DIG_DIG_Z4_LSB])); + + /* read dig_xyz1 lsb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_XYZ1_LSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_DIG_XYZ1_LSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* read dig_xyz1 msb value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_MAG_DIG_XYZ1_MSB); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[SMI130_BMM150_DIG_DIG_XYZ1_MSB], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + mag_trim.dig_xyz1 = + (u16)((((u32)((u8)v_data_u8[SMI130_BMM150_DIG_DIG_XYZ1_MSB])) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[SMI130_BMM150_DIG_DIG_XYZ1_LSB])); + + return com_rslt; +} + /*! +* @brief This function used for initialize +* the AKM09911 and AKM09912 sensor +* +* +* @param v_akm_i2c_address_u8: The value of device address +* AKM sensor | Slave address +* --------------|--------------------- +* AKM09911 | AKM09911_I2C_ADDR_1 +* - | and AKM09911_I2C_ADDR_2 +* AKM09912 | AKM09912_I2C_ADDR_1 +* - | AKM09912_I2C_ADDR_2 +* - | AKM09912_I2C_ADDR_3 +* - | AKM09912_I2C_ADDR_4 +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm_mag_interface_init( +u8 v_akm_i2c_address_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_pull_value_u8 = SMI130_INIT_VALUE; + u8 v_data_u8 = SMI130_INIT_VALUE; + u8 v_akm_chip_id_u8 = SMI130_INIT_VALUE; + /* accel operation mode to normal*/ + com_rslt = smi130_set_command_register(ACCEL_MODE_NORMAL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_command_register(MAG_MODE_NORMAL); + p_smi130->delay_msec(SMI130_AKM_INIT_DELAY); + smi130_get_mag_power_mode_stat(&v_data_u8); + /* register 0x7E write the 0x37, 0x9A and 0x30*/ + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_ONE); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_TWO); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_THREE); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /*switch the page1*/ + com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_target_page(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_paging_enable(SMI130_WRITE_ENABLE_PAGE1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_paging_enable(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* enable the pullup configuration from + the register 0x05 bit 4 and 5 to 10*/ + smi130_get_pullup_configuration(&v_pull_value_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + v_pull_value_u8 = v_pull_value_u8 | SMI130_PULL_UP_DATA; + com_rslt += smi130_set_pullup_configuration(v_pull_value_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + /*switch the page0*/ + com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE0); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_target_page(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Write the AKM09911 0r AKM09912 i2c address*/ + com_rslt += smi130_set_i2c_device_addr(v_akm_i2c_address_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* enable the mag interface to manual mode*/ + com_rslt += smi130_set_mag_manual_enable(SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_mag_manual_enable(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /*Enable the MAG interface*/ + com_rslt += smi130_set_if_mode(SMI130_ENABLE_MAG_IF_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_if_mode(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + /* Set the AKM Fuse ROM mode*/ + /* Set value for fuse ROM mode*/ + com_rslt += smi130_set_mag_write_data(AKM_FUSE_ROM_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* AKM mode address is 0x31*/ + com_rslt += smi130_set_mag_write_addr(AKM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Read the Fuse ROM v_data_u8 from registers + 0x60,0x61 and 0x62*/ + /* ASAX v_data_u8*/ + com_rslt += smi130_read_bosch_akm_sensitivity_data(); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* read the device id of the AKM sensor + if device id is 0x05 - AKM09911 + if device id is 0x04 - AKM09912*/ + com_rslt += smi130_set_mag_read_addr(AKM09912_CHIP_ID_REG); + /* 0x04 is mag_x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_akm_chip_id_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + printk(KERN_INFO "smi130,addr:0x%x, akm_chip_id:0x%x", + v_akm_i2c_address_u8, v_akm_chip_id_u8); + /* Set value power down mode mode*/ + com_rslt += smi130_set_mag_write_data(AKM_POWER_DOWN_MODE_DATA); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* AKM mode address is 0x31*/ + com_rslt += smi130_set_mag_write_addr(AKM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Set AKM Force mode*/ + com_rslt += smi130_set_mag_write_data( + AKM_SINGLE_MEASUREMENT_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* AKM mode address is 0x31*/ + com_rslt += smi130_set_mag_write_addr(AKM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Set the AKM read xyz v_data_u8 address*/ + com_rslt += smi130_set_mag_read_addr(AKM_DATA_REGISTER); + /* write the mag v_data_bw_u8 as 25Hz*/ + com_rslt += smi130_set_mag_output_data_rate( + SMI130_MAG_OUTPUT_DATA_RATE_25HZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Enable mag interface to auto mode*/ + com_rslt += smi130_set_mag_manual_enable(SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_mag_manual_enable(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + return com_rslt; +} + /*! +* @brief This function used for read the sensitivity data of +* AKM09911 and AKM09912 +* +* @note Before reading the mag sensitivity values +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_bosch_akm_sensitivity_data(void) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array holding the sensitivity ax,ay and az data*/ + u8 v_data_u8[SMI130_AKM_SENSITIVITY_DATA_SIZE] = { + SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* read asax value*/ + com_rslt = smi130_set_mag_read_addr(SMI130_BST_AKM_ASAX); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[AKM_ASAX], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + akm_asa_data.asax = v_data_u8[AKM_ASAX]; + /* read asay value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_BST_AKM_ASAY); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[AKM_ASAY], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + akm_asa_data.asay = v_data_u8[AKM_ASAY]; + /* read asaz value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_BST_AKM_ASAZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[AKM_ASAZ], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + akm_asa_data.asaz = v_data_u8[AKM_ASAZ]; + + return com_rslt; +} +/*! +* @brief This API used to get the compensated X data +* of AKM09911 the out put of X as s32 +* @note Before start reading the mag compensated X data +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* @param v_bosch_akm_x_s16 : The value of X data +* +* @return results of compensated X data value output as s32 +* +*/ +s32 smi130_bosch_akm09911_compensate_X(s16 v_bosch_akm_x_s16) +{ + /*Return value of AKM x compensated v_data_u8*/ + s32 retval = SMI130_INIT_VALUE; + /* Convert raw v_data_u8 into compensated v_data_u8*/ + retval = (v_bosch_akm_x_s16* + ((akm_asa_data.asax/AKM09911_SENSITIVITY_DIV) + + SMI130_GEN_READ_WRITE_DATA_LENGTH)); + return retval; +} +/*! +* @brief This API used to get the compensated Y data +* of AKM09911 the out put of Y as s32 +* @note Before start reading the mag compensated Y data +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* @param v_bosch_akm_y_s16 : The value of Y data +* +* @return results of compensated Y data value output as s32 +* +*/ +s32 smi130_bosch_akm09911_compensate_Y(s16 v_bosch_akm_y_s16) +{ + /*Return value of AKM y compensated v_data_u8*/ + s32 retval = SMI130_INIT_VALUE; + /* Convert raw v_data_u8 into compensated v_data_u8*/ + retval = (v_bosch_akm_y_s16* + ((akm_asa_data.asay/AKM09911_SENSITIVITY_DIV) + + SMI130_GEN_READ_WRITE_DATA_LENGTH)); + return retval; +} +/*! +* @brief This API used to get the compensated Z data +* of AKM09911 the out put of Z as s32 +* @note Before start reading the mag compensated Z data +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* @param v_bosch_akm_z_s16 : The value of Z data +* +* @return results of compensated Z data value output as s32 +* +*/ +s32 smi130_bosch_akm09911_compensate_Z(s16 v_bosch_akm_z_s16) +{ + /*Return value of AKM z compensated v_data_u8*/ + s32 retval = SMI130_INIT_VALUE; + /* Convert raw v_data_u8 into compensated v_data_u8*/ + retval = (v_bosch_akm_z_s16* + ((akm_asa_data.asaz/AKM09911_SENSITIVITY_DIV) + + SMI130_GEN_READ_WRITE_DATA_LENGTH)); + return retval; +} +/*! +* @brief This API used to get the compensated X data +* of AKM09912 the out put of X as s32 +* @note Before start reading the mag compensated X data +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* @param v_bosch_akm_x_s16 : The value of X data +* +* @return results of compensated X data value output as s32 +* +*/ +s32 smi130_bosch_akm09912_compensate_X(s16 v_bosch_akm_x_s16) +{ + /*Return value of AKM x compensated data*/ + s32 retval = SMI130_INIT_VALUE; + /* Convert raw data into compensated data*/ + retval = v_bosch_akm_x_s16* + (akm_asa_data.asax + AKM09912_SENSITIVITY) + / AKM09912_SENSITIVITY_DIV; + return retval; +} +/*! +* @brief This API used to get the compensated Y data +* of AKM09912 the out put of Y as s32 +* @note Before start reading the mag compensated Y data +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* @param v_bosch_akm_y_s16 : The value of Y data +* +* @return results of compensated Y data value output as s32 +* +*/ +s32 smi130_bosch_akm09912_compensate_Y(s16 v_bosch_akm_y_s16) +{ + /*Return value of AKM y compensated data*/ + s32 retval = SMI130_INIT_VALUE; + /* Convert raw data into compensated data*/ + retval = v_bosch_akm_y_s16* + (akm_asa_data.asax + AKM09912_SENSITIVITY) + / AKM09912_SENSITIVITY_DIV; + return retval; +} +/*! +* @brief This API used to get the compensated Z data +* of AKM09912 the out put of Z as s32 +* @note Before start reading the mag compensated Z data +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* +* @param v_bosch_akm_z_s16 : The value of Z data +* +* @return results of compensated Z data value output as s32 +* +*/ +s32 smi130_bosch_akm09912_compensate_Z(s16 v_bosch_akm_z_s16) +{ + /*Return value of AKM z compensated data*/ + s32 retval = SMI130_INIT_VALUE; + /* Convert raw data into compensated data*/ + retval = v_bosch_akm_z_s16* + (akm_asa_data.asax + AKM09912_SENSITIVITY) + / AKM09912_SENSITIVITY_DIV; + return retval; +} + /*! +* @brief This function used for read the compensated value of +* AKM09911 +* @note Before start reading the mag compensated data's +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. + +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm09911_compensate_xyz( +struct smi130_mag_xyz_s32_t*bosch_akm_xyz) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + struct smi130_mag_t mag_xyz; + + com_rslt = smi130_read_mag_xyz(&mag_xyz, BST_AKM); + /* Compensation for X axis*/ + bosch_akm_xyz->x = smi130_bosch_akm09911_compensate_X(mag_xyz.x); + + /* Compensation for Y axis*/ + bosch_akm_xyz->y = smi130_bosch_akm09911_compensate_Y(mag_xyz.y); + + /* Compensation for Z axis*/ + bosch_akm_xyz->z = smi130_bosch_akm09911_compensate_Z(mag_xyz.z); + + return com_rslt; +} + /*! +* @brief This function used for read the compensated value of +* AKM09912 +* @note Before start reading the mag compensated data's +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. + +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm09912_compensate_xyz( +struct smi130_mag_xyz_s32_t*bosch_akm_xyz) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + struct smi130_mag_t mag_xyz; + + com_rslt = smi130_read_mag_xyz(&mag_xyz, BST_AKM); + printk(KERN_INFO "akm09912_raw_x:%d, %d, %d, <%s>,<%d>", + mag_xyz.x, mag_xyz.y, mag_xyz.z, __func__, __LINE__); + /* Compensation for X axis*/ + bosch_akm_xyz->x = smi130_bosch_akm09912_compensate_X(mag_xyz.x); + + /* Compensation for Y axis*/ + bosch_akm_xyz->y = smi130_bosch_akm09912_compensate_Y(mag_xyz.y); + + /* Compensation for Z axis*/ + bosch_akm_xyz->z = smi130_bosch_akm09912_compensate_Z(mag_xyz.z); + return com_rslt; +} + /*! +* @brief This function used for read the compensated value of +* AKM09912 +* @note Before start reading the mag compensated data's +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. + +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm09912_compensate_xyz_raw( +struct smi130_mag_xyz_s32_t*bosch_akm_xyz) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Compensation for X axis*/ + bosch_akm_xyz->x = smi130_bosch_akm09912_compensate_X(bosch_akm_xyz->x); + + /* Compensation for Y axis*/ + bosch_akm_xyz->y = smi130_bosch_akm09912_compensate_Y(bosch_akm_xyz->y); + + /* Compensation for Z axis*/ + bosch_akm_xyz->z = smi130_bosch_akm09912_compensate_Z(bosch_akm_xyz->z); + + return com_rslt; +} +/*! +* @brief This function used for set the AKM09911 and AKM09912 +* power mode. +* @note Before set the AKM power mode +* make sure the following two points are addressed +* @note 1. Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* @note 2. And also confirm the secondary-interface power mode +* is not in the SUSPEND mode. +* by using the function smi130_get_mag_pmu_status(). +* If the secondary-interface power mode is in SUSPEND mode +* set the value of 0x19(NORMAL mode)by using the +* smi130_set_command_register(0x19) function. +* +* @param v_akm_pow_mode_u8 : The value of akm power mode +* value | Description +* ---------|-------------------- +* 0 | AKM_POWER_DOWN_MODE +* 1 | AKM_SINGLE_MEAS_MODE +* 2 | FUSE_ROM_MODE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm_set_powermode( +u8 v_akm_pow_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + /* set mag interface manual mode*/ + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) { + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s>\n", + com_rslt, p_smi130->mag_manual_enable, __func__); + switch (v_akm_pow_mode_u8) { + case AKM_POWER_DOWN_MODE: + /* Set the power mode of AKM as power down mode*/ + com_rslt += smi130_set_mag_write_data(AKM_POWER_DOWN_MODE_DATA); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(AKM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + case AKM_SINGLE_MEAS_MODE: + /* Set the power mode of AKM as + single measurement mode*/ + com_rslt += smi130_set_mag_write_data + (AKM_SINGLE_MEASUREMENT_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(AKM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_read_addr(AKM_DATA_REGISTER); + break; + case FUSE_ROM_MODE: + /* Set the power mode of AKM as + Fuse ROM mode*/ + com_rslt += smi130_set_mag_write_data(AKM_FUSE_ROM_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(AKM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Sensitivity v_data_u8*/ + com_rslt += smi130_read_bosch_akm_sensitivity_data(); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* power down mode*/ + com_rslt += smi130_set_mag_write_data(AKM_POWER_DOWN_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(AKM_POWER_MODE_REG); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + /* set mag interface auto mode*/ + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) { + com_rslt += smi130_set_mag_manual_enable( + SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_smi130->mag_manual_enable, __func__, __LINE__); + return com_rslt; +} + /*! +* @brief This function used for set the magnetometer +* power mode of AKM09911 and AKM09912 +* @note Before set the mag power mode +* make sure the following two point is addressed +* Make sure the mag interface is enabled or not, +* by using the smi130_get_if_mode() function. +* If mag interface is not enabled set the value of 0x02 +* to the function smi130_get_if_mode(0x02) +* +* @param v_mag_sec_if_pow_mode_u8 : The value of secondary if power mode +* value | Description +* ---------|-------------------- +* 0 | SMI130_MAG_FORCE_MODE +* 1 | SMI130_MAG_SUSPEND_MODE +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_bosch_akm_and_secondary_if_powermode( +u8 v_mag_sec_if_pow_mode_u8) +{ + /* variable used for return the status of communication result*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* accel operation mode to normal*/ + com_rslt = smi130_set_command_register(ACCEL_MODE_NORMAL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* set mag interface manual mode*/ + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) { + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + } + printk(KERN_ERR "com_rslt:%d, manual:%d,after setacc normal mode\n", + com_rslt, p_smi130->mag_manual_enable); + switch (v_mag_sec_if_pow_mode_u8) { + case SMI130_MAG_FORCE_MODE: + /* set the secondary mag power mode as NORMAL*/ + com_rslt += smi130_set_mag_interface_normal(); + /* set the akm power mode as single measurement mode*/ + com_rslt += smi130_bosch_akm_set_powermode(AKM_SINGLE_MEAS_MODE); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_read_addr(AKM_DATA_REGISTER); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + break; + case SMI130_MAG_SUSPEND_MODE: + /* set the akm power mode as power down mode*/ + com_rslt += smi130_bosch_akm_set_powermode(AKM_POWER_DOWN_MODE); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* set the secondary mag power mode as SUSPEND*/ + com_rslt += smi130_set_command_register(MAG_MODE_SUSPEND); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_SMI130_OUT_OF_RANGE; + break; + } + /* set mag interface auto mode*/ + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) + com_rslt += smi130_set_mag_manual_enable( + SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + return com_rslt; +} +/*! +* @brief This function used for read the YAMAH-YAS532 init +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas532_mag_interface_init( +void) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + u8 v_pull_value_u8 = SMI130_INIT_VALUE; + u8 v_data_u8 = SMI130_INIT_VALUE; + u8 i = SMI130_INIT_VALUE; + /* accel operation mode to normal*/ + com_rslt = smi130_set_command_register(ACCEL_MODE_NORMAL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* write mag power mode as NORMAL*/ + com_rslt += smi130_set_mag_interface_normal(); + /* register 0x7E write the 0x37, 0x9A and 0x30*/ + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_ONE); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_TWO); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_THREE); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /*switch the page1*/ + com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_target_page(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_paging_enable(SMI130_WRITE_ENABLE_PAGE1); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_paging_enable(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* enable the pullup configuration from + the register 0x05 bit 4 and 5 as 10*/ + smi130_get_pullup_configuration(&v_pull_value_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + v_pull_value_u8 = v_pull_value_u8 | SMI130_PULL_UP_DATA; + com_rslt += smi130_set_pullup_configuration(v_pull_value_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /*switch the page0*/ + com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE0); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_target_page(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Write the YAS532 i2c address*/ + com_rslt += smi130_set_i2c_device_addr(SMI130_AUX_YAS532_I2C_ADDRESS); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* enable the mag interface to manual mode*/ + com_rslt += smi130_set_mag_manual_enable(SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_mag_manual_enable(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /*Enable the MAG interface*/ + com_rslt += smi130_set_if_mode(SMI130_ENABLE_MAG_IF_MODE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_if_mode(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + v_data_u8 = SMI130_MANUAL_DISABLE; + /* Read the YAS532 device id is 0x02*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS_DEVICE_ID_REG); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Read the YAS532 calibration data*/ + com_rslt += smi130_bosch_yamaha_yas532_calib_values(); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Assign the data acquisition mode*/ + yas532_data.measure_state = YAS532_MAG_STATE_INIT_COIL; + /* Set the default offset as invalid offset*/ + set_vector(yas532_data.v_hard_offset_s8, INVALID_OFFSET); + /* set the transform to zero*/ + yas532_data.transform = SMI130_NULL; + /* Assign overflow as zero*/ + yas532_data.overflow = 0; + #if YAS532_MAG_LOG < YAS532_MAG_TEMPERATURE_LOG + yas532_data.temp_data.num = + yas532_data.temp_data.idx = 0; + #endif + /* Assign the coef value*/ + for (i = 0; i < 3; i++) { + yas532_data.coef[i] = yas532_version_ac_coef[i]; + yas532_data.last_raw[i] = 0; + } + yas532_data.last_raw[3] = 0; + /* Set the initial values of yas532*/ + com_rslt += smi130_bosch_yas532_set_initial_values(); + /* write the mag v_data_bw_u8 as 25Hz*/ + com_rslt += smi130_set_mag_output_data_rate( + SMI130_MAG_OUTPUT_DATA_RATE_25HZ); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Enable mag interface to auto mode*/ + com_rslt += smi130_set_mag_manual_enable( + SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + smi130_get_mag_manual_enable(&v_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + return com_rslt; +} +/*! +* @brief This function used to set the YAS532 initial values +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_set_initial_values(void) +{ +/* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* write testr1 as 0x00*/ + com_rslt = smi130_set_mag_write_data( + SMI130_YAS532_WRITE_TESTR1); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(SMI130_YAS532_TESTR1); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write testr2 as 0x00*/ + com_rslt += smi130_set_mag_write_data( + SMI130_YAS532_WRITE_TESTR2); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(SMI130_YAS532_TESTR2); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write Rcoil as 0x00*/ + com_rslt += smi130_set_mag_write_data( + SMI130_YAS532_WRITE_RCOIL); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(SMI130_YAS532_RCOIL); + p_smi130->delay_msec(SMI130_YAS532_SET_INITIAL_VALUE_DELAY); + /* check the valid offset*/ + if (is_valid_offset(yas532_data.v_hard_offset_s8)) { + com_rslt += smi130_bosch_yas532_set_offset( + yas532_data.v_hard_offset_s8); + yas532_data.measure_state = YAS532_MAG_STATE_NORMAL; + } else { + /* set the default offset as invalid offset*/ + set_vector(yas532_data.v_hard_offset_s8, INVALID_OFFSET); + /*Set the default measure state for offset correction*/ + yas532_data.measure_state = YAS532_MAG_STATE_MEASURE_OFFSET; + } + return com_rslt; +} +/*! +* @brief This function used for YAS532 offset correction +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_magnetic_measure_set_offset( +void) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* used for offset value set to the offset register*/ + s8 v_hard_offset_s8[SMI130_HARD_OFFSET_DATA_SIZE] = { + SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* offset correction factors*/ + static const u8 v_correct_u8[SMI130_YAS_CORRECT_DATA_SIZE] = { + 16, 8, 4, 2, 1}; + /* used for the temperature*/ + u16 v_temp_u16 = SMI130_INIT_VALUE; + /* used for the xy1y2 read*/ + u16 v_xy1y2_u16[SMI130_YAS_XY1Y2_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* local flag for assign the values*/ + s32 v_flag_s32[SMI130_YAS_FLAG_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + u8 i, j, v_busy_u8, v_overflow_u8 = SMI130_INIT_VALUE; + + for (i = 0; i < 5; i++) { + /* set the offset values*/ + com_rslt = smi130_bosch_yas532_set_offset(v_hard_offset_s8); + /* read the sensor data*/ + com_rslt += smi130_bosch_yas532_normal_measurement_data( + SMI130_YAS532_ACQ_START, &v_busy_u8, &v_temp_u16, + v_xy1y2_u16, &v_overflow_u8); + /* check the sensor busy status*/ + if (v_busy_u8) + return E_SMI130_BUSY; + /* calculate the magnetic correction with + offset and assign the values + to the offset register*/ + for (j = 0; j < 3; j++) { + if (YAS532_DATA_CENTER == v_xy1y2_u16[j]) + v_flag_s32[j] = 0; + if (YAS532_DATA_CENTER < v_xy1y2_u16[j]) + v_flag_s32[j] = 1; + if (v_xy1y2_u16[j] < YAS532_DATA_CENTER) + v_flag_s32[j] = -1; + } + for (j = 0; j < 3; j++) { + if (v_flag_s32[j]) + v_hard_offset_s8[j] = (s8)(v_hard_offset_s8[j] + + v_flag_s32[j]* v_correct_u8[i]); + } + } + /* set the offset*/ + com_rslt += smi130_bosch_yas532_set_offset(v_hard_offset_s8); + return com_rslt; +} +/*! +* @brief This function used for read the +* YAMAHA YAS532 calibration data +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas532_calib_values(void) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array holding the YAS532 calibration values*/ + u8 v_data_u8[SMI130_YAS532_CALIB_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* Read the DX value*/ + com_rslt = smi130_set_mag_read_addr(SMI130_YAS532_CALIB_CX); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[0], SMI130_GEN_READ_WRITE_DATA_LENGTH); + yas532_data.calib_yas532.cx = (s32)((v_data_u8[0] + * 10) - 1280); + /* Read the DY1 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB_CY1); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[1], SMI130_GEN_READ_WRITE_DATA_LENGTH); + yas532_data.calib_yas532.cy1 = + (s32)((v_data_u8[1]* 10) - 1280); + /* Read the DY2 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB_CY2); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[2], SMI130_GEN_READ_WRITE_DATA_LENGTH); + yas532_data.calib_yas532.cy2 = + (s32)((v_data_u8[2]* 10) - 1280); + /* Read the D2 and D3 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB1); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[3], SMI130_GEN_READ_WRITE_DATA_LENGTH); + yas532_data.calib_yas532.a2 = + (s32)(((v_data_u8[3] >> + SMI130_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x03F) - 32); + /* Read the D3 and D4 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB2); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[4], SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a3*/ + yas532_data.calib_yas532.a3 = (s32)((((v_data_u8[3] << + SMI130_SHIFT_BIT_POSITION_BY_02_BITS) & 0x0C) | + ((v_data_u8[4] + >> SMI130_SHIFT_BIT_POSITION_BY_06_BITS) + & 0x03)) - 8); + /* calculate a4*/ + yas532_data.calib_yas532.a4 = (s32)((v_data_u8[4] + & 0x3F) - 32); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* Read the D5 and D6 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB3); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[5], SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a5*/ + yas532_data.calib_yas532.a5 = + (s32)(((v_data_u8[5] + >> SMI130_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x3F) + 38); + /* Read the D6 and D7 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB4); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[6], SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a6*/ + yas532_data.calib_yas532.a6 = + (s32)((((v_data_u8[5] + << SMI130_SHIFT_BIT_POSITION_BY_04_BITS) + & 0x30) | ((v_data_u8[6] >> + SMI130_SHIFT_BIT_POSITION_BY_04_BITS) + & 0x0F)) - 32); + /* Read the D7 and D8 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB5); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[7], SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a7*/ + yas532_data.calib_yas532.a7 = (s32)((((v_data_u8[6] + << SMI130_SHIFT_BIT_POSITION_BY_03_BITS) + & 0x78) | + ((v_data_u8[7] + >> SMI130_SHIFT_BIT_POSITION_BY_05_BITS) & + 0x07)) - 64); + /* Read the D8 and D9 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CLAIB6); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[8], SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a8*/ + yas532_data.calib_yas532.a8 = (s32)((((v_data_u8[7] << + SMI130_GEN_READ_WRITE_DATA_LENGTH) & 0x3E) | + ((v_data_u8[8] >> + SMI130_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)) - + 32); + + /* Read the D8 and D9 value*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB7); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[9], SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a9*/ + yas532_data.calib_yas532.a9 = (s32)(((v_data_u8[8] << + SMI130_GEN_READ_WRITE_DATA_LENGTH) & 0xFE) | + ((v_data_u8[9] >> + SMI130_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + /* calculate k*/ + yas532_data.calib_yas532.k = (s32)((v_data_u8[9] >> + SMI130_SHIFT_BIT_POSITION_BY_02_BITS) & 0x1F); + /* Read the value from register 0x9A*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB8); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[10], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* Read the value from register 0x9B*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIIB9); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[11], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* Read the value from register 0x9C*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB10); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[12], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* Read the value from register 0x9D*/ + com_rslt += smi130_set_mag_read_addr(SMI130_YAS532_CALIB11); + /* 0x04 is secondary read mag x lsb register*/ + com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, + &v_data_u8[13], + SMI130_GEN_READ_WRITE_DATA_LENGTH); + /* Calculate the fxy1y2 and rxy1y1*/ + yas532_data.calib_yas532.fxy1y2[0] = + (u8)(((v_data_u8[10] + & 0x01) + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) + | ((v_data_u8[11] >> + SMI130_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + yas532_data.calib_yas532.rxy1y2[0] = + ((s8)(((v_data_u8[10] + >> SMI130_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F) + << SMI130_SHIFT_BIT_POSITION_BY_02_BITS)) + >> SMI130_SHIFT_BIT_POSITION_BY_02_BITS; + yas532_data.calib_yas532.fxy1y2[1] = + (u8)(((v_data_u8[11] & 0x01) + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) + | ((v_data_u8[12] >> + SMI130_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + yas532_data.calib_yas532.rxy1y2[1] = + ((s8)(((v_data_u8[11] + >> SMI130_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F) + << SMI130_SHIFT_BIT_POSITION_BY_02_BITS)) + >> SMI130_SHIFT_BIT_POSITION_BY_02_BITS; + yas532_data.calib_yas532.fxy1y2[2] = + (u8)(((v_data_u8[12] & 0x01) + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) + | ((v_data_u8[13] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + yas532_data.calib_yas532.rxy1y2[2] = + ((s8)(((v_data_u8[12] + >> SMI130_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F) + << SMI130_SHIFT_BIT_POSITION_BY_02_BITS)) + >> SMI130_SHIFT_BIT_POSITION_BY_02_BITS; + + return com_rslt; +} +/*! +* @brief This function used for calculate the +* YAS532 read the linear data +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_xy1y2_to_linear( +u16*v_xy1y2_u16, s32*xy1y2_linear) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SUCCESS; + static const u16 v_calib_data[] = { + 3721, 3971, 4221, 4471}; + u8 i = SMI130_INIT_VALUE; + + for (i = 0; i < 3; i++) + xy1y2_linear[i] = v_xy1y2_u16[i] - + v_calib_data[yas532_data.calib_yas532.fxy1y2[i]] + + (yas532_data.v_hard_offset_s8[i] - + yas532_data.calib_yas532.rxy1y2[i]) + * yas532_data.coef[i]; + return com_rslt; +} +/*! +* @brief This function used for read the YAS532 sensor data +* @param v_acquisition_command_u8: used to set the data acquisition +* acquisition_command | operation +* ---------------------|------------------------- +* 0x17 | turn on the acquisition coil +* - | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Deferred acquisition mode +* 0x07 | turn on the acquisition coil +* _ | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Normal acquisition mode +* 0x11 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Deferred acquisition mode +* 0x01 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Normal acquisition mode +* +* @param v_busy_u8 : used to get the busy flay for sensor data read +* @param v_temp_u16 : used to get the temperature data +* @param v_xy1y2_u16 : used to get the sensor xy1y2 data +* @param v_overflow_u8 : used to get the overflow data +* +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_normal_measurement_data( +u8 v_acquisition_command_u8, u8*v_busy_u8, +u16*v_temp_u16, u16*v_xy1y2_u16, u8*v_overflow_u8) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + /* Array holding the YAS532 xyy1 data*/ + u8 v_data_u8[SMI130_YAS_XY1Y2T_DATA_SIZE] = { + SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + u8 i = SMI130_INIT_VALUE; + /* check the p_smi130 structure as NULL*/ + if (p_smi130 == SMI130_NULL) { + return E_SMI130_NULL_PTR; + } else { + /* read the sensor data*/ + com_rslt = smi130_bosch_yas532_acquisition_command_register( + v_acquisition_command_u8); + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_MAG_X_LSB__REG, + v_data_u8, SMI130_MAG_YAS_DATA_LENGTH); + /* read the xyy1 data*/ + *v_busy_u8 = + ((v_data_u8[0] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01); + *v_temp_u16 = + (u16)((((s32)v_data_u8[0] + << SMI130_SHIFT_BIT_POSITION_BY_03_BITS) + & 0x3F8) | ((v_data_u8[1] + >> SMI130_SHIFT_BIT_POSITION_BY_05_BITS) & 0x07)); + v_xy1y2_u16[0] = + (u16)((((s32)v_data_u8[2] + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS) & 0x1FC0) + | ((v_data_u8[3] >> + SMI130_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F)); + v_xy1y2_u16[1] = + (u16)((((s32)v_data_u8[4] + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS) + & 0x1FC0) + | ((v_data_u8[5] + >> SMI130_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F)); + v_xy1y2_u16[2] = + (u16)((((s32)v_data_u8[6] + << SMI130_SHIFT_BIT_POSITION_BY_06_BITS) + & 0x1FC0) + | ((v_data_u8[7] + >> SMI130_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F)); + *v_overflow_u8 = 0; + for (i = 0; i < 3; i++) { + if (v_xy1y2_u16[i] == YAS532_DATA_OVERFLOW) + *v_overflow_u8 |= (1 << (i* 2)); + if (v_xy1y2_u16[i] == YAS532_DATA_UNDERFLOW) + *v_overflow_u8 |= (1 << (i* 2 + 1)); + } + } + return com_rslt; +} +/*! +* @brief This function used for YAS532 sensor data +* @param v_acquisition_command_u8 : the value of CMDR +* acquisition_command | operation +* ---------------------|------------------------- +* 0x17 | turn on the acquisition coil +* - | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Deferred acquisition mode +* 0x07 | turn on the acquisition coil +* _ | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Normal acquisition mode +* 0x11 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Deferred acquisition mode +* 0x01 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Normal acquisition mode +* +* @param xyz_data : the vector xyz output +* @param v_overflow_s8 : the value of overflow +* @param v_temp_correction_u8 : the value of temperate correction enable +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_measurement_xyz_data( +struct yas532_vector*xyz_data, u8*v_overflow_s8, u8 v_temp_correction_u8, +u8 v_acquisition_command_u8) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = SMI130_INIT_VALUE; + /* Array holding the linear calculation output*/ + s32 v_xy1y2_linear_s32[SMI130_YAS_XY1Y2_DATA_SIZE] = { + SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* Array holding the temperature data*/ + s32 v_xyz_tmp_s32[SMI130_YAS_TEMP_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + s32 tmp = SMI130_INIT_VALUE; + s32 sx, sy1, sy2, sy, sz = SMI130_INIT_VALUE; + u8 i, v_busy_u8 = SMI130_INIT_VALUE; + u16 v_temp_u16 = SMI130_INIT_VALUE; + /* Array holding the xyy1 sensor raw data*/ + u16 v_xy1y2_u16[SMI130_YAS_XY1Y2_DATA_SIZE] = {SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + #if YAS532_MAG_LOG < YAS532_MAG_TEMPERATURE_LOG + s32 sum = SMI130_INIT_VALUE; + #endif + *v_overflow_s8 = SMI130_INIT_VALUE; + switch (yas532_data.measure_state) { + case YAS532_MAG_STATE_INIT_COIL: + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + /* write Rcoil*/ + com_rslt += smi130_set_mag_write_data( + SMI130_YAS_DISABLE_RCOIL); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(SMI130_YAS532_RCOIL); + p_smi130->delay_msec(SMI130_YAS532_MEASUREMENT_DELAY); + if (!yas532_data.overflow && is_valid_offset( + yas532_data.v_hard_offset_s8)) + yas532_data.measure_state = 0; + break; + case YAS532_MAG_STATE_MEASURE_OFFSET: + com_rslt = smi130_bosch_yas532_magnetic_measure_set_offset(); + yas532_data.measure_state = 0; + break; + default: + break; + } + /* Read sensor data*/ + com_rslt += smi130_bosch_yas532_normal_measurement_data( + v_acquisition_command_u8, &v_busy_u8, &v_temp_u16, + v_xy1y2_u16, v_overflow_s8); + /* Calculate the linear data*/ + com_rslt += smi130_bosch_yas532_xy1y2_to_linear(v_xy1y2_u16, + v_xy1y2_linear_s32); + /* Calculate temperature correction*/ + #if YAS532_MAG_LOG < YAS532_MAG_TEMPERATURE_LOG + yas532_data.temp_data.log[yas532_data.temp_data.idx++] = + v_temp_u16; + if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.idx) + yas532_data.temp_data.idx = 0; + yas532_data.temp_data.num++; + if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.num) + yas532_data.temp_data.num = YAS532_MAG_TEMPERATURE_LOG; + for (i = 0; i < yas532_data.temp_data.num; i++) + sum += yas532_data.temp_data.log[i]; + tmp = sum* 10 / yas532_data.temp_data.num + - YAS532_TEMP20DEGREE_TYPICAL* 10; + #else + tmp = (v_temp_u16 - YAS532_TEMP20DEGREE_TYPICAL) + * 10; + #endif + sx = v_xy1y2_linear_s32[0]; + sy1 = v_xy1y2_linear_s32[1]; + sy2 = v_xy1y2_linear_s32[2]; + /* Temperature correction*/ + if (v_temp_correction_u8) { + sx -= (yas532_data.calib_yas532.cx * tmp) + / 1000; + sy1 -= (yas532_data.calib_yas532.cy1* tmp) + / 1000; + sy2 -= (yas532_data.calib_yas532.cy2* tmp) + / 1000; + } + sy = sy1 - sy2; + sz = -sy1 - sy2; + + xyz_data->yas532_vector_xyz[0] = yas532_data.calib_yas532.k* + ((100* sx + yas532_data.calib_yas532.a2* sy + + yas532_data.calib_yas532.a3* sz) / 10); + xyz_data->yas532_vector_xyz[1] = yas532_data.calib_yas532.k* + ((yas532_data.calib_yas532.a4* sx + yas532_data.calib_yas532.a5* sy + + yas532_data.calib_yas532.a6* sz) / 10); + xyz_data->yas532_vector_xyz[2] = yas532_data.calib_yas532.k* + ((yas532_data.calib_yas532.a7* sx + yas532_data.calib_yas532.a8* sy + + yas532_data.calib_yas532.a9* sz) / 10); + if (yas532_data.transform != SMI130_NULL) { + for (i = 0; i < 3; i++) { + v_xyz_tmp_s32[i] = yas532_data.transform[i + * 3]* + xyz_data->yas532_vector_xyz[0] + + yas532_data.transform[i* 3 + 1]* + xyz_data->yas532_vector_xyz[1] + + yas532_data.transform[i* 3 + 2]* + xyz_data->yas532_vector_xyz[2]; + } + set_vector(xyz_data->yas532_vector_xyz, v_xyz_tmp_s32); + } + for (i = 0; i < 3; i++) { + xyz_data->yas532_vector_xyz[i] -= + xyz_data->yas532_vector_xyz[i] % 10; + if (*v_overflow_s8 & (1 + << (i* 2))) + xyz_data->yas532_vector_xyz[i] += + 1; /* set overflow*/ + if (*v_overflow_s8 & (1 << + (i* 2 + 1))) + xyz_data->yas532_vector_xyz[i] += 2; /* set underflow*/ + } + + +if (v_busy_u8) + return com_rslt; + if (0 <*v_overflow_s8) { + if (!yas532_data.overflow) + yas532_data.overflow = 1; + yas532_data.measure_state = YAS532_MAG_STATE_INIT_COIL; + } else + yas532_data.overflow = 0; + for (i = 0; i < 3; i++) + yas532_data.last_raw[i] = v_xy1y2_u16[i]; + yas532_data.last_raw[i] = v_temp_u16; + return com_rslt; +} +/*! +* @brief This function used for YAS532 write data acquisition +* command register write +* @param v_command_reg_data_u8 : the value of data acquisition +* acquisition_command | operation +* ---------------------|------------------------- +* 0x17 | turn on the acquisition coil +* - | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Deferred acquisition mode +* 0x07 | turn on the acquisition coil +* _ | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Normal acquisition mode +* 0x11 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Deferred acquisition mode +* 0x01 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Normal acquisition mode +* +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_acquisition_command_register( +u8 v_command_reg_data_u8) +{ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + + com_rslt = smi130_set_mag_write_data(v_command_reg_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* YAMAHA YAS532-0x82*/ + com_rslt += smi130_set_mag_write_addr( + SMI130_YAS532_COMMAND_REGISTER); + p_smi130->delay_msec(SMI130_YAS_ACQ_COMMAND_DELAY); + com_rslt += smi130_set_mag_read_addr( + SMI130_YAS532_DATA_REGISTER); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) + com_rslt += smi130_set_mag_manual_enable(SMI130_MANUAL_DISABLE); + + return com_rslt; + +} +/*! +* @brief This function used write offset of YAS532 +* +* @param p_offset_s8 : The value of offset to write +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_set_offset( +const s8*p_offset_s8) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) + com_rslt = smi130_set_mag_manual_enable(SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_YAS532_OFFSET_DELAY); + + /* Write offset X data*/ + com_rslt = smi130_set_mag_write_data(p_offset_s8[0]); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* YAS532 offset x write*/ + com_rslt += smi130_set_mag_write_addr(SMI130_YAS532_OFFSET_X); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + /* Write offset Y data*/ + com_rslt = smi130_set_mag_write_data(p_offset_s8[1]); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* YAS532 offset y write*/ + com_rslt += smi130_set_mag_write_addr(SMI130_YAS532_OFFSET_Y); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + /* Write offset Z data*/ + com_rslt = smi130_set_mag_write_data(p_offset_s8[2]); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* YAS532 offset z write*/ + com_rslt += smi130_set_mag_write_addr(SMI130_YAS532_OFFSET_Z); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + set_vector(yas532_data.v_hard_offset_s8, p_offset_s8); + + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) + com_rslt = smi130_set_mag_manual_enable(SMI130_MANUAL_DISABLE); + return com_rslt; +} +/*! +* @brief This function used to init the YAMAH-YAS537 +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_mag_interface_init( +void) +{ +/* This variable used for provide the communication +results*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +u8 v_pull_value_u8 = SMI130_INIT_VALUE; +u8 v_data_u8 = SMI130_INIT_VALUE; +u8 i = SMI130_INIT_VALUE; +/* accel operation mode to normal*/ +com_rslt = smi130_set_command_register(ACCEL_MODE_NORMAL); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* write mag power mode as NORMAL*/ +com_rslt += smi130_set_mag_interface_normal(); +/* register 0x7E write the 0x37, 0x9A and 0x30*/ +com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_ONE); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_TWO); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_command_register(SMI130_COMMAND_REG_THREE); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/*switch the page1*/ +com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE1); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +smi130_get_target_page(&v_data_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_paging_enable(SMI130_WRITE_ENABLE_PAGE1); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +smi130_get_paging_enable(&v_data_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* enable the pullup configuration from +the register 0x05 bit 4 and 5 as 10*/ +smi130_get_pullup_configuration(&v_pull_value_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +v_pull_value_u8 = v_pull_value_u8 | SMI130_PULL_UP_DATA; +com_rslt += smi130_set_pullup_configuration(v_pull_value_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/*switch the page0*/ +com_rslt += smi130_set_target_page(SMI130_WRITE_TARGET_PAGE0); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +smi130_get_target_page(&v_data_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* Write the YAS532 i2c address*/ +com_rslt += smi130_set_i2c_device_addr(SMI130_YAS537_I2C_ADDRESS); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* enable the mag interface to manual mode*/ +com_rslt += smi130_set_mag_manual_enable(SMI130_MANUAL_ENABLE); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +smi130_get_mag_manual_enable(&v_data_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/*Enable the MAG interface*/ +com_rslt += smi130_set_if_mode(SMI130_ENABLE_MAG_IF_MODE); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +smi130_get_if_mode(&v_data_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +v_data_u8 = SMI130_MANUAL_DISABLE; +/* Read the YAS537 device id*/ +com_rslt += smi130_set_mag_read_addr(SMI130_YAS_DEVICE_ID_REG); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&v_data_u8, SMI130_GEN_READ_WRITE_DATA_LENGTH); +yas537_data.dev_id = v_data_u8; +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* Read the YAS532 calibration data*/ +com_rslt += +smi130_bosch_yamaha_yas537_calib_values( +SMI130_GEN_READ_WRITE_DATA_LENGTH); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* set the mode to NORMAL*/ +yas537_data.measure_state = YAS537_MAG_STATE_NORMAL; +/* set the transform to zero*/ +yas537_data.transform = SMI130_NULL; +yas537_data.average = 32; +for (i = 0; i < 3; i++) { + yas537_data.hard_offset[i] = -128; + yas537_data.last_after_rcoil[i] = 0; +} +for (i = 0; i < 4; i++) + yas537_data.last_raw[i] = 0; +/* write the mag bandwidth as 25Hz*/ +com_rslt += smi130_set_mag_output_data_rate( +SMI130_MAG_OUTPUT_DATA_RATE_25HZ); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* Enable mag interface to auto mode*/ +com_rslt += smi130_set_mag_manual_enable( +SMI130_MANUAL_DISABLE); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +smi130_get_mag_manual_enable(&v_data_u8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +return com_rslt; +} +/*! +* @brief This function used for read the +* YAMAHA YAS537 calibration data +* +* +* @param v_rcoil_u8 : The value of r coil +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_calib_values( +u8 v_rcoil_u8) +{ +/* This variable used for provide the communication +results*/ +SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; +/* Array holding the YAS532 calibration values*/ +u8 a_data_u8[SMI130_YAS537_CALIB_DATA_SIZE] = { +SMI130_INIT_VALUE, SMI130_INIT_VALUE, +SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, +SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, +SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, +SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, +SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, +}; +static const u8 v_avrr_u8[] = {0x50, 0x60, 0x70}; +u8 v_cal_valid_u8 = SMI130_INIT_VALUE, i; +/* write soft reset as 0x02*/ +com_rslt = smi130_set_mag_write_data( +YAS537_SRSTR_DATA); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_mag_write_addr(YAS537_REG_SRSTR); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* Read the DX value*/ +com_rslt = smi130_set_mag_read_addr(YAS537_REG_CALR_C0); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[0], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the DY1 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C1); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[1], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the DY2 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C2); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[2], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D2 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C3); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[3], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D3 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C4); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[4], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D4 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C5); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[5], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D5 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C6); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[6], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D6 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C7); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[7], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D7 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C8); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[8], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D8 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_C9); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[9], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D9 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_CA); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[10], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RX value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_CB); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[11], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RY1 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_CC); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[12], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RY2 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_CD); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[13], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RY2 value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_CE); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[14], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the CHF value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_CF); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[15], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* Read the VER value*/ +com_rslt += smi130_set_mag_read_addr(YAS537_REG_CALR_DO); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register*/ +com_rslt += smi130_read_reg(SMI130_MAG_DATA_READ_REG, +&a_data_u8[16], SMI130_GEN_READ_WRITE_DATA_LENGTH); +/* get the calib ver*/ +yas537_data.calib_yas537.ver = +(a_data_u8[16] >> SMI130_SHIFT_BIT_POSITION_BY_06_BITS); +for (i = 0; i < 17; i++) { + if (((i < 16 && a_data_u8[i]) != 0)) + v_cal_valid_u8 = 1; + if ((i < 16 && + (a_data_u8[i] & 0x3F)) != 0) + v_cal_valid_u8 = 1; +} +if (!v_cal_valid_u8) + return ERROR; +if (yas537_data.calib_yas537.ver == 0) { + for (i = 0; i < 17; i++) { + if (i < 12) { + /* write offset*/ + com_rslt += smi130_set_mag_write_data( + a_data_u8[i]); + p_smi130->delay_msec( + SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + YAS537_REG_MTCR + i); + p_smi130->delay_msec( + SMI130_GEN_READ_WRITE_DELAY); + } else if (i < 15) { + /* write offset correction*/ + com_rslt += smi130_set_mag_write_data( + a_data_u8[i]); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(( + (YAS537_REG_OXR + i) - 12)); + p_smi130->delay_msec( + SMI130_GEN_READ_WRITE_DELAY); + yas537_data.hard_offset[i - 12] + = a_data_u8[i]; + } else { + /* write offset correction*/ + com_rslt += smi130_set_mag_write_data( + a_data_u8[i]); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(( + (YAS537_REG_OXR + i) - 11)); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + } + +} +} else if (yas537_data.calib_yas537.ver == 1) { + for (i = 0; i < 3; i++) { + /* write offset*/ + com_rslt += smi130_set_mag_write_data( + a_data_u8[i]); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + YAS537_REG_MTCR + i); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + if (com_rslt == SUCCESS) { + /* write offset*/ + com_rslt += smi130_set_mag_write_data( + a_data_u8[i + 12]); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + YAS537_REG_OXR + i); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + yas537_data.hard_offset[i] = + a_data_u8[i + 12]; + } else { + com_rslt = ERROR; + } + } + /* write offset*/ + com_rslt += smi130_set_mag_write_data( + ((a_data_u8[i] & 0xE0) | 0x10)); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr( + YAS537_REG_MTCR + i); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write offset*/ + com_rslt += smi130_set_mag_write_data( + ((a_data_u8[15] + >> SMI130_SHIFT_BIT_POSITION_BY_03_BITS) + & 0x1E)); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(YAS537_REG_HCKR); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write offset*/ + com_rslt += smi130_set_mag_write_data( + ((a_data_u8[15] << 1) & 0x1E)); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(YAS537_REG_LCKR); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write offset*/ + com_rslt += smi130_set_mag_write_data( + (a_data_u8[16] & 0x3F)); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(YAS537_REG_OCR); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + + /* Assign the calibration values*/ + /* a2*/ + yas537_data.calib_yas537.a2 = + ((((a_data_u8[3] + << SMI130_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x7C) + | (a_data_u8[4] + >> SMI130_SHIFT_BIT_POSITION_BY_06_BITS)) - 64); + /* a3*/ + yas537_data.calib_yas537.a3 = + ((((a_data_u8[4] << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) + & 0x7E) + | (a_data_u8[5] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS)) - 64); + /* a4*/ + yas537_data.calib_yas537.a4 = + ((((a_data_u8[5] + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) + & 0xFE) + | (a_data_u8[6] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS)) + - 128); + /* a5*/ + yas537_data.calib_yas537.a5 = + ((((a_data_u8[6] + << SMI130_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x1FC) + | (a_data_u8[7] + >> SMI130_SHIFT_BIT_POSITION_BY_06_BITS)) + - 112); + /* a6*/ + yas537_data.calib_yas537.a6 = + ((((a_data_u8[7] + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) + & 0x7E) + | (a_data_u8[8] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS)) - 64); + /* a7*/ + yas537_data.calib_yas537.a7 = + ((((a_data_u8[8] + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) + & 0xFE) + | (a_data_u8[9] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS)) + - 128); + /* a8*/ + yas537_data.calib_yas537.a8 = ((a_data_u8[9] & + 0x7F) - 64); + /* a9*/ + yas537_data.calib_yas537.a9 = ((((a_data_u8[10] + << SMI130_SHIFT_BIT_POSITION_BY_01_BIT) & 0x1FE) + | (a_data_u8[11] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS)) + - 112); + /* k*/ + yas537_data.calib_yas537.k = ( + a_data_u8[11] & 0x7F); + } else { + return ERROR; + } +/* write A/D converter*/ +com_rslt += smi130_set_mag_write_data( +YAS537_WRITE_A_D_CONVERTER); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_mag_write_addr(YAS537_REG_ADCCALR); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* write A/D converter second register*/ +com_rslt += smi130_set_mag_write_data( +YAS537_WRITE_A_D_CONVERTER2); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_mag_write_addr(YAS537_REG_ADCCALR_ONE); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* write temperature calibration register*/ +com_rslt += smi130_set_mag_write_data(YAS537_WRITE_TEMP_CALIB); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_mag_write_addr(YAS537_REG_TRMR); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* write average filter register*/ +com_rslt += smi130_set_mag_write_data( +v_avrr_u8[yas537_data.average]); +p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); +com_rslt += smi130_set_mag_write_addr(YAS537_REG_AVRR); +p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +if (v_rcoil_u8) { + /* write average; filter register*/ + com_rslt += smi130_set_mag_write_data( + YAS537_WRITE_FILTER); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(YAS537_REG_CONFR); + p_smi130->delay_msec( + SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +} + +return com_rslt; + +} +/*! +* @brief This function used for YAS537 write data acquisition +* command register write +* @param v_command_reg_data_u8 : the value of data acquisition +* acquisition_command | operation +* ---------------------|------------------------- +* 0x17 | turn on the acquisition coil +* - | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Deferred acquisition mode +* 0x07 | turn on the acquisition coil +* _ | set direction of the coil +* _ | (x and y as minus(-)) +* _ | Normal acquisition mode +* 0x11 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Deferred acquisition mode +* 0x01 | turn OFF the acquisition coil +* _ | set direction of the coil +* _ | (x and y as plus(+)) +* _ | Normal acquisition mode +* +* +* + * @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas537_acquisition_command_register( +u8 v_command_reg_data_u8) +{ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + com_rslt = smi130_set_mag_write_data(v_command_reg_data_u8); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + /* YAMAHA YAS532-0x82*/ + com_rslt += smi130_set_mag_write_addr( + SMI130_REG_YAS537_CMDR); + /* set the mode to RECORD*/ + yas537_data.measure_state = YAS537_MAG_STATE_RECORD_DATA; + p_smi130->delay_msec(SMI130_YAS_ACQ_COMMAND_DELAY); + com_rslt += smi130_set_mag_read_addr( + YAS537_REG_TEMPERATURE_0); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) + com_rslt += smi130_set_mag_manual_enable( + SMI130_MANUAL_DISABLE); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + + return com_rslt; + +} +/*! +* @brief This function used for read the +* YAMAHA YAS537 xy1y2 data +* +* @param xy1y2: The value of raw xy1y2 data +* @param xyz: The value of xyz data +* +* +* @return None +* +* +*/ +static void xy1y2_to_xyz(u16*xy1y2, s32*xyz) +{ + xyz[0] = ((xy1y2[0] - 8192) + * 300); + xyz[1] = (((xy1y2[1] - xy1y2[2]) + * 1732) / 10); + xyz[2] = (((-xy1y2[2] - xy1y2[2]) + + 16384)* 300); +} +/*! +* @brief This function used for read the +* YAMAHA YAS537 xy1y2 data +* +* @param v_coil_stat_u8: The value of R coil status +* @param v_busy_u8: The value of busy status +* @param v_temperature_u16: The value of temperature +* @param xy1y2: The value of raw xy1y2 data +* @param v_ouflow_u8: The value of overflow +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_read_xy1y2_data( +u8*v_coil_stat_u8, u8*v_busy_u8, +u16*v_temperature_u16, u16*xy1y2, u8*v_ouflow_u8) +{ + /* This variable used for provide the communication + results*/ + SMI130_RETURN_FUNCTION_TYPE com_rslt = E_SMI130_COMM_RES; + /* Array holding the YAS532 calibration values*/ + u8 a_data_u8[SMI130_YAS_XY1Y2T_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE, + }; + u8 i = SMI130_INIT_VALUE; + s32 a_h_s32[SMI130_YAS_H_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + s32 a_s_s32[SMI130_YAS_S_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + /* set command register*/ + com_rslt = smi130_bosch_yas537_acquisition_command_register( + YAS537_SET_COMMAND_REGISTER); + /* read the yas537 sensor data of xy1y2*/ + com_rslt += + p_smi130->SMI130_BUS_READ_FUNC(p_smi130->dev_addr, + SMI130_USER_DATA_MAG_X_LSB__REG, + a_data_u8, SMI130_MAG_YAS_DATA_LENGTH); + /* read the busy flag*/ + *v_busy_u8 = a_data_u8[2] + >> SMI130_SHIFT_BIT_POSITION_BY_07_BITS; + /* read the coil status*/ + *v_coil_stat_u8 = + ((a_data_u8[2] >> + SMI130_SHIFT_BIT_POSITION_BY_06_BITS) & 0X01); + /* read temperature data*/ + *v_temperature_u16 = (u16)((a_data_u8[0] + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | a_data_u8[1]); + /* read x data*/ + xy1y2[0] = (u16)(((a_data_u8[2] & + 0x3F) + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8[3])); + /* read y1 data*/ + xy1y2[1] = (u16)((a_data_u8[4] + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[5]); + /* read y2 data*/ + xy1y2[2] = (u16)((a_data_u8[6] + << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[7]); + for (i = 0; i < 3; i++) + yas537_data.last_raw[i] = xy1y2[i]; + yas537_data.last_raw[i] =*v_temperature_u16; + if (yas537_data.calib_yas537.ver == 1) { + for (i = 0; i < 3; i++) + a_s_s32[i] = xy1y2[i] - 8192; + /* read hx*/ + a_h_s32[0] = ((yas537_data.calib_yas537.k* ( + (128* a_s_s32[0]) + + (yas537_data.calib_yas537.a2* a_s_s32[1]) + + (yas537_data.calib_yas537.a3* a_s_s32[2]))) + / (8192)); + /* read hy1*/ + a_h_s32[1] = ((yas537_data.calib_yas537.k* ( + (yas537_data.calib_yas537.a4* a_s_s32[0]) + + (yas537_data.calib_yas537.a5* a_s_s32[1]) + + (yas537_data.calib_yas537.a6* a_s_s32[2]))) + / (8192)); + /* read hy2*/ + a_h_s32[2] = ((yas537_data.calib_yas537.k* ( + (yas537_data.calib_yas537.a7* a_s_s32[0]) + + (yas537_data.calib_yas537.a8* a_s_s32[1]) + + (yas537_data.calib_yas537.a9* a_s_s32[2]))) + / (8192)); + + for (i = 0; i < 3; i++) { + if (a_h_s32[i] < -8192) + a_h_s32[i] = -8192; + + if (8192 < a_h_s32[i]) + a_h_s32[i] = 8192; + + xy1y2[i] = a_h_s32[i] + 8192; + + } + } + *v_ouflow_u8 = 0; + for (i = 0; i < 3; i++) { + if (YAS537_DATA_OVERFLOW <= xy1y2[i]) + *v_ouflow_u8 |= (1 << (i* 2)); + if (xy1y2[i] == YAS537_DATA_UNDERFLOW) + *v_ouflow_u8 |= (1 << (i* 2 + 1)); + } + + return com_rslt; + +} +/*! +* @brief This function used for read the +* YAMAHA YAS537 xy1y2 data +* +* @param v_ouflow_u8: The value of overflow +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +static SMI130_RETURN_FUNCTION_TYPE invalid_magnetic_field( +u16*v_cur_u16, u16*v_last_u16) +{ + s16 invalid_thresh[] = {1500, 1500, 1500}; + u8 i = SMI130_INIT_VALUE; + + for (i = 0; i < 3; i++) + if (invalid_thresh[i] < ABS(v_cur_u16[i] - v_last_u16[i])) + return 1; + return 0; +} +/*! +* @brief This function used for read the +* YAMAHA YAS537 xy1y2 data +* +* @param v_ouflow_u8: The value of overflow +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_measure_xyz_data( +u8*v_ouflow_u8, struct yas_vector*vector_xyz) +{ + s32 a_xyz_tmp_s32[SMI130_YAS_TEMP_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + u8 i = SMI130_INIT_VALUE; + s8 com_rslt = SMI130_INIT_VALUE; + u8 v_busy_u8 = SMI130_INIT_VALUE; + u8 v_rcoil_u8 = SMI130_INIT_VALUE; + u16 v_temperature_u16 = SMI130_INIT_VALUE; + u16 a_xy1y2_u16[SMI130_YAS_XY1Y2_DATA_SIZE] = { + SMI130_INIT_VALUE, SMI130_INIT_VALUE, SMI130_INIT_VALUE}; + *v_ouflow_u8 = 0; + /* read the yas537 xy1y2 data*/ + com_rslt = smi130_bosch_yamaha_yas537_read_xy1y2_data( + &v_rcoil_u8, &v_busy_u8, + &v_temperature_u16, a_xy1y2_u16, v_ouflow_u8); + /* linear calculation*/ + xy1y2_to_xyz(a_xy1y2_u16, vector_xyz->yas537_vector_xyz); + if (yas537_data.transform != SMI130_NULL) { + for (i = 0; i < 3; i++) { + a_xyz_tmp_s32[i] = (( + yas537_data.transform[i + 3] + * vector_xyz->yas537_vector_xyz[0]) + + (yas537_data.transform[ + i* 3 + 1] + * vector_xyz->yas537_vector_xyz[1]) + + (yas537_data.transform[ + i* 3 + 2] + * vector_xyz->yas537_vector_xyz[2])); + } + yas537_set_vector( + vector_xyz->yas537_vector_xyz, a_xyz_tmp_s32); + } + for (i = 0; i < 3; i++) { + vector_xyz->yas537_vector_xyz[i] -= + vector_xyz->yas537_vector_xyz[i] % 10; + if (*v_ouflow_u8 & (1 << + (i* 2))) + vector_xyz->yas537_vector_xyz[i] += + 1; /* set overflow*/ + if (*v_ouflow_u8 & (1 << (i* 2 + 1))) + /* set underflow*/ + vector_xyz->yas537_vector_xyz[i] += 2; + } + if (v_busy_u8) + return ERROR; + switch (yas537_data.measure_state) { + case YAS537_MAG_STATE_INIT_COIL: + if (p_smi130->mag_manual_enable != SMI130_MANUAL_ENABLE) + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_ENABLE); + com_rslt += smi130_set_mag_write_data(YAS537_WRITE_CONFR); + p_smi130->delay_msec(SMI130_GEN_READ_WRITE_DELAY); + com_rslt += smi130_set_mag_write_addr(YAS537_REG_CONFR); + p_smi130->delay_msec(SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + yas537_data.measure_state = YAS537_MAG_STATE_RECORD_DATA; + if (p_smi130->mag_manual_enable == SMI130_MANUAL_ENABLE) + com_rslt = smi130_set_mag_manual_enable( + SMI130_MANUAL_DISABLE); + break; + case YAS537_MAG_STATE_RECORD_DATA: + if (v_rcoil_u8) + break; + yas537_set_vector(yas537_data.last_after_rcoil, a_xy1y2_u16); + yas537_data.measure_state = YAS537_MAG_STATE_NORMAL; + break; + case YAS537_MAG_STATE_NORMAL: + if (SMI130_INIT_VALUE < v_ouflow_u8 + || invalid_magnetic_field(a_xy1y2_u16, + yas537_data.last_after_rcoil)) { + yas537_data.measure_state = YAS537_MAG_STATE_INIT_COIL; + for (i = 0; i < 3; i++) { + if (!*v_ouflow_u8) + vector_xyz->yas537_vector_xyz[i] += 3; + } + } + break; + } + + return com_rslt; +} +/*! +* @brief This function used for reading +* smi130_t structure +* +* @return the reference and values of smi130_t +* +* +*/ +struct smi130_t*smi130_get_ptr(void) +{ + return p_smi130; +} diff --git a/smi130.h b/smi130.h new file mode 100644 index 000000000000..fe2032b695a1 --- /dev/null +++ b/smi130.h @@ -0,0 +1,11848 @@ +/* +**************************************************************************** +* Copyright (C) 2014 Bosch Sensortec GmbH +* +* (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved +* +* smi130.h +* @Date : 2015/04/02 +* @Modification Date 2018/06/21 15:03 +* @id 836294d +* Revision : 2.0.9 $ +* @brief +* The head file of SMI130API +* +* Special: Description of the Software: +* +* This software module (hereinafter called "Software") and any +* information on application-sheets (hereinafter called "Information") is +* provided free of charge for the sole purpose to support your application +* work. +* +* As such, the Software is merely an experimental software, not tested for +* safety in the field and only intended for inspiration for further development +* and testing. Any usage in a safety-relevant field of use (like automotive, +* seafaring, spacefaring, industrial plants etc.) was not intended, so there are +* no precautions for such usage incorporated in the Software. +* +* The Software is specifically designed for the exclusive use for Bosch +* Sensortec products by personnel who have special experience and training. Do +* not use this Software if you do not have the proper experience or training. +* +* This Software package is provided as is and without any expressed or +* implied warranties, including without limitation, the implied warranties of +* merchantability and fitness for a particular purpose. +* +* Bosch Sensortec and their representatives and agents deny any liability for +* the functional impairment of this Software in terms of fitness, performance +* and safety. Bosch Sensortec and their representatives and agents shall not be +* liable for any direct or indirect damages or injury, except as otherwise +* stipulated in mandatory applicable law. +* The Information provided is believed to be accurate and reliable. Bosch +* Sensortec assumes no responsibility for the consequences of use of such +* Information nor for any infringement of patents or other rights of third +* parties which may result from its use. +* +*------------------------------------------------------------------------------ +* The following Product Disclaimer does not apply to the BSX4-HAL-4.1NoFusion Software +* which is licensed under the Apache License, Version 2.0 as stated above. +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Product Disclaimer +* +* Common: +* +* Assessment of Products Returned from Field +* +* Returned products are considered good if they fulfill the specifications / +* test data for 0-mileage and field listed in this document. +* +* Engineering Samples +* +* Engineering samples are marked with (e) or (E). Samples may vary from the +* valid technical specifications of the series product contained in this +* data sheet. Therefore, they are not intended or fit for resale to +* third parties or for use in end products. Their sole purpose is internal +* client testing. The testing of an engineering sample may in no way replace +* the testing of a series product. Bosch assumes no liability for the use +* of engineering samples. The purchaser shall indemnify Bosch from all claims +* arising from the use of engineering samples. +* +* Intended use +* +* Provided that SMI130 is used within the conditions (environment, application, +* installation, loads) as described in this TCD and the corresponding +* agreed upon documents, Bosch ensures that the product complies with +* the agreed properties. Agreements beyond this require +* the written approval by Bosch. The product is considered fit for the intended +* use when the product successfully has passed the tests +* in accordance with the TCD and agreed upon documents. +* +* It is the responsibility of the customer to ensure the proper application +* of the product in the overall system/vehicle. +* +* Bosch does not assume any responsibility for changes to the environment +* of the product that deviate from the TCD and the agreed upon documents +* as well as all applications not released by Bosch +* +* The resale and/or use of products are at the purchaser’s own risk and +* responsibility. The examination and testing of the SMI130 +* is the sole responsibility of the purchaser. +* +* The purchaser shall indemnify Bosch from all third party claims +* arising from any product use not covered by the parameters of +* this product data sheet or not approved by Bosch and reimburse Bosch +* for all costs and damages in connection with such claims. +* +* The purchaser must monitor the market for the purchased products, +* particularly with regard to product safety, and inform Bosch without delay +* of all security relevant incidents. +* +* Application Examples and Hints +* +* With respect to any application examples, advice, normal values +* and/or any information regarding the application of the device, +* Bosch hereby disclaims any and all warranties and liabilities of any kind, +* including without limitation warranties of +* non-infringement of intellectual property rights or copyrights +* of any third party. +* The information given in this document shall in no event be regarded +* as a guarantee of conditions or characteristics. They are provided +* for illustrative purposes only and no evaluation regarding infringement +* of intellectual property rights or copyrights or regarding functionality, +* performance or error has been made. +* +* +**************************************************************************/ +/*! \file smi130.h + \brief SMI130 Sensor Driver Support Header File */ +/* user defined code to be added here ... */ +#ifndef __SMI130_H__ +#define __SMI130_H__ + +/*! +* @brief The following definition uses for define the data types +* +* @note While porting the API please consider the following +* @note Please check the version of C standard +* @note Are you using Linux platform +*/ + +/*! +* @brief For the Linux platform support +* Please use the types.h for your data types definitions +*/ +#ifdef __KERNEL__ + +#include <linux/types.h> + +#else /* ! __KERNEL__ */ +/********************************************************** +* These definition uses for define the C +* standard version data types +***********************************************************/ +# if !defined(__STDC_VERSION__) + +/************************************************ + * compiler is C11 C standard +************************************************/ +#if (__STDC_VERSION__ == 201112L) + +/************************************************/ +#include <stdint.h> +/************************************************/ + +/*unsigned integer types*/ +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t + +/*signed integer types*/ +#define s8 int8_t +#define s16 int16_t +#define s32 int32_t +#define s64 int64_t +/************************************************ + * compiler is C99 C standard +************************************************/ + +#elif (__STDC_VERSION__ == 199901L) + +/* stdint.h is a C99 supported c library. +which is used to fixed the integer size*/ +/************************************************/ +#include <stdint.h> +/************************************************/ + +/*unsigned integer types*/ +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t + +/*signed integer types*/ +#define s8 int8_t +#define s16 int16_t +#define s32 int32_t +#define s64 int64_t +/************************************************ + * compiler is C89 or other C standard +************************************************/ +#else /* !defined(__STDC_VERSION__) */ +/* By default it is defined as 32 bit machine configuration*/ +/* define the definition based on your machine configuration*/ +/* define the data types based on your + machine/compiler/controller configuration*/ +#define MACHINE_32_BIT + +/* If your machine support 16 bit +define the MACHINE_16_BIT*/ +#ifdef MACHINE_16_BIT +#include <limits.h> +/*signed integer types*/ +#define s8 signed char +#define s16 signed short int +#define s32 signed long int + +#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL +#define s64 long int +#define u64 unsigned long int +#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) +#define s64 long long int +#define u64 unsigned long long int +#else +#warning Either the correct data type for signed 64 bit integer \ +could not be found, or 64 bit integers are not supported in your environment. +#warning If 64 bit integers are supported on your platform, \ +please set s64 manually. +#endif + +/*unsigned integer types*/ +#define u8 unsigned char +#define u16 unsigned short int +#define u32 unsigned long int + +/* If your machine support 32 bit +define the MACHINE_32_BIT*/ +#elif defined MACHINE_32_BIT +/*signed integer types*/ +#define s8 signed char +#define s16 signed short int +#define s32 signed int +#define s64 signed long long int + +/*unsigned integer types*/ +#define u8 unsigned char +#define u16 unsigned short int +#define u32 unsigned int +#define u64 unsigned long long int + +/* If your machine support 64 bit +define the MACHINE_64_BIT*/ +#elif defined MACHINE_64_BIT +/*signed integer types*/ +#define s8 signed char +#define s16 signed short int +#define s32 signed int +#define s64 signed long int + +/*unsigned integer types*/ +#define u8 unsigned char +#define u16 unsigned short int +#define u32 unsigned int +#define u64 unsigned long int + +#else +#warning The data types defined above which not supported \ +define the data types manually +#endif +#endif + +/*** This else will execute for the compilers + * which are not supported the C standards + * Like C89/C99/C11***/ +#else +/* By default it is defined as 32 bit machine configuration*/ +/* define the definition based on your machine configuration*/ +/* define the data types based on your + machine/compiler/controller configuration*/ +#define MACHINE_32_BIT + +/* If your machine support 16 bit +define the MACHINE_16_BIT*/ +#ifdef MACHINE_16_BIT +#include <limits.h> +/*signed integer types*/ +#define s8 signed char +#define s16 signed short int +#define s32 signed long int + +#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL +#define s64 long int +#define u64 unsigned long int +#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) +#define s64 long long int +#define u64 unsigned long long int +#else +#warning Either the correct data type for signed 64 bit integer \ +could not be found, or 64 bit integers are not supported in your environment. +#warning If 64 bit integers are supported on your platform, \ +please set s64 manually. +#endif + +/*unsigned integer types*/ +#define u8 unsigned char +#define u16 unsigned short int +#define u32 unsigned long int + +/* If your machine support 32 bit +define the MACHINE_32_BIT*/ +#elif defined MACHINE_32_BIT +/*signed integer types*/ +#define s8 signed char +#define s16 signed short int +#define s32 signed int +#define s64 signed long long int + +/*unsigned integer types*/ +#define u8 unsigned char +#define u16 unsigned short int +#define u32 unsigned int +#define u64 unsigned long long int + +/* If your machine support 64 bit +define the MACHINE_64_BIT*/ +#elif defined MACHINE_64_BIT +/*signed integer types*/ +#define s8 signed char +#define s16 signed short int +#define s32 signed int +#define s64 signed long int + +/*unsigned integer types*/ +#define u8 unsigned char +#define u16 unsigned short int +#define u32 unsigned int +#define u64 unsigned long int + +#else +#warning The data types defined above which not supported \ +define the data types manually +#endif +#endif +#endif +/***************************************************************/ +/**\name BUS READ AND WRITE FUNCTION POINTERS */ +/***************************************************************/ +/*! + @brief Define the calling convention of YOUR bus communication routine. + @note This includes types of parameters. This example shows the + configuration for an SPI bus link. + + If your communication function looks like this: + + write_my_bus_xy(u8 device_addr, u8 register_addr, + u8 * data, u8 length); + + The SMI130_WR_FUNC_PTR would equal: + + SMI130_WR_FUNC_PTR s8 (* bus_write)(u8, + u8, u8 *, u8) + + Parameters can be mixed as needed refer to the + @ref SMI130_BUS_WRITE_FUNC macro. + + +*/ +#define SMI130_WR_FUNC_PTR s8 (*bus_write)(u8, u8,\ +u8 *, u8) +/**< link macro between API function calls and bus write function + @note The bus write function can change since this is a + system dependant issue. + + If the bus_write parameter calling order is like: reg_addr, + reg_data, wr_len it would be as it is here. + + If the parameters are differently ordered or your communication + function like I2C need to know the device address, + you can change this macro accordingly. + + + SMI130_BUS_WRITE_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ + bus_write(dev_addr, reg_addr, reg_data, wr_len) + + This macro lets all API functions call YOUR communication routine in a + way that equals your definition in the + @ref SMI130_WR_FUNC_PTR definition. + +*/ +#define SMI130_BUS_WRITE_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ + bus_write(dev_addr, reg_addr, reg_data, wr_len) + +/**< Define the calling convention of YOUR bus communication routine. + @note This includes types of parameters. This example shows the + configuration for an SPI bus link. + + If your communication function looks like this: + + read_my_bus_xy(u8 device_addr, u8 register_addr, + u8 * data, u8 length); + + The SMI130_RD_FUNC_PTR would equal: + + SMI130_RD_FUNC_PTR s8 (* bus_read)(u8, + u8, u8 *, u8) + + Parameters can be mixed as needed refer to the + refer SMI130_BUS_READ_FUNC macro. + +*/ +#define SMI130_SPI_RD_MASK (0x80) /* for spi read transactions on SPI the + MSB has to be set */ +#define SMI130_RD_FUNC_PTR s8 (*bus_read)(u8,\ + u8, u8 *, u8) + +#define SMI130_BRD_FUNC_PTR s8 \ +(*burst_read)(u8, u8, u8 *, u32) + +/**< link macro between API function calls and bus read function + @note The bus write function can change since this is a + system dependant issue. + + If the bus_read parameter calling order is like: reg_addr, + reg_data, wr_len it would be as it is here. + + If the parameters are differently ordered or your communication + function like I2C need to know the device address, + you can change this macro accordingly. + + + SMI130_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ + bus_read(dev_addr, reg_addr, reg_data, wr_len) + + This macro lets all API functions call YOUR communication routine in a + way that equals your definition in the + refer SMI130_WR_FUNC_PTR definition. + + @note: this macro also includes the "MSB='1' + for reading SMI130 addresses. + +*/ +#define SMI130_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, r_len)\ + bus_read(dev_addr, reg_addr, reg_data, r_len) + +#define SMI130_BURST_READ_FUNC(device_addr, \ +register_addr, register_data, rd_len)\ +burst_read(device_addr, register_addr, register_data, rd_len) + + +#define SMI130_MDELAY_DATA_TYPE u32 + +/***************************************************************/ +/**\name BUS READ AND WRITE FUNCTION POINTERS */ +/***************************************************************/ +#define SMI130_I2C_ADDR1 0x68 /**< I2C Address needs to be changed */ +#define SMI130_I2C_ADDR2 0x18 /**< I2C Address needs to be changed */ +#define SMI130_AUX_BMM150_I2C_ADDRESS (0x10) +#define SMI130_AUX_YAS532_I2C_ADDRESS (0x2E) +/**< I2C address of YAS532*/ +#define SMI130_AKM09911_I2C_ADDRESS 0x0C/**< I2C address of AKM09911*/ +/**< I2C address of AKM09911*/ +#define SMI130_AUX_AKM09911_I2C_ADDR_2 (0x0D) +/**< I2C address of AKM09911*/ +#define SMI130_AUX_AKM09912_I2C_ADDR_1 (0x0C) +/**< I2C address of AKM09912*/ +#define SMI130_AUX_AKM09912_I2C_ADDR_2 (0x0D) +/**< I2C address of AKM09912*/ +#define SMI130_AUX_AKM09912_I2C_ADDR_3 (0x0E) +/**< I2C address of AKM09912*/ +#define SMI130_AKM09912_I2C_ADDRESS 0x0F/**< I2C address of akm09912*/ + +#define SMI130_YAS532_I2C_ADDRESS 0x2E/**< I2C address of YAS532*/ +/*******************************************/ +/**\name CONSTANTS */ +/******************************************/ +#define SMI130_INIT_VALUE (0) +#define SMI130_GEN_READ_WRITE_DATA_LENGTH (1) +#define SMI130_MAXIMUM_TIMEOUT (10) +/* output data rate condition check*/ +#define SMI130_OUTPUT_DATA_RATE0 (0) +#define SMI130_OUTPUT_DATA_RATE1 (1) +#define SMI130_OUTPUT_DATA_RATE2 (2) +#define SMI130_OUTPUT_DATA_RATE3 (3) +#define SMI130_OUTPUT_DATA_RATE4 (4) +#define SMI130_OUTPUT_DATA_RATE5 (5) +#define SMI130_OUTPUT_DATA_RATE6 (14) +#define SMI130_OUTPUT_DATA_RATE7 (15) +/* accel range check*/ +#define SMI130_ACCEL_RANGE0 (3) +#define SMI130_ACCEL_RANGE1 (5) +#define SMI130_ACCEL_RANGE3 (8) +#define SMI130_ACCEL_RANGE4 (12) +/* check the status of registers*/ +#define SMI130_FOC_STAT_HIGH (1) +#define SMI130_SIG_MOTION_STAT_HIGH (1) +#define SMI130_STEP_DET_STAT_HIGH (1) + +/*condition check for reading and writing data*/ +#define SMI130_MAX_VALUE_SIGNIFICANT_MOTION (1) +#define SMI130_MAX_VALUE_FIFO_FILTER (1) +#define SMI130_MAX_VALUE_FIFO_TIME (1) +#define SMI130_MAX_VALUE_FIFO_INTR (1) +#define SMI130_MAX_VALUE_FIFO_HEADER (1) +#define SMI130_MAX_VALUE_FIFO_MAG (1) +#define SMI130_MAX_VALUE_FIFO_ACCEL (1) +#define SMI130_MAX_VALUE_FIFO_GYRO (1) +#define SMI130_MAX_VALUE_SOURCE_INTR (1) +#define SMI130_MAX_VALUE_LOW_G_MODE (1) +#define SMI130_MAX_VALUE_NO_MOTION (1) +#define SMI130_MAX_VALUE_TAP_SHOCK (1) +#define SMI130_MAX_VALUE_TAP_QUIET (1) +#define SMI130_MAX_VALUE_ORIENT_UD (1) +#define SMI130_MAX_VALUE_ORIENT_AXES (1) +#define SMI130_MAX_VALUE_NVM_PROG (1) +#define SMI130_MAX_VALUE_SPI3 (1) +#define SMI130_MAX_VALUE_PAGE (1) +#define SMI130_MAX_VALUE_I2C_WDT (1) +#define SMI130_MAX_VALUE_SLEEP_STATE (1) +#define SMI130_MAX_VALUE_WAKEUP_INTR (1) +#define SMI130_MAX_VALUE_SELFTEST_SIGN (1) +#define SMI130_MAX_VALUE_SELFTEST_AMP (1) +#define SMI130_MAX_VALUE_SELFTEST_START (1) +#define SMI130_MAX_GYRO_WAKEUP_TRIGGER (3) +#define SMI130_MAX_ACCEL_SELFTEST_AXIS (3) +#define SMI130_MAX_GYRO_STEP_COUNTER (1) +#define SMI130_MAX_GYRO_BW (3) +#define SMI130_MAX_ACCEL_BW (7) +#define SMI130_MAX_ORIENT_MODE (3) +#define SMI130_MAX_ORIENT_BLOCKING (3) +#define SMI130_MAX_FLAT_HOLD (3) +#define SMI130_MAX_ACCEL_FOC (3) +#define SMI130_MAX_IF_MODE (3) +#define SMI130_MAX_TARGET_PAGE (3) +#define SMI130_MAX_GYRO_RANGE (4) +#define SMI130_MAX_GYRO_SLEEP_TIGGER (7) +#define SMI130_MAX_TAP_TURN (7) +#define SMI130_MAX_UNDER_SAMPLING (1) +#define SMI130_MAX_UNDER_SIG_MOTION (3) +#define SMI130_MAX_ACCEL_OUTPUT_DATA_RATE (12) +#define SMI130_MAX_LATCH_INTR (15) +#define SMI130_MAX_FLAT_HYST (15) +#define SMI130_MAX_ORIENT_THETA (63) +#define SMI130_MAX_FLAT_THETA (63) + +/* FIFO index definitions*/ +#define SMI130_FIFO_X_LSB_DATA (0) +#define SMI130_FIFO_X_MSB_DATA (1) +#define SMI130_FIFO_Y_LSB_DATA (2) +#define SMI130_FIFO_Y_MSB_DATA (3) +#define SMI130_FIFO_Z_LSB_DATA (4) +#define SMI130_FIFO_Z_MSB_DATA (5) +#define SMI130_FIFO_R_LSB_DATA (6) +#define SMI130_FIFO_R_MSB_DATA (7) +/* FIFO gyro definition*/ +#define SMI130_GA_FIFO_G_X_LSB (0) +#define SMI130_GA_FIFO_G_X_MSB (1) +#define SMI130_GA_FIFO_G_Y_LSB (2) +#define SMI130_GA_FIFO_G_Y_MSB (3) +#define SMI130_GA_FIFO_G_Z_LSB (4) +#define SMI130_GA_FIFO_G_Z_MSB (5) +#define SMI130_GA_FIFO_A_X_LSB (6) +#define SMI130_GA_FIFO_A_X_MSB (7) +#define SMI130_GA_FIFO_A_Y_LSB (8) +#define SMI130_GA_FIFO_A_Y_MSB (9) +#define SMI130_GA_FIFO_A_Z_LSB (10) +#define SMI130_GA_FIFO_A_Z_MSB (11) +/* FIFO mag/gyro/accel definition*/ +#define SMI130_MGA_FIFO_M_X_LSB (0) +#define SMI130_MGA_FIFO_M_X_MSB (1) +#define SMI130_MGA_FIFO_M_Y_LSB (2) +#define SMI130_MGA_FIFO_M_Y_MSB (3) +#define SMI130_MGA_FIFO_M_Z_LSB (4) +#define SMI130_MGA_FIFO_M_Z_MSB (5) +#define SMI130_MGA_FIFO_M_R_LSB (6) +#define SMI130_MGA_FIFO_M_R_MSB (7) +#define SMI130_MGA_FIFO_G_X_LSB (8) +#define SMI130_MGA_FIFO_G_X_MSB (9) +#define SMI130_MGA_FIFO_G_Y_LSB (10) +#define SMI130_MGA_FIFO_G_Y_MSB (11) +#define SMI130_MGA_FIFO_G_Z_LSB (12) +#define SMI130_MGA_FIFO_G_Z_MSB (13) +#define SMI130_MGA_FIFO_A_X_LSB (14) +#define SMI130_MGA_FIFO_A_X_MSB (15) +#define SMI130_MGA_FIFO_A_Y_LSB (16) +#define SMI130_MGA_FIFO_A_Y_MSB (17) +#define SMI130_MGA_FIFO_A_Z_LSB (18) +#define SMI130_MGA_FIFO_A_Z_MSB (19) +/* FIFO mag definition*/ +#define SMI130_MA_FIFO_M_X_LSB (0) +#define SMI130_MA_FIFO_M_X_MSB (1) +#define SMI130_MA_FIFO_M_Y_LSB (2) +#define SMI130_MA_FIFO_M_Y_MSB (3) +#define SMI130_MA_FIFO_M_Z_LSB (4) +#define SMI130_MA_FIFO_M_Z_MSB (5) +#define SMI130_MA_FIFO_M_R_LSB (6) +#define SMI130_MA_FIFO_M_R_MSB (7) +#define SMI130_MA_FIFO_A_X_LSB (8) +#define SMI130_MA_FIFO_A_X_MSB (9) +#define SMI130_MA_FIFO_A_Y_LSB (10) +#define SMI130_MA_FIFO_A_Y_MSB (11) +#define SMI130_MA_FIFO_A_Z_LSB (12) +#define SMI130_MA_FIFO_A_Z_MSB (13) +/* FIFO mag/gyro definition*/ +#define SMI130_MG_FIFO_M_X_LSB (0) +#define SMI130_MG_FIFO_M_X_MSB (1) +#define SMI130_MG_FIFO_M_Y_LSB (2) +#define SMI130_MG_FIFO_M_Y_MSB (3) +#define SMI130_MG_FIFO_M_Z_LSB (4) +#define SMI130_MG_FIFO_M_Z_MSB (5) +#define SMI130_MG_FIFO_M_R_LSB (6) +#define SMI130_MG_FIFO_M_R_MSB (7) +#define SMI130_MG_FIFO_G_X_LSB (8) +#define SMI130_MG_FIFO_G_X_MSB (9) +#define SMI130_MG_FIFO_G_Y_LSB (10) +#define SMI130_MG_FIFO_G_Y_MSB (11) +#define SMI130_MG_FIFO_G_Z_LSB (12) +#define SMI130_MG_FIFO_G_Z_MSB (13) +/* FIFO length definitions*/ +#define SMI130_FIFO_SENSOR_TIME_LSB (0) +#define SMI130_FIFO_SENSOR_TIME_XLSB (1) +#define SMI130_FIFO_SENSOR_TIME_MSB (2) +#define SMI130_FIFO_SENSOR_TIME_LENGTH (3) +#define SMI130_FIFO_A_LENGTH (6) +#define SMI130_FIFO_G_LENGTH (6) +#define SMI130_FIFO_M_LENGTH (8) +#define SMI130_FIFO_AG_LENGTH (12) +#define SMI130_FIFO_AMG_LENGTH (20) +#define SMI130_FIFO_MA_OR_MG_LENGTH (14) + +/* bus read and write length for mag, accel and gyro*/ +#define SMI130_MAG_X_DATA_LENGTH (2) +#define SMI130_MAG_Y_DATA_LENGTH (2) +#define SMI130_MAG_Z_DATA_LENGTH (2) +#define SMI130_MAG_R_DATA_LENGTH (2) +#define SMI130_MAG_XYZ_DATA_LENGTH (6) +#define SMI130_MAG_XYZR_DATA_LENGTH (8) +#define SMI130_MAG_YAS_DATA_LENGTH (8) +#define SMI130_GYRO_DATA_LENGTH (2) +#define SMI130_GYRO_XYZ_DATA_LENGTH (6) +#define SMI130_ACCEL_DATA_LENGTH (2) +#define SMI130_ACCEL_XYZ_DATA_LENGTH (6) +#define SMI130_TEMP_DATA_LENGTH (2) +#define SMI130_FIFO_DATA_LENGTH (2) +#define SMI130_STEP_COUNTER_LENGTH (2) +#define SMI130_SENSOR_TIME_LENGTH (3) + +/* Delay definitions*/ +#define SMI130_SEC_INTERFACE_GEN_READ_WRITE_DELAY (5) +#define SMI130_BMM150_WAKEUP_DELAY1 (2) +#define SMI130_BMM150_WAKEUP_DELAY2 (3) +#define SMI130_BMM150_WAKEUP_DELAY3 (1) +#define SMI130_YAS532_OFFSET_DELAY (2) +#define SMI130_GEN_READ_WRITE_DELAY (1) +#define SMI130_YAS532_MEASUREMENT_DELAY (25) +#define SMI130_YAS_ACQ_COMMAND_DELAY (50) +#define SMI130_YAS532_SET_INITIAL_VALUE_DELAY (200) +#define SMI130_AKM_INIT_DELAY (60) +/****************************************************/ +/**\name ARRAY SIZE DEFINITIONS */ +/***************************************************/ +#define SMI130_ACCEL_X_DATA_SIZE (2) +#define SMI130_ACCEL_Y_DATA_SIZE (2) +#define SMI130_ACCEL_Z_DATA_SIZE (2) +#define SMI130_ACCEL_XYZ_DATA_SIZE (6) + +#define SMI130_GYRO_X_DATA_SIZE (2) +#define SMI130_GYRO_Y_DATA_SIZE (2) +#define SMI130_GYRO_Z_DATA_SIZE (2) +#define SMI130_GYRO_XYZ_DATA_SIZE (6) + +#define SMI130_MAG_X_DATA_SIZE (2) +#define SMI130_MAG_Y_DATA_SIZE (2) +#define SMI130_MAG_Z_DATA_SIZE (2) +#define SMI130_MAG_R_DATA_SIZE (2) +#define SMI130_MAG_XYZ_DATA_SIZE (6) +#define SMI130_MAG_XYZR_DATA_SIZE (8) +#define SMI130_MAG_TRIM_DATA_SIZE (16) + + +#define SMI130_TEMP_DATA_SIZE (2) +#define SMI130_FIFO_DATA_SIZE (2) +#define SMI130_STEP_COUNT_DATA_SIZE (2) + +#define SMI130_SENSOR_TIME_DATA_SIZE (3) +#define SMI130_AKM_SENSITIVITY_DATA_SIZE (3) +#define SMI130_HARD_OFFSET_DATA_SIZE (3) +#define SMI130_YAS_XY1Y2_DATA_SIZE (3) +#define SMI130_YAS_FLAG_DATA_SIZE (3) +#define SMI130_YAS_TEMP_DATA_SIZE (3) +#define SMI130_YAS_H_DATA_SIZE (3) +#define SMI130_YAS_S_DATA_SIZE (3) +#define SMI130_YAS_CORRECT_DATA_SIZE (5) +#define SMI130_YAS_XY1Y2T_DATA_SIZE (8) +#define SMI130_YAS537_CALIB_DATA_SIZE (17) +#define SMI130_YAS532_CALIB_DATA_SIZE (14) +/****************************************************/ +/**\name ARRAY PARAMETER DEFINITIONS */ +/***************************************************/ +#define SMI130_SENSOR_TIME_MSB_BYTE (2) +#define SMI130_SENSOR_TIME_XLSB_BYTE (1) +#define SMI130_SENSOR_TIME_LSB_BYTE (0) + +#define SMI130_MAG_X_LSB_BYTE (0) +#define SMI130_MAG_X_MSB_BYTE (1) +#define SMI130_MAG_Y_LSB_BYTE (0) +#define SMI130_MAG_Y_MSB_BYTE (1) +#define SMI130_MAG_Z_LSB_BYTE (0) +#define SMI130_MAG_Z_MSB_BYTE (1) +#define SMI130_MAG_R_LSB_BYTE (0) +#define SMI130_MAG_R_MSB_BYTE (1) +#define SMI130_DATA_FRAME_MAG_X_LSB_BYTE (0) +#define SMI130_DATA_FRAME_MAG_X_MSB_BYTE (1) +#define SMI130_DATA_FRAME_MAG_Y_LSB_BYTE (2) +#define SMI130_DATA_FRAME_MAG_Y_MSB_BYTE (3) +#define SMI130_DATA_FRAME_MAG_Z_LSB_BYTE (4) +#define SMI130_DATA_FRAME_MAG_Z_MSB_BYTE (5) +#define SMI130_DATA_FRAME_MAG_R_LSB_BYTE (6) +#define SMI130_DATA_FRAME_MAG_R_MSB_BYTE (7) + +#define SMI130_GYRO_X_LSB_BYTE (0) +#define SMI130_GYRO_X_MSB_BYTE (1) +#define SMI130_GYRO_Y_LSB_BYTE (0) +#define SMI130_GYRO_Y_MSB_BYTE (1) +#define SMI130_GYRO_Z_LSB_BYTE (0) +#define SMI130_GYRO_Z_MSB_BYTE (1) +#define SMI130_DATA_FRAME_GYRO_X_LSB_BYTE (0) +#define SMI130_DATA_FRAME_GYRO_X_MSB_BYTE (1) +#define SMI130_DATA_FRAME_GYRO_Y_LSB_BYTE (2) +#define SMI130_DATA_FRAME_GYRO_Y_MSB_BYTE (3) +#define SMI130_DATA_FRAME_GYRO_Z_LSB_BYTE (4) +#define SMI130_DATA_FRAME_GYRO_Z_MSB_BYTE (5) + +#define SMI130_ACCEL_X_LSB_BYTE (0) +#define SMI130_ACCEL_X_MSB_BYTE (1) +#define SMI130_ACCEL_Y_LSB_BYTE (0) +#define SMI130_ACCEL_Y_MSB_BYTE (1) +#define SMI130_ACCEL_Z_LSB_BYTE (0) +#define SMI130_ACCEL_Z_MSB_BYTE (1) +#define SMI130_DATA_FRAME_ACCEL_X_LSB_BYTE (0) +#define SMI130_DATA_FRAME_ACCEL_X_MSB_BYTE (1) +#define SMI130_DATA_FRAME_ACCEL_Y_LSB_BYTE (2) +#define SMI130_DATA_FRAME_ACCEL_Y_MSB_BYTE (3) +#define SMI130_DATA_FRAME_ACCEL_Z_LSB_BYTE (4) +#define SMI130_DATA_FRAME_ACCEL_Z_MSB_BYTE (5) + +#define SMI130_TEMP_LSB_BYTE (0) +#define SMI130_TEMP_MSB_BYTE (1) + +#define SMI130_FIFO_LENGTH_LSB_BYTE (0) +#define SMI130_FIFO_LENGTH_MSB_BYTE (1) + +#define SMI130_STEP_COUNT_LSB_BYTE (0) +#define SMI130_STEP_COUNT_MSB_BYTE (1) +/****************************************************/ +/**\name ERROR CODES */ +/***************************************************/ + +#define E_SMI130_NULL_PTR ((s8)-127) +#define E_SMI130_COMM_RES ((s8)-1) +#define E_SMI130_OUT_OF_RANGE ((s8)-2) +#define E_SMI130_BUSY ((s8)-3) +#define SUCCESS ((u8)0) +#define ERROR ((s8)-1) + +/* Constants */ +#define SMI130_NULL (0) +#define SMI130_DELAY_SETTLING_TIME (5) +/*This refers SMI130 return type as s8 */ +#define SMI130_RETURN_FUNCTION_TYPE s8 +/****************************************************/ +/**\name REGISTER DEFINITIONS */ +/***************************************************/ +/*******************/ +/**\name CHIP ID */ +/*******************/ +#define SMI130_USER_CHIP_ID_ADDR (0x00) +/*******************/ +/**\name ERROR STATUS */ +/*******************/ +#define SMI130_USER_ERROR_ADDR (0X02) +/*******************/ +/**\name POWER MODE STATUS */ +/*******************/ +#define SMI130_USER_PMU_STAT_ADDR (0X03) +/*******************/ +/**\name MAG DATA REGISTERS */ +/*******************/ +#define SMI130_USER_DATA_0_ADDR (0X04) +#define SMI130_USER_DATA_1_ADDR (0X05) +#define SMI130_USER_DATA_2_ADDR (0X06) +#define SMI130_USER_DATA_3_ADDR (0X07) +#define SMI130_USER_DATA_4_ADDR (0X08) +#define SMI130_USER_DATA_5_ADDR (0X09) +#define SMI130_USER_DATA_6_ADDR (0X0A) +#define SMI130_USER_DATA_7_ADDR (0X0B) +/*******************/ +/**\name GYRO DATA REGISTERS */ +/*******************/ +#define SMI130_USER_DATA_8_ADDR (0X0C) +#define SMI130_USER_DATA_9_ADDR (0X0D) +#define SMI130_USER_DATA_10_ADDR (0X0E) +#define SMI130_USER_DATA_11_ADDR (0X0F) +#define SMI130_USER_DATA_12_ADDR (0X10) +#define SMI130_USER_DATA_13_ADDR (0X11) +#define SMI130_USER_DATA_14_ADDR (0X12) +#define SMI130_USER_DATA_15_ADDR (0X13) +/*******************/ +/**\name ACCEL DATA REGISTERS */ +/*******************/ +#define SMI130_USER_DATA_16_ADDR (0X14) +#define SMI130_USER_DATA_17_ADDR (0X15) +#define SMI130_USER_DATA_18_ADDR (0X16) +#define SMI130_USER_DATA_19_ADDR (0X17) +/*******************/ +/**\name SENSOR TIME REGISTERS */ +/*******************/ +#define SMI130_USER_SENSORTIME_0_ADDR (0X18) +#define SMI130_USER_SENSORTIME_1_ADDR (0X19) +#define SMI130_USER_SENSORTIME_2_ADDR (0X1A) +/*******************/ +/**\name STATUS REGISTER FOR SENSOR STATUS FLAG */ +/*******************/ +#define SMI130_USER_STAT_ADDR (0X1B) +/*******************/ +/**\name INTERRUPY STATUS REGISTERS */ +/*******************/ +#define SMI130_USER_INTR_STAT_0_ADDR (0X1C) +#define SMI130_USER_INTR_STAT_1_ADDR (0X1D) +#define SMI130_USER_INTR_STAT_2_ADDR (0X1E) +#define SMI130_USER_INTR_STAT_3_ADDR (0X1F) +/*******************/ +/**\name TEMPERATURE REGISTERS */ +/*******************/ +#define SMI130_USER_TEMPERATURE_0_ADDR (0X20) +#define SMI130_USER_TEMPERATURE_1_ADDR (0X21) +/*******************/ +/**\name FIFO REGISTERS */ +/*******************/ +#define SMI130_USER_FIFO_LENGTH_0_ADDR (0X22) +#define SMI130_USER_FIFO_LENGTH_1_ADDR (0X23) +#define SMI130_USER_FIFO_DATA_ADDR (0X24) +/***************************************************/ +/**\name ACCEL CONFIG REGISTERS FOR ODR, BANDWIDTH AND UNDERSAMPLING*/ +/******************************************************/ +#define SMI130_USER_ACCEL_CONFIG_ADDR (0X40) +/*******************/ +/**\name ACCEL RANGE */ +/*******************/ +#define SMI130_USER_ACCEL_RANGE_ADDR (0X41) +/***************************************************/ +/**\name GYRO CONFIG REGISTERS FOR ODR AND BANDWIDTH */ +/******************************************************/ +#define SMI130_USER_GYRO_CONFIG_ADDR (0X42) +/*******************/ +/**\name GYRO RANGE */ +/*******************/ +#define SMI130_USER_GYRO_RANGE_ADDR (0X43) +/***************************************************/ +/**\name MAG CONFIG REGISTERS FOR ODR*/ +/******************************************************/ +#define SMI130_USER_MAG_CONFIG_ADDR (0X44) +/***************************************************/ +/**\name REGISTER FOR GYRO AND ACCEL DOWNSAMPLING RATES FOR FIFO*/ +/******************************************************/ +#define SMI130_USER_FIFO_DOWN_ADDR (0X45) +/***************************************************/ +/**\name FIFO CONFIG REGISTERS*/ +/******************************************************/ +#define SMI130_USER_FIFO_CONFIG_0_ADDR (0X46) +#define SMI130_USER_FIFO_CONFIG_1_ADDR (0X47) +/***************************************************/ +/**\name MAG INTERFACE REGISTERS*/ +/******************************************************/ +#define SMI130_USER_MAG_IF_0_ADDR (0X4B) +#define SMI130_USER_MAG_IF_1_ADDR (0X4C) +#define SMI130_USER_MAG_IF_2_ADDR (0X4D) +#define SMI130_USER_MAG_IF_3_ADDR (0X4E) +#define SMI130_USER_MAG_IF_4_ADDR (0X4F) +/***************************************************/ +/**\name INTERRUPT ENABLE REGISTERS*/ +/******************************************************/ +#define SMI130_USER_INTR_ENABLE_0_ADDR (0X50) +#define SMI130_USER_INTR_ENABLE_1_ADDR (0X51) +#define SMI130_USER_INTR_ENABLE_2_ADDR (0X52) +#define SMI130_USER_INTR_OUT_CTRL_ADDR (0X53) +/***************************************************/ +/**\name LATCH DURATION REGISTERS*/ +/******************************************************/ +#define SMI130_USER_INTR_LATCH_ADDR (0X54) +/***************************************************/ +/**\name MAP INTERRUPT 1 and 2 REGISTERS*/ +/******************************************************/ +#define SMI130_USER_INTR_MAP_0_ADDR (0X55) +#define SMI130_USER_INTR_MAP_1_ADDR (0X56) +#define SMI130_USER_INTR_MAP_2_ADDR (0X57) +/***************************************************/ +/**\name DATA SOURCE REGISTERS*/ +/******************************************************/ +#define SMI130_USER_INTR_DATA_0_ADDR (0X58) +#define SMI130_USER_INTR_DATA_1_ADDR (0X59) +/***************************************************/ +/**\name +INTERRUPT THRESHOLD, HYSTERESIS, DURATION, MODE CONFIGURATION REGISTERS*/ +/******************************************************/ +#define SMI130_USER_INTR_LOWHIGH_0_ADDR (0X5A) +#define SMI130_USER_INTR_LOWHIGH_1_ADDR (0X5B) +#define SMI130_USER_INTR_LOWHIGH_2_ADDR (0X5C) +#define SMI130_USER_INTR_LOWHIGH_3_ADDR (0X5D) +#define SMI130_USER_INTR_LOWHIGH_4_ADDR (0X5E) +#define SMI130_USER_INTR_MOTION_0_ADDR (0X5F) +#define SMI130_USER_INTR_MOTION_1_ADDR (0X60) +#define SMI130_USER_INTR_MOTION_2_ADDR (0X61) +#define SMI130_USER_INTR_MOTION_3_ADDR (0X62) +#define SMI130_USER_INTR_TAP_0_ADDR (0X63) +#define SMI130_USER_INTR_TAP_1_ADDR (0X64) +#define SMI130_USER_INTR_ORIENT_0_ADDR (0X65) +#define SMI130_USER_INTR_ORIENT_1_ADDR (0X66) +#define SMI130_USER_INTR_FLAT_0_ADDR (0X67) +#define SMI130_USER_INTR_FLAT_1_ADDR (0X68) +/***************************************************/ +/**\name FAST OFFSET CONFIGURATION REGISTER*/ +/******************************************************/ +#define SMI130_USER_FOC_CONFIG_ADDR (0X69) +/***************************************************/ +/**\name MISCELLANEOUS CONFIGURATION REGISTER*/ +/******************************************************/ +#define SMI130_USER_CONFIG_ADDR (0X6A) +/***************************************************/ +/**\name SERIAL INTERFACE SETTINGS REGISTER*/ +/******************************************************/ +#define SMI130_USER_IF_CONFIG_ADDR (0X6B) +/***************************************************/ +/**\name GYRO POWER MODE TRIGGER REGISTER */ +/******************************************************/ +#define SMI130_USER_PMU_TRIGGER_ADDR (0X6C) +/***************************************************/ +/**\name SELF_TEST REGISTER*/ +/******************************************************/ +#define SMI130_USER_SELF_TEST_ADDR (0X6D) +/***************************************************/ +/**\name SPI,I2C SELECTION REGISTER*/ +/******************************************************/ +#define SMI130_USER_NV_CONFIG_ADDR (0x70) +/***************************************************/ +/**\name ACCEL AND GYRO OFFSET REGISTERS*/ +/******************************************************/ +#define SMI130_USER_OFFSET_0_ADDR (0X71) +#define SMI130_USER_OFFSET_1_ADDR (0X72) +#define SMI130_USER_OFFSET_2_ADDR (0X73) +#define SMI130_USER_OFFSET_3_ADDR (0X74) +#define SMI130_USER_OFFSET_4_ADDR (0X75) +#define SMI130_USER_OFFSET_5_ADDR (0X76) +#define SMI130_USER_OFFSET_6_ADDR (0X77) +/***************************************************/ +/**\name STEP COUNTER INTERRUPT REGISTERS*/ +/******************************************************/ +#define SMI130_USER_STEP_COUNT_0_ADDR (0X78) +#define SMI130_USER_STEP_COUNT_1_ADDR (0X79) +/***************************************************/ +/**\name STEP COUNTER CONFIGURATION REGISTERS*/ +/******************************************************/ +#define SMI130_USER_STEP_CONFIG_0_ADDR (0X7A) +#define SMI130_USER_STEP_CONFIG_1_ADDR (0X7B) +/***************************************************/ +/**\name COMMAND REGISTER*/ +/******************************************************/ +#define SMI130_CMD_COMMANDS_ADDR (0X7E) +/***************************************************/ +/**\name PAGE REGISTERS*/ +/******************************************************/ +#define SMI130_CMD_EXT_MODE_ADDR (0X7F) +#define SMI130_COM_C_TRIM_FIVE_ADDR (0X05) + +/****************************************************/ +/**\name SHIFT VALUE DEFINITION */ +/***************************************************/ +#define SMI130_SHIFT_BIT_POSITION_BY_01_BIT (1) +#define SMI130_SHIFT_BIT_POSITION_BY_02_BITS (2) +#define SMI130_SHIFT_BIT_POSITION_BY_03_BITS (3) +#define SMI130_SHIFT_BIT_POSITION_BY_04_BITS (4) +#define SMI130_SHIFT_BIT_POSITION_BY_05_BITS (5) +#define SMI130_SHIFT_BIT_POSITION_BY_06_BITS (6) +#define SMI130_SHIFT_BIT_POSITION_BY_07_BITS (7) +#define SMI130_SHIFT_BIT_POSITION_BY_08_BITS (8) +#define SMI130_SHIFT_BIT_POSITION_BY_09_BITS (9) +#define SMI130_SHIFT_BIT_POSITION_BY_12_BITS (12) +#define SMI130_SHIFT_BIT_POSITION_BY_13_BITS (13) +#define SMI130_SHIFT_BIT_POSITION_BY_14_BITS (14) +#define SMI130_SHIFT_BIT_POSITION_BY_15_BITS (15) +#define SMI130_SHIFT_BIT_POSITION_BY_16_BITS (16) + +/****************************************************/ +/**\name DEFINITIONS USED FOR YAMAHA-YAS532 */ +/***************************************************/ +#define YAS532_MAG_STATE_NORMAL (0) +#define YAS532_MAG_STATE_INIT_COIL (1) +#define YAS532_MAG_STATE_MEASURE_OFFSET (2) +#define YAS532_MAG_INITCOIL_TIMEOUT (1000) +#define YAS532_MAG_NOTRANS_POSITION (3) +#define YAS532_DEFAULT_SENSOR_DELAY (50) +#define YAS532_DATA_OVERFLOW (8190) +#define YAS532_DATA_UNDERFLOW (0) +#define YAS532_MAG_LOG (20) +#define YAS532_MAG_TEMPERATURE_LOG (10) +#define YAS532_TEMP20DEGREE_TYPICAL (390) +#define YAS532_VERSION_AC_COEF_X (850) +#define YAS532_VERSION_AC_COEF_Y1 (750) +#define YAS532_VERSION_AC_COEF_Y2 (750) +#define YAS532_DATA_CENTER (4096) +/****************************************************/ +/**\name YAMAHA-YAS532 OFFSET DEFINITION */ +/***************************************************/ +static const s8 INVALID_OFFSET[] = {0x7f, 0x7f, 0x7f}; +#define set_vector(to, from) \ + {int _l; for (_l = 0; _l < 3; _l++) (to)[_l] = (from)[_l]; } +#define is_valid_offset(a) \ + (((a)[0] <= 31) && ((a)[1] <= 31) && ((a)[2] <= 31) \ + && (-31 <= (a)[0]) && (-31 <= (a)[1]) && (-31 <= (a)[2])) + +/**************************************************/ +/**\name YAS532 CALIB DATA DEFINITIONS */ +/*************************************************/ + + +/* register address of YAS532*/ +#define SMI130_YAS532_TESTR1 (0x88) +#define SMI130_YAS532_TESTR2 (0x89) +#define SMI130_YAS532_RCOIL (0x81) +#define SMI130_YAS532_COMMAND_REGISTER (0x82) +#define SMI130_YAS532_DATA_REGISTER (0xB0) +/* calib data register definition*/ +#define SMI130_YAS532_CALIB_CX (0x90) +#define SMI130_YAS532_CALIB_CY1 (0x91) +#define SMI130_YAS532_CALIB_CY2 (0x92) +#define SMI130_YAS532_CALIB1 (0x93) +#define SMI130_YAS532_CALIB2 (0x94) +#define SMI130_YAS532_CALIB3 (0x95) +#define SMI130_YAS532_CALIB4 (0x96) +#define SMI130_YAS532_CALIB5 (0x97) +#define SMI130_YAS532_CLAIB6 (0x98) +#define SMI130_YAS532_CALIB7 (0x99) +#define SMI130_YAS532_CALIB8 (0x9A) +#define SMI130_YAS532_CALIIB9 (0x9B) +#define SMI130_YAS532_CALIB10 (0x9C) +#define SMI130_YAS532_CALIB11 (0x9D) +/* offset definition */ +#define SMI130_YAS532_OFFSET_X (0x85) +#define SMI130_YAS532_OFFSET_Y (0x86) +#define SMI130_YAS532_OFFSET_Z (0x87) +/* data to write register for yas532*/ +#define SMI130_YAS532_WRITE_TESTR1 (0x00) +#define SMI130_YAS532_WRITE_TESTR2 (0x00) +#define SMI130_YAS532_WRITE_RCOIL (0x00) +/**************************************************/ +/**\name YAS537 DEFINITION */ +/*************************************************/ + +#define YAS537_SRSTR_DATA (0x02) +#define YAS537_WRITE_A_D_CONVERTER (0x03) +#define YAS537_WRITE_A_D_CONVERTER2 (0xF8) +#define YAS537_WRITE_FILTER (0x08) +#define YAS537_WRITE_CONFR (0x08) +#define YAS537_WRITE_TEMP_CALIB (0xFF) +#define YAS537_SET_COMMAND_REGISTER (0x01) + +/**************************************************/ +/**\name YAS537 REGISTER DEFINITION */ +/*************************************************/ +#define YAS537_REG_SRSTR (0x90) +#define YAS537_REG_CALR_C0 (0xC0) +#define YAS537_REG_CALR_C1 (0xC1) +#define YAS537_REG_CALR_C2 (0xC2) +#define YAS537_REG_CALR_C3 (0xC3) +#define YAS537_REG_CALR_C4 (0xC4) +#define YAS537_REG_CALR_C5 (0xC5) +#define YAS537_REG_CALR_C6 (0xC6) +#define YAS537_REG_CALR_C7 (0xC7) +#define YAS537_REG_CALR_C8 (0xC8) +#define YAS537_REG_CALR_C9 (0xC9) +#define YAS537_REG_CALR_CA (0xCA) +#define YAS537_REG_CALR_CB (0xCB) +#define YAS537_REG_CALR_CC (0xCC) +#define YAS537_REG_CALR_CD (0xCD) +#define YAS537_REG_CALR_CE (0xCE) +#define YAS537_REG_CALR_CF (0xCF) +#define YAS537_REG_CALR_DO (0xD0) +#define YAS537_REG_MTCR (0x93) +#define YAS537_REG_CONFR (0x82) +#define SMI130_REG_YAS537_CMDR (0x81) +#define YAS537_REG_OXR (0x84) +#define YAS537_REG_AVRR (0x87) +#define YAS537_REG_HCKR (0x88) +#define YAS537_REG_LCKR (0x89) +#define YAS537_REG_ADCCALR (0x91) +#define YAS537_REG_ADCCALR_ONE (0x92) +#define YAS537_REG_OCR (0x9E) +#define YAS537_REG_TRMR (0x9F) +#define YAS537_REG_TEMPERATURE_0 (0xB0) +#define YAS537_REG_TEMPERATURE_1 (0xB1) +#define YAS537_REG_DATA_X_0 (0xB2) +#define YAS537_REG_DATA_X_1 (0xB3) +#define YAS537_REG_DATA_Y1_0 (0xB4) +#define YAS537_REG_DATA_Y1_1 (0xB5) +#define YAS537_REG_DATA_Y2_0 (0xB6) +#define YAS537_REG_DATA_Y2_1 (0xB7) +#define YAS537_MAG_STATE_NORMAL (0) +#define YAS537_MAG_STATE_INIT_COIL (1) +#define YAS537_MAG_STATE_RECORD_DATA (2) +#define YAS537_DATA_UNDERFLOW (0) +#define YAS537_DATA_OVERFLOW (16383) +/****************************************************/ +/**\name YAS537_set vector */ +/***************************************************/ +#define yas537_set_vector(to, from) \ + {int _l; for (_l = 0; _l < 3; _l++) (to)[_l] = (from)[_l]; } + +#ifndef ABS +#define ABS(a) ((a) > 0 ? (a) : -(a)) /*!< Absolute value */ +#endif +/****************************************************/ +/**\name AKM09911 AND AKM09912 DEFINITION */ +/***************************************************/ +#define AKM09912_SENSITIVITY_DIV (256) +#define AKM09912_SENSITIVITY (128) +#define AKM09911_SENSITIVITY_DIV (128) +#define AKM_ASAX (0) +#define AKM_ASAY (1) +#define AKM_ASAZ (2) +#define AKM_POWER_DOWN_MODE_DATA (0x00) +#define AKM_FUSE_ROM_MODE (0x1F) +#define AKM_POWER_MODE_REG (0x31) +#define AKM_SINGLE_MEASUREMENT_MODE (0x01) +#define AKM_DATA_REGISTER (0x11) +/*! AKM09912 Register definition */ +#define AKM09912_CHIP_ID_REG (0x01) +/****************************************************/ +/**\name BMM150 DEFINITION */ +/***************************************************/ +#define SMI130_BMM150_SET_POWER_CONTROL (0x01) +#define SMI130_BMM150_MAX_RETRY_WAKEUP (5) +#define SMI130_BMM150_POWER_ON (0x01) +#define SMI130_BMM150_POWER_OFF (0x00) +#define SMI130_BMM150_FORCE_MODE (0x02) +#define SMI130_BMM150_POWER_ON_SUCCESS (0) +#define SMI130_BMM150_POWER_ON_FAIL ((s8)-1) + +#define SMI130_BMM150_DIG_X1 (0) +#define SMI130_BMM150_DIG_Y1 (1) +#define SMI130_BMM150_DIG_X2 (2) +#define SMI130_BMM150_DIG_Y3 (3) +#define SMI130_BMM150_DIG_XY1 (4) +#define SMI130_BMM150_DIG_XY2 (5) +#define SMI130_BMM150_DIG_Z1_LSB (6) +#define SMI130_BMM150_DIG_Z1_MSB (7) +#define SMI130_BMM150_DIG_Z2_LSB (8) +#define SMI130_BMM150_DIG_Z2_MSB (9) +#define SMI130_BMM150_DIG_DIG_Z3_LSB (10) +#define SMI130_BMM150_DIG_DIG_Z3_MSB (11) +#define SMI130_BMM150_DIG_DIG_Z4_LSB (12) +#define SMI130_BMM150_DIG_DIG_Z4_MSB (13) +#define SMI130_BMM150_DIG_DIG_XYZ1_LSB (14) +#define SMI130_BMM150_DIG_DIG_XYZ1_MSB (15) + +/**************************************************************/ +/**\name STRUCTURE DEFINITIONS */ +/**************************************************************/ +/*! +* @brief smi130 structure +* This structure holds all relevant information about smi130 +*/ +struct smi130_t { +u8 chip_id;/**< chip id of SMI130 */ +u8 dev_addr;/**< device address of SMI130 */ +s8 mag_manual_enable;/**< used for check the mag manual/auto mode status */ +SMI130_WR_FUNC_PTR;/**< bus write function pointer */ +SMI130_RD_FUNC_PTR;/**< bus read function pointer */ +SMI130_BRD_FUNC_PTR;/**< burst write function pointer */ +void (*delay_msec)(SMI130_MDELAY_DATA_TYPE);/**< delay function pointer */ +}; +/*! + * @brief Structure containing bmm150 and akm09911 + * magnetometer values for x,y and + * z-axis in s16 + */ +struct smi130_mag_t { +s16 x;/**< BMM150 and AKM09911 and AKM09912 X raw data*/ +s16 y;/**< BMM150 and AKM09911 and AKM09912 Y raw data*/ +s16 z;/**< BMM150 and AKM09911 and AKM09912 Z raw data*/ +}; +/*! + * @brief Structure containing bmm150 xyz data and temperature + */ +struct smi130_mag_xyzr_t { +s16 x;/**< BMM150 X raw data*/ +s16 y;/**< BMM150 Y raw data*/ +s16 z;/**<BMM150 Z raw data*/ +u16 r;/**<BMM150 R raw data*/ +}; +/*! + * @brief Structure containing gyro xyz data + */ +struct smi130_gyro_t { +s16 x;/**<gyro X data*/ +s16 y;/**<gyro Y data*/ +s16 z;/**<gyro Z data*/ +}; +/*! + * @brief Structure containing accel xyz data + */ +struct smi130_accel_t { +s16 x;/**<accel X data*/ +s16 y;/**<accel Y data*/ +s16 z;/**<accel Z data*/ +}; +/*! + * @brief Structure bmm150 mag compensated data with s32 output + */ +struct smi130_mag_xyz_s32_t { +s16 x;/**<BMM150 X compensated data*/ +s16 y;/**<BMM150 Y compensated data*/ +s16 z;/**<BMM150 Z compensated data*/ +}; +/*! + * @brief Structure bmm150 mag trim data + */ +struct trim_data_t { +s8 dig_x1;/**<BMM150 trim x1 data*/ +s8 dig_y1;/**<BMM150 trim y1 data*/ + +s8 dig_x2;/**<BMM150 trim x2 data*/ +s8 dig_y2;/**<BMM150 trim y2 data*/ + +u16 dig_z1;/**<BMM150 trim z1 data*/ +s16 dig_z2;/**<BMM150 trim z2 data*/ +s16 dig_z3;/**<BMM150 trim z3 data*/ +s16 dig_z4;/**<BMM150 trim z4 data*/ + +u8 dig_xy1;/**<BMM150 trim xy1 data*/ +s8 dig_xy2;/**<BMM150 trim xy2 data*/ + +u16 dig_xyz1;/**<BMM150 trim xyz1 data*/ +}; + +/*! +* @brief Structure for reading AKM compensating data +*/ +struct bosch_akm_sensitivity_data_t { +u8 asax;/**<AKM09911 and AKM09912 X sensitivity data*/ +u8 asay;/**<AKM09911 and AKM09912 Y sensitivity data*/ +u8 asaz;/**<AKM09911 and AKM09912 Z sensitivity data*/ +}; +/*! +* @brief YAMAHA-YAS532 struct +* Calibration YAS532 data struct +*/ +struct bosch_yas532_calib_data_t { +s32 cx;/**<YAS532 calib cx data */ +s32 cy1;/**<YAS532 calib cy1 data */ +s32 cy2;/**<YAS532 calib cy2 data */ +s32 a2;/**<YAS532 calib a2 data */ +s32 a3;/**<YAS532 calib a3 data */ +s32 a4;/**<YAS532 calib a4 data */ +s32 a5;/**<YAS532 calib a5 data */ +s32 a6;/**<YAS532 calib a6 data */ +s32 a7;/**<YAS532 calib a7 data */ +s32 a8;/**<YAS532 calib a8 data */ +s32 a9;/**<YAS532 calib a9 data */ +s32 k;/**<YAS532 calib k data */ +s8 rxy1y2[3];/**<YAS532 calib rxy1y2 data */ +u8 fxy1y2[3];/**<YAS532 calib fxy1y2 data */ +}; +/*! +* @brief YAS532 Temperature structure +*/ +#if YAS532_MAG_LOG < YAS532_MAG_TEMPERATURE_LOG +struct yas_temp_filter_t { +u16 log[YAS532_MAG_TEMPERATURE_LOG];/**<YAS532 temp log array */ +u8 num;/**< used for increment the index */ +u8 idx;/**< used for increment the index */ +}; +#endif +/*! +* @brief YAS532 sensor initialization +*/ +struct yas532_t { +struct bosch_yas532_calib_data_t calib_yas532;/**< calib data */ +s8 measure_state;/**< update measure state */ +s8 v_hard_offset_s8[3];/**< offset write array*/ +s32 coef[3];/**< co efficient data */ +s8 overflow;/**< over flow condition check */ +u8 dev_id;/**< device id information */ +const s8 *transform;/**< transform condition check */ +#if YAS532_MAG_LOG < YAS532_MAG_TEMPERATURE_LOG +struct yas_temp_filter_t temp_data;/**< temp data */ +#endif +u16 last_raw[4];/**< raw data */ +}; +/*! +* @brief Used for reading the YAS532 XYZ data +*/ +struct yas532_vector { +s32 yas532_vector_xyz[3];/**< YAS532 compensated xyz data*/ +}; +/** + * @struct yas_vector + * @brief Stores the sensor data + */ +struct yas_vector { + s32 yas537_vector_xyz[3]; /*!< vector data */ +}; +/*! +* @brief YAMAHA-YAS532 struct +* Calibration YAS532 data struct +*/ +struct bosch_yas537_calib_data_t { +s8 a2;/**<YAS532 calib a2 data */ +s8 a3;/**<YAS532 calib a3 data */ +s8 a4;/**<YAS532 calib a4 data */ +s16 a5;/**<YAS532 calib a5 data */ +s8 a6;/**<YAS532 calib a6 data */ +s8 a7;/**<YAS532 calib a7 data */ +s8 a8;/**<YAS532 calib a8 data */ +s16 a9;/**<YAS532 calib a9 data */ +u8 k;/**<YAS532 calib k data */ +u8 ver;/**<YAS532 calib ver data*/ +}; +/*! +* @brief YAS537 sensor initialization +*/ +struct yas537_t { +struct bosch_yas537_calib_data_t calib_yas537;/**< calib data */ +s8 measure_state;/**< update measure state */ +s8 hard_offset[3];/**< offset write array*/ +u16 last_after_rcoil[3];/**< rcoil write array*/ +s32 coef[3];/**< co efficient data */ +s8 overflow;/**< over flow condition check */ +u8 dev_id;/**< device id information */ +u8 average;/**<average selection for offset configuration*/ +const s8 *transform;/**< transform condition check */ +u16 last_raw[4];/**< raw data */ +struct yas_vector xyz; /*!< X, Y, Z measurement data of the sensor */ +}; +/**************************************************************/ +/**\name USER DATA REGISTERS DEFINITION START */ +/**************************************************************/ + +/**************************************************************/ +/**\name CHIP ID LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Chip ID Description - Reg Addr --> (0x00), Bit --> 0...7 */ +#define SMI130_USER_CHIP_ID__POS (0) +#define SMI130_USER_CHIP_ID__MSK (0xFF) +#define SMI130_USER_CHIP_ID__LEN (8) +#define SMI130_USER_CHIP_ID__REG (SMI130_USER_CHIP_ID_ADDR) +/**************************************************************/ +/**\name ERROR STATUS LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Error Description - Reg Addr --> (0x02), Bit --> 0 */ +#define SMI130_USER_ERR_STAT__POS (0) +#define SMI130_USER_ERR_STAT__LEN (8) +#define SMI130_USER_ERR_STAT__MSK (0xFF) +#define SMI130_USER_ERR_STAT__REG (SMI130_USER_ERROR_ADDR) + +#define SMI130_USER_FATAL_ERR__POS (0) +#define SMI130_USER_FATAL_ERR__LEN (1) +#define SMI130_USER_FATAL_ERR__MSK (0x01) +#define SMI130_USER_FATAL_ERR__REG (SMI130_USER_ERROR_ADDR) + +/* Error Description - Reg Addr --> (0x02), Bit --> 1...4 */ +#define SMI130_USER_ERR_CODE__POS (1) +#define SMI130_USER_ERR_CODE__LEN (4) +#define SMI130_USER_ERR_CODE__MSK (0x1E) +#define SMI130_USER_ERR_CODE__REG (SMI130_USER_ERROR_ADDR) + +/* Error Description - Reg Addr --> (0x02), Bit --> 5 */ +#define SMI130_USER_I2C_FAIL_ERR__POS (5) +#define SMI130_USER_I2C_FAIL_ERR__LEN (1) +#define SMI130_USER_I2C_FAIL_ERR__MSK (0x20) +#define SMI130_USER_I2C_FAIL_ERR__REG (SMI130_USER_ERROR_ADDR) + +/* Error Description - Reg Addr --> (0x02), Bit --> 6 */ +#define SMI130_USER_DROP_CMD_ERR__POS (6) +#define SMI130_USER_DROP_CMD_ERR__LEN (1) +#define SMI130_USER_DROP_CMD_ERR__MSK (0x40) +#define SMI130_USER_DROP_CMD_ERR__REG (SMI130_USER_ERROR_ADDR) +/**************************************************************/ +/**\name MAG DATA READY LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Error Description - Reg Addr --> (0x02), Bit --> 7 */ +#define SMI130_USER_MAG_DADA_RDY_ERR__POS (7) +#define SMI130_USER_MAG_DADA_RDY_ERR__LEN (1) +#define SMI130_USER_MAG_DADA_RDY_ERR__MSK (0x80) +#define SMI130_USER_MAG_DADA_RDY_ERR__REG (SMI130_USER_ERROR_ADDR) +/**************************************************************/ +/**\name MAG POWER MODE LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* PMU_Status Description of MAG - Reg Addr --> (0x03), Bit --> 1..0 */ +#define SMI130_USER_MAG_POWER_MODE_STAT__POS (0) +#define SMI130_USER_MAG_POWER_MODE_STAT__LEN (2) +#define SMI130_USER_MAG_POWER_MODE_STAT__MSK (0x03) +#define SMI130_USER_MAG_POWER_MODE_STAT__REG \ +(SMI130_USER_PMU_STAT_ADDR) +/**************************************************************/ +/**\name GYRO POWER MODE LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* PMU_Status Description of GYRO - Reg Addr --> (0x03), Bit --> 3...2 */ +#define SMI130_USER_GYRO_POWER_MODE_STAT__POS (2) +#define SMI130_USER_GYRO_POWER_MODE_STAT__LEN (2) +#define SMI130_USER_GYRO_POWER_MODE_STAT__MSK (0x0C) +#define SMI130_USER_GYRO_POWER_MODE_STAT__REG \ +(SMI130_USER_PMU_STAT_ADDR) +/**************************************************************/ +/**\name ACCEL POWER MODE LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* PMU_Status Description of ACCEL - Reg Addr --> (0x03), Bit --> 5...4 */ +#define SMI130_USER_ACCEL_POWER_MODE_STAT__POS (4) +#define SMI130_USER_ACCEL_POWER_MODE_STAT__LEN (2) +#define SMI130_USER_ACCEL_POWER_MODE_STAT__MSK (0x30) +#define SMI130_USER_ACCEL_POWER_MODE_STAT__REG \ +(SMI130_USER_PMU_STAT_ADDR) +/**************************************************************/ +/**\name MAG DATA XYZ LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Mag_X(LSB) Description - Reg Addr --> (0x04), Bit --> 0...7 */ +#define SMI130_USER_DATA_0_MAG_X_LSB__POS (0) +#define SMI130_USER_DATA_0_MAG_X_LSB__LEN (8) +#define SMI130_USER_DATA_0_MAG_X_LSB__MSK (0xFF) +#define SMI130_USER_DATA_0_MAG_X_LSB__REG (SMI130_USER_DATA_0_ADDR) + +/* Mag_X(LSB) Description - Reg Addr --> (0x04), Bit --> 3...7 */ +#define SMI130_USER_DATA_MAG_X_LSB__POS (3) +#define SMI130_USER_DATA_MAG_X_LSB__LEN (5) +#define SMI130_USER_DATA_MAG_X_LSB__MSK (0xF8) +#define SMI130_USER_DATA_MAG_X_LSB__REG (SMI130_USER_DATA_0_ADDR) + +/* Mag_X(MSB) Description - Reg Addr --> (0x05), Bit --> 0...7 */ +#define SMI130_USER_DATA_1_MAG_X_MSB__POS (0) +#define SMI130_USER_DATA_1_MAG_X_MSB__LEN (8) +#define SMI130_USER_DATA_1_MAG_X_MSB__MSK (0xFF) +#define SMI130_USER_DATA_1_MAG_X_MSB__REG (SMI130_USER_DATA_1_ADDR) + +/* Mag_Y(LSB) Description - Reg Addr --> (0x06), Bit --> 0...7 */ +#define SMI130_USER_DATA_2_MAG_Y_LSB__POS (0) +#define SMI130_USER_DATA_2_MAG_Y_LSB__LEN (8) +#define SMI130_USER_DATA_2_MAG_Y_LSB__MSK (0xFF) +#define SMI130_USER_DATA_2_MAG_Y_LSB__REG (SMI130_USER_DATA_2_ADDR) + +/* Mag_Y(LSB) Description - Reg Addr --> (0x06), Bit --> 3...7 */ +#define SMI130_USER_DATA_MAG_Y_LSB__POS (3) +#define SMI130_USER_DATA_MAG_Y_LSB__LEN (5) +#define SMI130_USER_DATA_MAG_Y_LSB__MSK (0xF8) +#define SMI130_USER_DATA_MAG_Y_LSB__REG (SMI130_USER_DATA_2_ADDR) + +/* Mag_Y(MSB) Description - Reg Addr --> (0x07), Bit --> 0...7 */ +#define SMI130_USER_DATA_3_MAG_Y_MSB__POS (0) +#define SMI130_USER_DATA_3_MAG_Y_MSB__LEN (8) +#define SMI130_USER_DATA_3_MAG_Y_MSB__MSK (0xFF) +#define SMI130_USER_DATA_3_MAG_Y_MSB__REG (SMI130_USER_DATA_3_ADDR) + +/* Mag_Z(LSB) Description - Reg Addr --> (0x08), Bit --> 0...7 */ +#define SMI130_USER_DATA_4_MAG_Z_LSB__POS (0) +#define SMI130_USER_DATA_4_MAG_Z_LSB__LEN (8) +#define SMI130_USER_DATA_4_MAG_Z_LSB__MSK (0xFF) +#define SMI130_USER_DATA_4_MAG_Z_LSB__REG (SMI130_USER_DATA_4_ADDR) + +/* Mag_X(LSB) Description - Reg Addr --> (0x08), Bit --> 3...7 */ +#define SMI130_USER_DATA_MAG_Z_LSB__POS (1) +#define SMI130_USER_DATA_MAG_Z_LSB__LEN (7) +#define SMI130_USER_DATA_MAG_Z_LSB__MSK (0xFE) +#define SMI130_USER_DATA_MAG_Z_LSB__REG (SMI130_USER_DATA_4_ADDR) + +/* Mag_Z(MSB) Description - Reg Addr --> (0x09), Bit --> 0...7 */ +#define SMI130_USER_DATA_5_MAG_Z_MSB__POS (0) +#define SMI130_USER_DATA_5_MAG_Z_MSB__LEN (8) +#define SMI130_USER_DATA_5_MAG_Z_MSB__MSK (0xFF) +#define SMI130_USER_DATA_5_MAG_Z_MSB__REG (SMI130_USER_DATA_5_ADDR) + +/* RHALL(LSB) Description - Reg Addr --> (0x0A), Bit --> 0...7 */ +#define SMI130_USER_DATA_6_RHALL_LSB__POS (0) +#define SMI130_USER_DATA_6_RHALL_LSB__LEN (8) +#define SMI130_USER_DATA_6_RHALL_LSB__MSK (0xFF) +#define SMI130_USER_DATA_6_RHALL_LSB__REG (SMI130_USER_DATA_6_ADDR) + +/* Mag_R(LSB) Description - Reg Addr --> (0x0A), Bit --> 3...7 */ +#define SMI130_USER_DATA_MAG_R_LSB__POS (2) +#define SMI130_USER_DATA_MAG_R_LSB__LEN (6) +#define SMI130_USER_DATA_MAG_R_LSB__MSK (0xFC) +#define SMI130_USER_DATA_MAG_R_LSB__REG (SMI130_USER_DATA_6_ADDR) + +/* RHALL(MSB) Description - Reg Addr --> (0x0B), Bit --> 0...7 */ +#define SMI130_USER_DATA_7_RHALL_MSB__POS (0) +#define SMI130_USER_DATA_7_RHALL_MSB__LEN (8) +#define SMI130_USER_DATA_7_RHALL_MSB__MSK (0xFF) +#define SMI130_USER_DATA_7_RHALL_MSB__REG (SMI130_USER_DATA_7_ADDR) +/**************************************************************/ +/**\name GYRO DATA XYZ LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* GYR_X (LSB) Description - Reg Addr --> (0x0C), Bit --> 0...7 */ +#define SMI130_USER_DATA_8_GYRO_X_LSB__POS (0) +#define SMI130_USER_DATA_8_GYRO_X_LSB__LEN (8) +#define SMI130_USER_DATA_8_GYRO_X_LSB__MSK (0xFF) +#define SMI130_USER_DATA_8_GYRO_X_LSB__REG (SMI130_USER_DATA_8_ADDR) + +/* GYR_X (MSB) Description - Reg Addr --> (0x0D), Bit --> 0...7 */ +#define SMI130_USER_DATA_9_GYRO_X_MSB__POS (0) +#define SMI130_USER_DATA_9_GYRO_X_MSB__LEN (8) +#define SMI130_USER_DATA_9_GYRO_X_MSB__MSK (0xFF) +#define SMI130_USER_DATA_9_GYRO_X_MSB__REG (SMI130_USER_DATA_9_ADDR) + +/* GYR_Y (LSB) Description - Reg Addr --> 0x0E, Bit --> 0...7 */ +#define SMI130_USER_DATA_10_GYRO_Y_LSB__POS (0) +#define SMI130_USER_DATA_10_GYRO_Y_LSB__LEN (8) +#define SMI130_USER_DATA_10_GYRO_Y_LSB__MSK (0xFF) +#define SMI130_USER_DATA_10_GYRO_Y_LSB__REG (SMI130_USER_DATA_10_ADDR) + +/* GYR_Y (MSB) Description - Reg Addr --> (0x0F), Bit --> 0...7 */ +#define SMI130_USER_DATA_11_GYRO_Y_MSB__POS (0) +#define SMI130_USER_DATA_11_GYRO_Y_MSB__LEN (8) +#define SMI130_USER_DATA_11_GYRO_Y_MSB__MSK (0xFF) +#define SMI130_USER_DATA_11_GYRO_Y_MSB__REG (SMI130_USER_DATA_11_ADDR) + +/* GYR_Z (LSB) Description - Reg Addr --> (0x10), Bit --> 0...7 */ +#define SMI130_USER_DATA_12_GYRO_Z_LSB__POS (0) +#define SMI130_USER_DATA_12_GYRO_Z_LSB__LEN (8) +#define SMI130_USER_DATA_12_GYRO_Z_LSB__MSK (0xFF) +#define SMI130_USER_DATA_12_GYRO_Z_LSB__REG (SMI130_USER_DATA_12_ADDR) + +/* GYR_Z (MSB) Description - Reg Addr --> (0x11), Bit --> 0...7 */ +#define SMI130_USER_DATA_13_GYRO_Z_MSB__POS (0) +#define SMI130_USER_DATA_13_GYRO_Z_MSB__LEN (8) +#define SMI130_USER_DATA_13_GYRO_Z_MSB__MSK (0xFF) +#define SMI130_USER_DATA_13_GYRO_Z_MSB__REG (SMI130_USER_DATA_13_ADDR) +/**************************************************************/ +/**\name ACCEL DATA XYZ LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* ACC_X (LSB) Description - Reg Addr --> (0x12), Bit --> 0...7 */ +#define SMI130_USER_DATA_14_ACCEL_X_LSB__POS (0) +#define SMI130_USER_DATA_14_ACCEL_X_LSB__LEN (8) +#define SMI130_USER_DATA_14_ACCEL_X_LSB__MSK (0xFF) +#define SMI130_USER_DATA_14_ACCEL_X_LSB__REG (SMI130_USER_DATA_14_ADDR) + +/* ACC_X (MSB) Description - Reg Addr --> 0x13, Bit --> 0...7 */ +#define SMI130_USER_DATA_15_ACCEL_X_MSB__POS (0) +#define SMI130_USER_DATA_15_ACCEL_X_MSB__LEN (8) +#define SMI130_USER_DATA_15_ACCEL_X_MSB__MSK (0xFF) +#define SMI130_USER_DATA_15_ACCEL_X_MSB__REG (SMI130_USER_DATA_15_ADDR) + +/* ACC_Y (LSB) Description - Reg Addr --> (0x14), Bit --> 0...7 */ +#define SMI130_USER_DATA_16_ACCEL_Y_LSB__POS (0) +#define SMI130_USER_DATA_16_ACCEL_Y_LSB__LEN (8) +#define SMI130_USER_DATA_16_ACCEL_Y_LSB__MSK (0xFF) +#define SMI130_USER_DATA_16_ACCEL_Y_LSB__REG (SMI130_USER_DATA_16_ADDR) + +/* ACC_Y (MSB) Description - Reg Addr --> (0x15), Bit --> 0...7 */ +#define SMI130_USER_DATA_17_ACCEL_Y_MSB__POS (0) +#define SMI130_USER_DATA_17_ACCEL_Y_MSB__LEN (8) +#define SMI130_USER_DATA_17_ACCEL_Y_MSB__MSK (0xFF) +#define SMI130_USER_DATA_17_ACCEL_Y_MSB__REG (SMI130_USER_DATA_17_ADDR) + +/* ACC_Z (LSB) Description - Reg Addr --> 0x16, Bit --> 0...7 */ +#define SMI130_USER_DATA_18_ACCEL_Z_LSB__POS (0) +#define SMI130_USER_DATA_18_ACCEL_Z_LSB__LEN (8) +#define SMI130_USER_DATA_18_ACCEL_Z_LSB__MSK (0xFF) +#define SMI130_USER_DATA_18_ACCEL_Z_LSB__REG (SMI130_USER_DATA_18_ADDR) + +/* ACC_Z (MSB) Description - Reg Addr --> (0x17), Bit --> 0...7 */ +#define SMI130_USER_DATA_19_ACCEL_Z_MSB__POS (0) +#define SMI130_USER_DATA_19_ACCEL_Z_MSB__LEN (8) +#define SMI130_USER_DATA_19_ACCEL_Z_MSB__MSK (0xFF) +#define SMI130_USER_DATA_19_ACCEL_Z_MSB__REG (SMI130_USER_DATA_19_ADDR) +/**************************************************************/ +/**\name SENSOR TIME LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* SENSORTIME_0 (LSB) Description - Reg Addr --> (0x18), Bit --> 0...7 */ +#define SMI130_USER_SENSORTIME_0_SENSOR_TIME_LSB__POS (0) +#define SMI130_USER_SENSORTIME_0_SENSOR_TIME_LSB__LEN (8) +#define SMI130_USER_SENSORTIME_0_SENSOR_TIME_LSB__MSK (0xFF) +#define SMI130_USER_SENSORTIME_0_SENSOR_TIME_LSB__REG \ + (SMI130_USER_SENSORTIME_0_ADDR) + +/* SENSORTIME_1 (MSB) Description - Reg Addr --> (0x19), Bit --> 0...7 */ +#define SMI130_USER_SENSORTIME_1_SENSOR_TIME_MSB__POS (0) +#define SMI130_USER_SENSORTIME_1_SENSOR_TIME_MSB__LEN (8) +#define SMI130_USER_SENSORTIME_1_SENSOR_TIME_MSB__MSK (0xFF) +#define SMI130_USER_SENSORTIME_1_SENSOR_TIME_MSB__REG \ + (SMI130_USER_SENSORTIME_1_ADDR) + +/* SENSORTIME_2 (MSB) Description - Reg Addr --> (0x1A), Bit --> 0...7 */ +#define SMI130_USER_SENSORTIME_2_SENSOR_TIME_MSB__POS (0) +#define SMI130_USER_SENSORTIME_2_SENSOR_TIME_MSB__LEN (8) +#define SMI130_USER_SENSORTIME_2_SENSOR_TIME_MSB__MSK (0xFF) +#define SMI130_USER_SENSORTIME_2_SENSOR_TIME_MSB__REG \ + (SMI130_USER_SENSORTIME_2_ADDR) +/**************************************************************/ +/**\name GYRO SELF TEST LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 1 */ +#define SMI130_USER_STAT_GYRO_SELFTEST_OK__POS (1) +#define SMI130_USER_STAT_GYRO_SELFTEST_OK__LEN (1) +#define SMI130_USER_STAT_GYRO_SELFTEST_OK__MSK (0x02) +#define SMI130_USER_STAT_GYRO_SELFTEST_OK__REG \ + (SMI130_USER_STAT_ADDR) +/**************************************************************/ +/**\name MAG MANUAL OPERATION LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 2 */ +#define SMI130_USER_STAT_MAG_MANUAL_OPERATION__POS (2) +#define SMI130_USER_STAT_MAG_MANUAL_OPERATION__LEN (1) +#define SMI130_USER_STAT_MAG_MANUAL_OPERATION__MSK (0x04) +#define SMI130_USER_STAT_MAG_MANUAL_OPERATION__REG \ + (SMI130_USER_STAT_ADDR) +/**************************************************************/ +/**\name FOC STATUS LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 3 */ +#define SMI130_USER_STAT_FOC_RDY__POS (3) +#define SMI130_USER_STAT_FOC_RDY__LEN (1) +#define SMI130_USER_STAT_FOC_RDY__MSK (0x08) +#define SMI130_USER_STAT_FOC_RDY__REG (SMI130_USER_STAT_ADDR) +/**************************************************************/ +/**\name NVM READY LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 4 */ +#define SMI130_USER_STAT_NVM_RDY__POS (4) +#define SMI130_USER_STAT_NVM_RDY__LEN (1) +#define SMI130_USER_STAT_NVM_RDY__MSK (0x10) +#define SMI130_USER_STAT_NVM_RDY__REG (SMI130_USER_STAT_ADDR) +/**************************************************************/ +/**\name DATA READY LENGTH, POSITION AND MASK FOR ACCEL, MAG AND GYRO*/ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 5 */ +#define SMI130_USER_STAT_DATA_RDY_MAG__POS (5) +#define SMI130_USER_STAT_DATA_RDY_MAG__LEN (1) +#define SMI130_USER_STAT_DATA_RDY_MAG__MSK (0x20) +#define SMI130_USER_STAT_DATA_RDY_MAG__REG (SMI130_USER_STAT_ADDR) + +/* Status Description - Reg Addr --> 0x1B, Bit --> 6 */ +#define SMI130_USER_STAT_DATA_RDY_GYRO__POS (6) +#define SMI130_USER_STAT_DATA_RDY_GYRO__LEN (1) +#define SMI130_USER_STAT_DATA_RDY_GYRO__MSK (0x40) +#define SMI130_USER_STAT_DATA_RDY_GYRO__REG (SMI130_USER_STAT_ADDR) + +/* Status Description - Reg Addr --> 0x1B, Bit --> 7 */ +#define SMI130_USER_STAT_DATA_RDY_ACCEL__POS (7) +#define SMI130_USER_STAT_DATA_RDY_ACCEL__LEN (1) +#define SMI130_USER_STAT_DATA_RDY_ACCEL__MSK (0x80) +#define SMI130_USER_STAT_DATA_RDY_ACCEL__REG (SMI130_USER_STAT_ADDR) +/**************************************************************/ +/**\name INTERRUPT STATUS LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 0 */ +#define SMI130_USER_INTR_STAT_0_STEP_INTR__POS (0) +#define SMI130_USER_INTR_STAT_0_STEP_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_0_STEP_INTR__MSK (0x01) +#define SMI130_USER_INTR_STAT_0_STEP_INTR__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name SIGNIFICANT INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 1 */ +#define SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR__POS (1) +#define SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR__MSK (0x02) +#define SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name ANY_MOTION INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 2 */ +#define SMI130_USER_INTR_STAT_0_ANY_MOTION__POS (2) +#define SMI130_USER_INTR_STAT_0_ANY_MOTION__LEN (1) +#define SMI130_USER_INTR_STAT_0_ANY_MOTION__MSK (0x04) +#define SMI130_USER_INTR_STAT_0_ANY_MOTION__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name PMU TRIGGER INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 3 */ +#define SMI130_USER_INTR_STAT_0_PMU_TRIGGER__POS 3 +#define SMI130_USER_INTR_STAT_0_PMU_TRIGGER__LEN (1) +#define SMI130_USER_INTR_STAT_0_PMU_TRIGGER__MSK (0x08) +#define SMI130_USER_INTR_STAT_0_PMU_TRIGGER__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name DOUBLE TAP INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 4 */ +#define SMI130_USER_INTR_STAT_0_DOUBLE_TAP_INTR__POS 4 +#define SMI130_USER_INTR_STAT_0_DOUBLE_TAP_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_0_DOUBLE_TAP_INTR__MSK (0x10) +#define SMI130_USER_INTR_STAT_0_DOUBLE_TAP_INTR__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name SINGLE TAP INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 5 */ +#define SMI130_USER_INTR_STAT_0_SINGLE_TAP_INTR__POS 5 +#define SMI130_USER_INTR_STAT_0_SINGLE_TAP_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_0_SINGLE_TAP_INTR__MSK (0x20) +#define SMI130_USER_INTR_STAT_0_SINGLE_TAP_INTR__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name ORIENT INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 6 */ +#define SMI130_USER_INTR_STAT_0_ORIENT__POS (6) +#define SMI130_USER_INTR_STAT_0_ORIENT__LEN (1) +#define SMI130_USER_INTR_STAT_0_ORIENT__MSK (0x40) +#define SMI130_USER_INTR_STAT_0_ORIENT__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name FLAT INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 7 */ +#define SMI130_USER_INTR_STAT_0_FLAT__POS (7) +#define SMI130_USER_INTR_STAT_0_FLAT__LEN (1) +#define SMI130_USER_INTR_STAT_0_FLAT__MSK (0x80) +#define SMI130_USER_INTR_STAT_0_FLAT__REG \ + (SMI130_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name HIGH_G INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 2 */ +#define SMI130_USER_INTR_STAT_1_HIGH_G_INTR__POS (2) +#define SMI130_USER_INTR_STAT_1_HIGH_G_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_1_HIGH_G_INTR__MSK (0x04) +#define SMI130_USER_INTR_STAT_1_HIGH_G_INTR__REG \ + (SMI130_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name LOW_G INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 3 */ +#define SMI130_USER_INTR_STAT_1_LOW_G_INTR__POS (3) +#define SMI130_USER_INTR_STAT_1_LOW_G_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_1_LOW_G_INTR__MSK (0x08) +#define SMI130_USER_INTR_STAT_1_LOW_G_INTR__REG \ + (SMI130_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name DATA READY INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 4 */ +#define SMI130_USER_INTR_STAT_1_DATA_RDY_INTR__POS (4) +#define SMI130_USER_INTR_STAT_1_DATA_RDY_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_1_DATA_RDY_INTR__MSK (0x10) +#define SMI130_USER_INTR_STAT_1_DATA_RDY_INTR__REG \ + (SMI130_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name FIFO FULL INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 5 */ +#define SMI130_USER_INTR_STAT_1_FIFO_FULL_INTR__POS (5) +#define SMI130_USER_INTR_STAT_1_FIFO_FULL_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_1_FIFO_FULL_INTR__MSK (0x20) +#define SMI130_USER_INTR_STAT_1_FIFO_FULL_INTR__REG \ + (SMI130_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name FIFO WATERMARK INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 6 */ +#define SMI130_USER_INTR_STAT_1_FIFO_WM_INTR__POS (6) +#define SMI130_USER_INTR_STAT_1_FIFO_WM_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_1_FIFO_WM_INTR__MSK (0x40) +#define SMI130_USER_INTR_STAT_1_FIFO_WM_INTR__REG \ + (SMI130_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name NO MOTION INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 7 */ +#define SMI130_USER_INTR_STAT_1_NOMOTION_INTR__POS (7) +#define SMI130_USER_INTR_STAT_1_NOMOTION_INTR__LEN (1) +#define SMI130_USER_INTR_STAT_1_NOMOTION_INTR__MSK (0x80) +#define SMI130_USER_INTR_STAT_1_NOMOTION_INTR__REG \ + (SMI130_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name ANY MOTION-XYZ AXIS INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 0 */ +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__POS (0) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__LEN (1) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__MSK (0x01) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 1 */ +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__POS (1) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__LEN (1) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__MSK (0x02) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 2 */ +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__POS (2) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__LEN (1) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__MSK (0x04) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) +/**************************************************************/ +/**\name ANY MOTION SIGN LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 3 */ +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_SIGN__POS (3) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_SIGN__LEN (1) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_SIGN__MSK (0x08) +#define SMI130_USER_INTR_STAT_2_ANY_MOTION_SIGN__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) +/**************************************************************/ +/**\name TAP_XYZ AND SIGN LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 4 */ +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_X__POS (4) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_X__LEN (1) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_X__MSK (0x10) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_X__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 5 */ +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Y__POS (5) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Y__LEN (1) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Y__MSK (0x20) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Y__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 6 */ +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Z__POS (6) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Z__LEN (1) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Z__MSK (0x40) +#define SMI130_USER_INTR_STAT_2_TAP_FIRST_Z__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 7 */ +#define SMI130_USER_INTR_STAT_2_TAP_SIGN__POS (7) +#define SMI130_USER_INTR_STAT_2_TAP_SIGN__LEN (1) +#define SMI130_USER_INTR_STAT_2_TAP_SIGN__MSK (0x80) +#define SMI130_USER_INTR_STAT_2_TAP_SIGN__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT SATAUS FOR WHOLE 0x1E LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 0...7 */ +#define SMI130_USER_INTR_STAT_2__POS (0) +#define SMI130_USER_INTR_STAT_2__LEN (8) +#define SMI130_USER_INTR_STAT_2__MSK (0xFF) +#define SMI130_USER_INTR_STAT_2__REG \ + (SMI130_USER_INTR_STAT_2_ADDR) +/**************************************************************/ +/**\name HIGH_G-XYZ AND SIGN LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 0 */ +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_X__POS (0) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_X__LEN (1) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_X__MSK (0x01) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_X__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> 0x1E, Bit --> 1 */ +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Y__POS (1) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Y__LEN (1) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Y__MSK (0x02) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Y__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 2 */ +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Z__POS (2) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Z__LEN (1) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Z__MSK (0x04) +#define SMI130_USER_INTR_STAT_3_HIGH_G_FIRST_Z__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 3 */ +#define SMI130_USER_INTR_STAT_3_HIGH_G_SIGN__POS (3) +#define SMI130_USER_INTR_STAT_3_HIGH_G_SIGN__LEN (1) +#define SMI130_USER_INTR_STAT_3_HIGH_G_SIGN__MSK (0x08) +#define SMI130_USER_INTR_STAT_3_HIGH_G_SIGN__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) +/**************************************************************/ +/**\name ORIENT XY and Z AXIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 4...5 */ +#define SMI130_USER_INTR_STAT_3_ORIENT_XY__POS (4) +#define SMI130_USER_INTR_STAT_3_ORIENT_XY__LEN (2) +#define SMI130_USER_INTR_STAT_3_ORIENT_XY__MSK (0x30) +#define SMI130_USER_INTR_STAT_3_ORIENT_XY__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 6 */ +#define SMI130_USER_INTR_STAT_3_ORIENT_Z__POS (6) +#define SMI130_USER_INTR_STAT_3_ORIENT_Z__LEN (1) +#define SMI130_USER_INTR_STAT_3_ORIENT_Z__MSK (0x40) +#define SMI130_USER_INTR_STAT_3_ORIENT_Z__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) +/**************************************************************/ +/**\name FLAT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 7 */ +#define SMI130_USER_INTR_STAT_3_FLAT__POS (7) +#define SMI130_USER_INTR_STAT_3_FLAT__LEN (1) +#define SMI130_USER_INTR_STAT_3_FLAT__MSK (0x80) +#define SMI130_USER_INTR_STAT_3_FLAT__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) +/**************************************************************/ +/**\name (0x1F) LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 0...7 */ +#define SMI130_USER_INTR_STAT_3__POS (0) +#define SMI130_USER_INTR_STAT_3__LEN (8) +#define SMI130_USER_INTR_STAT_3__MSK (0xFF) +#define SMI130_USER_INTR_STAT_3__REG \ + (SMI130_USER_INTR_STAT_3_ADDR) +/**************************************************************/ +/**\name TEMPERATURE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Temperature Description - LSB Reg Addr --> (0x20), Bit --> 0...7 */ +#define SMI130_USER_TEMP_LSB_VALUE__POS (0) +#define SMI130_USER_TEMP_LSB_VALUE__LEN (8) +#define SMI130_USER_TEMP_LSB_VALUE__MSK (0xFF) +#define SMI130_USER_TEMP_LSB_VALUE__REG \ + (SMI130_USER_TEMPERATURE_0_ADDR) + +/* Temperature Description - LSB Reg Addr --> 0x21, Bit --> 0...7 */ +#define SMI130_USER_TEMP_MSB_VALUE__POS (0) +#define SMI130_USER_TEMP_MSB_VALUE__LEN (8) +#define SMI130_USER_TEMP_MSB_VALUE__MSK (0xFF) +#define SMI130_USER_TEMP_MSB_VALUE__REG \ + (SMI130_USER_TEMPERATURE_1_ADDR) +/**************************************************************/ +/**\name FIFO BYTE COUNTER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Length0 Description - Reg Addr --> 0x22, Bit --> 0...7 */ +#define SMI130_USER_FIFO_BYTE_COUNTER_LSB__POS (0) +#define SMI130_USER_FIFO_BYTE_COUNTER_LSB__LEN (8) +#define SMI130_USER_FIFO_BYTE_COUNTER_LSB__MSK (0xFF) +#define SMI130_USER_FIFO_BYTE_COUNTER_LSB__REG \ + (SMI130_USER_FIFO_LENGTH_0_ADDR) + +/*Fifo_Length1 Description - Reg Addr --> 0x23, Bit --> 0...2 */ +#define SMI130_USER_FIFO_BYTE_COUNTER_MSB__POS (0) +#define SMI130_USER_FIFO_BYTE_COUNTER_MSB__LEN 3 +#define SMI130_USER_FIFO_BYTE_COUNTER_MSB__MSK (0x07) +#define SMI130_USER_FIFO_BYTE_COUNTER_MSB__REG \ + (SMI130_USER_FIFO_LENGTH_1_ADDR) + +/**************************************************************/ +/**\name FIFO DATA LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Data Description - Reg Addr --> 0x24, Bit --> 0...7 */ +#define SMI130_USER_FIFO_DATA__POS (0) +#define SMI130_USER_FIFO_DATA__LEN (8) +#define SMI130_USER_FIFO_DATA__MSK (0xFF) +#define SMI130_USER_FIFO_DATA__REG (SMI130_USER_FIFO_DATA_ADDR) + +/**************************************************************/ +/**\name ACCEL CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Acc_Conf Description - Reg Addr --> (0x40), Bit --> 0...3 */ +#define SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__POS (0) +#define SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__LEN (4) +#define SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__MSK (0x0F) +#define SMI130_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG \ +(SMI130_USER_ACCEL_CONFIG_ADDR) + +/* Acc_Conf Description - Reg Addr --> (0x40), Bit --> 4...6 */ +#define SMI130_USER_ACCEL_CONFIG_ACCEL_BW__POS (4) +#define SMI130_USER_ACCEL_CONFIG_ACCEL_BW__LEN (3) +#define SMI130_USER_ACCEL_CONFIG_ACCEL_BW__MSK (0x70) +#define SMI130_USER_ACCEL_CONFIG_ACCEL_BW__REG (SMI130_USER_ACCEL_CONFIG_ADDR) + +/* Acc_Conf Description - Reg Addr --> (0x40), Bit --> 7 */ +#define SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__POS (7) +#define SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__LEN (1) +#define SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__MSK (0x80) +#define SMI130_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG \ +(SMI130_USER_ACCEL_CONFIG_ADDR) + +/* Acc_Range Description - Reg Addr --> 0x41, Bit --> 0...3 */ +#define SMI130_USER_ACCEL_RANGE__POS (0) +#define SMI130_USER_ACCEL_RANGE__LEN (4) +#define SMI130_USER_ACCEL_RANGE__MSK (0x0F) +#define SMI130_USER_ACCEL_RANGE__REG \ +(SMI130_USER_ACCEL_RANGE_ADDR) +/**************************************************************/ +/**\name GYRO CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Gyro_Conf Description - Reg Addr --> (0x42), Bit --> 0...3 */ +#define SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__POS (0) +#define SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__LEN (4) +#define SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__MSK (0x0F) +#define SMI130_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG \ +(SMI130_USER_GYRO_CONFIG_ADDR) + +/* Gyro_Conf Description - Reg Addr --> (0x42), Bit --> 4...5 */ +#define SMI130_USER_GYRO_CONFIG_BW__POS (4) +#define SMI130_USER_GYRO_CONFIG_BW__LEN (2) +#define SMI130_USER_GYRO_CONFIG_BW__MSK (0x30) +#define SMI130_USER_GYRO_CONFIG_BW__REG \ +(SMI130_USER_GYRO_CONFIG_ADDR) + +/* Gyr_Range Description - Reg Addr --> 0x43, Bit --> 0...2 */ +#define SMI130_USER_GYRO_RANGE__POS (0) +#define SMI130_USER_GYRO_RANGE__LEN (3) +#define SMI130_USER_GYRO_RANGE__MSK (0x07) +#define SMI130_USER_GYRO_RANGE__REG (SMI130_USER_GYRO_RANGE_ADDR) +/**************************************************************/ +/**\name MAG CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Mag_Conf Description - Reg Addr --> (0x44), Bit --> 0...3 */ +#define SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE__POS (0) +#define SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE__LEN (4) +#define SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE__MSK (0x0F) +#define SMI130_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG \ +(SMI130_USER_MAG_CONFIG_ADDR) +/**************************************************************/ +/**\name FIFO DOWNS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Downs Description - Reg Addr --> 0x45, Bit --> 0...2 */ +#define SMI130_USER_FIFO_DOWN_GYRO__POS (0) +#define SMI130_USER_FIFO_DOWN_GYRO__LEN (3) +#define SMI130_USER_FIFO_DOWN_GYRO__MSK (0x07) +#define SMI130_USER_FIFO_DOWN_GYRO__REG (SMI130_USER_FIFO_DOWN_ADDR) +/**************************************************************/ +/**\name FIFO FILTER FOR ACCEL AND GYRO LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_filt Description - Reg Addr --> 0x45, Bit --> 3 */ +#define SMI130_USER_FIFO_FILTER_GYRO__POS (3) +#define SMI130_USER_FIFO_FILTER_GYRO__LEN (1) +#define SMI130_USER_FIFO_FILTER_GYRO__MSK (0x08) +#define SMI130_USER_FIFO_FILTER_GYRO__REG (SMI130_USER_FIFO_DOWN_ADDR) + +/* Fifo_Downs Description - Reg Addr --> 0x45, Bit --> 4...6 */ +#define SMI130_USER_FIFO_DOWN_ACCEL__POS (4) +#define SMI130_USER_FIFO_DOWN_ACCEL__LEN (3) +#define SMI130_USER_FIFO_DOWN_ACCEL__MSK (0x70) +#define SMI130_USER_FIFO_DOWN_ACCEL__REG (SMI130_USER_FIFO_DOWN_ADDR) + +/* Fifo_FILT Description - Reg Addr --> 0x45, Bit --> 7 */ +#define SMI130_USER_FIFO_FILTER_ACCEL__POS (7) +#define SMI130_USER_FIFO_FILTER_ACCEL__LEN (1) +#define SMI130_USER_FIFO_FILTER_ACCEL__MSK (0x80) +#define SMI130_USER_FIFO_FILTER_ACCEL__REG (SMI130_USER_FIFO_DOWN_ADDR) +/**************************************************************/ +/**\name FIFO WATER MARK LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_0 Description - Reg Addr --> 0x46, Bit --> 0...7 */ +#define SMI130_USER_FIFO_WM__POS (0) +#define SMI130_USER_FIFO_WM__LEN (8) +#define SMI130_USER_FIFO_WM__MSK (0xFF) +#define SMI130_USER_FIFO_WM__REG (SMI130_USER_FIFO_CONFIG_0_ADDR) +/**************************************************************/ +/**\name FIFO TIME LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 1 */ +#define SMI130_USER_FIFO_TIME_ENABLE__POS (1) +#define SMI130_USER_FIFO_TIME_ENABLE__LEN (1) +#define SMI130_USER_FIFO_TIME_ENABLE__MSK (0x02) +#define SMI130_USER_FIFO_TIME_ENABLE__REG (SMI130_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO TAG INTERRUPT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 2 */ +#define SMI130_USER_FIFO_TAG_INTR2_ENABLE__POS (2) +#define SMI130_USER_FIFO_TAG_INTR2_ENABLE__LEN (1) +#define SMI130_USER_FIFO_TAG_INTR2_ENABLE__MSK (0x04) +#define SMI130_USER_FIFO_TAG_INTR2_ENABLE__REG (SMI130_USER_FIFO_CONFIG_1_ADDR) + +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 3 */ +#define SMI130_USER_FIFO_TAG_INTR1_ENABLE__POS (3) +#define SMI130_USER_FIFO_TAG_INTR1_ENABLE__LEN (1) +#define SMI130_USER_FIFO_TAG_INTR1_ENABLE__MSK (0x08) +#define SMI130_USER_FIFO_TAG_INTR1_ENABLE__REG (SMI130_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO HEADER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 4 */ +#define SMI130_USER_FIFO_HEADER_ENABLE__POS (4) +#define SMI130_USER_FIFO_HEADER_ENABLE__LEN (1) +#define SMI130_USER_FIFO_HEADER_ENABLE__MSK (0x10) +#define SMI130_USER_FIFO_HEADER_ENABLE__REG \ +(SMI130_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO MAG ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 5 */ +#define SMI130_USER_FIFO_MAG_ENABLE__POS (5) +#define SMI130_USER_FIFO_MAG_ENABLE__LEN (1) +#define SMI130_USER_FIFO_MAG_ENABLE__MSK (0x20) +#define SMI130_USER_FIFO_MAG_ENABLE__REG \ +(SMI130_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO ACCEL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 6 */ +#define SMI130_USER_FIFO_ACCEL_ENABLE__POS (6) +#define SMI130_USER_FIFO_ACCEL_ENABLE__LEN (1) +#define SMI130_USER_FIFO_ACCEL_ENABLE__MSK (0x40) +#define SMI130_USER_FIFO_ACCEL_ENABLE__REG \ +(SMI130_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO GYRO ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 7 */ +#define SMI130_USER_FIFO_GYRO_ENABLE__POS (7) +#define SMI130_USER_FIFO_GYRO_ENABLE__LEN (1) +#define SMI130_USER_FIFO_GYRO_ENABLE__MSK (0x80) +#define SMI130_USER_FIFO_GYRO_ENABLE__REG \ +(SMI130_USER_FIFO_CONFIG_1_ADDR) + +/**************************************************************/ +/**\name MAG I2C ADDRESS SELECTION LENGTH, POSITION AND MASK*/ +/**************************************************************/ + +/* Mag_IF_0 Description - Reg Addr --> 0x4b, Bit --> 1...7 */ +#define SMI130_USER_I2C_DEVICE_ADDR__POS (1) +#define SMI130_USER_I2C_DEVICE_ADDR__LEN (7) +#define SMI130_USER_I2C_DEVICE_ADDR__MSK (0xFE) +#define SMI130_USER_I2C_DEVICE_ADDR__REG (SMI130_USER_MAG_IF_0_ADDR) +/**************************************************************/ +/**\name MAG CONFIGURATION FOR SECONDARY + INTERFACE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Mag_IF_1 Description - Reg Addr --> 0x4c, Bit --> 0...1 */ +#define SMI130_USER_MAG_BURST__POS (0) +#define SMI130_USER_MAG_BURST__LEN (2) +#define SMI130_USER_MAG_BURST__MSK (0x03) +#define SMI130_USER_MAG_BURST__REG (SMI130_USER_MAG_IF_1_ADDR) + +/* Mag_IF_1 Description - Reg Addr --> 0x4c, Bit --> 2...5 */ +#define SMI130_USER_MAG_OFFSET__POS (2) +#define SMI130_USER_MAG_OFFSET__LEN (4) +#define SMI130_USER_MAG_OFFSET__MSK (0x3C) +#define SMI130_USER_MAG_OFFSET__REG (SMI130_USER_MAG_IF_1_ADDR) + +/* Mag_IF_1 Description - Reg Addr --> 0x4c, Bit --> 7 */ +#define SMI130_USER_MAG_MANUAL_ENABLE__POS (7) +#define SMI130_USER_MAG_MANUAL_ENABLE__LEN (1) +#define SMI130_USER_MAG_MANUAL_ENABLE__MSK (0x80) +#define SMI130_USER_MAG_MANUAL_ENABLE__REG \ +(SMI130_USER_MAG_IF_1_ADDR) + +/* Mag_IF_2 Description - Reg Addr --> 0x4d, Bit -->0... 7 */ +#define SMI130_USER_READ_ADDR__POS (0) +#define SMI130_USER_READ_ADDR__LEN (8) +#define SMI130_USER_READ_ADDR__MSK (0xFF) +#define SMI130_USER_READ_ADDR__REG (SMI130_USER_MAG_IF_2_ADDR) + +/* Mag_IF_3 Description - Reg Addr --> 0x4e, Bit -->0... 7 */ +#define SMI130_USER_WRITE_ADDR__POS (0) +#define SMI130_USER_WRITE_ADDR__LEN (8) +#define SMI130_USER_WRITE_ADDR__MSK (0xFF) +#define SMI130_USER_WRITE_ADDR__REG (SMI130_USER_MAG_IF_3_ADDR) + +/* Mag_IF_4 Description - Reg Addr --> 0x4f, Bit -->0... 7 */ +#define SMI130_USER_WRITE_DATA__POS (0) +#define SMI130_USER_WRITE_DATA__LEN (8) +#define SMI130_USER_WRITE_DATA__MSK (0xFF) +#define SMI130_USER_WRITE_DATA__REG (SMI130_USER_MAG_IF_4_ADDR) +/**************************************************************/ +/**\name ANY MOTION XYZ AXIS ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->0 */ +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__POS (0) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__MSK (0x01) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_0_ADDR) + +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->1 */ +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__POS (1) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__MSK (0x02) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_0_ADDR) + +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->2 */ +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__POS (2) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__MSK (0x04) +#define SMI130_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name DOUBLE TAP ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->4 */ +#define SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__POS (4) +#define SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__MSK (0x10) +#define SMI130_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name SINGLE TAP ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->5 */ +#define SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__POS (5) +#define SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__MSK (0x20) +#define SMI130_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name ORIENT ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->6 */ +#define SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE__POS (6) +#define SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE__MSK (0x40) +#define SMI130_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name FLAT ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->7 */ +#define SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE__POS (7) +#define SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE__MSK (0x80) +#define SMI130_USER_INTR_ENABLE_0_FLAT_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name HIGH_G XYZ ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->0 */ +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__POS (0) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__MSK (0x01) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_1_ADDR) + +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->1 */ +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__POS (1) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__MSK (0x02) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_1_ADDR) + +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->2 */ +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__POS (2) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__MSK (0x04) +#define SMI130_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_1_ADDR) +/**************************************************************/ +/**\name LOW_G ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->3 */ +#define SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__POS (3) +#define SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__MSK (0x08) +#define SMI130_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_1_ADDR) +/**************************************************************/ +/**\name DATA READY ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->4 */ +#define SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__POS (4) +#define SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__MSK (0x10) +#define SMI130_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_1_ADDR) +/**************************************************************/ +/**\name FIFO FULL AND WATER MARK ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->5 */ +#define SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__POS (5) +#define SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__MSK (0x20) +#define SMI130_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_1_ADDR) + +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->6 */ +#define SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__POS (6) +#define SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__MSK (0x40) +#define SMI130_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_1_ADDR) +/**************************************************************/ +/**\name NO MOTION XYZ ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->0 */ +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__POS (0) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__MSK (0x01) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_2_ADDR) + +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->1 */ +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__POS (1) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__MSK (0x02) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_2_ADDR) + +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->2 */ +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__POS (2) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__MSK (0x04) +#define SMI130_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_2_ADDR) +/**************************************************************/ +/**\name STEP DETECTOR ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->3 */ +#define SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__POS (3) +#define SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__LEN (1) +#define SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__MSK (0x08) +#define SMI130_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG \ +(SMI130_USER_INTR_ENABLE_2_ADDR) +/**************************************************************/ +/**\name EDGE CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->0 */ +#define SMI130_USER_INTR1_EDGE_CTRL__POS (0) +#define SMI130_USER_INTR1_EDGE_CTRL__LEN (1) +#define SMI130_USER_INTR1_EDGE_CTRL__MSK (0x01) +#define SMI130_USER_INTR1_EDGE_CTRL__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name LEVEL CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->1 */ +#define SMI130_USER_INTR1_LEVEL__POS (1) +#define SMI130_USER_INTR1_LEVEL__LEN (1) +#define SMI130_USER_INTR1_LEVEL__MSK (0x02) +#define SMI130_USER_INTR1_LEVEL__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name OUTPUT TYPE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->2 */ +#define SMI130_USER_INTR1_OUTPUT_TYPE__POS (2) +#define SMI130_USER_INTR1_OUTPUT_TYPE__LEN (1) +#define SMI130_USER_INTR1_OUTPUT_TYPE__MSK (0x04) +#define SMI130_USER_INTR1_OUTPUT_TYPE__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name OUTPUT TYPE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->3 */ +#define SMI130_USER_INTR1_OUTPUT_ENABLE__POS (3) +#define SMI130_USER_INTR1_OUTPUT_ENABLE__LEN (1) +#define SMI130_USER_INTR1_OUTPUT_ENABLE__MSK (0x08) +#define SMI130_USER_INTR1_OUTPUT_ENABLE__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name EDGE CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->4 */ +#define SMI130_USER_INTR2_EDGE_CTRL__POS (4) +#define SMI130_USER_INTR2_EDGE_CTRL__LEN (1) +#define SMI130_USER_INTR2_EDGE_CTRL__MSK (0x10) +#define SMI130_USER_INTR2_EDGE_CTRL__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name LEVEL CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->5 */ +#define SMI130_USER_INTR2_LEVEL__POS (5) +#define SMI130_USER_INTR2_LEVEL__LEN (1) +#define SMI130_USER_INTR2_LEVEL__MSK (0x20) +#define SMI130_USER_INTR2_LEVEL__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name OUTPUT TYPE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->6 */ +#define SMI130_USER_INTR2_OUTPUT_TYPE__POS (6) +#define SMI130_USER_INTR2_OUTPUT_TYPE__LEN (1) +#define SMI130_USER_INTR2_OUTPUT_TYPE__MSK (0x40) +#define SMI130_USER_INTR2_OUTPUT_TYPE__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) + +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->7 */ +#define SMI130_USER_INTR2_OUTPUT_EN__POS (7) +#define SMI130_USER_INTR2_OUTPUT_EN__LEN (1) +#define SMI130_USER_INTR2_OUTPUT_EN__MSK (0x80) +#define SMI130_USER_INTR2_OUTPUT_EN__REG \ +(SMI130_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name LATCH INTERRUPT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Latch Description - Reg Addr --> 0x54, Bit -->0...3 */ +#define SMI130_USER_INTR_LATCH__POS (0) +#define SMI130_USER_INTR_LATCH__LEN (4) +#define SMI130_USER_INTR_LATCH__MSK (0x0F) +#define SMI130_USER_INTR_LATCH__REG (SMI130_USER_INTR_LATCH_ADDR) +/**************************************************************/ +/**\name INPUT ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Latch Description - Reg Addr --> 0x54, Bit -->4 */ +#define SMI130_USER_INTR1_INPUT_ENABLE__POS (4) +#define SMI130_USER_INTR1_INPUT_ENABLE__LEN (1) +#define SMI130_USER_INTR1_INPUT_ENABLE__MSK (0x10) +#define SMI130_USER_INTR1_INPUT_ENABLE__REG \ +(SMI130_USER_INTR_LATCH_ADDR) + +/* Int_Latch Description - Reg Addr --> 0x54, Bit -->5*/ +#define SMI130_USER_INTR2_INPUT_ENABLE__POS (5) +#define SMI130_USER_INTR2_INPUT_ENABLE__LEN (1) +#define SMI130_USER_INTR2_INPUT_ENABLE__MSK (0x20) +#define SMI130_USER_INTR2_INPUT_ENABLE__REG \ +(SMI130_USER_INTR_LATCH_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF LOW_G LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->0 */ +#define SMI130_USER_INTR_MAP_0_INTR1_LOW_G__POS (0) +#define SMI130_USER_INTR_MAP_0_INTR1_LOW_G__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_LOW_G__MSK (0x01) +#define SMI130_USER_INTR_MAP_0_INTR1_LOW_G__REG (SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF HIGH_G LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->1 */ +#define SMI130_USER_INTR_MAP_0_INTR1_HIGH_G__POS (1) +#define SMI130_USER_INTR_MAP_0_INTR1_HIGH_G__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_HIGH_G__MSK (0x02) +#define SMI130_USER_INTR_MAP_0_INTR1_HIGH_G__REG \ +(SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT MAPPIONG OF ANY MOTION_G LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->2 */ +#define SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__POS (2) +#define SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__MSK (0x04) +#define SMI130_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG \ +(SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF NO MOTION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->3 */ +#define SMI130_USER_INTR_MAP_0_INTR1_NOMOTION__POS (3) +#define SMI130_USER_INTR_MAP_0_INTR1_NOMOTION__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_NOMOTION__MSK (0x08) +#define SMI130_USER_INTR_MAP_0_INTR1_NOMOTION__REG (SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF DOUBLE TAP LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->4 */ +#define SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__POS (4) +#define SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__MSK (0x10) +#define SMI130_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG \ +(SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF SINGLE TAP LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->5 */ +#define SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP__POS (5) +#define SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP__MSK (0x20) +#define SMI130_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG \ +(SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF ORIENT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->6 */ +#define SMI130_USER_INTR_MAP_0_INTR1_ORIENT__POS (6) +#define SMI130_USER_INTR_MAP_0_INTR1_ORIENT__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_ORIENT__MSK (0x40) +#define SMI130_USER_INTR_MAP_0_INTR1_ORIENT__REG \ +(SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT MAPPIONG OF FLAT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x56, Bit -->7 */ +#define SMI130_USER_INTR_MAP_0_INTR1_FLAT__POS (7) +#define SMI130_USER_INTR_MAP_0_INTR1_FLAT__LEN (1) +#define SMI130_USER_INTR_MAP_0_INTR1_FLAT__MSK (0x80) +#define SMI130_USER_INTR_MAP_0_INTR1_FLAT__REG (SMI130_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF PMU TRIGGER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->0 */ +#define SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG__POS (0) +#define SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG__MSK (0x01) +#define SMI130_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG (SMI130_USER_INTR_MAP_1_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF FIFO FULL AND + WATER MARK LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->1 */ +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL__POS (1) +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL__MSK (0x02) +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG \ +(SMI130_USER_INTR_MAP_1_ADDR) + +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->2 */ +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM__POS (2) +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM__MSK (0x04) +#define SMI130_USER_INTR_MAP_1_INTR2_FIFO_WM__REG \ +(SMI130_USER_INTR_MAP_1_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF DATA READY LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->3 */ +#define SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY__POS (3) +#define SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY__MSK (0x08) +#define SMI130_USER_INTR_MAP_1_INTR2_DATA_RDY__REG \ +(SMI130_USER_INTR_MAP_1_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF PMU TRIGGER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->4 */ +#define SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG__POS (4) +#define SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG__MSK (0x10) +#define SMI130_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG (SMI130_USER_INTR_MAP_1_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF FIFO FULL AND + WATER MARK LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->5 */ +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL__POS (5) +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL__MSK (0x20) +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG \ +(SMI130_USER_INTR_MAP_1_ADDR) + +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->6 */ +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM__POS (6) +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM__MSK (0x40) +#define SMI130_USER_INTR_MAP_1_INTR1_FIFO_WM__REG \ +(SMI130_USER_INTR_MAP_1_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF DATA READY LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->7 */ +#define SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY__POS (7) +#define SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY__LEN (1) +#define SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY__MSK (0x80) +#define SMI130_USER_INTR_MAP_1_INTR1_DATA_RDY__REG \ +(SMI130_USER_INTR_MAP_1_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF LOW_G LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->0 */ +#define SMI130_USER_INTR_MAP_2_INTR2_LOW_G__POS (0) +#define SMI130_USER_INTR_MAP_2_INTR2_LOW_G__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_LOW_G__MSK (0x01) +#define SMI130_USER_INTR_MAP_2_INTR2_LOW_G__REG (SMI130_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF HIGH_G LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->1 */ +#define SMI130_USER_INTR_MAP_2_INTR2_HIGH_G__POS (1) +#define SMI130_USER_INTR_MAP_2_INTR2_HIGH_G__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_HIGH_G__MSK (0x02) +#define SMI130_USER_INTR_MAP_2_INTR2_HIGH_G__REG \ +(SMI130_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF ANY MOTION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->2 */ +#define SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__POS (2) +#define SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__MSK (0x04) +#define SMI130_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG \ +(SMI130_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF NO MOTION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->3 */ +#define SMI130_USER_INTR_MAP_2_INTR2_NOMOTION__POS (3) +#define SMI130_USER_INTR_MAP_2_INTR2_NOMOTION__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_NOMOTION__MSK (0x08) +#define SMI130_USER_INTR_MAP_2_INTR2_NOMOTION__REG (SMI130_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF DOUBLE TAP LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->4 */ +#define SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__POS (4) +#define SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__MSK (0x10) +#define SMI130_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG \ +(SMI130_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF SINGLE TAP LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->5 */ +#define SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP__POS (5) +#define SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP__MSK (0x20) +#define SMI130_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG \ +(SMI130_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF ORIENT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->6 */ +#define SMI130_USER_INTR_MAP_2_INTR2_ORIENT__POS (6) +#define SMI130_USER_INTR_MAP_2_INTR2_ORIENT__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_ORIENT__MSK (0x40) +#define SMI130_USER_INTR_MAP_2_INTR2_ORIENT__REG \ +(SMI130_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF FLAT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->7 */ +#define SMI130_USER_INTR_MAP_2_INTR2_FLAT__POS (7) +#define SMI130_USER_INTR_MAP_2_INTR2_FLAT__LEN (1) +#define SMI130_USER_INTR_MAP_2_INTR2_FLAT__MSK (0x80) +#define SMI130_USER_INTR_MAP_2_INTR2_FLAT__REG (SMI130_USER_INTR_MAP_2_ADDR) + +/**************************************************************/ +/**\name TAP SOURCE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Data_0 Description - Reg Addr --> 0x58, Bit --> 3 */ +#define SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE__POS (3) +#define SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE__LEN (1) +#define SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE__MSK (0x08) +#define SMI130_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG \ +(SMI130_USER_INTR_DATA_0_ADDR) + +/**************************************************************/ +/**\name HIGH SOURCE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Data_0 Description - Reg Addr --> 0x58, Bit --> 7 */ +#define SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__POS (7) +#define SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__LEN (1) +#define SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__MSK (0x80) +#define SMI130_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG \ +(SMI130_USER_INTR_DATA_0_ADDR) + +/**************************************************************/ +/**\name MOTION SOURCE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Data_1 Description - Reg Addr --> 0x59, Bit --> 7 */ +#define SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE__POS (7) +#define SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE__LEN (1) +#define SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE__MSK (0x80) +#define SMI130_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG \ + (SMI130_USER_INTR_DATA_1_ADDR) +/**************************************************************/ +/**\name LOW HIGH DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_0 Description - Reg Addr --> 0x5a, Bit --> 0...7 */ +#define SMI130_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__POS (0) +#define SMI130_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__LEN (8) +#define SMI130_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__MSK (0xFF) +#define SMI130_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG \ + (SMI130_USER_INTR_LOWHIGH_0_ADDR) +/**************************************************************/ +/**\name LOW THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_1 Description - Reg Addr --> 0x5b, Bit --> 0...7 */ +#define SMI130_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__POS (0) +#define SMI130_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__LEN (8) +#define SMI130_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__MSK (0xFF) +#define SMI130_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG \ + (SMI130_USER_INTR_LOWHIGH_1_ADDR) +/**************************************************************/ +/**\name LOW HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_2 Description - Reg Addr --> 0x5c, Bit --> 0...1 */ +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__POS (0) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__LEN (2) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__MSK (0x03) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG \ + (SMI130_USER_INTR_LOWHIGH_2_ADDR) +/**************************************************************/ +/**\name LOW MODE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_2 Description - Reg Addr --> 0x5c, Bit --> 2 */ +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__POS (2) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__LEN (1) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__MSK (0x04) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG \ + (SMI130_USER_INTR_LOWHIGH_2_ADDR) +/**************************************************************/ +/**\name HIGH_G HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_2 Description - Reg Addr --> 0x5c, Bit --> 6...7 */ +#define SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__POS (6) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__LEN (2) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__MSK (0xC0) +#define SMI130_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG \ + (SMI130_USER_INTR_LOWHIGH_2_ADDR) +/**************************************************************/ +/**\name HIGH_G DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_3 Description - Reg Addr --> 0x5d, Bit --> 0...7 */ +#define SMI130_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__POS (0) +#define SMI130_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__LEN (8) +#define SMI130_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__MSK (0xFF) +#define SMI130_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG \ + (SMI130_USER_INTR_LOWHIGH_3_ADDR) +/**************************************************************/ +/**\name HIGH_G THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_4 Description - Reg Addr --> 0x5e, Bit --> 0...7 */ +#define SMI130_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__POS (0) +#define SMI130_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__LEN (8) +#define SMI130_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__MSK (0xFF) +#define SMI130_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG \ + (SMI130_USER_INTR_LOWHIGH_4_ADDR) +/**************************************************************/ +/**\name ANY MOTION DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_0 Description - Reg Addr --> 0x5f, Bit --> 0...1 */ +#define SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__POS (0) +#define SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__LEN (2) +#define SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__MSK (0x03) +#define SMI130_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG \ + (SMI130_USER_INTR_MOTION_0_ADDR) +/**************************************************************/ +/**\name SLOW/NO MOTION DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ + /* Int_Motion_0 Description - Reg Addr --> 0x5f, Bit --> 2...7 */ +#define SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__POS (2) +#define SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__LEN (6) +#define SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__MSK (0xFC) +#define SMI130_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG \ + (SMI130_USER_INTR_MOTION_0_ADDR) +/**************************************************************/ +/**\name ANY MOTION THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_1 Description - Reg Addr --> (0x60), Bit --> 0...7 */ +#define SMI130_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__POS (0) +#define SMI130_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__LEN (8) +#define SMI130_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__MSK (0xFF) +#define SMI130_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG \ + (SMI130_USER_INTR_MOTION_1_ADDR) +/**************************************************************/ +/**\name SLOW/NO MOTION THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_2 Description - Reg Addr --> 0x61, Bit --> 0...7 */ +#define SMI130_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__POS (0) +#define SMI130_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__LEN (8) +#define SMI130_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__MSK (0xFF) +#define SMI130_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG \ + (SMI130_USER_INTR_MOTION_2_ADDR) +/**************************************************************/ +/**\name SLOW/NO MOTION SELECT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 0 */ +#define SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__POS (0) +#define SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__LEN (1) +#define SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__MSK (0x01) +#define SMI130_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG \ +(SMI130_USER_INTR_MOTION_3_ADDR) +/**************************************************************/ +/**\name SIGNIFICANT MOTION SELECT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 1 */ +#define SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT__POS (1) +#define SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT__LEN (1) +#define SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT__MSK (0x02) +#define SMI130_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG \ + (SMI130_USER_INTR_MOTION_3_ADDR) + +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 3..2 */ +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP__POS (2) +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP__LEN (2) +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP__MSK (0x0C) +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG \ + (SMI130_USER_INTR_MOTION_3_ADDR) + +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 5..4 */ +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF__POS (4) +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF__LEN (2) +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF__MSK (0x30) +#define SMI130_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG \ + (SMI130_USER_INTR_MOTION_3_ADDR) +/**************************************************************/ +/**\name TAP DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* INT_TAP_0 Description - Reg Addr --> (0x63), Bit --> 0..2*/ +#define SMI130_USER_INTR_TAP_0_INTR_TAP_DURN__POS (0) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_DURN__LEN (3) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_DURN__MSK (0x07) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_DURN__REG \ +(SMI130_USER_INTR_TAP_0_ADDR) +/**************************************************************/ +/**\name TAP SHOCK LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Tap_0 Description - Reg Addr --> (0x63), Bit --> 6 */ +#define SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK__POS (6) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK__LEN (1) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK__MSK (0x40) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG (SMI130_USER_INTR_TAP_0_ADDR) +/**************************************************************/ +/**\name TAP QUIET LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Tap_0 Description - Reg Addr --> (0x63), Bit --> 7 */ +#define SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET__POS (7) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET__LEN (1) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET__MSK (0x80) +#define SMI130_USER_INTR_TAP_0_INTR_TAP_QUIET__REG (SMI130_USER_INTR_TAP_0_ADDR) +/**************************************************************/ +/**\name TAP THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Tap_1 Description - Reg Addr --> (0x64), Bit --> 0...4 */ +#define SMI130_USER_INTR_TAP_1_INTR_TAP_THRES__POS (0) +#define SMI130_USER_INTR_TAP_1_INTR_TAP_THRES__LEN (5) +#define SMI130_USER_INTR_TAP_1_INTR_TAP_THRES__MSK (0x1F) +#define SMI130_USER_INTR_TAP_1_INTR_TAP_THRES__REG (SMI130_USER_INTR_TAP_1_ADDR) +/**************************************************************/ +/**\name ORIENT MODE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_0 Description - Reg Addr --> (0x65), Bit --> 0...1 */ +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__POS (0) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__LEN (2) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__MSK (0x03) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG \ + (SMI130_USER_INTR_ORIENT_0_ADDR) +/**************************************************************/ +/**\name ORIENT BLOCKING LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_0 Description - Reg Addr --> (0x65), Bit --> 2...3 */ +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__POS (2) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__LEN (2) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__MSK (0x0C) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG \ + (SMI130_USER_INTR_ORIENT_0_ADDR) +/**************************************************************/ +/**\name ORIENT HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_0 Description - Reg Addr --> (0x65), Bit --> 4...7 */ +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__POS (4) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__LEN (4) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__MSK (0xF0) +#define SMI130_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG \ + (SMI130_USER_INTR_ORIENT_0_ADDR) +/**************************************************************/ +/**\name ORIENT THETA LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_1 Description - Reg Addr --> 0x66, Bit --> 0...5 */ +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__POS (0) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__LEN (6) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__MSK (0x3F) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG \ + (SMI130_USER_INTR_ORIENT_1_ADDR) +/**************************************************************/ +/**\name ORIENT UD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_1 Description - Reg Addr --> 0x66, Bit --> 6 */ +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__POS (6) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__LEN (1) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__MSK (0x40) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG \ + (SMI130_USER_INTR_ORIENT_1_ADDR) +/**************************************************************/ +/**\name ORIENT AXIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_1 Description - Reg Addr --> 0x66, Bit --> 7 */ +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__POS (7) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__LEN (1) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__MSK (0x80) +#define SMI130_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG \ + (SMI130_USER_INTR_ORIENT_1_ADDR) +/**************************************************************/ +/**\name FLAT THETA LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Flat_0 Description - Reg Addr --> 0x67, Bit --> 0...5 */ +#define SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA__POS (0) +#define SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA__LEN (6) +#define SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA__MSK (0x3F) +#define SMI130_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG \ + (SMI130_USER_INTR_FLAT_0_ADDR) +/**************************************************************/ +/**\name FLAT HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Flat_1 Description - Reg Addr --> (0x68), Bit --> 0...3 */ +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST__POS (0) +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST__LEN (4) +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST__MSK (0x0F) +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG \ +(SMI130_USER_INTR_FLAT_1_ADDR) +/**************************************************************/ +/**\name FLAT HOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Flat_1 Description - Reg Addr --> (0x68), Bit --> 4...5 */ +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD__POS (4) +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD__LEN (2) +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD__MSK (0x30) +#define SMI130_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG \ +(SMI130_USER_INTR_FLAT_1_ADDR) +/**************************************************************/ +/**\name FOC ACCEL XYZ LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 0...1 */ +#define SMI130_USER_FOC_ACCEL_Z__POS (0) +#define SMI130_USER_FOC_ACCEL_Z__LEN (2) +#define SMI130_USER_FOC_ACCEL_Z__MSK (0x03) +#define SMI130_USER_FOC_ACCEL_Z__REG (SMI130_USER_FOC_CONFIG_ADDR) + +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 2...3 */ +#define SMI130_USER_FOC_ACCEL_Y__POS (2) +#define SMI130_USER_FOC_ACCEL_Y__LEN (2) +#define SMI130_USER_FOC_ACCEL_Y__MSK (0x0C) +#define SMI130_USER_FOC_ACCEL_Y__REG (SMI130_USER_FOC_CONFIG_ADDR) + +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 4...5 */ +#define SMI130_USER_FOC_ACCEL_X__POS (4) +#define SMI130_USER_FOC_ACCEL_X__LEN (2) +#define SMI130_USER_FOC_ACCEL_X__MSK (0x30) +#define SMI130_USER_FOC_ACCEL_X__REG (SMI130_USER_FOC_CONFIG_ADDR) +/**************************************************************/ +/**\name FOC GYRO LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 6 */ +#define SMI130_USER_FOC_GYRO_ENABLE__POS (6) +#define SMI130_USER_FOC_GYRO_ENABLE__LEN (1) +#define SMI130_USER_FOC_GYRO_ENABLE__MSK (0x40) +#define SMI130_USER_FOC_GYRO_ENABLE__REG \ +(SMI130_USER_FOC_CONFIG_ADDR) +/**************************************************************/ +/**\name NVM PROGRAM LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* CONF Description - Reg Addr --> (0x6A), Bit --> 1 */ +#define SMI130_USER_CONFIG_NVM_PROG_ENABLE__POS (1) +#define SMI130_USER_CONFIG_NVM_PROG_ENABLE__LEN (1) +#define SMI130_USER_CONFIG_NVM_PROG_ENABLE__MSK (0x02) +#define SMI130_USER_CONFIG_NVM_PROG_ENABLE__REG \ +(SMI130_USER_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x6B), Bit --> 0 */ + +#define SMI130_USER_IF_CONFIG_SPI3__POS (0) +#define SMI130_USER_IF_CONFIG_SPI3__LEN (1) +#define SMI130_USER_IF_CONFIG_SPI3__MSK (0x01) +#define SMI130_USER_IF_CONFIG_SPI3__REG \ +(SMI130_USER_IF_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x6B), Bit --> 5..4 */ +#define SMI130_USER_IF_CONFIG_IF_MODE__POS (4) +#define SMI130_USER_IF_CONFIG_IF_MODE__LEN (2) +#define SMI130_USER_IF_CONFIG_IF_MODE__MSK (0x30) +#define SMI130_USER_IF_CONFIG_IF_MODE__REG \ +(SMI130_USER_IF_CONFIG_ADDR) +/**************************************************************/ +/**\name GYRO SLEEP CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 0...2 */ +#define SMI130_USER_GYRO_SLEEP_TRIGGER__POS (0) +#define SMI130_USER_GYRO_SLEEP_TRIGGER__LEN (3) +#define SMI130_USER_GYRO_SLEEP_TRIGGER__MSK (0x07) +#define SMI130_USER_GYRO_SLEEP_TRIGGER__REG (SMI130_USER_PMU_TRIGGER_ADDR) + +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 3...4 */ +#define SMI130_USER_GYRO_WAKEUP_TRIGGER__POS (3) +#define SMI130_USER_GYRO_WAKEUP_TRIGGER__LEN (2) +#define SMI130_USER_GYRO_WAKEUP_TRIGGER__MSK (0x18) +#define SMI130_USER_GYRO_WAKEUP_TRIGGER__REG (SMI130_USER_PMU_TRIGGER_ADDR) + +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 5 */ +#define SMI130_USER_GYRO_SLEEP_STATE__POS (5) +#define SMI130_USER_GYRO_SLEEP_STATE__LEN (1) +#define SMI130_USER_GYRO_SLEEP_STATE__MSK (0x20) +#define SMI130_USER_GYRO_SLEEP_STATE__REG (SMI130_USER_PMU_TRIGGER_ADDR) + +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 6 */ +#define SMI130_USER_GYRO_WAKEUP_INTR__POS (6) +#define SMI130_USER_GYRO_WAKEUP_INTR__LEN (1) +#define SMI130_USER_GYRO_WAKEUP_INTR__MSK (0x40) +#define SMI130_USER_GYRO_WAKEUP_INTR__REG (SMI130_USER_PMU_TRIGGER_ADDR) +/**************************************************************/ +/**\name ACCEL SELF TEST LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 0...1 */ +#define SMI130_USER_ACCEL_SELFTEST_AXIS__POS (0) +#define SMI130_USER_ACCEL_SELFTEST_AXIS__LEN (2) +#define SMI130_USER_ACCEL_SELFTEST_AXIS__MSK (0x03) +#define SMI130_USER_ACCEL_SELFTEST_AXIS__REG (SMI130_USER_SELF_TEST_ADDR) + +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 2 */ +#define SMI130_USER_ACCEL_SELFTEST_SIGN__POS (2) +#define SMI130_USER_ACCEL_SELFTEST_SIGN__LEN (1) +#define SMI130_USER_ACCEL_SELFTEST_SIGN__MSK (0x04) +#define SMI130_USER_ACCEL_SELFTEST_SIGN__REG (SMI130_USER_SELF_TEST_ADDR) + +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 3 */ +#define SMI130_USER_SELFTEST_AMP__POS (3) +#define SMI130_USER_SELFTEST_AMP__LEN (1) +#define SMI130_USER_SELFTEST_AMP__MSK (0x08) +#define SMI130_USER_SELFTEST_AMP__REG (SMI130_USER_SELF_TEST_ADDR) +/**************************************************************/ +/**\name GYRO SELF TEST LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 4 */ +#define SMI130_USER_GYRO_SELFTEST_START__POS (4) +#define SMI130_USER_GYRO_SELFTEST_START__LEN (1) +#define SMI130_USER_GYRO_SELFTEST_START__MSK (0x10) +#define SMI130_USER_GYRO_SELFTEST_START__REG \ +(SMI130_USER_SELF_TEST_ADDR) +/**************************************************************/ +/**\name NV_CONFIG LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* NV_CONF Description - Reg Addr --> (0x70), Bit --> 0 */ +#define SMI130_USER_NV_CONFIG_SPI_ENABLE__POS (0) +#define SMI130_USER_NV_CONFIG_SPI_ENABLE__LEN (1) +#define SMI130_USER_NV_CONFIG_SPI_ENABLE__MSK (0x01) +#define SMI130_USER_NV_CONFIG_SPI_ENABLE__REG (SMI130_USER_NV_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x70), Bit --> 1 */ +#define SMI130_USER_IF_CONFIG_I2C_WDT_SELECT__POS (1) +#define SMI130_USER_IF_CONFIG_I2C_WDT_SELECT__LEN (1) +#define SMI130_USER_IF_CONFIG_I2C_WDT_SELECT__MSK (0x02) +#define SMI130_USER_IF_CONFIG_I2C_WDT_SELECT__REG \ +(SMI130_USER_NV_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x70), Bit --> 2 */ +#define SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE__POS (2) +#define SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE__LEN (1) +#define SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE__MSK (0x04) +#define SMI130_USER_IF_CONFIG_I2C_WDT_ENABLE__REG \ +(SMI130_USER_NV_CONFIG_ADDR) + +/* NV_CONF Description - Reg Addr --> (0x70), Bit --> 3 */ +#define SMI130_USER_NV_CONFIG_SPARE0__POS (3) +#define SMI130_USER_NV_CONFIG_SPARE0__LEN (1) +#define SMI130_USER_NV_CONFIG_SPARE0__MSK (0x08) +#define SMI130_USER_NV_CONFIG_SPARE0__REG (SMI130_USER_NV_CONFIG_ADDR) + +/* NV_CONF Description - Reg Addr --> (0x70), Bit --> 4...7 */ +#define SMI130_USER_NV_CONFIG_NVM_COUNTER__POS (4) +#define SMI130_USER_NV_CONFIG_NVM_COUNTER__LEN (4) +#define SMI130_USER_NV_CONFIG_NVM_COUNTER__MSK (0xF0) +#define SMI130_USER_NV_CONFIG_NVM_COUNTER__REG (SMI130_USER_NV_CONFIG_ADDR) +/**************************************************************/ +/**\name ACCEL MANUAL OFFSET LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_0 Description - Reg Addr --> (0x71), Bit --> 0...7 */ +#define SMI130_USER_OFFSET_0_ACCEL_OFF_X__POS (0) +#define SMI130_USER_OFFSET_0_ACCEL_OFF_X__LEN (8) +#define SMI130_USER_OFFSET_0_ACCEL_OFF_X__MSK (0xFF) +#define SMI130_USER_OFFSET_0_ACCEL_OFF_X__REG (SMI130_USER_OFFSET_0_ADDR) + +/* Offset_1 Description - Reg Addr --> 0x72, Bit --> 0...7 */ +#define SMI130_USER_OFFSET_1_ACCEL_OFF_Y__POS (0) +#define SMI130_USER_OFFSET_1_ACCEL_OFF_Y__LEN (8) +#define SMI130_USER_OFFSET_1_ACCEL_OFF_Y__MSK (0xFF) +#define SMI130_USER_OFFSET_1_ACCEL_OFF_Y__REG (SMI130_USER_OFFSET_1_ADDR) + +/* Offset_2 Description - Reg Addr --> 0x73, Bit --> 0...7 */ +#define SMI130_USER_OFFSET_2_ACCEL_OFF_Z__POS (0) +#define SMI130_USER_OFFSET_2_ACCEL_OFF_Z__LEN (8) +#define SMI130_USER_OFFSET_2_ACCEL_OFF_Z__MSK (0xFF) +#define SMI130_USER_OFFSET_2_ACCEL_OFF_Z__REG (SMI130_USER_OFFSET_2_ADDR) +/**************************************************************/ +/**\name GYRO MANUAL OFFSET LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_3 Description - Reg Addr --> 0x74, Bit --> 0...7 */ +#define SMI130_USER_OFFSET_3_GYRO_OFF_X__POS (0) +#define SMI130_USER_OFFSET_3_GYRO_OFF_X__LEN (8) +#define SMI130_USER_OFFSET_3_GYRO_OFF_X__MSK (0xFF) +#define SMI130_USER_OFFSET_3_GYRO_OFF_X__REG (SMI130_USER_OFFSET_3_ADDR) + +/* Offset_4 Description - Reg Addr --> 0x75, Bit --> 0...7 */ +#define SMI130_USER_OFFSET_4_GYRO_OFF_Y__POS (0) +#define SMI130_USER_OFFSET_4_GYRO_OFF_Y__LEN (8) +#define SMI130_USER_OFFSET_4_GYRO_OFF_Y__MSK (0xFF) +#define SMI130_USER_OFFSET_4_GYRO_OFF_Y__REG (SMI130_USER_OFFSET_4_ADDR) + +/* Offset_5 Description - Reg Addr --> 0x76, Bit --> 0...7 */ +#define SMI130_USER_OFFSET_5_GYRO_OFF_Z__POS (0) +#define SMI130_USER_OFFSET_5_GYRO_OFF_Z__LEN (8) +#define SMI130_USER_OFFSET_5_GYRO_OFF_Z__MSK (0xFF) +#define SMI130_USER_OFFSET_5_GYRO_OFF_Z__REG (SMI130_USER_OFFSET_5_ADDR) + + +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 0..1 */ +#define SMI130_USER_OFFSET_6_GYRO_OFF_X__POS (0) +#define SMI130_USER_OFFSET_6_GYRO_OFF_X__LEN (2) +#define SMI130_USER_OFFSET_6_GYRO_OFF_X__MSK (0x03) +#define SMI130_USER_OFFSET_6_GYRO_OFF_X__REG (SMI130_USER_OFFSET_6_ADDR) + +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 2...3 */ +#define SMI130_USER_OFFSET_6_GYRO_OFF_Y__POS (2) +#define SMI130_USER_OFFSET_6_GYRO_OFF_Y__LEN (2) +#define SMI130_USER_OFFSET_6_GYRO_OFF_Y__MSK (0x0C) +#define SMI130_USER_OFFSET_6_GYRO_OFF_Y__REG (SMI130_USER_OFFSET_6_ADDR) + +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 4...5 */ +#define SMI130_USER_OFFSET_6_GYRO_OFF_Z__POS (4) +#define SMI130_USER_OFFSET_6_GYRO_OFF_Z__LEN (2) +#define SMI130_USER_OFFSET_6_GYRO_OFF_Z__MSK (0x30) +#define SMI130_USER_OFFSET_6_GYRO_OFF_Z__REG (SMI130_USER_OFFSET_6_ADDR) +/**************************************************************/ +/**\name ACCEL OFFSET ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 6 */ +#define SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE__POS (6) +#define SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE__LEN (1) +#define SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE__MSK (0x40) +#define SMI130_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG \ +(SMI130_USER_OFFSET_6_ADDR) +/**************************************************************/ +/**\name GYRO OFFSET ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 7 */ +#define SMI130_USER_OFFSET_6_GYRO_OFF_EN__POS (7) +#define SMI130_USER_OFFSET_6_GYRO_OFF_EN__LEN (1) +#define SMI130_USER_OFFSET_6_GYRO_OFF_EN__MSK (0x80) +#define SMI130_USER_OFFSET_6_GYRO_OFF_EN__REG (SMI130_USER_OFFSET_6_ADDR) +/**************************************************************/ +/**\name STEP COUNTER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* STEP_CNT_0 Description - Reg Addr --> 0x78, Bit --> 0 to 7 */ +#define SMI130_USER_STEP_COUNT_LSB__POS (0) +#define SMI130_USER_STEP_COUNT_LSB__LEN (7) +#define SMI130_USER_STEP_COUNT_LSB__MSK (0xFF) +#define SMI130_USER_STEP_COUNT_LSB__REG (SMI130_USER_STEP_COUNT_0_ADDR) + +/* STEP_CNT_1 Description - Reg Addr --> 0x79, Bit --> 0 to 7 */ +#define SMI130_USER_STEP_COUNT_MSB__POS (0) +#define SMI130_USER_STEP_COUNT_MSB__LEN (7) +#define SMI130_USER_STEP_COUNT_MSB__MSK (0xFF) +#define SMI130_USER_STEP_COUNT_MSB__REG (SMI130_USER_STEP_COUNT_1_ADDR) +/**************************************************************/ +/**\name STEP COUNTER CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* STEP_CONFIG_0 Description - Reg Addr --> 0x7A, Bit --> 0 to 7 */ +#define SMI130_USER_STEP_CONFIG_ZERO__POS (0) +#define SMI130_USER_STEP_CONFIG_ZERO__LEN (7) +#define SMI130_USER_STEP_CONFIG_ZERO__MSK (0xFF) +#define SMI130_USER_STEP_CONFIG_ZERO__REG \ +(SMI130_USER_STEP_CONFIG_0_ADDR) + + +/* STEP_CONFIG_1 Description - Reg Addr --> 0x7B, Bit --> 0 to 2 and +4 to 7 */ +#define SMI130_USER_STEP_CONFIG_ONE_CNF1__POS (0) +#define SMI130_USER_STEP_CONFIG_ONE_CNF1__LEN (3) +#define SMI130_USER_STEP_CONFIG_ONE_CNF1__MSK (0x07) +#define SMI130_USER_STEP_CONFIG_ONE_CNF1__REG \ +(SMI130_USER_STEP_CONFIG_1_ADDR) + +#define SMI130_USER_STEP_CONFIG_ONE_CNF2__POS (4) +#define SMI130_USER_STEP_CONFIG_ONE_CNF2__LEN (4) +#define SMI130_USER_STEP_CONFIG_ONE_CNF2__MSK (0xF0) +#define SMI130_USER_STEP_CONFIG_ONE_CNF2__REG \ +(SMI130_USER_STEP_CONFIG_1_ADDR) +/**************************************************************/ +/**\name STEP COUNTER ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* STEP_CONFIG_1 Description - Reg Addr --> 0x7B, Bit --> 0 to 2 */ +#define SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__POS (3) +#define SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__LEN (1) +#define SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__MSK (0x08) +#define SMI130_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG \ +(SMI130_USER_STEP_CONFIG_1_ADDR) + +/* USER REGISTERS DEFINITION END */ +/**************************************************************************/ +/* CMD REGISTERS DEFINITION START */ +/**************************************************************/ +/**\name COMMAND REGISTER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Command description address - Reg Addr --> 0x7E, Bit --> 0....7 */ +#define SMI130_CMD_COMMANDS__POS (0) +#define SMI130_CMD_COMMANDS__LEN (8) +#define SMI130_CMD_COMMANDS__MSK (0xFF) +#define SMI130_CMD_COMMANDS__REG (SMI130_CMD_COMMANDS_ADDR) +/**************************************************************/ +/**\name PAGE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Target page address - Reg Addr --> 0x7F, Bit --> 4....5 */ +#define SMI130_CMD_TARGET_PAGE__POS (4) +#define SMI130_CMD_TARGET_PAGE__LEN (2) +#define SMI130_CMD_TARGET_PAGE__MSK (0x30) +#define SMI130_CMD_TARGET_PAGE__REG (SMI130_CMD_EXT_MODE_ADDR) + +/* Target page address - Reg Addr --> 0x7F, Bit --> 4....5 */ +#define SMI130_CMD_PAGING_EN__POS (7) +#define SMI130_CMD_PAGING_EN__LEN (1) +#define SMI130_CMD_PAGING_EN__MSK (0x80) +#define SMI130_CMD_PAGING_EN__REG (SMI130_CMD_EXT_MODE_ADDR) + +/* Target page address - Reg Addr --> 0x7F, Bit --> 4....5 */ +#define SMI130_COM_C_TRIM_FIVE__POS (0) +#define SMI130_COM_C_TRIM_FIVE__LEN (8) +#define SMI130_COM_C_TRIM_FIVE__MSK (0xFF) +#define SMI130_COM_C_TRIM_FIVE__REG (SMI130_COM_C_TRIM_FIVE_ADDR) + +/**************************************************************************/ +/* CMD REGISTERS DEFINITION END */ + +/**************************************************/ +/**\name FIFO FRAME COUNT DEFINITION */ +/*************************************************/ +#define FIFO_FRAME (1024) +#define FIFO_CONFIG_CHECK1 (0x00) +#define FIFO_CONFIG_CHECK2 (0x80) +/**************************************************/ +/**\name MAG SENSOR SELECT */ +/*************************************************/ +#define BST_BMM (0) +#define BST_AKM (1) +#define SMI130_YAS537_I2C_ADDRESS (0x2E) +/**************************************************/ +/**\name ACCEL RANGE */ +/*************************************************/ +#define SMI130_ACCEL_RANGE_2G (0X03) +#define SMI130_ACCEL_RANGE_4G (0X05) +#define SMI130_ACCEL_RANGE_8G (0X08) +#define SMI130_ACCEL_RANGE_16G (0X0C) +/**************************************************/ +/**\name ACCEL ODR */ +/*************************************************/ +#define SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED (0x00) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_0_78HZ (0x01) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_1_56HZ (0x02) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_3_12HZ (0x03) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_6_25HZ (0x04) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_12_5HZ (0x05) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_25HZ (0x06) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_50HZ (0x07) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_100HZ (0x08) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_200HZ (0x09) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_400HZ (0x0A) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_800HZ (0x0B) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_1600HZ (0x0C) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED0 (0x0D) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED1 (0x0E) +#define SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED2 (0x0F) +/**************************************************/ +/**\name ACCEL BANDWIDTH PARAMETER */ +/*************************************************/ +#define SMI130_ACCEL_OSR4_AVG1 (0x00) +#define SMI130_ACCEL_OSR2_AVG2 (0x01) +#define SMI130_ACCEL_NORMAL_AVG4 (0x02) +#define SMI130_ACCEL_CIC_AVG8 (0x03) +#define SMI130_ACCEL_RES_AVG16 (0x04) +#define SMI130_ACCEL_RES_AVG32 (0x05) +#define SMI130_ACCEL_RES_AVG64 (0x06) +#define SMI130_ACCEL_RES_AVG128 (0x07) +/**************************************************/ +/**\name GYRO ODR */ +/*************************************************/ +#define SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED (0x00) +#define SMI130_GYRO_OUTPUT_DATA_RATE_25HZ (0x06) +#define SMI130_GYRO_OUTPUT_DATA_RATE_50HZ (0x07) +#define SMI130_GYRO_OUTPUT_DATA_RATE_100HZ (0x08) +#define SMI130_GYRO_OUTPUT_DATA_RATE_200HZ (0x09) +#define SMI130_GYRO_OUTPUT_DATA_RATE_400HZ (0x0A) +#define SMI130_GYRO_OUTPUT_DATA_RATE_800HZ (0x0B) +#define SMI130_GYRO_OUTPUT_DATA_RATE_1600HZ (0x0C) +#define SMI130_GYRO_OUTPUT_DATA_RATE_3200HZ (0x0D) +/**************************************************/ +/**\name GYRO BANDWIDTH PARAMETER */ +/*************************************************/ +#define SMI130_GYRO_OSR4_MODE (0x00) +#define SMI130_GYRO_OSR2_MODE (0x01) +#define SMI130_GYRO_NORMAL_MODE (0x02) +#define SMI130_GYRO_CIC_MODE (0x03) +/**************************************************/ +/**\name GYROSCOPE RANGE PARAMETER */ +/*************************************************/ +#define SMI130_GYRO_RANGE_2000_DEG_SEC (0x00) +#define SMI130_GYRO_RANGE_1000_DEG_SEC (0x01) +#define SMI130_GYRO_RANGE_500_DEG_SEC (0x02) +#define SMI130_GYRO_RANGE_250_DEG_SEC (0x03) +#define SMI130_GYRO_RANGE_125_DEG_SEC (0x04) +/**************************************************/ +/**\name MAG ODR */ +/*************************************************/ +#define SMI130_MAG_OUTPUT_DATA_RATE_RESERVED (0x00) +#define SMI130_MAG_OUTPUT_DATA_RATE_0_78HZ (0x01) +#define SMI130_MAG_OUTPUT_DATA_RATE_1_56HZ (0x02) +#define SMI130_MAG_OUTPUT_DATA_RATE_3_12HZ (0x03) +#define SMI130_MAG_OUTPUT_DATA_RATE_6_25HZ (0x04) +#define SMI130_MAG_OUTPUT_DATA_RATE_12_5HZ (0x05) +#define SMI130_MAG_OUTPUT_DATA_RATE_25HZ (0x06) +#define SMI130_MAG_OUTPUT_DATA_RATE_50HZ (0x07) +#define SMI130_MAG_OUTPUT_DATA_RATE_100HZ (0x08) +#define SMI130_MAG_OUTPUT_DATA_RATE_200HZ (0x09) +#define SMI130_MAG_OUTPUT_DATA_RATE_400HZ (0x0A) +#define SMI130_MAG_OUTPUT_DATA_RATE_800HZ (0x0B) +#define SMI130_MAG_OUTPUT_DATA_RATE_1600HZ (0x0C) +#define SMI130_MAG_OUTPUT_DATA_RATE_RESERVED0 (0x0D) +#define SMI130_MAG_OUTPUT_DATA_RATE_RESERVED1 (0x0E) +#define SMI130_MAG_OUTPUT_DATA_RATE_RESERVED2 (0x0F) + +/**************************************************/ +/**\name ENABLE/DISABLE SELECTIONS */ +/*************************************************/ + +/* Enable accel and gyro offset */ +#define ACCEL_OFFSET_ENABLE (0x01) +#define GYRO_OFFSET_ENABLE (0x01) + +/* command register definition */ +#define START_FOC_ACCEL_GYRO (0X03) + + /* INT ENABLE 1 */ +#define SMI130_ANY_MOTION_X_ENABLE (0) +#define SMI130_ANY_MOTION_Y_ENABLE (1) +#define SMI130_ANY_MOTION_Z_ENABLE (2) +#define SMI130_DOUBLE_TAP_ENABLE (4) +#define SMI130_SINGLE_TAP_ENABLE (5) +#define SMI130_ORIENT_ENABLE (6) +#define SMI130_FLAT_ENABLE (7) + +/* INT ENABLE 1 */ +#define SMI130_HIGH_G_X_ENABLE (0) +#define SMI130_HIGH_G_Y_ENABLE (1) +#define SMI130_HIGH_G_Z_ENABLE (2) +#define SMI130_LOW_G_ENABLE (3) +#define SMI130_DATA_RDY_ENABLE (4) +#define SMI130_FIFO_FULL_ENABLE (5) +#define SMI130_FIFO_WM_ENABLE (6) + +/* INT ENABLE 2 */ +#define SMI130_NOMOTION_X_ENABLE (0) +#define SMI130_NOMOTION_Y_ENABLE (1) +#define SMI130_NOMOTION_Z_ENABLE (2) +#define SMI130_STEP_DETECTOR_EN (3) + +/* FOC axis selection for accel*/ +#define FOC_X_AXIS (0) +#define FOC_Y_AXIS (1) +#define FOC_Z_AXIS (2) + +/* IN OUT CONTROL */ +#define SMI130_INTR1_EDGE_CTRL (0) +#define SMI130_INTR2_EDGE_CTRL (1) +#define SMI130_INTR1_LEVEL (0) +#define SMI130_INTR2_LEVEL (1) +#define SMI130_INTR1_OUTPUT_TYPE (0) +#define SMI130_INTR2_OUTPUT_TYPE (1) +#define SMI130_INTR1_OUTPUT_ENABLE (0) +#define SMI130_INTR2_OUTPUT_ENABLE (1) + +#define SMI130_INTR1_INPUT_ENABLE (0) +#define SMI130_INTR2_INPUT_ENABLE (1) + +/* INTERRUPT MAPS */ +#define SMI130_INTR1_MAP_LOW_G (0) +#define SMI130_INTR2_MAP_LOW_G (1) +#define SMI130_INTR1_MAP_HIGH_G (0) +#define SMI130_INTR2_MAP_HIGH_G (1) +#define SMI130_INTR1_MAP_ANY_MOTION (0) +#define SMI130_INTR2_MAP_ANY_MOTION (1) +#define SMI130_INTR1_MAP_NOMO (0) +#define SMI130_INTR2_MAP_NOMO (1) +#define SMI130_INTR1_MAP_DOUBLE_TAP (0) +#define SMI130_INTR2_MAP_DOUBLE_TAP (1) +#define SMI130_INTR1_MAP_SINGLE_TAP (0) +#define SMI130_INTR2_MAP_SINGLE_TAP (1) +#define SMI130_INTR1_MAP_ORIENT (0) +#define SMI130_INTR2_MAP_ORIENT (1) +#define SMI130_INTR1_MAP_FLAT (0) +#define SMI130_INTR2_MAP_FLAT (1) +#define SMI130_INTR1_MAP_DATA_RDY (0) +#define SMI130_INTR2_MAP_DATA_RDY (1) +#define SMI130_INTR1_MAP_FIFO_WM (0) +#define SMI130_INTR2_MAP_FIFO_WM (1) +#define SMI130_INTR1_MAP_FIFO_FULL (0) +#define SMI130_INTR2_MAP_FIFO_FULL (1) +#define SMI130_INTR1_MAP_PMUTRIG (0) +#define SMI130_INTR2_MAP_PMUTRIG (1) + +/* Interrupt mapping*/ +#define SMI130_MAP_INTR1 (0) +#define SMI130_MAP_INTR2 (1) +/**************************************************/ +/**\name TAP DURATION */ +/*************************************************/ +#define SMI130_TAP_DURN_50MS (0x00) +#define SMI130_TAP_DURN_100MS (0x01) +#define SMI130_TAP_DURN_150MS (0x02) +#define SMI130_TAP_DURN_200MS (0x03) +#define SMI130_TAP_DURN_250MS (0x04) +#define SMI130_TAP_DURN_375MS (0x05) +#define SMI130_TAP_DURN_500MS (0x06) +#define SMI130_TAP_DURN_700MS (0x07) +/**************************************************/ +/**\name TAP SHOCK */ +/*************************************************/ +#define SMI130_TAP_SHOCK_50MS (0x00) +#define SMI130_TAP_SHOCK_75MS (0x01) +/**************************************************/ +/**\name TAP QUIET */ +/*************************************************/ +#define SMI130_TAP_QUIET_30MS (0x00) +#define SMI130_TAP_QUIET_20MS (0x01) +/**************************************************/ +/**\name STEP DETECTION SELECTION MODES */ +/*************************************************/ +#define SMI130_STEP_NORMAL_MODE (0) +#define SMI130_STEP_SENSITIVE_MODE (1) +#define SMI130_STEP_ROBUST_MODE (2) +/**************************************************/ +/**\name STEP CONFIGURATION SELECT MODE */ +/*************************************************/ +#define STEP_CONFIG_NORMAL (0X315) +#define STEP_CONFIG_SENSITIVE (0X2D) +#define STEP_CONFIG_ROBUST (0X71D) +/**************************************************/ +/**\name BMM150 TRIM DATA DEFINITIONS */ +/*************************************************/ +#define SMI130_MAG_DIG_X1 (0x5D) +#define SMI130_MAG_DIG_Y1 (0x5E) +#define SMI130_MAG_DIG_Z4_LSB (0x62) +#define SMI130_MAG_DIG_Z4_MSB (0x63) +#define SMI130_MAG_DIG_X2 (0x64) +#define SMI130_MAG_DIG_Y2 (0x65) +#define SMI130_MAG_DIG_Z2_LSB (0x68) +#define SMI130_MAG_DIG_Z2_MSB (0x69) +#define SMI130_MAG_DIG_Z1_LSB (0x6A) +#define SMI130_MAG_DIG_Z1_MSB (0x6B) +#define SMI130_MAG_DIG_XYZ1_LSB (0x6C) +#define SMI130_MAG_DIG_XYZ1_MSB (0x6D) +#define SMI130_MAG_DIG_Z3_LSB (0x6E) +#define SMI130_MAG_DIG_Z3_MSB (0x6F) +#define SMI130_MAG_DIG_XY2 (0x70) +#define SMI130_MAG_DIG_XY1 (0x71) +/**************************************************/ +/**\name BMM150 PRE-SET MODE DEFINITIONS */ +/*************************************************/ +#define SMI130_MAG_PRESETMODE_LOWPOWER (1) +#define SMI130_MAG_PRESETMODE_REGULAR (2) +#define SMI130_MAG_PRESETMODE_HIGHACCURACY (3) +#define SMI130_MAG_PRESETMODE_ENHANCED (4) +/**************************************************/ +/**\name BMM150 PRESET MODES - DATA RATES */ +/*************************************************/ +#define SMI130_MAG_LOWPOWER_DR (0x02) +#define SMI130_MAG_REGULAR_DR (0x02) +#define SMI130_MAG_HIGHACCURACY_DR (0x2A) +#define SMI130_MAG_ENHANCED_DR (0x02) +/**************************************************/ +/**\name BMM150 PRESET MODES - REPETITIONS-XY RATES */ +/*************************************************/ +#define SMI130_MAG_LOWPOWER_REPXY (1) +#define SMI130_MAG_REGULAR_REPXY (4) +#define SMI130_MAG_HIGHACCURACY_REPXY (23) +#define SMI130_MAG_ENHANCED_REPXY (7) +/**************************************************/ +/**\name BMM150 PRESET MODES - REPETITIONS-Z RATES */ +/*************************************************/ +#define SMI130_MAG_LOWPOWER_REPZ (2) +#define SMI130_MAG_REGULAR_REPZ (14) +#define SMI130_MAG_HIGHACCURACY_REPZ (82) +#define SMI130_MAG_ENHANCED_REPZ (26) +#define SMI130_MAG_NOAMRL_SWITCH_TIMES (5) +#define MAG_INTERFACE_PMU_ENABLE (1) +#define MAG_INTERFACE_PMU_DISABLE (0) +/**************************************************/ +/**\name USED FOR MAG OVERFLOW CHECK FOR BMM150 */ +/*************************************************/ +#define SMI130_MAG_OVERFLOW_OUTPUT ((s16)-32768) +#define SMI130_MAG_OVERFLOW_OUTPUT_S32 ((s32)(-2147483647-1)) +#define SMI130_MAG_NEGATIVE_SATURATION_Z ((s16)-32767) +#define SMI130_MAG_POSITIVE_SATURATION_Z ((u16)32767) +#define SMI130_MAG_FLIP_OVERFLOW_ADCVAL ((s16)-4096) +#define SMI130_MAG_HALL_OVERFLOW_ADCVAL ((s16)-16384) +/**************************************************/ +/**\name BMM150 REGISTER DEFINITION */ +/*************************************************/ +#define SMI130_BMM150_CHIP_ID (0x40) +#define SMI130_BMM150_POWE_CONTROL_REG (0x4B) +#define SMI130_BMM150_POWE_MODE_REG (0x4C) +#define SMI130_BMM150_DATA_REG (0x42) +#define SMI130_BMM150_XY_REP (0x51) +#define SMI130_BMM150_Z_REP (0x52) +/**************************************************/ +/**\name AKM COMPENSATING DATA REGISTERS */ +/*************************************************/ +#define SMI130_BST_AKM_ASAX (0x60) +#define SMI130_BST_AKM_ASAY (0x61) +#define SMI130_BST_AKM_ASAZ (0x62) +/**************************************************/ +/**\name AKM POWER MODE SELECTION */ +/*************************************************/ +#define AKM_POWER_DOWN_MODE (0) +#define AKM_SINGLE_MEAS_MODE (1) +#define FUSE_ROM_MODE (2) +/**************************************************/ +/**\name SECONDARY_MAG POWER MODE SELECTION */ +/*************************************************/ +#define SMI130_MAG_FORCE_MODE (0) +#define SMI130_MAG_SUSPEND_MODE (1) +/**************************************************/ +/**\name MAG POWER MODE SELECTION */ +/*************************************************/ +#define FORCE_MODE (0) +#define SUSPEND_MODE (1) +#define NORMAL_MODE (2) +#define MAG_SUSPEND_MODE (1) +/**************************************************/ +/**\name FIFO CONFIGURATIONS */ +/*************************************************/ +#define FIFO_HEADER_ENABLE (0x01) +#define FIFO_MAG_ENABLE (0x01) +#define FIFO_ACCEL_ENABLE (0x01) +#define FIFO_GYRO_ENABLE (0x01) +#define FIFO_TIME_ENABLE (0x01) +#define FIFO_STOPONFULL_ENABLE (0x01) +#define FIFO_WM_INTERRUPT_ENABLE (0x01) +#define SMI130_FIFO_INDEX_LENGTH (1) +#define SMI130_FIFO_TAG_INTR_MASK (0xFC) + +/**************************************************/ +/**\name ACCEL POWER MODE */ +/*************************************************/ +#define ACCEL_MODE_NORMAL (0x11) +#define ACCEL_LOWPOWER (0X12) +#define ACCEL_SUSPEND (0X10) +/**************************************************/ +/**\name GYRO POWER MODE */ +/*************************************************/ +#define GYRO_MODE_SUSPEND (0x14) +#define GYRO_MODE_NORMAL (0x15) +#define GYRO_MODE_FASTSTARTUP (0x17) +/**************************************************/ +/**\name MAG POWER MODE */ +/*************************************************/ +#define MAG_MODE_SUSPEND (0x18) +#define MAG_MODE_NORMAL (0x19) +#define MAG_MODE_LOWPOWER (0x1A) +/**************************************************/ +/**\name ENABLE/DISABLE BIT VALUES */ +/*************************************************/ +#define SMI130_ENABLE (0x01) +#define SMI130_DISABLE (0x00) +/**************************************************/ +/**\name INTERRUPT EDGE TRIGGER ENABLE */ +/*************************************************/ +#define SMI130_EDGE (0x01) +#define SMI130_LEVEL (0x00) +/**************************************************/ +/**\name INTERRUPT LEVEL ENABLE */ +/*************************************************/ +#define SMI130_LEVEL_LOW (0x00) +#define SMI130_LEVEL_HIGH (0x01) +/**************************************************/ +/**\name INTERRUPT OUTPUT ENABLE */ +/*************************************************/ +#define SMI130_OPEN_DRAIN (0x01) +#define SMI130_PUSH_PULL (0x00) + +/* interrupt output enable*/ +#define SMI130_INPUT (0x01) +#define SMI130_OUTPUT (0x00) + +/**************************************************/ +/**\name INTERRUPT TAP SOURCE ENABLE */ +/*************************************************/ +#define FILTER_DATA (0x00) +#define UNFILTER_DATA (0x01) +/**************************************************/ +/**\name SLOW MOTION/ NO MOTION SELECT */ +/*************************************************/ +#define SLOW_MOTION (0x00) +#define NO_MOTION (0x01) +/**************************************************/ +/**\name SIGNIFICANT MOTION SELECTION */ +/*************************************************/ +#define ANY_MOTION (0x00) +#define SIGNIFICANT_MOTION (0x01) +/**************************************************/ +/**\name LATCH DURATION */ +/*************************************************/ +#define SMI130_LATCH_DUR_NONE (0x00) +#define SMI130_LATCH_DUR_312_5_MICRO_SEC (0x01) +#define SMI130_LATCH_DUR_625_MICRO_SEC (0x02) +#define SMI130_LATCH_DUR_1_25_MILLI_SEC (0x03) +#define SMI130_LATCH_DUR_2_5_MILLI_SEC (0x04) +#define SMI130_LATCH_DUR_5_MILLI_SEC (0x05) +#define SMI130_LATCH_DUR_10_MILLI_SEC (0x06) +#define SMI130_LATCH_DUR_20_MILLI_SEC (0x07) +#define SMI130_LATCH_DUR_40_MILLI_SEC (0x08) +#define SMI130_LATCH_DUR_80_MILLI_SEC (0x09) +#define SMI130_LATCH_DUR_160_MILLI_SEC (0x0A) +#define SMI130_LATCH_DUR_320_MILLI_SEC (0x0B) +#define SMI130_LATCH_DUR_640_MILLI_SEC (0x0C) +#define SMI130_LATCH_DUR_1_28_SEC (0x0D) +#define SMI130_LATCH_DUR_2_56_SEC (0x0E) +#define SMI130_LATCHED (0x0F) +/**************************************************/ +/**\name GYRO OFFSET MASK DEFINITION */ +/*************************************************/ +#define SMI130_GYRO_MANUAL_OFFSET_0_7 (0x00FF) +#define SMI130_GYRO_MANUAL_OFFSET_8_9 (0x0300) +/**************************************************/ +/**\name STEP CONFIGURATION MASK DEFINITION */ +/*************************************************/ +#define SMI130_STEP_CONFIG_0_7 (0x00FF) +#define SMI130_STEP_CONFIG_8_10 (0x0700) +#define SMI130_STEP_CONFIG_11_14 (0xF000) +/**************************************************/ +/**\name DEFINITION USED FOR DIFFERENT WRITE */ +/*************************************************/ +#define SMI130_WRITE_TARGET_PAGE0 (0x00) +#define SMI130_WRITE_TARGET_PAGE1 (0x01) +#define SMI130_WRITE_ENABLE_PAGE1 (0x01) +#define SMI130_MANUAL_DISABLE (0x00) +#define SMI130_MANUAL_ENABLE (0x01) +#define SMI130_YAS_DISABLE_RCOIL (0x00) +#define SMI130_ENABLE_MAG_IF_MODE (0x02) +#define SMI130_ENABLE_ANY_MOTION_INTR1 (0x04) +#define SMI130_ENABLE_ANY_MOTION_INTR2 (0x04) +#define SMI130_MAG_DATA_READ_REG (0x04) +#define SMI130_BMM_POWER_MODE_REG (0x06) +#define SMI130_ENABLE_ANY_MOTION_AXIS (0x07) +#define SMI130_ENABLE_LOW_G (0x08) +#define SMI130_YAS532_ACQ_START (0x11) +#define SMI130_YAS_DEVICE_ID_REG (0x80) +#define SMI130_FIFO_GYRO_ENABLE (0x80) +#define SMI130_SIG_MOTION_INTR_ENABLE (0x01) +#define SMI130_STEP_DETECT_INTR_ENABLE (0x01) +#define SMI130_LOW_G_INTR_STAT (0x01) +#define SMI130_PULL_UP_DATA (0x30) +#define SMI130_FIFO_M_G_A_ENABLE (0xE0) +#define SMI130_FIFO_M_G_ENABLE (0xA0) +#define SMI130_FIFO_M_A_ENABLE (0x60) +#define SMI130_FIFO_G_A_ENABLE (0xC0) +#define SMI130_FIFO_A_ENABLE (0x40) +#define SMI130_FIFO_M_ENABLE (0x20) +/**************************************************/ +/**\name MAG INIT DEFINITION */ +/*************************************************/ +#define SMI130_COMMAND_REG_ONE (0x37) +#define SMI130_COMMAND_REG_TWO (0x9A) +#define SMI130_COMMAND_REG_THREE (0xC0) +#define RESET_STEP_COUNTER (0xB2) +/**************************************************/ +/**\name BIT SLICE GET AND SET FUNCTIONS */ +/*************************************************/ +#define SMI130_GET_BITSLICE(regvar, bitname)\ + ((regvar & bitname##__MSK) >> bitname##__POS) + + +#define SMI130_SET_BITSLICE(regvar, bitname, val)\ + ((regvar & ~bitname##__MSK) | \ + ((val<<bitname##__POS)&bitname##__MSK)) + +/**************************************************/ +/**\name FUNCTION DECLARATIONS */ +/*************************************************/ +/**************************************************/ +/**\name FUNCTION FOR SMI130 INITIALIZE */ +/*************************************************/ +/*! + * @brief + * This function is used for initialize + * bus read and bus write functions + * assign the chip id and device address + * chip id is read in the register 0x00 bit from 0 to 7 + * + * @param smi130 : structure pointer + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * @note + * While changing the parameter of the smi130_t + * consider the following point: + * Changing the reference value of the parameter + * will changes the local copy or local reference + * make sure your changes will not + * affect the reference value of the parameter + * (Better case don't change the reference value of the parameter) + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_init(struct smi130_t *smi130); +/**************************************************/ +/**\name FUNCTION FOR READ AND WRITE REGISTERS */ +/*************************************************/ +/*! + * @brief + * This API write the data to + * the given register + * + * + * @param v_addr_u8 -> Address of the register + * @param v_data_u8 -> The data from the register + * @param v_len_u8 -> no of bytes to read + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_write_reg(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8); +/*! + * @brief + * This API reads the data from + * the given register + * + * + * @param v_addr_u8 -> Address of the register + * @param v_data_u8 -> The data from the register + * @param v_len_u8 -> no of bytes to read + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_read_reg(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8); +/**************************************************/ +/**\name FUNCTION FOR ERROR CODES */ +/*************************************************/ +/*! + * @brief This API used to reads the fatal error + * from the Register 0x02 bit 0 + * This flag will be reset only by power-on-reset and soft reset + * + * + * @param v_fatal_err_u8 : The status of fatal error + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fatal_err(u8 +*v_fatal_err_u8); +/*! + * @brief This API used to read the error code + * from register 0x02 bit 1 to 4 + * + * + * @param v_err_code_u8 : The status of error codes + * error_code | description + * ------------|--------------- + * 0x00 |no error + * 0x01 |ACC_CONF error (accel ODR and bandwidth not compatible) + * 0x02 |GYR_CONF error (Gyroscope ODR and bandwidth not compatible) + * 0x03 |Under sampling mode and interrupt uses pre filtered data + * 0x04 |reserved + * 0x05 |Selected trigger-readout offset in + * - |MAG_IF greater than selected ODR + * 0x06 |FIFO configuration error for header less mode + * 0x07 |Under sampling mode and pre filtered data as FIFO source + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_err_code(u8 +*v_error_code_u8); +/*! + * @brief This API Reads the i2c error code from the + * Register 0x02 bit 5. + * This error occurred in I2C master detected + * + * @param v_i2c_err_code_u8 : The status of i2c fail error + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_fail_err(u8 +*v_i2c_error_code_u8); + /*! + * @brief This API Reads the dropped command error + * from the register 0x02 bit 6 + * + * + * @param v_drop_cmd_err_u8 : The status of drop command error + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_drop_cmd_err(u8 +*v_drop_cmd_err_u8); +/*! + * @brief This API reads the magnetometer data ready + * interrupt not active. + * It reads from the error register 0x0x2 bit 7 + * + * + * + * + * @param v_mag_data_rdy_err_u8 : The status of mag data ready interrupt + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_dada_rdy_err(u8 +*v_mag_data_rdy_err_u8); +/*! + * @brief This API reads the error status + * from the error register 0x02 bit 0 to 7 + * + * @param v_mag_data_rdy_err_u8 : The status of mag data ready interrupt + * @param v_fatal_er_u8r : The status of fatal error + * @param v_err_code_u8 : The status of error code + * @param v_i2c_fail_err_u8 : The status of I2C fail error + * @param v_drop_cmd_err_u8 : The status of drop command error + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_error_status(u8 *v_fatal_er_u8r, +u8 *v_err_code_u8, u8 *v_i2c_fail_err_u8, +u8 *v_drop_cmd_err_u8, u8 *v_mag_data_rdy_err_u8); +/******************************************************************/ +/**\name FUNCTIONS FOR MAG,ACCEL AND GYRO POWER MODE STATUS */ +/*****************************************************************/ +/*! + * @brief This API reads the magnetometer power mode from + * PMU status register 0x03 bit 0 and 1 + * + * @param v_mag_power_mode_stat_u8 : The value of mag power mode + * mag_powermode | value + * ------------------|---------- + * SUSPEND | 0x00 + * NORMAL | 0x01 + * LOW POWER | 0x02 + * + * + * @note The power mode of mag set by the 0x7E command register + * @note using the function "smi130_set_command_register()" + * value | mode + * ---------|---------------- + * 0x18 | MAG_MODE_SUSPEND + * 0x19 | MAG_MODE_NORMAL + * 0x1A | MAG_MODE_LOWPOWER + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_power_mode_stat(u8 +*v_mag_power_mode_stat_u8); +/*! + * @brief This API reads the gyroscope power mode from + * PMU status register 0x03 bit 2 and 3 + * + * @param v_gyro_power_mode_stat_u8 : The value of gyro power mode + * gyro_powermode | value + * ------------------|---------- + * SUSPEND | 0x00 + * NORMAL | 0x01 + * FAST POWER UP | 0x03 + * + * @note The power mode of gyro set by the 0x7E command register + * @note using the function "smi130_set_command_register()" + * value | mode + * ---------|---------------- + * 0x14 | GYRO_MODE_SUSPEND + * 0x15 | GYRO_MODE_NORMAL + * 0x17 | GYRO_MODE_FASTSTARTUP + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_power_mode_stat(u8 +*v_gyro_power_mode_stat_u8); +/*! + * @brief This API reads the accelerometer power mode from + * PMU status register 0x03 bit 4 and 5 + * + * + * @param v_accel_power_mode_stat_u8 : The value of accel power mode + * accel_powermode | value + * ------------------|---------- + * SUSPEND | 0x00 + * NORMAL | 0x01 + * LOW POWER | 0x03 + * + * @note The power mode of accel set by the 0x7E command register + * @note using the function "smi130_set_command_register()" + * value | mode + * ---------|---------------- + * 0x11 | ACCEL_MODE_NORMAL + * 0x12 | ACCEL_LOWPOWER + * 0x10 | ACCEL_SUSPEND + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_power_mode_stat(u8 +*v_accel_power_mode_stat_u8); +/*! + * @brief This API switch mag interface to normal mode + * and confirm whether the mode switching done successfully or not +* + * @return results of bus communication function and current MAG_PMU result + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_interface_normal(void); +/**************************************************/ +/**\name FUNCTION FOR Mag XYZ data read */ +/*************************************************/ +/*! + * @brief This API reads magnetometer data X values + * from the register 0x04 and 0x05 + * @brief The mag sensor data read form auxiliary mag + * + * @param v_mag_x_s16 : The value of mag x + * @param v_sensor_select_u8 : Mag selection value + * value | sensor + * ---------|---------------- + * 0 | BMM150 + * 1 | AKM09911 or AKM09912 + * + * @note For mag data output rate configuration use the following function + * @note smi130_set_mag_output_data_rate() + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_x(s16 *v_mag_x_s16, +u8 v_sensor_select_u8); +/*! + * @brief This API reads magnetometer data Y values + * from the register 0x06 and 0x07 + * @brief The mag sensor data read form auxiliary mag + * + * @param v_mag_y_s16 : The value of mag y + * @param v_sensor_select_u8 : Mag selection value + * value | sensor + * ---------|---------------- + * 0 | BMM150 + * 1 | AKM09911 or AKM09912 + * + * @note For mag data output rate configuration use the following function + * @note smi130_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_y(s16 *v_mag_y_s16, +u8 v_sensor_select_u8); +/*! + * @brief This API reads magnetometer data Z values + * from the register 0x08 and 0x09 + * @brief The mag sensor data read form auxiliary mag + * + * @param v_mag_z_s16 : The value of mag z + * @param v_sensor_select_u8 : Mag selection value + * value | sensor + * ---------|---------------- + * 0 | BMM150 + * 1 | AKM09911 or AKM09912 + * + * @note For mag data output rate configuration use the following function + * @note smi130_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_z(s16 *v_mag_z_s16, +u8 v_sensor_select_u8); +/*! + * @brief This API reads magnetometer data RHALL values + * from the register 0x0A and 0x0B + * + * + * @param v_mag_r_s16 : The value of BMM150 r data + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_r( +s16 *v_mag_r_s16); +/*! + * @brief This API reads magnetometer data X,Y,Z values + * from the register 0x04 to 0x09 + * + * @brief The mag sensor data read form auxiliary mag + * + * @param mag : The value of mag xyz data + * @param v_sensor_select_u8 : Mag selection value + * value | sensor + * ---------|---------------- + * 0 | BMM150 + * 1 | AKM09911 or AKM09912 + * + * @note For mag data output rate configuration use the following function + * @note smi130_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_xyz( +struct smi130_mag_t *mag, u8 v_sensor_select_u8); + /*!* + * @brief This API reads magnetometer data X,Y,Z,r + * values from the register 0x04 to 0x0B + * + * @brief The mag sensor data read form auxiliary mag + * + * @param mag : The value of mag-BMM150 xyzr data + * + * @note For mag data output rate configuration use the following function + * @note smi130_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_mag_xyzr( +struct smi130_mag_xyzr_t *mag); +/**************************************************/ +/**\name FUNCTION FOR GYRO XYZ DATA READ */ +/*************************************************/ +/*! + * @brief This API reads gyro data X values + * form the register 0x0C and 0x0D + * + * + * + * + * @param v_gyro_x_s16 : The value of gyro x data + * + * @note Gyro Configuration use the following function + * @note smi130_set_gyro_output_data_rate() + * @note smi130_set_gyro_bw() + * @note smi130_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_x( +s16 *v_gyro_x_s16); +/*! + * @brief This API reads gyro data Y values + * form the register 0x0E and 0x0F + * + * + * + * + * @param v_gyro_y_s16 : The value of gyro y data + * + * @note Gyro Configuration use the following function + * @note smi130_set_gyro_output_data_rate() + * @note smi130_set_gyro_bw() + * @note smi130_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error result of communication routines + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_y( +s16 *v_gyro_y_s16); +/*! + * @brief This API reads gyro data Z values + * form the register 0x10 and 0x11 + * + * + * + * + * @param v_gyro_z_s16 : The value of gyro z data + * + * @note Gyro Configuration use the following function + * @note smi130_set_gyro_output_data_rate() + * @note smi130_set_gyro_bw() + * @note smi130_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_z( +s16 *v_gyro_z_s16); +/*! + * @brief This API reads gyro data X,Y,Z values + * from the register 0x0C to 0x11 + * + * + * + * + * @param gyro : The value of gyro xyz + * + * @note Gyro Configuration use the following function + * @note smi130_set_gyro_output_data_rate() + * @note smi130_set_gyro_bw() + * @note smi130_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_gyro_xyz( +struct smi130_gyro_t *gyro); +/**************************************************/ +/**\name FUNCTION FOR ACCEL XYZ DATA READ */ +/*************************************************/ +/*! + * @brief This API reads accelerometer data X values + * form the register 0x12 and 0x13 + * + * + * + * + * @param v_accel_x_s16 : The value of accel x + * + * @note For accel configuration use the following functions + * @note smi130_set_accel_output_data_rate() + * @note smi130_set_accel_bw() + * @note smi130_set_accel_under_sampling_parameter() + * @note smi130_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_x( +s16 *v_accel_x_s16); +/*! + * @brief This API reads accelerometer data Y values + * form the register 0x14 and 0x15 + * + * + * + * + * @param v_accel_y_s16 : The value of accel y + * + * @note For accel configuration use the following functions + * @note smi130_set_accel_output_data_rate() + * @note smi130_set_accel_bw() + * @note smi130_set_accel_under_sampling_parameter() + * @note smi130_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_y( +s16 *v_accel_y_s16); +/*! + * @brief This API reads accelerometer data Z values + * form the register 0x16 and 0x17 + * + * + * + * + * @param v_accel_z_s16 : The value of accel z + * + * @note For accel configuration use the following functions + * @note smi130_set_accel_output_data_rate() + * @note smi130_set_accel_bw() + * @note smi130_set_accel_under_sampling_parameter() + * @note smi130_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_z( +s16 *v_accel_z_s16); +/*! + * @brief This API reads accelerometer data X,Y,Z values + * from the register 0x12 to 0x17 + * + * + * + * + * @param accel :The value of accel xyz + * + * @note For accel configuration use the following functions + * @note smi130_set_accel_output_data_rate() + * @note smi130_set_accel_bw() + * @note smi130_set_accel_under_sampling_parameter() + * @note smi130_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_accel_xyz( +struct smi130_accel_t *accel); +/**************************************************/ +/**\name FUNCTION FOR SENSOR TIME */ +/*************************************************/ +/*! + * @brief This API reads sensor_time from the register + * 0x18 to 0x1A + * + * + * @param v_sensor_time_u32 : The value of sensor time + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_sensor_time( +u32 *v_sensor_time_u32); +/**************************************************/ +/**\name FUNCTION FOR GYRO SLEF TEST */ +/*************************************************/ +/*! + * @brief This API reads the Gyroscope self test + * status from the register 0x1B bit 1 + * + * + * @param v_gyro_selftest_u8 : The value of gyro self test status + * value | status + * ---------|---------------- + * 0 | Gyroscope self test is running or failed + * 1 | Gyroscope self test completed successfully + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_selftest(u8 +*v_gyro_selftest_u8); +/**************************************************/ +/**\name FUNCTION FOR MANUAL INTERFACE */ +/*************************************************/ +/*! + * @brief This API reads the status of + * mag manual interface operation form the register 0x1B bit 2 + * + * + * + * @param v_mag_manual_stat_u8 : The value of mag manual operation status + * value | status + * ---------|---------------- + * 0 | Indicates no manual magnetometer + * - | interface operation is ongoing + * 1 | Indicates manual magnetometer + * - | interface operation is ongoing + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_manual_operation_stat(u8 +*v_mag_manual_stat_u8); +/**************************************************/ +/**\name FUNCTION FOR FAST OFFSET READY */ +/*************************************************/ +/*! + * @brief This API reads the fast offset compensation + * status form the register 0x1B bit 3 + * + * + * @param v_foc_rdy_u8 : The status of fast compensation + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_rdy(u8 +*v_foc_rdy_u8); +/**************************************************/ +/**\name FUNCTION FOR NVM READY */ +/*************************************************/ +/*! + * @brief This API Reads the nvm_rdy status from the + * resister 0x1B bit 4 + * + * + * @param v_nvm_rdy_u8 : The value of NVM ready status + * value | status + * ---------|---------------- + * 0 | NVM write operation in progress + * 1 | NVM is ready to accept a new write trigger + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_nvm_rdy(u8 +*v_nvm_rdy_u8); +/**************************************************/ +/**\name FUNCTION FOR DATA READY FOR MAG, GYRO, AND ACCEL */ +/*************************************************/ +/*! + * @brief This API reads the status of mag data ready + * from the register 0x1B bit 5 + * The status get reset when one mag data register is read out + * + * @param v_data_rdy_u8 : The value of mag data ready status + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_data_rdy_mag(u8 +*v_data_rdy_u8); +/*! + * @brief This API reads the status of gyro data ready form the + * register 0x1B bit 6 + * The status get reset when gyro data register read out + * + * + * @param v_data_rdy_u8 : The value of gyro data ready + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_data_rdy(u8 +*v_data_rdy_u8); +/*! + * @brief This API reads the status of accel data ready form the + * register 0x1B bit 7 + * The status get reset when accel data register read out + * + * + * @param v_data_rdy_u8 : The value of accel data ready status + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_data_rdy(u8 +*drdy_acc); +/**************************************************/ +/**\name FUNCTION FOR STEP INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads the step detector interrupt status + * from the register 0x1C bit 0 + * flag is associated with a specific interrupt function. + * It is set when the single tab interrupt triggers. The + * setting of INT_LATCH controls if the interrupt + * signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_step_intr_u8 : The status of step detector interrupt + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_step_intr(u8 +*v_step_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR SIGNIFICANT INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads the + * significant motion interrupt status + * from the register 0x1C bit 1 + * flag is associated with a specific interrupt function. + * It is set when the single tab interrupt triggers. The + * setting of INT_LATCH controls if the interrupt + * signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * + * @param v_significant_intr_u8 : The status of step + * motion interrupt + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_significant_intr(u8 +*sigmot_intr); +/**************************************************/ +/**\name FUNCTION FOR ANY MOTION INTERRUPT STATUS */ +/*************************************************/ + /*! + * @brief This API reads the any motion interrupt status + * from the register 0x1C bit 2 + * flag is associated with a specific interrupt function. + * It is set when the single tab interrupt triggers. The + * setting of INT_LATCH controls if the interrupt + * signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * @param v_any_motion_intr_u8 : The status of any-motion interrupt + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_any_motion_intr(u8 +*v_any_motion_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR PMU TRIGGER INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads the power mode trigger interrupt status + * from the register 0x1C bit 3 + * flag is associated with a specific interrupt function. + * It is set when the single tab interrupt triggers. The + * setting of INT_LATCH controls if the interrupt + * signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * + * @param v_pmu_trigger_intr_u8 : The status of power mode trigger interrupt + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_pmu_trigger_intr(u8 +*v_pmu_trigger_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR DOUBLE TAB STATUS */ +/*************************************************/ +/*! + * @brief This API reads the double tab status + * from the register 0x1C bit 4 + * flag is associated with a specific interrupt function. + * It is set when the single tab interrupt triggers. The + * setting of INT_LATCH controls if the interrupt + * signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_double_tap_intr_u8 :The status of double tab interrupt + * + * @note Double tap interrupt can be configured by the following functions + * @note INTERRUPT MAPPING + * @note smi130_set_intr_double_tap() + * @note AXIS MAPPING + * @note smi130_get_stat2_tap_first_x() + * @note smi130_get_stat2_tap_first_y() + * @note smi130_get_stat2_tap_first_z() + * @note DURATION + * @note smi130_set_intr_tap_durn() + * @note THRESHOLD + * @note smi130_set_intr_tap_thres() + * @note TAP QUIET + * @note smi130_set_intr_tap_quiet() + * @note TAP SHOCK + * @note smi130_set_intr_tap_shock() + * @note TAP SOURCE + * @note smi130_set_intr_tap_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_double_tap_intr(u8 +*v_double_tap_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR SINGLE TAB STATUS */ +/*************************************************/ +/*! + * @brief This API reads the single tab status + * from the register 0x1C bit 5 + * flag is associated with a specific interrupt function. + * It is set when the single tab interrupt triggers. The + * setting of INT_LATCH controls if the interrupt + * signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_single_tap_intr_u8 :The status of single tap interrupt + * + * @note Single tap interrupt can be configured by the following functions + * @note INTERRUPT MAPPING + * @note smi130_set_intr_single_tap() + * @note AXIS MAPPING + * @note smi130_get_stat2_tap_first_x() + * @note smi130_get_stat2_tap_first_y() + * @note smi130_get_stat2_tap_first_z() + * @note DURATION + * @note smi130_set_intr_tap_durn() + * @note THRESHOLD + * @note smi130_set_intr_tap_thres() + * @note TAP QUIET + * @note smi130_set_intr_tap_quiet() + * @note TAP SHOCK + * @note smi130_set_intr_tap_shock() + * @note TAP SOURCE + * @note smi130_set_intr_tap_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_single_tap_intr(u8 +*v_single_tap_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR ORIENT INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads the orient status + * from the register 0x1C bit 6 + * flag is associated with a specific interrupt function. + * It is set when the orient interrupt triggers. The + * setting of INT_LATCH controls if the + * interrupt signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_orient_intr_u8 : The status of orient interrupt + * + * @note For orient interrupt configuration use the following functions + * @note STATUS + * @note smi130_get_stat0_orient_intr() + * @note AXIS MAPPING + * @note smi130_get_stat3_orient_xy() + * @note smi130_get_stat3_orient_z() + * @note smi130_set_intr_orient_axes_enable() + * @note INTERRUPT MAPPING + * @note smi130_set_intr_orient() + * @note INTERRUPT OUTPUT + * @note smi130_set_intr_orient_ud_enable() + * @note THETA + * @note smi130_set_intr_orient_theta() + * @note HYSTERESIS + * @note smi130_set_intr_orient_hyst() + * @note BLOCKING + * @note smi130_set_intr_orient_blocking() + * @note MODE + * @note smi130_set_intr_orient_mode() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_orient_intr(u8 +*v_orient_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR FLAT INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads the flat interrupt status + * from the register 0x1C bit 7 + * flag is associated with a specific interrupt function. + * It is set when the flat interrupt triggers. The + * setting of INT_LATCH controls if the + * interrupt signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_flat_intr_u8 : The status of flat interrupt + * + * @note For flat configuration use the following functions + * @note STATS + * @note smi130_get_stat0_flat_intr() + * @note smi130_get_stat3_flat() + * @note INTERRUPT MAPPING + * @note smi130_set_intr_flat() + * @note THETA + * @note smi130_set_intr_flat_theta() + * @note HOLD TIME + * @note smi130_set_intr_flat_hold() + * @note HYSTERESIS + * @note smi130_set_intr_flat_hyst() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat0_flat_intr(u8 +*v_flat_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR HIGH_G INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads the high_g interrupt status + * from the register 0x1D bit 2 + * flag is associated with a specific interrupt function. + * It is set when the high g interrupt triggers. The + * setting of INT_LATCH controls if the interrupt signal and hence the + * respective interrupt flag will be permanently + * latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_high_g_intr_u8 : The status of high_g interrupt + * + * @note High_g interrupt configured by following functions + * @note STATUS + * @note smi130_get_stat1_high_g_intr() + * @note AXIS MAPPING + * @note smi130_get_stat3_high_g_first_x() + * @note smi130_get_stat3_high_g_first_y() + * @note smi130_get_stat3_high_g_first_z() + * @note SIGN MAPPING + * @note smi130_get_stat3_high_g_first_sign() + * @note INTERRUPT MAPPING + * @note smi130_set_intr_high_g() + * @note HYSTERESIS + * @note smi130_set_intr_high_g_hyst() + * @note DURATION + * @note smi130_set_intr_high_g_durn() + * @note THRESHOLD + * @note smi130_set_intr_high_g_thres() + * @note SOURCE + * @note smi130_set_intr_low_high_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_high_g_intr(u8 +*v_high_g_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR LOW_G INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads the low g interrupt status + * from the register 0x1D bit 3 + * flag is associated with a specific interrupt function. + * It is set when the low g interrupt triggers. The + * setting of INT_LATCH controls if the interrupt signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_low_g_intr_u8 : The status of low_g interrupt + * + * @note Low_g interrupt configured by following functions + * @note STATUS + * @note smi130_get_stat1_low_g_intr() + * @note INTERRUPT MAPPING + * @note smi130_set_intr_low_g() + * @note SOURCE + * @note smi130_set_intr_low_high_source() + * @note DURATION + * @note smi130_set_intr_low_g_durn() + * @note THRESHOLD + * @note smi130_set_intr_low_g_thres() + * @note HYSTERESIS + * @note smi130_set_intr_low_g_hyst() + * @note MODE + * @note smi130_set_intr_low_g_mode() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_low_g_intr(u8 +*v_low_g_intr_u8); +/**************************************************/ +/**\name FUNCTION FOR DATA READY INTERRUPT STATUS */ +/*************************************************/ +/*! + * @brief This API reads data ready interrupt status + * from the register 0x1D bit 4 + * flag is associated with a specific interrupt function. + * It is set when the data ready interrupt triggers. The + * setting of INT_LATCH controls if the interrupt signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_data_rdy_intr_u8 : The status of data ready interrupt + * + * @note Data ready interrupt configured by following functions + * @note STATUS + * @note smi130_get_stat1_data_rdy_intr() + * @note INTERRUPT MAPPING + * @note smi130_set_intr_data_rdy() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_data_rdy_intr(u8 +*v_data_rdy_intr_u8); +/**************************************************/ +/**\name FUNCTIONS FOR FIFO FULL AND WATER MARK INTERRUPT STATUS*/ +/*************************************************/ +/*! + * @brief This API reads data ready FIFO full interrupt status + * from the register 0x1D bit 5 + * flag is associated with a specific interrupt function. + * It is set when the FIFO full interrupt triggers. The + * setting of INT_LATCH controls if the + * interrupt signal and hence the + * respective interrupt flag will + * be permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_fifo_full_intr_u8 : The status of fifo full interrupt + * + * @note FIFO full interrupt can be configured by following functions + * @note smi130_set_intr_fifo_full() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_fifo_full_intr(u8 +*v_fifo_full_intr_u8); +/*! + * @brief This API reads data + * ready FIFO watermark interrupt status + * from the register 0x1D bit 6 + * flag is associated with a specific interrupt function. + * It is set when the FIFO watermark interrupt triggers. The + * setting of INT_LATCH controls if the + * interrupt signal and hence the + * respective interrupt flag will be + * permanently latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_fifo_wm_intr_u8 : The status of fifo water mark interrupt + * + * @note FIFO full interrupt can be configured by following functions + * @note smi130_set_intr_fifo_wm() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_fifo_wm_intr(u8 +*v_fifo_wm_intr_u8); +/**************************************************/ +/**\name FUNCTIONS FOR NO MOTION INTERRUPT STATUS*/ +/*************************************************/ +/*! + * @brief This API reads data ready no motion interrupt status + * from the register 0x1D bit 7 + * flag is associated with a specific interrupt function. + * It is set when the no motion interrupt triggers. The + * setting of INT_LATCH controls if the interrupt signal and hence the + * respective interrupt flag will be permanently + * latched, temporarily latched + * or not latched. + * + * + * + * + * @param v_nomotion_intr_u8 : The status of no motion interrupt + * + * @note No motion interrupt can be configured by following function + * @note STATUS + * @note smi130_get_stat1_nomotion_intr() + * @note INTERRUPT MAPPING + * @note smi130_set_intr_nomotion() + * @note DURATION + * @note smi130_set_intr_slow_no_motion_durn() + * @note THRESHOLD + * @note smi130_set_intr_slow_no_motion_thres() + * @note SLOW/NO MOTION SELECT + * @note smi130_set_intr_slow_no_motion_select() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat1_nomotion_intr(u8 +*nomo_intr); +/**************************************************/ +/**\name FUNCTIONS FOR ANY MOTION FIRST XYZ AND SIGN INTERRUPT STATUS*/ +/*************************************************/ +/*! + * @brief This API reads the status of any motion first x + * from the register 0x1E bit 0 + * + * + * @param v_anymotion_first_x_u8 : The status of any motion first x interrupt + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by x axis + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_first_x(u8 +*v_anymotion_first_x_u8); +/*! + * @brief This API reads the status of any motion first y interrupt + * from the register 0x1E bit 1 + * + * + * + *@param v_any_motion_first_y_u8 : The status of any motion first y interrupt + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_first_y(u8 +*v_any_motion_first_y_u8); +/*! + * @brief This API reads the status of any motion first z interrupt + * from the register 0x1E bit 2 + * + * + * + * + *@param v_any_motion_first_z_u8 : The status of any motion first z interrupt + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_first_z(u8 +*v_any_motion_first_z_u8); +/*! + * @brief This API reads the any motion sign status from the + * register 0x1E bit 3 + * + * + * + * + * @param v_anymotion_sign_u8 : The status of any motion sign + * value | sign + * -----------|------------- + * 0 | positive + * 1 | negative + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_any_motion_sign(u8 +*v_anymotion_sign_u8); +/**************************************************/ +/**\name FUNCTIONS FOR TAP FIRST XYZ AND SIGN INTERRUPT STATUS*/ +/*************************************************/ +/*! + * @brief This API reads the any motion tap first x status from the + * register 0x1E bit 4 + * + * + * + * + * @param v_tap_first_x_u8 :The status of any motion tap first x + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by x axis + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_first_x(u8 +*v_tap_first_x_u8); +/*! + * @brief This API reads the tap first y interrupt status from the + * register 0x1E bit 5 + * + * + * + * + * @param v_tap_first_y_u8 :The status of tap first y interrupt + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_first_y(u8 +*v_tap_first_y_u8); +/*! + * @brief This API reads the tap first z interrupt status from the + * register 0x1E bit 6 + * + * + * + * + * @param v_tap_first_z_u8 :The status of tap first z interrupt + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by z axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_first_z(u8 +*v_tap_first_z_u8); +/*! + * @brief This API reads the tap sign status from the + * register 0x1E bit 7 + * + * + * + * + * @param v_tap_sign_u8 : The status of tap sign + * value | sign + * -----------|------------- + * 0 | positive + * 1 | negative + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat2_tap_sign(u8 +*tap_sign); +/**************************************************/ +/**\name FUNCTIONS FOR HIGH_G FIRST XYZ AND SIGN INTERRUPT STATUS*/ +/*************************************************/ +/*! + * @brief This API reads the high_g first x status from the + * register 0x1F bit 0 + * + * + * + * + * @param v_high_g_first_x_u8 :The status of high_g first x + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by x axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_first_x(u8 +*v_high_g_first_x_u8); +/*! + * @brief This API reads the high_g first y status from the + * register 0x1F bit 1 + * + * + * + * + * @param v_high_g_first_y_u8 : The status of high_g first y + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_first_y(u8 +*v_high_g_first_y_u8); +/*! + * @brief This API reads the high_g first z status from the + * register 0x1F bit 3 + * + * + * + * + * @param v_high_g_first_z_u8 : The status of high_g first z + * value | status + * -----------|------------- + * 0 | not triggered + * 1 | triggered by z axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_first_z(u8 +*v_high_g_first_z_u8); +/*! + * @brief This API reads the high sign status from the + * register 0x1F bit 3 + * + * + * + * + * @param v_high_g_sign_u8 :The status of high sign + * value | sign + * -----------|------------- + * 0 | positive + * 1 | negative + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_high_g_sign(u8 +*v_high_g_sign_u8); +/**************************************************/ +/**\name FUNCTIONS FOR ORIENT XY AND Z INTERRUPT STATUS*/ +/*************************************************/ +/*! + * @brief This API reads the status of orient_xy plane + * from the register 0x1F bit 4 and 5 + * + * + * @param v_orient_xy_u8 :The status of orient_xy plane + * value | status + * -----------|------------- + * 0x00 | portrait upright + * 0x01 | portrait upside down + * 0x02 | landscape left + * 0x03 | landscape right + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_orient_xy(u8 +*v_orient_xy_u8); +/*! + * @brief This API reads the status of orient z plane + * from the register 0x1F bit 6 + * + * + * @param v_orient_z_u8 :The status of orient z + * value | status + * -----------|------------- + * 0x00 | upward looking + * 0x01 | downward looking + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_orient_z(u8 +*v_orient_z_u8); +/**************************************************/ +/**\name FUNCTIONS FOR FLAT INTERRUPT STATUS*/ +/*************************************************/ +/*! + * @brief This API reads the flat status from the register + * 0x1F bit 7 + * + * + * @param v_flat_u8 : The status of flat interrupt + * value | status + * -----------|------------- + * 0x00 | non flat + * 0x01 | flat position + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_stat3_flat(u8 +*flat); +/**************************************************/ +/**\name FUNCTION FOR TEMPERATUE READ */ +/*************************************************/ +/*! + * @brief This API reads the temperature of the sensor + * from the register 0x21 bit 0 to 7 + * + * + * + * @param v_temp_s16 : The value of temperature + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_temp(s16 +*v_temp_s16); +/**************************************************/ +/**\name FUNCTION FOR FIFO LENGTH AND FIFO DATA READ */ +/*************************************************/ +/*! + * @brief This API reads the of the sensor + * form the register 0x23 and 0x24 bit 0 to 7 and 0 to 2 + * @brief this byte counter is updated each time a complete frame + * was read or writtern + * + * + * @param v_fifo_length_u32 : The value of fifo byte counter + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_fifo_length( +u32 *v_fifo_length_u32); +/*! + * @brief This API reads the fifo data of the sensor + * from the register 0x24 + * @brief Data format depends on the setting of register FIFO_CONFIG + * + * + * + * @param v_fifodata_u8 : Pointer holding the fifo data + * + * @note For reading FIFO data use the following functions + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_fifo_data( +u8 *v_fifodata_u8, u16 v_fifo_length_u16); +/**************************************************/ +/**\name FUNCTION FOR ACCEL CONFIGURATIONS */ +/*************************************************/ +/*! + * @brief This API is used to get the + * accel output date rate form the register 0x40 bit 0 to 3 + * + * + * @param v_output_data_rate_u8 :The value of accel output date rate + * value | output data rate + * -------|-------------------------- + * 0 | SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED + * 1 | SMI130_ACCEL_OUTPUT_DATA_RATE_0_78HZ + * 2 | SMI130_ACCEL_OUTPUT_DATA_RATE_1_56HZ + * 3 | SMI130_ACCEL_OUTPUT_DATA_RATE_3_12HZ + * 4 | SMI130_ACCEL_OUTPUT_DATA_RATE_6_25HZ + * 5 | SMI130_ACCEL_OUTPUT_DATA_RATE_12_5HZ + * 6 | SMI130_ACCEL_OUTPUT_DATA_RATE_25HZ + * 7 | SMI130_ACCEL_OUTPUT_DATA_RATE_50HZ + * 8 | SMI130_ACCEL_OUTPUT_DATA_RATE_100HZ + * 9 | SMI130_ACCEL_OUTPUT_DATA_RATE_200HZ + * 10 | SMI130_ACCEL_OUTPUT_DATA_RATE_400HZ + * 11 | SMI130_ACCEL_OUTPUT_DATA_RATE_800HZ + * 12 | SMI130_ACCEL_OUTPUT_DATA_RATE_1600HZ + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_output_data_rate( +u8 *v_output_data_rate_u8); +/*! + * @brief This API is used to set the + * accel output date rate form the register 0x40 bit 0 to 3 + * + * + * @param v_output_data_rate_u8 :The value of accel output date rate + * value | output data rate + * -------|-------------------------- + * 0 | SMI130_ACCEL_OUTPUT_DATA_RATE_RESERVED + * 1 | SMI130_ACCEL_OUTPUT_DATA_RATE_0_78HZ + * 2 | SMI130_ACCEL_OUTPUT_DATA_RATE_1_56HZ + * 3 | SMI130_ACCEL_OUTPUT_DATA_RATE_3_12HZ + * 4 | SMI130_ACCEL_OUTPUT_DATA_RATE_6_25HZ + * 5 | SMI130_ACCEL_OUTPUT_DATA_RATE_12_5HZ + * 6 | SMI130_ACCEL_OUTPUT_DATA_RATE_25HZ + * 7 | SMI130_ACCEL_OUTPUT_DATA_RATE_50HZ + * 8 | SMI130_ACCEL_OUTPUT_DATA_RATE_100HZ + * 9 | SMI130_ACCEL_OUTPUT_DATA_RATE_200HZ + * 10 | SMI130_ACCEL_OUTPUT_DATA_RATE_400HZ + * 11 | SMI130_ACCEL_OUTPUT_DATA_RATE_800HZ + * 12 | SMI130_ACCEL_OUTPUT_DATA_RATE_1600HZ + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_output_data_rate(u8 odr); +/*! + * @brief This API is used to get the + * accel bandwidth from the register 0x40 bit 4 to 6 + * @brief bandwidth parameter determines filter configuration(acc_us=0) + * and averaging for under sampling mode(acc_us=1) + * + * + * @param v_bw_u8 : The value of accel bandwidth + * + * @note accel bandwidth depends on under sampling parameter + * @note under sampling parameter cab be set by the function + * "SMI130_SET_ACCEL_UNDER_SAMPLING_PARAMETER" + * + * @note Filter configuration + * accel_us | Filter configuration + * -----------|--------------------- + * 0x00 | OSR4 mode + * 0x01 | OSR2 mode + * 0x02 | normal mode + * 0x03 | CIC mode + * 0x04 | Reserved + * 0x05 | Reserved + * 0x06 | Reserved + * 0x07 | Reserved + * + * @note accel under sampling mode + * accel_us | Under sampling mode + * -----------|--------------------- + * 0x00 | no averaging + * 0x01 | average 2 samples + * 0x02 | average 4 samples + * 0x03 | average 8 samples + * 0x04 | average 16 samples + * 0x05 | average 32 samples + * 0x06 | average 64 samples + * 0x07 | average 128 samples + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_bw(u8 *v_bw_u8); +/*! + * @brief This API is used to set the + * accel bandwidth from the register 0x40 bit 4 to 6 + * @brief bandwidth parameter determines filter configuration(acc_us=0) + * and averaging for under sampling mode(acc_us=1) + * + * + * @param v_bw_u8 : The value of accel bandwidth + * + * @note accel bandwidth depends on under sampling parameter + * @note under sampling parameter cab be set by the function + * "SMI130_SET_ACCEL_UNDER_SAMPLING_PARAMETER" + * + * @note Filter configuration + * accel_us | Filter configuration + * -----------|--------------------- + * 0x00 | OSR4 mode + * 0x01 | OSR2 mode + * 0x02 | normal mode + * 0x03 | CIC mode + * 0x04 | Reserved + * 0x05 | Reserved + * 0x06 | Reserved + * 0x07 | Reserved + * + * @note accel under sampling mode + * accel_us | Under sampling mode + * -----------|--------------------- + * 0x00 | no averaging + * 0x01 | average 2 samples + * 0x02 | average 4 samples + * 0x03 | average 8 samples + * 0x04 | average 16 samples + * 0x05 | average 32 samples + * 0x06 | average 64 samples + * 0x07 | average 128 samples + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_bw(u8 v_bw_u8); +/*! + * @brief This API is used to get the accel + * under sampling parameter form the register 0x40 bit 7 + * + * + * + * + * @param v_accel_under_sampling_u8 : The value of accel under sampling + * value | under_sampling + * ----------|--------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_under_sampling_parameter( +u8 *v_accel_under_sampling_u8); +/*! + * @brief This API is used to set the accel + * under sampling parameter form the register 0x40 bit 7 + * + * + * + * + * @param v_accel_under_sampling_u8 : The value of accel under sampling + * value | under_sampling + * ----------|--------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_under_sampling_parameter( +u8 v_accel_under_sampling_u8); +/*! + * @brief This API is used to get the ranges + * (g values) of the accel from the register 0x41 bit 0 to 3 + * + * + * + * + * @param v_range_u8 : The value of accel g range + * value | g_range + * ----------|----------- + * 0x03 | SMI130_ACCEL_RANGE_2G + * 0x05 | SMI130_ACCEL_RANGE_4G + * 0x08 | SMI130_ACCEL_RANGE_8G + * 0x0C | SMI130_ACCEL_RANGE_16G + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_range( +u8 *v_range_u8); +/*! + * @brief This API is used to set the ranges + * (g values) of the accel from the register 0x41 bit 0 to 3 + * + * + * + * + * @param v_range_u8 : The value of accel g range + * value | g_range + * ----------|----------- + * 0x03 | SMI130_ACCEL_RANGE_2G + * 0x05 | SMI130_ACCEL_RANGE_4G + * 0x08 | SMI130_ACCEL_RANGE_8G + * 0x0C | SMI130_ACCEL_RANGE_16G + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_range( +u8 v_range_u8); +/**************************************************/ +/**\name FUNCTION FOR GYRO CONFIGURATIONS */ +/*************************************************/ +/*! + * @brief This API is used to get the + * gyroscope output data rate from the register 0x42 bit 0 to 3 + * + * + * + * + * @param v_output_data_rate_u8 :The value of gyro output data rate + * value | gyro output data rate + * -----------|----------------------------- + * 0x00 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x01 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x02 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x03 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x04 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x05 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x06 | SMI130_GYRO_OUTPUT_DATA_RATE_25HZ + * 0x07 | SMI130_GYRO_OUTPUT_DATA_RATE_50HZ + * 0x08 | SMI130_GYRO_OUTPUT_DATA_RATE_100HZ + * 0x09 | SMI130_GYRO_OUTPUT_DATA_RATE_200HZ + * 0x0A | SMI130_GYRO_OUTPUT_DATA_RATE_400HZ + * 0x0B | SMI130_GYRO_OUTPUT_DATA_RATE_800HZ + * 0x0C | SMI130_GYRO_OUTPUT_DATA_RATE_1600HZ + * 0x0D | SMI130_GYRO_OUTPUT_DATA_RATE_3200HZ + * 0x0E | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x0F | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_output_data_rate( +u8 *gyro_output_typer); +/*! + * @brief This API is used to set the + * gyroscope output data rate from the register 0x42 bit 0 to 3 + * + * + * + * + * @param v_output_data_rate_u8 :The value of gyro output data rate + * value | gyro output data rate + * -----------|----------------------------- + * 0x00 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x01 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x02 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x03 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x04 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x05 | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x06 | SMI130_GYRO_OUTPUT_DATA_RATE_25HZ + * 0x07 | SMI130_GYRO_OUTPUT_DATA_RATE_50HZ + * 0x08 | SMI130_GYRO_OUTPUT_DATA_RATE_100HZ + * 0x09 | SMI130_GYRO_OUTPUT_DATA_RATE_200HZ + * 0x0A | SMI130_GYRO_OUTPUT_DATA_RATE_400HZ + * 0x0B | SMI130_GYRO_OUTPUT_DATA_RATE_800HZ + * 0x0C | SMI130_GYRO_OUTPUT_DATA_RATE_1600HZ + * 0x0D | SMI130_GYRO_OUTPUT_DATA_RATE_3200HZ + * 0x0E | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x0F | SMI130_GYRO_OUTPUT_DATA_RATE_RESERVED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_output_data_rate( +u8 gyro_output_typer); +/*! + * @brief This API is used to get the + * data of gyro from the register 0x42 bit 4 to 5 + * + * + * + * + * @param v_bw_u8 : The value of gyro bandwidth + * value | gyro bandwidth + * ----------|---------------- + * 0x00 | SMI130_GYRO_OSR4_MODE + * 0x01 | SMI130_GYRO_OSR2_MODE + * 0x02 | SMI130_GYRO_NORMAL_MODE + * 0x03 | SMI130_GYRO_CIC_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_bw(u8 *v_bw_u8); +/*! + * @brief This API is used to set the + * data of gyro from the register 0x42 bit 4 to 5 + * + * + * + * + * @param v_bw_u8 : The value of gyro bandwidth + * value | gyro bandwidth + * ----------|---------------- + * 0x00 | SMI130_GYRO_OSR4_MODE + * 0x01 | SMI130_GYRO_OSR2_MODE + * 0x02 | SMI130_GYRO_NORMAL_MODE + * 0x03 | SMI130_GYRO_CIC_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_bw(u8 v_bw_u8); +/*! + * @brief This API reads the range + * of gyro from the register 0x43 bit 0 to 2 + * + * @param v_range_u8 : The value of gyro range + * value | range + * ----------|------------------------------- + * 0x00 | SMI130_GYRO_RANGE_2000_DEG_SEC + * 0x01 | SMI130_GYRO_RANGE_1000_DEG_SEC + * 0x02 | SMI130_GYRO_RANGE_500_DEG_SEC + * 0x03 | SMI130_GYRO_RANGE_250_DEG_SEC + * 0x04 | SMI130_GYRO_RANGE_125_DEG_SEC + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_range( +u8 *v_range_u8); +/*! + * @brief This API set the range + * of gyro from the register 0x43 bit 0 to 2 + * + * @param v_range_u8 : The value of gyro range + * value | range + * ----------|------------------------------- + * 0x00 | SMI130_GYRO_RANGE_2000_DEG_SEC + * 0x01 | SMI130_GYRO_RANGE_1000_DEG_SEC + * 0x02 | SMI130_GYRO_RANGE_500_DEG_SEC + * 0x03 | SMI130_GYRO_RANGE_250_DEG_SEC + * 0x04 | SMI130_GYRO_RANGE_125_DEG_SEC + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_range( +u8 v_range_u8); +/**************************************************/ +/**\name FUNCTION FOR MAG CONFIGURATIONS */ +/*************************************************/ +/*! + * @brief This API is used to get the + * output data rate of magnetometer from the register 0x44 bit 0 to 3 + * + * + * + * + * @param v_output_data_rat_u8e : The value of mag output data rate + * value | mag output data rate + * ---------|--------------------------- + * 0x00 |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED + * 0x01 |SMI130_MAG_OUTPUT_DATA_RATE_0_78HZ + * 0x02 |SMI130_MAG_OUTPUT_DATA_RATE_1_56HZ + * 0x03 |SMI130_MAG_OUTPUT_DATA_RATE_3_12HZ + * 0x04 |SMI130_MAG_OUTPUT_DATA_RATE_6_25HZ + * 0x05 |SMI130_MAG_OUTPUT_DATA_RATE_12_5HZ + * 0x06 |SMI130_MAG_OUTPUT_DATA_RATE_25HZ + * 0x07 |SMI130_MAG_OUTPUT_DATA_RATE_50HZ + * 0x08 |SMI130_MAG_OUTPUT_DATA_RATE_100HZ + * 0x09 |SMI130_MAG_OUTPUT_DATA_RATE_200HZ + * 0x0A |SMI130_MAG_OUTPUT_DATA_RATE_400HZ + * 0x0B |SMI130_MAG_OUTPUT_DATA_RATE_800HZ + * 0x0C |SMI130_MAG_OUTPUT_DATA_RATE_1600HZ + * 0x0D |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED0 + * 0x0E |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED1 + * 0x0F |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED2 + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_output_data_rate(u8 *odr); +/*! + * @brief This API is used to set the + * output data rate of magnetometer from the register 0x44 bit 0 to 3 + * + * + * + * + * @param v_output_data_rat_u8e : The value of mag output data rate + * value | mag output data rate + * ---------|--------------------------- + * 0x00 |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED + * 0x01 |SMI130_MAG_OUTPUT_DATA_RATE_0_78HZ + * 0x02 |SMI130_MAG_OUTPUT_DATA_RATE_1_56HZ + * 0x03 |SMI130_MAG_OUTPUT_DATA_RATE_3_12HZ + * 0x04 |SMI130_MAG_OUTPUT_DATA_RATE_6_25HZ + * 0x05 |SMI130_MAG_OUTPUT_DATA_RATE_12_5HZ + * 0x06 |SMI130_MAG_OUTPUT_DATA_RATE_25HZ + * 0x07 |SMI130_MAG_OUTPUT_DATA_RATE_50HZ + * 0x08 |SMI130_MAG_OUTPUT_DATA_RATE_100HZ + * 0x09 |SMI130_MAG_OUTPUT_DATA_RATE_200HZ + * 0x0A |SMI130_MAG_OUTPUT_DATA_RATE_400HZ + * 0x0B |SMI130_MAG_OUTPUT_DATA_RATE_800HZ + * 0x0C |SMI130_MAG_OUTPUT_DATA_RATE_1600HZ + * 0x0D |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED0 + * 0x0E |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED1 + * 0x0F |SMI130_MAG_OUTPUT_DATA_RATE_RESERVED2 + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_output_data_rate(u8 odr); +/**************************************************/ +/**\name FUNCTION FOR FIFO CONFIGURATIONS */ +/*************************************************/ + /*! + * @brief This API is used to read Down sampling + * for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2 + * + * + * + * + * @param v_fifo_down_gyro_u8 :The value of gyro fifo down + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_down_gyro( +u8 *v_fifo_down_gyro_u8); + /*! + * @brief This API is used to set Down sampling + * for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2 + * + * + * + * + * @param v_fifo_down_gyro_u8 :The value of gyro fifo down + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_down_gyro( +u8 v_fifo_down_gyro_u8); +/*! + * @brief This API is used to read gyro fifo filter data + * from the register 0x45 bit 3 + * + * + * + * @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data + * value | gyro_fifo_filter_data + * ------------|------------------------- + * 0x00 | Unfiltered data + * 0x01 | Filtered data + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_fifo_filter_data( +u8 *v_gyro_fifo_filter_data_u8); +/*! + * @brief This API is used to set gyro fifo filter data + * from the register 0x45 bit 3 + * + * + * + * @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data + * value | gyro_fifo_filter_data + * ------------|------------------------- + * 0x00 | Unfiltered data + * 0x01 | Filtered data + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_fifo_filter_data( +u8 v_gyro_fifo_filter_data_u8); +/*! + * @brief This API is used to read Down sampling + * for accel (2*downs_accel) from the register 0x45 bit 4 to 6 + * + * + * + * + * @param v_fifo_down_u8 :The value of accel fifo down + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_down_accel( +u8 *v_fifo_down_u8); + /*! + * @brief This API is used to set Down sampling + * for accel (2*downs_accel) from the register 0x45 bit 4 to 6 + * + * + * + * + * @param v_fifo_down_u8 :The value of accel fifo down + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_down_accel( +u8 v_fifo_down_u8); +/*! + * @brief This API is used to read accel fifo filter data + * from the register 0x45 bit 7 + * + * + * + * @param v_accel_fifo_filter_u8 :The value of accel filter data + * value | accel_fifo_filter_data + * ------------|------------------------- + * 0x00 | Unfiltered data + * 0x01 | Filtered data + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_fifo_filter_data( +u8 *v_accel_fifo_filter_u8); +/*! + * @brief This API is used to set accel fifo filter data + * from the register 0x45 bit 7 + * + * + * + * @param v_accel_fifo_filter_u8 :The value of accel filter data + * value | accel_fifo_filter_data + * ------------|------------------------- + * 0x00 | Unfiltered data + * 0x01 | Filtered data + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_fifo_filter_data( +u8 v_accel_fifo_filter_u8); +/**************************************************/ +/**\name FUNCTION FOR FIFO WATER MARK ENABLE */ +/*************************************************/ +/*! + * @brief This API is used to Trigger an interrupt + * when FIFO contains water mark level from the register 0x46 bit 0 to 7 + * + * + * + * @param v_fifo_wm_u8 : The value of fifo water mark level + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_wm( +u8 *v_fifo_wm_u8); +/*! + * @brief This API is used to Trigger an interrupt + * when FIFO contains water mark level from the register 0x46 bit 0 to 7 + * + * + * + * @param v_fifo_wm_u8 : The value of fifo water mark level + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_wm( +u8 v_fifo_wm_u8); +/**************************************************/ +/**\name FUNCTION FOR FIFO CONFIGURATIONS */ +/*************************************************/ +/*! + * @brief This API reads fifo sensor time + * frame after the last valid data frame form the register 0x47 bit 1 + * + * + * + * + * @param v_fifo_time_enable_u8 : The value of sensor time + * value | fifo sensor time + * ------------|------------------------- + * 0x00 | do not return sensortime frame + * 0x01 | return sensortime frame + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_time_enable( +u8 *v_fifo_time_enable_u8); +/*! + * @brief This API set fifo sensor time + * frame after the last valid data frame form the register 0x47 bit 1 + * + * + * + * + * @param v_fifo_time_enable_u8 : The value of sensor time + * value | fifo sensor time + * ------------|------------------------- + * 0x00 | do not return sensortime frame + * 0x01 | return sensortime frame + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_time_enable( +u8 v_fifo_time_enable_u8); +/*! + * @brief This API reads FIFO tag interrupt2 enable status + * from the resister 0x47 bit 2 + * + * @param v_fifo_tag_intr2_u8 : The value of fifo tag interrupt + * value | fifo tag interrupt + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_tag_intr2_enable( +u8 *v_fifo_tag_intr2_u8); +/*! + * @brief This API set FIFO tag interrupt2 enable status + * from the resister 0x47 bit 2 + * + * @param v_fifo_tag_intr2_u8 : The value of fifo tag interrupt + * value | fifo tag interrupt + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_tag_intr2_enable( +u8 v_fifo_tag_intr2_u8); +/*! + * @brief This API get FIFO tag interrupt1 enable status + * from the resister 0x47 bit 3 + * + * @param v_fifo_tag_intr1_u8 :The value of fifo tag interrupt1 + * value | fifo tag interrupt + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_tag_intr1_enable( +u8 *v_fifo_tag_intr1_u8); +/*! + * @brief This API set FIFO tag interrupt1 enable status + * from the resister 0x47 bit 3 + * + * @param v_fifo_tag_intr1_u8 :The value of fifo tag interrupt1 + * value | fifo tag interrupt + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_tag_intr1_enable( +u8 v_fifo_tag_intr1_u8); +/*! + * @brief This API reads FIFO frame + * header enable from the register 0x47 bit 4 + * + * @param v_fifo_header_u8 :The value of fifo header + * value | fifo header + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_header_enable( +u8 *v_fifo_header_u8); +/*! + * @brief This API set FIFO frame + * header enable from the register 0x47 bit 4 + * + * @param v_fifo_header_u8 :The value of fifo header + * value | fifo header + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_header_enable( +u8 v_fifo_header_u8); +/*! + * @brief This API is used to read stored + * magnetometer data in FIFO (all 3 axes) from the register 0x47 bit 5 + * + * @param v_fifo_mag_u8 : The value of fifo mag enble + * value | fifo mag + * ----------|------------------- + * 0x00 | no magnetometer data is stored + * 0x01 | magnetometer data is stored + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_mag_enable( +u8 *v_fifo_mag_u8); +/*! + * @brief This API is used to set stored + * magnetometer data in FIFO (all 3 axes) from the register 0x47 bit 5 + * + * @param v_fifo_mag_u8 : The value of fifo mag enble + * value | fifo mag + * ----------|------------------- + * 0x00 | no magnetometer data is stored + * 0x01 | magnetometer data is stored + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_mag_enable( +u8 v_fifo_mag_u8); +/*! + * @brief This API is used to read stored + * accel data in FIFO (all 3 axes) from the register 0x47 bit 6 + * + * @param v_fifo_accel_u8 : The value of fifo accel enble + * value | fifo accel + * ----------|------------------- + * 0x00 | no accel data is stored + * 0x01 | accel data is stored + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_accel_enable( +u8 *v_fifo_accel_u8); +/*! + * @brief This API is used to set stored + * accel data in FIFO (all 3 axes) from the register 0x47 bit 6 + * + * @param v_fifo_accel_u8 : The value of fifo accel enble + * value | fifo accel + * ----------|------------------- + * 0x00 | no accel data is stored + * 0x01 | accel data is stored + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_accel_enable( +u8 v_fifo_accel_u8); +/*! + * @brief This API is used to read stored + * gyro data in FIFO (all 3 axes) from the resister 0x47 bit 7 + * + * + * @param v_fifo_gyro_u8 : The value of fifo gyro enble + * value | fifo gyro + * ----------|------------------- + * 0x00 | no gyro data is stored + * 0x01 | gyro data is stored + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_fifo_gyro_enable( +u8 *v_fifo_gyro_u8); +/*! + * @brief This API is used to set stored + * gyro data in FIFO (all 3 axes) from the resister 0x47 bit 7 + * + * + * @param v_fifo_gyro_u8 : The value of fifo gyro enble + * value | fifo gyro + * ----------|------------------- + * 0x00 | no gyro data is stored + * 0x01 | gyro data is stored + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_fifo_gyro_enable( +u8 v_fifo_gyro_u8); +/***************************************************************/ +/**\name FUNCTION FOR MAG I2C ADDRESS SELECTION */ +/***************************************************************/ +/*! + * @brief This API is used to read + * I2C device address of auxiliary mag from the register 0x4B bit 1 to 7 + * + * + * + * + * @param v_i2c_device_addr_u8 : The value of mag I2C device address + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_device_addr( +u8 *v_i2c_device_addr_u8); +/*! + * @brief This API is used to set + * I2C device address of auxiliary mag from the register 0x4B bit 1 to 7 + * + * + * + * + * @param v_i2c_device_addr_u8 : The value of mag I2C device address + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_i2c_device_addr( +u8 v_i2c_device_addr_u8); +/*! + * @brief This API is used to read + * Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1 + * + * + * + * + * @param v_mag_burst_u8 : The data of mag burst read lenth + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_burst( +u8 *v_mag_burst_u8); +/*! + * @brief This API is used to set + * Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1 + * + * + * + * + * @param v_mag_burst_u8 : The data of mag burst read lenth + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_burst( +u8 v_mag_burst_u8); +/***************************************************************/ +/**\name FUNCTION FOR MAG OFFSET */ +/***************************************************************/ +/*! + * @brief This API is used to read + * trigger-readout offset in units of 2.5 ms. If set to zero, + * the offset is maximum, i.e. after readout a trigger + * is issued immediately. from the register 0x4C bit 2 to 5 + * + * + * + * + * @param v_mag_offset_u8 : The value of mag offset + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_offset( +u8 *v_mag_offset_u8); +/*! + * @brief This API is used to set + * trigger-readout offset in units of 2.5 ms. If set to zero, + * the offset is maximum, i.e. after readout a trigger + * is issued immediately. from the register 0x4C bit 2 to 5 + * + * + * + * + * @param v_mag_offset_u8 : The value of mag offset + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_offset( +u8 v_mag_offset_u8); +/***************************************************************/ +/**\name FUNCTION FOR MAG MANUAL/AUTO MODE SELECTION */ +/***************************************************************/ +/*! + * @brief This API is used to read + * Enable register access on MAG_IF[2] or MAG_IF[3] writes. + * This implies that the DATA registers are not updated with + * magnetometer values. Accessing magnetometer requires + * the magnetometer in normal mode in PMU_STATUS. + * from the register 0x4C bit 7 + * + * + * + * @param v_mag_manual_u8 : The value of mag manual enable + * value | mag manual + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_manual_enable( +u8 *v_mag_manual_u8); +/*! + * @brief This API is used to set + * Enable register access on MAG_IF[2] or MAG_IF[3] writes. + * This implies that the DATA registers are not updated with + * magnetometer values. Accessing magnetometer requires + * the magnetometer in normal mode in PMU_STATUS. + * from the register 0x4C bit 7 + * + * + * + * @param v_mag_manual_u8 : The value of mag manual enable + * value | mag manual + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_manual_enable( +u8 v_mag_manual_u8); +/***************************************************************/ +/**\name FUNCTIONS FOR MAG READ, WRITE AND WRITE DATA ADDRESS */ +/***************************************************************/ +/*! + * @brief This API is used to read data + * magnetometer address to read from the register 0x4D bit 0 to 7 + * @brief It used to provide mag read address of auxiliary mag + * + * + * + * + * @param v_mag_read_addr_u8 : The value of address need to be read + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_read_addr( +u8 *v_mag_read_addr_u8); +/*! + * @brief This API is used to set + * magnetometer write address from the register 0x4D bit 0 to 7 + * @brief mag write address writes the address of auxiliary mag to write + * + * + * + * @param v_mag_read_addr_u8: + * The data of auxiliary mag address to write data + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_read_addr( +u8 v_mag_read_addr_u8); +/*! + * @brief This API is used to read + * magnetometer write address from the register 0x4E bit 0 to 7 + * @brief mag write address writes the address of auxiliary mag to write + * + * + * + * @param v_mag_write_addr_u8: + * The data of auxiliary mag address to write data + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_write_addr( +u8 *v_mag_write_addr_u8); +/*! + * @brief This API is used to set + * magnetometer write address from the register 0x4E bit 0 to 7 + * @brief mag write address writes the address of auxiliary mag to write + * + * + * + * @param v_mag_write_addr_u8: + * The data of auxiliary mag address to write data + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_write_addr( +u8 v_mag_write_addr_u8); +/*! + * @brief This API is used to read magnetometer write data + * form the resister 0x4F bit 0 to 7 + * @brief This writes the data will be wrote to mag + * + * + * + * @param v_mag_write_data_u8: The value of mag data + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_mag_write_data( +u8 *v_mag_write_data_u8); +/*! + * @brief This API is used to set magnetometer write data + * form the resister 0x4F bit 0 to 7 + * @brief This writes the data will be wrote to mag + * + * + * + * @param v_mag_write_data_u8: The value of mag data + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_mag_write_data( +u8 v_mag_write_data_u8); +/***************************************************************/ +/**\name FUNCTION FOR INTERRUPT ENABLE OF +ANY-MOTION XYZ, DOUBLE AND SINGLE TAP, ORIENT AND FLAT */ +/***************************************************************/ +/*! + * @brief This API is used to read + * interrupt enable from the register 0x50 bit 0 to 7 + * + * + * + * + * @param v_enable_u8 : Value to decided to select interrupt + * v_enable_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_ANY_MOTION_X_ENABLE + * 1 | SMI130_ANY_MOTION_Y_ENABLE + * 2 | SMI130_ANY_MOTION_Z_ENABLE + * 3 | SMI130_DOUBLE_TAP_ENABLE + * 4 | SMI130_SINGLE_TAP_ENABLE + * 5 | SMI130_ORIENT_ENABLE + * 6 | SMI130_FLAT_ENABLE + * + * @param v_intr_enable_zero_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_enable_0( +u8 enable, u8 *v_intr_enable_zero_u8); +/*! + * @brief This API is used to set + * interrupt enable from the register 0x50 bit 0 to 7 + * + * + * + * + * @param v_enable_u8 : Value to decided to select interrupt + * v_enable_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_ANY_MOTION_X_ENABLE + * 1 | SMI130_ANY_MOTION_Y_ENABLE + * 2 | SMI130_ANY_MOTION_Z_ENABLE + * 3 | SMI130_DOUBLE_TAP_ENABLE + * 4 | SMI130_SINGLE_TAP_ENABLE + * 5 | SMI130_ORIENT_ENABLE + * 6 | SMI130_FLAT_ENABLE + * + * @param v_intr_enable_zero_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_enable_0( +u8 enable, u8 v_intr_enable_zero_u8); +/***************************************************************/ +/**\name FUNCTION FOR INTERRUPT ENABLE OF +HIGH_G XYZ, LOW_G, DATA READY, FIFO FULL AND FIFO WATER MARK */ +/***************************************************************/ +/*! + * @brief This API is used to read + * interrupt enable byte1 from the register 0x51 bit 0 to 6 + * @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable + * data ready, fifo full and fifo water mark. + * + * + * + * @param v_enable_u8 : The value of interrupt enable + * @param v_enable_u8 : Value to decided to select interrupt + * v_enable_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_HIGH_G_X_ENABLE + * 1 | SMI130_HIGH_G_Y_ENABLE + * 2 | SMI130_HIGH_G_Z_ENABLE + * 3 | SMI130_LOW_G_ENABLE + * 4 | SMI130_DATA_RDY_ENABLE + * 5 | SMI130_FIFO_FULL_ENABLE + * 6 | SMI130_FIFO_WM_ENABLE + * + * @param v_intr_enable_1_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_enable_1( +u8 enable, u8 *v_intr_enable_1_u8); +/*! + * @brief This API is used to set + * interrupt enable byte1 from the register 0x51 bit 0 to 6 + * @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable + * data ready, fifo full and fifo water mark. + * + * + * + * @param v_enable_u8 : The value of interrupt enable + * @param v_enable_u8 : Value to decided to select interrupt + * v_enable_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_HIGH_G_X_ENABLE + * 1 | SMI130_HIGH_G_Y_ENABLE + * 2 | SMI130_HIGH_G_Z_ENABLE + * 3 | SMI130_LOW_G_ENABLE + * 4 | SMI130_DATA_RDY_ENABLE + * 5 | SMI130_FIFO_FULL_ENABLE + * 6 | SMI130_FIFO_WM_ENABLE + * + * @param v_intr_enable_1_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_enable_1( +u8 enable, u8 v_intr_enable_1_u8); +/***************************************************************/ +/**\name FUNCTION FOR INTERRUPT ENABLE OF +NO MOTION XYZ */ +/***************************************************************/ +/*! + * @brief This API is used to read + * interrupt enable byte2 from the register bit 0x52 bit 0 to 3 + * @brief It reads no motion x,y and z + * + * + * + * @param v_enable_u8: The value of interrupt enable + * v_enable_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_NOMOTION_X_ENABLE + * 1 | SMI130_NOMOTION_Y_ENABLE + * 2 | SMI130_NOMOTION_Z_ENABLE + * + * @param v_intr_enable_2_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_enable_2( +u8 enable, u8 *v_intr_enable_2_u8); +/*! + * @brief This API is used to set + * interrupt enable byte2 from the register bit 0x52 bit 0 to 3 + * @brief It reads no motion x,y and z + * + * + * + * @param v_enable_u8: The value of interrupt enable + * v_enable_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_NOMOTION_X_ENABLE + * 1 | SMI130_NOMOTION_Y_ENABLE + * 2 | SMI130_NOMOTION_Z_ENABLE + * + * @param v_intr_enable_2_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_enable_2( +u8 enable, u8 v_intr_enable_2_u8); +/***************************************************************/ +/**\name FUNCTION FOR INTERRUPT ENABLE OF + STEP DETECTOR */ +/***************************************************************/ + /*! + * @brief This API is used to read + * interrupt enable step detector interrupt from + * the register bit 0x52 bit 3 + * + * + * + * + * @param v_step_intr_u8 : The value of step detector interrupt enable + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_step_detector_enable( +u8 *v_step_intr_u8); + /*! + * @brief This API is used to set + * interrupt enable step detector interrupt from + * the register bit 0x52 bit 3 + * + * + * + * + * @param v_step_intr_u8 : The value of step detector interrupt enable + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_detector_enable( +u8 v_step_intr_u8); +/***************************************************************/ +/**\name FUNCTION FOR INTERRUPT CONTROL */ +/***************************************************************/ +/*! + * @brief Configure trigger condition of interrupt1 + * and interrupt2 pin from the register 0x53 + * @brief interrupt1 - bit 0 + * @brief interrupt2 - bit 4 + * + * @param v_channel_u8: The value of edge trigger selection + * v_channel_u8 | Edge trigger + * ---------------|--------------- + * 0 | SMI130_INTR1_EDGE_CTRL + * 1 | SMI130_INTR2_EDGE_CTRL + * + * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_EDGE + * 0x00 | SMI130_LEVEL + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_edge_ctrl( +u8 v_channel_u8, u8 *v_intr_edge_ctrl_u8); +/*! + * @brief Configure trigger condition of interrupt1 + * and interrupt2 pin from the register 0x53 + * @brief interrupt1 - bit 0 + * @brief interrupt2 - bit 4 + * + * @param v_channel_u8: The value of edge trigger selection + * v_channel_u8 | Edge trigger + * ---------------|--------------- + * 0 | SMI130_INTR1_EDGE_CTRL + * 1 | SMI130_INTR2_EDGE_CTRL + * + * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_EDGE + * 0x00 | SMI130_LEVEL + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_edge_ctrl( +u8 v_channel_u8, u8 v_intr_edge_ctrl_u8); +/*! + * @brief API used for get the Configure level condition of interrupt1 + * and interrupt2 pin form the register 0x53 + * @brief interrupt1 - bit 1 + * @brief interrupt2 - bit 5 + * + * @param v_channel_u8: The value of level condition selection + * v_channel_u8 | level selection + * ---------------|--------------- + * 0 | SMI130_INTR1_LEVEL + * 1 | SMI130_INTR2_LEVEL + * + * @param v_intr_level_u8 : The value of level of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_LEVEL_HIGH + * 0x00 | SMI130_LEVEL_LOW + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_level( +u8 v_channel_u8, u8 *v_intr_level_u8); +/*! + * @brief API used for set the Configure level condition of interrupt1 + * and interrupt2 pin form the register 0x53 + * @brief interrupt1 - bit 1 + * @brief interrupt2 - bit 5 + * + * @param v_channel_u8: The value of level condition selection + * v_channel_u8 | level selection + * ---------------|--------------- + * 0 | SMI130_INTR1_LEVEL + * 1 | SMI130_INTR2_LEVEL + * + * @param v_intr_level_u8 : The value of level of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_LEVEL_HIGH + * 0x00 | SMI130_LEVEL_LOW + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_level( +u8 v_channel_u8, u8 v_intr_level_u8); +/*! + * @brief API used to get configured output enable of interrupt1 + * and interrupt2 from the register 0x53 + * @brief interrupt1 - bit 2 + * @brief interrupt2 - bit 6 + * + * + * @param v_channel_u8: The value of output type enable selection + * v_channel_u8 | level selection + * ---------------|--------------- + * 0 | SMI130_INTR1_OUTPUT_TYPE + * 1 | SMI130_INTR2_OUTPUT_TYPE + * + * @param v_intr_output_type_u8 : + * The value of output type of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_OPEN_DRAIN + * 0x00 | SMI130_PUSH_PULL + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_output_type( +u8 v_channel_u8, u8 *v_intr_output_type_u8); +/*! + * @brief API used to set output enable of interrupt1 + * and interrupt2 from the register 0x53 + * @brief interrupt1 - bit 2 + * @brief interrupt2 - bit 6 + * + * + * @param v_channel_u8: The value of output type enable selection + * v_channel_u8 | level selection + * ---------------|--------------- + * 0 | SMI130_INTR1_OUTPUT_TYPE + * 1 | SMI130_INTR2_OUTPUT_TYPE + * + * @param v_intr_output_type_u8 : + * The value of output type of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_OPEN_DRAIN + * 0x00 | SMI130_PUSH_PULL + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_output_type( +u8 v_channel_u8, u8 v_intr_output_type_u8); + /*! + * @brief API used to get the Output enable for interrupt1 + * and interrupt1 pin from the register 0x53 + * @brief interrupt1 - bit 3 + * @brief interrupt2 - bit 7 + * + * @param v_channel_u8: The value of output enable selection + * v_channel_u8 | level selection + * ---------------|--------------- + * 0 | SMI130_INTR1_OUTPUT_TYPE + * 1 | SMI130_INTR2_OUTPUT_TYPE + * + * @param v_output_enable_u8 : + * The value of output enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_INPUT + * 0x00 | SMI130_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_output_enable( +u8 v_channel_u8, u8 *v_output_enable_u8); + /*! + * @brief API used to set the Output enable for interrupt1 + * and interrupt1 pin from the register 0x53 + * @brief interrupt1 - bit 3 + * @brief interrupt2 - bit 7 + * + * @param v_channel_u8: The value of output enable selection + * v_channel_u8 | level selection + * ---------------|--------------- + * 0 | SMI130_INTR1_OUTPUT_TYPE + * 1 | SMI130_INTR2_OUTPUT_TYPE + * + * @param v_output_enable_u8 : + * The value of output enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_INPUT + * 0x00 | SMI130_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_output_enable( +u8 v_channel_u8, u8 v_output_enable_u8); +/***************************************************************/ +/**\name FUNCTION FOR INTERRUPT LATCH INTERRUPT */ +/***************************************************************/ +/*! +* @brief This API is used to get the latch duration +* from the register 0x54 bit 0 to 3 +* @brief This latch selection is not applicable for data ready, +* orientation and flat interrupts. +* +* +* +* @param v_latch_intr_u8 : The value of latch duration +* Latch Duration | value +* --------------------------------------|------------------ +* SMI130_LATCH_DUR_NONE | 0x00 +* SMI130_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* SMI130_LATCH_DUR_625_MICRO_SEC | 0x02 +* SMI130_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* SMI130_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* SMI130_LATCH_DUR_5_MILLI_SEC | 0x05 +* SMI130_LATCH_DUR_10_MILLI_SEC | 0x06 +* SMI130_LATCH_DUR_20_MILLI_SEC | 0x07 +* SMI130_LATCH_DUR_40_MILLI_SEC | 0x08 +* SMI130_LATCH_DUR_80_MILLI_SEC | 0x09 +* SMI130_LATCH_DUR_160_MILLI_SEC | 0x0A +* SMI130_LATCH_DUR_320_MILLI_SEC | 0x0B +* SMI130_LATCH_DUR_640_MILLI_SEC | 0x0C +* SMI130_LATCH_DUR_1_28_SEC | 0x0D +* SMI130_LATCH_DUR_2_56_SEC | 0x0E +* SMI130_LATCHED | 0x0F +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_latch_intr( +u8 *v_latch_intr_u8); +/*! +* @brief This API is used to set the latch duration +* from the register 0x54 bit 0 to 3 +* @brief This latch selection is not applicable for data ready, +* orientation and flat interrupts. +* +* +* +* @param v_latch_intr_u8 : The value of latch duration +* Latch Duration | value +* --------------------------------------|------------------ +* SMI130_LATCH_DUR_NONE | 0x00 +* SMI130_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* SMI130_LATCH_DUR_625_MICRO_SEC | 0x02 +* SMI130_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* SMI130_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* SMI130_LATCH_DUR_5_MILLI_SEC | 0x05 +* SMI130_LATCH_DUR_10_MILLI_SEC | 0x06 +* SMI130_LATCH_DUR_20_MILLI_SEC | 0x07 +* SMI130_LATCH_DUR_40_MILLI_SEC | 0x08 +* SMI130_LATCH_DUR_80_MILLI_SEC | 0x09 +* SMI130_LATCH_DUR_160_MILLI_SEC | 0x0A +* SMI130_LATCH_DUR_320_MILLI_SEC | 0x0B +* SMI130_LATCH_DUR_640_MILLI_SEC | 0x0C +* SMI130_LATCH_DUR_1_28_SEC | 0x0D +* SMI130_LATCH_DUR_2_56_SEC | 0x0E +* SMI130_LATCHED | 0x0F +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_latch_intr( +u8 v_latch_intr_u8); +/*! + * @brief API used to get input enable for interrupt1 + * and interrupt2 pin from the register 0x54 + * @brief interrupt1 - bit 4 + * @brief interrupt2 - bit 5 + * + * @param v_channel_u8: The value of input enable selection + * v_channel_u8 | input selection + * ---------------|--------------- + * 0 | SMI130_INTR1_INPUT_ENABLE + * 1 | SMI130_INTR2_INPUT_ENABLE + * + * @param v_input_en_u8 : + * The value of input enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_INPUT + * 0x00 | SMI130_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_input_enable( +u8 v_channel_u8, u8 *v_input_en_u8); +/*! + * @brief API used to set input enable for interrupt1 + * and interrupt2 pin from the register 0x54 + * @brief interrupt1 - bit 4 + * @brief interrupt2 - bit 5 + * + * @param v_channel_u8: The value of input enable selection + * v_channel_u8 | input selection + * ---------------|--------------- + * 0 | SMI130_INTR1_INPUT_ENABLE + * 1 | SMI130_INTR2_INPUT_ENABLE + * + * @param v_input_en_u8 : + * The value of input enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | SMI130_INPUT + * 0x00 | SMI130_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_input_enable( +u8 v_channel_u8, u8 v_input_en_u8); +/***************************************************************/ +/**\name FUNCTION FOR INTERRUPT1 AND INTERRUPT2 MAPPING */ +/***************************************************************/ + /*! + * @brief reads the Low g interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 0 in the register 0x55 + * @brief interrupt2 bit 0 in the register 0x57 + * + * + * @param v_channel_u8: The value of low_g selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_LOW_G + * 1 | SMI130_INTR2_MAP_LOW_G + * + * @param v_intr_low_g_u8 : The value of low_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g( +u8 v_channel_u8, u8 *v_intr_low_g_u8); + /*! + * @brief set the Low g interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 0 in the register 0x55 + * @brief interrupt2 bit 0 in the register 0x57 + * + * + * @param v_channel_u8: The value of low_g selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_LOW_G + * 1 | SMI130_INTR2_MAP_LOW_G + * + * @param v_intr_low_g_u8 : The value of low_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g( +u8 v_channel_u8, u8 v_intr_low_g_u8); +/*! + * @brief Reads the HIGH g interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 1 in the register 0x55 + * @brief interrupt2 bit 1 in the register 0x57 + * + * + * @param v_channel_u8: The value of high_g selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_HIGH_G + * 1 | SMI130_INTR2_MAP_HIGH_G + * + * @param v_intr_high_g_u8 : The value of high_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g( +u8 v_channel_u8, u8 *v_intr_high_g_u8); +/*! + * @brief Write the HIGH g interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 1 in the register 0x55 + * @brief interrupt2 bit 1 in the register 0x57 + * + * + * @param v_channel_u8: The value of high_g selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_HIGH_G + * 1 | SMI130_INTR2_MAP_HIGH_G + * + * @param v_intr_high_g_u8 : The value of high_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g( +u8 v_channel_u8, u8 v_intr_high_g_u8); +/*! + * @brief Reads the Any motion interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 2 in the register 0x55 + * @brief interrupt2 bit 2 in the register 0x57 + * + * + * @param v_channel_u8: The value of any motion selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_ANY_MOTION + * 1 | SMI130_INTR2_MAP_ANY_MOTION + * + * @param v_intr_any_motion_u8 : The value of any motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_any_motion( +u8 v_channel_u8, u8 *v_intr_any_motion_u8); +/*! + * @brief Write the Any motion interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 2 in the register 0x55 + * @brief interrupt2 bit 2 in the register 0x57 + * + * + * @param v_channel_u8: The value of any motion selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_ANY_MOTION + * 1 | SMI130_INTR2_MAP_ANY_MOTION + * + * @param v_intr_any_motion_u8 : The value of any motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_any_motion( +u8 v_channel_u8, u8 v_intr_any_motion_u8); +/*! + * @brief Reads the No motion interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 3 in the register 0x55 + * @brief interrupt2 bit 3 in the register 0x57 + * + * + * @param v_channel_u8: The value of no motion selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_NOMO + * 1 | SMI130_INTR2_MAP_NOMO + * + * @param v_intr_nomotion_u8 : The value of no motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_nomotion( +u8 v_channel_u8, u8 *v_intr_nomotion_u8); +/*! + * @brief Write the No motion interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 3 in the register 0x55 + * @brief interrupt2 bit 3 in the register 0x57 + * + * + * @param v_channel_u8: The value of no motion selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_NOMO + * 1 | SMI130_INTR2_MAP_NOMO + * + * @param v_intr_nomotion_u8 : The value of no motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_nomotion( +u8 v_channel_u8, u8 v_intr_nomotion_u8); +/*! + * @brief Reads the Double Tap interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 4 in the register 0x55 + * @brief interrupt2 bit 4 in the register 0x57 + * + * + * @param v_channel_u8: The value of double tap interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_DOUBLE_TAP + * 1 | SMI130_INTR2_MAP_DOUBLE_TAP + * + * @param v_intr_double_tap_u8 : The value of double tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_double_tap( +u8 v_channel_u8, u8 *v_intr_double_tap_u8); +/*! + * @brief Write the Double Tap interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 4 in the register 0x55 + * @brief interrupt2 bit 4 in the register 0x57 + * + * + * @param v_channel_u8: The value of double tap interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_DOUBLE_TAP + * 1 | SMI130_INTR2_MAP_DOUBLE_TAP + * + * @param v_intr_double_tap_u8 : The value of double tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_double_tap( +u8 v_channel_u8, u8 v_intr_double_tap_u8); +/*! + * @brief Reads the Single Tap interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 5 in the register 0x55 + * @brief interrupt2 bit 5 in the register 0x57 + * + * + * @param v_channel_u8: The value of single tap interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_SINGLE_TAP + * 1 | SMI130_INTR2_MAP_SINGLE_TAP + * + * @param v_intr_single_tap_u8 : The value of single tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_single_tap( +u8 v_channel_u8, u8 *v_intr_single_tap_u8); +/*! + * @brief Write the Single Tap interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 5 in the register 0x55 + * @brief interrupt2 bit 5 in the register 0x57 + * + * + * @param v_channel_u8: The value of single tap interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_SINGLE_TAP + * 1 | SMI130_INTR2_MAP_SINGLE_TAP + * + * @param v_intr_single_tap_u8 : The value of single tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_single_tap( +u8 v_channel_u8, u8 v_intr_single_tap_u8); +/*! + * @brief Reads the Orient interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 6 in the register 0x55 + * @brief interrupt2 bit 6 in the register 0x57 + * + * + * @param v_channel_u8: The value of orient interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_ORIENT + * 1 | SMI130_INTR2_MAP_ORIENT + * + * @param v_intr_orient_u8 : The value of orient enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient( +u8 v_channel_u8, u8 *v_intr_orient_u8); +/*! + * @brief Write the Orient interrupt + * interrupt mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 6 in the register 0x55 + * @brief interrupt2 bit 6 in the register 0x57 + * + * + * @param v_channel_u8: The value of orient interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_ORIENT + * 1 | SMI130_INTR2_MAP_ORIENT + * + * @param v_intr_orient_u8 : The value of orient enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient( +u8 v_channel_u8, u8 v_intr_orient_u8); + /*! + * @brief Reads the Flat interrupt + * mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 7 in the register 0x55 + * @brief interrupt2 bit 7 in the register 0x57 + * + * + * @param v_channel_u8: The value of flat interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_FLAT + * 1 | SMI130_INTR2_MAP_FLAT + * + * @param v_intr_flat_u8 : The value of flat enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat( +u8 v_channel_u8, u8 *v_intr_flat_u8); + /*! + * @brief Write the Flat interrupt + * mapped to interrupt1 + * and interrupt2 from the register 0x55 and 0x57 + * @brief interrupt1 bit 7 in the register 0x55 + * @brief interrupt2 bit 7 in the register 0x57 + * + * + * @param v_channel_u8: The value of flat interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_FLAT + * 1 | SMI130_INTR2_MAP_FLAT + * + * @param v_intr_flat_u8 : The value of flat enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat( +u8 v_channel_u8, u8 v_intr_flat_u8); +/*! + * @brief Reads PMU trigger interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 bit 0 and 4 + * @brief interrupt1 bit 0 in the register 0x56 + * @brief interrupt2 bit 4 in the register 0x56 + * + * + * @param v_channel_u8: The value of pmu trigger selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_PMUTRIG + * 1 | SMI130_INTR2_MAP_PMUTRIG + * + * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_pmu_trig( +u8 v_channel_u8, u8 *v_intr_pmu_trig_u8); +/*! + * @brief Write PMU trigger interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 bit 0 and 4 + * @brief interrupt1 bit 0 in the register 0x56 + * @brief interrupt2 bit 4 in the register 0x56 + * + * + * @param v_channel_u8: The value of pmu trigger selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_PMUTRIG + * 1 | SMI130_INTR2_MAP_PMUTRIG + * + * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable + * value | trigger enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_pmu_trig( +u8 v_channel_u8, u8 v_intr_pmu_trig_u8); +/*! + * @brief Reads FIFO Full interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 bit 5 and 1 + * @brief interrupt1 bit 5 in the register 0x56 + * @brief interrupt2 bit 1 in the register 0x56 + * + * + * @param v_channel_u8: The value of fifo full interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_FIFO_FULL + * 1 | SMI130_INTR2_MAP_FIFO_FULL + * + * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_fifo_full( +u8 v_channel_u8, u8 *v_intr_fifo_full_u8); +/*! + * @brief Write FIFO Full interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 bit 5 and 1 + * @brief interrupt1 bit 5 in the register 0x56 + * @brief interrupt2 bit 1 in the register 0x56 + * + * + * @param v_channel_u8: The value of fifo full interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_FIFO_FULL + * 1 | SMI130_INTR2_MAP_FIFO_FULL + * + * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_fifo_full( +u8 v_channel_u8, u8 v_intr_fifo_full_u8); +/*! + * @brief Reads FIFO Watermark interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 bit 6 and 2 + * @brief interrupt1 bit 6 in the register 0x56 + * @brief interrupt2 bit 2 in the register 0x56 + * + * + * @param v_channel_u8: The value of fifo Watermark interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_FIFO_WM + * 1 | SMI130_INTR2_MAP_FIFO_WM + * + * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_fifo_wm( +u8 v_channel_u8, u8 *v_intr_fifo_wm_u8); +/*! + * @brief Write FIFO Watermark interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 bit 6 and 2 + * @brief interrupt1 bit 6 in the register 0x56 + * @brief interrupt2 bit 2 in the register 0x56 + * + * + * @param v_channel_u8: The value of fifo Watermark interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_FIFO_WM + * 1 | SMI130_INTR2_MAP_FIFO_WM + * + * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_fifo_wm( +u8 v_channel_u8, u8 v_intr_fifo_wm_u8); +/*! + * @brief Reads Data Ready interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 + * @brief interrupt1 bit 7 in the register 0x56 + * @brief interrupt2 bit 3 in the register 0x56 + * + * + * @param v_channel_u8: The value of data ready interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_DATA_RDY + * 1 | SMI130_INTR2_MAP_DATA_RDY + * + * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_data_rdy( +u8 v_channel_u8, u8 *v_intr_data_rdy_u8); +/*! + * @brief Write Data Ready interrupt mapped to interrupt1 + * and interrupt2 form the register 0x56 + * @brief interrupt1 bit 7 in the register 0x56 + * @brief interrupt2 bit 3 in the register 0x56 + * + * + * @param v_channel_u8: The value of data ready interrupt selection + * v_channel_u8 | interrupt + * ---------------|--------------- + * 0 | SMI130_INTR1_MAP_DATA_RDY + * 1 | SMI130_INTR2_MAP_DATA_RDY + * + * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | SMI130_ENABLE + * 0x00 | SMI130_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_data_rdy( +u8 v_channel_u8, u8 v_intr_data_rdy_u8); +/***************************************************************/ +/**\name FUNCTION FOR TAP SOURCE CONFIGURATION */ +/***************************************************************/ + /*! + * @brief This API reads data source for the interrupt + * engine for the single and double tap interrupts from the register + * 0x58 bit 3 + * + * + * @param v_tap_source_u8 : The value of the tap source + * value | Description + * ----------|------------------- + * 0x01 | UNFILTER_DATA + * 0x00 | FILTER_DATA + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_source( +u8 *v_tap_source_u8); + /*! + * @brief This API write data source for the interrupt + * engine for the single and double tap interrupts from the register + * 0x58 bit 3 + * + * + * @param v_tap_source_u8 : The value of the tap source + * value | Description + * ----------|------------------- + * 0x01 | UNFILTER_DATA + * 0x00 | FILTER_DATA + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_source( +u8 v_tap_source_u8); +/***************************************************************/ +/**\name FUNCTION FOR LOW_G AND HIGH_G SOURCE CONFIGURATION */ +/***************************************************************/ + /*! + * @brief This API Reads Data source for the + * interrupt engine for the low and high g interrupts + * from the register 0x58 bit 7 + * + * @param v_low_high_source_u8 : The value of the tap source + * value | Description + * ----------|------------------- + * 0x01 | UNFILTER_DATA + * 0x00 | FILTER_DATA + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_high_source( +u8 *v_low_high_source_u8); + /*! + * @brief This API write Data source for the + * interrupt engine for the low and high g interrupts + * from the register 0x58 bit 7 + * + * @param v_low_high_source_u8 : The value of the tap source + * value | Description + * ----------|------------------- + * 0x01 | UNFILTER_DATA + * 0x00 | FILTER_DATA + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_high_source( +u8 v_low_high_source_u8); +/***************************************************************/ +/**\name FUNCTION FOR MOTION SOURCE CONFIGURATION */ +/***************************************************************/ + /*! + * @brief This API reads Data source for the + * interrupt engine for the nomotion and anymotion interrupts + * from the register 0x59 bit 7 + * + * @param v_motion_source_u8 : + * The value of the any/no motion interrupt source + * value | Description + * ----------|------------------- + * 0x01 | UNFILTER_DATA + * 0x00 | FILTER_DATA + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_motion_source( +u8 *v_motion_source_u8); + /*! + * @brief This API write Data source for the + * interrupt engine for the nomotion and anymotion interrupts + * from the register 0x59 bit 7 + * + * @param v_motion_source_u8 : + * The value of the any/no motion interrupt source + * value | Description + * ----------|------------------- + * 0x01 | UNFILTER_DATA + * 0x00 | FILTER_DATA + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_motion_source( +u8 v_motion_source_u8); +/***************************************************************/ +/**\name FUNCTION FOR LOW_G DURATION CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API is used to read the low_g duration from register + * 0x5A bit 0 to 7 + * + * + * + * + * @param v_low_g_durn_u8 : The value of low_g duration + * + * @note Low_g duration trigger trigger delay according to + * "(v_low_g_durn_u8 * 2.5)ms" in a range from 2.5ms to 640ms. + * the default corresponds delay is 20ms + * @note When low_g data source of interrupt is unfiltered + * the sensor must not be in low power mode + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_durn( +u8 *v_low_durn_u8); + /*! + * @brief This API is used to write the low_g duration from register + * 0x5A bit 0 to 7 + * + * + * + * + * @param v_low_g_durn_u8 : The value of low_g duration + * + * @note Low_g duration trigger trigger delay according to + * "(v_low_g_durn_u8 * 2.5)ms" in a range from 2.5ms to 640ms. + * the default corresponds delay is 20ms + * @note When low_g data source of interrupt is unfiltered + * the sensor must not be in low power mode + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_durn( +u8 v_low_durn_u8); +/***************************************************************/ +/**\name FUNCTION FOR LOW_G THRESH CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API is used to read Threshold + * definition for the low-g interrupt from the register 0x5B bit 0 to 7 + * + * + * + * + * @param v_low_g_thres_u8 : The value of low_g threshold + * + * @note Low_g interrupt trigger threshold according to + * (v_low_g_thres_u8 * 7.81)mg for v_low_g_thres_u8 > 0 + * 3.91 mg for v_low_g_thres_u8 = 0 + * The threshold range is form 3.91mg to 2.000mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_thres( +u8 *v_low_g_thres_u8); +/*! + * @brief This API is used to write Threshold + * definition for the low-g interrupt from the register 0x5B bit 0 to 7 + * + * + * + * + * @param v_low_g_thres_u8 : The value of low_g threshold + * + * @note Low_g interrupt trigger threshold according to + * (v_low_g_thres_u8 * 7.81)mg for v_low_g_thres_u8 > 0 + * 3.91 mg for v_low_g_thres_u8 = 0 + * The threshold range is form 3.91mg to 2.000mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_thres( +u8 v_low_g_thres_u8); +/***************************************************************/ +/**\name FUNCTION FOR LOW_G HYSTERESIS CONFIGURATION */ +/***************************************************************/ + /*! + * @brief This API Reads Low-g interrupt hysteresis + * from the register 0x5C bit 0 to 1 + * + * @param v_low_hyst_u8 :The value of low_g hysteresis + * + * @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_hyst( +u8 *v_low_hyst_u8); + /*! + * @brief This API write Low-g interrupt hysteresis + * from the register 0x5C bit 0 to 1 + * + * @param v_low_hyst_u8 :The value of low_g hysteresis + * + * @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_hyst( +u8 v_low_hyst_u8); +/***************************************************************/ +/**\name FUNCTION FOR LOW_G MODE CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API reads Low-g interrupt mode + * from the register 0x5C bit 2 + * + * @param v_low_g_mode_u8 : The value of low_g mode + * Value | Description + * ----------|----------------- + * 0 | single-axis + * 1 | axis-summing + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_low_g_mode( +u8 *v_low_g_mode_u8); +/*! + * @brief This API write Low-g interrupt mode + * from the register 0x5C bit 2 + * + * @param v_low_g_mode_u8 : The value of low_g mode + * Value | Description + * ----------|----------------- + * 0 | single-axis + * 1 | axis-summing + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_low_g_mode( +u8 v_low_g_mode_u8); +/***************************************************************/ +/**\name FUNCTION FOR HIGH_G HYST CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API reads High-g interrupt hysteresis + * from the register 0x5C bit 6 and 7 + * + * @param v_high_g_hyst_u8 : The value of high hysteresis + * + * @note High_g hysteresis changes according to accel g range + * accel g range can be set by the function "" + * accel_range | high_g hysteresis + * ----------------|--------------------- + * 2g | high_hy*125 mg + * 4g | high_hy*250 mg + * 8g | high_hy*500 mg + * 16g | high_hy*1000 mg + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g_hyst( +u8 *v_high_g_hyst_u8); +/*! + * @brief This API write High-g interrupt hysteresis + * from the register 0x5C bit 6 and 7 + * + * @param v_high_g_hyst_u8 : The value of high hysteresis + * + * @note High_g hysteresis changes according to accel g range + * accel g range can be set by the function "" + * accel_range | high_g hysteresis + * ----------------|--------------------- + * 2g | high_hy*125 mg + * 4g | high_hy*250 mg + * 8g | high_hy*500 mg + * 16g | high_hy*1000 mg + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g_hyst( +u8 v_high_g_hyst_u8); +/***************************************************************/ +/**\name FUNCTION FOR HIGH_G DURATION CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API is used to read Delay + * time definition for the high-g interrupt from the register + * 0x5D bit 0 to 7 + * + * + * + * @param v_high_g_durn_u8 : The value of high duration + * + * @note High_g interrupt delay triggered according to + * v_high_g_durn_u8 * 2.5ms in a range from 2.5ms to 640ms + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g_durn( +u8 *v_high_g_durn_u8); +/*! + * @brief This API is used to write Delay + * time definition for the high-g interrupt from the register + * 0x5D bit 0 to 7 + * + * + * + * @param v_high_g_durn_u8 : The value of high duration + * + * @note High_g interrupt delay triggered according to + * v_high_g_durn_u8 * 2.5ms in a range from 2.5ms to 640ms + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g_durn( +u8 v_high_g_durn_u8); +/***************************************************************/ +/**\name FUNCTION FOR HIGH_G THRESHOLD CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API is used to read Threshold + * definition for the high-g interrupt from the register 0x5E 0 to 7 + * + * + * + * + * @param v_high_g_thres_u8 : Pointer holding the value of Threshold + * @note High_g threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | high_g threshold + * ----------------|--------------------- + * 2g | v_high_g_thres_u8*7.81 mg + * 4g | v_high_g_thres_u8*15.63 mg + * 8g | v_high_g_thres_u8*31.25 mg + * 16g | v_high_g_thres_u8*62.5 mg + * @note when v_high_g_thres_u8 = 0 + * accel_range | high_g threshold + * ----------------|--------------------- + * 2g | 3.91 mg + * 4g | 7.81 mg + * 8g | 15.63 mg + * 16g | 31.25 mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_high_g_thres( +u8 *v_high_g_thres_u8); +/*! + * @brief This API is used to write Threshold + * definition for the high-g interrupt from the register 0x5E 0 to 7 + * + * + * + * + * @param v_high_g_thres_u8 : Pointer holding the value of Threshold + * @note High_g threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | high_g threshold + * ----------------|--------------------- + * 2g | v_high_g_thres_u8*7.81 mg + * 4g | v_high_g_thres_u8*15.63 mg + * 8g | v_high_g_thres_u8*31.25 mg + * 16g | v_high_g_thres_u8*62.5 mg + * @note when v_high_g_thres_u8 = 0 + * accel_range | high_g threshold + * ----------------|--------------------- + * 2g | 3.91 mg + * 4g | 7.81 mg + * 8g | 15.63 mg + * 16g | 31.25 mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_high_g_thres( +u8 v_high_g_thres_u8); +/***************************************************************/ +/**\name FUNCTION FOR ANY MOTION DURATION CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API reads any motion duration + * from the register 0x5F bit 0 and 1 + * + * @param v_any_motion_durn_u8 : The value of any motion duration + * + * @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1" + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_any_motion_durn( +u8 *v_any_motion_durn_u8); +/*! + * @brief This API write any motion duration + * from the register 0x5F bit 0 and 1 + * + * @param v_any_motion_durn_u8 : The value of any motion duration + * + * @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1" + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_any_motion_durn( +u8 nomotion); +/***************************************************************/ +/**\name FUNCTION FOR SLOW NO MOTION DURATION CONFIGURATION */ +/***************************************************************/ + /*! + * @brief This API read Slow/no-motion + * interrupt trigger delay duration from the register 0x5F bit 2 to 7 + * + * @param v_slow_no_motion_u8 :The value of slow no motion duration + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * @note + * @note v_slow_no_motion_u8(5:4)=0b00 -> + * [v_slow_no_motion_u8(3:0) + 1] * 1.28s (1.28s-20.48s) + * @note v_slow_no_motion_u8(5:4)=1 -> + * [v_slow_no_motion_u8(3:0)+5] * 5.12s (25.6s-102.4s) + * @note v_slow_no_motion_u8(5)='1' -> + * [(v_slow_no_motion_u8:0)+11] * 10.24s (112.64s-430.08s); + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_slow_no_motion_durn( +u8 *v_slow_no_motion_u8); + /*! + * @brief This API write Slow/no-motion + * interrupt trigger delay duration from the register 0x5F bit 2 to 7 + * + * @param v_slow_no_motion_u8 :The value of slow no motion duration + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * @note + * @note v_slow_no_motion_u8(5:4)=0b00 -> + * [v_slow_no_motion_u8(3:0) + 1] * 1.28s (1.28s-20.48s) + * @note v_slow_no_motion_u8(5:4)=1 -> + * [v_slow_no_motion_u8(3:0)+5] * 5.12s (25.6s-102.4s) + * @note v_slow_no_motion_u8(5)='1' -> + * [(v_slow_no_motion_u8:0)+11] * 10.24s (112.64s-430.08s); + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_slow_no_motion_durn( +u8 v_slow_no_motion_u8); +/***************************************************************/ +/**\name FUNCTION FOR ANY MOTION THRESHOLD CONFIGURATION */ +/***************************************************************/ +/*! + * @brief This API is used to read threshold + * definition for the any-motion interrupt + * from the register 0x60 bit 0 to 7 + * + * + * @param v_any_motion_thres_u8 : The value of any motion threshold + * + * @note any motion threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | any motion threshold + * ----------------|--------------------- + * 2g | v_any_motion_thres_u8*3.91 mg + * 4g | v_any_motion_thres_u8*7.81 mg + * 8g | v_any_motion_thres_u8*15.63 mg + * 16g | v_any_motion_thres_u8*31.25 mg + * @note when v_any_motion_thres_u8 = 0 + * accel_range | any motion threshold + * ----------------|--------------------- + * 2g | 1.95 mg + * 4g | 3.91 mg + * 8g | 7.81 mg + * 16g | 15.63 mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_any_motion_thres( +u8 *v_any_motion_thres_u8); +/*! + * @brief This API is used to write threshold + * definition for the any-motion interrupt + * from the register 0x60 bit 0 to 7 + * + * + * @param v_any_motion_thres_u8 : The value of any motion threshold + * + * @note any motion threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | any motion threshold + * ----------------|--------------------- + * 2g | v_any_motion_thres_u8*3.91 mg + * 4g | v_any_motion_thres_u8*7.81 mg + * 8g | v_any_motion_thres_u8*15.63 mg + * 16g | v_any_motion_thres_u8*31.25 mg + * @note when v_any_motion_thres_u8 = 0 + * accel_range | any motion threshold + * ----------------|--------------------- + * 2g | 1.95 mg + * 4g | 3.91 mg + * 8g | 7.81 mg + * 16g | 15.63 mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_any_motion_thres( +u8 v_any_motion_thres_u8); +/***************************************************************/ +/**\name FUNCTION FOR SLO/NO MOTION THRESHOLD CONFIGURATION */ +/***************************************************************/ + /*! + * @brief This API is used to read threshold + * for the slow/no-motion interrupt + * from the register 0x61 bit 0 to 7 + * + * + * + * + * @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold + * @note slow no motion threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | slow no motion threshold + * ----------------|--------------------- + * 2g | v_slow_no_motion_thres_u8*3.91 mg + * 4g | v_slow_no_motion_thres_u8*7.81 mg + * 8g | v_slow_no_motion_thres_u8*15.63 mg + * 16g | v_slow_no_motion_thres_u8*31.25 mg + * @note when v_slow_no_motion_thres_u8 = 0 + * accel_range | slow no motion threshold + * ----------------|--------------------- + * 2g | 1.95 mg + * 4g | 3.91 mg + * 8g | 7.81 mg + * 16g | 15.63 mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_slow_no_motion_thres( +u8 *v_slow_no_motion_thres_u8); + /*! + * @brief This API is used to write threshold + * for the slow/no-motion interrupt + * from the register 0x61 bit 0 to 7 + * + * + * + * + * @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold + * @note slow no motion threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | slow no motion threshold + * ----------------|--------------------- + * 2g | v_slow_no_motion_thres_u8*3.91 mg + * 4g | v_slow_no_motion_thres_u8*7.81 mg + * 8g | v_slow_no_motion_thres_u8*15.63 mg + * 16g | v_slow_no_motion_thres_u8*31.25 mg + * @note when v_slow_no_motion_thres_u8 = 0 + * accel_range | slow no motion threshold + * ----------------|--------------------- + * 2g | 1.95 mg + * 4g | 3.91 mg + * 8g | 7.81 mg + * 16g | 15.63 mg + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_slow_no_motion_thres( +u8 v_slow_no_motion_thres_u8); +/***************************************************************/ +/**\name FUNCTION FOR SLO/NO MOTION SELECT CONFIGURATION */ +/***************************************************************/ + /*! + * @brief This API is used to read + * the slow/no-motion selection from the register 0x62 bit 0 + * + * + * + * + * @param v_intr_slow_no_motion_select_u8 : + * The value of slow/no-motion select + * value | Behaviour + * ----------|------------------- + * 0x00 | SLOW_MOTION + * 0x01 | NO_MOTION + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_slow_no_motion_select( +u8 *v_intr_slow_no_motion_select_u8); + /*! + * @brief This API is used to write + * the slow/no-motion selection from the register 0x62 bit 0 + * + * + * + * + * @param v_intr_slow_no_motion_select_u8 : + * The value of slow/no-motion select + * value | Behaviour + * ----------|------------------- + * 0x00 | SLOW_MOTION + * 0x01 | NO_MOTION + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_slow_no_motion_select( +u8 v_intr_slow_no_motion_select_u8); +/***************************************************************/ +/**\name FUNCTION FOR SIGNIFICANT MOTION SELECT CONFIGURATION*/ +/***************************************************************/ + /*! + * @brief This API is used to select + * the significant or any motion interrupt from the register 0x62 bit 1 + * + * + * + * + * @param v_intr_significant_motion_select_u8 : + * the value of significant or any motion interrupt selection + * value | Behaviour + * ----------|------------------- + * 0x00 | ANY_MOTION + * 0x01 | SIGNIFICANT_MOTION + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_significant_motion_select( +u8 *int_sig_mot_sel); + /*! + * @brief This API is used to write, select + * the significant or any motion interrupt from the register 0x62 bit 1 + * + * + * + * + * @param v_intr_significant_motion_select_u8 : + * the value of significant or any motion interrupt selection + * value | Behaviour + * ----------|------------------- + * 0x00 | ANY_MOTION + * 0x01 | SIGNIFICANT_MOTION + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_significant_motion_select( +u8 int_sig_mot_sel); + /*! + * @brief This API is used to read + * the significant skip time from the register 0x62 bit 2 and 3 + * + * + * + * + * @param v_int_sig_mot_skip_u8 : the value of significant skip time + * value | Behaviour + * ----------|------------------- + * 0x00 | skip time 1.5 seconds + * 0x01 | skip time 3 seconds + * 0x02 | skip time 6 seconds + * 0x03 | skip time 12 seconds + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_significant_motion_skip( +u8 *v_int_sig_mot_skip_u8); + /*! + * @brief This API is used to write + * the significant skip time from the register 0x62 bit 2 and 3 + * + * + * + * + * @param v_int_sig_mot_skip_u8 : the value of significant skip time + * value | Behaviour + * ----------|------------------- + * 0x00 | skip time 1.5 seconds + * 0x01 | skip time 3 seconds + * 0x02 | skip time 6 seconds + * 0x03 | skip time 12 seconds + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_significant_motion_skip( +u8 v_int_sig_mot_skip_u8); + /*! + * @brief This API is used to read + * the significant proof time from the register 0x62 bit 4 and 5 + * + * + * + * + * @param v_significant_motion_proof_u8 : + * the value of significant proof time + * value | Behaviour + * ----------|------------------- + * 0x00 | proof time 0.25 seconds + * 0x01 | proof time 0.5 seconds + * 0x02 | proof time 1 seconds + * 0x03 | proof time 2 seconds + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_significant_motion_proof( +u8 *int_sig_mot_proof); + /*! + * @brief This API is used to write + * the significant proof time from the register 0x62 bit 4 and 5 + * + * + * + * + * @param v_significant_motion_proof_u8 : + * the value of significant proof time + * value | Behaviour + * ----------|------------------- + * 0x00 | proof time 0.25 seconds + * 0x01 | proof time 0.5 seconds + * 0x02 | proof time 1 seconds + * 0x03 | proof time 2 seconds + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_significant_motion_proof( +u8 int_sig_mot_proof); +/***************************************************************/ +/**\name FUNCTION FOR TAP DURATION CONFIGURATION*/ +/***************************************************************/ +/*! + * @brief This API is used to get the tap duration + * from the register 0x63 bit 0 to 2 + * + * + * + * @param v_tap_durn_u8 : The value of tap duration + * value | Behaviour + * ----------|------------------- + * 0x00 | SMI130_TAP_DURN_50MS + * 0x01 | SMI130_TAP_DURN_100MS + * 0x03 | SMI130_TAP_DURN_150MS + * 0x04 | SMI130_TAP_DURN_200MS + * 0x05 | SMI130_TAP_DURN_250MS + * 0x06 | SMI130_TAP_DURN_375MS + * 0x07 | SMI130_TAP_DURN_700MS + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_durn( +u8 *v_tap_durn_u8); +/*! + * @brief This API is used to write the tap duration + * from the register 0x63 bit 0 to 2 + * + * + * + * @param v_tap_durn_u8 : The value of tap duration + * value | Behaviour + * ----------|------------------- + * 0x00 | SMI130_TAP_DURN_50MS + * 0x01 | SMI130_TAP_DURN_100MS + * 0x03 | SMI130_TAP_DURN_150MS + * 0x04 | SMI130_TAP_DURN_200MS + * 0x05 | SMI130_TAP_DURN_250MS + * 0x06 | SMI130_TAP_DURN_375MS + * 0x07 | SMI130_TAP_DURN_700MS + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_durn( +u8 v_tap_durn_u8); +/***************************************************************/ +/**\name FUNCTION FOR TAP SHOCK CONFIGURATION*/ +/***************************************************************/ + /*! + * @brief This API read the + * tap shock duration from the register 0x63 bit 2 + * + * @param v_tap_shock_u8 :The value of tap shock + * value | Behaviour + * ----------|------------------- + * 0x00 | SMI130_TAP_SHOCK_50MS + * 0x01 | SMI130_TAP_SHOCK_75MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_shock( +u8 *v_tap_shock_u8); + /*! + * @brief This API write the + * tap shock duration from the register 0x63 bit 2 + * + * @param v_tap_shock_u8 :The value of tap shock + * value | Behaviour + * ----------|------------------- + * 0x00 | SMI130_TAP_SHOCK_50MS + * 0x01 | SMI130_TAP_SHOCK_75MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_shock( +u8 v_tap_shock_u8); +/***************************************************************/ +/**\name FUNCTION FOR TAP QUIET CONFIGURATION*/ +/***************************************************************/ +/*! + * @brief This API read + * tap quiet duration from the register 0x63 bit 7 + * + * + * @param v_tap_quiet_u8 : The value of tap quiet + * value | Behaviour + * ----------|------------------- + * 0x00 | SMI130_TAP_QUIET_30MS + * 0x01 | SMI130_TAP_QUIET_20MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_quiet( +u8 *v_tap_quiet_u8); +/*! + * @brief This API write + * tap quiet duration from the register 0x63 bit 7 + * + * + * @param v_tap_quiet_u8 : The value of tap quiet + * value | Behaviour + * ----------|------------------- + * 0x00 | SMI130_TAP_QUIET_30MS + * 0x01 | SMI130_TAP_QUIET_20MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_quiet( +u8 v_tap_quiet_u8); +/***************************************************************/ +/**\name FUNCTION FOR TAP THRESHOLD CONFIGURATION*/ +/***************************************************************/ + /*! + * @brief This API read Threshold of the + * single/double tap interrupt from the register 0x64 bit 0 to 4 + * + * + * @param v_tap_thres_u8 : The value of single/double tap threshold + * + * @note single/double tap threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | single/double tap threshold + * ----------------|--------------------- + * 2g | ((v_tap_thres_u8 + 1) * 62.5)mg + * 4g | ((v_tap_thres_u8 + 1) * 125)mg + * 8g | ((v_tap_thres_u8 + 1) * 250)mg + * 16g | ((v_tap_thres_u8 + 1) * 500)mg + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_tap_thres( +u8 *v_tap_thres_u8); + /*! + * @brief This API write Threshold of the + * single/double tap interrupt from the register 0x64 bit 0 to 4 + * + * + * @param v_tap_thres_u8 : The value of single/double tap threshold + * + * @note single/double tap threshold changes according to accel g range + * accel g range can be set by the function "" + * accel_range | single/double tap threshold + * ----------------|--------------------- + * 2g | ((v_tap_thres_u8 + 1) * 62.5)mg + * 4g | ((v_tap_thres_u8 + 1) * 125)mg + * 8g | ((v_tap_thres_u8 + 1) * 250)mg + * 16g | ((v_tap_thres_u8 + 1) * 500)mg + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_tap_thres( +u8 v_tap_thres_u8); +/***************************************************************/ +/**\name FUNCTION FOR ORIENT MODE CONFIGURATION*/ +/***************************************************************/ + /*! + * @brief This API read the threshold for orientation interrupt + * from the register 0x65 bit 0 and 1 + * + * @param v_orient_mode_u8 : The value of threshold for orientation + * value | Behaviour + * ----------|------------------- + * 0x00 | symmetrical + * 0x01 | high-asymmetrical + * 0x02 | low-asymmetrical + * 0x03 | symmetrical + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_mode( +u8 *v_orient_mode_u8); + /*! + * @brief This API write the threshold for orientation interrupt + * from the register 0x65 bit 0 and 1 + * + * @param v_orient_mode_u8 : The value of threshold for orientation + * value | Behaviour + * ----------|------------------- + * 0x00 | symmetrical + * 0x01 | high-asymmetrical + * 0x02 | low-asymmetrical + * 0x03 | symmetrical + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_mode( +u8 v_orient_mode_u8); +/***************************************************************/ +/**\name FUNCTION FOR ORIENT BLOCKING CONFIGURATION*/ +/***************************************************************/ +/*! + * @brief This API read the orient blocking mode + * that is used for the generation of the orientation interrupt. + * from the register 0x65 bit 2 and 3 + * + * @param v_orient_blocking_u8 : The value of orient blocking mode + * value | Behaviour + * ----------|------------------- + * 0x00 | No blocking + * 0x01 | Theta blocking or acceleration in any axis > 1.5g + * 0x02 | Theta blocking or acceleration slope in any axis > + * - | 0.2g or acceleration in any axis > 1.5g + * 0x03 | Theta blocking or acceleration slope in any axis > + * - | 0.4g or acceleration in any axis > + * - | 1.5g and value of orient is not stable + * - | for at least 100 ms + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_blocking( +u8 *v_orient_blocking_u8); +/*! + * @brief This API write the orient blocking mode + * that is used for the generation of the orientation interrupt. + * from the register 0x65 bit 2 and 3 + * + * @param v_orient_blocking_u8 : The value of orient blocking mode + * value | Behaviour + * ----------|------------------- + * 0x00 | No blocking + * 0x01 | Theta blocking or acceleration in any axis > 1.5g + * 0x02 | Theta blocking or acceleration slope in any axis > + * - | 0.2g or acceleration in any axis > 1.5g + * 0x03 | Theta blocking or acceleration slope in any axis > + * - | 0.4g or acceleration in any axis > + * - | 1.5g and value of orient is not stable + * - | for at least 100 ms + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_blocking( +u8 v_orient_blocking_u8); +/***************************************************************/ +/**\name FUNCTION FOR ORIENT HYSTERESIS CONFIGURATION*/ +/***************************************************************/ +/*! + * @brief This API read Orient interrupt + * hysteresis, from the register 0x64 bit 4 to 7 + * + * + * + * @param v_orient_hyst_u8 : The value of orient hysteresis + * + * @note 1 LSB corresponds to 62.5 mg, + * irrespective of the selected accel range + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_hyst( +u8 *v_orient_hyst_u8); +/*! + * @brief This API write Orient interrupt + * hysteresis, from the register 0x64 bit 4 to 7 + * + * + * + * @param v_orient_hyst_u8 : The value of orient hysteresis + * + * @note 1 LSB corresponds to 62.5 mg, + * irrespective of the selected accel range + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_hyst( +u8 v_orient_hyst_u8); +/***************************************************************/ +/**\name FUNCTION FOR ORIENT THETA CONFIGURATION*/ +/***************************************************************/ + /*! + * @brief This API read Orient + * blocking angle (0 to 44.8) from the register 0x66 bit 0 to 5 + * + * @param v_orient_theta_u8 : The value of Orient blocking angle + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_theta( +u8 *v_orient_theta_u8); + /*! + * @brief This API write Orient + * blocking angle (0 to 44.8) from the register 0x66 bit 0 to 5 + * + * @param v_orient_theta_u8 : The value of Orient blocking angle + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_theta( +u8 v_orient_theta_u8); +/***************************************************************/ +/**\name FUNCTION FOR ORIENT OUTPUT ENABLE CONFIGURATION*/ +/***************************************************************/ +/*! + * @brief This API read orient change + * of up/down bit from the register 0x66 bit 6 + * + * @param v_orient_ud_u8 : The value of orient change of up/down + * value | Behaviour + * ----------|------------------- + * 0x00 | Is ignored + * 0x01 | Generates orientation interrupt + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_ud_enable( +u8 *v_orient_ud_u8); +/*! + * @brief This API write orient change + * of up/down bit from the register 0x66 bit 6 + * + * @param v_orient_ud_u8 : The value of orient change of up/down + * value | Behaviour + * ----------|------------------- + * 0x00 | Is ignored + * 0x01 | Generates orientation interrupt + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_ud_enable( +u8 v_orient_ud_u8); +/***************************************************************/ +/**\name FUNCTION FOR ORIENT AXIS ENABLE CONFIGURATION*/ +/***************************************************************/ + /*! + * @brief This API read orientation axes changes + * from the register 0x66 bit 7 + * + * @param v_orient_axes_u8 : The value of orient axes assignment + * value | Behaviour | Name + * ----------|--------------------|------ + * 0x00 | x = x, y = y, z = z|orient_ax_noex + * 0x01 | x = y, y = z, z = x|orient_ax_ex + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_orient_axes_enable( +u8 *v_orient_axes_u8); + /*! + * @brief This API write orientation axes changes + * from the register 0x66 bit 7 + * + * @param v_orient_axes_u8 : The value of orient axes assignment + * value | Behaviour | Name + * ----------|--------------------|------ + * 0x00 | x = x, y = y, z = z|orient_ax_noex + * 0x01 | x = y, y = z, z = x|orient_ax_ex + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_orient_axes_enable( +u8 v_orient_axes_u8); +/***************************************************************/ +/**\name FUNCTION FOR FLAT THETA CONFIGURATION*/ +/***************************************************************/ + /*! + * @brief This API read Flat angle (0 to 44.8) for flat interrupt + * from the register 0x67 bit 0 to 5 + * + * @param v_flat_theta_u8 : The value of flat angle + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat_theta( +u8 *v_flat_theta_u8); + /*! + * @brief This API write Flat angle (0 to 44.8) for flat interrupt + * from the register 0x67 bit 0 to 5 + * + * @param v_flat_theta_u8 : The value of flat angle + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat_theta( +u8 v_flat_theta_u8); +/***************************************************************/ +/**\name FUNCTION FOR FLAT HOLD CONFIGURATION*/ +/***************************************************************/ +/*! + * @brief This API read Flat interrupt hold time; + * from the register 0x68 bit 4 and 5 + * + * @param v_flat_hold_u8 : The value of flat hold time + * value | Behaviour + * ----------|------------------- + * 0x00 | 0ms + * 0x01 | 512ms + * 0x01 | 1024ms + * 0x01 | 2048ms + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat_hold( +u8 *v_flat_hold_u8); +/*! + * @brief This API write Flat interrupt hold time; + * from the register 0x68 bit 4 and 5 + * + * @param v_flat_hold_u8 : The value of flat hold time + * value | Behaviour + * ----------|------------------- + * 0x00 | 0ms + * 0x01 | 512ms + * 0x01 | 1024ms + * 0x01 | 2048ms + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat_hold( +u8 v_flat_hold_u8); +/***************************************************************/ +/**\name FUNCTION FOR FLAT HYSTERESIS CONFIGURATION*/ +/***************************************************************/ +/*! + * @brief This API read flat interrupt hysteresis + * from the register 0x68 bit 0 to 3 + * + * @param v_flat_hyst_u8 : The value of flat hysteresis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_intr_flat_hyst( +u8 *v_flat_hyst_u8); +/*! + * @brief This API write flat interrupt hysteresis + * from the register 0x68 bit 0 to 3 + * + * @param v_flat_hyst_u8 : The value of flat hysteresis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_intr_flat_hyst( +u8 v_flat_hyst_u8); +/***************************************************************/ +/**\name FUNCTION FAST OFFSET COMPENSATION FOR ACCEL */ +/***************************************************************/ + /*! + * @brief This API read accel offset compensation + * target value for z-axis from the register 0x69 bit 0 and 1 + * + * @param v_foc_accel_z_u8 : the value of accel offset compensation z axis + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_accel_z( +u8 *v_foc_accel_z_u8); + /*! + * @brief This API write accel offset compensation + * target value for z-axis from the register 0x69 bit 0 and 1 + * + * @param v_foc_accel_z_u8 : the value of accel offset compensation z axis + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_accel_z( +u8 v_foc_accel_z_u8); +/*! + * @brief This API read accel offset compensation + * target value for y-axis + * from the register 0x69 bit 2 and 3 + * + * @param v_foc_accel_y_u8 : the value of accel offset compensation y axis + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_accel_y( +u8 *v_foc_accel_y_u8); +/*! + * @brief This API write accel offset compensation + * target value for y-axis + * from the register 0x69 bit 2 and 3 + * + * @param v_foc_accel_y_u8 : the value of accel offset compensation y axis + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_accel_y( +u8 v_foc_accel_y_u8); +/*! + * @brief This API read accel offset compensation + * target value for x-axis is + * from the register 0x69 bit 4 and 5 + * + * @param v_foc_accel_x_u8 : the value of accel offset compensation x axis + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_accel_x( +u8 *v_foc_accel_x_u8); +/*! + * @brief This API write accel offset compensation + * target value for x-axis is + * from the register 0x69 bit 4 and 5 + * + * @param v_foc_accel_x_u8 : the value of accel offset compensation x axis + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_accel_x( +u8 v_foc_accel_x_u8); +/***************************************************************/ +/**\name FUNCTION FAST OFFSET COMPENSATION FOR GYRO */ +/***************************************************************/ +/*! + * @brief This API write gyro fast offset enable + * from the register 0x69 bit 6 + * + * @param v_foc_gyro_u8 : The value of gyro fast offset enable + * value | Description + * ----------|------------- + * 0 | fast offset compensation disabled + * 1 | fast offset compensation enabled + * + * @param v_gyro_off_x_s16 : The value of gyro fast offset x axis data + * @param v_gyro_off_y_s16 : The value of gyro fast offset y axis data + * @param v_gyro_off_z_s16 : The value of gyro fast offset z axis data + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_foc_gyro_enable( +u8 v_foc_gyro_u8, s16 *v_gyro_off_x_s16, +s16 *v_gyro_off_y_s16, s16 *v_gyro_off_z_s16); +/***************************************************/ +/**\name FUNCTION FOR NVM*/ +/***************************************************/ + /*! + * @brief This API read NVM program enable + * from the register 0x6A bit 1 + * + * @param v_nvm_prog_u8 : The value of NVM program enable + * Value | Description + * --------|------------- + * 0 | DISABLE + * 1 | ENABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_nvm_prog_enable( +u8 *v_nvm_prog_u8); + /*! + * @brief This API write NVM program enable + * from the register 0x6A bit 1 + * + * @param v_nvm_prog_u8 : The value of NVM program enable + * Value | Description + * --------|------------- + * 0 | DISABLE + * 1 | ENABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_nvm_prog_enable( +u8 v_nvm_prog_u8); +/***************************************************/ +/**\name FUNCTION FOR SPI MODE*/ +/***************************************************/ +/*! + * @brief This API read to configure SPI + * Interface Mode for primary and OIS interface + * from the register 0x6B bit 0 + * + * @param v_spi3_u8 : The value of SPI mode selection + * Value | Description + * --------|------------- + * 0 | SPI 4-wire mode + * 1 | SPI 3-wire mode + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_get_spi3( +u8 *v_spi3_u8); +/*! + * @brief This API write to configure SPI + * Interface Mode for primary and OIS interface + * from the register 0x6B bit 0 + * + * @param v_spi3_u8 : The value of SPI mode selection + * Value | Description + * --------|------------- + * 0 | SPI 4-wire mode + * 1 | SPI 3-wire mode + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_spi3( +u8 v_spi3_u8); +/***************************************************/ +/**\name FUNCTION FOR FOC GYRO */ +/***************************************************/ +/*! + * @brief This API read gyro fast offset enable + * from the register 0x69 bit 6 + * + * @param v_foc_gyro_u8 : The value of gyro fast offset enable + * value | Description + * ----------|------------- + * 0 | fast offset compensation disabled + * 1 | fast offset compensation enabled + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_foc_gyro_enable( +u8 *v_foc_gyro_u8); +/***************************************************/ +/**\name FUNCTION FOR I2C WATCHDOG TIMBER */ +/***************************************************/ +/*! + * @brief This API read I2C Watchdog timer + * from the register 0x70 bit 1 + * + * @param v_i2c_wdt_u8 : The value of I2C watch dog timer + * Value | Description + * --------|------------- + * 0 | I2C watchdog v_timeout_u8 after 1 ms + * 1 | I2C watchdog v_timeout_u8 after 50 ms + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_wdt_select( +u8 *v_i2c_wdt_u8); +/*! + * @brief This API write I2C Watchdog timer + * from the register 0x70 bit 1 + * + * @param v_i2c_wdt_u8 : The value of I2C watch dog timer + * Value | Description + * --------|------------- + * 0 | I2C watchdog v_timeout_u8 after 1 ms + * 1 | I2C watchdog v_timeout_u8 after 50 ms + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE +smi130_set_i2c_wdt_select(u8 v_i2c_wdt_u8); +/*! + * @brief This API read I2C watchdog enable + * from the register 0x70 bit 2 + * + * @param v_i2c_wdt_u8 : The value of I2C watchdog enable + * Value | Description + * --------|------------- + * 0 | DISABLE + * 1 | ENABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_i2c_wdt_enable( +u8 *v_i2c_wdt_u8); +/*! + * @brief This API write I2C watchdog enable + * from the register 0x70 bit 2 + * + * @param v_i2c_wdt_u8 : The value of I2C watchdog enable + * Value | Description + * --------|------------- + * 0 | DISABLE + * 1 | ENABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_i2c_wdt_enable( +u8 v_i2c_wdt_u8); +/***************************************************/ +/**\name FUNCTION FOR IF MODE*/ +/***************************************************/ +/*! + * @brief This API read I2C interface configuration(if) moe + * from the register 0x6B bit 4 and 5 + * + * @param v_if_mode_u8 : The value of interface configuration mode + * Value | Description + * --------|------------- + * 0x00 | Primary interface:autoconfig / secondary interface:off + * 0x01 | Primary interface:I2C / secondary interface:OIS + * 0x02 | Primary interface:autoconfig/secondary interface:Magnetometer + * 0x03 | Reserved + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_if_mode( +u8 *v_if_mode_u8); +/*! + * @brief This API write I2C interface configuration(if) moe + * from the register 0x6B bit 4 and 5 + * + * @param v_if_mode_u8 : The value of interface configuration mode + * Value | Description + * --------|------------- + * 0x00 | Primary interface:autoconfig / secondary interface:off + * 0x01 | Primary interface:I2C / secondary interface:OIS + * 0x02 | Primary interface:autoconfig/secondary interface:Magnetometer + * 0x03 | Reserved + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_if_mode( +u8 v_if_mode_u8); +/***************************************************/ +/**\name FUNCTION FOR GYRO SLEEP TRIGGER INTERRUPT CONFIGURATION*/ +/***************************************************/ +/*! + * @brief This API read gyro sleep trigger + * from the register 0x6C bit 0 to 2 + * + * @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger + * Value | Description + * --------|------------- + * 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no + * 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes + * 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no + * 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes + * 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no + * 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes + * 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no + * 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_sleep_trigger( +u8 *v_gyro_sleep_trigger_u8); +/*! + * @brief This API write gyro sleep trigger + * from the register 0x6C bit 0 to 2 + * + * @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger + * Value | Description + * --------|------------- + * 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no + * 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes + * 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no + * 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes + * 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no + * 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes + * 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no + * 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_sleep_trigger( +u8 v_gyro_sleep_trigger_u8); +/*! + * @brief This API read gyro wakeup trigger + * from the register 0x6C bit 3 and 4 + * + * @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger + * Value | Description + * --------|------------- + * 0x00 | anymotion: no / INT1 pin: no + * 0x01 | anymotion: no / INT1 pin: yes + * 0x02 | anymotion: yes / INT1 pin: no + * 0x03 | anymotion: yes / INT1 pin: yes + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_wakeup_trigger( +u8 *v_gyro_wakeup_trigger_u8); +/*! + * @brief This API write gyro wakeup trigger + * from the register 0x6C bit 3 and 4 + * + * @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger + * Value | Description + * --------|------------- + * 0x00 | anymotion: no / INT1 pin: no + * 0x01 | anymotion: no / INT1 pin: yes + * 0x02 | anymotion: yes / INT1 pin: no + * 0x03 | anymotion: yes / INT1 pin: yes + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_wakeup_trigger( +u8 v_gyro_wakeup_trigger_u8); +/*! + * @brief This API read Target state for gyro sleep mode + * from the register 0x6C bit 5 + * + * @param v_gyro_sleep_state_u8 : The value of gyro sleep mode + * Value | Description + * --------|------------- + * 0x00 | Sleep transition to fast wake up state + * 0x01 | Sleep transition to suspend state + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_sleep_state( +u8 *v_gyro_sleep_state_u8); +/*! + * @brief This API write Target state for gyro sleep mode + * from the register 0x6C bit 5 + * + * @param v_gyro_sleep_state_u8 : The value of gyro sleep mode + * Value | Description + * --------|------------- + * 0x00 | Sleep transition to fast wake up state + * 0x01 | Sleep transition to suspend state + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_sleep_state( +u8 v_gyro_sleep_state_u8); +/*! + * @brief This API read gyro wakeup interrupt + * from the register 0x6C bit 6 + * + * @param v_gyro_wakeup_intr_u8 : The valeu of gyro wakeup interrupt + * Value | Description + * --------|------------- + * 0x00 | DISABLE + * 0x01 | ENABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_wakeup_intr( +u8 *v_gyro_wakeup_intr_u8); +/*! + * @brief This API write gyro wakeup interrupt + * from the register 0x6C bit 6 + * + * @param v_gyro_wakeup_intr_u8 : The valeu of gyro wakeup interrupt + * Value | Description + * --------|------------- + * 0x00 | DISABLE + * 0x01 | ENABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_wakeup_intr( +u8 v_gyro_wakeup_intr_u8); +/***************************************************/ +/**\name FUNCTION FOR ACCEL SELF TEST */ +/***************************************************/ +/*! + * @brief This API read accel select axis to be self-test + * + * @param v_accel_selftest_axis_u8 : + * The value of accel self test axis selection + * Value | Description + * --------|------------- + * 0x00 | disabled + * 0x01 | x-axis + * 0x02 | y-axis + * 0x03 | z-axis + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_selftest_axis( +u8 *acc_selftest_axis); +/*! + * @brief This API write accel select axis to be self-test + * + * @param v_accel_selftest_axis_u8 : + * The value of accel self test axis selection + * Value | Description + * --------|------------- + * 0x00 | disabled + * 0x01 | x-axis + * 0x02 | y-axis + * 0x03 | z-axis + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_selftest_axis( +u8 acc_selftest_axis); +/*! + * @brief This API read accel self test axis sign + * from the register 0x6D bit 2 + * + * @param v_accel_selftest_sign_u8: The value of accel self test axis sign + * Value | Description + * --------|------------- + * 0x00 | negative + * 0x01 | positive + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_selftest_sign( +u8 *acc_selftest_sign); +/*! + * @brief This API write accel self test axis sign + * from the register 0x6D bit 2 + * + * @param v_accel_selftest_sign_u8: The value of accel self test axis sign + * Value | Description + * --------|------------- + * 0x00 | negative + * 0x01 | positive + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_selftest_sign( +u8 acc_selftest_sign); +/*! + * @brief This API read accel self test amplitude + * from the register 0x6D bit 3 + * select amplitude of the selftest deflection: + * + * @param v_accel_selftest_amp_u8 : The value of accel self test amplitude + * Value | Description + * --------|------------- + * 0x00 | LOW + * 0x01 | HIGH + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_selftest_amp( +u8 *acc_selftest_amp); +/*! + * @brief This API write accel self test amplitude + * from the register 0x6D bit 3 + * select amplitude of the selftest deflection: + * + * @param v_accel_selftest_amp_u8 : The value of accel self test amplitude + * Value | Description + * --------|------------- + * 0x00 | LOW + * 0x01 | HIGH + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_selftest_amp( +u8 acc_selftest_amp); +/***************************************************/ +/**\name FUNCTION FOR GYRO SELF TEST */ +/***************************************************/ +/*! + * @brief This API read gyro self test trigger + * + * @param v_gyro_selftest_start_u8: The value of gyro self test start + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_selftest_start( +u8 *v_gyro_selftest_start_u8); +/*! + * @brief This API write gyro self test trigger + * + * @param v_gyro_selftest_start_u8: The value of gyro self test start + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_selftest_start( +u8 v_gyro_selftest_start_u8); +/***************************************************/ +/**\name FUNCTION FOR SPI/I2C ENABLE */ +/***************************************************/ + /*! + * @brief This API read primary interface selection I2C or SPI + * from the register 0x70 bit 0 + * + * @param v_spi_enable_u8: The value of Interface selection + * Value | Description + * --------|------------- + * 0x00 | I2C Enable + * 0x01 | I2C DISBALE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_spi_enable( +u8 *v_spi_enable_u8); + /*! + * @brief This API write primary interface selection I2C or SPI + * from the register 0x70 bit 0 + * + * @param v_spi_enable_u8: The value of Interface selection + * Value | Description + * --------|------------- + * 0x00 | I2C Enable + * 0x01 | I2C DISBALE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_spi_enable( +u8 v_spi_enable_u8); + /*! + * @brief This API read the spare zero + * form register 0x70 bit 3 + * + * + * @param v_spare0_trim_u8: The value of spare zero + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_spare0_trim +(u8 *v_spare0_trim_u8); + /*! + * @brief This API write the spare zero + * form register 0x70 bit 3 + * + * + * @param v_spare0_trim_u8: The value of spare zero + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_spare0_trim +(u8 v_spare0_trim_u8); +/***************************************************/ +/**\name FUNCTION FOR NVM COUNTER */ +/***************************************************/ + /*! + * @brief This API read the NVM counter + * form register 0x70 bit 4 to 7 + * + * + * @param v_nvm_counter_u8: The value of NVM counter + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_nvm_counter( +u8 *v_nvm_counter_u8); + /*! + * @brief This API write the NVM counter + * form register 0x70 bit 4 to 7 + * + * + * @param v_nvm_counter_u8: The value of NVM counter + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_nvm_counter( +u8 v_nvm_counter_u8); +/***************************************************/ +/**\name FUNCTION FOR ACCEL MANUAL OFFSET COMPENSATION */ +/***************************************************/ +/*! + * @brief This API read accel manual offset compensation of x axis + * from the register 0x71 bit 0 to 7 + * + * + * + * @param v_accel_off_x_s8: + * The value of accel manual offset compensation of x axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_compensation_xaxis( +s8 *v_accel_off_x_s8); +/*! + * @brief This API write accel manual offset compensation of x axis + * from the register 0x71 bit 0 to 7 + * + * + * + * @param v_accel_off_x_s8: + * The value of accel manual offset compensation of x axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_compensation_xaxis( +s8 v_accel_off_x_s8); +/*! + * @brief This API read accel manual offset compensation of y axis + * from the register 0x72 bit 0 to 7 + * + * + * + * @param v_accel_off_y_s8: + * The value of accel manual offset compensation of y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_compensation_yaxis( +s8 *v_accel_off_y_s8); +/*! + * @brief This API write accel manual offset compensation of y axis + * from the register 0x72 bit 0 to 7 + * + * + * + * @param v_accel_off_y_s8: + * The value of accel manual offset compensation of y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_compensation_yaxis( +s8 v_accel_off_y_s8); +/*! + * @brief This API read accel manual offset compensation of z axis + * from the register 0x73 bit 0 to 7 + * + * + * + * @param v_accel_off_z_s8: + * The value of accel manual offset compensation of z axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_compensation_zaxis( +s8 *v_accel_off_z_s8); +/*! + * @brief This API write accel manual offset compensation of z axis + * from the register 0x73 bit 0 to 7 + * + * + * + * @param v_accel_off_z_s8: + * The value of accel manual offset compensation of z axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_compensation_zaxis( +s8 v_accel_off_z_s8); +/***************************************************/ +/**\name FUNCTION FOR GYRO MANUAL OFFSET COMPENSATION */ +/***************************************************/ +/*! + * @brief This API read gyro manual offset compensation of x axis + * from the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1 + * + * + * + * @param v_gyro_off_x_s16: + * The value of gyro manual offset compensation of x axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_compensation_xaxis( +s16 *v_gyro_off_x_s16); +/*! + * @brief This API write gyro manual offset compensation of x axis + * from the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1 + * + * + * + * @param v_gyro_off_x_s16: + * The value of gyro manual offset compensation of x axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_compensation_xaxis( +s16 v_gyro_off_x_s16); +/*! + * @brief This API read gyro manual offset compensation of y axis + * from the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3 + * + * + * + * @param v_gyro_off_y_s16: + * The value of gyro manual offset compensation of y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_compensation_yaxis( +s16 *v_gyro_off_y_s16); +/*! + * @brief This API write gyro manual offset compensation of y axis + * from the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3 + * + * + * + * @param v_gyro_off_y_s16: + * The value of gyro manual offset compensation of y axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_compensation_yaxis( +s16 v_gyro_off_y_s16); +/*! + * @brief This API read gyro manual offset compensation of z axis + * from the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5 + * + * + * + * @param v_gyro_off_z_s16: + * The value of gyro manual offset compensation of z axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_compensation_zaxis( +s16 *v_gyro_off_z_s16); +/*! + * @brief This API write gyro manual offset compensation of z axis + * from the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5 + * + * + * + * @param v_gyro_off_z_s16: + * The value of gyro manual offset compensation of z axis + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_compensation_zaxis( +s16 v_gyro_off_z_s16); +/*! + * @brief This API writes accel fast offset compensation + * from the register 0x69 bit 0 to 5 + * @brief This API writes each axis individually + * FOC_X_AXIS - bit 4 and 5 + * FOC_Y_AXIS - bit 2 and 3 + * FOC_Z_AXIS - bit 0 and 1 + * + * @param v_foc_accel_u8: The value of accel offset compensation + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * @param v_axis_u8: The value of accel offset axis selection + * value | axis + * ----------|------------------- + * 0 | FOC_X_AXIS + * 1 | FOC_Y_AXIS + * 2 | FOC_Z_AXIS + * + * @param v_accel_offset_s8: The accel offset value + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_foc_trigger(u8 axis, +u8 foc_acc, s8 *accel_offset); +/*! + * @brief This API write fast accel offset compensation + * it writes all axis together.To the register 0x69 bit 0 to 5 + * FOC_X_AXIS - bit 4 and 5 + * FOC_Y_AXIS - bit 2 and 3 + * FOC_Z_AXIS - bit 0 and 1 + * + * @param v_foc_accel_x_u8: The value of accel offset x compensation + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * @param v_foc_accel_y_u8: The value of accel offset y compensation + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * @param v_foc_accel_z_u8: The value of accel offset z compensation + * value | Behaviour + * ----------|------------------- + * 0x00 | disable + * 0x01 | +1g + * 0x01 | -1g + * 0x01 | 0g + * + * @param v_accel_off_x_s8: The value of accel offset x axis + * @param v_accel_off_y_s8: The value of accel offset y axis + * @param v_accel_off_z_s8: The value of accel offset z axis + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_accel_foc_trigger_xyz(u8 v_foc_accel_x_u8, +u8 v_foc_accel_y_u8, u8 v_foc_accel_z_u8, +s8 *acc_off_x, s8 *acc_off_y, s8 *acc_off_z); +/***************************************************/ +/**\name FUNCTION FOR ACEL AND GYRO OFFSET ENABLE */ +/***************************************************/ +/*! + * @brief This API read the accel offset enable bit + * from the register 0x77 bit 6 + * + * + * + * @param v_accel_off_enable_u8: The value of accel offset enable + * value | Description + * ----------|-------------- + * 0x01 | ENABLE + * 0x00 | DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_accel_offset_enable( +u8 *acc_off_en); +/*! + * @brief This API write the accel offset enable bit + * from the register 0x77 bit 6 + * + * + * + * @param v_accel_off_enable_u8: The value of accel offset enable + * value | Description + * ----------|-------------- + * 0x01 | ENABLE + * 0x00 | DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_accel_offset_enable( +u8 acc_off_en); +/*! + * @brief This API read the accel offset enable bit + * from the register 0x77 bit 7 + * + * + * + * @param v_gyro_off_enable_u8: The value of gyro offset enable + * value | Description + * ----------|-------------- + * 0x01 | ENABLE + * 0x00 | DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_gyro_offset_enable( +u8 *v_gyro_off_enable_u8); +/*! + * @brief This API write the accel offset enable bit + * from the register 0x77 bit 7 + * + * + * + * @param v_gyro_off_enable_u8: The value of gyro offset enable + * value | Description + * ----------|-------------- + * 0x01 | ENABLE + * 0x00 | DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_gyro_offset_enable( +u8 v_gyro_off_enable_u8); +/***************************************************/ +/**\name FUNCTION FOR STEP COUNTER INTERRUPT */ +/***************************************************/ +/*! + * @brief This API reads step counter value + * form the register 0x78 and 0x79 + * + * + * + * + * @param v_step_cnt_s16 : The value of step counter + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_read_step_count(u16 *v_step_cnt_s16); + /*! + * @brief This API Reads + * step counter configuration + * from the register 0x7A bit 0 to 7 + * and from the register 0x7B bit 0 to 2 and 4 to 7 + * + * + * @param v_step_config_u16 : The value of step configuration + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_step_config( +u16 *v_step_config_u16); + /*! + * @brief This API write + * step counter configuration + * from the register 0x7A bit 0 to 7 + * and from the register 0x7B bit 0 to 2 and 4 to 7 + * + * + * @param v_step_config_u16 : + * the value of Enable step configuration + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_config( +u16 v_step_config_u16); + /*! + * @brief This API read enable step counter + * from the register 0x7B bit 3 + * + * + * @param v_step_counter_u8 : The value of step counter enable + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_step_counter_enable( +u8 *v_step_counter_u8); + /*! + * @brief This API write enable step counter + * from the register 0x7B bit 3 + * + * + * @param v_step_counter_u8 : The value of step counter enable + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_counter_enable( +u8 v_step_counter_u8); + /*! + * @brief This API set Step counter modes + * + * + * @param v_step_mode_u8 : The value of step counter mode + * value | mode + * ----------|----------- + * 0 | SMI130_STEP_NORMAL_MODE + * 1 | SMI130_STEP_SENSITIVE_MODE + * 2 | SMI130_STEP_ROBUST_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_step_mode(u8 v_step_mode_u8); +/*! + * @brief This API used to trigger the signification motion + * interrupt + * + * + * @param v_significant_u8 : The value of interrupt selection + * value | interrupt + * ----------|----------- + * 0 | SMI130_MAP_INTR1 + * 1 | SMI130_MAP_INTR2 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_map_significant_motion_intr( +u8 v_significant_u8); +/*! + * @brief This API used to trigger the step detector + * interrupt + * + * + * @param v_step_detector_u8 : The value of interrupt selection + * value | interrupt + * ----------|----------- + * 0 | SMI130_MAP_INTR1 + * 1 | SMI130_MAP_INTR2 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_map_step_detector_intr( +u8 v_step_detector_u8); + /*! + * @brief This API used to clear the step counter interrupt + * interrupt + * + * + * @param : None + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_clear_step_counter(void); +/***************************************************/ +/**\name FUNCTION FOR STEP COMMAND REGISTER WRITE */ +/***************************************************/ + /*! + * @brief This API writes value to the register 0x7E bit 0 to 7 + * + * + * @param v_command_reg_u8 : The value to write command register + * value | Description + * ---------|-------------------------------------------------------- + * 0x00 | Reserved + * 0x03 | Starts fast offset calibration for the accel and gyro + * 0x10 | Sets the PMU mode for the Accelerometer to suspend + * 0x11 | Sets the PMU mode for the Accelerometer to normal + * 0x12 | Sets the PMU mode for the Accelerometer Lowpower + * 0x14 | Sets the PMU mode for the Gyroscope to suspend + * 0x15 | Sets the PMU mode for the Gyroscope to normal + * 0x16 | Reserved + * 0x17 | Sets the PMU mode for the Gyroscope to fast start-up + * 0x18 | Sets the PMU mode for the Magnetometer to suspend + * 0x19 | Sets the PMU mode for the Magnetometer to normal + * 0x1A | Sets the PMU mode for the Magnetometer to Lowpower + * 0xB0 | Clears all data in the FIFO + * 0xB1 | Resets the interrupt engine + * 0xB2 | step_cnt_clr Clears the step counter + * 0xB6 | Triggers a reset + * 0x37 | See extmode_en_last + * 0x9A | See extmode_en_last + * 0xC0 | Enable the extended mode + * 0xC4 | Erase NVM cell + * 0xC8 | Load NVM cell + * 0xF0 | Reset acceleration data path + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_command_register( +u8 v_command_reg_u8); +/***************************************************/ +/**\name FUNCTION FOR PAGE ENABLE */ +/***************************************************/ + /*! + * @brief This API read target page from the register 0x7F bit 4 and 5 + * + * @param v_target_page_u8: The value of target page + * value | page + * ---------|----------- + * 0 | User data/configure page + * 1 | Chip level trim/test page + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_target_page( +u8 *v_target_page_u8); + /*! + * @brief This API write target page from the register 0x7F bit 4 and 5 + * + * @param v_target_page_u8: The value of target page + * value | page + * ---------|----------- + * 0 | User data/configure page + * 1 | Chip level trim/test page + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_target_page( +u8 v_target_page_u8); + /*! + * @brief This API read page enable from the register 0x7F bit 7 + * + * + * + * @param v_page_enable_u8: The value of page enable + * value | page + * ---------|----------- + * 0 | DISABLE + * 1 | ENABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_paging_enable( +u8 *v_page_enable_u8); + /*! + * @brief This API write page enable from the register 0x7F bit 7 + * + * + * + * @param v_page_enable_u8: The value of page enable + * value | page + * ---------|----------- + * 0 | DISABLE + * 1 | ENABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_paging_enable( +u8 v_page_enable_u8); + /*! + * @brief This API read + * pull up configuration from the register 0X85 bit 4 an 5 + * + * + * + * @param v_control_pullup_u8: The value of pull up register + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_get_pullup_configuration( +u8 *v_control_pullup_u8); + /*! + * @brief This API write + * pull up configuration from the register 0X85 bit 4 an 5 + * + * + * + * @param v_control_pullup_u8: The value of pull up register + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_pullup_configuration( +u8 v_control_pullup_u8); +/***************************************************/ +/**\name FUNCTION FOR BMM150 */ +/***************************************************/ + /*! + * @brief This function used for initialize the bmm150 sensor + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_interface_init(void); + /*! + * @brief This function used for set the mag power control + * bit enable + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_wakeup(void); + /*! + * @brief This function used for read the trim values of magnetometer + * + * @note + * Before reading the mag trimming values + * make sure the following two points are addressed + * @note + * 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_bmm150_mag_trim(void); + /*! + * @brief This function used for read the compensated value of mag + * Before start reading the mag compensated data's + * make sure the following two points are addressed + * @note + * 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_compensate_xyz( +struct smi130_mag_xyz_s32_t *mag_comp_xyz); +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_compensate_xyz_raw( +struct smi130_mag_xyz_s32_t *mag_comp_xyz, struct smi130_mag_xyzr_t mag_xyzr); + +/*! + * @brief This API used to get the compensated BMM150-X data + * the out put of X as s32 + * Before start reading the mag compensated X data + * make sure the following two points are addressed + * @note + * 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * + * @param v_mag_data_x_s16 : The value of mag raw X data + * @param v_data_r_u16 : The value of mag R data + * + * @return results of compensated X data value output as s32 + * + */ +s32 smi130_bmm150_mag_compensate_X(s16 v_mag_data_x_s16, u16 v_data_r_u16); +/*! + * @brief This API used to get the compensated BMM150-Y data + * the out put of Y as s32 + * Before start reading the mag compensated Y data + * make sure the following two points are addressed + * @note + * 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * + * @param v_mag_data_y_s16 : The value of mag raw Y data + * @param v_data_r_u16 : The value of mag R data + * + * @return results of compensated Y data value output as s32 + */ +s32 smi130_bmm150_mag_compensate_Y(s16 v_mag_data_y_s16, u16 v_data_r_u16); +/*! + * @brief This API used to get the compensated BMM150-Z data + * the out put of Z as s32 + * Before start reading the mag compensated Z data + * make sure the following two points are addressed + * @note + * 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * + * @param v_mag_data_z_s16 : The value of mag raw Z data + * @param v_data_r_u16 : The value of mag R data + * + * @return results of compensated Z data value output as s32 + */ +s32 smi130_bmm150_mag_compensate_Z(s16 v_mag_data_z_s16, u16 v_data_r_u16); +/*! + * @brief This API used to set the pre-set modes of bmm150 + * The pre-set mode setting is depend on data rate and xy and z repetitions + * + * @note + * Before set the mag preset mode + * make sure the following two points are addressed + * @note + * 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * @param v_mode_u8: The value of pre-set mode selection value + * value | pre_set mode + * ----------|------------ + * 1 | SMI130_MAG_PRESETMODE_LOWPOWER + * 2 | SMI130_MAG_PRESETMODE_REGULAR + * 3 | SMI130_MAG_PRESETMODE_HIGHACCURACY + * 4 | SMI130_MAG_PRESETMODE_ENHANCED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_set_bmm150_mag_presetmode(u8 mode); +/*! + * @brief This function used for set the magnetometer + * power mode. + * @note + * Before set the mag power mode + * make sure the following two points are addressed + * @note + * 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * @param v_mag_pow_mode_u8 : The value of mag power mode + * value | mode + * ----------|------------ + * 0 | FORCE_MODE + * 1 | SUSPEND_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bmm150_mag_set_power_mode(u8 mag_pow_mode); + /*! + * @brief This function used for set the magnetometer + * power mode. + * @note + * Before set the mag power mode + * make sure the following two point is addressed + * Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * + * @param v_mag_sec_if_pow_mode_u8 : The value of mag power mode + * value | mode + * ----------|------------ + * 0 | SMI130_MAG_FORCE_MODE + * 1 | SMI130_MAG_SUSPEND_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_bmm150_mag_and_secondary_if_power_mode( +u8 v_mag_sec_if_pow_mode_u8); +/***************************************************/ +/**\name FUNCTIONS FOR AKM09911 AND AKM09912*/ +/***************************************************/ + /*! + * @brief This function used for initialize + * the AKM09911 and AKM09912 sensor + * + * + * @param v_akm_i2c_address_u8: The value of device address + * AKM sensor | Slave address + * --------------|--------------------- + * AKM09911 | AKM09911_I2C_ADDR_1 + * - | and AKM09911_I2C_ADDR_2 + * AKM09912 | AKM09912_I2C_ADDR_1 + * - | AKM09912_I2C_ADDR_2 + * - | AKM09912_I2C_ADDR_3 + * - | AKM09912_I2C_ADDR_4 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm_mag_interface_init( +u8 v_akm_i2c_address_u8); + /*! + * @brief This function used for read the sensitivity data of + * AKM09911 and AKM09912 + * + * @note Before reading the mag sensitivity values + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_read_bosch_akm_sensitivity_data(void); +/*! + * @brief This API used to get the compensated X data + * of AKM09911 the out put of X as s32 + * @note Before start reading the mag compensated X data + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * @param v_bosch_akm_x_s16 : The value of X data + * + * @return results of compensated X data value output as s32 + * + */ +s32 smi130_bosch_akm09911_compensate_X(s16 v_bosch_akm_x_s16); +/*! + * @brief This API used to get the compensated Y data + * of AKM09911 the out put of Y as s32 + * @note Before start reading the mag compensated Y data + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * @param v_bosch_akm_y_s16 : The value of Y data + * + * @return results of compensated Y data value output as s32 + * + */ +s32 smi130_bosch_akm09911_compensate_Y(s16 v_bosch_akm_y_s16); +/*! + * @brief This API used to get the compensated Z data + * of AKM09911 the out put of Z as s32 + * @note Before start reading the mag compensated Z data + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * @param v_bosch_akm_z_s16 : The value of Z data + * + * @return results of compensated Z data value output as s32 + * + */ +s32 smi130_bosch_akm09911_compensate_Z(s16 v_bosch_akm_z_s16); +/*! + * @brief This API used to get the compensated X data + * of AKM09912 the out put of X as s32 + * @note Before start reading the mag compensated X data + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * @param v_bosch_akm_x_s16 : The value of X data + * + * @return results of compensated X data value output as s32 + * + */ +s32 smi130_bosch_akm09912_compensate_X(s16 v_bosch_akm_x_s16); +/*! + * @brief This API used to get the compensated Y data + * of AKM09912 the out put of Y as s32 + * @note Before start reading the mag compensated Y data + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * @param v_bosch_akm_y_s16 : The value of Y data + * + * @return results of compensated Y data value output as s32 + * + */ +s32 smi130_bosch_akm09912_compensate_Y(s16 v_bosch_akm_y_s16); +/*! + * @brief This API used to get the compensated Z data + * of AKM09912 the out put of Z as s32 + * @note Before start reading the mag compensated Z data + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * + * @param v_bosch_akm_z_s16 : The value of Z data + * + * @return results of compensated Z data value output as s32 + * + */ +s32 smi130_bosch_akm09912_compensate_Z(s16 v_bosch_akm_z_s16); + /*! + * @brief This function used for read the compensated value of + * AKM09911 + * @note Before start reading the mag compensated data's + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm09911_compensate_xyz( +struct smi130_mag_xyz_s32_t *bosch_akm_xyz); + /*! + * @brief This function used for read the compensated value of + * AKM09912 + * @note Before start reading the mag compensated data's + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm09912_compensate_xyz( +struct smi130_mag_xyz_s32_t *bosch_akm_xyz); +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm09912_compensate_xyz_raw( +struct smi130_mag_xyz_s32_t *bosch_akm_xyz); +/*! + * @brief This function used for set the AKM09911 and AKM09912 + * power mode. + * @note Before set the AKM power mode + * make sure the following two points are addressed + * @note 1. Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function smi130_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * smi130_set_command_register(0x19) function. + * + * @param v_akm_pow_mode_u8 : The value of akm power mode + * value | Description + * ---------|-------------------- + * 0 | AKM_POWER_DOWN_MODE + * 1 | AKM_SINGLE_MEAS_MODE + * 2 | FUSE_ROM_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_akm_set_powermode(u8 v_akm_pow_mode_u8); + /*! + * @brief This function used for set the magnetometer + * power mode of AKM09911 and AKM09912 + * @note Before set the mag power mode + * make sure the following two point is addressed + * Make sure the mag interface is enabled or not, + * by using the smi130_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function smi130_get_if_mode(0x02) + * + * @param v_mag_sec_if_pow_mode_u8 : The value of secondary if power mode + * value | Description + * ---------|-------------------- + * 0 | SMI130_MAG_FORCE_MODE + * 1 | SMI130_MAG_SUSPEND_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_set_bosch_akm_and_secondary_if_powermode( +u8 v_mag_sec_if_pow_mode_u8); +/***************************************************/ +/**\name FUNCTIONS FOR YAMAH-YAS532 */ +/***************************************************/ +/*! + * @brief This function used for read the YAMAH-YAS532 init + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas532_mag_interface_init( +void); +/*! + * @brief This function used to set the YAS532 initial values + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_set_initial_values(void); +/*! + * @brief This function used for YAS532 offset correction + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_magnetic_measure_set_offset( +void); +/*! + * @brief This function used for read the + * YAMAHA YAS532 calibration data + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas532_calib_values(void); +/*! + * @brief This function used for calculate the + * YAS532 read the linear data + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_xy1y2_to_linear( +u16 *v_xy1y2_u16, s32 *xy1y2_linear); +/*! + * @brief This function used for read the YAS532 sensor data + * @param v_acquisition_command_u8: used to set the data acquisition + * acquisition_command | operation + * ---------------------|------------------------- + * 0x17 | turn on the acquisition coil + * - | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Deferred acquisition mode + * 0x07 | turn on the acquisition coil + * _ | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Normal acquisition mode + * 0x11 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Deferred acquisition mode + * 0x01 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Normal acquisition mode + * + * @param v_busy_u8 : used to get the busy flay for sensor data read + * @param v_temp_u16 : used to get the temperature data + * @param v_xy1y2_u16 : used to get the sensor xy1y2 data + * @param v_overflow_u8 : used to get the overflow data + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_normal_measurement_data( +u8 v_acquisition_command_u8, u8 *v_busy_u8, +u16 *v_temp_u16, u16 *v_xy1y2_u16, u8 *v_overflow_u8); +/*! + * @brief This function used for YAS532 sensor data + * @param v_acquisition_command_u8 : the value of CMDR + * acquisition_command | operation + * ---------------------|------------------------- + * 0x17 | turn on the acquisition coil + * - | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Deferred acquisition mode + * 0x07 | turn on the acquisition coil + * _ | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Normal acquisition mode + * 0x11 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Deferred acquisition mode + * 0x01 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Normal acquisition mode + * + * @param xyz_data : the vector xyz output + * @param v_overflow_s8 : the value of overflow + * @param v_temp_correction_u8 : the value of temperate correction enable + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_measurement_xyz_data( +struct yas532_vector *xyz_data, u8 *v_overflow_s8, u8 v_temp_correction_u8, +u8 v_acquisition_command_u8); +/*! + * @brief This function used for YAS532 write data acquisition + * command register write + * @param v_command_reg_data_u8 : the value of data acquisition + * acquisition_command | operation + * ---------------------|------------------------- + * 0x17 | turn on the acquisition coil + * - | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Deferred acquisition mode + * 0x07 | turn on the acquisition coil + * _ | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Normal acquisition mode + * 0x11 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Deferred acquisition mode + * 0x01 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Normal acquisition mode + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_acquisition_command_register( +u8 v_command_reg_data_u8); +/*! + * @brief This function used write offset of YAS532 + * + * @param p_offset_s8 : The value of offset to write + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas532_set_offset( +const s8 *p_offset_s8); +/*! + * @brief This function used to init the YAMAH-YAS537 + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_mag_interface_init( +void); +/*! + * @brief This function used for read the + * YAMAHA YAS537 calibration data + * + * + * @param v_rcoil_u8 : The value of r coil + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_calib_values( +u8 v_rcoil_u8); +/*! + * @brief This function used for YAS537 write data acquisition + * command register write + * @param v_command_reg_data_u8 : the value of data acquisition + * acquisition_command | operation + * ---------------------|------------------------- + * 0x17 | turn on the acquisition coil + * - | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Deferred acquisition mode + * 0x07 | turn on the acquisition coil + * _ | set direction of the coil + * _ | (x and y as minus(-)) + * _ | Normal acquisition mode + * 0x11 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Deferred acquisition mode + * 0x01 | turn OFF the acquisition coil + * _ | set direction of the coil + * _ | (x and y as plus(+)) + * _ | Normal acquisition mode + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yas537_acquisition_command_register( +u8 v_command_reg_data_u8); + +/*! + * @brief This function used for read the + * YAMAHA YAS537 xy1y2 data + * + * @param v_coil_stat_u8: The value of R coil status + * @param v_busy_u8: The value of busy status + * @param v_temperature_u16: The value of temperature + * @param xy1y2: The value of raw xy1y2 data + * @param v_ouflow_u8: The value of overflow + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_read_xy1y2_data( +u8 *v_coil_stat_u8, u8 *v_busy_u8, +u16 *v_temperature_u16, u16 *xy1y2, u8 *v_ouflow_u8); +/*! + * @brief This function used for read the + * YAMAHA YAS537 xy1y2 data + * + * @param v_ouflow_u8: The value of overflow + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_bosch_yamaha_yas537_measure_xyz_data( +u8 *v_ouflow_u8, struct yas_vector *vector_xyz); + +/***************************************************/ +/**\name FUNCTIONS FOR FIFO DATA READ */ +/***************************************************/ +/*! + * @brief This function used for reading the + * fifo data of header less mode + * + * + * + * @note Configure the below functions for FIFO header less mode + * @note 1. smi130_set_fifo_down_gyro + * @note 2. smi130_set_gyro_fifo_filter_data + * @note 3. smi130_set_fifo_down_accel + * @note 4. smi130_set_accel_fifo_filter_dat + * @note 5. smi130_set_fifo_mag_enable + * @note 6. smi130_set_fifo_accel_enable + * @note 7. smi130_set_fifo_gyro_enable + * @note For interrupt configuration + * @note 1. smi130_set_intr_fifo_full + * @note 2. smi130_set_intr_fifo_wm + * @note 3. smi130_set_fifo_tag_intr2_enable + * @note 4. smi130_set_fifo_tag_intr1_enable + * + * @note The fifo reads the whole 1024 bytes + * and processing the data + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_read_fifo_headerless_mode( +void); +/*! + * @brief This function used for reading the + * fifo data of header less mode for using user defined length + * + * + * @param v_fifo_user_length_u16: The value of length of fifo read data + * + * @note Configure the below functions for FIFO header less mode + * @note 1. smi130_set_fifo_down_gyro + * @note 2. smi130_set_gyro_fifo_filter_data + * @note 3. smi130_set_fifo_down_accel + * @note 4. smi130_set_accel_fifo_filter_dat + * @note 5. smi130_set_fifo_mag_enable + * @note 6. smi130_set_fifo_accel_enable + * @note 7. smi130_set_fifo_gyro_enable + * @note For interrupt configuration + * @note 1. smi130_set_intr_fifo_full + * @note 2. smi130_set_intr_fifo_wm + * @note 3. smi130_set_fifo_tag_intr2_enable + * @note 4. smi130_set_fifo_tag_intr1_enable + * + * @note The fifo reads the whole 1024 bytes + * and processing the data + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE +smi130_read_fifo_headerless_mode_user_defined_length( +u16 v_fifo_user_length_u16); +/*! + * @brief This function used for reading the + * fifo data of header mode + * + * + * @note Configure the below functions for FIFO header mode + * @note 1. smi130_set_fifo_down_gyro() + * @note 2. smi130_set_gyro_fifo_filter_data() + * @note 3. smi130_set_fifo_down_accel() + * @note 4. smi130_set_accel_fifo_filter_dat() + * @note 5. smi130_set_fifo_mag_enable() + * @note 6. smi130_set_fifo_accel_enable() + * @note 7. smi130_set_fifo_gyro_enable() + * @note 8. smi130_set_fifo_header_enable() + * @note For interrupt configuration + * @note 1. smi130_set_intr_fifo_full() + * @note 2. smi130_set_intr_fifo_wm() + * @note 3. smi130_set_fifo_tag_intr2_enable() + * @note 4. smi130_set_fifo_tag_intr1_enable() + * + * @note The fifo reads the whole 1024 bytes + * and processing the data + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_read_fifo_header_data( +void); +/*! + * @brief This function used for reading the + * fifo data of header mode for using user defined length + * + * + * @note Configure the below functions for FIFO header mode + * @note 1. smi130_set_fifo_down_gyro() + * @note 2. smi130_set_gyro_fifo_filter_data() + * @note 3. smi130_set_fifo_down_accel() + * @note 4. smi130_set_accel_fifo_filter_dat() + * @note 5. smi130_set_fifo_mag_enable() + * @note 6. smi130_set_fifo_accel_enable() + * @note 7. smi130_set_fifo_gyro_enable() + * @note 8. smi130_set_fifo_header_enable() + * @note For interrupt configuration + * @note 1. smi130_set_intr_fifo_full() + * @note 2. smi130_set_intr_fifo_wm() + * @note 3. smi130_set_fifo_tag_intr2_enable() + * @note 4. smi130_set_fifo_tag_intr1_enable() + * + * @note The fifo reads the whole 1024 bytes + * and processing the data + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +SMI130_RETURN_FUNCTION_TYPE smi130_read_fifo_header_data_user_defined_length( +u16 v_fifo_user_length_u16); +/*! + * @brief This function used for reading + * smi130_t structure + * + * @return the reference and values of smi130_t + * + * +*/ +struct smi130_t *smi130_get_ptr(void); + +#endif + diff --git a/smi130_driver.c b/smi130_driver.c new file mode 100644 index 000000000000..16c1754d59e2 --- /dev/null +++ b/smi130_driver.c @@ -0,0 +1,4021 @@ +/* + * @section LICENSE + * (C) Copyright 2011~2018 Bosch Sensortec GmbH All Rights Reserved + * + * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved + * + * This software program is licensed subject to the GNU General + * Public License (GPL).Version 2,June 1991, + * available at http://www.fsf.org/copyleft/gpl.html + * + * + * @filename smi130_driver.c + * @date 2016/08/01 14:40 + * @Modification Date 2018/06/21 15:03 + * @version 1.3 + * + * @brief + * The core code of SMI130 device driver + * + * @detail + * This file implements the core code of SMI130 device driver, + * which includes hardware related functions, input device register, + * device attribute files, etc. +*/ + +#include "smi130.h" +#include "smi130_driver.h" +#include <linux/device.h> +#include <linux/gpio.h> +#include <linux/of_gpio.h> +#include <linux/of_irq.h> + + +#define DRIVER_VERSION "0.0.53.0" +#define I2C_BURST_READ_MAX_LEN (256) +#define SMI130_STORE_COUNT (6000) +#define LMADA (1) +uint64_t g_current_apts_us; + + +enum SMI_SENSOR_INT_T { + /* Interrupt enable0*/ + SMI_ANYMO_X_INT = 0, + SMI_ANYMO_Y_INT, + SMI_ANYMO_Z_INT, + SMI_D_TAP_INT, + SMI_S_TAP_INT, + SMI_ORIENT_INT, + SMI_FLAT_INT, + /* Interrupt enable1*/ + SMI_HIGH_X_INT, + SMI_HIGH_Y_INT, + SMI_HIGH_Z_INT, + SMI_LOW_INT, + SMI_DRDY_INT, + SMI_FFULL_INT, + SMI_FWM_INT, + /* Interrupt enable2 */ + SMI_NOMOTION_X_INT, + SMI_NOMOTION_Y_INT, + SMI_NOMOTION_Z_INT, + SMI_STEP_DETECTOR_INT, + INT_TYPE_MAX +}; + +/*smi fifo sensor type combination*/ +enum SMI_SENSOR_FIFO_COMBINATION { + SMI_FIFO_A = 0, + SMI_FIFO_G, + SMI_FIFO_M, + SMI_FIFO_G_A, + SMI_FIFO_M_A, + SMI_FIFO_M_G, + SMI_FIFO_M_G_A, + SMI_FIFO_COM_MAX +}; + +/*smi fifo analyse return err status*/ +enum SMI_FIFO_ANALYSE_RETURN_T { + FIFO_OVER_READ_RETURN = -10, + FIFO_SENSORTIME_RETURN = -9, + FIFO_SKIP_OVER_LEN = -8, + FIFO_M_G_A_OVER_LEN = -7, + FIFO_M_G_OVER_LEN = -6, + FIFO_M_A_OVER_LEN = -5, + FIFO_G_A_OVER_LEN = -4, + FIFO_M_OVER_LEN = -3, + FIFO_G_OVER_LEN = -2, + FIFO_A_OVER_LEN = -1 +}; + +/*!smi sensor generic power mode enum */ +enum SMI_DEV_OP_MODE { + SENSOR_PM_NORMAL = 0, + SENSOR_PM_LP1, + SENSOR_PM_SUSPEND, + SENSOR_PM_LP2 +}; + +/*! smi acc sensor power mode enum */ +enum SMI_ACC_PM_TYPE { + SMI_ACC_PM_NORMAL = 0, + SMI_ACC_PM_LP1, + SMI_ACC_PM_SUSPEND, + SMI_ACC_PM_LP2, + SMI_ACC_PM_MAX +}; + +/*! smi gyro sensor power mode enum */ +enum SMI_GYRO_PM_TYPE { + SMI_GYRO_PM_NORMAL = 0, + SMI_GYRO_PM_FAST_START, + SMI_GYRO_PM_SUSPEND, + SMI_GYRO_PM_MAX +}; + +/*! smi mag sensor power mode enum */ +enum SMI_MAG_PM_TYPE { + SMI_MAG_PM_NORMAL = 0, + SMI_MAG_PM_LP1, + SMI_MAG_PM_SUSPEND, + SMI_MAG_PM_LP2, + SMI_MAG_PM_MAX +}; + + +/*! smi sensor support type*/ +enum SMI_SENSOR_TYPE { + SMI_ACC_SENSOR, + SMI_GYRO_SENSOR, + SMI_MAG_SENSOR, + SMI_SENSOR_TYPE_MAX +}; + +/*!smi sensor generic power mode enum */ +enum SMI_AXIS_TYPE { + X_AXIS = 0, + Y_AXIS, + Z_AXIS, + AXIS_MAX +}; + +/*!smi sensor generic intterrupt enum */ +enum SMI_INT_TYPE { + SMI130_INT0 = 0, + SMI130_INT1, + SMI130_INT_MAX +}; + +/*! smi sensor time resolution definition*/ +enum SMI_SENSOR_TIME_RS_TYPE { + TS_0_78_HZ = 1,/*0.78HZ*/ + TS_1_56_HZ,/*1.56HZ*/ + TS_3_125_HZ,/*3.125HZ*/ + TS_6_25_HZ,/*6.25HZ*/ + TS_12_5_HZ,/*12.5HZ*/ + TS_25_HZ,/*25HZ, odr=6*/ + TS_50_HZ,/*50HZ*/ + TS_100_HZ,/*100HZ*/ + TS_200_HZ,/*200HZ*/ + TS_400_HZ,/*400HZ*/ + TS_800_HZ,/*800HZ*/ + TS_1600_HZ,/*1600HZ*/ + TS_MAX_HZ +}; + +/*! smi sensor interface mode */ +enum SMI_SENSOR_IF_MODE_TYPE { + /*primary interface:autoconfig/secondary interface off*/ + P_AUTO_S_OFF = 0, + /*primary interface:I2C/secondary interface:OIS*/ + P_I2C_S_OIS, + /*primary interface:autoconfig/secondary interface:Magnetometer*/ + P_AUTO_S_MAG, + /*interface mode reseved*/ + IF_MODE_RESEVED + +}; + +/*! smi130 acc/gyro calibration status in H/W layer */ +enum SMI_CALIBRATION_STATUS_TYPE { + /*SMI FAST Calibration ready x/y/z status*/ + SMI_ACC_X_FAST_CALI_RDY = 0, + SMI_ACC_Y_FAST_CALI_RDY, + SMI_ACC_Z_FAST_CALI_RDY +}; + +unsigned int reg_op_addr; + +static const int smi_pmu_cmd_acc_arr[SMI_ACC_PM_MAX] = { + /*!smi pmu for acc normal, low power1, + * suspend, low power2 mode command */ + CMD_PMU_ACC_NORMAL, + CMD_PMU_ACC_LP1, + CMD_PMU_ACC_SUSPEND, + CMD_PMU_ACC_LP2 +}; + +static const int smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_MAX] = { + /*!smi pmu for gyro normal, fast startup, + * suspend mode command */ + CMD_PMU_GYRO_NORMAL, + CMD_PMU_GYRO_FASTSTART, + CMD_PMU_GYRO_SUSPEND +}; + +static const int smi_pmu_cmd_mag_arr[SMI_MAG_PM_MAX] = { + /*!smi pmu for mag normal, low power1, + * suspend, low power2 mode command */ + CMD_PMU_MAG_NORMAL, + CMD_PMU_MAG_LP1, + CMD_PMU_MAG_SUSPEND, + CMD_PMU_MAG_LP2 +}; + +static const char *smi_axis_name[AXIS_MAX] = {"x", "y", "z"}; + +static const int smi_interrupt_type[] = { + /*!smi interrupt type */ + /* Interrupt enable0 , index=0~6*/ + SMI130_ANY_MOTION_X_ENABLE, + SMI130_ANY_MOTION_Y_ENABLE, + SMI130_ANY_MOTION_Z_ENABLE, + SMI130_DOUBLE_TAP_ENABLE, + SMI130_SINGLE_TAP_ENABLE, + SMI130_ORIENT_ENABLE, + SMI130_FLAT_ENABLE, + /* Interrupt enable1, index=7~13*/ + SMI130_HIGH_G_X_ENABLE, + SMI130_HIGH_G_Y_ENABLE, + SMI130_HIGH_G_Z_ENABLE, + SMI130_LOW_G_ENABLE, + SMI130_DATA_RDY_ENABLE, + SMI130_FIFO_FULL_ENABLE, + SMI130_FIFO_WM_ENABLE, + /* Interrupt enable2, index = 14~17*/ + SMI130_NOMOTION_X_ENABLE, + SMI130_NOMOTION_Y_ENABLE, + SMI130_NOMOTION_Z_ENABLE, + SMI130_STEP_DETECTOR_EN +}; + +/*! smi sensor time depend on ODR*/ +struct smi_sensor_time_odr_tbl { + u32 ts_duration_lsb; + u32 ts_duration_us; + u32 ts_delat;/*sub current delat fifo_time*/ +}; + +struct smi130_axis_data_t { + s16 x; + s16 y; + s16 z; +}; + +struct smi130_type_mapping_type { + + /*! smi16x sensor chip id */ + uint16_t chip_id; + + /*! smi16x chip revision code */ + uint16_t revision_id; + + /*! bma2x2 sensor name */ + const char *sensor_name; +}; + +struct smi130_store_info_t { + uint8_t current_frm_cnt; + uint64_t current_apts_us[2]; + uint8_t fifo_ts_total_frmcnt; + uint64_t fifo_time; +}; + +uint64_t get_current_timestamp(void) +{ + uint64_t ts_ap; + struct timespec tmp_time; + get_monotonic_boottime(&tmp_time); + ts_ap = (uint64_t)tmp_time.tv_sec * 1000000000 + tmp_time.tv_nsec; + return ts_ap; + +} + +/*! sensor support type map */ +static const struct smi130_type_mapping_type sensor_type_map[] = { + + {SENSOR_CHIP_ID_SMI, SENSOR_CHIP_REV_ID_SMI, "SMI130/162AB"}, + {SENSOR_CHIP_ID_SMI_C2, SENSOR_CHIP_REV_ID_SMI, "SMI130C2"}, + {SENSOR_CHIP_ID_SMI_C3, SENSOR_CHIP_REV_ID_SMI, "SMI130C3"}, + +}; + +/*!smi130 sensor time depends on ODR */ +static const struct smi_sensor_time_odr_tbl + sensortime_duration_tbl[TS_MAX_HZ] = { + {0x010000, 2560000, 0x00ffff},/*2560ms, 0.39hz, odr=resver*/ + {0x008000, 1280000, 0x007fff},/*1280ms, 0.78hz, odr_acc=1*/ + {0x004000, 640000, 0x003fff},/*640ms, 1.56hz, odr_acc=2*/ + {0x002000, 320000, 0x001fff},/*320ms, 3.125hz, odr_acc=3*/ + {0x001000, 160000, 0x000fff},/*160ms, 6.25hz, odr_acc=4*/ + {0x000800, 80000, 0x0007ff},/*80ms, 12.5hz*/ + {0x000400, 40000, 0x0003ff},/*40ms, 25hz, odr_acc = odr_gyro =6*/ + {0x000200, 20000, 0x0001ff},/*20ms, 50hz, odr = 7*/ + {0x000100, 10000, 0x0000ff},/*10ms, 100hz, odr=8*/ + {0x000080, 5000, 0x00007f},/*5ms, 200hz, odr=9*/ + {0x000040, 2500, 0x00003f},/*2.5ms, 400hz, odr=10*/ + {0x000020, 1250, 0x00001f},/*1.25ms, 800hz, odr=11*/ + {0x000010, 625, 0x00000f},/*0.625ms, 1600hz, odr=12*/ + +}; + +#if defined(CONFIG_USE_QUALCOMM_HAL) +#define POLL_INTERVAL_MIN_MS 10 +#define POLL_INTERVAL_MAX_MS 4000 +#define POLL_DEFAULT_INTERVAL_MS 200 +#define SMI130_ACCEL_MIN_VALUE -32768 +#define SMI130_ACCEL_MAX_VALUE 32767 +#define SMI130_GYRO_MIN_VALUE -32768 +#define SMI130_GYRO_MAX_VALUE 32767 +#define SMI130_ACCEL_DEFAULT_POLL_INTERVAL_MS 200 +#define SMI130_GYRO_DEFAULT_POLL_INTERVAL_MS 200 +#define SMI130_ACCEL_MIN_POLL_INTERVAL_MS 10 +#define SMI130_ACCEL_MAX_POLL_INTERVAL_MS 5000 +#define SMI130_GYRO_MIN_POLL_INTERVAL_MS 10 +#define SMI130_GYRO_MAX_POLL_INTERVAL_MS 5000 +static struct sensors_classdev smi130_accel_cdev = { + .name = "smi130-accel", + .vendor = "bosch", + .version = 1, + .handle = SENSORS_ACCELERATION_HANDLE, + .type = SENSOR_TYPE_ACCELEROMETER, + .max_range = "156.8", /* 16g */ + .resolution = "0.153125", /* 15.6mg */ + .sensor_power = "0.13", /* typical value */ + .min_delay = POLL_INTERVAL_MIN_MS * 1000, /* in microseconds */ + .max_delay = POLL_INTERVAL_MAX_MS, + .delay_msec = POLL_DEFAULT_INTERVAL_MS, /* in millisecond */ + .fifo_reserved_event_count = 0, + .fifo_max_event_count = 0, + .enabled = 0, + .max_latency = 0, + .flags = 0, + .sensors_enable = NULL, + .sensors_poll_delay = NULL, + .sensors_set_latency = NULL, + .sensors_flush = NULL, + .sensors_self_test = NULL, +}; +static struct sensors_classdev smi130_gyro_cdev = { + .name = "smi130-gyro", + .vendor = "bosch", + .version = 1, + .handle = SENSORS_GYROSCOPE_HANDLE, + .type = SENSOR_TYPE_GYROSCOPE, + .max_range = "34.906586", /* rad/s */ + .resolution = "0.0010681152", /* rad/s */ + .sensor_power = "3.6", /* 3.6 mA */ + .min_delay = SMI130_GYRO_MIN_POLL_INTERVAL_MS * 1000, + .max_delay = SMI130_GYRO_MAX_POLL_INTERVAL_MS, + .delay_msec = SMI130_GYRO_DEFAULT_POLL_INTERVAL_MS, + .fifo_reserved_event_count = 0, + .fifo_max_event_count = 0, + .enabled = 0, + .max_latency = 0, + .flags = 0, /* SENSOR_FLAG_CONTINUOUS_MODE */ + .sensors_enable = NULL, + .sensors_poll_delay = NULL, + .sensors_enable_wakeup = NULL, + .sensors_set_latency = NULL, + .sensors_flush = NULL, +}; +#endif +static void smi_delay(u32 msec) +{ + if (msec <= 20) + usleep_range(msec * 1000, msec * 1000); + else + msleep(msec); +} + +static void smi_dump_reg(struct smi_client_data *client_data) +{ + #define REG_MAX0 0x24 + #define REG_MAX1 0x56 + int i; + u8 dbg_buf0[REG_MAX0]; + u8 dbg_buf1[REG_MAX1]; + u8 dbg_buf_str0[REG_MAX0 * 3 + 1] = ""; + u8 dbg_buf_str1[REG_MAX1 * 3 + 1] = ""; + + dev_notice(client_data->dev, "\nFrom 0x00:\n"); + + client_data->device.bus_read(client_data->device.dev_addr, + SMI_REG_NAME(USER_CHIP_ID), dbg_buf0, REG_MAX0); + for (i = 0; i < REG_MAX0; i++) { + snprintf(dbg_buf_str0 + i * 3, 16, "%02x%c", dbg_buf0[i], + (((i + 1) % BYTES_PER_LINE == 0) ? '\n' : ' ')); + } + dev_notice(client_data->dev, "%s\n", dbg_buf_str0); + + client_data->device.bus_read(client_data->device.dev_addr, + SMI130_USER_ACCEL_CONFIG_ADDR, dbg_buf1, REG_MAX1); + dev_notice(client_data->dev, "\nFrom 0x40:\n"); + for (i = 0; i < REG_MAX1; i++) { + snprintf(dbg_buf_str1 + i * 3, 16, "%02x%c", dbg_buf1[i], + (((i + 1) % BYTES_PER_LINE == 0) ? '\n' : ' ')); + } + dev_notice(client_data->dev, "\n%s\n", dbg_buf_str1); + } + + +void smi_fifo_frame_bytes_extend_calc( + struct smi_client_data *client_data, + unsigned int *fifo_frmbytes_extend) +{ + + switch (client_data->fifo_data_sel) { + case SMI_FIFO_A_SEL: + case SMI_FIFO_G_SEL: + *fifo_frmbytes_extend = 7; + break; + case SMI_FIFO_G_A_SEL: + *fifo_frmbytes_extend = 13; + break; + case SMI_FIFO_M_SEL: + *fifo_frmbytes_extend = 9; + break; + case SMI_FIFO_M_A_SEL: + case SMI_FIFO_M_G_SEL: + /*8(mag) + 6(gyro or acc) +1(head) = 15*/ + *fifo_frmbytes_extend = 15; + break; + case SMI_FIFO_M_G_A_SEL: + /*8(mag) + 6(gyro or acc) + 6 + 1 = 21*/ + *fifo_frmbytes_extend = 21; + break; + default: + *fifo_frmbytes_extend = 0; + break; + + }; + +} + +static int smi_input_init(struct smi_client_data *client_data) +{ + struct input_dev *dev; + int err = 0; + + dev = input_allocate_device(); + if (NULL == dev) + return -ENOMEM; +#if defined(CONFIG_USE_QUALCOMM_HAL) + dev->name = "smi130-accel"; +#else + dev->name = SENSOR_NAME; +#endif + dev->id.bustype = BUS_I2C; + + input_set_capability(dev, EV_MSC, MSC_GESTURE); + input_set_capability(dev, EV_MSC, INPUT_EVENT_SGM); + + input_set_capability(dev, EV_MSC, INPUT_EVENT_FAST_GYRO_CALIB_DONE); + input_set_capability(dev, EV_MSC, INPUT_EVENT_STEP_DETECTOR); + input_set_capability(dev, EV_MSC, INPUT_EVENT_FAST_ACC_CALIB_DONE); + + + input_set_capability(dev, EV_REL, REL_X); + input_set_capability(dev, EV_REL, REL_Y); + input_set_capability(dev, EV_REL, REL_Z); + #if defined(CONFIG_USE_QUALCOMM_HAL) + input_set_capability(dev, EV_ABS, ABS_MISC); + input_set_abs_params(dev, ABS_X, + SMI130_ACCEL_MIN_VALUE, SMI130_ACCEL_MAX_VALUE, + 0, 0); + input_set_abs_params(dev, ABS_Y, + SMI130_ACCEL_MIN_VALUE, SMI130_ACCEL_MAX_VALUE, + 0, 0); + input_set_abs_params(dev, ABS_Z, + SMI130_ACCEL_MIN_VALUE, SMI130_ACCEL_MAX_VALUE, + 0, 0); + #endif + input_set_drvdata(dev, client_data); + + err = input_register_device(dev); + if (err < 0) { + input_free_device(dev); + dev_notice(client_data->dev, "smi130 input free!\n"); + return err; + } + client_data->input = dev; + dev_notice(client_data->dev, + "smi130 input register successfully, %s!\n", + client_data->input->name); + return err; +} + +//#if defined(CONFIG_USE_QUALCOMM_HAL) +static int smi_gyro_input_init(struct smi_client_data *client_data) +{ + struct input_dev *dev; + int err = 0; + + dev = input_allocate_device(); + if (NULL == dev) + return -ENOMEM; + dev->name = "smi130-gyro"; + dev->id.bustype = BUS_I2C; + input_set_capability(dev, EV_ABS, ABS_MISC); + input_set_capability(dev, EV_MSC, MSC_GESTURE); + input_set_capability(dev, EV_MSC, INPUT_EVENT_SGM); + + input_set_capability(dev, EV_MSC, INPUT_EVENT_FAST_GYRO_CALIB_DONE); + input_set_capability(dev, EV_MSC, INPUT_EVENT_STEP_DETECTOR); + input_set_capability(dev, EV_MSC, INPUT_EVENT_FAST_ACC_CALIB_DONE); + #if defined(CONFIG_USE_QUALCOMM_HAL) + input_set_abs_params(dev, ABS_RX, + SMI130_ACCEL_MIN_VALUE, SMI130_ACCEL_MAX_VALUE, + 0, 0); + input_set_abs_params(dev, ABS_RY, + SMI130_ACCEL_MIN_VALUE, SMI130_ACCEL_MAX_VALUE, + 0, 0); + input_set_abs_params(dev, ABS_RZ, + SMI130_ACCEL_MIN_VALUE, SMI130_ACCEL_MAX_VALUE, + 0, 0); + #endif + input_set_drvdata(dev, client_data); + err = input_register_device(dev); + if (err < 0) { + input_free_device(dev); + dev_notice(client_data->dev, "smi130 input free!\n"); + return err; + } + client_data->gyro_input = dev; + dev_notice(client_data->dev, + "smi130 input register successfully, %s!\n", + client_data->gyro_input->name); + return err; +} +//#endif +static void smi_input_destroy(struct smi_client_data *client_data) +{ + struct input_dev *dev = client_data->input; + + input_unregister_device(dev); + input_free_device(dev); +} + +static int smi_check_chip_id(struct smi_client_data *client_data) +{ + int8_t err = 0; + int8_t i = 0; + uint8_t chip_id = 0; + uint8_t read_count = 0; + u8 smi_sensor_cnt = sizeof(sensor_type_map) + / sizeof(struct smi130_type_mapping_type); + /* read and check chip id */ + while (read_count++ < CHECK_CHIP_ID_TIME_MAX) { + if (client_data->device.bus_read(client_data->device.dev_addr, + SMI_REG_NAME(USER_CHIP_ID), &chip_id, 1) < 0) { + + dev_err(client_data->dev, + "Bosch Sensortec Device not found" + "read chip_id:%d\n", chip_id); + continue; + } else { + for (i = 0; i < smi_sensor_cnt; i++) { + if (sensor_type_map[i].chip_id == chip_id) { + client_data->chip_id = chip_id; + dev_notice(client_data->dev, + "Bosch Sensortec Device detected, " + "HW IC name: %s\n", sensor_type_map[i].sensor_name); + break; + } + } + if (i < smi_sensor_cnt) + break; + else { + if (read_count == CHECK_CHIP_ID_TIME_MAX) { + dev_err(client_data->dev, + "Failed!Bosch Sensortec Device not found" + " mismatch chip_id:%d\n", chip_id); + err = -ENODEV; + return err; + } + } + smi_delay(1); + } + } + return err; + +} + +static int smi_pmu_set_suspend(struct smi_client_data *client_data) +{ + int err = 0; + if (client_data == NULL) + return -EINVAL; + else { + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SENSOR_PM_SUSPEND]); + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SENSOR_PM_SUSPEND]); + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_mag_arr[SENSOR_PM_SUSPEND]); + client_data->pw.acc_pm = SMI_ACC_PM_SUSPEND; + client_data->pw.gyro_pm = SMI_GYRO_PM_SUSPEND; + client_data->pw.mag_pm = SMI_MAG_PM_SUSPEND; + } + + return err; +} + +static int smi_get_err_status(struct smi_client_data *client_data) +{ + int err = 0; + + err = SMI_CALL_API(get_error_status)(&client_data->err_st.fatal_err, + &client_data->err_st.err_code, &client_data->err_st.i2c_fail, + &client_data->err_st.drop_cmd, &client_data->err_st.mag_drdy_err); + return err; +} + +static void smi_work_func(struct work_struct *work) +{ + struct smi_client_data *client_data = + container_of((struct delayed_work *)work, + struct smi_client_data, work); + unsigned long delay = + msecs_to_jiffies(atomic_read(&client_data->delay)); + struct smi130_accel_t data; + int err; + + err = SMI_CALL_API(read_accel_xyz)(&data); + if (err < 0) + return; + + /*report current frame via input event*/ + input_event(client_data->input, EV_REL, REL_X, data.x); + input_event(client_data->input, EV_REL, REL_Y, data.y); + input_event(client_data->input, EV_REL, REL_Z, data.z); + input_sync(client_data->input); + + schedule_delayed_work(&client_data->work, delay); +} + +static ssize_t smi130_chip_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + return snprintf(buf, 16, "0x%x\n", client_data->chip_id); +} + +static ssize_t smi130_err_st_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err = 0; + err = smi_get_err_status(client_data); + if (err) + return err; + else { + return snprintf(buf, 128, "fatal_err:0x%x, err_code:%d,\n\n" + "i2c_fail_err:%d, drop_cmd_err:%d, mag_drdy_err:%d\n", + client_data->err_st.fatal_err, + client_data->err_st.err_code, + client_data->err_st.i2c_fail, + client_data->err_st.drop_cmd, + client_data->err_st.mag_drdy_err); + + } +} + +static ssize_t smi130_sensor_time_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err = 0; + u32 sensor_time; + err = SMI_CALL_API(get_sensor_time)(&sensor_time); + if (err) + return err; + else + return snprintf(buf, 16, "0x%x\n", (unsigned int)sensor_time); +} + +static ssize_t smi130_fifo_flush_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long enable; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &enable); + if (err) + return err; + if (enable) + err = SMI_CALL_API(set_command_register)(CMD_CLR_FIFO_DATA); + + if (err) + dev_err(client_data->dev, "fifo flush failed!\n"); + + return count; + +} + + +static ssize_t smi130_fifo_bytecount_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned int fifo_bytecount = 0; + + SMI_CALL_API(fifo_length)(&fifo_bytecount); + err = snprintf(buf, 16, "%u\n", fifo_bytecount); + return err; +} + +static ssize_t smi130_fifo_bytecount_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err; + unsigned long data; + err = kstrtoul(buf, 10, &data); + if (err) + return err; + client_data->fifo_bytecount = (unsigned int) data; + + return count; +} + +int smi130_fifo_data_sel_get(struct smi_client_data *client_data) +{ + int err = 0; + unsigned char fifo_acc_en, fifo_gyro_en, fifo_mag_en; + unsigned char fifo_datasel; + + err += SMI_CALL_API(get_fifo_accel_enable)(&fifo_acc_en); + err += SMI_CALL_API(get_fifo_gyro_enable)(&fifo_gyro_en); + err += SMI_CALL_API(get_fifo_mag_enable)(&fifo_mag_en); + + if (err) + return err; + + fifo_datasel = (fifo_acc_en << SMI_ACC_SENSOR) | + (fifo_gyro_en << SMI_GYRO_SENSOR) | + (fifo_mag_en << SMI_MAG_SENSOR); + + client_data->fifo_data_sel = fifo_datasel; + + return err; + + +} + +static ssize_t smi130_fifo_data_sel_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err = 0; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + err = smi130_fifo_data_sel_get(client_data); + if (err) { + dev_err(client_data->dev, "get fifo_sel failed!\n"); + return -EINVAL; + } + return snprintf(buf, 16, "%d\n", client_data->fifo_data_sel); +} + +/* write any value to clear all the fifo data. */ +static ssize_t smi130_fifo_data_sel_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err; + unsigned long data; + unsigned char fifo_datasel; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + /* data format: aimed 0b0000 0x(m)x(g)x(a), x:1 enable, 0:disable*/ + if (data > 7) + return -EINVAL; + + + fifo_datasel = (unsigned char)data; + + + err += SMI_CALL_API(set_fifo_accel_enable) + ((fifo_datasel & (1 << SMI_ACC_SENSOR)) ? 1 : 0); + err += SMI_CALL_API(set_fifo_gyro_enable) + (fifo_datasel & (1 << SMI_GYRO_SENSOR) ? 1 : 0); + err += SMI_CALL_API(set_fifo_mag_enable) + ((fifo_datasel & (1 << SMI_MAG_SENSOR)) ? 1 : 0); + + err += SMI_CALL_API(set_command_register)(CMD_CLR_FIFO_DATA); + if (err) + return -EIO; + else { + dev_notice(client_data->dev, "FIFO A_en:%d, G_en:%d, M_en:%d\n", + (fifo_datasel & (1 << SMI_ACC_SENSOR)) ? 1 : 0, + (fifo_datasel & (1 << SMI_GYRO_SENSOR) ? 1 : 0), + ((fifo_datasel & (1 << SMI_MAG_SENSOR)) ? 1 : 0)); + client_data->fifo_data_sel = fifo_datasel; + } + return count; +} + +static ssize_t smi130_fifo_data_out_frame_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + int err = 0; + uint32_t fifo_bytecount = 0; + + err = SMI_CALL_API(fifo_length)(&fifo_bytecount); + if (err < 0) { + dev_err(client_data->dev, "read fifo_length err"); + return -EINVAL; + } + if (fifo_bytecount == 0) + return 0; + err = smi_burst_read_wrapper(client_data->device.dev_addr, + SMI130_USER_FIFO_DATA__REG, buf, + fifo_bytecount); + if (err) { + dev_err(client_data->dev, "read fifo err"); + SMI_CALL_API(set_command_register)(CMD_CLR_FIFO_DATA); + return -EINVAL; + } + return fifo_bytecount; + +} + +static ssize_t smi130_fifo_watermark_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char data = 0xff; + + err = SMI_CALL_API(get_fifo_wm)(&data); + + if (err) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_fifo_watermark_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long data; + unsigned char fifo_watermark; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + fifo_watermark = (unsigned char)data; + err = SMI_CALL_API(set_fifo_wm)(fifo_watermark); + if (err) + return -EIO; + + return count; +} + + +static ssize_t smi130_fifo_header_en_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char data = 0xff; + + err = SMI_CALL_API(get_fifo_header_enable)(&data); + + if (err) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_fifo_header_en_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err; + unsigned long data; + unsigned char fifo_header_en; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + if (data > 1) + return -ENOENT; + + fifo_header_en = (unsigned char)data; + err = SMI_CALL_API(set_fifo_header_enable)(fifo_header_en); + if (err) + return -EIO; + + client_data->fifo_head_en = fifo_header_en; + + return count; +} + +static ssize_t smi130_fifo_time_en_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char data = 0; + + err = SMI_CALL_API(get_fifo_time_enable)(&data); + + if (!err) + err = snprintf(buf, 16, "%d\n", data); + + return err; +} + +static ssize_t smi130_fifo_time_en_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long data; + unsigned char fifo_ts_en; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + fifo_ts_en = (unsigned char)data; + + err = SMI_CALL_API(set_fifo_time_enable)(fifo_ts_en); + if (err) + return -EIO; + + return count; +} + +static ssize_t smi130_fifo_int_tag_en_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err = 0; + unsigned char fifo_tag_int1 = 0; + unsigned char fifo_tag_int2 = 0; + unsigned char fifo_tag_int; + + err += SMI_CALL_API(get_fifo_tag_intr1_enable)(&fifo_tag_int1); + err += SMI_CALL_API(get_fifo_tag_intr2_enable)(&fifo_tag_int2); + + fifo_tag_int = (fifo_tag_int1 << SMI130_INT0) | + (fifo_tag_int2 << SMI130_INT1); + + if (!err) + err = snprintf(buf, 16, "%d\n", fifo_tag_int); + + return err; +} + +static ssize_t smi130_fifo_int_tag_en_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err; + unsigned long data; + unsigned char fifo_tag_int_en; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + if (data > 3) + return -EINVAL; + + fifo_tag_int_en = (unsigned char)data; + + err += SMI_CALL_API(set_fifo_tag_intr1_enable) + ((fifo_tag_int_en & (1 << SMI130_INT0)) ? 1 : 0); + err += SMI_CALL_API(set_fifo_tag_intr2_enable) + ((fifo_tag_int_en & (1 << SMI130_INT1)) ? 1 : 0); + + if (err) { + dev_err(client_data->dev, "fifo int tag en err:%d\n", err); + return -EIO; + } + client_data->fifo_int_tag_en = fifo_tag_int_en; + + return count; +} + +static int smi130_set_acc_op_mode(struct smi_client_data *client_data, + unsigned long op_mode) +{ + int err = 0; + unsigned char stc_enable; + unsigned char std_enable; + mutex_lock(&client_data->mutex_op_mode); + + if (op_mode < SMI_ACC_PM_MAX) { + switch (op_mode) { + case SMI_ACC_PM_NORMAL: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_NORMAL]); + client_data->pw.acc_pm = SMI_ACC_PM_NORMAL; + smi_delay(10); + break; + case SMI_ACC_PM_LP1: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_LP1]); + client_data->pw.acc_pm = SMI_ACC_PM_LP1; + smi_delay(3); + break; + case SMI_ACC_PM_SUSPEND: + SMI_CALL_API(get_step_counter_enable)(&stc_enable); + SMI_CALL_API(get_step_detector_enable)(&std_enable); + if ((stc_enable == 0) && (std_enable == 0) && + (client_data->sig_flag == 0)) { + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_SUSPEND]); + client_data->pw.acc_pm = SMI_ACC_PM_SUSPEND; + smi_delay(10); + } + break; + case SMI_ACC_PM_LP2: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_LP2]); + client_data->pw.acc_pm = SMI_ACC_PM_LP2; + smi_delay(3); + break; + default: + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + } else { + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + + mutex_unlock(&client_data->mutex_op_mode); + + return err; + + +} + +static ssize_t smi130_temperature_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + s16 temp = 0xff; + + err = SMI_CALL_API(get_temp)(&temp); + + if (!err) + err = snprintf(buf, 16, "0x%x\n", temp); + + return err; +} + +static ssize_t smi130_place_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int place = BOSCH_SENSOR_PLACE_UNKNOWN; + + if (NULL != client_data->bosch_pd) + place = client_data->bosch_pd->place; + + return snprintf(buf, 16, "%d\n", place); +} + +static ssize_t smi130_delay_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + return snprintf(buf, 16, "%d\n", atomic_read(&client_data->delay)); + +} + +static ssize_t smi130_delay_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err; + unsigned long data; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + if (data == 0) { + err = -EINVAL; + return err; + } + + if (data < SMI_DELAY_MIN) + data = SMI_DELAY_MIN; + + atomic_set(&client_data->delay, (unsigned int)data); + + return count; +} + +static ssize_t smi130_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + return snprintf(buf, 16, "%d\n", atomic_read(&client_data->wkqueue_en)); + +} + +static ssize_t smi130_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err; + unsigned long enable; + int pre_enable = atomic_read(&client_data->wkqueue_en); + + err = kstrtoul(buf, 10, &enable); + if (err) + return err; + + enable = enable ? 1 : 0; + mutex_lock(&client_data->mutex_enable); + if (enable) { + if (pre_enable == 0) { + smi130_set_acc_op_mode(client_data, + SMI_ACC_PM_NORMAL); + schedule_delayed_work(&client_data->work, + msecs_to_jiffies(atomic_read(&client_data->delay))); + atomic_set(&client_data->wkqueue_en, 1); + } + + } else { + if (pre_enable == 1) { + smi130_set_acc_op_mode(client_data, + SMI_ACC_PM_SUSPEND); + + cancel_delayed_work_sync(&client_data->work); + atomic_set(&client_data->wkqueue_en, 0); + } + } + + mutex_unlock(&client_data->mutex_enable); + + return count; +} + +#if defined(SMI130_ENABLE_INT1) || defined(SMI130_ENABLE_INT2) +/* accel sensor part */ +static ssize_t smi130_anymot_duration_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char data; + + err = SMI_CALL_API(get_intr_any_motion_durn)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_anymot_duration_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_intr_any_motion_durn)((unsigned char)data); + if (err < 0) + return -EIO; + + return count; +} + +static ssize_t smi130_anymot_threshold_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_intr_any_motion_thres)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_anymot_threshold_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_intr_any_motion_thres)((unsigned char)data); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_step_detector_status_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u8 data = 0; + u8 step_det; + int err; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + err = SMI_CALL_API(get_step_detector_enable)(&step_det); + /*smi130_get_status0_step_int*/ + if (err < 0) + return err; +/*client_data->std will be updated in smi_stepdetector_interrupt_handle */ + if ((step_det == 1) && (client_data->std == 1)) { + data = 1; + client_data->std = 0; + } + else { + data = 0; + } + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_step_detector_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_step_detector_enable)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_step_detector_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_step_detector_enable)((unsigned char)data); + if (err < 0) + return -EIO; + if (data == 0) + client_data->pedo_data.wkar_step_detector_status = 0; + return count; +} + +static ssize_t smi130_signification_motion_enable_store( + struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + /*0x62 (bit 1) INT_MOTION_3 int_sig_mot_sel*/ + err = SMI_CALL_API(set_intr_significant_motion_select)( + (unsigned char)data); + if (err < 0) + return -EIO; + if (data == 1) { + err = SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_X_ENABLE, 1); + err += SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_Y_ENABLE, 1); + err += SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_Z_ENABLE, 1); + if (err < 0) + return -EIO; + enable_irq_wake(client_data->IRQ); + client_data->sig_flag = 1; + } else { + err = SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_X_ENABLE, 0); + err += SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_Y_ENABLE, 0); + err += SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_Z_ENABLE, 0); + if (err < 0) + return -EIO; + disable_irq_wake(client_data->IRQ); + client_data->sig_flag = 0; + } + return count; +} + +static ssize_t smi130_signification_motion_enable_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + /*0x62 (bit 1) INT_MOTION_3 int_sig_mot_sel*/ + err = SMI_CALL_API(get_intr_significant_motion_select)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static int sigmotion_init_interrupts(u8 sig_map_int_pin) +{ + int ret = 0; +/*0x60 */ + ret += smi130_set_intr_any_motion_thres(0x1e); +/* 0x62(bit 3~2) 0=1.5s */ + ret += smi130_set_intr_significant_motion_skip(0); +/*0x62(bit 5~4) 1=0.5s*/ + ret += smi130_set_intr_significant_motion_proof(1); +/*0x50 (bit 0, 1, 2) INT_EN_0 anymo x y z*/ + ret += smi130_map_significant_motion_intr(sig_map_int_pin); +/*0x62 (bit 1) INT_MOTION_3 int_sig_mot_sel +close the signification_motion*/ + ret += smi130_set_intr_significant_motion_select(0); +/*close the anymotion interrupt*/ + ret += SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_X_ENABLE, 0); + ret += SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_Y_ENABLE, 0); + ret += SMI_CALL_API(set_intr_enable_0) + (SMI130_ANY_MOTION_Z_ENABLE, 0); + if (ret) + printk(KERN_ERR "smi130 sig motion failed setting,%d!\n", ret); + return ret; + +} +#endif + +static ssize_t smi130_acc_range_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char range; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = SMI_CALL_API(get_accel_range)(&range); + if (err) + return err; + + client_data->range.acc_range = range; + return snprintf(buf, 16, "%d\n", range); +} + +static ssize_t smi130_acc_range_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long range; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + + err = kstrtoul(buf, 10, &range); + if (err) + return err; + + err = SMI_CALL_API(set_accel_range)(range); + if (err) + return -EIO; + + client_data->range.acc_range = range; + return count; +} + +static ssize_t smi130_acc_odr_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char acc_odr; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = SMI_CALL_API(get_accel_output_data_rate)(&acc_odr); + if (err) + return err; + + client_data->odr.acc_odr = acc_odr; + return snprintf(buf, 16, "%d\n", acc_odr); +} + +static ssize_t smi130_acc_odr_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long acc_odr; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &acc_odr); + if (err) + return err; + + if (acc_odr < 1 || acc_odr > 12) + return -EIO; + + if (acc_odr < 5) + err = SMI_CALL_API(set_accel_under_sampling_parameter)(1); + else + err = SMI_CALL_API(set_accel_under_sampling_parameter)(0); + + if (err) + return err; + + err = SMI_CALL_API(set_accel_output_data_rate)(acc_odr); + if (err) + return -EIO; + client_data->odr.acc_odr = acc_odr; + return count; +} + +static ssize_t smi130_acc_op_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err = 0; + u8 accel_pmu_status = 0; + err = SMI_CALL_API(get_accel_power_mode_stat)( + &accel_pmu_status); + + if (err) + return err; + else + return snprintf(buf, 32, "reg:%d, val:%d\n", accel_pmu_status, + client_data->pw.acc_pm); +} + +static ssize_t smi130_acc_op_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err; + unsigned long op_mode; + err = kstrtoul(buf, 10, &op_mode); + if (err) + return err; + + err = smi130_set_acc_op_mode(client_data, op_mode); + if (err) + return err; + else + return count; + +} + +static ssize_t smi130_acc_value_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct smi130_accel_t data; + + int err; + + err = SMI_CALL_API(read_accel_xyz)(&data); + if (err < 0) + return err; + + return snprintf(buf, 48, "%hd %hd %hd\n", + data.x, data.y, data.z); +} + +static ssize_t smi130_acc_fast_calibration_x_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_foc_accel_x)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_acc_fast_calibration_x_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + s8 accel_offset_x = 0; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + /* 0: disable, 1: +1g, 2: -1g, 3: 0g */ + if (data > 3) + return -EINVAL; + + err = SMI_CALL_API(set_accel_foc_trigger)(X_AXIS, + data, &accel_offset_x); + if (err) + return -EIO; + else + client_data->calib_status |= + SMI_FAST_CALI_TRUE << SMI_ACC_X_FAST_CALI_RDY; + return count; +} + +static ssize_t smi130_acc_fast_calibration_y_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_foc_accel_y)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_acc_fast_calibration_y_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + s8 accel_offset_y = 0; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + /* 0: disable, 1: +1g, 2: -1g, 3: 0g */ + if (data > 3) + return -EINVAL; + + err = SMI_CALL_API(set_accel_foc_trigger)(Y_AXIS, + data, &accel_offset_y); + if (err) + return -EIO; + else + client_data->calib_status |= + SMI_FAST_CALI_TRUE << SMI_ACC_Y_FAST_CALI_RDY; + return count; +} + +static ssize_t smi130_acc_fast_calibration_z_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_foc_accel_z)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_acc_fast_calibration_z_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + s8 accel_offset_z = 0; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + unsigned char data1[3] = {0}; + err = kstrtoul(buf, 10, &data); + if (err) + return err; + /* 0: disable, 1: +1g, 2: -1g, 3: 0g */ + if (data > 3) + return -EINVAL; + + err = SMI_CALL_API(set_accel_foc_trigger)(Z_AXIS, + data, &accel_offset_z); + if (err) + return -EIO; + else + client_data->calib_status |= + SMI_FAST_CALI_TRUE << SMI_ACC_Z_FAST_CALI_RDY; + + if (client_data->calib_status == SMI_FAST_CALI_ALL_RDY) { + err = SMI_CALL_API(get_accel_offset_compensation_xaxis)( + &data1[0]); + err += SMI_CALL_API(get_accel_offset_compensation_yaxis)( + &data1[1]); + err += SMI_CALL_API(get_accel_offset_compensation_zaxis)( + &data1[2]); + dev_info(client_data->dev, "accx %d, accy %d, accz %d\n", + data1[0], data1[1], data1[2]); + if (err) + return -EIO; + input_event(client_data->input, EV_MSC, + INPUT_EVENT_FAST_ACC_CALIB_DONE, + (data1[0] | (data1[1] << 8) | (data1[2] << 16))); + input_sync(client_data->input); + client_data->calib_status = 0; + } + + return count; +} + +static ssize_t smi130_acc_offset_x_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_accel_offset_compensation_xaxis)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + + +static ssize_t smi130_acc_offset_x_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_accel_offset_compensation_xaxis) + ((unsigned char)data); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_acc_offset_y_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_accel_offset_compensation_yaxis)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_acc_offset_y_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_accel_offset_compensation_yaxis) + ((unsigned char)data); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_acc_offset_z_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_accel_offset_compensation_zaxis)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_acc_offset_z_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_accel_offset_compensation_zaxis) + ((unsigned char)data); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_test_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + u8 raw_data[15] = {0}; + unsigned int sensor_time = 0; + + int err; + memset(raw_data, 0, sizeof(raw_data)); + + err = client_data->device.bus_read(client_data->device.dev_addr, + SMI130_USER_DATA_8_GYRO_X_LSB__REG, raw_data, 15); + if (err) + return err; + + udelay(10); + sensor_time = (u32)(raw_data[14] << 16 | raw_data[13] << 8 + | raw_data[12]); + + return snprintf(buf, 128, "%d %d %d %d %d %d %u", + (s16)(raw_data[1] << 8 | raw_data[0]), + (s16)(raw_data[3] << 8 | raw_data[2]), + (s16)(raw_data[5] << 8 | raw_data[4]), + (s16)(raw_data[7] << 8 | raw_data[6]), + (s16)(raw_data[9] << 8 | raw_data[8]), + (s16)(raw_data[11] << 8 | raw_data[10]), + sensor_time); + +} + +static ssize_t smi130_step_counter_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = SMI_CALL_API(get_step_counter_enable)(&data); + + client_data->stc_enable = data; + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_step_counter_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_step_counter_enable)((unsigned char)data); + + client_data->stc_enable = data; + + if (err < 0) + return -EIO; + return count; +} + + +static ssize_t smi130_step_counter_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_step_mode)((unsigned char)data); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_step_counter_clc_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = smi130_clear_step_counter(); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_step_counter_value_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u16 data; + int err; + static u16 last_stc_value; + + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = SMI_CALL_API(read_step_count)(&data); + + if (err < 0) + return err; + if (data >= last_stc_value) { + client_data->pedo_data.last_step_counter_value += ( + data - last_stc_value); + last_stc_value = data; + } else + last_stc_value = data; + return snprintf(buf, 16, "%d\n", + client_data->pedo_data.last_step_counter_value); +} + +static ssize_t smi130_smi_value_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + u8 raw_data[12] = {0}; + + int err; + memset(raw_data, 0, sizeof(raw_data)); + + err = client_data->device.bus_read(client_data->device.dev_addr, + SMI130_USER_DATA_8_GYRO_X_LSB__REG, raw_data, 12); + if (err) + return err; + /*output:gyro x y z acc x y z*/ + return snprintf(buf, 96, "%hd %d %hd %hd %hd %hd\n", + (s16)(raw_data[1] << 8 | raw_data[0]), + (s16)(raw_data[3] << 8 | raw_data[2]), + (s16)(raw_data[5] << 8 | raw_data[4]), + (s16)(raw_data[7] << 8 | raw_data[6]), + (s16)(raw_data[9] << 8 | raw_data[8]), + (s16)(raw_data[11] << 8 | raw_data[10])); + +} + + +static ssize_t smi130_selftest_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + return snprintf(buf, 16, "0x%x\n", + atomic_read(&client_data->selftest_result)); +} + +static int smi_restore_hw_cfg(struct smi_client_data *client); + +/*! + * @brief store selftest result which make up of acc and gyro + * format: 0b 0000 xxxx x:1 failed, 0 success + * bit3: gyro_self + * bit2..0: acc_self z y x + */ +static ssize_t smi130_selftest_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err = 0; + int i = 0; + + u8 acc_selftest = 0; + u8 gyro_selftest = 0; + u8 smi_selftest = 0; + s16 axis_p_value, axis_n_value; + u16 diff_axis[3] = {0xff, 0xff, 0xff}; + u8 acc_odr, range, acc_selftest_amp, acc_selftest_sign; + + dev_notice(client_data->dev, "Selftest for SMI16x starting.\n"); + + client_data->selftest = 1; + + /*soft reset*/ + err = SMI_CALL_API(set_command_register)(CMD_RESET_USER_REG); + msleep(70); + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_NORMAL]); + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_NORMAL]); + err += SMI_CALL_API(set_accel_under_sampling_parameter)(0); + err += SMI_CALL_API(set_accel_output_data_rate)( + SMI130_ACCEL_OUTPUT_DATA_RATE_1600HZ); + + /* set to 8G range*/ + err += SMI_CALL_API(set_accel_range)(SMI130_ACCEL_RANGE_8G); + /* set to self amp high */ + err += SMI_CALL_API(set_accel_selftest_amp)(SMI_SELFTEST_AMP_HIGH); + + + err += SMI_CALL_API(get_accel_output_data_rate)(&acc_odr); + err += SMI_CALL_API(get_accel_range)(&range); + err += SMI_CALL_API(get_accel_selftest_amp)(&acc_selftest_amp); + err += SMI_CALL_API(read_accel_x)(&axis_n_value); + + dev_info(client_data->dev, + "acc_odr:%d, acc_range:%d, acc_selftest_amp:%d, acc_x:%d\n", + acc_odr, range, acc_selftest_amp, axis_n_value); + + for (i = X_AXIS; i < AXIS_MAX; i++) { + axis_n_value = 0; + axis_p_value = 0; + /* set every selftest axis */ + /*set_acc_selftest_axis(param),param x:1, y:2, z:3 + * but X_AXIS:0, Y_AXIS:1, Z_AXIS:2 + * so we need to +1*/ + err += SMI_CALL_API(set_accel_selftest_axis)(i + 1); + msleep(50); + switch (i) { + case X_AXIS: + /* set negative sign */ + err += SMI_CALL_API(set_accel_selftest_sign)(0); + err += SMI_CALL_API(get_accel_selftest_sign)( + &acc_selftest_sign); + + msleep(60); + err += SMI_CALL_API(read_accel_x)(&axis_n_value); + dev_info(client_data->dev, + "acc_x_selftest_sign:%d, axis_n_value:%d\n", + acc_selftest_sign, axis_n_value); + + /* set postive sign */ + err += SMI_CALL_API(set_accel_selftest_sign)(1); + err += SMI_CALL_API(get_accel_selftest_sign)( + &acc_selftest_sign); + + msleep(60); + err += SMI_CALL_API(read_accel_x)(&axis_p_value); + dev_info(client_data->dev, + "acc_x_selftest_sign:%d, axis_p_value:%d\n", + acc_selftest_sign, axis_p_value); + diff_axis[i] = abs(axis_p_value - axis_n_value); + break; + + case Y_AXIS: + /* set negative sign */ + err += SMI_CALL_API(set_accel_selftest_sign)(0); + msleep(60); + err += SMI_CALL_API(read_accel_y)(&axis_n_value); + /* set postive sign */ + err += SMI_CALL_API(set_accel_selftest_sign)(1); + msleep(60); + err += SMI_CALL_API(read_accel_y)(&axis_p_value); + diff_axis[i] = abs(axis_p_value - axis_n_value); + break; + + case Z_AXIS: + /* set negative sign */ + err += SMI_CALL_API(set_accel_selftest_sign)(0); + msleep(60); + err += SMI_CALL_API(read_accel_z)(&axis_n_value); + /* set postive sign */ + err += SMI_CALL_API(set_accel_selftest_sign)(1); + msleep(60); + err += SMI_CALL_API(read_accel_z)(&axis_p_value); + /* also start gyro self test */ + err += SMI_CALL_API(set_gyro_selftest_start)(1); + msleep(60); + err += SMI_CALL_API(get_gyro_selftest)(&gyro_selftest); + + diff_axis[i] = abs(axis_p_value - axis_n_value); + break; + default: + err += -EINVAL; + break; + } + if (err) { + dev_err(client_data->dev, + "Failed selftest axis:%s, p_val=%d, n_val=%d\n", + smi_axis_name[i], axis_p_value, axis_n_value); + client_data->selftest = 0; + return -EINVAL; + } + + /*400mg for acc z axis*/ + if (Z_AXIS == i) { + if (diff_axis[i] < 1639) { + acc_selftest |= 1 << i; + dev_err(client_data->dev, + "Over selftest minimum for " + "axis:%s,diff=%d,p_val=%d, n_val=%d\n", + smi_axis_name[i], diff_axis[i], + axis_p_value, axis_n_value); + } + } else { + /*800mg for x or y axis*/ + if (diff_axis[i] < 3277) { + acc_selftest |= 1 << i; + + if (smi_get_err_status(client_data) < 0) + return err; + dev_err(client_data->dev, + "Over selftest minimum for " + "axis:%s,diff=%d, p_val=%d, n_val=%d\n", + smi_axis_name[i], diff_axis[i], + axis_p_value, axis_n_value); + dev_err(client_data->dev, "err_st:0x%x\n", + client_data->err_st.err_st_all); + + } + } + + } + /* gyro_selftest==1,gyro selftest successfully, + * but smi_result bit4 0 is successful, 1 is failed*/ + smi_selftest = (acc_selftest & 0x0f) | ((!gyro_selftest) << AXIS_MAX); + atomic_set(&client_data->selftest_result, smi_selftest); + /*soft reset*/ + err = SMI_CALL_API(set_command_register)(CMD_RESET_USER_REG); + if (err) { + client_data->selftest = 0; + return err; + } + msleep(50); + + smi_restore_hw_cfg(client_data); + + client_data->selftest = 0; + dev_notice(client_data->dev, "Selftest for SMI16x finished\n"); + + return count; +} + +/* gyro sensor part */ +static ssize_t smi130_gyro_op_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int err = 0; + u8 gyro_pmu_status = 0; + + err = SMI_CALL_API(get_gyro_power_mode_stat)( + &gyro_pmu_status); + + if (err) + return err; + else + return snprintf(buf, 32, "reg:%d, val:%d\n", gyro_pmu_status, + client_data->pw.gyro_pm); +} + +static ssize_t smi130_gyro_op_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + unsigned long op_mode; + int err; + + err = kstrtoul(buf, 10, &op_mode); + if (err) + return err; + + mutex_lock(&client_data->mutex_op_mode); + + if (op_mode < SMI_GYRO_PM_MAX) { + switch (op_mode) { + case SMI_GYRO_PM_NORMAL: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_NORMAL]); + client_data->pw.gyro_pm = SMI_GYRO_PM_NORMAL; + smi_delay(60); + break; + case SMI_GYRO_PM_FAST_START: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_FAST_START]); + client_data->pw.gyro_pm = SMI_GYRO_PM_FAST_START; + smi_delay(60); + break; + case SMI_GYRO_PM_SUSPEND: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_SUSPEND]); + client_data->pw.gyro_pm = SMI_GYRO_PM_SUSPEND; + smi_delay(60); + break; + default: + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + } else { + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + + mutex_unlock(&client_data->mutex_op_mode); + + if (err) + return err; + else + return count; + +} + +static ssize_t smi130_gyro_value_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct smi130_gyro_t data; + int err; + + err = SMI_CALL_API(read_gyro_xyz)(&data); + if (err < 0) + return err; + + + return snprintf(buf, 48, "%hd %hd %hd\n", data.x, + data.y, data.z); +} + +static ssize_t smi130_gyro_range_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char range; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = SMI_CALL_API(get_gyro_range)(&range); + if (err) + return err; + + client_data->range.gyro_range = range; + return snprintf(buf, 16, "%d\n", range); +} + +static ssize_t smi130_gyro_range_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long range; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &range); + if (err) + return err; + + err = SMI_CALL_API(set_gyro_range)(range); + if (err) + return -EIO; + + client_data->range.gyro_range = range; + return count; +} + +static ssize_t smi130_gyro_odr_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err; + unsigned char gyro_odr; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = SMI_CALL_API(get_gyro_output_data_rate)(&gyro_odr); + if (err) + return err; + + client_data->odr.gyro_odr = gyro_odr; + return snprintf(buf, 16, "%d\n", gyro_odr); +} + +static ssize_t smi130_gyro_odr_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long gyro_odr; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &gyro_odr); + if (err) + return err; + + if (gyro_odr < 6 || gyro_odr > 13) + return -EIO; + + err = SMI_CALL_API(set_gyro_output_data_rate)(gyro_odr); + if (err) + return -EIO; + + client_data->odr.gyro_odr = gyro_odr; + return count; +} + +static ssize_t smi130_gyro_fast_calibration_en_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned char data; + int err; + + err = SMI_CALL_API(get_foc_gyro_enable)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_gyro_fast_calibration_en_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long enable; + s8 err; + s16 gyr_off_x; + s16 gyr_off_y; + s16 gyr_off_z; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &enable); + if (err) + return err; + + err = SMI_CALL_API(set_foc_gyro_enable)((u8)enable, + &gyr_off_x, &gyr_off_y, &gyr_off_z); + + if (err < 0) + return -EIO; + else { + input_event(client_data->input, EV_MSC, + INPUT_EVENT_FAST_GYRO_CALIB_DONE, 1); + input_sync(client_data->input); + } + return count; +} + +static ssize_t smi130_gyro_offset_x_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + s16 data = 0; + s8 err = 0; + + err = SMI_CALL_API(get_gyro_offset_compensation_xaxis)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_gyro_offset_x_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + s8 err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_gyro_offset_compensation_xaxis)((s16)data); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_gyro_offset_y_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + s16 data = 0; + s8 err = 0; + + err = SMI_CALL_API(get_gyro_offset_compensation_yaxis)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_gyro_offset_y_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + s8 err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_gyro_offset_compensation_yaxis)((s16)data); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_gyro_offset_z_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + s16 data = 0; + int err = 0; + + err = SMI_CALL_API(get_gyro_offset_compensation_zaxis)(&data); + + if (err < 0) + return err; + return snprintf(buf, 16, "%d\n", data); +} + +static ssize_t smi130_gyro_offset_z_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err = SMI_CALL_API(set_gyro_offset_compensation_zaxis)((s16)data); + + if (err < 0) + return -EIO; + return count; +} + + +/* mag sensor part */ +#ifdef SMI130_MAG_INTERFACE_SUPPORT +static ssize_t smi130_mag_op_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + u8 mag_op_mode; + s8 err; + err = smi130_get_mag_power_mode_stat(&mag_op_mode); + if (err) { + dev_err(client_data->dev, + "Failed to get SMI130 mag power mode:%d\n", err); + return err; + } else + return snprintf(buf, 32, "%d, reg:%d\n", + client_data->pw.mag_pm, mag_op_mode); +} + +static ssize_t smi130_mag_op_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + unsigned long op_mode; + int err; + + err = kstrtoul(buf, 10, &op_mode); + if (err) + return err; + + if (op_mode == client_data->pw.mag_pm) + return count; + + mutex_lock(&client_data->mutex_op_mode); + + + if (op_mode < SMI_MAG_PM_MAX) { + switch (op_mode) { + case SMI_MAG_PM_NORMAL: + /* need to modify as mag sensor connected, + * set write address to 0x4c and triggers + * write operation + * 0x4c(op mode control reg) + * enables normal mode in magnetometer */ +#if defined(SMI130_AKM09912_SUPPORT) + err = smi130_set_bosch_akm_and_secondary_if_powermode( + SMI130_MAG_FORCE_MODE); +#else + err = smi130_set_bmm150_mag_and_secondary_if_power_mode( + SMI130_MAG_FORCE_MODE); +#endif + client_data->pw.mag_pm = SMI_MAG_PM_NORMAL; + smi_delay(5); + break; + case SMI_MAG_PM_LP1: + /* need to modify as mag sensor connected, + * set write address to 0x4 band triggers + * write operation + * 0x4b(bmm150, power control reg, bit0) + * enables power in magnetometer*/ +#if defined(SMI130_AKM09912_SUPPORT) + err = smi130_set_bosch_akm_and_secondary_if_powermode( + SMI130_MAG_FORCE_MODE); +#else + err = smi130_set_bmm150_mag_and_secondary_if_power_mode( + SMI130_MAG_FORCE_MODE); +#endif + client_data->pw.mag_pm = SMI_MAG_PM_LP1; + smi_delay(5); + break; + case SMI_MAG_PM_SUSPEND: + case SMI_MAG_PM_LP2: +#if defined(SMI130_AKM09912_SUPPORT) + err = smi130_set_bosch_akm_and_secondary_if_powermode( + SMI130_MAG_SUSPEND_MODE); +#else + err = smi130_set_bmm150_mag_and_secondary_if_power_mode( + SMI130_MAG_SUSPEND_MODE); +#endif + client_data->pw.mag_pm = op_mode; + smi_delay(5); + break; + default: + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + } else { + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + + mutex_unlock(&client_data->mutex_op_mode); + + if (err) { + dev_err(client_data->dev, + "Failed to switch SMI130 mag power mode:%d\n", + client_data->pw.mag_pm); + return err; + } else + return count; + +} + +static ssize_t smi130_mag_odr_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err = 0; + unsigned char mag_odr = 0; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = SMI_CALL_API(get_mag_output_data_rate)(&mag_odr); + if (err) + return err; + + client_data->odr.mag_odr = mag_odr; + return snprintf(buf, 16, "%d\n", mag_odr); +} + +static ssize_t smi130_mag_odr_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long mag_odr; + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + err = kstrtoul(buf, 10, &mag_odr); + if (err) + return err; + /*1~25/32hz,..6(25hz),7(50hz),... */ + err = SMI_CALL_API(set_mag_output_data_rate)(mag_odr); + if (err) + return -EIO; + + client_data->odr.mag_odr = mag_odr; + return count; +} + +static ssize_t smi130_mag_i2c_address_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u8 data; + s8 err; + + err = SMI_CALL_API(set_mag_manual_enable)(1); + err += SMI_CALL_API(get_i2c_device_addr)(&data); + err += SMI_CALL_API(set_mag_manual_enable)(0); + + if (err < 0) + return err; + return snprintf(buf, 16, "0x%x\n", data); +} + +static ssize_t smi130_mag_i2c_address_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err += SMI_CALL_API(set_mag_manual_enable)(1); + if (!err) + err += SMI_CALL_API(set_i2c_device_addr)((unsigned char)data); + err += SMI_CALL_API(set_mag_manual_enable)(0); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_mag_value_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + struct smi130_mag_xyz_s32_t data; + int err; + /* raw data with compensation */ +#if defined(SMI130_AKM09912_SUPPORT) + err = smi130_bosch_akm09912_compensate_xyz(&data); +#else + err = smi130_bmm150_mag_compensate_xyz(&data); +#endif + + if (err < 0) { + memset(&data, 0, sizeof(data)); + dev_err(client_data->dev, "mag not ready!\n"); + } + return snprintf(buf, 48, "%hd %hd %hd\n", data.x, + data.y, data.z); +} +static ssize_t smi130_mag_offset_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int err = 0; + unsigned char mag_offset; + err = SMI_CALL_API(get_mag_offset)(&mag_offset); + if (err) + return err; + + return snprintf(buf, 16, "%d\n", mag_offset); + +} + +static ssize_t smi130_mag_offset_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long data; + int err; + + err = kstrtoul(buf, 10, &data); + if (err) + return err; + + err += SMI_CALL_API(set_mag_manual_enable)(1); + if (err == 0) + err += SMI_CALL_API(set_mag_offset)((unsigned char)data); + err += SMI_CALL_API(set_mag_manual_enable)(0); + + if (err < 0) + return -EIO; + return count; +} + +static ssize_t smi130_mag_chip_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + s8 err = 0; + u8 mag_chipid; + + err = smi130_set_mag_manual_enable(0x01); + /* read mag chip_id value */ +#if defined(SMI130_AKM09912_SUPPORT) + err += smi130_set_mag_read_addr(AKM09912_CHIP_ID_REG); + /* 0x04 is mag_x lsb register */ + err += smi130_read_reg(SMI130_USER_DATA_0_MAG_X_LSB__REG, + &mag_chipid, 1); + + /* Must add this commands to re-set data register addr of mag sensor */ + err += smi130_set_mag_read_addr(AKM_DATA_REGISTER); +#else + err += smi130_set_mag_read_addr(SMI130_BMM150_CHIP_ID); + /* 0x04 is mag_x lsb register */ + err += smi130_read_reg(SMI130_USER_DATA_0_MAG_X_LSB__REG, + &mag_chipid, 1); + + /* Must add this commands to re-set data register addr of mag sensor */ + /* 0x42 is bmm150 data register address */ + err += smi130_set_mag_read_addr(SMI130_BMM150_DATA_REG); +#endif + + err += smi130_set_mag_manual_enable(0x00); + + if (err) + return err; + + return snprintf(buf, 16, "%x\n", mag_chipid); + +} + +static ssize_t smi130_mag_chip_name_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u8 mag_chipid = 0; +#if defined(SMI130_AKM09912_SUPPORT) + mag_chipid = 15; +#else + mag_chipid = 150; +#endif + return snprintf(buf, 16, "%d\n", mag_chipid); +} + +struct smi130_mag_xyz_s32_t mag_compensate; +static ssize_t smi130_mag_compensate_xyz_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + memcpy(buf, &mag_compensate, sizeof(mag_compensate)); + return sizeof(mag_compensate); +} +static ssize_t smi130_mag_compensate_xyz_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct smi130_mag_xyzr_t mag_raw; + memset(&mag_compensate, 0, sizeof(mag_compensate)); + memset(&mag_raw, 0, sizeof(mag_raw)); + mag_raw.x = (buf[1] << 8 | buf[0]); + mag_raw.y = (buf[3] << 8 | buf[2]); + mag_raw.z = (buf[5] << 8 | buf[4]); + mag_raw.r = (buf[7] << 8 | buf[6]); + mag_raw.x = mag_raw.x >> 3; + mag_raw.y = mag_raw.y >> 3; + mag_raw.z = mag_raw.z >> 1; + mag_raw.r = mag_raw.r >> 2; + smi130_bmm150_mag_compensate_xyz_raw( + &mag_compensate, mag_raw); + return count; +} + +#endif + +#if defined(SMI130_ENABLE_INT1) || defined(SMI130_ENABLE_INT2) +static ssize_t smi_enable_int_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int interrupt_type, value; + + sscanf(buf, "%3d %3d", &interrupt_type, &value); + + if (interrupt_type < 0 || interrupt_type > 16) + return -EINVAL; + + if (interrupt_type <= SMI_FLAT_INT) { + if (SMI_CALL_API(set_intr_enable_0) + (smi_interrupt_type[interrupt_type], value) < 0) + return -EINVAL; + } else if (interrupt_type <= SMI_FWM_INT) { + if (SMI_CALL_API(set_intr_enable_1) + (smi_interrupt_type[interrupt_type], value) < 0) + return -EINVAL; + } else { + if (SMI_CALL_API(set_intr_enable_2) + (smi_interrupt_type[interrupt_type], value) < 0) + return -EINVAL; + } + + return count; +} + +#endif + +static ssize_t smi130_show_reg_sel(struct device *dev + , struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + if (client_data == NULL) { + printk(KERN_ERR "Invalid client_data pointer"); + return -ENODEV; + } + + return snprintf(buf, 64, "reg=0X%02X, len=%d\n", + client_data->reg_sel, client_data->reg_len); +} + +static ssize_t smi130_store_reg_sel(struct device *dev + , struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + ssize_t ret; + + if (client_data == NULL) { + printk(KERN_ERR "Invalid client_data pointer"); + return -ENODEV; + } + ret = sscanf(buf, "%11X %11d", + &client_data->reg_sel, &client_data->reg_len); + if (ret != 2) { + dev_err(client_data->dev, "Invalid argument"); + return -EINVAL; + } + + return count; +} + +static ssize_t smi130_show_reg_val(struct device *dev + , struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + + ssize_t ret; + u8 reg_data[128], i; + int pos; + + if (client_data == NULL) { + printk(KERN_ERR "Invalid client_data pointer"); + return -ENODEV; + } + + ret = smi_burst_read_wrapper(client_data->device.dev_addr, + client_data->reg_sel, + reg_data, client_data->reg_len); + if (ret < 0) { + dev_err(client_data->dev, "Reg op failed"); + return ret; + } + + pos = 0; + for (i = 0; i < client_data->reg_len; ++i) { + pos += snprintf(buf + pos, 16, "%02X", reg_data[i]); + buf[pos++] = (i + 1) % 16 == 0 ? '\n' : ' '; + } + if (buf[pos - 1] == ' ') + buf[pos - 1] = '\n'; + + return pos; +} + +static ssize_t smi130_store_reg_val(struct device *dev + , struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + ssize_t ret; + u8 reg_data[32]; + int i, j, status, digit; + + if (client_data == NULL) { + printk(KERN_ERR "Invalid client_data pointer"); + return -ENODEV; + } + status = 0; + for (i = j = 0; i < count && j < client_data->reg_len; ++i) { + if (buf[i] == ' ' || buf[i] == '\n' || buf[i] == '\t' || + buf[i] == '\r') { + status = 0; + ++j; + continue; + } + digit = buf[i] & 0x10 ? (buf[i] & 0xF) : ((buf[i] & 0xF) + 9); + printk(KERN_INFO "digit is %d", digit); + switch (status) { + case 2: + ++j; /* Fall thru */ + case 0: + reg_data[j] = digit; + status = 1; + break; + case 1: + reg_data[j] = reg_data[j] * 16 + digit; + status = 2; + break; + } + } + if (status > 0) + ++j; + if (j > client_data->reg_len) + j = client_data->reg_len; + else if (j < client_data->reg_len) { + dev_err(client_data->dev, "Invalid argument"); + return -EINVAL; + } + printk(KERN_INFO "Reg data read as"); + for (i = 0; i < j; ++i) + printk(KERN_INFO "%d", reg_data[i]); + + ret = SMI_CALL_API(write_reg)( + client_data->reg_sel, + reg_data, client_data->reg_len); + if (ret < 0) { + dev_err(client_data->dev, "Reg op failed"); + return ret; + } + + return count; +} + +static ssize_t smi130_driver_version_show(struct device *dev + , struct device_attribute *attr, char *buf) +{ + struct input_dev *input = to_input_dev(dev); + struct smi_client_data *client_data = input_get_drvdata(input); + int ret; + + if (client_data == NULL) { + printk(KERN_ERR "Invalid client_data pointer"); + return -ENODEV; + } + + ret = snprintf(buf, 128, "Driver version: %s\n", + DRIVER_VERSION); + + return ret; +} +static DEVICE_ATTR(chip_id, S_IRUGO, + smi130_chip_id_show, NULL); +static DEVICE_ATTR(err_st, S_IRUGO, + smi130_err_st_show, NULL); +static DEVICE_ATTR(sensor_time, S_IRUGO, + smi130_sensor_time_show, NULL); + +static DEVICE_ATTR(selftest, S_IRUGO | S_IWUSR, + smi130_selftest_show, smi130_selftest_store); +static DEVICE_ATTR(fifo_flush, S_IRUGO | S_IWUSR, + NULL, smi130_fifo_flush_store); +static DEVICE_ATTR(fifo_bytecount, S_IRUGO | S_IWUSR, + smi130_fifo_bytecount_show, smi130_fifo_bytecount_store); +static DEVICE_ATTR(fifo_data_sel, S_IRUGO | S_IWUSR, + smi130_fifo_data_sel_show, smi130_fifo_data_sel_store); +static DEVICE_ATTR(fifo_data_frame, S_IRUGO, + smi130_fifo_data_out_frame_show, NULL); + +static DEVICE_ATTR(fifo_watermark, S_IRUGO | S_IWUSR, + smi130_fifo_watermark_show, smi130_fifo_watermark_store); + +static DEVICE_ATTR(fifo_header_en, S_IRUGO | S_IWUSR, + smi130_fifo_header_en_show, smi130_fifo_header_en_store); +static DEVICE_ATTR(fifo_time_en, S_IRUGO | S_IWUSR, + smi130_fifo_time_en_show, smi130_fifo_time_en_store); +static DEVICE_ATTR(fifo_int_tag_en, S_IRUGO | S_IWUSR, + smi130_fifo_int_tag_en_show, smi130_fifo_int_tag_en_store); + +static DEVICE_ATTR(temperature, S_IRUGO, + smi130_temperature_show, NULL); +static DEVICE_ATTR(place, S_IRUGO, + smi130_place_show, NULL); +static DEVICE_ATTR(delay, S_IRUGO | S_IWUSR, + smi130_delay_show, smi130_delay_store); +static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, + smi130_enable_show, smi130_enable_store); +static DEVICE_ATTR(acc_range, S_IRUGO | S_IWUSR, + smi130_acc_range_show, smi130_acc_range_store); +static DEVICE_ATTR(acc_odr, S_IRUGO | S_IWUSR, + smi130_acc_odr_show, smi130_acc_odr_store); +static DEVICE_ATTR(acc_op_mode, S_IRUGO | S_IWUSR, + smi130_acc_op_mode_show, smi130_acc_op_mode_store); +static DEVICE_ATTR(acc_value, S_IRUGO, + smi130_acc_value_show, NULL); +static DEVICE_ATTR(acc_fast_calibration_x, S_IRUGO | S_IWUSR, + smi130_acc_fast_calibration_x_show, + smi130_acc_fast_calibration_x_store); +static DEVICE_ATTR(acc_fast_calibration_y, S_IRUGO | S_IWUSR, + smi130_acc_fast_calibration_y_show, + smi130_acc_fast_calibration_y_store); +static DEVICE_ATTR(acc_fast_calibration_z, S_IRUGO | S_IWUSR, + smi130_acc_fast_calibration_z_show, + smi130_acc_fast_calibration_z_store); +static DEVICE_ATTR(acc_offset_x, S_IRUGO | S_IWUSR, + smi130_acc_offset_x_show, + smi130_acc_offset_x_store); +static DEVICE_ATTR(acc_offset_y, S_IRUGO | S_IWUSR, + smi130_acc_offset_y_show, + smi130_acc_offset_y_store); +static DEVICE_ATTR(acc_offset_z, S_IRUGO | S_IWUSR, + smi130_acc_offset_z_show, + smi130_acc_offset_z_store); +static DEVICE_ATTR(test, S_IRUGO, + smi130_test_show, NULL); +static DEVICE_ATTR(stc_enable, S_IRUGO | S_IWUSR, + smi130_step_counter_enable_show, + smi130_step_counter_enable_store); +static DEVICE_ATTR(stc_mode, S_IRUGO | S_IWUSR, + NULL, smi130_step_counter_mode_store); +static DEVICE_ATTR(stc_clc, S_IRUGO | S_IWUSR, + NULL, smi130_step_counter_clc_store); +static DEVICE_ATTR(stc_value, S_IRUGO, + smi130_step_counter_value_show, NULL); +static DEVICE_ATTR(reg_sel, S_IRUGO | S_IWUSR, + smi130_show_reg_sel, smi130_store_reg_sel); +static DEVICE_ATTR(reg_val, S_IRUGO | S_IWUSR, + smi130_show_reg_val, smi130_store_reg_val); +static DEVICE_ATTR(driver_version, S_IRUGO, + smi130_driver_version_show, NULL); +/* gyro part */ +static DEVICE_ATTR(gyro_op_mode, S_IRUGO | S_IWUSR, + smi130_gyro_op_mode_show, smi130_gyro_op_mode_store); +static DEVICE_ATTR(gyro_value, S_IRUGO, + smi130_gyro_value_show, NULL); +static DEVICE_ATTR(gyro_range, S_IRUGO | S_IWUSR, + smi130_gyro_range_show, smi130_gyro_range_store); +static DEVICE_ATTR(gyro_odr, S_IRUGO | S_IWUSR, + smi130_gyro_odr_show, smi130_gyro_odr_store); +static DEVICE_ATTR(gyro_fast_calibration_en, S_IRUGO | S_IWUSR, +smi130_gyro_fast_calibration_en_show, smi130_gyro_fast_calibration_en_store); +static DEVICE_ATTR(gyro_offset_x, S_IRUGO | S_IWUSR, +smi130_gyro_offset_x_show, smi130_gyro_offset_x_store); +static DEVICE_ATTR(gyro_offset_y, S_IRUGO | S_IWUSR, +smi130_gyro_offset_y_show, smi130_gyro_offset_y_store); +static DEVICE_ATTR(gyro_offset_z, S_IRUGO | S_IWUSR, +smi130_gyro_offset_z_show, smi130_gyro_offset_z_store); + +#ifdef SMI130_MAG_INTERFACE_SUPPORT +static DEVICE_ATTR(mag_op_mode, S_IRUGO | S_IWUSR, + smi130_mag_op_mode_show, smi130_mag_op_mode_store); +static DEVICE_ATTR(mag_odr, S_IRUGO | S_IWUSR, + smi130_mag_odr_show, smi130_mag_odr_store); +static DEVICE_ATTR(mag_i2c_addr, S_IRUGO | S_IWUSR, + smi130_mag_i2c_address_show, smi130_mag_i2c_address_store); +static DEVICE_ATTR(mag_value, S_IRUGO, + smi130_mag_value_show, NULL); +static DEVICE_ATTR(mag_offset, S_IRUGO | S_IWUSR, + smi130_mag_offset_show, smi130_mag_offset_store); +static DEVICE_ATTR(mag_chip_id, S_IRUGO, + smi130_mag_chip_id_show, NULL); +static DEVICE_ATTR(mag_chip_name, S_IRUGO, + smi130_mag_chip_name_show, NULL); +static DEVICE_ATTR(mag_compensate, S_IRUGO | S_IWUSR, + smi130_mag_compensate_xyz_show, + smi130_mag_compensate_xyz_store); +#endif + + +#if defined(SMI130_ENABLE_INT1) || defined(SMI130_ENABLE_INT2) +static DEVICE_ATTR(enable_int, S_IRUGO | S_IWUSR, + NULL, smi_enable_int_store); +static DEVICE_ATTR(anymot_duration, S_IRUGO | S_IWUSR, + smi130_anymot_duration_show, smi130_anymot_duration_store); +static DEVICE_ATTR(anymot_threshold, S_IRUGO | S_IWUSR, + smi130_anymot_threshold_show, smi130_anymot_threshold_store); +static DEVICE_ATTR(std_stu, S_IRUGO, + smi130_step_detector_status_show, NULL); +static DEVICE_ATTR(std_en, S_IRUGO | S_IWUSR, + smi130_step_detector_enable_show, + smi130_step_detector_enable_store); +static DEVICE_ATTR(sig_en, S_IRUGO | S_IWUSR, + smi130_signification_motion_enable_show, + smi130_signification_motion_enable_store); + +#endif + + + +static DEVICE_ATTR(smi_value, S_IRUGO, + smi130_smi_value_show, NULL); + + +static struct attribute *smi130_attributes[] = { + &dev_attr_chip_id.attr, + &dev_attr_err_st.attr, + &dev_attr_sensor_time.attr, + &dev_attr_selftest.attr, + &dev_attr_driver_version.attr, + &dev_attr_test.attr, + &dev_attr_fifo_flush.attr, + &dev_attr_fifo_header_en.attr, + &dev_attr_fifo_time_en.attr, + &dev_attr_fifo_int_tag_en.attr, + &dev_attr_fifo_bytecount.attr, + &dev_attr_fifo_data_sel.attr, + &dev_attr_fifo_data_frame.attr, + + &dev_attr_fifo_watermark.attr, + + &dev_attr_enable.attr, + &dev_attr_delay.attr, + &dev_attr_temperature.attr, + &dev_attr_place.attr, + + &dev_attr_acc_range.attr, + &dev_attr_acc_odr.attr, + &dev_attr_acc_op_mode.attr, + &dev_attr_acc_value.attr, + + &dev_attr_acc_fast_calibration_x.attr, + &dev_attr_acc_fast_calibration_y.attr, + &dev_attr_acc_fast_calibration_z.attr, + &dev_attr_acc_offset_x.attr, + &dev_attr_acc_offset_y.attr, + &dev_attr_acc_offset_z.attr, + + &dev_attr_stc_enable.attr, + &dev_attr_stc_mode.attr, + &dev_attr_stc_clc.attr, + &dev_attr_stc_value.attr, + + &dev_attr_gyro_op_mode.attr, + &dev_attr_gyro_value.attr, + &dev_attr_gyro_range.attr, + &dev_attr_gyro_odr.attr, + &dev_attr_gyro_fast_calibration_en.attr, + &dev_attr_gyro_offset_x.attr, + &dev_attr_gyro_offset_y.attr, + &dev_attr_gyro_offset_z.attr, + +#ifdef SMI130_MAG_INTERFACE_SUPPORT + &dev_attr_mag_chip_id.attr, + &dev_attr_mag_op_mode.attr, + &dev_attr_mag_odr.attr, + &dev_attr_mag_i2c_addr.attr, + &dev_attr_mag_chip_name.attr, + &dev_attr_mag_value.attr, + &dev_attr_mag_offset.attr, + &dev_attr_mag_compensate.attr, +#endif + +#if defined(SMI130_ENABLE_INT1) || defined(SMI130_ENABLE_INT2) + &dev_attr_enable_int.attr, + + &dev_attr_anymot_duration.attr, + &dev_attr_anymot_threshold.attr, + &dev_attr_std_stu.attr, + &dev_attr_std_en.attr, + &dev_attr_sig_en.attr, + +#endif + &dev_attr_reg_sel.attr, + &dev_attr_reg_val.attr, + &dev_attr_smi_value.attr, + NULL +}; + +static struct attribute_group smi130_attribute_group = { + .attrs = smi130_attributes +}; + +#if defined(SMI130_ENABLE_INT1) || defined(SMI130_ENABLE_INT2) +static void smi_slope_interrupt_handle(struct smi_client_data *client_data) +{ + /* anym_first[0..2]: x, y, z */ + u8 anym_first[3] = {0}; + u8 status2; + u8 anym_sign; + u8 i = 0; + + client_data->device.bus_read(client_data->device.dev_addr, + SMI130_USER_INTR_STAT_2_ADDR, &status2, 1); + anym_first[0] = SMI130_GET_BITSLICE(status2, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_X); + anym_first[1] = SMI130_GET_BITSLICE(status2, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y); + anym_first[2] = SMI130_GET_BITSLICE(status2, + SMI130_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z); + anym_sign = SMI130_GET_BITSLICE(status2, + SMI130_USER_INTR_STAT_2_ANY_MOTION_SIGN); + + for (i = 0; i < 3; i++) { + if (anym_first[i]) { + /*1: negative*/ + if (anym_sign) + dev_notice(client_data->dev, + "Anymotion interrupt happend!" + "%s axis, negative sign\n", smi_axis_name[i]); + else + dev_notice(client_data->dev, + "Anymotion interrupt happend!" + "%s axis, postive sign\n", smi_axis_name[i]); + } + } + + +} + +static void smi_fifo_watermark_interrupt_handle + (struct smi_client_data *client_data) +{ + int err = 0; + unsigned int fifo_len0 = 0; + unsigned int fifo_frmbytes_ext = 0; + unsigned char *fifo_data = NULL; + fifo_data = kzalloc(FIFO_DATA_BUFSIZE, GFP_KERNEL); + /*TO DO*/ + if (NULL == fifo_data) { + dev_err(client_data->dev, "no memory available"); + err = -ENOMEM; + } + smi_fifo_frame_bytes_extend_calc(client_data, &fifo_frmbytes_ext); + + if (client_data->pw.acc_pm == 2 && client_data->pw.gyro_pm == 2 + && client_data->pw.mag_pm == 2) + printk(KERN_INFO "pw_acc: %d, pw_gyro: %d\n", + client_data->pw.acc_pm, client_data->pw.gyro_pm); + if (!client_data->fifo_data_sel) + printk(KERN_INFO "no selsect sensor fifo, fifo_data_sel:%d\n", + client_data->fifo_data_sel); + + err = SMI_CALL_API(fifo_length)(&fifo_len0); + client_data->fifo_bytecount = fifo_len0; + + if (client_data->fifo_bytecount == 0 || err) + return; + + if (client_data->fifo_bytecount + fifo_frmbytes_ext > FIFO_DATA_BUFSIZE) + client_data->fifo_bytecount = FIFO_DATA_BUFSIZE; + /* need give attention for the time of burst read*/ + if (!err) { + err = smi_burst_read_wrapper(client_data->device.dev_addr, + SMI130_USER_FIFO_DATA__REG, fifo_data, + client_data->fifo_bytecount + fifo_frmbytes_ext); + } else + dev_err(client_data->dev, "read fifo leght err"); + + if (err) + dev_err(client_data->dev, "brust read fifo err\n"); + /*err = smi_fifo_analysis_handle(client_data, fifo_data, + client_data->fifo_bytecount + 20, fifo_out_data);*/ + if (fifo_data != NULL) { + kfree(fifo_data); + fifo_data = NULL; + } + +} +static void smi_data_ready_interrupt_handle( + struct smi_client_data *client_data, uint8_t status) +{ + uint8_t data12[12] = {0}; + struct smi130_accel_t accel; + struct smi130_gyro_t gyro; + struct timespec ts; + client_data->device.bus_read(client_data->device.dev_addr, + SMI130_USER_DATA_8_ADDR, data12, 12); + if (status & 0x80) + { + /*report acc data*/ + /* Data X */ + accel.x = (s16)((((s32)((s8)data12[7])) << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (data12[6])); + /* Data Y */ + accel.y = (s16)((((s32)((s8)data12[9])) << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (data12[8])); + /* Data Z */ + accel.z = (s16)((((s32)((s8)data12[11]))<< SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (data12[10])); + ts = ns_to_timespec(client_data->timestamp); + input_event(client_data->input, EV_MSC, 6, ts.tv_sec); + input_event(client_data->input, EV_MSC, 6, ts.tv_nsec); + input_event(client_data->input, EV_MSC, MSC_GESTURE, accel.x); + input_event(client_data->input, EV_MSC, MSC_RAW, accel.y); + input_event(client_data->input, EV_MSC, MSC_SCAN, accel.z); + input_sync(client_data->input); + } + if (status & 0x40) + { + /*report gyro data*/ + /* Data X */ + gyro.x = (s16)((((s32)((s8)data12[1])) << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (data12[0])); + /* Data Y */ + gyro.y = (s16)((((s32)((s8)data12[3])) << SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (data12[2])); + /* Data Z */ + gyro.z = (s16)((((s32)((s8)data12[5]))<< SMI130_SHIFT_BIT_POSITION_BY_08_BITS) | (data12[4])); + ts = ns_to_timespec(client_data->timestamp); + input_event(client_data->gyro_input, EV_MSC, 6, ts.tv_sec); + input_event(client_data->gyro_input, EV_MSC, 6, ts.tv_nsec); + input_event(client_data->gyro_input, EV_MSC, MSC_GESTURE, gyro.x); + input_event(client_data->gyro_input, EV_MSC, MSC_RAW, gyro.y); + input_event(client_data->gyro_input, EV_MSC, MSC_SCAN, gyro.z); + input_sync(client_data->gyro_input); + } +} + +static void smi_signification_motion_interrupt_handle( + struct smi_client_data *client_data) +{ + printk(KERN_INFO "smi_signification_motion_interrupt_handle\n"); + input_event(client_data->input, EV_MSC, INPUT_EVENT_SGM, 1); +/*input_report_rel(client_data->input,INPUT_EVENT_SGM,1);*/ + input_sync(client_data->input); + smi130_set_command_register(CMD_RESET_INT_ENGINE); + +} +static void smi_stepdetector_interrupt_handle( + struct smi_client_data *client_data) +{ + u8 current_step_dector_st = 0; + client_data->pedo_data.wkar_step_detector_status++; + current_step_dector_st = + client_data->pedo_data.wkar_step_detector_status; + client_data->std = ((current_step_dector_st == 1) ? 0 : 1); + + input_event(client_data->input, EV_MSC, INPUT_EVENT_STEP_DETECTOR, 1); + input_sync(client_data->input); +} + +static void smi_irq_work_func(struct work_struct *work) +{ + struct smi_client_data *client_data = + container_of((struct work_struct *)work, + struct smi_client_data, irq_work); + + unsigned char int_status[4] = {0, 0, 0, 0}; + uint8_t status = 0; + + //client_data->device.bus_read(client_data->device.dev_addr, + // SMI130_USER_INTR_STAT_0_ADDR, int_status, 4); + client_data->device.bus_read(client_data->device.dev_addr, + SMI130_USER_STAT_ADDR, &status, 1); + printk("status = 0x%x", status); + if (SMI130_GET_BITSLICE(int_status[0], + SMI130_USER_INTR_STAT_0_ANY_MOTION)) + smi_slope_interrupt_handle(client_data); + + if (SMI130_GET_BITSLICE(int_status[0], + SMI130_USER_INTR_STAT_0_STEP_INTR)) + smi_stepdetector_interrupt_handle(client_data); + if (SMI130_GET_BITSLICE(int_status[1], + SMI130_USER_INTR_STAT_1_FIFO_WM_INTR)) + smi_fifo_watermark_interrupt_handle(client_data); + if ((status & 0x80) || (status & 0x40)) + smi_data_ready_interrupt_handle(client_data, status); + /* Clear ALL inputerrupt status after handler sig mition*/ + /* Put this commads intot the last one*/ + if (SMI130_GET_BITSLICE(int_status[0], + SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR)) + smi_signification_motion_interrupt_handle(client_data); + +} + +static void smi130_delay_sigmo_work_func(struct work_struct *work) +{ + struct smi_client_data *client_data = + container_of(work, struct smi_client_data, + delay_work_sig.work); + unsigned char int_status[4] = {0, 0, 0, 0}; + + client_data->device.bus_read(client_data->device.dev_addr, + SMI130_USER_INTR_STAT_0_ADDR, int_status, 4); + if (SMI130_GET_BITSLICE(int_status[0], + SMI130_USER_INTR_STAT_0_SIGNIFICANT_INTR)) + smi_signification_motion_interrupt_handle(client_data); +} + +static irqreturn_t smi_irq_handler(int irq, void *handle) +{ + struct smi_client_data *client_data = handle; + int in_suspend_copy; + in_suspend_copy = atomic_read(&client_data->in_suspend); + + if (client_data == NULL) + return IRQ_HANDLED; + if (client_data->dev == NULL) + return IRQ_HANDLED; + /*this only deal with SIG_motion CTS test*/ + if ((in_suspend_copy == 1) && + (client_data->sig_flag == 1)) { + /*wake_lock_timeout(&client_data->wakelock, HZ);*/ + schedule_delayed_work(&client_data->delay_work_sig, + msecs_to_jiffies(50)); + } + schedule_work(&client_data->irq_work); + + return IRQ_HANDLED; +} +#endif /* defined(SMI_ENABLE_INT1)||defined(SMI_ENABLE_INT2) */ + +static int smi_restore_hw_cfg(struct smi_client_data *client) +{ + int err = 0; + + if ((client->fifo_data_sel) & (1 << SMI_ACC_SENSOR)) { + err += SMI_CALL_API(set_accel_range)(client->range.acc_range); + err += SMI_CALL_API(set_accel_output_data_rate) + (client->odr.acc_odr); + err += SMI_CALL_API(set_fifo_accel_enable)(1); + } + if ((client->fifo_data_sel) & (1 << SMI_GYRO_SENSOR)) { + err += SMI_CALL_API(set_gyro_range)(client->range.gyro_range); + err += SMI_CALL_API(set_gyro_output_data_rate) + (client->odr.gyro_odr); + err += SMI_CALL_API(set_fifo_gyro_enable)(1); + } + if ((client->fifo_data_sel) & (1 << SMI_MAG_SENSOR)) { + err += SMI_CALL_API(set_mag_output_data_rate) + (client->odr.mag_odr); + err += SMI_CALL_API(set_fifo_mag_enable)(1); + } + err += SMI_CALL_API(set_command_register)(CMD_CLR_FIFO_DATA); + + mutex_lock(&client->mutex_op_mode); + if (client->pw.acc_pm != SMI_ACC_PM_SUSPEND) { + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_NORMAL]); + smi_delay(3); + } + mutex_unlock(&client->mutex_op_mode); + + mutex_lock(&client->mutex_op_mode); + if (client->pw.gyro_pm != SMI_GYRO_PM_SUSPEND) { + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_NORMAL]); + smi_delay(3); + } + mutex_unlock(&client->mutex_op_mode); + + mutex_lock(&client->mutex_op_mode); + + if (client->pw.mag_pm != SMI_MAG_PM_SUSPEND) { +#ifdef SMI130_AKM09912_SUPPORT + err += smi130_set_bosch_akm_and_secondary_if_powermode + (SMI130_MAG_FORCE_MODE); +#else + err += smi130_set_bmm150_mag_and_secondary_if_power_mode + (SMI130_MAG_FORCE_MODE); +#endif + smi_delay(3); + } + mutex_unlock(&client->mutex_op_mode); + + return err; +} + +#if defined(CONFIG_USE_QUALCOMM_HAL) +static void smi130_accel_work_fn(struct work_struct *work) +{ + struct smi_client_data *sensor; + ktime_t timestamp; + struct smi130_accel_t data; + int err; + sensor = container_of((struct delayed_work *)work, + struct smi_client_data, accel_poll_work); + timestamp = ktime_get(); + err = SMI_CALL_API(read_accel_xyz)(&data); + if (err) + dev_err(sensor->dev, "read data err"); + input_report_abs(sensor->input, ABS_X, + (data.x)); + input_report_abs(sensor->input, ABS_Y, + (data.y)); + input_report_abs(sensor->input, ABS_Z, + (data.z)); + input_event(sensor->input, + EV_SYN, SYN_TIME_SEC, + ktime_to_timespec(timestamp).tv_sec); + input_event(sensor->input, EV_SYN, + SYN_TIME_NSEC, + ktime_to_timespec(timestamp).tv_nsec); + input_sync(sensor->input); + if (atomic_read(&sensor->accel_en)) + queue_delayed_work(sensor->data_wq, + &sensor->accel_poll_work, + msecs_to_jiffies(sensor->accel_poll_ms)); +} +static void smi130_gyro_work_fn(struct work_struct *work) +{ + struct smi_client_data *sensor; + ktime_t timestamp; + struct smi130_gyro_t data; + int err; + sensor = container_of((struct delayed_work *)work, + struct smi_client_data, gyro_poll_work); + timestamp = ktime_get(); + err = SMI_CALL_API(read_gyro_xyz)(&data); + if (err) + dev_err(sensor->dev, "read data err"); + input_report_abs(sensor->gyro_input, ABS_RX, + (data.x)); + input_report_abs(sensor->gyro_input, ABS_RY, + (data.y)); + input_report_abs(sensor->gyro_input, ABS_RZ, + (data.z)); + input_event(sensor->gyro_input, + EV_SYN, SYN_TIME_SEC, + ktime_to_timespec(timestamp).tv_sec); + input_event(sensor->gyro_input, EV_SYN, + SYN_TIME_NSEC, + ktime_to_timespec(timestamp).tv_nsec); + input_sync(sensor->gyro_input); + if (atomic_read(&sensor->gyro_en)) + queue_delayed_work(sensor->data_wq, + &sensor->gyro_poll_work, + msecs_to_jiffies(sensor->gyro_poll_ms)); +} +static int smi130_set_gyro_op_mode(struct smi_client_data *client_data, + unsigned long op_mode) +{ + int err = 0; + mutex_lock(&client_data->mutex_op_mode); + if (op_mode < SMI_GYRO_PM_MAX) { + switch (op_mode) { + case SMI_GYRO_PM_NORMAL: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_NORMAL]); + client_data->pw.gyro_pm = SMI_GYRO_PM_NORMAL; + smi_delay(60); + break; + case SMI_GYRO_PM_FAST_START: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_FAST_START]); + client_data->pw.gyro_pm = SMI_GYRO_PM_FAST_START; + smi_delay(60); + break; + case SMI_GYRO_PM_SUSPEND: + err = SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_SUSPEND]); + client_data->pw.gyro_pm = SMI_GYRO_PM_SUSPEND; + smi_delay(60); + break; + default: + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + } else { + mutex_unlock(&client_data->mutex_op_mode); + return -EINVAL; + } + mutex_unlock(&client_data->mutex_op_mode); + return err; +} +static int smi130_accel_set_enable( + struct smi_client_data *client_data, bool enable) +{ + int ret = 0; + dev_notice(client_data->dev, + "smi130_accel_set_enable enable=%d\n", enable); + if (enable) { + ret = smi130_set_acc_op_mode(client_data, 0); + if (ret) { + dev_err(client_data->dev, + "Fail to enable accel engine ret=%d\n", ret); + ret = -EBUSY; + goto exit; + } + queue_delayed_work(client_data->data_wq, + &client_data->accel_poll_work, + msecs_to_jiffies(client_data->accel_poll_ms)); + atomic_set(&client_data->accel_en, 1); + } else { + atomic_set(&client_data->accel_en, 0); + cancel_delayed_work_sync(&client_data->accel_poll_work); + ret = smi130_set_acc_op_mode(client_data, 2); + if (ret) { + dev_err(client_data->dev, + "Fail to disable accel engine ret=%d\n", ret); + ret = -EBUSY; + goto exit; + } + } +exit: + return ret; +} +static int smi130_accel_set_poll_delay(struct smi_client_data *client_data, + unsigned long delay) +{ + dev_info(client_data->dev, + "smi130_accel_set_poll_delay delay_ms=%ld\n", delay); + if (delay < SMI130_ACCEL_MIN_POLL_INTERVAL_MS) + delay = SMI130_ACCEL_MIN_POLL_INTERVAL_MS; + if (delay > SMI130_ACCEL_MAX_POLL_INTERVAL_MS) + delay = SMI130_ACCEL_MAX_POLL_INTERVAL_MS; + client_data->accel_poll_ms = delay; + if (!atomic_read(&client_data->accel_en)) + goto exit; + cancel_delayed_work_sync(&client_data->accel_poll_work); + queue_delayed_work(client_data->data_wq, + &client_data->accel_poll_work, + msecs_to_jiffies(client_data->accel_poll_ms)); +exit: + return 0; +} +static int smi130_gyro_set_enable( + struct smi_client_data *client_data, bool enable) +{ + int ret = 0; + dev_notice(client_data->dev, + "smi130_gyro_set_enable enable=%d\n", enable); + if (enable) { + ret = smi130_set_gyro_op_mode(client_data, 0); + if (ret) { + dev_err(client_data->dev, + "Fail to enable gyro engine ret=%d\n", ret); + ret = -EBUSY; + goto exit; + } + queue_delayed_work(client_data->data_wq, + &client_data->gyro_poll_work, + msecs_to_jiffies(client_data->gyro_poll_ms)); + atomic_set(&client_data->gyro_en, 1); + } else { + atomic_set(&client_data->gyro_en, 0); + cancel_delayed_work_sync(&client_data->gyro_poll_work); + ret = smi130_set_gyro_op_mode(client_data, 2); + if (ret) { + dev_err(client_data->dev, + "Fail to disable accel engine ret=%d\n", ret); + ret = -EBUSY; + goto exit; + } + } +exit: + return ret; +} +static int smi130_gyro_set_poll_delay(struct smi_client_data *client_data, + unsigned long delay) +{ + dev_info(client_data->dev, + "smi130_accel_set_poll_delay delay_ms=%ld\n", delay); + if (delay < SMI130_GYRO_MIN_POLL_INTERVAL_MS) + delay = SMI130_GYRO_MIN_POLL_INTERVAL_MS; + if (delay > SMI130_GYRO_MAX_POLL_INTERVAL_MS) + delay = SMI130_GYRO_MAX_POLL_INTERVAL_MS; + client_data->gyro_poll_ms = delay; + if (!atomic_read(&client_data->gyro_en)) + goto exit; + cancel_delayed_work_sync(&client_data->gyro_poll_work); + queue_delayed_work(client_data->data_wq, + &client_data->gyro_poll_work, + msecs_to_jiffies(client_data->gyro_poll_ms)); +exit: + return 0; +} +static int smi130_accel_cdev_enable(struct sensors_classdev *sensors_cdev, + unsigned int enable) +{ + struct smi_client_data *sensor = container_of(sensors_cdev, + struct smi_client_data, accel_cdev); + return smi130_accel_set_enable(sensor, enable); +} +static int smi130_accel_cdev_poll_delay(struct sensors_classdev *sensors_cdev, + unsigned int delay_ms) +{ + struct smi_client_data *sensor = container_of(sensors_cdev, + struct smi_client_data, accel_cdev); + + return smi130_accel_set_poll_delay(sensor, delay_ms); +} + +static int smi130_gyro_cdev_enable(struct sensors_classdev *sensors_cdev, + unsigned int enable) +{ + struct smi_client_data *sensor = container_of(sensors_cdev, + struct smi_client_data, gyro_cdev); + + return smi130_gyro_set_enable(sensor, enable); +} + +static int smi130_gyro_cdev_poll_delay(struct sensors_classdev *sensors_cdev, + unsigned int delay_ms) +{ + struct smi_client_data *sensor = container_of(sensors_cdev, + struct smi_client_data, gyro_cdev); + + return smi130_gyro_set_poll_delay(sensor, delay_ms); +} +#endif + +int smi_probe(struct smi_client_data *client_data, struct device *dev) +{ + int err = 0; +#ifdef SMI130_MAG_INTERFACE_SUPPORT + u8 mag_dev_addr; + u8 mag_urst_len; + u8 mag_op_mode; +#endif + /* check chip id */ + err = smi_check_chip_id(client_data); + if (err) + goto exit_err_clean; + + dev_set_drvdata(dev, client_data); + client_data->dev = dev; + + mutex_init(&client_data->mutex_enable); + mutex_init(&client_data->mutex_op_mode); + + /* input device init */ + err = smi_input_init(client_data); + if (err < 0) + goto exit_err_clean; + + /* sysfs node creation */ + err = sysfs_create_group(&client_data->input->dev.kobj, + &smi130_attribute_group); + + if (err < 0) + goto exit_err_sysfs; + + if (NULL != dev->platform_data) { + client_data->bosch_pd = kzalloc(sizeof(*client_data->bosch_pd), + GFP_KERNEL); + + if (NULL != client_data->bosch_pd) { + memcpy(client_data->bosch_pd, dev->platform_data, + sizeof(*client_data->bosch_pd)); + dev_notice(dev, "%s sensor driver set place: p%d\n", + client_data->bosch_pd->name, + client_data->bosch_pd->place); + } + } + + if (NULL != client_data->bosch_pd) { + memcpy(client_data->bosch_pd, dev->platform_data, + sizeof(*client_data->bosch_pd)); + dev_notice(dev, "%s sensor driver set place: p%d\n", + client_data->bosch_pd->name, + client_data->bosch_pd->place); + } + + + /* workqueue init */ + INIT_DELAYED_WORK(&client_data->work, smi_work_func); + atomic_set(&client_data->delay, SMI_DELAY_DEFAULT); + atomic_set(&client_data->wkqueue_en, 0); + + /* h/w init */ + client_data->device.delay_msec = smi_delay; + err = SMI_CALL_API(init)(&client_data->device); + + smi_dump_reg(client_data); + + /*power on detected*/ + /*or softrest(cmd 0xB6) */ + /*fatal err check*/ + /*soft reset*/ + err += SMI_CALL_API(set_command_register)(CMD_RESET_USER_REG); + smi_delay(3); + if (err) + dev_err(dev, "Failed soft reset, er=%d", err); + /*usr data config page*/ + err += SMI_CALL_API(set_target_page)(USER_DAT_CFG_PAGE); + if (err) + dev_err(dev, "Failed cffg page, er=%d", err); + err += smi_get_err_status(client_data); + if (err) { + dev_err(dev, "Failed to smi16x init!err_st=0x%x\n", + client_data->err_st.err_st_all); + goto exit_err_sysfs; + } + +#ifdef SMI130_MAG_INTERFACE_SUPPORT + err += smi130_set_command_register(MAG_MODE_NORMAL); + smi_delay(2); + err += smi130_get_mag_power_mode_stat(&mag_op_mode); + smi_delay(2); + err += SMI_CALL_API(get_i2c_device_addr)(&mag_dev_addr); + smi_delay(2); +#if defined(SMI130_AKM09912_SUPPORT) + err += SMI_CALL_API(set_i2c_device_addr)(SMI130_AKM09912_I2C_ADDRESS); + smi130_bosch_akm_mag_interface_init(SMI130_AKM09912_I2C_ADDRESS); +#else + err += SMI_CALL_API(set_i2c_device_addr)( + SMI130_AUX_BMM150_I2C_ADDRESS); + smi130_bmm150_mag_interface_init(); +#endif + + err += smi130_set_mag_burst(3); + err += smi130_get_mag_burst(&mag_urst_len); + if (err) + dev_err(client_data->dev, "Failed cffg mag, er=%d", err); + dev_info(client_data->dev, + "SMI130 mag_urst_len:%d, mag_add:0x%x, mag_op_mode:%d\n", + mag_urst_len, mag_dev_addr, mag_op_mode); +#endif + if (err < 0) + goto exit_err_sysfs; + + +#if defined(SMI130_ENABLE_INT1) || defined(SMI130_ENABLE_INT2) + /*wake_lock_init(&client_data->wakelock, + WAKE_LOCK_SUSPEND, "smi130");*/ + client_data->gpio_pin = of_get_named_gpio_flags(dev->of_node, + "smi,gpio_irq", 0, NULL); + dev_info(client_data->dev, "SMI130 qpio number:%d\n", + client_data->gpio_pin); + err += gpio_request_one(client_data->gpio_pin, + GPIOF_IN, "smi130_int"); + err += gpio_direction_input(client_data->gpio_pin); + client_data->IRQ = gpio_to_irq(client_data->gpio_pin); + if (err) { + dev_err(client_data->dev, + "can not request gpio to irq number\n"); + client_data->gpio_pin = 0; + } + INIT_DELAYED_WORK(&client_data->delay_work_sig, + smi130_delay_sigmo_work_func); +#ifdef SMI130_ENABLE_INT1 + /* maps interrupt to INT1/InT2 pin */ + SMI_CALL_API(set_intr_any_motion)(SMI_INT0, ENABLE); + SMI_CALL_API(set_intr_fifo_wm)(SMI_INT0, ENABLE); + SMI_CALL_API(set_intr_data_rdy)(SMI_INT0, ENABLE); + + /*Set interrupt trige level way */ + SMI_CALL_API(set_intr_edge_ctrl)(SMI_INT0, SMI_INT_LEVEL); + smi130_set_intr_level(SMI_INT0, 1); + /*set interrupt latch temporary, 5 ms*/ + /*smi130_set_latch_int(5);*/ + + SMI_CALL_API(set_output_enable)( + SMI130_INTR1_OUTPUT_ENABLE, ENABLE); + sigmotion_init_interrupts(SMI130_MAP_INTR1); + SMI_CALL_API(map_step_detector_intr)(SMI130_MAP_INTR1); + /*close step_detector in init function*/ + SMI_CALL_API(set_step_detector_enable)(0); +#endif + +#ifdef SMI130_ENABLE_INT2 + /* maps interrupt to INT1/InT2 pin */ + SMI_CALL_API(set_intr_any_motion)(SMI_INT1, ENABLE); + SMI_CALL_API(set_intr_fifo_wm)(SMI_INT1, ENABLE); + SMI_CALL_API(set_intr_data_rdy)(SMI_INT1, ENABLE); + + /*Set interrupt trige level way */ + SMI_CALL_API(set_intr_edge_ctrl)(SMI_INT1, SMI_INT_LEVEL); + smi130_set_intr_level(SMI_INT1, 1); + /*set interrupt latch temporary, 5 ms*/ + /*smi130_set_latch_int(5);*/ + + SMI_CALL_API(set_output_enable)( + SMI130_INTR2_OUTPUT_ENABLE, ENABLE); + sigmotion_init_interrupts(SMI130_MAP_INTR2); + SMI_CALL_API(map_step_detector_intr)(SMI130_MAP_INTR2); + /*close step_detector in init function*/ + SMI_CALL_API(set_step_detector_enable)(0); +#endif + err = request_irq(client_data->IRQ, smi_irq_handler, + IRQF_TRIGGER_RISING, "smi130", client_data); + if (err) + dev_err(client_data->dev, "could not request irq\n"); + + INIT_WORK(&client_data->irq_work, smi_irq_work_func); +#endif + + client_data->selftest = 0; + + client_data->fifo_data_sel = 0; + #if defined(CONFIG_USE_QUALCOMM_HAL) + SMI_CALL_API(set_accel_output_data_rate)(9);/*defalut odr 200HZ*/ + SMI_CALL_API(set_gyro_output_data_rate)(9);/*defalut odr 200HZ*/ + #endif + SMI_CALL_API(get_accel_output_data_rate)(&client_data->odr.acc_odr); + SMI_CALL_API(get_gyro_output_data_rate)(&client_data->odr.gyro_odr); + SMI_CALL_API(get_mag_output_data_rate)(&client_data->odr.mag_odr); + SMI_CALL_API(set_fifo_time_enable)(1); + SMI_CALL_API(get_accel_range)(&client_data->range.acc_range); + SMI_CALL_API(get_gyro_range)(&client_data->range.gyro_range); + /* now it's power on which is considered as resuming from suspend */ + + /* gyro input device init */ + err = smi_gyro_input_init(client_data); + #if defined(CONFIG_USE_QUALCOMM_HAL) + /* gyro input device init */ + err = smi_gyro_input_init(client_data); + if (err < 0) + goto exit_err_clean; + client_data->accel_poll_ms = SMI130_ACCEL_DEFAULT_POLL_INTERVAL_MS; + client_data->gyro_poll_ms = SMI130_GYRO_DEFAULT_POLL_INTERVAL_MS; + client_data->data_wq = create_freezable_workqueue("smi130_data_work"); + if (!client_data->data_wq) { + dev_err(dev, "Cannot create workqueue!\n"); + goto exit_err_clean; + } + INIT_DELAYED_WORK(&client_data->accel_poll_work, + smi130_accel_work_fn); + client_data->accel_cdev = smi130_accel_cdev; + client_data->accel_cdev.delay_msec = client_data->accel_poll_ms; + client_data->accel_cdev.sensors_enable = smi130_accel_cdev_enable; + client_data->accel_cdev.sensors_poll_delay = + smi130_accel_cdev_poll_delay; + err = sensors_classdev_register(dev, &client_data->accel_cdev); + if (err) { + dev_err(dev, + "create accel class device file failed!\n"); + goto exit_err_clean; + } + INIT_DELAYED_WORK(&client_data->gyro_poll_work, smi130_gyro_work_fn); + client_data->gyro_cdev = smi130_gyro_cdev; + client_data->gyro_cdev.delay_msec = client_data->gyro_poll_ms; + client_data->gyro_cdev.sensors_enable = smi130_gyro_cdev_enable; + client_data->gyro_cdev.sensors_poll_delay = smi130_gyro_cdev_poll_delay; + err = sensors_classdev_register(dev, &client_data->gyro_cdev); + if (err) { + dev_err(dev, + "create accel class device file failed!\n"); + goto exit_err_clean; + } + #endif + /* set sensor PMU into suspend power mode for all */ + if (smi_pmu_set_suspend(client_data) < 0) { + dev_err(dev, "Failed to set SMI130 to suspend power mode\n"); + goto exit_err_sysfs; + } + /*enable the data ready interrupt*/ + SMI_CALL_API(set_intr_enable_1)(SMI130_DATA_RDY_ENABLE, 1); + dev_notice(dev, "sensor_time:%d, %d, %d", + sensortime_duration_tbl[0].ts_delat, + sensortime_duration_tbl[0].ts_duration_lsb, + sensortime_duration_tbl[0].ts_duration_us); + dev_notice(dev, "sensor %s probed successfully", SENSOR_NAME); + + return 0; + +exit_err_sysfs: + if (err) + smi_input_destroy(client_data); + +exit_err_clean: + if (err) { + if (client_data != NULL) { + if (NULL != client_data->bosch_pd) { + kfree(client_data->bosch_pd); + client_data->bosch_pd = NULL; + } + } + } + return err; +} +EXPORT_SYMBOL(smi_probe); + +/*! + * @brief remove smi client + * + * @param dev the pointer of device + * + * @return zero + * @retval zero +*/ +int smi_remove(struct device *dev) +{ + int err = 0; + struct smi_client_data *client_data = dev_get_drvdata(dev); + + if (NULL != client_data) { +#ifdef CONFIG_HAS_EARLYSUSPEND + unregister_early_suspend(&client_data->early_suspend_handler); +#endif + mutex_lock(&client_data->mutex_enable); + if (SMI_ACC_PM_NORMAL == client_data->pw.acc_pm || + SMI_GYRO_PM_NORMAL == client_data->pw.gyro_pm || + SMI_MAG_PM_NORMAL == client_data->pw.mag_pm) { + cancel_delayed_work_sync(&client_data->work); + } + mutex_unlock(&client_data->mutex_enable); + + err = smi_pmu_set_suspend(client_data); + + smi_delay(5); + + sysfs_remove_group(&client_data->input->dev.kobj, + &smi130_attribute_group); + smi_input_destroy(client_data); + + if (NULL != client_data->bosch_pd) { + kfree(client_data->bosch_pd); + client_data->bosch_pd = NULL; + } + kfree(client_data); + } + + return err; +} +EXPORT_SYMBOL(smi_remove); + +static int smi_post_resume(struct smi_client_data *client_data) +{ + int err = 0; + + mutex_lock(&client_data->mutex_enable); + + if (atomic_read(&client_data->wkqueue_en) == 1) { + smi130_set_acc_op_mode(client_data, SMI_ACC_PM_NORMAL); + schedule_delayed_work(&client_data->work, + msecs_to_jiffies( + atomic_read(&client_data->delay))); + } + mutex_unlock(&client_data->mutex_enable); + + return err; +} + + +int smi_suspend(struct device *dev) +{ + int err = 0; + struct smi_client_data *client_data = dev_get_drvdata(dev); + unsigned char stc_enable; + unsigned char std_enable; + dev_err(client_data->dev, "smi suspend function entrance"); + + atomic_set(&client_data->in_suspend, 1); + if (atomic_read(&client_data->wkqueue_en) == 1) { + smi130_set_acc_op_mode(client_data, SMI_ACC_PM_SUSPEND); + cancel_delayed_work_sync(&client_data->work); + } + SMI_CALL_API(get_step_counter_enable)(&stc_enable); + SMI_CALL_API(get_step_detector_enable)(&std_enable); + if (client_data->pw.acc_pm != SMI_ACC_PM_SUSPEND && + (stc_enable != 1) && (std_enable != 1) && + (client_data->sig_flag != 1)) { + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_SUSPEND]); + smi_delay(3); + } + if (client_data->pw.gyro_pm != SMI_GYRO_PM_SUSPEND) { + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_SUSPEND]); + smi_delay(3); + } + + if (client_data->pw.mag_pm != SMI_MAG_PM_SUSPEND) { +#if defined(SMI130_AKM09912_SUPPORT) + err += smi130_set_bosch_akm_and_secondary_if_powermode( + SMI130_MAG_SUSPEND_MODE); +#else + err += smi130_set_bmm150_mag_and_secondary_if_power_mode( + SMI130_MAG_SUSPEND_MODE); +#endif + smi_delay(3); + } + + return err; +} +EXPORT_SYMBOL(smi_suspend); + +int smi_resume(struct device *dev) +{ + int err = 0; + struct smi_client_data *client_data = dev_get_drvdata(dev); + atomic_set(&client_data->in_suspend, 0); + if (client_data->pw.acc_pm != SMI_ACC_PM_SUSPEND) { + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_acc_arr[SMI_ACC_PM_NORMAL]); + smi_delay(3); + } + if (client_data->pw.gyro_pm != SMI_GYRO_PM_SUSPEND) { + err += SMI_CALL_API(set_command_register) + (smi_pmu_cmd_gyro_arr[SMI_GYRO_PM_NORMAL]); + smi_delay(3); + } + + if (client_data->pw.mag_pm != SMI_MAG_PM_SUSPEND) { +#if defined(SMI130_AKM09912_SUPPORT) + err += smi130_set_bosch_akm_and_secondary_if_powermode + (SMI130_MAG_FORCE_MODE); +#else + err += smi130_set_bmm150_mag_and_secondary_if_power_mode + (SMI130_MAG_FORCE_MODE); +#endif + smi_delay(3); + } + /* post resume operation */ + err += smi_post_resume(client_data); + + return err; +} +EXPORT_SYMBOL(smi_resume); + diff --git a/smi130_driver.h b/smi130_driver.h new file mode 100644 index 000000000000..9855b22132da --- /dev/null +++ b/smi130_driver.h @@ -0,0 +1,411 @@ + /* + * @section LICENSE + * (C) Copyright 2011~2018 Bosch Sensortec GmbH All Rights Reserved + * + * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved + * + * This software program is licensed subject to the GNU General + * Public License (GPL).Version 2,June 1991, + * available at http://www.fsf.org/copyleft/gpl.html + * + * @filename smi130_driver.h + * @date 2015/08/17 14:40 + * @Modification Date 2018/06/21 15:03 + * @version 1.3 + * + * @brief + * The head file of SMI130 device driver core code +*/ +#ifndef _SMI130_DRIVER_H +#define _SMI130_DRIVER_H + +#ifdef __KERNEL__ +#include <linux/kernel.h> +#include <linux/unistd.h> +#include <linux/types.h> +#include <linux/string.h> +#else +#include <unistd.h> +#include <sys/types.h> +#include <string.h> +#endif + +#include <linux/version.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/input.h> +#include <linux/workqueue.h> +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/time.h> +#include <linux/ktime.h> + +#ifdef CONFIG_HAS_EARLYSUSPEND +#include <linux/earlysuspend.h> +#endif + +#include "smi130.h" + +#if defined(CONFIG_USE_QUALCOMM_HAL) +#include <linux/sensors.h> +#endif +/* sensor specific */ +#define SENSOR_NAME "smi130" +#define SMI130_ENABLE_INT1 1 +#define SMI130_ENABLE_INT2 1 +/*#define SMI130_MAG_INTERFACE_SUPPORT 1*/ + +/*#define SMI130_AKM09912_SUPPORT 1*/ +#define SMI_USE_BASIC_I2C_FUNC 1 +#define SENSOR_CHIP_ID_SMI (0xD0) +#define SENSOR_CHIP_ID_SMI_C2 (0xD1) +#define SENSOR_CHIP_ID_SMI_C3 (0xD3) + +#define SENSOR_CHIP_REV_ID_SMI (0x00) + +#define CHECK_CHIP_ID_TIME_MAX 5 + +#define SMI_REG_NAME(name) SMI130_##name##__REG +#define SMI_VAL_NAME(name) SMI130_##name +#define SMI_CALL_API(name) smi130_##name + +#define SMI_I2C_WRITE_DELAY_TIME (1) + +/* generic */ +#define SMI_MAX_RETRY_I2C_XFER (10) +#define SMI_MAX_RETRY_WAKEUP (5) +#define SMI_MAX_RETRY_WAIT_DRDY (100) + +#define SMI_DELAY_MIN (1) +#define SMI_DELAY_DEFAULT (200) + +#define SMI_VALUE_MAX (32767) +#define SMI_VALUE_MIN (-32768) + +#define BYTES_PER_LINE (16) + +#define BUF_SIZE_PRINT (16) + +#define SMI_FAST_CALI_TRUE (1) +#define SMI_FAST_CALI_ALL_RDY (7) + +/*! FIFO 1024 byte, max fifo frame count not over 150 */ +#define FIFO_FRAME_CNT 170 +#define FIFO_DATA_BUFSIZE 1024 + + +#define FRAME_LEN_ACC 6 +#define FRAME_LEN_GYRO 6 +#define FRAME_LEN_MAG 8 + +/*! SMI Self test */ +#define SMI_SELFTEST_AMP_HIGH 1 + +/* CMD */ +#define CMD_FOC_START 0x03 +#define CMD_PMU_ACC_SUSPEND 0x10 +#define CMD_PMU_ACC_NORMAL 0x11 +#define CMD_PMU_ACC_LP1 0x12 +#define CMD_PMU_ACC_LP2 0x13 +#define CMD_PMU_GYRO_SUSPEND 0x14 +#define CMD_PMU_GYRO_NORMAL 0x15 +#define CMD_PMU_GYRO_FASTSTART 0x17 +#define CMD_PMU_MAG_SUSPEND 0x18 +#define CMD_PMU_MAG_NORMAL 0x19 +#define CMD_PMU_MAG_LP1 0x1A +#define CMD_PMU_MAG_LP2 0x1B +#define CMD_CLR_FIFO_DATA 0xB0 +#define CMD_RESET_INT_ENGINE 0xB1 +#define CMD_RESET_USER_REG 0xB6 + +#define USER_DAT_CFG_PAGE 0x00 + +/*! FIFO Head definition*/ +#define FIFO_HEAD_A 0x84 +#define FIFO_HEAD_G 0x88 +#define FIFO_HEAD_M 0x90 + +#define FIFO_HEAD_G_A (FIFO_HEAD_G | FIFO_HEAD_A) +#define FIFO_HEAD_M_A (FIFO_HEAD_M | FIFO_HEAD_A) +#define FIFO_HEAD_M_G (FIFO_HEAD_M | FIFO_HEAD_G) + +#define FIFO_HEAD_M_G_A (FIFO_HEAD_M | FIFO_HEAD_G | FIFO_HEAD_A) + +#define FIFO_HEAD_SENSOR_TIME 0x44 +#define FIFO_HEAD_SKIP_FRAME 0x40 +#define FIFO_HEAD_OVER_READ_LSB 0x80 +#define FIFO_HEAD_OVER_READ_MSB 0x00 + +/*! FIFO head mode Frame bytes number definition */ +#define A_BYTES_FRM 6 +#define G_BYTES_FRM 6 +#define M_BYTES_FRM 8 +#define GA_BYTES_FRM 12 +#define MG_BYTES_FRM 14 +#define MA_BYTES_FRM 14 +#define MGA_BYTES_FRM 20 + +#define ACC_FIFO_HEAD "acc" +#define GYRO_FIFO_HEAD "gyro" +#define MAG_FIFO_HEAD "mag" + +/*! Bosch sensor unknown place*/ +#define BOSCH_SENSOR_PLACE_UNKNOWN (-1) +/*! Bosch sensor remapping table size P0~P7*/ +#define MAX_AXIS_REMAP_TAB_SZ 8 + +#define ENABLE 1 +#define DISABLE 0 + +/* smi sensor HW interrupt pin number */ +#define SMI_INT0 0 +#define SMI_INT1 1 + +#define SMI_INT_LEVEL 0 +#define SMI_INT_EDGE 1 + +/*! SMI mag interface */ + + +/* compensated output value returned if sensor had overflow */ +#define BMM050_OVERFLOW_OUTPUT -32768 +#define BMM050_OVERFLOW_OUTPUT_S32 ((s32)(-2147483647-1)) + +/* Trim Extended Registers */ +#define BMM050_DIG_X1 0x5D +#define BMM050_DIG_Y1 0x5E +#define BMM050_DIG_Z4_LSB 0x62 +#define BMM050_DIG_Z4_MSB 0x63 +#define BMM050_DIG_X2 0x64 +#define BMM050_DIG_Y2 0x65 +#define BMM050_DIG_Z2_LSB 0x68 +#define BMM050_DIG_Z2_MSB 0x69 +#define BMM050_DIG_Z1_LSB 0x6A +#define BMM050_DIG_Z1_MSB 0x6B +#define BMM050_DIG_XYZ1_LSB 0x6C +#define BMM050_DIG_XYZ1_MSB 0x6D +#define BMM050_DIG_Z3_LSB 0x6E +#define BMM050_DIG_Z3_MSB 0x6F +#define BMM050_DIG_XY2 0x70 +#define BMM050_DIG_XY1 0x71 + +struct smi130mag_compensate_t { + signed char dig_x1; + signed char dig_y1; + + signed char dig_x2; + signed char dig_y2; + + u16 dig_z1; + s16 dig_z2; + s16 dig_z3; + s16 dig_z4; + + unsigned char dig_xy1; + signed char dig_xy2; + + u16 dig_xyz1; +}; + +/*smi fifo sensor type combination*/ +enum SMI_FIFO_DATA_SELECT_T { + SMI_FIFO_A_SEL = 1, + SMI_FIFO_G_SEL, + SMI_FIFO_G_A_SEL, + SMI_FIFO_M_SEL, + SMI_FIFO_M_A_SEL, + SMI_FIFO_M_G_SEL, + SMI_FIFO_M_G_A_SEL, + SMI_FIFO_DATA_SEL_MAX +}; + +/*smi interrupt about step_detector and sgm*/ +#define INPUT_EVENT_STEP_DETECTOR 5 +#define INPUT_EVENT_SGM 3/*7*/ +#define INPUT_EVENT_FAST_ACC_CALIB_DONE 6 +#define INPUT_EVENT_FAST_GYRO_CALIB_DONE 4 + + +/*! +* Bst sensor common definition, +* please give parameters in BSP file. +*/ +struct bosch_sensor_specific { + char *name; + /* 0 to 7 */ + unsigned int place:3; + int irq; + int (*irq_gpio_cfg)(void); +}; + +/*! smi130 sensor spec of power mode */ +struct pw_mode { + u8 acc_pm; + u8 gyro_pm; + u8 mag_pm; +}; + +/*! smi130 sensor spec of odr */ +struct odr_t { + u8 acc_odr; + u8 gyro_odr; + u8 mag_odr; +}; + +/*! smi130 sensor spec of range */ +struct range_t { + u8 acc_range; + u8 gyro_range; +}; + +/*! smi130 sensor error status */ +struct err_status { + u8 fatal_err; + u8 err_code; + u8 i2c_fail; + u8 drop_cmd; + u8 mag_drdy_err; + u8 err_st_all; +}; + +/*! smi130 fifo frame for all sensors */ +struct fifo_frame_t { + struct smi130_accel_t *acc_farr; + struct smi130_gyro_t *gyro_farr; + struct smi130_mag_xyz_s32_t *mag_farr; + + unsigned char acc_frame_cnt; + unsigned char gyro_frame_cnt; + unsigned char mag_frame_cnt; + + u32 acc_lastf_ts; + u32 gyro_lastf_ts; + u32 mag_lastf_ts; +}; + +/*! smi130 fifo sensor time */ +struct fifo_sensor_time_t { + u32 acc_ts; + u32 gyro_ts; + u32 mag_ts; +}; + +struct pedometer_data_t { + /*! Fix step detector misinformation for the first time*/ + u8 wkar_step_detector_status; + u_int32_t last_step_counter_value; +}; + +struct smi_client_data { + struct smi130_t device; + struct device *dev; + struct input_dev *input;/*acc_device*/ + struct input_dev *gyro_input; + #if defined(CONFIG_USE_QUALCOMM_HAL) + struct input_dev *gyro_input; + struct sensors_classdev accel_cdev; + struct sensors_classdev gyro_cdev; + struct delayed_work accel_poll_work; + struct delayed_work gyro_poll_work; + u32 accel_poll_ms; + u32 gyro_poll_ms; + u32 accel_latency_ms; + u32 gyro_latency_ms; + atomic_t accel_en; + atomic_t gyro_en; + struct workqueue_struct *data_wq; + #endif + struct delayed_work work; + struct work_struct irq_work; + + u8 chip_id; + + struct pw_mode pw; + struct odr_t odr; + struct range_t range; /*TO DO*/ + struct err_status err_st; + struct pedometer_data_t pedo_data; + s8 place; + u8 selftest; + /*struct wake_lock wakelock;*/ + struct delayed_work delay_work_sig; + atomic_t in_suspend; + + atomic_t wkqueue_en; /*TO DO acc gyro mag*/ + atomic_t delay; + atomic_t selftest_result; + + u8 fifo_data_sel; + u16 fifo_bytecount; + u8 fifo_head_en; + unsigned char fifo_int_tag_en; + struct fifo_frame_t fifo_frame; + + unsigned char *fifo_data; + u64 fifo_time; + u8 stc_enable; + uint16_t gpio_pin; + u8 std; + u8 sig_flag; + unsigned char calib_status; + struct mutex mutex_op_mode; + struct mutex mutex_enable; + struct bosch_sensor_specific *bosch_pd; + int IRQ; + int reg_sel; + int reg_len; + uint64_t timestamp; +#ifdef CONFIG_HAS_EARLYSUSPEND + struct early_suspend early_suspend_handler; +#endif +}; + + +/*! + * we use a typedef to hide the detail, + * because this type might be changed + */ +struct bosch_sensor_axis_remap { + /* src means which source will be mapped to target x, y, z axis */ + /* if an target OS axis is remapped from (-)x, + * src is 0, sign_* is (-)1 */ + /* if an target OS axis is remapped from (-)y, + * src is 1, sign_* is (-)1 */ + /* if an target OS axis is remapped from (-)z, + * src is 2, sign_* is (-)1 */ + int src_x:3; + int src_y:3; + int src_z:3; + + int sign_x:2; + int sign_y:2; + int sign_z:2; +}; + + +struct bosch_sensor_data { + union { + int16_t v[3]; + struct { + int16_t x; + int16_t y; + int16_t z; + }; + }; +}; + +s8 smi_burst_read_wrapper(u8 dev_addr, u8 reg_addr, u8 *data, u16 len); +int smi_probe(struct smi_client_data *client_data, struct device *dev); +int smi_remove(struct device *dev); +int smi_suspend(struct device *dev); +int smi_resume(struct device *dev); + + + + +#endif/*_SMI130_DRIVER_H*/ +/*@}*/ + diff --git a/smi130_i2c.c b/smi130_i2c.c new file mode 100644 index 000000000000..24a66c8cb31b --- /dev/null +++ b/smi130_i2c.c @@ -0,0 +1,372 @@ + /* + * @section LICENSE + * (C) Copyright 2011~2018 Bosch Sensortec GmbH All Rights Reserved + * + * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved + * + * This software program is licensed subject to the GNU General + * Public License (GPL).Version 2,June 1991, + * available at http://www.fsf.org/copyleft/gpl.html + * + * + * @filename smi130_i2c.c + * @date 2014/11/25 14:40 + * @Modification Date 2018/06/21 15:03 + * @version 1.3 + * + * @brief + * This file implements moudle function, which add + * the driver to I2C core. +*/ + +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/delay.h> +#include "smi130_driver.h" + +/*! @defgroup smi130_i2c_src + * @brief smi130 i2c driver module + @{*/ + +static struct i2c_client *smi_client; +/*! + * @brief define i2c wirte function + * + * @param client the pointer of i2c client + * @param reg_addr register address + * @param data the pointer of data buffer + * @param len block size need to write + * + * @return zero success, non-zero failed + * @retval zero success + * @retval non-zero failed +*/ +/* i2c read routine for API*/ +static s8 smi_i2c_read(struct i2c_client *client, u8 reg_addr, + u8 *data, u8 len) + { +#if !defined SMI_USE_BASIC_I2C_FUNC + s32 dummy; + if (NULL == client) + return -EINVAL; + + while (0 != len--) { +#ifdef SMI_SMBUS + dummy = i2c_smbus_read_byte_data(client, reg_addr); + if (dummy < 0) { + dev_err(&client->dev, "i2c smbus read error"); + return -EIO; + } + *data = (u8)(dummy & 0xff); +#else + dummy = i2c_master_send(client, (char *)®_addr, 1); + if (dummy < 0) { + dev_err(&client->dev, "i2c bus master write error"); + return -EIO; + } + + dummy = i2c_master_recv(client, (char *)data, 1); + if (dummy < 0) { + dev_err(&client->dev, "i2c bus master read error"); + return -EIO; + } +#endif + reg_addr++; + data++; + } + return 0; +#else + int retry; + + struct i2c_msg msg[] = { + { + .addr = client->addr, + .flags = 0, + .len = 1, + .buf = ®_addr, + }, + + { + .addr = client->addr, + .flags = I2C_M_RD, + .len = len, + .buf = data, + }, + }; + + for (retry = 0; retry < SMI_MAX_RETRY_I2C_XFER; retry++) { + if (i2c_transfer(client->adapter, msg, + ARRAY_SIZE(msg)) > 0) + break; + else + usleep_range(SMI_I2C_WRITE_DELAY_TIME * 1000, + SMI_I2C_WRITE_DELAY_TIME * 1000); + } + + if (SMI_MAX_RETRY_I2C_XFER <= retry) { + dev_err(&client->dev, "I2C xfer error"); + return -EIO; + } + + return 0; +#endif + } + + +static s8 smi_i2c_burst_read(struct i2c_client *client, u8 reg_addr, + u8 *data, u16 len) +{ + int retry; + + struct i2c_msg msg[] = { + { + .addr = client->addr, + .flags = 0, + .len = 1, + .buf = ®_addr, + }, + + { + .addr = client->addr, + .flags = I2C_M_RD, + .len = len, + .buf = data, + }, + }; + + for (retry = 0; retry < SMI_MAX_RETRY_I2C_XFER; retry++) { + if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0) + break; + else + usleep_range(SMI_I2C_WRITE_DELAY_TIME * 1000, + SMI_I2C_WRITE_DELAY_TIME * 1000); + } + + if (SMI_MAX_RETRY_I2C_XFER <= retry) { + dev_err(&client->dev, "I2C xfer error"); + return -EIO; + } + + return 0; +} + + +/* i2c write routine for */ +static s8 smi_i2c_write(struct i2c_client *client, u8 reg_addr, + u8 *data, u8 len) +{ +#if !defined SMI_USE_BASIC_I2C_FUNC + s32 dummy; + +#ifndef SMI_SMBUS + u8 buffer[2]; +#endif + + if (NULL == client) + return -EPERM; + + while (0 != len--) { +#ifdef SMI_SMBUS + dummy = i2c_smbus_write_byte_data(client, reg_addr, *data); +#else + buffer[0] = reg_addr; + buffer[1] = *data; + dummy = i2c_master_send(client, (char *)buffer, 2); +#endif + reg_addr++; + data++; + if (dummy < 0) { + dev_err(&client->dev, "error writing i2c bus"); + return -EPERM; + } + + } + usleep_range(SMI_I2C_WRITE_DELAY_TIME * 1000, + SMI_I2C_WRITE_DELAY_TIME * 1000); + return 0; +#else + u8 buffer[2]; + int retry; + struct i2c_msg msg[] = { + { + .addr = client->addr, + .flags = 0, + .len = 2, + .buf = buffer, + }, + }; + + while (0 != len--) { + buffer[0] = reg_addr; + buffer[1] = *data; + for (retry = 0; retry < SMI_MAX_RETRY_I2C_XFER; retry++) { + if (i2c_transfer(client->adapter, msg, + ARRAY_SIZE(msg)) > 0) { + break; + } else { + usleep_range(SMI_I2C_WRITE_DELAY_TIME * 1000, + SMI_I2C_WRITE_DELAY_TIME * 1000); + } + } + if (SMI_MAX_RETRY_I2C_XFER <= retry) { + dev_err(&client->dev, "I2C xfer error"); + return -EIO; + } + reg_addr++; + data++; + } + + usleep_range(SMI_I2C_WRITE_DELAY_TIME * 1000, + SMI_I2C_WRITE_DELAY_TIME * 1000); + return 0; +#endif +} + + +static s8 smi_i2c_read_wrapper(u8 dev_addr, u8 reg_addr, u8 *data, u8 len) +{ + int err = 0; + err = smi_i2c_read(smi_client, reg_addr, data, len); + return err; +} + +static s8 smi_i2c_write_wrapper(u8 dev_addr, u8 reg_addr, u8 *data, u8 len) +{ + int err = 0; + err = smi_i2c_write(smi_client, reg_addr, data, len); + return err; +} + +s8 smi_burst_read_wrapper(u8 dev_addr, u8 reg_addr, u8 *data, u16 len) +{ + int err = 0; + err = smi_i2c_burst_read(smi_client, reg_addr, data, len); + return err; +} +EXPORT_SYMBOL(smi_burst_read_wrapper); +/*! + * @brief SMI probe function via i2c bus + * + * @param client the pointer of i2c client + * @param id the pointer of i2c device id + * + * @return zero success, non-zero failed + * @retval zero success + * @retval non-zero failed +*/ +static int smi_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int err = 0; + struct smi_client_data *client_data = NULL; + + dev_info(&client->dev, "SMI130 i2c function probe entrance"); + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(&client->dev, "i2c_check_functionality error!"); + err = -EIO; + goto exit_err_clean; + } + + if (NULL == smi_client) { + smi_client = client; + } else { + dev_err(&client->dev, + "this driver does not support multiple clients"); + err = -EBUSY; + goto exit_err_clean; + } + + client_data = kzalloc(sizeof(struct smi_client_data), + GFP_KERNEL); + if (NULL == client_data) { + dev_err(&client->dev, "no memory available"); + err = -ENOMEM; + goto exit_err_clean; + } + + client_data->device.bus_read = smi_i2c_read_wrapper; + client_data->device.bus_write = smi_i2c_write_wrapper; + + return smi_probe(client_data, &client->dev); + +exit_err_clean: + if (err) + smi_client = NULL; + return err; +} +/* +static int smi_i2c_suspend(struct i2c_client *client, pm_message_t mesg) +{ + int err = 0; + err = smi_suspend(&client->dev); + return err; +} + +static int smi_i2c_resume(struct i2c_client *client) +{ + int err = 0; + + err = smi_resume(&client->dev); + + return err; +} +*/ + +static int smi_i2c_remove(struct i2c_client *client) +{ + int err = 0; + err = smi_remove(&client->dev); + smi_client = NULL; + + return err; +} + + + +static const struct i2c_device_id smi_id[] = { + {SENSOR_NAME, 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, smi_id); + +static const struct of_device_id smi130_of_match[] = { + { .compatible = "bosch-sensortec,smi130", }, + { .compatible = "smi130", }, + { .compatible = "bosch, smi130", }, + { } +}; +MODULE_DEVICE_TABLE(of, smi130_of_match); + +static struct i2c_driver smi_i2c_driver = { + .driver = { + .owner = THIS_MODULE, + .name = SENSOR_NAME, + .of_match_table = smi130_of_match, + }, + .class = I2C_CLASS_HWMON, + .id_table = smi_id, + .probe = smi_i2c_probe, + .remove = smi_i2c_remove, + /*.suspend = smi_i2c_suspend, + .resume = smi_i2c_resume,*/ +}; + +static int __init SMI_i2c_init(void) +{ + return i2c_add_driver(&smi_i2c_driver); +} + +static void __exit SMI_i2c_exit(void) +{ + i2c_del_driver(&smi_i2c_driver); +} + +MODULE_AUTHOR("Contact <contact@bosch-sensortec.com>"); +MODULE_DESCRIPTION("driver for " SENSOR_NAME); +MODULE_LICENSE("GPL v2"); + +module_init(SMI_i2c_init); +module_exit(SMI_i2c_exit); + diff --git a/smi130_spi.c b/smi130_spi.c new file mode 100644 index 000000000000..05bd4b8a9b60 --- /dev/null +++ b/smi130_spi.c @@ -0,0 +1,402 @@ +/* +* @section LICENSE +* (C) Copyright 2011~2018 Bosch Sensortec GmbH All Rights Reserved +* +* (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved +* +* This software program is licensed subject to the GNU General +* Public License (GPL).Version 2,June 1991, +* available at http://www.fsf.org/copyleft/gpl.html +* +* Special: Description of the Software: +* +* This software module (hereinafter called "Software") and any +* information on application-sheets (hereinafter called "Information") is +* provided free of charge for the sole purpose to support your application +* work. +* +* As such, the Software is merely an experimental software, not tested for +* safety in the field and only intended for inspiration for further development +* and testing. Any usage in a safety-relevant field of use (like automotive, +* seafaring, spacefaring, industrial plants etc.) was not intended, so there are +* no precautions for such usage incorporated in the Software. +* +* The Software is specifically designed for the exclusive use for Bosch +* Sensortec products by personnel who have special experience and training. Do +* not use this Software if you do not have the proper experience or training. +* +* This Software package is provided as is and without any expressed or +* implied warranties, including without limitation, the implied warranties of +* merchantability and fitness for a particular purpose. +* +* Bosch Sensortec and their representatives and agents deny any liability for +* the functional impairment of this Software in terms of fitness, performance +* and safety. Bosch Sensortec and their representatives and agents shall not be +* liable for any direct or indirect damages or injury, except as otherwise +* stipulated in mandatory applicable law. +* The Information provided is believed to be accurate and reliable. Bosch +* Sensortec assumes no responsibility for the consequences of use of such +* Information nor for any infringement of patents or other rights of third +* parties which may result from its use. +* +*------------------------------------------------------------------------------ +* The following Product Disclaimer does not apply to the BSX4-HAL-4.1NoFusion Software +* which is licensed under the Apache License, Version 2.0 as stated above. +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Product Disclaimer +* +* Common: +* +* Assessment of Products Returned from Field +* +* Returned products are considered good if they fulfill the specifications / +* test data for 0-mileage and field listed in this document. +* +* Engineering Samples +* +* Engineering samples are marked with (e) or (E). Samples may vary from the +* valid technical specifications of the series product contained in this +* data sheet. Therefore, they are not intended or fit for resale to +* third parties or for use in end products. Their sole purpose is internal +* client testing. The testing of an engineering sample may in no way replace +* the testing of a series product. Bosch assumes no liability for the use +* of engineering samples. The purchaser shall indemnify Bosch from all claims +* arising from the use of engineering samples. +* +* Intended use +* +* Provided that SMI130 is used within the conditions (environment, application, +* installation, loads) as described in this TCD and the corresponding +* agreed upon documents, Bosch ensures that the product complies with +* the agreed properties. Agreements beyond this require +* the written approval by Bosch. The product is considered fit for the intended +* use when the product successfully has passed the tests +* in accordance with the TCD and agreed upon documents. +* +* It is the responsibility of the customer to ensure the proper application +* of the product in the overall system/vehicle. +* +* Bosch does not assume any responsibility for changes to the environment +* of the product that deviate from the TCD and the agreed upon documents +* as well as all applications not released by Bosch +* +* The resale and/or use of products are at the purchaser’s own risk and +* responsibility. The examination and testing of the SMI130 +* is the sole responsibility of the purchaser. +* +* The purchaser shall indemnify Bosch from all third party claims +* arising from any product use not covered by the parameters of +* this product data sheet or not approved by Bosch and reimburse Bosch +* for all costs and damages in connection with such claims. +* +* The purchaser must monitor the market for the purchased products, +* particularly with regard to product safety, and inform Bosch without delay +* of all security relevant incidents. +* +* Application Examples and Hints +* +* With respect to any application examples, advice, normal values +* and/or any information regarding the application of the device, +* Bosch hereby disclaims any and all warranties and liabilities of any kind, +* including without limitation warranties of +* non-infringement of intellectual property rights or copyrights +* of any third party. +* The information given in this document shall in no event be regarded +* as a guarantee of conditions or characteristics. They are provided +* for illustrative purposes only and no evaluation regarding infringement +* of intellectual property rights or copyrights or regarding functionality, +* performance or error has been made. +* +* +* @filename smi130_spi.c +* @date 2014/11/25 14:40 +* @Modification Date 2018/06/21 15:03 +* @version 1.3 +* +* @brief +* This file implements moudle function, which add +* the driver to SPI core. +*/ + +#include <linux/module.h> +#include <linux/spi/spi.h> +#include <linux/delay.h> +#include "smi130_driver.h" + +/*! @defgroup smi130_spi_src + * @brief smi130 spi driver module + @{*/ +/*! the maximum of transfer buffer size */ +#define SMI_MAX_BUFFER_SIZE 32 + +static struct spi_device *smi_spi_client; + +/*! + * @brief define spi wirte function + * + * @param dev_addr sensor device address + * @param reg_addr register address + * @param data the pointer of data buffer + * @param len block size need to write + * + * @return zero success, non-zero failed + * @retval zero success + * @retval non-zero failed +*/ +static char smi_spi_write_block(u8 dev_addr, u8 reg_addr, u8 *data, u8 len) +{ + struct spi_device *client = smi_spi_client; + u8 buffer[SMI_MAX_BUFFER_SIZE + 1]; + struct spi_transfer xfer = { + .tx_buf = buffer, + .len = len + 1, + }; + struct spi_message msg; + + if (len > SMI_MAX_BUFFER_SIZE) + return -EINVAL; + + buffer[0] = reg_addr&0x7F;/* write: MSB = 0 */ + memcpy(&buffer[1], data, len); + + spi_message_init(&msg); + spi_message_add_tail(&xfer, &msg); + return spi_sync(client, &msg); +} + +/*! + * @brief define spi read function + * + * @param dev_addr sensor device address + * @param reg_addr register address + * @param data the pointer of data buffer + * @param len block size need to read + * + * @return zero success, non-zero failed + * @retval zero success + * @retval non-zero failed +*/ +static char smi_spi_read_block(u8 dev_addr, u8 reg_addr, u8 *data, u8 len) +{ + struct spi_device *client = smi_spi_client; + u8 reg = reg_addr | 0x80;/* read: MSB = 1 */ + struct spi_transfer xfer[2] = { + [0] = { + .tx_buf = ®, + .len = 1, + }, + [1] = { + .rx_buf = data, + .len = len, + } + }; + struct spi_message msg; + + spi_message_init(&msg); + spi_message_add_tail(&xfer[0], &msg); + spi_message_add_tail(&xfer[1], &msg); + return spi_sync(client, &msg); +} + +s8 smi_burst_read_wrapper(u8 dev_addr, u8 reg_addr, u8 *data, u16 len) +{ + struct spi_device *client = smi_spi_client; + u8 reg = reg_addr | 0x80;/* read: MSB = 1 */ + struct spi_transfer xfer[2] = { + [0] = { + .tx_buf = ®, + .len = 1, + }, + [1] = { + .rx_buf = data, + .len = len, + } + }; + struct spi_message msg; + + spi_message_init(&msg); + spi_message_add_tail(&xfer[0], &msg); + spi_message_add_tail(&xfer[1], &msg); + return spi_sync(client, &msg); +} +EXPORT_SYMBOL(smi_burst_read_wrapper); +/*! + * @brief SMI probe function via spi bus + * + * @param client the pointer of spi client + * + * @return zero success, non-zero failed + * @retval zero success + * @retval non-zero failed +*/ +static int smi_spi_probe(struct spi_device *client) +{ + int status; + int err = 0; + struct smi_client_data *client_data = NULL; + + if (NULL == smi_spi_client) + smi_spi_client = client; + else{ + dev_err(&client->dev, "This driver does not support multiple clients!\n"); + return -EBUSY; + } + + client->bits_per_word = 8; + status = spi_setup(client); + if (status < 0) { + dev_err(&client->dev, "spi_setup failed!\n"); + return status; + } + + client_data = kzalloc(sizeof(struct smi_client_data), GFP_KERNEL); + if (NULL == client_data) { + dev_err(&client->dev, "no memory available"); + err = -ENOMEM; + goto exit_err_clean; + } + + client_data->device.bus_read = smi_spi_read_block; + client_data->device.bus_write = smi_spi_write_block; + + return smi_probe(client_data, &client->dev); + +exit_err_clean: + if (err) + smi_spi_client = NULL; + return err; +} + +/*! + * @brief shutdown smi device in spi driver + * + * @param client the pointer of spi client + * + * @return no return value +*/ +static void smi_spi_shutdown(struct spi_device *client) +{ +#ifdef CONFIG_PM + smi_suspend(&client->dev); +#endif +} + +/*! + * @brief remove smi spi client + * + * @param client the pointer of spi client + * + * @return zero + * @retval zero +*/ +static int smi_spi_remove(struct spi_device *client) +{ + int err = 0; + err = smi_remove(&client->dev); + smi_spi_client = NULL; + + return err; +} + +#ifdef CONFIG_PM +/*! + * @brief suspend smi device in spi driver + * + * @param dev the pointer of device + * + * @return zero + * @retval zero +*/ +static int smi_spi_suspend(struct device *dev) +{ + int err = 0; + err = smi_suspend(dev); + return err; +} + +/*! + * @brief resume smi device in spi driver + * + * @param dev the pointer of device + * + * @return zero + * @retval zero +*/ +static int smi_spi_resume(struct device *dev) +{ + int err = 0; + /* post resume operation */ + err = smi_resume(dev); + + return err; +} + +/*! + * @brief register spi device power manager hooks +*/ +static const struct dev_pm_ops smi_spi_pm_ops = { + /**< device suspend */ + .suspend = smi_spi_suspend, + /**< device resume */ + .resume = smi_spi_resume +}; +#endif + +/*! + * @brief register spi device id +*/ +static const struct spi_device_id smi_id[] = { + { SENSOR_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(spi, smi_id); + +/*! + * @brief register spi driver hooks +*/ +static struct spi_driver smi_spi_driver = { + .driver = { + .owner = THIS_MODULE, + .name = SENSOR_NAME, +#ifdef CONFIG_PM + .pm = &smi_spi_pm_ops, +#endif + }, + .id_table = smi_id, + .probe = smi_spi_probe, + .shutdown = smi_spi_shutdown, + .remove = smi_spi_remove +}; + +/*! + * @brief initialize smi spi module + * + * @return zero success, non-zero failed + * @retval zero success + * @retval non-zero failed +*/ +static int __init smi_spi_init(void) +{ + return spi_register_driver(&smi_spi_driver); +} + +/*! + * @brief remove smi spi module + * + * @return no return value +*/ +static void __exit smi_spi_exit(void) +{ + spi_unregister_driver(&smi_spi_driver); +} + + +MODULE_AUTHOR("Contact <contact@bosch-sensortec.com>"); +MODULE_DESCRIPTION("SMI130 SPI DRIVER"); +MODULE_LICENSE("GPL v2"); + +module_init(smi_spi_init); +module_exit(smi_spi_exit); +/*@}*/ + |
