TS80 Support Stage 1 (#365)
* Estimated pinout into the ioc file * Fix Atollic paths to be somewhat more portable * Add make command * Add rough calls to ADC2 [untested] * Using dual ADC injected modes * Start both ADCs * Move some IRQ's to ram exec * Stabilize PID a bit more * Add in ideas for tip type selection * Update peripheral setup to support TS80 * Add tiptype formula / settings struct * Add function ids to the settings menu * Rough tip selection * Rough out new cal routine for simple tips * Hardware test is fairly close for first pass * Add Simple calibration case [UNTESTED] This adds the calibration option that uses boiling water to the calibration menu. This is untested, and may need gain adjustments before use. * [Feat] Add some QC testing code * Typo fix * Add double button press handler for different rising times * Add hook for jump to sleep mode * QC for 9V Works! * Rough out QC handler, trim out old menu help text thats useless * QC 9V working... Static all the things (Low on ROM)! * Static all I2C to save space * Move QC negotiation into background task so it doesnt block the UI * Input V display works, tune ADC * QC 3 steps working * Start tip R measurements * Impliment tip resistance * Fix up the accel position, link in auto QC stages * Fix tip title * Tip type settings, Static OLED * Revert I2C callbacks * Misc Cleanup * Better Gain value, need to investiate offset * Add model warning * Add TS80 Boot Logo (#367) * Add TS80 Boot Logo * Refined * Moved down by 1px * Add in power selection 18/24W * Clean up accelerometer, fix TS100 builds, Fix voltage div cal
This commit is contained in:
@@ -250,7 +250,18 @@ void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin);
|
||||
*/
|
||||
/* IO operation functions *****************************************************/
|
||||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
|
||||
inline void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
||||
{
|
||||
|
||||
if(PinState != GPIO_PIN_RESET)
|
||||
{
|
||||
GPIOx->BSRR = GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
|
||||
}
|
||||
}
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
|
||||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
|
||||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
|
||||
|
||||
@@ -479,21 +479,8 @@ GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
||||
* @arg GPIO_BIT_SET: to set the port pin
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
||||
{
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_PIN_ACTION(PinState));
|
||||
//void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
||||
|
||||
if(PinState != GPIO_PIN_RESET)
|
||||
{
|
||||
GPIOx->BSRR = GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the specified GPIO pin
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,8 @@
|
||||
|
||||
OUTPUT_EXE=TS100_$(lang)
|
||||
ifndef model
|
||||
model:=TS100
|
||||
endif
|
||||
OUTPUT_EXE=$(model)_$(lang)
|
||||
ifndef lang
|
||||
lang:= EN
|
||||
endif
|
||||
@@ -36,7 +39,7 @@ OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color
|
||||
|
||||
|
||||
# global defines ---------------------------------------------------------------
|
||||
GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG
|
||||
GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model)
|
||||
|
||||
# Enable debug code generation
|
||||
DEBUG=-g
|
||||
|
||||
@@ -11,29 +11,30 @@
|
||||
#include "cmsis_os.h"
|
||||
|
||||
class FRToSI2C {
|
||||
public:
|
||||
public:
|
||||
|
||||
FRToSI2C(I2C_HandleTypeDef *i2chandle) : i2c(i2chandle),
|
||||
I2CSemaphore(nullptr) {
|
||||
}
|
||||
static void init(I2C_HandleTypeDef *i2chandle) {i2c=i2chandle;
|
||||
I2CSemaphore=nullptr;}
|
||||
|
||||
void FRToSInit() {
|
||||
static void FRToSInit() {
|
||||
I2CSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
|
||||
void CpltCallback(); //Normal Tx Callback
|
||||
static void CpltCallback(); //Normal Tx Callback
|
||||
|
||||
void Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize,
|
||||
uint8_t *pData, uint16_t Size);
|
||||
void Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
|
||||
static void Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize,
|
||||
uint8_t *pData, uint16_t Size);
|
||||
static void Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
|
||||
|
||||
void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
|
||||
static void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
|
||||
static void I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data);
|
||||
static uint8_t I2C_RegisterRead(uint8_t address, uint8_t reg);
|
||||
|
||||
private:
|
||||
I2C_HandleTypeDef *i2c;
|
||||
SemaphoreHandle_t I2CSemaphore;
|
||||
private:
|
||||
static I2C_HandleTypeDef *i2c;
|
||||
static SemaphoreHandle_t I2CSemaphore;
|
||||
};
|
||||
|
||||
#endif /* FRTOSI2C_HPP_ */
|
||||
|
||||
@@ -102,12 +102,12 @@
|
||||
#define configMAX_PRIORITIES ( 4 )
|
||||
#define configMINIMAL_STACK_SIZE ((uint16_t)256)
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)10240) /*Currently use about 9000*/
|
||||
#define configMAX_TASK_NAME_LEN ( 48 )
|
||||
#define configMAX_TASK_NAME_LEN ( 24 )
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 8
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 0 /*Bump this to 2 during development and bug hunting*/
|
||||
|
||||
|
||||
/* Co-routine definitions. */
|
||||
@@ -117,10 +117,10 @@
|
||||
/* Set the following definitions to 1 to include the API function, or zero
|
||||
to exclude the API function. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 0
|
||||
#define INCLUDE_vTaskDelete 0
|
||||
#define INCLUDE_vTaskCleanUpResources 0
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskSuspend 0
|
||||
#define INCLUDE_vTaskDelayUntil 0
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 1
|
||||
|
||||
@@ -14,15 +14,29 @@
|
||||
|
||||
class LIS2DH12 {
|
||||
public:
|
||||
LIS2DH12(FRToSI2C* i2cHandle) : i2c(i2cHandle) {}
|
||||
void initalize();
|
||||
Orientation getOrientation() { return static_cast<Orientation>((I2C_RegisterRead(LIS_INT2_SRC) >> 2) - 1); }
|
||||
void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
|
||||
static void initalize();
|
||||
//1 = rh, 2,=lh, 8=flat
|
||||
static Orientation getOrientation() {
|
||||
#ifdef MODEL_TS80
|
||||
uint8_t val = (FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS,
|
||||
LIS_INT2_SRC) >> 2);
|
||||
if (val == 8)
|
||||
val = 3;
|
||||
else if (val==1)
|
||||
val=0;
|
||||
else if(val==2)
|
||||
val=1;
|
||||
else
|
||||
val=3;
|
||||
return static_cast<Orientation>(val);
|
||||
#endif
|
||||
#ifdef MODEL_TS100
|
||||
return static_cast<Orientation>((FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS,LIS_INT2_SRC) >> 2) - 1);
|
||||
#endif
|
||||
}
|
||||
static void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
|
||||
|
||||
private:
|
||||
void I2C_RegisterWrite(uint8_t reg, uint8_t data);
|
||||
uint8_t I2C_RegisterRead(uint8_t reg);
|
||||
FRToSI2C* i2c;
|
||||
};
|
||||
|
||||
#endif /* LIS2DH12_HPP_ */
|
||||
|
||||
@@ -16,17 +16,12 @@ class MMA8652FC {
|
||||
|
||||
public:
|
||||
|
||||
MMA8652FC(FRToSI2C* i2cHandle) : i2c(i2cHandle) {}
|
||||
void initalize(); // Initalize the system
|
||||
Orientation getOrientation();// Reads the I2C register and returns the orientation (true == left)
|
||||
void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
|
||||
|
||||
static void initalize(); // Initalize the system
|
||||
static Orientation getOrientation();// Reads the I2C register and returns the orientation (true == left)
|
||||
static void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
|
||||
|
||||
private:
|
||||
|
||||
void I2C_RegisterWrite(uint8_t reg, uint8_t data);
|
||||
uint8_t I2C_RegisterRead(uint8_t reg);
|
||||
FRToSI2C* i2c;
|
||||
|
||||
};
|
||||
|
||||
#endif /* MMA8652FC_HPP_ */
|
||||
|
||||
@@ -26,79 +26,83 @@ extern "C" {
|
||||
#define OLED_WIDTH 96
|
||||
#define FRAMEBUFFER_START 17
|
||||
|
||||
|
||||
class OLED {
|
||||
public:
|
||||
OLED(FRToSI2C* i2cHandle); // Initialize Driver and store I2C pointer
|
||||
void initialize(); // Startup the I2C coms (brings screen out of reset etc)
|
||||
|
||||
static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
|
||||
|
||||
// Draw the buffer out to the LCD using the DMA Channel
|
||||
void refresh() {
|
||||
i2c->Transmit( DEVICEADDR_OLED, screenBuffer, FRAMEBUFFER_START + (OLED_WIDTH * 2));
|
||||
static void refresh() {
|
||||
FRToSI2C::Transmit( DEVICEADDR_OLED, screenBuffer,
|
||||
FRAMEBUFFER_START + (OLED_WIDTH * 2));
|
||||
//DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
|
||||
//or we need to goto double buffering
|
||||
}
|
||||
|
||||
void drawChar(char c, char preCursorCommand = '\0'); // Draw a character to a specific location
|
||||
static void drawChar(char c, char preCursorCommand = '\0'); // Draw a character to a specific location
|
||||
// Turn the screen on or not
|
||||
void displayOnOff(bool on) {
|
||||
static void displayOnOff(bool on) {
|
||||
displayOnOffState = on;
|
||||
screenBuffer[1] = on ? 0xAF : 0xAE;
|
||||
}
|
||||
void setRotation(bool leftHanded); // Set the rotation for the screen
|
||||
}
|
||||
static void setRotation(bool leftHanded); // Set the rotation for the screen
|
||||
// Get the current rotation of the LCD
|
||||
bool getRotation() const {
|
||||
static bool getRotation() {
|
||||
return inLeftHandedMode;
|
||||
}
|
||||
void print(const char* string); // Draw a string to the current location, with current font
|
||||
}
|
||||
static int16_t getCursorX() {
|
||||
return cursor_x;
|
||||
}
|
||||
static void print(const char* string);// Draw a string to the current location, with current font
|
||||
// Set the cursor location by pixels
|
||||
void setCursor(int16_t x, int16_t y) {
|
||||
static void setCursor(int16_t x, int16_t y) {
|
||||
cursor_x = x;
|
||||
cursor_y = y;
|
||||
}
|
||||
cursor_y = y;
|
||||
}
|
||||
//Set cursor location by chars in current font
|
||||
void setCharCursor(int16_t x, int16_t y) {
|
||||
static void setCharCursor(int16_t x, int16_t y) {
|
||||
cursor_x = x * fontWidth;
|
||||
cursor_y = y * fontHeight;
|
||||
}
|
||||
void setFont(uint8_t fontNumber); // (Future) Set the font that is being used
|
||||
void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
|
||||
static void setFont(uint8_t fontNumber); // (Future) Set the font that is being used
|
||||
static void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
|
||||
drawArea(x, 0, width, 16, buffer);
|
||||
}
|
||||
// Draws an image to the buffer, at x offset from top to bottom (fixed height renders)
|
||||
void printNumber(uint16_t number, uint8_t places);
|
||||
static void printNumber(uint16_t number, uint8_t places);
|
||||
// Draws a number at the current cursor location
|
||||
// Clears the buffer
|
||||
void clearScreen() {
|
||||
static void clearScreen() {
|
||||
memset(&screenBuffer[FRAMEBUFFER_START], 0, OLED_WIDTH * 2);
|
||||
}
|
||||
}
|
||||
// Draws the battery level symbol
|
||||
void drawBattery(uint8_t state) {
|
||||
static void drawBattery(uint8_t state) {
|
||||
drawSymbol(3 + (state > 10 ? 10 : state));
|
||||
}
|
||||
}
|
||||
// Draws a checkbox
|
||||
void drawCheckbox(bool state) {
|
||||
static void drawCheckbox(bool state) {
|
||||
drawSymbol((state) ? 16 : 17);
|
||||
}
|
||||
void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width
|
||||
void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
|
||||
void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset
|
||||
void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,bool clear);
|
||||
void drawHeatSymbol(uint8_t state);
|
||||
static void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width
|
||||
static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
|
||||
static void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset
|
||||
static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
|
||||
bool clear);
|
||||
static void drawHeatSymbol(uint8_t state);
|
||||
private:
|
||||
|
||||
//Draw a buffer to the screen buffer
|
||||
|
||||
FRToSI2C* i2c; //i2c Pointer
|
||||
const uint8_t* currentFont; // Pointer to the current font used for rendering to the buffer
|
||||
uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
|
||||
uint8_t* secondStripPtr; //Pointers to the strips
|
||||
bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
|
||||
bool displayOnOffState; // If the display is on or not
|
||||
uint8_t fontWidth, fontHeight;
|
||||
int16_t cursor_x, cursor_y;
|
||||
uint8_t displayOffset;
|
||||
uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
|
||||
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer
|
||||
static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
|
||||
static uint8_t* secondStripPtr; //Pointers to the strips
|
||||
static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
|
||||
static bool displayOnOffState; // If the display is on or not
|
||||
static uint8_t fontWidth, fontHeight;
|
||||
static int16_t cursor_x, cursor_y;
|
||||
static uint8_t displayOffset;
|
||||
static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
|
||||
};
|
||||
|
||||
#endif /* OLED_HPP_ */
|
||||
|
||||
@@ -11,36 +11,45 @@
|
||||
#define SETTINGS_H_
|
||||
#include <stdint.h>
|
||||
#include "stm32f1xx_hal.h"
|
||||
#define SETTINGSVERSION 0x15 /*Change this if you change the struct below to prevent people getting out of sync*/
|
||||
#define SETTINGSVERSION \
|
||||
0x16 /*Change this if you change the struct below to prevent people getting \
|
||||
out of sync*/
|
||||
|
||||
/*
|
||||
* This struct must be a multiple of 2 bytes as it is saved / restored from flash in uint16_t chunks
|
||||
* This struct must be a multiple of 2 bytes as it is saved / restored from
|
||||
* flash in uint16_t chunks
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t SolderingTemp; //current set point for the iron
|
||||
uint16_t SleepTemp; //temp to drop to in sleep
|
||||
uint8_t SleepTime; //minutes timeout to sleep
|
||||
uint8_t cutoutSetting; // The voltage we cut out at for under voltage
|
||||
uint8_t OrientationMode:2; //If true we want to invert the display for lefties
|
||||
uint8_t sensitivity :4; //Sensitivity of accelerometer (5 bits)
|
||||
uint8_t autoStartMode :2; //Should the unit automatically jump straight into soldering mode when power is applied
|
||||
uint8_t ShutdownTime; //Time until unit shuts down if left alone
|
||||
uint8_t boostModeEnabled :1; //Boost mode swaps BUT_A in soldering mode to temporary soldering temp over-ride
|
||||
uint8_t coolingTempBlink :1; //Should the temperature blink on the cool down screen until its <50C
|
||||
uint8_t detailedIDLE :1; //Detailed idle screen
|
||||
uint8_t detailedSoldering :1; //Detailed soldering screens
|
||||
uint8_t temperatureInF; //Should the temp be in F or C (true is F)
|
||||
uint8_t descriptionScrollSpeed:1; // Description scroll speed
|
||||
uint16_t voltageDiv; //Voltage divisor factor
|
||||
uint16_t BoostTemp; //Boost mode set point for the iron
|
||||
int16_t CalibrationOffset; //This stores the temperature offset for this tip in the iron.
|
||||
uint8_t PID_P; //PID P Term
|
||||
uint8_t PID_I; //PID I Term
|
||||
uint8_t PID_D; //PID D Term
|
||||
uint8_t version; //Used to track if a reset is needed on firmware upgrade
|
||||
uint8_t customTipGain; // Tip gain value if custom tuned, or 0 if using a tipType param
|
||||
uint16_t SolderingTemp; // current set point for the iron
|
||||
uint16_t SleepTemp; // temp to drop to in sleep
|
||||
uint8_t SleepTime; // minutes timeout to sleep
|
||||
uint8_t cutoutSetting; // The voltage we cut out at for under voltage OR Power level for TS80
|
||||
uint8_t OrientationMode :2; // If true we want to invert the display for lefties
|
||||
uint8_t sensitivity :4; // Sensitivity of accelerometer (5 bits)
|
||||
uint8_t autoStartMode :2; // Should the unit automatically jump straight
|
||||
// into soldering mode when power is applied
|
||||
uint8_t ShutdownTime; // Time until unit shuts down if left alone
|
||||
uint8_t boostModeEnabled :1; // Boost mode swaps BUT_A in soldering mode to
|
||||
// temporary soldering temp over-ride
|
||||
uint8_t coolingTempBlink :1; // Should the temperature blink on the cool
|
||||
// down screen until its <50C
|
||||
uint8_t detailedIDLE :1; // Detailed idle screen
|
||||
uint8_t detailedSoldering :1; // Detailed soldering screens
|
||||
uint8_t temperatureInF; // Should the temp be in F or C (true is F)
|
||||
uint8_t descriptionScrollSpeed :1; // Description scroll speed
|
||||
uint16_t voltageDiv; // Voltage divisor factor
|
||||
uint16_t BoostTemp; // Boost mode set point for the iron
|
||||
int16_t CalibrationOffset; // This stores the temperature offset for this tip
|
||||
// in the iron.
|
||||
uint8_t PID_P; // PID P Term
|
||||
uint8_t PID_I; // PID I Term
|
||||
uint8_t PID_D; // PID D Term
|
||||
uint8_t version; // Used to track if a reset is needed on firmware upgrade
|
||||
uint8_t customTipGain; // Tip gain value if custom tuned, or 0 if using a
|
||||
// tipType param
|
||||
uint8_t tipType;
|
||||
uint32_t padding; //This is here for in case we are not an even divisor so that nothing gets cut off
|
||||
uint32_t padding; // This is here for in case we are not an even divisor so
|
||||
// that nothing gets cut off
|
||||
} systemSettingsType;
|
||||
|
||||
extern volatile systemSettingsType systemSettings;
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#define TRANSLATION_H_
|
||||
|
||||
enum ShortNameType {
|
||||
SHORT_NAME_SINGLE_LINE = 1, SHORT_NAME_DOUBLE_LINE = 2,
|
||||
SHORT_NAME_SINGLE_LINE = 1,
|
||||
SHORT_NAME_DOUBLE_LINE = 2,
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -17,10 +18,9 @@ enum ShortNameType {
|
||||
* use SettingsShortNames as SettingsShortNames[16][1].. second column undefined
|
||||
*/
|
||||
extern const enum ShortNameType SettingsShortNameType;
|
||||
extern const char* SettingsShortNames[][2];
|
||||
extern const char* SettingsDescriptions[];
|
||||
extern const char* SettingsShortNames[21][2];
|
||||
extern const char* SettingsDescriptions[21];
|
||||
extern const char* SettingsMenuEntries[4];
|
||||
extern const char* SettingsMenuEntriesDescriptions[4];
|
||||
|
||||
extern const char* SettingsCalibrationDone;
|
||||
extern const char* SettingsCalibrationWarning;
|
||||
|
||||
@@ -7,36 +7,38 @@
|
||||
|
||||
#ifndef HARDWARE_H_
|
||||
#define HARDWARE_H_
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "Setup.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum Orientation {
|
||||
ORIENTATION_LEFT_HAND = 0, ORIENTATION_RIGHT_HAND = 1, ORIENTATION_FLAT = 3
|
||||
};
|
||||
/*
|
||||
* Keep in a uint8_t range for the ID's
|
||||
*/
|
||||
enum TipType {
|
||||
TS_B2 = 0,
|
||||
TS_D24 = 1,
|
||||
TS_BC2 = 2,
|
||||
TS_C1 = 3,
|
||||
Tip_MiniWare=4,
|
||||
HAKKO_BC2=4,
|
||||
Tip_Hakko=5,
|
||||
Tip_Custom=5,
|
||||
ORIENTATION_LEFT_HAND = 0,
|
||||
ORIENTATION_RIGHT_HAND = 1,
|
||||
ORIENTATION_FLAT = 3
|
||||
};
|
||||
#ifndef MODEL_TS100
|
||||
#ifndef MODEL_TS80
|
||||
#error "Please Define the model you are building for! MODEL=TS100 or MODEL=TS80"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_TS100
|
||||
|
||||
#define KEY_B_Pin GPIO_PIN_6
|
||||
#define KEY_B_GPIO_Port GPIOA
|
||||
#define TMP36_INPUT_Pin GPIO_PIN_7
|
||||
#define TMP36_INPUT_GPIO_Port GPIOA
|
||||
#define TMP36_ADC1_CHANNEL ADC_CHANNEL_7
|
||||
#define TIP_TEMP_Pin GPIO_PIN_0
|
||||
#define TIP_TEMP_GPIO_Port GPIOB
|
||||
#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_8
|
||||
#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_8
|
||||
#define VIN_Pin GPIO_PIN_1
|
||||
#define VIN_GPIO_Port GPIOB
|
||||
#define VIN_ADC1_CHANNEL ADC_CHANNEL_9
|
||||
#define VIN_ADC2_CHANNEL ADC_CHANNEL_9
|
||||
#define OLED_RESET_Pin GPIO_PIN_8
|
||||
#define OLED_RESET_GPIO_Port GPIOA
|
||||
#define KEY_A_Pin GPIO_PIN_9
|
||||
@@ -45,6 +47,8 @@ enum TipType {
|
||||
#define INT_Orientation_GPIO_Port GPIOB
|
||||
#define PWM_Out_Pin GPIO_PIN_4
|
||||
#define PWM_Out_GPIO_Port GPIOB
|
||||
#define PWM_Out_CHANNEL TIM_CHANNEL_1
|
||||
#define PWM_Out_CCR
|
||||
#define INT_Movement_Pin GPIO_PIN_5
|
||||
#define INT_Movement_GPIO_Port GPIOB
|
||||
#define SCL_Pin GPIO_PIN_6
|
||||
@@ -52,6 +56,64 @@ enum TipType {
|
||||
#define SDA_Pin GPIO_PIN_7
|
||||
#define SDA_GPIO_Port GPIOB
|
||||
|
||||
#else
|
||||
// TS80 pin map
|
||||
#define KEY_B_Pin GPIO_PIN_0
|
||||
#define KEY_B_GPIO_Port GPIOB
|
||||
#define TMP36_INPUT_Pin GPIO_PIN_4
|
||||
#define TMP36_INPUT_GPIO_Port GPIOA
|
||||
#define TMP36_ADC1_CHANNEL ADC_CHANNEL_4
|
||||
#define TIP_TEMP_Pin GPIO_PIN_3
|
||||
#define TIP_TEMP_GPIO_Port GPIOA
|
||||
#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_3
|
||||
#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_3
|
||||
|
||||
#define VIN_Pin GPIO_PIN_2
|
||||
#define VIN_GPIO_Port GPIOA
|
||||
#define VIN_ADC1_CHANNEL ADC_CHANNEL_2
|
||||
#define VIN_ADC2_CHANNEL ADC_CHANNEL_2
|
||||
#define OLED_RESET_Pin GPIO_PIN_15
|
||||
#define OLED_RESET_GPIO_Port GPIOA
|
||||
#define KEY_A_Pin GPIO_PIN_1
|
||||
#define KEY_A_GPIO_Port GPIOB
|
||||
#define INT_Orientation_Pin GPIO_PIN_4
|
||||
#define INT_Orientation_GPIO_Port GPIOB
|
||||
#define PWM_Out_Pin GPIO_PIN_6
|
||||
#define PWM_Out_GPIO_Port GPIOA
|
||||
#define PWM_Out_CHANNEL TIM_CHANNEL_1
|
||||
#define INT_Movement_Pin GPIO_PIN_5
|
||||
#define INT_Movement_GPIO_Port GPIOB
|
||||
#define SCL_Pin GPIO_PIN_6
|
||||
#define SCL_GPIO_Port GPIOB
|
||||
#define SDA_Pin GPIO_PIN_7
|
||||
#define SDA_GPIO_Port GPIOB
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Keep in a uint8_t range for the ID's
|
||||
*/
|
||||
#ifdef MODEL_TS100
|
||||
enum TipType {
|
||||
TS_B2 = 0,
|
||||
TS_D24 = 1,
|
||||
TS_BC2 = 2,
|
||||
TS_C1 = 3,
|
||||
Tip_MiniWare = 4,
|
||||
HAKKO_BC2 = 4,
|
||||
Tip_Hakko = 5,
|
||||
Tip_Custom = 5,
|
||||
};
|
||||
#endif
|
||||
#ifdef MODEL_TS80
|
||||
enum TipType {
|
||||
TS_B02 = 0,
|
||||
TS_D25 = 1,
|
||||
Tip_MiniWare = 2,
|
||||
Tip_Custom = 2,
|
||||
};
|
||||
#endif
|
||||
|
||||
uint16_t getHandleTemperature();
|
||||
uint16_t getTipRawTemp(uint8_t instant);
|
||||
uint16_t getInputVoltageX10(uint16_t divisor);
|
||||
@@ -62,9 +124,17 @@ uint16_t ctoTipMeasurement(uint16_t temp);
|
||||
uint16_t tipMeasurementToC(uint16_t raw);
|
||||
uint16_t ftoTipMeasurement(uint16_t temp);
|
||||
uint16_t tipMeasurementToF(uint16_t raw);
|
||||
|
||||
void seekQC(int16_t Vx10);
|
||||
void setCalibrationOffset(int16_t offSet);
|
||||
void setTipType(enum TipType tipType, uint8_t manualCalGain);
|
||||
uint32_t calculateTipR(uint8_t useFilter);
|
||||
int16_t calculateMaxVoltage(uint8_t useFilter, uint8_t useHP);
|
||||
void startQC(); // Tries to negotiate QC for highest voltage, must be run after
|
||||
// RToS
|
||||
// This will try for 12V, failing that 9V, failing that 5V
|
||||
// If input is over 12V returns -1
|
||||
// If the input is [5-12] Will return the value.
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2,25 +2,23 @@
|
||||
#define __MAIN_H
|
||||
|
||||
#include <MMA8652FC.hpp>
|
||||
#include "Setup.h"
|
||||
#include "OLED.hpp"
|
||||
extern uint16_t currentlyActiveTemperatureTarget;
|
||||
extern OLED lcd;
|
||||
extern MMA8652FC accel;
|
||||
#include "Setup.h"
|
||||
extern uint8_t PCBVersion;
|
||||
extern uint16_t currentlyActiveTemperatureTarget;
|
||||
enum ButtonState {
|
||||
BUTTON_NONE = 0, /* No buttons pressed / < filter time*/
|
||||
BUTTON_F_SHORT = 1, /* User has pressed the front button*/
|
||||
BUTTON_B_SHORT = 2, /* User has pressed the back button*/
|
||||
BUTTON_F_LONG = 4, /* User is holding the front button*/
|
||||
BUTTON_B_LONG = 8, /* User is holding the back button*/
|
||||
BUTTON_BOTH = 16, /* User has pressed both buttons*/
|
||||
BUTTON_NONE = 0, /* No buttons pressed / < filter time*/
|
||||
BUTTON_F_SHORT = 1, /* User has pressed the front button*/
|
||||
BUTTON_B_SHORT = 2, /* User has pressed the back button*/
|
||||
BUTTON_F_LONG = 4, /* User is holding the front button*/
|
||||
BUTTON_B_LONG = 8, /* User is holding the back button*/
|
||||
BUTTON_BOTH = 16, /* User has pressed both buttons*/
|
||||
|
||||
/*
|
||||
* Note:
|
||||
* Pressed means press + release, we trigger on a full \__/ pulse
|
||||
* holding means it has gone low, and been low for longer than filter time
|
||||
*/
|
||||
/*
|
||||
* Note:
|
||||
* Pressed means press + release, we trigger on a full \__/ pulse
|
||||
* holding means it has gone low, and been low for longer than filter time
|
||||
*/
|
||||
};
|
||||
|
||||
ButtonState getButtonState();
|
||||
@@ -31,15 +29,15 @@ void GUIDelay();
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc);
|
||||
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc);
|
||||
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
|
||||
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
|
||||
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
|
||||
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
|
||||
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
|
||||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
|
||||
void vApplicationStackOverflowHook( xTaskHandle *pxTask,
|
||||
signed portCHAR *pcTaskName);
|
||||
void vApplicationStackOverflowHook(xTaskHandle *pxTask,
|
||||
signed portCHAR *pcTaskName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -7,82 +7,85 @@
|
||||
|
||||
#include "FRToSI2C.hpp"
|
||||
|
||||
void __attribute__ ((long_call, section (".data.ramfuncs"))) FRToSI2C::CpltCallback() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
i2c->State = HAL_I2C_STATE_READY;//Force state reset
|
||||
if (I2CSemaphore) {
|
||||
xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
I2C_HandleTypeDef* FRToSI2C::i2c;
|
||||
SemaphoreHandle_t FRToSI2C::I2CSemaphore;
|
||||
void FRToSI2C::CpltCallback() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
i2c->State = HAL_I2C_STATE_READY; // Force state reset (even if tx error)
|
||||
if (I2CSemaphore) {
|
||||
xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
|
||||
|| I2CSemaphore == NULL) {
|
||||
//no RToS, run blocking code
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
} else {
|
||||
//RToS is active, run threading
|
||||
//Get the mutex so we can use the I2C port
|
||||
//Wait up to 1 second for the mutex
|
||||
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) {
|
||||
if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData,
|
||||
Size, 5000) != HAL_OK) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
} else {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
if (I2CSemaphore == NULL) {
|
||||
// no RToS, run blocking code
|
||||
HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
} else {
|
||||
// RToS is active, run threading
|
||||
// Get the mutex so we can use the I2C port
|
||||
// Wait up to 1 second for the mutex
|
||||
if (xSemaphoreTake(I2CSemaphore, (TickType_t)5000) == pdTRUE) {
|
||||
if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000) != HAL_OK) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
} else {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
void FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) {
|
||||
Mem_Write(address, reg, I2C_MEMADD_SIZE_8BIT, &data, 1);
|
||||
}
|
||||
|
||||
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
||||
uint8_t tx_data[1];
|
||||
Mem_Read(add, reg, I2C_MEMADD_SIZE_8BIT, tx_data, 1);
|
||||
return tx_data[0];
|
||||
}
|
||||
void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
|
||||
|| I2CSemaphore == NULL) {
|
||||
//no RToS, run blocking code
|
||||
HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
} else {
|
||||
//RToS is active, run threading
|
||||
//Get the mutex so we can use the I2C port
|
||||
//Wait up to 1 second for the mutex
|
||||
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) {
|
||||
if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize,
|
||||
pData, Size, 5000) != HAL_OK) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
uint16_t MemAddSize, uint8_t* pData, uint16_t Size) {
|
||||
if (I2CSemaphore == NULL) {
|
||||
// no RToS, run blocking code
|
||||
HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size,
|
||||
5000);
|
||||
} else {
|
||||
// RToS is active, run threading
|
||||
// Get the mutex so we can use the I2C port
|
||||
// Wait up to 1 second for the mutex
|
||||
if (xSemaphoreTake(I2CSemaphore, (TickType_t)5000) == pdTRUE) {
|
||||
if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData,
|
||||
Size, 5000) != HAL_OK) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
|
||||
} else {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED
|
||||
|| I2CSemaphore == NULL) {
|
||||
//no RToS, run blocking code
|
||||
HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
|
||||
} else {
|
||||
//RToS is active, run threading
|
||||
//Get the mutex so we can use the I2C port
|
||||
//Wait up to 1 second for the mutex
|
||||
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) {
|
||||
if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size)
|
||||
!= HAL_OK) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
//xSemaphoreGive(I2CSemaphore);
|
||||
} else {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
if (I2CSemaphore == NULL) {
|
||||
// no RToS, run blocking code
|
||||
HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000);
|
||||
} else {
|
||||
// RToS is active, run threading
|
||||
// Get the mutex so we can use the I2C port
|
||||
// Wait up to 1 second for the mutex
|
||||
if (xSemaphoreTake(I2CSemaphore, (TickType_t)5000) == pdTRUE) {
|
||||
if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size) != HAL_OK) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
// xSemaphoreGive(I2CSemaphore);
|
||||
} else {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <LIS2DH12.hpp>
|
||||
#include "cmsis_os.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
const uint8_t reg;
|
||||
const uint8_t value;
|
||||
@@ -31,13 +32,13 @@ static const LIS_REG i2c_registers[] = {
|
||||
|
||||
void LIS2DH12::initalize() {
|
||||
for (size_t index = 0; index < (sizeof(i2c_registers) / sizeof(i2c_registers[0])); index++) {
|
||||
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].value);
|
||||
FRToSI2C::I2C_RegisterWrite(LIS2DH_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].value);
|
||||
}
|
||||
}
|
||||
|
||||
void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) {
|
||||
uint8_t tempArr[6];
|
||||
i2c->Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT,
|
||||
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT,
|
||||
(uint8_t*) tempArr, 6);
|
||||
|
||||
(*x) = ((uint16_t) (tempArr[1] << 8 | tempArr[0]));
|
||||
@@ -45,13 +46,4 @@ void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) {
|
||||
(*z) = ((uint16_t) (tempArr[5] << 8 | tempArr[4]));
|
||||
}
|
||||
|
||||
void LIS2DH12::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
|
||||
i2c->Mem_Write(LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1);
|
||||
|
||||
}
|
||||
|
||||
uint8_t LIS2DH12::I2C_RegisterRead(uint8_t reg) {
|
||||
uint8_t tx_data[1];
|
||||
i2c->Mem_Read( LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, tx_data, 1);
|
||||
return tx_data[0];
|
||||
}
|
||||
|
||||
@@ -9,55 +9,47 @@
|
||||
#include "cmsis_os.h"
|
||||
|
||||
typedef struct {
|
||||
const uint8_t reg;
|
||||
const uint8_t val;
|
||||
const uint8_t reg;
|
||||
const uint8_t val;
|
||||
} MMA_REG;
|
||||
|
||||
static const MMA_REG i2c_registers[] = {
|
||||
{CTRL_REG2, 0}, //Normal mode
|
||||
{CTRL_REG2, 0x40}, // Reset all registers to POR values
|
||||
{FF_MT_CFG_REG, 0x78}, // Enable motion detection for X, Y, Z axis, latch disabled
|
||||
{PL_CFG_REG, 0x40}, //Enable the orientation detection
|
||||
{PL_COUNT_REG, 200}, //200 count debounce
|
||||
{PL_BF_ZCOMP_REG, 0b01000111}, //Set the threshold to 42 degrees
|
||||
{P_L_THS_REG, 0b10011100}, //Up the trip angles
|
||||
{CTRL_REG4, 0x01 | (1 << 4)}, // Enable dataready interrupt & orientation interrupt
|
||||
{CTRL_REG5, 0x01}, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
||||
{CTRL_REG2, 0x12}, //Set maximum resolution oversampling
|
||||
{XYZ_DATA_CFG_REG, (1 << 4)}, //select high pass filtered data
|
||||
{HP_FILTER_CUTOFF_REG, 0x03}, //select high pass filtered data
|
||||
{CTRL_REG1, 0x19} // ODR=12 Hz, Active mode
|
||||
static const MMA_REG i2c_registers[] = { { CTRL_REG2, 0 }, //Normal mode
|
||||
{ CTRL_REG2, 0x40 }, // Reset all registers to POR values
|
||||
{ FF_MT_CFG_REG, 0x78 }, // Enable motion detection for X, Y, Z axis, latch disabled
|
||||
{ PL_CFG_REG, 0x40 }, //Enable the orientation detection
|
||||
{ PL_COUNT_REG, 200 }, //200 count debounce
|
||||
{ PL_BF_ZCOMP_REG, 0b01000111 }, //Set the threshold to 42 degrees
|
||||
{ P_L_THS_REG, 0b10011100 }, //Up the trip angles
|
||||
{ CTRL_REG4, 0x01 | (1 << 4) }, // Enable dataready interrupt & orientation interrupt
|
||||
{ CTRL_REG5, 0x01 }, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
||||
{ CTRL_REG2, 0x12 }, //Set maximum resolution oversampling
|
||||
{ XYZ_DATA_CFG_REG, (1 << 4) }, //select high pass filtered data
|
||||
{ HP_FILTER_CUTOFF_REG, 0x03 }, //select high pass filtered data
|
||||
{ CTRL_REG1, 0x19 } // ODR=12 Hz, Active mode
|
||||
};
|
||||
|
||||
void MMA8652FC::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
|
||||
i2c->Mem_Write( MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1);
|
||||
}
|
||||
|
||||
uint8_t MMA8652FC::I2C_RegisterRead(uint8_t reg) {
|
||||
uint8_t tx_data[1];
|
||||
i2c->Mem_Read( MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, tx_data,
|
||||
1);
|
||||
|
||||
return tx_data[0];
|
||||
}
|
||||
void MMA8652FC::initalize() {
|
||||
size_t index = 0;
|
||||
|
||||
//send all the init commands to the unit
|
||||
|
||||
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++;
|
||||
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++;
|
||||
FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].val);
|
||||
index++;
|
||||
FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].val);
|
||||
index++;
|
||||
|
||||
HAL_Delay(2); // ~1ms delay
|
||||
|
||||
while (index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]))) {
|
||||
I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++;
|
||||
FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].val);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
Orientation MMA8652FC::getOrientation() {
|
||||
//First read the PL_STATUS register
|
||||
uint8_t plStatus = I2C_RegisterRead(PL_STATUS_REG);
|
||||
uint8_t plStatus = FRToSI2C::I2C_RegisterRead(MMA8652FC_I2C_ADDRESS,PL_STATUS_REG);
|
||||
if ((plStatus & 0b10000000) == 0b10000000) {
|
||||
plStatus >>= 1; //We don't need the up/down bit
|
||||
plStatus &= 0x03; //mask to the two lower bits
|
||||
@@ -67,12 +59,13 @@ Orientation MMA8652FC::getOrientation() {
|
||||
|
||||
return static_cast<Orientation>(plStatus);
|
||||
}
|
||||
|
||||
|
||||
return ORIENTATION_FLAT;
|
||||
}
|
||||
void MMA8652FC::getAxisReadings(int16_t *x, int16_t *y, int16_t *z) {
|
||||
uint8_t tempArr[6];
|
||||
i2c->Mem_Read( MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG,I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6);
|
||||
FRToSI2C::Mem_Read( MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG, I2C_MEMADD_SIZE_8BIT,
|
||||
(uint8_t*) tempArr, 6);
|
||||
|
||||
(*x) = tempArr[0] << 8 | tempArr[1];
|
||||
(*y) = tempArr[2] << 8 | tempArr[3];
|
||||
|
||||
@@ -5,69 +5,81 @@
|
||||
* Author: Ben V. Brown
|
||||
*/
|
||||
|
||||
#include <OLED.hpp>
|
||||
#include <string.h>
|
||||
#include <OLED.hpp>
|
||||
#include "Translation.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
const uint8_t* OLED::currentFont; // Pointer to the current font used for
|
||||
// rendering to the buffer
|
||||
uint8_t* OLED::firstStripPtr; // Pointers to the strips to allow for buffer
|
||||
// having extra content
|
||||
uint8_t* OLED::secondStripPtr; // Pointers to the strips
|
||||
bool OLED::inLeftHandedMode; // Whether the screen is in left or not (used for
|
||||
// offsets in GRAM)
|
||||
bool OLED::displayOnOffState; // If the display is on or not
|
||||
uint8_t OLED::fontWidth, OLED::fontHeight;
|
||||
int16_t OLED::cursor_x, OLED::cursor_y;
|
||||
uint8_t OLED::displayOffset;
|
||||
uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
|
||||
|
||||
/*Setup params for the OLED screen*/
|
||||
/*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/
|
||||
/*All commands are prefixed with 0x80*/
|
||||
/*Data packets are prefixed with 0x40*/
|
||||
uint8_t OLED_Setup_Array[] = { /**/
|
||||
0x80, 0xAE,/*Display off*/
|
||||
0x80, 0xD5,/*Set display clock divide ratio / osc freq*/
|
||||
0x80, 0x52,/*Divide ratios*/
|
||||
0x80, 0xA8,/*Set Multiplex Ratio*/
|
||||
0x80, 0x0F,/*16 == max brightness,39==dimmest*/
|
||||
0x80, 0xC0,/*Set COM Scan direction*/
|
||||
0x80, 0xD3,/*Set vertical Display offset*/
|
||||
0x80, 0x00,/*0 Offset*/
|
||||
0x80, 0x40,/*Set Display start line to 0*/
|
||||
0x80, 0xA0,/*Set Segment remap to normal*/
|
||||
0x80, 0x8D,/*Charge Pump*/
|
||||
0x80, 0x14,/*Charge Pump settings*/
|
||||
0x80, 0xDA,/*Set VCOM Pins hardware config*/
|
||||
0x80, 0x02,/*Combination 2*/
|
||||
0x80, 0x81,/*Contrast*/
|
||||
0x80, 0x33,/*^51*/
|
||||
0x80, 0xD9,/*Set pre-charge period*/
|
||||
0x80, 0xF1,/*Pre charge period*/
|
||||
0x80, 0xDB,/*Adjust VCOMH regulator ouput*/
|
||||
0x80, 0x30,/*VCOM level*/
|
||||
0x80, 0xA4,/*Enable the display GDDR*/
|
||||
0x80, 0XA6,/*Normal display*/
|
||||
0x80, 0x20,/*Memory Mode*/
|
||||
0x80, 0x00,/*Wrap memory*/
|
||||
0x80, 0xAF /*Display on*/
|
||||
uint8_t OLED_Setup_Array[] = {
|
||||
/**/
|
||||
0x80, 0xAE, /*Display off*/
|
||||
0x80, 0xD5, /*Set display clock divide ratio / osc freq*/
|
||||
0x80, 0x52, /*Divide ratios*/
|
||||
0x80, 0xA8, /*Set Multiplex Ratio*/
|
||||
0x80, 0x0F, /*16 == max brightness,39==dimmest*/
|
||||
0x80, 0xC0, /*Set COM Scan direction*/
|
||||
0x80, 0xD3, /*Set vertical Display offset*/
|
||||
0x80, 0x00, /*0 Offset*/
|
||||
0x80, 0x40, /*Set Display start line to 0*/
|
||||
0x80, 0xA0, /*Set Segment remap to normal*/
|
||||
0x80, 0x8D, /*Charge Pump*/
|
||||
0x80, 0x14, /*Charge Pump settings*/
|
||||
0x80, 0xDA, /*Set VCOM Pins hardware config*/
|
||||
0x80, 0x02, /*Combination 2*/
|
||||
0x80, 0x81, /*Contrast*/
|
||||
0x80, 0x33, /*^51*/
|
||||
0x80, 0xD9, /*Set pre-charge period*/
|
||||
0x80, 0xF1, /*Pre charge period*/
|
||||
0x80, 0xDB, /*Adjust VCOMH regulator ouput*/
|
||||
0x80, 0x30, /*VCOM level*/
|
||||
0x80, 0xA4, /*Enable the display GDDR*/
|
||||
0x80, 0XA6, /*Normal display*/
|
||||
0x80, 0x20, /*Memory Mode*/
|
||||
0x80, 0x00, /*Wrap memory*/
|
||||
0x80, 0xAF /*Display on*/
|
||||
};
|
||||
//Setup based on the SSD1307 and modified for the SSD1306
|
||||
// Setup based on the SSD1307 and modified for the SSD1306
|
||||
|
||||
const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80,
|
||||
0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 };
|
||||
|
||||
OLED::OLED(FRToSI2C* i2cHandle) {
|
||||
i2c = i2cHandle;
|
||||
cursor_x = cursor_y = 0;
|
||||
currentFont = FONT_12;
|
||||
fontWidth = 12;
|
||||
inLeftHandedMode = false;
|
||||
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
|
||||
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
|
||||
fontHeight = 16;
|
||||
displayOffset = 0;
|
||||
displayOnOffState = true;
|
||||
}
|
||||
const uint8_t REFRESH_COMMANDS[17] = {0x80, 0xAF, 0x80, 0x21, 0x80, 0x20,
|
||||
0x80, 0x7F, 0x80, 0xC0, 0x80, 0x22,
|
||||
0x80, 0x00, 0x80, 0x01, 0x40};
|
||||
|
||||
void OLED::initialize() {
|
||||
memcpy(&screenBuffer[0], &REFRESH_COMMANDS[0], sizeof(REFRESH_COMMANDS));
|
||||
cursor_x = cursor_y = 0;
|
||||
currentFont = FONT_12;
|
||||
fontWidth = 12;
|
||||
inLeftHandedMode = false;
|
||||
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
|
||||
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
|
||||
fontHeight = 16;
|
||||
displayOffset = 0;
|
||||
displayOnOffState = true;
|
||||
memcpy(&screenBuffer[0], &REFRESH_COMMANDS[0], sizeof(REFRESH_COMMANDS));
|
||||
|
||||
HAL_Delay(50);
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(50);
|
||||
//Send the setup settings
|
||||
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array,
|
||||
sizeof(OLED_Setup_Array));
|
||||
displayOnOff(true);
|
||||
HAL_Delay(50);
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(50);
|
||||
// Send the setup settings
|
||||
FRToSI2C::Transmit(DEVICEADDR_OLED, (uint8_t*)OLED_Setup_Array,
|
||||
sizeof(OLED_Setup_Array));
|
||||
displayOnOff(true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -76,259 +88,262 @@ void OLED::initialize() {
|
||||
* Precursor is the command char that is used to select the table.
|
||||
*/
|
||||
void OLED::drawChar(char c, char PrecursorCommand) {
|
||||
if (c == '\n' && cursor_y == 0) {
|
||||
cursor_x = 0;
|
||||
cursor_y = 8;
|
||||
}
|
||||
if (c < ' ') {
|
||||
return;
|
||||
}
|
||||
uint16_t index = 0;
|
||||
if (PrecursorCommand == 0) {
|
||||
//Fonts are offset to start at the space char
|
||||
index = (c - ' ');
|
||||
} else {
|
||||
//This is for extended range
|
||||
//We decode the precursor command to find the offset
|
||||
//Latin starts at 96
|
||||
c -= 0x80;
|
||||
if (c == '\n' && cursor_y == 0) {
|
||||
cursor_x = 0;
|
||||
cursor_y = 8;
|
||||
}
|
||||
if (c < ' ') {
|
||||
return;
|
||||
}
|
||||
uint16_t index = 0;
|
||||
if (PrecursorCommand == 0) {
|
||||
// Fonts are offset to start at the space char
|
||||
index = (c - ' ');
|
||||
} else {
|
||||
// This is for extended range
|
||||
// We decode the precursor command to find the offset
|
||||
// Latin starts at 96
|
||||
c -= 0x80;
|
||||
|
||||
switch (PrecursorCommand) {
|
||||
|
||||
case 0xC2:
|
||||
index = (96 - 32) + (c);
|
||||
break; //-32 compensate for chars excluded from font C2 section
|
||||
case 0xC3:
|
||||
index = (128) + (c);
|
||||
break;
|
||||
#if defined(LANG_RU) || defined(LANG_UK) || defined(LANG_SR) || defined(LANG_BG) || defined(LANG_MK)
|
||||
case 0xD0:
|
||||
index = (192) + (c);
|
||||
break;
|
||||
case 0xD1:
|
||||
index = (256) + (c);
|
||||
break;
|
||||
switch (PrecursorCommand) {
|
||||
case 0xC2:
|
||||
index = (96 - 32) + (c);
|
||||
break; //-32 compensate for chars excluded from font C2 section
|
||||
case 0xC3:
|
||||
index = (128) + (c);
|
||||
break;
|
||||
#if defined(LANG_RU) || defined(LANG_UK) || defined(LANG_SR) || \
|
||||
defined(LANG_BG) || defined(LANG_MK)
|
||||
case 0xD0:
|
||||
index = (192) + (c);
|
||||
break;
|
||||
case 0xD1:
|
||||
index = (256) + (c);
|
||||
break;
|
||||
#else
|
||||
case 0xC4:
|
||||
index = (192) + (c);
|
||||
break;
|
||||
case 0xC5:
|
||||
index = (256) + (c);
|
||||
break;
|
||||
case 0xC4:
|
||||
index = (192) + (c);
|
||||
break;
|
||||
case 0xC5:
|
||||
index = (256) + (c);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
uint8_t* charPointer;
|
||||
charPointer = ((uint8_t*) currentFont)
|
||||
+ ((fontWidth * (fontHeight / 8)) * index);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
uint8_t* charPointer;
|
||||
charPointer =
|
||||
((uint8_t*)currentFont) + ((fontWidth * (fontHeight / 8)) * index);
|
||||
|
||||
drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer);
|
||||
drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer);
|
||||
|
||||
cursor_x += fontWidth;
|
||||
cursor_x += fontWidth;
|
||||
}
|
||||
|
||||
void OLED::setRotation(bool leftHanded) {
|
||||
if (inLeftHandedMode == leftHanded) {
|
||||
return;
|
||||
}
|
||||
if (inLeftHandedMode == leftHanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
//send command struct again with changes
|
||||
if (leftHanded) {
|
||||
OLED_Setup_Array[11] = 0xC8; //c1?
|
||||
OLED_Setup_Array[19] = 0xA1;
|
||||
} else {
|
||||
OLED_Setup_Array[11] = 0xC0;
|
||||
OLED_Setup_Array[19] = 0xA0;
|
||||
}
|
||||
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array,
|
||||
sizeof(OLED_Setup_Array));
|
||||
inLeftHandedMode = leftHanded;
|
||||
// send command struct again with changes
|
||||
if (leftHanded) {
|
||||
OLED_Setup_Array[11] = 0xC8; // c1?
|
||||
OLED_Setup_Array[19] = 0xA1;
|
||||
} else {
|
||||
OLED_Setup_Array[11] = 0xC0;
|
||||
OLED_Setup_Array[19] = 0xA0;
|
||||
}
|
||||
FRToSI2C::Transmit(DEVICEADDR_OLED, (uint8_t*)OLED_Setup_Array,
|
||||
sizeof(OLED_Setup_Array));
|
||||
inLeftHandedMode = leftHanded;
|
||||
|
||||
screenBuffer[5] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide
|
||||
screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide)
|
||||
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
|
||||
screenBuffer[5] =
|
||||
inLeftHandedMode ? 0 : 32; // display is shifted by 32 in left handed
|
||||
// mode as driver ram is 128 wide
|
||||
screenBuffer[7] =
|
||||
inLeftHandedMode
|
||||
? 95
|
||||
: 0x7F; // End address of the ram segment we are writing to (96 wide)
|
||||
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
|
||||
}
|
||||
|
||||
//print a string to the current cursor location
|
||||
// print a string to the current cursor location
|
||||
void OLED::print(const char* str) {
|
||||
while (str[0]) {
|
||||
if (str[0] >= 0x80) {
|
||||
drawChar(str[1], str[0]);
|
||||
str++; //skip this marker
|
||||
} else
|
||||
drawChar(str[0]);
|
||||
str++;
|
||||
}
|
||||
while (str[0]) {
|
||||
if (str[0] >= 0x80) {
|
||||
drawChar(str[1], str[0]);
|
||||
str++; // skip this marker
|
||||
} else
|
||||
drawChar(str[0]);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::setFont(uint8_t fontNumber) {
|
||||
if (fontNumber == 1) {
|
||||
//small font
|
||||
currentFont = FONT_6x8;
|
||||
fontHeight = 8;
|
||||
fontWidth = 6;
|
||||
} else if (fontNumber == 2) {
|
||||
currentFont = ExtraFontChars;
|
||||
fontHeight = 16;
|
||||
fontWidth = 12;
|
||||
} else {
|
||||
currentFont = FONT_12;
|
||||
fontHeight = 16;
|
||||
fontWidth = 12;
|
||||
}
|
||||
if (fontNumber == 1) {
|
||||
// small font
|
||||
currentFont = FONT_6x8;
|
||||
fontHeight = 8;
|
||||
fontWidth = 6;
|
||||
} else if (fontNumber == 2) {
|
||||
currentFont = ExtraFontChars;
|
||||
fontHeight = 16;
|
||||
fontWidth = 12;
|
||||
} else {
|
||||
currentFont = FONT_12;
|
||||
fontHeight = 16;
|
||||
fontWidth = 12;
|
||||
}
|
||||
}
|
||||
|
||||
//maximum places is 5
|
||||
// maximum places is 5
|
||||
void OLED::printNumber(uint16_t number, uint8_t places) {
|
||||
char buffer[7] = { 0 };
|
||||
char buffer[7] = {0};
|
||||
|
||||
if (places >= 5) {
|
||||
buffer[5] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
if (places > 4) {
|
||||
buffer[4] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
if (places >= 5) {
|
||||
buffer[5] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
if (places > 4) {
|
||||
buffer[4] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
if (places > 3) {
|
||||
buffer[3] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
if (places > 3) {
|
||||
buffer[3] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
if (places > 2) {
|
||||
buffer[2] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
if (places > 2) {
|
||||
buffer[2] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
if (places > 1) {
|
||||
buffer[1] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
if (places > 1) {
|
||||
buffer[1] = '0' + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
buffer[0] = '0' + number % 10;
|
||||
number /= 10;
|
||||
print(buffer);
|
||||
buffer[0] = '0' + number % 10;
|
||||
number /= 10;
|
||||
print(buffer);
|
||||
}
|
||||
|
||||
void OLED::drawSymbol(uint8_t symbolID) {
|
||||
//draw a symbol to the current cursor location
|
||||
setFont(2);
|
||||
drawChar(' ' + symbolID); // space offset is in all fonts, so we pad it here and remove it later
|
||||
setFont(0);
|
||||
// draw a symbol to the current cursor location
|
||||
setFont(2);
|
||||
drawChar(' ' + symbolID); // space offset is in all fonts, so we pad it here
|
||||
// and remove it later
|
||||
setFont(0);
|
||||
}
|
||||
|
||||
//Draw an area, but y must be aligned on 0/8 offset
|
||||
// Draw an area, but y must be aligned on 0/8 offset
|
||||
void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t* ptr) {
|
||||
// Splat this from x->x+wide in two strides
|
||||
if (x <= -wide)
|
||||
return; //cutoffleft
|
||||
if (x > 96)
|
||||
return; //cutoff right
|
||||
const uint8_t* ptr) {
|
||||
// Splat this from x->x+wide in two strides
|
||||
if (x <= -wide) return; // cutoffleft
|
||||
if (x > 96) return; // cutoff right
|
||||
|
||||
uint8_t visibleStart = 0;
|
||||
uint8_t visibleEnd = wide;
|
||||
uint8_t visibleStart = 0;
|
||||
uint8_t visibleEnd = wide;
|
||||
|
||||
// trimming to draw partials
|
||||
if (x < 0) {
|
||||
visibleStart -= x; //subtract negative value == add absolute value
|
||||
}
|
||||
if (x + wide > 96) {
|
||||
visibleEnd = 96 - x;
|
||||
}
|
||||
// trimming to draw partials
|
||||
if (x < 0) {
|
||||
visibleStart -= x; // subtract negative value == add absolute value
|
||||
}
|
||||
if (x + wide > 96) {
|
||||
visibleEnd = 96 - x;
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
//Splat first line of data
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
firstStripPtr[xx + x] = ptr[xx];
|
||||
}
|
||||
}
|
||||
if (y == 8 || height == 16) {
|
||||
// Splat the second line
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)];
|
||||
}
|
||||
}
|
||||
if (y == 0) {
|
||||
// Splat first line of data
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
firstStripPtr[xx + x] = ptr[xx];
|
||||
}
|
||||
}
|
||||
if (y == 8 || height == 16) {
|
||||
// Splat the second line
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)];
|
||||
}
|
||||
}
|
||||
}
|
||||
void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t value) {
|
||||
// Splat this from x->x+wide in two strides
|
||||
if (x <= -wide)
|
||||
return; //cutoffleft
|
||||
if (x > 96)
|
||||
return; //cutoff right
|
||||
const uint8_t value) {
|
||||
// Splat this from x->x+wide in two strides
|
||||
if (x <= -wide) return; // cutoffleft
|
||||
if (x > 96) return; // cutoff right
|
||||
|
||||
uint8_t visibleStart = 0;
|
||||
uint8_t visibleEnd = wide;
|
||||
uint8_t visibleStart = 0;
|
||||
uint8_t visibleEnd = wide;
|
||||
|
||||
// trimming to draw partials
|
||||
if (x < 0) {
|
||||
visibleStart -= x; //subtract negative value == add absolute value
|
||||
}
|
||||
if (x + wide > 96) {
|
||||
visibleEnd = 96 - x;
|
||||
}
|
||||
// trimming to draw partials
|
||||
if (x < 0) {
|
||||
visibleStart -= x; // subtract negative value == add absolute value
|
||||
}
|
||||
if (x + wide > 96) {
|
||||
visibleEnd = 96 - x;
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
//Splat first line of data
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
firstStripPtr[xx + x] = value;
|
||||
}
|
||||
}
|
||||
if (y == 8 || height == 16) {
|
||||
// Splat the second line
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
secondStripPtr[x + xx] = value;
|
||||
}
|
||||
}
|
||||
if (y == 0) {
|
||||
// Splat first line of data
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
firstStripPtr[xx + x] = value;
|
||||
}
|
||||
}
|
||||
if (y == 8 || height == 16) {
|
||||
// Splat the second line
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
secondStripPtr[x + xx] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
|
||||
bool clear) {
|
||||
//Draw this in 3 sections
|
||||
//This is basically a N wide version of vertical line
|
||||
bool clear) {
|
||||
// Draw this in 3 sections
|
||||
// This is basically a N wide version of vertical line
|
||||
|
||||
//Step 1 : Draw in the top few pixels that are not /8 aligned
|
||||
//LSB is at the top of the screen
|
||||
uint8_t mask = 0xFF;
|
||||
if (y0) {
|
||||
mask = mask << (y0 % 8);
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
if (clear)
|
||||
firstStripPtr[(y0 / 8) * 96 + col] &= ~mask;
|
||||
else
|
||||
firstStripPtr[(y0 / 8) * 96 + col] |= mask;
|
||||
}
|
||||
//Next loop down the line the total number of solids
|
||||
if (y0 / 8 != y1 / 8)
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
for (uint8_t r = (y0 / 8); r < (y1 / 8); r++) {
|
||||
//This gives us the row index r
|
||||
if (clear)
|
||||
firstStripPtr[(r * 96) + col] = 0;
|
||||
else
|
||||
firstStripPtr[(r * 96) + col] = 0xFF;
|
||||
}
|
||||
// Step 1 : Draw in the top few pixels that are not /8 aligned
|
||||
// LSB is at the top of the screen
|
||||
uint8_t mask = 0xFF;
|
||||
if (y0) {
|
||||
mask = mask << (y0 % 8);
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
if (clear)
|
||||
firstStripPtr[(y0 / 8) * 96 + col] &= ~mask;
|
||||
else
|
||||
firstStripPtr[(y0 / 8) * 96 + col] |= mask;
|
||||
}
|
||||
// Next loop down the line the total number of solids
|
||||
if (y0 / 8 != y1 / 8)
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
for (uint8_t r = (y0 / 8); r < (y1 / 8); r++) {
|
||||
// This gives us the row index r
|
||||
if (clear)
|
||||
firstStripPtr[(r * 96) + col] = 0;
|
||||
else
|
||||
firstStripPtr[(r * 96) + col] = 0xFF;
|
||||
}
|
||||
|
||||
//Finally draw the tail
|
||||
mask = ~(mask << (y1 % 8));
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
if (clear)
|
||||
firstStripPtr[(y1 / 8) * 96 + col] &= ~mask;
|
||||
else
|
||||
firstStripPtr[(y1 / 8) * 96 + col] |= mask;
|
||||
// Finally draw the tail
|
||||
mask = ~(mask << (y1 % 8));
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
if (clear)
|
||||
firstStripPtr[(y1 / 8) * 96 + col] &= ~mask;
|
||||
else
|
||||
firstStripPtr[(y1 / 8) * 96 + col] |= mask;
|
||||
}
|
||||
|
||||
void OLED::drawHeatSymbol(uint8_t state) {
|
||||
//Draw symbol 14
|
||||
//Then draw over it botom 5 pixels always stay. 8 pixels above that are the levels
|
||||
state /= 12; // 0-> 8 range
|
||||
//Then we want to draw down (16-(5+state)
|
||||
uint8_t cursor_x_temp = cursor_x;
|
||||
drawSymbol(14);
|
||||
drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true);
|
||||
// Draw symbol 14
|
||||
// Then draw over it, the bottom 5 pixels always stay. 8 pixels above that are
|
||||
// the levels masks the symbol nicely
|
||||
state /= 12; // 0-> 8 range
|
||||
// Then we want to draw down (16-(5+state)
|
||||
uint8_t cursor_x_temp = cursor_x;
|
||||
drawSymbol(14);
|
||||
drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true);
|
||||
}
|
||||
|
||||
@@ -4,61 +4,62 @@
|
||||
* Created on: 29 Sep 2016
|
||||
* Author: Ralim
|
||||
*
|
||||
* This file holds the users settings and saves / restores them to the devices flash
|
||||
* This file holds the users settings and saves / restores them to the
|
||||
* devices flash
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Setup.h"
|
||||
#define FLASH_ADDR (0x8000000|0xFC00)/*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
||||
#define FLASH_ADDR \
|
||||
(0x8000000 | \
|
||||
0xFC00) /*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
||||
#include "string.h"
|
||||
volatile systemSettingsType systemSettings;
|
||||
|
||||
void saveSettings() {
|
||||
//First we erase the flash
|
||||
FLASH_EraseInitTypeDef pEraseInit;
|
||||
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
pEraseInit.Banks = FLASH_BANK_1;
|
||||
pEraseInit.NbPages = 1;
|
||||
pEraseInit.PageAddress = FLASH_ADDR;
|
||||
uint32_t failingAddress = 0;
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
__HAL_FLASH_CLEAR_FLAG(
|
||||
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
||||
HAL_FLASH_Unlock();
|
||||
HAL_Delay(10);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
||||
//^ Erase the page of flash (1024 bytes on this stm32)
|
||||
//erased the chunk
|
||||
//now we program it
|
||||
uint16_t *data = (uint16_t*) &systemSettings;
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2),
|
||||
data[i]);
|
||||
}
|
||||
HAL_FLASH_Lock();
|
||||
// First we erase the flash
|
||||
FLASH_EraseInitTypeDef pEraseInit;
|
||||
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
pEraseInit.Banks = FLASH_BANK_1;
|
||||
pEraseInit.NbPages = 1;
|
||||
pEraseInit.PageAddress = FLASH_ADDR;
|
||||
uint32_t failingAddress = 0;
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR |
|
||||
FLASH_FLAG_BSY);
|
||||
HAL_FLASH_Unlock();
|
||||
HAL_Delay(10);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
||||
//^ Erase the page of flash (1024 bytes on this stm32)
|
||||
// erased the chunk
|
||||
// now we program it
|
||||
uint16_t *data = (uint16_t *)&systemSettings;
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2),
|
||||
data[i]);
|
||||
}
|
||||
HAL_FLASH_Lock();
|
||||
}
|
||||
|
||||
void restoreSettings() {
|
||||
//We read the flash
|
||||
uint16_t *data = (uint16_t*) &systemSettings;
|
||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
||||
data[i] = *((uint16_t*) (FLASH_ADDR + (i * 2)));
|
||||
}
|
||||
|
||||
//if the version is correct were done
|
||||
//if not we reset and save
|
||||
if (systemSettings.version != SETTINGSVERSION) {
|
||||
//probably not setup
|
||||
resetSettings();
|
||||
}
|
||||
// We read the flash
|
||||
uint16_t *data = (uint16_t *)&systemSettings;
|
||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
||||
data[i] = *((uint16_t *)(FLASH_ADDR + (i * 2)));
|
||||
}
|
||||
|
||||
// if the version is correct were done
|
||||
// if not we reset and save
|
||||
if (systemSettings.version != SETTINGSVERSION) {
|
||||
// probably not setup
|
||||
resetSettings();
|
||||
}
|
||||
}
|
||||
//Lookup function for cutoff setting -> X10 voltage
|
||||
// Lookup function for cutoff setting -> X10 voltage
|
||||
/*
|
||||
* 0=DC
|
||||
* 1=3S
|
||||
@@ -67,36 +68,54 @@ void restoreSettings() {
|
||||
* 4=6S
|
||||
*/
|
||||
uint8_t lookupVoltageLevel(uint8_t level) {
|
||||
if (level == 0)
|
||||
return 90; //9V since iron does not function effectively below this
|
||||
else
|
||||
return (level * 33) + (33 * 2);
|
||||
if (level == 0)
|
||||
return 90; // 9V since iron does not function effectively below this
|
||||
else
|
||||
return (level * 33) + (33 * 2);
|
||||
}
|
||||
void resetSettings() {
|
||||
memset((void*) &systemSettings, 0, sizeof(systemSettingsType));
|
||||
systemSettings.SleepTemp = 150; //Temperature the iron sleeps at - default 150.0 C
|
||||
systemSettings.SleepTime = 6; //How many seconds/minutes we wait until going to sleep - default 1 min
|
||||
systemSettings.SolderingTemp = 320; //Default soldering temp is 320.0 C
|
||||
systemSettings.cutoutSetting = 0; //default to no cut-off voltage
|
||||
systemSettings.version = SETTINGSVERSION;//Store the version number to allow for easier upgrades
|
||||
systemSettings.detailedSoldering = 0; // Detailed soldering screen
|
||||
systemSettings.detailedIDLE = 0;// Detailed idle screen (off for first time users)
|
||||
systemSettings.OrientationMode = 2; //Default to automatic
|
||||
systemSettings.sensitivity = 7; //Default high sensitivity
|
||||
systemSettings.voltageDiv = 467; //Default divider from schematic
|
||||
systemSettings.ShutdownTime = 10;//How many minutes until the unit turns itself off
|
||||
systemSettings.boostModeEnabled = 1;//Default to safe, with no boost mode
|
||||
systemSettings.BoostTemp = 420; //default to 400C
|
||||
systemSettings.autoStartMode = 0; //Auto start off for safety
|
||||
systemSettings.coolingTempBlink = 0;//Blink the temperature on the cooling screen when its > 50C
|
||||
systemSettings.temperatureInF = 0; //default to 0
|
||||
systemSettings.descriptionScrollSpeed = 0; //default to slow
|
||||
systemSettings.PID_P = 42;
|
||||
systemSettings.PID_I = 50;
|
||||
systemSettings.PID_D = 15;
|
||||
systemSettings.CalibrationOffset = 2780; // the adc offset
|
||||
systemSettings.customTipGain = 0; // The tip type is either default or a custom gain
|
||||
systemSettings.tipType = TS_B2;
|
||||
saveSettings();
|
||||
}
|
||||
memset((void *)&systemSettings, 0, sizeof(systemSettingsType));
|
||||
systemSettings.SleepTemp =
|
||||
150; // Temperature the iron sleeps at - default 150.0 C
|
||||
systemSettings.SleepTime = 6; // How many seconds/minutes we wait until going
|
||||
// to sleep - default 1 min
|
||||
systemSettings.SolderingTemp = 320; // Default soldering temp is 320.0 C
|
||||
systemSettings.cutoutSetting = 0; // default to no cut-off voltage (or 18W for TS80)
|
||||
systemSettings.version =
|
||||
SETTINGSVERSION; // Store the version number to allow for easier upgrades
|
||||
systemSettings.detailedSoldering = 0; // Detailed soldering screen
|
||||
systemSettings.detailedIDLE =
|
||||
0; // Detailed idle screen (off for first time users)
|
||||
systemSettings.OrientationMode = 2; // Default to automatic
|
||||
systemSettings.sensitivity = 7; // Default high sensitivity
|
||||
#ifdef MODEL_TS80
|
||||
systemSettings.voltageDiv = 780; // Default divider from schematic
|
||||
|
||||
#else
|
||||
systemSettings.voltageDiv = 467; // Default divider from schematic
|
||||
#endif
|
||||
systemSettings.ShutdownTime =
|
||||
10; // How many minutes until the unit turns itself off
|
||||
systemSettings.boostModeEnabled =
|
||||
1; // Default to having boost mode on as most people prefer itF
|
||||
systemSettings.BoostTemp = 420; // default to 400C
|
||||
systemSettings.autoStartMode = 0; // Auto start off for safety
|
||||
systemSettings.coolingTempBlink =
|
||||
0; // Blink the temperature on the cooling screen when its > 50C
|
||||
systemSettings.temperatureInF = 0; // default to 0
|
||||
systemSettings.descriptionScrollSpeed = 0; // default to slow
|
||||
systemSettings.PID_P = 42; // PID tuning constants
|
||||
systemSettings.PID_I = 50;
|
||||
systemSettings.PID_D = 15;
|
||||
systemSettings.CalibrationOffset = 2780; // the adc offset
|
||||
systemSettings.customTipGain =
|
||||
0; // The tip type is either default or a custom gain
|
||||
#ifdef MODEL_TS100
|
||||
systemSettings.tipType = TS_B2; // Default to the B2 Tip
|
||||
#endif
|
||||
#ifdef MODEL_TS80
|
||||
|
||||
systemSettings.tipType = TS_B02; // Default to the B2 Tip
|
||||
#endif
|
||||
saveSettings(); // Save defaults
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ IWDG_HandleTypeDef hiwdg;
|
||||
TIM_HandleTypeDef htim2;
|
||||
TIM_HandleTypeDef htim3;
|
||||
|
||||
uint16_t ADCReadings[64]; //room for 32 lots of the pair of readings
|
||||
uint16_t ADCReadings[64]; // room for 32 lots of the pair of readings
|
||||
|
||||
//Functions
|
||||
// Functions
|
||||
void SystemClock_Config(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_I2C1_Init(void);
|
||||
@@ -31,344 +31,340 @@ static void MX_GPIO_Init(void);
|
||||
static void MX_ADC2_Init(void);
|
||||
|
||||
void Setup_HAL() {
|
||||
SystemClock_Config();
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_ADC2_Init();
|
||||
MX_TIM3_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_IWDG_Init();
|
||||
HAL_ADC_Start(&hadc2);
|
||||
HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*) ADCReadings, 64); //start DMA of normal readings
|
||||
HAL_ADCEx_InjectedStart(&hadc1); //enable injected readings
|
||||
HAL_ADCEx_InjectedStart(&hadc2); //enable injected readings
|
||||
|
||||
|
||||
SystemClock_Config();
|
||||
__HAL_AFIO_REMAP_SWJ_DISABLE();
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_ADC2_Init();
|
||||
MX_TIM3_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_IWDG_Init();
|
||||
HAL_ADC_Start(&hadc2);
|
||||
HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*)ADCReadings,
|
||||
64); // start DMA of normal readings
|
||||
HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
|
||||
HAL_ADCEx_InjectedStart(&hadc2); // enable injected readings
|
||||
}
|
||||
|
||||
//channel 0 -> temperature sensor, 1-> VIN
|
||||
// channel 0 -> temperature sensor, 1-> VIN
|
||||
uint16_t getADC(uint8_t channel) {
|
||||
uint32_t sum = 0;
|
||||
for (uint8_t i = 0; i < 32; i++)
|
||||
sum += ADCReadings[channel + (i * 2)];
|
||||
return sum >> 2;
|
||||
uint32_t sum = 0;
|
||||
for (uint8_t i = 0; i < 32; i++) sum += ADCReadings[channel + (i * 2)];
|
||||
return sum >> 2;
|
||||
}
|
||||
|
||||
/** System Clock Configuration
|
||||
*/
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
||||
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType =
|
||||
RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = 16;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; // 64MHz
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI
|
||||
| RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = 16;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; //64MHz
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; // TIM
|
||||
// 2,3,4,5,6,7,12,13,14
|
||||
RCC_ClkInitStruct.APB2CLKDivider =
|
||||
RCC_HCLK_DIV1; // 64 mhz to some peripherals and adc
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
|
||||
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; //TIM 2,3,4,5,6,7,12,13,14
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; //64 mhz to some peripherals and adc
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.AdcClockSelection =
|
||||
RCC_ADCPCLK2_DIV6; // 6 or 8 are the only non overclocked options
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
|
||||
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; //6 or 8 are the only non overclocked options
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
|
||||
/**Configure the Systick interrupt time
|
||||
*/
|
||||
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
|
||||
|
||||
/**Configure the Systick interrupt time
|
||||
*/
|
||||
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
|
||||
/**Configure the Systick
|
||||
*/
|
||||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
||||
|
||||
/**Configure the Systick
|
||||
*/
|
||||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
||||
|
||||
/* SysTick_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
|
||||
/* SysTick_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
|
||||
}
|
||||
|
||||
/* ADC1 init function */
|
||||
static void MX_ADC1_Init(void) {
|
||||
ADC_MultiModeTypeDef multimode;
|
||||
ADC_MultiModeTypeDef multimode;
|
||||
|
||||
ADC_ChannelConfTypeDef sConfig;
|
||||
ADC_InjectionConfTypeDef sConfigInjected;
|
||||
/**Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
|
||||
hadc1.Init.ContinuousConvMode = ENABLE;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.NbrOfConversion = 2;
|
||||
HAL_ADC_Init(&hadc1);
|
||||
ADC_ChannelConfTypeDef sConfig;
|
||||
ADC_InjectionConfTypeDef sConfigInjected;
|
||||
/**Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
|
||||
hadc1.Init.ContinuousConvMode = ENABLE;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.NbrOfConversion = 2;
|
||||
HAL_ADC_Init(&hadc1);
|
||||
|
||||
/**Configure the ADC multi-mode
|
||||
*/
|
||||
multimode.Mode = ADC_DUALMODE_REGSIMULT_INJECSIMULT;
|
||||
HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode);
|
||||
/**Configure the ADC multi-mode
|
||||
*/
|
||||
multimode.Mode = ADC_DUALMODE_REGSIMULT_INJECSIMULT;
|
||||
HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode);
|
||||
|
||||
/**Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_7;
|
||||
sConfig.Rank = 1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
/**Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = TMP36_ADC1_CHANNEL;
|
||||
sConfig.Rank = 1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
|
||||
/**Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_9;
|
||||
sConfig.Rank = 2;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
/**Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = VIN_ADC1_CHANNEL;
|
||||
sConfig.Rank = 2;
|
||||
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
|
||||
|
||||
/**Configure Injected Channel
|
||||
*/
|
||||
//F in = 10.66 MHz
|
||||
/*
|
||||
* Injected time is 1 delay clock + (12 adc cycles*4)+4*sampletime =~217 clocks = 0.2ms
|
||||
* Charge time is 0.016 uS ideally
|
||||
* So Sampling time must be >= 0.016uS
|
||||
* 1/10.66MHz is 0.09uS, so 1 CLK is *should* be enough
|
||||
* */
|
||||
sConfigInjected.InjectedChannel = ADC_CHANNEL_8;
|
||||
sConfigInjected.InjectedRank = 1;
|
||||
sConfigInjected.InjectedNbrOfConversion = 4;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1;
|
||||
sConfigInjected.AutoInjectedConv = DISABLE;
|
||||
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
||||
sConfigInjected.InjectedOffset = 0;
|
||||
/**Configure Injected Channel
|
||||
*/
|
||||
// F in = 10.66 MHz
|
||||
/*
|
||||
* Injected time is 1 delay clock + (12 adc cycles*4)+4*sampletime =~217
|
||||
* clocks = 0.2ms Charge time is 0.016 uS ideally So Sampling time must be >=
|
||||
* 0.016uS 1/10.66MHz is 0.09uS, so 1 CLK is *should* be enough
|
||||
* */
|
||||
sConfigInjected.InjectedChannel = TIP_TEMP_ADC1_CHANNEL;
|
||||
sConfigInjected.InjectedRank = 1;
|
||||
sConfigInjected.InjectedNbrOfConversion = 4;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1;
|
||||
sConfigInjected.AutoInjectedConv = DISABLE;
|
||||
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
||||
sConfigInjected.InjectedOffset = 0;
|
||||
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||
sConfigInjected.InjectedRank = 2;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = 3;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = 4;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
SET_BIT(hadc1.Instance->CR1, ( ADC_CR1_JEOCIE )); //Enable end of injected conv irq
|
||||
// Run ADC internal calibration
|
||||
while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
|
||||
;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||
sConfigInjected.InjectedRank = 2;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = 3;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = 4;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
|
||||
SET_BIT(hadc1.Instance->CR1,
|
||||
(ADC_CR1_JEOCIE)); // Enable end of injected conv irq
|
||||
// Run ADC internal calibration
|
||||
while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
|
||||
;
|
||||
}
|
||||
|
||||
/* ADC2 init function */
|
||||
static void MX_ADC2_Init(void) {
|
||||
ADC_ChannelConfTypeDef sConfig;
|
||||
ADC_InjectionConfTypeDef sConfigInjected;
|
||||
|
||||
ADC_ChannelConfTypeDef sConfig;
|
||||
ADC_InjectionConfTypeDef sConfigInjected;
|
||||
/**Common config
|
||||
*/
|
||||
hadc2.Instance = ADC2;
|
||||
hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
|
||||
hadc2.Init.ContinuousConvMode = ENABLE;
|
||||
hadc2.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc2.Init.NbrOfConversion = 2;
|
||||
HAL_ADC_Init(&hadc2);
|
||||
|
||||
/**Common config
|
||||
*/
|
||||
hadc2.Instance = ADC2;
|
||||
hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
|
||||
hadc2.Init.ContinuousConvMode = ENABLE;
|
||||
hadc2.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc2.Init.NbrOfConversion = 2;
|
||||
HAL_ADC_Init(&hadc2);
|
||||
/**Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = TIP_TEMP_ADC2_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
|
||||
sConfig.Channel = VIN_ADC2_CHANNEL;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_2;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
|
||||
|
||||
/**Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_8;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
|
||||
sConfig.Channel = ADC_CHANNEL_8;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_2;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
||||
HAL_ADC_ConfigChannel(&hadc2, &sConfig);
|
||||
/**Configure Injected Channel
|
||||
*/
|
||||
sConfigInjected.InjectedChannel = TIP_TEMP_ADC2_CHANNEL;
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
|
||||
sConfigInjected.InjectedNbrOfConversion = 4;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1;
|
||||
sConfigInjected.AutoInjectedConv = DISABLE;
|
||||
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
||||
sConfigInjected.InjectedOffset = 0;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||
|
||||
/**Configure Injected Channel
|
||||
*/
|
||||
sConfigInjected.InjectedChannel = ADC_CHANNEL_8;
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
|
||||
sConfigInjected.InjectedNbrOfConversion = 4;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1;
|
||||
sConfigInjected.AutoInjectedConv = DISABLE;
|
||||
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
||||
sConfigInjected.InjectedOffset = 0;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_4;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
|
||||
// Run ADC internal calibration
|
||||
while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK)
|
||||
;
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_4;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
|
||||
// Run ADC internal calibration
|
||||
while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK)
|
||||
;
|
||||
}
|
||||
/* I2C1 init function */
|
||||
static void MX_I2C1_Init(void) {
|
||||
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000; // OLED doesnt handle >100k when its asleep (off).
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
HAL_I2C_Init(&hi2c1);
|
||||
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed =
|
||||
100000; // OLED doesnt handle >100k when its asleep (off).
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
HAL_I2C_Init(&hi2c1);
|
||||
}
|
||||
|
||||
/* IWDG init function */
|
||||
static void MX_IWDG_Init(void) {
|
||||
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
|
||||
hiwdg.Init.Reload = 100;
|
||||
HAL_IWDG_Init(&hiwdg);
|
||||
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
|
||||
hiwdg.Init.Reload = 100;
|
||||
HAL_IWDG_Init(&hiwdg);
|
||||
}
|
||||
|
||||
/* TIM3 init function */
|
||||
static void MX_TIM3_Init(void) {
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig;
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig;
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 2;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 100; // 10 Khz PWM freq
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before div
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
HAL_TIM_Base_Init(&htim3);
|
||||
|
||||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 2;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 100; //10 Khz PWM freq
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; //4mhz before div
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
HAL_TIM_Base_Init(&htim3);
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);
|
||||
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);
|
||||
HAL_TIM_PWM_Init(&htim3);
|
||||
|
||||
HAL_TIM_PWM_Init(&htim3);
|
||||
HAL_TIM_OC_Init(&htim3);
|
||||
|
||||
HAL_TIM_OC_Init(&htim3);
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
|
||||
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 50;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL);
|
||||
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 50;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/**TIM3 GPIO Configuration
|
||||
PB4 ------> TIM3_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = PWM_Out_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
__HAL_AFIO_REMAP_TIM3_PARTIAL()
|
||||
;
|
||||
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/**TIM3 GPIO Configuration
|
||||
PWM_Out_Pin ------> TIM3_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = PWM_Out_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct);
|
||||
#ifdef MODEL_TS100
|
||||
// Remap TIM3_CH1 to be on pB4
|
||||
__HAL_AFIO_REMAP_TIM3_PARTIAL();
|
||||
#else
|
||||
// No re-map required
|
||||
#endif
|
||||
HAL_TIM_PWM_Start(&htim3, PWM_Out_CHANNEL);
|
||||
}
|
||||
/* TIM3 init function */
|
||||
static void MX_TIM2_Init(void) {
|
||||
/*
|
||||
* We use the channel 1 to trigger the ADC at end of PWM period
|
||||
* And we use the channel 4 as the PWM modulation source using Interrupts
|
||||
* */
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig;
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
/*
|
||||
* We use the channel 1 to trigger the ADC at end of PWM period
|
||||
* And we use the channel 4 as the PWM modulation source using Interrupts
|
||||
* */
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig;
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
//Timer 2 is fairly slow as its being used to run the PWM and trigger the ADC in the PWM off time.
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 2000; // pwm out is 10k, we want to run our PWM at around 100hz
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 122;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; //4mhz before divide
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
HAL_TIM_Base_Init(&htim2);
|
||||
// Timer 2 is fairly slow as its being used to run the PWM and trigger the ADC
|
||||
// in the PWM off time.
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler =
|
||||
2000; // pwm out is 10k, we want to run our PWM at around 100hz
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 122;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before divide
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
HAL_TIM_Base_Init(&htim2);
|
||||
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);
|
||||
|
||||
HAL_TIM_PWM_Init(&htim2);
|
||||
HAL_TIM_OC_Init(&htim2);
|
||||
HAL_TIM_PWM_Init(&htim2);
|
||||
HAL_TIM_OC_Init(&htim2);
|
||||
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);
|
||||
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 118;
|
||||
/*
|
||||
* It takes 4 milliseconds for output to be stable after PWM turns off.
|
||||
* Assume ADC samples in 0.5ms
|
||||
* We need to set this to 100% + 5.5ms
|
||||
* */
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 118;
|
||||
/*
|
||||
* It takes 4 milliseconds for output to be stable after PWM turns off.
|
||||
* Assume ADC samples in 0.5ms
|
||||
* We need to set this to 100% + 5.5ms
|
||||
* */
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);
|
||||
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4);
|
||||
|
||||
HAL_TIM_Base_Start_IT(&htim2);
|
||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Start_IT(&htim2, TIM_CHANNEL_4);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4);
|
||||
|
||||
HAL_TIM_Base_Start_IT(&htim2);
|
||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Start_IT(&htim2, TIM_CHANNEL_4);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void) {
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE()
|
||||
;
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
/* DMA1_Channel6_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
|
||||
/* DMA1_Channel7_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
/* DMA1_Channel6_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
|
||||
/* DMA1_Channel7_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
|
||||
}
|
||||
|
||||
/** Configure pins as
|
||||
@@ -382,71 +378,73 @@ static void MX_DMA_Init(void) {
|
||||
PB1 ------> ADCx_IN9
|
||||
*/
|
||||
static void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
;
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
/*Configure GPIO pins : PD0 PD1 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
/*Configure peripheral I/O remapping */
|
||||
__HAL_AFIO_REMAP_PD01_ENABLE();
|
||||
//^ remap XTAL so that pins can be analog (all input buffers off).
|
||||
// reduces power consumption
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
/*Configure GPIO pins : PD0 PD1 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
/*
|
||||
* Configure All pins as analog by default
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
|
||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
|
||||
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
|
||||
#ifdef MODEL_TS100
|
||||
GPIO_PIN_3 |
|
||||
#endif
|
||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
|
||||
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
|
||||
GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PA0 PA1 PA2 PA3
|
||||
PA4 PA5 PA10 PA15 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3
|
||||
| GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12
|
||||
| GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
#ifdef MODEL_TS100
|
||||
/* Pull USB lines low to disable, pull down debug too*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||
#else
|
||||
/* TS80 */
|
||||
/* Leave USB lines open circuit*/
|
||||
|
||||
//Set PA 11 and PA 12 to GND to stop usb detection, 13/14 re-rused for debug
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||
#endif
|
||||
|
||||
/*Configure GPIO pins : KEY_B_Pin KEY_A_Pin */
|
||||
GPIO_InitStruct.Pin = KEY_B_Pin | KEY_A_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
/*Configure GPIO pins : KEY_B_Pin KEY_A_Pin */
|
||||
GPIO_InitStruct.Pin = KEY_B_Pin | KEY_A_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(KEY_B_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : TIP_TEMP_Pin VIN_Pin PB2 */
|
||||
GPIO_InitStruct.Pin = TIP_TEMP_Pin | VIN_Pin | GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : OLED_RESET_Pin */
|
||||
GPIO_InitStruct.Pin = OLED_RESET_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(OLED_RESET_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/* Configure GPIO pins : INT_Orientation_Pin INT_Movement_Pin */
|
||||
/* Not used anymore*/
|
||||
GPIO_InitStruct.Pin = INT_Orientation_Pin | INT_Movement_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure peripheral I/O remapping */
|
||||
__HAL_AFIO_REMAP_PD01_ENABLE();
|
||||
//^ remap XTAL so that pins can be analog (all input buffers off).
|
||||
// reduces power consumption
|
||||
/*Configure GPIO pin : OLED_RESET_Pin */
|
||||
GPIO_InitStruct.Pin = OLED_RESET_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(OLED_RESET_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
||||
|
||||
// Pull down LCD reset
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(10);
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// WARNING: THIS FILE WAS AUTO GENERATED BY make_translation.py. PLEASE DO NOT EDIT.
|
||||
// WARNING: THIS FILE WAS AUTO GENERATED BY make_translation.py. PLEASE DO NOT
|
||||
// EDIT.
|
||||
|
||||
#include "Translation.h"
|
||||
#ifndef LANG
|
||||
@@ -29,6 +30,7 @@ const char* SettingsDescriptions[] = {
|
||||
/* TipModel */ "Tip Model selection",
|
||||
/* SimpleCalibrationMode */ "Simple Calibration using Hot water",
|
||||
/* AdvancedCalibrationMode */ "Advanced calibration using thermocouple on the tip",
|
||||
/* Power Input */ "The power rating of the power adapter",
|
||||
};
|
||||
|
||||
const char* SettingsCalibrationDone = "Calibration done!";
|
||||
@@ -81,17 +83,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Soldering settings",
|
||||
/* PowerSavingMenu */ "Power saving settings",
|
||||
/* UIMenu */ "User interface settings",
|
||||
/* AdvancedMenu */ "Advanced options",
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -172,17 +167,17 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Поялник\nНастройки",
|
||||
/* PowerSavingMenu */ "Режими\nНастройки",
|
||||
/* UIMenu */ "Интерфейс\nНастройки",
|
||||
/* AdvancedMenu */ "Разширени\nНастройки",
|
||||
/* SolderingMenu */ "Поялник\nНастройки",
|
||||
/* PowerSavingMenu */ "Режими\nНастройки",
|
||||
/* UIMenu */ "Интерфейс\nНастройки",
|
||||
/* AdvancedMenu */ "Разширени\nНастройки",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Настройки на поялника",
|
||||
/* PowerSavingMenu */ "Настройки енергоспестяване",
|
||||
/* UIMenu */ "Настройки на интерфейса",
|
||||
/* AdvancedMenu */ "Допълнителни настройки",
|
||||
/* SolderingMenu */ "Настройки на поялника",
|
||||
/* PowerSavingMenu */ "Настройки енергоспестяване",
|
||||
/* UIMenu */ "Настройки на интерфейса",
|
||||
/* AdvancedMenu */ "Допълнителни настройки",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -263,17 +258,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Pájecí\nnastavení",
|
||||
/* PowerSavingMenu */ "Režim\nspánku",
|
||||
/* UIMenu */ "Uživatelské\nrozhraní",
|
||||
/* AdvancedMenu */ "Pokročilé\nvolby",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Nastavení pájení (boost, auto start...)",
|
||||
/* PowerSavingMenu */ "Nastavení režimu spánku, automatického vypnutí...",
|
||||
/* UIMenu */ "Nastavení uživatelského rozhraní.",
|
||||
/* AdvancedMenu */ "Pokročilé volby (detailní obrazovky, kalibrace, tovární nastavení...)",
|
||||
/* SolderingMenu */ "Pájecí\nnastavení",
|
||||
/* PowerSavingMenu */ "Režim\nspánku",
|
||||
/* UIMenu */ "Uživatelské\nrozhraní",
|
||||
/* AdvancedMenu */ "Pokročilé\nvolby",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -354,17 +342,17 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Löt-\neinstellungen",
|
||||
/* PowerSavingMenu */ "Schlaf-\nmodus",
|
||||
/* UIMenu */ "Menü-\neinstellungen",
|
||||
/* AdvancedMenu */ "Erweiterte\nEinstellungen",
|
||||
/* SolderingMenu */ "Löt-\neinstellungen",
|
||||
/* PowerSavingMenu */ "Schlaf-\nmodus",
|
||||
/* UIMenu */ "Menü-\neinstellungen",
|
||||
/* AdvancedMenu */ "Erweiterte\nEinstellungen",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Löteinstellungen",
|
||||
/* PowerSavingMenu */ "Energiespareinstellungen",
|
||||
/* UIMenu */ "Menüeinstellungen",
|
||||
/* AdvancedMenu */ "Erweiterte Einstellungen",
|
||||
/* SolderingMenu */ "Löteinstellungen",
|
||||
/* PowerSavingMenu */ "Energiespareinstellungen",
|
||||
/* UIMenu */ "Menüeinstellungen",
|
||||
/* AdvancedMenu */ "Erweiterte Einstellungen",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -445,17 +433,17 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Soldering settings",
|
||||
/* PowerSavingMenu */ "Power Saving Settings",
|
||||
/* UIMenu */ "User Interface settings",
|
||||
/* AdvancedMenu */ "Advanced options",
|
||||
/* SolderingMenu */ "Soldering settings",
|
||||
/* PowerSavingMenu */ "Power Saving Settings",
|
||||
/* UIMenu */ "User Interface settings",
|
||||
/* AdvancedMenu */ "Advanced options",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -536,17 +524,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Opciones de\nSoldadura",
|
||||
/* PowerSavingMenu */ "Modos de\nReposo",
|
||||
/* UIMenu */ "Interfaz\nde Usuario",
|
||||
/* AdvancedMenu */ "Opciones\nAvanzadas",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Opciones de Soldadura",
|
||||
/* PowerSavingMenu */ "Opciones de ahorro energético",
|
||||
/* UIMenu */ "Opciones de interfaz de usuario",
|
||||
/* AdvancedMenu */ "Opciones avanzadas",
|
||||
/* SolderingMenu */ "Opciones de\nSoldadura",
|
||||
/* PowerSavingMenu */ "Modos de\nReposo",
|
||||
/* UIMenu */ "Interfaz\nde Usuario",
|
||||
/* AdvancedMenu */ "Opciones\nAvanzadas",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -627,17 +608,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Juotos-\nasetukset",
|
||||
/* PowerSavingMenu */ "Lepotilan\nasetukset",
|
||||
/* UIMenu */ "Käyttö-\nliittymä",
|
||||
/* AdvancedMenu */ "Lisä-\nasetukset",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Juotosasetukset",
|
||||
/* PowerSavingMenu */ "Virransäästöasetukset",
|
||||
/* UIMenu */ "Käyttöliittymän asetukset",
|
||||
/* AdvancedMenu */ "Lisäasetukset",
|
||||
/* SolderingMenu */ "Juotos-\nasetukset",
|
||||
/* PowerSavingMenu */ "Lepotilan\nasetukset",
|
||||
/* UIMenu */ "Käyttö-\nliittymä",
|
||||
/* AdvancedMenu */ "Lisä-\nasetukset",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -718,17 +692,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Soudure\nParamètres",
|
||||
/* PowerSavingMenu */ "Mode\nVeille",
|
||||
/* UIMenu */ "Interface\nUtilisateur",
|
||||
/* AdvancedMenu */ "Options\nAdvanced",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Paramètres de soudage",
|
||||
/* PowerSavingMenu */ "Paramètres d'économie d'énergie",
|
||||
/* UIMenu */ "Paramètres de l'interface utilisateur",
|
||||
/* AdvancedMenu */ "Options avancées",
|
||||
/* SolderingMenu */ "Soudure\nParamètres",
|
||||
/* PowerSavingMenu */ "Mode\nVeille",
|
||||
/* UIMenu */ "Interface\nUtilisateur",
|
||||
/* AdvancedMenu */ "Options\nAdvanced",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -809,17 +776,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Postavke\nlemljenja",
|
||||
/* PowerSavingMenu */ "Ušteda\nenergije",
|
||||
/* UIMenu */ "Korisničko\nsučelje",
|
||||
/* AdvancedMenu */ "Napredne\nopcije",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Postavke pri lemljenju",
|
||||
/* PowerSavingMenu */ "Postavke spavanja i štednje energije",
|
||||
/* UIMenu */ "Postavke korisničkog sučelja",
|
||||
/* AdvancedMenu */ "Upravljanje naprednim opcijama",
|
||||
/* SolderingMenu */ "Postavke\nlemljenja",
|
||||
/* PowerSavingMenu */ "Ušteda\nenergije",
|
||||
/* UIMenu */ "Korisničko\nsučelje",
|
||||
/* AdvancedMenu */ "Napredne\nopcije",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -900,17 +860,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Forrasztás\nBeállítások",
|
||||
/* PowerSavingMenu */ "Alvás\nMódok",
|
||||
/* UIMenu */ "Felhasználó\nfelület",
|
||||
/* AdvancedMenu */ "Speciális\nbeállítások",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Forrasztási beállítások",
|
||||
/* PowerSavingMenu */ "Energiatakarékossági beállítások",
|
||||
/* UIMenu */ "Felhasználói felület beállításai",
|
||||
/* AdvancedMenu */ "Speciális beállítások",
|
||||
/* SolderingMenu */ "Forrasztás\nBeállítások",
|
||||
/* PowerSavingMenu */ "Alvás\nMódok",
|
||||
/* UIMenu */ "Felhasználó\nfelület",
|
||||
/* AdvancedMenu */ "Speciális\nbeállítások",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1082,17 +1035,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Litavimo\nnustatymai",
|
||||
/* PowerSavingMenu */ "Miego\nrežimai",
|
||||
/* UIMenu */ "Naudotojo\nsąsaja",
|
||||
/* AdvancedMenu */ "Išplėstin.\nnustatymai",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Litavimo nustatymai",
|
||||
/* PowerSavingMenu */ "Energijos vartojimo nustatymai",
|
||||
/* UIMenu */ "Naudotojo sąsajos nustatymai",
|
||||
/* AdvancedMenu */ "Išplėstiniai nustatymai",
|
||||
/* SolderingMenu */ "Litavimo\nnustatymai",
|
||||
/* PowerSavingMenu */ "Miego\nrežimai",
|
||||
/* UIMenu */ "Naudotojo\nsąsaja",
|
||||
/* AdvancedMenu */ "Išplėstin.\nnustatymai",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1173,17 +1119,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Soldeer\nInstellingen",
|
||||
/* PowerSavingMenu */ "Slaap\nModes",
|
||||
/* UIMenu */ "Gebruikers-\nInterface",
|
||||
/* AdvancedMenu */ "geavanceerde\nInstellingen",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Soldeerinstellingen",
|
||||
/* PowerSavingMenu */ "Batterijbesparingsinstellingen",
|
||||
/* UIMenu */ "Gebruikersinterface Instellingen",
|
||||
/* AdvancedMenu */ "geavanceerde Instellingen",
|
||||
/* SolderingMenu */ "Soldeer\nInstellingen",
|
||||
/* PowerSavingMenu */ "Slaap\nModes",
|
||||
/* UIMenu */ "Gebruikers-\nInterface",
|
||||
/* AdvancedMenu */ "geavanceerde\nInstellingen",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1264,17 +1203,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Lodde-\ninnst.",
|
||||
/* PowerSavingMenu */ "Dvale-\ninnst.",
|
||||
/* UIMenu */ "Bruker-\ngrensesn.",
|
||||
/* AdvancedMenu */ "Avanserte\nvalg",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Loddeinnstillinger",
|
||||
/* PowerSavingMenu */ "Dvaleinnstillinger",
|
||||
/* UIMenu */ "Brukergrensesnitt-innstillinger",
|
||||
/* AdvancedMenu */ "Avanserte valg",
|
||||
/* SolderingMenu */ "Lodde-\ninnst.",
|
||||
/* PowerSavingMenu */ "Dvale-\ninnst.",
|
||||
/* UIMenu */ "Bruker-\ngrensesn.",
|
||||
/* AdvancedMenu */ "Avanserte\nvalg",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1355,17 +1287,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Soldering settings",
|
||||
/* PowerSavingMenu */ "Power Saving Settings",
|
||||
/* UIMenu */ "User Interface settings",
|
||||
/* AdvancedMenu */ "Advanced options",
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1446,17 +1371,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Configurações\nSolda",
|
||||
/* PowerSavingMenu */ "Modos\nRepouso",
|
||||
/* UIMenu */ "Interface\nUsuário",
|
||||
/* AdvancedMenu */ "Menu\nAvançado",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Configurações de soldagem",
|
||||
/* PowerSavingMenu */ "Configurações de economia de energia",
|
||||
/* UIMenu */ "Configurações da interface do usuário",
|
||||
/* AdvancedMenu */ "Opções avançadas",
|
||||
/* SolderingMenu */ "Configurações\nSolda",
|
||||
/* PowerSavingMenu */ "Modos\nRepouso",
|
||||
/* UIMenu */ "Interface\nUsuário",
|
||||
/* AdvancedMenu */ "Menu\nAvançado",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1537,17 +1455,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Параметры\nпайки",
|
||||
/* PowerSavingMenu */ "Режим\nсна",
|
||||
/* UIMenu */ "Пользовател\nинтерфейс",
|
||||
/* AdvancedMenu */ "Дополнител.\nпараметры",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Параметры пайки",
|
||||
/* PowerSavingMenu */ "Параметры экономии энергии",
|
||||
/* UIMenu */ "Параметры пользовательского интерфейса",
|
||||
/* AdvancedMenu */ "Дополнительные параметры",
|
||||
/* SolderingMenu */ "Параметры\nпайки",
|
||||
/* PowerSavingMenu */ "Режим\nсна",
|
||||
/* UIMenu */ "Пользовател\nинтерфейс",
|
||||
/* AdvancedMenu */ "Дополнител.\nпараметры",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1628,17 +1539,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Soldering settings",
|
||||
/* PowerSavingMenu */ "Power Saving Settings",
|
||||
/* UIMenu */ "User Interface settings",
|
||||
/* AdvancedMenu */ "Advanced options",
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1719,17 +1623,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Postavke\nlemljenja",
|
||||
/* PowerSavingMenu */ "Ušteda\nenergije",
|
||||
/* UIMenu */ "Korisničke\nopcije",
|
||||
/* AdvancedMenu */ "Napredne\nopcije",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Postavke pri lemljenju",
|
||||
/* PowerSavingMenu */ "Postavke spavanja i štednje energije",
|
||||
/* UIMenu */ "Postavke korisničkih opcija",
|
||||
/* AdvancedMenu */ "Upravljanje naprednim opcijama",
|
||||
/* SolderingMenu */ "Postavke\nlemljenja",
|
||||
/* PowerSavingMenu */ "Ušteda\nenergije",
|
||||
/* UIMenu */ "Korisničke\nopcije",
|
||||
/* AdvancedMenu */ "Napredne\nopcije",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1810,17 +1707,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Lödnings-\ninställningar",
|
||||
/* PowerSavingMenu */ "Vilo-\nlägen",
|
||||
/* UIMenu */ "Användar-\ngränssnitt",
|
||||
/* AdvancedMenu */ "Avancerade\nalternativ",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Lödningsinställningar",
|
||||
/* PowerSavingMenu */ "Viloläges-inställningar",
|
||||
/* UIMenu */ "Användargränssnitts-inställningar",
|
||||
/* AdvancedMenu */ "Avancerade alternativ",
|
||||
/* SolderingMenu */ "Lödnings-\ninställningar",
|
||||
/* PowerSavingMenu */ "Vilo-\nlägen",
|
||||
/* UIMenu */ "Användar-\ngränssnitt",
|
||||
/* AdvancedMenu */ "Avancerade\nalternativ",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1901,17 +1791,10 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Soldering settings",
|
||||
/* PowerSavingMenu */ "Power Saving Settings",
|
||||
/* UIMenu */ "User Interface settings",
|
||||
/* AdvancedMenu */ "Advanced options",
|
||||
/* SolderingMenu */ "Soldering\nSettings",
|
||||
/* PowerSavingMenu */ "Sleep\nModes",
|
||||
/* UIMenu */ "User\nInterface",
|
||||
/* AdvancedMenu */ "Advanced\nOptions",
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1992,17 +1875,9 @@ const char* SettingsShortNames[][2] = {
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntries[4] = {
|
||||
/* SolderingMenu */ "Пайка\n",
|
||||
/* PowerSavingMenu */ "Сон\n",
|
||||
/* UIMenu */ "Інтерфейс\n",
|
||||
/* AdvancedMenu */ "Інші\n",
|
||||
/* SolderingMenu */ "Пайка\n",
|
||||
/* PowerSavingMenu */ "Сон\n",
|
||||
/* UIMenu */ "Інтерфейс\n",
|
||||
/* AdvancedMenu */ "Інші\n",
|
||||
};
|
||||
|
||||
const char* SettingsMenuEntriesDescriptions[4] = {
|
||||
/* SolderingMenu */ "Налаштування для режиму пайки. Діють при включеному жалі.",
|
||||
/* PowerSavingMenu */ "Налаштування при бездіяльності. Корисно що б не обпектися і з часом не спалити житло.",
|
||||
/* UIMenu */ "Користувальницький інтерфейс.",
|
||||
/* AdvancedMenu */ "Розширені налаштування. Додаткові зручності.",
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,10 @@
|
||||
* Author: Ben V. Brown
|
||||
*/
|
||||
|
||||
//These are all the functions for interacting with the hardware
|
||||
// These are all the functions for interacting with the hardware
|
||||
#include "hardware.h"
|
||||
#include "FreeRTos.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
volatile uint16_t PWMSafetyTimer = 0;
|
||||
volatile int16_t CalibrationTempOffset = 0;
|
||||
uint16_t tipGainCalValue = 0;
|
||||
@@ -22,32 +24,30 @@ void setCalibrationOffset(int16_t offSet) {
|
||||
}
|
||||
uint16_t getHandleTemperature() {
|
||||
// We return the current handle temperature in X10 C
|
||||
// TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for example)
|
||||
// STM32 = 4096 count @ 3.3V input -> But
|
||||
// We oversample by 32/(2^2) = 8 times oversampling
|
||||
// Therefore 32768 is the 3.3V input, so 0.201416015625 mV per count
|
||||
// So we need to subtract an offset of 0.5V to center on 0C (2482*2 counts)
|
||||
// TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for
|
||||
// example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) =
|
||||
// 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125
|
||||
// mV per count So we need to subtract an offset of 0.5V to center on 0C
|
||||
// (4964.8 counts)
|
||||
//
|
||||
uint16_t result = getADC(0);
|
||||
if (result < 4964)
|
||||
return 0;
|
||||
result -= 4964; //remove 0.5V offset
|
||||
result /= 10; //convert to X10 C
|
||||
int32_t result = getADC(0);
|
||||
result -= 4965; // remove 0.5V offset
|
||||
// 10mV per C
|
||||
// 99.29 counts per Deg C above 0C
|
||||
result *= 10;
|
||||
result /= 993;
|
||||
return result;
|
||||
|
||||
}
|
||||
uint16_t tipMeasurementToC(uint16_t raw) {
|
||||
|
||||
//((Raw Tip-RawOffset) * calibrationgain) / 1000 = tip delta in CX10
|
||||
// tip delta in CX10 + handleTemp in CX10 = tip absolute temp in CX10
|
||||
//Div answer by 10 to get final result
|
||||
// Div answer by 10 to get final result
|
||||
|
||||
uint32_t tipDelta = ((raw - CalibrationTempOffset) * tipGainCalValue)
|
||||
/ 1000;
|
||||
tipDelta += getHandleTemperature();
|
||||
|
||||
return tipDelta / 10;
|
||||
|
||||
}
|
||||
uint16_t ctoTipMeasurement(uint16_t temp) {
|
||||
//[ (temp-handle/10) * 10000 ]/calibrationgain = tip raw delta
|
||||
@@ -59,37 +59,34 @@ uint16_t ctoTipMeasurement(uint16_t temp) {
|
||||
}
|
||||
|
||||
uint16_t tipMeasurementToF(uint16_t raw) {
|
||||
//Convert result from C to F
|
||||
// Convert result from C to F
|
||||
return (tipMeasurementToC(raw) * 9) / 5 + 32;
|
||||
|
||||
}
|
||||
uint16_t ftoTipMeasurement(uint16_t temp) {
|
||||
//Convert the temp back to C from F
|
||||
// Convert the temp back to C from F
|
||||
return ctoTipMeasurement(((temp - 32) * 5) / 9);
|
||||
}
|
||||
|
||||
uint16_t __attribute__ ((long_call, section (".data.ramfuncs"))) getTipInstantTemperature() {
|
||||
uint16_t getTipInstantTemperature() {
|
||||
uint16_t sum;
|
||||
sum = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_1);
|
||||
sum += HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_2);
|
||||
sum += HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_3);
|
||||
sum += HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_4);
|
||||
sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_1);
|
||||
sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_2);
|
||||
sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_3);
|
||||
sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_4);
|
||||
|
||||
return sum; // 8x over sample
|
||||
|
||||
sum = hadc1.Instance->JDR1;
|
||||
sum += hadc1.Instance->JDR2;
|
||||
sum += hadc1.Instance->JDR3;
|
||||
sum += hadc1.Instance->JDR4;
|
||||
sum += hadc2.Instance->JDR1;
|
||||
sum += hadc2.Instance->JDR2;
|
||||
sum += hadc2.Instance->JDR3;
|
||||
sum += hadc2.Instance->JDR4;
|
||||
return sum; // 8x over sample
|
||||
}
|
||||
/*
|
||||
* Loopup table for the tip calibration values for
|
||||
* the gain of the tip's
|
||||
* This can be found by line of best fit of TipRaw on X, and TipTemp-handle on Y.
|
||||
* Then take the m term * 10000
|
||||
* This can be found by line of best fit of TipRaw on X, and TipTemp-handle on
|
||||
* Y. Then take the m term * 10000
|
||||
* */
|
||||
uint16_t lookupTipDefaultCalValue(enum TipType tipID) {
|
||||
|
||||
#ifdef MODEL_TS100
|
||||
switch (tipID) {
|
||||
case TS_D24:
|
||||
return 141;
|
||||
@@ -103,16 +100,28 @@ uint16_t lookupTipDefaultCalValue(enum TipType tipID) {
|
||||
case TS_B2:
|
||||
return 133;
|
||||
default:
|
||||
return 132; // make this the average of all
|
||||
return 132; // make this the average of all
|
||||
break;
|
||||
}
|
||||
#else
|
||||
switch (tipID) {
|
||||
case TS_D25:
|
||||
return 154;
|
||||
break;
|
||||
case TS_B02:
|
||||
return 154;
|
||||
break;
|
||||
default:
|
||||
return 154; // make this the average of all
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t __attribute__ ((long_call, section (".data.ramfuncs"))) getTipRawTemp(
|
||||
uint8_t instant) {
|
||||
uint16_t getTipRawTemp(uint8_t instant) {
|
||||
static int64_t filterFP = 0;
|
||||
static uint16_t lastSample = 0;
|
||||
const uint8_t filterBeta = 7; //higher values smooth out more, but reduce responsiveness
|
||||
const uint8_t filterBeta = 7; // higher values smooth out more, but reduce responsiveness
|
||||
|
||||
if (instant == 1) {
|
||||
uint16_t itemp = getTipInstantTemperature();
|
||||
@@ -132,10 +141,10 @@ uint16_t __attribute__ ((long_call, section (".data.ramfuncs"))) getTipRawTemp(
|
||||
}
|
||||
}
|
||||
uint16_t getInputVoltageX10(uint16_t divisor) {
|
||||
//ADC maximum is 32767 == 3.3V at input == 28.05V at VIN
|
||||
//Therefore we can divide down from there
|
||||
//Multiplying ADC max by 4 for additional calibration options,
|
||||
//ideal term is 467
|
||||
// ADC maximum is 32767 == 3.3V at input == 28.05V at VIN
|
||||
// Therefore we can divide down from there
|
||||
// Multiplying ADC max by 4 for additional calibration options,
|
||||
// ideal term is 467
|
||||
#define BATTFILTERDEPTH 64
|
||||
static uint8_t preFillneeded = 1;
|
||||
static uint32_t samples[BATTFILTERDEPTH];
|
||||
@@ -157,27 +166,277 @@ uint16_t getInputVoltageX10(uint16_t divisor) {
|
||||
preFillneeded = 1;
|
||||
return sum * 4 / divisor;
|
||||
}
|
||||
#ifdef MODEL_TS80
|
||||
uint8_t QCMode = 0;
|
||||
void seekQC(int16_t Vx10) {
|
||||
if (QCMode <= 1)
|
||||
return; // NOT connected to a QC Charger
|
||||
if (Vx10 < 50)
|
||||
return;
|
||||
// Seek the QC to the Voltage given if this adapter supports continuous mode
|
||||
// try and step towards the wanted value
|
||||
|
||||
// 1. Measure current voltage
|
||||
int16_t vStart = getInputVoltageX10(195);
|
||||
int difference = Vx10 - vStart;
|
||||
|
||||
// 2. calculate ideal steps (0.2V changes)
|
||||
|
||||
int steps = difference / 2;
|
||||
if (QCMode == 3) {
|
||||
while (steps < 0) {
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
|
||||
vTaskDelay(3);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
vTaskDelay(3);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
vTaskDelay(3);
|
||||
steps++;
|
||||
}
|
||||
while (steps > 0) {
|
||||
// step once up
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
|
||||
vTaskDelay(3);
|
||||
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
|
||||
vTaskDelay(3);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
vTaskDelay(3);
|
||||
steps--;
|
||||
}
|
||||
}
|
||||
// Re-measure
|
||||
/* Disabled due to nothing to test and code space of around 1k*/
|
||||
#ifdef QC2_ROUND_DOWN
|
||||
steps = vStart - getInputVoltageX10(195);
|
||||
if (steps < 0) steps = -steps;
|
||||
if (steps > (difference / 2)) {
|
||||
// No continuous mode, so QC2
|
||||
QCMode = 2;
|
||||
// Goto nearest
|
||||
if (Vx10 > 10.5) {
|
||||
// request 12V
|
||||
// D- = 0.6V, D+ = 0.6V
|
||||
// Clamp PB3
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull down D+
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
|
||||
} else {
|
||||
// request 9V
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Must be called after FreeRToS Starts
|
||||
void startQC() {
|
||||
// Pre check that the input could be >5V already, and if so, dont both
|
||||
// negotiating as someone is feeding in hv
|
||||
uint16_t vin = getInputVoltageX10(205);
|
||||
if (vin > 150)
|
||||
return;// Over voltage
|
||||
if (vin > 100) {
|
||||
QCMode = 1; // ALready at ~12V
|
||||
return;
|
||||
}
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
// Tries to negotiate QC for 9V
|
||||
// This is a multiple step process.
|
||||
// 1. Set around 0.6V on D+ for 1.25 Seconds or so
|
||||
// 2. After this It should un-short D+->D- and instead add a 20k pulldown on
|
||||
// D-
|
||||
// 3. Now set D+ to 3.3V and D- to 0.6V to request 9V
|
||||
// OR both at 0.6V for 12V request (if the adapter can do it).
|
||||
// If 12V is implimented then should fallback to 9V after validation
|
||||
// Step 1. We want to pull D+ to 0.6V
|
||||
// Pull PB3 donwn to ground
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull low to put 0.6V on D+
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull low to put 0.6V on D+
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// Delay 1.25 seconds
|
||||
uint8_t enteredQC = 0;
|
||||
for (uint16_t i = 0; i < 130 && enteredQC == 0; i++) {
|
||||
// HAL_Delay(10);
|
||||
vTaskDelay(1);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
// Check if D- is low to spot a QC charger
|
||||
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET)
|
||||
enteredQC = 1;
|
||||
if (enteredQC) {
|
||||
// We have a QC capable charger
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_8;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
// Wait for frontend ADC to stabilise
|
||||
QCMode = 4;
|
||||
for (uint8_t i = 0; i < 10; i++) {
|
||||
if (getInputVoltageX10(195) > 80) {
|
||||
// yay we have at least QC2.0 or QC3.0
|
||||
QCMode = 3;// We have at least QC2, pray for 3
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
|
||||
return;
|
||||
}
|
||||
vTaskDelay(10); // 100mS
|
||||
}
|
||||
QCMode = 0;
|
||||
// No QC / not working to us
|
||||
|
||||
} else {
|
||||
// no QC
|
||||
}
|
||||
}
|
||||
// Get tip resistance in milliohms
|
||||
uint32_t calculateTipR(uint8_t useFilter) {
|
||||
// We inject a small current into the front end of the iron,
|
||||
// By measuring the Vdrop over the tip we can calculate the resistance
|
||||
// Turn PA0 into an output and drive high to inject (3.3V-0.6)/(6K8+Rtip)
|
||||
// current PA0->Diode -> 6K8 -> Tip -> GND So the op-amp will amplify the
|
||||
// small signal across the tip and convert this into an easily read voltage
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);// Set low first
|
||||
setTipPWM(0);
|
||||
vTaskDelay(1);
|
||||
uint32_t offReading = getTipInstantTemperature();
|
||||
for (uint8_t i = 0; i < 24; i++) {
|
||||
if (useFilter == 0) {
|
||||
vTaskDelay(1); // delay to allow it too stabilize
|
||||
offReading += getTipInstantTemperature();
|
||||
} else {
|
||||
offReading += getTipRawTemp(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Turn on
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);// Set low first
|
||||
vTaskDelay(1);// delay to allow it too stabilize
|
||||
uint32_t onReading = getTipInstantTemperature();
|
||||
for (uint8_t i = 0; i < 24; i++) {
|
||||
if (useFilter == 0) {
|
||||
vTaskDelay(1); // delay to allow it too stabilize
|
||||
onReading += getTipInstantTemperature();
|
||||
} else {
|
||||
onReading += getTipRawTemp(0);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t difference = onReading - offReading;
|
||||
// V = IR, therefore I = V/R
|
||||
// We can divide this reading by a known "gain" to get the resulting
|
||||
// resistance This was determined emperically This tip is 4.688444162 ohms,
|
||||
// 4688 milliohms (Measured using 4 terminal measurement) 25x oversampling
|
||||
// reads this as around 47490 Almost perfectly 10x the milliohms value This
|
||||
// will drift massively with tip temp However we really only need 10x ohms
|
||||
return (difference / 10) + 1;// ceil
|
||||
}
|
||||
static unsigned int sqrt32(unsigned long n) {
|
||||
unsigned int c = 0x8000;
|
||||
unsigned int g = 0x8000;
|
||||
|
||||
for (;;) {
|
||||
if (g * g > n)
|
||||
g ^= c;
|
||||
c >>= 1;
|
||||
if (c == 0)
|
||||
return g;
|
||||
g |= c;
|
||||
}
|
||||
}
|
||||
int16_t calculateMaxVoltage(uint8_t useFilter, uint8_t useHP) {
|
||||
// This measures the tip resistance, then it calculates the appropriate
|
||||
// voltage To stay under ~18W. Mosfet is "9A", so no issues there
|
||||
// QC3.0 supports up to 18W, which is 2A @9V and 1.5A @12V
|
||||
uint32_t milliOhms = calculateTipR(useFilter);
|
||||
// Check no tip
|
||||
if (milliOhms > 10000)
|
||||
return -1;
|
||||
//
|
||||
// V = sqrt(18W*R)
|
||||
// Convert this to sqrt(18W)*sqrt(milli ohms)*sqrt(1/1000)
|
||||
|
||||
uint32_t Vx = sqrt32(milliOhms);
|
||||
if (useHP)
|
||||
Vx *= 1549;//sqrt(24)*sqrt(1/1000)
|
||||
else
|
||||
Vx *= 1342;// sqrt(18) * sqrt(1/1000)
|
||||
|
||||
// Round to nearest 200mV,
|
||||
// So divide by 100 to start, to get in Vxx
|
||||
Vx /= 100;
|
||||
if (Vx % 10 >= 5)
|
||||
Vx += 10;
|
||||
Vx /= 10;
|
||||
// Round to nearest increment of 2
|
||||
if (Vx % 2 == 1)
|
||||
Vx++;
|
||||
return Vx;
|
||||
}
|
||||
|
||||
#endif
|
||||
volatile uint32_t pendingPWM = 0;
|
||||
uint8_t getTipPWM() {
|
||||
return pendingPWM;
|
||||
}
|
||||
void __attribute__ ((long_call, section (".data.ramfuncs"))) setTipPWM(uint8_t pulse) {
|
||||
PWMSafetyTimer = 2; //This is decremented in the handler for PWM so that the tip pwm is disabled if the PID task is not scheduled often enough.
|
||||
void setTipPWM(uint8_t pulse) {
|
||||
PWMSafetyTimer = 2; // This is decremented in the handler for PWM so that the tip pwm is
|
||||
// disabled if the PID task is not scheduled often enough.
|
||||
if (pulse > 100)
|
||||
pulse = 100;
|
||||
|
||||
pendingPWM = pulse;
|
||||
}
|
||||
|
||||
//These are called by the HAL after the corresponding events from the system timers.
|
||||
// These are called by the HAL after the corresponding events from the system
|
||||
// timers.
|
||||
|
||||
void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PeriodElapsedCallback(
|
||||
TIM_HandleTypeDef *htim) {
|
||||
//Period has elapsed
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
// Period has elapsed
|
||||
if (htim->Instance == TIM2) {
|
||||
//we want to turn on the output again
|
||||
PWMSafetyTimer--; //We decrement this safety value so that lockups in the scheduler will not cause the PWM to become locked in an active driving state.
|
||||
//While we could assume this could never happen, its a small price for increased safety
|
||||
// we want to turn on the output again
|
||||
PWMSafetyTimer--; // We decrement this safety value so that lockups in the
|
||||
// scheduler will not cause the PWM to become locked in an
|
||||
// active driving state.
|
||||
// While we could assume this could never happen, its a small price for
|
||||
// increased safety
|
||||
htim2.Instance->CCR4 = pendingPWM;
|
||||
if (htim2.Instance->CCR4 && PWMSafetyTimer) {
|
||||
htim3.Instance->CCR1 = 50;
|
||||
@@ -192,15 +451,12 @@ void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PeriodElaps
|
||||
}
|
||||
}
|
||||
|
||||
void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PWM_PulseFinishedCallback(
|
||||
TIM_HandleTypeDef *htim) {
|
||||
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
|
||||
if (htim->Instance == TIM2) {
|
||||
//This was a when the PWM for the output has timed out
|
||||
// This was a when the PWM for the output has timed out
|
||||
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) {
|
||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
|
||||
htim3.Instance->CCR1 = 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,18 +41,6 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) {
|
||||
if (hadc->Instance == ADC1) {
|
||||
__HAL_RCC_ADC1_CLK_ENABLE()
|
||||
;
|
||||
/**ADC1 GPIO Configuration
|
||||
PA7 ------> ADC1_IN7
|
||||
PB0 ------> ADC1_IN8
|
||||
PB1 ------> ADC1_IN9
|
||||
*/
|
||||
GPIO_InitStruct.Pin = TMP36_INPUT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(TMP36_INPUT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = TIP_TEMP_Pin | VIN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* ADC1 DMA Init */
|
||||
/* ADC1 Init */
|
||||
@@ -100,7 +88,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) {
|
||||
GPIO_InitStruct.Pin = SCL_Pin | SDA_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* Peripheral clock enable */
|
||||
|
||||
@@ -45,25 +45,12 @@ void _exit (int status)
|
||||
|
||||
int _read (int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = __io_getchar();
|
||||
}
|
||||
|
||||
return len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
__io_putchar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
caddr_t _sbrk(int incr)
|
||||
|
||||
Reference in New Issue
Block a user