1
0
forked from me/IronOS

Refactor QC logic for TS80

This commit is contained in:
Ben V. Brown
2020-05-29 22:25:43 +10:00
parent cd5d9df5ed
commit a01e79aa64
6 changed files with 119 additions and 49 deletions

View File

@@ -1,6 +1,7 @@
#include "Defines.h"
#include "stdint.h"
#include "UnitSettings.h"
#include "BSP_QC.h"
/*
* BSP.h -- Board Support
*

View 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_ */

View 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;
}