From 85cdf78f42f18d1fcae6b73e8e4b5aec6f1c2d23 Mon Sep 17 00:00:00 2001 From: vipinbb Date: Fri, 13 Sep 2019 14:51:02 -0400 Subject: [PATCH 01/76] MeiG Change-Id: I5119fe450ae57b860cca823bcff83ab9db448118 --- arch/arm/boot/dts/qcom/Makefile | 1 + ...si-panel-hx8394f-zzw500hah-720p-video.dtsi | 95 + .../dts/qcom/dsi-panel-ortustech-video.dtsi | 186 + .../dts/qcom/dsi-panel-ortustech32-video.dtsi | 80 + ...el-otm1289a-zzw500hc0-145b-720p-video.dtsi | 144 + .../dts/qcom/msm8909-camera-sensor-skua.dtsi | 114 + arch/arm/boot/dts/qcom/msm8909-pinctrl.dtsi | 4 +- arch/arm/boot/dts/qcom/msm8909-qrd-skua.dtsi | 286 +- arch/arm/boot/dts/qcom/msm8909-qrd.dtsi | 32 +- arch/arm/configs/msm8909-perf_defconfig | 13 + arch/arm/configs/msm8909_defconfig | 14 +- drivers/input/misc/Kconfig | 51 + drivers/input/misc/Makefile | 27 +- drivers/input/misc/akm09911.c | 2 +- drivers/input/misc/akm09911m.c | 2661 +++ drivers/input/misc/bmi160.c | 18752 ++++++++++++++++ drivers/input/misc/bmi160.h | 11605 ++++++++++ drivers/input/misc/bmi160_driver.c | 5283 +++++ drivers/input/misc/bmi160_driver.h | 401 + drivers/input/misc/bmi160_i2c.c | 366 + drivers/input/misc/bmp280.c | 1624 ++ drivers/input/misc/bmp280.h | 1366 ++ drivers/input/misc/bmp280_core.c | 1734 ++ drivers/input/misc/bmp280_core.h | 67 + drivers/input/misc/bmp280_i2c.c | 477 + drivers/input/misc/bmp280_spi.c | 258 + drivers/input/touchscreen/Kconfig | 11 + drivers/input/touchscreen/Makefile | 2 +- drivers/input/touchscreen/gt1xx/Kconfig | 19 + drivers/input/touchscreen/gt1xx/Makefile | 16 + drivers/input/touchscreen/gt1xx/gt1x.c | 898 + drivers/input/touchscreen/gt1xx/gt1x.h | 62 + .../input/touchscreen/gt1xx/gt1x_extents.c | 930 + .../input/touchscreen/gt1xx/gt1x_firmware.h | 551 + .../input/touchscreen/gt1xx/gt1x_generic.c | 2472 ++ .../input/touchscreen/gt1xx/gt1x_generic.h | 604 + drivers/input/touchscreen/gt1xx/gt1x_tools.c | 437 + drivers/input/touchscreen/gt1xx/gt1x_update.c | 1472 ++ drivers/platform/msm/qpnp-vibrator.c | 28 +- include/linux/akm09911.h | 168 + 40 files changed, 53271 insertions(+), 42 deletions(-) mode change 100644 => 100755 arch/arm/boot/dts/qcom/Makefile create mode 100755 arch/arm/boot/dts/qcom/dsi-panel-hx8394f-zzw500hah-720p-video.dtsi create mode 100755 arch/arm/boot/dts/qcom/dsi-panel-ortustech-video.dtsi create mode 100755 arch/arm/boot/dts/qcom/dsi-panel-ortustech32-video.dtsi create mode 100755 arch/arm/boot/dts/qcom/dsi-panel-otm1289a-zzw500hc0-145b-720p-video.dtsi create mode 100755 arch/arm/boot/dts/qcom/msm8909-camera-sensor-skua.dtsi mode change 100644 => 100755 arch/arm/boot/dts/qcom/msm8909-pinctrl.dtsi mode change 100644 => 100755 arch/arm/boot/dts/qcom/msm8909-qrd-skua.dtsi mode change 100644 => 100755 arch/arm/boot/dts/qcom/msm8909-qrd.dtsi mode change 100644 => 100755 arch/arm/configs/msm8909-perf_defconfig mode change 100644 => 100755 arch/arm/configs/msm8909_defconfig mode change 100644 => 100755 drivers/input/misc/Kconfig mode change 100644 => 100755 drivers/input/misc/Makefile mode change 100644 => 100755 drivers/input/misc/akm09911.c create mode 100755 drivers/input/misc/akm09911m.c create mode 100755 drivers/input/misc/bmi160.c create mode 100755 drivers/input/misc/bmi160.h create mode 100755 drivers/input/misc/bmi160_driver.c create mode 100755 drivers/input/misc/bmi160_driver.h create mode 100755 drivers/input/misc/bmi160_i2c.c create mode 100755 drivers/input/misc/bmp280.c create mode 100755 drivers/input/misc/bmp280.h create mode 100755 drivers/input/misc/bmp280_core.c create mode 100755 drivers/input/misc/bmp280_core.h create mode 100755 drivers/input/misc/bmp280_i2c.c create mode 100755 drivers/input/misc/bmp280_spi.c mode change 100644 => 100755 drivers/input/touchscreen/Kconfig mode change 100644 => 100755 drivers/input/touchscreen/Makefile create mode 100755 drivers/input/touchscreen/gt1xx/Kconfig create mode 100755 drivers/input/touchscreen/gt1xx/Makefile create mode 100755 drivers/input/touchscreen/gt1xx/gt1x.c create mode 100755 drivers/input/touchscreen/gt1xx/gt1x.h create mode 100755 drivers/input/touchscreen/gt1xx/gt1x_extents.c create mode 100755 drivers/input/touchscreen/gt1xx/gt1x_firmware.h create mode 100755 drivers/input/touchscreen/gt1xx/gt1x_generic.c create mode 100755 drivers/input/touchscreen/gt1xx/gt1x_generic.h create mode 100755 drivers/input/touchscreen/gt1xx/gt1x_tools.c create mode 100755 drivers/input/touchscreen/gt1xx/gt1x_update.c mode change 100644 => 100755 drivers/platform/msm/qpnp-vibrator.c create mode 100755 include/linux/akm09911.h diff --git a/arch/arm/boot/dts/qcom/Makefile b/arch/arm/boot/dts/qcom/Makefile old mode 100644 new mode 100755 index 588774d9339..222dbd27229 --- a/arch/arm/boot/dts/qcom/Makefile +++ b/arch/arm/boot/dts/qcom/Makefile @@ -294,6 +294,7 @@ dtb-$(CONFIG_ARCH_MSM8916) += msm8952-qrd-skum.dtb \ dtb-$(CONFIG_ARCH_MSM8909) += msm8909-pm8916-mtp.dtb \ msm8909-cdp.dtb \ + msm8909-1gb-qrd-skua.dtb\ msm8909-1gb-qrd-skuc.dtb \ msm8909-1gb-qrd-skue.dtb \ msm8909-qrd-skue.dtb \ diff --git a/arch/arm/boot/dts/qcom/dsi-panel-hx8394f-zzw500hah-720p-video.dtsi b/arch/arm/boot/dts/qcom/dsi-panel-hx8394f-zzw500hah-720p-video.dtsi new file mode 100755 index 00000000000..2a690e8610b --- /dev/null +++ b/arch/arm/boot/dts/qcom/dsi-panel-hx8394f-zzw500hah-720p-video.dtsi @@ -0,0 +1,95 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/*--------------------------------------------------------------------------- + * This file is autogenerated file using gcdb parser. Please do not edit it. + * Update input XML file to add a new entry or update variable in this file + * VERSION = "1.0" + *---------------------------------------------------------------------------*/ +&mdss_mdp { + dsi_hx8394f_zzw500hah_720p_video: qcom,mdss_dsi_hx8394f_zzw500hah_720p_video { + qcom,mdss-dsi-panel-name = "hx8394f zzw500hah hd 720X1280 video mode dsi panel"; + qcom,mdss-dsi-panel-controller = <&mdss_dsi0>; + qcom,mdss-dsi-panel-type = "dsi_video_mode"; + qcom,mdss-dsi-panel-destination = "display_1"; + qcom,mdss-dsi-panel-framerate = <60>; + qcom,mdss-dsi-virtual-channel-id = <0>; + qcom,mdss-dsi-stream = <0>; + qcom,mdss-dsi-panel-width = <720>; + qcom,mdss-dsi-panel-height = <1280>; + qcom,mdss-dsi-h-front-porch = <70>; + qcom,mdss-dsi-h-back-porch = <70>; + qcom,mdss-dsi-h-pulse-width = <20>; + qcom,mdss-dsi-h-sync-skew = <0>; + qcom,mdss-dsi-v-back-porch = <12>; + qcom,mdss-dsi-v-front-porch = <15>; + qcom,mdss-dsi-v-pulse-width = <4>; + qcom,mdss-dsi-h-left-border = <0>; + qcom,mdss-dsi-h-right-border = <0>; + qcom,mdss-dsi-v-top-border = <0>; + qcom,mdss-dsi-v-bottom-border = <0>; + qcom,mdss-dsi-bpp = <24>; + qcom,mdss-dsi-color-order = "rgb_swap_rgb"; + qcom,mdss-dsi-underflow-color = <0xff>; + qcom,mdss-dsi-border-color = <0>; + qcom,mdss-dsi-pixel-packing = "tight"; + qcom,mdss-dsi-pixel-alignment = <0>; + qcom,mdss-dsi-on-command = [29 01 00 00 00 00 04 B9 FF 83 94 + 29 01 00 00 00 00 07 BA 63 03 68 6B B2 C0 + 29 01 00 00 00 00 0B B1 48 11 71 09 32 54 71 71 4E 43 + 29 01 00 00 00 00 07 B2 65 80 64 05 07 2F + 29 01 00 00 00 00 16 B4 26 76 26 76 26 26 05 10 86 75 00 3F 26 76 26 76 26 26 05 10 80 + 29 01 00 00 00 00 22 D3 00 00 04 04 01 01 10 10 32 10 00 00 00 32 15 04 05 04 32 15 14 05 14 37 33 04 04 37 00 00 47 05 40 + 29 01 00 00 00 00 2D D5 18 18 18 18 18 18 18 18 18 18 18 18 18 18 25 24 27 26 18 18 11 10 15 14 13 12 17 16 01 00 05 04 03 02 07 06 21 20 23 22 18 18 18 18 + 29 01 00 00 00 00 2D D6 18 18 18 18 18 18 18 18 18 18 18 18 18 18 22 23 20 21 18 18 12 13 16 17 10 11 14 15 06 07 02 03 04 05 00 01 26 27 24 25 18 18 18 18 + 29 01 00 00 00 00 3B E0 00 04 11 1B 1E 22 27 26 51 60 70 6F 7A 8C 94 9A A9 AC A9 B9 C8 64 62 67 69 6A 7F 7F 7F 00 04 11 1A 1D 22 27 26 51 60 70 6F 79 8C 93 98 A8 AB AA B7 C8 64 63 67 6D 72 7F 7F 7F + 29 01 00 00 00 00 03 B6 7D 7D + 29 01 00 00 00 00 02 CC 0B + 29 01 00 00 00 00 03 C0 1F 31 + 29 01 00 00 00 00 02 D2 88 + 29 01 00 00 00 00 02 D4 02 + 29 01 00 00 00 00 02 BD 01 + 29 01 00 00 00 00 02 B1 00 + 29 01 00 00 00 00 02 BD 00 + 29 01 00 00 00 00 08 BF 40 81 50 00 1A FC 01 + 29 01 00 00 00 00 02 C6 EF + 05 01 00 00 78 00 02 11 00 + 05 01 00 00 14 00 02 29 00]; + qcom,mdss-dsi-off-command = [05 01 00 00 32 00 02 28 00 + 05 01 00 00 78 00 02 10 00]; + qcom,mdss-dsi-on-command-state = "dsi_lp_mode"; + qcom,mdss-dsi-off-command-state = "dsi_hs_mode"; + qcom,mdss-dsi-h-sync-pulse = <1>; + qcom,mdss-dsi-traffic-mode = "burst_mode"; + qcom,mdss-dsi-lane-map = "lane_map_0123"; + qcom,mdss-dsi-bllp-eof-power-mode; + qcom,mdss-dsi-bllp-power-mode; + qcom,mdss-dsi-lane-0-state; + qcom,mdss-dsi-lane-1-state; + qcom,mdss-dsi-lane-2-state; + qcom,mdss-dsi-lane-3-state; + qcom,mdss-dsi-te-pin-select = <1>; + qcom,mdss-dsi-te-v-sync-rd-ptr-irq-line = <0x2c>; + qcom,mdss-dsi-te-dcs-command = <1>; + qcom,mdss-dsi-te-check-enable; + qcom,mdss-dsi-te-using-te-pin; + qcom,mdss-dsi-panel-timings = [7B 1A 10 00 3E 40 16 1C 15 03 04 00]; + qcom,mdss-dsi-t-clk-post = <0x04>; + qcom,mdss-dsi-t-clk-pre = <0x26>; + qcom,mdss-dsi-bl-min-level = <1>; + qcom,mdss-dsi-bl-max-level = <255>; + qcom,mdss-dsi-dma-trigger = "trigger_sw"; + qcom,mdss-dsi-mdp-trigger = "none"; + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm"; + qcom,mdss-dsi-reset-sequence = <1 20>, <0 20>, <1 50>; + }; +}; diff --git a/arch/arm/boot/dts/qcom/dsi-panel-ortustech-video.dtsi b/arch/arm/boot/dts/qcom/dsi-panel-ortustech-video.dtsi new file mode 100755 index 00000000000..c68160d7f04 --- /dev/null +++ b/arch/arm/boot/dts/qcom/dsi-panel-ortustech-video.dtsi @@ -0,0 +1,186 @@ +/* Copyright (c) 2013 The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/*--------------------------------------------------------------------------- + * This file is autogenerated file using gcdb parser. Please do not edit it. + * Update input XML file to add a new entry or update variable in this file + * VERSION = "1.0" + *---------------------------------------------------------------------------*/ +&mdss_mdp { + dsi_ortustech_video: qcom,dsi_ortustech_video { + qcom,mdss-dsi-panel-name = "mdss_dsi_ortustech_video 1440x640 video panel"; + qcom,mdss-dsi-panel-controller = <&mdss_dsi0>; + qcom,mdss-dsi-panel-type = "dsi_video_mode"; + qcom,mdss-dsi-panel-destination = "display_1"; + qcom,mdss-dsi-panel-framerate = <60>; + qcom,mdss-dsi-virtual-channel-id = <0>; + qcom,mdss-dsi-stream = <0>; + qcom,mdss-dsi-panel-width = <480>; + qcom,mdss-dsi-panel-height = <640>; + qcom,mdss-dsi-h-front-porch = <16>; + qcom,mdss-dsi-h-back-porch = <16>; + qcom,mdss-dsi-h-pulse-width = <16>; + qcom,mdss-dsi-h-sync-skew = <0>; + qcom,mdss-dsi-v-back-porch = <16>; + qcom,mdss-dsi-v-front-porch = <52>; + qcom,mdss-dsi-v-pulse-width = <4>; + qcom,mdss-dsi-h-left-border = <0>; + qcom,mdss-dsi-h-right-border = <0>; + qcom,mdss-dsi-v-top-border = <0>; + qcom,mdss-dsi-v-bottom-border = <0>; + qcom,mdss-dsi-bpp = <24>; + qcom,mdss-dsi-color-order = "rgb_swap_rgb"; + qcom,mdss-dsi-underflow-color = <0xff>; + qcom,mdss-dsi-border-color = <0>; + qcom,mdss-dsi-pixel-packing = "tight"; + qcom,mdss-dsi-pixel-alignment = <0>; + qcom,mdss-dsi-on-command = [39 01 00 00 00 00 06 FF FF 98 06 04 01 + 39 01 00 00 00 00 02 08 18 + 39 01 00 00 00 00 02 21 01 + 39 01 00 00 00 00 02 30 03 + 39 01 00 00 00 00 02 31 00 + 39 01 00 00 00 00 02 60 0D + 39 01 00 00 00 00 02 61 08 + 39 01 00 00 00 00 02 62 08 + 39 01 00 00 00 00 02 63 09 + 39 01 00 00 00 00 02 40 30 + 39 01 00 00 00 00 02 41 44 + 39 01 00 00 00 00 02 42 00 + 39 01 00 00 00 00 02 43 89 + 39 01 00 00 00 00 02 44 8E + 39 01 00 00 00 00 02 45 D9 + 39 01 00 00 00 00 02 46 33 + 39 01 00 00 00 00 02 47 33 + 39 01 00 00 00 00 02 50 90 + 39 01 00 00 00 00 02 51 90 + 39 01 00 00 00 00 02 56 00 + 39 01 00 00 00 00 02 A0 00 + 39 01 00 00 00 00 02 A1 0C + 39 01 00 00 00 00 02 A2 13 + 39 01 00 00 00 00 02 A3 0F + 39 01 00 00 00 00 02 A4 12 + 39 01 00 00 00 00 02 A5 0D + 39 01 00 00 00 00 02 A6 0C + 39 01 00 00 00 00 02 A7 0B + 39 01 00 00 00 00 02 A8 01 + 39 01 00 00 00 00 02 A9 06 + 39 01 00 00 00 00 02 AA 15 + 39 01 00 00 00 00 02 AB 16 + 39 01 00 00 00 00 02 AC 12 + 39 01 00 00 00 00 02 AD 28 + 39 01 00 00 00 00 02 AE 20 + 39 01 00 00 00 00 02 AF 14 + 39 01 00 00 00 00 02 C0 00 + 39 01 00 00 00 00 02 C1 0C + 39 01 00 00 00 00 02 C2 13 + 39 01 00 00 00 00 02 C3 0F + 39 01 00 00 00 00 02 C4 11 + 39 01 00 00 00 00 02 C5 0D + 39 01 00 00 00 00 02 C6 0C + 39 01 00 00 00 00 02 C7 0B + 39 01 00 00 00 00 02 C8 01 + 39 01 00 00 00 00 02 C9 06 + 39 01 00 00 00 00 02 CA 14 + 39 01 00 00 00 00 02 CB 16 + 39 01 00 00 00 00 02 CC 0F + 39 01 00 00 00 00 02 CD 21 + 39 01 00 00 00 00 02 CE 17 + 39 01 00 00 00 00 02 CF 0A + 39 01 00 00 00 00 06 FF FF 98 06 04 07 + 39 01 00 00 00 00 02 06 11 + 39 01 00 00 00 00 02 18 1D + 39 01 00 00 00 00 02 17 32 + 39 01 00 00 00 00 06 FF FF 98 06 04 06 + 39 01 00 00 00 00 02 00 20 + 39 01 00 00 00 00 02 01 02 + 39 01 00 00 00 00 02 02 00 + 39 01 00 00 00 00 02 03 02 + 39 01 00 00 00 00 02 04 01 + 39 01 00 00 00 00 02 05 01 + 39 01 00 00 00 00 02 06 88 + 39 01 00 00 00 00 02 07 00 + 39 01 00 00 00 00 02 08 01 + 39 01 00 00 00 00 02 09 80 + 39 01 00 00 00 00 02 0A 00 + 39 01 00 00 00 00 02 0B 00 + 39 01 00 00 00 00 02 0C 01 + 39 01 00 00 00 00 02 0D 01 + 39 01 00 00 00 00 02 0E 00 + 39 01 00 00 00 00 02 0F 00 + 39 01 00 00 00 00 02 10 55 + 39 01 00 00 00 00 02 11 50 + 39 01 00 00 00 00 02 12 01 + 39 01 00 00 00 00 02 13 00 + 39 01 00 00 00 00 02 14 00 + 39 01 00 00 00 00 02 15 43 + 39 01 00 00 00 00 02 16 0B + 39 01 00 00 00 00 02 17 00 + 39 01 00 00 00 00 02 18 00 + 39 01 00 00 00 00 02 19 00 + 39 01 00 00 00 00 02 1A 00 + 39 01 00 00 00 00 02 1B 00 + 39 01 00 00 00 00 02 1C 00 + 39 01 00 00 00 00 02 1D 00 + 39 01 00 00 00 00 02 20 01 + 39 01 00 00 00 00 02 21 23 + 39 01 00 00 00 00 02 22 45 + 39 01 00 00 00 00 02 23 67 + 39 01 00 00 00 00 02 24 01 + 39 01 00 00 00 00 02 25 23 + 39 01 00 00 00 00 02 26 45 + 39 01 00 00 00 00 02 27 67 + 39 01 00 00 00 00 02 30 02 + 39 01 00 00 00 00 02 31 22 + 39 01 00 00 00 00 02 32 22 + 39 01 00 00 00 00 02 33 88 + 39 01 00 00 00 00 02 34 AA + 39 01 00 00 00 00 02 35 BB + 39 01 00 00 00 00 02 36 66 + 39 01 00 00 00 00 02 37 22 + 39 01 00 00 00 00 02 38 22 + 39 01 00 00 00 00 02 39 22 + 39 01 00 00 00 00 02 3A 22 + 39 01 00 00 00 00 02 3B 22 + 39 01 00 00 00 00 02 3C 22 + 39 01 00 00 00 00 02 3D 22 + 39 01 00 00 00 00 02 3E 22 + 39 01 00 00 00 00 02 3F 22 + 39 01 00 00 00 00 02 40 22 + 39 01 00 00 00 00 02 53 12 + 39 01 00 00 00 00 06 FF FF 98 06 04 00 + 39 01 00 00 00 00 02 3A 60 + 05 01 00 00 78 00 02 11 00 + 05 01 00 00 1C 00 02 29 00]; + qcom,mdss-dsi-off-command = [ + 05 01 00 00 32 00 02 28 00 + 05 01 00 00 78 00 02 10 00]; + qcom,mdss-dsi-on-command-state = "dsi_lp_mode"; + qcom,mdss-dsi-off-command-state = "dsi_hs_mode"; + qcom,mdss-dsi-h-sync-pulse = <1>; + qcom,mdss-dsi-traffic-mode = "burst_mode"; + qcom,mdss-dsi-lane-map = "lane_map_0123"; + qcom,mdss-dsi-bllp-eof-power-mode; + qcom,mdss-dsi-bllp-power-mode; + qcom,mdss-dsi-lane-0-state; + qcom,mdss-dsi-lane-1-state; + qcom,mdss-dsi-force-clock-lane-hs; + qcom,mdss-dsi-panel-timings = [5A 10 0A 00 30 34 0E 14 0C 03 04 00]; + qcom,mdss-dsi-t-clk-post = <0x05>; + qcom,mdss-dsi-t-clk-pre = <0x14>; + qcom,mdss-dsi-bl-min-level = <1>; + qcom,mdss-dsi-bl-max-level = <4095>; + qcom,mdss-dsi-dma-trigger = "trigger_sw"; + qcom,mdss-dsi-mdp-trigger = "none"; + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm"; + qcom,mdss-dsi-reset-sequence = <1 20>, <0 20>, <1 120>; + }; +}; diff --git a/arch/arm/boot/dts/qcom/dsi-panel-ortustech32-video.dtsi b/arch/arm/boot/dts/qcom/dsi-panel-ortustech32-video.dtsi new file mode 100755 index 00000000000..1eeb50e3390 --- /dev/null +++ b/arch/arm/boot/dts/qcom/dsi-panel-ortustech32-video.dtsi @@ -0,0 +1,80 @@ +/* Copyright (c) 2013 The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/*--------------------------------------------------------------------------- + * This file is autogenerated file using gcdb parser. Please do not edit it. + * Update input XML file to add a new entry or update variable in this file + * VERSION = "1.0" + *---------------------------------------------------------------------------*/ +&mdss_mdp { + dsi_ortustech32_video: qcom,dsi_ortustech32_video { + qcom,mdss-dsi-panel-name = "mdss_dsi_ortustech_video 480x800 video panel"; + qcom,mdss-dsi-panel-controller = <&mdss_dsi0>; + qcom,mdss-dsi-panel-type = "dsi_video_mode"; + qcom,mdss-dsi-panel-destination = "display_1"; + qcom,mdss-dsi-panel-framerate = <60>; + qcom,mdss-dsi-virtual-channel-id = <0>; + qcom,mdss-dsi-stream = <0>; + qcom,mdss-dsi-panel-width = <480>; + qcom,mdss-dsi-panel-height = <800>; + qcom,mdss-dsi-h-front-porch = <16>; + qcom,mdss-dsi-h-back-porch = <16>; + qcom,mdss-dsi-h-pulse-width = <16>; + qcom,mdss-dsi-h-sync-skew = <0>; + qcom,mdss-dsi-v-back-porch = <8>; + qcom,mdss-dsi-v-front-porch = <8>; + qcom,mdss-dsi-v-pulse-width = <8>; + qcom,mdss-dsi-h-left-border = <0>; + qcom,mdss-dsi-h-right-border = <0>; + qcom,mdss-dsi-v-top-border = <0>; + qcom,mdss-dsi-v-bottom-border = <0>; + qcom,mdss-dsi-bpp = <24>; + qcom,mdss-dsi-color-order = "rgb_swap_rgb"; + qcom,mdss-dsi-underflow-color = <0xff>; + qcom,mdss-dsi-border-color = <0>; + qcom,mdss-dsi-pixel-packing = "tight"; + qcom,mdss-dsi-pixel-alignment = <0>; + qcom,mdss-dsi-on-command = [ + 05 01 00 00 a8 00 02 11 00 + 39 01 00 00 00 00 04 B9 FF 83 63 + 39 01 00 00 00 00 0E BA 80 00 10 08 08 10 7E 6E 6D 0A 01 84 43 + 15 01 00 00 00 00 02 36 00 + 15 01 00 00 0e 00 02 3A 70 + 39 01 00 00 00 00 0D B1 78 24 04 02 02 03 10 10 34 3C 3F 3F + 39 01 00 00 00 00 0A B4 00 08 6E 07 01 01 62 01 57 + 15 01 00 00 00 00 02 CC 0B + 39 01 00 00 0e 00 1F E0 01 48 4D 4E 58 F6 0B 4E 12 D5 15 95 55 8E 11 01 48 4D 55 5F FD 0A 4E 51 D3 17 95 96 4E 11 + 05 01 00 00 29 00 02 29 00]; + qcom,mdss-dsi-off-command = [ + 05 01 00 00 32 00 02 28 00 + 05 01 00 00 78 00 02 10 00]; + qcom,mdss-dsi-on-command-state = "dsi_lp_mode"; + qcom,mdss-dsi-off-command-state = "dsi_hs_mode"; + qcom,mdss-dsi-h-sync-pulse = <1>; + qcom,mdss-dsi-traffic-mode = "burst_mode"; + qcom,mdss-dsi-lane-map = "lane_map_0123"; + qcom,mdss-dsi-bllp-eof-power-mode; + qcom,mdss-dsi-bllp-power-mode; + qcom,mdss-dsi-lane-0-state; + qcom,mdss-dsi-lane-1-state; + qcom,mdss-dsi-force-clock-lane-hs; + qcom,mdss-dsi-panel-timings = [7d 12 0C 01 34 38 10 16 0E 03 04 00]; + qcom,mdss-dsi-t-clk-post = <0x20>; + qcom,mdss-dsi-t-clk-pre = <0x24>; + qcom,mdss-dsi-bl-min-level = <1>; + qcom,mdss-dsi-bl-max-level = <4095>; + qcom,mdss-dsi-dma-trigger = "trigger_sw"; + qcom,mdss-dsi-mdp-trigger = "none"; + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm"; + qcom,mdss-dsi-reset-sequence = <1 20>, <0 20>, <1 120>; + }; +}; diff --git a/arch/arm/boot/dts/qcom/dsi-panel-otm1289a-zzw500hc0-145b-720p-video.dtsi b/arch/arm/boot/dts/qcom/dsi-panel-otm1289a-zzw500hc0-145b-720p-video.dtsi new file mode 100755 index 00000000000..839db4d5de5 --- /dev/null +++ b/arch/arm/boot/dts/qcom/dsi-panel-otm1289a-zzw500hc0-145b-720p-video.dtsi @@ -0,0 +1,144 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/*--------------------------------------------------------------------------- + * This file is autogenerated file using gcdb parser. Please do not edit it. + * Update input XML file to add a new entry or update variable in this file + * VERSION = "1.0" + *---------------------------------------------------------------------------*/ +&mdss_mdp { + dsi_otm1289a_zzw500ha0_166b_720p_video: qcom,dsi_otm1289a_zzw500ha0_166b_720p_video { + qcom,mdss-dsi-panel-name = "zhongzhengwei otm1289a zzw500ha0-166B 1280x720p video panel"; + qcom,mdss-dsi-panel-controller = <&mdss_dsi0>; + qcom,mdss-dsi-panel-type = "dsi_video_mode"; + qcom,mdss-dsi-panel-destination = "display_1"; + qcom,mdss-dsi-panel-framerate = <60>; + qcom,mdss-dsi-virtual-channel-id = <0>; + qcom,mdss-dsi-stream = <0>; + qcom,mdss-dsi-panel-width = <720>; + qcom,mdss-dsi-panel-height = <1280>; + qcom,mdss-dsi-h-front-porch = <70>; + qcom,mdss-dsi-h-back-porch = <70>; + qcom,mdss-dsi-h-pulse-width = <20>; + qcom,mdss-dsi-h-sync-skew = <0>; + qcom,mdss-dsi-v-back-porch = <12>; + qcom,mdss-dsi-v-front-porch = <15>; + qcom,mdss-dsi-v-pulse-width = <4>; + qcom,mdss-dsi-h-left-border = <0>; + qcom,mdss-dsi-h-right-border = <0>; + qcom,mdss-dsi-v-top-border = <0>; + qcom,mdss-dsi-v-bottom-border = <0>; + qcom,mdss-dsi-bpp = <24>; + qcom,mdss-dsi-color-order = "rgb_swap_rgb"; + qcom,mdss-dsi-underflow-color = <0xff>; + qcom,mdss-dsi-border-color = <0>; + qcom,mdss-dsi-pixel-packing = "tight"; + qcom,mdss-dsi-pixel-alignment = <0>; + qcom,mdss-dsi-on-command = [39 01 00 00 00 00 02 00 00 + 39 01 00 00 00 00 04 ff 12 89 01 + 39 01 00 00 00 00 02 00 80 + 39 01 00 00 00 00 03 ff 12 89 + 39 01 00 00 00 00 02 00 90 + 39 01 00 00 00 00 02 ff b0 + 39 01 00 00 00 00 02 00 80 + 39 01 00 00 00 00 09 c0 4a 00 10 10 96 01 68 40 + 39 01 00 00 00 00 02 00 90 + 39 01 00 00 00 00 04 c0 3b 01 09 + 39 01 00 00 00 00 02 00 8c + 39 01 00 00 00 00 02 c0 00 + 39 01 00 00 00 00 02 00 80 + 39 01 00 00 00 00 02 c1 33 + 39 01 00 00 00 00 02 00 85 + 39 01 00 00 00 00 04 c5 0a 0a 46 + 39 01 00 00 00 00 02 00 00 + 39 01 00 00 00 00 03 d8 27 27 + 39 01 00 00 00 00 02 00 01 + 39 01 00 00 00 00 02 d9 77 + 39 01 00 00 00 00 02 00 84 + 39 01 00 00 00 00 02 C4 02 + 39 01 00 00 00 00 02 00 93 + 39 01 00 00 00 00 02 C4 04 + 39 01 00 00 00 00 02 00 96 + 39 01 00 00 00 00 02 F5 E7 + 39 01 00 00 00 00 02 00 A0 + 39 01 00 00 00 00 02 F5 4A + 39 01 00 00 00 00 02 00 8a + 39 01 00 00 00 00 02 c0 11 + 39 01 00 00 00 00 02 00 83 + 39 01 00 00 00 00 02 F5 81 + 39 01 00 00 00 00 02 00 90 + 39 01 00 00 00 00 03 c4 96 05 + 39 01 00 00 00 00 02 00 80 + 39 01 00 00 00 00 10 cb 14 14 14 14 14 00 00 00 00 00 00 00 00 00 00 + 39 01 00 00 00 00 02 00 90 + 39 01 00 00 00 00 08 cb FC FC FC 00 14 14 14 + 39 01 00 00 00 00 02 00 80 + 39 01 00 00 00 00 0F cc 02 0A 0C 0E 10 00 00 00 00 00 00 00 00 00 + 39 01 00 00 00 00 02 00 90 + 39 01 00 00 00 00 10 cc 00 00 00 00 1E 1D 06 01 09 0B 0d 0F 00 00 00 + 39 01 00 00 00 00 02 00 a0 + 39 01 00 00 00 00 0E cc 00 00 00 00 00 00 00 00 00 00 1E 1D 05 + 39 01 00 00 00 00 02 00 b0 + 39 01 00 00 00 00 0F cc 05 0F 0D 0B 09 00 00 00 00 00 00 00 00 00 + 39 01 00 00 00 00 02 00 c0 + 39 01 00 00 00 00 10 cc 00 00 00 00 1D 1E 01 06 10 0E 0C 0A 00 00 00 + 39 01 00 00 00 00 02 00 d0 + 39 01 00 00 00 00 0E cc 00 00 00 00 00 00 00 00 00 00 1D 1E 02 + 39 01 00 00 00 00 02 00 80 + 39 01 00 00 00 00 07 ce 87 03 10 86 00 00 + 39 01 00 00 00 00 02 00 90 + 39 01 00 00 00 00 0A ce 34 ff 10 05 00 00 00 00 00 + 39 01 00 00 00 00 02 00 a0 + 39 01 00 00 00 00 10 ce 30 83 88 00 20 00 82 87 00 81 86 00 80 85 00 + 39 01 00 00 00 00 02 00 b0 + 39 01 00 00 00 00 10 ce 30 00 84 00 20 00 01 83 00 02 82 00 03 81 00 + 39 01 00 00 00 00 02 00 E0 + 39 01 00 00 00 00 09 CE 0A 04 FC 00 00 0A 04 FC + 39 01 00 00 00 00 02 00 F0 + 39 01 00 00 00 00 07 CE 01 20 01 01 00 00 + 39 01 00 00 00 00 02 00 00 + 39 01 00 00 00 00 11 E1 00 16 26 37 47 65 64 7d 76 62 69 50 38 21 13 00 + 39 01 00 00 00 00 02 00 00 + 39 01 00 00 00 00 11 E2 00 16 26 37 47 65 64 7d 76 62 69 50 38 21 13 00 + 39 01 00 00 00 00 02 00 00 + 39 01 00 00 00 00 04 ff ff ff ff + 05 01 00 00 C8 00 02 11 00 + 05 01 00 00 32 00 02 29 00]; + qcom,mdss-dsi-off-command = [05 01 00 00 32 00 02 28 00 + 05 01 00 00 78 00 02 10 00]; + qcom,mdss-dsi-on-command-state = "dsi_lp_mode"; + qcom,mdss-dsi-off-command-state = "dsi_hs_mode"; + qcom,mdss-dsi-h-sync-pulse = <1>; + qcom,mdss-dsi-traffic-mode = "burst_mode"; + qcom,mdss-dsi-lane-map = "lane_map_0123"; + qcom,mdss-dsi-bllp-eof-power-mode; + qcom,mdss-dsi-bllp-power-mode; + qcom,mdss-dsi-lane-0-state; + qcom,mdss-dsi-lane-1-state; + qcom,mdss-dsi-lane-2-state; + qcom,mdss-dsi-lane-3-state; + qcom,mdss-dsi-te-pin-select = <1>; + qcom,mdss-dsi-te-v-sync-rd-ptr-irq-line = <0x2c>; + qcom,mdss-dsi-te-dcs-command = <1>; + qcom,mdss-dsi-te-check-enable; + qcom,mdss-dsi-te-using-te-pin; + qcom,mdss-dsi-panel-timings = [7B 1A 10 00 3E 40 16 1C 15 03 04 00]; + qcom,mdss-dsi-t-clk-post = <0x04>; + qcom,mdss-dsi-t-clk-pre = <0x26>; + qcom,mdss-dsi-bl-min-level = <1>; + qcom,mdss-dsi-bl-max-level = <4095>; + qcom,mdss-dsi-dma-trigger = "trigger_sw"; + qcom,mdss-dsi-mdp-trigger = "none"; + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_wled"; + qcom,mdss-dsi-reset-sequence = <1 20>, <0 20>, <1 120>; + }; +}; diff --git a/arch/arm/boot/dts/qcom/msm8909-camera-sensor-skua.dtsi b/arch/arm/boot/dts/qcom/msm8909-camera-sensor-skua.dtsi new file mode 100755 index 00000000000..8434c3c93c1 --- /dev/null +++ b/arch/arm/boot/dts/qcom/msm8909-camera-sensor-skua.dtsi @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +&soc { +}; + +&i2c_3 { + + actuator0: qcom,actuator@0 { /* added by luosiyuan 2017.05.19 */ + cell-index = <0>; + reg = <0x18>; + compatible = "qcom,actuator"; + qcom,cci-master = <0>; + cam_vaf-supply = <&pm8909_l8>; + qcom,cam-vreg-name = "cam_vaf"; + qcom,cam-vreg-type = <0>; + qcom,cam-vreg-min-voltage = <2850000>; + qcom,cam-vreg-max-voltage = <2900000>; + qcom,cam-vreg-op-mode = <80000>; + }; + + qcom,camera@0 { + cell-index = <0>; + compatible = "qcom,camera"; + reg = <0x2>; + qcom,csiphy-sd-index = <0>; + qcom,csid-sd-index = <0>; + qcom,mount-angle = <90>; + qcom,actuator-src = <&actuator0>;/*added by luosiyuan 2017.05.19*/ + cam_vana-supply = <&pm8909_l17>; + cam_vio-supply = <&pm8909_l6>; + qcom,cam-vreg-name = "cam_vio", "cam_vana"; + qcom,cam-vreg-min-voltage = <0 2800000>; + qcom,cam-vreg-max-voltage = <0 2850000>; + qcom,cam-vreg-op-mode = <0 80000>; + pinctrl-names = "cam_default", "cam_suspend"; + pinctrl-0 = <&cam_sensor_mclk0_default + &cam_sensor_rear_default>; + pinctrl-1 = <&cam_sensor_mclk0_sleep &cam_sensor_rear_sleep>; + gpios = <&msm_gpio 26 0>, + <&msm_gpio 35 0>, + <&msm_gpio 34 0>, + <&msm_gpio 17 0>, /* added by luosiyuan 2017.05.19 */ + <&msm_gpio 99 0>; /* added by luosiyuan 2017.05.19 */ + qcom,gpio-reset = <1>; + qcom,gpio-standby = <2>; + qcom,gpio-custom2 = <3>; + qcom,gpio-custom3 = <4>; + qcom,gpio-req-tbl-num = <0 1 2 3 4>; + qcom,gpio-req-tbl-flags = <1 0 0 0 0>; + qcom,gpio-req-tbl-label = "CAMIF_MCLK", + "CAM_RESET1", + "CAM_STANDBY", + "CAM_DVDD_1V2", + "CAM_DVAF_2V8"; + qcom,sensor-position = <0>; + qcom,sensor-mode = <0>; + qcom,cci-master = <0>; + status = "ok"; + clocks = <&clock_gcc clk_mclk0_clk_src>, + <&clock_gcc clk_gcc_camss_mclk0_clk>; + clock-names = "cam_src_clk", "cam_clk"; + }; + + qcom,camera@1 { + cell-index = <1>; + compatible = "qcom,camera"; + reg = <0x1>; + qcom,csiphy-sd-index = <0>; + qcom,csid-sd-index = <0>; + qcom,mount-angle = <90>; + cam_vana-supply = <&pm8909_l17>; + cam_vio-supply = <&pm8909_l6>; + qcom,cam-vreg-name = "cam_vio", "cam_vana"; + qcom,cam-vreg-type = <1 0>; + qcom,cam-vreg-min-voltage = <0 2850000>; + qcom,cam-vreg-max-voltage = <0 2850000>; + qcom,cam-vreg-op-mode = <0 80000>; + pinctrl-names = "cam_default", "cam_suspend"; + pinctrl-0 = <&cam_sensor_mclk1_default &cam_sensor_front_default>; + pinctrl-1 = <&cam_sensor_mclk1_sleep &cam_sensor_front_sleep>; + gpios = <&msm_gpio 27 0>, + <&msm_gpio 28 0>, + <&msm_gpio 33 0>, + <&msm_gpio 17 0>, /* Add ov5670_8909 DVDD enable by huangfusheng 2017-05-19 */ + <&msm_gpio 99 0>; /* Add ov5670_8909 VAF enable by huangfusheng 2017-05-19 */ + qcom,gpio-reset = <1>; + qcom,gpio-standby = <2>; + qcom,gpio-custom2 = <3>; /* Add ov5670_8909 DVDD enable by huangfusheng 2017-05-19 */ + qcom,gpio-custom3 = <4>; /* Add ov5670_8909 VAF enable by huangfusheng 2017-05-19 */ + qcom,gpio-req-tbl-num = <0 1 2 3 4>; + qcom,gpio-req-tbl-flags = <1 0 0 0 0>; + qcom,gpio-req-tbl-label = "CAMIF_MCLK", + "CAM_RESET", + "CAM_STANDBY", + "CAM_DVDD_1V2", /* Add ov5670_8909 DVDD enable by huangfusheng 2017-05-19 */ + "CAM_DVAF_2V8"; /* Add ov5670_8909 VAF enable by huangfusheng 2017-05-19 */ + qcom,cci-master = <0>; + status = "ok"; + clocks = <&clock_gcc clk_mclk1_clk_src>, + <&clock_gcc clk_gcc_camss_mclk1_clk>; + clock-names = "cam_src_clk", "cam_clk"; + }; +}; diff --git a/arch/arm/boot/dts/qcom/msm8909-pinctrl.dtsi b/arch/arm/boot/dts/qcom/msm8909-pinctrl.dtsi old mode 100644 new mode 100755 index c064cfec9d6..2e968b72912 --- a/arch/arm/boot/dts/qcom/msm8909-pinctrl.dtsi +++ b/arch/arm/boot/dts/qcom/msm8909-pinctrl.dtsi @@ -909,12 +909,12 @@ tlmm_gpio_key { gpio_key_active: gpio_key_active { mux { - pins = "gpio90", "gpio91", "gpio92"; + pins = "gpio90", "gpio92", "gpio11"; function = "gpio"; }; config { - pins = "gpio90", "gpio91", "gpio92"; + pins = "gpio90", "gpio92", "gpio11"; drive-strength = <2>; bias-pull-up; }; diff --git a/arch/arm/boot/dts/qcom/msm8909-qrd-skua.dtsi b/arch/arm/boot/dts/qcom/msm8909-qrd-skua.dtsi old mode 100644 new mode 100755 index 6a0554a6de5..f4239d6b52b --- a/arch/arm/boot/dts/qcom/msm8909-qrd-skua.dtsi +++ b/arch/arm/boot/dts/qcom/msm8909-qrd-skua.dtsi @@ -11,7 +11,11 @@ */ #include "msm8909-qrd.dtsi" - +//#include "msm8909-camera-sensor-skua.dtsi" +#include "dsi-panel-hx8394f-zzw500hah-720p-video.dtsi" +#include "dsi-panel-otm1289a-zzw500hc0-145b-720p-video.dtsi" +//#include "dsi-panel-ortustech-video.dtsi" +#include "dsi-panel-ortustech32-video.dtsi" / { model = "Qualcomm Technologies, Inc. MSM8909 QRD SKUA"; compatible = "qcom,msm8909-qrd", "qcom,msm8909", "qcom,qrd"; @@ -19,14 +23,31 @@ &soc { i2c@78b9000 { /* BLSP1 QUP5 */ - focaltech@38 { + status = "ok"; + goodix@5d { + compatible = "goodix,gt1x"; + reg = <0x5d>; + interrupt-parent = <&msm_gpio>; + interrupts = <13 0x2>; + vdd_ana-supply = <&pm8909_l17>; + vcc_i2c-supply = <&pm8909_l6>; + goodix,rst-gpio = <&msm_gpio 12 0x00>; + goodix,irq-gpio = <&msm_gpio 13 0x00>; + pinctrl-names = "pmx_ts_active", + "pmx_ts_suspend", + "pmx_ts_release"; + pinctrl-0 = <&ts_int_active &ts_reset_active>; + pinctrl-1 = <&ts_int_suspend &ts_reset_suspend>; + pinctrl-2 = <&ts_release>; + }; +/* focaltech@38 { compatible = "focaltech,5x06"; reg = <0x38>; interrupt-parent = <&msm_gpio>; interrupts = <13 0x2>; vdd-supply = <&pm8909_l17>; vcc_i2c-supply = <&pm8909_l6>; - /* pins used by touchscreen */ + // pins used by touchscreen pinctrl-names = "pmx_ts_active","pmx_ts_suspend","pmx_ts_release"; pinctrl-0 = <&ts_int_active &ts_reset_active>; pinctrl-1 = <&ts_int_suspend &ts_reset_suspend>; @@ -53,6 +74,7 @@ focaltech,fw-auto-cal; focaltech,ignore-id-check; }; +*/ }; gen-vkeys { @@ -66,14 +88,17 @@ qcom,y-offset = <0>; }; +/* Modified by kuangjincheng @20171119 to optimize audio code */ sound { + status = "ok"; compatible = "qcom,msm8x16-audio-codec"; qcom,model = "msm8909-skua-snd-card"; qcom,msm-snd-card-id = <0>; qcom,msm-codec-type = "internal"; qcom,msm-ext-pa = "primary"; + qcom,msm-spk-ext-pa = <&msm_gpio 17 0x0>; qcom,msm-mclk-freq = <9600000>; - qcom,msm-mbhc-hphl-swh = <1>; + qcom,msm-mbhc-hphl-swh = <0>; qcom,msm-mbhc-gnd-swh = <0>; qcom,msm-hs-micbias-type = "internal"; qcom,msm-micbias1-ext-cap; @@ -125,31 +150,41 @@ }; }; -&tlmm_pinmux { - bma2x2_int1_pin { - qcom,pins = <&gp 96>; - qcom,num-grp-pins = <1>; - label = "bma2x2_int1_pin"; - bma2x2_int1_default: int1_default { - drive-strength = <6>; - bias-pull-up; - }; - }; - - bma2x2_int2_pin { - qcom,pins = <&gp 65>; - qcom,num-grp-pins = <1>; - label = "bma2x2_int2_pin"; - bma2x2_int2_default: int2_default { - drive-strength = <6>; - bias-pull-up; - }; +&i2c_1 { /* BLSP1 QUP1 */ + //light and proximity sensor +/* + liteon@23 { + compatible = "liteon,ltr553"; + reg = <0x23>; + pinctrl-names = "default","sleep"; + pinctrl-0 = <<r553_default>; + pinctrl-1 = <<r553_sleep>; + interrupt-parent = <&msm_gpio>; + interrupts = <94 0x2>; + vdd-supply = <&pm8909_l17>; + vio-supply = <&pm8909_l6>; + liteon,intr = <&msm_gpio 94 0x2>; + liteon,highthr = <800>; + liteon,lowthr = <300>; }; -}; +*/ + akm@c { + compatible = "ak,ak09911"; + reg = <0x0c>; + pinctrl-names = "default","sleep"; + pinctrl-0 = <&akm_default>; + pinctrl-1 = <&akm_sleep>; + vdd-supply = <&pm8909_l17>; + vio-supply = <&pm8909_l6>; + akm,layout = <0x3>; + akm,poll_interval = <200>; + akm,gpio_rstn = <&msm_gpio 65 0x0>; + akm,auto-report; + }; -&i2c_1 { /* BLSP1 QUP1 */ - bosch@18 { /* Accelerometer sensor */ + bosch@18 { //Accelerometer sensor compatible = "bosch,bma2x2"; + status = "disabled"; reg = <0x18>; pinctrl-names = "default"; pinctrl-0 = <&bma2x2_int1_default &bma2x2_int2_default>; @@ -160,8 +195,29 @@ bosch,init-interval = <200>; bosch,place = <2>; bosch,gpio-int1 = <&msm_gpio 96 0x2002>; - bosch,gpio-int2 = <&msm_gpio 65 0x2002>; + bosch,gpio-int2 = <&msm_gpio 31 0x2002>; }; + + bmp@76 { + compatible = "bmp280"; + reg = <0x76>; + vdd-supply = <&pm8909_l17>; + vio-supply = <&pm8909_l6>; + }; + + bosch@68 { /* Accelerometer and gyroscope sensor */ + compatible = "bosch,bmi160"; + //status = "disabled"; + reg = <0x68>; + pinctrl-names = "default"; + pinctrl-0 = <&bmi160_int1_default>; + interrupt-parent = <&msm_gpio>; + interrupts = <95 0x2002>; + vdd-supply = <&pm8909_l17>; + vio-supply = <&pm8909_l6>; + bosch,place = <5>; + bosch,gpio-int1 = <&msm_gpio 95 0x2002>; + }; }; &pm8909_vadc { @@ -208,12 +264,14 @@ }; &sdhc_2 { +/* qcom,nonhotplug; interrupts = <0 1>; interrupt-map = <0 &intc 0 125 0 1 &intc 0 221 0>; interrupt-names = "hc_irq", "pwr_irq"; /delete-property/ cd-gpios; +*/ }; &pm8909_mpps { @@ -251,18 +309,178 @@ qcom,panel-supply-entries = <&dsi_panel_pwr_supply>; }; -&pmx_mdss { - qcom,num-grp-pins = <1>; - qcom,pins = <&gp 25>; +&msm_gpio { + pmx_mdss { + mdss_dsi_active: mdss_dsi_active { + mux { + pins = "gpio25"; + }; + config { + pins = "gpio25"; + }; + }; + mdss_dsi_suspend: mdss_dsi_suspend { + mux { + pins = "gpio25"; + }; + config { + pins = "gpio25"; + }; + }; + }; + pmx_mdss_te { + mdss_te_active: mdss_te_active { + mux { + pins = "gpio24"; + }; + config { + pins = "gpio24"; + }; + }; + mdss_te_suspend: mdss_te_suspend { + mux { + pins = "gpio24"; + }; + config { + pins = "gpio24"; + }; + }; + }; + bma2x2_int1_pin { + bma2x2_int1_default: int1_default { + mux { + pins = "gpio96"; + function = "gpio"; + }; + config { + pins = "gpio96"; + drive-dtrength = <6>; + bias-pull-up; + }; + }; + }; + bma2x2_int2_pin { + bma2x2_int2_default: int2_default { + mux { + pins = "gpio65"; + function = "gpio"; + }; + config { + pins = "gpio65"; + drive-dtrength = <6>; + bias-pull-up; + }; + }; + }; + + bmi160_int1_pin { + bmi160_int1_default: int1_default { + mux { + pins = "gpio95"; + function = "gpio"; + }; + config { + pins = "gpio95"; + drive-dtrength = <6>; + bias-pull-up; + }; + }; + }; + + ltr553_int_pin { + ltr553_default: ltr553_default { + mux { + pins = "gpio94"; + function = "gpio"; + }; + config { + pins = "gpio94"; + drive-dtrength = <6>; + bias-pull-up; + }; + }; + ltr553_sleep: ltr553_sleep { + mux { + pins = "gpio94"; + function = "gpio"; + }; + config { + pins = "gpio94"; + drive-strength = <2>; + bias-pull-down; + }; + }; + }; + + akm_reset_pin { + akm_default: akm_default { + mux { + pins = "gpio65"; + function = "gpio"; + }; + config { + pins = "gpio65"; + drive-dtrength = <6>; + bias-pull-up; + }; + }; + akm_sleep: akm_sleep { + mux { + pins = "gpio65"; + function = "gpio"; + }; + config { + pins = "gpio65"; + drive-strength = <2>; + bias-pull-down; + }; + }; + }; + }; -&pmx_mdss_te { - qcom,num-grp-pins = <1>; - qcom,pins = <&gp 24>; +&dsi_otm1289a_zzw500ha0_166b_720p_video { + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm"; + qcom,mdss-dsi-bl-pmic-pwm-frequency = <1000>; + qcom,mdss-dsi-bl-pmic-bank-select = <0>; + qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>; + qcom,cont-splash-enabled; + qcom,panel-supply-entries = <&dsi_panel_pwr_supply>; +}; + +&dsi_hx8394f_zzw500hah_720p_video { + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm"; + qcom,mdss-dsi-bl-pmic-pwm-frequency = <1000>; + qcom,mdss-dsi-bl-pmic-bank-select = <0>; + qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>; + qcom,cont-splash-enabled; + qcom,panel-supply-entries = <&dsi_panel_pwr_supply>; }; +/*&dsi_ortustech_video { + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm"; + qcom,mdss-dsi-bl-pmic-pwm-frequency = <1000>; + qcom,mdss-dsi-bl-pmic-bank-select = <0>; + qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>; + qcom,cont-splash-enabled; + qcom,panel-supply-entries = <&dsi_panel_pwr_supply>; +};*/ + + +&dsi_ortustech32_video { + qcom,mdss-dsi-bl-pmic-control-type = "bl_ctrl_pwm"; + qcom,mdss-dsi-bl-pmic-pwm-frequency = <1000>; + qcom,mdss-dsi-bl-pmic-bank-select = <0>; + qcom,mdss-dsi-pwm-gpio = <&pm8909_mpps 2 0>; + qcom,cont-splash-enabled; + qcom,panel-supply-entries = <&dsi_panel_pwr_supply>; +}; + + &mdss_dsi0 { - qcom,dsi-pref-prim-pan = <&dsi_hx8379a_fwvga_skua_vid>; + //qcom,dsi-pref-prim-pan = <&dsi_hx8379a_fwvga_skua_vid>; + //qcom,dsi-pref-prim-pan = <&dsi_ortustech_video>; + qcom,dsi-pref-prim-pan = <&dsi_ortustech32_video>; pinctrl-names = "mdss_default", "mdss_sleep"; pinctrl-0 = <&mdss_dsi_active &mdss_te_active>; pinctrl-1 = <&mdss_dsi_suspend &mdss_te_suspend>; diff --git a/arch/arm/boot/dts/qcom/msm8909-qrd.dtsi b/arch/arm/boot/dts/qcom/msm8909-qrd.dtsi old mode 100644 new mode 100755 index 5ee6d9ca315..d0c00183fa0 --- a/arch/arm/boot/dts/qcom/msm8909-qrd.dtsi +++ b/arch/arm/boot/dts/qcom/msm8909-qrd.dtsi @@ -21,11 +21,19 @@ compatible = "qcom,msm8909-qrd", "qcom,msm8909", "qcom,qrd"; }; +&pm8909_vib { + status = "okay"; +}; &blsp1_uart1 { status = "ok"; pinctrl-names = "default"; pinctrl-0 = <&uart_console_sleep>; }; +//&blsp1_uart2 { +// status = "ok"; +// pinctrl-names = "default"; +// pinctrl-0 = <&hsuart_active>; +//}; &qcom_rng { status = "okay"; @@ -59,10 +67,25 @@ label = "volume_up"; gpios = <&msm_gpio 90 0x1>; linux,input-type = <1>; - linux,code = <115>; + linux,code = <0x19c>;/* KEY_PREVIOUS <115>;*/ + gpio-key,wakeup; + debounce-interval = <15>; + }; + vol_down { + label = "volume_down"; + gpios = <&msm_gpio 11 0x1>; + linux,input-type = <1>; + linux,code = <0x197>;/* KEY_NEXT <114>;*/ gpio-key,wakeup; debounce-interval = <15>; }; + + home_key { + label = "home_key"; + gpios = <&msm_gpio 98 0x1>; + linux,input-type = <1>; + linux,code = <28>; /* KEY_ENTER <102>*/ + }; }; }; @@ -120,6 +143,7 @@ status = "okay"; qcom,vib-timeout-ms = <15000>; qcom,vib-vtg-level-mV = <3100>; + vib-gpios = <&msm_gpio 16 0x1>; }; }; }; @@ -146,8 +170,14 @@ &qdsd_data3_jtag>; pinctrl-5 = <&qdsd_clk_spmi &qdsd_cmd_spmi &qdsd_data0_spmi &qdsd_data3_spmi>; + status = "disabled"; }; &android_usb { qcom,android-usb-cdrom; }; + +&spi_0 { + status = "disabled"; +}; + diff --git a/arch/arm/configs/msm8909-perf_defconfig b/arch/arm/configs/msm8909-perf_defconfig old mode 100644 new mode 100755 index 22e84cb1df4..b778f15ca42 --- a/arch/arm/configs/msm8909-perf_defconfig +++ b/arch/arm/configs/msm8909-perf_defconfig @@ -306,6 +306,7 @@ CONFIG_SENSORS_AKM8963=y CONFIG_INPUT_UINPUT=y CONFIG_INPUT_GPIO=m CONFIG_SENSORS_LTR553=y +# CONFIG_SENSORS_AKM09911=y CONFIG_SENSORS_BMA2X2=y # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set @@ -532,3 +533,15 @@ CONFIG_EXT4_FS_SECURITY=y CONFIG_ANDROID_LOW_MEMORY_KILLER=y CONFIG_FUSE_FS=y CONFIG_CMA_SIZE_MBYTES=8 +# add by liangdi +CONFIG_TOUCHSCREEN_GT1XX=y +CONFIG_SENSORS_AKM09911=y +# add by liangdi 20190821 +CONFIG_SENSORS_BMI160=y +#CONFIG_BMI160_MAG_INTERFACE_SUPPORT=y +CONFIG_SENSORS_BMI160_I2C=y +CONFIG_SENSORS_BMI160_ENABLE_INT1=y +# CONFIG_SENSORS_BMI160_ENABLE_INT2=y +CONFIG_SENSORS_BMP280=y +CONFIG_SENSORS_BMP280_I2C=y + diff --git a/arch/arm/configs/msm8909_defconfig b/arch/arm/configs/msm8909_defconfig old mode 100644 new mode 100755 index 63c888e32a1..f2f16d7ab43 --- a/arch/arm/configs/msm8909_defconfig +++ b/arch/arm/configs/msm8909_defconfig @@ -307,7 +307,7 @@ CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_FW_UPDATE=y CONFIG_INPUT_MISC=y CONFIG_SENSORS_MPU6050=y -CONFIG_SENSORS_AKM8963=y +# CONFIG_SENSORS_AKM8963=y CONFIG_INPUT_UINPUT=y CONFIG_INPUT_GPIO=m CONFIG_SENSORS_LTR553=y @@ -598,3 +598,15 @@ CONFIG_CRYPTO_DEV_QCEDEV=y CONFIG_QMI_ENCDEC=y CONFIG_MEMCG=y CONFIG_MEMCG_SWAP=y +# add by liangdi +CONFIG_TOUCHSCREEN_GT1XX=y +CONFIG_SENSORS_AKM09911=y +# add by liangdi 20190821 +CONFIG_SENSORS_BMI160=y +#CONFIG_BMI160_MAG_INTERFACE_SUPPORT=y +CONFIG_SENSORS_BMI160_I2C=y +CONFIG_SENSORS_BMI160_ENABLE_INT1=y +# CONFIG_SENSORS_BMI160_ENABLE_INT2=y +CONFIG_SENSORS_BMP280=y +CONFIG_SENSORS_BMP280_I2C=y + diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig old mode 100644 new mode 100755 index 7c02e682aa3..0897a5c101d --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -854,4 +854,55 @@ config DOUBLE_TAP help If you say yes here, you get support Bosch double tap sensor function +config SENSORS_BMI160 + tristate "BMI160 Sensor Support" + depends on I2C || SPI_MASTER + help + If you say yes here, you get support for Bosch Sensortec's + sensor driver of BMI160. + +config SENSORS_BMI160_I2C + tristate "support I2C bus communication" + depends on SENSORS_BMI160 && I2C + help + If you say yes here, you get support Bosch Sensortec's BMI160 sensor hooked to an I2C bus. + +config BMI160_MAG_INTERFACE_SUPPORT + tristate "BMI160 Sensor mag interface support" + depends on SENSORS_BMI160 + help + If you say yes here, you get support for Bosch Sensortec's + sensor driver of BMI160 with mag sensor support. + +config SENSORS_BMI160_ENABLE_INT1 + tristate "BMI160 sensor interrupt INT1 support" + depends on SENSORS_BMI160 + help + If you say yes here, you get INT1 support for Bosch Sensortec + sensors BMI160. + +config SENSORS_BMI160_ENABLE_INT2 + tristate "BMI160 sensor interrupt INT2 support" + depends on SENSORS_BMI160 + help + If you say yes here, you get INT2 support for Bosch Sensortec + sensors BMI160. + +config SENSORS_BMP280 + tristate "BMP280 digital Pressure Sensor" + depends on (I2C || SPI_MASTER) && SYSFS + help + If you say yes here, you get support for Bosch Sensortec's BMP280 digital pressure sensors. + +config SENSORS_BMP280_I2C + tristate "support I2C bus communication" + depends on SENSORS_BMP280 && I2C + help + If you say yes here, you get support Bosch Sensortec's BMP280 pressure sensor hooked to an I2C bus. + +config SENSORS_BMP280_SPI + tristate "support SPI bus communication" + depends on SENSORS_BMP280 && SPI_MASTER + help + If you say yes here, you get support Bosch Sensortec's BMP280 pressure sensor hooked to an SPI bus. endif diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile old mode 100644 new mode 100755 index e1bb7cc45b7..5355259fc5e --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -73,7 +73,7 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o obj-$(CONFIG_INPUT_YEALINK) += yealink.o obj-$(CONFIG_SENSORS_MMC3416X) += mmc3416x.o -obj-$(CONFIG_SENSORS_AKM09911) += akm09911.o +obj-$(CONFIG_SENSORS_AKM09911) += akm09911m.o obj-$(CONFIG_SENSORS_AP3426) += ap3426.o obj-$(CONFIG_SENSORS_BMA2X2) += bstclass.o @@ -89,3 +89,28 @@ ifeq ($(CONFIG_BOSCH_BMA2X2_ENABLE_INT2),y) endif obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o obj-$(CONFIG_INPUT_PIXART_OTS_PAT9125_SWITCH) += ots_pat9125/ + +obj-$(CONFIG_SENSORS_BMI160) += bmi160_driver.o bmi160.o +ifeq ($(CONFIG_BMI160_MAG_INTERFACE_SUPPORT),y) + EXTRA_CFLAGS += -DBMI160_MAG_INTERFACE_SUPPORT +endif +ifeq ($(CONFIG_SENSORS_BMI160_ENABLE_INT1),y) + EXTRA_CFLAGS += -DBMI160_ENABLE_INT1 +endif + +ifeq ($(CONFIG_SENSORS_BMI160_ENABLE_INT2),y) + EXTRA_CFLAGS += -DBMI160_ENABLE_INT2 +endif + +obj-$(CONFIG_SENSORS_BMI160_I2C) += bmi160_i2c.o +ifeq ($(CONFIG_SENSORS_BMI160_I2C),y) + EXTRA_CFLAGS += -DBMI_USE_BASIC_I2C_FUNC + +obj-$(CONFIG_SENSORS_BMP280) += bmp280_core.o bmp280.o +obj-$(CONFIG_SENSORS_BMP280_I2C) += bmp280_i2c.o +obj-$(CONFIG_SENSORS_BMP280_SPI) += bmp280_spi.o +ifeq ($(CONFIG_SENSORS_BMP280_I2C),y) + EXTRA_CFLAGS += -DBMP_USE_BASIC_I2C_FUNC +endif +endif + diff --git a/drivers/input/misc/akm09911.c b/drivers/input/misc/akm09911.c old mode 100644 new mode 100755 index 6a2c8d0bd07..73a386e70e0 --- a/drivers/input/misc/akm09911.c +++ b/drivers/input/misc/akm09911.c @@ -2370,7 +2370,7 @@ static struct i2c_driver akm_compass_driver = { static int __init akm_compass_init(void) { - pr_info("AKM compass driver: initialize."); + pr_info("AKM compass driver: initialize.22"); return i2c_add_driver(&akm_compass_driver); } diff --git a/drivers/input/misc/akm09911m.c b/drivers/input/misc/akm09911m.c new file mode 100755 index 00000000000..87c3bbc5e46 --- /dev/null +++ b/drivers/input/misc/akm09911m.c @@ -0,0 +1,2661 @@ +/* drivers/misc/akm09911.c - akm09911 compass driver + * + * Copyright (c) 2014-2015, Linux Foundation. All rights reserved. + * Copyright (C) 2007-2014 HTC Corporation. + * Author: Hou-Kun Chen + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +/*#define DEBUG*/ +/*#define VERBOSE_DEBUG*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AKM_DEBUG_IF 1 +#define AKM_HAS_RESET 1 +#define AKM_INPUT_DEVICE_NAME "compass" +#define AKM_DRDY_TIMEOUT_MS 100 +#define AKM_BASE_NUM 10 + +#define AKM_IS_MAG_DATA_ENABLED() (akm->enable_flag & (1 << MAG_DATA_FLAG)) + +/* POWER SUPPLY VOLTAGE RANGE */ +#define AKM09911_VDD_MIN_UV 2000000 +#define AKM09911_VDD_MAX_UV 3300000 +#define AKM09911_VIO_MIN_UV 1750000 +#define AKM09911_VIO_MAX_UV 1950000 + +#define STATUS_ERROR(st) (((st)&0x08) != 0x0) + +#define AKM09911_RETRY_COUNT 10 + +enum { + AKM09911_AXIS_X = 0, + AKM09911_AXIS_Y, + AKM09911_AXIS_Z, + AKM09911_AXIS_COUNT, +}; + +/* Save last device state for power down */ +struct akm_sensor_state { + bool power_on; + uint8_t mode; +}; + +struct akm_compass_data { + struct i2c_client *i2c; + struct input_dev *input; + struct device *class_dev; + struct class *compass; + struct pinctrl *pinctrl; + struct pinctrl_state *pin_default; + struct pinctrl_state *pin_sleep; + struct sensors_classdev cdev; + struct delayed_work dwork; + struct workqueue_struct *work_queue; + struct mutex op_mutex; + + wait_queue_head_t drdy_wq; + wait_queue_head_t open_wq; + + /* These two buffers are initialized at start up. + After that, the value is not changed */ + uint8_t sense_info[AKM_SENSOR_INFO_SIZE]; + uint8_t sense_conf[AKM_SENSOR_CONF_SIZE]; + + struct mutex sensor_mutex; + uint8_t sense_data[AKM_SENSOR_DATA_SIZE]; + struct mutex accel_mutex; + int16_t accel_data[3]; + + /* Positive value means the device is working. + 0 or negative value means the device is not woking, + i.e. in power-down mode. */ + int8_t is_busy; + + struct mutex val_mutex; + uint32_t enable_flag; + int64_t delay[AKM_NUM_SENSORS]; + + atomic_t active; + atomic_t drdy; + + char layout; + int irq; + int gpio_rstn; + int power_enabled; + int auto_report; + int use_hrtimer; + + /* The input event last time */ + int last_x; + int last_y; + int last_z; + + struct regulator *vdd; + struct regulator *vio; + struct akm_sensor_state state; + struct hrtimer poll_timer; +}; + +static struct sensors_classdev sensors_cdev = { + .name = "akm09911-mag", + .vendor = "Asahi Kasei Microdevices Corporation", + .version = 1, + .handle = SENSORS_MAGNETIC_FIELD_HANDLE, + .type = SENSOR_TYPE_MAGNETIC_FIELD, + .max_range = "1228.8", + .resolution = "0.6", + .sensor_power = "0.35", + .min_delay = 200, + .max_delay = 10000, + .fifo_reserved_event_count = 0, + .fifo_max_event_count = 0, + .enabled = 0, + .delay_msec = 0, + .sensors_enable = NULL, + .sensors_poll_delay = NULL, +}; + +static struct akm_compass_data *s_akm; + +static int akm_compass_power_set(struct akm_compass_data *data, bool on); +/***** I2C I/O function ***********************************************/ +static int akm_i2c_rxdata( + struct i2c_client *i2c, + uint8_t *rxData, + int length) +{ + int ret; + + struct i2c_msg msgs[] = { + { + .addr = i2c->addr, + .flags = 0, + .len = 1, + .buf = rxData, + }, + { + .addr = i2c->addr, + .flags = I2C_M_RD, + .len = length, + .buf = rxData, + }, + }; + uint8_t addr = rxData[0]; + + ret = i2c_transfer(i2c->adapter, msgs, ARRAY_SIZE(msgs)); + if (ret < 0) { + dev_err(&i2c->dev, "%s: transfer failed.", __func__); + return ret; + } else if (ret != ARRAY_SIZE(msgs)) { + dev_err(&i2c->dev, "%s: transfer failed(size error).\n", + __func__); + return -ENXIO; + } + + dev_vdbg(&i2c->dev, "RxData: len=%02x, addr=%02x, data=%02x", + length, addr, rxData[0]); + + return 0; +} + +static int akm_i2c_txdata( + struct i2c_client *i2c, + uint8_t *txData, + int length) +{ + int ret; + + struct i2c_msg msg[] = { + { + .addr = i2c->addr, + .flags = 0, + .len = length, + .buf = txData, + }, + }; + + ret = i2c_transfer(i2c->adapter, msg, ARRAY_SIZE(msg)); + if (ret < 0) { + dev_err(&i2c->dev, "%s: transfer failed.", __func__); + return ret; + } else if (ret != ARRAY_SIZE(msg)) { + dev_err(&i2c->dev, "%s: transfer failed(size error).", + __func__); + return -ENXIO; + } + + dev_vdbg(&i2c->dev, "TxData: len=%02x, addr=%02x data=%02x", + length, txData[0], txData[1]); + + return 0; +} + +/***** akm miscdevice functions *************************************/ +static int AKECS_Set_CNTL( + struct akm_compass_data *akm, + uint8_t mode) +{ + uint8_t buffer[2]; + int err; + + /***** lock *****/ + mutex_lock(&akm->sensor_mutex); + /* Busy check */ + if (akm->is_busy > 0) { + dev_err(&akm->i2c->dev, + "%s: device is busy.", __func__); + err = -EBUSY; + } else { + /* Set measure mode */ + buffer[0] = AKM_REG_MODE; + buffer[1] = mode; + err = akm_i2c_txdata(akm->i2c, buffer, 2); + if (err < 0) { + dev_err(&akm->i2c->dev, + "%s: Can not set CNTL.", __func__); + } else { + dev_vdbg(&akm->i2c->dev, + "Mode is set to (%d).", mode); + /* Set flag */ + akm->is_busy = 1; + atomic_set(&akm->drdy, 0); + /* wait at least 100us after changing mode */ + udelay(100); + } + } + + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + + return err; +} + +static int AKECS_Set_PowerDown( + struct akm_compass_data *akm) +{ + uint8_t buffer[2]; + int err; + + /***** lock *****/ + mutex_lock(&akm->sensor_mutex); + + /* Set powerdown mode */ + buffer[0] = AKM_REG_MODE; + buffer[1] = AKM_MODE_POWERDOWN; + err = akm_i2c_txdata(akm->i2c, buffer, 2); + if (err < 0) { + dev_err(&akm->i2c->dev, + "%s: Can not set to powerdown mode.", __func__); + } else { + dev_dbg(&akm->i2c->dev, "Powerdown mode is set."); + /* wait at least 100us after changing mode */ + udelay(100); + } + /* Clear status */ + akm->is_busy = 0; + atomic_set(&akm->drdy, 0); + + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + + return err; +} + +static int AKECS_Reset( + struct akm_compass_data *akm, + int hard) +{ + int err; + +#if AKM_HAS_RESET + uint8_t buffer[2]; + + /***** lock *****/ + mutex_lock(&akm->sensor_mutex); + + if (hard != 0) { + gpio_set_value(akm->gpio_rstn, 0); + gpio_direction_output(akm->gpio_rstn, 0); + udelay(5); + gpio_set_value(akm->gpio_rstn, 1); + gpio_direction_output(akm->gpio_rstn, 1); + /* No error is returned */ + err = 0; + } else { + buffer[0] = AKM_REG_RESET; + buffer[1] = AKM_RESET_DATA; + err = akm_i2c_txdata(akm->i2c, buffer, 2); + if (err < 0) { + dev_err(&akm->i2c->dev, + "%s: Can not set SRST bit.", __func__); + } else { + dev_dbg(&akm->i2c->dev, "Soft reset is done."); + } + } + /* Device will be accessible 100 us after */ + udelay(100); + /* Clear status */ + akm->is_busy = 0; + atomic_set(&akm->drdy, 0); + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + +#else + err = AKECS_Set_PowerDown(akm); +#endif + + return err; +} + +static int AKECS_SetMode( + struct akm_compass_data *akm, + uint8_t mode) +{ + int err; + + switch (mode & 0x1F) { + case AKM_MODE_SNG_MEASURE: + case AKM_MODE_SELF_TEST: + case AKM_MODE_FUSE_ACCESS: + case AKM_MODE_CONTINUOUS_10HZ: + case AKM_MODE_CONTINUOUS_20HZ: + case AKM_MODE_CONTINUOUS_50HZ: + case AKM_MODE_CONTINUOUS_100HZ: + err = AKECS_Set_CNTL(akm, mode); + break; + case AKM_MODE_POWERDOWN: + err = AKECS_Set_PowerDown(akm); + break; + default: + dev_err(&akm->i2c->dev, + "%s: Unknown mode(%d).", __func__, mode); + return -EINVAL; + } + + return err; +} + +static void AKECS_SetYPR( + struct akm_compass_data *akm, + int *rbuf) +{ + uint32_t ready; + dev_vdbg(&akm->i2c->dev, "%s: flag =0x%X", __func__, rbuf[0]); + dev_vdbg(&akm->input->dev, " Acc [LSB] : %6d,%6d,%6d stat=%d", + rbuf[1], rbuf[2], rbuf[3], rbuf[4]); + dev_vdbg(&akm->input->dev, " Geo [LSB] : %6d,%6d,%6d stat=%d", + rbuf[5], rbuf[6], rbuf[7], rbuf[8]); + dev_vdbg(&akm->input->dev, " Orientation : %6d,%6d,%6d", + rbuf[9], rbuf[10], rbuf[11]); + dev_vdbg(&akm->input->dev, " Rotation V : %6d,%6d,%6d,%6d", + rbuf[12], rbuf[13], rbuf[14], rbuf[15]); + + /* No events are reported */ + if (!rbuf[0]) { + dev_dbg(&akm->i2c->dev, "Don't waste a time."); + return; + } + + mutex_lock(&akm->val_mutex); + ready = (akm->enable_flag & (uint32_t)rbuf[0]); + mutex_unlock(&akm->val_mutex); + + /* Report acceleration sensor information */ + if (ready & ACC_DATA_READY) { + input_report_abs(akm->input, ABS_X, rbuf[1]); + input_report_abs(akm->input, ABS_Y, rbuf[2]); + input_report_abs(akm->input, ABS_Z, rbuf[3]); + input_report_abs(akm->input, ABS_RX, rbuf[4]); + } + /* Report magnetic vector information */ + if (ready & MAG_DATA_READY) { + input_report_abs(akm->input, ABS_X, rbuf[5]); + input_report_abs(akm->input, ABS_Y, rbuf[6]); + input_report_abs(akm->input, ABS_Z, rbuf[7]); + input_report_abs(akm->input, ABS_MISC, rbuf[8]); + } + /* Report fusion sensor information */ + if (ready & FUSION_DATA_READY) { + /* Orientation */ + input_report_abs(akm->input, ABS_HAT0Y, rbuf[9]); + input_report_abs(akm->input, ABS_HAT1X, rbuf[10]); + input_report_abs(akm->input, ABS_HAT1Y, rbuf[11]); + /* Rotation Vector */ + input_report_abs(akm->input, ABS_TILT_X, rbuf[12]); + input_report_abs(akm->input, ABS_TILT_Y, rbuf[13]); + input_report_abs(akm->input, ABS_TOOL_WIDTH, rbuf[14]); + input_report_abs(akm->input, ABS_VOLUME, rbuf[15]); + } + + input_sync(akm->input); +} + +/* This function will block a process until the latest measurement + * data is available. + */ +static int AKECS_GetData( + struct akm_compass_data *akm, + uint8_t *rbuf, + int size) +{ + int err; + + /* Block! */ + err = wait_event_interruptible_timeout( + akm->drdy_wq, + atomic_read(&akm->drdy), + msecs_to_jiffies(AKM_DRDY_TIMEOUT_MS)); + + if (err < 0) { + dev_err(&akm->i2c->dev, + "%s: wait_event failed (%d).", __func__, err); + return err; + } + if (!atomic_read(&akm->drdy)) { + dev_err(&akm->i2c->dev, + "%s: DRDY is not set.", __func__); + return -ENODATA; + } + + /***** lock *****/ + mutex_lock(&akm->sensor_mutex); + + memcpy(rbuf, akm->sense_data, size); + atomic_set(&akm->drdy, 0); + + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + + return 0; +} + +static int AKECS_GetData_Poll( + struct akm_compass_data *akm, + uint8_t *rbuf, + int size) +{ + uint8_t buffer[AKM_SENSOR_DATA_SIZE]; + int err; + + /* Read data */ + buffer[0] = AKM_REG_STATUS; + err = akm_i2c_rxdata(akm->i2c, buffer, AKM_SENSOR_DATA_SIZE); + if (err < 0) { + dev_err(&akm->i2c->dev, "%s failed.", __func__); + return err; + } + + /* Check ST bit */ + if (!(AKM_DRDY_IS_HIGH(buffer[0]))) + dev_dbg(&akm->i2c->dev, "DRDY is low. Use last value.\n"); + + /* Data is over run is */ + if (AKM_DOR_IS_HIGH(buffer[0])) + dev_dbg(&akm->i2c->dev, "Data over run!\n"); + + memcpy(rbuf, buffer, size); + atomic_set(&akm->drdy, 0); + + /***** lock *****/ + mutex_lock(&akm->sensor_mutex); + akm->is_busy = 0; + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + + return 0; +} + +static int AKECS_GetOpenStatus( + struct akm_compass_data *akm) +{ + return wait_event_interruptible( + akm->open_wq, (atomic_read(&akm->active) > 0)); +} + +static int AKECS_GetCloseStatus( + struct akm_compass_data *akm) +{ + return wait_event_interruptible( + akm->open_wq, (atomic_read(&akm->active) <= 0)); +} + +static int AKECS_Open(struct inode *inode, struct file *file) +{ + file->private_data = s_akm; + return nonseekable_open(inode, file); +} + +static int AKECS_Release(struct inode *inode, struct file *file) +{ + return 0; +} + +static long +AKECS_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + void __user *argp = (void __user *)arg; + struct akm_compass_data *akm = file->private_data; + + /* NOTE: In this function the size of "char" should be 1-byte. */ + uint8_t i2c_buf[AKM_RWBUF_SIZE]; /* for READ/WRITE */ + uint8_t dat_buf[AKM_SENSOR_DATA_SIZE];/* for GET_DATA */ + int32_t ypr_buf[AKM_YPR_DATA_SIZE]; /* for SET_YPR */ + int64_t delay[AKM_NUM_SENSORS]; /* for GET_DELAY */ + int16_t acc_buf[3]; /* for GET_ACCEL */ + uint8_t mode; /* for SET_MODE*/ + int status; /* for OPEN/CLOSE_STATUS */ + int ret = 0; /* Return value. */ + + switch (cmd) { + case ECS_IOCTL_READ: + case ECS_IOCTL_WRITE: + if (argp == NULL) { + dev_err(&akm->i2c->dev, "invalid argument."); + return -EINVAL; + } + if (copy_from_user(&i2c_buf, argp, sizeof(i2c_buf))) { + dev_err(&akm->i2c->dev, "copy_from_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_SET_MODE: + if (argp == NULL) { + dev_err(&akm->i2c->dev, "invalid argument."); + return -EINVAL; + } + if (copy_from_user(&mode, argp, sizeof(mode))) { + dev_err(&akm->i2c->dev, "copy_from_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_SET_YPR: + if (argp == NULL) { + dev_err(&akm->i2c->dev, "invalid argument."); + return -EINVAL; + } + if (copy_from_user(&ypr_buf, argp, sizeof(ypr_buf))) { + dev_err(&akm->i2c->dev, "copy_from_user failed."); + return -EFAULT; + } + case ECS_IOCTL_GET_INFO: + case ECS_IOCTL_GET_CONF: + case ECS_IOCTL_GET_DATA: + case ECS_IOCTL_GET_OPEN_STATUS: + case ECS_IOCTL_GET_CLOSE_STATUS: + case ECS_IOCTL_GET_DELAY: + case ECS_IOCTL_GET_LAYOUT: + case ECS_IOCTL_GET_ACCEL: + /* Check buffer pointer for writing a data later. */ + if (argp == NULL) { + dev_err(&akm->i2c->dev, "invalid argument."); + return -EINVAL; + } + break; + default: + break; + } + + switch (cmd) { + case ECS_IOCTL_READ: + dev_vdbg(&akm->i2c->dev, "IOCTL_READ called."); + if ((i2c_buf[0] < 1) || (i2c_buf[0] > (AKM_RWBUF_SIZE-1))) { + dev_err(&akm->i2c->dev, "invalid argument."); + return -EINVAL; + } + ret = akm_i2c_rxdata(akm->i2c, &i2c_buf[1], i2c_buf[0]); + if (ret < 0) + return ret; + break; + case ECS_IOCTL_WRITE: + dev_vdbg(&akm->i2c->dev, "IOCTL_WRITE called."); + if ((i2c_buf[0] < 2) || (i2c_buf[0] > (AKM_RWBUF_SIZE-1))) { + dev_err(&akm->i2c->dev, "invalid argument."); + return -EINVAL; + } + ret = akm_i2c_txdata(akm->i2c, &i2c_buf[1], i2c_buf[0]); + if (ret < 0) + return ret; + break; + case ECS_IOCTL_RESET: + dev_vdbg(&akm->i2c->dev, "IOCTL_RESET called."); + ret = AKECS_Reset(akm, akm->gpio_rstn); + if (ret < 0) + return ret; + break; + case ECS_IOCTL_SET_MODE: + dev_vdbg(&akm->i2c->dev, "IOCTL_SET_MODE called."); + ret = AKECS_SetMode(akm, mode); + if (ret < 0) + return ret; + break; + case ECS_IOCTL_SET_YPR: + dev_vdbg(&akm->i2c->dev, "IOCTL_SET_YPR called."); + AKECS_SetYPR(akm, ypr_buf); + break; + case ECS_IOCTL_GET_DATA: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_DATA called."); + if (akm->irq) + ret = AKECS_GetData(akm, dat_buf, AKM_SENSOR_DATA_SIZE); + else + ret = AKECS_GetData_Poll( + akm, dat_buf, AKM_SENSOR_DATA_SIZE); + + if (ret < 0) + return ret; + break; + case ECS_IOCTL_GET_OPEN_STATUS: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_OPEN_STATUS called."); + ret = AKECS_GetOpenStatus(akm); + if (ret < 0) { + dev_err(&akm->i2c->dev, + "Get Open returns error (%d).", ret); + return ret; + } + break; + case ECS_IOCTL_GET_CLOSE_STATUS: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_CLOSE_STATUS called."); + ret = AKECS_GetCloseStatus(akm); + if (ret < 0) { + dev_err(&akm->i2c->dev, + "Get Close returns error (%d).", ret); + return ret; + } + break; + case ECS_IOCTL_GET_DELAY: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_DELAY called."); + mutex_lock(&akm->val_mutex); + delay[0] = ((akm->enable_flag & ACC_DATA_READY) ? + akm->delay[0] : -1); + delay[1] = ((akm->enable_flag & MAG_DATA_READY) ? + akm->delay[1] : -1); + delay[2] = ((akm->enable_flag & FUSION_DATA_READY) ? + akm->delay[2] : -1); + mutex_unlock(&akm->val_mutex); + break; + case ECS_IOCTL_GET_INFO: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_INFO called."); + break; + case ECS_IOCTL_GET_CONF: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_CONF called."); + break; + case ECS_IOCTL_GET_LAYOUT: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_LAYOUT called."); + break; + case ECS_IOCTL_GET_ACCEL: + dev_vdbg(&akm->i2c->dev, "IOCTL_GET_ACCEL called."); + mutex_lock(&akm->accel_mutex); + acc_buf[0] = akm->accel_data[0]; + acc_buf[1] = akm->accel_data[1]; + acc_buf[2] = akm->accel_data[2]; + mutex_unlock(&akm->accel_mutex); + break; + default: + return -ENOTTY; + } + + switch (cmd) { + case ECS_IOCTL_READ: + /* +1 is for the first byte */ + if (copy_to_user(argp, &i2c_buf, i2c_buf[0]+1)) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_GET_INFO: + if (copy_to_user(argp, &akm->sense_info, + sizeof(akm->sense_info))) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_GET_CONF: + if (copy_to_user(argp, &akm->sense_conf, + sizeof(akm->sense_conf))) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_GET_DATA: + if (copy_to_user(argp, &dat_buf, sizeof(dat_buf))) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_GET_OPEN_STATUS: + case ECS_IOCTL_GET_CLOSE_STATUS: + status = atomic_read(&akm->active); + if (copy_to_user(argp, &status, sizeof(status))) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_GET_DELAY: + if (copy_to_user(argp, &delay, sizeof(delay))) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_GET_LAYOUT: + if (copy_to_user(argp, &akm->layout, sizeof(akm->layout))) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + case ECS_IOCTL_GET_ACCEL: + if (copy_to_user(argp, &acc_buf, sizeof(acc_buf))) { + dev_err(&akm->i2c->dev, "copy_to_user failed."); + return -EFAULT; + } + break; + default: + break; + } + + return 0; +} + +static const struct file_operations AKECS_fops = { + .owner = THIS_MODULE, + .open = AKECS_Open, + .release = AKECS_Release, + .unlocked_ioctl = AKECS_ioctl, +}; + +static struct miscdevice akm_compass_dev = { + .minor = MISC_DYNAMIC_MINOR, + .name = AKM_MISCDEV_NAME, + .fops = &AKECS_fops, +}; + +/***** akm sysfs functions ******************************************/ +static int create_device_attributes( + struct device *dev, + struct device_attribute *attrs) +{ + int i; + int err = 0; + + for (i = 0 ; NULL != attrs[i].attr.name ; ++i) { + err = device_create_file(dev, &attrs[i]); + if (err) + break; + } + + if (err) { + for (--i; i >= 0 ; --i) + device_remove_file(dev, &attrs[i]); + } + + return err; +} + +static void remove_device_attributes( + struct device *dev, + struct device_attribute *attrs) +{ + int i; + + for (i = 0 ; NULL != attrs[i].attr.name ; ++i) + device_remove_file(dev, &attrs[i]); +} + +static int create_device_binary_attributes( + struct kobject *kobj, + struct bin_attribute *attrs) +{ + int i; + int err = 0; + + err = 0; + + for (i = 0 ; NULL != attrs[i].attr.name ; ++i) { + err = sysfs_create_bin_file(kobj, &attrs[i]); + if (0 != err) + break; + } + + if (0 != err) { + for (--i; i >= 0 ; --i) + sysfs_remove_bin_file(kobj, &attrs[i]); + } + + return err; +} + +static void remove_device_binary_attributes( + struct kobject *kobj, + struct bin_attribute *attrs) +{ + int i; + + for (i = 0 ; NULL != attrs[i].attr.name ; ++i) + sysfs_remove_bin_file(kobj, &attrs[i]); +} + +/********************************************************************* + * + * SysFS attribute functions + * + * directory : /sys/class/compass/akmXXXX/ + * files : + * - enable_acc [rw] [t] : enable flag for accelerometer + * - enable_mag [rw] [t] : enable flag for magnetometer + * - enable_fusion [rw] [t] : enable flag for fusion sensor + * - delay_acc [rw] [t] : delay in nanosecond for accelerometer + * - delay_mag [rw] [t] : delay in nanosecond for magnetometer + * - delay_fusion [rw] [t] : delay in nanosecond for fusion sensor + * + * debug : + * - mode [w] [t] : E-Compass mode + * - bdata [r] [t] : buffered raw data + * - asa [r] [t] : FUSEROM data + * - regs [r] [t] : read all registers + * + * [b] = binary format + * [t] = text format + */ + +/***** sysfs enable *************************************************/ +static void akm_compass_sysfs_update_status( + struct akm_compass_data *akm) +{ + uint32_t en; + mutex_lock(&akm->val_mutex); + en = akm->enable_flag; + mutex_unlock(&akm->val_mutex); + + if (en == 0) { + if (atomic_cmpxchg(&akm->active, 1, 0) == 1) { + wake_up(&akm->open_wq); + dev_dbg(akm->class_dev, "Deactivated"); + } + } else { + if (atomic_cmpxchg(&akm->active, 0, 1) == 0) { + wake_up(&akm->open_wq); + dev_dbg(akm->class_dev, "Activated"); + } + } + dev_dbg(&akm->i2c->dev, + "Status updated: enable=0x%X, active=%d", + en, atomic_read(&akm->active)); +} + +static inline uint8_t akm_select_frequency(int64_t delay_ns) +{ + if (delay_ns >= 100000000LL) + return AKM_MODE_CONTINUOUS_10HZ; + else if (delay_ns >= 50000000LL) + return AKM_MODE_CONTINUOUS_20HZ; + else if (delay_ns >= 20000000LL) + return AKM_MODE_CONTINUOUS_50HZ; + else + return AKM_MODE_CONTINUOUS_100HZ; +} + +static int akm_enable_set(struct sensors_classdev *sensors_cdev, + unsigned int enable) +{ + int ret = 0; + struct akm_compass_data *akm = container_of(sensors_cdev, + struct akm_compass_data, cdev); + uint8_t mode; + + mutex_lock(&akm->val_mutex); + akm->enable_flag &= ~(1<enable_flag |= ((uint32_t)(enable))<val_mutex); + + akm_compass_sysfs_update_status(akm); + mutex_lock(&akm->op_mutex); + if (enable) { + ret = akm_compass_power_set(akm, true); + if (ret) { + dev_err(&akm->i2c->dev, + "Fail to power on the device!\n"); + goto exit; + } + + if (akm->auto_report) { + mode = akm_select_frequency(akm->delay[MAG_DATA_FLAG]); + AKECS_SetMode(akm, mode); + if (akm->use_hrtimer) + hrtimer_start(&akm->poll_timer, + ns_to_ktime(akm->delay[MAG_DATA_FLAG]), + HRTIMER_MODE_REL); + else + queue_delayed_work(akm->work_queue, &akm->dwork, + (unsigned long)nsecs_to_jiffies64( + akm->delay[MAG_DATA_FLAG])); + } + } else { + if (akm->auto_report) { + if (akm->use_hrtimer) { + hrtimer_cancel(&akm->poll_timer); + cancel_work_sync(&akm->dwork.work); + } else { + cancel_delayed_work_sync(&akm->dwork); + } + AKECS_SetMode(akm, AKM_MODE_POWERDOWN); + } + ret = akm_compass_power_set(akm, false); + if (ret) { + dev_err(&akm->i2c->dev, + "Fail to power off the device!\n"); + goto exit; + } + } + +exit: + mutex_unlock(&akm->op_mutex); + return ret; +} + +static ssize_t akm_compass_sysfs_enable_show( + struct akm_compass_data *akm, char *buf, int pos) +{ + int flag; + + mutex_lock(&akm->val_mutex); + flag = ((akm->enable_flag >> pos) & 1); + mutex_unlock(&akm->val_mutex); + + return scnprintf(buf, PAGE_SIZE, "%d\n", flag); +} + +static ssize_t akm_compass_sysfs_enable_store( + struct akm_compass_data *akm, char const *buf, size_t count, int pos) +{ + long en = 0; + int ret = 0; + + if (NULL == buf) + return -EINVAL; + + if (0 == count) + return 0; + + if (kstrtol(buf, AKM_BASE_NUM, &en)) + return -EINVAL; + + en = en ? 1 : 0; + + mutex_lock(&akm->op_mutex); + ret = akm_compass_power_set(akm, en); + if (ret) { + dev_err(&akm->i2c->dev, + "Fail to configure device power!\n"); + goto exit; + } + mutex_lock(&akm->val_mutex); + akm->enable_flag &= ~(1<enable_flag |= ((uint32_t)(en))<val_mutex); + + akm_compass_sysfs_update_status(akm); + +exit: + mutex_unlock(&akm->op_mutex); + + return ret ? ret : count; +} + +/***** Acceleration ***/ +static ssize_t akm_enable_acc_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + return akm_compass_sysfs_enable_show( + dev_get_drvdata(dev), buf, ACC_DATA_FLAG); +} +static ssize_t akm_enable_acc_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + return akm_compass_sysfs_enable_store( + dev_get_drvdata(dev), buf, count, ACC_DATA_FLAG); +} + +/***** Magnetic field ***/ +static ssize_t akm_enable_mag_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + return akm_compass_sysfs_enable_show( + dev_get_drvdata(dev), buf, MAG_DATA_FLAG); +} +static ssize_t akm_enable_mag_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + return akm_compass_sysfs_enable_store( + dev_get_drvdata(dev), buf, count, MAG_DATA_FLAG); +} + +/***** Fusion ***/ +static ssize_t akm_enable_fusion_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + return akm_compass_sysfs_enable_show( + dev_get_drvdata(dev), buf, FUSION_DATA_FLAG); +} +static ssize_t akm_enable_fusion_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + return akm_compass_sysfs_enable_store( + dev_get_drvdata(dev), buf, count, FUSION_DATA_FLAG); +} + +/***** sysfs delay **************************************************/ +static int akm_poll_delay_set(struct sensors_classdev *sensors_cdev, + unsigned int delay_msec) +{ + struct akm_compass_data *akm = container_of(sensors_cdev, + struct akm_compass_data, cdev); + uint8_t mode; + int ret; + + mutex_lock(&akm->val_mutex); + + s_akm->delay[MAG_DATA_FLAG] = delay_msec * 1000000; + mode = akm_select_frequency(akm->delay[MAG_DATA_FLAG]); + ret = AKECS_SetMode(akm, mode); + if (ret < 0) + dev_err(&akm->i2c->dev, "Failed to set to mode(%x)\n", mode); + + mutex_unlock(&akm->val_mutex); + return ret; +} + +static ssize_t akm_compass_sysfs_delay_show( + struct akm_compass_data *akm, char *buf, int pos) +{ + int64_t val; + + mutex_lock(&akm->val_mutex); + val = akm->delay[pos]; + mutex_unlock(&akm->val_mutex); + + return scnprintf(buf, PAGE_SIZE, "%lld\n", val); +} + +static ssize_t akm_compass_sysfs_delay_store( + struct akm_compass_data *akm, char const *buf, size_t count, int pos) +{ + long long val = 0; + + if (NULL == buf) + return -EINVAL; + + if (0 == count) + return 0; + + if (kstrtoll(buf, AKM_BASE_NUM, &val)) + return -EINVAL; + + mutex_lock(&akm->val_mutex); + akm->delay[pos] = val; + mutex_unlock(&akm->val_mutex); + + return count; +} + +/*add by eliot shao 2016.8.27 start*/ +static ssize_t akm_compass_sysfs_layout_show( + struct akm_compass_data *akm, char *buf, int pos) +{ + int64_t val; + + mutex_lock(&akm->val_mutex); + val = akm->layout; + mutex_unlock(&akm->val_mutex); + + return scnprintf(buf, PAGE_SIZE, "%lld\n", val); +} + +static ssize_t akm_compass_sysfs_layout_store( + struct akm_compass_data *akm, char const *buf, size_t count, int pos) +{ + long long val = 0; + + if (NULL == buf) + return -EINVAL; + + if (0 == count) + return 0; + + if (kstrtoll(buf, AKM_BASE_NUM, &val)) + return -EINVAL; + + mutex_lock(&akm->val_mutex); + akm->layout = val; + mutex_unlock(&akm->val_mutex); + + return count; +} + +static ssize_t akm_layout_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + return akm_compass_sysfs_layout_show( + dev_get_drvdata(dev), buf, ACC_DATA_FLAG); +} +static ssize_t akm_layout_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + return akm_compass_sysfs_layout_store( + dev_get_drvdata(dev), buf, count, ACC_DATA_FLAG); +} + + +/*add by eliot shao 2016.8.27 end*/ +/***** Accelerometer ***/ +static ssize_t akm_delay_acc_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + return akm_compass_sysfs_delay_show( + dev_get_drvdata(dev), buf, ACC_DATA_FLAG); +} +static ssize_t akm_delay_acc_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + return akm_compass_sysfs_delay_store( + dev_get_drvdata(dev), buf, count, ACC_DATA_FLAG); +} + +/***** Magnetic field ***/ +static ssize_t akm_delay_mag_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + return akm_compass_sysfs_delay_show( + dev_get_drvdata(dev), buf, MAG_DATA_FLAG); +} +static ssize_t akm_delay_mag_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + return akm_compass_sysfs_delay_store( + dev_get_drvdata(dev), buf, count, MAG_DATA_FLAG); +} + +/***** Fusion ***/ +static ssize_t akm_delay_fusion_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + return akm_compass_sysfs_delay_show( + dev_get_drvdata(dev), buf, FUSION_DATA_FLAG); +} +static ssize_t akm_delay_fusion_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + return akm_compass_sysfs_delay_store( + dev_get_drvdata(dev), buf, count, FUSION_DATA_FLAG); +} + +/***** accel (binary) ***/ +static ssize_t akm_bin_accel_write( + struct file *file, + struct kobject *kobj, + struct bin_attribute *attr, + char *buf, + loff_t pos, + size_t size) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct akm_compass_data *akm = dev_get_drvdata(dev); + int16_t *accel_data; + + if (size == 0) + return 0; + + accel_data = (int16_t *)buf; + + mutex_lock(&akm->accel_mutex); + akm->accel_data[0] = accel_data[0]; + akm->accel_data[1] = accel_data[1]; + akm->accel_data[2] = accel_data[2]; + mutex_unlock(&akm->accel_mutex); + + dev_vdbg(&akm->i2c->dev, "accel:%d,%d,%d\n", + accel_data[0], accel_data[1], accel_data[2]); + + return size; +} + + +#if AKM_DEBUG_IF +static ssize_t akm_sysfs_mode_store( + struct device *dev, struct device_attribute *attr, + char const *buf, size_t count) +{ + struct akm_compass_data *akm = dev_get_drvdata(dev); + long mode = 0; + + if (NULL == buf) + return -EINVAL; + + if (0 == count) + return 0; + + if (kstrtol(buf, AKM_BASE_NUM, &mode)) + return -EINVAL; + + if (AKECS_SetMode(akm, (uint8_t)mode) < 0) + return -EINVAL; + + return 1; +} + +static ssize_t akm_buf_print( + char *buf, uint8_t *data, size_t num) +{ + int sz, i; + char *cur; + size_t cur_len; + + cur = buf; + cur_len = PAGE_SIZE; + sz = snprintf(cur, cur_len, "(HEX):"); + if (sz < 0) + return sz; + cur += sz; + cur_len -= sz; + for (i = 0; i < num; i++) { + sz = snprintf(cur, cur_len, "%02X,", *data); + if (sz < 0) + return sz; + cur += sz; + cur_len -= sz; + data++; + } + sz = snprintf(cur, cur_len, "\n"); + if (sz < 0) + return sz; + cur += sz; + + return (ssize_t)(cur - buf); +} + +static ssize_t akm_sysfs_bdata_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + struct akm_compass_data *akm = dev_get_drvdata(dev); + uint8_t rbuf[AKM_SENSOR_DATA_SIZE]; + + mutex_lock(&akm->sensor_mutex); + memcpy(&rbuf, akm->sense_data, sizeof(rbuf)); + mutex_unlock(&akm->sensor_mutex); + + return akm_buf_print(buf, rbuf, AKM_SENSOR_DATA_SIZE); +} + +static ssize_t akm_sysfs_asa_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + struct akm_compass_data *akm = dev_get_drvdata(dev); + int err; + uint8_t asa[3]; + + err = AKECS_SetMode(akm, AKM_MODE_FUSE_ACCESS); + if (err < 0) + return err; + + asa[0] = AKM_FUSE_1ST_ADDR; + err = akm_i2c_rxdata(akm->i2c, asa, 3); + if (err < 0) + return err; + + err = AKECS_SetMode(akm, AKM_MODE_POWERDOWN); + if (err < 0) + return err; + + return akm_buf_print(buf, asa, 3); +} + +static ssize_t akm_sysfs_regs_show( + struct device *dev, struct device_attribute *attr, char *buf) +{ + /* The total number of registers depends on the device. */ + struct akm_compass_data *akm = dev_get_drvdata(dev); + int err; + uint8_t regs[AKM_REGS_SIZE]; + + /* This function does not lock mutex obj */ + regs[0] = AKM_REGS_1ST_ADDR; + err = akm_i2c_rxdata(akm->i2c, regs, AKM_REGS_SIZE); + if (err < 0) + return err; + + return akm_buf_print(buf, regs, AKM_REGS_SIZE); +} +#endif + +static struct device_attribute akm_compass_attributes[] = { + __ATTR(enable_acc, 0660, akm_enable_acc_show, akm_enable_acc_store), + __ATTR(enable_mag, 0660, akm_enable_mag_show, akm_enable_mag_store), + __ATTR(enable_fusion, 0660, akm_enable_fusion_show, + akm_enable_fusion_store), + __ATTR(delay_acc, 0660, akm_delay_acc_show, akm_delay_acc_store), + //add by eliot shao 2016.8.27 sys/class/compass/akm09911/layout_mag + __ATTR(layout_mag, 0660, akm_layout_show, akm_layout_store), + __ATTR(delay_mag, 0660, akm_delay_mag_show, akm_delay_mag_store), + __ATTR(delay_fusion, 0660, akm_delay_fusion_show, + akm_delay_fusion_store), +#if AKM_DEBUG_IF + __ATTR(mode, 0220, NULL, akm_sysfs_mode_store), + __ATTR(bdata, 0440, akm_sysfs_bdata_show, NULL), + __ATTR(asa, 0440, akm_sysfs_asa_show, NULL), + __ATTR(regs, 0440, akm_sysfs_regs_show, NULL), +#endif + __ATTR_NULL, +}; +#ifdef __BIN_ATTR +#undef __BIN_ATTR +#endif + +#define __BIN_ATTR(name_, mode_, size_, private_, read_, write_) \ + { \ + .attr = { .name = __stringify(name_), .mode = mode_ }, \ + .size = size_, \ + .private = private_, \ + .read = read_, \ + .write = write_, \ + } +#ifdef __BIN_ATTR_NULL +#undef __BIN_ATTR_NULL +#endif +#define __BIN_ATTR_NULL \ + { \ + .attr = { .name = NULL }, \ + } + +static struct bin_attribute akm_compass_bin_attributes[] = { + __BIN_ATTR(accel, 0220, 6, NULL, + NULL, akm_bin_accel_write), + __BIN_ATTR_NULL +}; + +static char const *const device_link_name = "i2c"; +static dev_t const akm_compass_device_dev_t = MKDEV(MISC_MAJOR, 240); + +static int create_sysfs_interfaces(struct akm_compass_data *akm) +{ + int err; + + if (NULL == akm) + return -EINVAL; + + err = 0; + + akm->compass = class_create(THIS_MODULE, AKM_SYSCLS_NAME); + if (IS_ERR(akm->compass)) { + err = PTR_ERR(akm->compass); + goto exit_class_create_failed; + } + + akm->class_dev = device_create( + akm->compass, + NULL, + akm_compass_device_dev_t, + akm, + AKM_SYSDEV_NAME); + if (IS_ERR(akm->class_dev)) { + err = PTR_ERR(akm->class_dev); + goto exit_class_device_create_failed; + } + + err = sysfs_create_link( + &akm->class_dev->kobj, + &akm->i2c->dev.kobj, + device_link_name); + if (0 > err) + goto exit_sysfs_create_link_failed; + + err = create_device_attributes( + akm->class_dev, + akm_compass_attributes); + if (0 > err) + goto exit_device_attributes_create_failed; + + err = create_device_binary_attributes( + &akm->class_dev->kobj, + akm_compass_bin_attributes); + if (0 > err) + goto exit_device_binary_attributes_create_failed; + + return err; + +exit_device_binary_attributes_create_failed: + remove_device_attributes(akm->class_dev, akm_compass_attributes); +exit_device_attributes_create_failed: + sysfs_remove_link(&akm->class_dev->kobj, device_link_name); +exit_sysfs_create_link_failed: + device_destroy(akm->compass, akm_compass_device_dev_t); +exit_class_device_create_failed: + akm->class_dev = NULL; + class_destroy(akm->compass); +exit_class_create_failed: + akm->compass = NULL; + return err; +} + +static void remove_sysfs_interfaces(struct akm_compass_data *akm) +{ + if (NULL == akm) + return; + + if (NULL != akm->class_dev) { + remove_device_binary_attributes( + &akm->class_dev->kobj, + akm_compass_bin_attributes); + remove_device_attributes( + akm->class_dev, + akm_compass_attributes); + sysfs_remove_link( + &akm->class_dev->kobj, + device_link_name); + akm->class_dev = NULL; + } + if (NULL != akm->compass) { + device_destroy( + akm->compass, + akm_compass_device_dev_t); + class_destroy(akm->compass); + akm->compass = NULL; + } +} + + +/***** akm input device functions ***********************************/ +static int akm_compass_input_init( + struct input_dev **input) +{ + int err = 0; + + /* Declare input device */ + *input = input_allocate_device(); + if (!*input) + return -ENOMEM; + + /* Setup input device */ + set_bit(EV_ABS, (*input)->evbit); + /* Accelerometer (720 x 16G)*/ + input_set_abs_params(*input, ABS_X, + -11520, 11520, 0, 0); + input_set_abs_params(*input, ABS_Y, + -11520, 11520, 0, 0); + input_set_abs_params(*input, ABS_Z, + -11520, 11520, 0, 0); + input_set_abs_params(*input, ABS_RX, + 0, 3, 0, 0); + /* Magnetic field (limited to 16bit) */ + input_set_abs_params(*input, ABS_RY, + -32768, 32767, 0, 0); + input_set_abs_params(*input, ABS_RZ, + -32768, 32767, 0, 0); + input_set_abs_params(*input, ABS_THROTTLE, + -32768, 32767, 0, 0); + input_set_abs_params(*input, ABS_RUDDER, + 0, 3, 0, 0); + + /* Orientation (degree in Q6 format) */ + /* yaw[0,360) pitch[-180,180) roll[-90,90) */ + input_set_abs_params(*input, ABS_HAT0Y, + 0, 23040, 0, 0); + input_set_abs_params(*input, ABS_HAT1X, + -11520, 11520, 0, 0); + input_set_abs_params(*input, ABS_HAT1Y, + -5760, 5760, 0, 0); + /* Rotation Vector [-1,+1] in Q14 format */ + input_set_abs_params(*input, ABS_TILT_X, + -16384, 16384, 0, 0); + input_set_abs_params(*input, ABS_TILT_Y, + -16384, 16384, 0, 0); + input_set_abs_params(*input, ABS_TOOL_WIDTH, + -16384, 16384, 0, 0); + input_set_abs_params(*input, ABS_VOLUME, + -16384, 16384, 0, 0); + + /* Report the dummy value */ + input_set_abs_params(*input, ABS_MISC, + INT_MIN, INT_MAX, 0, 0); + + /* Set name */ + (*input)->name = AKM_INPUT_DEVICE_NAME; + + /* Register */ + err = input_register_device(*input); + if (err) { + input_free_device(*input); + return err; + } + + return err; +} + +/***** akm functions ************************************************/ +static irqreturn_t akm_compass_irq(int irq, void *handle) +{ + struct akm_compass_data *akm = handle; + uint8_t buffer[AKM_SENSOR_DATA_SIZE]; + int err; + + memset(buffer, 0, sizeof(buffer)); + + /***** lock *****/ + mutex_lock(&akm->sensor_mutex); + + /* Read whole data */ + buffer[0] = AKM_REG_STATUS; + err = akm_i2c_rxdata(akm->i2c, buffer, AKM_SENSOR_DATA_SIZE); + if (err < 0) { + dev_err(&akm->i2c->dev, "IRQ I2C error."); + akm->is_busy = 0; + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + + return IRQ_HANDLED; + } + /* Check ST bit */ + if (!(AKM_DRDY_IS_HIGH(buffer[0]))) + goto work_func_none; + + memcpy(akm->sense_data, buffer, AKM_SENSOR_DATA_SIZE); + akm->is_busy = 0; + + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + + atomic_set(&akm->drdy, 1); + wake_up(&akm->drdy_wq); + + dev_vdbg(&akm->i2c->dev, "IRQ handled."); + return IRQ_HANDLED; + +work_func_none: + mutex_unlock(&akm->sensor_mutex); + /***** unlock *****/ + + dev_vdbg(&akm->i2c->dev, "IRQ not handled."); + return IRQ_NONE; +} + +static int akm_compass_suspend(struct device *dev) +{ + struct akm_compass_data *akm = dev_get_drvdata(dev); + int ret = 0; + + if (AKM_IS_MAG_DATA_ENABLED() && akm->auto_report) { + if (akm->use_hrtimer) + hrtimer_cancel(&akm->poll_timer); + else + cancel_delayed_work_sync(&akm->dwork); + } + + ret = AKECS_SetMode(akm, AKM_MODE_POWERDOWN); + if (ret) + dev_warn(&akm->i2c->dev, "Failed to set to POWERDOWN mode.\n"); + + akm->state.power_on = akm->power_enabled; + if (akm->state.power_on) + akm_compass_power_set(akm, false); + + ret = pinctrl_select_state(akm->pinctrl, akm->pin_sleep); + if (ret) + dev_err(dev, "Can't select pinctrl state\n"); + + dev_dbg(&akm->i2c->dev, "suspended\n"); + + return ret; +} + +static int akm_compass_resume(struct device *dev) +{ + struct akm_compass_data *akm = dev_get_drvdata(dev); + int ret = 0; + uint8_t mode; + + ret = pinctrl_select_state(akm->pinctrl, akm->pin_default); + if (ret) + dev_err(dev, "Can't select pinctrl state\n"); + + if (akm->state.power_on) { + ret = akm_compass_power_set(akm, true); + if (ret) { + dev_err(dev, "Sensor power resume fail!\n"); + goto exit; + } + + if (AKM_IS_MAG_DATA_ENABLED() && akm->auto_report) { + mode = akm_select_frequency(akm->delay[MAG_DATA_FLAG]); + ret = AKECS_SetMode(akm, akm->state.mode); + if (ret < 0) { + dev_err(&akm->i2c->dev, "Failed to set to mode(%d)\n", + mode); + goto exit; + } + if (akm->use_hrtimer) + hrtimer_start(&akm->poll_timer, + ns_to_ktime(akm->delay[MAG_DATA_FLAG]), + HRTIMER_MODE_REL); + else + queue_delayed_work(akm->work_queue, &akm->dwork, + (unsigned long)nsecs_to_jiffies64( + akm->delay[MAG_DATA_FLAG])); + } + } + + dev_dbg(&akm->i2c->dev, "resumed\n"); + +exit: + return ret; +} + +static int akm09911_i2c_check_device( + struct i2c_client *client) +{ + /* AK09911 specific function */ + struct akm_compass_data *akm = i2c_get_clientdata(client); + int err; + + akm->sense_info[0] = AK09911_REG_WIA1; + err = akm_i2c_rxdata(client, akm->sense_info, AKM_SENSOR_INFO_SIZE); + if (err < 0) + return err; + + /* Set FUSE access mode */ + err = AKECS_SetMode(akm, AK09911_MODE_FUSE_ACCESS); + if (err < 0) + return err; + + akm->sense_conf[0] = AK09911_FUSE_ASAX; + err = akm_i2c_rxdata(client, akm->sense_conf, AKM_SENSOR_CONF_SIZE); + if (err < 0) + return err; + + err = AKECS_SetMode(akm, AK09911_MODE_POWERDOWN); + if (err < 0) + return err; + + /* Check read data */ + if ((akm->sense_info[0] != AK09911_WIA1_VALUE) || + (akm->sense_info[1] != AK09911_WIA2_VALUE)){ + dev_err(&client->dev, + "%s: The device is not AKM Compass.", __func__); + return -ENXIO; + } + + return err; +} + +static int akm_compass_power_set(struct akm_compass_data *data, bool on) +{ + int rc = 0; + + if (!on && data->power_enabled) { + rc = regulator_disable(data->vdd); + if (rc) { + dev_err(&data->i2c->dev, + "Regulator vdd disable failed rc=%d\n", rc); + goto err_vdd_disable; + } + + rc = regulator_disable(data->vio); + if (rc) { + dev_err(&data->i2c->dev, + "Regulator vio disable failed rc=%d\n", rc); + goto err_vio_disable; + } + data->power_enabled = false; + return rc; + } else if (on && !data->power_enabled) { + rc = regulator_enable(data->vdd); + if (rc) { + dev_err(&data->i2c->dev, + "Regulator vdd enable failed rc=%d\n", rc); + goto err_vdd_enable; + } + + rc = regulator_enable(data->vio); + if (rc) { + dev_err(&data->i2c->dev, + "Regulator vio enable failed rc=%d\n", rc); + goto err_vio_enable; + } + data->power_enabled = true; + + /* + * The max time for the power supply rise time is 50ms. + * Use 80ms to make sure it meets the requirements. + */ + msleep(80); + return rc; + } else { + dev_warn(&data->i2c->dev, + "Power on=%d. enabled=%d\n", + on, data->power_enabled); + return rc; + } + +err_vio_enable: + regulator_disable(data->vio); +err_vdd_enable: + return rc; + +err_vio_disable: + if (regulator_enable(data->vdd)) + dev_warn(&data->i2c->dev, "Regulator vdd enable failed\n"); +err_vdd_disable: + return rc; +} + +static int akm_compass_power_init(struct akm_compass_data *data, bool on) +{ + int rc; + + if (!on) { + if (regulator_count_voltages(data->vdd) > 0) + regulator_set_voltage(data->vdd, 0, + AKM09911_VDD_MAX_UV); + + regulator_put(data->vdd); + + if (regulator_count_voltages(data->vio) > 0) + regulator_set_voltage(data->vio, 0, + AKM09911_VIO_MAX_UV); + + regulator_put(data->vio); + + } else { + data->vdd = regulator_get(&data->i2c->dev, "vdd"); + if (IS_ERR(data->vdd)) { + rc = PTR_ERR(data->vdd); + dev_err(&data->i2c->dev, + "Regulator get failed vdd rc=%d\n", rc); + return rc; + } + + if (regulator_count_voltages(data->vdd) > 0) { + rc = regulator_set_voltage(data->vdd, + AKM09911_VDD_MIN_UV, AKM09911_VDD_MAX_UV); + if (rc) { + dev_err(&data->i2c->dev, + "Regulator set failed vdd rc=%d\n", + rc); + goto reg_vdd_put; + } + } + + data->vio = regulator_get(&data->i2c->dev, "vio"); + if (IS_ERR(data->vio)) { + rc = PTR_ERR(data->vio); + dev_err(&data->i2c->dev, + "Regulator get failed vio rc=%d\n", rc); + goto reg_vdd_set; + } + + if (regulator_count_voltages(data->vio) > 0) { + rc = regulator_set_voltage(data->vio, + AKM09911_VIO_MIN_UV, AKM09911_VIO_MAX_UV); + if (rc) { + dev_err(&data->i2c->dev, + "Regulator set failed vio rc=%d\n", rc); + goto reg_vio_put; + } + } + } + + return 0; + +reg_vio_put: + regulator_put(data->vio); +reg_vdd_set: + if (regulator_count_voltages(data->vdd) > 0) + regulator_set_voltage(data->vdd, 0, AKM09911_VDD_MAX_UV); +reg_vdd_put: + regulator_put(data->vdd); + return rc; +} + +#ifdef CONFIG_OF +static int akm_compass_parse_dt(struct device *dev, + struct akm_compass_data *akm) +{ + struct device_node *np = dev->of_node; + u32 temp_val; + int rc; + + rc = of_property_read_u32(np, "akm,layout", &temp_val); + if (rc && (rc != -EINVAL)) { + dev_err(dev, "Unable to read akm,layout\n"); + return rc; + } else { + s_akm->layout = temp_val; + } + + akm->auto_report = of_property_read_bool(np, "akm,auto-report"); + akm->use_hrtimer = of_property_read_bool(np, "akm,use-hrtimer"); + rc = of_property_read_u32(np, "akm,poll_interval", &temp_val); + if (rc && (rc != -EINVAL)) { + dev_err(dev, "Unable to read akm,layout\n"); + return rc; + } else + s_akm->delay[MAG_DATA_FLAG] = temp_val * 1000000; + + if (of_property_read_bool(np, "akm,auto-report")) + s_akm->auto_report = 1; + else + s_akm->auto_report = 0; + s_akm->gpio_rstn = of_get_named_gpio_flags(dev->of_node, + "akm,gpio_rstn", 0, NULL); + + if (!gpio_is_valid(s_akm->gpio_rstn)) { + dev_err(dev, "gpio reset pin %d is invalid.\n", + s_akm->gpio_rstn); + return -EINVAL; + } + + return 0; +} +#else +static int akm_compass_parse_dt(struct device *dev, + struct akm_compass_data *akm) +{ + return -EINVAL; +} +#endif /* !CONFIG_OF */ + +static int akm_pinctrl_init(struct akm_compass_data *akm) +{ + struct i2c_client *client = akm->i2c; + + akm->pinctrl = devm_pinctrl_get(&client->dev); + if (IS_ERR_OR_NULL(akm->pinctrl)) { + dev_err(&client->dev, "Failed to get pinctrl\n"); + return PTR_ERR(akm->pinctrl); + } + + akm->pin_default = pinctrl_lookup_state(akm->pinctrl, "default"); + if (IS_ERR_OR_NULL(akm->pin_default)) { + dev_err(&client->dev, "Failed to look up default state\n"); + return PTR_ERR(akm->pin_default); + } + + akm->pin_sleep = pinctrl_lookup_state(akm->pinctrl, "sleep"); + if (IS_ERR_OR_NULL(akm->pin_sleep)) { + dev_err(&client->dev, "Failed to look up sleep state\n"); + return PTR_ERR(akm->pin_sleep); + } + + return 0; +} +#define CALIBRATION_BY_OURSELF 1 +//static int calibrate_xyz[3] = {-13,-28,-80}; +//static int calibrate_xyz[3] = {5,-31,24}; +//static int calibrate_xyz[3] = {12,-23,25}; +//static int calibrate_xyz[3] = {54,40,41}; +//static int calibrate_xyz[3] = {58,78,35}; +//static int calibrate_xyz[3] = {52,39,35}; +//static int calibrate_xyz[3] = {53,67,31}; + +#if CALIBRATION_BY_OURSELF +static int calibrate_xyz[3] = {70,7,-8}; +static int max_xyz[3] = {126,64,50}; +static int min_xyz[3] = {14,-50,-66}; +//static int max_xyz1[3] = {0,0,0}; +//static int min_xyz1[3] = {0,0,0}; +static int range_xyz[3] = {112,114,116}; +static void akm_calibrate_xyz(int *data) +{ + //static bool first_data = 1; + //static bool calibrate_use_defult[3] = {1,1,1}; + int i = 0; + /* + if(first_data) + { + max_xyz1[0] = min_xyz1[0] = data[0]; + max_xyz1[1] = min_xyz1[1] = data[1]; + max_xyz1[2] = min_xyz1[2] = data[2]; + first_data = 0; + //return; + } + */ + for(i = 0;i < 3;i ++) + { + /* + if(max_xyz1[i] < data[i] || min_xyz1[i] > data[i]) + { + if(max_xyz1[i] < data[i]) max_xyz1[i] = data[i]; + else min_xyz1[i] = data[i]; + if(!calibrate_use_defult[i]) + { + if(max_xyz1[i] - min_xyz1[i] - range_xyz[i] > -50) + { + first_data = 0; + calibrate_use_defult[0] = 1; + calibrate_use_defult[1] = 1; + calibrate_use_defult[2] = 1; + return; + } + calibrate_xyz[i] = (max_xyz1[i] + min_xyz1[i]) / 2; + } + } + */ + //if(calibrate_use_defult[i]) + //{ + if(max_xyz[i] < data[i] || min_xyz[i] > data[i]) + { + if(max_xyz[i] < data[i]) + { + max_xyz[i] = data[i]; + min_xyz[i] = max_xyz[i] - range_xyz[i]; + } + else + { + min_xyz[i] = data[i]; + max_xyz[i] = min_xyz[i] + range_xyz[i]; + } + calibrate_xyz[i] = (max_xyz[i] + min_xyz[i]) / 2; + } + /* + if(max_xyz1[i] - min_xyz1[i] - range_xyz[i] > -80) + { + calibrate_xyz[i] = (max_xyz1[i] + min_xyz1[i]) / 2; + calibrate_use_defult[i] = 0; + } + */ + //} + } + /* + if(max_xyz[0] < data[0] || min_xyz[0] > data[0]) + { + if(max_xyz[0] < data[0]) + { + max_xyz[0] = data[0]; + min_xyz[0] = max_xyz[0] - range_xyz[0]; + } + else + { + min_xyz[0] = data[0]; + max_xyz[0] = min_xyz[0] + range_xyz[0]; + } + calibrate_xyz[0] = (max_xyz[0] + min_xyz[0])/2; + } + if(max_xyz[1] < data[1] || min_xyz[1] > data[1]) + { + if(max_xyz[1] < data[1]) + { + max_xyz[1] = data[1]; + min_xyz[1] = max_xyz[1] - range_xyz[1]; + } + else + { + min_xyz[1] = data[1]; + max_xyz[1] = min_xyz[1] + range_xyz[1]; + } + calibrate_xyz[1] = (max_xyz[1] + min_xyz[1])/2; + } + if(max_xyz[2] < data[2] || min_xyz[2] > data[2]) + { + if(max_xyz[2] < data[2]) + { + max_xyz[2] = data[2]; + min_xyz[2] = max_xyz[2] - range_xyz[2]; + } + else + { + min_xyz[2] = data[2]; + max_xyz[2] = min_xyz[2] + range_xyz[2]; + } + calibrate_xyz[2] = (max_xyz[2] + min_xyz[2])/2; + } + */ + return; +} +#endif +static int akm_report_data(struct akm_compass_data *akm) +{ + uint8_t dat_buf[AKM_SENSOR_DATA_SIZE];/* for GET_DATA */ + int ret; + int mag_x, mag_y, mag_z; + int tmp; + int count = 10; + ktime_t timestamp; +#if CALIBRATION_BY_OURSELF + int data[3] = {0}; + int i,j,temp_max,temp_min; + static int pre_data[5][3] = {{0}}; + static int cnt = 0; +#endif + + do { + /* The typical time for single measurement is 7.2ms */ + ret = AKECS_GetData_Poll(akm, dat_buf, AKM_SENSOR_DATA_SIZE); + if (ret == -EAGAIN) + usleep_range(1000, 10000); + } while ((ret == -EAGAIN) && (--count)); + if (!count) { + dev_err(&akm->i2c->dev, "Timeout get valid data.\n"); + return -EIO; + } + + tmp = dat_buf[0] | dat_buf[8]; + if (STATUS_ERROR(tmp)) { + dev_warn(&s_akm->i2c->dev, "Status error(0x%x). Reset...\n", + tmp); + AKECS_Reset(akm, 0); + return -EIO; + } + + timestamp = ktime_get_boottime(); + ///////////////////////////////////////////////////////////////////////////// +#if CALIBRATION_BY_OURSELF + //data[0] = (int)((int16_t)(dat_buf[2]<<8)+((int16_t)dat_buf[1])); + //data[1] = (int)((int16_t)(dat_buf[4]<<8)+((int16_t)dat_buf[3])); + //data[2] = (int)((int16_t)(dat_buf[6]<<8)+((int16_t)dat_buf[5])); + //mag_x = data[0] - calibrate_xyz[0]; + //mag_y = data[1] - calibrate_xyz[1]; + //mag_z = data[2] - calibrate_xyz[2]; + //akm_calibrate_xyz(data); + data[0] = (int)((int16_t)(dat_buf[2]<<8)+((int16_t)dat_buf[1])); + data[1] = (int)((int16_t)(dat_buf[4]<<8)+((int16_t)dat_buf[3])); + data[2] = (int)((int16_t)(dat_buf[6]<<8)+((int16_t)dat_buf[5])); + akm_calibrate_xyz(data); + pre_data[cnt][0] = data[0] - calibrate_xyz[0]; + pre_data[cnt][1] = data[1] - calibrate_xyz[1]; + pre_data[cnt][2] = data[2] - calibrate_xyz[2]; + cnt ++; + cnt %= 5; + for(j = 0;j < 3;j ++) + { + temp_max = temp_min = pre_data[0][j]; + for(i = 1;i < 5;i ++) + { + if(pre_data[i][j] > temp_max) temp_max = pre_data[i][j]; + else if(pre_data[i][j] < temp_min) temp_min = pre_data[i][j]; + } + //data[j] = pre_data[0][j] + pre_data[1][j] + pre_data[2][j] + pre_data[3][j] + pre_data[4][j] - temp_max - temp_min; + } + //akm_calibrate_xyz(data); + mag_x = data[0]; + mag_y = data[1]; + mag_z = -data[2]; + //pr_err("%d:%d:%d\n",mag_x,mag_y,mag_y); + //orientation[0] = (float) Math.atan2((mGeomagnetic[0]*mGravity[1] - mGeomagnetic[1]*mGravity[0]) , (mGeomagnetic[2]*mGravity[1] - mGeomagnetic[1]*mGravity[2])); + //pr_err("%d,%d,%d %d,%d,%d %d,%d,%d\n",calibrate_xyz[0],calibrate_xyz[1],calibrate_xyz[2],max_xyz[0],max_xyz[1],max_xyz[2],min_xyz[0],min_xyz[1],min_xyz[2]); + //pr_err("%d:%s:===mag_x = %d,mag_y = %d,mag_z = %d\n\n",__LINE__,__func__,mag_x,mag_y,mag_y); +#else + tmp = (int)((int16_t)(dat_buf[2]<<8)+((int16_t)dat_buf[1])); + tmp = tmp * akm->sense_conf[0] / 128 + tmp; + mag_x = tmp; + + tmp = (int)((int16_t)(dat_buf[4]<<8)+((int16_t)dat_buf[3])); + tmp = tmp * akm->sense_conf[1] / 128 + tmp; + mag_y = tmp; + + tmp = (int)((int16_t)(dat_buf[6]<<8)+((int16_t)dat_buf[5])); + tmp = tmp * akm->sense_conf[2] / 128 + tmp; + mag_z = tmp; +#endif +//////////////////////////////////////////////////////////////////////////////// + + dev_dbg(&s_akm->i2c->dev, "mag_x:%d mag_y:%d mag_z:%d\n", + mag_x, mag_y, mag_z); + dev_dbg(&s_akm->i2c->dev, "raw data: %d %d %d %d %d %d %d %d\n", + dat_buf[0], dat_buf[1], dat_buf[2], dat_buf[3], + dat_buf[4], dat_buf[5], dat_buf[6], dat_buf[7]); + dev_dbg(&s_akm->i2c->dev, "asa: %d %d %d\n", akm->sense_conf[0], + akm->sense_conf[1], akm->sense_conf[2]); + + switch (akm->layout) { + case 0: + case 1: + /* Fall into the default direction */ + break; + case 2: + tmp = mag_x; + mag_x = mag_y; + mag_y = -tmp; + break; + case 3: + mag_x = -mag_x; + mag_y = -mag_y; + break; + case 4: + tmp = mag_x; + mag_x = -mag_y; + mag_y = tmp; + break; + case 5: + mag_x = -mag_x; + mag_z = -mag_z; + break; + case 6: + tmp = mag_x; + mag_x = mag_y; + mag_y = tmp; + mag_z = -mag_z; + break; + case 7: + mag_y = -mag_y; + mag_z = -mag_z; + break; + case 8: + tmp = mag_x; + mag_x = -mag_y; + mag_y = -tmp; + mag_z = -mag_z; + break; + } + + input_report_abs(akm->input, ABS_X, mag_x); + input_report_abs(akm->input, ABS_Y, mag_y); + input_report_abs(akm->input, ABS_Z, mag_z); + input_event(akm->input, + EV_SYN, SYN_TIME_SEC, + ktime_to_timespec(timestamp).tv_sec); + input_event(akm->input, + EV_SYN, SYN_TIME_NSEC, + ktime_to_timespec(timestamp).tv_nsec); + + akm->last_x = mag_x; + akm->last_y = mag_y; + akm->last_z = mag_z; + input_sync(akm->input); + + return 0; +} + +static void akm_dev_poll(struct work_struct *work) +{ + struct akm_compass_data *akm; + int ret; + + akm = container_of((struct delayed_work *)work, + struct akm_compass_data, dwork); + + ret = akm_report_data(akm); + if (ret < 0) + dev_warn(&s_akm->i2c->dev, "Failed to report data\n"); + + if (!akm->use_hrtimer) + queue_delayed_work(akm->work_queue, &akm->dwork, + (unsigned long)nsecs_to_jiffies64( + akm->delay[MAG_DATA_FLAG])); +} + +static enum hrtimer_restart akm_timer_func(struct hrtimer *timer) +{ + struct akm_compass_data *akm; + + akm = container_of(timer, struct akm_compass_data, poll_timer); + + queue_work(akm->work_queue, &akm->dwork.work); + hrtimer_forward_now(&akm->poll_timer, + ns_to_ktime(akm->delay[MAG_DATA_FLAG])); + + return HRTIMER_RESTART; +} + +static int case_test(struct akm_compass_data *akm, const char test_name[], + const int testdata, const int lo_limit, const int hi_limit, + int *fail_total) +{ + /* Pass:0, Fail:-1 */ + int result = 0; + + if (fail_total == NULL) + return -EINVAL; + + if (strcmp(test_name, "START") == 0) { + dev_dbg(&akm->i2c->dev, "----------------------------------------------------------\n"); + dev_dbg(&akm->i2c->dev, "Test Name Fail Test Data [ Low High]\n"); + dev_dbg(&akm->i2c->dev, "----------------------------------------------------------\n"); + } else if (strcmp(test_name, "END") == 0) { + dev_dbg(&akm->i2c->dev, "----------------------------------------------------------\n"); + if (*fail_total == 0) + dev_dbg(&akm->i2c->dev, "Factory shipment test passed.\n\n"); + else + dev_dbg(&akm->i2c->dev, "%d test cases failed.\n\n", + *fail_total); + } else { + if ((testdata < lo_limit) || (testdata > hi_limit)) { + result = -1; + *fail_total += 1; + } + + dev_dbg(&akm->i2c->dev, " %-10s %c %9d [%9d %9d]\n", + test_name, ((result == 0) ? ('.') : ('F')), + testdata, lo_limit, hi_limit); + } + + return result; +} + +static int akm_self_test(struct sensors_classdev *sensors_cdev) +{ + struct akm_compass_data *akm = container_of(sensors_cdev, + struct akm_compass_data, cdev); + uint8_t i2c_data[AKM_SENSOR_DATA_SIZE]; + int hdata[AKM09911_AXIS_COUNT]; + int asax, asay, asaz; + int count; + int ret; + int fail_total = 0; + uint8_t mode; + bool power_enabled = akm->power_enabled ? true : false; + + mutex_lock(&akm->op_mutex); + + asax = akm->sense_conf[AKM09911_AXIS_X]; + asay = akm->sense_conf[AKM09911_AXIS_Y]; + asaz = akm->sense_conf[AKM09911_AXIS_Z]; + + if (!power_enabled) { + ret = akm_compass_power_set(akm, true); + if (ret) { + dev_err(&akm->i2c->dev, "Power up failed.\n"); + goto exit; + } + } else { + i2c_data[0] = AKM_REG_MODE; + ret = akm_i2c_rxdata(akm->i2c, i2c_data, 1); + if (ret < 0) { + dev_err(&akm->i2c->dev, "Get mode failed.\n"); + goto exit; + } + mode = i2c_data[1]; + } + + ret = AKECS_Reset(akm, 0); + if (ret < 0) { + dev_err(&akm->i2c->dev, "Reset failed.\n"); + goto exit; + } + + /* start test */ + case_test(akm, "START", 0, 0, 0, &fail_total); + + case_test(akm, TLIMIT_TN_ASAX_09911, asax, TLIMIT_LO_ASAX_09911, + TLIMIT_HI_ASAX_09911, &fail_total); + case_test(akm, TLIMIT_TN_ASAY_09911, asay, TLIMIT_LO_ASAY_09911, + TLIMIT_HI_ASAY_09911, &fail_total); + case_test(akm, TLIMIT_TN_ASAZ_09911, asaz, TLIMIT_LO_ASAZ_09911, + TLIMIT_HI_ASAZ_09911, &fail_total); + + ret = AKECS_SetMode(akm, AK09911_MODE_SNG_MEASURE); + if (ret < 0) { + dev_err(&akm->i2c->dev, "Set to single measurement failed.\n"); + goto exit; + } + + count = AKM09911_RETRY_COUNT; + do { + /* The typical time for single measurement is 7.2ms */ + ret = AKECS_GetData_Poll(akm, i2c_data, AKM_SENSOR_DATA_SIZE); + if (ret == -EAGAIN) + usleep_range(1000, 10000); + } while ((ret == -EAGAIN) && (--count)); + + if (!count) { + dev_err(&akm->i2c->dev, "Timeout get valid data.\n"); + goto exit; + } + + hdata[AKM09911_AXIS_X] = (s16)(i2c_data[1] | (i2c_data[2] << 8)); + hdata[AKM09911_AXIS_Y] = (s16)(i2c_data[3] | (i2c_data[4] << 8)); + hdata[AKM09911_AXIS_Z] = (s16)(i2c_data[5] | (i2c_data[6] << 8)); + + i2c_data[0] &= 0x7F; + case_test(akm, TLIMIT_TN_SNG_ST1_09911, + (int)i2c_data[0], TLIMIT_LO_SNG_ST1_09911, + TLIMIT_HI_SNG_ST1_09911, &fail_total); + + case_test(akm, TLIMIT_TN_SNG_HX_09911, hdata[0], TLIMIT_LO_SNG_HX_09911, + TLIMIT_HI_SNG_HX_09911, &fail_total); + case_test(akm, TLIMIT_TN_SNG_HY_09911, hdata[1], TLIMIT_LO_SNG_HY_09911, + TLIMIT_HI_SNG_HY_09911, &fail_total); + case_test(akm, TLIMIT_TN_SNG_HZ_09911, hdata[2], TLIMIT_LO_SNG_HZ_09911, + TLIMIT_HI_SNG_HZ_09911, &fail_total); + + case_test(akm, TLIMIT_TN_SNG_ST2_09911, (int)i2c_data[8], + TLIMIT_LO_SNG_ST2_09911, TLIMIT_HI_SNG_ST2_09911, + &fail_total); + + /* self-test mode */ + ret = AKECS_SetMode(akm, AK09911_MODE_SELF_TEST); + if (ret < 0) { + dev_err(&akm->i2c->dev, "Set to self test mode failed\n"); + goto exit; + } + + count = AKM09911_RETRY_COUNT; + do { + /* The typical time for single measurement is 7.2ms */ + ret = AKECS_GetData_Poll(akm, i2c_data, AKM_SENSOR_DATA_SIZE); + if (ret == -EAGAIN) + usleep_range(1000, 10000); + } while ((ret == -EAGAIN) && (--count)); + + if (!count) { + dev_err(&akm->i2c->dev, "Timeout get valid data.\n"); + goto exit; + } + + i2c_data[0] &= 0x7F; + + case_test(akm, TLIMIT_TN_SLF_ST1_09911, (int)i2c_data[0], + TLIMIT_LO_SLF_ST1_09911, TLIMIT_HI_SLF_ST1_09911, + &fail_total); + + hdata[AKM09911_AXIS_X] = (s16)(i2c_data[1] | (i2c_data[2] << 8)); + hdata[AKM09911_AXIS_Y] = (s16)(i2c_data[3] | (i2c_data[4] << 8)); + hdata[AKM09911_AXIS_Z] = (s16)(i2c_data[5] | (i2c_data[6] << 8)); + + case_test(akm, TLIMIT_TN_SLF_RVHX_09911, (hdata[0])*(asax/128 + 1), + TLIMIT_LO_SLF_RVHX_09911, TLIMIT_HI_SLF_RVHX_09911, + &fail_total); + + case_test(akm, TLIMIT_TN_SLF_RVHY_09911, (hdata[1])*(asay/128 + 1), + TLIMIT_LO_SLF_RVHY_09911, TLIMIT_HI_SLF_RVHY_09911, + &fail_total); + + case_test(akm, TLIMIT_TN_SLF_RVHZ_09911, (hdata[2])*(asaz/128 + 1), + TLIMIT_LO_SLF_RVHZ_09911, TLIMIT_HI_SLF_RVHZ_09911, + &fail_total); + + case_test(akm, TLIMIT_TN_SLF_ST2_09911, (int)i2c_data[8], + TLIMIT_LO_SLF_ST2_09911, TLIMIT_HI_SLF_ST2_09911, + &fail_total); + + case_test(akm, "END", 0, 0, 0, &fail_total); + /* clean up */ + if (!power_enabled) { + ret = akm_compass_power_set(akm, false); + if (ret) { + dev_err(&akm->i2c->dev, "Power down failed.\n"); + goto exit; + } + } else { + /* Set measure mode */ + i2c_data[0] = AKM_REG_MODE; + i2c_data[1] = mode; + ret = akm_i2c_txdata(akm->i2c, i2c_data, 2); + if (ret < 0) { + dev_err(&akm->i2c->dev, "restore mode failed\n"); + goto exit; + } + } + +exit: + mutex_unlock(&akm->op_mutex); + return ((fail_total > 0) || ret) ? -EIO : 0; +} + +static int akm_compass_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + struct akm09911_platform_data *pdata; + int err = 0; + int i; + printk(KERN_ERR"=====================ak,akm09911=================\n"); + dev_dbg(&client->dev, "start probing."); + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(&client->dev, + "%s: check_functionality failed.", __func__); + err = -ENODEV; + goto exit0; + } + + /* Allocate memory for driver data */ + s_akm = kzalloc(sizeof(struct akm_compass_data), GFP_KERNEL); + if (!s_akm) { + dev_err(&client->dev, + "%s: memory allocation failed.", __func__); + err = -ENOMEM; + goto exit1; + } + + /**** initialize variables in akm_compass_data *****/ + init_waitqueue_head(&s_akm->drdy_wq); + init_waitqueue_head(&s_akm->open_wq); + + mutex_init(&s_akm->sensor_mutex); + mutex_init(&s_akm->accel_mutex); + mutex_init(&s_akm->val_mutex); + mutex_init(&s_akm->op_mutex); + + atomic_set(&s_akm->active, 0); + atomic_set(&s_akm->drdy, 0); + + s_akm->is_busy = 0; + s_akm->enable_flag = 0; + + /* Set to 1G in Android coordination, AKSC format */ + s_akm->accel_data[0] = 0; + s_akm->accel_data[1] = 0; + s_akm->accel_data[2] = 720; + + for (i = 0; i < AKM_NUM_SENSORS; i++) + s_akm->delay[i] = -1; + + if (client->dev.of_node) { + err = akm_compass_parse_dt(&client->dev, s_akm); + if (err) { + dev_err(&client->dev, + "Unable to parse platfrom data err=%d\n", err); + goto exit2; + } + } else { + if (client->dev.platform_data) { + /* Copy platform data to local. */ + pdata = client->dev.platform_data; + s_akm->layout = pdata->layout; + s_akm->gpio_rstn = pdata->gpio_RSTN; + } else { + /* Platform data is not available. + Layout and information should be set by each application. */ + s_akm->layout = 0; + s_akm->gpio_rstn = 0; + dev_warn(&client->dev, "%s: No platform data.", + __func__); + } + } + + /***** I2C initialization *****/ + s_akm->i2c = client; + /* set client data */ + i2c_set_clientdata(client, s_akm); + /* request GPIO */ + err = gpio_request(s_akm->gpio_rstn, "akm_rsrn"); + if (err) { + printk("gpio reset request fail\n"); + goto exit2; + } + /* initialize pinctrl */ + if (!akm_pinctrl_init(s_akm)) { + err = pinctrl_select_state(s_akm->pinctrl, s_akm->pin_default); + if (err) { + dev_err(&client->dev, "Can't select pinctrl state\n"); + goto exit2; + } + } + + /* Pull up the reset pin */ + AKECS_Reset(s_akm, 1); + dev_err(&client->dev, "AKECS_Reset@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + + /* check connection */ + err = akm_compass_power_init(s_akm, 1); + if (err < 0) + goto exit2; + err = akm_compass_power_set(s_akm, 1); + if (err < 0) + goto exit3; + + err = akm09911_i2c_check_device(client); + if (err < 0) + goto exit4; + + /***** input *****/ + err = akm_compass_input_init(&s_akm->input); + if (err) { + dev_err(&client->dev, + "%s: input_dev register failed", __func__); + goto exit4; + } + input_set_drvdata(s_akm->input, s_akm); + + /***** IRQ setup *****/ + s_akm->irq = client->irq; + + dev_dbg(&client->dev, "%s: IRQ is #%d.", + __func__, s_akm->irq); + + if (s_akm->irq) { + err = request_threaded_irq( + s_akm->irq, + NULL, + akm_compass_irq, + IRQF_TRIGGER_HIGH|IRQF_ONESHOT, + dev_name(&client->dev), + s_akm); + if (err < 0) { + dev_err(&client->dev, + "%s: request irq failed.", __func__); + goto exit5; + } + } else if (s_akm->auto_report) { + if (s_akm->use_hrtimer) { + hrtimer_init(&s_akm->poll_timer, CLOCK_MONOTONIC, + HRTIMER_MODE_REL); + s_akm->poll_timer.function = akm_timer_func; + s_akm->work_queue = alloc_workqueue("akm_poll_work", + WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI, 1); + INIT_WORK(&s_akm->dwork.work, akm_dev_poll); + } else { + s_akm->work_queue = alloc_workqueue("akm_poll_work", + /*WQ_NON_REENTRANT*/WQ_FREEZABLE, 0); + INIT_DELAYED_WORK(&s_akm->dwork, akm_dev_poll); + } + } + + /***** misc *****/ + err = misc_register(&akm_compass_dev); + if (err) { + dev_err(&client->dev, + "%s: akm_compass_dev register failed", __func__); + goto exit6; + } + + /***** sysfs *****/ + err = create_sysfs_interfaces(s_akm); + if (0 > err) { + dev_err(&client->dev, + "%s: create sysfs failed.", __func__); + goto exit7; + } + + s_akm->cdev = sensors_cdev; + s_akm->cdev.sensors_enable = akm_enable_set; + s_akm->cdev.sensors_poll_delay = akm_poll_delay_set; + s_akm->cdev.sensors_self_test = akm_self_test; +/* + s_akm->delay[MAG_DATA_FLAG] = sensors_cdev.delay_msec * 1000000; +*/ + err = sensors_classdev_register(&s_akm->input->dev, &s_akm->cdev); + + if (err) { + dev_err(&client->dev, "class device create failed: %d\n", err); + goto exit8; + } + + akm_compass_power_set(s_akm, false); + + dev_info(&client->dev, "successfully probed."); + return 0; + +exit8: + remove_sysfs_interfaces(s_akm); +exit7: + misc_deregister(&akm_compass_dev); +exit6: + if (s_akm->irq) + free_irq(s_akm->irq, s_akm); +exit5: + input_unregister_device(s_akm->input); +exit4: + akm_compass_power_set(s_akm, 0); +exit3: + akm_compass_power_init(s_akm, 0); +exit2: + kfree(s_akm); +exit1: +exit0: + return err; +} + +static int akm_compass_remove(struct i2c_client *client) +{ + struct akm_compass_data *akm = i2c_get_clientdata(client); + + if (akm->auto_report) { + if (akm->use_hrtimer) { + hrtimer_cancel(&akm->poll_timer); + cancel_work_sync(&akm->dwork.work); + } else { + cancel_delayed_work_sync(&akm->dwork); + } + destroy_workqueue(akm->work_queue); + } + + if (akm_compass_power_set(akm, 0)) + dev_err(&client->dev, "power set failed."); + if (akm_compass_power_init(akm, 0)) + dev_err(&client->dev, "power deinit failed."); + remove_sysfs_interfaces(akm); + sensors_classdev_unregister(&akm->cdev); + if (misc_deregister(&akm_compass_dev) < 0) + dev_err(&client->dev, "misc deregister failed."); + if (akm->irq) + free_irq(akm->irq, akm); + input_unregister_device(akm->input); + kfree(akm); + dev_info(&client->dev, "successfully removed."); + return 0; +} + +static const struct i2c_device_id akm_compass_id[] = { + {AKM_I2C_NAME, 0 }, + { } +}; + +static const struct dev_pm_ops akm_compass_pm_ops = { + .suspend = akm_compass_suspend, + .resume = akm_compass_resume, +}; + +static struct of_device_id akm09911_match_table[] = { + { .compatible = "ak,ak09911", }, +// { .compatible = "akm,akm09911", }, + { }, +}; + +static struct i2c_driver akm_compass_driver = { + .probe = akm_compass_probe, + .remove = akm_compass_remove, + .id_table = akm_compass_id, + .driver = { + .name = AKM_I2C_NAME, + .owner = THIS_MODULE, + .of_match_table = akm09911_match_table, + .pm = &akm_compass_pm_ops, + }, +}; + +static int __init akm_compass_init(void) +{ + pr_info("AKM compass driver: initialize1111111."); + return i2c_add_driver(&akm_compass_driver); +} + +static void __exit akm_compass_exit(void) +{ + pr_info("AKM compass driver: release."); + i2c_del_driver(&akm_compass_driver); +} + +module_init(akm_compass_init); +module_exit(akm_compass_exit); + +MODULE_AUTHOR("viral wang "); +MODULE_DESCRIPTION("AKM compass driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/input/misc/bmi160.c b/drivers/input/misc/bmi160.c new file mode 100755 index 00000000000..286b975a2a1 --- /dev/null +++ b/drivers/input/misc/bmi160.c @@ -0,0 +1,18752 @@ +/* +* @section LICENSE + * (C) Copyright 2011~2016 Bosch Sensortec GmbH 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 bmi160.c +* @Date: 2015/04/02 +* @id "2e89046" +* @Revision: 2.0.9 $ +* +* Usage: Sensor Driver for BMI160 sensor +* +**************************************************************************** +* \section Disclaimer +* +* Common: +* Bosch Sensortec products are developed for the consumer goods industry. +* They may only be used within the parameters of the respective valid +* product data sheet. Bosch Sensortec products are provided with the +* express understanding that there is no warranty of fitness for a +* particular purpose.They are not fit for use in life-sustaining, +* safety or security sensitive systems or any system or device +* that may lead to bodily harm or property damage if the system +* or device malfunctions. In addition,Bosch Sensortec products are +* not fit for use in products which interact with motor vehicle systems. +* The resale and or use of products are at the purchasers own risk and +* his own responsibility. The examination of fitness for the intended use +* is the sole responsibility of the Purchaser. +* +* The purchaser shall indemnify Bosch Sensortec from all third party +* claims, including any claims for incidental, or consequential damages, +* arising from any product use not covered by the parameters of +* the respective valid product data sheet or not approved by +* Bosch Sensortec and reimburse Bosch Sensortec for all costs in +* connection with such claims. +* +* The purchaser must monitor the market for the purchased products, +* particularly with regard to product safety and inform Bosch Sensortec +* without delay of all security relevant incidents. +* +* Engineering Samples are marked with an asterisk (*) or (e). +* Samples may vary from the valid technical specifications of the product +* series. They are therefore 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 product series. Bosch Sensortec assumes +* no liability for the use of engineering samples. +* By accepting the engineering samples, the Purchaser agrees to indemnify +* Bosch Sensortec from all claims arising from the use of engineering +* samples. +* +* Special: +* 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. +* The Software and Information is subject to the following +* terms and conditions: +* +* 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. +* No license is granted by implication or otherwise under any patent or +* patent rights of Bosch. Specifications mentioned in the Information are +* subject to change without notice. +**************************************************************************/ +/*! file + brief */ +#include "bmi160.h" +#include + +/* user defined code to be added here ... */ +struct bmi160_t *p_bmi160; +/* 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 = BMI160_INIT_VALUE; +/* used for reading the AKM compensating data */ +struct bst_akm_sensitivity_data_t akm_asa_data; +/* Assign the fifo time */ +u32 V_fifo_time_U32 = BMI160_INIT_VALUE; + +/* FIFO data read for 1024 bytes of data */ +u8 v_fifo_data_u8[FIFO_FRAME] = {BMI160_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 bmi160 : structure pointer + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * @note + * While changing the parameter of the bmi160_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) + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_init(struct bmi160_t *bmi160) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + u8 v_pmu_data_u8 = BMI160_INIT_VALUE; + /* assign bmi160 ptr */ + p_bmi160 = bmi160; + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_CHIP_ID__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* read Chip Id */ + p_bmi160->chip_id = v_data_u8; + /* To avoid gyro wakeup it is required to write 0x00 to 0x6C*/ + com_rslt += bmi160_write_reg(BMI160_USER_PMU_TRIGGER_ADDR, + &v_pmu_data_u8, BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_write_reg(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write data from register*/ + com_rslt = + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_reg(u8 v_addr_u8, +u8 *v_data_u8, u8 v_len_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* Read data from register*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fatal_err(u8 +*v_fatal_err_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* reading the fatal error status*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FATAL_ERR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fatal_err_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_err_code(u8 +*v_err_code_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ERR_CODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_err_code_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_fail_err(u8 +*v_i2c_err_code_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_I2C_FAIL_ERR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_err_code_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_drop_cmd_err(u8 +*v_drop_cmd_err_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_DROP_CMD_ERR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_drop_cmd_err_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_dada_rdy_err( +u8 *v_mag_data_rdy_err_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_MAG_DADA_RDY_ERR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_data_rdy_err_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the error codes*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ERR_STAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* fatal error*/ + *v_fatal_er_u8r = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_FATAL_ERR); + /* user error*/ + *v_err_code_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_ERR_CODE); + /* i2c fail error*/ + *v_i2c_fail_err_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_I2C_FAIL_ERR); + /* drop command error*/ + *v_drop_cmd_err_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_DROP_CMD_ERR); + /* mag data ready error*/ + *v_mag_data_rdy_err_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 "bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_power_mode_stat(u8 +*v_mag_power_mode_stat_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_POWER_MODE_STAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_power_mode_stat_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 "bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_power_mode_stat(u8 +*v_gyro_power_mode_stat_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_GYRO_POWER_MODE_STAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_power_mode_stat_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 "bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_power_mode_stat(u8 +*v_accel_power_mode_stat_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_POWER_MODE_STAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_power_mode_stat_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_interface_normal(void) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + /* aim to check the result of switching mag normal */ + u8 v_try_times_u8 = BMI160_MAG_NOAMRL_SWITCH_TIMES; + u8 v_mag_pum_status_u8 = BMI160_INIT_VALUE; + + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt = bmi160_set_command_register(MAG_MODE_NORMAL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + while (v_try_times_u8) { + com_rslt = bmi160_get_mag_power_mode_stat(&v_mag_pum_status_u8); + if (v_mag_pum_status_u8 == MAG_INTERFACE_PMU_ENABLE) + break; + p_bmi160->delay_msec(BMI160_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_BMI160_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 bmi160_set_mag_output_data_rate() + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_x(s16 *v_mag_x_s16, +u8 v_sensor_select_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_MAG_X_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_DATA_MAG_X_LSB__REG, + v_data_u8, BMI160_MAG_X_DATA_LENGTH); + /* X axis*/ + v_data_u8[BMI160_MAG_X_LSB_BYTE] = + BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_X_LSB_BYTE], + BMI160_USER_DATA_MAG_X_LSB); + *v_mag_x_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_MAG_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[BMI160_MAG_X_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_0_MAG_X_LSB__REG, + v_data_u8, BMI160_MAG_X_DATA_LENGTH); + *v_mag_x_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_MAG_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_MAG_X_LSB_BYTE])); + break; + default: + com_rslt = E_BMI160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_y(s16 *v_mag_y_s16, +u8 v_sensor_select_u8) +{ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_MAG_Y_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_DATA_MAG_Y_LSB__REG, + v_data_u8, BMI160_MAG_Y_DATA_LENGTH); + /*Y-axis lsb value shifting*/ + v_data_u8[BMI160_MAG_Y_LSB_BYTE] = + BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_Y_LSB_BYTE], + BMI160_USER_DATA_MAG_Y_LSB); + *v_mag_y_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_MAG_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[BMI160_MAG_Y_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_DATA_2_MAG_Y_LSB__REG, + v_data_u8, BMI160_MAG_Y_DATA_LENGTH); + *v_mag_y_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_MAG_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_MAG_Y_LSB_BYTE])); + break; + default: + com_rslt = E_BMI160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_z(s16 *v_mag_z_s16, +u8 v_sensor_select_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_MAG_Z_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_DATA_MAG_Z_LSB__REG, + v_data_u8, BMI160_MAG_Z_DATA_LENGTH); + /*Z-axis lsb value shifting*/ + v_data_u8[BMI160_MAG_Z_LSB_BYTE] = + BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_Z_LSB_BYTE], + BMI160_USER_DATA_MAG_Z_LSB); + *v_mag_z_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_MAG_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_07_BITS) | + (v_data_u8[BMI160_MAG_Z_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_DATA_4_MAG_Z_LSB__REG, + v_data_u8, BMI160_MAG_Z_DATA_LENGTH); + *v_mag_z_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_MAG_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | ( + v_data_u8[BMI160_MAG_Z_LSB_BYTE])); + break; + default: + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_r(s16 *v_mag_r_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_MAG_R_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_6_RHALL_LSB__REG, + v_data_u8, BMI160_MAG_R_DATA_LENGTH); + /*R-axis lsb value shifting*/ + v_data_u8[BMI160_MAG_R_LSB_BYTE] = + BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_R_LSB_BYTE], + BMI160_USER_DATA_MAG_R_LSB); + *v_mag_r_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_MAG_R_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) | + (v_data_u8[BMI160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyz( +struct bmi160_mag_t *mag, u8 v_sensor_select_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_MAG_XYZ_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_sensor_select_u8) { + case BST_BMM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_DATA_MAG_X_LSB__REG, + v_data_u8, BMI160_MAG_XYZ_DATA_LENGTH); + /*X-axis lsb value shifting*/ + v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE] = + BMI160_GET_BITSLICE( + v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE], + BMI160_USER_DATA_MAG_X_LSB); + /* Data X */ + mag->x = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE])); + /* Data Y */ + /*Y-axis lsb value shifting*/ + v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE] = + BMI160_GET_BITSLICE( + v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE], + BMI160_USER_DATA_MAG_Y_LSB); + mag->y = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) | + (v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE])); + + /* Data Z */ + /*Z-axis lsb value shifting*/ + v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE] + = BMI160_GET_BITSLICE( + v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE], + BMI160_USER_DATA_MAG_Z_LSB); + mag->z = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_07_BITS) | + (v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE])); + break; + case BST_AKM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_0_MAG_X_LSB__REG, + v_data_u8, BMI160_MAG_XYZ_DATA_LENGTH); + /* Data X */ + mag->x = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE])); + /* Data Y */ + mag->y = ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE])); + /* Data Z */ + mag->z = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE])); + break; + default: + com_rslt = E_BMI160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyzr( +struct bmi160_mag_xyzr_t *mag) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8[BMI160_MAG_XYZR_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_MAG_X_LSB__REG, + v_data_u8, BMI160_MAG_XYZR_DATA_LENGTH); + + /* Data X */ + /*X-axis lsb value shifting*/ + v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE] + = BMI160_GET_BITSLICE( + v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE], + BMI160_USER_DATA_MAG_X_LSB); + mag->x = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) + | (v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE])); + /* Data Y */ + /*Y-axis lsb value shifting*/ + v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE] + = BMI160_GET_BITSLICE( + v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE], + BMI160_USER_DATA_MAG_Y_LSB); + mag->y = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) + | (v_data_u8[ + BMI160_DATA_FRAME_MAG_Y_LSB_BYTE])); + + /* Data Z */ + /*Z-axis lsb value shifting*/ + v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE] + = BMI160_GET_BITSLICE( + v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE], + BMI160_USER_DATA_MAG_Z_LSB); + mag->z = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_07_BITS) + | (v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE])); + + /* RHall */ + /*R-axis lsb value shifting*/ + v_data_u8[BMI160_DATA_FRAME_MAG_R_LSB_BYTE] + = BMI160_GET_BITSLICE( + v_data_u8[BMI160_DATA_FRAME_MAG_R_LSB_BYTE], + BMI160_USER_DATA_MAG_R_LSB); + mag->r = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_MAG_R_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) + | (v_data_u8[BMI160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_x(s16 *v_gyro_x_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_GYRO_X_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_8_GYRO_X_LSB__REG, + v_data_u8, BMI160_GYRO_DATA_LENGTH); + + *v_gyro_x_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_GYRO_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error result of communication routines + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_y(s16 *v_gyro_y_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_GYRO_Y_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro y data*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_10_GYRO_Y_LSB__REG, + v_data_u8, BMI160_GYRO_DATA_LENGTH); + + *v_gyro_y_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_GYRO_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_z(s16 *v_gyro_z_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_GYRO_Z_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro z data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_12_GYRO_Z_LSB__REG, + v_data_u8, BMI160_GYRO_DATA_LENGTH); + + *v_gyro_z_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_GYRO_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_xyz(struct bmi160_gyro_t *gyro) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_GYRO_XYZ_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the gyro xyz data*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_8_GYRO_X_LSB__REG, + v_data_u8, BMI160_GYRO_XYZ_DATA_LENGTH); + + /* Data X */ + gyro->x = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_GYRO_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_DATA_FRAME_GYRO_X_LSB_BYTE])); + /* Data Y */ + gyro->y = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_GYRO_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_DATA_FRAME_GYRO_Y_LSB_BYTE])); + + /* Data Z */ + gyro->z = (s16) + ((((s32)((s8)v_data_u8[ + BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_x(s16 *v_accel_x_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_ACCEL_X_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_14_ACCEL_X_LSB__REG, + v_data_u8, BMI160_ACCEL_DATA_LENGTH); + + *v_accel_x_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_ACCEL_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_y(s16 *v_accel_y_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_ACCEL_Y_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_16_ACCEL_Y_LSB__REG, + v_data_u8, BMI160_ACCEL_DATA_LENGTH); + + *v_accel_y_s16 = (s16) + ((((s32)((s8)v_data_u8[BMI160_ACCEL_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (v_data_u8[BMI160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_z(s16 *v_accel_z_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_ACCEL_Z_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_18_ACCEL_Z_LSB__REG, + a_data_u8r, BMI160_ACCEL_DATA_LENGTH); + + *v_accel_z_s16 = (s16) + ((((s32)((s8)a_data_u8r[BMI160_ACCEL_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[BMI160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_xyz( +struct bmi160_accel_t *accel) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_ACCEL_XYZ_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_14_ACCEL_X_LSB__REG, + a_data_u8r, BMI160_ACCEL_XYZ_DATA_LENGTH); + + /* Data X */ + accel->x = (s16) + ((((s32)((s8)a_data_u8r[ + BMI160_DATA_FRAME_ACCEL_X_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_X_LSB_BYTE])); + /* Data Y */ + accel->y = (s16) + ((((s32)((s8)a_data_u8r[ + BMI160_DATA_FRAME_ACCEL_Y_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_Y_LSB_BYTE])); + + /* Data Z */ + accel->z = (s16) + ((((s32)((s8)a_data_u8r[ + BMI160_DATA_FRAME_ACCEL_Z_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_sensor_time(u32 *v_sensor_time_u32) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_SENSOR_TIME_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_SENSORTIME_0_SENSOR_TIME_LSB__REG, + a_data_u8r, BMI160_SENSOR_TIME_LENGTH); + + *v_sensor_time_u32 = (u32) + ((((u32)a_data_u8r[BMI160_SENSOR_TIME_MSB_BYTE]) + << BMI160_SHIFT_BIT_POSITION_BY_16_BITS) + |(((u32)a_data_u8r[BMI160_SENSOR_TIME_XLSB_BYTE]) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_selftest(u8 +*v_gyro_selftest_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STAT_GYRO_SELFTEST_OK__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_selftest_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_manual_operation_stat(u8 +*v_mag_manual_stat_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read manual operation*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STAT_MAG_MANUAL_OPERATION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_manual_stat_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_rdy(u8 +*v_foc_rdy_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the FOC status*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STAT_FOC_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_nvm_rdy(u8 +*v_nvm_rdy_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the nvm ready status*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STAT_NVM_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_nvm_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_data_rdy_mag(u8 +*v_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STAT_DATA_RDY_MAG__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_data_rdy(u8 +*v_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STAT_DATA_RDY_GYRO__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_data_rdy(u8 +*v_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /*reads the status of accel data ready*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STAT_DATA_RDY_ACCEL__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_step_intr(u8 +*v_step_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_STEP_INTR__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_step_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_significant_intr(u8 +*v_significant_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_significant_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_any_motion_intr(u8 +*v_any_motion_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_ANY_MOTION__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_pmu_trigger_intr(u8 +*v_pmu_trigger_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_PMU_TRIGGER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_pmu_trigger_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_set_intr_double_tap() + * @note AXIS MAPPING + * @note bmi160_get_stat2_tap_first_x() + * @note bmi160_get_stat2_tap_first_y() + * @note bmi160_get_stat2_tap_first_z() + * @note DURATION + * @note bmi160_set_intr_tap_durn() + * @note THRESHOLD + * @note bmi160_set_intr_tap_thres() + * @note TAP QUIET + * @note bmi160_set_intr_tap_quiet() + * @note TAP SHOCK + * @note bmi160_set_intr_tap_shock() + * @note TAP SOURCE + * @note bmi160_set_intr_tap_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_double_tap_intr(u8 +*v_double_tap_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_double_tap_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_set_intr_single_tap() + * @note AXIS MAPPING + * @note bmi160_get_stat2_tap_first_x() + * @note bmi160_get_stat2_tap_first_y() + * @note bmi160_get_stat2_tap_first_z() + * @note DURATION + * @note bmi160_set_intr_tap_durn() + * @note THRESHOLD + * @note bmi160_set_intr_tap_thres() + * @note TAP QUIET + * @note bmi160_set_intr_tap_quiet() + * @note TAP SHOCK + * @note bmi160_set_intr_tap_shock() + * @note TAP SOURCE + * @note bmi160_set_intr_tap_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_single_tap_intr(u8 +*v_single_tap_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_single_tap_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_get_stat0_orient_intr() + * @note AXIS MAPPING + * @note bmi160_get_stat3_orient_xy() + * @note bmi160_get_stat3_orient_z() + * @note bmi160_set_intr_orient_axes_enable() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_orient() + * @note INTERRUPT OUTPUT + * @note bmi160_set_intr_orient_ud_enable() + * @note THETA + * @note bmi160_set_intr_orient_theta() + * @note HYSTERESIS + * @note bmi160_set_intr_orient_hyst() + * @note BLOCKING + * @note bmi160_set_intr_orient_blocking() + * @note MODE + * @note bmi160_set_intr_orient_mode() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_orient_intr(u8 +*v_orient_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_ORIENT__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_get_stat0_flat_intr() + * @note bmi160_get_stat3_flat() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_flat() + * @note THETA + * @note bmi160_set_intr_flat_theta() + * @note HOLD TIME + * @note bmi160_set_intr_flat_hold() + * @note HYSTERESIS + * @note bmi160_set_intr_flat_hyst() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_flat_intr(u8 +*v_flat_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_0_FLAT__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_get_stat1_high_g_intr() + * @note AXIS MAPPING + * @note bmi160_get_stat3_high_g_first_x() + * @note bmi160_get_stat3_high_g_first_y() + * @note bmi160_get_stat3_high_g_first_z() + * @note SIGN MAPPING + * @note bmi160_get_stat3_high_g_first_sign() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_high_g() + * @note HYSTERESIS + * @note bmi160_set_intr_high_g_hyst() + * @note DURATION + * @note bmi160_set_intr_high_g_durn() + * @note THRESHOLD + * @note bmi160_set_intr_high_g_thres() + * @note SOURCE + * @note bmi160_set_intr_low_high_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_high_g_intr(u8 +*v_high_g_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_1_HIGH_G_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_get_stat1_low_g_intr() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_low_g() + * @note SOURCE + * @note bmi160_set_intr_low_high_source() + * @note DURATION + * @note bmi160_set_intr_low_g_durn() + * @note THRESHOLD + * @note bmi160_set_intr_low_g_thres() + * @note HYSTERESIS + * @note bmi160_set_intr_low_g_hyst() + * @note MODE + * @note bmi160_set_intr_low_g_mode() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_low_g_intr(u8 +*v_low_g_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_1_LOW_G_INTR__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_get_stat1_data_rdy_intr() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_data_rdy() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_data_rdy_intr(u8 +*v_data_rdy_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_1_DATA_RDY_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_data_rdy_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_set_intr_fifo_full() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_fifo_full_intr(u8 +*v_fifo_full_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_full_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_set_intr_fifo_wm() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_fifo_wm_intr(u8 +*v_fifo_wm_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_1_FIFO_WM_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_wm_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 bmi160_get_stat1_nomotion_intr() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_nomotion() + * @note DURATION + * @note bmi160_set_intr_slow_no_motion_durn() + * @note THRESHOLD + * @note bmi160_set_intr_slow_no_motion_thres() + * @note SLOW/NO MOTION SELECT + * @note bmi160_set_intr_slow_no_motion_select() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_nomotion_intr(u8 +*v_nomotion_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the no motion interrupt*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_1_NOMOTION_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_nomotion_intr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_x(u8 +*v_anymotion_first_x_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the any motion first x interrupt*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_anymotion_first_x_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_y(u8 +*v_any_motion_first_y_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the any motion first y interrupt*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_first_y_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_z(u8 +*v_any_motion_first_z_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the any motion first z interrupt*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_first_z_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_sign(u8 +*v_anymotion_sign_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read any motion sign interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_anymotion_sign_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_x(u8 +*v_tap_first_x_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap first x interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_TAP_FIRST_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_first_x_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_y(u8 +*v_tap_first_y_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap first y interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_TAP_FIRST_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_first_y_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_z(u8 +*v_tap_first_z_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap first z interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_TAP_FIRST_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_first_z_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_sign(u8 +*v_tap_sign_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap_sign interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_2_TAP_SIGN__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_sign_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_x(u8 +*v_high_g_first_x_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read highg_x interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_first_x_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_y(u8 +*v_high_g_first_y_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read highg_y interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_first_y_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_z(u8 +*v_high_g_first_z_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read highg_z interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_first_z_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_sign(u8 +*v_high_g_sign_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read highg_sign interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_3_HIGH_G_SIGN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_sign_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_orient_xy(u8 +*v_orient_xy_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read orient plane xy interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_3_ORIENT_XY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_xy_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_orient_z(u8 +*v_orient_z_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read orient z plane interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_3_ORIENT_Z__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_z_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_flat(u8 +*v_flat_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read flat interrupt status */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_INTR_STAT_3_FLAT__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_temp(s16 +*v_temp_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* Array contains the temperature lSB and MSB data + v_data_u8[0] - LSB + v_data_u8[1] - MSB*/ + u8 v_data_u8[BMI160_TEMP_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read temperature data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_TEMP_LSB_VALUE__REG, v_data_u8, + BMI160_TEMP_DATA_LENGTH); + *v_temp_s16 = + (s16)(((s32)((s8) (v_data_u8[BMI160_TEMP_MSB_BYTE]) << + BMI160_SHIFT_BIT_POSITION_BY_08_BITS)) + | v_data_u8[BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_fifo_length(u32 *v_fifo_length_u32) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* Array contains the fifo length data + v_data_u8[0] - fifo length + v_data_u8[1] - fifo length*/ + u8 a_data_u8r[BMI160_FIFO_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read fifo length*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_BYTE_COUNTER_LSB__REG, a_data_u8r, + BMI160_FIFO_DATA_LENGTH); + + a_data_u8r[BMI160_FIFO_LENGTH_MSB_BYTE] = + BMI160_GET_BITSLICE( + a_data_u8r[BMI160_FIFO_LENGTH_MSB_BYTE], + BMI160_USER_FIFO_BYTE_COUNTER_MSB); + + *v_fifo_length_u32 = + (u32)(((u32)((u8) ( + a_data_u8r[BMI160_FIFO_LENGTH_MSB_BYTE]) << + BMI160_SHIFT_BIT_POSITION_BY_08_BITS)) + | a_data_u8r[BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_fifo_data( +u8 *v_fifodata_u8, u16 v_fifo_length_u16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read fifo data*/ + com_rslt = + p_bmi160->BMI160_BURST_READ_FUNC(p_bmi160->dev_addr, + BMI160_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 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED + * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ + * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ + * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ + * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ + * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ + * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ + * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ + * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ + * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ + * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ + * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ + * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_output_data_rate( +u8 *v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel output data rate*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_output_data_rate_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED + * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ + * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ + * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ + * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ + * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ + * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ + * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ + * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ + * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ + * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ + * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ + * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_output_data_rate( +u8 v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* accel output data rate selection */ + if ((v_output_data_rate_u8 != BMI160_INIT_VALUE) && + (v_output_data_rate_u8 <= BMI160_MAX_ACCEL_OUTPUT_DATA_RATE)) { + /* write accel output data rate */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE, + v_output_data_rate_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * "BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_bw(u8 *v_bw_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel bandwidth */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_bw_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * "BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_bw(u8 v_bw_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* select accel bandwidth*/ + if (v_bw_u8 <= BMI160_MAX_ACCEL_BW) { + /* write accel bandwidth*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_ACCEL_CONFIG_ACCEL_BW, + v_bw_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_under_sampling_parameter( +u8 *v_accel_under_sampling_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel under sampling parameter */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_under_sampling_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_under_sampling_parameter( +u8 v_accel_under_sampling_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_accel_under_sampling_u8 <= BMI160_MAX_UNDER_SAMPLING) { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + /* write the accel under sampling parameter */ + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING, + v_accel_under_sampling_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_ACCEL_RANGE_2G + * 0x05 | BMI160_ACCEL_RANGE_4G + * 0x08 | BMI160_ACCEL_RANGE_8G + * 0x0C | BMI160_ACCEL_RANGE_16G + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_range( +u8 *v_range_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel range*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_RANGE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_range_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_ACCEL_RANGE_2G + * 0x05 | BMI160_ACCEL_RANGE_4G + * 0x08 | BMI160_ACCEL_RANGE_8G + * 0x0C | BMI160_ACCEL_RANGE_16G + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_range(u8 v_range_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if ((v_range_u8 == BMI160_ACCEL_RANGE0) || + (v_range_u8 == BMI160_ACCEL_RANGE1) || + (v_range_u8 == BMI160_ACCEL_RANGE3) || + (v_range_u8 == BMI160_ACCEL_RANGE4)) { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_ACCEL_RANGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE( + v_data_u8, BMI160_USER_ACCEL_RANGE, + v_range_u8); + /* write the accel range*/ + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_RANGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ + * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ + * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ + * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ + * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ + * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ + * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ + * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ + * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_output_data_rate( +u8 *v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the gyro output data rate*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_output_data_rate_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ + * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ + * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ + * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ + * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ + * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ + * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ + * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ + * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_output_data_rate( +u8 v_output_data_rate_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* select the gyro output data rate*/ + if ((v_output_data_rate_u8 < BMI160_OUTPUT_DATA_RATE6) && + (v_output_data_rate_u8 != BMI160_INIT_VALUE) + && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE1) + && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE2) + && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE3) + && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE4) + && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE5) + && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE6) + && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE7)) { + /* write the gyro output data rate */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE, + v_output_data_rate_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_GYRO_OSR4_MODE + * 0x01 | BMI160_GYRO_OSR2_MODE + * 0x02 | BMI160_GYRO_NORMAL_MODE + * 0x03 | BMI160_GYRO_CIC_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_bw(u8 *v_bw_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro bandwidth*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_GYRO_CONFIG_BW__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_bw_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_GYRO_OSR4_MODE + * 0x01 | BMI160_GYRO_OSR2_MODE + * 0x02 | BMI160_GYRO_NORMAL_MODE + * 0x03 | BMI160_GYRO_CIC_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_bw(u8 v_bw_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_bw_u8 <= BMI160_MAX_GYRO_BW) { + /* write the gyro bandwidth*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_GYRO_CONFIG_BW__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_CONFIG_BW, v_bw_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_CONFIG_BW__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_GYRO_RANGE_2000_DEG_SEC + * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC + * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC + * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC + * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_range(u8 *v_range_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the gyro range */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_GYRO_RANGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_range_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_GYRO_RANGE_2000_DEG_SEC + * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC + * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC + * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC + * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_range(u8 v_range_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_range_u8 <= BMI160_MAX_GYRO_RANGE) { + /* write the gyro range value */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_GYRO_RANGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_RANGE, + v_range_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_GYRO_RANGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED + * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ + * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ + * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ + * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ + * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ + * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ + * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ + * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ + * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ + * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ + * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ + * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ + * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0 + * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1 + * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2 + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_output_data_rate( +u8 *v_output_data_rat_u8e) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the mag data output rate*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_output_data_rat_u8e = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED + * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ + * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ + * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ + * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ + * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ + * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ + * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ + * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ + * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ + * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ + * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ + * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ + * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0 + * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1 + * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2 + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_output_data_rate( +u8 v_output_data_rat_u8e) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* select the mag data output rate*/ + if ((v_output_data_rat_u8e + <= BMI160_MAX_ACCEL_OUTPUT_DATA_RATE) + && (v_output_data_rat_u8e + != BMI160_OUTPUT_DATA_RATE0) + && (v_output_data_rat_u8e + != BMI160_OUTPUT_DATA_RATE6) + && (v_output_data_rat_u8e + != BMI160_OUTPUT_DATA_RATE7)) { + /* write the mag data output rate*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE, + v_output_data_rat_u8e); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_down_gyro( +u8 *v_fifo_down_gyro_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the gyro fifo down*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_DOWN_GYRO__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_down_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_down_gyro( +u8 v_fifo_down_gyro_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the gyro fifo down*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_DOWN_GYRO__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE( + v_data_u8, + BMI160_USER_FIFO_DOWN_GYRO, + v_fifo_down_gyro_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_DOWN_GYRO__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_fifo_filter_data( +u8 *v_gyro_fifo_filter_data_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the gyro fifo filter data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_FILTER_GYRO__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_fifo_filter_data_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_fifo_filter_data( +u8 v_gyro_fifo_filter_data_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_gyro_fifo_filter_data_u8 + <= BMI160_MAX_VALUE_FIFO_FILTER) { + /* write the gyro fifo filter data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_FILTER_GYRO__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE( + v_data_u8, + BMI160_USER_FIFO_FILTER_GYRO, + v_gyro_fifo_filter_data_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_FILTER_GYRO__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_down_accel( +u8 *v_fifo_down_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel fifo down data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_down_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_down_accel( +u8 v_fifo_down_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the accel fifo down data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_DOWN_ACCEL, v_fifo_down_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_DOWN_ACCEL__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_fifo_filter_data( +u8 *v_accel_fifo_filter_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel fifo filter data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_FILTER_ACCEL__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_fifo_filter_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_fifo_filter_data( +u8 v_accel_fifo_filter_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_accel_fifo_filter_u8 <= BMI160_MAX_VALUE_FIFO_FILTER) { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_FILTER_ACCEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + /* write accel fifo filter data */ + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_FILTER_ACCEL, + v_accel_fifo_filter_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_FILTER_ACCEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_wm( +u8 *v_fifo_wm_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the fifo water mark level*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_WM__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_wm_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_wm( +u8 v_fifo_wm_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the fifo water mark level*/ + com_rslt = + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_WM__REG, + &v_fifo_wm_u8, BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_time_enable( +u8 *v_fifo_time_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the fifo sensor time*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_TIME_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_time_enable_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_time_enable( +u8 v_fifo_time_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_fifo_time_enable_u8 <= BMI160_MAX_VALUE_FIFO_TIME) { + /* write the fifo sensor time*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_TIME_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_TIME_ENABLE, + v_fifo_time_enable_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_TIME_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_tag_intr2_enable( +u8 *v_fifo_tag_intr2_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the fifo tag interrupt2*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_tag_intr2_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_tag_intr2_enable( +u8 v_fifo_tag_intr2_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_fifo_tag_intr2_u8 <= BMI160_MAX_VALUE_FIFO_INTR) { + /* write the fifo tag interrupt2*/ + com_rslt = bmi160_set_input_enable(1, + v_fifo_tag_intr2_u8); + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_TAG_INTR2_ENABLE, + v_fifo_tag_intr2_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_tag_intr1_enable( +u8 *v_fifo_tag_intr1_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read fifo tag interrupt*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_tag_intr1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_tag_intr1_enable( +u8 v_fifo_tag_intr1_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_fifo_tag_intr1_u8 <= BMI160_MAX_VALUE_FIFO_INTR) { + /* write the fifo tag interrupt*/ + com_rslt = bmi160_set_input_enable(BMI160_INIT_VALUE, + v_fifo_tag_intr1_u8); + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_TAG_INTR1_ENABLE, + v_fifo_tag_intr1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_header_enable( +u8 *v_fifo_header_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read fifo header */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_header_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_header_enable( +u8 v_fifo_header_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_fifo_header_u8 <= BMI160_MAX_VALUE_FIFO_HEADER) { + /* write the fifo header */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_HEADER_ENABLE, + v_fifo_header_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_HEADER_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_mag_enable( +u8 *v_fifo_mag_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the fifo mag enable*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_MAG_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_mag_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_mag_enable( +u8 v_fifo_mag_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_fifo_mag_u8 <= BMI160_MAX_VALUE_FIFO_MAG) { + /* write the fifo mag enable*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FIFO_MAG_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_MAG_ENABLE, + v_fifo_mag_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FIFO_MAG_ENABLE__REG, + &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_accel_enable( +u8 *v_fifo_accel_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel fifo enable*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_accel_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_accel_enable( +u8 v_fifo_accel_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_fifo_accel_u8 <= BMI160_MAX_VALUE_FIFO_ACCEL) { + /* write the fifo mag enables*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_ACCEL_ENABLE, v_fifo_accel_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_ACCEL_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_gyro_enable( +u8 *v_fifo_gyro_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read fifo gyro enable */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_fifo_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_gyro_enable( +u8 v_fifo_gyro_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_fifo_gyro_u8 <= BMI160_MAX_VALUE_FIFO_GYRO) { + /* write fifo gyro enable*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FIFO_GYRO_ENABLE, v_fifo_gyro_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FIFO_GYRO_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_device_addr( +u8 *v_i2c_device_addr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the mag I2C device address*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_I2C_DEVICE_ADDR__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_device_addr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_device_addr( +u8 v_i2c_device_addr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the mag I2C device address*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_I2C_DEVICE_ADDR__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_I2C_DEVICE_ADDR, + v_i2c_device_addr_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_I2C_DEVICE_ADDR__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_burst( +u8 *v_mag_burst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read mag burst mode length*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_BURST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_burst_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_burst( +u8 v_mag_burst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write mag burst mode length*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_BURST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_MAG_BURST, v_mag_burst_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_MAG_BURST__REG, &v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_offset( +u8 *v_mag_offset_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_OFFSET__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_offset_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_offset( +u8 v_mag_offset_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_OFFSET__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_MAG_OFFSET, v_mag_offset_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_OFFSET__REG, + &v_data_u8, BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_manual_enable( +u8 *v_mag_manual_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read mag manual */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_manual_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_manual_enable( +u8 v_mag_manual_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the mag manual*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + if (com_rslt == SUCCESS) { + /* set the bit of mag manual enable*/ + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_MAG_MANUAL_ENABLE, v_mag_manual_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr, + BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + if (com_rslt == SUCCESS) + p_bmi160->mag_manual_enable = v_mag_manual_u8; + else + p_bmi160->mag_manual_enable = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_read_addr( +u8 *v_mag_read_addr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the written address*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_READ_ADDR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_read_addr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_read_addr( +u8 v_mag_read_addr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the mag read address*/ + com_rslt = + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr, + BMI160_USER_READ_ADDR__REG, &v_mag_read_addr_u8, + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_write_addr( +u8 *v_mag_write_addr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the address of last written */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_WRITE_ADDR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_write_addr_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_write_addr( +u8 v_mag_write_addr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the data of mag address to write data */ + com_rslt = + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr, + BMI160_USER_WRITE_ADDR__REG, &v_mag_write_addr_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_write_data( +u8 *v_mag_write_data_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_WRITE_DATA__REG, &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_mag_write_data_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_write_data( +u8 v_mag_write_data_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr, + BMI160_USER_WRITE_DATA__REG, &v_mag_write_data_u8, + BMI160_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 | BMI160_ANY_MOTION_X_ENABLE + * 1 | BMI160_ANY_MOTION_Y_ENABLE + * 2 | BMI160_ANY_MOTION_Z_ENABLE + * 3 | BMI160_DOUBLE_TAP_ENABLE + * 4 | BMI160_SINGLE_TAP_ENABLE + * 5 | BMI160_ORIENT_ENABLE + * 6 | BMI160_FLAT_ENABLE + * + * @param v_intr_enable_zero_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_0( +u8 v_enable_u8, u8 *v_intr_enable_zero_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* select interrupt to read*/ + switch (v_enable_u8) { + case BMI160_ANY_MOTION_X_ENABLE: + /* read the any motion interrupt x data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE); + break; + case BMI160_ANY_MOTION_Y_ENABLE: + /* read the any motion interrupt y data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE); + break; + case BMI160_ANY_MOTION_Z_ENABLE: + /* read the any motion interrupt z data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE); + break; + case BMI160_DOUBLE_TAP_ENABLE: + /* read the double tap interrupt data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE); + break; + case BMI160_SINGLE_TAP_ENABLE: + /* read the single tap interrupt data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE); + break; + case BMI160_ORIENT_ENABLE: + /* read the orient interrupt data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE); + break; + case BMI160_FLAT_ENABLE: + /* read the flat interrupt data */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_zero_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE); + break; + default: + com_rslt = E_BMI160_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 | BMI160_ANY_MOTION_X_ENABLE + * 1 | BMI160_ANY_MOTION_Y_ENABLE + * 2 | BMI160_ANY_MOTION_Z_ENABLE + * 3 | BMI160_DOUBLE_TAP_ENABLE + * 4 | BMI160_SINGLE_TAP_ENABLE + * 5 | BMI160_ORIENT_ENABLE + * 6 | BMI160_FLAT_ENABLE + * + * @param v_intr_enable_zero_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_0( +u8 v_enable_u8, u8 v_intr_enable_zero_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_enable_u8) { + case BMI160_ANY_MOTION_X_ENABLE: + /* write any motion x*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_ANY_MOTION_Y_ENABLE: + /* write any motion y*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_ANY_MOTION_Z_ENABLE: + /* write any motion z*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_DOUBLE_TAP_ENABLE: + /* write double tap*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_SINGLE_TAP_ENABLE: + /* write single tap */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_ORIENT_ENABLE: + /* write orient interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_FLAT_ENABLE: + /* write flat interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE, + v_intr_enable_zero_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_HIGH_G_X_ENABLE + * 1 | BMI160_HIGH_G_Y_ENABLE + * 2 | BMI160_HIGH_G_Z_ENABLE + * 3 | BMI160_LOW_G_ENABLE + * 4 | BMI160_DATA_RDY_ENABLE + * 5 | BMI160_FIFO_FULL_ENABLE + * 6 | BMI160_FIFO_WM_ENABLE + * + * @param v_intr_enable_1_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_1( +u8 v_enable_u8, u8 *v_intr_enable_1_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_enable_u8) { + case BMI160_HIGH_G_X_ENABLE: + /* read high_g_x interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE); + break; + case BMI160_HIGH_G_Y_ENABLE: + /* read high_g_y interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE); + break; + case BMI160_HIGH_G_Z_ENABLE: + /* read high_g_z interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE); + break; + case BMI160_LOW_G_ENABLE: + /* read low_g interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE); + break; + case BMI160_DATA_RDY_ENABLE: + /* read data ready interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE); + break; + case BMI160_FIFO_FULL_ENABLE: + /* read fifo full interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE); + break; + case BMI160_FIFO_WM_ENABLE: + /* read fifo water mark interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE); + break; + default: + com_rslt = E_BMI160_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 | BMI160_HIGH_G_X_ENABLE + * 1 | BMI160_HIGH_G_Y_ENABLE + * 2 | BMI160_HIGH_G_Z_ENABLE + * 3 | BMI160_LOW_G_ENABLE + * 4 | BMI160_DATA_RDY_ENABLE + * 5 | BMI160_FIFO_FULL_ENABLE + * 6 | BMI160_FIFO_WM_ENABLE + * + * @param v_intr_enable_1_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_1( +u8 v_enable_u8, u8 v_intr_enable_1_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_enable_u8) { + case BMI160_HIGH_G_X_ENABLE: + /* write high_g_x interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_HIGH_G_Y_ENABLE: + /* write high_g_y interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_HIGH_G_Z_ENABLE: + /* write high_g_z interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_LOW_G_ENABLE: + /* write low_g interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_DATA_RDY_ENABLE: + /* write data ready interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_FIFO_FULL_ENABLE: + /* write fifo full interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_FIFO_WM_ENABLE: + /* write fifo water mark interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE, + v_intr_enable_1_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_NOMOTION_X_ENABLE + * 1 | BMI160_NOMOTION_Y_ENABLE + * 2 | BMI160_NOMOTION_Z_ENABLE + * + * @param v_intr_enable_2_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_2( +u8 v_enable_u8, u8 *v_intr_enable_2_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_enable_u8) { + case BMI160_NOMOTION_X_ENABLE: + /* read no motion x */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE); + break; + case BMI160_NOMOTION_Y_ENABLE: + /* read no motion y */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE); + break; + case BMI160_NOMOTION_Z_ENABLE: + /* read no motion z */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE); + break; + default: + com_rslt = E_BMI160_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 | BMI160_NOMOTION_X_ENABLE + * 1 | BMI160_NOMOTION_Y_ENABLE + * 2 | BMI160_NOMOTION_Z_ENABLE + * + * @param v_intr_enable_2_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_2( +u8 v_enable_u8, u8 v_intr_enable_2_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_enable_u8) { + case BMI160_NOMOTION_X_ENABLE: + /* write no motion x */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE, + v_intr_enable_2_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_NOMOTION_Y_ENABLE: + /* write no motion y */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE, + v_intr_enable_2_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_NOMOTION_Z_ENABLE: + /* write no motion z */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE, + v_intr_enable_2_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_detector_enable( +u8 *v_step_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the step detector interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_step_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_detector_enable( +u8 v_step_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE, + v_step_intr_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG, + &v_data_u8, BMI160_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 | BMI160_INTR1_EDGE_CTRL + * 1 | BMI160_INTR2_EDGE_CTRL + * + * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_EDGE + * 0x00 | BMI160_LEVEL + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_edge_ctrl( +u8 v_channel_u8, u8 *v_intr_edge_ctrl_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_EDGE_CTRL: + /* read the edge trigger interrupt1*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_edge_ctrl_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_EDGE_CTRL); + break; + case BMI160_INTR2_EDGE_CTRL: + /* read the edge trigger interrupt2*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_edge_ctrl_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_EDGE_CTRL); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_EDGE_CTRL + * 1 | BMI160_INTR2_EDGE_CTRL + * + * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_EDGE + * 0x00 | BMI160_LEVEL + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_edge_ctrl( +u8 v_channel_u8, u8 v_intr_edge_ctrl_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_EDGE_CTRL: + /* write the edge trigger interrupt1*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_EDGE_CTRL, + v_intr_edge_ctrl_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_EDGE_CTRL: + /* write the edge trigger interrupt2*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_EDGE_CTRL, + v_intr_edge_ctrl_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_LEVEL + * 1 | BMI160_INTR2_LEVEL + * + * @param v_intr_level_u8 : The value of level of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_LEVEL_HIGH + * 0x00 | BMI160_LEVEL_LOW + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_level( +u8 v_channel_u8, u8 *v_intr_level_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_LEVEL: + /* read the interrupt1 level*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_LEVEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_level_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_LEVEL); + break; + case BMI160_INTR2_LEVEL: + /* read the interrupt2 level*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_LEVEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_level_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_LEVEL); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_LEVEL + * 1 | BMI160_INTR2_LEVEL + * + * @param v_intr_level_u8 : The value of level of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_LEVEL_HIGH + * 0x00 | BMI160_LEVEL_LOW + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_level( +u8 v_channel_u8, u8 v_intr_level_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_LEVEL: + /* write the interrupt1 level*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_LEVEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_LEVEL, v_intr_level_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_LEVEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_LEVEL: + /* write the interrupt2 level*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_LEVEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_LEVEL, v_intr_level_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_LEVEL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_intr_output_type_u8 : + * The value of output type of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_OPEN_DRAIN + * 0x00 | BMI160_PUSH_PULL + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_output_type( +u8 v_channel_u8, u8 *v_intr_output_type_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_OUTPUT_TYPE: + /* read the output type of interrupt1*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_output_type_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_OUTPUT_TYPE); + break; + case BMI160_INTR2_OUTPUT_TYPE: + /* read the output type of interrupt2*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_output_type_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_OUTPUT_TYPE); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_intr_output_type_u8 : + * The value of output type of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_OPEN_DRAIN + * 0x00 | BMI160_PUSH_PULL + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_output_type( +u8 v_channel_u8, u8 v_intr_output_type_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_OUTPUT_TYPE: + /* write the output type of interrupt1*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_OUTPUT_TYPE, + v_intr_output_type_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_OUTPUT_TYPE: + /* write the output type of interrupt2*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_OUTPUT_TYPE, + v_intr_output_type_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_output_enable_u8 : + * The value of output enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_output_enable( +u8 v_channel_u8, u8 *v_output_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_OUTPUT_ENABLE: + /* read the output enable of interrupt1*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_output_enable_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_OUTPUT_ENABLE); + break; + case BMI160_INTR2_OUTPUT_ENABLE: + /* read the output enable of interrupt2*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_output_enable_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_OUTPUT_EN); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_output_enable_u8 : + * The value of output enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_output_enable( +u8 v_channel_u8, u8 v_output_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_OUTPUT_ENABLE: + /* write the output enable of interrupt1*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_OUTPUT_ENABLE, + v_output_enable_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_OUTPUT_ENABLE: + /* write the output enable of interrupt2*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_OUTPUT_EN, + v_output_enable_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 +* --------------------------------------|------------------ +* BMI160_LATCH_DUR_NONE | 0x00 +* BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* BMI160_LATCH_DUR_625_MICRO_SEC | 0x02 +* BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* BMI160_LATCH_DUR_5_MILLI_SEC | 0x05 +* BMI160_LATCH_DUR_10_MILLI_SEC | 0x06 +* BMI160_LATCH_DUR_20_MILLI_SEC | 0x07 +* BMI160_LATCH_DUR_40_MILLI_SEC | 0x08 +* BMI160_LATCH_DUR_80_MILLI_SEC | 0x09 +* BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A +* BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B +* BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C +* BMI160_LATCH_DUR_1_28_SEC | 0x0D +* BMI160_LATCH_DUR_2_56_SEC | 0x0E +* BMI160_LATCHED | 0x0F +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_latch_intr( +u8 *v_latch_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the latch duration value */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_LATCH__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_latch_intr_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 +* --------------------------------------|------------------ +* BMI160_LATCH_DUR_NONE | 0x00 +* BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* BMI160_LATCH_DUR_625_MICRO_SEC | 0x02 +* BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* BMI160_LATCH_DUR_5_MILLI_SEC | 0x05 +* BMI160_LATCH_DUR_10_MILLI_SEC | 0x06 +* BMI160_LATCH_DUR_20_MILLI_SEC | 0x07 +* BMI160_LATCH_DUR_40_MILLI_SEC | 0x08 +* BMI160_LATCH_DUR_80_MILLI_SEC | 0x09 +* BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A +* BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B +* BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C +* BMI160_LATCH_DUR_1_28_SEC | 0x0D +* BMI160_LATCH_DUR_2_56_SEC | 0x0E +* BMI160_LATCHED | 0x0F +* +* +* + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error +* +* +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_latch_intr(u8 v_latch_intr_u8) +{ + u8 v_data_u8 = BMI160_INIT_VALUE; + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_latch_intr_u8 <= BMI160_MAX_LATCH_INTR) { + /* write the latch duration value */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_LATCH__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_LATCH, v_latch_intr_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_LATCH__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_INTR1_INPUT_ENABLE + * 1 | BMI160_INTR2_INPUT_ENABLE + * + * @param v_input_en_u8 : + * The value of input enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_input_enable( +u8 v_channel_u8, u8 *v_input_en_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read input enable of interrup1 and interrupt2*/ + case BMI160_INTR1_INPUT_ENABLE: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_input_en_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_INPUT_ENABLE); + break; + case BMI160_INTR2_INPUT_ENABLE: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_input_en_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_INPUT_ENABLE); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_INPUT_ENABLE + * 1 | BMI160_INTR2_INPUT_ENABLE + * + * @param v_input_en_u8 : + * The value of input enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_input_enable( +u8 v_channel_u8, u8 v_input_en_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write input enable of interrup1 and interrupt2*/ + case BMI160_INTR1_INPUT_ENABLE: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR1_INPUT_ENABLE, v_input_en_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_INPUT_ENABLE: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR2_INPUT_ENABLE, v_input_en_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_LOW_G + * 1 | BMI160_INTR2_MAP_LOW_G + * + * @param v_intr_low_g_u8 : The value of low_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g( +u8 v_channel_u8, u8 *v_intr_low_g_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the low_g interrupt */ + case BMI160_INTR1_MAP_LOW_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_low_g_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_LOW_G); + break; + case BMI160_INTR2_MAP_LOW_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_low_g_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_LOW_G); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_LOW_G + * 1 | BMI160_INTR2_MAP_LOW_G + * + * @param v_intr_low_g_u8 : The value of low_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g( +u8 v_channel_u8, u8 v_intr_low_g_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +u8 v_step_cnt_stat_u8 = BMI160_INIT_VALUE; +u8 v_step_det_stat_u8 = BMI160_INIT_VALUE; + +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* check the step detector interrupt enable status*/ + com_rslt = bmi160_get_step_detector_enable(&v_step_det_stat_u8); + /* disable the step detector interrupt */ + if (v_step_det_stat_u8 != BMI160_INIT_VALUE) + com_rslt += bmi160_set_step_detector_enable(BMI160_INIT_VALUE); + /* check the step counter interrupt enable status*/ + com_rslt += bmi160_get_step_counter_enable(&v_step_cnt_stat_u8); + /* disable the step counter interrupt */ + if (v_step_cnt_stat_u8 != BMI160_INIT_VALUE) + com_rslt += bmi160_set_step_counter_enable( + BMI160_INIT_VALUE); + switch (v_channel_u8) { + /* write the low_g interrupt*/ + case BMI160_INTR1_MAP_LOW_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_LOW_G, v_intr_low_g_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_LOW_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_LOW_G, v_intr_low_g_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_HIGH_G + * 1 | BMI160_INTR2_MAP_HIGH_G + * + * @param v_intr_high_g_u8 : The value of high_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g( +u8 v_channel_u8, u8 *v_intr_high_g_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the high_g interrupt*/ + switch (v_channel_u8) { + case BMI160_INTR1_MAP_HIGH_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_high_g_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_HIGH_G); + break; + case BMI160_INTR2_MAP_HIGH_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_high_g_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_HIGH_G); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_HIGH_G + * 1 | BMI160_INTR2_MAP_HIGH_G + * + * @param v_intr_high_g_u8 : The value of high_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g( +u8 v_channel_u8, u8 v_intr_high_g_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the high_g interrupt*/ + case BMI160_INTR1_MAP_HIGH_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_HIGH_G, v_intr_high_g_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_HIGH_G: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_HIGH_G, v_intr_high_g_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_ANY_MOTION + * 1 | BMI160_INTR2_MAP_ANY_MOTION + * + * @param v_intr_any_motion_u8 : The value of any motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion( +u8 v_channel_u8, u8 *v_intr_any_motion_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the any motion interrupt */ + case BMI160_INTR1_MAP_ANY_MOTION: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_any_motion_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION); + break; + case BMI160_INTR2_MAP_ANY_MOTION: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_any_motion_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_ANY_MOTION + * 1 | BMI160_INTR2_MAP_ANY_MOTION + * + * @param v_intr_any_motion_u8 : The value of any motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion( +u8 v_channel_u8, u8 v_intr_any_motion_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +u8 sig_mot_stat = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the status of significant motion interrupt */ + com_rslt = bmi160_get_intr_significant_motion_select(&sig_mot_stat); + /* disable the significant motion interrupt */ + if (sig_mot_stat != BMI160_INIT_VALUE) + com_rslt += bmi160_set_intr_significant_motion_select( + BMI160_INIT_VALUE); + switch (v_channel_u8) { + /* write the any motion interrupt */ + case BMI160_INTR1_MAP_ANY_MOTION: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION, + v_intr_any_motion_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_ANY_MOTION: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION, + v_intr_any_motion_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_NOMO + * 1 | BMI160_INTR2_MAP_NOMO + * + * @param v_intr_nomotion_u8 : The value of no motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_nomotion( +u8 v_channel_u8, u8 *v_intr_nomotion_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the no motion interrupt*/ + case BMI160_INTR1_MAP_NOMO: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_nomotion_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_NOMOTION); + break; + case BMI160_INTR2_MAP_NOMO: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_nomotion_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_NOMOTION); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_NOMO + * 1 | BMI160_INTR2_MAP_NOMO + * + * @param v_intr_nomotion_u8 : The value of no motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_nomotion( +u8 v_channel_u8, u8 v_intr_nomotion_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the no motion interrupt*/ + case BMI160_INTR1_MAP_NOMO: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_NOMOTION, + v_intr_nomotion_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_NOMO: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_NOMOTION, + v_intr_nomotion_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_DOUBLE_TAP + * 1 | BMI160_INTR2_MAP_DOUBLE_TAP + * + * @param v_intr_double_tap_u8 : The value of double tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_double_tap( +u8 v_channel_u8, u8 *v_intr_double_tap_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + case BMI160_INTR1_MAP_DOUBLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_double_tap_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP); + break; + case BMI160_INTR2_MAP_DOUBLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_double_tap_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_DOUBLE_TAP + * 1 | BMI160_INTR2_MAP_DOUBLE_TAP + * + * @param v_intr_double_tap_u8 : The value of double tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_double_tap( +u8 v_channel_u8, u8 v_intr_double_tap_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* set the double tap interrupt */ + case BMI160_INTR1_MAP_DOUBLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP, + v_intr_double_tap_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_DOUBLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP, + v_intr_double_tap_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_SINGLE_TAP + * 1 | BMI160_INTR2_MAP_SINGLE_TAP + * + * @param v_intr_single_tap_u8 : The value of single tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_single_tap( +u8 v_channel_u8, u8 *v_intr_single_tap_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* reads the single tap interrupt*/ + case BMI160_INTR1_MAP_SINGLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_single_tap_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP); + break; + case BMI160_INTR2_MAP_SINGLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_single_tap_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_SINGLE_TAP + * 1 | BMI160_INTR2_MAP_SINGLE_TAP + * + * @param v_intr_single_tap_u8 : The value of single tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_single_tap( +u8 v_channel_u8, u8 v_intr_single_tap_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the single tap interrupt */ + case BMI160_INTR1_MAP_SINGLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP, + v_intr_single_tap_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_SINGLE_TAP: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP, + v_intr_single_tap_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_ORIENT + * 1 | BMI160_INTR2_MAP_ORIENT + * + * @param v_intr_orient_u8 : The value of orient enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient( +u8 v_channel_u8, u8 *v_intr_orient_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the orientation interrupt*/ + case BMI160_INTR1_MAP_ORIENT: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_orient_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_ORIENT); + break; + case BMI160_INTR2_MAP_ORIENT: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_orient_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_ORIENT); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_ORIENT + * 1 | BMI160_INTR2_MAP_ORIENT + * + * @param v_intr_orient_u8 : The value of orient enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient( +u8 v_channel_u8, u8 v_intr_orient_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the orientation interrupt*/ + case BMI160_INTR1_MAP_ORIENT: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_ORIENT, v_intr_orient_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_ORIENT: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_ORIENT, v_intr_orient_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_FLAT + * 1 | BMI160_INTR2_MAP_FLAT + * + * @param v_intr_flat_u8 : The value of flat enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat( +u8 v_channel_u8, u8 *v_intr_flat_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the flat interrupt*/ + case BMI160_INTR1_MAP_FLAT: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_flat_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_FLAT); + break; + case BMI160_INTR2_MAP_FLAT: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_flat_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_FLAT); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_FLAT + * 1 | BMI160_INTR2_MAP_FLAT + * + * @param v_intr_flat_u8 : The value of flat enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat( +u8 v_channel_u8, u8 v_intr_flat_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the flat interrupt */ + case BMI160_INTR1_MAP_FLAT: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_0_INTR1_FLAT, + v_intr_flat_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_FLAT: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_2_INTR2_FLAT, + v_intr_flat_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_PMUTRIG + * 1 | BMI160_INTR2_MAP_PMUTRIG + * + * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_pmu_trig( +u8 v_channel_u8, u8 *v_intr_pmu_trig_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the pmu trigger interrupt*/ + case BMI160_INTR1_MAP_PMUTRIG: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_pmu_trig_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG); + break; + case BMI160_INTR2_MAP_PMUTRIG: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_pmu_trig_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_PMUTRIG + * 1 | BMI160_INTR2_MAP_PMUTRIG + * + * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable + * value | trigger enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_pmu_trig( +u8 v_channel_u8, u8 v_intr_pmu_trig_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the pmu trigger interrupt */ + case BMI160_INTR1_MAP_PMUTRIG: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG, + v_intr_pmu_trig_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_PMUTRIG: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG, + v_intr_pmu_trig_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_FIFO_FULL + * 1 | BMI160_INTR2_MAP_FIFO_FULL + * + * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_fifo_full( +u8 v_channel_u8, u8 *v_intr_fifo_full_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the fifo full interrupt */ + case BMI160_INTR1_MAP_FIFO_FULL: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_full_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL); + break; + case BMI160_INTR2_MAP_FIFO_FULL: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_full_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_FIFO_FULL + * 1 | BMI160_INTR2_MAP_FIFO_FULL + * + * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_fifo_full( +u8 v_channel_u8, u8 v_intr_fifo_full_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the fifo full interrupt */ + case BMI160_INTR1_MAP_FIFO_FULL: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL, + v_intr_fifo_full_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_FIFO_FULL: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL, + v_intr_fifo_full_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_FIFO_WM + * 1 | BMI160_INTR2_MAP_FIFO_WM + * + * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_fifo_wm( +u8 v_channel_u8, u8 *v_intr_fifo_wm_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* read the fifo water mark interrupt */ + case BMI160_INTR1_MAP_FIFO_WM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_wm_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM); + break; + case BMI160_INTR2_MAP_FIFO_WM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_fifo_wm_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_FIFO_WM + * 1 | BMI160_INTR2_MAP_FIFO_WM + * + * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_fifo_wm( +u8 v_channel_u8, u8 v_intr_fifo_wm_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /* write the fifo water mark interrupt */ + case BMI160_INTR1_MAP_FIFO_WM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM, + v_intr_fifo_wm_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_FIFO_WM: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM, + v_intr_fifo_wm_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, + BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_DATA_RDY + * 1 | BMI160_INTR2_MAP_DATA_RDY + * + * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_data_rdy( +u8 v_channel_u8, u8 *v_intr_data_rdy_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /*Read Data Ready interrupt*/ + case BMI160_INTR1_MAP_DATA_RDY: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY); + break; + case BMI160_INTR2_MAP_DATA_RDY: + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY); + break; + default: + com_rslt = E_BMI160_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 | BMI160_INTR1_MAP_DATA_RDY + * 1 | BMI160_INTR2_MAP_DATA_RDY + * + * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_data_rdy( +u8 v_channel_u8, u8 v_intr_data_rdy_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + switch (v_channel_u8) { + /*Write Data Ready interrupt*/ + case BMI160_INTR1_MAP_DATA_RDY: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY, + v_intr_data_rdy_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + case BMI160_INTR2_MAP_DATA_RDY: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY, + v_intr_data_rdy_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160-> + dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + break; + default: + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_source(u8 *v_tap_source_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the tap source interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_source_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_source( +u8 v_tap_source_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_tap_source_u8 <= BMI160_MAX_VALUE_SOURCE_INTR) { + /* write the tap source interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE, + v_tap_source_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_high_source( +u8 *v_low_high_source_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the high_low_g source interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_low_high_source_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_high_source( +u8 v_low_high_source_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_low_high_source_u8 <= BMI160_MAX_VALUE_SOURCE_INTR) { + /* write the high_low_g source interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE, + v_low_high_source_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_motion_source( +u8 *v_motion_source_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the any/no motion interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_motion_source_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_motion_source( +u8 v_motion_source_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_motion_source_u8 <= BMI160_MAX_VALUE_SOURCE_INTR) { + /* write the any/no motion interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE, + v_motion_source_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_durn( +u8 *v_low_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the low_g interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_durn_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_durn(u8 v_low_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the low_g interrupt */ + com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG, + &v_low_g_durn_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_thres( +u8 *v_low_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read low_g threshold */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_thres_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_thres( +u8 v_low_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write low_g threshold */ + com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG, + &v_low_g_thres_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_hyst( +u8 *v_low_hyst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read low_g hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_low_hyst_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_hyst( +u8 v_low_hyst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write low_g hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST, + v_low_hyst_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_mode(u8 *v_low_g_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /*read Low-g interrupt mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_low_g_mode_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_mode( +u8 v_low_g_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_low_g_mode_u8 <= BMI160_MAX_VALUE_LOW_G_MODE) { + /*write Low-g interrupt mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE, + v_low_g_mode_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_hyst( +u8 *v_high_g_hyst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read high_g hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_hyst_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_hyst( +u8 v_high_g_hyst_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write high_g hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST, + v_high_g_hyst_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_durn( +u8 *v_high_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read high_g duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_durn_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_durn( +u8 v_high_g_durn_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write high_g duration*/ + com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG, + &v_high_g_durn_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_thres( +u8 *v_high_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_high_g_thres_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_thres( +u8 v_high_g_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG, + &v_high_g_thres_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion_durn( +u8 *v_any_motion_durn_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read any motion duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_durn_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion_durn( +u8 v_any_motion_durn_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write any motion duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN, + v_any_motion_durn_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG, + &v_data_u8, BMI160_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); + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_durn( +u8 *v_slow_no_motion_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read slow no motion duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_slow_no_motion_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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); + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_durn( +u8 v_slow_no_motion_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write slow no motion duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE + (v_data_u8, + BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN, + v_slow_no_motion_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion_thres( +u8 *v_any_motion_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read any motion threshold*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_any_motion_thres_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion_thres( +u8 v_any_motion_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write any motion threshold*/ + com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG, + &v_any_motion_thres_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_thres( +u8 *v_slow_no_motion_thres_u8) +{ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read slow no motion threshold*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_slow_no_motion_thres_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_thres( +u8 v_slow_no_motion_thres_u8) +{ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write slow no motion threshold*/ + com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG, + &v_slow_no_motion_thres_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_select( +u8 *v_intr_slow_no_motion_select_u8) +{ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read slow no motion select*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_slow_no_motion_select_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_select( +u8 v_intr_slow_no_motion_select_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; +} else { +if (v_intr_slow_no_motion_select_u8 <= BMI160_MAX_VALUE_NO_MOTION) { + /* write slow no motion select*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT, + v_intr_slow_no_motion_select_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } +} else { +com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_select( +u8 *v_intr_significant_motion_select_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the significant or any motion interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_intr_significant_motion_select_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_select( +u8 v_intr_significant_motion_select_u8) +{ +/* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_intr_significant_motion_select_u8 <= + BMI160_MAX_VALUE_SIGNIFICANT_MOTION) { + /* write the significant or any motion interrupt*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT, + v_intr_significant_motion_select_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_skip( +u8 *v_int_sig_mot_skip_u8) +{ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read significant skip time*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_int_sig_mot_skip_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_skip( +u8 v_int_sig_mot_skip_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_int_sig_mot_skip_u8 <= BMI160_MAX_UNDER_SIG_MOTION) { + /* write significant skip time*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP, + v_int_sig_mot_skip_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_proof( +u8 *v_significant_motion_proof_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read significant proof time */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_significant_motion_proof_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_proof( +u8 v_significant_motion_proof_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_significant_motion_proof_u8 + <= BMI160_MAX_UNDER_SIG_MOTION) { + /* write significant proof time */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF, + v_significant_motion_proof_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_TAP_DURN_50MS + * 0x01 | BMI160_TAP_DURN_100MS + * 0x03 | BMI160_TAP_DURN_150MS + * 0x04 | BMI160_TAP_DURN_200MS + * 0x05 | BMI160_TAP_DURN_250MS + * 0x06 | BMI160_TAP_DURN_375MS + * 0x07 | BMI160_TAP_DURN_700MS + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_durn( +u8 *v_tap_durn_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_durn_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 | BMI160_TAP_DURN_50MS + * 0x01 | BMI160_TAP_DURN_100MS + * 0x03 | BMI160_TAP_DURN_150MS + * 0x04 | BMI160_TAP_DURN_200MS + * 0x05 | BMI160_TAP_DURN_250MS + * 0x06 | BMI160_TAP_DURN_375MS + * 0x07 | BMI160_TAP_DURN_700MS + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_durn( +u8 v_tap_durn_u8) +{ + u8 v_data_u8 = BMI160_INIT_VALUE; + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_tap_durn_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_tap_durn_u8 <= BMI160_MAX_TAP_TURN) { + switch (v_tap_durn_u8) { + case BMI160_TAP_DURN_50MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_50MS; + break; + case BMI160_TAP_DURN_100MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_100MS; + break; + case BMI160_TAP_DURN_150MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_150MS; + break; + case BMI160_TAP_DURN_200MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_200MS; + break; + case BMI160_TAP_DURN_250MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_250MS; + break; + case BMI160_TAP_DURN_375MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_375MS; + break; + case BMI160_TAP_DURN_500MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_500MS; + break; + case BMI160_TAP_DURN_700MS: + v_data_tap_durn_u8 = BMI160_TAP_DURN_700MS; + break; + default: + break; + } + /* write tap duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_TAP_0_INTR_TAP_DURN, + v_data_tap_durn_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_TAP_SHOCK_50MS + * 0x01 | BMI160_TAP_SHOCK_75MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_shock( +u8 *v_tap_shock_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap shock duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_shock_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 | BMI160_TAP_SHOCK_50MS + * 0x01 | BMI160_TAP_SHOCK_75MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_shock(u8 v_tap_shock_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_tap_shock_u8 <= BMI160_MAX_VALUE_TAP_SHOCK) { + /* write tap shock duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK, + v_tap_shock_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_TAP_QUIET_30MS + * 0x01 | BMI160_TAP_QUIET_20MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_quiet( +u8 *v_tap_quiet_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap quiet duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_quiet_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 | BMI160_TAP_QUIET_30MS + * 0x01 | BMI160_TAP_QUIET_20MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_quiet(u8 v_tap_quiet_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_tap_quiet_u8 <= BMI160_MAX_VALUE_TAP_QUIET) { + /* write tap quiet duration*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET, + v_tap_quiet_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_thres( +u8 *v_tap_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read tap threshold*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_tap_thres_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_thres( +u8 v_tap_thres_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write tap threshold*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_TAP_1_INTR_TAP_THRES, + v_tap_thres_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_mode( +u8 *v_orient_mode_u8) +{ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read orientation threshold*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_mode_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_mode( +u8 v_orient_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_orient_mode_u8 <= BMI160_MAX_ORIENT_MODE) { + /* write orientation threshold*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE, + v_orient_mode_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_blocking( +u8 *v_orient_blocking_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read orient blocking mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_blocking_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_blocking( +u8 v_orient_blocking_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_orient_blocking_u8 <= BMI160_MAX_ORIENT_BLOCKING) { + /* write orient blocking mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING, + v_orient_blocking_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_hyst( +u8 *v_orient_hyst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read orient hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_hyst_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_hyst( +u8 v_orient_hyst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write orient hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST, + v_orient_hyst_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_theta( +u8 *v_orient_theta_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read Orient blocking angle*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_theta_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_theta( +u8 v_orient_theta_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_orient_theta_u8 <= BMI160_MAX_ORIENT_THETA) { + /* write Orient blocking angle*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA, + v_orient_theta_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_ud_enable( +u8 *v_orient_ud_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read orient up/down enable*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_ud_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_ud_enable( +u8 v_orient_ud_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_orient_ud_u8 <= BMI160_MAX_VALUE_ORIENT_UD) { + /* write orient up/down enable */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE, + v_orient_ud_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_axes_enable( +u8 *v_orient_axes_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read orientation axes changes */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_orient_axes_u8 = BMI160_GET_BITSLICE + (v_data_u8, + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_axes_enable( +u8 v_orient_axes_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_orient_axes_u8 <= BMI160_MAX_VALUE_ORIENT_AXES) { + /*write orientation axes changes */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX, + v_orient_axes_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_theta( +u8 *v_flat_theta_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read Flat angle*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_theta_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_theta( +u8 v_flat_theta_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_flat_theta_u8 <= BMI160_MAX_FLAT_THETA) { + /* write Flat angle */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA, + v_flat_theta_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_hold( +u8 *v_flat_hold_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read flat hold time*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_hold_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_hold( +u8 v_flat_hold_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_flat_hold_u8 <= BMI160_MAX_FLAT_HOLD) { + /* write flat hold time*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD, + v_flat_hold_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_hyst( +u8 *v_flat_hyst_u8) +{ + /* variable used to return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the flat hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_flat_hyst_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_hyst( +u8 v_flat_hyst_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_flat_hyst_u8 <= BMI160_MAX_FLAT_HYST) { + /* read the flat hysteresis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST, + v_flat_hyst_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_z(u8 *v_foc_accel_z_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel offset compensation for z axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_accel_z_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_z( +u8 v_foc_accel_z_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write the accel offset compensation for z axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FOC_ACCEL_Z, + v_foc_accel_z_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Z__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_y(u8 *v_foc_accel_y_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel offset compensation for y axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_accel_y_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_y(u8 v_foc_accel_y_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_foc_accel_y_u8 <= BMI160_MAX_ACCEL_FOC) { + /* write the accel offset compensation for y axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FOC_ACCEL_Y, + v_foc_accel_y_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_x(u8 *v_foc_accel_x_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the accel offset compensation for x axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_accel_x_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_x(u8 v_foc_accel_x_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_foc_accel_x_u8 <= BMI160_MAX_ACCEL_FOC) { + /* write the accel offset compensation for x axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FOC_ACCEL_X, + v_foc_accel_x_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +s8 v_status_s8 = SUCCESS; +u8 v_timeout_u8 = BMI160_INIT_VALUE; +s8 v_foc_accel_offset_x_s8 = BMI160_INIT_VALUE; +s8 v_foc_accel_offset_y_s8 = BMI160_INIT_VALUE; +s8 v_foc_accel_offset_z_s8 = BMI160_INIT_VALUE; +u8 focstatus = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; +} else { + v_status_s8 = bmi160_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + switch (v_axis_u8) { + case FOC_X_AXIS: + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FOC_ACCEL_X, + v_foc_accel_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the + FOC need to write + 0x03 in the register 0x7e*/ + com_rslt += + bmi160_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += + bmi160_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH + && v_timeout_u8 < + BMI160_MAXIMUM_TIMEOUT)) { + p_bmi160->delay_msec( + BMI160_DELAY_SETTLING_TIME); + com_rslt = bmi160_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == BMI160_FOC_STAT_HIGH)) { + com_rslt += + bmi160_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_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FOC_ACCEL_Y, + v_foc_accel_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC + need to write 0x03 + in the register 0x7e*/ + com_rslt += + bmi160_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += + bmi160_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH + && v_timeout_u8 < + BMI160_MAXIMUM_TIMEOUT)) { + p_bmi160->delay_msec( + BMI160_DELAY_SETTLING_TIME); + com_rslt = bmi160_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == BMI160_FOC_STAT_HIGH)) { + com_rslt += + bmi160_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_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FOC_ACCEL_Z, + v_foc_accel_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC need to write + 0x03 in the register 0x7e*/ + com_rslt += + bmi160_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += + bmi160_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH + && v_timeout_u8 < + BMI160_MAXIMUM_TIMEOUT)) { + p_bmi160->delay_msec( + BMI160_DELAY_SETTLING_TIME); + com_rslt = bmi160_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == BMI160_FOC_STAT_HIGH)) { + com_rslt += + bmi160_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 + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 focx = BMI160_INIT_VALUE; +u8 focy = BMI160_INIT_VALUE; +u8 focz = BMI160_INIT_VALUE; +s8 v_foc_accel_offset_x_s8 = BMI160_INIT_VALUE; +s8 v_foc_accel_offset_y_s8 = BMI160_INIT_VALUE; +s8 v_foc_accel_offset_z_s8 = BMI160_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +u8 v_timeout_u8 = BMI160_INIT_VALUE; +u8 focstatus = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + v_status_s8 = bmi160_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* foc x axis*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_X__REG, + &focx, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + focx = BMI160_SET_BITSLICE(focx, + BMI160_USER_FOC_ACCEL_X, + v_foc_accel_x_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_X__REG, + &focx, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + /* foc y axis*/ + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Y__REG, + &focy, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + focy = BMI160_SET_BITSLICE(focy, + BMI160_USER_FOC_ACCEL_Y, + v_foc_accel_y_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Y__REG, + &focy, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + /* foc z axis*/ + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Z__REG, + &focz, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + focz = BMI160_SET_BITSLICE(focz, + BMI160_USER_FOC_ACCEL_Z, + v_foc_accel_z_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_ACCEL_Z__REG, + &focz, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC need to + write 0x03 in the register 0x7e*/ + com_rslt += bmi160_set_command_register( + START_FOC_ACCEL_GYRO); + + com_rslt += bmi160_get_foc_rdy( + &focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH + && v_timeout_u8 < + BMI160_MAXIMUM_TIMEOUT)) { + p_bmi160->delay_msec( + BMI160_DELAY_SETTLING_TIME); + com_rslt = bmi160_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == BMI160_GEN_READ_WRITE_DATA_LENGTH)) { + com_rslt += + bmi160_get_accel_offset_compensation_xaxis( + &v_foc_accel_offset_x_s8); + *v_accel_off_x_s8 = + v_foc_accel_offset_x_s8; + com_rslt += + bmi160_get_accel_offset_compensation_yaxis( + &v_foc_accel_offset_y_s8); + *v_accel_off_y_s8 = + v_foc_accel_offset_y_s8; + com_rslt += + bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_gyro_enable( +u8 *v_foc_gyro_u8) +{ + /* used for return the status of bus communication */ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the gyro fast offset enable*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_FOC_GYRO_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_foc_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +u8 v_timeout_u8 = BMI160_INIT_VALUE; +s16 offsetx = BMI160_INIT_VALUE; +s16 offsety = BMI160_INIT_VALUE; +s16 offsetz = BMI160_INIT_VALUE; +u8 focstatus = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + v_status_s8 = bmi160_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FOC_GYRO_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_FOC_GYRO_ENABLE, + v_foc_gyro_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_FOC_GYRO_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + /* trigger the FOC need to write 0x03 + in the register 0x7e*/ + com_rslt += bmi160_set_command_register + (START_FOC_ACCEL_GYRO); + + com_rslt += bmi160_get_foc_rdy(&focstatus); + if ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH)) { + while ((com_rslt != SUCCESS) || + (focstatus != BMI160_FOC_STAT_HIGH + && v_timeout_u8 < + BMI160_MAXIMUM_TIMEOUT)) { + p_bmi160->delay_msec( + BMI160_DELAY_SETTLING_TIME); + com_rslt = bmi160_get_foc_rdy( + &focstatus); + v_timeout_u8++; + } + } + if ((com_rslt == SUCCESS) && + (focstatus == BMI160_FOC_STAT_HIGH)) { + com_rslt += + bmi160_get_gyro_offset_compensation_xaxis + (&offsetx); + *v_gyro_off_x_s16 = offsetx; + + com_rslt += + bmi160_get_gyro_offset_compensation_yaxis + (&offsety); + *v_gyro_off_y_s16 = offsety; + + com_rslt += + bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_nvm_prog_enable( +u8 *v_nvm_prog_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read NVM program*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_CONFIG_NVM_PROG_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_nvm_prog_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_nvm_prog_enable( +u8 v_nvm_prog_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_nvm_prog_u8 <= BMI160_MAX_VALUE_NVM_PROG) { + /* write the NVM program*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_CONFIG_NVM_PROG_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_CONFIG_NVM_PROG_ENABLE, + v_nvm_prog_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_CONFIG_NVM_PROG_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_spi3( +u8 *v_spi3_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read SPI mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_SPI3__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_spi3_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_spi3( +u8 v_spi3_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_spi3_u8 <= BMI160_MAX_VALUE_SPI3) { + /* write SPI mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_SPI3__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_IF_CONFIG_SPI3, + v_spi3_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_SPI3__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_wdt_select( +u8 *v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read I2C watch dog timer */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_wdt_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_wdt_select( +u8 v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_i2c_wdt_u8 <= BMI160_MAX_VALUE_I2C_WDT) { + /* write I2C watch dog timer */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_IF_CONFIG_I2C_WDT_SELECT, + v_i2c_wdt_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_wdt_enable( +u8 *v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read i2c watch dog eneble */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_i2c_wdt_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_wdt_enable( +u8 v_i2c_wdt_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_i2c_wdt_u8 <= BMI160_MAX_VALUE_I2C_WDT) { + /* write i2c watch dog eneble */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE, + v_i2c_wdt_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_if_mode( +u8 *v_if_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read if mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_IF_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_if_mode_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_if_mode( +u8 v_if_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_if_mode_u8 <= BMI160_MAX_IF_MODE) { + /* write if mode*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_IF_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_IF_CONFIG_IF_MODE, + v_if_mode_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_IF_CONFIG_IF_MODE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_sleep_trigger( +u8 *v_gyro_sleep_trigger_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro sleep trigger */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SLEEP_TRIGGER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_sleep_trigger_u8 = + BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_sleep_trigger( +u8 v_gyro_sleep_trigger_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_gyro_sleep_trigger_u8 <= BMI160_MAX_GYRO_SLEEP_TIGGER) { + /* write gyro sleep trigger */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SLEEP_TRIGGER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_SLEEP_TRIGGER, + v_gyro_sleep_trigger_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SLEEP_TRIGGER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_wakeup_trigger( +u8 *v_gyro_wakeup_trigger_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro wakeup trigger */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_WAKEUP_TRIGGER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_wakeup_trigger_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_wakeup_trigger( +u8 v_gyro_wakeup_trigger_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_gyro_wakeup_trigger_u8 + <= BMI160_MAX_GYRO_WAKEUP_TRIGGER) { + /* write gyro wakeup trigger */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_WAKEUP_TRIGGER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_WAKEUP_TRIGGER, + v_gyro_wakeup_trigger_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_WAKEUP_TRIGGER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_sleep_state( +u8 *v_gyro_sleep_state_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro sleep state*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SLEEP_STATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_sleep_state_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_sleep_state( +u8 v_gyro_sleep_state_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_gyro_sleep_state_u8 <= BMI160_MAX_VALUE_SLEEP_STATE) { + /* write gyro sleep state*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SLEEP_STATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_SLEEP_STATE, + v_gyro_sleep_state_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SLEEP_STATE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_wakeup_intr( +u8 *v_gyro_wakeup_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro wakeup interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_WAKEUP_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_wakeup_intr_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_wakeup_intr( +u8 v_gyro_wakeup_intr_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_gyro_wakeup_intr_u8 <= BMI160_MAX_VALUE_WAKEUP_INTR) { + /* write gyro wakeup interrupt */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_WAKEUP_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_WAKEUP_INTR, + v_gyro_wakeup_intr_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_WAKEUP_INTR__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_axis( +u8 *v_accel_selftest_axis_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read accel self test axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_SELFTEST_AXIS__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_selftest_axis_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_axis( +u8 v_accel_selftest_axis_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_accel_selftest_axis_u8 + <= BMI160_MAX_ACCEL_SELFTEST_AXIS) { + /* write accel self test axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_SELFTEST_AXIS__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_ACCEL_SELFTEST_AXIS, + v_accel_selftest_axis_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_SELFTEST_AXIS__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_sign( +u8 *v_accel_selftest_sign_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read accel self test axis sign*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_SELFTEST_SIGN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_selftest_sign_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_sign( +u8 v_accel_selftest_sign_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_accel_selftest_sign_u8 <= + BMI160_MAX_VALUE_SELFTEST_SIGN) { + /* write accel self test axis sign*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_SELFTEST_SIGN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_ACCEL_SELFTEST_SIGN, + v_accel_selftest_sign_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_ACCEL_SELFTEST_SIGN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_amp( +u8 *v_accel_selftest_amp_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read self test amplitude*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_SELFTEST_AMP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_selftest_amp_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_amp( +u8 v_accel_selftest_amp_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_accel_selftest_amp_u8 <= + BMI160_MAX_VALUE_SELFTEST_AMP) { + /* write self test amplitude*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_SELFTEST_AMP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_SELFTEST_AMP, + v_accel_selftest_amp_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_SELFTEST_AMP__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_selftest_start( +u8 *v_gyro_selftest_start_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro self test start */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SELFTEST_START__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_selftest_start_u8 = BMI160_GET_BITSLICE( + v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_selftest_start( +u8 v_gyro_selftest_start_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_gyro_selftest_start_u8 <= + BMI160_MAX_VALUE_SELFTEST_START) { + /* write gyro self test start */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SELFTEST_START__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_GYRO_SELFTEST_START, + v_gyro_selftest_start_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_GYRO_SELFTEST_START__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_spi_enable(u8 *v_spi_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read interface section*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_SPI_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_spi_enable_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_spi_enable(u8 v_spi_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write interface section*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_SPI_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_NV_CONFIG_SPI_ENABLE, + v_spi_enable_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_SPI_ENABLE__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_spare0_trim(u8 *v_spare0_trim_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read spare zero*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_SPARE0__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_spare0_trim_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_spare0_trim(u8 v_spare0_trim_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write spare zero*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_SPARE0__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_NV_CONFIG_SPARE0, + v_spare0_trim_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_SPARE0__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_nvm_counter(u8 *v_nvm_counter_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read NVM counter*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_NVM_COUNTER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_nvm_counter_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_nvm_counter( +u8 v_nvm_counter_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write NVM counter*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_NVM_COUNTER__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_NV_CONFIG_NVM_COUNTER, + v_nvm_counter_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_NV_CONFIG_NVM_COUNTER__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_xaxis( +s8 *v_accel_off_x_s8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read accel manual offset compensation of x axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_x_s8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_xaxis( +s8 v_accel_off_x_s8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* enable accel offset */ + v_status_s8 = bmi160_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* write accel manual offset compensation of x axis*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE( + v_data_u8, + BMI160_USER_OFFSET_0_ACCEL_OFF_X, + v_accel_off_x_s8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_yaxis( +s8 *v_accel_off_y_s8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read accel manual offset compensation of y axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_y_s8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_yaxis( +s8 v_accel_off_y_s8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* enable accel offset */ + v_status_s8 = bmi160_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* write accel manual offset compensation of y axis*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE( + v_data_u8, + BMI160_USER_OFFSET_1_ACCEL_OFF_Y, + v_accel_off_y_s8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_zaxis( +s8 *v_accel_off_z_s8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read accel manual offset compensation of z axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_z_s8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_zaxis( +s8 v_accel_off_z_s8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + u8 v_status_s8 = SUCCESS; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* enable accel offset */ + v_status_s8 = bmi160_set_accel_offset_enable( + ACCEL_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + /* write accel manual offset + compensation of z axis*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG, + &v_data_u8, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_OFFSET_2_ACCEL_OFF_Z, + v_accel_off_z_s8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG, + &v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_xaxis( +s16 *v_gyro_off_x_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data1_u8r = BMI160_INIT_VALUE; + u8 v_data2_u8r = BMI160_INIT_VALUE; + s16 v_data3_u8r, v_data4_u8r = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro offset x*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_3_GYRO_OFF_X__REG, + &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r, + BMI160_USER_OFFSET_3_GYRO_OFF_X); + com_rslt += p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_X__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r, + BMI160_USER_OFFSET_6_GYRO_OFF_X); + v_data3_u8r = v_data2_u8r + << BMI160_SHIFT_BIT_POSITION_BY_14_BITS; + v_data4_u8r = v_data1_u8r + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS; + v_data3_u8r = v_data3_u8r | v_data4_u8r; + *v_gyro_off_x_s16 = v_data3_u8r + >> BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_xaxis( +s16 v_gyro_off_x_s16) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data1_u8r, v_data2_u8r = BMI160_INIT_VALUE; +u16 v_data3_u8r = BMI160_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write gyro offset x*/ + v_status_s8 = bmi160_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + if (v_status_s8 == SUCCESS) { + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_3_GYRO_OFF_X__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data1_u8r = + ((s8) (v_gyro_off_x_s16 & + BMI160_GYRO_MANUAL_OFFSET_0_7)); + v_data2_u8r = BMI160_SET_BITSLICE( + v_data2_u8r, + BMI160_USER_OFFSET_3_GYRO_OFF_X, + v_data1_u8r); + /* write 0x74 bit 0 to 7*/ + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_3_GYRO_OFF_X__REG, + &v_data2_u8r, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + com_rslt += p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_X__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u8r = + (u16) (v_gyro_off_x_s16 & + BMI160_GYRO_MANUAL_OFFSET_8_9); + v_data1_u8r = (u8)(v_data3_u8r + >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = BMI160_SET_BITSLICE( + v_data2_u8r, + BMI160_USER_OFFSET_6_GYRO_OFF_X, + v_data1_u8r); + /* write 0x77 bit 0 and 1*/ + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_X__REG, + &v_data2_u8r, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_yaxis( +s16 *v_gyro_off_y_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data1_u8r = BMI160_INIT_VALUE; + u8 v_data2_u8r = BMI160_INIT_VALUE; + s16 v_data3_u8r, v_data4_u8r = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro offset y*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG, + &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r, + BMI160_USER_OFFSET_4_GYRO_OFF_Y); + com_rslt += p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r, + BMI160_USER_OFFSET_6_GYRO_OFF_Y); + v_data3_u8r = v_data2_u8r + << BMI160_SHIFT_BIT_POSITION_BY_14_BITS; + v_data4_u8r = v_data1_u8r + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS; + v_data3_u8r = v_data3_u8r | v_data4_u8r; + *v_gyro_off_y_s16 = v_data3_u8r + >> BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_yaxis( +s16 v_gyro_off_y_s16) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data1_u8r, v_data2_u8r = BMI160_INIT_VALUE; +u16 v_data3_u8r = BMI160_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* enable gyro offset bit */ + v_status_s8 = bmi160_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + /* write gyro offset y*/ + if (v_status_s8 == SUCCESS) { + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data1_u8r = + ((s8) (v_gyro_off_y_s16 & + BMI160_GYRO_MANUAL_OFFSET_0_7)); + v_data2_u8r = BMI160_SET_BITSLICE( + v_data2_u8r, + BMI160_USER_OFFSET_4_GYRO_OFF_Y, + v_data1_u8r); + /* write 0x75 bit 0 to 7*/ + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG, + &v_data2_u8r, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + com_rslt += p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u8r = + (u16) (v_gyro_off_y_s16 & + BMI160_GYRO_MANUAL_OFFSET_8_9); + v_data1_u8r = (u8)(v_data3_u8r + >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = BMI160_SET_BITSLICE( + v_data2_u8r, + BMI160_USER_OFFSET_6_GYRO_OFF_Y, + v_data1_u8r); + /* write 0x77 bit 2 and 3*/ + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG, + &v_data2_u8r, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_zaxis( +s16 *v_gyro_off_z_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data1_u8r = BMI160_INIT_VALUE; + u8 v_data2_u8r = BMI160_INIT_VALUE; + s16 v_data3_u8r, v_data4_u8r = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro manual offset z axis*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG, + &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = BMI160_GET_BITSLICE + (v_data1_u8r, + BMI160_USER_OFFSET_5_GYRO_OFF_Z); + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = BMI160_GET_BITSLICE( + v_data2_u8r, + BMI160_USER_OFFSET_6_GYRO_OFF_Z); + v_data3_u8r = v_data2_u8r + << BMI160_SHIFT_BIT_POSITION_BY_14_BITS; + v_data4_u8r = v_data1_u8r + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS; + v_data3_u8r = v_data3_u8r | v_data4_u8r; + *v_gyro_off_z_s16 = v_data3_u8r + >> BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_zaxis( +s16 v_gyro_off_z_s16) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data1_u8r, v_data2_u8r = BMI160_INIT_VALUE; +u16 v_data3_u8r = BMI160_INIT_VALUE; +u8 v_status_s8 = SUCCESS; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* enable gyro offset*/ + v_status_s8 = bmi160_set_gyro_offset_enable( + GYRO_OFFSET_ENABLE); + /* write gyro manual offset z axis*/ + if (v_status_s8 == SUCCESS) { + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data1_u8r = + ((u8) (v_gyro_off_z_s16 & + BMI160_GYRO_MANUAL_OFFSET_0_7)); + v_data2_u8r = BMI160_SET_BITSLICE( + v_data2_u8r, + BMI160_USER_OFFSET_5_GYRO_OFF_Z, + v_data1_u8r); + /* write 0x76 bit 0 to 7*/ + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG, + &v_data2_u8r, + BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + + com_rslt += p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u8r = + (u16) (v_gyro_off_z_s16 & + BMI160_GYRO_MANUAL_OFFSET_8_9); + v_data1_u8r = (u8)(v_data3_u8r + >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = BMI160_SET_BITSLICE( + v_data2_u8r, + BMI160_USER_OFFSET_6_GYRO_OFF_Z, + v_data1_u8r); + /* write 0x77 bit 4 and 5*/ + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG, + &v_data2_u8r, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_enable( +u8 *v_accel_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read accel offset enable */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_accel_off_enable_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_enable( +u8 v_accel_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write accel offset enable */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE, + v_accel_off_enable_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_enable( +u8 *v_gyro_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read gyro offset*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_gyro_off_enable_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_enable( +u8 v_gyro_off_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write gyro offset*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_OFFSET_6_GYRO_OFF_EN, + v_gyro_off_enable_u8); + com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG, + &v_data_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_step_count(s16 *v_step_cnt_s16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_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[BMI160_STEP_COUNT_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read step counter */ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STEP_COUNT_LSB__REG, + a_data_u8r, BMI160_STEP_COUNTER_LENGTH); + + *v_step_cnt_s16 = (s16) + ((((s32)((s8)a_data_u8r[BMI160_STEP_COUNT_MSB_BYTE])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8r[BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_config( +u16 *v_step_config_u16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data1_u8r = BMI160_INIT_VALUE; + u8 v_data2_u8r = BMI160_INIT_VALUE; + u16 v_data3_u8r = BMI160_INIT_VALUE; + /* Read the 0 to 7 bit*/ + com_rslt = + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ZERO__REG, + &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* Read the 8 to 10 bit*/ + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ONE_CNF1__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r, + BMI160_USER_STEP_CONFIG_ONE_CNF1); + v_data3_u8r = ((u16)((((u32) + ((u8)v_data2_u8r)) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | (v_data1_u8r))); + /* Read the 11 to 14 bit*/ + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ONE_CNF2__REG, + &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r, + BMI160_USER_STEP_CONFIG_ONE_CNF2); + *v_step_config_u16 = ((u16)((((u32) + ((u8)v_data1_u8r)) + << BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_config( +u16 v_step_config_u16) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data1_u8r = BMI160_INIT_VALUE; + u8 v_data2_u8r = BMI160_INIT_VALUE; + u16 v_data3_u16 = BMI160_INIT_VALUE; + + /* write the 0 to 7 bit*/ + v_data1_u8r = (u8)(v_step_config_u16 & + BMI160_STEP_CONFIG_0_7); + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ZERO__REG, + &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* write the 8 to 10 bit*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ONE_CNF1__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u16 = (u16) (v_step_config_u16 & + BMI160_STEP_CONFIG_8_10); + v_data1_u8r = (u8)(v_data3_u16 + >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS); + v_data2_u8r = BMI160_SET_BITSLICE(v_data2_u8r, + BMI160_USER_STEP_CONFIG_ONE_CNF1, v_data1_u8r); + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ONE_CNF1__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + /* write the 11 to 14 bit*/ + com_rslt += p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ONE_CNF2__REG, + &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data3_u16 = (u16) (v_step_config_u16 & + BMI160_STEP_CONFIG_11_14); + v_data1_u8r = (u8)(v_data3_u16 + >> BMI160_SHIFT_BIT_POSITION_BY_12_BITS); + v_data2_u8r = BMI160_SET_BITSLICE(v_data2_u8r, + BMI160_USER_STEP_CONFIG_ONE_CNF2, v_data1_u8r); + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_ONE_CNF2__REG, + &v_data2_u8r, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_counter_enable( +u8 *v_step_counter_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the step counter */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_step_counter_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_counter_enable(u8 v_step_counter_u8) +{ +/* variable used for return the status of communication result*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_data_u8 = BMI160_INIT_VALUE; +/* check the p_bmi160 structure as NULL*/ +if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; +} else { + if (v_step_counter_u8 <= BMI160_MAX_GYRO_STEP_COUNTER) { + /* write the step counter */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE, + v_step_counter_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 | BMI160_STEP_NORMAL_MODE + * 1 | BMI160_STEP_SENSITIVE_MODE + * 2 | BMI160_STEP_ROBUST_MODE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_mode(u8 v_step_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + + switch (v_step_mode_u8) { + case BMI160_STEP_NORMAL_MODE: + com_rslt = bmi160_set_step_config( + STEP_CONFIG_NORMAL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_STEP_SENSITIVE_MODE: + com_rslt = bmi160_set_step_config( + STEP_CONFIG_SENSITIVE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_STEP_ROBUST_MODE: + com_rslt = bmi160_set_step_config( + STEP_CONFIG_ROBUST); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_BMI160_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 | BMI160_MAP_INTR1 + * 1 | BMI160_MAP_INTR2 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_map_significant_motion_intr( +u8 v_significant_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_sig_motion_u8 = BMI160_INIT_VALUE; + u8 v_data_u8 = BMI160_INIT_VALUE; + u8 v_any_motion_intr1_stat_u8 = BMI160_ENABLE_ANY_MOTION_INTR1; + u8 v_any_motion_intr2_stat_u8 = BMI160_ENABLE_ANY_MOTION_INTR2; + u8 v_any_motion_axis_stat_u8 = BMI160_ENABLE_ANY_MOTION_AXIS; + /* enable the significant motion interrupt */ + com_rslt = bmi160_get_intr_significant_motion_select(&v_sig_motion_u8); + if (v_sig_motion_u8 != BMI160_SIG_MOTION_STAT_HIGH) + com_rslt += bmi160_set_intr_significant_motion_select( + BMI160_SIG_MOTION_INTR_ENABLE); + switch (v_significant_u8) { + case BMI160_MAP_INTR1: + /* interrupt */ + com_rslt += bmi160_read_reg( + BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_intr1_stat_u8; + /* map the signification interrupt to any-motion interrupt1*/ + com_rslt += bmi160_write_reg( + BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* axis*/ + com_rslt = bmi160_read_reg(BMI160_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_axis_stat_u8; + com_rslt += bmi160_write_reg( + BMI160_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + + case BMI160_MAP_INTR2: + /* map the signification interrupt to any-motion interrupt2*/ + com_rslt += bmi160_read_reg( + BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_intr2_stat_u8; + com_rslt += bmi160_write_reg( + BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* axis*/ + com_rslt = bmi160_read_reg(BMI160_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_any_motion_axis_stat_u8; + com_rslt += bmi160_write_reg( + BMI160_USER_INTR_ENABLE_0_ADDR, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + + default: + com_rslt = E_BMI160_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 | BMI160_MAP_INTR1 + * 1 | BMI160_MAP_INTR2 + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_map_step_detector_intr( +u8 v_step_detector_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_step_det_u8 = BMI160_INIT_VALUE; + u8 v_data_u8 = BMI160_INIT_VALUE; + u8 v_low_g_intr_u81_stat_u8 = BMI160_LOW_G_INTR_STAT; + u8 v_low_g_intr_u82_stat_u8 = BMI160_LOW_G_INTR_STAT; + u8 v_low_g_enable_u8 = BMI160_ENABLE_LOW_G; + /* read the v_status_s8 of step detector interrupt*/ + com_rslt = bmi160_get_step_detector_enable(&v_step_det_u8); + if (v_step_det_u8 != BMI160_STEP_DET_STAT_HIGH) + com_rslt += bmi160_set_step_detector_enable( + BMI160_STEP_DETECT_INTR_ENABLE); + switch (v_step_detector_u8) { + case BMI160_MAP_INTR1: + com_rslt += bmi160_read_reg( + BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, BMI160_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 += bmi160_write_reg( + BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Enable the Low-g interrupt*/ + com_rslt = bmi160_read_reg( + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_low_g_enable_u8; + com_rslt += bmi160_write_reg( + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_MAP_INTR2: + /* map the step detector interrupt + to Low-g interrupt 1*/ + com_rslt += bmi160_read_reg( + BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_low_g_intr_u82_stat_u8; + + com_rslt += bmi160_write_reg( + BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Enable the Low-g interrupt*/ + com_rslt = bmi160_read_reg( + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_data_u8 |= v_low_g_enable_u8; + com_rslt += bmi160_write_reg( + BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_clear_step_counter(void) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* clear the step counter*/ + com_rslt = bmi160_set_command_register(RESET_STEP_COUNTER); + p_bmi160->delay_msec(BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_command_register(u8 v_command_reg_u8) +{ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write command register */ + com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC( + p_bmi160->dev_addr, + BMI160_CMD_COMMANDS__REG, + &v_command_reg_u8, BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_target_page(u8 *v_target_page_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the page*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_CMD_TARGET_PAGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_target_page_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_target_page(u8 v_target_page_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_target_page_u8 <= BMI160_MAX_TARGET_PAGE) { + /* write the page*/ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_CMD_TARGET_PAGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_CMD_TARGET_PAGE, + v_target_page_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_CMD_TARGET_PAGE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_paging_enable(u8 *v_page_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the page enable */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_CMD_PAGING_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_page_enable_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_paging_enable( +u8 v_page_enable_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + if (v_page_enable_u8 <= BMI160_MAX_VALUE_PAGE) { + /* write the page enable */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_CMD_PAGING_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_CMD_PAGING_EN, + v_page_enable_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_CMD_PAGING_EN__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + } + } else { + com_rslt = E_BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_get_pullup_configuration( +u8 *v_control_pullup_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read pull up value */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC( + p_bmi160->dev_addr, + BMI160_COM_C_TRIM_FIVE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + *v_control_pullup_u8 = BMI160_GET_BITSLICE(v_data_u8, + BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_pullup_configuration( +u8 v_control_pullup_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* write pull up value */ + com_rslt = p_bmi160->BMI160_BUS_READ_FUNC + (p_bmi160->dev_addr, + BMI160_COM_C_TRIM_FIVE__REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + if (com_rslt == SUCCESS) { + v_data_u8 = + BMI160_SET_BITSLICE(v_data_u8, + BMI160_COM_C_TRIM_FIVE, + v_control_pullup_u8); + com_rslt += + p_bmi160->BMI160_BUS_WRITE_FUNC + (p_bmi160->dev_addr, + BMI160_COM_C_TRIM_FIVE__REG, + &v_data_u8, BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_compensate_xyz( +struct bmi160_mag_xyz_s32_t *mag_comp_xyz) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + struct bmi160_mag_xyzr_t mag_xyzr; + com_rslt = bmi160_read_mag_xyzr(&mag_xyzr); + if (com_rslt) + return com_rslt; + /* Compensation for X axis */ + mag_comp_xyz->x = bmi160_bmm150_mag_compensate_X( + mag_xyzr.x, mag_xyzr.r); + + /* Compensation for Y axis */ + mag_comp_xyz->y = bmi160_bmm150_mag_compensate_Y( + mag_xyzr.y, mag_xyzr.r); + + /* Compensation for Z axis */ + mag_comp_xyz->z = bmi160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_compensate_xyz_raw( +struct bmi160_mag_xyz_s32_t *mag_comp_xyz, struct bmi160_mag_xyzr_t mag_xyzr) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + + /* Compensation for X axis */ + mag_comp_xyz->x = bmi160_bmm150_mag_compensate_X( + mag_xyzr.x, mag_xyzr.r); + + /* Compensation for Y axis */ + mag_comp_xyz->y = bmi160_bmm150_mag_compensate_Y( + mag_xyzr.y, mag_xyzr.r); + + /* Compensation for Z axis */ + mag_comp_xyz->z = bmi160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_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 bmi160_bmm150_mag_compensate_X(s16 v_mag_data_x_s16, u16 v_data_r_u16) +{ +s32 inter_retval = BMI160_INIT_VALUE; +/* no overflow */ +if (v_mag_data_x_s16 != BMI160_MAG_FLIP_OVERFLOW_ADCVAL) { + if ((v_data_r_u16 != 0) + && (mag_trim.dig_xyz1 != 0)) { + inter_retval = ((s32)(((u16) + ((((s32)mag_trim.dig_xyz1) + << BMI160_SHIFT_BIT_POSITION_BY_14_BITS)/ + (v_data_r_u16 != 0 ? + v_data_r_u16 : mag_trim.dig_xyz1))) - + ((u16)0x4000))); + } else { + inter_retval = BMI160_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)) + >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) + + (((s32)inter_retval) * + ((s32)(((s16)mag_trim.dig_xy1) + << BMI160_SHIFT_BIT_POSITION_BY_07_BITS)))) + >> BMI160_SHIFT_BIT_POSITION_BY_09_BITS) + + ((s32)0x100000)) * + ((s32)(((s16)mag_trim.dig_x2) + + ((s16)0xA0)))) + >> BMI160_SHIFT_BIT_POSITION_BY_12_BITS)) + >> BMI160_SHIFT_BIT_POSITION_BY_13_BITS)) + + (((s16)mag_trim.dig_x1) + << BMI160_SHIFT_BIT_POSITION_BY_03_BITS); + /* check the overflow output */ + if (inter_retval == (s32)BMI160_MAG_OVERFLOW_OUTPUT) + inter_retval = BMI160_MAG_OVERFLOW_OUTPUT_S32; +} else { + /* overflow */ + inter_retval = BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_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 bmi160_bmm150_mag_compensate_Y(s16 v_mag_data_y_s16, u16 v_data_r_u16) +{ +s32 inter_retval = BMI160_INIT_VALUE; +/* no overflow */ +if (v_mag_data_y_s16 != BMI160_MAG_FLIP_OVERFLOW_ADCVAL) { + if ((v_data_r_u16 != 0) + && (mag_trim.dig_xyz1 != 0)) { + inter_retval = ((s32)(((u16)((( + (s32)mag_trim.dig_xyz1) + << BMI160_SHIFT_BIT_POSITION_BY_14_BITS) / + (v_data_r_u16 != 0 ? + v_data_r_u16 : mag_trim.dig_xyz1))) - + ((u16)0x4000))); + } else { + inter_retval = BMI160_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)) >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) + + (((s32)inter_retval) * + ((s32)(((s16)mag_trim.dig_xy1) + << BMI160_SHIFT_BIT_POSITION_BY_07_BITS)))) + >> BMI160_SHIFT_BIT_POSITION_BY_09_BITS) + + ((s32)0x100000)) + * ((s32)(((s16)mag_trim.dig_y2) + + ((s16)0xA0)))) + >> BMI160_SHIFT_BIT_POSITION_BY_12_BITS)) + >> BMI160_SHIFT_BIT_POSITION_BY_13_BITS)) + + (((s16)mag_trim.dig_y1) + << BMI160_SHIFT_BIT_POSITION_BY_03_BITS); + /* check the overflow output */ + if (inter_retval == (s32)BMI160_MAG_OVERFLOW_OUTPUT) + inter_retval = BMI160_MAG_OVERFLOW_OUTPUT_S32; +} else { + /* overflow */ + inter_retval = BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_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 bmi160_bmm150_mag_compensate_Z(s16 v_mag_data_z_s16, u16 v_data_r_u16) +{ + s32 retval = BMI160_INIT_VALUE; + + if (v_mag_data_z_s16 != BMI160_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)) + << BMI160_SHIFT_BIT_POSITION_BY_15_BITS) - + ((((s32)mag_trim.dig_z3) * + ((s32)(((s16)v_data_r_u16) - + ((s16)mag_trim.dig_xyz1)))) + >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS))/ + (mag_trim.dig_z2 + + ((s16)(((((s32)mag_trim.dig_z1) * + ((((s16)v_data_r_u16) + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT))) + + (1 << BMI160_SHIFT_BIT_POSITION_BY_15_BITS)) + >> BMI160_SHIFT_BIT_POSITION_BY_16_BITS)))); + } + } else { + retval = BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_interface_init(void) +{ + /* This variable used for provide the communication + results*/ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + u8 v_pull_value_u8 = BMI160_INIT_VALUE; + u8 v_data_u8 = BMI160_INIT_VALUE; + /* accel operation mode to normal*/ + com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* write the mag power mode as NORMAL*/ + com_rslt += bmi160_set_mag_interface_normal(); + + /* register 0x7E write the 0x37, 0x9A and 0x30*/ + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_ONE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_TWO); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_THREE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /*switch the page1*/ + com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_target_page(&v_data_u8); + com_rslt += bmi160_set_paging_enable(BMI160_WRITE_ENABLE_PAGE1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_paging_enable(&v_data_u8); + /* enable the pullup configuration from + the register 0x05 bit 4 and 5 as 10*/ + bmi160_get_pullup_configuration(&v_pull_value_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + v_pull_value_u8 = v_pull_value_u8 | BMI160_PULL_UP_DATA; + com_rslt += bmi160_set_pullup_configuration(v_pull_value_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /*switch the page0*/ + com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE0); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_target_page(&v_data_u8); + /* Write the BMM150 i2c address*/ + com_rslt += bmi160_set_i2c_device_addr(BMI160_AUX_BMM150_I2C_ADDRESS); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* enable the mag interface to manual mode*/ + com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_mag_manual_enable(&v_data_u8); + /*Enable the MAG interface */ + com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_if_mode(&v_data_u8); + /* Mag normal mode*/ + com_rslt += bmi160_bmm150_mag_wakeup(); + printk(KERN_INFO "com_rslt:%d, <%s><%d>\n", + com_rslt, __func__, __LINE__); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Read the BMM150 device id is 0x32*/ + /*com_rslt += bmi160_set_mag_read_addr(BMI160_BMM150_CHIP_ID);*/ + /*p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);*/ + /*com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);*/ + /**v_chip_id_u8 = v_data_u8;*/ + /*p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);*/ + /* write the power mode register*/ + com_rslt += bmi160_set_mag_write_data(BMI160_BMM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /*write 0x4C register to write set power mode to normal*/ + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_MODE_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* read the mag trim values*/ + com_rslt += bmi160_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 = BMI160_MANUAL_ENABLE; + /* write the XY and Z repetitions*/ + com_rslt += bmi160_set_bmm150_mag_presetmode( + BMI160_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 = BMI160_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 += bmi160_set_mag_write_data(BMI160_BMM150_FORCE_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + printk(KERN_INFO "com_rslt:%d, <%s><%d>\n", + com_rslt, __func__, __LINE__); + /* write into power mode register*/ + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_MODE_REG); + /* write the mag v_data_bw_u8 as 25Hz*/ + com_rslt += bmi160_set_mag_output_data_rate( + BMI160_MAG_OUTPUT_DATA_RATE_25HZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + /* When mag interface is auto mode - The mag read address + starts the register 0x42*/ + com_rslt += bmi160_set_mag_read_addr( + BMI160_BMM150_DATA_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* enable mag interface to auto mode*/ + com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_mag_manual_enable(&v_data_u8); + p_bmi160->delay_msec(BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_wakeup(void) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + u8 v_try_times_u8 = BMI160_BMM150_MAX_RETRY_WAKEUP; + u8 v_power_control_bit_u8 = BMI160_INIT_VALUE; + u8 i = BMI160_INIT_VALUE; + + for (i = BMI160_INIT_VALUE; i < v_try_times_u8; i++) { + com_rslt = bmi160_set_mag_write_data(BMI160_BMM150_POWER_ON); + p_bmi160->delay_msec(BMI160_BMM150_WAKEUP_DELAY1); + /*write 0x4B register to enable power control bit*/ + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_CONTROL_REG); + p_bmi160->delay_msec(BMI160_BMM150_WAKEUP_DELAY2); + com_rslt += bmi160_set_mag_read_addr( + BMI160_BMM150_POWE_CONTROL_REG); + /* 0x04 is secondary read mag x lsb register */ + p_bmi160->delay_msec(BMI160_BMM150_WAKEUP_DELAY3); + com_rslt += bmi160_read_reg(BMI160_USER_DATA_0_ADDR, + &v_power_control_bit_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + v_power_control_bit_u8 = BMI160_BMM150_SET_POWER_CONTROL + & v_power_control_bit_u8; + if (v_power_control_bit_u8 == BMI160_BMM150_POWER_ON) + break; + } + com_rslt = (i >= v_try_times_u8) ? + BMI160_BMM150_POWER_ON_FAIL : BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * + * @param v_mag_sec_if_pow_mode_u8 : The value of mag power mode + * value | mode + * ----------|------------ + * 0 | BMI160_MAG_FORCE_MODE + * 1 | BMI160_MAG_SUSPEND_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + /* set the accel power mode to NORMAL*/ + com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + /* set mag interface manual mode*/ + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) { + com_rslt += bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + + switch (v_mag_sec_if_pow_mode_u8) { + case BMI160_MAG_FORCE_MODE: + /* set the secondary mag power mode as NORMAL*/ + com_rslt += bmi160_set_mag_interface_normal(); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + /* set the mag power mode as FORCE mode*/ + com_rslt += bmi160_bmm150_mag_set_power_mode(FORCE_MODE); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_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_bmi160->mag_manual_enable, __func__, __LINE__); + com_rslt += bmi160_bmm150_mag_set_power_mode(SUSPEND_MODE); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* set the secondary mag power mode as SUSPEND*/ + com_rslt += bmi160_set_command_register(MAG_MODE_SUSPEND); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_BMI160_OUT_OF_RANGE; + break; + } + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) { + /* set mag interface auto mode*/ + com_rslt += bmi160_set_mag_manual_enable( + BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_set_power_mode( +u8 v_mag_pow_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + u8 manual_enable_status = 0; + /* set mag interface manual mode*/ + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) { + com_rslt = bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_get_mag_manual_enable(&manual_enable_status); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + printk(KERN_INFO "1com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_bmi160->mag_manual_enable, manual_enable_status); + } + printk(KERN_INFO "2com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_bmi160->mag_manual_enable, manual_enable_status); + + switch (v_mag_pow_mode_u8) { + case FORCE_MODE: + /* Set the power control bit enabled */ + com_rslt = bmi160_bmm150_mag_wakeup(); + /* write the mag power mode as FORCE mode*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_BMM150_FORCE_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_MODE_REG); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* To avoid the auto mode enable when manual + mode operation running*/ + V_bmm150_maual_auto_condition_u8 = BMI160_MANUAL_ENABLE; + /* set the preset mode */ + com_rslt += bmi160_set_bmm150_mag_presetmode( + BMI160_MAG_PRESETMODE_REGULAR); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* To avoid the auto mode enable when manual + mode operation running*/ + V_bmm150_maual_auto_condition_u8 = BMI160_MANUAL_DISABLE; + /* set the mag read address to data registers*/ + com_rslt += bmi160_set_mag_read_addr( + BMI160_BMM150_DATA_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case SUSPEND_MODE: + printk(KERN_INFO "3com_rslt:%d, manual:%d, read_manual:%d\n", + com_rslt, p_bmi160->mag_manual_enable, manual_enable_status); + /* Set the power mode of mag as suspend mode*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_BMM150_POWER_OFF); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_CONTROL_REG); + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->mag_manual_enable, __func__, __LINE__); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_BMI160_OUT_OF_RANGE; + break; + } + printk(KERN_INFO "4com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_bmi160->mag_manual_enable, manual_enable_status); + /* set mag interface auto mode*/ + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) { + com_rslt += bmi160_set_mag_manual_enable( + BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_get_mag_manual_enable(&manual_enable_status); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "5com_rslt:%d, manual:%d, manual_read:%d\n", + com_rslt, p_bmi160->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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * + * @param v_mode_u8: The value of pre-set mode selection value + * value | pre_set mode + * ----------|------------ + * 1 | BMI160_MAG_PRESETMODE_LOWPOWER + * 2 | BMI160_MAG_PRESETMODE_REGULAR + * 3 | BMI160_MAG_PRESETMODE_HIGHACCURACY + * 4 | BMI160_MAG_PRESETMODE_ENHANCED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_bmm150_mag_presetmode(u8 v_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + switch (v_mode_u8) { + case BMI160_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 = bmi160_set_mag_write_data( + BMI160_MAG_LOWPOWER_REPXY); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_XY_REP); + p_bmi160->delay_msec(BMI160_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 += bmi160_set_mag_write_data( + BMI160_MAG_LOWPOWER_REPZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_Z_REP); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 10 to the register 0x4C*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_MAG_LOWPOWER_DR); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_MODE_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_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 = bmi160_set_mag_write_data( + BMI160_MAG_REGULAR_REPXY); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_XY_REP); + p_bmi160->delay_msec(BMI160_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 += bmi160_set_mag_write_data( + BMI160_MAG_REGULAR_REPZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_Z_REP); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 10 to the register 0x4C*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_MAG_REGULAR_DR); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_MODE_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_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 = bmi160_set_mag_write_data( + BMI160_MAG_HIGHACCURACY_REPXY); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_XY_REP); + p_bmi160->delay_msec(BMI160_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 += bmi160_set_mag_write_data( + BMI160_MAG_HIGHACCURACY_REPZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_Z_REP); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 20 to the register 0x4C*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_MAG_HIGHACCURACY_DR); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_MODE_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_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 = bmi160_set_mag_write_data( + BMI160_MAG_ENHANCED_REPXY); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_XY_REP); + p_bmi160->delay_msec(BMI160_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 += bmi160_set_mag_write_data( + BMI160_MAG_ENHANCED_REPZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_Z_REP); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* set the mag v_data_u8 rate as 10 to the register 0x4C*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_MAG_ENHANCED_DR); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + BMI160_BMM150_POWE_MODE_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note + * 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_bmm150_mag_trim(void) +{ + /* This variable used for provide the communication + results*/ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* Array holding the bmm150 trim data + */ + u8 v_data_u8[BMI160_MAG_TRIM_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE}; + /* read dig_x1 value */ + com_rslt = bmi160_set_mag_read_addr( + BMI160_MAG_DIG_X1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_X1], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_x1 = v_data_u8[BMI160_BMM150_DIG_X1]; + /* read dig_y1 value */ + com_rslt += bmi160_set_mag_read_addr( + BMI160_MAG_DIG_Y1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_Y1], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_y1 = v_data_u8[BMI160_BMM150_DIG_Y1]; + + /* read dig_x2 value */ + com_rslt += bmi160_set_mag_read_addr( + BMI160_MAG_DIG_X2); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_X2], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_x2 = v_data_u8[BMI160_BMM150_DIG_X2]; + /* read dig_y2 value */ + com_rslt += bmi160_set_mag_read_addr( + BMI160_MAG_DIG_Y2); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_Y3], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_y2 = v_data_u8[BMI160_BMM150_DIG_Y3]; + + /* read dig_xy1 value */ + com_rslt += bmi160_set_mag_read_addr( + BMI160_MAG_DIG_XY1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_XY1], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_xy1 = v_data_u8[BMI160_BMM150_DIG_XY1]; + /* read dig_xy2 value */ + com_rslt += bmi160_set_mag_read_addr( + BMI160_MAG_DIG_XY2); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 ls register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_XY2], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_xy2 = v_data_u8[BMI160_BMM150_DIG_XY2]; + + /* read dig_z1 lsb value */ + com_rslt += bmi160_set_mag_read_addr( + BMI160_MAG_DIG_Z1_LSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_Z1_LSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* read dig_z1 msb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z1_MSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_Z1_MSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_z1 = + (u16)((((u32)((u8)v_data_u8[BMI160_BMM150_DIG_Z1_MSB])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_BMM150_DIG_Z1_LSB])); + + /* read dig_z2 lsb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z2_LSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_Z2_LSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* read dig_z2 msb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z2_MSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_Z2_MSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_z2 = + (s16)((((s32)((s8)v_data_u8[BMI160_BMM150_DIG_Z2_MSB])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_BMM150_DIG_Z2_LSB])); + + /* read dig_z3 lsb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z3_LSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_DIG_Z3_LSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* read dig_z3 msb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z3_MSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_DIG_Z3_MSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_z3 = + (s16)((((s32)((s8)v_data_u8[BMI160_BMM150_DIG_DIG_Z3_MSB])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_BMM150_DIG_DIG_Z3_LSB])); + + /* read dig_z4 lsb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z4_LSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_DIG_Z4_LSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* read dig_z4 msb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z4_MSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_DIG_Z4_MSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_z4 = + (s16)((((s32)((s8)v_data_u8[BMI160_BMM150_DIG_DIG_Z4_MSB])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_BMM150_DIG_DIG_Z4_LSB])); + + /* read dig_xyz1 lsb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_XYZ1_LSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_DIG_XYZ1_LSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* read dig_xyz1 msb value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_XYZ1_MSB); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is v_mag_x_s16 msb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[BMI160_BMM150_DIG_DIG_XYZ1_MSB], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + mag_trim.dig_xyz1 = + (u16)((((u32)((u8)v_data_u8[BMI160_BMM150_DIG_DIG_XYZ1_MSB])) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | + (v_data_u8[BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm_mag_interface_init( +u8 v_akm_i2c_address_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_pull_value_u8 = BMI160_INIT_VALUE; + u8 v_data_u8 = BMI160_INIT_VALUE; + u8 v_akm_chip_id_u8 = BMI160_INIT_VALUE; + /* accel operation mode to normal*/ + com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_command_register(MAG_MODE_NORMAL); + p_bmi160->delay_msec(BMI160_AKM_INIT_DELAY); + bmi160_get_mag_power_mode_stat(&v_data_u8); + /* register 0x7E write the 0x37, 0x9A and 0x30*/ + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_ONE); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_TWO); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_THREE); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /*switch the page1*/ + com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_target_page(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_paging_enable(BMI160_WRITE_ENABLE_PAGE1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_paging_enable(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* enable the pullup configuration from + the register 0x05 bit 4 and 5 to 10*/ + bmi160_get_pullup_configuration(&v_pull_value_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + v_pull_value_u8 = v_pull_value_u8 | BMI160_PULL_UP_DATA; + com_rslt += bmi160_set_pullup_configuration(v_pull_value_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + /*switch the page0*/ + com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE0); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_target_page(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Write the AKM09911 0r AKM09912 i2c address*/ + com_rslt += bmi160_set_i2c_device_addr(v_akm_i2c_address_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* enable the mag interface to manual mode*/ + com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_mag_manual_enable(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /*Enable the MAG interface */ + com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_if_mode(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + /* Set the AKM Fuse ROM mode */ + /* Set value for fuse ROM mode*/ + com_rslt += bmi160_set_mag_write_data(AKM_FUSE_ROM_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* AKM mode address is 0x31*/ + com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_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 += bmi160_read_bst_akm_sensitivity_data(); + p_bmi160->delay_msec(BMI160_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 += bmi160_set_mag_read_addr(AKM09912_CHIP_ID_REG); + /* 0x04 is mag_x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_akm_chip_id_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + printk(KERN_INFO "bmi160,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 += bmi160_set_mag_write_data(AKM_POWER_DOWN_MODE_DATA); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* AKM mode address is 0x31*/ + com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Set AKM Force mode*/ + com_rslt += bmi160_set_mag_write_data( + AKM_SINGLE_MEASUREMENT_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* AKM mode address is 0x31*/ + com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Set the AKM read xyz v_data_u8 address*/ + com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER); + /* write the mag v_data_bw_u8 as 25Hz*/ + com_rslt += bmi160_set_mag_output_data_rate( + BMI160_MAG_OUTPUT_DATA_RATE_25HZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Enable mag interface to auto mode*/ + com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_mag_manual_enable(&v_data_u8); + p_bmi160->delay_msec(BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_bst_akm_sensitivity_data(void) +{ + /* This variable used for provide the communication + results*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* Array holding the sensitivity ax,ay and az data*/ + u8 v_data_u8[BMI160_AKM_SENSITIVITY_DATA_SIZE] = { + BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* read asax value */ + com_rslt = bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAX); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[AKM_ASAX], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + akm_asa_data.asax = v_data_u8[AKM_ASAX]; + /* read asay value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAY); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[AKM_ASAY], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + akm_asa_data.asay = v_data_u8[AKM_ASAY]; + /* read asaz value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[AKM_ASAZ], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * + * @param v_bst_akm_x_s16 : The value of X data + * + * @return results of compensated X data value output as s32 + * + */ +s32 bmi160_bst_akm09911_compensate_X(s16 v_bst_akm_x_s16) +{ + /*Return value of AKM x compensated v_data_u8*/ + s32 retval = BMI160_INIT_VALUE; + /* Convert raw v_data_u8 into compensated v_data_u8*/ + retval = (v_bst_akm_x_s16 * + ((akm_asa_data.asax/AKM09911_SENSITIVITY_DIV) + + BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * + * @param v_bst_akm_y_s16 : The value of Y data + * + * @return results of compensated Y data value output as s32 + * + */ +s32 bmi160_bst_akm09911_compensate_Y(s16 v_bst_akm_y_s16) +{ + /*Return value of AKM y compensated v_data_u8*/ + s32 retval = BMI160_INIT_VALUE; + /* Convert raw v_data_u8 into compensated v_data_u8*/ + retval = (v_bst_akm_y_s16 * + ((akm_asa_data.asay/AKM09911_SENSITIVITY_DIV) + + BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * + * @param v_bst_akm_z_s16 : The value of Z data + * + * @return results of compensated Z data value output as s32 + * + */ +s32 bmi160_bst_akm09911_compensate_Z(s16 v_bst_akm_z_s16) +{ + /*Return value of AKM z compensated v_data_u8*/ + s32 retval = BMI160_INIT_VALUE; + /* Convert raw v_data_u8 into compensated v_data_u8*/ + retval = (v_bst_akm_z_s16 * + ((akm_asa_data.asaz/AKM09911_SENSITIVITY_DIV) + + BMI160_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * + * @param v_bst_akm_x_s16 : The value of X data + * + * @return results of compensated X data value output as s32 + * + */ +s32 bmi160_bst_akm09912_compensate_X(s16 v_bst_akm_x_s16) +{ + /*Return value of AKM x compensated data*/ + s32 retval = BMI160_INIT_VALUE; + /* Convert raw data into compensated data*/ + retval = v_bst_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * + * @param v_bst_akm_y_s16 : The value of Y data + * + * @return results of compensated Y data value output as s32 + * + */ +s32 bmi160_bst_akm09912_compensate_Y(s16 v_bst_akm_y_s16) +{ + /*Return value of AKM y compensated data*/ + s32 retval = BMI160_INIT_VALUE; + /* Convert raw data into compensated data*/ + retval = v_bst_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + * + * + * @param v_bst_akm_z_s16 : The value of Z data + * + * @return results of compensated Z data value output as s32 + * + */ +s32 bmi160_bst_akm09912_compensate_Z(s16 v_bst_akm_z_s16) +{ + /*Return value of AKM z compensated data*/ + s32 retval = BMI160_INIT_VALUE; + /* Convert raw data into compensated data*/ + retval = v_bst_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm09911_compensate_xyz( +struct bmi160_mag_xyz_s32_t *bst_akm_xyz) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + struct bmi160_mag_t mag_xyz; + + com_rslt = bmi160_read_mag_xyz(&mag_xyz, BST_AKM); + /* Compensation for X axis */ + bst_akm_xyz->x = bmi160_bst_akm09911_compensate_X(mag_xyz.x); + + /* Compensation for Y axis */ + bst_akm_xyz->y = bmi160_bst_akm09911_compensate_Y(mag_xyz.y); + + /* Compensation for Z axis */ + bst_akm_xyz->z = bmi160_bst_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm09912_compensate_xyz( +struct bmi160_mag_xyz_s32_t *bst_akm_xyz) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + struct bmi160_mag_t mag_xyz; + + com_rslt = bmi160_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 */ + bst_akm_xyz->x = bmi160_bst_akm09912_compensate_X(mag_xyz.x); + + /* Compensation for Y axis */ + bst_akm_xyz->y = bmi160_bst_akm09912_compensate_Y(mag_xyz.y); + + /* Compensation for Z axis */ + bst_akm_xyz->z = bmi160_bst_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_set_command_register(0x19) function. + + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm09912_compensate_xyz_raw( +struct bmi160_mag_xyz_s32_t *bst_akm_xyz) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* Compensation for X axis */ + bst_akm_xyz->x = bmi160_bst_akm09912_compensate_X(bst_akm_xyz->x); + + /* Compensation for Y axis */ + bst_akm_xyz->y = bmi160_bst_akm09912_compensate_Y(bst_akm_xyz->y); + + /* Compensation for Z axis */ + bst_akm_xyz->z = bmi160_bst_akm09912_compensate_Z(bst_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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * @note 2. And also confirm the secondary-interface power mode + * is not in the SUSPEND mode. + * by using the function bmi160_get_mag_pmu_status(). + * If the secondary-interface power mode is in SUSPEND mode + * set the value of 0x19(NORMAL mode)by using the + * bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm_set_powermode( +u8 v_akm_pow_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + /* set mag interface manual mode*/ + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) { + com_rslt = bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s>\n", + com_rslt, p_bmi160->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 += bmi160_set_mag_write_data(AKM_POWER_DOWN_MODE_DATA); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + case AKM_SINGLE_MEAS_MODE: + /* Set the power mode of AKM as + single measurement mode*/ + com_rslt += bmi160_set_mag_write_data + (AKM_SINGLE_MEASUREMENT_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER); + break; + case FUSE_ROM_MODE: + /* Set the power mode of AKM as + Fuse ROM mode*/ + com_rslt += bmi160_set_mag_write_data(AKM_FUSE_ROM_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* Sensitivity v_data_u8 */ + com_rslt += bmi160_read_bst_akm_sensitivity_data(); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* power down mode*/ + com_rslt += bmi160_set_mag_write_data(AKM_POWER_DOWN_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_BMI160_OUT_OF_RANGE; + break; + } + /* set mag interface auto mode*/ + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) { + com_rslt += bmi160_set_mag_manual_enable( + BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + } + printk(KERN_INFO "com_rslt:%d, manual:%d, <%s><%d>\n", + com_rslt, p_bmi160->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 bmi160_get_if_mode() function. + * If mag interface is not enabled set the value of 0x02 + * to the function bmi160_get_if_mode(0x02) + * + * @param v_mag_sec_if_pow_mode_u8 : The value of secondary if power mode + * value | Description + * ---------|-------------------- + * 0 | BMI160_MAG_FORCE_MODE + * 1 | BMI160_MAG_SUSPEND_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_set_bst_akm_and_secondary_if_powermode( +u8 v_mag_sec_if_pow_mode_u8) +{ + /* variable used for return the status of communication result*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* accel operation mode to normal*/ + com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* set mag interface manual mode*/ + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) { + com_rslt = bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + } + printk(KERN_ERR "com_rslt:%d, manual:%d,after setacc normal mode\n", + com_rslt, p_bmi160->mag_manual_enable); + switch (v_mag_sec_if_pow_mode_u8) { + case BMI160_MAG_FORCE_MODE: + /* set the secondary mag power mode as NORMAL*/ + com_rslt += bmi160_set_mag_interface_normal(); + /* set the akm power mode as single measurement mode*/ + com_rslt += bmi160_bst_akm_set_powermode(AKM_SINGLE_MEAS_MODE); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + break; + case BMI160_MAG_SUSPEND_MODE: + /* set the akm power mode as power down mode*/ + com_rslt += bmi160_bst_akm_set_powermode(AKM_POWER_DOWN_MODE); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* set the secondary mag power mode as SUSPEND*/ + com_rslt += bmi160_set_command_register(MAG_MODE_SUSPEND); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + break; + default: + com_rslt = E_BMI160_OUT_OF_RANGE; + break; + } + /* set mag interface auto mode*/ + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) + com_rslt += bmi160_set_mag_manual_enable( + BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas532_mag_interface_init( +void) +{ + /* This variable used for provide the communication + results*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + u8 v_pull_value_u8 = BMI160_INIT_VALUE; + u8 v_data_u8 = BMI160_INIT_VALUE; + u8 i = BMI160_INIT_VALUE; + /* accel operation mode to normal*/ + com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* write mag power mode as NORMAL*/ + com_rslt += bmi160_set_mag_interface_normal(); + /* register 0x7E write the 0x37, 0x9A and 0x30*/ + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_ONE); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_TWO); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_THREE); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /*switch the page1*/ + com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_target_page(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_paging_enable(BMI160_WRITE_ENABLE_PAGE1); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_paging_enable(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* enable the pullup configuration from + the register 0x05 bit 4 and 5 as 10*/ + bmi160_get_pullup_configuration(&v_pull_value_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + v_pull_value_u8 = v_pull_value_u8 | BMI160_PULL_UP_DATA; + com_rslt += bmi160_set_pullup_configuration(v_pull_value_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /*switch the page0*/ + com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE0); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_target_page(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Write the YAS532 i2c address*/ + com_rslt += bmi160_set_i2c_device_addr(BMI160_AUX_YAS532_I2C_ADDRESS); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* enable the mag interface to manual mode*/ + com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_mag_manual_enable(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /*Enable the MAG interface */ + com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_if_mode(&v_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + v_data_u8 = BMI160_MANUAL_DISABLE; + /* Read the YAS532 device id is 0x02*/ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS_DEVICE_ID_REG); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Read the YAS532 calibration data*/ + com_rslt += bmi160_bst_yamaha_yas532_calib_values(); + p_bmi160->delay_msec(BMI160_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 = BMI160_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 += bmi160_bst_yas532_set_initial_values(); + /* write the mag v_data_bw_u8 as 25Hz*/ + com_rslt += bmi160_set_mag_output_data_rate( + BMI160_MAG_OUTPUT_DATA_RATE_25HZ); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Enable mag interface to auto mode*/ + com_rslt += bmi160_set_mag_manual_enable( + BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + bmi160_get_mag_manual_enable(&v_data_u8); + p_bmi160->delay_msec(BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_set_initial_values(void) +{ +/* This variable used for provide the communication + results*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* write testr1 as 0x00*/ + com_rslt = bmi160_set_mag_write_data( + BMI160_YAS532_WRITE_TESTR1); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_TESTR1); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write testr2 as 0x00*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_YAS532_WRITE_TESTR2); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_TESTR2); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write Rcoil as 0x00*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_YAS532_WRITE_RCOIL); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_RCOIL); + p_bmi160->delay_msec(BMI160_YAS532_SET_INITIAL_VALUE_DELAY); + /* check the valid offset*/ + if (is_valid_offset(yas532_data.v_hard_offset_s8)) { + com_rslt += bmi160_bst_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_magnetic_measure_set_offset( +void) +{ + /* This variable used for provide the communication + results*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* used for offset value set to the offset register*/ + s8 v_hard_offset_s8[BMI160_HARD_OFFSET_DATA_SIZE] = { + BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* offset correction factors*/ + static const u8 v_correct_u8[BMI160_YAS_CORRECT_DATA_SIZE] = { + 16, 8, 4, 2, 1}; + /* used for the temperature */ + u16 v_temp_u16 = BMI160_INIT_VALUE; + /* used for the xy1y2 read*/ + u16 v_xy1y2_u16[BMI160_YAS_XY1Y2_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* local flag for assign the values*/ + s32 v_flag_s32[BMI160_YAS_FLAG_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + u8 i, j, v_busy_u8, v_overflow_u8 = BMI160_INIT_VALUE; + + for (i = 0; i < 5; i++) { + /* set the offset values*/ + com_rslt = bmi160_bst_yas532_set_offset(v_hard_offset_s8); + /* read the sensor data*/ + com_rslt += bmi160_bst_yas532_normal_measurement_data( + BMI160_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_BMI160_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 += bmi160_bst_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas532_calib_values(void) +{ + /* This variable used for provide the communication + results*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* Array holding the YAS532 calibration values */ + u8 v_data_u8[BMI160_YAS532_CALIB_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* Read the DX value */ + com_rslt = bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CX); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[0], BMI160_GEN_READ_WRITE_DATA_LENGTH); + yas532_data.calib_yas532.cx = (s32)((v_data_u8[0] + * 10) - 1280); + /* Read the DY1 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CY1); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[1], BMI160_GEN_READ_WRITE_DATA_LENGTH); + yas532_data.calib_yas532.cy1 = + (s32)((v_data_u8[1] * 10) - 1280); + /* Read the DY2 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CY2); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[2], BMI160_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 += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB1); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[3], BMI160_GEN_READ_WRITE_DATA_LENGTH); + yas532_data.calib_yas532.a2 = + (s32)(((v_data_u8[3] >> + BMI160_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x03F) - 32); + /* Read the D3 and D4 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB2); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[4], BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a3*/ + yas532_data.calib_yas532.a3 = (s32)((((v_data_u8[3] << + BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x0C) | + ((v_data_u8[4] + >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS) + & 0x03)) - 8); + /* calculate a4*/ + yas532_data.calib_yas532.a4 = (s32)((v_data_u8[4] + & 0x3F) - 32); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* Read the D5 and D6 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB3); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[5], BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a5*/ + yas532_data.calib_yas532.a5 = + (s32)(((v_data_u8[5] + >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x3F) + 38); + /* Read the D6 and D7 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB4); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[6], BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a6*/ + yas532_data.calib_yas532.a6 = + (s32)((((v_data_u8[5] + << BMI160_SHIFT_BIT_POSITION_BY_04_BITS) + & 0x30) | ((v_data_u8[6] >> + BMI160_SHIFT_BIT_POSITION_BY_04_BITS) + & 0x0F)) - 32); + /* Read the D7 and D8 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB5); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[7], BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a7*/ + yas532_data.calib_yas532.a7 = (s32)((((v_data_u8[6] + << BMI160_SHIFT_BIT_POSITION_BY_03_BITS) + & 0x78) | + ((v_data_u8[7] + >> BMI160_SHIFT_BIT_POSITION_BY_05_BITS) & + 0x07)) - 64); + /* Read the D8 and D9 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CLAIB6); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[8], BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a8*/ + yas532_data.calib_yas532.a8 = (s32)((((v_data_u8[7] << + BMI160_GEN_READ_WRITE_DATA_LENGTH) & 0x3E) | + ((v_data_u8[8] >> + BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)) - + 32); + + /* Read the D8 and D9 value */ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB7); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[9], BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* calculate a9*/ + yas532_data.calib_yas532.a9 = (s32)(((v_data_u8[8] << + BMI160_GEN_READ_WRITE_DATA_LENGTH) & 0xFE) | + ((v_data_u8[9] >> + BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + /* calculate k*/ + yas532_data.calib_yas532.k = (s32)((v_data_u8[9] >> + BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x1F); + /* Read the value from register 0x9A*/ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB8); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[10], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* Read the value from register 0x9B*/ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIIB9); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[11], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* Read the value from register 0x9C*/ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB10); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[12], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* Read the value from register 0x9D*/ + com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB11); + /* 0x04 is secondary read mag x lsb register */ + com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, + &v_data_u8[13], + BMI160_GEN_READ_WRITE_DATA_LENGTH); + /* Calculate the fxy1y2 and rxy1y1*/ + yas532_data.calib_yas532.fxy1y2[0] = + (u8)(((v_data_u8[10] + & 0x01) + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) + | ((v_data_u8[11] >> + BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + yas532_data.calib_yas532.rxy1y2[0] = + ((s8)(((v_data_u8[10] + >> BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F) + << BMI160_SHIFT_BIT_POSITION_BY_02_BITS)) + >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS; + yas532_data.calib_yas532.fxy1y2[1] = + (u8)(((v_data_u8[11] & 0x01) + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) + | ((v_data_u8[12] >> + BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + yas532_data.calib_yas532.rxy1y2[1] = + ((s8)(((v_data_u8[11] + >> BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F) + << BMI160_SHIFT_BIT_POSITION_BY_02_BITS)) + >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS; + yas532_data.calib_yas532.fxy1y2[2] = + (u8)(((v_data_u8[12] & 0x01) + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) + | ((v_data_u8[13] + >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)); + yas532_data.calib_yas532.rxy1y2[2] = + ((s8)(((v_data_u8[12] + >> BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F) + << BMI160_SHIFT_BIT_POSITION_BY_02_BITS)) + >> BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_xy1y2_to_linear( +u16 *v_xy1y2_u16, s32 *xy1y2_linear) +{ + /* This variable used for provide the communication + results*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = SUCCESS; + static const u16 v_calib_data[] = { + 3721, 3971, 4221, 4471}; + u8 i = BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_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*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + /* Array holding the YAS532 xyy1 data*/ + u8 v_data_u8[BMI160_YAS_XY1Y2T_DATA_SIZE] = { + BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + u8 i = BMI160_INIT_VALUE; + /* check the p_bmi160 structure as NULL*/ + if (p_bmi160 == BMI160_NULL) { + return E_BMI160_NULL_PTR; + } else { + /* read the sensor data */ + com_rslt = bmi160_bst_yas532_acquisition_command_register( + v_acquisition_command_u8); + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_MAG_X_LSB__REG, + v_data_u8, BMI160_MAG_YAS_DATA_LENGTH); + /* read the xyy1 data*/ + *v_busy_u8 = + ((v_data_u8[0] + >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01); + *v_temp_u16 = + (u16)((((s32)v_data_u8[0] + << BMI160_SHIFT_BIT_POSITION_BY_03_BITS) + & 0x3F8) | ((v_data_u8[1] + >> BMI160_SHIFT_BIT_POSITION_BY_05_BITS) & 0x07)); + v_xy1y2_u16[0] = + (u16)((((s32)v_data_u8[2] + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) & 0x1FC0) + | ((v_data_u8[3] >> + BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F)); + v_xy1y2_u16[1] = + (u16)((((s32)v_data_u8[4] + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) + & 0x1FC0) + | ((v_data_u8[5] + >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F)); + v_xy1y2_u16[2] = + (u16)((((s32)v_data_u8[6] + << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) + & 0x1FC0) + | ((v_data_u8[7] + >> BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_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*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE; + /* Array holding the linear calculation output*/ + s32 v_xy1y2_linear_s32[BMI160_YAS_XY1Y2_DATA_SIZE] = { + BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* Array holding the temperature data */ + s32 v_xyz_tmp_s32[BMI160_YAS_TEMP_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + s32 tmp = BMI160_INIT_VALUE; + s32 sx, sy1, sy2, sy, sz = BMI160_INIT_VALUE; + u8 i, v_busy_u8 = BMI160_INIT_VALUE; + u16 v_temp_u16 = BMI160_INIT_VALUE; + /* Array holding the xyy1 sensor raw data*/ + u16 v_xy1y2_u16[BMI160_YAS_XY1Y2_DATA_SIZE] = {BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + #if YAS532_MAG_LOG < YAS532_MAG_TEMPERATURE_LOG + s32 sum = BMI160_INIT_VALUE; + #endif + *v_overflow_s8 = BMI160_INIT_VALUE; + switch (yas532_data.measure_state) { + case YAS532_MAG_STATE_INIT_COIL: + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) + com_rslt = bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + /* write Rcoil*/ + com_rslt += bmi160_set_mag_write_data( + BMI160_YAS_DISABLE_RCOIL); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_RCOIL); + p_bmi160->delay_msec(BMI160_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 = bmi160_bst_yas532_magnetic_measure_set_offset(); + yas532_data.measure_state = 0; + break; + default: + break; + } + /* Read sensor data*/ + com_rslt += bmi160_bst_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 += bmi160_bst_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 != BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_acquisition_command_register( +u8 v_command_reg_data_u8) +{ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) + com_rslt = bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + + com_rslt = bmi160_set_mag_write_data(v_command_reg_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* YAMAHA YAS532-0x82*/ + com_rslt += bmi160_set_mag_write_addr( + BMI160_YAS532_COMMAND_REGISTER); + p_bmi160->delay_msec(BMI160_YAS_ACQ_COMMAND_DELAY); + com_rslt += bmi160_set_mag_read_addr( + BMI160_YAS532_DATA_REGISTER); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) + com_rslt += bmi160_set_mag_manual_enable(BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_set_offset( +const s8 *p_offset_s8) +{ + /* This variable used for provide the communication + results*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) + com_rslt = bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_YAS532_OFFSET_DELAY); + + /* Write offset X data*/ + com_rslt = bmi160_set_mag_write_data(p_offset_s8[0]); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* YAS532 offset x write*/ + com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_X); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + /* Write offset Y data*/ + com_rslt = bmi160_set_mag_write_data(p_offset_s8[1]); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* YAS532 offset y write*/ + com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_Y); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + /* Write offset Z data*/ + com_rslt = bmi160_set_mag_write_data(p_offset_s8[2]); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* YAS532 offset z write*/ + com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_Z); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + set_vector(yas532_data.v_hard_offset_s8, p_offset_s8); + + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) + com_rslt = bmi160_set_mag_manual_enable(BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_mag_interface_init( +void) +{ +/* This variable used for provide the communication +results*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +u8 v_pull_value_u8 = BMI160_INIT_VALUE; +u8 v_data_u8 = BMI160_INIT_VALUE; +u8 i = BMI160_INIT_VALUE; +/* accel operation mode to normal*/ +com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* write mag power mode as NORMAL*/ +com_rslt += bmi160_set_mag_interface_normal(); +/* register 0x7E write the 0x37, 0x9A and 0x30*/ +com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_ONE); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_TWO); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_THREE); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/*switch the page1*/ +com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE1); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +bmi160_get_target_page(&v_data_u8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_paging_enable(BMI160_WRITE_ENABLE_PAGE1); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +bmi160_get_paging_enable(&v_data_u8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* enable the pullup configuration from +the register 0x05 bit 4 and 5 as 10*/ +bmi160_get_pullup_configuration(&v_pull_value_u8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +v_pull_value_u8 = v_pull_value_u8 | BMI160_PULL_UP_DATA; +com_rslt += bmi160_set_pullup_configuration(v_pull_value_u8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/*switch the page0*/ +com_rslt += bmi160_set_target_page(BMI160_WRITE_TARGET_PAGE0); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +bmi160_get_target_page(&v_data_u8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* Write the YAS532 i2c address*/ +com_rslt += bmi160_set_i2c_device_addr(BMI160_YAS537_I2C_ADDRESS); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* enable the mag interface to manual mode*/ +com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +bmi160_get_mag_manual_enable(&v_data_u8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/*Enable the MAG interface */ +com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +bmi160_get_if_mode(&v_data_u8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +v_data_u8 = BMI160_MANUAL_DISABLE; +/* Read the YAS537 device id*/ +com_rslt += bmi160_set_mag_read_addr(BMI160_YAS_DEVICE_ID_REG); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH); +yas537_data.dev_id = v_data_u8; +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* Read the YAS532 calibration data*/ +com_rslt += +bmi160_bst_yamaha_yas537_calib_values( +BMI160_GEN_READ_WRITE_DATA_LENGTH); +p_bmi160->delay_msec(BMI160_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 = BMI160_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 += bmi160_set_mag_output_data_rate( +BMI160_MAG_OUTPUT_DATA_RATE_25HZ); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* Enable mag interface to auto mode*/ +com_rslt += bmi160_set_mag_manual_enable( +BMI160_MANUAL_DISABLE); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +bmi160_get_mag_manual_enable(&v_data_u8); +p_bmi160->delay_msec(BMI160_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 +* +* +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_calib_values( +u8 v_rcoil_u8) +{ +/* This variable used for provide the communication +results*/ +BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; +/* Array holding the YAS532 calibration values */ +u8 a_data_u8[BMI160_YAS537_CALIB_DATA_SIZE] = { +BMI160_INIT_VALUE, BMI160_INIT_VALUE, +BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, +BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, +BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, +BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, +BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, +}; +static const u8 v_avrr_u8[] = {0x50, 0x60, 0x70}; +u8 v_cal_valid_u8 = BMI160_INIT_VALUE, i; +/* write soft reset as 0x02*/ +com_rslt = bmi160_set_mag_write_data( +YAS537_SRSTR_DATA); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_mag_write_addr(YAS537_REG_SRSTR); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* Read the DX value */ +com_rslt = bmi160_set_mag_read_addr(YAS537_REG_CALR_C0); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[0], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the DY1 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C1); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[1], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the DY2 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C2); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[2], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D2 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C3); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[3], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D3 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C4); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[4], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D4 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C5); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[5], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D5 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C6); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[6], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D6 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C7); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[7], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D7 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C8); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[8], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D8 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C9); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[9], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the D9 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CA); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[10], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RX value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CB); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[11], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RY1 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CC); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[12], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RY2 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CD); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[13], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the RY2 value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CE); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[14], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the CHF value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CF); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[15], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* Read the VER value */ +com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_DO); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +/* 0x04 is secondary read mag x lsb register */ +com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG, +&a_data_u8[16], BMI160_GEN_READ_WRITE_DATA_LENGTH); +/* get the calib ver*/ +yas537_data.calib_yas537.ver = +(a_data_u8[16] >> BMI160_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 += bmi160_set_mag_write_data( + a_data_u8[i]); + p_bmi160->delay_msec( + BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + YAS537_REG_MTCR + i); + p_bmi160->delay_msec( + BMI160_GEN_READ_WRITE_DELAY); + } else if (i < 15) { + /* write offset correction*/ + com_rslt += bmi160_set_mag_write_data( + a_data_u8[i]); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(( + (YAS537_REG_OXR + i) - 12)); + p_bmi160->delay_msec( + BMI160_GEN_READ_WRITE_DELAY); + yas537_data.hard_offset[i - 12] + = a_data_u8[i]; + } else { + /* write offset correction*/ + com_rslt += bmi160_set_mag_write_data( + a_data_u8[i]); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(( + (YAS537_REG_OXR + i) - 11)); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + } + +} +} else if (yas537_data.calib_yas537.ver == 1) { + for (i = 0; i < 3; i++) { + /* write offset*/ + com_rslt += bmi160_set_mag_write_data( + a_data_u8[i]); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + YAS537_REG_MTCR + i); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + if (com_rslt == SUCCESS) { + /* write offset*/ + com_rslt += bmi160_set_mag_write_data( + a_data_u8[i + 12]); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + YAS537_REG_OXR + i); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + yas537_data.hard_offset[i] = + a_data_u8[i + 12]; + } else { + com_rslt = ERROR; + } + } + /* write offset*/ + com_rslt += bmi160_set_mag_write_data( + ((a_data_u8[i] & 0xE0) | 0x10)); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr( + YAS537_REG_MTCR + i); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write offset*/ + com_rslt += bmi160_set_mag_write_data( + ((a_data_u8[15] + >> BMI160_SHIFT_BIT_POSITION_BY_03_BITS) + & 0x1E)); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(YAS537_REG_HCKR); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write offset*/ + com_rslt += bmi160_set_mag_write_data( + ((a_data_u8[15] << 1) & 0x1E)); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(YAS537_REG_LCKR); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + /* write offset*/ + com_rslt += bmi160_set_mag_write_data( + (a_data_u8[16] & 0x3F)); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(YAS537_REG_OCR); + p_bmi160->delay_msec( + BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + + /* Assign the calibration values*/ + /* a2 */ + yas537_data.calib_yas537.a2 = + ((((a_data_u8[3] + << BMI160_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x7C) + | (a_data_u8[4] + >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS)) - 64); + /* a3 */ + yas537_data.calib_yas537.a3 = + ((((a_data_u8[4] << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) + & 0x7E) + | (a_data_u8[5] + >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) - 64); + /* a4 */ + yas537_data.calib_yas537.a4 = + ((((a_data_u8[5] + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) + & 0xFE) + | (a_data_u8[6] + >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) + - 128); + /* a5 */ + yas537_data.calib_yas537.a5 = + ((((a_data_u8[6] + << BMI160_SHIFT_BIT_POSITION_BY_02_BITS) + & 0x1FC) + | (a_data_u8[7] + >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS)) + - 112); + /* a6 */ + yas537_data.calib_yas537.a6 = + ((((a_data_u8[7] + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) + & 0x7E) + | (a_data_u8[8] + >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) - 64); + /* a7 */ + yas537_data.calib_yas537.a7 = + ((((a_data_u8[8] + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) + & 0xFE) + | (a_data_u8[9] + >> BMI160_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] + << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x1FE) + | (a_data_u8[11] + >> BMI160_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 += bmi160_set_mag_write_data( +YAS537_WRITE_A_D_CONVERTER); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_mag_write_addr(YAS537_REG_ADCCALR); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* write A/D converter second register*/ +com_rslt += bmi160_set_mag_write_data( +YAS537_WRITE_A_D_CONVERTER2); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_mag_write_addr(YAS537_REG_ADCCALR_ONE); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* write temperature calibration register*/ +com_rslt += bmi160_set_mag_write_data(YAS537_WRITE_TEMP_CALIB); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_mag_write_addr(YAS537_REG_TRMR); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +/* write average filter register*/ +com_rslt += bmi160_set_mag_write_data( +v_avrr_u8[yas537_data.average]); +p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); +com_rslt += bmi160_set_mag_write_addr(YAS537_REG_AVRR); +p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); +if (v_rcoil_u8) { + /* write average; filter register*/ + com_rslt += bmi160_set_mag_write_data( + YAS537_WRITE_FILTER); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(YAS537_REG_CONFR); + p_bmi160->delay_msec( + BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas537_acquisition_command_register( +u8 v_command_reg_data_u8) +{ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + + if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) + com_rslt = bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + com_rslt = bmi160_set_mag_write_data(v_command_reg_data_u8); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + /* YAMAHA YAS532-0x82*/ + com_rslt += bmi160_set_mag_write_addr( + BMI160_REG_YAS537_CMDR); + /* set the mode to RECORD*/ + yas537_data.measure_state = YAS537_MAG_STATE_RECORD_DATA; + p_bmi160->delay_msec(BMI160_YAS_ACQ_COMMAND_DELAY); + com_rslt += bmi160_set_mag_read_addr( + YAS537_REG_TEMPERATURE_0); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) + com_rslt += bmi160_set_mag_manual_enable( + BMI160_MANUAL_DISABLE); + p_bmi160->delay_msec(BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_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*/ + BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES; + /* Array holding the YAS532 calibration values */ + u8 a_data_u8[BMI160_YAS_XY1Y2T_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE, + }; + u8 i = BMI160_INIT_VALUE; + s32 a_h_s32[BMI160_YAS_H_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + s32 a_s_s32[BMI160_YAS_S_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + /* set command register*/ + com_rslt = bmi160_bst_yas537_acquisition_command_register( + YAS537_SET_COMMAND_REGISTER); + /* read the yas537 sensor data of xy1y2*/ + com_rslt += + p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr, + BMI160_USER_DATA_MAG_X_LSB__REG, + a_data_u8, BMI160_MAG_YAS_DATA_LENGTH); + /* read the busy flag*/ + *v_busy_u8 = a_data_u8[2] + >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS; + /* read the coil status*/ + *v_coil_stat_u8 = + ((a_data_u8[2] >> + BMI160_SHIFT_BIT_POSITION_BY_06_BITS) & 0X01); + /* read temperature data*/ + *v_temperature_u16 = (u16)((a_data_u8[0] + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | a_data_u8[1]); + /* read x data*/ + xy1y2[0] = (u16)(((a_data_u8[2] & + 0x3F) + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | (a_data_u8[3])); + /* read y1 data*/ + xy1y2[1] = (u16)((a_data_u8[4] + << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) + | a_data_u8[5]); + /* read y2 data*/ + xy1y2[2] = (u16)((a_data_u8[6] + << BMI160_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 BMI160_RETURN_FUNCTION_TYPE invalid_magnetic_field( +u16 *v_cur_u16, u16 *v_last_u16) +{ + s16 invalid_thresh[] = {1500, 1500, 1500}; + u8 i = BMI160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_measure_xyz_data( +u8 *v_ouflow_u8, struct yas_vector *vector_xyz) +{ + s32 a_xyz_tmp_s32[BMI160_YAS_TEMP_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + u8 i = BMI160_INIT_VALUE; + s8 com_rslt = BMI160_INIT_VALUE; + u8 v_busy_u8 = BMI160_INIT_VALUE; + u8 v_rcoil_u8 = BMI160_INIT_VALUE; + u16 v_temperature_u16 = BMI160_INIT_VALUE; + u16 a_xy1y2_u16[BMI160_YAS_XY1Y2_DATA_SIZE] = { + BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE}; + *v_ouflow_u8 = 0; + /* read the yas537 xy1y2 data*/ + com_rslt = bmi160_bst_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 != BMI160_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_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) + com_rslt = bmi160_set_mag_manual_enable( + BMI160_MANUAL_ENABLE); + com_rslt += bmi160_set_mag_write_data(YAS537_WRITE_CONFR); + p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY); + com_rslt += bmi160_set_mag_write_addr(YAS537_REG_CONFR); + p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY); + yas537_data.measure_state = YAS537_MAG_STATE_RECORD_DATA; + if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) + com_rslt = bmi160_set_mag_manual_enable( + BMI160_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 (BMI160_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 + * bmi160_t structure + * + * @return the reference and values of bmi160_t + * + * +*/ +struct bmi160_t *bmi160_get_ptr(void) +{ + return p_bmi160; +} diff --git a/drivers/input/misc/bmi160.h b/drivers/input/misc/bmi160.h new file mode 100755 index 00000000000..fdfa5b77001 --- /dev/null +++ b/drivers/input/misc/bmi160.h @@ -0,0 +1,11605 @@ +/* +**************************************************************************** +* Copyright (C) 2014 Bosch Sensortec GmbH +* +* bmi160.h +* Date : 2015/04/02 +* @id "2e89046" +* Revision : 2.0.9 $ +* @brief +* The head file of BMI160API +* +**************************************************************************** +* +* \section Disclaimer +* +* Common: +* Bosch Sensortec products are developed for the consumer goods industry. +* They may only be used within the parameters of the respective valid +* product data sheet. Bosch Sensortec products are provided with the +* express understanding that there is no warranty of fitness for a +* particular purpose.They are not fit for use in life-sustaining, +* safety or security sensitive systems or any system or device +* that may lead to bodily harm or property damage if the system +* or device malfunctions. In addition,Bosch Sensortec products are +* not fit for use in products which interact with motor vehicle systems. +* The resale and or use of products are at the purchasers own risk and +* his own responsibility. The examination of fitness for the intended use +* is the sole responsibility of the Purchaser. +* +* The purchaser shall indemnify Bosch Sensortec from all third party +* claims, including any claims for incidental, or consequential damages, +* arising from any product use not covered by the parameters of +* the respective valid product data sheet or not approved by +* Bosch Sensortec and reimburse Bosch Sensortec for all costs in +* connection with such claims. +* +* The purchaser must monitor the market for the purchased products, +* particularly with regard to product safety and inform Bosch Sensortec +* without delay of all security relevant incidents. +* +* Engineering Samples are marked with an asterisk (*) or (e). +* Samples may vary from the valid technical specifications of the product +* series. They are therefore 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 product series. Bosch Sensortec assumes +* no liability for the use of engineering samples. +* By accepting the engineering samples, the Purchaser agrees to indemnify +* Bosch Sensortec from all claims arising from the use of engineering +* samples. +* +* Special: +* 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. +* The Software and Information is subject to the following +* terms and conditions: +* +* 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. +* No license is granted by implication or otherwise under any patent or +* patent rights of Bosch. Specifications mentioned in the Information are +* subject to change without notice. +**************************************************************************/ +/*! \file bmi160.h + \brief BMI160 Sensor Driver Support Header File */ +/* user defined code to be added here ... */ +#ifndef __BMI160_H__ +#define __BMI160_H__ + + +#include + +/***************************************************************/ +/**\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 BMI160_WR_FUNC_PTR would equal: + + BMI160_WR_FUNC_PTR s8 (* bus_write)(u8, + u8, u8 *, u8) + + Parameters can be mixed as needed refer to the + @ref BMI160_BUS_WRITE_FUNC macro. + + +*/ +#define BMI160_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. + + + BMI160_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 BMI160_WR_FUNC_PTR definition. + +*/ +#define BMI160_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 BMI160_RD_FUNC_PTR would equal: + + BMI160_RD_FUNC_PTR s8 (* bus_read)(u8, + u8, u8 *, u8) + + Parameters can be mixed as needed refer to the + refer BMI160_BUS_READ_FUNC macro. + +*/ +#define BMI160_SPI_RD_MASK (0x80) /* for spi read transactions on SPI the + MSB has to be set */ +#define BMI160_RD_FUNC_PTR s8 (*bus_read)(u8,\ + u8, u8 *, u8) + +#define BMI160_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. + + + BMI160_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 BMI160_WR_FUNC_PTR definition. + + @note: this macro also includes the "MSB='1' + for reading BMI160 addresses. + +*/ +#define BMI160_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, r_len)\ + bus_read(dev_addr, reg_addr, reg_data, r_len) + +#define BMI160_BURST_READ_FUNC(device_addr, \ +register_addr, register_data, rd_len)\ +burst_read(device_addr, register_addr, register_data, rd_len) + + +#define BMI160_MDELAY_DATA_TYPE u32 + +/***************************************************************/ +/**\name BUS READ AND WRITE FUNCTION POINTERS */ +/***************************************************************/ +#define BMI160_I2C_ADDR1 0x68 /**< I2C Address needs to be changed */ +#define BMI160_I2C_ADDR2 0x69 /**< I2C Address needs to be changed */ +#define BMI160_AUX_BMM150_I2C_ADDRESS (0x10) +#define BMI160_AUX_YAS532_I2C_ADDRESS (0x2E) +/**< I2C address of YAS532*/ +#define BMI160_AKM09911_I2C_ADDRESS 0x0C/**< I2C address of AKM09911*/ +/**< I2C address of AKM09911*/ +#define BMI160_AUX_AKM09911_I2C_ADDR_2 (0x0D) +/**< I2C address of AKM09911*/ +#define BMI160_AUX_AKM09912_I2C_ADDR_1 (0x0C) +/**< I2C address of AKM09912*/ +#define BMI160_AUX_AKM09912_I2C_ADDR_2 (0x0D) +/**< I2C address of AKM09912*/ +#define BMI160_AUX_AKM09912_I2C_ADDR_3 (0x0E) +/**< I2C address of AKM09912*/ +#define BMI160_AKM09912_I2C_ADDRESS 0x0F/**< I2C address of akm09912*/ + +#define BMI160_YAS532_I2C_ADDRESS 0x2E/**< I2C address of YAS532*/ +/*******************************************/ +/**\name CONSTANTS */ +/******************************************/ +#define BMI160_INIT_VALUE (0) +#define BMI160_GEN_READ_WRITE_DATA_LENGTH (1) +#define BMI160_MAXIMUM_TIMEOUT (10) +/* output data rate condition check*/ +#define BMI160_OUTPUT_DATA_RATE0 (0) +#define BMI160_OUTPUT_DATA_RATE1 (1) +#define BMI160_OUTPUT_DATA_RATE2 (2) +#define BMI160_OUTPUT_DATA_RATE3 (3) +#define BMI160_OUTPUT_DATA_RATE4 (4) +#define BMI160_OUTPUT_DATA_RATE5 (5) +#define BMI160_OUTPUT_DATA_RATE6 (14) +#define BMI160_OUTPUT_DATA_RATE7 (15) +/* accel range check*/ +#define BMI160_ACCEL_RANGE0 (3) +#define BMI160_ACCEL_RANGE1 (5) +#define BMI160_ACCEL_RANGE3 (8) +#define BMI160_ACCEL_RANGE4 (12) +/* check the status of registers*/ +#define BMI160_FOC_STAT_HIGH (1) +#define BMI160_SIG_MOTION_STAT_HIGH (1) +#define BMI160_STEP_DET_STAT_HIGH (1) + +/*condition check for reading and writing data*/ +#define BMI160_MAX_VALUE_SIGNIFICANT_MOTION (1) +#define BMI160_MAX_VALUE_FIFO_FILTER (1) +#define BMI160_MAX_VALUE_FIFO_TIME (1) +#define BMI160_MAX_VALUE_FIFO_INTR (1) +#define BMI160_MAX_VALUE_FIFO_HEADER (1) +#define BMI160_MAX_VALUE_FIFO_MAG (1) +#define BMI160_MAX_VALUE_FIFO_ACCEL (1) +#define BMI160_MAX_VALUE_FIFO_GYRO (1) +#define BMI160_MAX_VALUE_SOURCE_INTR (1) +#define BMI160_MAX_VALUE_LOW_G_MODE (1) +#define BMI160_MAX_VALUE_NO_MOTION (1) +#define BMI160_MAX_VALUE_TAP_SHOCK (1) +#define BMI160_MAX_VALUE_TAP_QUIET (1) +#define BMI160_MAX_VALUE_ORIENT_UD (1) +#define BMI160_MAX_VALUE_ORIENT_AXES (1) +#define BMI160_MAX_VALUE_NVM_PROG (1) +#define BMI160_MAX_VALUE_SPI3 (1) +#define BMI160_MAX_VALUE_PAGE (1) +#define BMI160_MAX_VALUE_I2C_WDT (1) +#define BMI160_MAX_VALUE_SLEEP_STATE (1) +#define BMI160_MAX_VALUE_WAKEUP_INTR (1) +#define BMI160_MAX_VALUE_SELFTEST_SIGN (1) +#define BMI160_MAX_VALUE_SELFTEST_AMP (1) +#define BMI160_MAX_VALUE_SELFTEST_START (1) +#define BMI160_MAX_GYRO_WAKEUP_TRIGGER (3) +#define BMI160_MAX_ACCEL_SELFTEST_AXIS (3) +#define BMI160_MAX_GYRO_STEP_COUNTER (1) +#define BMI160_MAX_GYRO_BW (3) +#define BMI160_MAX_ACCEL_BW (7) +#define BMI160_MAX_ORIENT_MODE (3) +#define BMI160_MAX_ORIENT_BLOCKING (3) +#define BMI160_MAX_FLAT_HOLD (3) +#define BMI160_MAX_ACCEL_FOC (3) +#define BMI160_MAX_IF_MODE (3) +#define BMI160_MAX_TARGET_PAGE (3) +#define BMI160_MAX_GYRO_RANGE (4) +#define BMI160_MAX_GYRO_SLEEP_TIGGER (7) +#define BMI160_MAX_TAP_TURN (7) +#define BMI160_MAX_UNDER_SAMPLING (1) +#define BMI160_MAX_UNDER_SIG_MOTION (3) +#define BMI160_MAX_ACCEL_OUTPUT_DATA_RATE (12) +#define BMI160_MAX_LATCH_INTR (15) +#define BMI160_MAX_FLAT_HYST (15) +#define BMI160_MAX_ORIENT_THETA (63) +#define BMI160_MAX_FLAT_THETA (63) + +/* FIFO index definitions*/ +#define BMI160_FIFO_X_LSB_DATA (0) +#define BMI160_FIFO_X_MSB_DATA (1) +#define BMI160_FIFO_Y_LSB_DATA (2) +#define BMI160_FIFO_Y_MSB_DATA (3) +#define BMI160_FIFO_Z_LSB_DATA (4) +#define BMI160_FIFO_Z_MSB_DATA (5) +#define BMI160_FIFO_R_LSB_DATA (6) +#define BMI160_FIFO_R_MSB_DATA (7) +/* FIFO gyro definition*/ +#define BMI160_GA_FIFO_G_X_LSB (0) +#define BMI160_GA_FIFO_G_X_MSB (1) +#define BMI160_GA_FIFO_G_Y_LSB (2) +#define BMI160_GA_FIFO_G_Y_MSB (3) +#define BMI160_GA_FIFO_G_Z_LSB (4) +#define BMI160_GA_FIFO_G_Z_MSB (5) +#define BMI160_GA_FIFO_A_X_LSB (6) +#define BMI160_GA_FIFO_A_X_MSB (7) +#define BMI160_GA_FIFO_A_Y_LSB (8) +#define BMI160_GA_FIFO_A_Y_MSB (9) +#define BMI160_GA_FIFO_A_Z_LSB (10) +#define BMI160_GA_FIFO_A_Z_MSB (11) +/* FIFO mag/gyro/accel definition*/ +#define BMI160_MGA_FIFO_M_X_LSB (0) +#define BMI160_MGA_FIFO_M_X_MSB (1) +#define BMI160_MGA_FIFO_M_Y_LSB (2) +#define BMI160_MGA_FIFO_M_Y_MSB (3) +#define BMI160_MGA_FIFO_M_Z_LSB (4) +#define BMI160_MGA_FIFO_M_Z_MSB (5) +#define BMI160_MGA_FIFO_M_R_LSB (6) +#define BMI160_MGA_FIFO_M_R_MSB (7) +#define BMI160_MGA_FIFO_G_X_LSB (8) +#define BMI160_MGA_FIFO_G_X_MSB (9) +#define BMI160_MGA_FIFO_G_Y_LSB (10) +#define BMI160_MGA_FIFO_G_Y_MSB (11) +#define BMI160_MGA_FIFO_G_Z_LSB (12) +#define BMI160_MGA_FIFO_G_Z_MSB (13) +#define BMI160_MGA_FIFO_A_X_LSB (14) +#define BMI160_MGA_FIFO_A_X_MSB (15) +#define BMI160_MGA_FIFO_A_Y_LSB (16) +#define BMI160_MGA_FIFO_A_Y_MSB (17) +#define BMI160_MGA_FIFO_A_Z_LSB (18) +#define BMI160_MGA_FIFO_A_Z_MSB (19) +/* FIFO mag definition*/ +#define BMI160_MA_FIFO_M_X_LSB (0) +#define BMI160_MA_FIFO_M_X_MSB (1) +#define BMI160_MA_FIFO_M_Y_LSB (2) +#define BMI160_MA_FIFO_M_Y_MSB (3) +#define BMI160_MA_FIFO_M_Z_LSB (4) +#define BMI160_MA_FIFO_M_Z_MSB (5) +#define BMI160_MA_FIFO_M_R_LSB (6) +#define BMI160_MA_FIFO_M_R_MSB (7) +#define BMI160_MA_FIFO_A_X_LSB (8) +#define BMI160_MA_FIFO_A_X_MSB (9) +#define BMI160_MA_FIFO_A_Y_LSB (10) +#define BMI160_MA_FIFO_A_Y_MSB (11) +#define BMI160_MA_FIFO_A_Z_LSB (12) +#define BMI160_MA_FIFO_A_Z_MSB (13) +/* FIFO mag/gyro definition*/ +#define BMI160_MG_FIFO_M_X_LSB (0) +#define BMI160_MG_FIFO_M_X_MSB (1) +#define BMI160_MG_FIFO_M_Y_LSB (2) +#define BMI160_MG_FIFO_M_Y_MSB (3) +#define BMI160_MG_FIFO_M_Z_LSB (4) +#define BMI160_MG_FIFO_M_Z_MSB (5) +#define BMI160_MG_FIFO_M_R_LSB (6) +#define BMI160_MG_FIFO_M_R_MSB (7) +#define BMI160_MG_FIFO_G_X_LSB (8) +#define BMI160_MG_FIFO_G_X_MSB (9) +#define BMI160_MG_FIFO_G_Y_LSB (10) +#define BMI160_MG_FIFO_G_Y_MSB (11) +#define BMI160_MG_FIFO_G_Z_LSB (12) +#define BMI160_MG_FIFO_G_Z_MSB (13) +/* FIFO length definitions*/ +#define BMI160_FIFO_SENSOR_TIME_LSB (0) +#define BMI160_FIFO_SENSOR_TIME_XLSB (1) +#define BMI160_FIFO_SENSOR_TIME_MSB (2) +#define BMI160_FIFO_SENSOR_TIME_LENGTH (3) +#define BMI160_FIFO_A_LENGTH (6) +#define BMI160_FIFO_G_LENGTH (6) +#define BMI160_FIFO_M_LENGTH (8) +#define BMI160_FIFO_AG_LENGTH (12) +#define BMI160_FIFO_AMG_LENGTH (20) +#define BMI160_FIFO_MA_OR_MG_LENGTH (14) + +/* bus read and write length for mag, accel and gyro*/ +#define BMI160_MAG_X_DATA_LENGTH (2) +#define BMI160_MAG_Y_DATA_LENGTH (2) +#define BMI160_MAG_Z_DATA_LENGTH (2) +#define BMI160_MAG_R_DATA_LENGTH (2) +#define BMI160_MAG_XYZ_DATA_LENGTH (6) +#define BMI160_MAG_XYZR_DATA_LENGTH (8) +#define BMI160_MAG_YAS_DATA_LENGTH (8) +#define BMI160_GYRO_DATA_LENGTH (2) +#define BMI160_GYRO_XYZ_DATA_LENGTH (6) +#define BMI160_ACCEL_DATA_LENGTH (2) +#define BMI160_ACCEL_XYZ_DATA_LENGTH (6) +#define BMI160_TEMP_DATA_LENGTH (2) +#define BMI160_FIFO_DATA_LENGTH (2) +#define BMI160_STEP_COUNTER_LENGTH (2) +#define BMI160_SENSOR_TIME_LENGTH (3) + +/* Delay definitions*/ +#define BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY (5) +#define BMI160_BMM150_WAKEUP_DELAY1 (2) +#define BMI160_BMM150_WAKEUP_DELAY2 (3) +#define BMI160_BMM150_WAKEUP_DELAY3 (1) +#define BMI160_YAS532_OFFSET_DELAY (2) +#define BMI160_GEN_READ_WRITE_DELAY (1) +#define BMI160_YAS532_MEASUREMENT_DELAY (25) +#define BMI160_YAS_ACQ_COMMAND_DELAY (50) +#define BMI160_YAS532_SET_INITIAL_VALUE_DELAY (200) +#define BMI160_AKM_INIT_DELAY (60) +/****************************************************/ +/**\name ARRAY SIZE DEFINITIONS */ +/***************************************************/ +#define BMI160_ACCEL_X_DATA_SIZE (2) +#define BMI160_ACCEL_Y_DATA_SIZE (2) +#define BMI160_ACCEL_Z_DATA_SIZE (2) +#define BMI160_ACCEL_XYZ_DATA_SIZE (6) + +#define BMI160_GYRO_X_DATA_SIZE (2) +#define BMI160_GYRO_Y_DATA_SIZE (2) +#define BMI160_GYRO_Z_DATA_SIZE (2) +#define BMI160_GYRO_XYZ_DATA_SIZE (6) + +#define BMI160_MAG_X_DATA_SIZE (2) +#define BMI160_MAG_Y_DATA_SIZE (2) +#define BMI160_MAG_Z_DATA_SIZE (2) +#define BMI160_MAG_R_DATA_SIZE (2) +#define BMI160_MAG_XYZ_DATA_SIZE (6) +#define BMI160_MAG_XYZR_DATA_SIZE (8) +#define BMI160_MAG_TRIM_DATA_SIZE (16) + + +#define BMI160_TEMP_DATA_SIZE (2) +#define BMI160_FIFO_DATA_SIZE (2) +#define BMI160_STEP_COUNT_DATA_SIZE (2) + +#define BMI160_SENSOR_TIME_DATA_SIZE (3) +#define BMI160_AKM_SENSITIVITY_DATA_SIZE (3) +#define BMI160_HARD_OFFSET_DATA_SIZE (3) +#define BMI160_YAS_XY1Y2_DATA_SIZE (3) +#define BMI160_YAS_FLAG_DATA_SIZE (3) +#define BMI160_YAS_TEMP_DATA_SIZE (3) +#define BMI160_YAS_H_DATA_SIZE (3) +#define BMI160_YAS_S_DATA_SIZE (3) +#define BMI160_YAS_CORRECT_DATA_SIZE (5) +#define BMI160_YAS_XY1Y2T_DATA_SIZE (8) +#define BMI160_YAS537_CALIB_DATA_SIZE (17) +#define BMI160_YAS532_CALIB_DATA_SIZE (14) +/****************************************************/ +/**\name ARRAY PARAMETER DEFINITIONS */ +/***************************************************/ +#define BMI160_SENSOR_TIME_MSB_BYTE (2) +#define BMI160_SENSOR_TIME_XLSB_BYTE (1) +#define BMI160_SENSOR_TIME_LSB_BYTE (0) + +#define BMI160_MAG_X_LSB_BYTE (0) +#define BMI160_MAG_X_MSB_BYTE (1) +#define BMI160_MAG_Y_LSB_BYTE (0) +#define BMI160_MAG_Y_MSB_BYTE (1) +#define BMI160_MAG_Z_LSB_BYTE (0) +#define BMI160_MAG_Z_MSB_BYTE (1) +#define BMI160_MAG_R_LSB_BYTE (0) +#define BMI160_MAG_R_MSB_BYTE (1) +#define BMI160_DATA_FRAME_MAG_X_LSB_BYTE (0) +#define BMI160_DATA_FRAME_MAG_X_MSB_BYTE (1) +#define BMI160_DATA_FRAME_MAG_Y_LSB_BYTE (2) +#define BMI160_DATA_FRAME_MAG_Y_MSB_BYTE (3) +#define BMI160_DATA_FRAME_MAG_Z_LSB_BYTE (4) +#define BMI160_DATA_FRAME_MAG_Z_MSB_BYTE (5) +#define BMI160_DATA_FRAME_MAG_R_LSB_BYTE (6) +#define BMI160_DATA_FRAME_MAG_R_MSB_BYTE (7) + +#define BMI160_GYRO_X_LSB_BYTE (0) +#define BMI160_GYRO_X_MSB_BYTE (1) +#define BMI160_GYRO_Y_LSB_BYTE (0) +#define BMI160_GYRO_Y_MSB_BYTE (1) +#define BMI160_GYRO_Z_LSB_BYTE (0) +#define BMI160_GYRO_Z_MSB_BYTE (1) +#define BMI160_DATA_FRAME_GYRO_X_LSB_BYTE (0) +#define BMI160_DATA_FRAME_GYRO_X_MSB_BYTE (1) +#define BMI160_DATA_FRAME_GYRO_Y_LSB_BYTE (2) +#define BMI160_DATA_FRAME_GYRO_Y_MSB_BYTE (3) +#define BMI160_DATA_FRAME_GYRO_Z_LSB_BYTE (4) +#define BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE (5) + +#define BMI160_ACCEL_X_LSB_BYTE (0) +#define BMI160_ACCEL_X_MSB_BYTE (1) +#define BMI160_ACCEL_Y_LSB_BYTE (0) +#define BMI160_ACCEL_Y_MSB_BYTE (1) +#define BMI160_ACCEL_Z_LSB_BYTE (0) +#define BMI160_ACCEL_Z_MSB_BYTE (1) +#define BMI160_DATA_FRAME_ACCEL_X_LSB_BYTE (0) +#define BMI160_DATA_FRAME_ACCEL_X_MSB_BYTE (1) +#define BMI160_DATA_FRAME_ACCEL_Y_LSB_BYTE (2) +#define BMI160_DATA_FRAME_ACCEL_Y_MSB_BYTE (3) +#define BMI160_DATA_FRAME_ACCEL_Z_LSB_BYTE (4) +#define BMI160_DATA_FRAME_ACCEL_Z_MSB_BYTE (5) + +#define BMI160_TEMP_LSB_BYTE (0) +#define BMI160_TEMP_MSB_BYTE (1) + +#define BMI160_FIFO_LENGTH_LSB_BYTE (0) +#define BMI160_FIFO_LENGTH_MSB_BYTE (1) + +#define BMI160_STEP_COUNT_LSB_BYTE (0) +#define BMI160_STEP_COUNT_MSB_BYTE (1) +/****************************************************/ +/**\name ERROR CODES */ +/***************************************************/ + +#define E_BMI160_NULL_PTR ((s8)-127) +#define E_BMI160_COMM_RES ((s8)-1) +#define E_BMI160_OUT_OF_RANGE ((s8)-2) +#define E_BMI160_BUSY ((s8)-3) +#define SUCCESS ((u8)0) +#define ERROR ((s8)-1) + +/* Constants */ +#define BMI160_NULL (0) +#define BMI160_DELAY_SETTLING_TIME (5) +/*This refers BMI160 return type as s8 */ +#define BMI160_RETURN_FUNCTION_TYPE s8 +/****************************************************/ +/**\name REGISTER DEFINITIONS */ +/***************************************************/ +/*******************/ +/**\name CHIP ID */ +/*******************/ +#define BMI160_USER_CHIP_ID_ADDR (0x00) +/*******************/ +/**\name ERROR STATUS */ +/*******************/ +#define BMI160_USER_ERROR_ADDR (0X02) +/*******************/ +/**\name POWER MODE STATUS */ +/*******************/ +#define BMI160_USER_PMU_STAT_ADDR (0X03) +/*******************/ +/**\name MAG DATA REGISTERS */ +/*******************/ +#define BMI160_USER_DATA_0_ADDR (0X04) +#define BMI160_USER_DATA_1_ADDR (0X05) +#define BMI160_USER_DATA_2_ADDR (0X06) +#define BMI160_USER_DATA_3_ADDR (0X07) +#define BMI160_USER_DATA_4_ADDR (0X08) +#define BMI160_USER_DATA_5_ADDR (0X09) +#define BMI160_USER_DATA_6_ADDR (0X0A) +#define BMI160_USER_DATA_7_ADDR (0X0B) +/*******************/ +/**\name GYRO DATA REGISTERS */ +/*******************/ +#define BMI160_USER_DATA_8_ADDR (0X0C) +#define BMI160_USER_DATA_9_ADDR (0X0D) +#define BMI160_USER_DATA_10_ADDR (0X0E) +#define BMI160_USER_DATA_11_ADDR (0X0F) +#define BMI160_USER_DATA_12_ADDR (0X10) +#define BMI160_USER_DATA_13_ADDR (0X11) +#define BMI160_USER_DATA_14_ADDR (0X12) +#define BMI160_USER_DATA_15_ADDR (0X13) +/*******************/ +/**\name ACCEL DATA REGISTERS */ +/*******************/ +#define BMI160_USER_DATA_16_ADDR (0X14) +#define BMI160_USER_DATA_17_ADDR (0X15) +#define BMI160_USER_DATA_18_ADDR (0X16) +#define BMI160_USER_DATA_19_ADDR (0X17) +/*******************/ +/**\name SENSOR TIME REGISTERS */ +/*******************/ +#define BMI160_USER_SENSORTIME_0_ADDR (0X18) +#define BMI160_USER_SENSORTIME_1_ADDR (0X19) +#define BMI160_USER_SENSORTIME_2_ADDR (0X1A) +/*******************/ +/**\name STATUS REGISTER FOR SENSOR STATUS FLAG */ +/*******************/ +#define BMI160_USER_STAT_ADDR (0X1B) +/*******************/ +/**\name INTERRUPY STATUS REGISTERS */ +/*******************/ +#define BMI160_USER_INTR_STAT_0_ADDR (0X1C) +#define BMI160_USER_INTR_STAT_1_ADDR (0X1D) +#define BMI160_USER_INTR_STAT_2_ADDR (0X1E) +#define BMI160_USER_INTR_STAT_3_ADDR (0X1F) +/*******************/ +/**\name TEMPERATURE REGISTERS */ +/*******************/ +#define BMI160_USER_TEMPERATURE_0_ADDR (0X20) +#define BMI160_USER_TEMPERATURE_1_ADDR (0X21) +/*******************/ +/**\name FIFO REGISTERS */ +/*******************/ +#define BMI160_USER_FIFO_LENGTH_0_ADDR (0X22) +#define BMI160_USER_FIFO_LENGTH_1_ADDR (0X23) +#define BMI160_USER_FIFO_DATA_ADDR (0X24) +/***************************************************/ +/**\name ACCEL CONFIG REGISTERS FOR ODR, BANDWIDTH AND UNDERSAMPLING*/ +/******************************************************/ +#define BMI160_USER_ACCEL_CONFIG_ADDR (0X40) +/*******************/ +/**\name ACCEL RANGE */ +/*******************/ +#define BMI160_USER_ACCEL_RANGE_ADDR (0X41) +/***************************************************/ +/**\name GYRO CONFIG REGISTERS FOR ODR AND BANDWIDTH */ +/******************************************************/ +#define BMI160_USER_GYRO_CONFIG_ADDR (0X42) +/*******************/ +/**\name GYRO RANGE */ +/*******************/ +#define BMI160_USER_GYRO_RANGE_ADDR (0X43) +/***************************************************/ +/**\name MAG CONFIG REGISTERS FOR ODR*/ +/******************************************************/ +#define BMI160_USER_MAG_CONFIG_ADDR (0X44) +/***************************************************/ +/**\name REGISTER FOR GYRO AND ACCEL DOWNSAMPLING RATES FOR FIFO*/ +/******************************************************/ +#define BMI160_USER_FIFO_DOWN_ADDR (0X45) +/***************************************************/ +/**\name FIFO CONFIG REGISTERS*/ +/******************************************************/ +#define BMI160_USER_FIFO_CONFIG_0_ADDR (0X46) +#define BMI160_USER_FIFO_CONFIG_1_ADDR (0X47) +/***************************************************/ +/**\name MAG INTERFACE REGISTERS*/ +/******************************************************/ +#define BMI160_USER_MAG_IF_0_ADDR (0X4B) +#define BMI160_USER_MAG_IF_1_ADDR (0X4C) +#define BMI160_USER_MAG_IF_2_ADDR (0X4D) +#define BMI160_USER_MAG_IF_3_ADDR (0X4E) +#define BMI160_USER_MAG_IF_4_ADDR (0X4F) +/***************************************************/ +/**\name INTERRUPT ENABLE REGISTERS*/ +/******************************************************/ +#define BMI160_USER_INTR_ENABLE_0_ADDR (0X50) +#define BMI160_USER_INTR_ENABLE_1_ADDR (0X51) +#define BMI160_USER_INTR_ENABLE_2_ADDR (0X52) +#define BMI160_USER_INTR_OUT_CTRL_ADDR (0X53) +/***************************************************/ +/**\name LATCH DURATION REGISTERS*/ +/******************************************************/ +#define BMI160_USER_INTR_LATCH_ADDR (0X54) +/***************************************************/ +/**\name MAP INTERRUPT 1 and 2 REGISTERS*/ +/******************************************************/ +#define BMI160_USER_INTR_MAP_0_ADDR (0X55) +#define BMI160_USER_INTR_MAP_1_ADDR (0X56) +#define BMI160_USER_INTR_MAP_2_ADDR (0X57) +/***************************************************/ +/**\name DATA SOURCE REGISTERS*/ +/******************************************************/ +#define BMI160_USER_INTR_DATA_0_ADDR (0X58) +#define BMI160_USER_INTR_DATA_1_ADDR (0X59) +/***************************************************/ +/**\name +INTERRUPT THRESHOLD, HYSTERESIS, DURATION, MODE CONFIGURATION REGISTERS*/ +/******************************************************/ +#define BMI160_USER_INTR_LOWHIGH_0_ADDR (0X5A) +#define BMI160_USER_INTR_LOWHIGH_1_ADDR (0X5B) +#define BMI160_USER_INTR_LOWHIGH_2_ADDR (0X5C) +#define BMI160_USER_INTR_LOWHIGH_3_ADDR (0X5D) +#define BMI160_USER_INTR_LOWHIGH_4_ADDR (0X5E) +#define BMI160_USER_INTR_MOTION_0_ADDR (0X5F) +#define BMI160_USER_INTR_MOTION_1_ADDR (0X60) +#define BMI160_USER_INTR_MOTION_2_ADDR (0X61) +#define BMI160_USER_INTR_MOTION_3_ADDR (0X62) +#define BMI160_USER_INTR_TAP_0_ADDR (0X63) +#define BMI160_USER_INTR_TAP_1_ADDR (0X64) +#define BMI160_USER_INTR_ORIENT_0_ADDR (0X65) +#define BMI160_USER_INTR_ORIENT_1_ADDR (0X66) +#define BMI160_USER_INTR_FLAT_0_ADDR (0X67) +#define BMI160_USER_INTR_FLAT_1_ADDR (0X68) +/***************************************************/ +/**\name FAST OFFSET CONFIGURATION REGISTER*/ +/******************************************************/ +#define BMI160_USER_FOC_CONFIG_ADDR (0X69) +/***************************************************/ +/**\name MISCELLANEOUS CONFIGURATION REGISTER*/ +/******************************************************/ +#define BMI160_USER_CONFIG_ADDR (0X6A) +/***************************************************/ +/**\name SERIAL INTERFACE SETTINGS REGISTER*/ +/******************************************************/ +#define BMI160_USER_IF_CONFIG_ADDR (0X6B) +/***************************************************/ +/**\name GYRO POWER MODE TRIGGER REGISTER */ +/******************************************************/ +#define BMI160_USER_PMU_TRIGGER_ADDR (0X6C) +/***************************************************/ +/**\name SELF_TEST REGISTER*/ +/******************************************************/ +#define BMI160_USER_SELF_TEST_ADDR (0X6D) +/***************************************************/ +/**\name SPI,I2C SELECTION REGISTER*/ +/******************************************************/ +#define BMI160_USER_NV_CONFIG_ADDR (0x70) +/***************************************************/ +/**\name ACCEL AND GYRO OFFSET REGISTERS*/ +/******************************************************/ +#define BMI160_USER_OFFSET_0_ADDR (0X71) +#define BMI160_USER_OFFSET_1_ADDR (0X72) +#define BMI160_USER_OFFSET_2_ADDR (0X73) +#define BMI160_USER_OFFSET_3_ADDR (0X74) +#define BMI160_USER_OFFSET_4_ADDR (0X75) +#define BMI160_USER_OFFSET_5_ADDR (0X76) +#define BMI160_USER_OFFSET_6_ADDR (0X77) +/***************************************************/ +/**\name STEP COUNTER INTERRUPT REGISTERS*/ +/******************************************************/ +#define BMI160_USER_STEP_COUNT_0_ADDR (0X78) +#define BMI160_USER_STEP_COUNT_1_ADDR (0X79) +/***************************************************/ +/**\name STEP COUNTER CONFIGURATION REGISTERS*/ +/******************************************************/ +#define BMI160_USER_STEP_CONFIG_0_ADDR (0X7A) +#define BMI160_USER_STEP_CONFIG_1_ADDR (0X7B) +/***************************************************/ +/**\name COMMAND REGISTER*/ +/******************************************************/ +#define BMI160_CMD_COMMANDS_ADDR (0X7E) +/***************************************************/ +/**\name PAGE REGISTERS*/ +/******************************************************/ +#define BMI160_CMD_EXT_MODE_ADDR (0X7F) +#define BMI160_COM_C_TRIM_FIVE_ADDR (0X05) + +/****************************************************/ +/**\name SHIFT VALUE DEFINITION */ +/***************************************************/ +#define BMI160_SHIFT_BIT_POSITION_BY_01_BIT (1) +#define BMI160_SHIFT_BIT_POSITION_BY_02_BITS (2) +#define BMI160_SHIFT_BIT_POSITION_BY_03_BITS (3) +#define BMI160_SHIFT_BIT_POSITION_BY_04_BITS (4) +#define BMI160_SHIFT_BIT_POSITION_BY_05_BITS (5) +#define BMI160_SHIFT_BIT_POSITION_BY_06_BITS (6) +#define BMI160_SHIFT_BIT_POSITION_BY_07_BITS (7) +#define BMI160_SHIFT_BIT_POSITION_BY_08_BITS (8) +#define BMI160_SHIFT_BIT_POSITION_BY_09_BITS (9) +#define BMI160_SHIFT_BIT_POSITION_BY_12_BITS (12) +#define BMI160_SHIFT_BIT_POSITION_BY_13_BITS (13) +#define BMI160_SHIFT_BIT_POSITION_BY_14_BITS (14) +#define BMI160_SHIFT_BIT_POSITION_BY_15_BITS (15) +#define BMI160_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 BMI160_YAS532_TESTR1 (0x88) +#define BMI160_YAS532_TESTR2 (0x89) +#define BMI160_YAS532_RCOIL (0x81) +#define BMI160_YAS532_COMMAND_REGISTER (0x82) +#define BMI160_YAS532_DATA_REGISTER (0xB0) +/* calib data register definition*/ +#define BMI160_YAS532_CALIB_CX (0x90) +#define BMI160_YAS532_CALIB_CY1 (0x91) +#define BMI160_YAS532_CALIB_CY2 (0x92) +#define BMI160_YAS532_CALIB1 (0x93) +#define BMI160_YAS532_CALIB2 (0x94) +#define BMI160_YAS532_CALIB3 (0x95) +#define BMI160_YAS532_CALIB4 (0x96) +#define BMI160_YAS532_CALIB5 (0x97) +#define BMI160_YAS532_CLAIB6 (0x98) +#define BMI160_YAS532_CALIB7 (0x99) +#define BMI160_YAS532_CALIB8 (0x9A) +#define BMI160_YAS532_CALIIB9 (0x9B) +#define BMI160_YAS532_CALIB10 (0x9C) +#define BMI160_YAS532_CALIB11 (0x9D) +/* offset definition */ +#define BMI160_YAS532_OFFSET_X (0x85) +#define BMI160_YAS532_OFFSET_Y (0x86) +#define BMI160_YAS532_OFFSET_Z (0x87) +/* data to write register for yas532*/ +#define BMI160_YAS532_WRITE_TESTR1 (0x00) +#define BMI160_YAS532_WRITE_TESTR2 (0x00) +#define BMI160_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 BMI160_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 BMI160_BMM150_SET_POWER_CONTROL (0x01) +#define BMI160_BMM150_MAX_RETRY_WAKEUP (5) +#define BMI160_BMM150_POWER_ON (0x01) +#define BMI160_BMM150_POWER_OFF (0x00) +#define BMI160_BMM150_FORCE_MODE (0x02) +#define BMI160_BMM150_POWER_ON_SUCCESS (0) +#define BMI160_BMM150_POWER_ON_FAIL ((s8)-1) + +#define BMI160_BMM150_DIG_X1 (0) +#define BMI160_BMM150_DIG_Y1 (1) +#define BMI160_BMM150_DIG_X2 (2) +#define BMI160_BMM150_DIG_Y3 (3) +#define BMI160_BMM150_DIG_XY1 (4) +#define BMI160_BMM150_DIG_XY2 (5) +#define BMI160_BMM150_DIG_Z1_LSB (6) +#define BMI160_BMM150_DIG_Z1_MSB (7) +#define BMI160_BMM150_DIG_Z2_LSB (8) +#define BMI160_BMM150_DIG_Z2_MSB (9) +#define BMI160_BMM150_DIG_DIG_Z3_LSB (10) +#define BMI160_BMM150_DIG_DIG_Z3_MSB (11) +#define BMI160_BMM150_DIG_DIG_Z4_LSB (12) +#define BMI160_BMM150_DIG_DIG_Z4_MSB (13) +#define BMI160_BMM150_DIG_DIG_XYZ1_LSB (14) +#define BMI160_BMM150_DIG_DIG_XYZ1_MSB (15) + +/**************************************************************/ +/**\name STRUCTURE DEFINITIONS */ +/**************************************************************/ +/*! +* @brief bmi160 structure +* This structure holds all relevant information about bmi160 +*/ +struct bmi160_t { +u8 chip_id;/**< chip id of BMI160 */ +u8 dev_addr;/**< device address of BMI160 */ +s8 mag_manual_enable;/**< used for check the mag manual/auto mode status */ +BMI160_WR_FUNC_PTR;/**< bus write function pointer */ +BMI160_RD_FUNC_PTR;/**< bus read function pointer */ +BMI160_BRD_FUNC_PTR;/**< burst write function pointer */ +void (*delay_msec)(BMI160_MDELAY_DATA_TYPE);/**< delay function pointer */ +}; +/*! + * @brief Structure containing bmm150 and akm09911 + * magnetometer values for x,y and + * z-axis in s16 + */ +struct bmi160_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 bmi160_mag_xyzr_t { +s16 x;/**< BMM150 X raw data*/ +s16 y;/**< BMM150 Y raw data*/ +s16 z;/** (0x00), Bit --> 0...7 */ +#define BMI160_USER_CHIP_ID__POS (0) +#define BMI160_USER_CHIP_ID__MSK (0xFF) +#define BMI160_USER_CHIP_ID__LEN (8) +#define BMI160_USER_CHIP_ID__REG (BMI160_USER_CHIP_ID_ADDR) +/**************************************************************/ +/**\name ERROR STATUS LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Error Description - Reg Addr --> (0x02), Bit --> 0 */ +#define BMI160_USER_ERR_STAT__POS (0) +#define BMI160_USER_ERR_STAT__LEN (8) +#define BMI160_USER_ERR_STAT__MSK (0xFF) +#define BMI160_USER_ERR_STAT__REG (BMI160_USER_ERROR_ADDR) + +#define BMI160_USER_FATAL_ERR__POS (0) +#define BMI160_USER_FATAL_ERR__LEN (1) +#define BMI160_USER_FATAL_ERR__MSK (0x01) +#define BMI160_USER_FATAL_ERR__REG (BMI160_USER_ERROR_ADDR) + +/* Error Description - Reg Addr --> (0x02), Bit --> 1...4 */ +#define BMI160_USER_ERR_CODE__POS (1) +#define BMI160_USER_ERR_CODE__LEN (4) +#define BMI160_USER_ERR_CODE__MSK (0x1E) +#define BMI160_USER_ERR_CODE__REG (BMI160_USER_ERROR_ADDR) + +/* Error Description - Reg Addr --> (0x02), Bit --> 5 */ +#define BMI160_USER_I2C_FAIL_ERR__POS (5) +#define BMI160_USER_I2C_FAIL_ERR__LEN (1) +#define BMI160_USER_I2C_FAIL_ERR__MSK (0x20) +#define BMI160_USER_I2C_FAIL_ERR__REG (BMI160_USER_ERROR_ADDR) + +/* Error Description - Reg Addr --> (0x02), Bit --> 6 */ +#define BMI160_USER_DROP_CMD_ERR__POS (6) +#define BMI160_USER_DROP_CMD_ERR__LEN (1) +#define BMI160_USER_DROP_CMD_ERR__MSK (0x40) +#define BMI160_USER_DROP_CMD_ERR__REG (BMI160_USER_ERROR_ADDR) +/**************************************************************/ +/**\name MAG DATA READY LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Error Description - Reg Addr --> (0x02), Bit --> 7 */ +#define BMI160_USER_MAG_DADA_RDY_ERR__POS (7) +#define BMI160_USER_MAG_DADA_RDY_ERR__LEN (1) +#define BMI160_USER_MAG_DADA_RDY_ERR__MSK (0x80) +#define BMI160_USER_MAG_DADA_RDY_ERR__REG (BMI160_USER_ERROR_ADDR) +/**************************************************************/ +/**\name MAG POWER MODE LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* PMU_Status Description of MAG - Reg Addr --> (0x03), Bit --> 1..0 */ +#define BMI160_USER_MAG_POWER_MODE_STAT__POS (0) +#define BMI160_USER_MAG_POWER_MODE_STAT__LEN (2) +#define BMI160_USER_MAG_POWER_MODE_STAT__MSK (0x03) +#define BMI160_USER_MAG_POWER_MODE_STAT__REG \ +(BMI160_USER_PMU_STAT_ADDR) +/**************************************************************/ +/**\name GYRO POWER MODE LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* PMU_Status Description of GYRO - Reg Addr --> (0x03), Bit --> 3...2 */ +#define BMI160_USER_GYRO_POWER_MODE_STAT__POS (2) +#define BMI160_USER_GYRO_POWER_MODE_STAT__LEN (2) +#define BMI160_USER_GYRO_POWER_MODE_STAT__MSK (0x0C) +#define BMI160_USER_GYRO_POWER_MODE_STAT__REG \ +(BMI160_USER_PMU_STAT_ADDR) +/**************************************************************/ +/**\name ACCEL POWER MODE LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* PMU_Status Description of ACCEL - Reg Addr --> (0x03), Bit --> 5...4 */ +#define BMI160_USER_ACCEL_POWER_MODE_STAT__POS (4) +#define BMI160_USER_ACCEL_POWER_MODE_STAT__LEN (2) +#define BMI160_USER_ACCEL_POWER_MODE_STAT__MSK (0x30) +#define BMI160_USER_ACCEL_POWER_MODE_STAT__REG \ +(BMI160_USER_PMU_STAT_ADDR) +/**************************************************************/ +/**\name MAG DATA XYZ LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Mag_X(LSB) Description - Reg Addr --> (0x04), Bit --> 0...7 */ +#define BMI160_USER_DATA_0_MAG_X_LSB__POS (0) +#define BMI160_USER_DATA_0_MAG_X_LSB__LEN (8) +#define BMI160_USER_DATA_0_MAG_X_LSB__MSK (0xFF) +#define BMI160_USER_DATA_0_MAG_X_LSB__REG (BMI160_USER_DATA_0_ADDR) + +/* Mag_X(LSB) Description - Reg Addr --> (0x04), Bit --> 3...7 */ +#define BMI160_USER_DATA_MAG_X_LSB__POS (3) +#define BMI160_USER_DATA_MAG_X_LSB__LEN (5) +#define BMI160_USER_DATA_MAG_X_LSB__MSK (0xF8) +#define BMI160_USER_DATA_MAG_X_LSB__REG (BMI160_USER_DATA_0_ADDR) + +/* Mag_X(MSB) Description - Reg Addr --> (0x05), Bit --> 0...7 */ +#define BMI160_USER_DATA_1_MAG_X_MSB__POS (0) +#define BMI160_USER_DATA_1_MAG_X_MSB__LEN (8) +#define BMI160_USER_DATA_1_MAG_X_MSB__MSK (0xFF) +#define BMI160_USER_DATA_1_MAG_X_MSB__REG (BMI160_USER_DATA_1_ADDR) + +/* Mag_Y(LSB) Description - Reg Addr --> (0x06), Bit --> 0...7 */ +#define BMI160_USER_DATA_2_MAG_Y_LSB__POS (0) +#define BMI160_USER_DATA_2_MAG_Y_LSB__LEN (8) +#define BMI160_USER_DATA_2_MAG_Y_LSB__MSK (0xFF) +#define BMI160_USER_DATA_2_MAG_Y_LSB__REG (BMI160_USER_DATA_2_ADDR) + +/* Mag_Y(LSB) Description - Reg Addr --> (0x06), Bit --> 3...7 */ +#define BMI160_USER_DATA_MAG_Y_LSB__POS (3) +#define BMI160_USER_DATA_MAG_Y_LSB__LEN (5) +#define BMI160_USER_DATA_MAG_Y_LSB__MSK (0xF8) +#define BMI160_USER_DATA_MAG_Y_LSB__REG (BMI160_USER_DATA_2_ADDR) + +/* Mag_Y(MSB) Description - Reg Addr --> (0x07), Bit --> 0...7 */ +#define BMI160_USER_DATA_3_MAG_Y_MSB__POS (0) +#define BMI160_USER_DATA_3_MAG_Y_MSB__LEN (8) +#define BMI160_USER_DATA_3_MAG_Y_MSB__MSK (0xFF) +#define BMI160_USER_DATA_3_MAG_Y_MSB__REG (BMI160_USER_DATA_3_ADDR) + +/* Mag_Z(LSB) Description - Reg Addr --> (0x08), Bit --> 0...7 */ +#define BMI160_USER_DATA_4_MAG_Z_LSB__POS (0) +#define BMI160_USER_DATA_4_MAG_Z_LSB__LEN (8) +#define BMI160_USER_DATA_4_MAG_Z_LSB__MSK (0xFF) +#define BMI160_USER_DATA_4_MAG_Z_LSB__REG (BMI160_USER_DATA_4_ADDR) + +/* Mag_X(LSB) Description - Reg Addr --> (0x08), Bit --> 3...7 */ +#define BMI160_USER_DATA_MAG_Z_LSB__POS (1) +#define BMI160_USER_DATA_MAG_Z_LSB__LEN (7) +#define BMI160_USER_DATA_MAG_Z_LSB__MSK (0xFE) +#define BMI160_USER_DATA_MAG_Z_LSB__REG (BMI160_USER_DATA_4_ADDR) + +/* Mag_Z(MSB) Description - Reg Addr --> (0x09), Bit --> 0...7 */ +#define BMI160_USER_DATA_5_MAG_Z_MSB__POS (0) +#define BMI160_USER_DATA_5_MAG_Z_MSB__LEN (8) +#define BMI160_USER_DATA_5_MAG_Z_MSB__MSK (0xFF) +#define BMI160_USER_DATA_5_MAG_Z_MSB__REG (BMI160_USER_DATA_5_ADDR) + +/* RHALL(LSB) Description - Reg Addr --> (0x0A), Bit --> 0...7 */ +#define BMI160_USER_DATA_6_RHALL_LSB__POS (0) +#define BMI160_USER_DATA_6_RHALL_LSB__LEN (8) +#define BMI160_USER_DATA_6_RHALL_LSB__MSK (0xFF) +#define BMI160_USER_DATA_6_RHALL_LSB__REG (BMI160_USER_DATA_6_ADDR) + +/* Mag_R(LSB) Description - Reg Addr --> (0x0A), Bit --> 3...7 */ +#define BMI160_USER_DATA_MAG_R_LSB__POS (2) +#define BMI160_USER_DATA_MAG_R_LSB__LEN (6) +#define BMI160_USER_DATA_MAG_R_LSB__MSK (0xFC) +#define BMI160_USER_DATA_MAG_R_LSB__REG (BMI160_USER_DATA_6_ADDR) + +/* RHALL(MSB) Description - Reg Addr --> (0x0B), Bit --> 0...7 */ +#define BMI160_USER_DATA_7_RHALL_MSB__POS (0) +#define BMI160_USER_DATA_7_RHALL_MSB__LEN (8) +#define BMI160_USER_DATA_7_RHALL_MSB__MSK (0xFF) +#define BMI160_USER_DATA_7_RHALL_MSB__REG (BMI160_USER_DATA_7_ADDR) +/**************************************************************/ +/**\name GYRO DATA XYZ LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* GYR_X (LSB) Description - Reg Addr --> (0x0C), Bit --> 0...7 */ +#define BMI160_USER_DATA_8_GYRO_X_LSB__POS (0) +#define BMI160_USER_DATA_8_GYRO_X_LSB__LEN (8) +#define BMI160_USER_DATA_8_GYRO_X_LSB__MSK (0xFF) +#define BMI160_USER_DATA_8_GYRO_X_LSB__REG (BMI160_USER_DATA_8_ADDR) + +/* GYR_X (MSB) Description - Reg Addr --> (0x0D), Bit --> 0...7 */ +#define BMI160_USER_DATA_9_GYRO_X_MSB__POS (0) +#define BMI160_USER_DATA_9_GYRO_X_MSB__LEN (8) +#define BMI160_USER_DATA_9_GYRO_X_MSB__MSK (0xFF) +#define BMI160_USER_DATA_9_GYRO_X_MSB__REG (BMI160_USER_DATA_9_ADDR) + +/* GYR_Y (LSB) Description - Reg Addr --> 0x0E, Bit --> 0...7 */ +#define BMI160_USER_DATA_10_GYRO_Y_LSB__POS (0) +#define BMI160_USER_DATA_10_GYRO_Y_LSB__LEN (8) +#define BMI160_USER_DATA_10_GYRO_Y_LSB__MSK (0xFF) +#define BMI160_USER_DATA_10_GYRO_Y_LSB__REG (BMI160_USER_DATA_10_ADDR) + +/* GYR_Y (MSB) Description - Reg Addr --> (0x0F), Bit --> 0...7 */ +#define BMI160_USER_DATA_11_GYRO_Y_MSB__POS (0) +#define BMI160_USER_DATA_11_GYRO_Y_MSB__LEN (8) +#define BMI160_USER_DATA_11_GYRO_Y_MSB__MSK (0xFF) +#define BMI160_USER_DATA_11_GYRO_Y_MSB__REG (BMI160_USER_DATA_11_ADDR) + +/* GYR_Z (LSB) Description - Reg Addr --> (0x10), Bit --> 0...7 */ +#define BMI160_USER_DATA_12_GYRO_Z_LSB__POS (0) +#define BMI160_USER_DATA_12_GYRO_Z_LSB__LEN (8) +#define BMI160_USER_DATA_12_GYRO_Z_LSB__MSK (0xFF) +#define BMI160_USER_DATA_12_GYRO_Z_LSB__REG (BMI160_USER_DATA_12_ADDR) + +/* GYR_Z (MSB) Description - Reg Addr --> (0x11), Bit --> 0...7 */ +#define BMI160_USER_DATA_13_GYRO_Z_MSB__POS (0) +#define BMI160_USER_DATA_13_GYRO_Z_MSB__LEN (8) +#define BMI160_USER_DATA_13_GYRO_Z_MSB__MSK (0xFF) +#define BMI160_USER_DATA_13_GYRO_Z_MSB__REG (BMI160_USER_DATA_13_ADDR) +/**************************************************************/ +/**\name ACCEL DATA XYZ LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* ACC_X (LSB) Description - Reg Addr --> (0x12), Bit --> 0...7 */ +#define BMI160_USER_DATA_14_ACCEL_X_LSB__POS (0) +#define BMI160_USER_DATA_14_ACCEL_X_LSB__LEN (8) +#define BMI160_USER_DATA_14_ACCEL_X_LSB__MSK (0xFF) +#define BMI160_USER_DATA_14_ACCEL_X_LSB__REG (BMI160_USER_DATA_14_ADDR) + +/* ACC_X (MSB) Description - Reg Addr --> 0x13, Bit --> 0...7 */ +#define BMI160_USER_DATA_15_ACCEL_X_MSB__POS (0) +#define BMI160_USER_DATA_15_ACCEL_X_MSB__LEN (8) +#define BMI160_USER_DATA_15_ACCEL_X_MSB__MSK (0xFF) +#define BMI160_USER_DATA_15_ACCEL_X_MSB__REG (BMI160_USER_DATA_15_ADDR) + +/* ACC_Y (LSB) Description - Reg Addr --> (0x14), Bit --> 0...7 */ +#define BMI160_USER_DATA_16_ACCEL_Y_LSB__POS (0) +#define BMI160_USER_DATA_16_ACCEL_Y_LSB__LEN (8) +#define BMI160_USER_DATA_16_ACCEL_Y_LSB__MSK (0xFF) +#define BMI160_USER_DATA_16_ACCEL_Y_LSB__REG (BMI160_USER_DATA_16_ADDR) + +/* ACC_Y (MSB) Description - Reg Addr --> (0x15), Bit --> 0...7 */ +#define BMI160_USER_DATA_17_ACCEL_Y_MSB__POS (0) +#define BMI160_USER_DATA_17_ACCEL_Y_MSB__LEN (8) +#define BMI160_USER_DATA_17_ACCEL_Y_MSB__MSK (0xFF) +#define BMI160_USER_DATA_17_ACCEL_Y_MSB__REG (BMI160_USER_DATA_17_ADDR) + +/* ACC_Z (LSB) Description - Reg Addr --> 0x16, Bit --> 0...7 */ +#define BMI160_USER_DATA_18_ACCEL_Z_LSB__POS (0) +#define BMI160_USER_DATA_18_ACCEL_Z_LSB__LEN (8) +#define BMI160_USER_DATA_18_ACCEL_Z_LSB__MSK (0xFF) +#define BMI160_USER_DATA_18_ACCEL_Z_LSB__REG (BMI160_USER_DATA_18_ADDR) + +/* ACC_Z (MSB) Description - Reg Addr --> (0x17), Bit --> 0...7 */ +#define BMI160_USER_DATA_19_ACCEL_Z_MSB__POS (0) +#define BMI160_USER_DATA_19_ACCEL_Z_MSB__LEN (8) +#define BMI160_USER_DATA_19_ACCEL_Z_MSB__MSK (0xFF) +#define BMI160_USER_DATA_19_ACCEL_Z_MSB__REG (BMI160_USER_DATA_19_ADDR) +/**************************************************************/ +/**\name SENSOR TIME LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* SENSORTIME_0 (LSB) Description - Reg Addr --> (0x18), Bit --> 0...7 */ +#define BMI160_USER_SENSORTIME_0_SENSOR_TIME_LSB__POS (0) +#define BMI160_USER_SENSORTIME_0_SENSOR_TIME_LSB__LEN (8) +#define BMI160_USER_SENSORTIME_0_SENSOR_TIME_LSB__MSK (0xFF) +#define BMI160_USER_SENSORTIME_0_SENSOR_TIME_LSB__REG \ + (BMI160_USER_SENSORTIME_0_ADDR) + +/* SENSORTIME_1 (MSB) Description - Reg Addr --> (0x19), Bit --> 0...7 */ +#define BMI160_USER_SENSORTIME_1_SENSOR_TIME_MSB__POS (0) +#define BMI160_USER_SENSORTIME_1_SENSOR_TIME_MSB__LEN (8) +#define BMI160_USER_SENSORTIME_1_SENSOR_TIME_MSB__MSK (0xFF) +#define BMI160_USER_SENSORTIME_1_SENSOR_TIME_MSB__REG \ + (BMI160_USER_SENSORTIME_1_ADDR) + +/* SENSORTIME_2 (MSB) Description - Reg Addr --> (0x1A), Bit --> 0...7 */ +#define BMI160_USER_SENSORTIME_2_SENSOR_TIME_MSB__POS (0) +#define BMI160_USER_SENSORTIME_2_SENSOR_TIME_MSB__LEN (8) +#define BMI160_USER_SENSORTIME_2_SENSOR_TIME_MSB__MSK (0xFF) +#define BMI160_USER_SENSORTIME_2_SENSOR_TIME_MSB__REG \ + (BMI160_USER_SENSORTIME_2_ADDR) +/**************************************************************/ +/**\name GYRO SELF TEST LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 1 */ +#define BMI160_USER_STAT_GYRO_SELFTEST_OK__POS (1) +#define BMI160_USER_STAT_GYRO_SELFTEST_OK__LEN (1) +#define BMI160_USER_STAT_GYRO_SELFTEST_OK__MSK (0x02) +#define BMI160_USER_STAT_GYRO_SELFTEST_OK__REG \ + (BMI160_USER_STAT_ADDR) +/**************************************************************/ +/**\name MAG MANUAL OPERATION LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 2 */ +#define BMI160_USER_STAT_MAG_MANUAL_OPERATION__POS (2) +#define BMI160_USER_STAT_MAG_MANUAL_OPERATION__LEN (1) +#define BMI160_USER_STAT_MAG_MANUAL_OPERATION__MSK (0x04) +#define BMI160_USER_STAT_MAG_MANUAL_OPERATION__REG \ + (BMI160_USER_STAT_ADDR) +/**************************************************************/ +/**\name FOC STATUS LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 3 */ +#define BMI160_USER_STAT_FOC_RDY__POS (3) +#define BMI160_USER_STAT_FOC_RDY__LEN (1) +#define BMI160_USER_STAT_FOC_RDY__MSK (0x08) +#define BMI160_USER_STAT_FOC_RDY__REG (BMI160_USER_STAT_ADDR) +/**************************************************************/ +/**\name NVM READY LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 4 */ +#define BMI160_USER_STAT_NVM_RDY__POS (4) +#define BMI160_USER_STAT_NVM_RDY__LEN (1) +#define BMI160_USER_STAT_NVM_RDY__MSK (0x10) +#define BMI160_USER_STAT_NVM_RDY__REG (BMI160_USER_STAT_ADDR) +/**************************************************************/ +/**\name DATA READY LENGTH, POSITION AND MASK FOR ACCEL, MAG AND GYRO*/ +/**************************************************************/ +/* Status Description - Reg Addr --> 0x1B, Bit --> 5 */ +#define BMI160_USER_STAT_DATA_RDY_MAG__POS (5) +#define BMI160_USER_STAT_DATA_RDY_MAG__LEN (1) +#define BMI160_USER_STAT_DATA_RDY_MAG__MSK (0x20) +#define BMI160_USER_STAT_DATA_RDY_MAG__REG (BMI160_USER_STAT_ADDR) + +/* Status Description - Reg Addr --> 0x1B, Bit --> 6 */ +#define BMI160_USER_STAT_DATA_RDY_GYRO__POS (6) +#define BMI160_USER_STAT_DATA_RDY_GYRO__LEN (1) +#define BMI160_USER_STAT_DATA_RDY_GYRO__MSK (0x40) +#define BMI160_USER_STAT_DATA_RDY_GYRO__REG (BMI160_USER_STAT_ADDR) + +/* Status Description - Reg Addr --> 0x1B, Bit --> 7 */ +#define BMI160_USER_STAT_DATA_RDY_ACCEL__POS (7) +#define BMI160_USER_STAT_DATA_RDY_ACCEL__LEN (1) +#define BMI160_USER_STAT_DATA_RDY_ACCEL__MSK (0x80) +#define BMI160_USER_STAT_DATA_RDY_ACCEL__REG (BMI160_USER_STAT_ADDR) +/**************************************************************/ +/**\name INTERRUPT STATUS LENGTH, POSITION AND MASK */ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 0 */ +#define BMI160_USER_INTR_STAT_0_STEP_INTR__POS (0) +#define BMI160_USER_INTR_STAT_0_STEP_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_0_STEP_INTR__MSK (0x01) +#define BMI160_USER_INTR_STAT_0_STEP_INTR__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name SIGNIFICANT INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 1 */ +#define BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR__POS (1) +#define BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR__MSK (0x02) +#define BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name ANY_MOTION INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 2 */ +#define BMI160_USER_INTR_STAT_0_ANY_MOTION__POS (2) +#define BMI160_USER_INTR_STAT_0_ANY_MOTION__LEN (1) +#define BMI160_USER_INTR_STAT_0_ANY_MOTION__MSK (0x04) +#define BMI160_USER_INTR_STAT_0_ANY_MOTION__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name PMU TRIGGER INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 3 */ +#define BMI160_USER_INTR_STAT_0_PMU_TRIGGER__POS 3 +#define BMI160_USER_INTR_STAT_0_PMU_TRIGGER__LEN (1) +#define BMI160_USER_INTR_STAT_0_PMU_TRIGGER__MSK (0x08) +#define BMI160_USER_INTR_STAT_0_PMU_TRIGGER__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name DOUBLE TAP INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 4 */ +#define BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR__POS 4 +#define BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR__MSK (0x10) +#define BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name SINGLE TAP INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 5 */ +#define BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR__POS 5 +#define BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR__MSK (0x20) +#define BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name ORIENT INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 6 */ +#define BMI160_USER_INTR_STAT_0_ORIENT__POS (6) +#define BMI160_USER_INTR_STAT_0_ORIENT__LEN (1) +#define BMI160_USER_INTR_STAT_0_ORIENT__MSK (0x40) +#define BMI160_USER_INTR_STAT_0_ORIENT__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name FLAT INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_0 Description - Reg Addr --> 0x1C, Bit --> 7 */ +#define BMI160_USER_INTR_STAT_0_FLAT__POS (7) +#define BMI160_USER_INTR_STAT_0_FLAT__LEN (1) +#define BMI160_USER_INTR_STAT_0_FLAT__MSK (0x80) +#define BMI160_USER_INTR_STAT_0_FLAT__REG \ + (BMI160_USER_INTR_STAT_0_ADDR) +/**************************************************************/ +/**\name HIGH_G INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 2 */ +#define BMI160_USER_INTR_STAT_1_HIGH_G_INTR__POS (2) +#define BMI160_USER_INTR_STAT_1_HIGH_G_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_1_HIGH_G_INTR__MSK (0x04) +#define BMI160_USER_INTR_STAT_1_HIGH_G_INTR__REG \ + (BMI160_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name LOW_G INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 3 */ +#define BMI160_USER_INTR_STAT_1_LOW_G_INTR__POS (3) +#define BMI160_USER_INTR_STAT_1_LOW_G_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_1_LOW_G_INTR__MSK (0x08) +#define BMI160_USER_INTR_STAT_1_LOW_G_INTR__REG \ + (BMI160_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name DATA READY INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 4 */ +#define BMI160_USER_INTR_STAT_1_DATA_RDY_INTR__POS (4) +#define BMI160_USER_INTR_STAT_1_DATA_RDY_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_1_DATA_RDY_INTR__MSK (0x10) +#define BMI160_USER_INTR_STAT_1_DATA_RDY_INTR__REG \ + (BMI160_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name FIFO FULL INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 5 */ +#define BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR__POS (5) +#define BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR__MSK (0x20) +#define BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR__REG \ + (BMI160_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name FIFO WATERMARK INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 6 */ +#define BMI160_USER_INTR_STAT_1_FIFO_WM_INTR__POS (6) +#define BMI160_USER_INTR_STAT_1_FIFO_WM_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_1_FIFO_WM_INTR__MSK (0x40) +#define BMI160_USER_INTR_STAT_1_FIFO_WM_INTR__REG \ + (BMI160_USER_INTR_STAT_1_ADDR) +/**************************************************************/ +/**\name NO MOTION INTERRUPT STATUS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_1 Description - Reg Addr --> 0x1D, Bit --> 7 */ +#define BMI160_USER_INTR_STAT_1_NOMOTION_INTR__POS (7) +#define BMI160_USER_INTR_STAT_1_NOMOTION_INTR__LEN (1) +#define BMI160_USER_INTR_STAT_1_NOMOTION_INTR__MSK (0x80) +#define BMI160_USER_INTR_STAT_1_NOMOTION_INTR__REG \ + (BMI160_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 BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__POS (0) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__LEN (1) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__MSK (0x01) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__REG \ + (BMI160_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 1 */ +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__POS (1) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__LEN (1) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__MSK (0x02) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__REG \ + (BMI160_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 2 */ +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__POS (2) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__LEN (1) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__MSK (0x04) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__REG \ + (BMI160_USER_INTR_STAT_2_ADDR) +/**************************************************************/ +/**\name ANY MOTION SIGN LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 3 */ +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN__POS (3) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN__LEN (1) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN__MSK (0x08) +#define BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN__REG \ + (BMI160_USER_INTR_STAT_2_ADDR) +/**************************************************************/ +/**\name TAP_XYZ AND SIGN LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 4 */ +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_X__POS (4) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_X__LEN (1) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_X__MSK (0x10) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_X__REG \ + (BMI160_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 5 */ +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Y__POS (5) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Y__LEN (1) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Y__MSK (0x20) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Y__REG \ + (BMI160_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 6 */ +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Z__POS (6) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Z__LEN (1) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Z__MSK (0x40) +#define BMI160_USER_INTR_STAT_2_TAP_FIRST_Z__REG \ + (BMI160_USER_INTR_STAT_2_ADDR) + +/* Int_Status_2 Description - Reg Addr --> 0x1E, Bit --> 7 */ +#define BMI160_USER_INTR_STAT_2_TAP_SIGN__POS (7) +#define BMI160_USER_INTR_STAT_2_TAP_SIGN__LEN (1) +#define BMI160_USER_INTR_STAT_2_TAP_SIGN__MSK (0x80) +#define BMI160_USER_INTR_STAT_2_TAP_SIGN__REG \ + (BMI160_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 BMI160_USER_INTR_STAT_2__POS (0) +#define BMI160_USER_INTR_STAT_2__LEN (8) +#define BMI160_USER_INTR_STAT_2__MSK (0xFF) +#define BMI160_USER_INTR_STAT_2__REG \ + (BMI160_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 BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X__POS (0) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X__LEN (1) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X__MSK (0x01) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X__REG \ + (BMI160_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> 0x1E, Bit --> 1 */ +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y__POS (1) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y__LEN (1) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y__MSK (0x02) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y__REG \ + (BMI160_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 2 */ +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z__POS (2) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z__LEN (1) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z__MSK (0x04) +#define BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z__REG \ + (BMI160_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 3 */ +#define BMI160_USER_INTR_STAT_3_HIGH_G_SIGN__POS (3) +#define BMI160_USER_INTR_STAT_3_HIGH_G_SIGN__LEN (1) +#define BMI160_USER_INTR_STAT_3_HIGH_G_SIGN__MSK (0x08) +#define BMI160_USER_INTR_STAT_3_HIGH_G_SIGN__REG \ + (BMI160_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 BMI160_USER_INTR_STAT_3_ORIENT_XY__POS (4) +#define BMI160_USER_INTR_STAT_3_ORIENT_XY__LEN (2) +#define BMI160_USER_INTR_STAT_3_ORIENT_XY__MSK (0x30) +#define BMI160_USER_INTR_STAT_3_ORIENT_XY__REG \ + (BMI160_USER_INTR_STAT_3_ADDR) + +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 6 */ +#define BMI160_USER_INTR_STAT_3_ORIENT_Z__POS (6) +#define BMI160_USER_INTR_STAT_3_ORIENT_Z__LEN (1) +#define BMI160_USER_INTR_STAT_3_ORIENT_Z__MSK (0x40) +#define BMI160_USER_INTR_STAT_3_ORIENT_Z__REG \ + (BMI160_USER_INTR_STAT_3_ADDR) +/**************************************************************/ +/**\name FLAT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 7 */ +#define BMI160_USER_INTR_STAT_3_FLAT__POS (7) +#define BMI160_USER_INTR_STAT_3_FLAT__LEN (1) +#define BMI160_USER_INTR_STAT_3_FLAT__MSK (0x80) +#define BMI160_USER_INTR_STAT_3_FLAT__REG \ + (BMI160_USER_INTR_STAT_3_ADDR) +/**************************************************************/ +/**\name (0x1F) LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Status_3 Description - Reg Addr --> (0x1F), Bit --> 0...7 */ +#define BMI160_USER_INTR_STAT_3__POS (0) +#define BMI160_USER_INTR_STAT_3__LEN (8) +#define BMI160_USER_INTR_STAT_3__MSK (0xFF) +#define BMI160_USER_INTR_STAT_3__REG \ + (BMI160_USER_INTR_STAT_3_ADDR) +/**************************************************************/ +/**\name TEMPERATURE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Temperature Description - LSB Reg Addr --> (0x20), Bit --> 0...7 */ +#define BMI160_USER_TEMP_LSB_VALUE__POS (0) +#define BMI160_USER_TEMP_LSB_VALUE__LEN (8) +#define BMI160_USER_TEMP_LSB_VALUE__MSK (0xFF) +#define BMI160_USER_TEMP_LSB_VALUE__REG \ + (BMI160_USER_TEMPERATURE_0_ADDR) + +/* Temperature Description - LSB Reg Addr --> 0x21, Bit --> 0...7 */ +#define BMI160_USER_TEMP_MSB_VALUE__POS (0) +#define BMI160_USER_TEMP_MSB_VALUE__LEN (8) +#define BMI160_USER_TEMP_MSB_VALUE__MSK (0xFF) +#define BMI160_USER_TEMP_MSB_VALUE__REG \ + (BMI160_USER_TEMPERATURE_1_ADDR) +/**************************************************************/ +/**\name FIFO BYTE COUNTER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Length0 Description - Reg Addr --> 0x22, Bit --> 0...7 */ +#define BMI160_USER_FIFO_BYTE_COUNTER_LSB__POS (0) +#define BMI160_USER_FIFO_BYTE_COUNTER_LSB__LEN (8) +#define BMI160_USER_FIFO_BYTE_COUNTER_LSB__MSK (0xFF) +#define BMI160_USER_FIFO_BYTE_COUNTER_LSB__REG \ + (BMI160_USER_FIFO_LENGTH_0_ADDR) + +/*Fifo_Length1 Description - Reg Addr --> 0x23, Bit --> 0...2 */ +#define BMI160_USER_FIFO_BYTE_COUNTER_MSB__POS (0) +#define BMI160_USER_FIFO_BYTE_COUNTER_MSB__LEN 3 +#define BMI160_USER_FIFO_BYTE_COUNTER_MSB__MSK (0x07) +#define BMI160_USER_FIFO_BYTE_COUNTER_MSB__REG \ + (BMI160_USER_FIFO_LENGTH_1_ADDR) + +/**************************************************************/ +/**\name FIFO DATA LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Data Description - Reg Addr --> 0x24, Bit --> 0...7 */ +#define BMI160_USER_FIFO_DATA__POS (0) +#define BMI160_USER_FIFO_DATA__LEN (8) +#define BMI160_USER_FIFO_DATA__MSK (0xFF) +#define BMI160_USER_FIFO_DATA__REG (BMI160_USER_FIFO_DATA_ADDR) + +/**************************************************************/ +/**\name ACCEL CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Acc_Conf Description - Reg Addr --> (0x40), Bit --> 0...3 */ +#define BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__POS (0) +#define BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__LEN (4) +#define BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__MSK (0x0F) +#define BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG \ +(BMI160_USER_ACCEL_CONFIG_ADDR) + +/* Acc_Conf Description - Reg Addr --> (0x40), Bit --> 4...6 */ +#define BMI160_USER_ACCEL_CONFIG_ACCEL_BW__POS (4) +#define BMI160_USER_ACCEL_CONFIG_ACCEL_BW__LEN (3) +#define BMI160_USER_ACCEL_CONFIG_ACCEL_BW__MSK (0x70) +#define BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG (BMI160_USER_ACCEL_CONFIG_ADDR) + +/* Acc_Conf Description - Reg Addr --> (0x40), Bit --> 7 */ +#define BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__POS (7) +#define BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__LEN (1) +#define BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__MSK (0x80) +#define BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG \ +(BMI160_USER_ACCEL_CONFIG_ADDR) + +/* Acc_Range Description - Reg Addr --> 0x41, Bit --> 0...3 */ +#define BMI160_USER_ACCEL_RANGE__POS (0) +#define BMI160_USER_ACCEL_RANGE__LEN (4) +#define BMI160_USER_ACCEL_RANGE__MSK (0x0F) +#define BMI160_USER_ACCEL_RANGE__REG \ +(BMI160_USER_ACCEL_RANGE_ADDR) +/**************************************************************/ +/**\name GYRO CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Gyro_Conf Description - Reg Addr --> (0x42), Bit --> 0...3 */ +#define BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__POS (0) +#define BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__LEN (4) +#define BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__MSK (0x0F) +#define BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG \ +(BMI160_USER_GYRO_CONFIG_ADDR) + +/* Gyro_Conf Description - Reg Addr --> (0x42), Bit --> 4...5 */ +#define BMI160_USER_GYRO_CONFIG_BW__POS (4) +#define BMI160_USER_GYRO_CONFIG_BW__LEN (2) +#define BMI160_USER_GYRO_CONFIG_BW__MSK (0x30) +#define BMI160_USER_GYRO_CONFIG_BW__REG \ +(BMI160_USER_GYRO_CONFIG_ADDR) + +/* Gyr_Range Description - Reg Addr --> 0x43, Bit --> 0...2 */ +#define BMI160_USER_GYRO_RANGE__POS (0) +#define BMI160_USER_GYRO_RANGE__LEN (3) +#define BMI160_USER_GYRO_RANGE__MSK (0x07) +#define BMI160_USER_GYRO_RANGE__REG (BMI160_USER_GYRO_RANGE_ADDR) +/**************************************************************/ +/**\name MAG CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Mag_Conf Description - Reg Addr --> (0x44), Bit --> 0...3 */ +#define BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__POS (0) +#define BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__LEN (4) +#define BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__MSK (0x0F) +#define BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG \ +(BMI160_USER_MAG_CONFIG_ADDR) +/**************************************************************/ +/**\name FIFO DOWNS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Downs Description - Reg Addr --> 0x45, Bit --> 0...2 */ +#define BMI160_USER_FIFO_DOWN_GYRO__POS (0) +#define BMI160_USER_FIFO_DOWN_GYRO__LEN (3) +#define BMI160_USER_FIFO_DOWN_GYRO__MSK (0x07) +#define BMI160_USER_FIFO_DOWN_GYRO__REG (BMI160_USER_FIFO_DOWN_ADDR) +/**************************************************************/ +/**\name FIFO FILTER FOR ACCEL AND GYRO LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_filt Description - Reg Addr --> 0x45, Bit --> 3 */ +#define BMI160_USER_FIFO_FILTER_GYRO__POS (3) +#define BMI160_USER_FIFO_FILTER_GYRO__LEN (1) +#define BMI160_USER_FIFO_FILTER_GYRO__MSK (0x08) +#define BMI160_USER_FIFO_FILTER_GYRO__REG (BMI160_USER_FIFO_DOWN_ADDR) + +/* Fifo_Downs Description - Reg Addr --> 0x45, Bit --> 4...6 */ +#define BMI160_USER_FIFO_DOWN_ACCEL__POS (4) +#define BMI160_USER_FIFO_DOWN_ACCEL__LEN (3) +#define BMI160_USER_FIFO_DOWN_ACCEL__MSK (0x70) +#define BMI160_USER_FIFO_DOWN_ACCEL__REG (BMI160_USER_FIFO_DOWN_ADDR) + +/* Fifo_FILT Description - Reg Addr --> 0x45, Bit --> 7 */ +#define BMI160_USER_FIFO_FILTER_ACCEL__POS (7) +#define BMI160_USER_FIFO_FILTER_ACCEL__LEN (1) +#define BMI160_USER_FIFO_FILTER_ACCEL__MSK (0x80) +#define BMI160_USER_FIFO_FILTER_ACCEL__REG (BMI160_USER_FIFO_DOWN_ADDR) +/**************************************************************/ +/**\name FIFO WATER MARK LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_0 Description - Reg Addr --> 0x46, Bit --> 0...7 */ +#define BMI160_USER_FIFO_WM__POS (0) +#define BMI160_USER_FIFO_WM__LEN (8) +#define BMI160_USER_FIFO_WM__MSK (0xFF) +#define BMI160_USER_FIFO_WM__REG (BMI160_USER_FIFO_CONFIG_0_ADDR) +/**************************************************************/ +/**\name FIFO TIME LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 1 */ +#define BMI160_USER_FIFO_TIME_ENABLE__POS (1) +#define BMI160_USER_FIFO_TIME_ENABLE__LEN (1) +#define BMI160_USER_FIFO_TIME_ENABLE__MSK (0x02) +#define BMI160_USER_FIFO_TIME_ENABLE__REG (BMI160_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO TAG INTERRUPT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 2 */ +#define BMI160_USER_FIFO_TAG_INTR2_ENABLE__POS (2) +#define BMI160_USER_FIFO_TAG_INTR2_ENABLE__LEN (1) +#define BMI160_USER_FIFO_TAG_INTR2_ENABLE__MSK (0x04) +#define BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG (BMI160_USER_FIFO_CONFIG_1_ADDR) + +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 3 */ +#define BMI160_USER_FIFO_TAG_INTR1_ENABLE__POS (3) +#define BMI160_USER_FIFO_TAG_INTR1_ENABLE__LEN (1) +#define BMI160_USER_FIFO_TAG_INTR1_ENABLE__MSK (0x08) +#define BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG (BMI160_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO HEADER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 4 */ +#define BMI160_USER_FIFO_HEADER_ENABLE__POS (4) +#define BMI160_USER_FIFO_HEADER_ENABLE__LEN (1) +#define BMI160_USER_FIFO_HEADER_ENABLE__MSK (0x10) +#define BMI160_USER_FIFO_HEADER_ENABLE__REG \ +(BMI160_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO MAG ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 5 */ +#define BMI160_USER_FIFO_MAG_ENABLE__POS (5) +#define BMI160_USER_FIFO_MAG_ENABLE__LEN (1) +#define BMI160_USER_FIFO_MAG_ENABLE__MSK (0x20) +#define BMI160_USER_FIFO_MAG_ENABLE__REG \ +(BMI160_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO ACCEL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 6 */ +#define BMI160_USER_FIFO_ACCEL_ENABLE__POS (6) +#define BMI160_USER_FIFO_ACCEL_ENABLE__LEN (1) +#define BMI160_USER_FIFO_ACCEL_ENABLE__MSK (0x40) +#define BMI160_USER_FIFO_ACCEL_ENABLE__REG \ +(BMI160_USER_FIFO_CONFIG_1_ADDR) +/**************************************************************/ +/**\name FIFO GYRO ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Fifo_Config_1 Description - Reg Addr --> 0x47, Bit --> 7 */ +#define BMI160_USER_FIFO_GYRO_ENABLE__POS (7) +#define BMI160_USER_FIFO_GYRO_ENABLE__LEN (1) +#define BMI160_USER_FIFO_GYRO_ENABLE__MSK (0x80) +#define BMI160_USER_FIFO_GYRO_ENABLE__REG \ +(BMI160_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 BMI160_USER_I2C_DEVICE_ADDR__POS (1) +#define BMI160_USER_I2C_DEVICE_ADDR__LEN (7) +#define BMI160_USER_I2C_DEVICE_ADDR__MSK (0xFE) +#define BMI160_USER_I2C_DEVICE_ADDR__REG (BMI160_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 BMI160_USER_MAG_BURST__POS (0) +#define BMI160_USER_MAG_BURST__LEN (2) +#define BMI160_USER_MAG_BURST__MSK (0x03) +#define BMI160_USER_MAG_BURST__REG (BMI160_USER_MAG_IF_1_ADDR) + +/* Mag_IF_1 Description - Reg Addr --> 0x4c, Bit --> 2...5 */ +#define BMI160_USER_MAG_OFFSET__POS (2) +#define BMI160_USER_MAG_OFFSET__LEN (4) +#define BMI160_USER_MAG_OFFSET__MSK (0x3C) +#define BMI160_USER_MAG_OFFSET__REG (BMI160_USER_MAG_IF_1_ADDR) + +/* Mag_IF_1 Description - Reg Addr --> 0x4c, Bit --> 7 */ +#define BMI160_USER_MAG_MANUAL_ENABLE__POS (7) +#define BMI160_USER_MAG_MANUAL_ENABLE__LEN (1) +#define BMI160_USER_MAG_MANUAL_ENABLE__MSK (0x80) +#define BMI160_USER_MAG_MANUAL_ENABLE__REG \ +(BMI160_USER_MAG_IF_1_ADDR) + +/* Mag_IF_2 Description - Reg Addr --> 0x4d, Bit -->0... 7 */ +#define BMI160_USER_READ_ADDR__POS (0) +#define BMI160_USER_READ_ADDR__LEN (8) +#define BMI160_USER_READ_ADDR__MSK (0xFF) +#define BMI160_USER_READ_ADDR__REG (BMI160_USER_MAG_IF_2_ADDR) + +/* Mag_IF_3 Description - Reg Addr --> 0x4e, Bit -->0... 7 */ +#define BMI160_USER_WRITE_ADDR__POS (0) +#define BMI160_USER_WRITE_ADDR__LEN (8) +#define BMI160_USER_WRITE_ADDR__MSK (0xFF) +#define BMI160_USER_WRITE_ADDR__REG (BMI160_USER_MAG_IF_3_ADDR) + +/* Mag_IF_4 Description - Reg Addr --> 0x4f, Bit -->0... 7 */ +#define BMI160_USER_WRITE_DATA__POS (0) +#define BMI160_USER_WRITE_DATA__LEN (8) +#define BMI160_USER_WRITE_DATA__MSK (0xFF) +#define BMI160_USER_WRITE_DATA__REG (BMI160_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 BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__POS (0) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__MSK (0x01) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_0_ADDR) + +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->1 */ +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__POS (1) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__MSK (0x02) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_0_ADDR) + +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->2 */ +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__POS (2) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__MSK (0x04) +#define BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name DOUBLE TAP ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->4 */ +#define BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__POS (4) +#define BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__MSK (0x10) +#define BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name SINGLE TAP ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->5 */ +#define BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__POS (5) +#define BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__MSK (0x20) +#define BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name ORIENT ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->6 */ +#define BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__POS (6) +#define BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__MSK (0x40) +#define BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name FLAT ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_0 Description - Reg Addr --> 0x50, Bit -->7 */ +#define BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__POS (7) +#define BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__MSK (0x80) +#define BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_0_ADDR) +/**************************************************************/ +/**\name HIGH_G XYZ ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->0 */ +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__POS (0) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__MSK (0x01) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_1_ADDR) + +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->1 */ +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__POS (1) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__MSK (0x02) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_1_ADDR) + +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->2 */ +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__POS (2) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__MSK (0x04) +#define BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_1_ADDR) +/**************************************************************/ +/**\name LOW_G ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->3 */ +#define BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__POS (3) +#define BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__MSK (0x08) +#define BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_1_ADDR) +/**************************************************************/ +/**\name DATA READY ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->4 */ +#define BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__POS (4) +#define BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__MSK (0x10) +#define BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG \ +(BMI160_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 BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__POS (5) +#define BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__MSK (0x20) +#define BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_1_ADDR) + +/* Int_En_1 Description - Reg Addr --> (0x51), Bit -->6 */ +#define BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__POS (6) +#define BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__MSK (0x40) +#define BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_1_ADDR) +/**************************************************************/ +/**\name NO MOTION XYZ ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->0 */ +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__POS (0) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__MSK (0x01) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_2_ADDR) + +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->1 */ +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__POS (1) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__MSK (0x02) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_2_ADDR) + +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->2 */ +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__POS (2) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__MSK (0x04) +#define BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_2_ADDR) +/**************************************************************/ +/**\name STEP DETECTOR ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_En_2 Description - Reg Addr --> (0x52), Bit -->3 */ +#define BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__POS (3) +#define BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__LEN (1) +#define BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__MSK (0x08) +#define BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG \ +(BMI160_USER_INTR_ENABLE_2_ADDR) +/**************************************************************/ +/**\name EDGE CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->0 */ +#define BMI160_USER_INTR1_EDGE_CTRL__POS (0) +#define BMI160_USER_INTR1_EDGE_CTRL__LEN (1) +#define BMI160_USER_INTR1_EDGE_CTRL__MSK (0x01) +#define BMI160_USER_INTR1_EDGE_CTRL__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name LEVEL CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->1 */ +#define BMI160_USER_INTR1_LEVEL__POS (1) +#define BMI160_USER_INTR1_LEVEL__LEN (1) +#define BMI160_USER_INTR1_LEVEL__MSK (0x02) +#define BMI160_USER_INTR1_LEVEL__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name OUTPUT TYPE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->2 */ +#define BMI160_USER_INTR1_OUTPUT_TYPE__POS (2) +#define BMI160_USER_INTR1_OUTPUT_TYPE__LEN (1) +#define BMI160_USER_INTR1_OUTPUT_TYPE__MSK (0x04) +#define BMI160_USER_INTR1_OUTPUT_TYPE__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name OUTPUT TYPE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->3 */ +#define BMI160_USER_INTR1_OUTPUT_ENABLE__POS (3) +#define BMI160_USER_INTR1_OUTPUT_ENABLE__LEN (1) +#define BMI160_USER_INTR1_OUTPUT_ENABLE__MSK (0x08) +#define BMI160_USER_INTR1_OUTPUT_ENABLE__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name EDGE CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->4 */ +#define BMI160_USER_INTR2_EDGE_CTRL__POS (4) +#define BMI160_USER_INTR2_EDGE_CTRL__LEN (1) +#define BMI160_USER_INTR2_EDGE_CTRL__MSK (0x10) +#define BMI160_USER_INTR2_EDGE_CTRL__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name LEVEL CONTROL ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->5 */ +#define BMI160_USER_INTR2_LEVEL__POS (5) +#define BMI160_USER_INTR2_LEVEL__LEN (1) +#define BMI160_USER_INTR2_LEVEL__MSK (0x20) +#define BMI160_USER_INTR2_LEVEL__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name OUTPUT TYPE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->6 */ +#define BMI160_USER_INTR2_OUTPUT_TYPE__POS (6) +#define BMI160_USER_INTR2_OUTPUT_TYPE__LEN (1) +#define BMI160_USER_INTR2_OUTPUT_TYPE__MSK (0x40) +#define BMI160_USER_INTR2_OUTPUT_TYPE__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) + +/* Int_Out_Ctrl Description - Reg Addr --> 0x53, Bit -->7 */ +#define BMI160_USER_INTR2_OUTPUT_EN__POS (7) +#define BMI160_USER_INTR2_OUTPUT_EN__LEN (1) +#define BMI160_USER_INTR2_OUTPUT_EN__MSK (0x80) +#define BMI160_USER_INTR2_OUTPUT_EN__REG \ +(BMI160_USER_INTR_OUT_CTRL_ADDR) +/**************************************************************/ +/**\name LATCH INTERRUPT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Latch Description - Reg Addr --> 0x54, Bit -->0...3 */ +#define BMI160_USER_INTR_LATCH__POS (0) +#define BMI160_USER_INTR_LATCH__LEN (4) +#define BMI160_USER_INTR_LATCH__MSK (0x0F) +#define BMI160_USER_INTR_LATCH__REG (BMI160_USER_INTR_LATCH_ADDR) +/**************************************************************/ +/**\name INPUT ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Latch Description - Reg Addr --> 0x54, Bit -->4 */ +#define BMI160_USER_INTR1_INPUT_ENABLE__POS (4) +#define BMI160_USER_INTR1_INPUT_ENABLE__LEN (1) +#define BMI160_USER_INTR1_INPUT_ENABLE__MSK (0x10) +#define BMI160_USER_INTR1_INPUT_ENABLE__REG \ +(BMI160_USER_INTR_LATCH_ADDR) + +/* Int_Latch Description - Reg Addr --> 0x54, Bit -->5*/ +#define BMI160_USER_INTR2_INPUT_ENABLE__POS (5) +#define BMI160_USER_INTR2_INPUT_ENABLE__LEN (1) +#define BMI160_USER_INTR2_INPUT_ENABLE__MSK (0x20) +#define BMI160_USER_INTR2_INPUT_ENABLE__REG \ +(BMI160_USER_INTR_LATCH_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF LOW_G LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->0 */ +#define BMI160_USER_INTR_MAP_0_INTR1_LOW_G__POS (0) +#define BMI160_USER_INTR_MAP_0_INTR1_LOW_G__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_LOW_G__MSK (0x01) +#define BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG (BMI160_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 BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__POS (1) +#define BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__MSK (0x02) +#define BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__POS (2) +#define BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__MSK (0x04) +#define BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__POS (3) +#define BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__MSK (0x08) +#define BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG (BMI160_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 BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__POS (4) +#define BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__MSK (0x10) +#define BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__POS (5) +#define BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__MSK (0x20) +#define BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG \ +(BMI160_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT1 MAPPIONG OF ORIENT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x55, Bit -->6 */ +#define BMI160_USER_INTR_MAP_0_INTR1_ORIENT__POS (6) +#define BMI160_USER_INTR_MAP_0_INTR1_ORIENT__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_ORIENT__MSK (0x40) +#define BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG \ +(BMI160_USER_INTR_MAP_0_ADDR) +/**************************************************************/ +/**\name INTERRUPT MAPPIONG OF FLAT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_0 Description - Reg Addr --> 0x56, Bit -->7 */ +#define BMI160_USER_INTR_MAP_0_INTR1_FLAT__POS (7) +#define BMI160_USER_INTR_MAP_0_INTR1_FLAT__LEN (1) +#define BMI160_USER_INTR_MAP_0_INTR1_FLAT__MSK (0x80) +#define BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG (BMI160_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 BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__POS (0) +#define BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__MSK (0x01) +#define BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG (BMI160_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 BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__POS (1) +#define BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__MSK (0x02) +#define BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG \ +(BMI160_USER_INTR_MAP_1_ADDR) + +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->2 */ +#define BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__POS (2) +#define BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__MSK (0x04) +#define BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__POS (3) +#define BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__MSK (0x08) +#define BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__POS (4) +#define BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__MSK (0x10) +#define BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG (BMI160_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 BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__POS (5) +#define BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__MSK (0x20) +#define BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG \ +(BMI160_USER_INTR_MAP_1_ADDR) + +/* Int_Map_1 Description - Reg Addr --> 0x56, Bit -->6 */ +#define BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__POS (6) +#define BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__MSK (0x40) +#define BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__POS (7) +#define BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__LEN (1) +#define BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__MSK (0x80) +#define BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_2_INTR2_LOW_G__POS (0) +#define BMI160_USER_INTR_MAP_2_INTR2_LOW_G__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_LOW_G__MSK (0x01) +#define BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG (BMI160_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 BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__POS (1) +#define BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__MSK (0x02) +#define BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__POS (2) +#define BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__MSK (0x04) +#define BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__POS (3) +#define BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__MSK (0x08) +#define BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG (BMI160_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 BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__POS (4) +#define BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__MSK (0x10) +#define BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG \ +(BMI160_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 BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__POS (5) +#define BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__MSK (0x20) +#define BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG \ +(BMI160_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF ORIENT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->6 */ +#define BMI160_USER_INTR_MAP_2_INTR2_ORIENT__POS (6) +#define BMI160_USER_INTR_MAP_2_INTR2_ORIENT__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_ORIENT__MSK (0x40) +#define BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG \ +(BMI160_USER_INTR_MAP_2_ADDR) +/**************************************************************/ +/**\name INTERRUPT2 MAPPIONG OF FLAT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Map_2 Description - Reg Addr --> 0x57, Bit -->7 */ +#define BMI160_USER_INTR_MAP_2_INTR2_FLAT__POS (7) +#define BMI160_USER_INTR_MAP_2_INTR2_FLAT__LEN (1) +#define BMI160_USER_INTR_MAP_2_INTR2_FLAT__MSK (0x80) +#define BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG (BMI160_USER_INTR_MAP_2_ADDR) + +/**************************************************************/ +/**\name TAP SOURCE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Data_0 Description - Reg Addr --> 0x58, Bit --> 3 */ +#define BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__POS (3) +#define BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__LEN (1) +#define BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__MSK (0x08) +#define BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG \ +(BMI160_USER_INTR_DATA_0_ADDR) + +/**************************************************************/ +/**\name HIGH SOURCE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Data_0 Description - Reg Addr --> 0x58, Bit --> 7 */ +#define BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__POS (7) +#define BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__LEN (1) +#define BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__MSK (0x80) +#define BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG \ +(BMI160_USER_INTR_DATA_0_ADDR) + +/**************************************************************/ +/**\name MOTION SOURCE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Data_1 Description - Reg Addr --> 0x59, Bit --> 7 */ +#define BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__POS (7) +#define BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__LEN (1) +#define BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__MSK (0x80) +#define BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG \ + (BMI160_USER_INTR_DATA_1_ADDR) +/**************************************************************/ +/**\name LOW HIGH DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_0 Description - Reg Addr --> 0x5a, Bit --> 0...7 */ +#define BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__POS (0) +#define BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__LEN (8) +#define BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__MSK (0xFF) +#define BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG \ + (BMI160_USER_INTR_LOWHIGH_0_ADDR) +/**************************************************************/ +/**\name LOW THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_1 Description - Reg Addr --> 0x5b, Bit --> 0...7 */ +#define BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__POS (0) +#define BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__LEN (8) +#define BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__MSK (0xFF) +#define BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG \ + (BMI160_USER_INTR_LOWHIGH_1_ADDR) +/**************************************************************/ +/**\name LOW HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_2 Description - Reg Addr --> 0x5c, Bit --> 0...1 */ +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__POS (0) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__LEN (2) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__MSK (0x03) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG \ + (BMI160_USER_INTR_LOWHIGH_2_ADDR) +/**************************************************************/ +/**\name LOW MODE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_2 Description - Reg Addr --> 0x5c, Bit --> 2 */ +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__POS (2) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__LEN (1) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__MSK (0x04) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG \ + (BMI160_USER_INTR_LOWHIGH_2_ADDR) +/**************************************************************/ +/**\name HIGH_G HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_2 Description - Reg Addr --> 0x5c, Bit --> 6...7 */ +#define BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__POS (6) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__LEN (2) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__MSK (0xC0) +#define BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG \ + (BMI160_USER_INTR_LOWHIGH_2_ADDR) +/**************************************************************/ +/**\name HIGH_G DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_3 Description - Reg Addr --> 0x5d, Bit --> 0...7 */ +#define BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__POS (0) +#define BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__LEN (8) +#define BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__MSK (0xFF) +#define BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG \ + (BMI160_USER_INTR_LOWHIGH_3_ADDR) +/**************************************************************/ +/**\name HIGH_G THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_LowHigh_4 Description - Reg Addr --> 0x5e, Bit --> 0...7 */ +#define BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__POS (0) +#define BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__LEN (8) +#define BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__MSK (0xFF) +#define BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG \ + (BMI160_USER_INTR_LOWHIGH_4_ADDR) +/**************************************************************/ +/**\name ANY MOTION DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_0 Description - Reg Addr --> 0x5f, Bit --> 0...1 */ +#define BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__POS (0) +#define BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__LEN (2) +#define BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__MSK (0x03) +#define BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG \ + (BMI160_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 BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__POS (2) +#define BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__LEN (6) +#define BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__MSK (0xFC) +#define BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG \ + (BMI160_USER_INTR_MOTION_0_ADDR) +/**************************************************************/ +/**\name ANY MOTION THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_1 Description - Reg Addr --> (0x60), Bit --> 0...7 */ +#define BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__POS (0) +#define BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__LEN (8) +#define BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__MSK (0xFF) +#define BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG \ + (BMI160_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 BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__POS (0) +#define BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__LEN (8) +#define BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__MSK (0xFF) +#define BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG \ + (BMI160_USER_INTR_MOTION_2_ADDR) +/**************************************************************/ +/**\name SLOW/NO MOTION SELECT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 0 */ +#define BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__POS (0) +#define BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__LEN (1) +#define BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__MSK (0x01) +#define BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG \ +(BMI160_USER_INTR_MOTION_3_ADDR) +/**************************************************************/ +/**\name SIGNIFICANT MOTION SELECT LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 1 */ +#define BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__POS (1) +#define BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__LEN (1) +#define BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__MSK (0x02) +#define BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG \ + (BMI160_USER_INTR_MOTION_3_ADDR) + +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 3..2 */ +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__POS (2) +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__LEN (2) +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__MSK (0x0C) +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG \ + (BMI160_USER_INTR_MOTION_3_ADDR) + +/* Int_Motion_3 Description - Reg Addr --> (0x62), Bit --> 5..4 */ +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__POS (4) +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__LEN (2) +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__MSK (0x30) +#define BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG \ + (BMI160_USER_INTR_MOTION_3_ADDR) +/**************************************************************/ +/**\name TAP DURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* INT_TAP_0 Description - Reg Addr --> (0x63), Bit --> 0..2*/ +#define BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__POS (0) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__LEN (3) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__MSK (0x07) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG \ +(BMI160_USER_INTR_TAP_0_ADDR) +/**************************************************************/ +/**\name TAP SHOCK LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Tap_0 Description - Reg Addr --> (0x63), Bit --> 6 */ +#define BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__POS (6) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__LEN (1) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__MSK (0x40) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG (BMI160_USER_INTR_TAP_0_ADDR) +/**************************************************************/ +/**\name TAP QUIET LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Tap_0 Description - Reg Addr --> (0x63), Bit --> 7 */ +#define BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__POS (7) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__LEN (1) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__MSK (0x80) +#define BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG (BMI160_USER_INTR_TAP_0_ADDR) +/**************************************************************/ +/**\name TAP THRESHOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Tap_1 Description - Reg Addr --> (0x64), Bit --> 0...4 */ +#define BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__POS (0) +#define BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__LEN (5) +#define BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__MSK (0x1F) +#define BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG (BMI160_USER_INTR_TAP_1_ADDR) +/**************************************************************/ +/**\name ORIENT MODE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_0 Description - Reg Addr --> (0x65), Bit --> 0...1 */ +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__POS (0) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__LEN (2) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__MSK (0x03) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG \ + (BMI160_USER_INTR_ORIENT_0_ADDR) +/**************************************************************/ +/**\name ORIENT BLOCKING LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_0 Description - Reg Addr --> (0x65), Bit --> 2...3 */ +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__POS (2) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__LEN (2) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__MSK (0x0C) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG \ + (BMI160_USER_INTR_ORIENT_0_ADDR) +/**************************************************************/ +/**\name ORIENT HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_0 Description - Reg Addr --> (0x65), Bit --> 4...7 */ +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__POS (4) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__LEN (4) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__MSK (0xF0) +#define BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG \ + (BMI160_USER_INTR_ORIENT_0_ADDR) +/**************************************************************/ +/**\name ORIENT THETA LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_1 Description - Reg Addr --> 0x66, Bit --> 0...5 */ +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__POS (0) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__LEN (6) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__MSK (0x3F) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG \ + (BMI160_USER_INTR_ORIENT_1_ADDR) +/**************************************************************/ +/**\name ORIENT UD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_1 Description - Reg Addr --> 0x66, Bit --> 6 */ +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__POS (6) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__LEN (1) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__MSK (0x40) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG \ + (BMI160_USER_INTR_ORIENT_1_ADDR) +/**************************************************************/ +/**\name ORIENT AXIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Orient_1 Description - Reg Addr --> 0x66, Bit --> 7 */ +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__POS (7) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__LEN (1) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__MSK (0x80) +#define BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG \ + (BMI160_USER_INTR_ORIENT_1_ADDR) +/**************************************************************/ +/**\name FLAT THETA LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Flat_0 Description - Reg Addr --> 0x67, Bit --> 0...5 */ +#define BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__POS (0) +#define BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__LEN (6) +#define BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__MSK (0x3F) +#define BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG \ + (BMI160_USER_INTR_FLAT_0_ADDR) +/**************************************************************/ +/**\name FLAT HYSTERESIS LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Flat_1 Description - Reg Addr --> (0x68), Bit --> 0...3 */ +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__POS (0) +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__LEN (4) +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__MSK (0x0F) +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG \ +(BMI160_USER_INTR_FLAT_1_ADDR) +/**************************************************************/ +/**\name FLAT HOLD LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Int_Flat_1 Description - Reg Addr --> (0x68), Bit --> 4...5 */ +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__POS (4) +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__LEN (2) +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__MSK (0x30) +#define BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG \ +(BMI160_USER_INTR_FLAT_1_ADDR) +/**************************************************************/ +/**\name FOC ACCEL XYZ LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 0...1 */ +#define BMI160_USER_FOC_ACCEL_Z__POS (0) +#define BMI160_USER_FOC_ACCEL_Z__LEN (2) +#define BMI160_USER_FOC_ACCEL_Z__MSK (0x03) +#define BMI160_USER_FOC_ACCEL_Z__REG (BMI160_USER_FOC_CONFIG_ADDR) + +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 2...3 */ +#define BMI160_USER_FOC_ACCEL_Y__POS (2) +#define BMI160_USER_FOC_ACCEL_Y__LEN (2) +#define BMI160_USER_FOC_ACCEL_Y__MSK (0x0C) +#define BMI160_USER_FOC_ACCEL_Y__REG (BMI160_USER_FOC_CONFIG_ADDR) + +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 4...5 */ +#define BMI160_USER_FOC_ACCEL_X__POS (4) +#define BMI160_USER_FOC_ACCEL_X__LEN (2) +#define BMI160_USER_FOC_ACCEL_X__MSK (0x30) +#define BMI160_USER_FOC_ACCEL_X__REG (BMI160_USER_FOC_CONFIG_ADDR) +/**************************************************************/ +/**\name FOC GYRO LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Foc_Conf Description - Reg Addr --> (0x69), Bit --> 6 */ +#define BMI160_USER_FOC_GYRO_ENABLE__POS (6) +#define BMI160_USER_FOC_GYRO_ENABLE__LEN (1) +#define BMI160_USER_FOC_GYRO_ENABLE__MSK (0x40) +#define BMI160_USER_FOC_GYRO_ENABLE__REG \ +(BMI160_USER_FOC_CONFIG_ADDR) +/**************************************************************/ +/**\name NVM PROGRAM LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* CONF Description - Reg Addr --> (0x6A), Bit --> 1 */ +#define BMI160_USER_CONFIG_NVM_PROG_ENABLE__POS (1) +#define BMI160_USER_CONFIG_NVM_PROG_ENABLE__LEN (1) +#define BMI160_USER_CONFIG_NVM_PROG_ENABLE__MSK (0x02) +#define BMI160_USER_CONFIG_NVM_PROG_ENABLE__REG \ +(BMI160_USER_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x6B), Bit --> 0 */ + +#define BMI160_USER_IF_CONFIG_SPI3__POS (0) +#define BMI160_USER_IF_CONFIG_SPI3__LEN (1) +#define BMI160_USER_IF_CONFIG_SPI3__MSK (0x01) +#define BMI160_USER_IF_CONFIG_SPI3__REG \ +(BMI160_USER_IF_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x6B), Bit --> 5..4 */ +#define BMI160_USER_IF_CONFIG_IF_MODE__POS (4) +#define BMI160_USER_IF_CONFIG_IF_MODE__LEN (2) +#define BMI160_USER_IF_CONFIG_IF_MODE__MSK (0x30) +#define BMI160_USER_IF_CONFIG_IF_MODE__REG \ +(BMI160_USER_IF_CONFIG_ADDR) +/**************************************************************/ +/**\name GYRO SLEEP CONFIGURATION LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 0...2 */ +#define BMI160_USER_GYRO_SLEEP_TRIGGER__POS (0) +#define BMI160_USER_GYRO_SLEEP_TRIGGER__LEN (3) +#define BMI160_USER_GYRO_SLEEP_TRIGGER__MSK (0x07) +#define BMI160_USER_GYRO_SLEEP_TRIGGER__REG (BMI160_USER_PMU_TRIGGER_ADDR) + +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 3...4 */ +#define BMI160_USER_GYRO_WAKEUP_TRIGGER__POS (3) +#define BMI160_USER_GYRO_WAKEUP_TRIGGER__LEN (2) +#define BMI160_USER_GYRO_WAKEUP_TRIGGER__MSK (0x18) +#define BMI160_USER_GYRO_WAKEUP_TRIGGER__REG (BMI160_USER_PMU_TRIGGER_ADDR) + +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 5 */ +#define BMI160_USER_GYRO_SLEEP_STATE__POS (5) +#define BMI160_USER_GYRO_SLEEP_STATE__LEN (1) +#define BMI160_USER_GYRO_SLEEP_STATE__MSK (0x20) +#define BMI160_USER_GYRO_SLEEP_STATE__REG (BMI160_USER_PMU_TRIGGER_ADDR) + +/* Pmu_Trigger Description - Reg Addr --> 0x6c, Bit --> 6 */ +#define BMI160_USER_GYRO_WAKEUP_INTR__POS (6) +#define BMI160_USER_GYRO_WAKEUP_INTR__LEN (1) +#define BMI160_USER_GYRO_WAKEUP_INTR__MSK (0x40) +#define BMI160_USER_GYRO_WAKEUP_INTR__REG (BMI160_USER_PMU_TRIGGER_ADDR) +/**************************************************************/ +/**\name ACCEL SELF TEST LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 0...1 */ +#define BMI160_USER_ACCEL_SELFTEST_AXIS__POS (0) +#define BMI160_USER_ACCEL_SELFTEST_AXIS__LEN (2) +#define BMI160_USER_ACCEL_SELFTEST_AXIS__MSK (0x03) +#define BMI160_USER_ACCEL_SELFTEST_AXIS__REG (BMI160_USER_SELF_TEST_ADDR) + +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 2 */ +#define BMI160_USER_ACCEL_SELFTEST_SIGN__POS (2) +#define BMI160_USER_ACCEL_SELFTEST_SIGN__LEN (1) +#define BMI160_USER_ACCEL_SELFTEST_SIGN__MSK (0x04) +#define BMI160_USER_ACCEL_SELFTEST_SIGN__REG (BMI160_USER_SELF_TEST_ADDR) + +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 3 */ +#define BMI160_USER_SELFTEST_AMP__POS (3) +#define BMI160_USER_SELFTEST_AMP__LEN (1) +#define BMI160_USER_SELFTEST_AMP__MSK (0x08) +#define BMI160_USER_SELFTEST_AMP__REG (BMI160_USER_SELF_TEST_ADDR) +/**************************************************************/ +/**\name GYRO SELF TEST LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Self_Test Description - Reg Addr --> 0x6d, Bit --> 4 */ +#define BMI160_USER_GYRO_SELFTEST_START__POS (4) +#define BMI160_USER_GYRO_SELFTEST_START__LEN (1) +#define BMI160_USER_GYRO_SELFTEST_START__MSK (0x10) +#define BMI160_USER_GYRO_SELFTEST_START__REG \ +(BMI160_USER_SELF_TEST_ADDR) +/**************************************************************/ +/**\name NV_CONFIG LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* NV_CONF Description - Reg Addr --> (0x70), Bit --> 0 */ +#define BMI160_USER_NV_CONFIG_SPI_ENABLE__POS (0) +#define BMI160_USER_NV_CONFIG_SPI_ENABLE__LEN (1) +#define BMI160_USER_NV_CONFIG_SPI_ENABLE__MSK (0x01) +#define BMI160_USER_NV_CONFIG_SPI_ENABLE__REG (BMI160_USER_NV_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x70), Bit --> 1 */ +#define BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__POS (1) +#define BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__LEN (1) +#define BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__MSK (0x02) +#define BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG \ +(BMI160_USER_NV_CONFIG_ADDR) + +/*IF_CONF Description - Reg Addr --> (0x70), Bit --> 2 */ +#define BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__POS (2) +#define BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__LEN (1) +#define BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__MSK (0x04) +#define BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG \ +(BMI160_USER_NV_CONFIG_ADDR) + +/* NV_CONF Description - Reg Addr --> (0x70), Bit --> 3 */ +#define BMI160_USER_NV_CONFIG_SPARE0__POS (3) +#define BMI160_USER_NV_CONFIG_SPARE0__LEN (1) +#define BMI160_USER_NV_CONFIG_SPARE0__MSK (0x08) +#define BMI160_USER_NV_CONFIG_SPARE0__REG (BMI160_USER_NV_CONFIG_ADDR) + +/* NV_CONF Description - Reg Addr --> (0x70), Bit --> 4...7 */ +#define BMI160_USER_NV_CONFIG_NVM_COUNTER__POS (4) +#define BMI160_USER_NV_CONFIG_NVM_COUNTER__LEN (4) +#define BMI160_USER_NV_CONFIG_NVM_COUNTER__MSK (0xF0) +#define BMI160_USER_NV_CONFIG_NVM_COUNTER__REG (BMI160_USER_NV_CONFIG_ADDR) +/**************************************************************/ +/**\name ACCEL MANUAL OFFSET LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_0 Description - Reg Addr --> (0x71), Bit --> 0...7 */ +#define BMI160_USER_OFFSET_0_ACCEL_OFF_X__POS (0) +#define BMI160_USER_OFFSET_0_ACCEL_OFF_X__LEN (8) +#define BMI160_USER_OFFSET_0_ACCEL_OFF_X__MSK (0xFF) +#define BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG (BMI160_USER_OFFSET_0_ADDR) + +/* Offset_1 Description - Reg Addr --> 0x72, Bit --> 0...7 */ +#define BMI160_USER_OFFSET_1_ACCEL_OFF_Y__POS (0) +#define BMI160_USER_OFFSET_1_ACCEL_OFF_Y__LEN (8) +#define BMI160_USER_OFFSET_1_ACCEL_OFF_Y__MSK (0xFF) +#define BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG (BMI160_USER_OFFSET_1_ADDR) + +/* Offset_2 Description - Reg Addr --> 0x73, Bit --> 0...7 */ +#define BMI160_USER_OFFSET_2_ACCEL_OFF_Z__POS (0) +#define BMI160_USER_OFFSET_2_ACCEL_OFF_Z__LEN (8) +#define BMI160_USER_OFFSET_2_ACCEL_OFF_Z__MSK (0xFF) +#define BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG (BMI160_USER_OFFSET_2_ADDR) +/**************************************************************/ +/**\name GYRO MANUAL OFFSET LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_3 Description - Reg Addr --> 0x74, Bit --> 0...7 */ +#define BMI160_USER_OFFSET_3_GYRO_OFF_X__POS (0) +#define BMI160_USER_OFFSET_3_GYRO_OFF_X__LEN (8) +#define BMI160_USER_OFFSET_3_GYRO_OFF_X__MSK (0xFF) +#define BMI160_USER_OFFSET_3_GYRO_OFF_X__REG (BMI160_USER_OFFSET_3_ADDR) + +/* Offset_4 Description - Reg Addr --> 0x75, Bit --> 0...7 */ +#define BMI160_USER_OFFSET_4_GYRO_OFF_Y__POS (0) +#define BMI160_USER_OFFSET_4_GYRO_OFF_Y__LEN (8) +#define BMI160_USER_OFFSET_4_GYRO_OFF_Y__MSK (0xFF) +#define BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG (BMI160_USER_OFFSET_4_ADDR) + +/* Offset_5 Description - Reg Addr --> 0x76, Bit --> 0...7 */ +#define BMI160_USER_OFFSET_5_GYRO_OFF_Z__POS (0) +#define BMI160_USER_OFFSET_5_GYRO_OFF_Z__LEN (8) +#define BMI160_USER_OFFSET_5_GYRO_OFF_Z__MSK (0xFF) +#define BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG (BMI160_USER_OFFSET_5_ADDR) + + +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 0..1 */ +#define BMI160_USER_OFFSET_6_GYRO_OFF_X__POS (0) +#define BMI160_USER_OFFSET_6_GYRO_OFF_X__LEN (2) +#define BMI160_USER_OFFSET_6_GYRO_OFF_X__MSK (0x03) +#define BMI160_USER_OFFSET_6_GYRO_OFF_X__REG (BMI160_USER_OFFSET_6_ADDR) + +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 2...3 */ +#define BMI160_USER_OFFSET_6_GYRO_OFF_Y__POS (2) +#define BMI160_USER_OFFSET_6_GYRO_OFF_Y__LEN (2) +#define BMI160_USER_OFFSET_6_GYRO_OFF_Y__MSK (0x0C) +#define BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG (BMI160_USER_OFFSET_6_ADDR) + +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 4...5 */ +#define BMI160_USER_OFFSET_6_GYRO_OFF_Z__POS (4) +#define BMI160_USER_OFFSET_6_GYRO_OFF_Z__LEN (2) +#define BMI160_USER_OFFSET_6_GYRO_OFF_Z__MSK (0x30) +#define BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG (BMI160_USER_OFFSET_6_ADDR) +/**************************************************************/ +/**\name ACCEL OFFSET ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 6 */ +#define BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__POS (6) +#define BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__LEN (1) +#define BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__MSK (0x40) +#define BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG \ +(BMI160_USER_OFFSET_6_ADDR) +/**************************************************************/ +/**\name GYRO OFFSET ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Offset_6 Description - Reg Addr --> 0x77, Bit --> 7 */ +#define BMI160_USER_OFFSET_6_GYRO_OFF_EN__POS (7) +#define BMI160_USER_OFFSET_6_GYRO_OFF_EN__LEN (1) +#define BMI160_USER_OFFSET_6_GYRO_OFF_EN__MSK (0x80) +#define BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG (BMI160_USER_OFFSET_6_ADDR) +/**************************************************************/ +/**\name STEP COUNTER LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* STEP_CNT_0 Description - Reg Addr --> 0x78, Bit --> 0 to 7 */ +#define BMI160_USER_STEP_COUNT_LSB__POS (0) +#define BMI160_USER_STEP_COUNT_LSB__LEN (7) +#define BMI160_USER_STEP_COUNT_LSB__MSK (0xFF) +#define BMI160_USER_STEP_COUNT_LSB__REG (BMI160_USER_STEP_COUNT_0_ADDR) + +/* STEP_CNT_1 Description - Reg Addr --> 0x79, Bit --> 0 to 7 */ +#define BMI160_USER_STEP_COUNT_MSB__POS (0) +#define BMI160_USER_STEP_COUNT_MSB__LEN (7) +#define BMI160_USER_STEP_COUNT_MSB__MSK (0xFF) +#define BMI160_USER_STEP_COUNT_MSB__REG (BMI160_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 BMI160_USER_STEP_CONFIG_ZERO__POS (0) +#define BMI160_USER_STEP_CONFIG_ZERO__LEN (7) +#define BMI160_USER_STEP_CONFIG_ZERO__MSK (0xFF) +#define BMI160_USER_STEP_CONFIG_ZERO__REG \ +(BMI160_USER_STEP_CONFIG_0_ADDR) + + +/* STEP_CONFIG_1 Description - Reg Addr --> 0x7B, Bit --> 0 to 2 and +4 to 7 */ +#define BMI160_USER_STEP_CONFIG_ONE_CNF1__POS (0) +#define BMI160_USER_STEP_CONFIG_ONE_CNF1__LEN (3) +#define BMI160_USER_STEP_CONFIG_ONE_CNF1__MSK (0x07) +#define BMI160_USER_STEP_CONFIG_ONE_CNF1__REG \ +(BMI160_USER_STEP_CONFIG_1_ADDR) + +#define BMI160_USER_STEP_CONFIG_ONE_CNF2__POS (4) +#define BMI160_USER_STEP_CONFIG_ONE_CNF2__LEN (4) +#define BMI160_USER_STEP_CONFIG_ONE_CNF2__MSK (0xF0) +#define BMI160_USER_STEP_CONFIG_ONE_CNF2__REG \ +(BMI160_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 BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__POS (3) +#define BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__LEN (1) +#define BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__MSK (0x08) +#define BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG \ +(BMI160_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 BMI160_CMD_COMMANDS__POS (0) +#define BMI160_CMD_COMMANDS__LEN (8) +#define BMI160_CMD_COMMANDS__MSK (0xFF) +#define BMI160_CMD_COMMANDS__REG (BMI160_CMD_COMMANDS_ADDR) +/**************************************************************/ +/**\name PAGE ENABLE LENGTH, POSITION AND MASK*/ +/**************************************************************/ +/* Target page address - Reg Addr --> 0x7F, Bit --> 4....5 */ +#define BMI160_CMD_TARGET_PAGE__POS (4) +#define BMI160_CMD_TARGET_PAGE__LEN (2) +#define BMI160_CMD_TARGET_PAGE__MSK (0x30) +#define BMI160_CMD_TARGET_PAGE__REG (BMI160_CMD_EXT_MODE_ADDR) + +/* Target page address - Reg Addr --> 0x7F, Bit --> 4....5 */ +#define BMI160_CMD_PAGING_EN__POS (7) +#define BMI160_CMD_PAGING_EN__LEN (1) +#define BMI160_CMD_PAGING_EN__MSK (0x80) +#define BMI160_CMD_PAGING_EN__REG (BMI160_CMD_EXT_MODE_ADDR) + +/* Target page address - Reg Addr --> 0x7F, Bit --> 4....5 */ +#define BMI160_COM_C_TRIM_FIVE__POS (0) +#define BMI160_COM_C_TRIM_FIVE__LEN (8) +#define BMI160_COM_C_TRIM_FIVE__MSK (0xFF) +#define BMI160_COM_C_TRIM_FIVE__REG (BMI160_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 BMI160_YAS537_I2C_ADDRESS (0x2E) +/**************************************************/ +/**\name ACCEL RANGE */ +/*************************************************/ +#define BMI160_ACCEL_RANGE_2G (0X03) +#define BMI160_ACCEL_RANGE_4G (0X05) +#define BMI160_ACCEL_RANGE_8G (0X08) +#define BMI160_ACCEL_RANGE_16G (0X0C) +/**************************************************/ +/**\name ACCEL ODR */ +/*************************************************/ +#define BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED (0x00) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ (0x01) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ (0x02) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ (0x03) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ (0x04) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ (0x05) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ (0x06) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ (0x07) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ (0x08) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ (0x09) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ (0x0A) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ (0x0B) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ (0x0C) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED0 (0x0D) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED1 (0x0E) +#define BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED2 (0x0F) +/**************************************************/ +/**\name ACCEL BANDWIDTH PARAMETER */ +/*************************************************/ +#define BMI160_ACCEL_OSR4_AVG1 (0x00) +#define BMI160_ACCEL_OSR2_AVG2 (0x01) +#define BMI160_ACCEL_NORMAL_AVG4 (0x02) +#define BMI160_ACCEL_CIC_AVG8 (0x03) +#define BMI160_ACCEL_RES_AVG16 (0x04) +#define BMI160_ACCEL_RES_AVG32 (0x05) +#define BMI160_ACCEL_RES_AVG64 (0x06) +#define BMI160_ACCEL_RES_AVG128 (0x07) +/**************************************************/ +/**\name GYRO ODR */ +/*************************************************/ +#define BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED (0x00) +#define BMI160_GYRO_OUTPUT_DATA_RATE_25HZ (0x06) +#define BMI160_GYRO_OUTPUT_DATA_RATE_50HZ (0x07) +#define BMI160_GYRO_OUTPUT_DATA_RATE_100HZ (0x08) +#define BMI160_GYRO_OUTPUT_DATA_RATE_200HZ (0x09) +#define BMI160_GYRO_OUTPUT_DATA_RATE_400HZ (0x0A) +#define BMI160_GYRO_OUTPUT_DATA_RATE_800HZ (0x0B) +#define BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ (0x0C) +#define BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ (0x0D) +/**************************************************/ +/**\name GYRO BANDWIDTH PARAMETER */ +/*************************************************/ +#define BMI160_GYRO_OSR4_MODE (0x00) +#define BMI160_GYRO_OSR2_MODE (0x01) +#define BMI160_GYRO_NORMAL_MODE (0x02) +#define BMI160_GYRO_CIC_MODE (0x03) +/**************************************************/ +/**\name GYROSCOPE RANGE PARAMETER */ +/*************************************************/ +#define BMI160_GYRO_RANGE_2000_DEG_SEC (0x00) +#define BMI160_GYRO_RANGE_1000_DEG_SEC (0x01) +#define BMI160_GYRO_RANGE_500_DEG_SEC (0x02) +#define BMI160_GYRO_RANGE_250_DEG_SEC (0x03) +#define BMI160_GYRO_RANGE_125_DEG_SEC (0x04) +/**************************************************/ +/**\name MAG ODR */ +/*************************************************/ +#define BMI160_MAG_OUTPUT_DATA_RATE_RESERVED (0x00) +#define BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ (0x01) +#define BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ (0x02) +#define BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ (0x03) +#define BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ (0x04) +#define BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ (0x05) +#define BMI160_MAG_OUTPUT_DATA_RATE_25HZ (0x06) +#define BMI160_MAG_OUTPUT_DATA_RATE_50HZ (0x07) +#define BMI160_MAG_OUTPUT_DATA_RATE_100HZ (0x08) +#define BMI160_MAG_OUTPUT_DATA_RATE_200HZ (0x09) +#define BMI160_MAG_OUTPUT_DATA_RATE_400HZ (0x0A) +#define BMI160_MAG_OUTPUT_DATA_RATE_800HZ (0x0B) +#define BMI160_MAG_OUTPUT_DATA_RATE_1600HZ (0x0C) +#define BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0 (0x0D) +#define BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1 (0x0E) +#define BMI160_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 BMI160_ANY_MOTION_X_ENABLE (0) +#define BMI160_ANY_MOTION_Y_ENABLE (1) +#define BMI160_ANY_MOTION_Z_ENABLE (2) +#define BMI160_DOUBLE_TAP_ENABLE (4) +#define BMI160_SINGLE_TAP_ENABLE (5) +#define BMI160_ORIENT_ENABLE (6) +#define BMI160_FLAT_ENABLE (7) + +/* INT ENABLE 1 */ +#define BMI160_HIGH_G_X_ENABLE (0) +#define BMI160_HIGH_G_Y_ENABLE (1) +#define BMI160_HIGH_G_Z_ENABLE (2) +#define BMI160_LOW_G_ENABLE (3) +#define BMI160_DATA_RDY_ENABLE (4) +#define BMI160_FIFO_FULL_ENABLE (5) +#define BMI160_FIFO_WM_ENABLE (6) + +/* INT ENABLE 2 */ +#define BMI160_NOMOTION_X_ENABLE (0) +#define BMI160_NOMOTION_Y_ENABLE (1) +#define BMI160_NOMOTION_Z_ENABLE (2) +#define BMI160_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 BMI160_INTR1_EDGE_CTRL (0) +#define BMI160_INTR2_EDGE_CTRL (1) +#define BMI160_INTR1_LEVEL (0) +#define BMI160_INTR2_LEVEL (1) +#define BMI160_INTR1_OUTPUT_TYPE (0) +#define BMI160_INTR2_OUTPUT_TYPE (1) +#define BMI160_INTR1_OUTPUT_ENABLE (0) +#define BMI160_INTR2_OUTPUT_ENABLE (1) + +#define BMI160_INTR1_INPUT_ENABLE (0) +#define BMI160_INTR2_INPUT_ENABLE (1) + +/* INTERRUPT MAPS */ +#define BMI160_INTR1_MAP_LOW_G (0) +#define BMI160_INTR2_MAP_LOW_G (1) +#define BMI160_INTR1_MAP_HIGH_G (0) +#define BMI160_INTR2_MAP_HIGH_G (1) +#define BMI160_INTR1_MAP_ANY_MOTION (0) +#define BMI160_INTR2_MAP_ANY_MOTION (1) +#define BMI160_INTR1_MAP_NOMO (0) +#define BMI160_INTR2_MAP_NOMO (1) +#define BMI160_INTR1_MAP_DOUBLE_TAP (0) +#define BMI160_INTR2_MAP_DOUBLE_TAP (1) +#define BMI160_INTR1_MAP_SINGLE_TAP (0) +#define BMI160_INTR2_MAP_SINGLE_TAP (1) +#define BMI160_INTR1_MAP_ORIENT (0) +#define BMI160_INTR2_MAP_ORIENT (1) +#define BMI160_INTR1_MAP_FLAT (0) +#define BMI160_INTR2_MAP_FLAT (1) +#define BMI160_INTR1_MAP_DATA_RDY (0) +#define BMI160_INTR2_MAP_DATA_RDY (1) +#define BMI160_INTR1_MAP_FIFO_WM (0) +#define BMI160_INTR2_MAP_FIFO_WM (1) +#define BMI160_INTR1_MAP_FIFO_FULL (0) +#define BMI160_INTR2_MAP_FIFO_FULL (1) +#define BMI160_INTR1_MAP_PMUTRIG (0) +#define BMI160_INTR2_MAP_PMUTRIG (1) + +/* Interrupt mapping*/ +#define BMI160_MAP_INTR1 (0) +#define BMI160_MAP_INTR2 (1) +/**************************************************/ +/**\name TAP DURATION */ +/*************************************************/ +#define BMI160_TAP_DURN_50MS (0x00) +#define BMI160_TAP_DURN_100MS (0x01) +#define BMI160_TAP_DURN_150MS (0x02) +#define BMI160_TAP_DURN_200MS (0x03) +#define BMI160_TAP_DURN_250MS (0x04) +#define BMI160_TAP_DURN_375MS (0x05) +#define BMI160_TAP_DURN_500MS (0x06) +#define BMI160_TAP_DURN_700MS (0x07) +/**************************************************/ +/**\name TAP SHOCK */ +/*************************************************/ +#define BMI160_TAP_SHOCK_50MS (0x00) +#define BMI160_TAP_SHOCK_75MS (0x01) +/**************************************************/ +/**\name TAP QUIET */ +/*************************************************/ +#define BMI160_TAP_QUIET_30MS (0x00) +#define BMI160_TAP_QUIET_20MS (0x01) +/**************************************************/ +/**\name STEP DETECTION SELECTION MODES */ +/*************************************************/ +#define BMI160_STEP_NORMAL_MODE (0) +#define BMI160_STEP_SENSITIVE_MODE (1) +#define BMI160_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 BMI160_MAG_DIG_X1 (0x5D) +#define BMI160_MAG_DIG_Y1 (0x5E) +#define BMI160_MAG_DIG_Z4_LSB (0x62) +#define BMI160_MAG_DIG_Z4_MSB (0x63) +#define BMI160_MAG_DIG_X2 (0x64) +#define BMI160_MAG_DIG_Y2 (0x65) +#define BMI160_MAG_DIG_Z2_LSB (0x68) +#define BMI160_MAG_DIG_Z2_MSB (0x69) +#define BMI160_MAG_DIG_Z1_LSB (0x6A) +#define BMI160_MAG_DIG_Z1_MSB (0x6B) +#define BMI160_MAG_DIG_XYZ1_LSB (0x6C) +#define BMI160_MAG_DIG_XYZ1_MSB (0x6D) +#define BMI160_MAG_DIG_Z3_LSB (0x6E) +#define BMI160_MAG_DIG_Z3_MSB (0x6F) +#define BMI160_MAG_DIG_XY2 (0x70) +#define BMI160_MAG_DIG_XY1 (0x71) +/**************************************************/ +/**\name BMM150 PRE-SET MODE DEFINITIONS */ +/*************************************************/ +#define BMI160_MAG_PRESETMODE_LOWPOWER (1) +#define BMI160_MAG_PRESETMODE_REGULAR (2) +#define BMI160_MAG_PRESETMODE_HIGHACCURACY (3) +#define BMI160_MAG_PRESETMODE_ENHANCED (4) +/**************************************************/ +/**\name BMM150 PRESET MODES - DATA RATES */ +/*************************************************/ +#define BMI160_MAG_LOWPOWER_DR (0x02) +#define BMI160_MAG_REGULAR_DR (0x02) +#define BMI160_MAG_HIGHACCURACY_DR (0x2A) +#define BMI160_MAG_ENHANCED_DR (0x02) +/**************************************************/ +/**\name BMM150 PRESET MODES - REPETITIONS-XY RATES */ +/*************************************************/ +#define BMI160_MAG_LOWPOWER_REPXY (1) +#define BMI160_MAG_REGULAR_REPXY (4) +#define BMI160_MAG_HIGHACCURACY_REPXY (23) +#define BMI160_MAG_ENHANCED_REPXY (7) +/**************************************************/ +/**\name BMM150 PRESET MODES - REPETITIONS-Z RATES */ +/*************************************************/ +#define BMI160_MAG_LOWPOWER_REPZ (2) +#define BMI160_MAG_REGULAR_REPZ (14) +#define BMI160_MAG_HIGHACCURACY_REPZ (82) +#define BMI160_MAG_ENHANCED_REPZ (26) +#define BMI160_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 BMI160_MAG_OVERFLOW_OUTPUT ((s16)-32768) +#define BMI160_MAG_OVERFLOW_OUTPUT_S32 ((s32)(-2147483647-1)) +#define BMI160_MAG_NEGATIVE_SATURATION_Z ((s16)-32767) +#define BMI160_MAG_POSITIVE_SATURATION_Z ((u16)32767) +#define BMI160_MAG_FLIP_OVERFLOW_ADCVAL ((s16)-4096) +#define BMI160_MAG_HALL_OVERFLOW_ADCVAL ((s16)-16384) +/**************************************************/ +/**\name BMM150 REGISTER DEFINITION */ +/*************************************************/ +#define BMI160_BMM150_CHIP_ID (0x40) +#define BMI160_BMM150_POWE_CONTROL_REG (0x4B) +#define BMI160_BMM150_POWE_MODE_REG (0x4C) +#define BMI160_BMM150_DATA_REG (0x42) +#define BMI160_BMM150_XY_REP (0x51) +#define BMI160_BMM150_Z_REP (0x52) +/**************************************************/ +/**\name AKM COMPENSATING DATA REGISTERS */ +/*************************************************/ +#define BMI160_BST_AKM_ASAX (0x60) +#define BMI160_BST_AKM_ASAY (0x61) +#define BMI160_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 BMI160_MAG_FORCE_MODE (0) +#define BMI160_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 BMI160_FIFO_INDEX_LENGTH (1) +#define BMI160_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 BMI160_ENABLE (0x01) +#define BMI160_DISABLE (0x00) +/**************************************************/ +/**\name INTERRUPT EDGE TRIGGER ENABLE */ +/*************************************************/ +#define BMI160_EDGE (0x01) +#define BMI160_LEVEL (0x00) +/**************************************************/ +/**\name INTERRUPT LEVEL ENABLE */ +/*************************************************/ +#define BMI160_LEVEL_LOW (0x00) +#define BMI160_LEVEL_HIGH (0x01) +/**************************************************/ +/**\name INTERRUPT OUTPUT ENABLE */ +/*************************************************/ +#define BMI160_OPEN_DRAIN (0x01) +#define BMI160_PUSH_PULL (0x00) + +/* interrupt output enable*/ +#define BMI160_INPUT (0x01) +#define BMI160_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 BMI160_LATCH_DUR_NONE (0x00) +#define BMI160_LATCH_DUR_312_5_MICRO_SEC (0x01) +#define BMI160_LATCH_DUR_625_MICRO_SEC (0x02) +#define BMI160_LATCH_DUR_1_25_MILLI_SEC (0x03) +#define BMI160_LATCH_DUR_2_5_MILLI_SEC (0x04) +#define BMI160_LATCH_DUR_5_MILLI_SEC (0x05) +#define BMI160_LATCH_DUR_10_MILLI_SEC (0x06) +#define BMI160_LATCH_DUR_20_MILLI_SEC (0x07) +#define BMI160_LATCH_DUR_40_MILLI_SEC (0x08) +#define BMI160_LATCH_DUR_80_MILLI_SEC (0x09) +#define BMI160_LATCH_DUR_160_MILLI_SEC (0x0A) +#define BMI160_LATCH_DUR_320_MILLI_SEC (0x0B) +#define BMI160_LATCH_DUR_640_MILLI_SEC (0x0C) +#define BMI160_LATCH_DUR_1_28_SEC (0x0D) +#define BMI160_LATCH_DUR_2_56_SEC (0x0E) +#define BMI160_LATCHED (0x0F) +/**************************************************/ +/**\name GYRO OFFSET MASK DEFINITION */ +/*************************************************/ +#define BMI160_GYRO_MANUAL_OFFSET_0_7 (0x00FF) +#define BMI160_GYRO_MANUAL_OFFSET_8_9 (0x0300) +/**************************************************/ +/**\name STEP CONFIGURATION MASK DEFINITION */ +/*************************************************/ +#define BMI160_STEP_CONFIG_0_7 (0x00FF) +#define BMI160_STEP_CONFIG_8_10 (0x0700) +#define BMI160_STEP_CONFIG_11_14 (0xF000) +/**************************************************/ +/**\name DEFINITION USED FOR DIFFERENT WRITE */ +/*************************************************/ +#define BMI160_WRITE_TARGET_PAGE0 (0x00) +#define BMI160_WRITE_TARGET_PAGE1 (0x01) +#define BMI160_WRITE_ENABLE_PAGE1 (0x01) +#define BMI160_MANUAL_DISABLE (0x00) +#define BMI160_MANUAL_ENABLE (0x01) +#define BMI160_YAS_DISABLE_RCOIL (0x00) +#define BMI160_ENABLE_MAG_IF_MODE (0x02) +#define BMI160_ENABLE_ANY_MOTION_INTR1 (0x04) +#define BMI160_ENABLE_ANY_MOTION_INTR2 (0x04) +#define BMI160_MAG_DATA_READ_REG (0x04) +#define BMI160_BMM_POWER_MODE_REG (0x06) +#define BMI160_ENABLE_ANY_MOTION_AXIS (0x07) +#define BMI160_ENABLE_LOW_G (0x08) +#define BMI160_YAS532_ACQ_START (0x11) +#define BMI160_YAS_DEVICE_ID_REG (0x80) +#define BMI160_FIFO_GYRO_ENABLE (0x80) +#define BMI160_SIG_MOTION_INTR_ENABLE (0x01) +#define BMI160_STEP_DETECT_INTR_ENABLE (0x01) +#define BMI160_LOW_G_INTR_STAT (0x01) +#define BMI160_PULL_UP_DATA (0x30) +#define BMI160_FIFO_M_G_A_ENABLE (0xE0) +#define BMI160_FIFO_M_G_ENABLE (0xA0) +#define BMI160_FIFO_M_A_ENABLE (0x60) +#define BMI160_FIFO_G_A_ENABLE (0xC0) +#define BMI160_FIFO_A_ENABLE (0x40) +#define BMI160_FIFO_M_ENABLE (0x20) +/**************************************************/ +/**\name MAG INIT DEFINITION */ +/*************************************************/ +#define BMI160_COMMAND_REG_ONE (0x37) +#define BMI160_COMMAND_REG_TWO (0x9A) +#define BMI160_COMMAND_REG_THREE (0xC0) +#define RESET_STEP_COUNTER (0xB2) +/**************************************************/ +/**\name BIT SLICE GET AND SET FUNCTIONS */ +/*************************************************/ +#define BMI160_GET_BITSLICE(regvar, bitname)\ + ((regvar & bitname##__MSK) >> bitname##__POS) + + +#define BMI160_SET_BITSLICE(regvar, bitname, val)\ + ((regvar & ~bitname##__MSK) | \ + ((val< Success + * @retval -1 -> Error + * + * @note + * While changing the parameter of the bmi160_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) + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_init(struct bmi160_t *bmi160); +/**************************************************/ +/**\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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 "bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 "bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 "bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_mag_output_data_rate() + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyz( +struct bmi160_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 bmi160_set_mag_output_data_rate() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyzr( +struct bmi160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error result of communication routines + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_gyro_output_data_rate() + * @note bmi160_set_gyro_bw() + * @note bmi160_set_gyro_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_xyz( +struct bmi160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_accel_output_data_rate() + * @note bmi160_set_accel_bw() + * @note bmi160_set_accel_under_sampling_parameter() + * @note bmi160_set_accel_range() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_xyz( +struct bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_intr_double_tap() + * @note AXIS MAPPING + * @note bmi160_get_stat2_tap_first_x() + * @note bmi160_get_stat2_tap_first_y() + * @note bmi160_get_stat2_tap_first_z() + * @note DURATION + * @note bmi160_set_intr_tap_durn() + * @note THRESHOLD + * @note bmi160_set_intr_tap_thres() + * @note TAP QUIET + * @note bmi160_set_intr_tap_quiet() + * @note TAP SHOCK + * @note bmi160_set_intr_tap_shock() + * @note TAP SOURCE + * @note bmi160_set_intr_tap_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_intr_single_tap() + * @note AXIS MAPPING + * @note bmi160_get_stat2_tap_first_x() + * @note bmi160_get_stat2_tap_first_y() + * @note bmi160_get_stat2_tap_first_z() + * @note DURATION + * @note bmi160_set_intr_tap_durn() + * @note THRESHOLD + * @note bmi160_set_intr_tap_thres() + * @note TAP QUIET + * @note bmi160_set_intr_tap_quiet() + * @note TAP SHOCK + * @note bmi160_set_intr_tap_shock() + * @note TAP SOURCE + * @note bmi160_set_intr_tap_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_get_stat0_orient_intr() + * @note AXIS MAPPING + * @note bmi160_get_stat3_orient_xy() + * @note bmi160_get_stat3_orient_z() + * @note bmi160_set_intr_orient_axes_enable() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_orient() + * @note INTERRUPT OUTPUT + * @note bmi160_set_intr_orient_ud_enable() + * @note THETA + * @note bmi160_set_intr_orient_theta() + * @note HYSTERESIS + * @note bmi160_set_intr_orient_hyst() + * @note BLOCKING + * @note bmi160_set_intr_orient_blocking() + * @note MODE + * @note bmi160_set_intr_orient_mode() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_get_stat0_flat_intr() + * @note bmi160_get_stat3_flat() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_flat() + * @note THETA + * @note bmi160_set_intr_flat_theta() + * @note HOLD TIME + * @note bmi160_set_intr_flat_hold() + * @note HYSTERESIS + * @note bmi160_set_intr_flat_hyst() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_get_stat1_high_g_intr() + * @note AXIS MAPPING + * @note bmi160_get_stat3_high_g_first_x() + * @note bmi160_get_stat3_high_g_first_y() + * @note bmi160_get_stat3_high_g_first_z() + * @note SIGN MAPPING + * @note bmi160_get_stat3_high_g_first_sign() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_high_g() + * @note HYSTERESIS + * @note bmi160_set_intr_high_g_hyst() + * @note DURATION + * @note bmi160_set_intr_high_g_durn() + * @note THRESHOLD + * @note bmi160_set_intr_high_g_thres() + * @note SOURCE + * @note bmi160_set_intr_low_high_source() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_get_stat1_low_g_intr() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_low_g() + * @note SOURCE + * @note bmi160_set_intr_low_high_source() + * @note DURATION + * @note bmi160_set_intr_low_g_durn() + * @note THRESHOLD + * @note bmi160_set_intr_low_g_thres() + * @note HYSTERESIS + * @note bmi160_set_intr_low_g_hyst() + * @note MODE + * @note bmi160_set_intr_low_g_mode() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_get_stat1_data_rdy_intr() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_data_rdy() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_intr_fifo_full() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_set_intr_fifo_wm() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 bmi160_get_stat1_nomotion_intr() + * @note INTERRUPT MAPPING + * @note bmi160_set_intr_nomotion() + * @note DURATION + * @note bmi160_set_intr_slow_no_motion_durn() + * @note THRESHOLD + * @note bmi160_set_intr_slow_no_motion_thres() + * @note SLOW/NO MOTION SELECT + * @note bmi160_set_intr_slow_no_motion_select() + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED + * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ + * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ + * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ + * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ + * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ + * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ + * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ + * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ + * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ + * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ + * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ + * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED + * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ + * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ + * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ + * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ + * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ + * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ + * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ + * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ + * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ + * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ + * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ + * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * "BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * "BMI160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ACCEL_RANGE_2G + * 0x05 | BMI160_ACCEL_RANGE_4G + * 0x08 | BMI160_ACCEL_RANGE_8G + * 0x0C | BMI160_ACCEL_RANGE_16G + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ACCEL_RANGE_2G + * 0x05 | BMI160_ACCEL_RANGE_4G + * 0x08 | BMI160_ACCEL_RANGE_8G + * 0x0C | BMI160_ACCEL_RANGE_16G + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ + * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ + * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ + * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ + * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ + * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ + * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ + * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ + * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ + * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ + * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ + * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ + * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ + * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ + * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ + * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ + * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_GYRO_OSR4_MODE + * 0x01 | BMI160_GYRO_OSR2_MODE + * 0x02 | BMI160_GYRO_NORMAL_MODE + * 0x03 | BMI160_GYRO_CIC_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_GYRO_OSR4_MODE + * 0x01 | BMI160_GYRO_OSR2_MODE + * 0x02 | BMI160_GYRO_NORMAL_MODE + * 0x03 | BMI160_GYRO_CIC_MODE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_GYRO_RANGE_2000_DEG_SEC + * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC + * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC + * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC + * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_GYRO_RANGE_2000_DEG_SEC + * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC + * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC + * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC + * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED + * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ + * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ + * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ + * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ + * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ + * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ + * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ + * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ + * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ + * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ + * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ + * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ + * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0 + * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1 + * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2 + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED + * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ + * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ + * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ + * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ + * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ + * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ + * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ + * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ + * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ + * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ + * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ + * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ + * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0 + * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1 + * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2 + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ANY_MOTION_X_ENABLE + * 1 | BMI160_ANY_MOTION_Y_ENABLE + * 2 | BMI160_ANY_MOTION_Z_ENABLE + * 3 | BMI160_DOUBLE_TAP_ENABLE + * 4 | BMI160_SINGLE_TAP_ENABLE + * 5 | BMI160_ORIENT_ENABLE + * 6 | BMI160_FLAT_ENABLE + * + * @param v_intr_enable_zero_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_ANY_MOTION_X_ENABLE + * 1 | BMI160_ANY_MOTION_Y_ENABLE + * 2 | BMI160_ANY_MOTION_Z_ENABLE + * 3 | BMI160_DOUBLE_TAP_ENABLE + * 4 | BMI160_SINGLE_TAP_ENABLE + * 5 | BMI160_ORIENT_ENABLE + * 6 | BMI160_FLAT_ENABLE + * + * @param v_intr_enable_zero_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_HIGH_G_X_ENABLE + * 1 | BMI160_HIGH_G_Y_ENABLE + * 2 | BMI160_HIGH_G_Z_ENABLE + * 3 | BMI160_LOW_G_ENABLE + * 4 | BMI160_DATA_RDY_ENABLE + * 5 | BMI160_FIFO_FULL_ENABLE + * 6 | BMI160_FIFO_WM_ENABLE + * + * @param v_intr_enable_1_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_HIGH_G_X_ENABLE + * 1 | BMI160_HIGH_G_Y_ENABLE + * 2 | BMI160_HIGH_G_Z_ENABLE + * 3 | BMI160_LOW_G_ENABLE + * 4 | BMI160_DATA_RDY_ENABLE + * 5 | BMI160_FIFO_FULL_ENABLE + * 6 | BMI160_FIFO_WM_ENABLE + * + * @param v_intr_enable_1_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_NOMOTION_X_ENABLE + * 1 | BMI160_NOMOTION_Y_ENABLE + * 2 | BMI160_NOMOTION_Z_ENABLE + * + * @param v_intr_enable_2_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_NOMOTION_X_ENABLE + * 1 | BMI160_NOMOTION_Y_ENABLE + * 2 | BMI160_NOMOTION_Z_ENABLE + * + * @param v_intr_enable_2_u8 : The interrupt enable value + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_EDGE_CTRL + * 1 | BMI160_INTR2_EDGE_CTRL + * + * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_EDGE + * 0x00 | BMI160_LEVEL + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_EDGE_CTRL + * 1 | BMI160_INTR2_EDGE_CTRL + * + * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_EDGE + * 0x00 | BMI160_LEVEL + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_LEVEL + * 1 | BMI160_INTR2_LEVEL + * + * @param v_intr_level_u8 : The value of level of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_LEVEL_HIGH + * 0x00 | BMI160_LEVEL_LOW + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_LEVEL + * 1 | BMI160_INTR2_LEVEL + * + * @param v_intr_level_u8 : The value of level of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_LEVEL_HIGH + * 0x00 | BMI160_LEVEL_LOW + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_intr_output_type_u8 : + * The value of output type of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_OPEN_DRAIN + * 0x00 | BMI160_PUSH_PULL + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_intr_output_type_u8 : + * The value of output type of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_OPEN_DRAIN + * 0x00 | BMI160_PUSH_PULL + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_output_enable_u8 : + * The value of output enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_OUTPUT_TYPE + * 1 | BMI160_INTR2_OUTPUT_TYPE + * + * @param v_output_enable_u8 : + * The value of output enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 +* --------------------------------------|------------------ +* BMI160_LATCH_DUR_NONE | 0x00 +* BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* BMI160_LATCH_DUR_625_MICRO_SEC | 0x02 +* BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* BMI160_LATCH_DUR_5_MILLI_SEC | 0x05 +* BMI160_LATCH_DUR_10_MILLI_SEC | 0x06 +* BMI160_LATCH_DUR_20_MILLI_SEC | 0x07 +* BMI160_LATCH_DUR_40_MILLI_SEC | 0x08 +* BMI160_LATCH_DUR_80_MILLI_SEC | 0x09 +* BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A +* BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B +* BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C +* BMI160_LATCH_DUR_1_28_SEC | 0x0D +* BMI160_LATCH_DUR_2_56_SEC | 0x0E +* BMI160_LATCHED | 0x0F +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 +* --------------------------------------|------------------ +* BMI160_LATCH_DUR_NONE | 0x00 +* BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01 +* BMI160_LATCH_DUR_625_MICRO_SEC | 0x02 +* BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03 +* BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04 +* BMI160_LATCH_DUR_5_MILLI_SEC | 0x05 +* BMI160_LATCH_DUR_10_MILLI_SEC | 0x06 +* BMI160_LATCH_DUR_20_MILLI_SEC | 0x07 +* BMI160_LATCH_DUR_40_MILLI_SEC | 0x08 +* BMI160_LATCH_DUR_80_MILLI_SEC | 0x09 +* BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A +* BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B +* BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C +* BMI160_LATCH_DUR_1_28_SEC | 0x0D +* BMI160_LATCH_DUR_2_56_SEC | 0x0E +* BMI160_LATCHED | 0x0F +* +* +* +* @return results of bus communication function +* @retval 0 -> Success +* @retval -1 -> Error +* +* +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_INPUT_ENABLE + * 1 | BMI160_INTR2_INPUT_ENABLE + * + * @param v_input_en_u8 : + * The value of input enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_INPUT_ENABLE + * 1 | BMI160_INTR2_INPUT_ENABLE + * + * @param v_input_en_u8 : + * The value of input enable of interrupt enable + * value | Behaviour + * ----------|------------------- + * 0x01 | BMI160_INPUT + * 0x00 | BMI160_OUTPUT + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_LOW_G + * 1 | BMI160_INTR2_MAP_LOW_G + * + * @param v_intr_low_g_u8 : The value of low_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_LOW_G + * 1 | BMI160_INTR2_MAP_LOW_G + * + * @param v_intr_low_g_u8 : The value of low_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_HIGH_G + * 1 | BMI160_INTR2_MAP_HIGH_G + * + * @param v_intr_high_g_u8 : The value of high_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_HIGH_G + * 1 | BMI160_INTR2_MAP_HIGH_G + * + * @param v_intr_high_g_u8 : The value of high_g enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_ANY_MOTION + * 1 | BMI160_INTR2_MAP_ANY_MOTION + * + * @param v_intr_any_motion_u8 : The value of any motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_ANY_MOTION + * 1 | BMI160_INTR2_MAP_ANY_MOTION + * + * @param v_intr_any_motion_u8 : The value of any motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_NOMO + * 1 | BMI160_INTR2_MAP_NOMO + * + * @param v_intr_nomotion_u8 : The value of no motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_NOMO + * 1 | BMI160_INTR2_MAP_NOMO + * + * @param v_intr_nomotion_u8 : The value of no motion enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_DOUBLE_TAP + * 1 | BMI160_INTR2_MAP_DOUBLE_TAP + * + * @param v_intr_double_tap_u8 : The value of double tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_DOUBLE_TAP + * 1 | BMI160_INTR2_MAP_DOUBLE_TAP + * + * @param v_intr_double_tap_u8 : The value of double tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_SINGLE_TAP + * 1 | BMI160_INTR2_MAP_SINGLE_TAP + * + * @param v_intr_single_tap_u8 : The value of single tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_SINGLE_TAP + * 1 | BMI160_INTR2_MAP_SINGLE_TAP + * + * @param v_intr_single_tap_u8 : The value of single tap enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_ORIENT + * 1 | BMI160_INTR2_MAP_ORIENT + * + * @param v_intr_orient_u8 : The value of orient enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_ORIENT + * 1 | BMI160_INTR2_MAP_ORIENT + * + * @param v_intr_orient_u8 : The value of orient enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_FLAT + * 1 | BMI160_INTR2_MAP_FLAT + * + * @param v_intr_flat_u8 : The value of flat enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_FLAT + * 1 | BMI160_INTR2_MAP_FLAT + * + * @param v_intr_flat_u8 : The value of flat enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_PMUTRIG + * 1 | BMI160_INTR2_MAP_PMUTRIG + * + * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_PMUTRIG + * 1 | BMI160_INTR2_MAP_PMUTRIG + * + * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable + * value | trigger enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_FIFO_FULL + * 1 | BMI160_INTR2_MAP_FIFO_FULL + * + * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_FIFO_FULL + * 1 | BMI160_INTR2_MAP_FIFO_FULL + * + * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_FIFO_WM + * 1 | BMI160_INTR2_MAP_FIFO_WM + * + * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_FIFO_WM + * 1 | BMI160_INTR2_MAP_FIFO_WM + * + * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_DATA_RDY + * 1 | BMI160_INTR2_MAP_DATA_RDY + * + * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_INTR1_MAP_DATA_RDY + * 1 | BMI160_INTR2_MAP_DATA_RDY + * + * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable + * value | interrupt enable + * ----------|------------------- + * 0x01 | BMI160_ENABLE + * 0x00 | BMI160_DISABLE + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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); + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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); + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_TAP_DURN_50MS + * 0x01 | BMI160_TAP_DURN_100MS + * 0x03 | BMI160_TAP_DURN_150MS + * 0x04 | BMI160_TAP_DURN_200MS + * 0x05 | BMI160_TAP_DURN_250MS + * 0x06 | BMI160_TAP_DURN_375MS + * 0x07 | BMI160_TAP_DURN_700MS + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_TAP_DURN_50MS + * 0x01 | BMI160_TAP_DURN_100MS + * 0x03 | BMI160_TAP_DURN_150MS + * 0x04 | BMI160_TAP_DURN_200MS + * 0x05 | BMI160_TAP_DURN_250MS + * 0x06 | BMI160_TAP_DURN_375MS + * 0x07 | BMI160_TAP_DURN_700MS + * + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_TAP_SHOCK_50MS + * 0x01 | BMI160_TAP_SHOCK_75MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_TAP_SHOCK_50MS + * 0x01 | BMI160_TAP_SHOCK_75MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_TAP_QUIET_30MS + * 0x01 | BMI160_TAP_QUIET_20MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 | BMI160_TAP_QUIET_30MS + * 0x01 | BMI160_TAP_QUIET_20MS + * + * + * @return results of bus communication function + * @retval 0 -> Success + * @retval -1 -> Error + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * + */ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi160_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 + * + * +*/ +BMI160_RETURN_FUNCTION_TYPE bmi1