This commit is contained in:
jonasius
2025-02-25 22:01:44 +01:00
committed by GitHub
28 changed files with 237 additions and 115 deletions

View File

@@ -153,6 +153,7 @@
#define PROFILE_SUPPORT
#define OLED_96x16 1
#define POW_PD 1
#define USB_PD_TIMEOUT 20 // Default Timeout for USB-PD Protocol negotiation in x100ms
#define POW_PD_EXT 0
#define USB_PD_EPR_WATTAGE 0 /*No EPR*/
#define TEMP_NTC

View File

@@ -132,6 +132,7 @@
#define ADC_VDD_MV 3300 // ADC max reading millivolts
#define POW_PD_EXT 0
#define USB_PD_TIMEOUT 20 // Default Timeout for USB-PD Protocol negotiation in x100ms
// Deriving the Voltage div:
// Vin_max = (3.3*(r1+r2))/(r2)

View File

@@ -149,6 +149,7 @@
#define POW_PD 1
#define USB_PD_EPR_WATTAGE 0 /*No EPR (Yet?) */
#define POW_PD_EXT 0
#define USB_PD_TIMEOUT 20 // Default Timeout for USB-PD Protocol negotiation in x100ms
#define POW_QC 1
#define POW_DC 1
#define POW_QC_20V 1

View File

@@ -148,6 +148,7 @@
#define POW_PD 1 // Supported features
#define USB_PD_EPR_WATTAGE 140 // USB PD EPR Wattage
#define POW_PD_EXT 0 // Future-proof macro for other models with other PD modes
#define USB_PD_TIMEOUT 20 // Default Timeout for USB-PD Protocol negotiation in x100ms
#define POW_QC 1 // Supported features
#define POW_DC 1 // Supported features
#define POW_QC_20V 1 // Supported features

View File

@@ -126,77 +126,7 @@ void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
}
}
void unstick_I2C() {
#ifdef SCL_Pin
GPIO_InitTypeDef GPIO_InitStruct;
int timeout = 100;
int timeout_cnt = 0;
// 1. Clear PE bit.
hi2c1.Instance->CR1 &= ~(0x0001);
/**I2C1 GPIO Configuration
PB6 ------> I2C1_SCL
PB7 ------> I2C1_SDA
*/
// 2. Configure the SCL and SDA I/Os as General Purpose Output Open-Drain, High level (Write 1 to GPIOx_ODR).
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pin = SCL_Pin;
HAL_GPIO_Init(SCL_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_SET);
GPIO_InitStruct.Pin = SDA_Pin;
HAL_GPIO_Init(SDA_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
while (GPIO_PIN_SET != HAL_GPIO_ReadPin(SDA_GPIO_Port, SDA_Pin)) {
// Move clock to release I2C
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_RESET);
asm("nop");
asm("nop");
asm("nop");
asm("nop");
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_SET);
timeout_cnt++;
if (timeout_cnt > timeout) {
return;
}
}
// 12. Configure the SCL and SDA I/Os as Alternate function Open-Drain.
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pin = SCL_Pin;
HAL_GPIO_Init(SCL_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = SDA_Pin;
HAL_GPIO_Init(SDA_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
// 13. Set SWRST bit in I2Cx_CR1 register.
hi2c1.Instance->CR1 |= 0x8000;
asm("nop");
// 14. Clear SWRST bit in I2Cx_CR1 register.
hi2c1.Instance->CR1 &= ~0x8000;
asm("nop");
// 15. Enable the I2C peripheral by setting the PE bit in I2Cx_CR1 register
hi2c1.Instance->CR1 |= 0x0001;
// Call initialization function.
HAL_I2C_Init(&hi2c1);
#endif
}
void unstick_I2C() {}
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
uint8_t getButtonB() { return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0; }

View File

@@ -5,8 +5,8 @@
* Author: Ralim
*/
#ifndef BSP_MINIWARE_PINS_H_
#define BSP_MINIWARE_PINS_H_
#ifndef BSP_SEQURE_PINS_H_
#define BSP_SEQURE_PINS_H_
#include "configuration.h"
#ifdef MODEL_S60
@@ -65,6 +65,45 @@
#define SCL2_GPIO_Port GPIOB
#define SDA2_Pin GPIO_PIN_7
#define SDA2_GPIO_Port GPIOB
#define SCL_Pin GPIO_PIN_11
#define SCL_GPIO_Port GPIOB
#define SDA_Pin GPIO_PIN_10
#define SDA_GPIO_Port GPIOB
// Pin gets pulled high on movement
#define MOVEMENT_Pin GPIO_PIN_3
#define MOVEMENT_GPIO_Port GPIOA
#endif
#ifdef MODEL_S99
#define KEY_B_Pin GPIO_PIN_1
#define KEY_B_GPIO_Port GPIOB
#define TMP36_INPUT_Pin GPIO_PIN_5
#define TMP36_INPUT_GPIO_Port GPIOA
#define TMP36_ADC1_CHANNEL ADC_CHANNEL_5
#define TMP36_ADC2_CHANNEL ADC_CHANNEL_5
#define TIP_TEMP_Pin GPIO_PIN_0
#define TIP_TEMP_GPIO_Port GPIOA
#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_0
#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_0
#define VIN_Pin GPIO_PIN_4
#define VIN_GPIO_Port GPIOA
#define VIN_ADC1_CHANNEL ADC_CHANNEL_4
#define VIN_ADC2_CHANNEL ADC_CHANNEL_4
#define KEY_A_Pin GPIO_PIN_0
#define KEY_A_GPIO_Port GPIOB
#define PWM_Out_Pin GPIO_PIN_8
#define PWM_Out_GPIO_Port GPIOB
#define PWM_Out_CHANNEL TIM_CHANNEL_3 // Timer 4; channel 3
#define SCL2_Pin GPIO_PIN_6
#define SCL2_GPIO_Port GPIOB
#define SDA2_Pin GPIO_PIN_7
#define SDA2_GPIO_Port GPIOB
#define SCL_Pin GPIO_PIN_11
#define SCL_GPIO_Port GPIOB
#define SDA_Pin GPIO_PIN_10
#define SDA_GPIO_Port GPIOB
// Pin gets pulled high on movement
#define MOVEMENT_Pin GPIO_PIN_3
#define MOVEMENT_GPIO_Port GPIOA
@@ -98,4 +137,4 @@
#endif // MODEL_T55
#endif /* BSP_MINIWARE_PINS_H_ */
#endif /* BSP_SEQURE_PINS_H_ */

View File

@@ -1,5 +1,6 @@
#include "BSP.h"
#include "BSP_Power.h"
#include "FS2711.hpp"
#include "Pins.h"
#include "QC3.h"
#include "Settings.h"
@@ -16,9 +17,26 @@ void power_check() {
return; // We are using PD
}
#endif
#if POW_PD_EXT == 2
if (FS2711::has_run_selection()) {
return;
}
#endif
#ifdef POW_QC
QC_resync();
#endif
}
bool getIsPoweredByDCIN() { return false; }
bool getIsPoweredByDCIN() {
#if POW_PD_EXT == 2 && defined(POW_DC)
if (!FS2711::has_run_selection()) {
return true;
} else if (FS2711::debug_get_state().source_voltage > 0) {
return false;
} else {
return true;
}
#else
return false;
#endif
}

View File

@@ -1,6 +1,6 @@
# BSP section for STM32F103 based Miniware products
# BSP section for STM32F103 based Sequre products
This folder contains the hardware abstractions required for the TS100, TS80 and probably TS80P soldering irons.
This folder contains the hardware abstractions required for the S60, S60P and S99 soldering irons.
## Main abstractions

View File

@@ -5,19 +5,32 @@
* Author: Ralim
*/
#ifndef BSP_MINIWARE_SOFTWARE_I2C_H_
#define BSP_MINIWARE_SOFTWARE_I2C_H_
#ifndef BSP_SEQURE_SOFTWARE_I2C_H_
#define BSP_SEQURE_SOFTWARE_I2C_H_
#include "BSP.h"
#include "configuration.h"
#include "stm32f1xx_hal.h"
#ifdef I2C_SOFT_BUS_2
#ifdef I2C_SOFT_BUS_1
#define SOFT_SCL1_HIGH() HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_SET)
#define SOFT_SCL1_LOW() HAL_GPIO_WritePin(SCL_GPIO_Port, SCL_Pin, GPIO_PIN_RESET)
#define SOFT_SDA1_HIGH() HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET)
#define SOFT_SDA1_LOW() HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_RESET)
#define SOFT_SDA1_READ() (HAL_GPIO_ReadPin(SDA_GPIO_Port, SDA_Pin) == GPIO_PIN_SET ? 1 : 0)
#define SOFT_SCL1_READ() (HAL_GPIO_ReadPin(SCL_GPIO_Port, SCL_Pin) == GPIO_PIN_SET ? 1 : 0)
#endif /* I2C_SOFT_BUS_1 */
#ifdef I2C_SOFT_BUS_2
#define SOFT_SCL2_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
#define SOFT_SCL2_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
#define SOFT_SDA2_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
#define SOFT_SDA2_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
#define SOFT_SDA2_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0)
#define SOFT_SCL2_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0)
#endif /* I2C_SOFT_BUS_2 */
// clang-format off
#define SOFT_I2C_DELAY() \
{ \
@@ -27,7 +40,6 @@
}
// clang-format on
#endif
// 40 ~= 100kHz; 15 gives around 250kHz or so which is fast _and_ stable
#endif /* BSP_MINIWARE_SOFTWARE_I2C_H_ */
#endif /* BSP_SEQURE_SOFTWARE_I2C_H_ */

View File

@@ -83,3 +83,10 @@ TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
#ifdef TEMP_uV_LOOKUP_S60
TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 50) / 485; }
#endif // TEMP_uV_LOOKUP_S60
#ifdef TEMP_uV_LOOKUP_S99
// 42.85 uV / K -> 1/42.85 K/uV = 20/857
// TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 20) / 857; }
// Measurement is probably with heating element in series, thats why the reading differs from the approx 42.85 uV/K
TemperatureType_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) { return (tipuVDelta * 1) / 30; }
#endif // TEMP_uV_LOOKUP_S99

View File

@@ -116,7 +116,7 @@
// Vin_max = (3.3*(r1+r2))/(r2)
// vdiv = (32768*4)/(vin_max*10)
#if defined(MODEL_S60) + defined(MODEL_S60P) + defined(MODEL_T55) == 0
#if defined(MODEL_S60) + defined(MODEL_S60P) + defined(MODEL_T55) + defined(MODEL_S99) == 0
#error "No model defined!"
#endif
@@ -131,9 +131,10 @@
#define POWER_LIMIT_STEPS 5
#define OP_AMP_GAIN_STAGE 536
#define TEMP_uV_LOOKUP_S60
#define USB_PD_VMAX 12 // Maximum voltage for PD to negotiate
#define USB_PD_VMAX 12 // Maximum voltage for PD to negotiate
#define THERMAL_RUNAWAY_TIME_SEC 20
#define THERMAL_RUNAWAY_TEMP_C 3
#define USB_PD_TIMEOUT 1 // Default Timeout for USB-PD Protocol negotiation in x100ms
#define HARDWARE_MAX_WATTAGE_X10 600
@@ -165,9 +166,10 @@
#define POWER_LIMIT_STEPS 5
#define OP_AMP_GAIN_STAGE 536
#define TEMP_uV_LOOKUP_S60
#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate
#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate
#define THERMAL_RUNAWAY_TIME_SEC 20
#define THERMAL_RUNAWAY_TEMP_C 3
#define USB_PD_TIMEOUT 1 // Default Timeout for USB-PD Protocol negotiation in x100ms
#define HARDWARE_MAX_WATTAGE_X10 600
@@ -180,10 +182,13 @@
#define GPIO_VIBRATION
#define POW_PD_EXT 2
#define USB_PD_EPR_WATTAGE 0 /*No EPR*/
#define POW_DC
#define DEBUG_POWER_MENU_BUTTON_B 1
#define HAS_POWER_DEBUG_MENU
#define TEMP_NTC
#define I2C_SOFT_BUS_2 // For now we are doing software I2C to get around hardware chip issues
#define I2C_PROBE_POW_PD // For now we are doing software I2C to get around hardware chip issues
#define I2C_SOFT_BUS_1 // For now we are doing software I2C to get around hardware chip issues
#define OLED_I2CBB2
#define FILTER_DISPLAYED_TIP_TEMP 4 // Filtering for GUI display
@@ -206,6 +211,8 @@
#define OP_AMP_GAIN_STAGE 1
#define TEMP_uV_LOOKUP_PT1000
#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate
#define USB_PD_TIMEOUT 1 // Default Timeout for USB-PD Protocol negotiation in x100ms
#define NO_DISPLAY_ROTATE // Disable OLED rotation by accel
#define MAX_TEMP_C 350 // Max soldering temp selectable °C
#define MAX_TEMP_F 660 // Max soldering temp selectable °F
@@ -239,6 +246,44 @@
#define MODEL_HAS_DCDC // We dont have DC/DC but have reallly fast PWM that gets us roughly the same place
#endif /* T55 */
#ifdef MODEL_S99
#define VOLTAGE_DIV 460 // Default divider scaler
#define CALIBRATION_OFFSET 200 // Default adc offset in uV
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit
#define POWER_LIMIT 0 // 0 watts default limit
#define MAX_POWER_LIMIT 70
#define POWER_LIMIT_STEPS 5
#define OP_AMP_GAIN_STAGE 237 // Two sequential op-amps 1st: 1+(9k29/997R)=10.31 2nd: 1+(22k/1k)=23 -> 10.31*23=237
#define TEMP_uV_LOOKUP_S99
#define USB_PD_VMAX 20 // Maximum voltage for PD to negotiate
#define USB_PD_TIMEOUT 1 // Default Timeout for USB-PD Protocol negotiation in x100ms
#define HARDWARE_MAX_WATTAGE_X10 1300
#define TIP_THERMAL_MASS 8 // X10 watts to raise 1 deg C in 1 second
#define TIP_THERMAL_INERTIA 128 // We use a large inertia value to smooth out the drive to the tip since its stupidly sensitive
#define THERMAL_RUNAWAY_TIME_SEC 20
#define THERMAL_RUNAWAY_TEMP_C 10
#define TIP_RESISTANCE 20 //(actually 2.5 ish but we need to be more conservative on pwm'ing watt limit) x10 ohms
#define OLED_128x32
#define GPIO_VIBRATION
#define POW_PD_EXT 2
#define USB_PD_EPR_WATTAGE 0 /*No EPR*/
#define POW_DC
#define DEBUG_POWER_MENU_BUTTON_B 1
#define HAS_POWER_DEBUG_MENU
#define TEMP_NTC
#define I2C_SOFT_BUS_2 // For now we are doing software I2C to get around hardware chip issues
#define I2C_PROBE_POW_PD // For now we are doing software I2C to get around hardware chip issues
#define I2C_SOFT_BUS_1 // For now we are doing software I2C to get around hardware chip issues
#define OLED_I2CBB2
#define FILTER_DISPLAYED_TIP_TEMP 4 // Filtering for GUI display
#define MODEL_HAS_DCDC // We dont have DC/DC but have reallly fast PWM that gets us roughly the same place
#endif /* S99 */
#define FLASH_LOGOADDR (0x08000000 + (62 * 1024))
#define SETTINGS_START_PAGE (0x08000000 + (63 * 1024))

View File

@@ -6,10 +6,14 @@
*/
#include "BSP.h"
#include "I2CBB1.hpp"
#include "I2CBB2.hpp"
#include "Pins.h"
#include "Setup.h"
#include <I2C_Wrapper.hpp>
#if defined(I2C_PROBE_POW_PD) && POW_PD_EXT == 2
#include "FS2711.hpp"
#endif
void preRToSInit() {
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
@@ -17,7 +21,14 @@ void preRToSInit() {
HAL_Init();
Setup_HAL(); // Setup all the HAL objects
BSPInit();
#ifdef I2C_SOFT_BUS_1
I2CBB1::init();
#endif /* I2C_SOFT_BUS_1 */
#ifdef I2C_SOFT_BUS_2
I2CBB2::init();
#endif
#endif /* I2C_SOFT_BUS_2 */
#if defined(I2C_PROBE_POW_PD) && POW_PD_EXT == 2
// Detect and set FS2711 I2C bus num
FS2711::detect_i2c_bus_num();
#endif /* defined(I2C_PROBE_POW_PD) && POW_PD_EXT == 2 */
}