mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
SC7A20 tweaks (#1251)
* Clean up handling of addresses * Update SC7A20.hpp * Try remapped Accel readings * Fake LIS setup? * Refining build options
This commit is contained in:
@@ -5,11 +5,16 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include "LIS2DH12_defines.hpp"
|
||||
#include <SC7A20.hpp>
|
||||
#include <SC7A20_defines.h>
|
||||
#include <array>
|
||||
|
||||
uint8_t SC7A20::activeAddress;
|
||||
bool SC7A20::isInImitationMode;
|
||||
/*
|
||||
- This little accelerometer seems to come in two forms, its "normal" setup, and then one where it imitates the LIS2DH12
|
||||
- This can be detected by checking the whoami registers
|
||||
*/
|
||||
|
||||
bool SC7A20::detect() {
|
||||
if (FRToSI2C::probe(SC7A20_ADDRESS)) {
|
||||
@@ -17,7 +22,7 @@ bool SC7A20::detect() {
|
||||
uint8_t id = 0;
|
||||
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_WHO_AMI_I, &id, 1)) {
|
||||
if (id == SC7A20_WHO_AM_I_VALUE) {
|
||||
activeAddress = SC7A20_ADDRESS;
|
||||
isInImitationMode = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +32,7 @@ bool SC7A20::detect() {
|
||||
uint8_t id = 0;
|
||||
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS2, SC7A20_WHO_AMI_I, &id, 1)) {
|
||||
if (id == SC7A20_WHO_AM_I_VALUE) {
|
||||
activeAddress = SC7A20_ADDRESS2;
|
||||
isInImitationMode = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +59,20 @@ static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||
|
||||
//
|
||||
};
|
||||
static const FRToSI2C::I2C_REG i2c_registers_alt[] = {{LIS_CTRL_REG1, 0b00110111, 0}, // 200Hz XYZ
|
||||
{LIS_CTRL_REG2, 0b00000000, 0}, //
|
||||
{LIS_CTRL_REG3, 0b01100000, 0}, // Setup interrupt pins
|
||||
{LIS_CTRL_REG4, 0b00001000, 0}, // Block update mode off, HR on
|
||||
{LIS_CTRL_REG5, 0b00000010, 0}, //
|
||||
{LIS_CTRL_REG6, 0b01100010, 0},
|
||||
// Basically setup the unit to run, and enable 4D orientation detection
|
||||
{LIS_INT2_CFG, 0b01111110, 0}, // setup for movement detection
|
||||
{LIS_INT2_THS, 0x28, 0}, //
|
||||
{LIS_INT2_DURATION, 64, 0}, //
|
||||
{LIS_INT1_CFG, 0b01111110, 0}, //
|
||||
{LIS_INT1_THS, 0x28, 0}, //
|
||||
{LIS_INT1_DURATION, 64, 0}};
|
||||
|
||||
bool SC7A20::initalize() {
|
||||
// Setup acceleration readings
|
||||
// 2G range
|
||||
@@ -63,15 +82,18 @@ bool SC7A20::initalize() {
|
||||
// Orientation recognition in symmetrical mode
|
||||
// Hysteresis is set to ~ 16 counts
|
||||
// Theta blocking is set to 0b10
|
||||
|
||||
return FRToSI2C::writeRegistersBulk(activeAddress, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
if (isInImitationMode) {
|
||||
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS2, i2c_registers_alt, sizeof(i2c_registers_alt) / sizeof(i2c_registers_alt[0]));
|
||||
} else {
|
||||
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
}
|
||||
}
|
||||
|
||||
void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
// We can tell the accelerometer to output in LE mode which makes this simple
|
||||
uint16_t sensorData[3] = {0, 0, 0};
|
||||
|
||||
if (FRToSI2C::Mem_Read(SC7A20_ADDRESS, SC7A20_OUT_X_L, (uint8_t *)sensorData, 6) == false) {
|
||||
if (FRToSI2C::Mem_Read(isInImitationMode ? SC7A20_ADDRESS2 : SC7A20_ADDRESS, isInImitationMode ? SC7A20_OUT_X_L_ALT : SC7A20_OUT_X_L, (uint8_t *)sensorData, 6) == false) {
|
||||
x = y = z = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
static bool initalize();
|
||||
// 1 = rh, 2,=lh, 8=flat
|
||||
static Orientation getOrientation() {
|
||||
uint8_t val = ((FRToSI2C::I2C_RegisterRead(activeAddress, SC7A20_INT2_SOURCE) >> 2) - 1);
|
||||
uint8_t val = ((FRToSI2C::I2C_RegisterRead(isInImitationMode ? SC7A20_ADDRESS2 : SC7A20_ADDRESS, SC7A20_INT2_SOURCE) >> 2) - 1);
|
||||
if (val == 1) {
|
||||
#ifdef SC7_ORI_FLIP
|
||||
return Orientation::ORIENTATION_RIGHT_HAND;
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
|
||||
|
||||
private:
|
||||
static uint8_t activeAddress;
|
||||
static bool isInImitationMode;
|
||||
};
|
||||
|
||||
#endif /* CORE_DRIVERS_BMA223_HPP_ */
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#define SC7A20_REFERENCE 0x26
|
||||
#define SC7A20_STATUS_REG 0x27
|
||||
#define SC7A20_OUT_X_L 0x28
|
||||
#define SC7A20_OUT_X_L_ALT 0xA8
|
||||
#define SC7A20_OUT_X_H 0x29
|
||||
#define SC7A20_OUT_Y_L 0x2A
|
||||
#define SC7A20_OUT_Y_H 0x2B
|
||||
|
||||
@@ -192,7 +192,7 @@ $(shell find $(DEVICE_BSP_DIR) -type f -name '*.cpp') \
|
||||
$(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp')
|
||||
|
||||
# code optimisation ------------------------------------------------------------
|
||||
OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections -fshort-enums -fsingle-precision-constant -ffreestanding -fno-common
|
||||
OPTIM=-Os -flto -finline-small-functions -fshort-wchar -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections -fshort-enums -fsingle-precision-constant -fno-common
|
||||
|
||||
# global defines ---------------------------------------------------------------
|
||||
GLOBAL_DEFINES += $(DEV_GLOBAL_DEFS) -D USE_RTOS_SYSTICK -D MODEL_$(model) -D VECT_TAB_OFFSET=$(bootldr_size)U
|
||||
@@ -293,8 +293,6 @@ CXXFLAGS=$(DEV_CXXFLAGS) \
|
||||
-fno-non-call-exceptions \
|
||||
-fno-use-cxa-atexit \
|
||||
-fno-strict-aliasing \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-fno-threadsafe-statics \
|
||||
-T$(LDSCRIPT)
|
||||
|
||||
@@ -307,7 +305,7 @@ CFLAGS=$(DEV_CFLAGS) \
|
||||
$(GLOBAL_DEFINES) \
|
||||
-D${COMPILER} \
|
||||
-MMD \
|
||||
-std=gnu99 \
|
||||
-std=gnu11 \
|
||||
$(OPTIM) \
|
||||
-T$(LDSCRIPT) \
|
||||
-c
|
||||
|
||||
4342
source/Middlewares/Third_Party/FreeRTOS/Source/queue.c
vendored
4342
source/Middlewares/Third_Party/FreeRTOS/Source/queue.c
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user