@@ -36,6 +36,7 @@
|
||||
|
||||
#ifdef MODEL_TS80P
|
||||
#define ACCEL_LIS
|
||||
#define ACCEL_MSA
|
||||
#define POW_PD
|
||||
#define POW_QC
|
||||
#define TEMP_NTC
|
||||
|
||||
50
workspace/TS100/Core/Drivers/MSA301.cpp
Normal file
50
workspace/TS100/Core/Drivers/MSA301.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* MSA301.cpp
|
||||
*
|
||||
* Created on: 3 Jan 2021
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include <MSA301.h>
|
||||
#include "MSA301_defines.h"
|
||||
#define MSA301_I2C_ADDRESS 0x4C
|
||||
bool MSA301::detect() {
|
||||
return FRToSI2C::probe(MSA301_I2C_ADDRESS);
|
||||
}
|
||||
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
||||
//
|
||||
{ MSA301_REG_ODR, 0b00001000, 1 }, //X/Y/Z enabled @ 250Hz
|
||||
{ MSA301_REG_POWERMODE, 0b0001001, 1 }, // Normal mode
|
||||
{ MSA301_REG_RESRANGE, 0b00000001, 0 }, // 14bit resolution @ 4G range
|
||||
{ MSA301_REG_ORIENT_HY, 0b01000000, 0 }, // 4*62.5mg hyst, no blocking, symmetrical
|
||||
{ MSA301_REG_INTSET0, 1 << 6, 0 }, // Turn on orientation detection (by enabling its interrupt)
|
||||
|
||||
};
|
||||
|
||||
bool MSA301::initalize() {
|
||||
return FRToSI2C::writeRegistersBulk(MSA301_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
}
|
||||
|
||||
Orientation MSA301::getOrientation() {
|
||||
uint8_t temp = 0;
|
||||
FRToSI2C::Mem_Read(MSA301_I2C_ADDRESS, MSA301_REG_ORIENT_STATUS, &temp, 1);
|
||||
switch (temp) {
|
||||
case 112:
|
||||
return Orientation::ORIENTATION_LEFT_HAND;
|
||||
case 96:
|
||||
return Orientation::ORIENTATION_RIGHT_HAND;
|
||||
default:
|
||||
return Orientation::ORIENTATION_FLAT;
|
||||
}
|
||||
}
|
||||
|
||||
void MSA301::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
uint8_t temp[6];
|
||||
//Bulk read all 6 regs
|
||||
FRToSI2C::Mem_Read(MSA301_I2C_ADDRESS, MSA301_REG_OUT_X_L, temp, 6);
|
||||
x = int16_t(((int16_t) temp[1]) << 8 | temp[0]) >> 2;
|
||||
y = int16_t(((int16_t) temp[3]) << 8 | temp[2]) >> 2;
|
||||
z = int16_t(((int16_t) temp[5]) << 8 | temp[4]) >> 2;
|
||||
|
||||
}
|
||||
27
workspace/TS100/Core/Drivers/MSA301.h
Normal file
27
workspace/TS100/Core/Drivers/MSA301.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* MSA301.h
|
||||
*
|
||||
* Created on: 3 Jan 2021
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#ifndef DRIVERS_MSA301_H_
|
||||
#define DRIVERS_MSA301_H_
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "BSP.h"
|
||||
|
||||
class MSA301 {
|
||||
public:
|
||||
//Returns true if this accelerometer is detected
|
||||
static bool detect();
|
||||
//Init any internal state
|
||||
static bool initalize();
|
||||
// Reads the I2C register and returns the orientation
|
||||
static Orientation getOrientation();
|
||||
//Return the x/y/z axis readings as signed int16's
|
||||
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* DRIVERS_MSA301_H_ */
|
||||
34
workspace/TS100/Core/Drivers/MSA301_defines.h
Normal file
34
workspace/TS100/Core/Drivers/MSA301_defines.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* MSA301_defines.h
|
||||
*
|
||||
* Created on: 3 Jan 2021
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#ifndef DRIVERS_MSA301_DEFINES_H_
|
||||
#define DRIVERS_MSA301_DEFINES_H_
|
||||
//Definitions from Adafruit <3
|
||||
|
||||
#define MSA301_REG_PARTID 0x01 ///< Register that contains the part ID
|
||||
#define MSA301_REG_OUT_X_L 0x02 ///< Register address for X axis lower byte
|
||||
#define MSA301_REG_OUT_X_H 0x03 ///< Register address for X axis higher byte
|
||||
#define MSA301_REG_OUT_Y_L 0x04 ///< Register address for Y axis lower byte
|
||||
#define MSA301_REG_OUT_Y_H 0x05 ///< Register address for Y axis higher byte
|
||||
#define MSA301_REG_OUT_Z_L 0x06 ///< Register address for Z axis lower byte
|
||||
#define MSA301_REG_OUT_Z_H 0x07 ///< Register address for Z axis higher byte
|
||||
#define MSA301_REG_MOTIONINT 0x09 ///< Register address for motion interrupt
|
||||
#define MSA301_REG_DATAINT 0x0A ///< Register address for data interrupt
|
||||
#define MSA301_REG_CLICKSTATUS 0x0B ///< Register address for click/doubleclick status
|
||||
#define MSA301_REG_RESRANGE 0x0F ///< Register address for resolution range
|
||||
#define MSA301_REG_ODR 0x10 ///< Register address for data rate setting
|
||||
#define MSA301_REG_POWERMODE 0x11 ///< Register address for power mode setting
|
||||
#define MSA301_REG_INTSET0 0x16 ///< Register address for interrupt setting #0
|
||||
#define MSA301_REG_INTSET1 0x17 ///< Register address for interrupt setting #1
|
||||
#define MSA301_REG_INTMAP0 0x19 ///< Register address for interrupt map #0
|
||||
#define MSA301_REG_INTMAP1 0x1A ///< Register address for interrupt map #1
|
||||
#define MSA301_REG_TAPDUR 0x2A ///< Register address for tap duration
|
||||
#define MSA301_REG_TAPTH 0x2B ///< Register address for tap threshold
|
||||
#define MSA301_REG_ORIENT_HY 0x2C ///< Register address for orientation Hysteresis
|
||||
#define MSA301_REG_ORIENT_STATUS 0x0C ///< Register address for orientation hysteresis
|
||||
|
||||
#endif /* DRIVERS_MSA301_DEFINES_H_ */
|
||||
@@ -394,8 +394,8 @@ static void display_countdown(int sleepThres) {
|
||||
* mode is triggered.
|
||||
*/
|
||||
int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime;
|
||||
int downCount = sleepThres - xTaskGetTickCount() + lastEventTime;
|
||||
if (downCount > 99000) {
|
||||
TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime;
|
||||
if (downCount > (99 * TICKS_SECOND)) {
|
||||
OLED::printNumber(downCount / 60000 + 1, 2);
|
||||
OLED::print(SymbolMinutes);
|
||||
} else {
|
||||
@@ -645,10 +645,10 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
|
||||
void showDebugMenu(void) {
|
||||
uint8_t screen = 0;
|
||||
ButtonState b;
|
||||
OLED::setFont(1); // small font
|
||||
for (;;) {
|
||||
OLED::clearScreen(); // Ensure the buffer starts clean
|
||||
OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left)
|
||||
OLED::setFont(1); // small font
|
||||
OLED::print(SymbolVersionNumber); // Print version number
|
||||
OLED::setCursor(0, 8); // second line
|
||||
OLED::print(DebugMenu[screen]);
|
||||
@@ -717,7 +717,6 @@ void showDebugMenu(void) {
|
||||
}
|
||||
#endif
|
||||
if (poweredbyPD) {
|
||||
|
||||
OLED::printNumber(2, 1);
|
||||
} else {
|
||||
|
||||
|
||||
74
workspace/TS100/Core/Threads/MOVThread.cpp
Executable file → Normal file
74
workspace/TS100/Core/Threads/MOVThread.cpp
Executable file → Normal file
@@ -5,11 +5,13 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include "BMA223.hpp"
|
||||
#include "BSP.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "LIS2DH12.hpp"
|
||||
#include "MMA8652FC.hpp"
|
||||
#include "MSA301.h"
|
||||
#include "QC3.h"
|
||||
#include "Settings.h"
|
||||
#include "TipThermoModel.h"
|
||||
@@ -18,46 +20,47 @@
|
||||
#include "main.hpp"
|
||||
#include "power.hpp"
|
||||
#include "stdlib.h"
|
||||
#include "BMA223.hpp"
|
||||
#include "task.h"
|
||||
#define MOVFilter 8
|
||||
uint8_t accelInit = 0;
|
||||
TickType_t lastMovementTime = 0;
|
||||
void detectAccelerometerVersion() {
|
||||
DetectedAccelerometerVersion = ACCELEROMETERS_SCANNING;
|
||||
DetectedAccelerometerVersion = 99;
|
||||
#ifdef ACCEL_MMA
|
||||
if (MMA8652FC::detect()) {
|
||||
DetectedAccelerometerVersion = 1;
|
||||
if (!MMA8652FC::initalize()) {
|
||||
DetectedAccelerometerVersion = NO_DETECTED_ACCELEROMETER;
|
||||
}
|
||||
} else
|
||||
if (MMA8652FC::detect()) {
|
||||
if (MMA8652FC::initalize()) {
|
||||
DetectedAccelerometerVersion = 1;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_LIS
|
||||
if (LIS2DH12::detect()) {
|
||||
DetectedAccelerometerVersion = 2;
|
||||
// Setup the ST Accelerometer
|
||||
if (!LIS2DH12::initalize()) {
|
||||
DetectedAccelerometerVersion = NO_DETECTED_ACCELEROMETER;
|
||||
if (LIS2DH12::initalize()) {
|
||||
DetectedAccelerometerVersion = 2;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_BMA
|
||||
if (BMA223::detect()) {
|
||||
DetectedAccelerometerVersion = 3;
|
||||
// Setup the ST Accelerometer
|
||||
if (!BMA223::initalize()) {
|
||||
DetectedAccelerometerVersion = NO_DETECTED_ACCELEROMETER;
|
||||
if (BMA223::detect()) {
|
||||
// Setup the ST Accelerometer
|
||||
if (BMA223::initalize()) {
|
||||
DetectedAccelerometerVersion = 3;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_MSA
|
||||
if (MSA301::detect()) {
|
||||
// Setup the MSA301 Accelerometer
|
||||
if (MSA301::initalize()) {
|
||||
DetectedAccelerometerVersion = 4;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
DetectedAccelerometerVersion = NO_DETECTED_ACCELEROMETER;
|
||||
systemSettings.SleepTime = 0;
|
||||
systemSettings.ShutdownTime = 0; // No accel -> disable sleep
|
||||
// disable imu sensitivity
|
||||
systemSettings.sensitivity = 0;
|
||||
}
|
||||
|
||||
}
|
||||
inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz, Orientation &rotation) {
|
||||
#ifdef ACCEL_LIS
|
||||
@@ -67,27 +70,34 @@ inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz, Orientation
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_MMA
|
||||
if (DetectedAccelerometerVersion == 1) {
|
||||
MMA8652FC::getAxisReadings(tx, ty, tz);
|
||||
rotation = MMA8652FC::getOrientation();
|
||||
} else
|
||||
if (DetectedAccelerometerVersion == 1) {
|
||||
MMA8652FC::getAxisReadings(tx, ty, tz);
|
||||
rotation = MMA8652FC::getOrientation();
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_BMA
|
||||
if (DetectedAccelerometerVersion == 3) {
|
||||
BMA223::getAxisReadings(tx, ty, tz);
|
||||
rotation = BMA223::getOrientation();
|
||||
if (DetectedAccelerometerVersion == 3) {
|
||||
BMA223::getAxisReadings(tx, ty, tz);
|
||||
rotation = BMA223::getOrientation();
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_MSA
|
||||
if (DetectedAccelerometerVersion == 4) {
|
||||
MSA301::getAxisReadings(tx, ty, tz);
|
||||
rotation = MSA301::getOrientation();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
//do nothing :(
|
||||
// do nothing :(
|
||||
}
|
||||
}
|
||||
void startMOVTask(void const *argument __unused) {
|
||||
postRToSInit();
|
||||
detectAccelerometerVersion();
|
||||
osDelay(50); //wait ~50ms for setup of accel to finalise
|
||||
osDelay(TICKS_100MS / 2); // wait ~50ms for setup of accel to finalise
|
||||
lastMovementTime = 0;
|
||||
//Mask 2 seconds if we are in autostart so that if user is plugging in and then putting in stand it doesnt wake instantly
|
||||
// Mask 2 seconds if we are in autostart so that if user is plugging in and
|
||||
// then putting in stand it doesnt wake instantly
|
||||
if (systemSettings.autoStartMode)
|
||||
osDelay(2 * TICKS_SECOND);
|
||||
|
||||
@@ -102,7 +112,7 @@ void startMOVTask(void const *argument __unused) {
|
||||
Orientation rotation = ORIENTATION_FLAT;
|
||||
for (;;) {
|
||||
int32_t threshold = 1500 + (9 * 200);
|
||||
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
|
||||
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
|
||||
readAccelerometer(tx, ty, tz, rotation);
|
||||
if (systemSettings.OrientationMode == 2) {
|
||||
if (rotation != ORIENTATION_FLAT) {
|
||||
@@ -142,7 +152,7 @@ void startMOVTask(void const *argument __unused) {
|
||||
lastMovementTime = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
osDelay(100); // Slow down update rate
|
||||
osDelay(TICKS_100MS); // Slow down update rate
|
||||
power_check();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user