TS101 (#1695)
* Refactor I2C_SOFT to new #define * Stitch in some of TS101 Update ShowStartupWarnings.cpp Update OLED.hpp Update stm32f1xx_hal_msp.c Update Setup.cpp Update Power.cpp Update Pins.h Update configuration.h Power Muxing Working dual input Voltage handler Scan mode required for differing injected channels Inject both dc readings Update configuration.h Update configuration.h Use htim4 for adc control on TS101 Refactor htim names Add ADC_TRIGGER Speed up BB I2C a lil Update configuration.h Update startup_stm32f103t8ux.S Update configuration.h Add LIS2DH clone LIS2DH gains another clone Create tooling to allow mapping accelerometers onto different buses Update startup_stm32f103t8ux.S Ensure PD IRQ is pulled up * Stitch in some of TS101 Update ShowStartupWarnings.cpp Update OLED.hpp Update stm32f1xx_hal_msp.c Update Setup.cpp Update Power.cpp Update Pins.h Update configuration.h Power Muxing Working dual input Voltage handler Scan mode required for differing injected channels Inject both dc readings Update configuration.h Update configuration.h Use htim4 for adc control on TS101 Refactor htim names Add ADC_TRIGGER Speed up BB I2C a lil Update configuration.h Update startup_stm32f103t8ux.S Update configuration.h Add LIS2DH clone LIS2DH gains another clone Create tooling to allow mapping accelerometers onto different buses Update startup_stm32f103t8ux.S Ensure PD IRQ is pulled up Allow toggle which button enters PD debug * Update Pins.h * Fix hard coded IRQ Pin Update stm32f1xx_it.c * Enable EPR * Tip resistance measurement * TS101 is a direct drive tip Update BSP.cpp * Add S60 and TS101 to builds Update push.yml * Update MOVThread.cpp * Refactor power menu handler * Correct prescaler Forgot to update since I changed the period * Tune in the timer divider for tip control to make PWM less audible --------- Co-authored-by: discip <53649486+discip@users.noreply.github.com>
This commit is contained in:
@@ -10,14 +10,14 @@
|
||||
#include "BSP.h"
|
||||
#include "configuration.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#ifdef I2C_SOFT
|
||||
#ifdef I2C_SOFT_BUS_2
|
||||
|
||||
#define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
|
||||
#define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
|
||||
#define SOFT_SDA_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
|
||||
#define SOFT_SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
|
||||
#define SOFT_SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0)
|
||||
#define SOFT_SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0)
|
||||
#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)
|
||||
#define SOFT_I2C_DELAY() \
|
||||
{ \
|
||||
for (int xx = 0; xx < 20; xx++) { \
|
||||
|
||||
@@ -64,10 +64,10 @@
|
||||
* OLED Brightness
|
||||
*
|
||||
*/
|
||||
#define MIN_BRIGHTNESS 0 // Min OLED brightness selectable
|
||||
#define MAX_BRIGHTNESS 100 // Max OLED brightness selectable
|
||||
#define BRIGHTNESS_STEP 25 // OLED brightness increment
|
||||
#define DEFAULT_BRIGHTNESS 25 // default OLED brightness
|
||||
#define MIN_BRIGHTNESS 0 // Min OLED brightness selectable
|
||||
#define MAX_BRIGHTNESS 100 // Max OLED brightness selectable
|
||||
#define BRIGHTNESS_STEP 25 // OLED brightness increment
|
||||
#define DEFAULT_BRIGHTNESS 25 // default OLED brightness
|
||||
|
||||
/**
|
||||
* Temp change settings
|
||||
@@ -159,9 +159,9 @@
|
||||
|
||||
#define POW_PD 1
|
||||
#define TEMP_NTC
|
||||
#define I2C_SOFT
|
||||
#define I2C_SOFT_BUS_2
|
||||
#define BATTFILTERDEPTH 8
|
||||
#define OLED_I2CBB
|
||||
#define OLED_I2CBB2
|
||||
#define ACCEL_EXITS_ON_MOVEMENT
|
||||
#define NEEDS_VBUS_PROBE 0
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "BSP.h"
|
||||
#include "I2CBB.hpp"
|
||||
#include "I2CBB2.hpp"
|
||||
#include "Pins.h"
|
||||
#include "Setup.h"
|
||||
#include <I2C_Wrapper.hpp>
|
||||
@@ -17,7 +17,7 @@ void preRToSInit() {
|
||||
HAL_Init();
|
||||
Setup_HAL(); // Setup all the HAL objects
|
||||
BSPInit();
|
||||
I2CBB::init();
|
||||
I2CBB2::init();
|
||||
/* Init the IPC objects */
|
||||
FRToSI2C::FRToSInit();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Pins.h"
|
||||
#include "Setup.h"
|
||||
#include "TipThermoModel.h"
|
||||
#include "USBPD.h"
|
||||
#include "configuration.h"
|
||||
#include "history.hpp"
|
||||
#include "main.hpp"
|
||||
@@ -17,7 +18,7 @@ const uint16_t powerPWM = 255;
|
||||
static const uint8_t holdoffTicks = 14; // delay of 8 ms
|
||||
static const uint8_t tempMeasureTicks = 14;
|
||||
|
||||
uint16_t totalPWM; // htim2.Init.Period, the full PWM cycle
|
||||
uint16_t totalPWM; // htimADC.Init.Period, the full PWM cycle
|
||||
|
||||
static bool fastPWM;
|
||||
static bool infastPWM;
|
||||
@@ -99,20 +100,20 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
|
||||
|
||||
static void switchToFastPWM(void) {
|
||||
// 10Hz
|
||||
infastPWM = true;
|
||||
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
|
||||
htim2.Instance->ARR = totalPWM;
|
||||
htim2.Instance->CCR1 = powerPWM + holdoffTicks;
|
||||
htim2.Instance->PSC = 2690;
|
||||
infastPWM = true;
|
||||
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
|
||||
htimADC.Instance->ARR = totalPWM;
|
||||
htimADC.Instance->CCR1 = powerPWM + holdoffTicks;
|
||||
htimADC.Instance->PSC = 2690;
|
||||
}
|
||||
|
||||
static void switchToSlowPWM(void) {
|
||||
// 5Hz
|
||||
infastPWM = false;
|
||||
totalPWM = powerPWM + tempMeasureTicks / 2 + holdoffTicks / 2;
|
||||
htim2.Instance->ARR = totalPWM;
|
||||
htim2.Instance->CCR1 = powerPWM + holdoffTicks / 2;
|
||||
htim2.Instance->PSC = 2690 * 2;
|
||||
infastPWM = false;
|
||||
totalPWM = powerPWM + tempMeasureTicks / 2 + holdoffTicks / 2;
|
||||
htimADC.Instance->ARR = totalPWM;
|
||||
htimADC.Instance->CCR1 = powerPWM + holdoffTicks / 2;
|
||||
htimADC.Instance->PSC = 2690 * 2;
|
||||
}
|
||||
|
||||
void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
|
||||
@@ -126,20 +127,30 @@ void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
// Period has elapsed
|
||||
if (htim->Instance == TIM2) {
|
||||
if (htim->Instance == ADC_CONTROL_TIMER) {
|
||||
// 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) {
|
||||
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
|
||||
// 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
|
||||
#ifdef TIP_HAS_DIRECT_PWM
|
||||
htimADC.Instance->CCR4 = powerPWM;
|
||||
if (pendingPWM && PWMSafetyTimer) {
|
||||
htimTip.Instance->CCR1 = pendingPWM;
|
||||
HAL_TIM_PWM_Start(&htimTip, PWM_Out_CHANNEL);
|
||||
} else {
|
||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Stop(&htimTip, PWM_Out_CHANNEL);
|
||||
}
|
||||
#else
|
||||
htimADC.Instance->CCR4 = pendingPWM;
|
||||
if (htimADC.Instance->CCR4 && PWMSafetyTimer) {
|
||||
HAL_TIM_PWM_Start(&htimTip, PWM_Out_CHANNEL);
|
||||
} else {
|
||||
HAL_TIM_PWM_Stop(&htimTip, PWM_Out_CHANNEL);
|
||||
}
|
||||
#endif
|
||||
if (fastPWM != infastPWM) {
|
||||
if (fastPWM) {
|
||||
switchToFastPWM();
|
||||
@@ -157,10 +168,11 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
|
||||
// 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);
|
||||
HAL_TIM_PWM_Stop(&htimTip, PWM_Out_CHANNEL);
|
||||
}
|
||||
}
|
||||
void unstick_I2C() {
|
||||
#ifndef I2C_SOFT_BUS_1
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
int timeout = 100;
|
||||
int timeout_cnt = 0;
|
||||
@@ -227,6 +239,7 @@ void unstick_I2C() {
|
||||
|
||||
// Call initialization function.
|
||||
HAL_I2C_Init(&hi2c1);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||
@@ -238,25 +251,148 @@ void reboot() { NVIC_SystemReset(); }
|
||||
|
||||
void delay_ms(uint16_t count) { HAL_Delay(count); }
|
||||
|
||||
bool isTipDisconnected() {
|
||||
uint8_t lastTipResistance = 0; // default to unknown
|
||||
const uint8_t numTipResistanceReadings = 3;
|
||||
uint32_t tipResistanceReadings[3] = {0, 0, 0};
|
||||
uint8_t tipResistanceReadingSlot = 0;
|
||||
bool isTipDisconnected() {
|
||||
|
||||
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
||||
uint32_t tipTemp = TipThermoModel::getTipInC();
|
||||
return tipTemp > tipDisconnectedThres;
|
||||
}
|
||||
|
||||
void setStatusLED(const enum StatusLED state) {}
|
||||
void setBuzzer(bool on) {}
|
||||
uint8_t preStartChecks() { return 1; }
|
||||
void setStatusLED(const enum StatusLED state) {}
|
||||
void setBuzzer(bool on) {}
|
||||
#ifdef TIP_RESISTANCE_SENSE_Pin
|
||||
// We want to calculate lastTipResistance
|
||||
// If tip is connected, and the tip is cold and the tip is not being heated
|
||||
// We can use the GPIO to inject a small current into the tip and measure this
|
||||
// The gpio is 100k -> diode -> tip -> gnd
|
||||
// Source is 3.3V-0.5V
|
||||
// Which is around 0.028mA this will induce:
|
||||
// 6 ohm tip -> 3.24mV (Real world ~= 3320)
|
||||
// 8 ohm tip -> 4.32mV (Real world ~= 4500)
|
||||
// Which is definitely measureable
|
||||
// Taking shortcuts here as we know we only really have to pick apart 6 and 8 ohm tips
|
||||
// These are reported as 60 and 75 respectively
|
||||
void performTipResistanceSampleReading() {
|
||||
// 0 = read then turn on pullup, 1 = read then turn off pullup, 2 = read again
|
||||
tipResistanceReadings[tipResistanceReadingSlot] = TipThermoModel::convertTipRawADCTouV(getTipRawTemp(1));
|
||||
|
||||
HAL_GPIO_WritePin(TIP_RESISTANCE_SENSE_GPIO_Port, TIP_RESISTANCE_SENSE_Pin, (tipResistanceReadingSlot == 0) ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
|
||||
tipResistanceReadingSlot++;
|
||||
}
|
||||
void FinishMeasureTipResistance() {
|
||||
|
||||
// Otherwise we now have the 4 samples;
|
||||
// _^_ order, 2 delta's, combine these
|
||||
|
||||
int32_t calculatedSkew = tipResistanceReadings[0] - tipResistanceReadings[2]; // If positive tip is cooling
|
||||
calculatedSkew /= 2; // divide by two to get offset per time constant
|
||||
|
||||
int32_t reading = (((tipResistanceReadings[1] - tipResistanceReadings[0]) + calculatedSkew) // jump 1 - skew
|
||||
+ // +
|
||||
((tipResistanceReadings[1] - tipResistanceReadings[2]) + calculatedSkew) // jump 2 - skew
|
||||
) //
|
||||
/ 2; // Take average
|
||||
// // As we are only detecting two resistances; we can split the difference for now
|
||||
uint8_t newRes = 0;
|
||||
if (reading > 1200) {
|
||||
// return; // Change nothing as probably disconnected tip
|
||||
tipResistanceReadingSlot = lastTipResistance = 0;
|
||||
return;
|
||||
} else if (reading < 800) {
|
||||
newRes = 62;
|
||||
} else {
|
||||
newRes = 80;
|
||||
}
|
||||
lastTipResistance = newRes;
|
||||
}
|
||||
volatile bool tipMeasurementOccuring = true;
|
||||
volatile TickType_t nextTipMeasurement = 100;
|
||||
|
||||
void performTipMeasurementStep() {
|
||||
|
||||
// Wait 200ms for settle time
|
||||
if (xTaskGetTickCount() < (nextTipMeasurement)) {
|
||||
return;
|
||||
}
|
||||
nextTipMeasurement = xTaskGetTickCount() + (TICKS_100MS * 5);
|
||||
if (tipResistanceReadingSlot < numTipResistanceReadings) {
|
||||
performTipResistanceSampleReading();
|
||||
return;
|
||||
}
|
||||
|
||||
// We are sensing the resistance
|
||||
FinishMeasureTipResistance();
|
||||
|
||||
tipMeasurementOccuring = false;
|
||||
}
|
||||
#endif
|
||||
uint8_t preStartChecks() {
|
||||
#ifdef TIP_RESISTANCE_SENSE_Pin
|
||||
performTipMeasurementStep();
|
||||
if (preStartChecksDone() != 1) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAS_SPLIT_POWER_PATH
|
||||
|
||||
// We want to enable the power path that has the highest voltage
|
||||
// Nominally one will be ~=0 and one will be high. Unless you jamb both in, then both _may_ be high, or device may be dead
|
||||
{
|
||||
uint16_t dc = getRawDCVin();
|
||||
uint16_t pd = getRawPDVin();
|
||||
if (dc > pd) {
|
||||
HAL_GPIO_WritePin(DC_SELECT_GPIO_Port, DC_SELECT_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(PD_SELECT_GPIO_Port, PD_SELECT_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
HAL_GPIO_WritePin(PD_SELECT_GPIO_Port, PD_SELECT_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(DC_SELECT_GPIO_Port, DC_SELECT_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef POW_PD
|
||||
// If we are in the middle of negotiating PD, wait until timeout
|
||||
// Before turning on the heater
|
||||
if (!USBPowerDelivery::negotiationComplete()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
uint64_t getDeviceID() {
|
||||
//
|
||||
return HAL_GetUIDw0() | ((uint64_t)HAL_GetUIDw1() << 32);
|
||||
}
|
||||
|
||||
uint8_t getTipResistanceX10() { return TIP_RESISTANCE; }
|
||||
uint8_t preStartChecksDone() {
|
||||
#ifdef TIP_RESISTANCE_SENSE_Pin
|
||||
return (lastTipResistance == 0 || tipResistanceReadingSlot < numTipResistanceReadings || tipMeasurementOccuring) ? 0 : 1;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t preStartChecksDone() { return 1; }
|
||||
uint8_t getTipResistanceX10() {
|
||||
// Return tip resistance in x10 ohms
|
||||
// We can measure this using the op-amp
|
||||
return lastTipResistance;
|
||||
}
|
||||
|
||||
uint8_t getTipThermalMass() { return TIP_THERMAL_MASS; }
|
||||
|
||||
uint8_t getTipInertia() { return TIP_THERMAL_MASS; }
|
||||
uint8_t getTipThermalMass() {
|
||||
if (lastTipResistance >= 80) {
|
||||
return TIP_THERMAL_MASS;
|
||||
}
|
||||
return 45;
|
||||
}
|
||||
uint8_t getTipInertia() {
|
||||
if (lastTipResistance >= 80) {
|
||||
return TIP_THERMAL_MASS;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
@@ -6,87 +6,145 @@
|
||||
*/
|
||||
|
||||
#ifndef BSP_MINIWARE_PINS_H_
|
||||
#define BSP_MINIWARE_PINS_H_
|
||||
#include "configuration.h"
|
||||
#define BSP_MINIWARE_PINS_H_
|
||||
#include "configuration.h"
|
||||
|
||||
#ifdef MODEL_TS100
|
||||
#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 TMP36_ADC2_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
|
||||
#define KEY_A_GPIO_Port GPIOA
|
||||
#define INT_Orientation_Pin GPIO_PIN_3
|
||||
#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
|
||||
#define SCL_GPIO_Port GPIOB
|
||||
#define SDA_Pin GPIO_PIN_7
|
||||
#define SDA_GPIO_Port GPIOB
|
||||
#endif
|
||||
#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 TMP36_ADC2_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
|
||||
#define KEY_A_GPIO_Port GPIOA
|
||||
#define INT_Orientation_Pin GPIO_PIN_3
|
||||
#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 TIP_CONTROL_TIMER TIM3
|
||||
#define ADC_CONTROL_TIMER TIM2
|
||||
#define ADC_CONTROL_TIMER_IRQ TIM2_IRQn
|
||||
#define ADC_TRIGGER ADC_EXTERNALTRIGINJECCONV_T2_TRGO
|
||||
#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
|
||||
|
||||
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
|
||||
// TS80 & TS80P 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 TMP36_ADC2_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
|
||||
#ifdef MODEL_TS101
|
||||
|
||||
#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
|
||||
#define SCL2_Pin GPIO_PIN_5
|
||||
#define SCL2_GPIO_Port GPIOA
|
||||
#define SDA2_Pin GPIO_PIN_1
|
||||
#define SDA2_GPIO_Port GPIOA
|
||||
#define KEY_B_Pin GPIO_PIN_10
|
||||
#define KEY_B_GPIO_Port GPIOA
|
||||
#define TMP36_INPUT_Pin GPIO_PIN_4
|
||||
#define TMP36_INPUT_GPIO_Port GPIOA
|
||||
#define TMP36_ADC1_CHANNEL ADC_CHANNEL_4
|
||||
#define TMP36_ADC2_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 PD_VIN_Pin GPIO_PIN_6
|
||||
#define PD_VIN_GPIO_Port GPIOA
|
||||
#define PD_VIN_ADC1_CHANNEL ADC_CHANNEL_6
|
||||
#define PD_VIN_ADC2_CHANNEL ADC_CHANNEL_6
|
||||
#define OLED_RESET_Pin GPIO_PIN_7
|
||||
#define OLED_RESET_GPIO_Port GPIOA
|
||||
#define KEY_A_Pin GPIO_PIN_8
|
||||
#define KEY_A_GPIO_Port GPIOA
|
||||
#define PWM_Out_Pin GPIO_PIN_0
|
||||
#define PWM_Out_GPIO_Port GPIOA
|
||||
#define PWM_Out_CHANNEL TIM_CHANNEL_1
|
||||
#define TIP_CONTROL_TIMER TIM2
|
||||
#define ADC_CONTROL_TIMER TIM4
|
||||
#define ADC_CONTROL_TIMER_IRQ TIM4_IRQn
|
||||
#define ADC_TRIGGER ADC_EXTERNALTRIGINJECCONV_T4_TRGO
|
||||
#define SCL_Pin GPIO_PIN_0
|
||||
#define SCL_GPIO_Port GPIOB
|
||||
#define SDA_Pin GPIO_PIN_1
|
||||
#define SDA_GPIO_Port GPIOB
|
||||
// PD controller
|
||||
#define SCL2_Pin GPIO_PIN_6
|
||||
#define SCL2_GPIO_Port GPIOB
|
||||
#define SDA2_Pin GPIO_PIN_5
|
||||
#define SDA2_GPIO_Port GPIOB
|
||||
#define INT_PD_Pin GPIO_PIN_7
|
||||
#define INT_PD_GPIO_Port GPIOB
|
||||
// Selecting the DC source to route to theg
|
||||
#define DC_SELECT_Pin GPIO_PIN_4
|
||||
#define DC_SELECT_GPIO_Port GPIOB
|
||||
#define PD_SELECT_Pin GPIO_PIN_15
|
||||
#define PD_SELECT_GPIO_Port GPIOA
|
||||
|
||||
#endif
|
||||
#define TIP_RESISTANCE_SENSE_Pin GPIO_PIN_1
|
||||
#define TIP_RESISTANCE_SENSE_GPIO_Port GPIOA
|
||||
|
||||
#ifdef MODEL_TS80P
|
||||
// TS80P pin map
|
||||
#define INT_PD_Pin GPIO_PIN_9
|
||||
#define INT_PD_GPIO_Port GPIOA
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
|
||||
// TS80 & TS80P 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 TMP36_ADC2_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 TIP_CONTROL_TIMER TIM3
|
||||
#define ADC_CONTROL_TIMER TIM2
|
||||
#define ADC_CONTROL_TIMER_IRQ TIM2_IRQn
|
||||
#define ADC_TRIGGER ADC_EXTERNALTRIGINJECCONV_T2_TRGO
|
||||
#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
|
||||
#define SCL2_Pin GPIO_PIN_5
|
||||
#define SCL2_GPIO_Port GPIOA
|
||||
#define SDA2_Pin GPIO_PIN_1
|
||||
#define SDA2_GPIO_Port GPIOA
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_TS80P
|
||||
// TS80P pin map
|
||||
#define INT_PD_Pin GPIO_PIN_9
|
||||
#define INT_PD_GPIO_Port GPIOA
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* BSP_MINIWARE_PINS_H_ */
|
||||
|
||||
@@ -25,7 +25,10 @@ bool getIsPoweredByDCIN() {
|
||||
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
|
||||
return false;
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_TS101
|
||||
// TODO have to check what we are using
|
||||
return false;
|
||||
#endif
|
||||
#ifdef MODEL_TS100
|
||||
return true;
|
||||
#endif
|
||||
|
||||
@@ -18,8 +18,8 @@ DMA_HandleTypeDef hdma_i2c1_rx;
|
||||
DMA_HandleTypeDef hdma_i2c1_tx;
|
||||
|
||||
IWDG_HandleTypeDef hiwdg;
|
||||
TIM_HandleTypeDef htim2;
|
||||
TIM_HandleTypeDef htim3;
|
||||
TIM_HandleTypeDef htimADC;
|
||||
TIM_HandleTypeDef htimTip;
|
||||
#define ADC_FILTER_LEN 4
|
||||
#define ADC_SAMPLES 16
|
||||
uint16_t ADCReadings[ADC_SAMPLES]; // Used to store the adc readings for the handle cold junction temp
|
||||
@@ -29,8 +29,8 @@ static void SystemClock_Config(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_I2C1_Init(void);
|
||||
static void MX_IWDG_Init(void);
|
||||
static void MX_TIM3_Init(void);
|
||||
static void MX_TIM2_Init(void);
|
||||
static void MX_TIP_CONTROL_TIMER_Init(void);
|
||||
static void MX_ADC_CONTROL_TIMER_Init(void);
|
||||
static void MX_DMA_Init(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_ADC2_Init(void);
|
||||
@@ -45,11 +45,13 @@ void Setup_HAL() {
|
||||
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
#ifndef I2C_SOFT_BUS_1
|
||||
MX_I2C1_Init();
|
||||
#endif
|
||||
MX_ADC1_Init();
|
||||
MX_ADC2_Init();
|
||||
MX_TIM3_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_TIP_CONTROL_TIMER_Init();
|
||||
MX_ADC_CONTROL_TIMER_Init();
|
||||
MX_IWDG_Init();
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)ADCReadings, (ADC_SAMPLES)); // start DMA of normal readings
|
||||
HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
|
||||
@@ -68,7 +70,41 @@ uint16_t getADCHandleTemp(uint8_t sample) {
|
||||
return filter.average() >> 1;
|
||||
}
|
||||
|
||||
#ifdef HAS_SPLIT_POWER_PATH
|
||||
static history<uint16_t, ADC_FILTER_LEN> filteredDC = {{0}, 0, 0};
|
||||
static history<uint16_t, ADC_FILTER_LEN> filteredPD = {{0}, 0, 0};
|
||||
|
||||
uint16_t getRawDCVin() { return filteredDC.average(); }
|
||||
uint16_t getRawPDVin() { return filteredPD.average(); }
|
||||
#endif
|
||||
|
||||
uint16_t getADCVin(uint8_t sample) {
|
||||
#ifdef HAS_SPLIT_POWER_PATH
|
||||
// In split power path operation, we need to read both inputs, and return the larger
|
||||
|
||||
if (sample) {
|
||||
{
|
||||
uint16_t latestADC = 0;
|
||||
latestADC += hadc2.Instance->JDR1;
|
||||
latestADC += hadc2.Instance->JDR2;
|
||||
latestADC <<= 3;
|
||||
filteredDC.update(latestADC);
|
||||
}
|
||||
{
|
||||
uint16_t latestADC = 0;
|
||||
latestADC += hadc2.Instance->JDR3;
|
||||
latestADC += hadc2.Instance->JDR4;
|
||||
latestADC <<= 3;
|
||||
filteredPD.update(latestADC);
|
||||
}
|
||||
}
|
||||
uint16_t dc = filteredDC.average();
|
||||
uint16_t pd = filteredPD.average();
|
||||
if (dc > pd) {
|
||||
return dc;
|
||||
}
|
||||
return pd;
|
||||
#else
|
||||
static history<uint16_t, ADC_FILTER_LEN> filter = {{0}, 0, 0};
|
||||
if (sample) {
|
||||
uint16_t latestADC = 0;
|
||||
@@ -81,6 +117,7 @@ uint16_t getADCVin(uint8_t sample) {
|
||||
filter.update(latestADC);
|
||||
}
|
||||
return filter.average();
|
||||
#endif
|
||||
}
|
||||
// Returns either average or instant value. When sample is set the samples from the injected ADC are copied to the filter and then the raw reading is returned
|
||||
uint16_t getTipRawTemp(uint8_t sample) {
|
||||
@@ -178,7 +215,7 @@ static void MX_ADC1_Init(void) {
|
||||
sConfigInjected.InjectedRank = 1;
|
||||
sConfigInjected.InjectedNbrOfConversion = 4;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_28CYCLES_5;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_TRGO;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_TRIGGER;
|
||||
sConfigInjected.AutoInjectedConv = DISABLE;
|
||||
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
||||
sConfigInjected.InjectedOffset = 0;
|
||||
@@ -203,7 +240,7 @@ static void MX_ADC2_Init(void) {
|
||||
/**Common config
|
||||
*/
|
||||
hadc2.Instance = ADC2;
|
||||
hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
|
||||
hadc2.Init.ContinuousConvMode = ENABLE;
|
||||
hadc2.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
@@ -217,13 +254,18 @@ static void MX_ADC2_Init(void) {
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
|
||||
sConfigInjected.InjectedNbrOfConversion = 4;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_28CYCLES_5;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_TRGO;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_TRIGGER;
|
||||
sConfigInjected.AutoInjectedConv = DISABLE;
|
||||
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
||||
sConfigInjected.InjectedOffset = 0;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
|
||||
#ifdef HAS_SPLIT_POWER_PATH
|
||||
sConfigInjected.InjectedChannel = PD_VIN_ADC2_CHANNEL;
|
||||
#endif
|
||||
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;
|
||||
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_4;
|
||||
@@ -259,35 +301,43 @@ static void MX_IWDG_Init(void) {
|
||||
}
|
||||
|
||||
/* TIM3 init function */
|
||||
static void MX_TIM3_Init(void) {
|
||||
static void MX_TIP_CONTROL_TIMER_Init(void) {
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig;
|
||||
TIM_MasterConfigTypeDef sMasterConfig;
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 8;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 100; // 5 Khz PWM freq
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before div
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; // Preload the ARR register (though we dont use this)
|
||||
HAL_TIM_Base_Init(&htim3);
|
||||
htimTip.Instance = TIP_CONTROL_TIMER;
|
||||
#ifdef TIP_HAS_DIRECT_PWM
|
||||
htimTip.Init.Prescaler = 100;
|
||||
#else
|
||||
htimTip.Init.Prescaler = 3;
|
||||
#endif
|
||||
htimTip.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htimTip.Init.Period = 255; // 5 Khz PWM freq
|
||||
htimTip.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before div
|
||||
htimTip.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; // Preload the ARR register (though we dont use this)
|
||||
HAL_TIM_Base_Init(&htimTip);
|
||||
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);
|
||||
HAL_TIM_ConfigClockSource(&htimTip, &sClockSourceConfig);
|
||||
|
||||
HAL_TIM_PWM_Init(&htim3);
|
||||
HAL_TIM_PWM_Init(&htimTip);
|
||||
|
||||
HAL_TIM_OC_Init(&htim3);
|
||||
HAL_TIM_OC_Init(&htimTip);
|
||||
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htimTip, &sMasterConfig);
|
||||
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 50; // 50% duty cycle, that is AC coupled through the cap
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
#ifdef TIP_HAS_DIRECT_PWM
|
||||
sConfigOC.Pulse = 0; // PWM is direct to tip
|
||||
#else
|
||||
sConfigOC.Pulse = 127; // 50% duty cycle, that is AC coupled through the cap to provide an on signal (This does not do tip at 50% duty cycle)
|
||||
#endif
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL);
|
||||
HAL_TIM_PWM_ConfigChannel(&htimTip, &sConfigOC, PWM_Out_CHANNEL);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
@@ -302,12 +352,12 @@ static void MX_TIM3_Init(void) {
|
||||
// Remap TIM3_CH1 to be on PB4
|
||||
__HAL_AFIO_REMAP_TIM3_PARTIAL();
|
||||
#else
|
||||
// No re-map required
|
||||
// No re-map required
|
||||
#endif
|
||||
HAL_TIM_PWM_Start(&htim3, PWM_Out_CHANNEL);
|
||||
HAL_TIM_PWM_Start(&htimTip, PWM_Out_CHANNEL);
|
||||
}
|
||||
/* TIM3 init function */
|
||||
static void MX_TIM2_Init(void) {
|
||||
static void MX_ADC_CONTROL_TIMER_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
|
||||
@@ -318,30 +368,30 @@ static void MX_TIM2_Init(void) {
|
||||
|
||||
// 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;
|
||||
htimADC.Instance = ADC_CONTROL_TIMER;
|
||||
// dummy value, will be reconfigured by BSPInit()
|
||||
htim2.Init.Prescaler = 2000; // 2 MHz timer clock/2000 = 1 kHz tick rate
|
||||
htimADC.Init.Prescaler = 2000; // 2 MHz timer clock/2000 = 1 kHz tick rate
|
||||
|
||||
// pwm out is 10k from tim3, we want to run our PWM at around 10hz or slower on the output stage
|
||||
// These values give a rate of around 3.5 Hz for "fast" mode and 1.84 Hz for "slow"
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htimADC.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
// dummy value, will be reconfigured by BSPInit()
|
||||
htim2.Init.Period = powerPWM + 14 * 2;
|
||||
htimADC.Init.Period = powerPWM + 14 * 2;
|
||||
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 8 MHz (x2 APB1) before divide
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
htim2.Init.RepetitionCounter = 0;
|
||||
HAL_TIM_Base_Init(&htim2);
|
||||
htimADC.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 8 MHz (x2 APB1) before divide
|
||||
htimADC.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
htimADC.Init.RepetitionCounter = 0;
|
||||
HAL_TIM_Base_Init(&htimADC);
|
||||
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);
|
||||
HAL_TIM_ConfigClockSource(&htimADC, &sClockSourceConfig);
|
||||
|
||||
HAL_TIM_PWM_Init(&htim2);
|
||||
HAL_TIM_OC_Init(&htim2);
|
||||
HAL_TIM_PWM_Init(&htimADC);
|
||||
HAL_TIM_OC_Init(&htimADC);
|
||||
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);
|
||||
HAL_TIMEx_MasterConfigSynchronization(&htimADC, &sMasterConfig);
|
||||
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
// dummy value, will be reconfigured by BSPInit() in the BSP.cpp
|
||||
@@ -354,15 +404,15 @@ static void MX_TIM2_Init(void) {
|
||||
* */
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||
HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_ConfigChannel(&htimADC, &sConfigOC, TIM_CHANNEL_1);
|
||||
sConfigOC.Pulse = 0; // default to entirely off
|
||||
HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4);
|
||||
HAL_TIM_OC_ConfigChannel(&htimADC, &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_SetPriority(TIM2_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
HAL_TIM_Base_Start_IT(&htimADC);
|
||||
HAL_TIM_PWM_Start(&htimADC, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Start_IT(&htimADC, TIM_CHANNEL_4);
|
||||
HAL_NVIC_SetPriority(ADC_CONTROL_TIMER_IRQ, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(ADC_CONTROL_TIMER_IRQ);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,8 +496,8 @@ static void MX_GPIO_Init(void) {
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
#endif
|
||||
#else
|
||||
/* TS80 */
|
||||
/* Leave USB lines open circuit*/
|
||||
/* TS80 */
|
||||
/* Leave USB lines open circuit*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -462,12 +512,45 @@ static void MX_GPIO_Init(void) {
|
||||
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(30);
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||
|
||||
#ifdef DC_SELECT_Pin
|
||||
GPIO_InitStruct.Pin = DC_SELECT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(DC_SELECT_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(DC_SELECT_GPIO_Port, DC_SELECT_Pin, GPIO_PIN_RESET);
|
||||
#endif
|
||||
|
||||
#ifdef PD_SELECT_Pin
|
||||
GPIO_InitStruct.Pin = PD_SELECT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(PD_SELECT_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(PD_SELECT_GPIO_Port, PD_SELECT_Pin, GPIO_PIN_RESET);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TIP_RESISTANCE_SENSE_Pin
|
||||
GPIO_InitStruct.Pin = TIP_RESISTANCE_SENSE_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(TIP_RESISTANCE_SENSE_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_WritePin(TIP_RESISTANCE_SENSE_GPIO_Port, TIP_RESISTANCE_SENSE_Pin, GPIO_PIN_RESET);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef INT_PD_Pin
|
||||
GPIO_InitStruct.Pin = INT_PD_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(INT_PD_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
#endif
|
||||
}
|
||||
#ifdef USE_FULL_ASSERT
|
||||
void assert_failed(uint8_t *file, uint32_t line) { asm("bkpt"); }
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#ifndef SETUP_H_
|
||||
#define SETUP_H_
|
||||
|
||||
#include "configuration.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -24,13 +24,18 @@ extern I2C_HandleTypeDef hi2c1;
|
||||
|
||||
extern IWDG_HandleTypeDef hiwdg;
|
||||
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
extern TIM_HandleTypeDef htimADC;
|
||||
extern TIM_HandleTypeDef htimTip;
|
||||
void Setup_HAL();
|
||||
uint16_t getADCHandleTemp(uint8_t sample);
|
||||
uint16_t getADCVin(uint8_t sample);
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); // Since the hal header file does not define this one
|
||||
|
||||
#ifdef HAS_SPLIT_POWER_PATH
|
||||
uint16_t getRawDCVin();
|
||||
uint16_t getRawPDVin();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10,22 +10,34 @@
|
||||
#include "BSP.h"
|
||||
#include "configuration.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#ifdef I2C_SOFT
|
||||
#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
|
||||
|
||||
#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
|
||||
|
||||
#define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
|
||||
#define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
|
||||
#define SOFT_SDA_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
|
||||
#define SOFT_SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
|
||||
#define SOFT_SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0)
|
||||
#define SOFT_SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0)
|
||||
#define SOFT_I2C_DELAY() \
|
||||
{ \
|
||||
for (int xx = 0; xx < 15; xx++) { \
|
||||
for (int xx = 0; xx < 10; xx++) { \
|
||||
asm("nop"); \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
// 40 ~= 100kHz; 15 gives around 250kHz or so which is fast _and_ stable
|
||||
|
||||
#endif /* BSP_MINIWARE_SOFTWARE_I2C_H_ */
|
||||
|
||||
@@ -130,9 +130,9 @@
|
||||
// Vin_max = (3.3*(r1+r2))/(r2)
|
||||
// vdiv = (32768*4)/(vin_max*10)
|
||||
|
||||
#if defined(MODEL_TS100) + defined(MODEL_TS80) + defined(MODEL_TS80P) > 1
|
||||
#if defined(MODEL_TS100) + defined(MODEL_TS80) + defined(MODEL_TS80P) + defined(MODEL_TS101) > 1
|
||||
#error "Multiple models defined!"
|
||||
#elif defined(MODEL_TS100) + defined(MODEL_TS80) + defined(MODEL_TS80P) == 0
|
||||
#elif defined(MODEL_TS100) + defined(MODEL_TS80) + defined(MODEL_TS80P) + defined(MODEL_TS101) == 0
|
||||
#error "No model defined!"
|
||||
#endif
|
||||
#define NEEDS_VBUS_PROBE 0
|
||||
@@ -174,6 +174,39 @@
|
||||
#define TEMP_TMP36
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_TS101
|
||||
#define VOLTAGE_DIV 700 // 700 - Default divider from schematic
|
||||
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
|
||||
#define PID_POWER_LIMIT 100 // Sets the max pwm power limit
|
||||
#define POWER_LIMIT 0 // 0 watts default limit
|
||||
#define MAX_POWER_LIMIT 100
|
||||
#define POWER_LIMIT_STEPS 5
|
||||
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100
|
||||
#define TEMP_uV_LOOKUP_HAKKO
|
||||
|
||||
#define HARDWARE_MAX_WATTAGE_X10 1000
|
||||
#define TIP_THERMAL_MASS 65 // X10 watts to raise 1 deg C in 1 second
|
||||
#define TIP_RESISTANCE 75 // x10 ohms, 7.5 typical for ts100 tips
|
||||
|
||||
#define TIP_HAS_DIRECT_PWM 1
|
||||
#define POW_DC 1
|
||||
#define POW_PD 1
|
||||
#define I2C_SOFT_BUS_2 1
|
||||
#define I2C_SOFT_BUS_1 1
|
||||
#define OLED_I2CBB1 1
|
||||
#define USB_PD_I2CBB2 1
|
||||
#define USB_PD_VMAX 28 // Device supposedly can do 28V; looks like vmax is 33 ish
|
||||
#define OLED_128x32 1
|
||||
#define OLED_FLIP 1
|
||||
#define HAS_SPLIT_POWER_PATH 1
|
||||
#define TEMP_NTC 1
|
||||
#define ACCEL_I2CBB1 1
|
||||
#define POW_EPR 1
|
||||
#define HAS_POWER_DEBUG_MENU
|
||||
#define DEBUG_POWER_MENU_BUTTON_B
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
|
||||
#define MAX_POWER_LIMIT 40
|
||||
#define POWER_LIMIT_STEPS 2
|
||||
@@ -212,10 +245,20 @@
|
||||
#define POW_PD 1
|
||||
#define POW_QC 1
|
||||
#define TEMP_NTC
|
||||
#define I2C_SOFT
|
||||
#define I2C_SOFT_BUS_2 1
|
||||
#define SC7_ORI_FLIP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_TS101
|
||||
#define FLASH_LOGOADDR (0x08000000 + (126 * 1024))
|
||||
|
||||
#else
|
||||
#define FLASH_LOGOADDR (0x08000000 + (62 * 1024))
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_TS101
|
||||
#define SETTINGS_START_PAGE (0x08000000 + (127 * 1024))
|
||||
#else
|
||||
#define SETTINGS_START_PAGE (0x08000000 + (63 * 1024))
|
||||
#endif
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
void flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||
FLASH_EraseInitTypeDef pEraseInit;
|
||||
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
@@ -30,10 +31,9 @@ void flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||
HAL_FLASH_Unlock();
|
||||
for (uint16_t i = 0; i < (length / 2); i++) {
|
||||
resetWatchdog();
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE+ (i*sizeof(uint16_t)), data[i]);
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE + (i * sizeof(uint16_t)), data[i]);
|
||||
}
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
}
|
||||
|
||||
void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, (uint8_t*)SETTINGS_START_PAGE, length); }
|
||||
void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, (uint8_t *)SETTINGS_START_PAGE, length); }
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "configuration.h"
|
||||
#ifdef POW_PD
|
||||
#include "BSP.h"
|
||||
#include "I2CBB.hpp"
|
||||
#include "I2CBB2.hpp"
|
||||
#include "Setup.h"
|
||||
|
||||
bool fusb_read_buf(const uint8_t deviceAddr, const uint8_t registerAdd, const uint8_t size, uint8_t *buf) { return I2CBB::Mem_Read(deviceAddr, registerAdd, buf, size); }
|
||||
bool fusb_read_buf(const uint8_t deviceAddr, const uint8_t registerAdd, const uint8_t size, uint8_t *buf) { return I2CBB2::Mem_Read(deviceAddr, registerAdd, buf, size); }
|
||||
|
||||
bool fusb_write_buf(const uint8_t deviceAddr, const uint8_t registerAdd, const uint8_t size, uint8_t *buf) { return I2CBB::Mem_Write(deviceAddr, registerAdd, buf, size); }
|
||||
bool fusb_write_buf(const uint8_t deviceAddr, const uint8_t registerAdd, const uint8_t size, uint8_t *buf) { return I2CBB2::Mem_Write(deviceAddr, registerAdd, buf, size); }
|
||||
|
||||
void setupFUSBIRQ() {
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
@@ -6,20 +6,27 @@
|
||||
*/
|
||||
|
||||
#include "BSP.h"
|
||||
#include "I2CBB.hpp"
|
||||
#include "I2CBB1.hpp"
|
||||
#include "I2CBB2.hpp"
|
||||
#include "Pins.h"
|
||||
#include "Setup.h"
|
||||
#include "configuration.h"
|
||||
#include <I2C_Wrapper.hpp>
|
||||
|
||||
|
||||
void preRToSInit() {
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
|
||||
*/
|
||||
HAL_Init();
|
||||
Setup_HAL(); // Setup all the HAL objects
|
||||
BSPInit();
|
||||
#ifdef I2C_SOFT
|
||||
I2CBB::init();
|
||||
#ifdef I2C_SOFT_BUS_2
|
||||
I2CBB2::init();
|
||||
#endif
|
||||
#ifdef I2C_SOFT_BUS_1
|
||||
I2CBB1::init();
|
||||
#endif
|
||||
|
||||
/* Init the IPC objects */
|
||||
FRToSI2C::FRToSInit();
|
||||
}
|
||||
|
||||
@@ -58,14 +58,23 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
||||
*/
|
||||
GPIO_InitStruct.Pin = TIP_TEMP_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(TIP_TEMP_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = TMP36_INPUT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(TMP36_INPUT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = VIN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(VIN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
#ifdef PD_VIN_Pin
|
||||
|
||||
GPIO_InitStruct.Pin = PD_VIN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(PD_VIN_GPIO_Port, &GPIO_InitStruct);
|
||||
#endif
|
||||
/* ADC2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||
@@ -83,7 +92,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(SCL_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
@@ -128,5 +137,8 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim_base) {
|
||||
} else if (htim_base->Instance == TIM2) {
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||
} else if (htim_base->Instance == TIM4) {
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM4_CLK_ENABLE();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// This is the stock standard STM interrupt file full of handlers
|
||||
#include "stm32f1xx_it.h"
|
||||
#include "Pins.h"
|
||||
#include "Setup.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "stm32f1xx.h"
|
||||
@@ -11,7 +12,6 @@ extern TIM_HandleTypeDef htim1; // used for the systick
|
||||
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
// Systick is used by FreeRTOS tick
|
||||
void SysTick_Handler(void) { osSystickHandler(); }
|
||||
|
||||
@@ -29,11 +29,33 @@ void ADC1_2_IRQHandler(void) { HAL_ADC_IRQHandler(&hadc1); }
|
||||
|
||||
// Timer 1 has overflowed, used for HAL ticks
|
||||
void TIM1_UP_IRQHandler(void) { HAL_TIM_IRQHandler(&htim1); }
|
||||
|
||||
// Timer 3 is used for the PWM output to the tip
|
||||
void TIM3_IRQHandler(void) { HAL_TIM_IRQHandler(&htim3); }
|
||||
void TIM3_IRQHandler(void) {
|
||||
TIM_HandleTypeDef *handle = &htimADC;
|
||||
if (htimTip.Instance == TIM3) {
|
||||
handle = &htimTip;
|
||||
}
|
||||
HAL_TIM_IRQHandler(handle);
|
||||
}
|
||||
|
||||
// Timer 2 is used for co-ordination of PWM & ADC
|
||||
void TIM2_IRQHandler(void) { HAL_TIM_IRQHandler(&htim2); }
|
||||
void TIM2_IRQHandler(void) {
|
||||
TIM_HandleTypeDef *handle = &htimADC;
|
||||
if (htimTip.Instance == TIM2) {
|
||||
handle = &htimTip;
|
||||
}
|
||||
HAL_TIM_IRQHandler(handle);
|
||||
}
|
||||
|
||||
// Timer 2 is used for co-ordination of PWM & ADC
|
||||
void TIM4_IRQHandler(void) {
|
||||
TIM_HandleTypeDef *handle = &htimADC;
|
||||
if (htimTip.Instance == TIM4) {
|
||||
handle = &htimTip;
|
||||
}
|
||||
HAL_TIM_IRQHandler(handle);
|
||||
}
|
||||
|
||||
void I2C1_EV_IRQHandler(void) { HAL_I2C_EV_IRQHandler(&hi2c1); }
|
||||
void I2C1_ER_IRQHandler(void) { HAL_I2C_ER_IRQHandler(&hi2c1); }
|
||||
@@ -41,4 +63,9 @@ void I2C1_ER_IRQHandler(void) { HAL_I2C_ER_IRQHandler(&hi2c1); }
|
||||
void DMA1_Channel6_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_i2c1_tx); }
|
||||
|
||||
void DMA1_Channel7_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_i2c1_rx); }
|
||||
void EXTI9_5_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); }
|
||||
|
||||
void EXTI9_5_IRQHandler(void) {
|
||||
#ifdef INT_PD_Pin
|
||||
HAL_GPIO_EXTI_IRQHandler(INT_PD_Pin);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -12,12 +12,8 @@
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
#ifndef VECT_TAB_OFFSET
|
||||
#define VECT_TAB_OFFSET \
|
||||
0x00004000U /*!< Vector Table base offset field. \
|
||||
This value must be a multiple of 0x200. */
|
||||
// We offset this by 0x4000 to because of the bootloader
|
||||
#error VECT_TAB_OFFSET
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include "BSP.h"
|
||||
#include "configuration.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#ifdef I2C_SOFT
|
||||
#ifdef I2C_SOFT_BUS_2
|
||||
|
||||
#define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
|
||||
#define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
|
||||
#define SOFT_SDA_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
|
||||
#define SOFT_SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
|
||||
#define SOFT_SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0)
|
||||
#define SOFT_SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0)
|
||||
#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)
|
||||
#define SOFT_I2C_DELAY() \
|
||||
{ \
|
||||
for (int xx = 0; xx < 12; xx++) { \
|
||||
|
||||
@@ -155,10 +155,11 @@
|
||||
|
||||
#define OLED_128x32
|
||||
#define GPIO_VIBRATION
|
||||
#define POW_PD_EXT 1
|
||||
#define POW_PD_EXT 1
|
||||
#define DEBUG_POWER_MENU_BUTTON_B 1
|
||||
#define HAS_POWER_DEBUG_MENU
|
||||
#define TEMP_NTC
|
||||
#define I2C_SOFT // For now we are doing software I2C to get around hardware chip issues
|
||||
#define I2C_SOFT_BUS_2 // For now we are doing software I2C to get around hardware chip issues
|
||||
#define OLED_I2CBB
|
||||
|
||||
#define MODEL_HAS_DCDC // We dont have DC/DC but have reallly fast PWM that gets us roughly the same place
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "BSP.h"
|
||||
#include "I2CBB.hpp"
|
||||
#include "I2CBB2.hpp"
|
||||
#include "Pins.h"
|
||||
#include "Setup.h"
|
||||
#include <I2C_Wrapper.hpp>
|
||||
@@ -17,8 +17,8 @@ void preRToSInit() {
|
||||
HAL_Init();
|
||||
Setup_HAL(); // Setup all the HAL objects
|
||||
BSPInit();
|
||||
#ifdef I2C_SOFT
|
||||
I2CBB::init();
|
||||
#ifdef I2C_SOFT_BUS_2
|
||||
I2CBB2::init();
|
||||
#endif
|
||||
/* Init the IPC objects */
|
||||
FRToSI2C::FRToSInit();
|
||||
|
||||
Reference in New Issue
Block a user