mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Format BSP
This commit is contained in:
@@ -16,9 +16,7 @@ uint16_t totalPWM = 255;
|
|||||||
const uint16_t powerPWM = 255;
|
const uint16_t powerPWM = 255;
|
||||||
|
|
||||||
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0};
|
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0};
|
||||||
void resetWatchdog() {
|
void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); }
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef TEMP_NTC
|
#ifdef TEMP_NTC
|
||||||
// Lookup table for the NTC
|
// Lookup table for the NTC
|
||||||
@@ -39,8 +37,7 @@ static const uint16_t NTCHandleLookup[] = {
|
|||||||
28249, 50, //
|
28249, 50, //
|
||||||
29189, 0, //
|
29189, 0, //
|
||||||
};
|
};
|
||||||
const int NTCHandleLookupItems = sizeof(NTCHandleLookup)
|
const int NTCHandleLookupItems = sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t));
|
||||||
/ (2 * sizeof(uint16_t));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// These are called by the HAL after the corresponding events from the system
|
// These are called by the HAL after the corresponding events from the system
|
||||||
@@ -55,13 +52,10 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
|||||||
}
|
}
|
||||||
uint16_t getHandleTemperature() {
|
uint16_t getHandleTemperature() {
|
||||||
int32_t result = getADC(0);
|
int32_t result = getADC(0);
|
||||||
return Utils::InterpolateLookupTable(NTCHandleLookup, NTCHandleLookupItems,
|
return Utils::InterpolateLookupTable(NTCHandleLookup, NTCHandleLookupItems, result);
|
||||||
result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getTipInstantTemperature() {
|
uint16_t getTipInstantTemperature() { return getADC(2); }
|
||||||
return getADC(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getTipRawTemp(uint8_t refresh) {
|
uint16_t getTipRawTemp(uint8_t refresh) {
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
@@ -179,25 +173,14 @@ void unstick_I2C() {
|
|||||||
HAL_I2C_Init(&hi2c1);
|
HAL_I2C_Init(&hi2c1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getButtonA() {
|
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||||
return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ?
|
uint8_t getButtonB() { return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||||
1 : 0;
|
|
||||||
}
|
|
||||||
uint8_t getButtonB() {
|
|
||||||
return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ?
|
|
||||||
1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BSPInit(void) {
|
void BSPInit(void) {}
|
||||||
}
|
|
||||||
|
|
||||||
void reboot() {
|
void reboot() { NVIC_SystemReset(); }
|
||||||
NVIC_SystemReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void delay_ms(uint16_t count) {
|
void delay_ms(uint16_t count) { HAL_Delay(count); }
|
||||||
HAL_Delay(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPlatePullup(bool pullingUp) {
|
void setPlatePullup(bool pullingUp) {
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
@@ -206,13 +189,11 @@ void setPlatePullup(bool pullingUp) {
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
if (pullingUp) {
|
if (pullingUp) {
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port,
|
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port, PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_SET);
|
||||||
PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_SET);
|
|
||||||
} else {
|
} else {
|
||||||
// Hi-z
|
// Hi-z
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||||
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port,
|
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port, PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_RESET);
|
||||||
PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_RESET);
|
|
||||||
}
|
}
|
||||||
HAL_GPIO_Init(PLATE_SENSOR_PULLUP_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(PLATE_SENSOR_PULLUP_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
@@ -232,19 +213,26 @@ bool isTipDisconnected() {
|
|||||||
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
||||||
uint32_t tipTemp = TipThermoModel::getTipInC();
|
uint32_t tipTemp = TipThermoModel::getTipInC();
|
||||||
bool tipDisconnected = tipTemp > tipDisconnectedThres;
|
bool tipDisconnected = tipTemp > tipDisconnectedThres;
|
||||||
|
// We have to handle here that this ^ will trip while measuring the gain resistor
|
||||||
|
if (xTaskGetTickCount() - lastMeas < (TICKS_100MS * 2 + (TICKS_100MS / 2))) {
|
||||||
|
tipDisconnected = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (tipDisconnected != lastTipDisconnectedState) {
|
if (tipDisconnected != lastTipDisconnectedState) {
|
||||||
if (tipDisconnected) {
|
if (tipDisconnected) {
|
||||||
// Tip is now disconnected
|
// Tip is now disconnected
|
||||||
tipSenseResistancex10Ohms = 0; // zero out the resistance
|
tipSenseResistancex10Ohms = 0; // zero out the resistance
|
||||||
adcReadingPD1Set = 0;
|
adcReadingPD1Set = 0;
|
||||||
lastMeas = xTaskGetTickCount();
|
lastMeas = 0;
|
||||||
setPlatePullup(true);
|
|
||||||
}
|
}
|
||||||
lastTipDisconnectedState = tipDisconnected;
|
lastTipDisconnectedState = tipDisconnected;
|
||||||
}
|
}
|
||||||
if (!tipDisconnected) {
|
if (!tipDisconnected) {
|
||||||
if (tipSenseResistancex10Ohms == 0) {
|
if (tipSenseResistancex10Ohms == 0) {
|
||||||
if (xTaskGetTickCount() - lastMeas > (TICKS_100MS / 2)) {
|
if (lastMeas == 0) {
|
||||||
|
lastMeas = xTaskGetTickCount();
|
||||||
|
setPlatePullup(true);
|
||||||
|
} else if (xTaskGetTickCount() - lastMeas > (TICKS_100MS)) {
|
||||||
lastMeas = xTaskGetTickCount();
|
lastMeas = xTaskGetTickCount();
|
||||||
// We are sensing the resistance
|
// We are sensing the resistance
|
||||||
if (adcReadingPD1Set == 0) {
|
if (adcReadingPD1Set == 0) {
|
||||||
@@ -254,10 +242,14 @@ bool isTipDisconnected() {
|
|||||||
} else {
|
} else {
|
||||||
// We have taken reading one
|
// We have taken reading one
|
||||||
uint16_t adcReadingPD1Cleared = getADC(3);
|
uint16_t adcReadingPD1Cleared = getADC(3);
|
||||||
tipSenseResistancex10Ohms = ((((int) adcReadingPD1Set
|
uint32_t a = ((int)adcReadingPD1Set - (int)adcReadingPD1Cleared);
|
||||||
- (int) adcReadingPD1Cleared) * 10000)
|
a *= 10000;
|
||||||
/ ((int) adcReadingPD1Cleared
|
uint32_t b = ((int)adcReadingPD1Cleared + (32768 - (int)adcReadingPD1Set));
|
||||||
+ (65536 - (int) adcReadingPD1Set)));
|
if (b) {
|
||||||
|
tipSenseResistancex10Ohms = a / b;
|
||||||
|
} else {
|
||||||
|
tipSenseResistancex10Ohms = adcReadingPD1Set = lastMeas = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true; // we fake tip being disconnected until this is measured
|
return true; // we fake tip being disconnected until this is measured
|
||||||
|
|||||||
Reference in New Issue
Block a user