Starting hall effect support
This commit is contained in:
@@ -51,6 +51,10 @@ uint8_t showBootLogoIfavailable();
|
||||
void delay_ms(uint16_t count) ;
|
||||
//Used to allow knowledge of if usb_pd is being used
|
||||
uint8_t usb_pd_detect();
|
||||
// If the iron has a hall effect sensor in the handle, return an signed count of the reading
|
||||
// If the sensor is single polarity (or polarity insensitive) just return 0..32768
|
||||
int16_t getRawHallEffect();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#define POW_QC
|
||||
#define TEMP_TMP36
|
||||
#define ACCEL_BMA
|
||||
|
||||
#define HALL_SENSOR
|
||||
#define HALL_SI7210
|
||||
|
||||
#define BATTFILTERDEPTH 32
|
||||
#endif
|
||||
|
||||
@@ -9,10 +9,25 @@
|
||||
#include "task.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "fusbpd.h"
|
||||
#include "Si7210.h"
|
||||
|
||||
bool hall_effect_present = false;
|
||||
void postRToSInit() {
|
||||
// Any after RTos setup
|
||||
#ifdef POW_PD
|
||||
//Spawn all of the USB-C processors
|
||||
fusb302_start_processing();
|
||||
#endif
|
||||
#ifdef HALL_SI7210
|
||||
if (Si7210::detect()) {
|
||||
hall_effect_present = Si7210::init();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
int16_t getRawHallEffect() {
|
||||
if (hall_effect_present) {
|
||||
return Si7210::read();
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
35
workspace/TS100/Core/Drivers/Si7210.cpp
Normal file
35
workspace/TS100/Core/Drivers/Si7210.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Si7210.cpp
|
||||
*
|
||||
* Created on: 5 Oct. 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include <Si7210.h>
|
||||
#include "Si7210_defines.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
bool Si7210::detect() {
|
||||
return FRToSI2C::probe(SI7210_ADDRESS);
|
||||
}
|
||||
|
||||
bool Si7210::init() {
|
||||
//Turn on auto increment and sanity check ID
|
||||
uint8_t temp;
|
||||
if (FRToSI2C::Mem_Read(SI7210_ADDRESS, SI7210_REG_ID, &temp, 1)) {
|
||||
// We don't really care what model it is etc, just probing to check its probably this iC
|
||||
if (temp != 0x00 && temp != 0xFF) {
|
||||
temp = 0x01; //turn on auto increment
|
||||
if (FRToSI2C::Mem_Write(SI7210_ADDRESS, SI7210_REG_INCR, &temp, 1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int16_t Si7210::read() {
|
||||
//Read the two regs
|
||||
int16_t temp = 0;
|
||||
FRToSI2C::Mem_Read(SI7210_ADDRESS, SI7210_REG_DATAH,(uint8_t*) &temp, 2);
|
||||
return __builtin_bswap16(temp);
|
||||
}
|
||||
21
workspace/TS100/Core/Drivers/Si7210.h
Normal file
21
workspace/TS100/Core/Drivers/Si7210.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Si7210.h
|
||||
*
|
||||
* Created on: 5 Oct. 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#ifndef CORE_DRIVERS_SI7210_H_
|
||||
#define CORE_DRIVERS_SI7210_H_
|
||||
#include <stdint.h>
|
||||
class Si7210 {
|
||||
public:
|
||||
//Return true if present
|
||||
static bool detect();
|
||||
|
||||
static bool init();
|
||||
static int16_t read();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* CORE_DRIVERS_SI7210_H_ */
|
||||
19
workspace/TS100/Core/Drivers/Si7210_defines.h
Normal file
19
workspace/TS100/Core/Drivers/Si7210_defines.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Si7210_defines.h
|
||||
*
|
||||
* Created on: 5 Oct. 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#ifndef CORE_DRIVERS_SI7210_DEFINES_H_
|
||||
#define CORE_DRIVERS_SI7210_DEFINES_H_
|
||||
|
||||
#define SI7210_ADDRESS (0x30<<1)
|
||||
#define SI7210_REG_ID 0xC0
|
||||
#define SI7210_REG_DATAH 0xC1
|
||||
#define SI7210_REG_DATAL 0xC2
|
||||
#define SI7210_REG_INCR 0xC5
|
||||
|
||||
|
||||
|
||||
#endif /* CORE_DRIVERS_SI7210_DEFINES_H_ */
|
||||
@@ -54,7 +54,8 @@ typedef struct {
|
||||
uint8_t ReverseButtonTempChangeEnabled; // Change the plus and minus button assigment
|
||||
uint16_t TempChangeLongStep; // Change the plus and minus button assigment
|
||||
uint16_t TempChangeShortStep; // Change the plus and minus button assigment
|
||||
|
||||
uint8_t hallEffectMode; //Operating mode of the hall effect sensor
|
||||
int16_t hallEffectThreshold; //Threshold of the halleffect sensor
|
||||
uint32_t padding; // This is here for in case we are not an even divisor so
|
||||
// that nothing gets cut off
|
||||
//MUST BE LAST
|
||||
|
||||
@@ -383,6 +383,11 @@ static bool shouldBeSleeping() {
|
||||
if ((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout() && (xTaskGetTickCount() - lastButtonTime) > getSleepTimeout()) {
|
||||
return true;
|
||||
}
|
||||
#ifdef HALL_SENSOR
|
||||
//If the hall effect sensor is enabled in the build, check if its over threshold, and if so then we force sleep
|
||||
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
static void gui_solderingMode(uint8_t jumpToSleep) {
|
||||
|
||||
Reference in New Issue
Block a user