[update] update latch process

This commit is contained in:
ROY
2022-07-21 17:29:31 +08:00
parent dc5cabf2ae
commit 5e04fcb7e2
5 changed files with 24 additions and 129 deletions
@@ -278,8 +278,11 @@ static void __latch2_set(void)
static uint8_t __latch0_as_gpio(void)
{
__pin_ctrl(PC_LOAD0_CLR);
spi0_close();
spi1_close();
add_pin_d0_d3();
return 0;
@@ -356,7 +359,7 @@ uint8_t update_latch_stat(uint8_t latch, uint8_t dio, uint8_t value)
uint8_t latch_single_ctrl(uint8_t latch, uint8_t dio, uint8_t value)
{
//控制單一latch pin-> update_latch_stat -> 判斷是哪個latch -> latch?_ctrl
// control one latch pin -> update_latch_stat -> what latch to update? -> latch?_ctrl
uint8_t lh = latch;
uint8_t d = dio;
uint8_t val = value;
@@ -378,8 +381,6 @@ uint8_t latch_single_ctrl(uint8_t latch, uint8_t dio, uint8_t value)
break;
case LOAD1:
__pin_ctrl(PC_LOAD0_CLR);
__latch0_as_gpio();
__latch1_set();
@@ -390,8 +391,6 @@ uint8_t latch_single_ctrl(uint8_t latch, uint8_t dio, uint8_t value)
break;
case LOAD2:
__pin_ctrl(PC_LOAD0_CLR);
__latch0_as_gpio();
__latch2_set();
@@ -407,19 +406,21 @@ uint8_t latch_single_ctrl(uint8_t latch, uint8_t dio, uint8_t value)
uint8_t latch_multi_ctrl(void)
{
//控制多個latch pin-> update_latch_stat -> update_latch_stat -> ... -> latch_ctrl0.1.2
// control many latch pin -> update_latch_stat -> update_latch_stat -> ... -> latch_ctrl 0.1.2
__latch0_set();
__pin_ctrl(PC_LOAD0_SET);
__pin_ctrl(PC_LOAD0_CLR);
__latch0_as_gpio();
__latch1_set();
__pin_ctrl(PC_LOAD1_SET);
__pin_ctrl(PC_LOAD1_CLR);
__latch2_set();
__pin_ctrl(PC_LOAD2_SET);
__pin_ctrl(PC_LOAD2_CLR);
__latch0_as_spi();
return 0;
}
@@ -230,11 +230,6 @@ void IinADCGainCtrl(uint8_t IinADCLevel)
/* hardware need open before close, so don't change position*/
if (IinADCLevel == 0) {
// ADC gain level = 0, using 2M resister
// latch_single_ctrl(E_LATCH_I_LARGE_ON, 0);
// latch_single_ctrl(E_LATCH_I_MID_ON, 0);
// latch_single_ctrl(E_LATCH_I_SMALL_ON, 0);
update_latch_stat(E_LATCH_I_LARGE_ON, 0);
update_latch_stat(E_LATCH_I_MID_ON, 0);
update_latch_stat(E_LATCH_I_SMALL_ON, 0);
@@ -242,9 +237,6 @@ void IinADCGainCtrl(uint8_t IinADCLevel)
} else if (IinADCLevel == 1) {
// ADC gain level = 1, using 91K resister
// latch_single_ctrl(E_LATCH_I_SMALL_ON, 1); /* need open first */
// latch_single_ctrl(E_LATCH_I_LARGE_ON, 0);
// latch_single_ctrl(E_LATCH_I_MID_ON, 0);
update_latch_stat(E_LATCH_I_SMALL_ON, 1); /* need open first */
update_latch_stat(E_LATCH_I_LARGE_ON, 0);
update_latch_stat(E_LATCH_I_MID_ON, 0);
@@ -252,10 +244,6 @@ void IinADCGainCtrl(uint8_t IinADCLevel)
} else if (IinADCLevel == 2) {
// ADC gain level = 2, using 4.3K resister
// latch_single_ctrl(E_LATCH_I_MID_ON, 1); /* need open first */
// latch_single_ctrl(E_LATCH_I_LARGE_ON, 0);
// latch_single_ctrl(E_LATCH_I_SMALL_ON, 0);
update_latch_stat(E_LATCH_I_MID_ON, 1); /* need open first */
update_latch_stat(E_LATCH_I_LARGE_ON, 0);
update_latch_stat(E_LATCH_I_SMALL_ON, 0);
@@ -263,10 +251,6 @@ void IinADCGainCtrl(uint8_t IinADCLevel)
} else if (IinADCLevel == 3) {
// ADC gain level = 3, using 200R resistor
// latch_single_ctrl(E_LATCH_I_LARGE_ON, 1); /* need open first */
// latch_single_ctrl(E_LATCH_I_MID_ON, 0);
// latch_single_ctrl(E_LATCH_I_SMALL_ON, 0);
update_latch_stat(E_LATCH_I_LARGE_ON, 1); /* need open first */
update_latch_stat(E_LATCH_I_MID_ON, 0);
update_latch_stat(E_LATCH_I_SMALL_ON, 0);
@@ -274,10 +258,6 @@ void IinADCGainCtrl(uint8_t IinADCLevel)
} else if (IinADCLevel == 4) {
// ADC gain level = 3, auto gain (using 200R resister)
// latch_single_ctrl(E_LATCH_I_LARGE_ON, 1); /* need open first */
// latch_single_ctrl(E_LATCH_I_MID_ON, 0);
// latch_single_ctrl(E_LATCH_I_SMALL_ON, 0);
update_latch_stat(E_LATCH_I_LARGE_ON, 1); /* need open first */
update_latch_stat(E_LATCH_I_MID_ON, 0);
update_latch_stat(E_LATCH_I_SMALL_ON, 0);
@@ -285,10 +265,6 @@ void IinADCGainCtrl(uint8_t IinADCLevel)
} else {
// default using 100R resister
// latch_single_ctrl(E_LATCH_I_LARGE_ON, 1); /* need open first */
// latch_single_ctrl(E_LATCH_I_MID_ON, 0);
// latch_single_ctrl(E_LATCH_I_SMALL_ON, 0);
update_latch_stat(E_LATCH_I_LARGE_ON, 1); /* need open first */
update_latch_stat(E_LATCH_I_MID_ON, 0);
update_latch_stat(E_LATCH_I_SMALL_ON, 0);
@@ -314,28 +290,33 @@ void VinADCGainCtrl(uint8_t VinADCLevel)
/* hardware need open before close, so don't change position*/
if (VinADCLevel == 0) {
// Vin ADC gain level = 0, using 1M resister
latch_single_ctrl(E_LATCH_V_SMALL_ON, 0);
latch_single_ctrl(E_LATCH_V_MID_ON, 0);
update_latch_stat(E_LATCH_V_SMALL_ON, 0);
update_latch_stat(E_LATCH_V_MID_ON, 0);
latch_multi_ctrl();
} else if (VinADCLevel == 1) {
// Vin ADC gain level = 1, using 30K resister
latch_single_ctrl(E_LATCH_V_MID_ON, 1); /* need open first */
latch_single_ctrl(E_LATCH_V_SMALL_ON, 0);
update_latch_stat(E_LATCH_V_MID_ON, 1); /* need open first */
update_latch_stat(E_LATCH_V_SMALL_ON, 0);
latch_multi_ctrl();
} else if (VinADCLevel == 2) {
// Vin ADC gain level = 2, using 1K resister
latch_single_ctrl(E_LATCH_V_SMALL_ON, 1); /* need open first */
latch_single_ctrl(E_LATCH_V_MID_ON, 0);
update_latch_stat(E_LATCH_V_SMALL_ON, 1); /* need open first */
update_latch_stat(E_LATCH_V_MID_ON, 0);
latch_multi_ctrl();
} else if (VinADCLevel == 3) {
// Vin ADC gain level = 3, auto gain (using 1K resister)
latch_single_ctrl(E_LATCH_V_SMALL_ON, 1); /* need open first */
latch_single_ctrl(E_LATCH_V_MID_ON, 0);
update_latch_stat(E_LATCH_V_SMALL_ON, 1); /* need open first */
update_latch_stat(E_LATCH_V_MID_ON, 0);
latch_multi_ctrl();
} else {
// default using 1K resister
latch_single_ctrl(E_LATCH_V_SMALL_ON, 1); /* need open first */
latch_single_ctrl(E_LATCH_V_MID_ON, 0);
update_latch_stat(E_LATCH_V_SMALL_ON, 1); /* need open first */
update_latch_stat(E_LATCH_V_MID_ON, 0);
latch_multi_ctrl();
}
@@ -1,73 +0,0 @@
#ifndef ELITEKEYDETECT
#define ELITEKEYDETECT
static bool TurnOnElite(uint8_t key) {
static uint16_t TurnOnCounter = 0;
if (key == 0) {
// press 1 sec, power on LED, read bat power
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
headstage_battery_volt();
uint16_t bat = NotifyVoltBat;
if( bat < 768 && bat > 20){
latch_single_ctrl(E_LATCH_5V_ENABLE, 0);
return false;
}else{
latch_single_ctrl(E_LATCH_5V_ENABLE, 1); // enable 5V
TurnOn10V();
ModeLED(BT_WAIT);
return true;
}
} else {
TurnOnCounter++;
return false;
}
} else {
TurnOnCounter = 0;
latch_single_ctrl(E_LATCH_5V_ENABLE, 0); // disable 5V
return false;
}
}
static void EliteKeyPress(uint8_t key) {
static uint16_t ShutDownCounter = 0;
static uint8_t OriginEliteFxn = 0;
if (key == 0) {
// key = 0 if press
// press key => bight LED
if (ShutDownCounter == CLOCK_ONE_SECOND) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_ORANGE);
}
// press 3~4 sec, shutdown 2650
else if (ShutDownCounter > (CLOCK_ONE_SECOND*3) ) {
latch_single_ctrl(E_LATCH_5V_ENABLE, 0); // disable 5V
}
ShutDownCounter ++;
} else {
if (OriginEliteFxn == instru.eliteFxn) { // old function == currunt instruction
if (ShutDownCounter != 0) {
// dark LED
checkFlafLED();
ShutDownCounter = 0;
}
} else { // old function != currunt instruction
OriginEliteFxn = instru.eliteFxn;
if (ShutDownCounter != 0) {
ShutDownCounter = 0;
}
checkFlafLED();
}
}
}
static void TurnOn10V() {
If10Von = true;
latch_single_ctrl(E_LATCH_10V_ENABLE, 1);
CPUdelay(8000);
}
#endif
@@ -579,8 +579,6 @@ static void VoutGainControl(uint8_t VOUTLevel);
// Elite key detection & turn on/ shutdown function (peripheral hardware control)
static void ModeLED(uint16_t modeStatus);
static bool If10Von = false;
static void TurnOn10V();
// periodic event control
static void EliteADCControl(uint32_t time);
@@ -614,7 +612,6 @@ static void initDATBuf();
#include "EliteLatchInit.h"
#include "EliteReset.h"
#include "EliteLED.h"
#include "EliteKeyDetect.h"
#include "Elite_mode_ADC_DAC.h"
#include "scan_volt.h"
#include "impedance_meter.h"
@@ -624,7 +624,6 @@ static void key_manage(uint32_t delta_time)
keyTimer = keyTimer + t;
if (keyTimer >= 30000){
latch_single_ctrl(E_LATCH_5V_ENABLE, 0);
//pin_ctrl(PC_5V_ENABLE_CLR);
} else if (keyTimer >= 10000 && !byPass1sec) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_ORANGE);
@@ -750,17 +749,7 @@ for (;;) {
if(counter6994 <= CLOCK_ONE_SECOND*5) {
toggle_6994(counter6994);
counter6994++;
}
// /*************************************************************************************/
// if (counter6994 < CLOCK_ONE_SECOND*5) { // counter6994 enable a IC after 35 counts
// counter6994++;
// } else if (counter6994 == CLOCK_ONE_SECOND*5) {
// latch_single_ctrl(E_LATCH_OFF, 0); // OFF = 1 => turn off 6994
// counter6994++;
// } else if (counter6994 > CLOCK_ONE_SECOND*5) {
// counter6994 = 0;
// }
// /**************************************************************************************/
}
key = PIN_getInputValue(E_PIN_SHUT_DOWN);
if(key != 0){ //detect Elite battery power when no periodic event