Skip to content

Commit 70cda7e

Browse files
committed
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
1 parent a06d6cf commit 70cda7e

30 files changed

+869
-258
lines changed

source/Core/BSP/MHP30/Software_I2C.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
#include "BSP.h"
1111
#include "configuration.h"
1212
#include "stm32f1xx_hal.h"
13-
#ifdef I2C_SOFT_PD
13+
#ifdef I2C_SOFT_BUS_2
1414

15-
#define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
16-
#define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
17-
#define SOFT_SDA_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
18-
#define SOFT_SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
19-
#define SOFT_SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0)
20-
#define SOFT_SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0)
15+
#define SOFT_SCL2_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
16+
#define SOFT_SCL2_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
17+
#define SOFT_SDA2_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
18+
#define SOFT_SDA2_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
19+
#define SOFT_SDA2_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0)
20+
#define SOFT_SCL2_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0)
2121
#define SOFT_I2C_DELAY() \
2222
{ \
2323
for (int xx = 0; xx < 20; xx++) { \

source/Core/BSP/MHP30/configuration.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@
6464
* OLED Brightness
6565
*
6666
*/
67-
#define MIN_BRIGHTNESS 0 // Min OLED brightness selectable
68-
#define MAX_BRIGHTNESS 100 // Max OLED brightness selectable
69-
#define BRIGHTNESS_STEP 25 // OLED brightness increment
70-
#define DEFAULT_BRIGHTNESS 25 // default OLED brightness
67+
#define MIN_BRIGHTNESS 0 // Min OLED brightness selectable
68+
#define MAX_BRIGHTNESS 100 // Max OLED brightness selectable
69+
#define BRIGHTNESS_STEP 25 // OLED brightness increment
70+
#define DEFAULT_BRIGHTNESS 25 // default OLED brightness
7171

7272
/**
7373
* Temp change settings
@@ -159,9 +159,9 @@
159159

160160
#define POW_PD 1
161161
#define TEMP_NTC
162-
#define I2C_SOFT_PD
162+
#define I2C_SOFT_BUS_2
163163
#define BATTFILTERDEPTH 8
164-
#define OLED_I2CBB
164+
#define OLED_I2CBB2
165165
#define ACCEL_EXITS_ON_MOVEMENT
166166
#define NEEDS_VBUS_PROBE 0
167167

source/Core/BSP/MHP30/preRTOS.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
#include "BSP.h"
9-
#include "I2CBB.hpp"
9+
#include "I2CBB2.hpp"
1010
#include "Pins.h"
1111
#include "Setup.h"
1212
#include <I2C_Wrapper.hpp>
@@ -17,7 +17,7 @@ void preRToSInit() {
1717
HAL_Init();
1818
Setup_HAL(); // Setup all the HAL objects
1919
BSPInit();
20-
I2CBB::init();
20+
I2CBB2::init();
2121
/* Init the IPC objects */
2222
FRToSI2C::FRToSInit();
2323
}

source/Core/BSP/Miniware/BSP.cpp

+50-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Pins.h"
66
#include "Setup.h"
77
#include "TipThermoModel.h"
8+
#include "USBPD.h"
89
#include "configuration.h"
910
#include "history.hpp"
1011
#include "main.hpp"
@@ -17,7 +18,7 @@ const uint16_t powerPWM = 255;
1718
static const uint8_t holdoffTicks = 14; // delay of 8 ms
1819
static const uint8_t tempMeasureTicks = 14;
1920

20-
uint16_t totalPWM; // htim2.Init.Period, the full PWM cycle
21+
uint16_t totalPWM; // htimADC.Init.Period, the full PWM cycle
2122

2223
static bool fastPWM;
2324
static bool infastPWM;
@@ -99,20 +100,20 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
99100

100101
static void switchToFastPWM(void) {
101102
// 10Hz
102-
infastPWM = true;
103-
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
104-
htim2.Instance->ARR = totalPWM;
105-
htim2.Instance->CCR1 = powerPWM + holdoffTicks;
106-
htim2.Instance->PSC = 2690;
103+
infastPWM = true;
104+
totalPWM = powerPWM + tempMeasureTicks + holdoffTicks;
105+
htimADC.Instance->ARR = totalPWM;
106+
htimADC.Instance->CCR1 = powerPWM + holdoffTicks;
107+
htimADC.Instance->PSC = 2690;
107108
}
108109

109110
static void switchToSlowPWM(void) {
110111
// 5Hz
111-
infastPWM = false;
112-
totalPWM = powerPWM + tempMeasureTicks / 2 + holdoffTicks / 2;
113-
htim2.Instance->ARR = totalPWM;
114-
htim2.Instance->CCR1 = powerPWM + holdoffTicks / 2;
115-
htim2.Instance->PSC = 2690 * 2;
112+
infastPWM = false;
113+
totalPWM = powerPWM + tempMeasureTicks / 2 + holdoffTicks / 2;
114+
htimADC.Instance->ARR = totalPWM;
115+
htimADC.Instance->CCR1 = powerPWM + holdoffTicks / 2;
116+
htimADC.Instance->PSC = 2690 * 2;
116117
}
117118

118119
void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
@@ -126,19 +127,19 @@ void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
126127

127128
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
128129
// Period has elapsed
129-
if (htim->Instance == TIM2) {
130+
if (htim->Instance == ADC_CONTROL_TIMER) {
130131
// we want to turn on the output again
131132
PWMSafetyTimer--;
132133
// We decrement this safety value so that lockups in the
133134
// scheduler will not cause the PWM to become locked in an
134135
// active driving state.
135136
// While we could assume this could never happen, its a small price for
136137
// increased safety
137-
htim2.Instance->CCR4 = pendingPWM;
138-
if (htim2.Instance->CCR4 && PWMSafetyTimer) {
139-
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
138+
htimADC.Instance->CCR4 = pendingPWM;
139+
if (htimADC.Instance->CCR4 && PWMSafetyTimer) {
140+
HAL_TIM_PWM_Start(&htimTip, TIM_CHANNEL_1);
140141
} else {
141-
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
142+
HAL_TIM_PWM_Stop(&htimTip, TIM_CHANNEL_1);
142143
}
143144
if (fastPWM != infastPWM) {
144145
if (fastPWM) {
@@ -157,10 +158,11 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
157158
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
158159
// This was a when the PWM for the output has timed out
159160
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) {
160-
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
161+
HAL_TIM_PWM_Stop(&htimTip, TIM_CHANNEL_1);
161162
}
162163
}
163164
void unstick_I2C() {
165+
#ifndef I2C_SOFT_BUS_1
164166
GPIO_InitTypeDef GPIO_InitStruct;
165167
int timeout = 100;
166168
int timeout_cnt = 0;
@@ -227,6 +229,7 @@ void unstick_I2C() {
227229

228230
// Call initialization function.
229231
HAL_I2C_Init(&hi2c1);
232+
#endif
230233
}
231234

232235
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
@@ -245,9 +248,36 @@ bool isTipDisconnected() {
245248
return tipTemp > tipDisconnectedThres;
246249
}
247250

248-
void setStatusLED(const enum StatusLED state) {}
249-
void setBuzzer(bool on) {}
250-
uint8_t preStartChecks() { return 1; }
251+
void setStatusLED(const enum StatusLED state) {}
252+
void setBuzzer(bool on) {}
253+
uint8_t preStartChecks() {
254+
#ifdef HAS_SPLIT_POWER_PATH
255+
256+
// We want to enable the power path that has the highest voltage
257+
// 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
258+
{
259+
uint16_t dc = getRawDCVin();
260+
uint16_t pd = getRawPDVin();
261+
if (dc > pd) {
262+
HAL_GPIO_WritePin(DC_SELECT_GPIO_Port, DC_SELECT_Pin, GPIO_PIN_SET);
263+
HAL_GPIO_WritePin(PD_SELECT_GPIO_Port, PD_SELECT_Pin, GPIO_PIN_RESET);
264+
} else {
265+
HAL_GPIO_WritePin(PD_SELECT_GPIO_Port, PD_SELECT_Pin, GPIO_PIN_SET);
266+
HAL_GPIO_WritePin(DC_SELECT_GPIO_Port, DC_SELECT_Pin, GPIO_PIN_RESET);
267+
}
268+
}
269+
270+
#endif
271+
#ifdef POW_PD
272+
// If we are in the middle of negotiating PD, wait until timeout
273+
// Before turning on the heater
274+
if (!USBPowerDelivery::negotiationComplete()) {
275+
return 0;
276+
}
277+
278+
#endif
279+
return 1;
280+
}
251281
uint64_t getDeviceID() {
252282
//
253283
return HAL_GetUIDw0() | ((uint64_t)HAL_GetUIDw1() << 32);

0 commit comments

Comments
 (0)