Merge tag '1.0.5' into develop

tag 1.0.5
diff --git a/supwisdom/sp_menu.c b/supwisdom/sp_menu.c
index 88dea9b..572f788 100644
--- a/supwisdom/sp_menu.c
+++ b/supwisdom/sp_menu.c
@@ -611,6 +611,7 @@
     {
       if(kcode == SP_KEY_CLEAR)
       {
+        sp_valve_off();
         return;
       }
       ticker = sp_get_ticker();
@@ -623,6 +624,7 @@
       disp_hint_info_two(pos,"Á÷Á¿²âÊÔÖÐ",msg,DELAY_TIME100ms);
     }
   }
+  sp_valve_off();
   sprintf(msg,"Á÷Á¿¼ÆÊý:%d",sp_flowsensor_get_count());
   disp_hint_info_two(pos,"Á÷Á¿²âÊÔ½áÊø",msg,DELAY_TIME3s);
 }
diff --git a/sys_hw/drv_adc.c b/sys_hw/drv_adc.c
index ad54096..ec4664a 100644
--- a/sys_hw/drv_adc.c
+++ b/sys_hw/drv_adc.c
@@ -1,321 +1,367 @@
-#include "drv_adc.h"
-#include "stm32f10x.h"
-#include "keypad.h"
-#include "string.h"
-#include "../supwisdom/sp_util.h"
-#include "../supwisdom/sp_flash.h"
-
-//#include "mifare_one_hw_lib.h"
-#include "timer.h"
-#include "data_tools.h"
-//#include "crc.h"
-//#include "dbg.h"
-
-#define PDDThreshod_Votage    80
-#define PDDThreshod_ADCVal    (PDDThreshod_Votage*4095L/713L)
-
-#define Reset_Votage          74       //TPS54160Í£Ö¹¹¤×÷µçѹ7.1V
-#define Reset_ADCVal          (Reset_Votage*4095L/713L)
-
-
-typedef void (*adc_timer_tick_t)(void);
-
-volatile uint8_t  adc_timer;
-volatile uint8_t  ch_idx;
-volatile uint16_t adc_val_vdd=4095;
-volatile uint16_t adc_val;
-dac_para_t dac_para = {890, 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, 0}; //dacÊä³öµçѹĬÈÏ3.3V
-adc_timer_tick_t p_adc_timer_tick = 0;
-volatile uint16_t adc_buff[ADC_MAX_CH_NUM];
-static const uint8_t adc_ch_tbl[ADC_MAX_CH_NUM] =
-{
-  ADC_Channel_9,         //key_adc1,pb1
-  ADC_Channel_4,         //key_adc2,pa4
-  ADC_Channel_1,         //key_adc3,pa1
-  ADC_Channel_8,         //key_adc4,pb0
-  ADC_Channel_3,         //key_adc5,pa3
-  ADC_Channel_0,         //key_adc6,pa0
-  ADC_Channel_15,        //key_adc7,pc5
-  ADC_Channel_2,         //key_adc8,pa2
-  ADC_Channel_13,        //key_adc9,pc3
-  ADC_Channel_11,        //key_adc10,pc1
-  ADC_Channel_10,        //key_adc11,pc0
-  ADC_Channel_12,        //key_adc12,pc2
-  ADC_Channel_6,         //vcc_adc_in,pa6
-  ADC_Channel_14,        //fa_adc_in,pc4
-  ADC_Channel_7          //hall_adc_in,pa7
-};
-
-void adc_timer_tick(void);
-static void timer4_init(void);
-
-static void adc_gpio_init(void)
-{
-  GPIO_InitTypeDef GPIO_InitStructure;
-
-  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
-                         RCC_APB2Periph_GPIOB |
-                         RCC_APB2Periph_GPIOC, ENABLE);
-
-  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
-
-  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |
-                                GPIO_Pin_1 |
-                                GPIO_Pin_2 |
-                                GPIO_Pin_3 |
-                                GPIO_Pin_4 |
-                                GPIO_Pin_6 |
-                                GPIO_Pin_7;
-  GPIO_Init(GPIOA, &GPIO_InitStructure);
-
-  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |
-                                GPIO_Pin_1;
-  GPIO_Init(GPIOB, &GPIO_InitStructure);
-
-  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |
-                                GPIO_Pin_1 |
-                                GPIO_Pin_2 |
-                                GPIO_Pin_3 |
-                                GPIO_Pin_4 |
-                                GPIO_Pin_5;
-  GPIO_Init(GPIOC, &GPIO_InitStructure);
-}
-
-static void adc_channels_init(void)
-{
-  ADC_InitTypeDef ADC_InitStructure;
-
-  RCC_ADCCLKConfig(RCC_PCLK2_Div6);
-  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
-
-  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
-  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
-  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
-  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
-  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
-  ADC_InitStructure.ADC_NbrOfChannel = 1;
-  ADC_Init(ADC1, &ADC_InitStructure);
-  ADC1->CR2 |= 0x0010000;
-
-  //key adc 1 - 12
-  ch_idx = 0;
-  ADC_RegularChannelConfig(ADC1, adc_ch_tbl[ch_idx], 1,
-                           ADC_SampleTime_239Cycles5);
-  ADC_Cmd(ADC1, ENABLE);
-
-  ADC_ResetCalibration(ADC1);
-  while(ADC_GetResetCalibrationStatus(ADC1));
-
-  ADC_StartCalibration(ADC1);
-  while(ADC_GetCalibrationStatus(ADC1));
-  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
-  p_adc_timer_tick = adc_timer_tick;
-}
-
-static void adc_dma_init(void)
-{
-}
-
-static void adc_nvic_init(void)
-{
-
-}
-
-static void dac_init(void)
-{
-  GPIO_InitTypeDef GPIO_InitStructure;
-
-  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
-
-  DAC_DeInit();
-
-  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
-
-  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
-  GPIO_Init(GPIOA, &GPIO_InitStructure);
-
-
-  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
-
-  DAC->CR |= 0x00010000;
-  DAC_SetChannel2Data(DAC_Align_12b_R, dac_para.val[0]);
-}
-/**
-**У׼°´¼ü
-**/
-void calibrate_key(uint8 cache_enable)
-{
-  const uint8 len = sizeof(dac_para) +2;
-  uint8 buf[len];
-  if(cache_enable)
-  {
-    uint8 crc[2];
-    sp_flash_read(ADDR_KEY_PARA,buf,len);
-    sp_protocol_crc(buf ,len -2,crc);
-    if(memcmp(buf +len -2,crc,2) == 0)
-    {
-      memcpy((uint8*)&dac_para,buf,sizeof(dac_para));
-      return;
-    }
-  }
-  dac_para_auto_set();
-  memcpy(buf,(uint8*)&dac_para,sizeof(dac_para));
-  sp_protocol_crc(buf,len -2,buf +len -2);
-  sp_flash_erase(ADDR_KEY_PARA);
-  sp_flash_write(ADDR_KEY_PARA,buf,len);
-}
-
-void adc_init(void)
-{
-  timer4_init();
-  dac_init();
-  adc_gpio_init();
-  adc_nvic_init();
-  adc_dma_init();
-  adc_channels_init();
-  calibrate_key(1);
-}
-
-uint16_t adc_get_val(uint8_t ch)
-{
-  if(ch<ADC_MAX_CH_NUM)
-  {
-    return adc_buff[ch];
-  }
-  else
-  {
-    return 0;
-  }
-}
-
-void adc_timer_tick(void)
-{
-  adc_timer ++;
-  if(adc_timer>=8)
-  {
-    adc_timer = 0;
-  }
-  if(adc_timer==0)
-  {
-    adc_buff[ch_idx] = ADC_GetConversionValue(ADC1);
-    ch_idx ++;
-    if(ch_idx >= ADC_MAX_CH_NUM)
-    {
-      keypad_scan();
-      ch_idx = 0;
-    }
-
-    if(ch_idx < 12)
-    {
-      DAC_SetChannel2Data(DAC_Align_12b_R, dac_para.val[ch_idx]);
-    }
-  }
-  else if(adc_timer == 7)
-  {
-    ADC_RegularChannelConfig(ADC1, adc_ch_tbl[ch_idx], 1,
-                             ADC_SampleTime_239Cycles5);
-    ADC_SoftwareStartConvCmd(ADC1, ENABLE);
-  }
-}
-
-void adc_timer_task(void)
-{
-  if(p_adc_timer_tick)
-  {
-    //ÒѾ­³õʼ»¯Íê³É
-    p_adc_timer_tick();
-  }
-}
-
-void dac_para_auto_set(void)
-{
-  uint8_t i;
-  uint16_t dac_val = 4095;
-  uint8_t  adj_flags[12];
-
-  p_adc_timer_tick = 0;
-  delay_ms(10);
-  memset(adj_flags, 1, sizeof(adj_flags));
-  while((dac_val*3300ul*66/40950) > 2000)     //ÔË·ÅÊä³ö²»µÍÓÚ2V
-  {
-    for(i=0; i<12; i++)
-    {
-      if(adj_flags[i])
-      {
-        dac_para.val[i] = dac_val;
-      }
-      DAC_SetChannel2Data(DAC_Align_12b_R, dac_val);
-      delay_ms(6);
-      ADC_RegularChannelConfig(ADC1, adc_ch_tbl[i], 1, ADC_SampleTime_239Cycles5);
-      ADC_SoftwareStartConvCmd(ADC1, ENABLE);
-      delay_ms(2);
-      if(ADC_GetConversionValue(ADC1) < 300ul)
-      {
-        adj_flags[i] = 0;
-      }
-      else
-      {
-        adj_flags[i] = 1;
-      }
-    }
-
-    if(mem_test(adj_flags, 0, sizeof(adj_flags)) == 0)
-    {
-      break;
-    }
-    dac_val -= 124;
-  }
-  p_adc_timer_tick = adc_timer_tick;
-
-}
-
-static void timer4_init(void)
-{
-  uint16_t PrescalerValue = 0;
-  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
-  TIM_OCInitTypeDef  TIM_OCInitStructure;
-
-  GPIO_InitTypeDef GPIO_InitStructure;
-
-  /* TIM4 clock enable */
-  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
-
-  /* GPIOA and GPIOB clock enable */
-  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
-
-  /*GPIOB Configuration: TIM4 channel3 and 4 */
-  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8 | GPIO_Pin_9;
-  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
-  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-  GPIO_Init(GPIOB, &GPIO_InitStructure);
-
-  PrescalerValue = (uint16_t)(SystemCoreClock / 72000000) - 1;
-  /* Time base configuration */
-  TIM_TimeBaseStructure.TIM_Period = 719;
-  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
-  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
-  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
-
-  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
-
-  /* PWM1 Mode configuration: Channel1 */
-  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
-  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
-  TIM_OCInitStructure.TIM_Pulse = 359;
-  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
-  TIM_OC3Init(TIM4, &TIM_OCInitStructure);
-  TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
-
-  /* PWM1 Mode configuration: Channel2 */
-  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
-  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
-  TIM_OCInitStructure.TIM_Pulse = 359;
-  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
-  TIM_OC4Init(TIM4, &TIM_OCInitStructure);
-  TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
-
-  TIM_ARRPreloadConfig(TIM4, ENABLE);
-
-  /* TIM4 enable counter */
-  TIM_Cmd(TIM4, ENABLE);
-}
+#include "drv_adc.h"

+#include "stm32f10x.h"

+#include "keypad.h"

+#include "string.h"

+#include "../supwisdom/sp_util.h"

+#include "../supwisdom/sp_flash.h"

+

+//#include "mifare_one_hw_lib.h"

+#include "timer.h"

+#include "data_tools.h"

+//#include "crc.h"

+//#include "dbg.h"

+

+#define PDDThreshod_Votage    80

+#define PDDThreshod_ADCVal    (PDDThreshod_Votage*4095L/713L)

+

+#define Reset_Votage          74       //TPS54160Í£Ö¹¹¤×÷µçѹ7.1V

+#define Reset_ADCVal          (Reset_Votage*4095L/713L)

+

+

+typedef void (*adc_timer_tick_t)(void);

+

+volatile uint8_t  adc_timer;

+volatile uint8_t  ch_idx;

+volatile uint16_t adc_val_vdd=4095;

+volatile uint16_t adc_val;

+dac_para_t dac_para = {890, 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, 0}; //dacÊä³öµçѹĬÈÏ3.3V

+adc_timer_tick_t p_adc_timer_tick = 0;

+volatile uint16_t adc_buff[ADC_MAX_CH_NUM];

+static const uint8_t adc_ch_tbl[ADC_MAX_CH_NUM] =

+{

+  ADC_Channel_9,

+  ADC_Channel_4,

+  ADC_Channel_1,

+  ADC_Channel_8,

+  ADC_Channel_3,

+  ADC_Channel_0,

+  ADC_Channel_15,

+  ADC_Channel_2,

+  ADC_Channel_13,

+  ADC_Channel_11,

+  ADC_Channel_10,

+  ADC_Channel_12,

+  ADC_Channel_14,

+  ADC_Channel_7

+};

+

+void adc_timer_tick(void);

+static void adc_pdd_process(void);

+static void timer4_init(void);

+

+static void adc_gpio_init(void)

+{

+  GPIO_InitTypeDef GPIO_InitStructure;

+

+  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |

+                         RCC_APB2Periph_GPIOB |

+                         RCC_APB2Periph_GPIOC, ENABLE);

+

+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

+

+  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |

+                                GPIO_Pin_1 |

+                                GPIO_Pin_2 |

+                                GPIO_Pin_3 |

+                                GPIO_Pin_4 |

+                                GPIO_Pin_7;

+  GPIO_Init(GPIOA, &GPIO_InitStructure);

+

+  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |

+                                GPIO_Pin_1;

+  GPIO_Init(GPIOB, &GPIO_InitStructure);

+

+  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |

+                                GPIO_Pin_1 |

+                                GPIO_Pin_2 |

+                                GPIO_Pin_3 |

+                                GPIO_Pin_4 |

+                                GPIO_Pin_5;

+  GPIO_Init(GPIOC, &GPIO_InitStructure);

+}

+

+static void adc_channels_init(void)

+{

+  ADC_InitTypeDef ADC_InitStructure;

+

+  RCC_ADCCLKConfig(RCC_PCLK2_Div6);

+  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

+

+  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

+  ADC_InitStructure.ADC_ScanConvMode = DISABLE;

+  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

+  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

+  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

+  ADC_InitStructure.ADC_NbrOfChannel = 1;

+  ADC_Init(ADC1, &ADC_InitStructure);

+  ADC1->CR2 |= 0x0010000;

+

+  //key adc 1 - 12

+  ch_idx = 0;

+  ADC_RegularChannelConfig(ADC1, adc_ch_tbl[ch_idx], 1,

+                           ADC_SampleTime_239Cycles5);

+  ADC_Cmd(ADC1, ENABLE);

+

+  ADC_ResetCalibration(ADC1);

+  while(ADC_GetResetCalibrationStatus(ADC1));

+

+  ADC_StartCalibration(ADC1);

+  while(ADC_GetCalibrationStatus(ADC1));

+  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

+  p_adc_timer_tick = adc_timer_tick;

+}

+

+static void adc_dma_init(void)

+{

+}

+

+static void adc_nvic_init(void)

+{

+

+}

+

+static void dac_init(void)

+{

+  GPIO_InitTypeDef GPIO_InitStructure;

+

+  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

+

+  DAC_DeInit();

+

+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

+

+  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

+  GPIO_Init(GPIOA, &GPIO_InitStructure);

+

+

+  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

+

+  DAC->CR |= 0x00010000;

+  DAC_SetChannel2Data(DAC_Align_12b_R, dac_para.val[0]);

+}

+

+/**

+**У׼°´¼ü

+**/

+void calibrate_key(uint8 cache_enable)

+{

+  const uint8 len = sizeof(dac_para) +2;

+  uint8 buf[len];

+  if(cache_enable)

+  {

+    uint8 crc[2];

+    sp_flash_read(ADDR_KEY_PARA,buf,len);

+    sp_protocol_crc(buf ,len -2,crc);

+    if(memcmp(buf +len -2,crc,2) == 0)

+    {

+      memcpy((uint8*)&dac_para,buf,sizeof(dac_para));

+      return;

+    }

+  }

+  dac_para_auto_set();

+  memcpy(buf,(uint8*)&dac_para,sizeof(dac_para));

+  sp_protocol_crc(buf,len -2,buf +len -2);

+  sp_flash_erase(ADDR_KEY_PARA);

+  sp_flash_write(ADDR_KEY_PARA,buf,len);

+}

+

+void adc_init(void)

+{

+  timer4_init();

+  dac_init();

+  adc_gpio_init();

+  adc_nvic_init();

+  adc_dma_init();

+  adc_channels_init();

+  calibrate_key(1);

+}

+

+uint16_t adc_get_val(uint8_t ch)

+{

+  if(ch<ADC_MAX_CH_NUM)

+  {

+    return adc_buff[ch];

+  }

+  else

+  {

+    return 0;

+  }

+}

+

+void adc_timer_tick(void)

+{

+  adc_timer ++;

+  if(adc_timer>=8)

+  {

+    adc_timer = 0;

+  }

+  if(adc_timer==0)

+  {

+    adc_buff[ch_idx] = ADC_GetConversionValue(ADC1);

+    ch_idx ++;

+    if(ch_idx >= ADC_MAX_CH_NUM)

+    {

+      keypad_scan();

+      ch_idx = 0;

+      adc_pdd_process();   //¼ì²éÊÇ·ñµôµç

+    }

+

+    if(ch_idx < 12)

+    {

+      DAC_SetChannel2Data(DAC_Align_12b_R, dac_para.val[ch_idx]);

+    }

+  }

+  else if(adc_timer == 7)

+  {

+    ADC_RegularChannelConfig(ADC1, adc_ch_tbl[ch_idx], 1,

+                             ADC_SampleTime_239Cycles5);

+    ADC_SoftwareStartConvCmd(ADC1, ENABLE);

+  }

+}

+

+void adc_timer_task(void)

+{

+  if(p_adc_timer_tick)

+  {

+    //ÒѾ­³õʼ»¯Íê³É

+    p_adc_timer_tick();

+  }

+}

+

+vu8 PVDFilterCnt = 0;

+static void adc_pdd_process(void)

+{

+  static u16 PreADCValue = PDDThreshod_ADCVal;

+

+  adc_val_vdd = (adc_val_vdd*80ul + adc_get_val(12)*20)/100;

+  if(adc_val_vdd < PreADCValue)

+  {

+    if(PVDFilterCnt < 20)

+    {

+      PVDFilterCnt ++;

+    }

+    PreADCValue =adc_val_vdd;

+  }

+  else if(adc_val_vdd > PreADCValue)

+  {

+    PVDFilterCnt = 0;

+    PreADCValue = PDDThreshod_ADCVal;

+  }

+  /* adc_val_vdd = PreADCValue ˵Ã÷adc_val_vdd

+     δÍê³É¸üУ¬»òµçѹδ¼ÌÐøµøÂ䣬²»×öÈκδ¦Àí

+  else

+  {

+

+  }

+  */

+

+  if((PVDFilterCnt > 10)) // && (adc_val_vdd < Reset_ADCVal))

+  {

+    //¹Ø±Õ¶Á¿¨

+    /*		M1_HardPwrDwn();

+

+    		//µç¶¯Çò·§¹Ø·§´¦Àí

+    		GPIO_ResetBits(GPIOC, GPIO_Pin_9);

+    		GPIO_SetBits(GPIOA, GPIO_Pin_9);

+

+    		//¸´Î»

+    		IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable) ;

+    		IWDG_SetPrescaler(IWDG_Prescaler_128) ;

+    		IWDG_SetReload(1500) ;               //ÉèÖÿ´ÃŹ·¸´Î»Ê±¼ä6S£¬µç»ú·§ÄÜÍêÈ«¹Ø±Õ

+    		IWDG_ReloadCounter();

+    		IWDG_Enable();

+    		while(1);  */

+  }

+}

+

+void dac_para_auto_set(void)

+{

+  uint8_t i;

+  uint16_t dac_val = 4095;

+  uint8_t  adj_flags[12];

+

+  p_adc_timer_tick = 0;

+  delay_ms(10);

+  memset(adj_flags, 1, sizeof(adj_flags));

+  while((dac_val*3300ul*46/40950) > 2000)     //ÔË·ÅÊä³ö²»µÍÓÚ2V

+  {

+    for(i=0; i<12; i++)

+    {

+      if(adj_flags[i])

+      {

+        dac_para.val[i] = dac_val;

+      }

+      DAC_SetChannel2Data(DAC_Align_12b_R, dac_val);

+      delay_ms(6);

+      ADC_RegularChannelConfig(ADC1, adc_ch_tbl[i], 1, ADC_SampleTime_239Cycles5);

+      ADC_SoftwareStartConvCmd(ADC1, ENABLE);

+      delay_ms(2);

+      if(ADC_GetConversionValue(ADC1) < 300ul)

+      {

+        adj_flags[i] = 0;

+      }

+      else

+      {

+        adj_flags[i] = 1;

+      }

+    }

+

+    if(mem_test(adj_flags, 0, sizeof(adj_flags)) == 0)

+    {

+      break;

+    }

+    dac_val -= 124;

+  }

+  p_adc_timer_tick = adc_timer_tick;

+}

+

+static void timer4_init(void)

+{

+  uint16_t PrescalerValue = 0;

+  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

+  TIM_OCInitTypeDef  TIM_OCInitStructure;

+

+  GPIO_InitTypeDef GPIO_InitStructure;

+

+  /* TIM4 clock enable */

+  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

+

+  /* GPIOA and GPIOB clock enable */

+  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);

+

+  /*GPIOB Configuration: TIM4 channel3 and 4 */

+  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8 | GPIO_Pin_9;

+  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

+  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

+  GPIO_Init(GPIOB, &GPIO_InitStructure);

+

+  PrescalerValue = (uint16_t)(SystemCoreClock / 72000000) - 1;

+  /* Time base configuration */

+  TIM_TimeBaseStructure.TIM_Period = 719;

+  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;

+  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

+  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

+

+  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

+

+  /* PWM1 Mode configuration: Channel1 */

+  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

+  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

+  TIM_OCInitStructure.TIM_Pulse = 359;

+  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

+  TIM_OC3Init(TIM4, &TIM_OCInitStructure);

+  TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);

+

+  /* PWM1 Mode configuration: Channel2 */

+  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

+  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

+  TIM_OCInitStructure.TIM_Pulse = 359;

+  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;

+  TIM_OC4Init(TIM4, &TIM_OCInitStructure);

+  TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);

+

+  TIM_ARRPreloadConfig(TIM4, ENABLE);

+

+  /* TIM4 enable counter */

+  TIM_Cmd(TIM4, ENABLE);

+}

diff --git a/sys_hw/drv_adc.h b/sys_hw/drv_adc.h
index 9de4c5d..edbec9b 100644
--- a/sys_hw/drv_adc.h
+++ b/sys_hw/drv_adc.h
@@ -1,29 +1,24 @@
-#ifndef __adc_h__
-#define __adc_h__
-
-#include "stm32f10x.h"
-
-#define ADC_MAX_CH_NUM     (15u)
-
-#pragma pack(push)
-#pragma pack(1)
-
-typedef struct
-{
-	volatile uint16_t val[12];
-	uint16_t crc;
-} dac_para_t;
-
-#pragma pack(pop)
-
-extern dac_para_t dac_para;
-
-extern volatile uint16_t adc_buff[ADC_MAX_CH_NUM];
-
-extern void adc_init(void);
-extern void adc_timer_task(void);
-extern uint16_t adc_get_val(uint8_t ch);
-extern void dac_para_auto_set(void);
-extern void calibrate_key(uint8_t force);
-
-#endif
+#ifndef __adc_h__

+#define __adc_h__

+

+#include "stm32f10x.h"

+

+#define ADC_MAX_CH_NUM     (14u)

+

+typedef struct

+{

+  volatile uint16_t val[12];

+  uint16_t crc;

+} dac_para_t;

+

+extern dac_para_t dac_para;

+

+extern volatile uint16_t adc_buff[ADC_MAX_CH_NUM];

+

+extern void adc_init(void);

+extern void adc_timer_task(void);

+extern uint16_t adc_get_val(uint8_t ch);

+extern void dac_para_auto_set(void);

+extern void calibrate_key(uint8_t force);

+

+#endif