Skip to content

Commit

Permalink
Stitch in some of TS101
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ralim committed Jun 4, 2023
1 parent a06d6cf commit 70cda7e
Show file tree
Hide file tree
Showing 30 changed files with 869 additions and 258 deletions.
14 changes: 7 additions & 7 deletions source/Core/BSP/MHP30/Software_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#include "BSP.h"
#include "configuration.h"
#include "stm32f1xx_hal.h"
#ifdef I2C_SOFT_PD
#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++) { \
Expand Down
12 changes: 6 additions & 6 deletions source/Core/BSP/MHP30/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -159,9 +159,9 @@

#define POW_PD 1
#define TEMP_NTC
#define I2C_SOFT_PD
#define I2C_SOFT_BUS_2
#define BATTFILTERDEPTH 8
#define OLED_I2CBB
#define OLED_I2CBB2
#define ACCEL_EXITS_ON_MOVEMENT
#define NEEDS_VBUS_PROBE 0

Expand Down
4 changes: 2 additions & 2 deletions source/Core/BSP/MHP30/preRTOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "BSP.h"
#include "I2CBB.hpp"
#include "I2CBB2.hpp"
#include "Pins.h"
#include "Setup.h"
#include <I2C_Wrapper.hpp>
Expand All @@ -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();
}
70 changes: 50 additions & 20 deletions source/Core/BSP/Miniware/BSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -126,19 +127,19 @@ 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);
htimADC.Instance->CCR4 = pendingPWM;
if (htimADC.Instance->CCR4 && PWMSafetyTimer) {
HAL_TIM_PWM_Start(&htimTip, TIM_CHANNEL_1);
} else {
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
HAL_TIM_PWM_Stop(&htimTip, TIM_CHANNEL_1);
}
if (fastPWM != infastPWM) {
if (fastPWM) {
Expand All @@ -157,10 +158,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, TIM_CHANNEL_1);
}
}
void unstick_I2C() {
#ifndef I2C_SOFT_BUS_1
GPIO_InitTypeDef GPIO_InitStruct;
int timeout = 100;
int timeout_cnt = 0;
Expand Down Expand Up @@ -227,6 +229,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; }
Expand All @@ -245,9 +248,36 @@ bool isTipDisconnected() {
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) {}
uint8_t preStartChecks() {
#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);
Expand Down
Loading

0 comments on commit 70cda7e

Please sign in to comment.