mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Refactor QC logic for TS80
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "Defines.h"
|
#include "Defines.h"
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "UnitSettings.h"
|
#include "UnitSettings.h"
|
||||||
|
#include "BSP_QC.h"
|
||||||
/*
|
/*
|
||||||
* BSP.h -- Board Support
|
* BSP.h -- Board Support
|
||||||
*
|
*
|
||||||
|
|||||||
39
workspace/TS100/Core/BSP/BSP_QC.h
Normal file
39
workspace/TS100/Core/BSP/BSP_QC.h
Normal file
@@ -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_ */
|
||||||
68
workspace/TS100/Core/BSP/Miniware/QC_GPIO.c
Normal file
68
workspace/TS100/Core/BSP/Miniware/QC_GPIO.c
Normal file
@@ -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;
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#ifndef INC_QC3_H_
|
#ifndef INC_QC3_H_
|
||||||
#define INC_QC3_H_
|
#define INC_QC3_H_
|
||||||
|
#include "stdint.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,26 +5,11 @@
|
|||||||
* Author: Ralim
|
* Author: Ralim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//Quick charge 3.0 supporting functions
|
//Quick charge 3.0 supporting functions
|
||||||
|
#include "QC3.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "BSP.h"
|
||||||
#ifdef MODEL_TS80
|
#include "cmsis_os.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_Seek9V() {
|
void QC_Seek9V() {
|
||||||
DNegZero_Six();
|
DNegZero_Six();
|
||||||
@@ -127,20 +112,7 @@ void startQC(uint16_t divisor) {
|
|||||||
QCMode = 1; // Already at 12V, user has probably over-ridden this
|
QCMode = 1; // Already at 12V, user has probably over-ridden this
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
QC_Init_GPIO();
|
||||||
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);
|
|
||||||
|
|
||||||
// Tries to negotiate QC for 9V
|
// Tries to negotiate QC for 9V
|
||||||
// This is a multiple step process.
|
// 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++) {
|
for (uint16_t i = 0; i < 200 && enteredQC == 0; i++) {
|
||||||
vTaskDelay(1); //10mS pause
|
vTaskDelay(1); //10mS pause
|
||||||
if (i > 130) {
|
if (i > 130) {
|
||||||
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET) {
|
if (QC_DM_PulledDown()) {
|
||||||
enteredQC = 1;
|
enteredQC = 1;
|
||||||
}
|
}
|
||||||
if (i == 140) {
|
if (i == 140) {
|
||||||
//For some marginal QC chargers, we try adding a pulldown
|
//For some marginal QC chargers, we try adding a pulldown
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
QC_DM_PullDown();
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_11;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
QC_DM_No_PullDown();
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_11;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
if (enteredQC) {
|
if (enteredQC) {
|
||||||
// We have a QC capable charger
|
// We have a QC capable charger
|
||||||
QC_Seek9V();
|
QC_Seek9V();
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_10;
|
QC_Post_Probe_En();
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
QC_Seek9V();
|
QC_Seek9V();
|
||||||
// Wait for frontend ADC to stabilise
|
// Wait for frontend ADC to stabilise
|
||||||
QCMode = 4;
|
QCMode = 4;
|
||||||
@@ -199,5 +163,3 @@ void startQC(uint16_t divisor) {
|
|||||||
QCMode = 0;
|
QCMode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "LIS2DH12.hpp"
|
#include "LIS2DH12.hpp"
|
||||||
#include <MMA8652FC.hpp>
|
#include <MMA8652FC.hpp>
|
||||||
|
#include "QC3.h"
|
||||||
#define MOVFilter 8
|
#define MOVFilter 8
|
||||||
uint8_t accelInit = 0;
|
uint8_t accelInit = 0;
|
||||||
uint32_t lastMovementTime = 0;
|
uint32_t lastMovementTime = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user