diff --git a/workspace/TS100/Core/BSP/BSP.h b/workspace/TS100/Core/BSP/BSP.h index 2c02eabc..e86f941b 100644 --- a/workspace/TS100/Core/BSP/BSP.h +++ b/workspace/TS100/Core/BSP/BSP.h @@ -1,6 +1,7 @@ #include "Defines.h" #include "stdint.h" #include "UnitSettings.h" +#include "BSP_QC.h" /* * BSP.h -- Board Support * diff --git a/workspace/TS100/Core/BSP/BSP_QC.h b/workspace/TS100/Core/BSP/BSP_QC.h new file mode 100644 index 00000000..5ad58376 --- /dev/null +++ b/workspace/TS100/Core/BSP/BSP_QC.h @@ -0,0 +1,39 @@ +/* + * BSP_QC.h + * + * Created on: 29 May 2020 + * Author: Ralim + */ + +#ifndef BSP_BSP_QC_H_ +#define BSP_BSP_QC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +//Init GPIO for QC neg +void QC_Init_GPIO(); +//Set the DP pin to 0.6V +void DPlusZero_Six(); +//Set the DM pin to 0.6V +void DNegZero_Six(); +//Set the DP pin to 3.3V +void DPlusThree_Three(); +//Set the DM pin to 3.3V +void DNegThree_Three(); +//Turn on weak pulldown on the DM pin +//This is used as a helper for some power banks +void QC_DM_PullDown(); +//Turn off the pulldown +void QC_DM_No_PullDown(); +//Turn on output drivers that were initally disabled to prevent spike through QC disable mode +void QC_Post_Probe_En(); +//Check if DM was pulled down +//1=Pulled down, 0 == pulled high +uint8_t QC_DM_PulledDown(); +#ifdef __cplusplus +} +#endif + +#endif /* BSP_BSP_QC_H_ */ diff --git a/workspace/TS100/Core/BSP/Miniware/QC_GPIO.c b/workspace/TS100/Core/BSP/Miniware/QC_GPIO.c new file mode 100644 index 00000000..9b082788 --- /dev/null +++ b/workspace/TS100/Core/BSP/Miniware/QC_GPIO.c @@ -0,0 +1,68 @@ +/* + * QC.c + * + * Created on: 29 May 2020 + * Author: Ralim + */ +#include "BSP.h" +#include "Pins.h" +#include "stm32f1xx_hal.h" +void DPlusZero_Six() { + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+ +} +void DNegZero_Six() { + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); +} +void DPlusThree_Three() { + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); // pull up D+ +} +void DNegThree_Three() { + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); +} +void QC_DM_PullDown() { + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Pin = GPIO_PIN_11; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +} +void QC_DM_No_PullDown() { + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pin = GPIO_PIN_11; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + +} +void QC_Init_GPIO() { + //Setup any GPIO into the right states for QC + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Pin = GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_10; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + //Turn off output mode on pins that we can + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +} +void QC_Post_Probe_En() { + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +} + +uint8_t QC_DM_PulledDown() { + return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0; +} diff --git a/workspace/TS100/Core/Inc/QC3.h b/workspace/TS100/Core/Inc/QC3.h index 98bfa0f5..0ddf1b0f 100644 --- a/workspace/TS100/Core/Inc/QC3.h +++ b/workspace/TS100/Core/Inc/QC3.h @@ -7,7 +7,7 @@ #ifndef INC_QC3_H_ #define INC_QC3_H_ - +#include "stdint.h" #ifdef __cplusplus extern "C" { #endif diff --git a/workspace/TS100/Core/Src/QC3.c b/workspace/TS100/Core/Src/QC3.c index 6e47b7c1..bb773e1b 100644 --- a/workspace/TS100/Core/Src/QC3.c +++ b/workspace/TS100/Core/Src/QC3.c @@ -5,26 +5,11 @@ * Author: Ralim */ - //Quick charge 3.0 supporting functions - - - -#ifdef MODEL_TS80 -void DPlusZero_Six() { - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+ -} -void DNegZero_Six() { - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); -} -void DPlusThree_Three() { - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); // pull up D+ -} -void DNegThree_Three() { - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); -} +#include "QC3.h" +#include "stdint.h" +#include "BSP.h" +#include "cmsis_os.h" void QC_Seek9V() { DNegZero_Six(); @@ -127,20 +112,7 @@ void startQC(uint16_t divisor) { QCMode = 1; // Already at 12V, user has probably over-ridden this return; } - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_3; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_10; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - //Turn off output mode on pins that we can - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + QC_Init_GPIO(); // Tries to negotiate QC for 9V // This is a multiple step process. @@ -154,28 +126,20 @@ void startQC(uint16_t divisor) { for (uint16_t i = 0; i < 200 && enteredQC == 0; i++) { vTaskDelay(1); //10mS pause if (i > 130) { - if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET) { + if (QC_DM_PulledDown()) { enteredQC = 1; } if (i == 140) { //For some marginal QC chargers, we try adding a pulldown - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; - GPIO_InitStruct.Pin = GPIO_PIN_11; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + QC_DM_PullDown(); } } } - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Pin = GPIO_PIN_11; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + QC_DM_No_PullDown(); if (enteredQC) { // We have a QC capable charger QC_Seek9V(); - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_10; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + QC_Post_Probe_En(); QC_Seek9V(); // Wait for frontend ADC to stabilise QCMode = 4; @@ -199,5 +163,3 @@ void startQC(uint16_t divisor) { QCMode = 0; } - -#endif diff --git a/workspace/TS100/Core/Threads/MOVThread.cpp b/workspace/TS100/Core/Threads/MOVThread.cpp index 70c0727b..04220170 100644 --- a/workspace/TS100/Core/Threads/MOVThread.cpp +++ b/workspace/TS100/Core/Threads/MOVThread.cpp @@ -18,7 +18,7 @@ #include "stdlib.h" #include "LIS2DH12.hpp" #include - +#include "QC3.h" #define MOVFilter 8 uint8_t accelInit = 0; uint32_t lastMovementTime = 0;