mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 17:52:35 +00:00
Radiomaster Bandit Accelerometer support (#4667)
* Added STK8xxxx Accelerometer chip Added detection of STK8BA53 to I2C scanner. Change the way and order MCP9808, lLISH3DH and STK8BA53 is detected since they all shares the same I2C address. * Accelerometer support Radiomaster Bandit. Enables tap to wake screen if enabled in config, * Trunk Trunk
This commit is contained in:
@@ -160,4 +160,5 @@ lib_deps =
|
|||||||
mprograms/QMC5883LCompass@^1.2.0
|
mprograms/QMC5883LCompass@^1.2.0
|
||||||
|
|
||||||
|
|
||||||
https://github.com/meshtastic/DFRobot_LarkWeatherStation#dee914270dc7cb3e43fbf034edd85a63a16a12ee
|
https://github.com/meshtastic/DFRobot_LarkWeatherStation#dee914270dc7cb3e43fbf034edd85a63a16a12ee
|
||||||
|
https://github.com/gjelsoe/STK8xxx-Accelerometer.git#v0.1.1
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
#include <Adafruit_LIS3DH.h>
|
#include <Adafruit_LIS3DH.h>
|
||||||
#include <Adafruit_LSM6DS3TRC.h>
|
#include <Adafruit_LSM6DS3TRC.h>
|
||||||
#include <Adafruit_MPU6050.h>
|
#include <Adafruit_MPU6050.h>
|
||||||
|
#ifdef STK8XXX_INT
|
||||||
|
#include <stk8baxx.h>
|
||||||
|
#endif
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SensorBMA423.hpp>
|
#include <SensorBMA423.hpp>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
@@ -24,6 +27,8 @@
|
|||||||
#define ACCELEROMETER_CHECK_INTERVAL_MS 100
|
#define ACCELEROMETER_CHECK_INTERVAL_MS 100
|
||||||
#define ACCELEROMETER_CLICK_THRESHOLD 40
|
#define ACCELEROMETER_CLICK_THRESHOLD 40
|
||||||
|
|
||||||
|
volatile static bool STK_IRQ;
|
||||||
|
|
||||||
static inline int readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint8_t len)
|
static inline int readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint8_t len)
|
||||||
{
|
{
|
||||||
Wire.beginTransmission(address);
|
Wire.beginTransmission(address);
|
||||||
@@ -79,6 +84,11 @@ class AccelerometerThread : public concurrency::OSThread
|
|||||||
|
|
||||||
if (acceleremoter_type == ScanI2C::DeviceType::MPU6050 && mpu.getMotionInterruptStatus()) {
|
if (acceleremoter_type == ScanI2C::DeviceType::MPU6050 && mpu.getMotionInterruptStatus()) {
|
||||||
wakeScreen();
|
wakeScreen();
|
||||||
|
} else if (acceleremoter_type == ScanI2C::DeviceType::STK8BAXX && STK_IRQ) {
|
||||||
|
STK_IRQ = false;
|
||||||
|
if (config.display.wake_on_tap_or_motion) {
|
||||||
|
wakeScreen();
|
||||||
|
}
|
||||||
} else if (acceleremoter_type == ScanI2C::DeviceType::LIS3DH && lis.getClick() > 0) {
|
} else if (acceleremoter_type == ScanI2C::DeviceType::LIS3DH && lis.getClick() > 0) {
|
||||||
uint8_t click = lis.getClick();
|
uint8_t click = lis.getClick();
|
||||||
if (!config.device.double_tap_as_button_press) {
|
if (!config.device.double_tap_as_button_press) {
|
||||||
@@ -188,6 +198,15 @@ class AccelerometerThread : public concurrency::OSThread
|
|||||||
mpu.setMotionDetectionDuration(20);
|
mpu.setMotionDetectionDuration(20);
|
||||||
mpu.setInterruptPinLatch(true); // Keep it latched. Will turn off when reinitialized.
|
mpu.setInterruptPinLatch(true); // Keep it latched. Will turn off when reinitialized.
|
||||||
mpu.setInterruptPinPolarity(true);
|
mpu.setInterruptPinPolarity(true);
|
||||||
|
#ifdef STK8XXX_INT
|
||||||
|
} else if (acceleremoter_type == ScanI2C::DeviceType::STK8BAXX && stk8baxx.STK8xxx_Initialization(STK8xxx_VAL_RANGE_2G)) {
|
||||||
|
STK_IRQ = false;
|
||||||
|
LOG_DEBUG("STX8BAxx initialized\n");
|
||||||
|
stk8baxx.STK8xxx_Anymotion_init();
|
||||||
|
pinMode(STK8XXX_INT, INPUT_PULLUP);
|
||||||
|
attachInterrupt(
|
||||||
|
digitalPinToInterrupt(STK8XXX_INT), [] { STK_IRQ = true; }, RISING);
|
||||||
|
#endif
|
||||||
} else if (acceleremoter_type == ScanI2C::DeviceType::LIS3DH && lis.begin(accelerometer_found.address)) {
|
} else if (acceleremoter_type == ScanI2C::DeviceType::LIS3DH && lis.begin(accelerometer_found.address)) {
|
||||||
LOG_DEBUG("LIS3DH initializing\n");
|
LOG_DEBUG("LIS3DH initializing\n");
|
||||||
lis.setRange(LIS3DH_RANGE_2_G);
|
lis.setRange(LIS3DH_RANGE_2_G);
|
||||||
@@ -262,6 +281,9 @@ class AccelerometerThread : public concurrency::OSThread
|
|||||||
ScanI2C::DeviceType acceleremoter_type;
|
ScanI2C::DeviceType acceleremoter_type;
|
||||||
Adafruit_MPU6050 mpu;
|
Adafruit_MPU6050 mpu;
|
||||||
Adafruit_LIS3DH lis;
|
Adafruit_LIS3DH lis;
|
||||||
|
#ifdef STK8XXX_INT
|
||||||
|
STK8xxx stk8baxx;
|
||||||
|
#endif
|
||||||
Adafruit_LSM6DS3TRC lsm;
|
Adafruit_LSM6DS3TRC lsm;
|
||||||
SensorBMA423 bmaSensor;
|
SensorBMA423 bmaSensor;
|
||||||
bool BMA_IRQ = false;
|
bool BMA_IRQ = false;
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
// ACCELEROMETER
|
// ACCELEROMETER
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
#define MPU6050_ADDR 0x68
|
#define MPU6050_ADDR 0x68
|
||||||
|
#define STK8BXX_ADR 0x18
|
||||||
#define LIS3DH_ADR 0x18
|
#define LIS3DH_ADR 0x18
|
||||||
#define BMA423_ADDR 0x19
|
#define BMA423_ADDR 0x19
|
||||||
#define LSM6DS3_ADDR 0x6A
|
#define LSM6DS3_ADDR 0x6A
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ ScanI2C::FoundDevice ScanI2C::firstKeyboard() const
|
|||||||
|
|
||||||
ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
|
ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
|
||||||
{
|
{
|
||||||
ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, BMX160};
|
ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, BMX160, STK8BAXX};
|
||||||
return firstOfOrNONE(5, types);
|
return firstOfOrNONE(6, types);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScanI2C::FoundDevice ScanI2C::find(ScanI2C::DeviceType) const
|
ScanI2C::FoundDevice ScanI2C::find(ScanI2C::DeviceType) const
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ class ScanI2C
|
|||||||
AHT10,
|
AHT10,
|
||||||
BMX160,
|
BMX160,
|
||||||
DFROBOT_LARK,
|
DFROBOT_LARK,
|
||||||
NAU7802
|
NAU7802,
|
||||||
|
STK8BAXX
|
||||||
} DeviceType;
|
} DeviceType;
|
||||||
|
|
||||||
// typedef uint8_t DeviceAddress;
|
// typedef uint8_t DeviceAddress;
|
||||||
|
|||||||
@@ -313,17 +313,34 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MCP9808_ADDR:
|
case MCP9808_ADDR:
|
||||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x07), 2);
|
// We need to check for STK8BAXX first, since register 0x07 is new data flag for the z-axis and can produce some
|
||||||
if (registerValue == 0x0400) {
|
// weird result. and register 0x00 doesn't seems to be colliding with MCP9808 and LIS3DH chips.
|
||||||
type = MCP9808;
|
{
|
||||||
LOG_INFO("MCP9808 sensor found\n");
|
// Check register 0x00 for 0x8700 response to ID STK8BA53 chip.
|
||||||
} else {
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 2);
|
||||||
type = LIS3DH;
|
if (registerValue == 0x8700) {
|
||||||
LOG_INFO("LIS3DH accelerometer found\n");
|
type = STK8BAXX;
|
||||||
|
LOG_INFO("STK8BAXX accelerometer found\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check register 0x07 for 0x0400 response to ID MCP9808 chip.
|
||||||
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x07), 2);
|
||||||
|
if (registerValue == 0x0400) {
|
||||||
|
type = MCP9808;
|
||||||
|
LOG_INFO("MCP9808 sensor found\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check register 0x0F for 0x3300 response to ID LIS3DH chip.
|
||||||
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0F), 2);
|
||||||
|
if (registerValue == 0x3300) {
|
||||||
|
type = LIS3DH;
|
||||||
|
LOG_INFO("LIS3DH accelerometer found\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SHT31_4x_ADDR:
|
case SHT31_4x_ADDR:
|
||||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x89), 2);
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x89), 2);
|
||||||
if (registerValue == 0x11a2 || registerValue == 0x11da || registerValue == 0xe9c) {
|
if (registerValue == 0x11a2 || registerValue == 0x11da || registerValue == 0xe9c) {
|
||||||
|
|||||||
@@ -11,12 +11,17 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
I2C SDA and SCL.
|
I2C SDA and SCL.
|
||||||
0x18 - STK8XXX Accelerometer, Not supported yet.
|
0x18 - STK8XXX Accelerometer
|
||||||
0x3C - SH1115 Display Driver
|
0x3C - SH1115 Display Driver
|
||||||
*/
|
*/
|
||||||
#define I2C_SDA 14
|
#define I2C_SDA 14
|
||||||
#define I2C_SCL 12
|
#define I2C_SCL 12
|
||||||
|
|
||||||
|
/*
|
||||||
|
I2C STK8XXX Accelerometer Interrupt PIN to ESP32 Pin 6 - SENSOR_CAPP (GPIO37)
|
||||||
|
*/
|
||||||
|
#define STK8XXX_INT 37
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No GPS - but free pins are available.
|
No GPS - but free pins are available.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user