mirror of https://github.com/arendst/Tasmota.git
support for TTGO ESP32 watch
This commit is contained in:
parent
fd26855fac
commit
28b21171a8
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 TTGO
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,62 @@
|
|||
<h1 align = "center">🌟LilyGO T-Watch🌟</h1>
|
||||
|
||||
**English | [中文](docs/details_cn.md)**
|
||||
|
||||
|
||||
<h2 align = "left">⭐ News </h2>
|
||||
|
||||
1. In order to be compatible with multiple versions of T-Watch, all examples include a `config.h` file. For the first use, you need to define the **T-Watch** model you use in the `config.h` file
|
||||
2. In the `config.h` file, you can also see similar definitions, such as **LILYGO_WATCH_LVGL**, **LILYGO_WATCH_HAS_MOTOR**, this type of definition, it will be responsible for opening the defined module function, all definitions Will be available here [View](./docs/defined_en.md)
|
||||
3. Most of the examples are only used as hardware function demonstrations. This library only completes some initialization work and some demonstrations. For more advanced gameplay, please see [TTGO.h](https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library/blob/master/src/TTGO.h), to understand how to initialize, after being familiar with it, you can completely leave this library for more advanced gameplay
|
||||
- About API, please check the source code
|
||||
|
||||
<h2 align = "left">🚀 Characteristics</h2>
|
||||
|
||||
1. The library already contains all the hardware drivers for `T-Watch`
|
||||
2. Using **TFT_eSPI** as the display driver, you can directly call **TFT_eSPI** through the construction object.
|
||||
3. Using **lvgl 7.0.0** as the display graphics framework, the driver method has been implemented, you only need to call lvgl api according to your own needs.
|
||||
4. For the use of lvgl please refer to **[lvgl docs](https://docs.lvgl.io/v7/en/html/)**
|
||||
|
||||
|
||||
<h2 align = "left">🔷 Install</h2>
|
||||
|
||||
- Download a zipfile from github using the "Download ZIP" button and install it using the IDE ("Sketch" -> "Include Library" -> "Add .ZIP Library..."
|
||||
- Clone this git repository into your sketchbook/libraries folder.
|
||||
For more info, see https://www.arduino.cc/en/Guide/Libraries
|
||||
|
||||
|
||||
<h2 align = "left">🔶 How to find the sample program</h2>
|
||||
|
||||
- In the Arduino board select `TTGO T-Watch`
|
||||
- In the Arduino File -> Examples -> TTGO T-Watch
|
||||
|
||||
<h2 align = "left">🔷 Note</h2>
|
||||
|
||||
- If you don't have the `TTGO T-Watch` option in your board manager, please update the esp32 board as follows:
|
||||
- Using Arduino IDE Boards Manager (preferred)
|
||||
+ [Instructions for Boards Manager](docs/arduino-ide/boards_manager.md)
|
||||
- Using Arduino IDE with the development repository
|
||||
+ [Instructions for Windows](docs/arduino-ide/windows.md)
|
||||
+ [Instructions for Mac](docs/arduino-ide/mac.md)
|
||||
+ [Instructions for Debian/Ubuntu Linux](docs/arduino-ide/debian_ubuntu.md)
|
||||
+ [Instructions for Fedora](docs/arduino-ide/fedora.md)
|
||||
+ [Instructions for openSUSE](docs/arduino-ide/opensuse.md)
|
||||
|
||||
<h2 align = "left">🔶 Precautions</h2>
|
||||
|
||||
- T-Watch-2019 : Since Twatch uses a special IO as the SD interface, please remove the SD card when downloading the program.
|
||||
|
||||
|
||||
<h2 align = "left">🔷 Other</h2>
|
||||
|
||||
- [Click for details of power consumption](docs/power.md)
|
||||
- [Pin Map Click to View](docs/pinmap.md)
|
||||
- [3D Shell](https://github.com/Xinyuan-LilyGO/LilyGo-TWatch-DataSheet/tree/master/3DSHELL)
|
||||
- [Hardware Resource](https://github.com/Xinyuan-LilyGO/LilyGo-TWatch-DataSheet)
|
||||
- [Acsip S76/78 Library&Examples](https://github.com/lewisxhe/Acsip-S7xG-Library)
|
||||
|
||||
<h2 align = "left">🔶 More interesting projects</h2>
|
||||
|
||||
- [Flight Recorder](https://github.com/lyusupov/SoftRF/wiki/Flight-Recorder)
|
||||
- [TTGO_T_Watch_Baidu_Rec](https://github.com/lixy123/TTGO_T_Watch_Baidu_Rec)
|
||||
- [TTGO_T_Watch_Alarm_Clock](https://github.com/lixy123/TTGO_T_Watch_Alarm_Clock)
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "TTGO TWatch Library",
|
||||
"keywords": "Device Conterl,TWatch,Watch,TTGO",
|
||||
"description": "Arduino Library for TTGO T-Watch development kit",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library.git"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Xinyuan Electronics",
|
||||
"email": "lily@lilygo.cc",
|
||||
"url": "https://github.com/Xinyuan-LilyGO",
|
||||
"maintainer": true
|
||||
},
|
||||
{
|
||||
"name": "lewishe",
|
||||
"email": "lewishe@outlook.com",
|
||||
"url": "https://github.com/lewisxhe"
|
||||
}
|
||||
],
|
||||
"version": "1.2.0",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "esp32"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
name=TTGO TWatch Library
|
||||
version=1.2.0
|
||||
author=TTGO
|
||||
maintainer=lewis he <lewishe@outlook.com>
|
||||
sentence=Library for TTGO T-Watch development kit
|
||||
paragraph=twatch library
|
||||
category=Device Control
|
||||
url=https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library
|
||||
architectures=esp32
|
||||
includes=*
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,827 @@
|
|||
/////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 lewis he
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
axp20x.h - Arduino library for X-Power AXP202 chip.
|
||||
Created by Lewis he on April 1, 2019.
|
||||
github:https://github.com/lewisxhe/AXP202X_Libraries
|
||||
*/
|
||||
/////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// #define AXP_DEBUG_PORT Serial
|
||||
#ifdef AXP_DEBUG_PORT
|
||||
#define AXP_DEBUG(fmt, ...) AXP_DEBUG_PORT.printf_P((PGM_P)PSTR(fmt), ##__VA_ARGS__)
|
||||
#else
|
||||
#define AXP_DEBUG(...)
|
||||
#endif
|
||||
|
||||
#ifndef RISING
|
||||
#define RISING 0x01
|
||||
#endif
|
||||
|
||||
#ifndef FALLING
|
||||
#define FALLING 0x02
|
||||
#endif
|
||||
|
||||
#ifdef _BV
|
||||
#undef _BV
|
||||
#endif
|
||||
#define _BV(b) (1ULL << (b))
|
||||
|
||||
//! Error Code
|
||||
#define AXP_PASS (0)
|
||||
#define AXP_FAIL (-1)
|
||||
#define AXP_INVALID (-2)
|
||||
#define AXP_NOT_INIT (-3)
|
||||
#define AXP_NOT_SUPPORT (-4)
|
||||
#define AXP_ARG_INVALID (-5)
|
||||
|
||||
//! Chip Address
|
||||
#define AXP202_SLAVE_ADDRESS (0x35)
|
||||
#define AXP192_SLAVE_ADDRESS (0x34)
|
||||
#define AXP173_SLAVE_ADDRESS (0x34)
|
||||
|
||||
//! Chip ID
|
||||
#define AXP202_CHIP_ID 0x41
|
||||
#define AXP192_CHIP_ID 0x03
|
||||
#define AXP173_CHIP_ID 0xAD //!Axp173 does not have a chip ID, given a custom ID
|
||||
|
||||
//! Logic states
|
||||
#define AXP202_ON 1
|
||||
#define AXP202_OFF 0
|
||||
|
||||
//! REG MAP
|
||||
#define AXP202_STATUS (0x00)
|
||||
#define AXP202_MODE_CHGSTATUS (0x01)
|
||||
#define AXP202_OTG_STATUS (0x02)
|
||||
#define AXP202_IC_TYPE (0x03)
|
||||
#define AXP202_DATA_BUFFER1 (0x04)
|
||||
#define AXP202_DATA_BUFFER2 (0x05)
|
||||
#define AXP202_DATA_BUFFER3 (0x06)
|
||||
#define AXP202_DATA_BUFFER4 (0x07)
|
||||
#define AXP202_DATA_BUFFER5 (0x08)
|
||||
#define AXP202_DATA_BUFFER6 (0x09)
|
||||
#define AXP202_DATA_BUFFER7 (0x0A)
|
||||
#define AXP202_DATA_BUFFER8 (0x0B)
|
||||
#define AXP202_DATA_BUFFER9 (0x0C)
|
||||
#define AXP202_DATA_BUFFERA (0x0D)
|
||||
#define AXP202_DATA_BUFFERB (0x0E)
|
||||
#define AXP202_DATA_BUFFERC (0x0F)
|
||||
#define AXP202_LDO234_DC23_CTL (0x12)
|
||||
#define AXP202_DC2OUT_VOL (0x23)
|
||||
#define AXP202_LDO3_DC2_DVM (0x25)
|
||||
#define AXP202_DC3OUT_VOL (0x27)
|
||||
#define AXP202_LDO24OUT_VOL (0x28)
|
||||
#define AXP202_LDO3OUT_VOL (0x29)
|
||||
#define AXP202_IPS_SET (0x30)
|
||||
#define AXP202_VOFF_SET (0x31)
|
||||
#define AXP202_OFF_CTL (0x32)
|
||||
#define AXP202_CHARGE1 (0x33)
|
||||
#define AXP202_CHARGE2 (0x34)
|
||||
#define AXP202_BACKUP_CHG (0x35)
|
||||
#define AXP202_POK_SET (0x36)
|
||||
#define AXP202_DCDC_FREQSET (0x37)
|
||||
#define AXP202_VLTF_CHGSET (0x38)
|
||||
#define AXP202_VHTF_CHGSET (0x39)
|
||||
#define AXP202_APS_WARNING1 (0x3A)
|
||||
#define AXP202_APS_WARNING2 (0x3B)
|
||||
#define AXP202_TLTF_DISCHGSET (0x3C)
|
||||
#define AXP202_THTF_DISCHGSET (0x3D)
|
||||
#define AXP202_DCDC_MODESET (0x80)
|
||||
#define AXP202_ADC_EN1 (0x82)
|
||||
#define AXP202_ADC_EN2 (0x83)
|
||||
#define AXP202_ADC_SPEED (0x84)
|
||||
#define AXP202_ADC_INPUTRANGE (0x85)
|
||||
#define AXP202_ADC_IRQ_RETFSET (0x86)
|
||||
#define AXP202_ADC_IRQ_FETFSET (0x87)
|
||||
#define AXP202_TIMER_CTL (0x8A)
|
||||
#define AXP202_VBUS_DET_SRP (0x8B)
|
||||
#define AXP202_HOTOVER_CTL (0x8F)
|
||||
#define AXP202_GPIO0_CTL (0x90)
|
||||
#define AXP202_GPIO0_VOL (0x91)
|
||||
#define AXP202_GPIO1_CTL (0x92)
|
||||
#define AXP202_GPIO2_CTL (0x93)
|
||||
#define AXP202_GPIO012_SIGNAL (0x94)
|
||||
#define AXP202_GPIO3_CTL (0x95)
|
||||
#define AXP202_INTEN1 (0x40)
|
||||
#define AXP202_INTEN2 (0x41)
|
||||
#define AXP202_INTEN3 (0x42)
|
||||
#define AXP202_INTEN4 (0x43)
|
||||
#define AXP202_INTEN5 (0x44)
|
||||
#define AXP202_INTSTS1 (0x48)
|
||||
#define AXP202_INTSTS2 (0x49)
|
||||
#define AXP202_INTSTS3 (0x4A)
|
||||
#define AXP202_INTSTS4 (0x4B)
|
||||
#define AXP202_INTSTS5 (0x4C)
|
||||
|
||||
//Irq control register
|
||||
#define AXP192_INTEN1 (0x40)
|
||||
#define AXP192_INTEN2 (0x41)
|
||||
#define AXP192_INTEN3 (0x42)
|
||||
#define AXP192_INTEN4 (0x43)
|
||||
#define AXP192_INTEN5 (0x4A)
|
||||
//Irq status register
|
||||
#define AXP192_INTSTS1 (0x44)
|
||||
#define AXP192_INTSTS2 (0x45)
|
||||
#define AXP192_INTSTS3 (0x46)
|
||||
#define AXP192_INTSTS4 (0x47)
|
||||
#define AXP192_INTSTS5 (0x4D)
|
||||
|
||||
#define AXP192_DC1_VLOTAGE (0x26)
|
||||
#define AXP192_LDO23OUT_VOL (0x28)
|
||||
#define AXP192_GPIO0_CTL (0x90)
|
||||
#define AXP192_GPIO0_VOL (0x91)
|
||||
#define AXP192_GPIO1_CTL (0X92)
|
||||
#define AXP192_GPIO2_CTL (0x93)
|
||||
#define AXP192_GPIO012_SIGNAL (0x94)
|
||||
#define AXP192_GPIO34_CTL (0x95)
|
||||
|
||||
|
||||
|
||||
/* axp 192/202 adc data register */
|
||||
#define AXP202_BAT_AVERVOL_H8 (0x78)
|
||||
#define AXP202_BAT_AVERVOL_L4 (0x79)
|
||||
#define AXP202_BAT_AVERCHGCUR_H8 (0x7A)
|
||||
#define AXP202_BAT_AVERCHGCUR_L4 (0x7B)
|
||||
#define AXP202_BAT_AVERCHGCUR_L5 (0x7B)
|
||||
#define AXP202_ACIN_VOL_H8 (0x56)
|
||||
#define AXP202_ACIN_VOL_L4 (0x57)
|
||||
#define AXP202_ACIN_CUR_H8 (0x58)
|
||||
#define AXP202_ACIN_CUR_L4 (0x59)
|
||||
#define AXP202_VBUS_VOL_H8 (0x5A)
|
||||
#define AXP202_VBUS_VOL_L4 (0x5B)
|
||||
#define AXP202_VBUS_CUR_H8 (0x5C)
|
||||
#define AXP202_VBUS_CUR_L4 (0x5D)
|
||||
#define AXP202_INTERNAL_TEMP_H8 (0x5E)
|
||||
#define AXP202_INTERNAL_TEMP_L4 (0x5F)
|
||||
#define AXP202_TS_IN_H8 (0x62)
|
||||
#define AXP202_TS_IN_L4 (0x63)
|
||||
#define AXP202_GPIO0_VOL_ADC_H8 (0x64)
|
||||
#define AXP202_GPIO0_VOL_ADC_L4 (0x65)
|
||||
#define AXP202_GPIO1_VOL_ADC_H8 (0x66)
|
||||
#define AXP202_GPIO1_VOL_ADC_L4 (0x67)
|
||||
|
||||
#define AXP202_BAT_AVERDISCHGCUR_H8 (0x7C)
|
||||
#define AXP202_BAT_AVERDISCHGCUR_L5 (0x7D)
|
||||
#define AXP202_APS_AVERVOL_H8 (0x7E)
|
||||
#define AXP202_APS_AVERVOL_L4 (0x7F)
|
||||
#define AXP202_INT_BAT_CHGCUR_H8 (0xA0)
|
||||
#define AXP202_INT_BAT_CHGCUR_L4 (0xA1)
|
||||
#define AXP202_EXT_BAT_CHGCUR_H8 (0xA2)
|
||||
#define AXP202_EXT_BAT_CHGCUR_L4 (0xA3)
|
||||
#define AXP202_INT_BAT_DISCHGCUR_H8 (0xA4)
|
||||
#define AXP202_INT_BAT_DISCHGCUR_L4 (0xA5)
|
||||
#define AXP202_EXT_BAT_DISCHGCUR_H8 (0xA6)
|
||||
#define AXP202_EXT_BAT_DISCHGCUR_L4 (0xA7)
|
||||
#define AXP202_BAT_CHGCOULOMB3 (0xB0)
|
||||
#define AXP202_BAT_CHGCOULOMB2 (0xB1)
|
||||
#define AXP202_BAT_CHGCOULOMB1 (0xB2)
|
||||
#define AXP202_BAT_CHGCOULOMB0 (0xB3)
|
||||
#define AXP202_BAT_DISCHGCOULOMB3 (0xB4)
|
||||
#define AXP202_BAT_DISCHGCOULOMB2 (0xB5)
|
||||
#define AXP202_BAT_DISCHGCOULOMB1 (0xB6)
|
||||
#define AXP202_BAT_DISCHGCOULOMB0 (0xB7)
|
||||
#define AXP202_COULOMB_CTL (0xB8)
|
||||
#define AXP202_BAT_POWERH8 (0x70)
|
||||
#define AXP202_BAT_POWERM8 (0x71)
|
||||
#define AXP202_BAT_POWERL8 (0x72)
|
||||
|
||||
#define AXP202_VREF_TEM_CTRL (0xF3)
|
||||
#define AXP202_BATT_PERCENTAGE (0xB9)
|
||||
|
||||
/* bit definitions for AXP events, irq event */
|
||||
/* AXP202 */
|
||||
#define AXP202_IRQ_USBLO (1)
|
||||
#define AXP202_IRQ_USBRE (2)
|
||||
#define AXP202_IRQ_USBIN (3)
|
||||
#define AXP202_IRQ_USBOV (4)
|
||||
#define AXP202_IRQ_ACRE (5)
|
||||
#define AXP202_IRQ_ACIN (6)
|
||||
#define AXP202_IRQ_ACOV (7)
|
||||
|
||||
#define AXP202_IRQ_TEMLO (8)
|
||||
#define AXP202_IRQ_TEMOV (9)
|
||||
#define AXP202_IRQ_CHAOV (10)
|
||||
#define AXP202_IRQ_CHAST (11)
|
||||
#define AXP202_IRQ_BATATOU (12)
|
||||
#define AXP202_IRQ_BATATIN (13)
|
||||
#define AXP202_IRQ_BATRE (14)
|
||||
#define AXP202_IRQ_BATIN (15)
|
||||
|
||||
#define AXP202_IRQ_POKLO (16)
|
||||
#define AXP202_IRQ_POKSH (17)
|
||||
#define AXP202_IRQ_LDO3LO (18)
|
||||
#define AXP202_IRQ_DCDC3LO (19)
|
||||
#define AXP202_IRQ_DCDC2LO (20)
|
||||
#define AXP202_IRQ_CHACURLO (22)
|
||||
#define AXP202_IRQ_ICTEMOV (23)
|
||||
|
||||
#define AXP202_IRQ_EXTLOWARN2 (24)
|
||||
#define AXP202_IRQ_EXTLOWARN1 (25)
|
||||
#define AXP202_IRQ_SESSION_END (26)
|
||||
#define AXP202_IRQ_SESS_AB_VALID (27)
|
||||
#define AXP202_IRQ_VBUS_UN_VALID (28)
|
||||
#define AXP202_IRQ_VBUS_VALID (29)
|
||||
#define AXP202_IRQ_PDOWN_BY_NOE (30)
|
||||
#define AXP202_IRQ_PUP_BY_NOE (31)
|
||||
|
||||
#define AXP202_IRQ_GPIO0TG (32)
|
||||
#define AXP202_IRQ_GPIO1TG (33)
|
||||
#define AXP202_IRQ_GPIO2TG (34)
|
||||
#define AXP202_IRQ_GPIO3TG (35)
|
||||
#define AXP202_IRQ_PEKFE (37)
|
||||
#define AXP202_IRQ_PEKRE (38)
|
||||
#define AXP202_IRQ_TIMER (39)
|
||||
|
||||
//Signal Capture
|
||||
#define AXP202_BATT_VOLTAGE_STEP (1.1F)
|
||||
#define AXP202_BATT_DISCHARGE_CUR_STEP (0.5F)
|
||||
#define AXP202_BATT_CHARGE_CUR_STEP (0.5F)
|
||||
#define AXP202_ACIN_VOLTAGE_STEP (1.7F)
|
||||
#define AXP202_ACIN_CUR_STEP (0.625F)
|
||||
#define AXP202_VBUS_VOLTAGE_STEP (1.7F)
|
||||
#define AXP202_VBUS_CUR_STEP (0.375F)
|
||||
#define AXP202_INTERNAL_TEMP_STEP (0.1F)
|
||||
#define AXP202_APS_VOLTAGE_STEP (1.4F)
|
||||
#define AXP202_TS_PIN_OUT_STEP (0.8F)
|
||||
#define AXP202_GPIO0_STEP (0.5F)
|
||||
#define AXP202_GPIO1_STEP (0.5F)
|
||||
// AXP192 only
|
||||
#define AXP202_GPIO2_STEP (0.5F)
|
||||
#define AXP202_GPIO3_STEP (0.5F)
|
||||
|
||||
// AXP173
|
||||
#define AXP173_EXTEN_DC2_CTL (0x10)
|
||||
#define AXP173_CTL_DC2_BIT (0)
|
||||
#define AXP173_CTL_EXTEN_BIT (2)
|
||||
#define AXP173_DC1_VLOTAGE (0x26)
|
||||
#define AXP173_LDO4_VLOTAGE (0x27)
|
||||
|
||||
#define FORCED_OPEN_DCDC3(x) (x |= (AXP202_ON << AXP202_DCDC3))
|
||||
#define BIT_MASK(x) (1 << x)
|
||||
#define IS_OPEN(reg, channel) (bool)(reg & BIT_MASK(channel))
|
||||
|
||||
enum {
|
||||
AXP202_EXTEN = 0,
|
||||
AXP202_DCDC3 = 1,
|
||||
AXP202_LDO2 = 2,
|
||||
AXP202_LDO4 = 3,
|
||||
AXP202_DCDC2 = 4,
|
||||
AXP202_LDO3 = 6,
|
||||
AXP202_OUTPUT_MAX,
|
||||
};
|
||||
|
||||
enum {
|
||||
AXP192_DCDC1 = 0,
|
||||
AXP192_DCDC3 = 1,
|
||||
AXP192_LDO2 = 2,
|
||||
AXP192_LDO3 = 3,
|
||||
AXP192_DCDC2 = 4,
|
||||
AXP192_EXTEN = 6,
|
||||
AXP192_OUTPUT_MAX,
|
||||
};
|
||||
|
||||
enum {
|
||||
AXP173_DCDC1 = 0,
|
||||
AXP173_LDO4 = 1,
|
||||
AXP173_LDO2 = 2,
|
||||
AXP173_LDO3 = 3,
|
||||
AXP173_DCDC2 = 4,
|
||||
AXP173_EXTEN = 6,
|
||||
AXP173_OUTPUT_MAX,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
AXP202_STARTUP_TIME_128MS,
|
||||
AXP202_STARTUP_TIME_3S,
|
||||
AXP202_STARTUP_TIME_1S,
|
||||
AXP202_STARTUP_TIME_2S,
|
||||
} axp202_startup_time_t;
|
||||
|
||||
typedef enum {
|
||||
AXP192_STARTUP_TIME_128MS,
|
||||
AXP192_STARTUP_TIME_512MS,
|
||||
AXP192_STARTUP_TIME_1S,
|
||||
AXP192_STARTUP_TIME_2S,
|
||||
} axp192_startup_time_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_LONGPRESS_TIME_1S,
|
||||
AXP_LONGPRESS_TIME_1S5,
|
||||
AXP_LONGPRESS_TIME_2S,
|
||||
AXP_LONGPRESS_TIME_2S5,
|
||||
} axp_loonPress_time_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_POWER_OFF_TIME_4S,
|
||||
AXP_POWER_OFF_TIME_65,
|
||||
AXP_POWER_OFF_TIME_8S,
|
||||
AXP_POWER_OFF_TIME_16S,
|
||||
} axp_poweroff_time_t;
|
||||
|
||||
//REG 33H: Charging control 1 Charging target-voltage setting
|
||||
typedef enum {
|
||||
AXP202_TARGET_VOL_4_1V,
|
||||
AXP202_TARGET_VOL_4_15V,
|
||||
AXP202_TARGET_VOL_4_2V,
|
||||
AXP202_TARGET_VOL_4_36V
|
||||
} axp_chargeing_vol_t;
|
||||
|
||||
//REG 82H: ADC Enable 1 register Parameter
|
||||
typedef enum {
|
||||
AXP202_BATT_VOL_ADC1 = 1 << 7,
|
||||
AXP202_BATT_CUR_ADC1 = 1 << 6,
|
||||
AXP202_ACIN_VOL_ADC1 = 1 << 5,
|
||||
AXP202_ACIN_CUR_ADC1 = 1 << 4,
|
||||
AXP202_VBUS_VOL_ADC1 = 1 << 3,
|
||||
AXP202_VBUS_CUR_ADC1 = 1 << 2,
|
||||
AXP202_APS_VOL_ADC1 = 1 << 1,
|
||||
AXP202_TS_PIN_ADC1 = 1 << 0
|
||||
} axp_adc1_func_t;
|
||||
|
||||
// REG 83H: ADC Enable 2 register Parameter
|
||||
typedef enum {
|
||||
AXP202_TEMP_MONITORING_ADC2 = 1 << 7,
|
||||
AXP202_GPIO1_FUNC_ADC2 = 1 << 3,
|
||||
AXP202_GPIO0_FUNC_ADC2 = 1 << 2
|
||||
} axp_adc2_func_t;
|
||||
|
||||
typedef enum {
|
||||
AXP202_LDO3_MODE_LDO,
|
||||
AXP202_LDO3_MODE_DCIN
|
||||
} axp202_ldo3_mode_t;
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
//! IRQ1 REG 40H
|
||||
AXP202_VBUS_VHOLD_LOW_IRQ = _BV(1), //VBUS is available, but lower than V HOLD, IRQ enable
|
||||
AXP202_VBUS_REMOVED_IRQ = _BV(2), //VBUS removed, IRQ enable
|
||||
AXP202_VBUS_CONNECT_IRQ = _BV(3), //VBUS connected, IRQ enable
|
||||
AXP202_VBUS_OVER_VOL_IRQ = _BV(4), //VBUS over-voltage, IRQ enable
|
||||
AXP202_ACIN_REMOVED_IRQ = _BV(5), //ACIN removed, IRQ enable
|
||||
AXP202_ACIN_CONNECT_IRQ = _BV(6), //ACIN connected, IRQ enable
|
||||
AXP202_ACIN_OVER_VOL_IRQ = _BV(7), //ACIN over-voltage, IRQ enable
|
||||
|
||||
//! IRQ2 REG 41H
|
||||
AXP202_BATT_LOW_TEMP_IRQ = _BV(8), //Battery low-temperature, IRQ enable
|
||||
AXP202_BATT_OVER_TEMP_IRQ = _BV(9), //Battery over-temperature, IRQ enable
|
||||
AXP202_CHARGING_FINISHED_IRQ = _BV(10), //Charge finished, IRQ enable
|
||||
AXP202_CHARGING_IRQ = _BV(11), //Be charging, IRQ enable
|
||||
AXP202_BATT_EXIT_ACTIVATE_IRQ = _BV(12), //Exit battery activate mode, IRQ enable
|
||||
AXP202_BATT_ACTIVATE_IRQ = _BV(13), //Battery activate mode, IRQ enable
|
||||
AXP202_BATT_REMOVED_IRQ = _BV(14), //Battery removed, IRQ enable
|
||||
AXP202_BATT_CONNECT_IRQ = _BV(15), //Battery connected, IRQ enable
|
||||
|
||||
//! IRQ3 REG 42H
|
||||
AXP202_PEK_LONGPRESS_IRQ = _BV(16), //PEK long press, IRQ enable
|
||||
AXP202_PEK_SHORTPRESS_IRQ = _BV(17), //PEK short press, IRQ enable
|
||||
AXP202_LDO3_LOW_VOL_IRQ = _BV(18), //LDO3output voltage is lower than the set value, IRQ enable
|
||||
AXP202_DC3_LOW_VOL_IRQ = _BV(19), //DC-DC3output voltage is lower than the set value, IRQ enable
|
||||
AXP202_DC2_LOW_VOL_IRQ = _BV(20), //DC-DC2 output voltage is lower than the set value, IRQ enable
|
||||
//**Reserved and unchangeable BIT 5
|
||||
AXP202_CHARGE_LOW_CUR_IRQ = _BV(22), //Charge current is lower than the set current, IRQ enable
|
||||
AXP202_CHIP_TEMP_HIGH_IRQ = _BV(23), //AXP202 internal over-temperature, IRQ enable
|
||||
|
||||
//! IRQ4 REG 43H
|
||||
AXP202_APS_LOW_VOL_LEVEL2_IRQ = _BV(24), //APS low-voltage, IRQ enable(LEVEL2)
|
||||
APX202_APS_LOW_VOL_LEVEL1_IRQ = _BV(25), //APS low-voltage, IRQ enable(LEVEL1)
|
||||
AXP202_VBUS_SESSION_END_IRQ = _BV(26), //VBUS Session End IRQ enable
|
||||
AXP202_VBUS_SESSION_AB_IRQ = _BV(27), //VBUS Session A/B IRQ enable
|
||||
AXP202_VBUS_INVALID_IRQ = _BV(28), //VBUS invalid, IRQ enable
|
||||
AXP202_VBUS_VAILD_IRQ = _BV(29), //VBUS valid, IRQ enable
|
||||
AXP202_NOE_OFF_IRQ = _BV(30), //N_OE shutdown, IRQ enable
|
||||
AXP202_NOE_ON_IRQ = _BV(31), //N_OE startup, IRQ enable
|
||||
|
||||
//! IRQ5 REG 44H
|
||||
AXP202_GPIO0_EDGE_TRIGGER_IRQ = _BV(32), //GPIO0 input edge trigger, IRQ enable
|
||||
AXP202_GPIO1_EDGE_TRIGGER_IRQ = _BV(33), //GPIO1input edge trigger or ADC input, IRQ enable
|
||||
AXP202_GPIO2_EDGE_TRIGGER_IRQ = _BV(34), //GPIO2input edge trigger, IRQ enable
|
||||
AXP202_GPIO3_EDGE_TRIGGER_IRQ = _BV(35), //GPIO3 input edge trigger, IRQ enable
|
||||
//**Reserved and unchangeable BIT 4
|
||||
AXP202_PEK_FALLING_EDGE_IRQ = _BV(37), //PEK press falling edge, IRQ enable
|
||||
AXP202_PEK_RISING_EDGE_IRQ = _BV(38), //PEK press rising edge, IRQ enable
|
||||
AXP202_TIMER_TIMEOUT_IRQ = _BV(39), //Timer timeout, IRQ enable
|
||||
|
||||
AXP202_ALL_IRQ = (0xFFFFFFFFFFULL)
|
||||
} axp_irq_t;
|
||||
|
||||
typedef enum {
|
||||
AXP202_LDO4_1250MV,
|
||||
AXP202_LDO4_1300MV,
|
||||
AXP202_LDO4_1400MV,
|
||||
AXP202_LDO4_1500MV,
|
||||
AXP202_LDO4_1600MV,
|
||||
AXP202_LDO4_1700MV,
|
||||
AXP202_LDO4_1800MV,
|
||||
AXP202_LDO4_1900MV,
|
||||
AXP202_LDO4_2000MV,
|
||||
AXP202_LDO4_2500MV,
|
||||
AXP202_LDO4_2700MV,
|
||||
AXP202_LDO4_2800MV,
|
||||
AXP202_LDO4_3000MV,
|
||||
AXP202_LDO4_3100MV,
|
||||
AXP202_LDO4_3200MV,
|
||||
AXP202_LDO4_3300MV,
|
||||
AXP202_LDO4_MAX,
|
||||
} axp_ldo4_table_t;
|
||||
|
||||
typedef enum {
|
||||
AXP202_LDO5_1800MV,
|
||||
AXP202_LDO5_2500MV,
|
||||
AXP202_LDO5_2800MV,
|
||||
AXP202_LDO5_3000MV,
|
||||
AXP202_LDO5_3100MV,
|
||||
AXP202_LDO5_3300MV,
|
||||
AXP202_LDO5_3400MV,
|
||||
AXP202_LDO5_3500MV,
|
||||
} axp_ldo5_table_t;
|
||||
|
||||
typedef enum {
|
||||
AXP20X_LED_OFF,
|
||||
AXP20X_LED_BLINK_1HZ,
|
||||
AXP20X_LED_BLINK_4HZ,
|
||||
AXP20X_LED_LOW_LEVEL,
|
||||
} axp_chgled_mode_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_ADC_SAMPLING_RATE_25HZ = 0,
|
||||
AXP_ADC_SAMPLING_RATE_50HZ = 1,
|
||||
AXP_ADC_SAMPLING_RATE_100HZ = 2,
|
||||
AXP_ADC_SAMPLING_RATE_200HZ = 3,
|
||||
} axp_adc_sampling_rate_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_TS_PIN_CURRENT_20UA = 0,
|
||||
AXP_TS_PIN_CURRENT_40UA = 1,
|
||||
AXP_TS_PIN_CURRENT_60UA = 2,
|
||||
AXP_TS_PIN_CURRENT_80UA = 3,
|
||||
} axp_ts_pin_current_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_TS_PIN_FUNCTION_BATT = 0,
|
||||
AXP_TS_PIN_FUNCTION_ADC = 1,
|
||||
} axp_ts_pin_function_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_TS_PIN_MODE_DISABLE = 0,
|
||||
AXP_TS_PIN_MODE_CHARGING = 1,
|
||||
AXP_TS_PIN_MODE_SAMPLING = 2,
|
||||
AXP_TS_PIN_MODE_ENABLE = 3,
|
||||
} axp_ts_pin_mode_t;
|
||||
|
||||
//! Only AXP192 and AXP202 have gpio function
|
||||
typedef enum {
|
||||
AXP_GPIO_0,
|
||||
AXP_GPIO_1,
|
||||
AXP_GPIO_2,
|
||||
AXP_GPIO_3,
|
||||
AXP_GPIO_4,
|
||||
} axp_gpio_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_IO_OUTPUT_LOW_MODE,
|
||||
AXP_IO_OUTPUT_HIGH_MODE,
|
||||
AXP_IO_INPUT_MODE,
|
||||
AXP_IO_LDO_MODE,
|
||||
AXP_IO_ADC_MODE,
|
||||
AXP_IO_FLOATING_MODE,
|
||||
AXP_IO_OPEN_DRAIN_OUTPUT_MODE,
|
||||
AXP_IO_PWM_OUTPUT_MODE,
|
||||
AXP_IO_EXTERN_CHARGING_CTRL_MODE,
|
||||
} axp_gpio_mode_t;
|
||||
|
||||
typedef enum {
|
||||
AXP_IRQ_NONE,
|
||||
AXP_IRQ_RISING,
|
||||
AXP_IRQ_FALLING,
|
||||
AXP_IRQ_DOUBLE_EDGE,
|
||||
} axp_gpio_irq_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
AXP192_GPIO_1V8,
|
||||
AXP192_GPIO_1V9,
|
||||
AXP192_GPIO_2V0,
|
||||
AXP192_GPIO_2V1,
|
||||
AXP192_GPIO_2V2,
|
||||
AXP192_GPIO_2V3,
|
||||
AXP192_GPIO_2V4,
|
||||
AXP192_GPIO_2V5,
|
||||
AXP192_GPIO_2V6,
|
||||
AXP192_GPIO_2V7,
|
||||
AXP192_GPIO_2V8,
|
||||
AXP192_GPIO_2V9,
|
||||
AXP192_GPIO_3V0,
|
||||
AXP192_GPIO_3V1,
|
||||
AXP192_GPIO_3V2,
|
||||
AXP192_GPIO_3V3,
|
||||
} axp192_gpio_voltage_t;
|
||||
|
||||
typedef enum {
|
||||
AXP1XX_CHARGE_CUR_100MA,
|
||||
AXP1XX_CHARGE_CUR_190MA,
|
||||
AXP1XX_CHARGE_CUR_280MA,
|
||||
AXP1XX_CHARGE_CUR_360MA,
|
||||
AXP1XX_CHARGE_CUR_450MA,
|
||||
AXP1XX_CHARGE_CUR_550MA,
|
||||
AXP1XX_CHARGE_CUR_630MA,
|
||||
AXP1XX_CHARGE_CUR_700MA,
|
||||
AXP1XX_CHARGE_CUR_780MA,
|
||||
AXP1XX_CHARGE_CUR_880MA,
|
||||
AXP1XX_CHARGE_CUR_960MA,
|
||||
AXP1XX_CHARGE_CUR_1000MA,
|
||||
AXP1XX_CHARGE_CUR_1080MA,
|
||||
AXP1XX_CHARGE_CUR_1160MA,
|
||||
AXP1XX_CHARGE_CUR_1240MA,
|
||||
AXP1XX_CHARGE_CUR_1320MA,
|
||||
} axp1xx_charge_current_t;
|
||||
|
||||
typedef uint8_t (*axp_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint8_t len);
|
||||
|
||||
|
||||
class AXP20X_Class
|
||||
{
|
||||
public:
|
||||
int begin(TwoWire &port = Wire, uint8_t addr = AXP202_SLAVE_ADDRESS, bool isAxp173 = false);
|
||||
int begin(axp_com_fptr_t read_cb, axp_com_fptr_t write_cb, uint8_t addr = AXP202_SLAVE_ADDRESS, bool isAxp173 = false);
|
||||
|
||||
// Power Output Control
|
||||
int setPowerOutPut(uint8_t ch, bool en);
|
||||
|
||||
bool isBatteryConnect();
|
||||
bool isChargeing();
|
||||
bool isLDO2Enable();
|
||||
bool isLDO3Enable();
|
||||
bool isLDO4Enable();
|
||||
bool isDCDC3Enable();
|
||||
bool isDCDC2Enable();
|
||||
bool isChargeingEnable();
|
||||
bool isVBUSPlug();
|
||||
bool isExtenEnable();
|
||||
|
||||
//Only axp192 chip
|
||||
bool isDCDC1Enable();
|
||||
|
||||
|
||||
//IRQ Status
|
||||
bool isAcinOverVoltageIRQ();
|
||||
bool isAcinPlugInIRQ();
|
||||
bool isAcinRemoveIRQ();
|
||||
bool isVbusOverVoltageIRQ();
|
||||
bool isVbusPlugInIRQ();
|
||||
bool isVbusRemoveIRQ();
|
||||
bool isVbusLowVHOLDIRQ();
|
||||
|
||||
bool isBattPlugInIRQ();
|
||||
bool isBattRemoveIRQ();
|
||||
bool isBattEnterActivateIRQ();
|
||||
bool isBattExitActivateIRQ();
|
||||
bool isChargingIRQ();
|
||||
bool isChargingDoneIRQ();
|
||||
bool isBattTempLowIRQ();
|
||||
bool isBattTempHighIRQ();
|
||||
|
||||
bool isPEKShortPressIRQ();
|
||||
bool isPEKLongtPressIRQ();
|
||||
bool isTimerTimeoutIRQ();
|
||||
|
||||
//! Group4 ADC data
|
||||
float getAcinVoltage();
|
||||
float getAcinCurrent();
|
||||
float getVbusVoltage();
|
||||
float getVbusCurrent();
|
||||
float getTemp();
|
||||
float getTSTemp();
|
||||
float getGPIO0Voltage();
|
||||
float getGPIO1Voltage();
|
||||
float getBattInpower();
|
||||
float getBattVoltage();
|
||||
float getBattChargeCurrent();
|
||||
float getBattDischargeCurrent();
|
||||
float getSysIPSOUTVoltage();
|
||||
uint32_t getBattChargeCoulomb();
|
||||
uint32_t getBattDischargeCoulomb();
|
||||
float getSettingChargeCurrent();
|
||||
|
||||
int setChargingTargetVoltage(axp_chargeing_vol_t param);
|
||||
int enableChargeing(bool en);
|
||||
|
||||
int adc1Enable(uint16_t params, bool en);
|
||||
int adc2Enable(uint16_t params, bool en);
|
||||
|
||||
int setTScurrent(axp_ts_pin_current_t current);
|
||||
int setTSfunction(axp_ts_pin_function_t func);
|
||||
int setTSmode(axp_ts_pin_mode_t mode);
|
||||
|
||||
|
||||
int setTimer(uint8_t minutes);
|
||||
int offTimer();
|
||||
int clearTimerStatus();
|
||||
/**
|
||||
* param: axp202_startup_time_t or axp192_startup_time_t
|
||||
*/
|
||||
int setStartupTime(uint8_t param);
|
||||
|
||||
/**
|
||||
* param: axp_loonPress_time_t
|
||||
*/
|
||||
int setlongPressTime(uint8_t param);
|
||||
|
||||
/**
|
||||
* @param param: axp_poweroff_time_t
|
||||
*/
|
||||
int setShutdownTime(uint8_t param);
|
||||
|
||||
int setTimeOutShutdown(bool en);
|
||||
|
||||
int shutdown();
|
||||
|
||||
/**
|
||||
* params: axp_irq_t
|
||||
*/
|
||||
int enableIRQ(uint64_t params, bool en);
|
||||
int readIRQ();
|
||||
void clearIRQ();
|
||||
|
||||
int setDCDC1Voltage(uint16_t mv); //! Only AXP192 support and AXP173
|
||||
// return mv
|
||||
uint16_t getDCDC1Voltage(); //! Only AXP192 support and AXP173
|
||||
|
||||
// -----------------
|
||||
|
||||
/*
|
||||
!! Chip resource table
|
||||
| CHIP | AXP173 | AXP192 | AXP202 |
|
||||
| -------- | ---------------- | ---------------- | ---------------- |
|
||||
| DC1 | 0v7~3v5 /1200mA | 0v7~3v5 /1200mA | X |
|
||||
| DC2 | 0v7~2v275/1600mA | 0v7~2v275/1600mA | 0v7~2v275/1600mA |
|
||||
| DC3 | X | 0v7~3v5 /700mA | 0v7~3v5 /1200mA |
|
||||
| LDO1 | 3v3 /30mA | 3v3 /30mA | 3v3 /30mA |
|
||||
| LDO2 | 1v8~3v3 /200mA | 1v8~3v3 /200mA | 1v8~3v3 /200mA |
|
||||
| LDO3 | 1v8~3v3 /200mA | 1v8~3v3 /200mA | 0v7~3v3 /200mA |
|
||||
| LDO4 | 0v7~3v5 /500mA | X | 1v8~3v3 /200mA |
|
||||
| LDO5/IO0 | X | 1v8~3v3 /50mA | 1v8~3v3 /50mA |
|
||||
*/
|
||||
int setDCDC2Voltage(uint16_t mv);
|
||||
uint16_t getDCDC2Voltage();
|
||||
|
||||
int setDCDC3Voltage(uint16_t mv);
|
||||
uint16_t getDCDC3Voltage();
|
||||
|
||||
int setLDO2Voltage(uint16_t mv);
|
||||
uint16_t getLDO2Voltage();
|
||||
|
||||
int setLDO3Voltage(uint16_t mv);
|
||||
uint16_t getLDO3Voltage();
|
||||
|
||||
|
||||
int setLDO4Voltage(axp_ldo4_table_t param); //! Only axp202 support
|
||||
int setLDO4Voltage(uint16_t mv); //! Only axp173 support
|
||||
|
||||
// return mv
|
||||
uint16_t getLDO4Voltage(); //! Only axp173/axp202 support
|
||||
|
||||
|
||||
/**
|
||||
* @param mode: axp_chgled_mode_t
|
||||
*/
|
||||
int setChgLEDMode(axp_chgled_mode_t mode);
|
||||
|
||||
/**
|
||||
* @param mode: axp202_ldo3_mode_t
|
||||
*/
|
||||
int setLDO3Mode(uint8_t mode); //! Only AXP202 support
|
||||
|
||||
int getBattPercentage();
|
||||
|
||||
int debugCharging();
|
||||
int debugStatus();
|
||||
int limitingOff();
|
||||
|
||||
int setAdcSamplingRate(axp_adc_sampling_rate_t rate);
|
||||
uint8_t getAdcSamplingRate();
|
||||
float getCoulombData();
|
||||
uint8_t getCoulombRegister();
|
||||
int setCoulombRegister(uint8_t val);
|
||||
int EnableCoulombcounter(void);
|
||||
int DisableCoulombcounter(void);
|
||||
int StopCoulombcounter(void);
|
||||
int ClearCoulombcounter(void);
|
||||
|
||||
|
||||
int setGPIOMode(axp_gpio_t gpio, axp_gpio_mode_t mode);
|
||||
int setGPIOIrq(axp_gpio_t gpio, axp_gpio_irq_t irq);
|
||||
int setLDO5Voltage(axp_ldo5_table_t vol);
|
||||
|
||||
int gpioWrite(axp_gpio_t gpio, uint8_t vol);
|
||||
int gpioRead(axp_gpio_t gpio);
|
||||
|
||||
// When the chip is axp192 / 173, the allowed values are 0 ~ 15, corresponding to the axp1xx_charge_current_t enumeration
|
||||
// When the chip is axp202 allows maximum charging current of 1800mA, minimum 300mA
|
||||
int getChargeControlCur();
|
||||
int setChargeControlCur(uint16_t mA);
|
||||
|
||||
private:
|
||||
uint16_t _getRegistH8L5(uint8_t regh8, uint8_t regl5)
|
||||
{
|
||||
uint8_t hv, lv;
|
||||
_readByte(regh8, 1, &hv);
|
||||
_readByte(regl5, 1, &lv);
|
||||
return (hv << 5) | (lv & 0x1F);
|
||||
}
|
||||
|
||||
uint16_t _getRegistResult(uint8_t regh8, uint8_t regl4)
|
||||
{
|
||||
uint8_t hv, lv;
|
||||
_readByte(regh8, 1, &hv);
|
||||
_readByte(regl4, 1, &lv);
|
||||
return (hv << 4) | (lv & 0x0F);
|
||||
}
|
||||
|
||||
int _readByte(uint8_t reg, uint8_t nbytes, uint8_t *data)
|
||||
{
|
||||
if (_read_cb != nullptr) {
|
||||
return _read_cb(_address, reg, data, nbytes);
|
||||
}
|
||||
if (nbytes == 0 || !data)
|
||||
return -1;
|
||||
_i2cPort->beginTransmission(_address);
|
||||
_i2cPort->write(reg);
|
||||
_i2cPort->endTransmission();
|
||||
_i2cPort->requestFrom(_address, nbytes);
|
||||
uint8_t index = 0;
|
||||
while (_i2cPort->available())
|
||||
data[index++] = _i2cPort->read();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _writeByte(uint8_t reg, uint8_t nbytes, uint8_t *data)
|
||||
{
|
||||
if (_write_cb != nullptr) {
|
||||
return _write_cb(_address, reg, data, nbytes);
|
||||
}
|
||||
if (nbytes == 0 || !data)
|
||||
return -1;
|
||||
_i2cPort->beginTransmission(_address);
|
||||
_i2cPort->write(reg);
|
||||
for (uint8_t i = 0; i < nbytes; i++) {
|
||||
_i2cPort->write(data[i]);
|
||||
}
|
||||
_i2cPort->endTransmission();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _setGpioInterrupt(uint8_t *val, int mode, bool en);
|
||||
int _axp_probe();
|
||||
int _axp_irq_mask(axp_gpio_irq_t irq);
|
||||
|
||||
int _axp192_gpio_set(axp_gpio_t gpio, axp_gpio_mode_t mode);
|
||||
int _axp192_gpio_0_select( axp_gpio_mode_t mode);
|
||||
int _axp192_gpio_1_select( axp_gpio_mode_t mode);
|
||||
int _axp192_gpio_3_select( axp_gpio_mode_t mode);
|
||||
int _axp192_gpio_4_select( axp_gpio_mode_t mode);
|
||||
|
||||
int _axp202_gpio_set(axp_gpio_t gpio, axp_gpio_mode_t mode);
|
||||
int _axp202_gpio_0_select( axp_gpio_mode_t mode);
|
||||
int _axp202_gpio_1_select( axp_gpio_mode_t mode);
|
||||
int _axp202_gpio_2_select( axp_gpio_mode_t mode);
|
||||
int _axp202_gpio_3_select( axp_gpio_mode_t mode);
|
||||
int _axp202_gpio_irq_set(axp_gpio_t gpio, axp_gpio_irq_t irq);
|
||||
int _axp202_gpio_write(axp_gpio_t gpio, uint8_t val);
|
||||
int _axp202_gpio_read(axp_gpio_t gpio);
|
||||
|
||||
|
||||
static const uint8_t startupParams[], longPressParams[], shutdownParams[], targetVolParams[];
|
||||
static uint8_t _outputReg;
|
||||
uint8_t _address, _irq[5], _chip_id, _gpio[4];
|
||||
bool _init = false;
|
||||
axp_com_fptr_t _read_cb = nullptr;
|
||||
axp_com_fptr_t _write_cb = nullptr;
|
||||
TwoWire *_i2cPort;
|
||||
bool _isAxp173;
|
||||
};
|
|
@ -0,0 +1,279 @@
|
|||
#include "bma.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
I2CBus *BMA::_bus = nullptr;
|
||||
|
||||
BMA::BMA(I2CBus &bus)
|
||||
{
|
||||
_bus = &bus;
|
||||
}
|
||||
|
||||
BMA::~BMA()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint16_t BMA::read(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len)
|
||||
{
|
||||
return _bus->readBytes(addr, reg, data, len);
|
||||
}
|
||||
|
||||
uint16_t BMA::write(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len)
|
||||
{
|
||||
return _bus->writeBytes(addr, reg, data, len);
|
||||
}
|
||||
|
||||
bool BMA::begin()
|
||||
{
|
||||
_dev.dev_addr = BMA4_I2C_ADDR_SECONDARY;
|
||||
_dev.interface = BMA4_I2C_INTERFACE;
|
||||
_dev.bus_read = read;
|
||||
_dev.bus_write = write;
|
||||
_dev.delay = delay;
|
||||
_dev.read_write_len = 8;
|
||||
_dev.resolution = 12;
|
||||
_dev.feature_len = BMA423_FEATURE_SIZE;
|
||||
|
||||
reset();
|
||||
|
||||
delay(20);
|
||||
|
||||
if (bma423_init(&_dev) != BMA4_OK) {
|
||||
//Serial.println("bma4 init fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
config();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BMA::reset()
|
||||
{
|
||||
uint8_t reg = 0xB6;
|
||||
_bus->writeBytes(BMA4_I2C_ADDR_SECONDARY, 0x7E, ®, 1);
|
||||
}
|
||||
|
||||
uint16_t BMA::config()
|
||||
{
|
||||
return bma423_write_config_file(&_dev);
|
||||
}
|
||||
|
||||
bool BMA::getAccel(Accel &acc)
|
||||
{
|
||||
memset(&acc, 0, sizeof(acc));
|
||||
if (bma4_read_accel_xyz(&acc, &_dev) != BMA4_OK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t BMA::direction()
|
||||
{
|
||||
Accel acc;
|
||||
if (bma4_read_accel_xyz(&acc, &_dev) != BMA4_OK) {
|
||||
return 0;
|
||||
}
|
||||
uint16_t absX = abs(acc.x);
|
||||
uint16_t absY = abs(acc.y);
|
||||
uint16_t absZ = abs(acc.z);
|
||||
|
||||
if ((absZ > absX) && (absZ > absY)) {
|
||||
if (acc.z > 0) {
|
||||
return DIRECTION_DISP_DOWN;
|
||||
} else {
|
||||
return DIRECTION_DISP_UP;
|
||||
}
|
||||
} else if ((absY > absX) && (absY > absZ)) {
|
||||
if (acc.y > 0) {
|
||||
return DIRECTION_BOTTOM_EDGE;
|
||||
} else {
|
||||
return DIRECTION_TOP_EDGE;
|
||||
}
|
||||
} else {
|
||||
if (acc.x < 0) {
|
||||
return DIRECTION_RIGHT_EDGE;
|
||||
} else {
|
||||
return DIRECTION_LEFT_EDGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float BMA::temperature()
|
||||
{
|
||||
int32_t data = 0;
|
||||
bma4_get_temperature(&data, BMA4_DEG, &_dev);
|
||||
float res = (float)data / (float)BMA4_SCALE_TEMP;
|
||||
/* 0x80 - temp read from the register and 23 is the ambient temp added.
|
||||
* If the temp read from register is 0x80, it means no valid
|
||||
* information is available */
|
||||
if (((data - 23) / BMA4_SCALE_TEMP) == 0x80) {
|
||||
res = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void BMA::enableAccel()
|
||||
{
|
||||
if (bma4_set_accel_enable(BMA4_ENABLE, &_dev)) {
|
||||
return;
|
||||
}
|
||||
Acfg cfg;
|
||||
cfg.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
|
||||
cfg.range = BMA4_ACCEL_RANGE_2G;
|
||||
cfg.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
|
||||
cfg.perf_mode = BMA4_CONTINUOUS_MODE;
|
||||
|
||||
if (bma4_set_accel_config(&cfg, &_dev)) {
|
||||
Serial.println("[bma4] set accel config fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void BMA::disalbeIrq()
|
||||
{
|
||||
bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_STEP_CNTR_INT /* |BMA423_WAKEUP_INT*/, BMA4_DISABLE, &_dev);
|
||||
}
|
||||
|
||||
void BMA::enableIrq()
|
||||
{
|
||||
bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_STEP_CNTR_INT /* |BMA423_WAKEUP_INT*/, BMA4_ENABLE, &_dev);
|
||||
}
|
||||
|
||||
//attachInterrupt bma423 int1
|
||||
void BMA::attachInterrupt()
|
||||
{
|
||||
uint16_t rslt = BMA4_OK;
|
||||
enableAccel();
|
||||
// rslt |= bma423_reset_step_counter(&_dev);
|
||||
rslt |= bma423_step_detector_enable(BMA4_ENABLE, &_dev);
|
||||
rslt |= bma423_feature_enable(BMA423_STEP_CNTR, BMA4_ENABLE, &_dev);
|
||||
rslt |= bma423_feature_enable(BMA423_WAKEUP, BMA4_ENABLE, &_dev);
|
||||
rslt |= bma423_feature_enable(BMA423_TILT, BMA4_ENABLE, &_dev);
|
||||
rslt |= bma423_step_counter_set_watermark(100, &_dev);
|
||||
|
||||
// rslt |= bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_STEP_CNTR_INT | BMA423_WAKEUP_INT, BMA4_ENABLE, &_dev);
|
||||
|
||||
rslt |= bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_STEP_CNTR_INT, BMA4_ENABLE, &_dev);
|
||||
rslt |= bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_TILT_INT, BMA4_ENABLE, &_dev);
|
||||
|
||||
bma423_anymotion_enable_axis(BMA423_ALL_AXIS_DIS, &_dev);
|
||||
|
||||
struct bma4_int_pin_config config ;
|
||||
|
||||
config.edge_ctrl = BMA4_LEVEL_TRIGGER;
|
||||
config.lvl = BMA4_ACTIVE_HIGH;
|
||||
config.od = BMA4_PUSH_PULL;
|
||||
config.output_en = BMA4_OUTPUT_ENABLE;
|
||||
config.input_en = BMA4_INPUT_DISABLE;
|
||||
rslt |= bma4_set_int_pin_config(&config, BMA4_INTR1_MAP, &_dev);
|
||||
|
||||
// Serial.printf("[bma4] attachInterrupt %s\n", rslt != 0 ? "fail" : "pass");
|
||||
|
||||
|
||||
struct bma423_axes_remap remap_data;
|
||||
|
||||
remap_data.x_axis = 0;
|
||||
remap_data.x_axis_sign = 1;
|
||||
remap_data.y_axis = 1;
|
||||
remap_data.y_axis_sign = 1;
|
||||
remap_data.z_axis = 2;
|
||||
remap_data.z_axis_sign = 0;
|
||||
|
||||
bma423_set_remap_axes(&remap_data, &_dev);
|
||||
|
||||
}
|
||||
|
||||
bool BMA::set_remap_axes(struct bma423_axes_remap *remap_data)
|
||||
{
|
||||
bma423_set_remap_axes(remap_data, &_dev);
|
||||
}
|
||||
|
||||
bool BMA::readInterrupt()
|
||||
{
|
||||
return bma423_read_int_status(&_irqStatus, &_dev) == BMA4_OK;
|
||||
}
|
||||
|
||||
uint8_t BMA::getIrqStatus()
|
||||
{
|
||||
return _irqStatus;
|
||||
}
|
||||
|
||||
uint32_t BMA::getCounter()
|
||||
{
|
||||
uint32_t stepCount;
|
||||
if (bma423_step_counter_output(&stepCount, &_dev) == BMA4_OK) {
|
||||
return stepCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool BMA::isStepCounter()
|
||||
{
|
||||
return (bool)(BMA423_STEP_CNTR_INT & _irqStatus);
|
||||
}
|
||||
|
||||
bool BMA::isDoubleClick()
|
||||
{
|
||||
return (bool)(BMA423_WAKEUP_INT & _irqStatus);
|
||||
}
|
||||
|
||||
|
||||
bool BMA::isTilt()
|
||||
{
|
||||
return (bool)(BMA423_TILT_INT & _irqStatus);
|
||||
}
|
||||
|
||||
|
||||
bool BMA::isActivity()
|
||||
{
|
||||
return (bool)(BMA423_ACTIVITY_INT & _irqStatus);
|
||||
}
|
||||
|
||||
bool BMA::isAnyNoMotion()
|
||||
{
|
||||
return (bool)(BMA423_ANY_NO_MOTION_INT & _irqStatus);
|
||||
}
|
||||
|
||||
|
||||
const char *BMA::getActivity()
|
||||
{
|
||||
uint8_t activity;
|
||||
bma423_activity_output(&activity, &_dev);
|
||||
if (activity & BMA423_USER_STATIONARY) {
|
||||
return "BMA423_USER_STATIONARY";
|
||||
} else if (activity & BMA423_USER_WALKING) {
|
||||
return "BMA423_USER_WALKING";
|
||||
} else if (activity & BMA423_USER_RUNNING) {
|
||||
return "BMA423_USER_RUNNING";
|
||||
} else if (activity & BMA423_STATE_INVALID) {
|
||||
return "BMA423_STATE_INVALID";
|
||||
}
|
||||
return "None";
|
||||
}
|
||||
|
||||
bool BMA::enableStepCountInterrupt(bool en)
|
||||
{
|
||||
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_STEP_CNTR_INT, en, &_dev));
|
||||
}
|
||||
|
||||
bool BMA::enableTiltInterrupt(bool en)
|
||||
{
|
||||
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_TILT_INT, en, &_dev));
|
||||
}
|
||||
|
||||
bool BMA::enableWakeupInterrupt(bool en)
|
||||
{
|
||||
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_WAKEUP_INT, en, &_dev));
|
||||
}
|
||||
|
||||
bool BMA::enableAnyNoMotionInterrupt(bool en)
|
||||
{
|
||||
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ANY_NO_MOTION_INT, en, &_dev));
|
||||
}
|
||||
|
||||
bool BMA::enableActivityInterrupt(bool en)
|
||||
{
|
||||
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ACTIVITY_INT, en, &_dev));
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "bma423.h"
|
||||
#include "i2c_bus.h"
|
||||
|
||||
|
||||
enum {
|
||||
DIRECTION_TOP_EDGE = 0,
|
||||
DIRECTION_BOTTOM_EDGE = 1,
|
||||
DIRECTION_LEFT_EDGE = 2,
|
||||
DIRECTION_RIGHT_EDGE = 3,
|
||||
DIRECTION_DISP_UP = 4,
|
||||
DIRECTION_DISP_DOWN = 5
|
||||
} ;
|
||||
typedef struct bma4_dev Bma;
|
||||
typedef struct bma4_accel Accel;
|
||||
typedef struct bma4_accel_config Acfg;
|
||||
|
||||
class BMA
|
||||
{
|
||||
public:
|
||||
BMA(I2CBus &bus);
|
||||
~BMA();
|
||||
bool begin();
|
||||
void reset();
|
||||
uint8_t direction();
|
||||
float temperature();
|
||||
void enableAccel();
|
||||
|
||||
void disalbeIrq();
|
||||
void enableIrq();
|
||||
void attachInterrupt();
|
||||
uint32_t getCounter();
|
||||
bool isStepCounter();
|
||||
bool isDoubleClick();
|
||||
bool readInterrupt();
|
||||
bool isTilt();
|
||||
bool isActivity();
|
||||
bool isAnyNoMotion();
|
||||
bool getAccel(Accel &acc);
|
||||
uint8_t getIrqStatus();
|
||||
const char * getActivity();
|
||||
|
||||
bool set_remap_axes(struct bma423_axes_remap *remap_data);
|
||||
bool enableStepCountInterrupt(bool en = true);
|
||||
bool enableTiltInterrupt(bool en = true);
|
||||
bool enableWakeupInterrupt(bool en = true);
|
||||
bool enableAnyNoMotionInterrupt(bool en = true);
|
||||
bool enableActivityInterrupt(bool en = true);
|
||||
|
||||
private:
|
||||
static uint16_t read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *read_data, uint16_t len);
|
||||
static uint16_t write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *read_data, uint16_t len);
|
||||
|
||||
uint16_t config();
|
||||
Bma _dev;
|
||||
static bma4_com_fptr_t _read;
|
||||
static bma4_com_fptr_t _write;
|
||||
static I2CBus *_bus;
|
||||
bool _irqRead = false;
|
||||
uint16_t _irqStatus;
|
||||
|
||||
};
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,804 @@
|
|||
/*
|
||||
*
|
||||
****************************************************************************
|
||||
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
|
||||
*
|
||||
* File : bma423.h
|
||||
*
|
||||
* Date: 12 Oct 2017
|
||||
*
|
||||
* Revision : 1.1.4 $
|
||||
*
|
||||
* Usage: Sensor Driver for BMA423 sensor
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* 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 bma423.h
|
||||
\brief Sensor Driver for BMA423 sensor */
|
||||
#ifndef BMA423_H
|
||||
#define BMA423_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "bma4.h"
|
||||
|
||||
/**\name Chip ID of BMA423 sensor */
|
||||
#define BMA423_CHIP_ID UINT8_C(0x13)
|
||||
|
||||
/**\name Sensor feature size */
|
||||
#define BMA423_FEATURE_SIZE UINT8_C(64)
|
||||
#define BMA423_ANYMOTION_EN_LEN UINT8_C(2)
|
||||
#define BMA423_RD_WR_MIN_LEN UINT8_C(2)
|
||||
|
||||
/**\name Feature offset address */
|
||||
#define BMA423_ANY_NO_MOTION_OFFSET UINT8_C(0x00)
|
||||
#define BMA423_STEP_CNTR_OFFSET UINT8_C(0x36)
|
||||
#define BMA423_STEP_CNTR_PARAM_OFFSET UINT8_C(0x04)
|
||||
#define BMA423_WAKEUP_OFFSET UINT8_C(0x38)
|
||||
#define BMA423_TILT_OFFSET UINT8_C(0x3A)
|
||||
#define BMA423_CONFIG_ID_OFFSET UINT8_C(0x3C)
|
||||
#define BMA423_AXES_REMAP_OFFSET UINT8_C(0x3E)
|
||||
|
||||
|
||||
/**************************************************************/
|
||||
/**\name Remap Axes */
|
||||
/**************************************************************/
|
||||
#define BMA423_X_AXIS_MASK UINT8_C(0x03)
|
||||
#define BMA423_X_AXIS_SIGN_MASK UINT8_C(0x04)
|
||||
#define BMA423_Y_AXIS_MASK UINT8_C(0x18)
|
||||
#define BMA423_Y_AXIS_SIGN_MASK UINT8_C(0x20)
|
||||
#define BMA423_Z_AXIS_MASK UINT8_C(0xC0)
|
||||
#define BMA423_Z_AXIS_SIGN_MASK UINT8_C(0x01)
|
||||
|
||||
/**************************************************************/
|
||||
/**\name Step Counter & Detector */
|
||||
/**************************************************************/
|
||||
/**\name Step counter enable macros */
|
||||
#define BMA423_STEP_CNTR_EN_POS UINT8_C(4)
|
||||
#define BMA423_STEP_CNTR_EN_MSK UINT8_C(0x10)
|
||||
#define BMA423_ACTIVITY_EN_MSK UINT8_C(0x20)
|
||||
|
||||
/**\name Step counter watermark macros */
|
||||
#define BMA423_STEP_CNTR_WM_MSK UINT16_C(0x03FF)
|
||||
|
||||
/**\name Step counter reset macros */
|
||||
#define BMA423_STEP_CNTR_RST_POS UINT8_C(2)
|
||||
#define BMA423_STEP_CNTR_RST_MSK UINT8_C(0x04)
|
||||
|
||||
/**\name Step detector enable macros */
|
||||
#define BMA423_STEP_DETECTOR_EN_POS UINT8_C(3)
|
||||
#define BMA423_STEP_DETECTOR_EN_MSK UINT8_C(0x08)
|
||||
|
||||
/**\name Tilt enable macros */
|
||||
#define BMA423_TILT_EN_MSK UINT8_C(0x01)
|
||||
|
||||
/**\name Step count output length*/
|
||||
#define BMA423_STEP_CNTR_DATA_SIZE UINT16_C(4)
|
||||
|
||||
/**\name Wakeup enable macros */
|
||||
#define BMA423_WAKEUP_EN_MSK UINT8_C(0x01)
|
||||
|
||||
/**\name Wake up sensitivity macros */
|
||||
#define BMA423_WAKEUP_SENS_POS UINT8_C(1)
|
||||
#define BMA423_WAKEUP_SENS_MSK UINT8_C(0x0E)
|
||||
|
||||
/**\name Tap selection macro */
|
||||
#define BMA423_TAP_SEL_POS UINT8_C(4)
|
||||
#define BMA423_TAP_SEL_MSK UINT8_C(0x10)
|
||||
|
||||
/**************************************************************/
|
||||
/**\name Any Motion */
|
||||
/**************************************************************/
|
||||
/**\name Any motion threshold macros */
|
||||
#define BMA423_ANY_NO_MOTION_THRES_POS UINT8_C(0)
|
||||
#define BMA423_ANY_NO_MOTION_THRES_MSK UINT16_C(0x07FF)
|
||||
|
||||
/**\name Any motion selection macros */
|
||||
#define BMA423_ANY_NO_MOTION_SEL_POS UINT8_C(3)
|
||||
#define BMA423_ANY_NO_MOTION_SEL_MSK UINT8_C(0x08)
|
||||
|
||||
/**\name Any motion enable macros */
|
||||
#define BMA423_ANY_NO_MOTION_AXIS_EN_POS UINT8_C(5)
|
||||
#define BMA423_ANY_NO_MOTION_AXIS_EN_MSK UINT8_C(0xE0)
|
||||
|
||||
/**\name Any motion duration macros */
|
||||
#define BMA423_ANY_NO_MOTION_DUR_MSK UINT16_C(0x1FFF)
|
||||
|
||||
/**************************************************************/
|
||||
/**\name User macros */
|
||||
/**************************************************************/
|
||||
|
||||
/**\name Anymotion/Nomotion axis enable macros */
|
||||
#define BMA423_X_AXIS_EN UINT8_C(0x01)
|
||||
#define BMA423_Y_AXIS_EN UINT8_C(0x02)
|
||||
#define BMA423_Z_AXIS_EN UINT8_C(0x04)
|
||||
#define BMA423_ALL_AXIS_EN UINT8_C(0x07)
|
||||
#define BMA423_ALL_AXIS_DIS UINT8_C(0x00)
|
||||
|
||||
/**\name Feature enable macros for the sensor */
|
||||
#define BMA423_STEP_CNTR UINT8_C(0x01)
|
||||
/**\name Below macros are mutually exclusive */
|
||||
#define BMA423_ANY_MOTION UINT8_C(0x02)
|
||||
#define BMA423_NO_MOTION UINT8_C(0x04)
|
||||
#define BMA423_ACTIVITY UINT8_C(0x08)
|
||||
#define BMA423_TILT UINT8_C(0x10)
|
||||
#define BMA423_WAKEUP UINT8_C(0x20)
|
||||
|
||||
/**\name Interrupt status macros */
|
||||
#define BMA423_STEP_CNTR_INT UINT8_C(0x02)
|
||||
#define BMA423_ACTIVITY_INT UINT8_C(0x04)
|
||||
#define BMA423_TILT_INT UINT8_C(0x08)
|
||||
#define BMA423_WAKEUP_INT UINT8_C(0x20)
|
||||
#define BMA423_ANY_NO_MOTION_INT UINT8_C(0x40)
|
||||
#define BMA423_ERROR_INT UINT8_C(0x80)
|
||||
|
||||
/**\name Activity recognition macros */
|
||||
#define BMA423_USER_STATIONARY UINT8_C(0x00)
|
||||
#define BMA423_USER_WALKING UINT8_C(0x01)
|
||||
#define BMA423_USER_RUNNING UINT8_C(0x02)
|
||||
#define BMA423_STATE_INVALID UINT8_C(0x03)
|
||||
|
||||
/**\name Configuration selection macros */
|
||||
#define BMA423_PHONE_CONFIG UINT8_C(0x00)
|
||||
#define BMA423_WRIST_CONFIG UINT8_C(0x01)
|
||||
|
||||
/**\name Step counter parameter setting(1-25) for phone */
|
||||
#define BMA423_PHONE_SC_PARAM_1 UINT16_C(0x132)
|
||||
#define BMA423_PHONE_SC_PARAM_2 UINT16_C(0x78E6)
|
||||
#define BMA423_PHONE_SC_PARAM_3 UINT16_C(0x84)
|
||||
#define BMA423_PHONE_SC_PARAM_4 UINT16_C(0x6C9C)
|
||||
#define BMA423_PHONE_SC_PARAM_5 UINT8_C(0x07)
|
||||
#define BMA423_PHONE_SC_PARAM_6 UINT16_C(0x7564)
|
||||
#define BMA423_PHONE_SC_PARAM_7 UINT16_C(0x7EAA)
|
||||
#define BMA423_PHONE_SC_PARAM_8 UINT16_C(0x55F)
|
||||
#define BMA423_PHONE_SC_PARAM_9 UINT16_C(0xABE)
|
||||
#define BMA423_PHONE_SC_PARAM_10 UINT16_C(0x55F)
|
||||
#define BMA423_PHONE_SC_PARAM_11 UINT16_C(0xE896)
|
||||
#define BMA423_PHONE_SC_PARAM_12 UINT16_C(0x41EF)
|
||||
#define BMA423_PHONE_SC_PARAM_13 UINT8_C(0x01)
|
||||
#define BMA423_PHONE_SC_PARAM_14 UINT8_C(0x0C)
|
||||
#define BMA423_PHONE_SC_PARAM_15 UINT8_C(0x0C)
|
||||
#define BMA423_PHONE_SC_PARAM_16 UINT8_C(0x4A)
|
||||
#define BMA423_PHONE_SC_PARAM_17 UINT8_C(0xA0)
|
||||
#define BMA423_PHONE_SC_PARAM_18 UINT8_C(0x00)
|
||||
#define BMA423_PHONE_SC_PARAM_19 UINT8_C(0x0C)
|
||||
#define BMA423_PHONE_SC_PARAM_20 UINT16_C(0x3CF0)
|
||||
#define BMA423_PHONE_SC_PARAM_21 UINT16_C(0x100)
|
||||
#define BMA423_PHONE_SC_PARAM_22 UINT8_C(0x00)
|
||||
#define BMA423_PHONE_SC_PARAM_23 UINT8_C(0x00)
|
||||
#define BMA423_PHONE_SC_PARAM_24 UINT8_C(0x00)
|
||||
#define BMA423_PHONE_SC_PARAM_25 UINT8_C(0x00)
|
||||
|
||||
/**\name Step counter parameter setting(1-25) for wrist (Default) */
|
||||
#define BMA423_WRIST_SC_PARAM_1 UINT16_C(0x12D)
|
||||
#define BMA423_WRIST_SC_PARAM_2 UINT16_C(0x7BD4)
|
||||
#define BMA423_WRIST_SC_PARAM_3 UINT16_C(0x13B)
|
||||
#define BMA423_WRIST_SC_PARAM_4 UINT16_C(0x7ADB)
|
||||
#define BMA423_WRIST_SC_PARAM_5 UINT8_C(0x04)
|
||||
#define BMA423_WRIST_SC_PARAM_6 UINT16_C(0x7B3F)
|
||||
#define BMA423_WRIST_SC_PARAM_7 UINT16_C(0x6CCD)
|
||||
#define BMA423_WRIST_SC_PARAM_8 UINT16_C(0x4C3)
|
||||
#define BMA423_WRIST_SC_PARAM_9 UINT16_C(0x985)
|
||||
#define BMA423_WRIST_SC_PARAM_10 UINT16_C(0x4C3)
|
||||
#define BMA423_WRIST_SC_PARAM_11 UINT16_C(0xE6EC)
|
||||
#define BMA423_WRIST_SC_PARAM_12 UINT16_C(0x460C)
|
||||
#define BMA423_WRIST_SC_PARAM_13 UINT8_C(0x01)
|
||||
#define BMA423_WRIST_SC_PARAM_14 UINT8_C(0x27)
|
||||
#define BMA423_WRIST_SC_PARAM_15 UINT8_C(0x19)
|
||||
#define BMA423_WRIST_SC_PARAM_16 UINT8_C(0x96)
|
||||
#define BMA423_WRIST_SC_PARAM_17 UINT8_C(0xA0)
|
||||
#define BMA423_WRIST_SC_PARAM_18 UINT8_C(0x01)
|
||||
#define BMA423_WRIST_SC_PARAM_19 UINT8_C(0x0C)
|
||||
#define BMA423_WRIST_SC_PARAM_20 UINT16_C(0x3CF0)
|
||||
#define BMA423_WRIST_SC_PARAM_21 UINT16_C(0x100)
|
||||
#define BMA423_WRIST_SC_PARAM_22 UINT8_C(0x01)
|
||||
#define BMA423_WRIST_SC_PARAM_23 UINT8_C(0x03)
|
||||
#define BMA423_WRIST_SC_PARAM_24 UINT8_C(0x01)
|
||||
#define BMA423_WRIST_SC_PARAM_25 UINT8_C(0x0E)
|
||||
|
||||
/*!
|
||||
* @brief Any motion configuration
|
||||
*/
|
||||
struct bma423_anymotion_config {
|
||||
/*! Expressed in 50 Hz samples (20 ms) */
|
||||
uint16_t duration;
|
||||
/*! Threshold value for Any-motion / No-motion detection in
|
||||
5.11g format */
|
||||
uint16_t threshold;
|
||||
/*! Indicates if No-motion or Any-motion is selected */
|
||||
uint8_t nomotion_sel;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Axes remapping configuration
|
||||
*/
|
||||
struct bma423_axes_remap {
|
||||
uint8_t x_axis;
|
||||
uint8_t x_axis_sign;
|
||||
uint8_t y_axis;
|
||||
uint8_t y_axis_sign;
|
||||
uint8_t z_axis;
|
||||
uint8_t z_axis_sign;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Step counter param settings
|
||||
*/
|
||||
struct bma423_stepcounter_settings {
|
||||
/*! Step Counter param 1 */
|
||||
uint16_t param1;
|
||||
/*! Step Counter param 2 */
|
||||
uint16_t param2;
|
||||
/*! Step Counter param 3 */
|
||||
uint16_t param3;
|
||||
/*! Step Counter param 4 */
|
||||
uint16_t param4;
|
||||
/*! Step Counter param 5 */
|
||||
uint16_t param5;
|
||||
/*! Step Counter param 6 */
|
||||
uint16_t param6;
|
||||
/*! Step Counter param 7 */
|
||||
uint16_t param7;
|
||||
/*! Step Counter param 8 */
|
||||
uint16_t param8;
|
||||
/*! Step Counter param 9 */
|
||||
uint16_t param9;
|
||||
/*! Step Counter param 10 */
|
||||
uint16_t param10;
|
||||
/*! Step Counter param 11 */
|
||||
uint16_t param11;
|
||||
/*! Step Counter param 12 */
|
||||
uint16_t param12;
|
||||
/*! Step Counter param 13 */
|
||||
uint16_t param13;
|
||||
/*! Step Counter param 14 */
|
||||
uint16_t param14;
|
||||
/*! Step Counter param 15 */
|
||||
uint16_t param15;
|
||||
/*! Step Counter param 16 */
|
||||
uint16_t param16;
|
||||
/*! Step Counter param 17 */
|
||||
uint16_t param17;
|
||||
/*! Step Counter param 18 */
|
||||
uint16_t param18;
|
||||
/*! Step Counter param 19 */
|
||||
uint16_t param19;
|
||||
/*! Step Counter param 20 */
|
||||
uint16_t param20;
|
||||
/*! Step Counter param 21 */
|
||||
uint16_t param21;
|
||||
/*! Step Counter param 22 */
|
||||
uint16_t param22;
|
||||
/*! Step Counter param 23 */
|
||||
uint16_t param23;
|
||||
/*! Step Counter param 24 */
|
||||
uint16_t param24;
|
||||
/*! Step Counter param 25 */
|
||||
uint16_t param25;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief This API is the entry point.
|
||||
* Call this API before using all other APIs.
|
||||
* This API reads the chip-id of the sensor and sets the resolution.
|
||||
*
|
||||
* @param[in,out] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_init(struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API is used to upload the config file to enable
|
||||
* the features of the sensor.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bma4_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_write_config_file(struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API is used to get the configuration id of the sensor.
|
||||
*
|
||||
* @param[out] config_id : Pointer variable used to store
|
||||
* the configuration id.
|
||||
* @param[in] dev : Structure instance of bma4_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev);
|
||||
|
||||
|
||||
/*!
|
||||
* @brief This API sets/unsets the user provided interrupt to either
|
||||
* interrupt pin1 or pin2 in the sensor.
|
||||
*
|
||||
* @param[in] int_line: Variable to select either interrupt pin1 or pin2.
|
||||
* int_line | Macros
|
||||
* ------------|-------------------
|
||||
* 0 | BMA4_INTR1_MAP
|
||||
* 1 | BMA4_INTR2_MAP
|
||||
* @param[in] int_map : Variable to specify the interrupts.
|
||||
* @param[in] enable : Variable to specify mapping or unmapping of
|
||||
* interrupts.
|
||||
* enable | Macros
|
||||
* --------------------|-------------------
|
||||
* 0x00 | BMA4_DISABLE
|
||||
* 0x01 | BMA4_ENABLE
|
||||
* @param[in] dev : Structure instance of bma4_dev.
|
||||
*
|
||||
* @note Below macros specify the interrupts.
|
||||
* Feature Interrupts
|
||||
* - BMA423_STEP_CNTR_INT
|
||||
* - BMA423_ACTIVITY_INT
|
||||
* - BMA423_TILT_INT
|
||||
* - BMA423_WAKEUP_INT
|
||||
* - BMA423_ANY_NO_MOTION_INT
|
||||
* - BMA423_ERROR_INT
|
||||
*
|
||||
* Hardware Interrupts
|
||||
* - BMA4_FIFO_FULL_INT
|
||||
* - BMA4_FIFO_WM_INT
|
||||
* - BMA4_DATA_RDY_INT
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_map_interrupt(uint8_t int_line, uint16_t int_map, uint8_t enable, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API reads the bma423 interrupt status from the sensor.
|
||||
*
|
||||
* @param[out] int_status : Variable to store the interrupt status
|
||||
* read from the sensor.
|
||||
* @param[in] dev : Structure instance of bma4_dev.
|
||||
*
|
||||
* @note Below macros are used to check the interrupt status.
|
||||
* Feature Interrupts
|
||||
*
|
||||
* - BMA423_STEP_CNTR_INT
|
||||
* - BMA423_ACTIVITY_INT
|
||||
* - BMA423_TILT_INT
|
||||
* - BMA423_WAKEUP_INT
|
||||
* - BMA423_ANY_NO_MOTION_INT
|
||||
* - BMA423_ERROR_INT
|
||||
*
|
||||
*
|
||||
* Hardware Interrupts
|
||||
* - BMA4_FIFO_FULL_INT
|
||||
* - BMA4_FIFO_WM_INT
|
||||
* - BMA4_MAG_DATA_RDY_INT
|
||||
* - BMA4_ACCEL_DATA_RDY_INT
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_read_int_status(uint16_t *int_status, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API enables/disables the features of the sensor.
|
||||
*
|
||||
* @param[in] feature : Variable to specify the features
|
||||
* which are to be set in bma423 sensor.
|
||||
* @param[in] enable : Variable which specifies whether to enable or
|
||||
* disable the features in the bma423 sensor
|
||||
* enable | Macros
|
||||
* --------------------|-------------------
|
||||
* 0x00 | BMA4_DISABLE
|
||||
* 0x01 | BMA4_ENABLE
|
||||
* @param[in] dev : Structure instance of bma4_dev.
|
||||
*
|
||||
* @note User should use the below macros to enable or disable the
|
||||
* features of bma423 sensor
|
||||
* - BMA423_STEP_CNTR
|
||||
* - BMA423_ANY_MOTION (or) BMA423_NO_MOTION
|
||||
* - BMA423_ACTIVITY
|
||||
* - BMA423_WAKEUP
|
||||
* - BMA423_TILT
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_feature_enable(uint8_t feature, uint8_t enable, struct bma4_dev *dev);
|
||||
|
||||
|
||||
/*!
|
||||
* @brief This API performs x, y and z axis remapping in the sensor.
|
||||
*
|
||||
* @param[in] remap_data : Pointer to store axes remapping data.
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API reads the x, y and z axis remap data from the sensor.
|
||||
*
|
||||
* @param[out] remap_data : Pointer to store axis remap data which is read
|
||||
* from the bma423 sensor.
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_get_remap_axes(struct bma423_axes_remap *remap_data, struct bma4_dev *dev);
|
||||
|
||||
|
||||
/*!
|
||||
* @brief This API sets the watermark level for step counter
|
||||
* interrupt in the sensor.
|
||||
*
|
||||
* @param[in] step_counter_wm : Variable which specifies watermark level
|
||||
* count
|
||||
* @note Valid values are from 1 to 1023
|
||||
* @note Value 0 is used for step detector interrupt
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_step_counter_set_watermark(uint16_t step_counter_wm, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API gets the water mark level set for step counter interrupt
|
||||
* in the sensor
|
||||
*
|
||||
* @param[out] step_counter_wm : Pointer variable which stores
|
||||
* the water mark level read from the sensor.
|
||||
* @note valid values are from 1 to 1023
|
||||
* @note value 0 is used for step detector interrupt
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_step_counter_get_watermark(uint16_t *step_counter_wm, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API resets the counted steps of step counter.
|
||||
*
|
||||
* @param[in] dev : structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_reset_step_counter(struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API gets the number of counted steps of the step counter
|
||||
* feature from the sensor.
|
||||
*
|
||||
* @param[out] step_count : Pointer variable which stores counted steps
|
||||
* read from the sensor.
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_step_counter_output(uint32_t *step_count, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API gets the output for activity feature.
|
||||
*
|
||||
* @param[out] activity : Pointer variable which stores activity output
|
||||
* read from the sensor.
|
||||
* activity | State
|
||||
* --------------|------------------------
|
||||
* 0x00 | BMA423_USER_STATIONARY
|
||||
* 0x01 | BMA423_USER_WALKING
|
||||
* 0x02 | BMA423_USER_RUNNING
|
||||
* 0x03 | BMA423_STATE_INVALID
|
||||
*
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_activity_output(uint8_t *activity, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API select the platform configuration wrist(default) or phone.
|
||||
*
|
||||
* @param[in] platform : Variable to select wrist/phone
|
||||
*
|
||||
* platform | Macros
|
||||
* -------------|------------------------
|
||||
* 0x00 | BMA423_PHONE_CONFIG
|
||||
* 0x01 | BMA423_WRIST_CONFIG
|
||||
*
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_select_platform(uint8_t platform, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API gets the parameter1 to parameter7 settings of the
|
||||
* step counter feature.
|
||||
*
|
||||
* @param[out] setting : Pointer to structure variable which stores the
|
||||
* parameter1 to parameter7 read from the sensor.
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_stepcounter_get_parameter(struct bma423_stepcounter_settings *setting, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API sets the parameter1 to parameter7 settings of the
|
||||
* step counter feature in the sensor.
|
||||
*
|
||||
* @param[in] setting : Pointer to structure variable which stores the
|
||||
* parameter1 to parameter7 settings read from the sensor.
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_stepcounter_set_parameter(const struct bma423_stepcounter_settings *setting, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API enables or disables the step detector feature in the
|
||||
* sensor.
|
||||
*
|
||||
* @param[in] enable : Variable used to enable or disable step detector
|
||||
* enable | Macros
|
||||
* --------------------|-------------------
|
||||
* 0x00 | BMA4_DISABLE
|
||||
* 0x01 | BMA4_ENABLE
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_step_detector_enable(uint8_t enable, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API enables the any motion feature according to the axis
|
||||
* set by the user in the sensor.
|
||||
*
|
||||
* @param[in] axis : Variable to specify the axis of the any motion feature
|
||||
* to be enabled in the sensor.
|
||||
* Value | Axis
|
||||
* ---------|-------------------------
|
||||
* 0x00 | BMA423_ALL_AXIS_DIS
|
||||
* 0x01 | BMA423_X_AXIS_EN
|
||||
* 0x02 | BMA423_Y_AXIS_EN
|
||||
* 0x04 | BMA423_Z_AXIS_EN
|
||||
* 0x07 | BMA423_ALL_AXIS_EN
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_anymotion_enable_axis(uint8_t axis, struct bma4_dev *dev);
|
||||
|
||||
/*! @brief This API sets the configuration of Any motion feature in
|
||||
* the sensor.
|
||||
*
|
||||
* @param[in] any_motion : Pointer to structure variable to specify
|
||||
* the any motion feature settings.
|
||||
* Structure members are provided in the table below
|
||||
*@verbatim
|
||||
* -------------------------------------------------------------------------
|
||||
* Structure parameters | Description
|
||||
* --------------------------------|----------------------------------------
|
||||
* | Defines the number of
|
||||
* | consecutive data points for
|
||||
* | which the threshold condition
|
||||
* duration | must be respected, for interrupt
|
||||
* | assertion. It is expressed in
|
||||
* | 50 Hz samples (20 ms).
|
||||
* | Range is 0 to 163sec.
|
||||
* | Default value is 5 = 100ms.
|
||||
* --------------------------------|----------------------------------------
|
||||
* | Slope threshold value for
|
||||
* | Any-motion / No-motion detection
|
||||
* threshold | in 5.11g format.
|
||||
* | Range is 0 to 1g.
|
||||
* | Default value is 0xAA = 83mg.
|
||||
* --------------------------------|----------------------------------------
|
||||
* | Indicates if No motion (1) or
|
||||
* nomotion_sel | Any-motion (0) is selected;
|
||||
* | default value is 0 Any-motion.
|
||||
* -------------------------------------------------------------------------
|
||||
*@endverbatim
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_set_any_motion_config(const struct bma423_anymotion_config *any_motion, struct bma4_dev *dev);
|
||||
|
||||
/*! @brief This API gets the configuration of any motion feature from
|
||||
* the sensor.
|
||||
*
|
||||
* @param[out] any_motion : Pointer to structure variable used to store
|
||||
* the any motion feature settings read from the sensor.
|
||||
* Structure members are provided in the table below
|
||||
*@verbatim
|
||||
* -------------------------------------------------------------------------
|
||||
* Structure parameters | Description
|
||||
* --------------------------------|----------------------------------------
|
||||
* | Defines the number of
|
||||
* | consecutive data points for
|
||||
* | which the threshold condition
|
||||
* duration | must be respected, for interrupt
|
||||
* | assertion. It is expressed in
|
||||
* | 50 Hz samples (20 ms).
|
||||
* | Range is 0 to 163sec.
|
||||
* | Default value is 5 = 100ms.
|
||||
* --------------------------------|----------------------------------------
|
||||
* | Slope threshold value for
|
||||
* | Any-motion / No-motion detection
|
||||
* threshold | in 5.11g format.
|
||||
* | Range is 0 to 1g.
|
||||
* | Default value is 0xAA = 83mg.
|
||||
* --------------------------------|----------------------------------------
|
||||
* | Indicates if No motion (1) or
|
||||
* nomotion_sel | Any-motion (0) is selected;
|
||||
* | default value is 0 Any-motion.
|
||||
* -------------------------------------------------------------------------
|
||||
*@endverbatim
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API sets the sensitivity of wake up feature in the sensor
|
||||
*
|
||||
* @param[in] sensitivity : Variable used to specify the sensitivity of the
|
||||
* Wake up feature.
|
||||
* Value | Sensitivity
|
||||
* --------|-------------------------
|
||||
* 0x00 | MOST SENSITIVE
|
||||
* 0x07 | LEAST SENSITIVE
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_wakeup_set_sensitivity(uint8_t sensitivity, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API gets the sensitivity of wake up feature in the sensor
|
||||
*
|
||||
* @param[out] sensitivity : Pointer variable which stores the sensitivity
|
||||
* value read from the sensor.
|
||||
* Value | Sensitivity
|
||||
* --------|-------------------------
|
||||
* 0x00 | MOST SENSITIVE
|
||||
* 0x07 | LEAST SENSITIVE
|
||||
* @param[in] dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @retval 0 -> Success
|
||||
* @retval Any non zero value -> Fail
|
||||
*/
|
||||
uint16_t bma423_wakeup_get_sensitivity(uint8_t *sensitivity, struct bma4_dev *dev);
|
||||
|
||||
/*!
|
||||
* @brief This API is used to select single/double tap
|
||||
* feature in the sensor
|
||||
*
|
||||
* @param tap_select : Variable used to specify the single or
|
||||
* double tap selection in the sensor
|
||||
* tap_select | description
|
||||
* ------------|------------------------
|
||||
* 0x00 | Double tap selected
|
||||
* 0x01 | single tap selected
|
||||
*
|
||||
* @param dev : Structure instance of bma4_dev
|
||||
*
|
||||
* @return results of stream_transfer operation
|
||||
* @retval 0 -> Success
|
||||
* @retval Any positive value mentioned in ERROR CODES -> Fail
|
||||
*
|
||||
*/
|
||||
uint16_t bma423_tap_selection(const uint8_t tap_select, struct bma4_dev *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*End of CPP guard */
|
||||
|
||||
#endif /*End of header guard macro */
|
|
@ -0,0 +1,960 @@
|
|||
/*
|
||||
*
|
||||
****************************************************************************
|
||||
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
|
||||
*
|
||||
* File : bma4_defs.h
|
||||
*
|
||||
* Date: 12 Oct 2017
|
||||
*
|
||||
* Revision: 2.1.9 $
|
||||
*
|
||||
* Usage: Sensor Driver for BMA4 family of sensors
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* 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 bma4_defs.h
|
||||
\brief Sensor Driver for BMA4 family of sensors */
|
||||
#ifndef BMA4_DEFS_H__
|
||||
#define BMA4_DEFS_H__
|
||||
/*********************************************************************/
|
||||
/**\ header files */
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
/*********************************************************************/
|
||||
/* macro definitions */
|
||||
|
||||
/*
|
||||
#if (LONG_MAX) > 0x7fffffff
|
||||
#define __have_long64 1
|
||||
#elif (LONG_MAX) == 0x7fffffff
|
||||
#define __have_long32 1
|
||||
#endif
|
||||
*/
|
||||
|
||||
#if !defined(UINT8_C)
|
||||
#define INT8_C(x) x
|
||||
#if (INT_MAX) > 0x7f
|
||||
#define UINT8_C(x) x
|
||||
#else
|
||||
#define UINT8_C(x) x##U
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(UINT16_C)
|
||||
#define INT16_C(x) x
|
||||
#if (INT_MAX) > 0x7fff
|
||||
#define UINT16_C(x) x
|
||||
#else
|
||||
#define UINT16_C(x) x##U
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(INT32_C) && !defined(UINT32_C)
|
||||
#if __have_long32
|
||||
#define INT32_C(x) x##L
|
||||
#define UINT32_C(x) x##UL
|
||||
#else
|
||||
#define INT32_C(x) x
|
||||
#define UINT32_C(x) x##U
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(INT64_C) && !defined(UINT64_C)
|
||||
#if __have_long64
|
||||
#define INT64_C(x) x##L
|
||||
#define UINT64_C(x) x##UL
|
||||
#else
|
||||
#define INT64_C(x) x##LL
|
||||
#define UINT64_C(x) x##ULL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**\name CHIP ID ADDRESS*/
|
||||
#define BMA4_CHIP_ID_ADDR UINT8_C(0x00)
|
||||
|
||||
/**\name ERROR STATUS*/
|
||||
#define BMA4_ERROR_ADDR UINT8_C(0X02)
|
||||
|
||||
/**\name STATUS REGISTER FOR SENSOR STATUS FLAG*/
|
||||
#define BMA4_STATUS_ADDR UINT8_C(0X03)
|
||||
|
||||
/**\name AUX/ACCEL DATA BASE ADDRESS REGISTERS*/
|
||||
#define BMA4_DATA_0_ADDR UINT8_C(0X0A)
|
||||
#define BMA4_DATA_8_ADDR UINT8_C(0X12)
|
||||
|
||||
/**\name SENSOR TIME REGISTERS*/
|
||||
#define BMA4_SENSORTIME_0_ADDR UINT8_C(0X18)
|
||||
|
||||
/**\name INTERRUPT/FEATURE STATUS REGISTERS*/
|
||||
#define BMA4_INT_STAT_0_ADDR UINT8_C(0X1C)
|
||||
|
||||
/**\name INTERRUPT/FEATURE STATUS REGISTERS*/
|
||||
#define BMA4_INT_STAT_1_ADDR UINT8_C(0X1D)
|
||||
|
||||
/**\name TEMPERATURE REGISTERS*/
|
||||
#define BMA4_TEMPERATURE_ADDR UINT8_C(0X22)
|
||||
|
||||
/**\name FIFO REGISTERS*/
|
||||
#define BMA4_FIFO_LENGTH_0_ADDR UINT8_C(0X24)
|
||||
#define BMA4_FIFO_DATA_ADDR UINT8_C(0X26)
|
||||
|
||||
/**\name ACCEL CONFIG REGISTERS*/
|
||||
#define BMA4_ACCEL_CONFIG_ADDR UINT8_C(0X40)
|
||||
|
||||
/**\name ACCEL RANGE ADDRESS*/
|
||||
#define BMA4_ACCEL_RANGE_ADDR UINT8_C(0X41)
|
||||
|
||||
/**\name AUX CONFIG REGISTERS*/
|
||||
#define BMA4_AUX_CONFIG_ADDR UINT8_C(0X44)
|
||||
|
||||
/**\name FIFO DOWN SAMPLING REGISTER ADDRESS FOR ACCEL*/
|
||||
#define BMA4_FIFO_DOWN_ADDR UINT8_C(0X45)
|
||||
|
||||
/**\name FIFO WATERMARK REGISTER ADDRESS*/
|
||||
#define BMA4_FIFO_WTM_0_ADDR UINT8_C(0X46)
|
||||
|
||||
/**\name FIFO CONFIG REGISTERS*/
|
||||
#define BMA4_FIFO_CONFIG_0_ADDR UINT8_C(0X48)
|
||||
#define BMA4_FIFO_CONFIG_1_ADDR UINT8_C(0X49)
|
||||
|
||||
/**\name MAG INTERFACE REGISTERS*/
|
||||
#define BMA4_AUX_DEV_ID_ADDR UINT8_C(0X4B)
|
||||
#define BMA4_AUX_IF_CONF_ADDR UINT8_C(0X4C)
|
||||
#define BMA4_AUX_RD_ADDR UINT8_C(0X4D)
|
||||
#define BMA4_AUX_WR_ADDR UINT8_C(0X4E)
|
||||
#define BMA4_AUX_WR_DATA_ADDR UINT8_C(0X4F)
|
||||
|
||||
/**\name INTERRUPT ENABLE REGISTERS*/
|
||||
#define BMA4_INT1_IO_CTRL_ADDR UINT8_C(0X53)
|
||||
#define BMA4_INT2_IO_CTRL_ADDR UINT8_C(0X54)
|
||||
|
||||
/**\name LATCH DURATION REGISTERS*/
|
||||
#define BMA4_INTR_LATCH_ADDR UINT8_C(0X55)
|
||||
|
||||
/**\name MAP INTERRUPT 1 and 2 REGISTERS*/
|
||||
#define BMA4_INT_MAP_1_ADDR UINT8_C(0X56)
|
||||
#define BMA4_INT_MAP_2_ADDR UINT8_C(0X57)
|
||||
#define BMA4_INT_MAP_DATA_ADDR UINT8_C(0x58)
|
||||
#define BMA4_INIT_CTRL_ADDR UINT8_C(0x59)
|
||||
|
||||
/**\name FEATURE CONFIG RELATED */
|
||||
#define BMA4_RESERVED_REG_5B_ADDR UINT8_C(0x5B)
|
||||
#define BMA4_RESERVED_REG_5C_ADDR UINT8_C(0x5C)
|
||||
#define BMA4_FEATURE_CONFIG_ADDR UINT8_C(0x5E)
|
||||
#define BMA4_INTERNAL_ERROR UINT8_C(0x5F)
|
||||
|
||||
/**\name SERIAL INTERFACE SETTINGS REGISTER*/
|
||||
#define BMA4_IF_CONFIG_ADDR UINT8_C(0X6B)
|
||||
|
||||
/**\name SELF_TEST REGISTER*/
|
||||
#define BMA4_ACC_SELF_TEST_ADDR UINT8_C(0X6D)
|
||||
|
||||
/**\name SPI,I2C SELECTION REGISTER*/
|
||||
#define BMA4_NV_CONFIG_ADDR UINT8_C(0x70)
|
||||
|
||||
/**\name ACCEL OFFSET REGISTERS*/
|
||||
#define BMA4_OFFSET_0_ADDR UINT8_C(0X71)
|
||||
#define BMA4_OFFSET_1_ADDR UINT8_C(0X72)
|
||||
#define BMA4_OFFSET_2_ADDR UINT8_C(0X73)
|
||||
|
||||
/**\name POWER_CTRL REGISTER*/
|
||||
#define BMA4_POWER_CONF_ADDR UINT8_C(0x7C)
|
||||
#define BMA4_POWER_CTRL_ADDR UINT8_C(0x7D)
|
||||
|
||||
/**\name COMMAND REGISTER*/
|
||||
#define BMA4_CMD_ADDR UINT8_C(0X7E)
|
||||
|
||||
/**\name GPIO REGISTERS*/
|
||||
#define BMA4_STEP_CNT_OUT_0_ADDR UINT8_C(0x1E)
|
||||
#define BMA4_HIGH_G_OUT_ADDR UINT8_C(0x1F)
|
||||
#define BMA4_ACTIVITY_OUT_ADDR UINT8_C(0x27)
|
||||
#define BMA4_ORIENTATION_OUT_ADDR UINT8_C(0x28)
|
||||
#define BMA4_INTERNAL_STAT UINT8_C(0x2A)
|
||||
|
||||
/*!
|
||||
* @brief Block size for config write */
|
||||
#define BMA4_BLOCK_SIZE UINT8_C(32)
|
||||
|
||||
/**\name I2C slave address */
|
||||
#define BMA4_I2C_ADDR_PRIMARY UINT8_C(0x18)
|
||||
#define BMA4_I2C_ADDR_SECONDARY UINT8_C(0x19)
|
||||
#define BMA4_I2C_BMM150_ADDR UINT8_C(0x10)
|
||||
|
||||
/**\name Interface selection macro */
|
||||
#define BMA4_SPI_INTERFACE UINT8_C(1)
|
||||
#define BMA4_I2C_INTERFACE UINT8_C(2)
|
||||
|
||||
/**\name Interface selection macro */
|
||||
#define BMA4_SPI_WR_MASK UINT8_C(0x7F)
|
||||
#define BMA4_SPI_RD_MASK UINT8_C(0x80)
|
||||
|
||||
/**\name Chip ID macros */
|
||||
#define BMA4_CHIP_ID_MIN UINT8_C(0x10)
|
||||
#define BMA4_CHIP_ID_MAX UINT8_C(0x15)
|
||||
|
||||
/**\name Auxiliary sensor selection macro */
|
||||
#define BMM150_SENSOR UINT8_C(1)
|
||||
#define AKM9916_SENSOR UINT8_C(2)
|
||||
#define BMA4_ASIC_INITIALIZED UINT8_C(0x01)
|
||||
|
||||
/**\name Auxiliary sensor chip id macros */
|
||||
#define BMM150_CHIP_ID UINT8_C(0x32)
|
||||
|
||||
/**\name Auxiliary sensor other macros */
|
||||
#define BMM150_POWER_CONTROL_REG UINT8_C(0x4B)
|
||||
#define BMM150_POWER_MODE_REG UINT8_C(0x4C)
|
||||
|
||||
/**\name CONSTANTS */
|
||||
#define BMA4_FIFO_CONFIG_LENGTH UINT8_C(2)
|
||||
#define BMA4_ACCEL_CONFIG_LENGTH UINT8_C(2)
|
||||
#define BMA4_FIFO_WM_LENGTH UINT8_C(2)
|
||||
#define BMA4_CONFIG_STREAM_SIZE UINT16_C(6144)
|
||||
#define BMA4_NON_LATCH_MODE UINT8_C(0)
|
||||
#define BMA4_LATCH_MODE UINT8_C(1)
|
||||
#define BMA4_OPEN_DRAIN UINT8_C(1)
|
||||
#define BMA4_PUSH_PULL UINT8_C(0)
|
||||
#define BMA4_ACTIVE_HIGH UINT8_C(1)
|
||||
#define BMA4_ACTIVE_LOW UINT8_C(0)
|
||||
#define BMA4_EDGE_TRIGGER UINT8_C(1)
|
||||
#define BMA4_LEVEL_TRIGGER UINT8_C(0)
|
||||
#define BMA4_OUTPUT_ENABLE UINT8_C(1)
|
||||
#define BMA4_OUTPUT_DISABLE UINT8_C(0)
|
||||
#define BMA4_INPUT_ENABLE UINT8_C(1)
|
||||
#define BMA4_INPUT_DISABLE UINT8_C(0)
|
||||
|
||||
/**\name ACCEL RANGE CHECK*/
|
||||
#define BMA4_ACCEL_RANGE_2G UINT8_C(0)
|
||||
#define BMA4_ACCEL_RANGE_4G UINT8_C(1)
|
||||
#define BMA4_ACCEL_RANGE_8G UINT8_C(2)
|
||||
#define BMA4_ACCEL_RANGE_16G UINT8_C(3)
|
||||
|
||||
/**\name CONDITION CHECK FOR READING AND WRTING DATA*/
|
||||
#define BMA4_MAX_VALUE_FIFO_FILTER UINT8_C(1)
|
||||
#define BMA4_MAX_VALUE_SPI3 UINT8_C(1)
|
||||
#define BMA4_MAX_VALUE_SELFTEST_AMP UINT8_C(1)
|
||||
#define BMA4_MAX_IF_MODE UINT8_C(3)
|
||||
#define BMA4_MAX_VALUE_SELFTEST_SIGN UINT8_C(1)
|
||||
|
||||
/**\name BUS READ AND WRITE LENGTH FOR MAG & ACCEL*/
|
||||
#define BMA4_MAG_TRIM_DATA_SIZE UINT8_C(16)
|
||||
#define BMA4_MAG_XYZ_DATA_LENGTH UINT8_C(6)
|
||||
#define BMA4_MAG_XYZR_DATA_LENGTH UINT8_C(8)
|
||||
#define BMA4_ACCEL_DATA_LENGTH UINT8_C(6)
|
||||
#define BMA4_FIFO_DATA_LENGTH UINT8_C(2)
|
||||
#define BMA4_TEMP_DATA_SIZE UINT8_C(1)
|
||||
|
||||
/**\name TEMPERATURE CONSTANT */
|
||||
#define BMA4_OFFSET_TEMP UINT8_C(23)
|
||||
#define BMA4_DEG UINT8_C(1)
|
||||
#define BMA4_FAHREN UINT8_C(2)
|
||||
#define BMA4_KELVIN UINT8_C(3)
|
||||
|
||||
/**\name DELAY DEFINITION IN MSEC*/
|
||||
#define BMA4_AUX_IF_DELAY UINT8_C(5)
|
||||
#define BMA4_BMM150_WAKEUP_DELAY1 UINT8_C(2)
|
||||
#define BMA4_BMM150_WAKEUP_DELAY2 UINT8_C(3)
|
||||
#define BMA4_BMM150_WAKEUP_DELAY3 UINT8_C(1)
|
||||
#define BMA4_GEN_READ_WRITE_DELAY UINT8_C(1)
|
||||
#define BMA4_AUX_COM_DELAY UINT8_C(10)
|
||||
|
||||
/**\name ARRAY PARAMETER DEFINITIONS*/
|
||||
#define BMA4_SENSOR_TIME_MSB_BYTE UINT8_C(2)
|
||||
#define BMA4_SENSOR_TIME_XLSB_BYTE UINT8_C(1)
|
||||
#define BMA4_SENSOR_TIME_LSB_BYTE UINT8_C(0)
|
||||
#define BMA4_MAG_X_LSB_BYTE UINT8_C(0)
|
||||
#define BMA4_MAG_X_MSB_BYTE UINT8_C(1)
|
||||
#define BMA4_MAG_Y_LSB_BYTE UINT8_C(2)
|
||||
#define BMA4_MAG_Y_MSB_BYTE UINT8_C(3)
|
||||
#define BMA4_MAG_Z_LSB_BYTE UINT8_C(4)
|
||||
#define BMA4_MAG_Z_MSB_BYTE UINT8_C(5)
|
||||
#define BMA4_MAG_R_LSB_BYTE UINT8_C(6)
|
||||
#define BMA4_MAG_R_MSB_BYTE UINT8_C(7)
|
||||
#define BMA4_TEMP_BYTE UINT8_C(0)
|
||||
#define BMA4_FIFO_LENGTH_MSB_BYTE UINT8_C(1)
|
||||
|
||||
/**\name ERROR CODES */
|
||||
#define BMA4_OK UINT16_C(0)
|
||||
#define BMA4_E_NULL_PTR UINT16_C(1)
|
||||
#define BMA4_E_OUT_OF_RANGE UINT16_C(1 << 1)
|
||||
#define BMA4_E_INVALID_SENSOR UINT16_C(1 << 2)
|
||||
#define BMA4_E_CONFIG_STREAM_ERROR UINT16_C(1 << 3)
|
||||
#define BMA4_E_SELF_TEST_FAIL UINT16_C(1 << 4)
|
||||
#define BMA4_E_FOC_FAIL UINT16_C(1 << 5)
|
||||
#define BMA4_E_FAIL UINT16_C(1 << 6)
|
||||
#define BMA4_E_INT_LINE_INVALID UINT16_C(1 << 7)
|
||||
#define BMA4_E_RD_WR_LENGTH_INVALID UINT16_C(1 << 8)
|
||||
#define BMA4_E_AUX_CONFIG_FAIL UINT16_C(1 << 9)
|
||||
#define BMA4_E_SC_FIFO_HEADER_ERR UINT16_C(1 << 10)
|
||||
#define BMA4_E_SC_FIFO_CONFIG_ERR UINT16_C(1 << 11)
|
||||
|
||||
/**\name UTILITY MACROS */
|
||||
#define BMA4_SET_LOW_BYTE UINT16_C(0x00FF)
|
||||
#define BMA4_SET_HIGH_BYTE UINT16_C(0xFF00)
|
||||
#define BMA4_SET_LOW_NIBBLE UINT8_C(0x0F)
|
||||
|
||||
/**\name FOC RELATED MACROS */
|
||||
#define BMA4_ACCEL_CONFIG_FOC UINT8_C(0xB7)
|
||||
|
||||
/* Macros used for Self test */
|
||||
/* Self-test: Resulting minimum difference signal in mg for BMA42x */
|
||||
#define BMA42X_ST_ACC_X_AXIS_SIGNAL_DIFF UINT16_C(400)
|
||||
#define BMA42X_ST_ACC_Y_AXIS_SIGNAL_DIFF UINT16_C(800)
|
||||
#define BMA42X_ST_ACC_Z_AXIS_SIGNAL_DIFF UINT16_C(400)
|
||||
|
||||
/* Self-test: Resulting minimum difference signal in mg for BMA45x */
|
||||
#define BMA45X_ST_ACC_X_AXIS_SIGNAL_DIFF UINT16_C(1800)
|
||||
#define BMA45X_ST_ACC_Y_AXIS_SIGNAL_DIFF UINT16_C(1800)
|
||||
#define BMA45X_ST_ACC_Z_AXIS_SIGNAL_DIFF UINT16_C(1800)
|
||||
|
||||
/**\name BOOLEAN TYPES*/
|
||||
#ifndef TRUE
|
||||
#define TRUE UINT8_C(0x01)
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE UINT8_C(0x00)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL UINT8_C(0x00)
|
||||
#endif
|
||||
|
||||
/**\name ERROR STATUS POSITION AND MASK*/
|
||||
#define BMA4_FATAL_ERR_MSK UINT8_C(0x01)
|
||||
#define BMA4_CMD_ERR_POS UINT8_C(1)
|
||||
#define BMA4_CMD_ERR_MSK UINT8_C(0x02)
|
||||
#define BMA4_ERR_CODE_POS UINT8_C(2)
|
||||
#define BMA4_ERR_CODE_MSK UINT8_C(0x1C)
|
||||
#define BMA4_FIFO_ERR_POS UINT8_C(6)
|
||||
#define BMA4_FIFO_ERR_MSK UINT8_C(0x40)
|
||||
#define BMA4_AUX_ERR_POS UINT8_C(7)
|
||||
#define BMA4_AUX_ERR_MSK UINT8_C(0x80)
|
||||
|
||||
/**\name Maximum number of bytes to be read from the sensor */
|
||||
#define BMA4_MAX_BUFFER_SIZE UINT8_C(81)
|
||||
|
||||
/**\name NV_CONFIG POSITION AND MASK*/
|
||||
/* NV_CONF Description - Reg Addr --> (0x70), Bit --> 3 */
|
||||
#define BMA4_NV_ACCEL_OFFSET_POS UINT8_C(3)
|
||||
#define BMA4_NV_ACCEL_OFFSET_MSK UINT8_C(0x08)
|
||||
|
||||
/**\name MAG DATA XYZ POSITION AND MASK*/
|
||||
#define BMA4_DATA_MAG_X_LSB_POS UINT8_C(3)
|
||||
#define BMA4_DATA_MAG_X_LSB_MSK UINT8_C(0xF8)
|
||||
#define BMA4_DATA_MAG_Y_LSB_POS UINT8_C(3)
|
||||
#define BMA4_DATA_MAG_Y_LSB_MSK UINT8_C(0xF8)
|
||||
#define BMA4_DATA_MAG_Z_LSB_POS UINT8_C(1)
|
||||
#define BMA4_DATA_MAG_Z_LSB_MSK UINT8_C(0xFE)
|
||||
#define BMA4_DATA_MAG_R_LSB_POS UINT8_C(2)
|
||||
#define BMA4_DATA_MAG_R_LSB_MSK UINT8_C(0xFC)
|
||||
|
||||
/**\name ACCEL DATA READY POSITION AND MASK*/
|
||||
#define BMA4_STAT_DATA_RDY_ACCEL_POS UINT8_C(7)
|
||||
#define BMA4_STAT_DATA_RDY_ACCEL_MSK UINT8_C(0x80)
|
||||
|
||||
/**\name MAG DATA READY POSITION AND MASK*/
|
||||
#define BMA4_STAT_DATA_RDY_MAG_POS UINT8_C(5)
|
||||
#define BMA4_STAT_DATA_RDY_MAG_MSK UINT8_C(0x20)
|
||||
|
||||
/**\name ADVANCE POWER SAVE POSITION AND MASK*/
|
||||
#define BMA4_ADVANCE_POWER_SAVE_MSK UINT8_C(0x01)
|
||||
|
||||
/**\name ACCELEROMETER ENABLE POSITION AND MASK*/
|
||||
#define BMA4_ACCEL_ENABLE_POS UINT8_C(2)
|
||||
#define BMA4_ACCEL_ENABLE_MSK UINT8_C(0x04)
|
||||
|
||||
/**\name MAGNETOMETER ENABLE POSITION AND MASK*/
|
||||
#define BMA4_MAG_ENABLE_MSK UINT8_C(0x01)
|
||||
|
||||
/**\name ACCEL CONFIGURATION POSITION AND MASK*/
|
||||
#define BMA4_ACCEL_ODR_MSK UINT8_C(0x0F)
|
||||
#define BMA4_ACCEL_BW_POS UINT8_C(4)
|
||||
#define BMA4_ACCEL_BW_MSK UINT8_C(0x70)
|
||||
#define BMA4_ACCEL_RANGE_MSK UINT8_C(0x03)
|
||||
#define BMA4_ACCEL_PERFMODE_POS UINT8_C(7)
|
||||
#define BMA4_ACCEL_PERFMODE_MSK UINT8_C(0x80)
|
||||
|
||||
/**\name MAG CONFIGURATION POSITION AND MASK*/
|
||||
#define BMA4_MAG_CONFIG_OFFSET_POS UINT8_C(4)
|
||||
#define BMA4_MAG_CONFIG_OFFSET_LEN UINT8_C(4)
|
||||
#define BMA4_MAG_CONFIG_OFFSET_MSK UINT8_C(0xF0)
|
||||
#define BMA4_MAG_CONFIG_OFFSET_REG (BMA4_AUX_CONFIG_ADDR)
|
||||
|
||||
/**\name FIFO SELF WAKE UP POSITION AND MASK*/
|
||||
#define BMA4_FIFO_SELF_WAKE_UP_POS UINT8_C(1)
|
||||
#define BMA4_FIFO_SELF_WAKE_UP_MSK UINT8_C(0x02)
|
||||
|
||||
/**\name FIFO BYTE COUNTER POSITION AND MASK*/
|
||||
#define BMA4_FIFO_BYTE_COUNTER_MSB_MSK UINT8_C(0x3F)
|
||||
|
||||
/**\name FIFO DATA POSITION AND MASK*/
|
||||
#define BMA4_FIFO_DATA_POS UINT8_C(0)
|
||||
#define BMA4_FIFO_DATA_MSK UINT8_C(0xFF)
|
||||
|
||||
/**\name FIFO FILTER FOR ACCEL POSITION AND MASK*/
|
||||
#define BMA4_FIFO_DOWN_ACCEL_POS UINT8_C(4)
|
||||
#define BMA4_FIFO_DOWN_ACCEL_MSK UINT8_C(0x70)
|
||||
#define BMA4_FIFO_FILTER_ACCEL_POS UINT8_C(7)
|
||||
#define BMA4_FIFO_FILTER_ACCEL_MSK UINT8_C(0x80)
|
||||
|
||||
/**\name FIFO HEADER DATA DEFINITIONS */
|
||||
#define FIFO_HEAD_A UINT8_C(0x84)
|
||||
#define FIFO_HEAD_M UINT8_C(0x90)
|
||||
#define FIFO_HEAD_M_A UINT8_C(0x94)
|
||||
#define FIFO_HEAD_SENSOR_TIME UINT8_C(0x44)
|
||||
#define FIFO_HEAD_INPUT_CONFIG UINT8_C(0x48)
|
||||
#define FIFO_HEAD_SKIP_FRAME UINT8_C(0x40)
|
||||
#define FIFO_HEAD_OVER_READ_MSB UINT8_C(0x80)
|
||||
#define FIFO_HEAD_SAMPLE_DROP UINT8_C(0x50)
|
||||
|
||||
/**\name FIFO HEADERLESS MODE DATA ENABLE DEFINITIONS */
|
||||
#define BMA4_FIFO_M_A_ENABLE UINT8_C(0x60)
|
||||
#define BMA4_FIFO_A_ENABLE UINT8_C(0x40)
|
||||
#define BMA4_FIFO_M_ENABLE UINT8_C(0x20)
|
||||
|
||||
/**\name FIFO CONFIGURATION SELECTION */
|
||||
#define BMA4_FIFO_STOP_ON_FULL UINT8_C(0x01)
|
||||
#define BMA4_FIFO_TIME UINT8_C(0x02)
|
||||
#define BMA4_FIFO_TAG_INTR2 UINT8_C(0x04)
|
||||
#define BMA4_FIFO_TAG_INTR1 UINT8_C(0x08)
|
||||
#define BMA4_FIFO_HEADER UINT8_C(0x10)
|
||||
#define BMA4_FIFO_MAG UINT8_C(0x20)
|
||||
#define BMA4_FIFO_ACCEL UINT8_C(0x40)
|
||||
#define BMA4_FIFO_ALL UINT8_C(0x7F)
|
||||
#define BMA4_FIFO_CONFIG_0_MASK UINT8_C(0x03)
|
||||
#define BMA4_FIFO_CONFIG_1_MASK UINT8_C(0xFC)
|
||||
|
||||
/**\name FIFO FRAME COUNT DEFINITION */
|
||||
#define FIFO_LSB_CONFIG_CHECK UINT8_C(0x00)
|
||||
#define FIFO_MSB_CONFIG_CHECK UINT8_C(0x80)
|
||||
#define BMA4_FIFO_TAG_INTR_MASK UINT8_C(0xFC)
|
||||
|
||||
/**\name FIFO DROPPED FRAME DEFINITION */
|
||||
#define AUX_FIFO_DROP UINT8_C(0x04)
|
||||
#define ACCEL_AUX_FIFO_DROP UINT8_C(0x05)
|
||||
#define ACCEL_FIFO_DROP UINT8_C(0x01)
|
||||
|
||||
/**\name FIFO MAG DEFINITION*/
|
||||
#define BMA4_MA_FIFO_A_X_LSB UINT8_C(8)
|
||||
|
||||
/**\name FIFO sensor time length definitions*/
|
||||
#define BMA4_SENSOR_TIME_LENGTH UINT8_C(3)
|
||||
|
||||
/**\name FIFO LENGTH DEFINITION*/
|
||||
#define BMA4_FIFO_A_LENGTH UINT8_C(6)
|
||||
#define BMA4_FIFO_M_LENGTH UINT8_C(8)
|
||||
#define BMA4_FIFO_MA_LENGTH UINT8_C(14)
|
||||
|
||||
/**\name MAG I2C ADDRESS SELECTION POSITION AND MASK*/
|
||||
#define BMA4_I2C_DEVICE_ADDR_POS UINT8_C(1)
|
||||
#define BMA4_I2C_DEVICE_ADDR_MSK UINT8_C(0xFE)
|
||||
|
||||
/**\name MAG CONFIGURATION FOR SECONDARY INTERFACE POSITION AND MASK*/
|
||||
#define BMA4_MAG_BURST_MSK UINT8_C(0x03)
|
||||
#define BMA4_MAG_MANUAL_ENABLE_POS UINT8_C(7)
|
||||
#define BMA4_MAG_MANUAL_ENABLE_MSK UINT8_C(0x80)
|
||||
#define BMA4_READ_ADDR_MSK UINT8_C(0xFF)
|
||||
#define BMA4_WRITE_ADDR_MSK UINT8_C(0xFF)
|
||||
#define BMA4_WRITE_DATA_MSK UINT8_C(0xFF)
|
||||
|
||||
/**\name OUTPUT TYPE ENABLE POSITION AND MASK*/
|
||||
#define BMA4_INT_EDGE_CTRL_MASK UINT8_C(0x01)
|
||||
#define BMA4_INT_EDGE_CTRL_POS UINT8_C(0x00)
|
||||
#define BMA4_INT_LEVEL_MASK UINT8_C(0x02)
|
||||
#define BMA4_INT_LEVEL_POS UINT8_C(0x01)
|
||||
#define BMA4_INT_OPEN_DRAIN_MASK UINT8_C(0x04)
|
||||
#define BMA4_INT_OPEN_DRAIN_POS UINT8_C(0x02)
|
||||
#define BMA4_INT_OUTPUT_EN_MASK UINT8_C(0x08)
|
||||
#define BMA4_INT_OUTPUT_EN_POS UINT8_C(0x03)
|
||||
#define BMA4_INT_INPUT_EN_MASK UINT8_C(0x10)
|
||||
#define BMA4_INT_INPUT_EN_POS UINT8_C(0x04)
|
||||
|
||||
/**\name IF CONFIG POSITION AND MASK*/
|
||||
#define BMA4_CONFIG_SPI3_MSK UINT8_C(0x01)
|
||||
#define BMA4_IF_CONFIG_IF_MODE_POS UINT8_C(4)
|
||||
#define BMA4_IF_CONFIG_IF_MODE_MSK UINT8_C(0x10)
|
||||
|
||||
/**\name ACCEL SELF TEST POSITION AND MASK*/
|
||||
#define BMA4_ACCEL_SELFTEST_ENABLE_MSK UINT8_C(0x01)
|
||||
#define BMA4_ACCEL_SELFTEST_SIGN_POS UINT8_C(2)
|
||||
#define BMA4_ACCEL_SELFTEST_SIGN_MSK UINT8_C(0x04)
|
||||
#define BMA4_SELFTEST_AMP_POS UINT8_C(3)
|
||||
#define BMA4_SELFTEST_AMP_MSK UINT8_C(0x08)
|
||||
|
||||
/**\name ACCEL ODR */
|
||||
#define BMA4_OUTPUT_DATA_RATE_0_78HZ UINT8_C(0x01)
|
||||
#define BMA4_OUTPUT_DATA_RATE_1_56HZ UINT8_C(0x02)
|
||||
#define BMA4_OUTPUT_DATA_RATE_3_12HZ UINT8_C(0x03)
|
||||
#define BMA4_OUTPUT_DATA_RATE_6_25HZ UINT8_C(0x04)
|
||||
#define BMA4_OUTPUT_DATA_RATE_12_5HZ UINT8_C(0x05)
|
||||
#define BMA4_OUTPUT_DATA_RATE_25HZ UINT8_C(0x06)
|
||||
#define BMA4_OUTPUT_DATA_RATE_50HZ UINT8_C(0x07)
|
||||
#define BMA4_OUTPUT_DATA_RATE_100HZ UINT8_C(0x08)
|
||||
#define BMA4_OUTPUT_DATA_RATE_200HZ UINT8_C(0x09)
|
||||
#define BMA4_OUTPUT_DATA_RATE_400HZ UINT8_C(0x0A)
|
||||
#define BMA4_OUTPUT_DATA_RATE_800HZ UINT8_C(0x0B)
|
||||
#define BMA4_OUTPUT_DATA_RATE_1600HZ UINT8_C(0x0C)
|
||||
|
||||
/**\name ACCEL BANDWIDTH PARAMETER */
|
||||
#define BMA4_ACCEL_OSR4_AVG1 UINT8_C(0)
|
||||
#define BMA4_ACCEL_OSR2_AVG2 UINT8_C(1)
|
||||
#define BMA4_ACCEL_NORMAL_AVG4 UINT8_C(2)
|
||||
#define BMA4_ACCEL_CIC_AVG8 UINT8_C(3)
|
||||
#define BMA4_ACCEL_RES_AVG16 UINT8_C(4)
|
||||
#define BMA4_ACCEL_RES_AVG32 UINT8_C(5)
|
||||
#define BMA4_ACCEL_RES_AVG64 UINT8_C(6)
|
||||
#define BMA4_ACCEL_RES_AVG128 UINT8_C(7)
|
||||
|
||||
/**\name ACCEL PERFMODE PARAMETER */
|
||||
#define BMA4_CIC_AVG_MODE UINT8_C(0)
|
||||
#define BMA4_CONTINUOUS_MODE UINT8_C(1)
|
||||
|
||||
/**\name MAG OFFSET */
|
||||
#define BMA4_MAG_OFFSET_MAX UINT8_C(0x00)
|
||||
|
||||
/**\name ENABLE/DISABLE SELECTIONS */
|
||||
#define BMA4_X_AXIS UINT8_C(0)
|
||||
#define BMA4_Y_AXIS UINT8_C(1)
|
||||
#define BMA4_Z_AXIS UINT8_C(2)
|
||||
|
||||
/**\name SELF TEST*/
|
||||
#define BMA4_SELFTEST_PASS UINT8_C(0)
|
||||
#define BMA4_SELFTEST_FAIL UINT8_C(1)
|
||||
|
||||
/**\name INTERRUPT MAPS */
|
||||
#define BMA4_INTR1_MAP UINT8_C(0)
|
||||
#define BMA4_INTR2_MAP UINT8_C(1)
|
||||
|
||||
/**\name INTERRUPT MASKS */
|
||||
#define BMA4_FIFO_FULL_INT UINT16_C(0x0100)
|
||||
#define BMA4_FIFO_WM_INT UINT16_C(0x0200)
|
||||
#define BMA4_DATA_RDY_INT UINT16_C(0x0400)
|
||||
#define BMA4_MAG_DATA_RDY_INT UINT16_C(0x2000)
|
||||
#define BMA4_ACCEL_DATA_RDY_INT UINT16_C(0x8000)
|
||||
|
||||
|
||||
/**\name AKM POWER MODE SELECTION */
|
||||
#define AKM_POWER_DOWN_MODE UINT8_C(0)
|
||||
#define AKM_SINGLE_MEAS_MODE UINT8_C(1)
|
||||
|
||||
/**\name SECONDARY_MAG POWER MODE SELECTION */
|
||||
#define BMA4_MAG_FORCE_MODE UINT8_C(0)
|
||||
#define BMA4_MAG_SUSPEND_MODE UINT8_C(1)
|
||||
|
||||
/**\name MAG POWER MODE SELECTION */
|
||||
#define FORCE_MODE UINT8_C(0)
|
||||
#define SUSPEND_MODE UINT8_C(1)
|
||||
|
||||
/**\name ACCEL POWER MODE */
|
||||
#define ACCEL_MODE_NORMAL UINT8_C(0x11)
|
||||
|
||||
/**\name MAG POWER MODE */
|
||||
#define MAG_MODE_SUSPEND UINT8_C(0x18)
|
||||
|
||||
/**\name ENABLE/DISABLE BIT VALUES */
|
||||
#define BMA4_ENABLE UINT8_C(0x01)
|
||||
#define BMA4_DISABLE UINT8_C(0x00)
|
||||
|
||||
/**\name DEFINITION USED FOR DIFFERENT WRITE */
|
||||
#define BMA4_MANUAL_DISABLE UINT8_C(0x00)
|
||||
#define BMA4_MANUAL_ENABLE UINT8_C(0x01)
|
||||
#define BMA4_ENABLE_MAG_IF_MODE UINT8_C(0x01)
|
||||
#define BMA4_MAG_DATA_READ_REG UINT8_C(0x0A)
|
||||
#define BMA4_BMM_POWER_MODE_REG UINT8_C(0x06)
|
||||
#define BMA4_SEC_IF_NULL UINT8_C(0)
|
||||
#define BMA4_SEC_IF_BMM150 UINT8_C(1)
|
||||
#define BMA4_SEC_IF_AKM09916 UINT8_C(2)
|
||||
#define BMA4_ENABLE_AUX_IF_MODE UINT8_C(0x01)
|
||||
|
||||
/**\name SENSOR RESOLUTION */
|
||||
#define BMA4_12_BIT_RESOLUTION UINT8_C(12)
|
||||
#define BMA4_14_BIT_RESOLUTION UINT8_C(14)
|
||||
#define BMA4_16_BIT_RESOLUTION UINT8_C(16)
|
||||
|
||||
/**\name MULTIPLIER */
|
||||
/*! for handling micro-g values */
|
||||
#define BMA4XY_MULTIPLIER UINT32_C(1000000)
|
||||
/*! for handling float temperature values */
|
||||
#define BMA4_SCALE_TEMP INT32_C(1000)
|
||||
/* BMA4_FAHREN_SCALED = 1.8 * 1000 */
|
||||
#define BMA4_FAHREN_SCALED INT32_C(1800)
|
||||
/* BMA4_KELVIN_SCALED = 273.15 * 1000 */
|
||||
#define BMA4_KELVIN_SCALED INT32_C(273150)
|
||||
|
||||
|
||||
/**\name MAP BURST READ LENGTHS */
|
||||
#define BMA4_AUX_READ_LEN_0 0
|
||||
#define BMA4_AUX_READ_LEN_1 1
|
||||
#define BMA4_AUX_READ_LEN_2 2
|
||||
#define BMA4_AUX_READ_LEN_3 3
|
||||
|
||||
#ifndef ABS
|
||||
#define ABS(a) ((a) > 0 ? (a) : -(a)) /*!< Absolute value */
|
||||
#endif
|
||||
|
||||
/**\name BIT SLICE GET AND SET FUNCTIONS */
|
||||
#define BMA4_GET_BITSLICE(regvar, bitname)\
|
||||
((regvar & bitname##_MSK) >> bitname##_POS)
|
||||
#define BMA4_SET_BITSLICE(regvar, bitname, val)\
|
||||
((regvar & ~bitname##_MSK) | \
|
||||
((val<<bitname##_POS)&bitname##_MSK))
|
||||
#define BMA4_GET_DIFF(x, y) ((x) - (y))
|
||||
|
||||
#define BMA4_GET_LSB(var) (uint8_t)(var & BMA4_SET_LOW_BYTE)
|
||||
#define BMA4_GET_MSB(var) (uint8_t)((var & BMA4_SET_HIGH_BYTE) >> 8)
|
||||
|
||||
#define BMA4_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname##_MSK))
|
||||
|
||||
#define BMA4_SET_BITS_POS_0(reg_data, bitname, data) \
|
||||
((reg_data & ~(bitname##_MSK)) | \
|
||||
(data & bitname##_MSK))
|
||||
|
||||
#define BMA4_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
|
||||
|
||||
/**\name TYPEDEF DEFINITIONS */
|
||||
/*!
|
||||
* @brief Bus communication function pointer which should be mapped to
|
||||
* the platform specific read and write functions of the user
|
||||
*/
|
||||
typedef uint16_t (*bma4_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *read_data, uint16_t len);
|
||||
|
||||
/*! delay function pointer */
|
||||
typedef void (*bma4_delay_fptr_t)(uint32_t);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name Enum Declarations */
|
||||
/******************************************************************************/
|
||||
|
||||
/*! @name Enum to define BMA4 variants */
|
||||
enum bma4_variant {
|
||||
BMA42X_VARIANT = 1,
|
||||
BMA45X_VARIANT
|
||||
};
|
||||
|
||||
/**\name STRUCTURE DEFINITIONS*/
|
||||
|
||||
/*!
|
||||
* @brief
|
||||
* This structure holds asic info. for feature configuration.
|
||||
*/
|
||||
struct bma4_asic_data {
|
||||
/* Feature config start addr (0-3 bits)*/
|
||||
uint8_t asic_lsb;
|
||||
/* Feature config start addr (4-11 bits)*/
|
||||
uint8_t asic_msb;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Auxiliary configuration structure for user settings
|
||||
*/
|
||||
struct bma4_aux_config {
|
||||
/*! Device address of auxiliary sensor */
|
||||
uint8_t aux_dev_addr;
|
||||
/*! To enable manual or auto mode */
|
||||
uint8_t manual_enable;
|
||||
/*! No of bytes to be read at a time */
|
||||
uint8_t burst_read_length;
|
||||
/*! Variable to set the auxiliary interface */
|
||||
uint8_t if_mode;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief
|
||||
* This structure holds all relevant information about BMA4
|
||||
*/
|
||||
struct bma4_dev {
|
||||
/*! Chip id of BMA4 */
|
||||
uint8_t chip_id;
|
||||
/*! Chip id of auxiliary sensor */
|
||||
uint8_t aux_chip_id;
|
||||
/*! Device address of BMA4 */
|
||||
uint8_t dev_addr;
|
||||
/*! Interface detail */
|
||||
uint8_t interface;
|
||||
/*! Auxiliary sensor information */
|
||||
uint8_t aux_sensor;
|
||||
/*! Decide SPI or I2C read mechanism */
|
||||
uint8_t dummy_byte;
|
||||
/*! Resolution for FOC */
|
||||
uint8_t resolution;
|
||||
/*! Define the BMA4 variant BMA42X or BMA45X */
|
||||
enum bma4_variant variant;
|
||||
/* ! Used to check mag manual/auto mode status
|
||||
int8_t mag_manual_enable;*/
|
||||
/*! FIFO related configurations */
|
||||
struct bma4_fifo_frame *fifo;
|
||||
/*! Config stream data buffer address will be assigned*/
|
||||
const uint8_t *config_file_ptr;
|
||||
/*! Max read/write length (maximum supported length is 32).
|
||||
To be set by the user */
|
||||
uint8_t read_write_len;
|
||||
/*! Feature len */
|
||||
uint8_t feature_len;
|
||||
/*! Contains asic information */
|
||||
struct bma4_asic_data asic_data;
|
||||
/*! Contains aux configuration settings */
|
||||
struct bma4_aux_config aux_config;
|
||||
/*! Bus read function pointer */
|
||||
bma4_com_fptr_t bus_read;
|
||||
/*! Bus write function pointer */
|
||||
bma4_com_fptr_t bus_write;
|
||||
/*! delay(in ms) function pointer */
|
||||
bma4_delay_fptr_t delay;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief This structure holds the information for usage of
|
||||
* FIFO by the user.
|
||||
*/
|
||||
struct bma4_fifo_frame {
|
||||
/*! Data buffer of user defined length is to be mapped here */
|
||||
uint8_t *data;
|
||||
/*! Number of bytes of FIFO to be read as specified by the user */
|
||||
uint16_t length;
|
||||
/*! Enabling of the FIFO header to stream in header mode */
|
||||
uint8_t fifo_header_enable;
|
||||
/*! Streaming of the Accelerometer, Auxiliary
|
||||
* sensor data or both in FIFO */
|
||||
uint8_t fifo_data_enable;
|
||||
/*! Will be equal to length when no more frames are there to parse */
|
||||
uint16_t accel_byte_start_idx;
|
||||
/*! Will be equal to length when no more frames are there to parse */
|
||||
uint16_t mag_byte_start_idx;
|
||||
/*! Will be equal to length when no more frames are there to parse */
|
||||
uint16_t sc_frame_byte_start_idx;
|
||||
/*! Value of FIFO sensor time time */
|
||||
uint32_t sensor_time;
|
||||
/*! Value of Skipped frame counts */
|
||||
uint8_t skipped_frame_count;
|
||||
/*! Value of accel dropped frame count */
|
||||
uint8_t accel_dropped_frame_count;
|
||||
/*! Value of mag dropped frame count */
|
||||
uint8_t mag_dropped_frame_count;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Error Status structure
|
||||
*/
|
||||
struct bma4_err_reg {
|
||||
/*! Indicates fatal error */
|
||||
uint8_t fatal_err;
|
||||
/*! Indicates command error */
|
||||
uint8_t cmd_err;
|
||||
/*! Indicates error code */
|
||||
uint8_t err_code;
|
||||
/*! Indicates fifo error */
|
||||
uint8_t fifo_err;
|
||||
/*! Indicates mag error */
|
||||
uint8_t aux_err;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Asic Status structure
|
||||
*/
|
||||
struct bma4_asic_status {
|
||||
/*! Asic is in sleep/halt state */
|
||||
uint8_t sleep;
|
||||
/*! Dedicated interrupt is set again before previous interrupt
|
||||
was acknowledged */
|
||||
uint8_t irq_ovrn;
|
||||
/*! Watchcell event detected (asic stopped) */
|
||||
uint8_t wc_event;
|
||||
/*! Stream transfer has started and transactions are ongoing */
|
||||
uint8_t stream_transfer_active;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Interrupt Pin Configuration structure
|
||||
*/
|
||||
struct bma4_int_pin_config {
|
||||
/*! Trigger condition of interrupt pin */
|
||||
uint8_t edge_ctrl;
|
||||
/*! Level of interrupt pin */
|
||||
uint8_t lvl;
|
||||
/*! Behaviour of interrupt pin to open drain */
|
||||
uint8_t od;
|
||||
/*! Output enable for interrupt pin */
|
||||
uint8_t output_en;
|
||||
/*! Input enable for interrupt pin */
|
||||
uint8_t input_en;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Accelerometer configuration structure */
|
||||
struct bma4_accel_config {
|
||||
/*! Output data rate in Hz */
|
||||
uint8_t odr;
|
||||
/*! Bandwidth parameter, determines filter configuration */
|
||||
uint8_t bandwidth;
|
||||
/*! Filter performance mode */
|
||||
uint8_t perf_mode;
|
||||
/*! G-range */
|
||||
uint8_t range;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Auxiliary magnetometer configuration structure
|
||||
*/
|
||||
struct bma4_aux_mag_config {
|
||||
/*! Poll rate for the sensor attached to the Magnetometer interface */
|
||||
uint8_t odr;
|
||||
/*! 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 */
|
||||
uint8_t offset;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief ASIC Config structure
|
||||
*/
|
||||
struct bma4_asic_config {
|
||||
/*! Enable/Disable ASIC Wake Up */
|
||||
uint8_t asic_en;
|
||||
/*! Configure stream_transfer/FIFO mode */
|
||||
uint8_t fifo_mode_en;
|
||||
/*! Mapping of instance RAM1 */
|
||||
uint8_t mem_conf_ram1;
|
||||
/*! Mapping of instance RAM2 */
|
||||
uint8_t mem_conf_ram2;
|
||||
/*! Mapping of instance RAM3 */
|
||||
uint8_t mem_conf_ram3;
|
||||
};
|
||||
/*!
|
||||
* @brief bmm150 or akm09916
|
||||
* magnetometer values structure
|
||||
*/
|
||||
struct bma4_mag {
|
||||
/*! BMM150 and AKM09916 X raw data */
|
||||
int32_t x;
|
||||
/*! BMM150 and AKM09916 Y raw data */
|
||||
int32_t y;
|
||||
/*! BMM150 and AKM09916 Z raw data */
|
||||
int32_t z;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief bmm150 xyz data structure
|
||||
*/
|
||||
struct bma4_mag_xyzr {
|
||||
/*! BMM150 X raw data */
|
||||
int16_t x;
|
||||
/*! BMM150 Y raw data */
|
||||
int16_t y;
|
||||
/*! BMM150 Z raw data */
|
||||
int16_t z;
|
||||
/*! BMM150 R raw data */
|
||||
uint16_t r;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Accel xyz data structure
|
||||
*/
|
||||
struct bma4_accel {
|
||||
/*! Accel X data */
|
||||
int16_t x;
|
||||
/*! Accel Y data */
|
||||
int16_t y;
|
||||
/*! Accel Z data */
|
||||
int16_t z;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief FIFO mag data structure
|
||||
*/
|
||||
struct bma4_mag_fifo_data {
|
||||
/*! The value of mag x LSB data */
|
||||
uint8_t mag_x_lsb;
|
||||
/*! The value of mag x MSB data */
|
||||
uint8_t mag_x_msb;
|
||||
/*! The value of mag y LSB data */
|
||||
uint8_t mag_y_lsb;
|
||||
/*! The value of mag y MSB data */
|
||||
uint8_t mag_y_msb;
|
||||
/*! The value of mag z LSB data */
|
||||
uint8_t mag_z_lsb;
|
||||
/*! The value of mag z MSB data */
|
||||
uint8_t mag_z_msb;
|
||||
/*! The value of mag r for BMM150 Y2 for YAMAHA LSB data */
|
||||
uint8_t mag_r_y2_lsb;
|
||||
/*! The value of mag r for BMM150 Y2 for YAMAHA MSB data */
|
||||
uint8_t mag_r_y2_msb;
|
||||
};
|
||||
|
||||
#endif
|
||||
/* End of __BMA4_H__ */
|
|
@ -0,0 +1,94 @@
|
|||
#include "i2c_bus.h"
|
||||
#include "Wire.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
void I2CBus::scan(void)
|
||||
{
|
||||
uint8_t err, addr;
|
||||
int nDevices = 0;
|
||||
for (addr = 1; addr < 127; addr++) {
|
||||
_port->beginTransmission(addr);
|
||||
err = _port->endTransmission();
|
||||
if (err == 0) {
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (addr < 16)
|
||||
Serial.print("0");
|
||||
Serial.print(addr, HEX);
|
||||
Serial.println(" !");
|
||||
nDevices++;
|
||||
} else if (err == 4) {
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (addr < 16)
|
||||
Serial.print("0");
|
||||
Serial.println(addr, HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
}
|
||||
|
||||
|
||||
uint16_t I2CBus::readBytes(uint8_t addr, uint8_t *data, uint16_t len, uint16_t delay_ms)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY);
|
||||
uint8_t cnt = _port->requestFrom(addr, (uint8_t)len, (uint8_t)1);
|
||||
if (!cnt) {
|
||||
ret = 1 << 13;
|
||||
}
|
||||
uint16_t index = 0;
|
||||
while (_port->available()) {
|
||||
if (index > len)return 1 << 14;
|
||||
if (delay_ms)delay(delay_ms);
|
||||
data[index++] = _port->read();
|
||||
}
|
||||
xSemaphoreGiveRecursive(_i2c_mux);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint16_t I2CBus::readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY);
|
||||
_port->beginTransmission(addr);
|
||||
_port->write(reg);
|
||||
_port->endTransmission(false);
|
||||
uint8_t cnt = _port->requestFrom(addr, (uint8_t)len, (uint8_t)1);
|
||||
if (!cnt) {
|
||||
ret = 1 << 13;
|
||||
}
|
||||
uint16_t index = 0;
|
||||
while (_port->available()) {
|
||||
if (index > len)return 1 << 14;
|
||||
data[index++] = _port->read();
|
||||
}
|
||||
xSemaphoreGiveRecursive(_i2c_mux);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint16_t I2CBus::writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY);
|
||||
_port->beginTransmission(addr);
|
||||
_port->write(reg);
|
||||
for (uint16_t i = 0; i < len; i++) {
|
||||
_port->write(data[i]);
|
||||
}
|
||||
ret = _port->endTransmission();
|
||||
xSemaphoreGiveRecursive(_i2c_mux);
|
||||
return ret ? 1 << 12 : ret;
|
||||
}
|
||||
|
||||
bool I2CBus::deviceProbe(uint8_t addr)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY);
|
||||
_port->beginTransmission(addr);
|
||||
ret = _port->endTransmission();
|
||||
xSemaphoreGiveRecursive(_i2c_mux);
|
||||
return (ret == 0);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef TTGO_I2CBUF_H
|
||||
#define TTGO_I2CBUF_H
|
||||
|
||||
#include <Wire.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
class I2CBus
|
||||
{
|
||||
public:
|
||||
I2CBus(TwoWire &port = Wire, int sda = 21, int scl = 22)
|
||||
{
|
||||
_port = &port;
|
||||
_port->begin(sda, scl);
|
||||
_i2c_mux = xSemaphoreCreateRecursiveMutex();
|
||||
};
|
||||
void scan();
|
||||
uint16_t readBytes(uint8_t addr, uint8_t *data, uint16_t len, uint16_t delay_ms = 0);
|
||||
uint16_t readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len);
|
||||
uint16_t writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len);
|
||||
bool deviceProbe(uint8_t addr);
|
||||
private:
|
||||
TwoWire *_port;
|
||||
SemaphoreHandle_t _i2c_mux = NULL;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,453 @@
|
|||
/*
|
||||
xdrv_83_esp32watch.ino - ESP32 TTGO watch support for Tasmota
|
||||
|
||||
Copyright (C) 2020 Gerhard Mutz and Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef ESP32
|
||||
#ifdef USE_TTGO_WATCH
|
||||
|
||||
#include <axp20x.h>
|
||||
#include <i2c_bus.h>
|
||||
#include <bma.h>
|
||||
#include <soc/rtc.h>
|
||||
|
||||
#define XDRV_83 83
|
||||
|
||||
#define AXP202_INT 35
|
||||
|
||||
struct TTGO_ADC {
|
||||
float vbus_v;
|
||||
float vbus_c;
|
||||
float batt_v;
|
||||
float batt_c;
|
||||
float temp;
|
||||
uint16_t per;
|
||||
} ttgo_adc;
|
||||
|
||||
enum {
|
||||
Q_EVENT_WIFI_SCAN_DONE,
|
||||
Q_EVENT_WIFI_CONNECT,
|
||||
Q_EVENT_BMA_INT,
|
||||
Q_EVENT_AXP_INT,
|
||||
} ;
|
||||
|
||||
#define BMA423_INT1 39
|
||||
#define BMA423_INT2 0
|
||||
|
||||
#define WATCH_FLAG_SLEEP_MODE _BV(1)
|
||||
#define WATCH_FLAG_SLEEP_EXIT _BV(2)
|
||||
#define WATCH_FLAG_BMA_IRQ _BV(3)
|
||||
#define WATCH_FLAG_AXP_IRQ _BV(4)
|
||||
|
||||
struct TTGO_globs {
|
||||
AXP20X_Class *ttgo_power = nullptr;
|
||||
I2CBus *i2c = nullptr;
|
||||
BMA *bma = nullptr;
|
||||
QueueHandle_t g_event_queue_handle = NULL;
|
||||
//EventGroupHandle_t g_event_group = NULL;
|
||||
EventGroupHandle_t isr_group = NULL;
|
||||
bool lenergy = false;
|
||||
bool bma_double_click = false;
|
||||
bool bma_click = false;
|
||||
bool bma_button = false;
|
||||
} ttgo_globs;
|
||||
|
||||
|
||||
void TTGO_Init(void) {
|
||||
ttgo_globs.ttgo_power = new AXP20X_Class();
|
||||
ttgo_globs.i2c = new I2CBus();
|
||||
initPower();
|
||||
|
||||
#ifdef USE_BMA423
|
||||
ttgo_globs.bma = new BMA(*ttgo_globs.i2c);
|
||||
if (ttgo_globs.bma->begin()) {
|
||||
I2cSetActiveFound(BMA4_I2C_ADDR_SECONDARY, "BMA423");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
ttgo_globs.bma->attachInterrupt();
|
||||
pinMode(BMA423_INT1, INPUT);
|
||||
attachInterrupt(BMA423_INT1, [] {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
EventBits_t bits = xEventGroupGetBitsFromISR(ttgo_globs.isr_group);
|
||||
if (bits & WATCH_FLAG_SLEEP_MODE)
|
||||
{
|
||||
// Use an XEvent when waking from low energy sleep mode.
|
||||
xEventGroupSetBitsFromISR(ttgo_globs.isr_group, WATCH_FLAG_SLEEP_EXIT | WATCH_FLAG_BMA_IRQ, &xHigherPriorityTaskWoken);
|
||||
} else
|
||||
{
|
||||
// Use the XQueue mechanism when we are already awake.
|
||||
uint8_t data = Q_EVENT_BMA_INT;
|
||||
xQueueSendFromISR(ttgo_globs.g_event_queue_handle, &data, &xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
if (xHigherPriorityTaskWoken)
|
||||
{
|
||||
portYIELD_FROM_ISR ();
|
||||
}
|
||||
}, RISING);
|
||||
struct bma423_axes_remap remap_data;
|
||||
|
||||
remap_data.x_axis = 0;
|
||||
remap_data.x_axis_sign = 1;
|
||||
remap_data.y_axis = 1;
|
||||
remap_data.y_axis_sign = 0;
|
||||
remap_data.z_axis = 2;
|
||||
remap_data.z_axis_sign = 1;
|
||||
|
||||
ttgo_globs.bma->set_remap_axes(&remap_data);
|
||||
// Enable the double tap wakeup.
|
||||
ttgo_globs.bma->enableWakeupInterrupt(true);
|
||||
ttgo_globs.bma->enableAnyNoMotionInterrupt(true);
|
||||
ttgo_globs.bma->enableAccel();
|
||||
#endif
|
||||
}
|
||||
|
||||
void initPower(void) {
|
||||
int ret = ttgo_globs.ttgo_power->begin(axpReadBytes, axpWriteBytes);
|
||||
if (ret == AXP_FAIL) {
|
||||
//DBGX("AXP Power begin failed");
|
||||
} else {
|
||||
I2cSetActiveFound(AXP202_SLAVE_ADDRESS, "AXP202");
|
||||
//Change the button boot time to 4 seconds
|
||||
ttgo_globs.ttgo_power->setShutdownTime(AXP_POWER_OFF_TIME_4S);
|
||||
// Turn off the charging instructions, there should be no
|
||||
ttgo_globs.ttgo_power->setChgLEDMode(AXP20X_LED_OFF);
|
||||
// Turn off external enable
|
||||
ttgo_globs.ttgo_power->setPowerOutPut(AXP202_EXTEN, false);
|
||||
//axp202 allows maximum charging current of 1800mA, minimum 300mA
|
||||
ttgo_globs.ttgo_power->setChargeControlCur(300);
|
||||
|
||||
ttgo_globs.ttgo_power->adc1Enable(AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
|
||||
|
||||
ttgo_globs.ttgo_power->adc2Enable(AXP202_TEMP_MONITORING_ADC2, true);
|
||||
|
||||
ttgo_globs.ttgo_power->enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_CHARGING_FINISHED_IRQ, AXP202_ON);
|
||||
ttgo_globs.ttgo_power->clearIRQ();
|
||||
|
||||
ttgo_globs.ttgo_power->setPowerOutPut(AXP202_LDO2, AXP202_ON);
|
||||
|
||||
ttgo_globs.isr_group = xEventGroupCreate();
|
||||
ttgo_globs.g_event_queue_handle = xQueueCreate(20, sizeof(uint8_t));
|
||||
|
||||
// Connection interrupted to the specified pin
|
||||
pinMode(AXP202_INT, INPUT);
|
||||
attachInterrupt(AXP202_INT, [] {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
EventBits_t bits = xEventGroupGetBitsFromISR(ttgo_globs.isr_group);
|
||||
if (bits & WATCH_FLAG_SLEEP_MODE) {
|
||||
// Use an XEvent when waking from low energy sleep mode.
|
||||
xEventGroupSetBitsFromISR(ttgo_globs.isr_group, WATCH_FLAG_SLEEP_EXIT | WATCH_FLAG_AXP_IRQ, &xHigherPriorityTaskWoken);
|
||||
} else {
|
||||
// Use the XQueue mechanism when we are already awake.
|
||||
uint8_t data = Q_EVENT_AXP_INT;
|
||||
xQueueSendFromISR(ttgo_globs.g_event_queue_handle, &data, &xHigherPriorityTaskWoken);
|
||||
}
|
||||
if (xHigherPriorityTaskWoken) {
|
||||
portYIELD_FROM_ISR ();
|
||||
}
|
||||
}, FALLING);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static uint8_t axpWriteBytes(uint8_t devAddress, uint8_t regAddress, uint8_t *data, uint8_t len) {
|
||||
ttgo_globs.i2c->writeBytes(devAddress, regAddress, data, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t axpReadBytes(uint8_t devAddress, uint8_t regAddress, uint8_t *data, uint8_t len) {
|
||||
ttgo_globs.i2c->readBytes(devAddress, regAddress, data, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void TTGO_GetADC(void) {
|
||||
ttgo_adc.vbus_v = ttgo_globs.ttgo_power->getVbusVoltage();
|
||||
ttgo_adc.vbus_c = ttgo_globs.ttgo_power->getVbusCurrent();
|
||||
ttgo_adc.batt_v = ttgo_globs.ttgo_power->getBattVoltage();
|
||||
ttgo_adc.per = ttgo_globs.ttgo_power->getBattPercentage();
|
||||
ttgo_adc.batt_c = ttgo_globs.ttgo_power->getBattDischargeCurrent();
|
||||
ttgo_adc.temp = ttgo_globs.ttgo_power->getTemp();
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
const char HTTP_TTGO[] PROGMEM =
|
||||
"{s}TTGO " "VBUS Voltage" "{m}%s mV" "{e}"
|
||||
"{s}TTGO " "VBUS Current" "{m}%s mA" "{e}"
|
||||
"{s}TTGO " "BATT Voltage" "{m}%s mV" "{e}"
|
||||
"{s}TTGO " "BATT Current" "{m}%s mA" "{e}"
|
||||
"{s}TTGO " "BATT Percentage" "{m}%d %%" "{e}"
|
||||
"{s}TTGO " "Temperature" "{m}%s C" "{e}";
|
||||
#ifdef USE_BMA423
|
||||
const char HTTP_TTGO_BMA[] PROGMEM =
|
||||
"{s}TTGO " "BMA x" "{m}%d mg" "{e}"
|
||||
"{s}TTGO " "BMA y" "{m}%d mg" "{e}"
|
||||
"{s}TTGO " "BMA z" "{m}%d mg" "{e}";
|
||||
#endif // USE_BMA423
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
|
||||
void TTGO_WebShow(uint32_t json) {
|
||||
|
||||
TTGO_GetADC();
|
||||
|
||||
char vstring[32];
|
||||
char cstring[32];
|
||||
char bvstring[32];
|
||||
char bcstring[32];
|
||||
char tstring[32];
|
||||
dtostrfd(ttgo_adc.vbus_v,2,vstring);
|
||||
dtostrfd(ttgo_adc.vbus_c,2,cstring);
|
||||
dtostrfd(ttgo_adc.batt_v,2,bvstring);
|
||||
dtostrfd(ttgo_adc.batt_c,2,bcstring);
|
||||
dtostrfd(ttgo_adc.temp,2,tstring);
|
||||
|
||||
#ifdef USE_BMA423
|
||||
Accel acc;
|
||||
bool res = ttgo_globs.bma->getAccel(acc);
|
||||
#endif // USE_BMA423
|
||||
|
||||
if (json) {
|
||||
ResponseAppend_P(PSTR(",\"TTGO_WATCH\":{\"VBV\":%s,\"VBC\":%s,\"BV\":%s,\"BC\":%s,\"BP\":%d,\"CT\":%s"),
|
||||
vstring, cstring, bvstring, bcstring, ttgo_adc.per, tstring);
|
||||
#ifdef USE_BMA423
|
||||
ResponseAppend_P(PSTR(",\"BMAX\":%d,\"BMAY\":%d,\"BMAZ\":%d"),acc.x,acc.y,acc.z);
|
||||
#endif
|
||||
ResponseJsonEnd();
|
||||
} else {
|
||||
WSContentSend_PD(HTTP_TTGO,vstring,cstring,bvstring,bcstring,ttgo_adc.per,tstring);
|
||||
#ifdef USE_BMA423
|
||||
WSContentSend_PD(HTTP_TTGO_BMA,acc.x,acc.y,acc.z);
|
||||
#endif // USE_BMA423
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void enableLDO3(bool en = true) {
|
||||
if (!ttgo_globs.ttgo_power) return;
|
||||
ttgo_globs.ttgo_power->setLDO3Mode(1);
|
||||
ttgo_globs.ttgo_power->setPowerOutPut(AXP202_LDO3, en);
|
||||
}
|
||||
|
||||
void TTGO_audio_power(bool power) {
|
||||
enableLDO3(power);
|
||||
}
|
||||
|
||||
const char TTGO_Commands[] PROGMEM = "TTGO|"
|
||||
"LSLP";
|
||||
|
||||
void (* const TTTGO_Command[])(void) PROGMEM = {
|
||||
&TTGO_LightSleep};
|
||||
|
||||
void TTGO_LightSleep(void) {
|
||||
int32_t ttgo_sleeptime;
|
||||
|
||||
// switch device off
|
||||
if ((abs(XdrvMailbox.payload) >= 10) && (abs(XdrvMailbox.payload) <= 3600*24)) {
|
||||
ttgo_sleeptime = XdrvMailbox.payload;
|
||||
} else {
|
||||
ttgo_sleeptime = 0;
|
||||
}
|
||||
|
||||
ResponseCmndNumber(ttgo_sleeptime);
|
||||
|
||||
TTGO_Sleep(ttgo_sleeptime);
|
||||
|
||||
}
|
||||
|
||||
void TTGO_Sleep(int32_t stime) {
|
||||
int32_t ttgo_sleeptime;
|
||||
|
||||
ttgo_sleeptime = stime;
|
||||
|
||||
DisplayOnOff(0);
|
||||
|
||||
if (ttgo_sleeptime>=0) {
|
||||
// ligh sleep mode
|
||||
WifiShutdown();
|
||||
SettingsSaveAll();
|
||||
RtcSettingsSave();
|
||||
ttgo_globs.lenergy = true;
|
||||
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_2M);
|
||||
xEventGroupSetBits(ttgo_globs.isr_group, WATCH_FLAG_SLEEP_MODE);
|
||||
gpio_wakeup_enable ((gpio_num_t)AXP202_INT, GPIO_INTR_LOW_LEVEL);
|
||||
gpio_wakeup_enable ((gpio_num_t)BMA423_INT1, GPIO_INTR_HIGH_LEVEL);
|
||||
esp_sleep_enable_gpio_wakeup();
|
||||
if (ttgo_sleeptime) {
|
||||
esp_sleep_enable_timer_wakeup(ttgo_sleeptime * 1000000);
|
||||
}
|
||||
esp_light_sleep_start();
|
||||
} else {
|
||||
ttgo_globs.ttgo_power->setPowerOutPut(0xFF, false);
|
||||
Settings.deepsleep = -ttgo_sleeptime;
|
||||
#ifdef USE_DEEPSLEEP
|
||||
RtcSettings.nextwakeup = 0;
|
||||
deepsleep_flag = (0 == XdrvMailbox.payload) ? 0 : DEEPSLEEP_START_COUNTDOWN;
|
||||
if (deepsleep_flag) {
|
||||
if (!Settings.tele_period) {
|
||||
Settings.tele_period = TELE_PERIOD; // Need teleperiod to go back to sleep
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
if (ttgo_sleeptime) {
|
||||
ttgo_globs.lenergy = false;
|
||||
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_240M);
|
||||
DisplayOnOff(1);
|
||||
} else {
|
||||
while (ttgo_globs.lenergy == true) {
|
||||
TTGO_loop(0);
|
||||
OsWatchLoop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TTGO_loop(uint32_t flg) {
|
||||
bool rlst;
|
||||
uint8_t data;
|
||||
|
||||
if (!flg) {
|
||||
// An XEvent signifies that there has been a wakeup interrupt, bring the CPU out of low energy mode
|
||||
EventBits_t bits = xEventGroupGetBits(ttgo_globs.isr_group);
|
||||
if (bits & WATCH_FLAG_SLEEP_EXIT) {
|
||||
if (ttgo_globs.lenergy) {
|
||||
ttgo_globs.lenergy = false;
|
||||
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_240M);
|
||||
DisplayOnOff(1);
|
||||
}
|
||||
|
||||
#ifdef USE_BMA423
|
||||
if (bits & WATCH_FLAG_BMA_IRQ) {
|
||||
do {
|
||||
rlst = ttgo_globs.bma->readInterrupt();
|
||||
} while (!rlst);
|
||||
xEventGroupClearBits(ttgo_globs.isr_group, WATCH_FLAG_BMA_IRQ);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bits & WATCH_FLAG_AXP_IRQ) {
|
||||
ttgo_globs.ttgo_power->readIRQ();
|
||||
ttgo_globs.ttgo_power->clearIRQ();
|
||||
xEventGroupClearBits(ttgo_globs.isr_group, WATCH_FLAG_AXP_IRQ);
|
||||
}
|
||||
xEventGroupClearBits(ttgo_globs.isr_group, WATCH_FLAG_SLEEP_EXIT);
|
||||
xEventGroupClearBits(ttgo_globs.isr_group, WATCH_FLAG_SLEEP_MODE);
|
||||
}
|
||||
} else {
|
||||
//! Normal polling
|
||||
if (xQueueReceive(ttgo_globs.g_event_queue_handle, &data, 5 / portTICK_RATE_MS) == pdPASS) {
|
||||
switch (data) {
|
||||
#ifdef USE_BMA423
|
||||
case Q_EVENT_BMA_INT:
|
||||
// DSERIAL(println, "Q_EVENT_BMA_IRQ");
|
||||
do {
|
||||
rlst = ttgo_globs.bma->readInterrupt();
|
||||
} while (!rlst);
|
||||
|
||||
if (ttgo_globs.bma->isDoubleClick()) {
|
||||
ttgo_globs.bma_double_click = true;
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("double click"));
|
||||
}
|
||||
if (ttgo_globs.bma->isAnyNoMotion()) {
|
||||
ttgo_globs.bma_click = true;
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("click"));
|
||||
}
|
||||
|
||||
//! setp counter
|
||||
if (ttgo_globs.bma->isStepCounter()) {
|
||||
//updateStepCounter(ttgo_globs.bma->getCounter());
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case Q_EVENT_AXP_INT:
|
||||
// DSERIAL(println, "Q_EVENT_AXP_INT");
|
||||
ttgo_globs.ttgo_power->readIRQ();
|
||||
if (ttgo_globs.ttgo_power->isVbusPlugInIRQ()) {
|
||||
//batState = LV_ICON_CHARGE;
|
||||
//updateBatteryIcon(LV_ICON_CHARGE);
|
||||
}
|
||||
if (ttgo_globs.ttgo_power->isVbusRemoveIRQ()) {
|
||||
//batState = LV_ICON_CALCULATION;
|
||||
//updateBatteryIcon(LV_ICON_CALCULATION);
|
||||
}
|
||||
if (ttgo_globs.ttgo_power->isChargingDoneIRQ()) {
|
||||
//batState = LV_ICON_CALCULATION;
|
||||
//updateBatteryIcon(LV_ICON_CALCULATION);
|
||||
}
|
||||
if (ttgo_globs.ttgo_power->isPEKShortPressIRQ()) {
|
||||
ttgo_globs.bma_button = true;
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("button press"));
|
||||
}
|
||||
ttgo_globs.ttgo_power->clearIRQ();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TTGO_doubleclick(void) {
|
||||
bool retval = ttgo_globs.bma_double_click;
|
||||
ttgo_globs.bma_double_click = false;
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool TTGO_button(void) {
|
||||
bool retval = ttgo_globs.bma_button;
|
||||
ttgo_globs.bma_button = false;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
bool Xdrv83(uint8_t function) {
|
||||
bool result = false;
|
||||
|
||||
switch (function) {
|
||||
|
||||
case FUNC_WEB_SENSOR:
|
||||
#ifdef USE_WEBSERVER
|
||||
TTGO_WebShow(0);
|
||||
#endif
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
TTGO_WebShow(1);
|
||||
break;
|
||||
case FUNC_COMMAND:
|
||||
result = DecodeCommand(TTGO_Commands, TTTGO_Command);
|
||||
break;
|
||||
case FUNC_INIT:
|
||||
TTGO_Init();
|
||||
break;
|
||||
case FUNC_LOOP:
|
||||
TTGO_loop(1);
|
||||
break;
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // USE_TTGO_WATCH
|
||||
#endif // ESP32
|
Loading…
Reference in New Issue