From 58c4ecaea66fefa269f689351e5da12a39564d2f Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 13 Oct 2020 18:46:37 +1100 Subject: [PATCH] Starting hall effect support --- workspace/TS100/Core/BSP/BSP.h | 4 +++ .../TS100/Core/BSP/Pine64/Model_Config.h | 3 +- workspace/TS100/Core/BSP/Pine64/postRTOS.cpp | 15 ++++++++ workspace/TS100/Core/Drivers/Si7210.cpp | 35 +++++++++++++++++++ workspace/TS100/Core/Drivers/Si7210.h | 21 +++++++++++ workspace/TS100/Core/Drivers/Si7210_defines.h | 19 ++++++++++ workspace/TS100/Core/Inc/Settings.h | 3 +- workspace/TS100/Core/Threads/GUIThread.cpp | 5 +++ 8 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 workspace/TS100/Core/Drivers/Si7210.cpp create mode 100644 workspace/TS100/Core/Drivers/Si7210.h create mode 100644 workspace/TS100/Core/Drivers/Si7210_defines.h diff --git a/workspace/TS100/Core/BSP/BSP.h b/workspace/TS100/Core/BSP/BSP.h index f1765c0f..74844887 100644 --- a/workspace/TS100/Core/BSP/BSP.h +++ b/workspace/TS100/Core/BSP/BSP.h @@ -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 } diff --git a/workspace/TS100/Core/BSP/Pine64/Model_Config.h b/workspace/TS100/Core/BSP/Pine64/Model_Config.h index 2abb9142..2c6a0c84 100644 --- a/workspace/TS100/Core/BSP/Pine64/Model_Config.h +++ b/workspace/TS100/Core/BSP/Pine64/Model_Config.h @@ -20,7 +20,8 @@ #define POW_QC #define TEMP_TMP36 #define ACCEL_BMA - +#define HALL_SENSOR +#define HALL_SI7210 #define BATTFILTERDEPTH 32 #endif diff --git a/workspace/TS100/Core/BSP/Pine64/postRTOS.cpp b/workspace/TS100/Core/BSP/Pine64/postRTOS.cpp index d0022011..5914270f 100644 --- a/workspace/TS100/Core/BSP/Pine64/postRTOS.cpp +++ b/workspace/TS100/Core/BSP/Pine64/postRTOS.cpp @@ -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; + } diff --git a/workspace/TS100/Core/Drivers/Si7210.cpp b/workspace/TS100/Core/Drivers/Si7210.cpp new file mode 100644 index 00000000..63bf4936 --- /dev/null +++ b/workspace/TS100/Core/Drivers/Si7210.cpp @@ -0,0 +1,35 @@ +/* + * Si7210.cpp + * + * Created on: 5 Oct. 2020 + * Author: Ralim + */ + +#include +#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); +} diff --git a/workspace/TS100/Core/Drivers/Si7210.h b/workspace/TS100/Core/Drivers/Si7210.h new file mode 100644 index 00000000..5f0477b5 --- /dev/null +++ b/workspace/TS100/Core/Drivers/Si7210.h @@ -0,0 +1,21 @@ +/* + * Si7210.h + * + * Created on: 5 Oct. 2020 + * Author: Ralim + */ + +#ifndef CORE_DRIVERS_SI7210_H_ +#define CORE_DRIVERS_SI7210_H_ +#include +class Si7210 { +public: + //Return true if present + static bool detect(); + + static bool init(); + static int16_t read(); +private: +}; + +#endif /* CORE_DRIVERS_SI7210_H_ */ diff --git a/workspace/TS100/Core/Drivers/Si7210_defines.h b/workspace/TS100/Core/Drivers/Si7210_defines.h new file mode 100644 index 00000000..3a7dc13d --- /dev/null +++ b/workspace/TS100/Core/Drivers/Si7210_defines.h @@ -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_ */ diff --git a/workspace/TS100/Core/Inc/Settings.h b/workspace/TS100/Core/Inc/Settings.h index 08e4b830..6ade2cfb 100644 --- a/workspace/TS100/Core/Inc/Settings.h +++ b/workspace/TS100/Core/Inc/Settings.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 diff --git a/workspace/TS100/Core/Threads/GUIThread.cpp b/workspace/TS100/Core/Threads/GUIThread.cpp index 749e3d43..9f5e47f0 100644 --- a/workspace/TS100/Core/Threads/GUIThread.cpp +++ b/workspace/TS100/Core/Threads/GUIThread.cpp @@ -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) {