Bläddra i källkod

Last sources.

Vladimir N. Shilov 5 år sedan
förälder
incheckning
1effce3abc
14 ändrade filer med 4244 tillägg och 2588 borttagningar
  1. 252 253
      src/LabArm.c
  2. 42 0
      src/LabArm.cmd
  3. 27 26
      src/LabArm.h
  4. 1281 0
      src/LabArm.uvgui.Vova
  5. 317 0
      src/LabArm.uvopt
  6. 61 47
      src/LabArm.uvproj
  7. 378 378
      src/calibration.c
  8. 213 212
      src/clock.c
  9. 130 129
      src/config.c
  10. 419 418
      src/event.c
  11. 293 293
      src/graph.c
  12. 247 247
      src/n3310.c
  13. 1 1
      src/n3310.h
  14. 583 584
      src/ui.c

+ 252 - 253
src/LabArm.c

@@ -16,47 +16,47 @@ void DMA1_Channel1_IRQHandler()
 void DMAChannel1_IRQHandler(void) /* Read ADC values */
 #endif
 {
-    if (DMA1->ISR & DMA_ISR_HTIF1 && /*   Half Transfer complete */
-            (DMA1_Channel1->CCR & DMA_CCR1_HTIE) /* Half traisfer interrupt enabled */
-       )
+  if (DMA1->ISR & DMA_ISR_HTIF1 && /*   Half Transfer complete */
+       (DMA1_Channel1->CCR & DMA_CCR1_HTIE) /* Half traisfer interrupt enabled */
+      ) 
+  {
+    int i;
+    /* HTIF is set every time when transfer interrupt > half !!! */
+    DMA1_Channel1->CCR &= ~DMA_CCR1_HTIE; /* disable Half traisfer interrupt !!!! */
+
+    for (i = 0; i < ADC_ARRAY_SIZE/2; i = i+2)
     {
-        int i;
-        /* HTIF is set every time when transfer interrupt > half !!! */
-        DMA1_Channel1->CCR &= ~DMA_CCR1_HTIE; /* disable Half traisfer interrupt !!!! */
-
-        for (i = 0; i < ADC_ARRAY_SIZE/2; i = i+2)
-        {
-            ADCVoltageSum += AdcOutArray[i];
-            ADCCurrentSum += AdcOutArray[i+1];
-        }
-    } else if (DMA1->ISR & DMA_ISR_TCIF1 ) /* transfer complete */
-    {
-        int i;
-
-        /* transfer complete */
-        DMA1->IFCR |= DMA_IFCR_CGIF1; /* Clear all interrupt flags */
-        DMA1_Channel1->CCR |= DMA_CCR1_HTIE; /* enable Half traisfer interrupt  */
-
-        for (i=ADC_ARRAY_SIZE/2; i< ADC_ARRAY_SIZE; i=i+2)
-        {
-            ADCVoltageSum += AdcOutArray[i];
-            ADCCurrentSum += AdcOutArray[i+1];
-        }
-
-        DMACounter++;
-        if (DMACounter == 16) /* 2Mhz/195/ADC_ARRAY_SIZE*2/16 - refresh frenq = 5 Hz */
-        {
-            DMACounter = 0;
-            ADCVoltage = ADCVoltageSum;
-            ADCCurrent = ADCCurrentSum;
-            NVIC_SetPendingIRQ(EXTI4_IRQn);
-            ADCVoltageSum = 0;
-            ADCCurrentSum = 0;
-            if ( EventQueue == 0 ) /* Lowest priority */
-                EventQueue = EV_KEY_PRESSED|KEY_ADC;
-        }
+      ADCVoltageSum += AdcOutArray[i];
+      ADCCurrentSum += AdcOutArray[i+1];
     }
+  } else if (DMA1->ISR & DMA_ISR_TCIF1 ) /* transfer complete */
+  {
+    int i;
+
+    /* transfer complete */
     DMA1->IFCR |= DMA_IFCR_CGIF1; /* Clear all interrupt flags */
+    DMA1_Channel1->CCR |= DMA_CCR1_HTIE; /* enable Half traisfer interrupt  */
+
+    for (i=ADC_ARRAY_SIZE/2; i< ADC_ARRAY_SIZE; i=i+2)
+    {
+      ADCVoltageSum += AdcOutArray[i];
+      ADCCurrentSum += AdcOutArray[i+1];
+    }
+
+    DMACounter++;
+    if (DMACounter == 16) /* 2Mhz/195/ADC_ARRAY_SIZE*2/16 - refresh frenq = 5 Hz */
+    {
+      DMACounter = 0;
+      ADCVoltage = ADCVoltageSum;
+      ADCCurrent = ADCCurrentSum;
+      NVIC_SetPendingIRQ(EXTI4_IRQn);
+      ADCVoltageSum = 0;
+      ADCCurrentSum = 0;
+      if ( EventQueue == 0 ) /* Lowest priority */
+        EventQueue = EV_KEY_PRESSED|KEY_ADC; 
+    }
+  }
+  DMA1->IFCR |= DMA_IFCR_CGIF1; /* Clear all interrupt flags */
 }
 
 #if defined(__GNUC__)
@@ -65,34 +65,34 @@ void ADC1_IRQHandler(void)
 void ADC_IRQHandler(void) /*  Watchdog */
 #endif
 {
-    DAC_V = 0; /* OFF output */
-    DAC_I = 0;
-    ADC1->CR2 = 0; /* Adc Off */
-    GPIOB->BRR = GPIO_BRR_BR0|GPIO_BRR_BR1;
-    GPIOB->CRL &= ~(GPIO_CRL_CNF0|GPIO_CRL_CNF1); /* PUSH pull */
-    DAC->CR = 0; /* Dac OFF */
-
-    /* Save current settings */
-    SaveSettings(0);
-    LcdInit(Contrast*3+42);
-    LcdChr(Y_POSITION*3+X_POSITION*0+14+INVERSE, "Power fault" );
-
-    NVIC->ICER[(ADC1_IRQn >> 0x05)] =	(u32)0x01 << (ADC1_IRQn & (u8)0x1F); /* Off ADC interrupt */
-    NVIC->ICPR[(ADC1_IRQn >> 0x05)] =	(u32)0x01 << (ADC1_IRQn & (u8)0x1F); /* Clear pend ADC interrupt */
-
-    {   /* Waiting for power off */
-        __IO uint32_t Delay = 5000000;
-        while (Delay--) ;
-    }
-
-    /* Reboot */
-    NVIC_SystemReset();
+  DAC_V = 0; /* OFF output */
+  DAC_I = 0;
+  ADC1->CR2 = 0; /* Adc Off */
+  GPIOB->BRR = GPIO_BRR_BR0|GPIO_BRR_BR1;
+  GPIOB->CRL &= ~(GPIO_CRL_CNF0|GPIO_CRL_CNF1); /* PUSH pull */
+  DAC->CR = 0; /* Dac OFF */
+
+  /* Save current settings */
+  SaveSettings(0);
+  LcdInit(Contrast*3+42);
+  LcdChr(Y_POSITION*3+X_POSITION*0+14+INVERSE, "Power fault" );
+
+  NVIC->ICER[(ADC1_IRQn >> 0x05)] =	(u32)0x01 << (ADC1_IRQn & (u8)0x1F); /* Off ADC interrupt */
+  NVIC->ICPR[(ADC1_IRQn >> 0x05)] =	(u32)0x01 << (ADC1_IRQn & (u8)0x1F); /* Clear pend ADC interrupt */
+
+  { /* Waiting for power off */
+    __IO uint32_t Delay = 5000000;
+    while (Delay--) ;
+  }
+
+  /* Reboot */
+  NVIC_SystemReset();
 }
 
 void LcdBlank(void)
 {
-    LcdInit(42+Contrast*3);
-    LcdClear();
+  LcdInit(42+Contrast*3);
+  LcdClear();
 }
 
 int16_t HumanV;
@@ -101,228 +101,227 @@ int16_t HumanI;
 
 void EXTI4_IRQHandler(void)
 {
-    HumanV = VoltageFromAdc();
-    HumanI = CurrentFromAdc();
+  HumanV = VoltageFromAdc(); 
+  HumanI = CurrentFromAdc();
 #if defined(GRAPH)
+  {
+    static Graph_t I = {32000,-32000};
+    static Graph_t V = {32000,-32000};
+    static uint16_t Time;
+
+    if (  HumanI < I.Min )
+      I.Min = HumanI;
+    if ( HumanI > I.Max )
+      I.Max = HumanI;
+    if (HumanV < V.Min)
+      V.Min = HumanV;
+    if (HumanV > V.Max)
+      V.Max = HumanV;
+    Time++;
+    if (Time >= TimeInterval)
     {
-        static Graph_t I = {32000,-32000};
-        static Graph_t V = {32000,-32000};
-        static uint16_t Time;
-
-        if (  HumanI < I.Min )
-            I.Min = HumanI;
-        if ( HumanI > I.Max )
-            I.Max = HumanI;
-        if (HumanV < V.Min)
-            V.Min = HumanV;
-        if (HumanV > V.Max)
-            V.Max = HumanV;
-        Time++;
-        if (Time >= TimeInterval)
-        {
-            Time = 0;
-            GraphCurrentPoint++;
-            if (GraphCurrentPoint == GRAPH_SIZE)
-                GraphCurrentPoint = 0;
-            IGraphArray[GraphCurrentPoint] = I;
-            VGraphArray[GraphCurrentPoint] = V;
-            I.Min = 32000;
-            I.Max = -32000;
-            V.Min = 32000;
-            V.Max = -32000;
-        }
+      Time = 0;
+      GraphCurrentPoint++;
+      if (GraphCurrentPoint == GRAPH_SIZE)
+        GraphCurrentPoint = 0;
+      IGraphArray[GraphCurrentPoint] = I;
+      VGraphArray[GraphCurrentPoint] = V;
+      I.Min = 32000;
+      I.Max = -32000;
+      V.Min = 32000;
+      V.Max = -32000;
     }
+  }
 #endif
 }
 
 #if 1
-void SystemInit()
+void SystemInit() 
 {};
 
 
 int main()
 {
-    /* init hardware */
-    SCB->VTOR = FLASH_BASE;
-    NVIC_EnableIRQ(DMA1_Channel1_IRQn); /* Enable DMA interrupt */
-    NVIC_EnableIRQ(ADC1_IRQn); /* Enable ADC interrupt */
-    NVIC_EnableIRQ(EXTI4_IRQn); /*Additional IRQ to calculate V and I */
-    NVIC_SetPriority(EXTI4_IRQn, 12); /* Low priority */
-
-    /* CLOCK = 8MHz / 8 = 1 MHz */
-    RCC->CFGR |= RCC_CFGR_HPRE_DIV2|RCC_CFGR_PPRE1_DIV4|RCC_CFGR_PPRE2_DIV2; /* APB1 - 1MHz, AHB - 4MHz, APB2 - 2MHz, ADC - 1MHz */
-    /* Enable peripery clock */
-    RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |RCC_APB2ENR_ADC1EN|RCC_APB2ENR_TIM1EN;
-    RCC->APB1ENR |= RCC_APB1ENR_TIM3EN|RCC_APB1ENR_TIM2EN|RCC_APB1ENR_DACEN|RCC_APB1ENR_PWREN|RCC_APB1ENR_BKPEN;
-    RCC->AHBENR  |= RCC_AHBENR_DMA1EN|RCC_AHBENR_CRCEN;
-
-    /* Unlock the backup domain */
-    PWR->CR |= PWR_CR_DBP;
-
-    /* GPIO configure */
-    /* PB12 - PB14 - LCD, PA0 - PA2 - encoder(TIM2), PA4-PA5 - DAC Out, PB0-PB1 - ADC(8-9channel), PA7 - ADC power measure */
-    /* PB0 - Voltage IN, PB1 - CurrentIN, PA4 - VoltageOut, PA5 - CurrentOut */
-    GPIOB->CRH |= GPIO_CRH_MODE12_1|GPIO_CRH_MODE13_1|GPIO_CRH_MODE14_1|GPIO_CRH_MODE15_1; /* Output 2MHz */
-    GPIOB->CRH &= ~(GPIO_CRH_CNF12|GPIO_CRH_CNF13|GPIO_CRH_CNF14|GPIO_CRH_CNF15); /* Output Push-pull */
-    GPIOB->CRL |= GPIO_CRL_MODE0_1 |GPIO_CRL_MODE1_1;
-    GPIOB->CRL &= ~(GPIO_CRL_CNF0|GPIO_CRL_CNF1); /* PUSH pull */
-
-    GPIOA->CRL |= GPIO_CRL_MODE4_1 |GPIO_CRL_MODE5_1|GPIO_CRL_MODE6_1|GPIO_CRL_MODE7_1; /* Out 2 MHZ*/
-    GPIOA->CRL &= ~(GPIO_CRL_CNF4|GPIO_CRL_CNF5|GPIO_CRL_CNF6|GPIO_CRL_CNF7); /* PUSH pull */
-    GPIOA->BSRR =  GPIO_BSRR_BS6;
-
-    LcdBlank();
-    /* Enable the programmable voltage detector */
-    PWR->CR |= PWR_CR_PLS_2|PWR_CR_PLS_1; /* 2.8 V */
-    PWR->CR |= PWR_CR_PVDE; /* Enable the PVD */
-
-    {   /* Waiting for power stabilize */
-        __IO uint32_t Delay = 1000000;
-        while (Delay--) ;
-    }
-
-    /* Check power supply */
-    while ( (PWR->CSR & PWR_CSR_PVDO ) != 0 )
-        ; /* BLANK */
-    /* Power is OK for ADC */
-
-    /* Waiting for stabilize power voltage. It should be more then 1.2 V on the PB5 pin */
-    {
-        /* Measure PB5 and Vint by injected group */
-        GPIOA->CRL &= ~GPIO_CRL_MODE7; /* Input, Analog*/
-        ADC1->CR1 |= ADC_CR1_SCAN;
-        ADC1->CR2 |= ADC_CR2_TSVREFE|ADC_CR2_JEXTTRIG | ADC_CR2_JEXTSEL; /* injected start by JSWSTART */
-        ADC1->SMPR1 |= ADC_SMPR1_SMP17; /* Internal Vref, max sampling time */
-        ADC1->SMPR2 |= ADC_SMPR2_SMP7; /* max sampling time */
-        ADC1->CR2 |= ADC_CR2_ADON; /* On the ADC */
-
-        /* Additional delay to Vref on */
-        Delay(10000);
-
-        /* Calibration */
-        ADC1->CR2 |= ADC_CR2_RSTCAL;
-        while ( ADC1->CR2 & ADC_CR2_RSTCAL )
-            ; /* BLANK */
-        ADC1->CR2 |= ADC_CR2_CAL;
-        while ( ADC1->CR2 & ADC_CR2_CAL )
-            ; /* BLANK */
-
-        Delay(10000);
-    }
-
-    /* theck the power voltage */
-    /* 2 conversions. 7-th channels, 17-th channel  */
-    ADC1->JSQR |= ADC_JSQR_JL_0| /* 2 conversion */
-                  ADC_JSQR_JSQ3_0|ADC_JSQR_JSQ3_1|ADC_JSQR_JSQ3_2| /* CH 7 */
-                  ADC_JSQR_JSQ4_4|ADC_JSQR_JSQ4_0; /* CH 17 */
-    do
-    {
-        ADC1->SR &= ~ADC_SR_JEOC; /* Reset convertion flag */
-        ADC1->CR2 |= ADC_CR2_JSWSTART; /* Start the convertion for two channels */
-        while ((ADC1->SR & ADC_SR_JEOC) == 0) /* Waiting end of convertion */
-            ; /* BLANK */
-#if defined(AWD_ENABLED)
-    } while ( ADC1->JDR1/* Vin */ < ADC1->JDR2/* Vref */ );
-#else
-    }
-    while ( 0 );
-#endif
-    {
-        uint16_t SavedVRef = ADC1->JDR2;
-
-        /* Set up analog watch dog */
-        ADC1->CR2 = 0; /* Power off */
-        /* Reset the ADC */
-        RCC->APB2RSTR |= RCC_APB2RSTR_ADC1RST;
-        RCC->APB2RSTR &= ~RCC_APB2RSTR_ADC1RST;
-
-        ADC1->HTR = 0xFFF; /* Max value for HIGHT threshold*/
-        ADC1->LTR = SavedVRef/6*5; /* 1 V */
-    }
-
-    /* Set up ADC, TIM1, DMA for conversion */
-
-    ADC1->CR1 |=
-#if defined(AWD_ENABLED)
-        ADC_CR1_JAWDEN|ADC_CR1_AWDIE| /* AWD on injected channels whith interrupt */
-#endif
-        ADC_CR1_JAUTO|ADC_CR1_SCAN; /* Scan mode + auto injection */
-    ADC1->SMPR2 = ADC_SMPR2_SMP7_0|ADC_SMPR2_SMP8_0|ADC_SMPR2_SMP9_0; /* 7.5 sampling time, 20 - adc time, 5,6,7 ch */
-    ADC1->SQR1 =  ADC_SQR1_L_0; /* 2 conversion */
-    ADC1->SQR3 =  ADC_SQR3_SQ1_3| /* 8 channel - voltage*/
-                  ADC_SQR3_SQ2_3|ADC_SQR3_SQ2_0; /* 9- channel - current */
-    ADC1->JSQR = ADC_JSQR_JSQ4_2|ADC_JSQR_JSQ4_1|ADC_JSQR_JSQ4_0; /* 1 conversion by 7-th channel in inj */
-    ADC1->CR2 |= ADC_CR2_EXTTRIG|ADC_CR2_DMA; /* External trigger by T1 CC1, DMA */
-
-    GPIOA->CRL &= ~(GPIO_CRL_MODE4_1|GPIO_CRL_MODE5_1|GPIO_CRL_MODE7_1); /* Analog IN */
-    GPIOB->CRL &= ~(GPIO_CRL_MODE0_1|GPIO_CRL_MODE1_1); /* Analog IN */
-
-
-    /* TIM1 is configyred to trigger the ADC */
-    TIM1->ARR = 194; /* 2MHz / 200 = 10KHz */
-    TIM1->CCMR1 |= TIM_CCMR1_OC1M; /* PWM 2 mode */
-    TIM1->CCR1 = 99;
-    TIM1->BDTR |= TIM_BDTR_MOE; /* Only for TIM1 - MAIN OUTPUT ENABLE!!! */
-    TIM1->CCER |= TIM_CCER_CC1E; /* Output enable */
-
-    /* DMA configuring */
-    DMA1_Channel1->CCR |= DMA_CCR1_PL|DMA_CCR1_MSIZE_0|DMA_CCR1_PSIZE_0| /*Hight pry, 16 byte mem, 16 byte pereph */
-                          DMA_CCR1_MINC|DMA_CCR1_CIRC|DMA_CCR1_HTIE|DMA_CCR1_TCIE; /*  mem inc, circular, enterrupts by Half and End of conv */
-    DMA1_Channel1->CNDTR = ADC_ARRAY_SIZE;
-    DMA1_Channel1->CPAR = (uint32_t)&ADC1->DR;
-    DMA1_Channel1->CMAR = (uint32_t)&AdcOutArray[0];
-
-    /* On converting */
-    ADC1->CR2 |= ADC_CR2_ADON; /* Adc ON */
+ /* init hardware */
+  SCB->VTOR = FLASH_BASE;
+  NVIC_EnableIRQ(DMA1_Channel1_IRQn); /* Enable DMA interrupt */
+  NVIC_EnableIRQ(ADC1_IRQn); /* Enable ADC interrupt */
+  NVIC_EnableIRQ(EXTI4_IRQn); /*Additional IRQ to calculate V and I */
+  NVIC_SetPriority(EXTI4_IRQn, 12); /* Low priority */
+
+  /* CLOCK = 8MHz / 8 = 1 MHz */
+  RCC->CFGR |= RCC_CFGR_HPRE_DIV2|RCC_CFGR_PPRE1_DIV4|RCC_CFGR_PPRE2_DIV2; /* APB1 - 1MHz, AHB - 4MHz, APB2 - 2MHz, ADC - 1MHz */
+  /* Enable peripery clock */
+  RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |RCC_APB2ENR_ADC1EN|RCC_APB2ENR_TIM1EN;
+  RCC->APB1ENR |= RCC_APB1ENR_TIM3EN|RCC_APB1ENR_TIM2EN|RCC_APB1ENR_DACEN|RCC_APB1ENR_PWREN|RCC_APB1ENR_BKPEN; 
+  RCC->AHBENR  |= RCC_AHBENR_DMA1EN|RCC_AHBENR_CRCEN; 
+
+  /* Unlock the backup domain */
+  PWR->CR |= PWR_CR_DBP;
+
+  /* GPIO configure */
+  /* PB12 - PB14 - LCD, PA0 - PA2 - encoder(TIM2), PA4-PA5 - DAC Out, PB0-PB1 - ADC(8-9channel), PA7 - ADC power measure */
+  /* PB0 - Voltage IN, PB1 - CurrentIN, PA4 - VoltageOut, PA5 - CurrentOut */
+  GPIOB->CRH |= GPIO_CRH_MODE12_1|GPIO_CRH_MODE13_1|GPIO_CRH_MODE14_1|GPIO_CRH_MODE15_1; /* Output 2MHz */
+  GPIOB->CRH &= ~(GPIO_CRH_CNF12|GPIO_CRH_CNF13|GPIO_CRH_CNF14|GPIO_CRH_CNF15); /* Output Push-pull */
+  GPIOB->CRL |= GPIO_CRL_MODE0_1 |GPIO_CRL_MODE1_1;
+  GPIOB->CRL &= ~(GPIO_CRL_CNF0|GPIO_CRL_CNF1); /* PUSH pull */
+  
+  GPIOA->CRL |= GPIO_CRL_MODE4_1 |GPIO_CRL_MODE5_1|GPIO_CRL_MODE6_1|GPIO_CRL_MODE7_1; /* Out 2 MHZ*/
+  GPIOA->CRL &= ~(GPIO_CRL_CNF4|GPIO_CRL_CNF5|GPIO_CRL_CNF6|GPIO_CRL_CNF7); /* PUSH pull */
+  GPIOA->BSRR =  GPIO_BSRR_BS6;
+
+  LcdBlank();
+  /* Enable the programmable voltage detector */
+  PWR->CR |= PWR_CR_PLS_2|PWR_CR_PLS_1; /* 2.8 V */
+  PWR->CR |= PWR_CR_PVDE; /* Enable the PVD */
+
+  { /* Waiting for power stabilize */
+    __IO uint32_t Delay = 1000000;
+    while (Delay--) ;
+  }
+
+  /* Check power supply */
+  while ( (PWR->CSR & PWR_CSR_PVDO ) != 0 )
+    ; /* BLANK */
+  /* Power is OK for ADC */
+
+  /* Waiting for stabilize power voltage. It should be more then 1.2 V on the PB5 pin */
+  {
+    /* Measure PB5 and Vint by injected group */
+    GPIOA->CRL &= ~GPIO_CRL_MODE7; /* Input, Analog*/
+    ADC1->CR1 |= ADC_CR1_SCAN;
+    ADC1->CR2 |= ADC_CR2_TSVREFE|ADC_CR2_JEXTTRIG | ADC_CR2_JEXTSEL; /* injected start by JSWSTART */
+    ADC1->SMPR1 |= ADC_SMPR1_SMP17; /* Internal Vref, max sampling time */
+    ADC1->SMPR2 |= ADC_SMPR2_SMP7; /* max sampling time */
+    ADC1->CR2 |= ADC_CR2_ADON; /* On the ADC */
+    
     /* Additional delay to Vref on */
     Delay(10000);
 
     /* Calibration */
     ADC1->CR2 |= ADC_CR2_RSTCAL;
     while ( ADC1->CR2 & ADC_CR2_RSTCAL )
-        ; /* BLANK */
+      ; /* BLANK */
     ADC1->CR2 |= ADC_CR2_CAL;
     while ( ADC1->CR2 & ADC_CR2_CAL )
-        ; /* BLANK */
+      ; /* BLANK */
 
     Delay(10000);
-    DMA1_Channel1->CCR |= DMA_CCR1_EN; /* Enable DMA */
-    TIM1->CR1 |= TIM_CR1_CEN;    /* start TIM1 */
+  }
+    
+  /* theck the power voltage */
+  /* 2 conversions. 7-th channels, 17-th channel  */
+  ADC1->JSQR |= ADC_JSQR_JL_0| /* 2 conversion */
+                ADC_JSQR_JSQ3_0|ADC_JSQR_JSQ3_1|ADC_JSQR_JSQ3_2| /* CH 7 */
+                ADC_JSQR_JSQ4_4|ADC_JSQR_JSQ4_0; /* CH 17 */
+  do
+  {
+    ADC1->SR &= ~ADC_SR_JEOC; /* Reset convertion flag */
+    ADC1->CR2 |= ADC_CR2_JSWSTART; /* Start the convertion for two channels */
+    while ((ADC1->SR & ADC_SR_JEOC) == 0) /* Waiting end of convertion */
+      ; /* BLANK */
+#if defined(AWD_ENABLED)
+  } while ( ADC1->JDR1/* Vin */ < ADC1->JDR2/* Vref */ );
+#else
+  } while ( 0 );
+#endif
+  {
+    uint16_t SavedVRef = ADC1->JDR2;
 
-    /* DAC Init */
-    DAC_V = 0;
-    DAC_I = 0;
+    /* Set up analog watch dog */
+    ADC1->CR2 = 0; /* Power off */
+    /* Reset the ADC */
+    RCC->APB2RSTR |= RCC_APB2RSTR_ADC1RST;
+    RCC->APB2RSTR &= ~RCC_APB2RSTR_ADC1RST;
 
-    DAC->CR |= DAC_CR_BOFF2|DAC_CR_BOFF1; /* Disable buffers */
-    DAC->CR |= DAC_CR_EN1|DAC_CR_EN2; /* On DAC */
+    ADC1->HTR = 0xFFF; /* Max value for HIGHT threshold*/
+    ADC1->LTR = SavedVRef/6*5; /* 1 V */
+  }
 
-    LcdBlank();
-    EventInit();
+  /* Set up ADC, TIM1, DMA for conversion */
+
+  ADC1->CR1 |= 
+#if defined(AWD_ENABLED)
+                ADC_CR1_JAWDEN|ADC_CR1_AWDIE| /* AWD on injected channels whith interrupt */
+#endif
+                ADC_CR1_JAUTO|ADC_CR1_SCAN; /* Scan mode + auto injection */
+  ADC1->SMPR2 = ADC_SMPR2_SMP7_0|ADC_SMPR2_SMP8_0|ADC_SMPR2_SMP9_0; /* 7.5 sampling time, 20 - adc time, 5,6,7 ch */
+  ADC1->SQR1 =  ADC_SQR1_L_0; /* 2 conversion */
+  ADC1->SQR3 =  ADC_SQR3_SQ1_3| /* 8 channel - voltage*/
+                ADC_SQR3_SQ2_3|ADC_SQR3_SQ2_0; /* 9- channel - current */
+  ADC1->JSQR = ADC_JSQR_JSQ4_2|ADC_JSQR_JSQ4_1|ADC_JSQR_JSQ4_0; /* 1 conversion by 7-th channel in inj */
+  ADC1->CR2 |= ADC_CR2_EXTTRIG|ADC_CR2_DMA; /* External trigger by T1 CC1, DMA */
+
+  GPIOA->CRL &= ~(GPIO_CRL_MODE4_1|GPIO_CRL_MODE5_1|GPIO_CRL_MODE7_1); /* Analog IN */
+  GPIOB->CRL &= ~(GPIO_CRL_MODE0_1|GPIO_CRL_MODE1_1); /* Analog IN */
+
+
+  /* TIM1 is configyred to trigger the ADC */
+  TIM1->ARR = 194; /* 2MHz / 200 = 10KHz */
+  TIM1->CCMR1 |= TIM_CCMR1_OC1M; /* PWM 2 mode */
+  TIM1->CCR1 = 99;
+  TIM1->BDTR |= TIM_BDTR_MOE; /* Only for TIM1 - MAIN OUTPUT ENABLE!!! */
+  TIM1->CCER |= TIM_CCER_CC1E; /* Output enable */
+  
+  /* DMA configuring */
+  DMA1_Channel1->CCR |= DMA_CCR1_PL|DMA_CCR1_MSIZE_0|DMA_CCR1_PSIZE_0| /*Hight pry, 16 byte mem, 16 byte pereph */
+          DMA_CCR1_MINC|DMA_CCR1_CIRC|DMA_CCR1_HTIE|DMA_CCR1_TCIE; /*  mem inc, circular, enterrupts by Half and End of conv */
+  DMA1_Channel1->CNDTR = ADC_ARRAY_SIZE;
+  DMA1_Channel1->CPAR = (uint32_t)&ADC1->DR;
+  DMA1_Channel1->CMAR = (uint32_t)&AdcOutArray[0];
+
+  /* On converting */
+  ADC1->CR2 |= ADC_CR2_ADON; /* Adc ON */
+  /* Additional delay to Vref on */
+  Delay(10000);
+
+  /* Calibration */
+  ADC1->CR2 |= ADC_CR2_RSTCAL;
+  while ( ADC1->CR2 & ADC_CR2_RSTCAL )
+    ; /* BLANK */
+  ADC1->CR2 |= ADC_CR2_CAL;
+  while ( ADC1->CR2 & ADC_CR2_CAL )
+    ; /* BLANK */
+
+  Delay(10000);
+  DMA1_Channel1->CCR |= DMA_CCR1_EN; /* Enable DMA */
+  TIM1->CR1 |= TIM_CR1_CEN;    /* start TIM1 */
+
+  /* DAC Init */
+  DAC_V = 0;
+  DAC_I = 0;
+  
+  DAC->CR |= DAC_CR_BOFF2|DAC_CR_BOFF1; /* Disable buffers */
+  DAC->CR |= DAC_CR_EN1|DAC_CR_EN2; /* On DAC */
+
+  LcdBlank();
+  EventInit();
 #if defined(GRAPH)
-    ClearGraph();
+  ClearGraph();
 #endif
 
-    if ( RestoreConfig() != 0 || (GPIOA->IDR & KEY_ENTER) == 0 )
-    {
-        AfterContrast = CalibrationMenu;
-        Contrast = 7;
-        CurrentFunc(ContrastMenu);
+  if ( RestoreConfig() != 0 || (GPIOA->IDR & KEY_ENTER) == 0 )
+  {
+      AfterContrast = CalibrationMenu;
+      Contrast = 7;
+      CurrentFunc(ContrastMenu);
 //    CurrentFunc(StartFunction);
-    }
-    else
-    {
-        CurrentFunc(StartFunction);
-    }
+  }
+  else
+  {
+    CurrentFunc(StartFunction);
+  }
 #if defined(CLOCK_ENABLED)
-    if ( IS_ON_CLOCK  ) /* RTC clock is on */
-    {
-        SwitchOnTheClock();
-    }
+  if ( IS_ON_CLOCK  ) /* RTC clock is on */
+  {
+    SwitchOnTheClock();
+  }
 #endif
-
-    do
-        EventCheck();
-    while(1);
+  
+  do
+  	EventCheck();
+  while(1);
 }
 
 #endif

+ 42 - 0
src/LabArm.cmd

@@ -0,0 +1,42 @@
+SET PATH=C:\Keil\ARM\ARMCC\bin\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python37\Scripts\;C:\Python37\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\Program Files\TortoiseSVN\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ADB;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Vova\AppData\Local\Microsoft\WindowsApps;C:\MCU\GNU ARM Eclipse\Build Tools\bin;C:\MCU\gcc\bin
+SET CPU_TYPE=STM32F100C4
+SET CPU_VENDOR=STMicroelectronics
+SET UV2_TARGET=LabArm
+SET CPU_CLOCK=0x007A1200
+"C:\Keil\ARM\ARMCC\bin\ArmAsm" --Via ".\out\stm32f10x._ia"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\n3310._ip"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\n3310.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\event._ip"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\event.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\labarm._ip"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\labarm.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\config._ip"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\config.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\ui._ip"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\ui.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\CALIBR~1._IP"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\calibration.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\clock._ip"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\clock.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via "lst\graph._ip"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\graph.__i"
+"C:\Keil\ARM\ARMCC\bin\ArmLink" --Via ".\Out\LabArm.lnp"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\n3310._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\event._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\labarm._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\config._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\ui._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\calibration._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\clock._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\graph._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmLink" --Via ".\Out\LabArm.l2p"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\n3310._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\event._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\labarm._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\config._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\ui._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\calibration._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\clock._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmCC" --Via ".\out\graph._2i"
+"C:\Keil\ARM\ARMCC\bin\ArmLink" --Via ".\Out\LabArm.l2p"
+"C:\Keil\ARM\ARMCC\bin\fromelf.exe" ".\Out\LabArm.axf" --i32combined --output ".\Out\LabArm.hex"

+ 27 - 26
src/LabArm.h

@@ -37,7 +37,7 @@ void SaveMenu(void); /* Save settings to flash menu */
 int  SwitchOnTheClock(void);
 void SetupTheClock(void);
 
-/*
+/* 
 RTCVal - seconds to display
 InvPos - position that has to be inverted. If the first bit is 1 - display seconds also? else - onlu hours and minutes
 Position - start coordinated to display the clock. It can have size 5 or 8 characters depend on InPos 1-st bit */
@@ -50,46 +50,46 @@ extern uint16_t RemainTimerValue;
 
 typedef struct
 {
-    uint16_t VoltageDAC;  // & Contrast
-    uint16_t CurrentDAC;  // & Flafs
-} Settings_t;
+  uint16_t VoltageDAC;  // & Contrast
+  uint16_t CurrentDAC;  // & Flafs
+}Settings_t;
 
 typedef struct
 {
-    float ADCRamp;
-    float ADCOffset;
-    float DACRamp;
-    float DACOffset;
-    int8_t DotPosition;
-    int8_t Res[3];
+  float ADCRamp;
+  float ADCOffset;
+  float DACRamp;
+  float DACOffset;
+  int8_t DotPosition;
+  int8_t Res[3];
 }
 SubConfig_t;
 
 typedef struct
 {
-    uint16_t Value;
-    int8_t   DotPosition;
+  uint16_t Value;
+  int8_t   DotPosition;
 #define MENU_I_FLAG 1
 #define MENU_V_FLAG 2
-    int8_t   IVFlag;
-    char     Text[4];
+  int8_t   IVFlag;
+  char     Text[4];
 }
 UserMenu_t;
 
 typedef struct
 {
-    SubConfig_t V;
-    SubConfig_t I;
-    UserMenu_t Menu[14];
-    int32_t Crc;
-} Config_t;
+  SubConfig_t V;
+  SubConfig_t I;
+  UserMenu_t Menu[14];
+  int32_t Crc;
+}Config_t;
 
 #define SAVED_SETTINGS_COUNT (1024 - sizeof(Config_t))/sizeof(Settings_t)
 //#define SAVED_SETTINGS_COUNT 4
-typedef struct
+typedef struct 
 {
-    Settings_t   Settings[SAVED_SETTINGS_COUNT];
-    Config_t     Config;
+  Settings_t   Settings[SAVED_SETTINGS_COUNT];
+  Config_t     Config;
 //  char res[1024-sizeof(Config_t) - SAVED_SETTINGS_COUNT*sizeof(Settings_t)];
 } SavedDomain_t;
 
@@ -122,8 +122,8 @@ extern int16_t HumanI;
 #define GRAPH_SIZE 80
 typedef struct
 {
-    int16_t Min;
-    int16_t Max;
+  int16_t Min;
+  int16_t Max;
 }
 Graph_t;
 extern Graph_t IGraphArray[GRAPH_SIZE];
@@ -131,8 +131,8 @@ extern Graph_t VGraphArray[GRAPH_SIZE];
 extern uint8_t GraphCurrentPoint;
 typedef struct
 {
-    Graph_t* GraphArray;
-    int8_t   DotPosition;
+  Graph_t* GraphArray;
+  int8_t   DotPosition;
 } GraphData_t;
 extern GraphData_t GraphData;
 extern uint16_t TimeInterval;
@@ -140,3 +140,4 @@ void DisplayGraph(void);
 void ClearGraph(void);
 #endif /*FRAPH*/
 #endif /*__LAB_ARM_H__*/
+

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1281 - 0
src/LabArm.uvgui.Vova


+ 317 - 0
src/LabArm.uvopt

@@ -0,0 +1,317 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_opt.xsd">
+
+  <SchemaVersion>1.0</SchemaVersion>
+
+  <Header>### uVision Project, (C) Keil Software</Header>
+
+  <Extensions>
+    <cExt>*.c</cExt>
+    <aExt>*.s*; *.src; *.a*</aExt>
+    <oExt>*.obj</oExt>
+    <lExt>*.lib</lExt>
+    <tExt>*.txt; *.h; *.inc</tExt>
+    <pExt>*.plm</pExt>
+    <CppX>*.cpp</CppX>
+  </Extensions>
+
+  <DaveTm>
+    <dwLowDateTime>0</dwLowDateTime>
+    <dwHighDateTime>0</dwHighDateTime>
+  </DaveTm>
+
+  <Target>
+    <TargetName>LabArm</TargetName>
+    <ToolsetNumber>0x4</ToolsetNumber>
+    <ToolsetName>ARM-ADS</ToolsetName>
+    <TargetOption>
+      <CLKADS>8000000</CLKADS>
+      <OPTTT>
+        <gFlags>1</gFlags>
+        <BeepAtEnd>1</BeepAtEnd>
+        <RunSim>1</RunSim>
+        <RunTarget>0</RunTarget>
+      </OPTTT>
+      <OPTHX>
+        <HexSelection>1</HexSelection>
+        <FlashByte>65535</FlashByte>
+        <HexRangeLowAddress>0</HexRangeLowAddress>
+        <HexRangeHighAddress>0</HexRangeHighAddress>
+        <HexOffset>0</HexOffset>
+      </OPTHX>
+      <OPTLEX>
+        <PageWidth>79</PageWidth>
+        <PageLength>66</PageLength>
+        <TabStop>8</TabStop>
+        <ListingPath>.\Lst\</ListingPath>
+      </OPTLEX>
+      <ListingPage>
+        <CreateCListing>1</CreateCListing>
+        <CreateAListing>1</CreateAListing>
+        <CreateLListing>1</CreateLListing>
+        <CreateIListing>0</CreateIListing>
+        <AsmCond>1</AsmCond>
+        <AsmSymb>1</AsmSymb>
+        <AsmXref>0</AsmXref>
+        <CCond>1</CCond>
+        <CCode>0</CCode>
+        <CListInc>0</CListInc>
+        <CSymb>0</CSymb>
+        <LinkerCodeListing>0</LinkerCodeListing>
+      </ListingPage>
+      <OPTXL>
+        <LMap>1</LMap>
+        <LComments>1</LComments>
+        <LGenerateSymbols>1</LGenerateSymbols>
+        <LLibSym>1</LLibSym>
+        <LLines>1</LLines>
+        <LLocSym>1</LLocSym>
+        <LPubSym>1</LPubSym>
+        <LXref>0</LXref>
+        <LExpSel>0</LExpSel>
+      </OPTXL>
+      <OPTFL>
+        <tvExp>1</tvExp>
+        <tvExpOptDlg>0</tvExpOptDlg>
+        <IsCurrentTarget>1</IsCurrentTarget>
+      </OPTFL>
+      <CpuCode>255</CpuCode>
+      <DebugOpt>
+        <uSim>0</uSim>
+        <uTrg>1</uTrg>
+        <sLdApp>1</sLdApp>
+        <sGomain>1</sGomain>
+        <sRbreak>1</sRbreak>
+        <sRwatch>1</sRwatch>
+        <sRmem>1</sRmem>
+        <sRfunc>1</sRfunc>
+        <sRbox>1</sRbox>
+        <tLdApp>1</tLdApp>
+        <tGomain>1</tGomain>
+        <tRbreak>1</tRbreak>
+        <tRwatch>1</tRwatch>
+        <tRmem>1</tRmem>
+        <tRfunc>0</tRfunc>
+        <tRbox>1</tRbox>
+        <tRtrace>0</tRtrace>
+        <sRSysVw>1</sRSysVw>
+        <tRSysVw>1</tRSysVw>
+        <tPdscDbg>0</tPdscDbg>
+        <sRunDeb>0</sRunDeb>
+        <sLrtime>0</sLrtime>
+        <nTsel>1</nTsel>
+        <sDll></sDll>
+        <sDllPa></sDllPa>
+        <sDlgDll></sDlgDll>
+        <sDlgPa></sDlgPa>
+        <sIfile></sIfile>
+        <tDll></tDll>
+        <tDllPa></tDllPa>
+        <tDlgDll></tDlgDll>
+        <tDlgPa></tDlgPa>
+        <tIfile></tIfile>
+        <pMon>BIN\UL2CM3.DLL</pMon>
+      </DebugOpt>
+      <TargetDriverDllRegistry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>UL2CM3</Key>
+          <Name>UL2CM3(-O14 -S0 -C0 -N00("ARM Cortex-M3") -D00(1BA00477) -L00(4) -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_16 -FS08000000 -FL04000)</Name>
+        </SetRegEntry>
+      </TargetDriverDllRegistry>
+      <Breakpoint/>
+      <Tracepoint>
+        <THDelay>0</THDelay>
+      </Tracepoint>
+      <DebugFlag>
+        <trace>0</trace>
+        <periodic>0</periodic>
+        <aLwin>0</aLwin>
+        <aCover>0</aCover>
+        <aSer1>0</aSer1>
+        <aSer2>0</aSer2>
+        <aPa>0</aPa>
+        <viewmode>0</viewmode>
+        <vrSel>0</vrSel>
+        <aSym>0</aSym>
+        <aTbox>0</aTbox>
+        <AscS1>0</AscS1>
+        <AscS2>0</AscS2>
+        <AscS3>0</AscS3>
+        <aSer3>0</aSer3>
+        <eProf>0</eProf>
+        <aLa>0</aLa>
+        <aPa1>0</aPa1>
+        <AscS4>0</AscS4>
+        <aSer4>0</aSer4>
+        <StkLoc>0</StkLoc>
+        <TrcWin>0</TrcWin>
+        <newCpu>0</newCpu>
+        <uProt>0</uProt>
+      </DebugFlag>
+      <LintExecutable></LintExecutable>
+      <LintConfigFile></LintConfigFile>
+    </TargetOption>
+  </Target>
+
+  <Group>
+    <GroupName>asm</GroupName>
+    <tvExp>1</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>1</GroupNumber>
+      <FileNumber>1</FileNumber>
+      <FileType>2</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>61</TopLine>
+      <CurrentLine>1</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\STM32F10x.s</PathWithFileName>
+      <FilenameWithoutPath>STM32F10x.s</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+  <Group>
+    <GroupName>Src</GroupName>
+    <tvExp>1</tvExp>
+    <tvExpOptDlg>0</tvExpOptDlg>
+    <cbSel>0</cbSel>
+    <RteFlg>0</RteFlg>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>2</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>0</TopLine>
+      <CurrentLine>0</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\n3310.c</PathWithFileName>
+      <FilenameWithoutPath>n3310.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>3</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>0</TopLine>
+      <CurrentLine>0</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\event.c</PathWithFileName>
+      <FilenameWithoutPath>event.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>4</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>0</TopLine>
+      <CurrentLine>0</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\LabArm.c</PathWithFileName>
+      <FilenameWithoutPath>LabArm.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>5</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>0</TopLine>
+      <CurrentLine>0</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\config.c</PathWithFileName>
+      <FilenameWithoutPath>config.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>6</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>12</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>169</TopLine>
+      <CurrentLine>331</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\ui.c</PathWithFileName>
+      <FilenameWithoutPath>ui.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>7</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>0</TopLine>
+      <CurrentLine>0</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\calibration.c</PathWithFileName>
+      <FilenameWithoutPath>calibration.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>8</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>0</TopLine>
+      <CurrentLine>0</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\clock.c</PathWithFileName>
+      <FilenameWithoutPath>clock.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>9</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <Focus>0</Focus>
+      <ColumnNumber>0</ColumnNumber>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <TopLine>0</TopLine>
+      <CurrentLine>0</CurrentLine>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\graph.c</PathWithFileName>
+      <FilenameWithoutPath>graph.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+  </Group>
+
+</ProjectOpt>

+ 61 - 47
src/LabArm.uvprojx → src/LabArm.uvproj

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
-<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
+<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_proj.xsd">
 
-  <SchemaVersion>2.1</SchemaVersion>
+  <SchemaVersion>1.1</SchemaVersion>
 
   <Header>### uVision Project, (C) Keil Software</Header>
 
@@ -10,19 +10,16 @@
       <TargetName>LabArm</TargetName>
       <ToolsetNumber>0x4</ToolsetNumber>
       <ToolsetName>ARM-ADS</ToolsetName>
-      <pCCUsed>5060061::V5.06 update 1 (build 61)::ARMCC</pCCUsed>
       <TargetOption>
         <TargetCommonOption>
           <Device>STM32F100C4</Device>
           <Vendor>STMicroelectronics</Vendor>
-          <PackID>Keil.STM32F1xx_DFP.2.2.0</PackID>
-          <PackURL>http://www.keil.com/pack/</PackURL>
-          <Cpu>IROM(0x08000000,0x4000) IRAM(0x20000000,0x1000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
+          <Cpu>IRAM(0x20000000-0x20000FFF) IROM(0x8000000-0x8003FFF) CLOCK(8000000) CPUTYPE("Cortex-M3")</Cpu>
           <FlashUtilSpec></FlashUtilSpec>
-          <StartupFile></StartupFile>
-          <FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_16 -FS08000000 -FL04000 -FP0($$Device:STM32F100C4$Flash\STM32F10x_16.FLM))</FlashDriverDll>
-          <DeviceId>0</DeviceId>
-          <RegisterFile>$$Device:STM32F100C4$Device\Include\stm32f10x.h</RegisterFile>
+          <StartupFile>"STARTUP\ST\STM32F10x\startup_stm32f10x_ld_vl.s" ("STM32 Low density Value Line Startup Code")</StartupFile>
+          <FlashDriverDll>UL2CM3(-O14 -S0 -C0 -N00("ARM Cortex-M3") -D00(1BA00477) -L00(4) -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_16 -FS08000000 -FL04000)</FlashDriverDll>
+          <DeviceId>5079</DeviceId>
+          <RegisterFile>stm32f10x.h</RegisterFile>
           <MemoryEnv></MemoryEnv>
           <Cmp></Cmp>
           <Asm></Asm>
@@ -32,14 +29,14 @@
           <SLE66CMisc></SLE66CMisc>
           <SLE66AMisc></SLE66AMisc>
           <SLE66LinkerMisc></SLE66LinkerMisc>
-          <SFDFile>$$Device:STM32F100C4$SVD\STM32F100xx.svd</SFDFile>
+          <SFDFile>SFD\ST\STM32F10xx\STM32F10xx4.sfr</SFDFile>
           <bCustSvd>0</bCustSvd>
           <UseEnv>0</UseEnv>
           <BinPath></BinPath>
           <IncludePath></IncludePath>
           <LibPath></LibPath>
-          <RegisterFilePath></RegisterFilePath>
-          <DBRegisterFilePath></DBRegisterFilePath>
+          <RegisterFilePath>ST\STM32F10x\</RegisterFilePath>
+          <DBRegisterFilePath>ST\STM32F10x\</DBRegisterFilePath>
           <TargetStatus>
             <Error>0</Error>
             <ExitCodeStop>0</ExitCodeStop>
@@ -47,7 +44,7 @@
             <NotGenerated>0</NotGenerated>
             <InvalidFlash>1</InvalidFlash>
           </TargetStatus>
-          <OutputDirectory>.\Obj\</OutputDirectory>
+          <OutputDirectory>.\Out\</OutputDirectory>
           <OutputName>LabArm</OutputName>
           <CreateExecutable>1</CreateExecutable>
           <CreateLib>0</CreateLib>
@@ -57,7 +54,7 @@
           <ListingPath>.\Lst\</ListingPath>
           <HexFormatSelection>1</HexFormatSelection>
           <Merge32K>0</Merge32K>
-          <CreateBatchFile>0</CreateBatchFile>
+          <CreateBatchFile>1</CreateBatchFile>
           <BeforeCompile>
             <RunUserProg1>0</RunUserProg1>
             <RunUserProg2>0</RunUserProg2>
@@ -75,8 +72,6 @@
             <UserProg2Name></UserProg2Name>
             <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
             <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
-            <nStopB1X>0</nStopB1X>
-            <nStopB2X>0</nStopB2X>
           </BeforeMake>
           <AfterMake>
             <RunUserProg1>0</RunUserProg1>
@@ -85,8 +80,6 @@
             <UserProg2Name></UserProg2Name>
             <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
             <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
-            <nStopA1X>0</nStopA1X>
-            <nStopA2X>0</nStopA2X>
           </AfterMake>
           <SelectedForBatchBuild>0</SelectedForBatchBuild>
           <SVCSIdString></SVCSIdString>
@@ -109,7 +102,7 @@
         </CommonProperty>
         <DllOption>
           <SimDllName>SARMCM3.DLL</SimDllName>
-          <SimDllArguments> -REMAP</SimDllArguments>
+          <SimDllArguments></SimDllArguments>
           <SimDlgDll>DCM.DLL</SimDlgDll>
           <SimDlgDllArguments>-pCM3</SimDlgDllArguments>
           <TargetDllName>SARMCM3.DLL</TargetDllName>
@@ -125,6 +118,48 @@
             <HexOffset>0</HexOffset>
             <Oh166RecLen>16</Oh166RecLen>
           </OPTHX>
+          <Simulator>
+            <UseSimulator>0</UseSimulator>
+            <LoadApplicationAtStartup>1</LoadApplicationAtStartup>
+            <RunToMain>1</RunToMain>
+            <RestoreBreakpoints>1</RestoreBreakpoints>
+            <RestoreWatchpoints>1</RestoreWatchpoints>
+            <RestoreMemoryDisplay>1</RestoreMemoryDisplay>
+            <RestoreFunctions>1</RestoreFunctions>
+            <RestoreToolbox>1</RestoreToolbox>
+            <LimitSpeedToRealTime>0</LimitSpeedToRealTime>
+            <RestoreSysVw>1</RestoreSysVw>
+          </Simulator>
+          <Target>
+            <UseTarget>1</UseTarget>
+            <LoadApplicationAtStartup>1</LoadApplicationAtStartup>
+            <RunToMain>1</RunToMain>
+            <RestoreBreakpoints>1</RestoreBreakpoints>
+            <RestoreWatchpoints>1</RestoreWatchpoints>
+            <RestoreMemoryDisplay>1</RestoreMemoryDisplay>
+            <RestoreFunctions>0</RestoreFunctions>
+            <RestoreToolbox>1</RestoreToolbox>
+            <RestoreTracepoints>0</RestoreTracepoints>
+            <RestoreSysVw>1</RestoreSysVw>
+            <UsePdscDebugDescription>0</UsePdscDebugDescription>
+          </Target>
+          <RunDebugAfterBuild>0</RunDebugAfterBuild>
+          <TargetSelection>1</TargetSelection>
+          <SimDlls>
+            <CpuDll></CpuDll>
+            <CpuDllArguments></CpuDllArguments>
+            <PeripheralDll></PeripheralDll>
+            <PeripheralDllArguments></PeripheralDllArguments>
+            <InitializationFile></InitializationFile>
+          </SimDlls>
+          <TargetDlls>
+            <CpuDll></CpuDll>
+            <CpuDllArguments></CpuDllArguments>
+            <PeripheralDll></PeripheralDll>
+            <PeripheralDllArguments></PeripheralDllArguments>
+            <InitializationFile></InitializationFile>
+            <Driver>BIN\UL2CM3.DLL</Driver>
+          </TargetDlls>
         </DebugOption>
         <Utilities>
           <Flash1>
@@ -158,7 +193,7 @@
             <ldmm>1</ldmm>
             <ldXref>1</ldXref>
             <BigEnd>0</BigEnd>
-            <AdsALst>0</AdsALst>
+            <AdsALst>1</AdsALst>
             <AdsACrf>1</AdsACrf>
             <AdsANop>0</AdsANop>
             <AdsANot>0</AdsANot>
@@ -171,8 +206,8 @@
             <AdsLsun>1</AdsLsun>
             <AdsLven>1</AdsLven>
             <AdsLsxf>1</AdsLsxf>
-            <RvctClst>0</RvctClst>
-            <GenPPlst>0</GenPPlst>
+            <RvctClst>1</RvctClst>
+            <GenPPlst>1</GenPPlst>
             <AdsCpuType>"Cortex-M3"</AdsCpuType>
             <RvctDeviceName></RvctDeviceName>
             <mOS>0</mOS>
@@ -189,9 +224,8 @@
             <useUlib>1</useUlib>
             <EndSel>0</EndSel>
             <uLtcg>0</uLtcg>
-            <nSecure>0</nSecure>
             <RoSelD>3</RoSelD>
-            <RwSelD>3</RwSelD>
+            <RwSelD>5</RwSelD>
             <CodeSel>0</CodeSel>
             <OptFeed>1</OptFeed>
             <NoZi1>0</NoZi1>
@@ -322,12 +356,8 @@
             <wLevel>2</wLevel>
             <uThumb>0</uThumb>
             <uSurpInc>0</uSurpInc>
-            <uC99>0</uC99>
+            <uC99>1</uC99>
             <useXO>0</useXO>
-            <v6Lang>1</v6Lang>
-            <v6LangP>1</v6LangP>
-            <vShortEn>1</vShortEn>
-            <vShortWch>1</vShortWch>
             <VariousControls>
               <MiscControls></MiscControls>
               <Define>STM32F10X_LD_VL BIG REAL_FLASH AWD_ENABLED CLOCK_ENABLED GRAPH</Define>
@@ -339,7 +369,7 @@
             <interw>1</interw>
             <Ropi>0</Ropi>
             <Rwpi>0</Rwpi>
-            <thumb>1</thumb>
+            <thumb>0</thumb>
             <SplitLS>0</SplitLS>
             <SwStkChk>0</SwStkChk>
             <NoWarn>0</NoWarn>
@@ -427,24 +457,8 @@
             </File>
           </Files>
         </Group>
-        <Group>
-          <GroupName>::CMSIS</GroupName>
-        </Group>
       </Groups>
     </Target>
   </Targets>
 
-  <RTE>
-    <apis/>
-    <components>
-      <component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="3.40.0" condition="CMSIS Core">
-        <package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="4.2.0"/>
-        <targetInfos>
-          <targetInfo name="LabArm"/>
-        </targetInfos>
-      </component>
-    </components>
-    <files/>
-  </RTE>
-
 </Project>

+ 378 - 378
src/calibration.c

@@ -4,13 +4,13 @@
 uint8_t MenuMode;
 typedef struct
 {
-    uint32_t Adc;
-    int16_t Dac; /* 1 - 4095 */
-    int16_t Out; /* 1 - 9999 */
-    int8_t DotPosition; /* 0,1,2,3,4 */
-    int8_t Ok; /* Fiilled flag */
-    int16_t Res;
-} Calibration_t;
+  uint32_t Adc;
+  int16_t Dac; /* 1 - 4095 */
+  int16_t Out; /* 1 - 9999 */
+  int8_t DotPosition; /* 0,1,2,3,4 */
+  int8_t Ok; /* Fiilled flag */
+  int16_t Res;
+}Calibration_t;
 
 
 
@@ -26,170 +26,170 @@ MenuFunction_t  AfterContrast;
 
 void ContrastMenu(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
+  if (Event == EV_FUNC_FIRST)
+  {
 //    Contrast = CurrentSettings.VoltageDAC>>12;
-        LcdBlank(); /* Clear screen */
-        LcdChr(Y_POSITION*1 + X_POSITION * 0 + 14, "Contrast");
-        LcdChr(Y_POSITION*4 + X_POSITION * 0 + 14, "Press");
-        LcdChr(Y_POSITION*5 + X_POSITION * 0 + 14, "to exit");
-        goto redraw;
-    }
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+    LcdBlank(); /* Clear screen */
+    LcdChr(Y_POSITION*1 + X_POSITION * 0 + 14, "Contrast");
+    LcdChr(Y_POSITION*4 + X_POSITION * 0 + 14, "Press");
+    LcdChr(Y_POSITION*5 + X_POSITION * 0 + 14, "to exit");
+    goto redraw;
+  }
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_UP:
-            if ( Contrast < 15 )
-                Contrast++;
-            break;
-        case KEY_DOWN:
-            if ( Contrast > 0 )
-                Contrast--;
-            break;
-        case KEY_ENTER:
-            LcdContrast ( Contrast*3+42 );
-            CurrentFunc(AfterContrast);
-            return;
-        }
-redraw:
+      case KEY_UP:
+        if ( Contrast < 15 )
+          Contrast++;
+        break;
+      case KEY_DOWN:
+        if ( Contrast > 0 )
+          Contrast--;
+        break;
+      case KEY_ENTER:
         LcdContrast ( Contrast*3+42 );
-        {
-            char Buf[2];
-            uint8_t Counter = Contrast;
-
-            Buf[0] = Counter/10 + '0';
-            Counter = Counter%10;
-            Buf[1] = Counter + '0';
-            LcdChr(BIG_UP+Y_POSITION*2 + X_POSITION * 2 + 2, Buf);
-            LcdChr(BIG_DOWN+Y_POSITION*3 + X_POSITION * 2 + 2, Buf);
-        }
+        CurrentFunc(AfterContrast);
+         return;
     }
+redraw:
+    LcdContrast ( Contrast*3+42 );
+    {
+      char Buf[2];
+      uint8_t Counter = Contrast;
+      
+      Buf[0] = Counter/10 + '0';
+      Counter = Counter%10;
+      Buf[1] = Counter + '0';
+      LcdChr(BIG_UP+Y_POSITION*2 + X_POSITION * 2 + 2, Buf);
+      LcdChr(BIG_DOWN+Y_POSITION*3 + X_POSITION * 2 + 2, Buf);
+    }
+  }
 }
 
 
 static float Offset(float YMax, float YMin, float XMax, float XMin)
 {
-    return (YMin*XMax - YMax*XMin)/(XMax-XMin);
+  return (YMin*XMax - YMax*XMin)/(XMax-XMin);
 }
 static void CalibrationToConfig(Config_t* Config)
 {
-    int i;
-
-    Config->V.ADCRamp = ((float)(VMax.Out - VMin.Out))/(VMax.Adc-VMin.Adc);
-    Config->V.ADCOffset = Offset(VMax.Out, VMin.Out, VMax.Adc, VMin.Adc);
-    Config->I.ADCRamp = ((float)(IMax.Out - IMin.Out))/(IMax.Adc-IMin.Adc);
-    Config->I.ADCOffset = Offset(IMax.Out, IMin.Out, IMax.Adc, IMin.Adc);
-    Config->V.DACRamp = ((float)(VMax.Out - VMin.Out))/(VMax.Dac-VMin.Dac);
-    Config->V.DACOffset = Offset(VMax.Out, VMin.Out, VMax.Dac, VMin.Dac);
-    Config->I.DACRamp = ((float)(IMax.Out - IMin.Out))/(IMax.Dac-IMin.Dac);
-    Config->I.DACOffset = Offset(IMax.Out,IMin.Out,IMax.Dac, IMin.Dac);
-    Config->V.DotPosition = VMax.DotPosition;
-    Config->I.DotPosition = IMax.DotPosition;
-
-    /* Check menu correctness */
-    for (i=0; i<12; i++)
+  int i;
+
+  Config->V.ADCRamp = ((float)(VMax.Out - VMin.Out))/(VMax.Adc-VMin.Adc);
+  Config->V.ADCOffset = Offset(VMax.Out, VMin.Out, VMax.Adc, VMin.Adc);
+  Config->I.ADCRamp = ((float)(IMax.Out - IMin.Out))/(IMax.Adc-IMin.Adc);
+  Config->I.ADCOffset = Offset(IMax.Out, IMin.Out, IMax.Adc, IMin.Adc);
+  Config->V.DACRamp = ((float)(VMax.Out - VMin.Out))/(VMax.Dac-VMin.Dac);
+  Config->V.DACOffset = Offset(VMax.Out, VMin.Out, VMax.Dac, VMin.Dac);
+  Config->I.DACRamp = ((float)(IMax.Out - IMin.Out))/(IMax.Dac-IMin.Dac);
+  Config->I.DACOffset = Offset(IMax.Out,IMin.Out,IMax.Dac, IMin.Dac);
+  Config->V.DotPosition = VMax.DotPosition;
+  Config->I.DotPosition = IMax.DotPosition;
+  
+  /* Check menu correctness */
+  for (i=0; i<12; i++)
+  {
+    UserMenu_t* Menu = &CurrentConfig.Menu[i];
+    if ( (Menu->IVFlag == MENU_I_FLAG && IMax.DotPosition != Menu->DotPosition ) ||
+         (Menu->IVFlag == MENU_V_FLAG && VMax.DotPosition != Menu->DotPosition ) ) /* Dot position was changed */
     {
-        UserMenu_t* Menu = &CurrentConfig.Menu[i];
-        if ( (Menu->IVFlag == MENU_I_FLAG && IMax.DotPosition != Menu->DotPosition ) ||
-                (Menu->IVFlag == MENU_V_FLAG && VMax.DotPosition != Menu->DotPosition ) ) /* Dot position was changed */
-        {
-            memset(Menu, 0xFF, sizeof(*Menu)); /* Clear the menu */
-        }
+      memset(Menu, 0xFF, sizeof(*Menu)); /* Clear the menu */
     }
+  }
 }
 
 
 void OutValue(uint8_t Y, uint8_t X, uint16_t Num, uint8_t DotPosition, uint8_t SelectPos)
 {
-    int i;
-    int Div = 1000;
-    uint8_t DisplayFlag = 0;
-
-    for(i=0; i<4; i++)
+  int i;
+  int Div = 1000;
+  uint8_t DisplayFlag = 0;
+  
+  for(i=0; i<4; i++)
+  {
+    char Chr;
+    uint32_t Light = 0;
+
+    if (i == DotPosition )
     {
-        char Chr;
-        uint32_t Light = 0;
-
-        if (i == DotPosition )
-        {
-            LcdChr ( Y_POSITION*(Y)+X_POSITION*X+1, " " );
-            LcdChr ( Y_POSITION*(Y+1)+X_POSITION*X+1, "." );
-            X=X+1;
-            DisplayFlag++;
-        }
-
-        if ( DisplayFlag == 0 && i == (DotPosition - 1))
-        {
-            DisplayFlag++;
-        }
+      LcdChr ( Y_POSITION*(Y)+X_POSITION*X+1, " " );
+      LcdChr ( Y_POSITION*(Y+1)+X_POSITION*X+1, "." );
+      X=X+1;
+      DisplayFlag++;
+    }
 
-        Chr = Num / Div;
-        if ( DisplayFlag == 0 && Chr == 0)
-            Chr = ' ';
-        else
-        {
-            DisplayFlag = 1;
-            Chr = Chr + '0';
-        }
-        if (i == SelectPos)
-        {
-            Light = INVERSE;
-        }
-        LcdChr (Light + Y_POSITION*Y+X_POSITION*X+BIG_UP+1, &Chr );
-        LcdChr (Light + Y_POSITION*(Y+1)+X_POSITION*X+BIG_DOWN+1, &Chr );
-        X = X + 2;
-        Num = Num % Div;
-        Div = Div / 10;
+    if ( DisplayFlag == 0 && i == (DotPosition - 1))
+    {
+      DisplayFlag++;
     }
-    if ( DotPosition == 4)
+
+    Chr = Num / Div;
+    if ( DisplayFlag == 0 && Chr == 0)
+      Chr = ' ';
+    else
     {
-        LcdChr ( Y_POSITION*(Y)+X_POSITION*X+1, " " );
-        LcdChr ( Y_POSITION*(Y+1)+X_POSITION*X+1, " " );
+      DisplayFlag = 1;
+      Chr = Chr + '0';
     }
+    if (i == SelectPos)
+    {
+      Light = INVERSE;
+    } 
+    LcdChr (Light + Y_POSITION*Y+X_POSITION*X+BIG_UP+1, &Chr );
+    LcdChr (Light + Y_POSITION*(Y+1)+X_POSITION*X+BIG_DOWN+1, &Chr );
+    X = X + 2;
+    Num = Num % Div;
+    Div = Div / 10;
+  }
+  if ( DotPosition == 4)
+  {
+    LcdChr ( Y_POSITION*(Y)+X_POSITION*X+1, " " );
+    LcdChr ( Y_POSITION*(Y+1)+X_POSITION*X+1, " " );
+  }
 }
 
 void OutValueSmall(uint8_t Y, uint8_t X, uint16_t Num, uint8_t DotPosition, uint8_t InverseFlag)
 {
-    int i;
-    int Div = 1000;
-    uint32_t Light = InverseFlag?INVERSE:0;
-    uint8_t DisplayFlag=0;
-
-    for(i=0; i<4; i++)
+  int i;
+  int Div = 1000;
+  uint32_t Light = InverseFlag?INVERSE:0;
+  uint8_t DisplayFlag=0;
+  
+  for(i=0; i<4; i++)
+  {
+    char Chr;
+
+    if (i == DotPosition)
     {
-        char Chr;
-
-        if (i == DotPosition)
-        {
-            DisplayFlag = 1;
-            LcdChr ( Light + Y_POSITION*(Y)+X_POSITION*X+1, "." );
-            X=X+1;
-            DisplayFlag++;
-        }
-
-        if ( DisplayFlag == 0 && i == (DotPosition - 1))
-        {
-            DisplayFlag++;
-        }
+      DisplayFlag = 1;
+      LcdChr ( Light + Y_POSITION*(Y)+X_POSITION*X+1, "." );
+      X=X+1;     
+      DisplayFlag++;
+    }
 
-        Chr = Num / Div;
-        if ( DisplayFlag == 0 && Chr == 0)
-            Chr = ' ';
-        else
-        {
-            DisplayFlag = 1;
-            Chr = Chr + '0';
-        }
-        LcdChr (Light + Y_POSITION*Y+X_POSITION*X+1, &Chr );
-        X = X + 1;
-        Num = Num % Div;
-        Div = Div / 10;
+    if ( DisplayFlag == 0 && i == (DotPosition - 1))
+    {
+      DisplayFlag++;
     }
-    if ( DotPosition == 4)
+
+    Chr = Num / Div;
+    if ( DisplayFlag == 0 && Chr == 0)
+      Chr = ' ';
+    else
     {
-        LcdChr ( Y_POSITION*(Y)+X_POSITION*X+1, " " );
+      DisplayFlag = 1;
+      Chr = Chr + '0';
     }
+    LcdChr (Light + Y_POSITION*Y+X_POSITION*X+1, &Chr );
+    X = X + 1;
+    Num = Num % Div;
+    Div = Div / 10;
+  }
+  if ( DotPosition == 4)
+  {
+    LcdChr ( Y_POSITION*(Y)+X_POSITION*X+1, " " );
+  }
 }
 
 
@@ -197,40 +197,40 @@ void CalibrationMenuInternal(void);
 
 void SaveMenu(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        MenuMode = 0;
-        LcdBlank(); /* Clear screen */
-        goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  if (Event == EV_FUNC_FIRST)
+  {
+    MenuMode = 0;
+    LcdBlank(); /* Clear screen */
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if ( MenuMode == 0 )
+          MenuMode = 1;
+        break;
+      case KEY_DOWN:
+        if ( MenuMode != 0 )
+          MenuMode = 0;
+        break;
+      case KEY_ENTER:
+        if (MenuMode != 0)
         {
-        case KEY_UP:
-            if ( MenuMode == 0 )
-                MenuMode = 1;
-            break;
-        case KEY_DOWN:
-            if ( MenuMode != 0 )
-                MenuMode = 0;
-            break;
-        case KEY_ENTER:
-            if (MenuMode != 0)
-            {
-                SaveConfig();
-            }
-            CurrentFunc(StartFunction);
-            return;
+          SaveConfig();
         }
-    }
-    else
+        CurrentFunc(StartFunction);
         return;
+    }
+  }
+  else
+    return;
 
 redraw:
-    LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuMode)*INVERSE, "Save to memory");
-    LcdChr(X_POSITION*0+Y_POSITION*2+14 + (1==MenuMode)*INVERSE, "Save to flash");
+  LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuMode)*INVERSE, "Save to memory");
+  LcdChr(X_POSITION*0+Y_POSITION*2+14 + (1==MenuMode)*INVERSE, "Save to flash");
 }
 
 
@@ -238,267 +238,267 @@ void SetDac(void);
 
 void SelectDot(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
+      case KEY_UP:
+        Cur->DotPosition++;
+        if (Cur->DotPosition>4)
+          Cur->DotPosition = 4;
         goto redraw;
+      case KEY_DOWN:
+        Cur->DotPosition--;
+        if (Cur->DotPosition<0)
+          Cur->DotPosition = 0;
+        goto redraw;
+      case KEY_ENTER:
+        CurrentFunc(SetDac);
     }
+  }
 
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_UP:
-            Cur->DotPosition++;
-            if (Cur->DotPosition>4)
-                Cur->DotPosition = 4;
-            goto redraw;
-        case KEY_DOWN:
-            Cur->DotPosition--;
-            if (Cur->DotPosition<0)
-                Cur->DotPosition = 0;
-            goto redraw;
-        case KEY_ENTER:
-            CurrentFunc(SetDac);
-        }
-    }
-
-    return;
+  return;
 redraw:
-    LcdChr(X_POSITION*0+Y_POSITION*1+14, Text);
-    LcdChr(X_POSITION*0+Y_POSITION*2+14, "Set Dot");
-    OutValue(3, 1, Cur->Out, Cur->DotPosition, 0xFF);
+  LcdChr(X_POSITION*0+Y_POSITION*1+14, Text);
+  LcdChr(X_POSITION*0+Y_POSITION*2+14, "Set Dot");
+  OutValue(3, 1, Cur->Out, Cur->DotPosition, 0xFF);
 }
 
 int16_t IncrementMul;
 int8_t  ChangeNumberFlag;
 void SetOut(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        MenuMode = 0;
-        IncrementMul = 1000;
-        ChangeNumberFlag = 0;
-        LcdChr(X_POSITION*0+Y_POSITION*1+14, Text);
-        LcdChr(X_POSITION*0+Y_POSITION*2+14, "Set Out");
-        LcdChr(X_POSITION*0+Y_POSITION*5+14, "Longkey to end");
-        goto redraw;
-    }
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuMode = 0;
+    IncrementMul = 1000;
+    ChangeNumberFlag = 0;
+    LcdChr(X_POSITION*0+Y_POSITION*1+14, Text);
+    LcdChr(X_POSITION*0+Y_POSITION*2+14, "Set Out");
+    LcdChr(X_POSITION*0+Y_POSITION*5+14, "Longkey to end");
+    goto redraw;
+  }
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if ( ChangeNumberFlag )
         {
-        case KEY_UP:
-            if ( ChangeNumberFlag )
-            {
-                Cur->Out += IncrementMul;
-                goto redraw;
-            }
-            else
-            {
-                if ( MenuMode < 3 )
-                {
-                    IncrementMul /= 10;
-                    MenuMode++;
-                    goto redraw;
-                }
-            }
-            return;
-        case KEY_DOWN:
-            if ( ChangeNumberFlag )
-            {
-                Cur->Out -= IncrementMul;
-                goto redraw;
-            }
-            else
-            {
-                if ( MenuMode > 0 )
-                {
-                    IncrementMul *= 10;
-                    MenuMode--;
-                    goto redraw;
-                }
-            }
-            return;
-        case KEY_ENTER:
-            if ( ChangeNumberFlag == 0 )
-                ChangeNumberFlag = 1;
-            else
-                ChangeNumberFlag = 0;
-            return;
+          Cur->Out += IncrementMul;
+          goto redraw;
         }
+        else
+        {
+          if ( MenuMode < 3 )
+          {
+            IncrementMul /= 10;
+            MenuMode++;
+            goto redraw;
+          }
+        }
+        return;
+      case KEY_DOWN:
+        if ( ChangeNumberFlag )
+        {
+          Cur->Out -= IncrementMul;
+          goto redraw;
+        }
+        else
+        {
+          if ( MenuMode > 0 )
+          {
+            IncrementMul *= 10;
+            MenuMode--;
+            goto redraw;
+          }
+        }
+        return;
+      case KEY_ENTER:
+        if ( ChangeNumberFlag == 0 )
+          ChangeNumberFlag = 1;
+        else
+          ChangeNumberFlag = 0;
+        return;
     }
-    if ( (Event & EV_MASK) == EV_KEY_LONG )
-    {
-        Cur->Ok = 1;
-        CurrentFunc(CalibrationMenuInternal);
-    }
+  }
+  if ( (Event & EV_MASK) == EV_KEY_LONG )
+  {
+    Cur->Ok = 1;
+    CurrentFunc(CalibrationMenuInternal);
+  }
 
-    return;
+  return;
 
 redraw:
-    OutValue(3, 1, Cur->Out, Cur->DotPosition, MenuMode);
+  OutValue(3, 1, Cur->Out, Cur->DotPosition, MenuMode);
 }
 
 void WaitMeasure(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        LcdChr(X_POSITION*0+Y_POSITION*3+14, "Please wait");
-        MenuMode = 0;
-        return;
-    }
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    LcdChr(X_POSITION*0+Y_POSITION*3+14, "Please wait");
+    MenuMode = 0;
+    return;
+  }
 
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED &&
-            (Event & KEY_MASK) == KEY_ADC ) /* End of conversion */
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED &&
+       (Event & KEY_MASK) == KEY_ADC ) /* End of conversion */
+  {
+    if (MenuMode == 2)
     {
-        if (MenuMode == 2)
-        {
-            CurrentFunc(SetOut);
-            if ( Cur == &VMax || Cur == &VMin )
-                Cur->Adc = ADCVoltage;
-            else
-                Cur->Adc = ADCCurrent;
-        }
-        MenuMode++;
+      CurrentFunc(SetOut);
+      if ( Cur == &VMax || Cur == &VMin )
+        Cur->Adc = ADCVoltage;
+      else
+        Cur->Adc = ADCCurrent;
     }
+    MenuMode++;
+  }
 }
 
 void SetDac(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    LcdChr(X_POSITION*0+Y_POSITION*1+14, Text);
+    LcdChr(X_POSITION*0+Y_POSITION*2+14, "Set Out");
+    EncCounter = Cur->Dac;
+    goto redraw;
+  }
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        LcdChr(X_POSITION*0+Y_POSITION*1+14, Text);
-        LcdChr(X_POSITION*0+Y_POSITION*2+14, "Set Out");
-        EncCounter = Cur->Dac;
+      case KEY_UP:
+      case KEY_DOWN:
+        Cur->Dac = EncCounter;
         goto redraw;
+   case KEY_ENTER:
+        CurrentFunc(WaitMeasure);
     }
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_UP:
-        case KEY_DOWN:
-            Cur->Dac = EncCounter;
-            goto redraw;
-        case KEY_ENTER:
-            CurrentFunc(WaitMeasure);
-        }
-    }
+  }
 
-    return;
+  return;
 redraw:
-    OutValue(3, 1, Cur->Dac, 4,  0xFF);
-    *CurDac = Cur->Dac;
-    OutValueSmall(5,0, EncStep, 4, 0);
+  OutValue(3, 1, Cur->Dac, 4,  0xFF);
+  *CurDac = Cur->Dac;
+  OutValueSmall(5,0, EncStep, 4, 0);
 }
 
 
 void CalibrationMenu(void)
 {
-    /* Init The calibration */
-    VMax.Ok = 0;
-    VMin.Ok = 0;
-    IMax.Ok = 0;
-    IMin.Ok = 0;
-    CurrentFunc(CalibrationMenuInternal);
+  /* Init The calibration */
+  VMax.Ok = 0;
+  VMin.Ok = 0;
+  IMax.Ok = 0;
+  IMin.Ok = 0;
+  CurrentFunc(CalibrationMenuInternal);
 }
 
 void CalibrationMenuInternal(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    MenuMode = 0;
+    LcdBlank(); /* Clear screen */
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        MenuMode = 0;
-        LcdBlank(); /* Clear screen */
+      case KEY_DOWN:
+        if ( MenuMode == 0 )
+          MenuMode = 4;
+        else
+          MenuMode = MenuMode - 1;
         goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if ( MenuMode == 4 )
+          MenuMode = 0;
+        else
+          MenuMode = MenuMode + 1;
+        goto redraw;
+      case KEY_ENTER:
+        switch(MenuMode)
         {
-        case KEY_DOWN:
-            if ( MenuMode == 0 )
-                MenuMode = 4;
-            else
-                MenuMode = MenuMode - 1;
-            goto redraw;
-        case KEY_UP:
-            if ( MenuMode == 4 )
-                MenuMode = 0;
-            else
-                MenuMode = MenuMode + 1;
-            goto redraw;
-        case KEY_ENTER:
-            switch(MenuMode)
+          case 0:
+            Cur = &VMax;
+            Text = "Max Voltage";
+            Cur->Dac = 3700;
+            Cur->Out = 5555;
+            Cur->DotPosition = 2;
+            CurDac = &DAC_V;
+            CurrentFunc(SelectDot);
+            return;
+          case 1:
+            if (VMax.Ok == 0 ) /* The max value has not been set */
+              return;
+            Cur = &VMin;
+            Text = "Min Voltage";
+            Cur->Dac = 350;
+            Cur->Out = 555;
+            Cur->DotPosition = VMax.DotPosition;
+            CurDac = &DAC_V;
+            CurrentFunc(SetDac);
+            return;
+          case 2:
+            Cur = &IMax;
+            Text = "Max Current";
+            Cur->Dac = 3700;
+            Cur->Out = 5555;
+            Cur->DotPosition = 2;
+            CurDac = &DAC_I;
+            DAC_V = 2000; /* Set intermidiate voltage value !!! */
+            CurrentFunc(SelectDot);
+            return;
+          case 3:
+            if (IMax.Ok == 0 ) /* The max value has not been set */
+              return;
+            Cur = &IMin;
+            Text = "Min Current";
+            Cur->Dac = 350;
+            Cur->Out = 555;
+            Cur->DotPosition = IMax.DotPosition;
+            CurDac = &DAC_I;
+            CurrentFunc(SetDac);
+            return;
+          default:
+            if ( VMax.Ok && VMin.Ok && IMax.Ok && IMin.Ok )
             {
-            case 0:
-                Cur = &VMax;
-                Text = "Max Voltage";
-                Cur->Dac = 3700;
-                Cur->Out = 5555;
-                Cur->DotPosition = 2;
-                CurDac = &DAC_V;
-                CurrentFunc(SelectDot);
-                return;
-            case 1:
-                if (VMax.Ok == 0 ) /* The max value has not been set */
-                    return;
-                Cur = &VMin;
-                Text = "Min Voltage";
-                Cur->Dac = 350;
-                Cur->Out = 555;
-                Cur->DotPosition = VMax.DotPosition;
-                CurDac = &DAC_V;
-                CurrentFunc(SetDac);
-                return;
-            case 2:
-                Cur = &IMax;
-                Text = "Max Current";
-                Cur->Dac = 3700;
-                Cur->Out = 5555;
-                Cur->DotPosition = 2;
-                CurDac = &DAC_I;
-                DAC_V = 2000; /* Set intermidiate voltage value !!! */
-                CurrentFunc(SelectDot);
-                return;
-            case 3:
-                if (IMax.Ok == 0 ) /* The max value has not been set */
-                    return;
-                Cur = &IMin;
-                Text = "Min Current";
-                Cur->Dac = 350;
-                Cur->Out = 555;
-                Cur->DotPosition = IMax.DotPosition;
-                CurDac = &DAC_I;
-                CurrentFunc(SetDac);
-                return;
-            default:
-                if ( VMax.Ok && VMin.Ok && IMax.Ok && IMin.Ok )
-                {
-                    CalibrationToConfig(&CurrentConfig);
-                    CurrentFunc(SaveMenu);
-                }
-                return;
+              CalibrationToConfig(&CurrentConfig);
+              CurrentFunc(SaveMenu);
             }
+            return;
         }
     }
-    return;
-
+  }
+  return;
+  
 redraw:
-    LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuMode)*INVERSE, "Max Voltage");
-    LcdChr(X_POSITION*0+Y_POSITION*2+14 + (1==MenuMode)*INVERSE, "Min Voltage");
-    LcdChr(X_POSITION*0+Y_POSITION*3+14 + (2==MenuMode)*INVERSE, "Max Current");
-    LcdChr(X_POSITION*0+Y_POSITION*4+14 + (3==MenuMode)*INVERSE, "Min Current");
-    if ( VMax.Ok && VMin.Ok && IMax.Ok && IMin.Ok )
-    {
-        LcdChr(X_POSITION*0+Y_POSITION*5+14 + (4==MenuMode)*INVERSE, "Ok");
-    }
-    else
-    {
-        LcdChr(X_POSITION*0+Y_POSITION*5+14 + (4==MenuMode)*INVERSE, "");
-    }
+  LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuMode)*INVERSE, "Max Voltage");
+  LcdChr(X_POSITION*0+Y_POSITION*2+14 + (1==MenuMode)*INVERSE, "Min Voltage");
+  LcdChr(X_POSITION*0+Y_POSITION*3+14 + (2==MenuMode)*INVERSE, "Max Current");
+  LcdChr(X_POSITION*0+Y_POSITION*4+14 + (3==MenuMode)*INVERSE, "Min Current");
+  if ( VMax.Ok && VMin.Ok && IMax.Ok && IMin.Ok )
+  {
+    LcdChr(X_POSITION*0+Y_POSITION*5+14 + (4==MenuMode)*INVERSE, "Ok");
+  }
+  else
+  {
+    LcdChr(X_POSITION*0+Y_POSITION*5+14 + (4==MenuMode)*INVERSE, "");
+  }
 }

+ 213 - 212
src/clock.c

@@ -5,106 +5,106 @@
 
 void DisplayClock(uint32_t RTCVal, uint16_t InvPos, uint32_t Position)
 {
-    int Sec = RTCVal % (24*60*60); /* Seconds in the day */
-    int Value;
-    char Ch;
+  int Sec = RTCVal % (24*60*60); /* Seconds in the day */
+  int Value;
+  char Ch;
+  
+  if (Sec % 2 )
+    Ch = ' ';
+  else
+    Ch = ':';
+  LcdChr(Position + X_POSITION*2 + 1, &Ch );
 
-    if (Sec % 2 )
-        Ch = ' ';
-    else
-        Ch = ':';
-    LcdChr(Position + X_POSITION*2 + 1, &Ch );
-
-    if ( ((int16_t)InvPos) < 0 )
-    {
-        LcdChr(Position + X_POSITION*5 + 1, &Ch );
-        Value = Sec % 60; /* Seconds */
-        Ch = Value/10 + '0';
-        LcdChr( Position + X_POSITION*6 + 1, &Ch );
-        Ch = Value%10 + '0';
-        LcdChr( Position + X_POSITION*7 + 1, &Ch );
-    }
-    InvPos &= ~0x8000;
-    Value = Sec/(60*60); /* Hour */
+  if ( ((int16_t)InvPos) < 0 )
+  {
+    LcdChr(Position + X_POSITION*5 + 1, &Ch );
+    Value = Sec % 60; /* Seconds */
     Ch = Value/10 + '0';
-    LcdChr( Position + 1 + ((InvPos==0)?INVERSE:0), &Ch );
+    LcdChr( Position + X_POSITION*6 + 1, &Ch );
     Ch = Value%10 + '0';
-    LcdChr( Position + X_POSITION*1 + 1 +((InvPos==1)?INVERSE:0), &Ch );
-    Sec = Sec%(60*60); /* Sec in the hour*/
-    Value = Sec/60; /* Minutes */
-    Ch = Value/10 + '0';
-    LcdChr( Position + X_POSITION*3 + 1 + ((InvPos==2)?INVERSE:0), &Ch );
-    Ch = Value%10 + '0';
-    LcdChr( Position + X_POSITION*4 + 1 + ((InvPos==3)?INVERSE:0), &Ch );
-    return;
+    LcdChr( Position + X_POSITION*7 + 1, &Ch );
+  }
+  InvPos &= ~0x8000;
+  Value = Sec/(60*60); /* Hour */
+  Ch = Value/10 + '0';
+  LcdChr( Position + 1 + ((InvPos==0)?INVERSE:0), &Ch );
+  Ch = Value%10 + '0';
+  LcdChr( Position + X_POSITION*1 + 1 +((InvPos==1)?INVERSE:0), &Ch );
+  Sec = Sec%(60*60); /* Sec in the hour*/
+  Value = Sec/60; /* Minutes */
+  Ch = Value/10 + '0';
+  LcdChr( Position + X_POSITION*3 + 1 + ((InvPos==2)?INVERSE:0), &Ch );
+  Ch = Value%10 + '0';
+  LcdChr( Position + X_POSITION*4 + 1 + ((InvPos==3)?INVERSE:0), &Ch );
+  return;
 }
 
 
 int SwitchOnTheClock(void)
 {
-    if ( (RCC->BDCR & RCC_BDCR_RTCSEL) != RCC_BDCR_RTCSEL_0  ) /* RTC clock is off */
+  if ( (RCC->BDCR & RCC_BDCR_RTCSEL) != RCC_BDCR_RTCSEL_0  ) /* RTC clock is off */
+  {
+    GPIOC->CRH |= GPIO_CRH_MODE14_1 |GPIO_CRH_MODE15_1; /* Out 2 MHZ*/
+    GPIOC->CRH &= ~(GPIO_CRH_CNF14|GPIO_CRH_CNF15); /* PUSH pull */
+    Delay(30);
+    GPIOA->BSRR =  GPIO_BSRR_BS14; /* Boot the cristal */
+    Delay(30);
+    GPIOC->CRH &= ~(GPIO_CRH_MODE14_1|GPIO_CRH_MODE15_1); /* Analog IN */
+    RCC->BDCR |= RCC_BDCR_LSEON;
     {
-        GPIOC->CRH |= GPIO_CRH_MODE14_1 |GPIO_CRH_MODE15_1; /* Out 2 MHZ*/
-        GPIOC->CRH &= ~(GPIO_CRH_CNF14|GPIO_CRH_CNF15); /* PUSH pull */
-        Delay(30);
-        GPIOA->BSRR =  GPIO_BSRR_BS14; /* Boot the cristal */
-        Delay(30);
-        GPIOC->CRH &= ~(GPIO_CRH_MODE14_1|GPIO_CRH_MODE15_1); /* Analog IN */
-        RCC->BDCR |= RCC_BDCR_LSEON;
-        {
-            __IO int i=1000000;
-            while ( i != 0 && (RCC->BDCR & RCC_BDCR_LSERDY) == 0)
-                i--;
-        }
-        if ( (RCC->BDCR & RCC_BDCR_LSERDY) == 0 )
-            return -1;
-
-        RCC->BDCR |= RCC_BDCR_RTCSEL_0; /* RTC source is LSE */
-        RCC->BDCR |= RCC_BDCR_RTCEN; /* Enable RTC */
-
-        BKP->RTCCR = 63;
-
-        RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
-        RTC->PRLL = CLOCK_DIV; /* Freq is some higher that 1 hz */
-        BKP->DR7  = CLOCK_DIV;
-        RTC->CRL &= ~RTC_CRL_CNF; /* Write value  */
-        while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
-            ;
+      __IO int i=1000000;
+      while ( i != 0 && (RCC->BDCR & RCC_BDCR_LSERDY) == 0)
+        i--;
     }
+    if ( (RCC->BDCR & RCC_BDCR_LSERDY) == 0 )
+      return -1;
+  
+    RCC->BDCR |= RCC_BDCR_RTCSEL_0; /* RTC source is LSE */
+    RCC->BDCR |= RCC_BDCR_RTCEN; /* Enable RTC */
 
-    RTC->CRL &= ~RTC_CRL_RSF; /* This bit will be set at syncronisation time */
-    while ( (RTC->CRL & RTC_CRL_RSF) == 0)
-        ; /* Wait syncronisation */
-    while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
-        ;
+    BKP->RTCCR = 63; 
 
-    RTC->CRH |= RTC_CRH_SECIE; /* Enable second interrupt */
+    RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
+    RTC->PRLL = CLOCK_DIV; /* Freq is some higher that 1 hz */
+    BKP->DR7  = CLOCK_DIV;
+    RTC->CRL &= ~RTC_CRL_CNF; /* Write value  */
     while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
-        ;
-    NVIC->ISER[(RTC_IRQn >> 0x05)] =	(u32)0x01 << (RTC_IRQn & (u8)0x1F); /* Enable RTC second interrupt */
+      ;
+  }
+
+  RTC->CRL &= ~RTC_CRL_RSF; /* This bit will be set at syncronisation time */
+  while ( (RTC->CRL & RTC_CRL_RSF) == 0)
+    ; /* Wait syncronisation */
+  while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
+    ;
+
+  RTC->CRH |= RTC_CRH_SECIE; /* Enable second interrupt */
+  while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
+    ;
+  NVIC->ISER[(RTC_IRQn >> 0x05)] =	(u32)0x01 << (RTC_IRQn & (u8)0x1F); /* Enable RTC second interrupt */
 
-    return 0;
+  return 0;
 }
 
 void RTC_IRQHandler(void)
 {
-    if ((EventQueue & ~KEY_ADC) == 0 ) /* ADC has lower priority */
-        EventQueue = EV_KEY_PRESSED | KEY_CLOCK;
-    RTC->CRL &= ~RTC_CRL_SECF;
-    if (TimerValue != 0)
+  if ((EventQueue & ~KEY_ADC) == 0 ) /* ADC has lower priority */
+    EventQueue = EV_KEY_PRESSED | KEY_CLOCK;
+  RTC->CRL &= ~RTC_CRL_SECF;
+  if (TimerValue != 0)
+  {
+    if (RemainTimerValue > 1)
     {
-        if (RemainTimerValue > 1)
-        {
-            if ( RemainTimerValue != 0xFFFF )
-                RemainTimerValue--;
-        }
-        else
-        {
-            RemainTimerValue = 0xFFFF;
-            DAC_V = 0; /* Off the output */
-            DAC_I = 0;
-        }
+      if ( RemainTimerValue != 0xFFFF )
+        RemainTimerValue--;     
+    }
+    else
+    {
+      RemainTimerValue = 0xFFFF;
+      DAC_V = 0; /* Off the output */
+      DAC_I = 0;
     }
+  }
 }
 
 static int32_t NewTime;
@@ -113,137 +113,137 @@ static uint8_t Change;
 static int Inc;
 void SetupTheClock(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        MenuPos = 0;
-        Change = 0;
-        Inc = 1;
-        NewTime = (((RTC->CNTH<<16) + RTC->CNTL)%(24*60*60) + (24*60*60));
-        NewTime = NewTime / 60*60; /* Round to 1 minutes */
-        goto redraw;
-    }
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = 0;
+    Change = 0;
+    Inc = 1;
+    NewTime = (((RTC->CNTH<<16) + RTC->CNTL)%(24*60*60) + (24*60*60));
+    NewTime = NewTime / 60*60; /* Round to 1 minutes */
+    goto redraw;
+  }
 
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
+       case KEY_UP:
+        if ( Change == 0 )
         {
-        case KEY_UP:
-            if ( Change == 0 )
-            {
-                if ( MenuPos == 6 )
-                    MenuPos = 0;
-                else
-                    MenuPos = MenuPos + 1;
-                goto redraw;
-            }
-            else
-                Inc = 1;
-            goto ChangeTime;
-        case KEY_DOWN:
-            if ( Change == 0 )
-            {
-                if ( MenuPos == 0 )
-                    MenuPos = 6;
-                else
-                    MenuPos = MenuPos - 1;
-                goto redraw;
-            }
-            else
-                Inc = -1;
-            goto ChangeTime;
-        case KEY_ENTER:
-            switch(MenuPos)
-            {
-            case 0:
-            case 1:
-            case 2:
-            case 3:
-                Change = !Change;
-                return;
-            case 4:
-                BKP->DR5 = (NewTime >> 16); 	/* 05.10.11 Clear calibration time to prevent bad next calibration. */
-                BKP->DR6 = NewTime;
-
-                /* Restore default clock speed 18.10.11 */
-                BKP->RTCCR = 63;
-                BKP->DR7  = CLOCK_DIV;
+          if ( MenuPos == 6 )
+            MenuPos = 0;
+          else
+            MenuPos = MenuPos + 1;
+          goto redraw;
+        }
+        else
+          Inc = 1;
+      goto ChangeTime;
+      case KEY_DOWN:
+        if ( Change == 0 )
+        {
+          if ( MenuPos == 0 )
+            MenuPos = 6;
+          else
+            MenuPos = MenuPos - 1;
+          goto redraw;
+        }
+        else
+          Inc = -1;
+        goto ChangeTime;
+      case KEY_ENTER:
+        switch(MenuPos)
+        {
+          case 0:
+          case 1:
+          case 2:
+          case 3:
+            Change = !Change;
+            return;
+          case 4:
+            BKP->DR5 = (NewTime >> 16); 	/* 05.10.11 Clear calibration time to prevent bad next calibration. */
+    		    BKP->DR6 = NewTime; 
+            
+            /* Restore default clock speed 18.10.11 */
+            BKP->RTCCR = 63; 
+            BKP->DR7  = CLOCK_DIV;
 
-                RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
-                RTC->PRLL = CLOCK_DIV; /* Freq is some higher that 1 hz */
-                while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
-                    ;
-                goto SaveTime;
-            case 5:
-                CurrentFunc(StartFunction);
-                return;
-            case 6: /* Calibration */
-                if (BKP->DR5 != 0 || BKP->DR6 != 0 ) /* Trim the clock */
-                {   /* Trim the clock speed */
-                    int Delta;
-                    int Time;
-                    Delta = NewTime%(24*60*60) - (((RTC->CNTH<<16) + RTC->CNTL)%(24*60*60)); /* New time - old time. Positive is slow */
-                    Time  = ((RTC->CNTH<<16) + RTC->CNTL) - ((BKP->DR5<<16) +  BKP->DR6); /* Old time - last trim date */
-                    if ( Delta > (12*60*60) )
-                        Delta = Delta - (24*60*60);
-                    if ( Delta < -(12*60*60) )
-                        Delta = Delta + (24*60*60);
-                    if (Time > (24*60*60 - 60*10) ) /* Time eplased is More then 1 day without 10 minutes */
-                    {
+            RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
+            RTC->PRLL = CLOCK_DIV; /* Freq is some higher that 1 hz */
+            while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
+              ;
+            goto SaveTime;
+          case 5:
+            CurrentFunc(StartFunction);
+            return;
+          case 6: /* Calibration */
+            if (BKP->DR5 != 0 || BKP->DR6 != 0 ) /* Trim the clock */
+            {  /* Trim the clock speed */
+              int Delta;
+              int Time;
+              Delta = NewTime%(24*60*60) - (((RTC->CNTH<<16) + RTC->CNTL)%(24*60*60)); /* New time - old time. Positive is slow */
+              Time  = ((RTC->CNTH<<16) + RTC->CNTL) - ((BKP->DR5<<16) +  BKP->DR6); /* Old time - last trim date */
+              if ( Delta > (12*60*60) )
+                Delta = Delta - (24*60*60);
+              if ( Delta < -(12*60*60) )
+                Delta = Delta + (24*60*60);
+              if (Time > (24*60*60 - 60*10) ) /* Time eplased is More then 1 day without 10 minutes */
+              {
 #if !defined(__GNUC__)
-                        Delta = (Delta * ((int64_t)1024*1024))/Time; /* Delta in PPM */
+                Delta = (Delta * ((int64_t)1024*1024))/Time; /* Delta in PPM */
 #else
-                        /* Int64 operationd adds about 9k of code!!! */
-                        while ( Delta > 2047 || Delta < -2047 )
-                        {
-                            Delta = Delta/2;
-                            Time  = Time/2;
-                        }
-                        Delta = (Delta * (1024*1024))/Time;
+                /* Int64 operationd adds about 9k of code!!! */		
+                while ( Delta > 2047 || Delta < -2047 )
+                {
+                  Delta = Delta/2;
+                  Time  = Time/2;
+                }
+                Delta = (Delta * (1024*1024))/Time;
 #endif
-                        Delta = (BKP->RTCCR & BKP_RTCCR_CAL) - Delta;
-                        if (Delta < 0 || Delta > 127 )
-                        {
-                            BKP->DR7  = BKP->DR7 + Delta/32 - 2; /* Save new prescaler value */
-                            RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
-                            RTC->PRLL = BKP->DR7; /* Set new prescaler value. PRLL is read only */
-                            RTC->CRL &= ~RTC_CRL_CNF; /* Write value  */
-                            while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
-                                ;
-                            Delta = 64 + (Delta - Delta/32*32);
-                        }
-                        BKP->RTCCR = Delta; /* Write correction */
-                    }
+                Delta = (BKP->RTCCR & BKP_RTCCR_CAL) - Delta;
+                if (Delta < 0 || Delta > 127 )
+                {
+                  BKP->DR7  = BKP->DR7 + Delta/32 - 2; /* Save new prescaler value */
+                  RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
+                  RTC->PRLL = BKP->DR7; /* Set new prescaler value. PRLL is read only */
+                    RTC->CRL &= ~RTC_CRL_CNF; /* Write value  */
+                    while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
+                        ;
+                  Delta = 64 + (Delta - Delta/32*32);
                 }
-                BKP->DR5 = (NewTime >> 16);
-                BKP->DR6 = NewTime;
-                goto SaveTime;
+                BKP->RTCCR = Delta; /* Write correction */
+              }
             }
+            BKP->DR5 = (NewTime >> 16); 
+            BKP->DR6 = NewTime;
+            goto SaveTime;
         }
     }
-    return;
+  }
+  return;
 
 SaveTime:
     RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
     RTC->CNTH = NewTime>>16;
     RTC->CRL &= ~RTC_CRL_CNF; /* Write value  */
     while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
-        ;
+      ;
     RTC->CRL |= RTC_CRL_CNF; /* Enter config mode */
     RTC->CNTL = NewTime&0xFFFF;
     RTC->CRL &= ~RTC_CRL_CNF; /* Write value  */
     while ( (RTC->CRL & RTC_CRL_RTOFF) == 0 ) /* Wait to ready for writing */
-        ;
+      ;
     CurrentFunc(StartFunction);
     return;
 
 ChangeTime:
-    switch (MenuPos)
-    {
-    case 0:
+  switch (MenuPos)
+  {
+    case 0: 
         Inc = Inc * 10 * 60 * 60;  /* +-10 hours */
         break;
-    case 1:
+    case 1: 
         Inc = Inc * 60 * 60;  /* +-1 hours */
         break;
     case 2:
@@ -252,18 +252,18 @@ ChangeTime:
     case 3:
         Inc = Inc * 60;  /* +-1 min */
         break;
-    }
-    if ( NewTime + Inc < 24*60*60 )
-        return;
-    if ( NewTime + Inc >= ( 24*60*60*2 - 1 ) ) /* 2 day without 1 sec */
-        return;
-    NewTime += Inc;
+  }
+  if ( NewTime + Inc < 24*60*60 )
+    return;
+  if ( NewTime + Inc >= ( 24*60*60*2 - 1 ) ) /* 2 day without 1 sec */
+    return;
+  NewTime += Inc;
 
 redraw:
-    DisplayClock(NewTime, MenuPos, Y_POSITION*3+X_POSITION*9);
-    LcdChr (Y_POSITION*4+X_POSITION*0+14+(4==MenuPos)*INVERSE, "Set time" );
-    LcdChr (Y_POSITION*5+X_POSITION*0+14+(5==MenuPos)*INVERSE, "Return" );
-    LcdChr (Y_POSITION*1+X_POSITION*0+14+(6==MenuPos)*INVERSE, "Calibration" );
+  DisplayClock(NewTime, MenuPos, Y_POSITION*3+X_POSITION*9);
+  LcdChr (Y_POSITION*4+X_POSITION*0+14+(4==MenuPos)*INVERSE, "Set time" );
+  LcdChr (Y_POSITION*5+X_POSITION*0+14+(5==MenuPos)*INVERSE, "Return" );
+  LcdChr (Y_POSITION*1+X_POSITION*0+14+(6==MenuPos)*INVERSE, "Calibration" );
 }
 
 
@@ -271,28 +271,29 @@ uint16_t TimerValue = 0;
 uint16_t RemainTimerValue = 0;
 void TimerSetup(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        EncCounter = TimerValue;
-        EncStepMax = 1800;
-        EncMax = 18 * 3600 + 1;
-    }
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    EncCounter = TimerValue;
+    EncStepMax = 1800;
+    EncMax = 18 * 3600 + 1;
+  }
 
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    if ( (Event & KEY_MASK) == KEY_ENTER )
     {
-        if ( (Event & KEY_MASK) == KEY_ENTER )
-        {
-            TimerValue = EncCounter;
-            EncStepMax = ENC_STEP_MAX_DEFAULT;
-            EncMax = ENC_MAX_DEFAULT;
-            CurrentFunc(StartFunction);
-            return;
-        }
+      TimerValue = EncCounter;
+      EncStepMax = ENC_STEP_MAX_DEFAULT;
+      EncMax = ENC_MAX_DEFAULT;
+      CurrentFunc(StartFunction);
+      return;
     }
+  }
 
-    LcdChr(Y_POSITION*1+X_POSITION*0+14, "Timer value" );
-    DisplayClock(EncCounter, 10+0x8000, Y_POSITION*3+X_POSITION*6);
+  LcdChr(Y_POSITION*1+X_POSITION*0+14, "Timer value" );
+  DisplayClock(EncCounter, 10+0x8000, Y_POSITION*3+X_POSITION*6);
 }
 
+
 #endif

+ 130 - 129
src/config.c

@@ -16,177 +16,177 @@ const Settings_t*  NextSettings;
 
 static uint32_t Crc(const void* Pointer, int Len)
 {
-    int i;
-    const uint8_t* Data = (const uint8_t*)Pointer;
-    uint32_t Ret = 0x55;
+  int i;
+  const uint8_t* Data = (const uint8_t*)Pointer;
+  uint32_t Ret = 0x55;
 
 #if 1
-    for (i = 0; i<Len; i++)
-    {
-        Ret = Ret ^ (uint32_t)(Data[i]);
-    }
+  for (i = 0; i<Len; i++)
+  {
+    Ret = Ret ^ (uint32_t)(Data[i]);
+  }
 #else
-    CRC->CR |= CRC_CR_RESET;
-    CRC->IDR = Ret;
-    for (i = 0; i<Len; i++)
-    {
-        CRC->IDR = Data[i];
-        Ret = CRC->IDR;
-    }
+  CRC->CR |= CRC_CR_RESET;
+  CRC->IDR = Ret;
+  for (i = 0; i<Len; i++)
+  {
+    CRC->IDR = Data[i];
+    Ret = CRC->IDR;
+  }
 #endif
 
-    return Ret;
+  return Ret;
 }
 
 
 void WriteFlash(void* Src, void* Dst, int Len)
 {
-    uint16_t* SrcW = (uint16_t*)Src;
-    volatile uint16_t* DstW = (uint16_t*)Dst;
-
-    FLASH->KEYR = FLASH_KEY1;
-    FLASH->KEYR = FLASH_KEY2;
-
-    FLASH->CR |= FLASH_CR_PG; /* Programm the flash */
-    while (Len)
+  uint16_t* SrcW = (uint16_t*)Src;
+  volatile uint16_t* DstW = (uint16_t*)Dst;
+
+  FLASH->KEYR = FLASH_KEY1;
+  FLASH->KEYR = FLASH_KEY2;
+
+  FLASH->CR |= FLASH_CR_PG; /* Programm the flash */
+  while (Len)
+  {
+    *DstW = *SrcW;
+    while ((FLASH->SR & FLASH_SR_BSY) != 0 )
+      ;
+    if (*DstW != *SrcW )
     {
-        *DstW = *SrcW;
-        while ((FLASH->SR & FLASH_SR_BSY) != 0 )
-            ;
-        if (*DstW != *SrcW )
-        {
-            break;
-        }
-        DstW++;
-        SrcW++;
-        Len = Len - sizeof(uint16_t);
+      break;
     }
+    DstW++;
+    SrcW++;
+    Len = Len - sizeof(uint16_t);
+  }
 
-    FLASH->CR &= ~FLASH_CR_PG; /* Reset the flag back !!!! */
-    FLASH->CR |= FLASH_CR_LOCK; /* Lock the flash back */
+  FLASH->CR &= ~FLASH_CR_PG; /* Reset the flag back !!!! */
+  FLASH->CR |= FLASH_CR_LOCK; /* Lock the flash back */
 }
 void ErasePage(void* Addr)
 {
-    FLASH->KEYR = FLASH_KEY1;
-    FLASH->KEYR = FLASH_KEY2;
-
-    FLASH->CR |= FLASH_CR_PER; /* Page erase */
-    FLASH->AR = (uint32_t)Addr;
-    FLASH->CR|= FLASH_CR_STRT; /* Start erase */
-    while ((FLASH->SR & FLASH_SR_BSY) != 0 ) /* Wait end of eraze */
-        ;
-    FLASH->CR &= ~FLASH_CR_PER; /* Page erase end */
+  FLASH->KEYR = FLASH_KEY1;
+  FLASH->KEYR = FLASH_KEY2;
+
+  FLASH->CR |= FLASH_CR_PER; /* Page erase */
+  FLASH->AR = (uint32_t)Addr; 
+  FLASH->CR|= FLASH_CR_STRT; /* Start erase */
+  while ((FLASH->SR & FLASH_SR_BSY) != 0 ) /* Wait end of eraze */
+    ;
+  FLASH->CR &= ~FLASH_CR_PER; /* Page erase end */
 }
 void SaveConfig(void)
 {
-    const SavedDomain_t* ValidDomain;
+  const SavedDomain_t* ValidDomain;
 
-    CurrentConfig.Crc = Crc(&CurrentConfig, sizeof(Config_t) - sizeof(uint32_t));
+  CurrentConfig.Crc = Crc(&CurrentConfig, sizeof(Config_t) - sizeof(uint32_t));
 
-    ValidDomain = SavedDomain;
-    /* Clear 2 page */
-    ErasePage((void*)SavedDomain);
-    ErasePage((void*)(SavedDomain+1));
+  ValidDomain = SavedDomain;
+  /* Clear 2 page */
+  ErasePage((void*)SavedDomain); 
+  ErasePage((void*)(SavedDomain+1)); 
 
-    /* Save header and first settings */
-    WriteFlash(&CurrentConfig, (void*)&ValidDomain->Config, sizeof(Config_t));
+  /* Save header and first settings */
+  WriteFlash(&CurrentConfig, (void*)&ValidDomain->Config, sizeof(Config_t));
 
-    NextSettings = &ValidDomain->Settings[0];
-    SaveSettings(1);
-    NextSettings = &ValidDomain->Settings[1]; /* Prepare pointer to save at power fault */
+  NextSettings = &ValidDomain->Settings[0];
+  SaveSettings(1);
+  NextSettings = &ValidDomain->Settings[1]; /* Prepare pointer to save at power fault */
 }
 
 void SaveSettings(uint16_t AndFlash)
 {
-    if ( (DAC->DOR1 != 0 &&  DAC->DOR2 != 0) ) /* Is the out ON */
-    {
-        CurrentSettings.VoltageDAC = DAC->DOR1; /* Restore real current value */
-        CurrentSettings.CurrentDAC = DAC->DOR2;
-    }
-    /* Else - save preset values */
-
-    CurrentSettings.CurrentDAC |= Flags; /* Adding flags to save */
-    CurrentSettings.VoltageDAC |= (Contrast<<12);
-    if (Flags & BACKUP_SAVE_FLAG)
-    {
-        BKP->DR10 = CurrentSettings.VoltageDAC;
-        BKP->DR9  = CurrentSettings.CurrentDAC;
-        if (AndFlash == 0 )
-            goto Restore;
-    }
-    if ( NextSettings  == NULL )
-        return;
-    WriteFlash(&CurrentSettings, (void*)NextSettings, sizeof(CurrentSettings));
+  if ( (DAC->DOR1 != 0 &&  DAC->DOR2 != 0) ) /* Is the out ON */
+  {
+    CurrentSettings.VoltageDAC = DAC->DOR1; /* Restore real current value */
+    CurrentSettings.CurrentDAC = DAC->DOR2;
+  }
+  /* Else - save preset values */
+
+  CurrentSettings.CurrentDAC |= Flags; /* Adding flags to save */
+  CurrentSettings.VoltageDAC |= (Contrast<<12);
+  if (Flags & BACKUP_SAVE_FLAG)
+  {
+    BKP->DR10 = CurrentSettings.VoltageDAC;
+    BKP->DR9  = CurrentSettings.CurrentDAC;
+    if (AndFlash == 0 )
+      goto Restore;
+  }
+  if ( NextSettings  == NULL )
+    return;
+  WriteFlash(&CurrentSettings, (void*)NextSettings, sizeof(CurrentSettings));
 
 Restore:
-    CurrentSettings.CurrentDAC &= 0x0FFF; /* Remove flags back */
-    CurrentSettings.VoltageDAC &= 0x0FFF;
+  CurrentSettings.CurrentDAC &= 0x0FFF; /* Remove flags back */
+  CurrentSettings.VoltageDAC &= 0x0FFF;
 }
 
 
 int RestoreConfig(void) /* Return !0 if failed */
 {
-    const Settings_t* CurSettings;
-    const Settings_t* PrevSettings;
-    const SavedDomain_t* ValidDomain;
-
-    ValidDomain = SavedDomain;
+  const Settings_t* CurSettings;
+  const Settings_t* PrevSettings;
+  const SavedDomain_t* ValidDomain;
+ 
+  ValidDomain = SavedDomain;
+  if ( Crc( &ValidDomain->Config, sizeof(Config_t) - sizeof(uint32_t) ) != ValidDomain->Config.Crc )
+  {
+    ValidDomain = SavedDomain + 1;
     if ( Crc( &ValidDomain->Config, sizeof(Config_t) - sizeof(uint32_t) ) != ValidDomain->Config.Crc )
     {
-        ValidDomain = SavedDomain + 1;
-        if ( Crc( &ValidDomain->Config, sizeof(Config_t) - sizeof(uint32_t) ) != ValidDomain->Config.Crc )
-        {
-            return -1; /* Both blocks are invalid */
-        }
+      return -1; /* Both blocks are invalid */
     }
-    memcpy((char*)&CurrentConfig, (char*)&ValidDomain->Config, sizeof(CurrentConfig));
+  }
+  memcpy((char*)&CurrentConfig, (char*)&ValidDomain->Config, sizeof(CurrentConfig));
 
-    PrevSettings = ValidDomain->Settings;
+  PrevSettings = ValidDomain->Settings;
 
-    for ( CurSettings = PrevSettings; CurSettings < ValidDomain->Settings + SAVED_SETTINGS_COUNT; CurSettings++)
-    {
-        if ( CurSettings->VoltageDAC == 0xFFFF && CurSettings->CurrentDAC == 0xFFFF )
-            break;
-        PrevSettings = CurSettings;
-    }
+  for ( CurSettings = PrevSettings; CurSettings < ValidDomain->Settings + SAVED_SETTINGS_COUNT; CurSettings++)
+  {
+    if ( CurSettings->VoltageDAC == 0xFFFF && CurSettings->CurrentDAC == 0xFFFF )
+	  break;
+    PrevSettings = CurSettings;
+  }
 
-    memcpy(&CurrentSettings, PrevSettings, sizeof(CurrentSettings));
+  memcpy(&CurrentSettings, PrevSettings, sizeof(CurrentSettings));
 #if 0
-    Flags = CurrentSettings.CurrentDAC & 0xF000;
-    CurrentSettings.CurrentDAC &= 0x0FFF;
-    Contrast = CurrentSettings.VoltageDAC>>12;
-    CurrentSettings.VoltageDAC &= 0x0FFF;
+  Flags = CurrentSettings.CurrentDAC & 0xF000;
+  CurrentSettings.CurrentDAC &= 0x0FFF;
+  Contrast = CurrentSettings.VoltageDAC>>12;
+  CurrentSettings.VoltageDAC &= 0x0FFF;
 #endif
 
-    NextSettings = CurSettings;
-    if ( CurSettings == ValidDomain->Settings + SAVED_SETTINGS_COUNT ) // All space is full
-    {
-        const SavedDomain_t* NextDomain = SavedDomain;
-
-        if ( ValidDomain == SavedDomain )
-            NextDomain = SavedDomain + 1;
-
-        WriteFlash((void*)&ValidDomain->Config, (void*)&NextDomain->Config, sizeof(Config_t));
-        WriteFlash((void*)CurSettings, (void*)&NextDomain->Settings[0], sizeof(Settings_t));
-        NextSettings = &NextDomain->Settings[1];
-        ErasePage( (void*) ValidDomain );
-        ValidDomain = NextDomain;
-    }
-
-    if ( BKP->DR9 & BACKUP_SAVE_FLAG )
-    {
-        /* restore from backup domain */
-        CurrentSettings.VoltageDAC = BKP->DR10;
-        CurrentSettings.CurrentDAC = BKP->DR9;
-    }
-
-    Flags = CurrentSettings.CurrentDAC&0xF000;
-    CurrentSettings.CurrentDAC &= 0x0FFF;
-    Contrast = CurrentSettings.VoltageDAC>>12;
-    CurrentSettings.VoltageDAC &= 0x0FFF;
-    LcdContrast ( Contrast*3+42 );
-
-    return 0;
+  NextSettings = CurSettings;
+  if ( CurSettings == ValidDomain->Settings + SAVED_SETTINGS_COUNT ) // All space is full
+  {
+    const SavedDomain_t* NextDomain = SavedDomain;
+
+    if ( ValidDomain == SavedDomain )
+      NextDomain = SavedDomain + 1;
+
+    WriteFlash((void*)&ValidDomain->Config, (void*)&NextDomain->Config, sizeof(Config_t));
+    WriteFlash((void*)CurSettings, (void*)&NextDomain->Settings[0], sizeof(Settings_t));
+    NextSettings = &NextDomain->Settings[1];
+    ErasePage( (void*) ValidDomain );
+    ValidDomain = NextDomain;
+  }
+  
+  if ( BKP->DR9 & BACKUP_SAVE_FLAG )
+  {
+    /* restore from backup domain */
+    CurrentSettings.VoltageDAC = BKP->DR10;
+    CurrentSettings.CurrentDAC = BKP->DR9;
+  }
+
+  Flags = CurrentSettings.CurrentDAC&0xF000;
+  CurrentSettings.CurrentDAC &= 0x0FFF;
+  Contrast = CurrentSettings.VoltageDAC>>12;
+  CurrentSettings.VoltageDAC &= 0x0FFF;
+  LcdContrast ( Contrast*3+42 );
+
+  return 0;
 }
 
 #else  /* REAL_FLASH */
@@ -196,7 +196,7 @@ void SaveConfig(void)
 
 int RestoreConfig(void)
 {
-    return -1;
+  return -1;
 }
 
 void SaveSettings(void)
@@ -204,3 +204,4 @@ void SaveSettings(void)
 }
 
 #endif /* RAL_FLASH */
+

+ 419 - 418
src/event.c

@@ -14,120 +14,120 @@ static uint8_t  RealizeCounter; // Realize delay counter
 static uint16_t PrevCounter;
 void EventInit(void)
 {
-    NVIC->ISER[(TIM3_IRQn >> 0x05)] =	(u32)0x01 << (TIM3_IRQn & (u8)0x1F); /* Enable Timer interrupt */
-    NVIC->ISER[(TIM2_IRQn >> 0x05)] =	(u32)0x01 << (TIM2_IRQn & (u8)0x1F); /* Enable Timer interrupt */
-
-    TIM3->DIER |= TIM_DIER_UIE; /* enable update IRQ */
-    TIM3->ARR = 10000; /* 2MHz / 10000 = 200Hz  - 5mSec */
-    TIM3->CR1 |= TIM_CR1_CEN;    /* start TIM7 */
+  NVIC->ISER[(TIM3_IRQn >> 0x05)] =	(u32)0x01 << (TIM3_IRQn & (u8)0x1F); /* Enable Timer interrupt */
+  NVIC->ISER[(TIM2_IRQn >> 0x05)] =	(u32)0x01 << (TIM2_IRQn & (u8)0x1F); /* Enable Timer interrupt */
 
+  TIM3->DIER |= TIM_DIER_UIE; /* enable update IRQ */
+  TIM3->ARR = 10000; /* 2MHz / 10000 = 200Hz  - 5mSec */
+  TIM3->CR1 |= TIM_CR1_CEN;    /* start TIM7 */
+  
 //  TIM2->CNT = 0x8000;
-    TIM2->ARR = 0xFFFF;
-    TIM2->SMCR |= (TIM_SMCR_SMS_0|TIM_SMCR_SMS_1); /* encoder mode 2 */
+  TIM2->ARR = 0xFFFF;
+  TIM2->SMCR |= (TIM_SMCR_SMS_0|TIM_SMCR_SMS_1); /* encoder mode 2 */
 //  TIM2->CCMR1 |= TIM_CCMR1_CC1S_0|TIM_CCMR1_IC1F|TIM_CCMR1_CC2S_0|TIM_CCMR1_IC2F;  /* TI1, TI2 - inputs with max filter */
 //  TIM2->CCER |= TIM_CCER_CC1E|TIM_CCER_CC2E; /* Enable inputs */
-    TIM2->SR = 0;
-    TIM2->DIER |= TIM_DIER_CC2IE|TIM_DIER_CC1IE; /* Interrupt by trigger */
-    TIM2->CCR1 = (uint16_t)- 4;
-    TIM2->CCR2 = 0 + 4;
-    PrevCounter = 0;
-    TIM2->CR1 |= TIM_CR1_CEN;
+  TIM2->SR = 0;
+  TIM2->DIER |= TIM_DIER_CC2IE|TIM_DIER_CC1IE; /* Interrupt by trigger */
+  TIM2->CCR1 = (uint16_t)- 4;
+  TIM2->CCR2 = 0 + 4;
+  PrevCounter = 0;
+  TIM2->CR1 |= TIM_CR1_CEN;
 }
 
 void EventKeys(void)
 {
-    uint16_t Key;
-
-    if ( (EventQueue & KEY_MASK_SYS) != 0 ) /* Previous event hasn't been handled. The key hase highiest  priority */
-        return;
-    if (CurrentFunction != PrevFunc ) /* The function was changed */
-        return;
-    Key = (~KEYPORT) & KEY_MASK_SYS; /* Read the port */
+  uint16_t Key;
+  
+  if ( (EventQueue & KEY_MASK_SYS) != 0 ) /* Previous event hasn't been handled. The key hase highiest  priority */
+    return;
+  if (CurrentFunction != PrevFunc ) /* The function was changed */
+    return;
+  Key = (~KEYPORT) & KEY_MASK_SYS; /* Read the port */
 
-    if ( Key == 0 ) // no any key pressed
+  if ( Key == 0 ) // no any key pressed
+  {
+    if ( PrevKey == 0 ) // no any key was pressed before
     {
-        if ( PrevKey == 0 ) // no any key was pressed before
-        {
-            EvCounter = 0;
-            return;
-        }
-        if ( EvCounter > KEY_PRESSED_VALUE )
-        {
-            RealizeCounter++; // increase timer counter
-            if ( RealizeCounter > KEY_REALIZE_VALUE ) // expired realise timeout
-            {
-                if ( EvCounter != 0xFF ) /* There is no switch to new function. New function should not get previos function event */
-                {
-                    EventQueue = EV_KEY_REALIZED | PrevKey; /* Realized event - the last event */
-                }
-                EvCounter = 0; // Reset interval timer value
-                PrevKey = 0;   // Reset key pressed value
-                RealizeCounter = 0;  // Reset realise counter
-            }
-        }
-        else
-        {
-            EvCounter = 0; // Reset interval timer value
-            PrevKey = 0;   // Reset key pressed value
-            RealizeCounter = 0;  // Reset realise counter
-        }
+      EvCounter = 0;
+      return;
     }
-    else // Some keys are pressed
+    if ( EvCounter > KEY_PRESSED_VALUE )
     {
-        RealizeCounter = 0; //reset realise delay
-
-        if ( EvCounter == 0xFF ) /* Locked - new function has been set */
-            return;
-
-        if ( Key & (~PrevKey) ) //there are some new keys
-        {
-            PrevKey |= Key;       // adding the new keys
-            if ( EvCounter == 0 )
-            {
-                /* Generate KEY TOUCH event */
-                EventQueue = EV_KEY_TOUCH + PrevKey;
-            }
-            else if ( EvCounter > KEY_LONG_VALUE ) // Delay after first press is not long
-                EventQueue = EV_KEY_LONG | PrevKey; //generate key press event
-        }
-        else // the same keys are pressed
+      RealizeCounter++; // increase timer counter
+      if ( RealizeCounter > KEY_REALIZE_VALUE ) // expired realise timeout
+      {
+        if ( EvCounter != 0xFF ) /* There is no switch to new function. New function should not get previos function event */
         {
-            if ( EvCounter == KEY_PRESSED_VALUE ) // Delay after first press is not long
-                EventQueue = EV_KEY_PRESSED | PrevKey; //generate key press event
-            else if ( EvCounter == KEY_LONG_VALUE )  // Long press timeout has expired
-            {
-                EventQueue = EV_KEY_LONG | PrevKey; // Generate Long press event
-            }
-            else if ( EvCounter == KEY_REPEATE_VALUE ) // After long press the key is stil pressed
-            {
-                EventQueue = EV_KEY_REPEATE | PrevKey; // Generate repeate press event
-                EvCounter = KEY_LONG_VALUE; // Reset time counter for next delay
-            }
-            EvCounter++; // Delay counter increasing
+          EventQueue = EV_KEY_REALIZED | PrevKey; /* Realized event - the last event */
         }
+        EvCounter = 0; // Reset interval timer value
+        PrevKey = 0;   // Reset key pressed value
+        RealizeCounter = 0;  // Reset realise counter
+      }
     }
+    else
+    {
+      EvCounter = 0; // Reset interval timer value
+      PrevKey = 0;   // Reset key pressed value
+      RealizeCounter = 0;  // Reset realise counter
+    }
+  }
+  else // Some keys are pressed
+  {
+    RealizeCounter = 0; //reset realise delay
+   
+    if ( EvCounter == 0xFF ) /* Locked - new function has been set */
+      return; 
+    
+    if ( Key & (~PrevKey) ) //there are some new keys
+    {
+      PrevKey |= Key;       // adding the new keys
+      if ( EvCounter == 0 )
+      {
+      /* Generate KEY TOUCH event */
+        EventQueue = EV_KEY_TOUCH + PrevKey;
+      }
+      else if ( EvCounter > KEY_LONG_VALUE ) // Delay after first press is not long
+        EventQueue = EV_KEY_LONG | PrevKey; //generate key press event
+    }
+    else // the same keys are pressed
+    {
+      if ( EvCounter == KEY_PRESSED_VALUE ) // Delay after first press is not long
+        EventQueue = EV_KEY_PRESSED | PrevKey; //generate key press event
+      else if ( EvCounter == KEY_LONG_VALUE )  // Long press timeout has expired
+      {
+        EventQueue = EV_KEY_LONG | PrevKey; // Generate Long press event
+      }
+      else if ( EvCounter == KEY_REPEATE_VALUE ) // After long press the key is stil pressed
+      {
+        EventQueue = EV_KEY_REPEATE | PrevKey; // Generate repeate press event
+        EvCounter = KEY_LONG_VALUE; // Reset time counter for next delay
+      }
+      EvCounter++; // Delay counter increasing
+    }
+  }
 }
 
 void EventCheck(void)
 {
-    if ( CurrentFunction != PrevFunc ) // Function was changed
-    {
+      if ( CurrentFunction != PrevFunc ) // Function was changed
+      {
         Event = EV_FUNC_FIRST;       // Generate FUNC_FIRST event
         PrevFunc = CurrentFunction;      // Save the function
-        __disable_irq();
+    		__disable_irq();
         if ( EvCounter )             /// Some keys are stil pressed
-            EvCounter = 0xFF;            // Lock any key events until all keys are not realized
-        __enable_irq();
-    }
-    else
-    {
-        __disable_irq();
+          EvCounter = 0xFF;            // Lock any key events until all keys are not realized
+    		__enable_irq();
+      }
+      else
+      {
+    		__disable_irq();
         Event = EventQueue;          // Read event thar was generated in interrupt handlers
         EventQueue = 0;              // The interrupt handlers can write new value
-        __enable_irq();
-    }
+    		__enable_irq();
+      }
 
-    CurrentFunction();      // Run the current menu function
+      CurrentFunction();      // Run the current menu function
 }
 
 static uint16_t TickCounter;
@@ -136,16 +136,16 @@ uint16_t EncCounter;
 
 void TIM3_IRQHandler(void)
 {
-    TIM3->SR = 0; /* Clear pending flag */
-    EventKeys();
-    TickCounter++;
-    if ( TickCounter - PrevTickCounter > 1024 ) /* 10 cek */
-        PrevTickCounter = TickCounter - 512; /* Once in 2.5 second */
-    if ( TickCounter - PrevTickCounter == 2 )
-    {
-        TIM2->SR = 0; /* Clear pending flag */
-        TIM2->DIER |= TIM_DIER_CC2IE; /* Interrupt by trigger */
-    }
+  TIM3->SR = 0; /* Clear pending flag */
+  EventKeys();
+  TickCounter++;
+  if ( TickCounter - PrevTickCounter > 1024 ) /* 10 cek */
+    PrevTickCounter = TickCounter - 512; /* Once in 2.5 second */
+  if ( TickCounter - PrevTickCounter == 2 )
+  {
+	  TIM2->SR = 0; /* Clear pending flag */
+  	TIM2->DIER |= TIM_DIER_CC2IE; /* Interrupt by trigger */
+  }   
 }
 
 uint16_t EncStep;
@@ -154,53 +154,53 @@ uint16_t EncMax = ENC_MAX_DEFAULT;
 
 void TIM2_IRQHandler(void)
 {
-    static uint16_t Delta;
-
-    PrevCounter = TIM2->CNT;
-    TIM2->CCR1 = PrevCounter - 4;
-    TIM2->CCR2 = PrevCounter + 4;
-    TIM2->SR = 0; /* Clear pending flag - only trigger interrupt*/
-
-    Delta = TickCounter - PrevTickCounter;
-    PrevTickCounter = TickCounter;
-
-    Delta = Delta / 2;
-    if (EncStep == 0)
-        EncStep = 1;
-    if ( Delta < 8 && EncStep < EncStepMax) /* The step has to be inreased */
-    {
-        if ( EncStep < 4 )
-            EncStep = EncStep*2;
-        else if (EncStep < 64)
-            EncStep = EncStep + EncStep/4;
-        else
-            EncStep = EncStep + EncStep/8;
-    }
-    if ( Delta > 20 )
-    {
-        if (Delta > 120) /* 0.6 sec */
-            EncStep = 1;
-        EncStep = EncStep - EncStep/2;
-    }
-
-    if (TIM2->CR1 & TIM_CR1_DIR)
-    {
-        if ((int32_t)EncCounter - EncStep < 0 )
-            EncCounter = 0;
-        else
-            EncCounter -= EncStep;
-        if ( (EventQueue & KEY_MASK_SYS) == 0) /* Medium priority */
-            EventQueue = EV_KEY_PRESSED|KEY2;
-    }
+  static uint16_t Delta;
+
+  PrevCounter = TIM2->CNT;
+  TIM2->CCR1 = PrevCounter - 4;
+  TIM2->CCR2 = PrevCounter + 4;
+  TIM2->SR = 0; /* Clear pending flag - only trigger interrupt*/
+
+  Delta = TickCounter - PrevTickCounter;
+  PrevTickCounter = TickCounter;
+  
+  Delta = Delta / 2;
+  if (EncStep == 0)
+    EncStep = 1;
+  if ( Delta < 8 && EncStep < EncStepMax) /* The step has to be inreased */
+  {
+    if ( EncStep < 4 )
+      EncStep = EncStep*2;
+    else if (EncStep < 64)
+      EncStep = EncStep + EncStep/4;
     else
-    {
-        if ((uint32_t)EncCounter + EncStep > EncMax )
-            EncCounter = EncMax;
-        else
-            EncCounter += EncStep;
-        if ( (EventQueue & KEY_MASK_SYS) == 0) /* Medium priority */
-            EventQueue = EV_KEY_PRESSED|KEY3;
-    }
+      EncStep = EncStep + EncStep/8;
+  }
+  if ( Delta > 20 )
+  {
+    if (Delta > 120) /* 0.6 sec */
+      EncStep = 1;
+    EncStep = EncStep - EncStep/2;
+  }
+
+  if (TIM2->CR1 & TIM_CR1_DIR)
+  {
+    if ((int32_t)EncCounter - EncStep < 0 )
+      EncCounter = 0;
+    else
+      EncCounter -= EncStep;
+    if ( (EventQueue & KEY_MASK_SYS) == 0) /* Medium priority */
+      EventQueue = EV_KEY_PRESSED|KEY2; 
+  }
+  else
+  {
+    if ((uint32_t)EncCounter + EncStep > EncMax )
+      EncCounter = EncMax;
+    else
+      EncCounter += EncStep;
+    if ( (EventQueue & KEY_MASK_SYS) == 0) /* Medium priority */
+      EventQueue = EV_KEY_PRESSED|KEY3; 
+  }
 }
 
 
@@ -221,98 +221,98 @@ void Contrast(void)
 
 void StartFunction(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        Value = 0;
-        goto redraw;
-    }
-    if ( (Event & KEY2) || (Event & KEY3) )
-    {
-        Value = EncCounter;
-        LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Encoder" );
-        goto redraw;
-    }
-
-    if ( (Event & KEY_MASK) == 0)
-        return;
-
-    if ( ((Event & EV_MASK) == EV_KEY_LONG) )
-    {
-        LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Long key" );
-        goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_TOUCH )
-    {
-        LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Touch key" );
-        goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_REALIZED)
-    {
-        LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Realize key" );
-        goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_DOUBLE)
-    {
-        LcdChr ( Y_POSITION*5+X_POSITION*1+9, "Double key" );
-        goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        LcdChr ( Y_POSITION*5+X_POSITION*1+9, "" );
-        LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Key" );
-        Value = 1;
-        goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_REPEATE )
-    {
-        LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Repeate key" );
-        if ( Value < 9000 )
-            Value++;
-        goto redraw;
-    }
-
+  if (Event == EV_FUNC_FIRST)
+  {
+    Value = 0;
+    goto redraw;
+  }
+  if ( (Event & KEY2) || (Event & KEY3) )
+  {
+    Value = EncCounter;
+    LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Encoder" );
+    goto redraw;
+  }
+
+  if ( (Event & KEY_MASK) == 0)
     return;
 
+  if ( ((Event & EV_MASK) == EV_KEY_LONG) )
+  { 
+    LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Long key" );
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_TOUCH )
+  { 
+    LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Touch key" );
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_REALIZED)
+  { 
+    LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Realize key" );
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_DOUBLE)
+  { 
+    LcdChr ( Y_POSITION*5+X_POSITION*1+9, "Double key" );
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  { 
+    LcdChr ( Y_POSITION*5+X_POSITION*1+9, "" );
+    LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Key" );
+	Value = 1;
+    goto redraw;
+  }
+  
+  if ( (Event & EV_MASK) == EV_KEY_REPEATE )
+  {
+    LcdChr ( Y_POSITION*3+X_POSITION*1+9, "Repeate key" );
+    if ( Value < 9000 )
+   	  Value++;
+	goto redraw;
+  }
+
+  return;
+
 redraw:
-    {
+  {
 #define DIGIT_COUNT 4
 #define FIRST_DIV 1000
-        char Out[DIGIT_COUNT];
-        int Div = FIRST_DIV;
-        char* Pointer = Out;
-        char i = DIGIT_COUNT;
-        char OnFlag = 0;
-        int Data = Value;
-
-        while (i)
-        {
-            char Dig = Data/Div;
-
-            if ( Dig == 0 && OnFlag == 0)
-            {
-                *Pointer = ' '; //First zero digits are not displaed
-            }
-            else
-            {
-                *Pointer = Dig + '0';
-                OnFlag = 1;
-            }
-            Pointer++;
-            i--;
-            if ( i == 1 )
-                OnFlag = 1; /* Zero also should be displayed */
-            Data = Data%Div;
-            Div = Div/10;
-        } //while
-        LcdChr ( Y_POSITION*1+X_POSITION*1+DIGIT_COUNT+BIG_UP, Out );
-        LcdChr ( Y_POSITION*2+X_POSITION*1+DIGIT_COUNT+BIG_DOWN, Out );
-        LcdChr ( Y_POSITION*4+X_POSITION*1+9, "Menu Func" );
-    }
+    char Out[DIGIT_COUNT];
+  	int Div = FIRST_DIV;
+  	char* Pointer = Out;
+  	char i = DIGIT_COUNT;
+  	char OnFlag = 0;
+	int Data = Value;
+
+  	while (i)
+  	{
+     char Dig = Data/Div;
+
+     if ( Dig == 0 && OnFlag == 0)
+     {
+       *Pointer = ' '; //First zero digits are not displaed
+     }
+     else
+     {
+       *Pointer = Dig + '0';
+       OnFlag = 1;
+     }
+     Pointer++;
+     i--;
+	 if ( i == 1 )
+	   OnFlag = 1; /* Zero also should be displayed */
+     Data = Data%Div;
+     Div = Div/10;
+  	} //while
+    LcdChr ( Y_POSITION*1+X_POSITION*1+DIGIT_COUNT+BIG_UP, Out );
+    LcdChr ( Y_POSITION*2+X_POSITION*1+DIGIT_COUNT+BIG_DOWN, Out );
+    LcdChr ( Y_POSITION*4+X_POSITION*1+9, "Menu Func" );
+  }
 }
 #endif /* ENC_DEMO */
 
@@ -328,207 +328,207 @@ void FloatChange(void);
 
 void MainMenu()
 {
-    if ( Event == 0 )
-        return;
+  if ( Event == 0 )
+    return;
 
-    if ( Event == EV_FUNC_FIRST )
-    {
-        MenuCounter = 0;
-        goto RedrawMenu;
-    }
+  if ( Event == EV_FUNC_FIRST )
+  {
+    MenuCounter = 0;
+    goto RedrawMenu;
+  }
 
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if ( MenuCounter == 0 )
+          MenuCounter = 4;
+        else
+          MenuCounter = MenuCounter - 1;
+        break;
+      case KEY_DOWN:
+        if ( MenuCounter == 4 )
+          MenuCounter = 0;
+        else
+          MenuCounter = MenuCounter + 1;
+        break;
+      case KEY_ENTER:
+        switch(MenuCounter)
         {
-        case KEY_UP:
-            if ( MenuCounter == 0 )
-                MenuCounter = 4;
-            else
-                MenuCounter = MenuCounter - 1;
-            break;
-        case KEY_DOWN:
-            if ( MenuCounter == 4 )
-                MenuCounter = 0;
-            else
-                MenuCounter = MenuCounter + 1;
+          case 4:
+            CurrentFunc = Contrast;
             break;
-        case KEY_ENTER:
-            switch(MenuCounter)
-            {
-            case 4:
-                CurrentFunc = Contrast;
-                break;
 #if defined(FLOAT_DEMO)
-            case 2:
-                CurrentFunc = FloatChange;
-                break;
+          case 2:
+            CurrentFunc = FloatChange;
+            break;
 #endif
-            default:
-                CurrentFunc = MenuSelected;
-                return;
-            }
+          default:
+            CurrentFunc = MenuSelected;
+            return;
         }
     }
-    else
-        return;
+  }
+  else
+    return;
 RedrawMenu:
-    LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuCounter)*INVERSE, "Menu1");
-    LcdChr(X_POSITION*0+Y_POSITION*2+14 + (1==MenuCounter)*INVERSE, "Menu2");
+  LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuCounter)*INVERSE, "Menu1");
+  LcdChr(X_POSITION*0+Y_POSITION*2+14 + (1==MenuCounter)*INVERSE, "Menu2");
 #if defined(FLOAT_DEMO)
-    LcdChr(X_POSITION*0+Y_POSITION*3+14 + (2==MenuCounter)*INVERSE, "Float demo");
+  LcdChr(X_POSITION*0+Y_POSITION*3+14 + (2==MenuCounter)*INVERSE, "Float demo");
 #else
-    LcdChr(X_POSITION*0+Y_POSITION*3+14 + (2==MenuCounter)*INVERSE, "Menu3");
-#endif
-    LcdChr(X_POSITION*0+Y_POSITION*4+14 + (3==MenuCounter)*INVERSE, "Menu4");
-    LcdChr(X_POSITION*0+Y_POSITION*5+14 + (4==MenuCounter)*INVERSE, "Contrast");
+  LcdChr(X_POSITION*0+Y_POSITION*3+14 + (2==MenuCounter)*INVERSE, "Menu3");
+#endif  
+  LcdChr(X_POSITION*0+Y_POSITION*4+14 + (3==MenuCounter)*INVERSE, "Menu4");
+  LcdChr(X_POSITION*0+Y_POSITION*5+14 + (4==MenuCounter)*INVERSE, "Contrast");
 }
 
 void MenuSelected(void)
 {
-    if ( (Event&EV_MASK) == EV_FUNC_FIRST)
-    {
-        LcdChr(X_POSITION*0+Y_POSITION*1+14,  "Press key     ");
-        LcdChr(X_POSITION*0+Y_POSITION*2+14,  "ENTER for a   ");
-        LcdChr(X_POSITION*0+Y_POSITION*3+14,  "long time to  ");
-        LcdChr(X_POSITION*0+Y_POSITION*4+14,  "return main   ");
-        LcdChr(X_POSITION*0+Y_POSITION*5+14,  "menu");
-        return;
-    }
-
-    if ( Event == (EV_KEY_LONG + KEY_ENTER) )
-    {   /* Return back */
-        CurrentFunc = MainMenu;
-    }
+  if ( (Event&EV_MASK) == EV_FUNC_FIRST)
+  {
+    LcdChr(X_POSITION*0+Y_POSITION*1+14,  "Press key     ");
+    LcdChr(X_POSITION*0+Y_POSITION*2+14,  "ENTER for a   ");
+    LcdChr(X_POSITION*0+Y_POSITION*3+14,  "long time to  ");
+    LcdChr(X_POSITION*0+Y_POSITION*4+14,  "return main   ");
+    LcdChr(X_POSITION*0+Y_POSITION*5+14,  "menu");
+    return;
+  }
+  
+  if ( Event == (EV_KEY_LONG + KEY_ENTER) )
+  { /* Return back */
+    CurrentFunc = MainMenu;
+  } 
 }
 
 #if defined(FLOAT_DEMO)
 void FloatChange(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        EncCounter = 2000;
-        LcdClear(); /* Clear screen */
-        goto redraw;
-    }
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  if (Event == EV_FUNC_FIRST)
+  {
+    EncCounter = 2000;
+    LcdClear(); /* Clear screen */
+    goto redraw;
+  }
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_ENTER:
-            CurrentFunc = MainMenu;
-            return;
-        }
+      case KEY_ENTER:
+         CurrentFunc = MainMenu;
+         return;
     }
+  }
 redraw:
-    {
-        char Buf[10];
-        float Out = EncCounter *0.00756 + 0.015;
-
-        FToS(Out, Buf);
-
-        LcdChr(Y_POSITION*2 + X_POSITION * 2 + 10, Buf);
-    }
+  {
+    char Buf[10];
+    float Out = EncCounter *0.00756 + 0.015;
+    
+    FToS(Out, Buf);
+      
+    LcdChr(Y_POSITION*2 + X_POSITION * 2 + 10, Buf);
+  }
 }
 #endif /* FLAT_DEMO */
 
 void Contrast(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    MenuCounter = 70;
+    LcdClear(); /* Clear screen */
+    goto redraw;
+  }
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        MenuCounter = 70;
-        LcdClear(); /* Clear screen */
-        goto redraw;
+      case KEY_UP:
+        if ( MenuCounter < 90 )
+          MenuCounter++;
+        break;
+      case KEY_DOWN:
+        if ( MenuCounter > 0 )
+          MenuCounter--;
+        break;
+      case KEY_ENTER:
+         CurrentFunc = MainMenu;
+         return;
     }
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_UP:
-            if ( MenuCounter < 90 )
-                MenuCounter++;
-            break;
-        case KEY_DOWN:
-            if ( MenuCounter > 0 )
-                MenuCounter--;
-            break;
-        case KEY_ENTER:
-            CurrentFunc = MainMenu;
-            return;
-        }
 redraw:
-        LcdContrast ( MenuCounter );
-        {
-            char Buf[2];
-            uint8_t Counter = MenuCounter;
-
-            Buf[0] = Counter/10 + '0';
-            Counter = Counter%10;
-            Buf[1] = Counter + '0';
-            LcdChr(BIG_UP+Y_POSITION*2 + X_POSITION * 2 + 2, Buf);
-            LcdChr(BIG_DOWN+Y_POSITION*3 + X_POSITION * 2 + 2, Buf);
-        }
+    LcdContrast ( MenuCounter );
+    {
+      char Buf[2];
+      uint8_t Counter = MenuCounter;
+      
+      Buf[0] = Counter/10 + '0';
+      Counter = Counter%10;
+      Buf[1] = Counter + '0';
+      LcdChr(BIG_UP+Y_POSITION*2 + X_POSITION * 2 + 2, Buf);
+      LcdChr(BIG_DOWN+Y_POSITION*3 + X_POSITION * 2 + 2, Buf);
     }
+  }
 }
 
 int LongCounter;
 
 void StartFunction(void)
 {
-    char* OutString = "";
-    char  KeyArray[3];
-
-    if (Event == 0)
-        return;
-
-    switch ( Event & EV_MASK )
-    {
+  char* OutString = "";
+  char  KeyArray[3];
+  
+  if (Event == 0)
+    return;
+  
+  switch ( Event & EV_MASK )
+  {
     case EV_KEY_TOUCH:
-        OutString = "Touch";
+      OutString = "Touch";
 //      return;
-        break;
+      break;
     case EV_KEY_PRESSED:
-        OutString = "Press";
-        break;
+      OutString = "Press";
+      break;
     case EV_KEY_LONG:
-        OutString = "Long";
-        if ( Event & KEY_ENTER )
-        {
-            if (LongCounter > 3 )
-                CurrentFunc = MainMenu;
-            LongCounter++;
-        }
-        break;
+      OutString = "Long";
+      if ( Event & KEY_ENTER )
+	  {
+	    if (LongCounter > 3 )
+         CurrentFunc = MainMenu;
+        LongCounter++;
+	  }
+      break;
     case EV_KEY_REPEATE:
-        OutString = "Repeate";
-        break;
+      OutString = "Repeate";
+      break;
     case EV_KEY_REALIZED:
-        OutString = "Realize";
-        break;
+      OutString = "Realize";
+      break;
     case EV_KEY_DOUBLE:
-        OutString = "Double";
-        break;
+      OutString = "Double";
+      break;
     case EV_FUNC_FIRST:
-        OutString = "First";
-    }
-
-    LcdChr(Y_POSITION*(MenuCounter%5+1) + 14, OutString);
-    Event &= KEY_MASK;
-    KeyArray[0] = Event & KEY1 ? '*':'-';
-    KeyArray[1] = Event & KEY2 ? '*':'-';
-    KeyArray[2] = Event & KEY3 ? '*':'-';
-    LcdChr(Y_POSITION*(MenuCounter%5+1) + X_POSITION * 7 + 3, KeyArray);
-
-    {
-        uint8_t Counter = MenuCounter;
-        KeyArray[0] = Counter/100 + '0';
-        Counter = Counter%100;
-        KeyArray[1] = Counter/10 + '0';
-        Counter = Counter%10;
-        KeyArray[2] = Counter + '0';
-        LcdChr(Y_POSITION*(MenuCounter%5+1) + X_POSITION * 10 + 3, KeyArray);
-    }
-    MenuCounter++;
+      OutString = "First";
+  }
+    
+  LcdChr(Y_POSITION*(MenuCounter%5+1) + 14, OutString);
+  Event &= KEY_MASK;
+  KeyArray[0] = Event & KEY1 ? '*':'-';
+  KeyArray[1] = Event & KEY2 ? '*':'-';
+  KeyArray[2] = Event & KEY3 ? '*':'-';
+  LcdChr(Y_POSITION*(MenuCounter%5+1) + X_POSITION * 7 + 3, KeyArray);
+
+  {
+    uint8_t Counter = MenuCounter;
+    KeyArray[0] = Counter/100 + '0';
+    Counter = Counter%100;
+    KeyArray[1] = Counter/10 + '0';
+    Counter = Counter%10;
+    KeyArray[2] = Counter + '0';
+    LcdChr(Y_POSITION*(MenuCounter%5+1) + X_POSITION * 10 + 3, KeyArray);
+  }
+  MenuCounter++;
 }
 
 #endif /*MENU_DEMO*/
@@ -537,40 +537,41 @@ void StartFunction(void)
 
 int main()
 {
-    CurrentFunc(StartFunction);
-    /* init hardware */
-    SCB->VTOR = FLASH_BASE;
+  CurrentFunc(StartFunction);
+  /* init hardware */
+  SCB->VTOR = FLASH_BASE;
 //  NVIC->ISER[(TIM3_IRQn >> 0x05)] |=	(u32)0x01 << (TIM3_IRQn & (u8)0x1F); /* Enable Timer interrupt */
 //  NVIC->ISER[(TIM2_IRQn >> 0x05)] |=	(u32)0x01 << (TIM2_IRQn & (u8)0x1F); /* Enable Timer interrupt */
-    LcdInit();
-    LcdClear();
-
-    /* CLOCK = 8MHz / 8 = 1 MHz */
-    RCC->CFGR |= RCC_CFGR_HPRE_DIV2|RCC_CFGR_PPRE1_DIV4;
-    RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |RCC_APB2ENR_AFIOEN;
-    RCC->APB1ENR |= RCC_APB1ENR_TIM3EN|RCC_APB1ENR_TIM2EN;
-
-    GPIOB->CRH |= GPIO_CRH_MODE12_1|GPIO_CRH_MODE13_1|GPIO_CRH_MODE14_1|GPIO_CRH_MODE15_1; /* Output 2MHz */
-    GPIOB->CRH &= ~(GPIO_CRH_CNF12|GPIO_CRH_CNF13|GPIO_CRH_CNF14|GPIO_CRH_CNF15); /* Output Push-pull */
-
-#if 0
-    TIM3->DIER |= TIM_DIER_UIE; /* enable update IRQ */
-    TIM3->ARR = 10000; /* 1MHz / 10000 = 100Hz  - 10mSec */
-    TIM3->CR1 |= TIM_CR1_CEN;    /* start TIM7 */
-
-    TIM2->CNT = 0x8000;
-    TIM2->ARR = 0xFFFF;
-    TIM2->SMCR |= TIM_SMCR_SMS_0; /* encoder mode 1 */
-    TIM2->CCMR1 |= TIM_CCMR1_CC1S_0|TIM_CCMR1_IC1F|TIM_CCMR1_CC2S_0|TIM_CCMR1_IC2F;  /* TI1, TI2 - inputs with max filter */
-    TIM2->CCER |= TIM_CCER_CC1E|TIM_CCER_CC2E; /* Enable inputs */
-    TIM2->SR = 0;
-    TIM2->DIER |= TIM_DIER_CC2IE/*|TIM_DIER_CC1IE*/; /* Interrupt by trigger */
-    TIM2->CR1 |= TIM_CR1_CEN;
+  LcdInit();
+  LcdClear();
+
+  /* CLOCK = 8MHz / 8 = 1 MHz */
+  RCC->CFGR |= RCC_CFGR_HPRE_DIV2|RCC_CFGR_PPRE1_DIV4;
+  RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |RCC_APB2ENR_AFIOEN;
+  RCC->APB1ENR |= RCC_APB1ENR_TIM3EN|RCC_APB1ENR_TIM2EN; 
+
+  GPIOB->CRH |= GPIO_CRH_MODE12_1|GPIO_CRH_MODE13_1|GPIO_CRH_MODE14_1|GPIO_CRH_MODE15_1; /* Output 2MHz */
+  GPIOB->CRH &= ~(GPIO_CRH_CNF12|GPIO_CRH_CNF13|GPIO_CRH_CNF14|GPIO_CRH_CNF15); /* Output Push-pull */
+
+#if 0   
+  TIM3->DIER |= TIM_DIER_UIE; /* enable update IRQ */
+  TIM3->ARR = 10000; /* 1MHz / 10000 = 100Hz  - 10mSec */
+  TIM3->CR1 |= TIM_CR1_CEN;    /* start TIM7 */
+  
+  TIM2->CNT = 0x8000;
+  TIM2->ARR = 0xFFFF;
+  TIM2->SMCR |= TIM_SMCR_SMS_0; /* encoder mode 1 */
+  TIM2->CCMR1 |= TIM_CCMR1_CC1S_0|TIM_CCMR1_IC1F|TIM_CCMR1_CC2S_0|TIM_CCMR1_IC2F;  /* TI1, TI2 - inputs with max filter */
+  TIM2->CCER |= TIM_CCER_CC1E|TIM_CCER_CC2E; /* Enable inputs */
+  TIM2->SR = 0;
+  TIM2->DIER |= TIM_DIER_CC2IE/*|TIM_DIER_CC1IE*/; /* Interrupt by trigger */
+  TIM2->CR1 |= TIM_CR1_CEN;
 #endif
-    EventInit();
-
-    do
-        EventCheck();
-    while(1);
+  EventInit();
+   
+  do
+  	EventCheck();
+  while(1);
 }
 #endif  /* EVENT_DEMO*/
+

+ 293 - 293
src/graph.c

@@ -6,23 +6,23 @@
 
 typedef struct
 {
-    int16_t Delta;
-    int16_t Intercept;
-    int16_t Round0;
-    int16_t Round1;
+  int16_t Delta;
+  int16_t Intercept;
+  int16_t Round0;
+  int16_t Round1;
 } GraphTable_t;
 
 const GraphTable_t GraphTable [] = {
-    {30,1,10,5},
-    {60,2,20,10},
-    {150,5,50,20},
-    {300,10,100,50},
-    {600,20,200,100},
-    {1500,50,500,200},
-    {3000,100,1000,500},
-    {6000,200,2000,1000},
-    {12000,400,4000,2000},
-    {24000,800,8000,4000},
+{30,1,10,5},
+{60,2,20,10},
+{150,5,50,20},
+{300,10,100,50},
+{600,20,200,100},
+{1500,50,500,200},
+{3000,100,1000,500},
+{6000,200,2000,1000},
+{12000,400,4000,2000},
+{24000,800,8000,4000},
 };
 #define GRAPH_TABLE_SIZE (sizeof(GraphTable)/sizeof(GraphTable_t))
 
@@ -38,269 +38,269 @@ uint8_t GlobalDiapason;
 
 void CalculateExtr(int16_t Min, int16_t Max, int16_t* pRoundMin, uint8_t* pDiapason)
 {
-    int16_t Delta;
-    int16_t Round;
-    uint8_t Diapason;
-    int16_t RoundMin;
-    int16_t RoundMax;
-    int16_t RoundDelta;
-
-    Delta = Max - Min;
-
-    for (Diapason = 0; Diapason<GRAPH_TABLE_SIZE; Diapason++)
+  int16_t Delta;
+  int16_t Round;
+  uint8_t Diapason;
+  int16_t RoundMin;
+  int16_t RoundMax;
+  int16_t RoundDelta;
+
+  Delta = Max - Min;
+  
+  for (Diapason = 0; Diapason<GRAPH_TABLE_SIZE;Diapason++)
+  {
+    if ( Delta > GraphTable[Diapason].Delta )
+      continue;
+    break;
+  }
+
+ReselectDiapason:  
+  RoundDelta = GraphTable[Diapason].Delta;
+  Round = GraphTable[Diapason].Round0;
+
+  do
+  {
+    RoundMin = Min/Round*Round;
+    RoundMax = (Max+Round+1)/Round*Round;
+    if ( (RoundMax - RoundMin) <= RoundDelta )
+      break;
+    if (Round != GraphTable[Diapason].Round1)
     {
-        if ( Delta > GraphTable[Diapason].Delta )
-            continue;
-        break;
+      Round = GraphTable[Diapason].Round1;
+      continue;
     }
-
-ReselectDiapason:
-    RoundDelta = GraphTable[Diapason].Delta;
-    Round = GraphTable[Diapason].Round0;
-
-    do
+    Diapason++;
+    goto ReselectDiapason;
+  }
+  while(1);
+  
+  {
+    int16_t Add = (RoundDelta - (RoundMax - RoundMin))/2;
+    RoundMin = RoundMin - Add;
+    RoundMax = RoundMax + Add;
+    if (RoundMin < 0 )
     {
-        RoundMin = Min/Round*Round;
-        RoundMax = (Max+Round+1)/Round*Round;
-        if ( (RoundMax - RoundMin) <= RoundDelta )
-            break;
-        if (Round != GraphTable[Diapason].Round1)
-        {
-            Round = GraphTable[Diapason].Round1;
-            continue;
-        }
-        Diapason++;
-        goto ReselectDiapason;
+      RoundMax = RoundMax - RoundMin;
+      RoundMin = 0;
     }
-    while(1);
-
+  }
+  
+  Round = GraphTable[Diapason].Round0;
+  do
+  {
+    RoundMin = RoundMin/Round*Round;
+    RoundMax = RoundMin + GraphTable[Diapason].Delta;
+    if ( RoundMax >= Max && RoundMin <= Min )
+      break;
+    if (Round != GraphTable[Diapason].Round1)
     {
-        int16_t Add = (RoundDelta - (RoundMax - RoundMin))/2;
-        RoundMin = RoundMin - Add;
-        RoundMax = RoundMax + Add;
-        if (RoundMin < 0 )
-        {
-            RoundMax = RoundMax - RoundMin;
-            RoundMin = 0;
-        }
+      Round = GraphTable[Diapason].Round1;
+      continue;
     }
+    Diapason++;
+    goto ReselectDiapason;
+  } while(1);
 
-    Round = GraphTable[Diapason].Round0;
-    do
-    {
-        RoundMin = RoundMin/Round*Round;
-        RoundMax = RoundMin + GraphTable[Diapason].Delta;
-        if ( RoundMax >= Max && RoundMin <= Min )
-            break;
-        if (Round != GraphTable[Diapason].Round1)
-        {
-            Round = GraphTable[Diapason].Round1;
-            continue;
-        }
-        Diapason++;
-        goto ReselectDiapason;
-    } while(1);
-
-    *pRoundMin = RoundMin;
-    *pDiapason = Diapason;
+  *pRoundMin = RoundMin;
+  *pDiapason = Diapason;
 }
 
 static int8_t Offsetmin(Graph_t* Array, int8_t ColumnNum)
 {
-    return (Array[ColumnNum].Min - GlobalMin)/GraphTable[GlobalDiapason].Intercept+1;
+  return (Array[ColumnNum].Min - GlobalMin)/GraphTable[GlobalDiapason].Intercept+1;
 }
 static int8_t Offsetmax(Graph_t* Array, int8_t ColumnNum)
 {
-    return (Array[ColumnNum].Max - GlobalMin)/GraphTable[GlobalDiapason].Intercept+1;
+  return (Array[ColumnNum].Max - GlobalMin)/GraphTable[GlobalDiapason].Intercept+1;
 }
 
 void OutOneColumn(Graph_t* Array, int8_t ColumnNum)
 {
-    int8_t OffsetMin,OffsetMax;
-    uint32_t Column = 0;
-    int8_t PrevMin;
-    int8_t PrevMax;
-    int8_t  Prev;
-    int8_t  Next;
-
-    Next = GraphCurrentPoint + 1;
-    if ( Next >= GRAPH_SIZE)
-        Next = 0;
-
-    if( ColumnNum == Next)
+  int8_t OffsetMin,OffsetMax;
+  uint32_t Column = 0;
+  int8_t PrevMin;
+  int8_t PrevMax;
+  int8_t  Prev;
+  int8_t  Next;
+
+  Next = GraphCurrentPoint + 1;
+  if ( Next >= GRAPH_SIZE)
+    Next = 0;
+
+  if( ColumnNum == Next)
+  {
+    Column = 0xFFFFFFFF;
+    goto draw;
+  }
+
+  if ( ColumnNum%10 == 0)
+  {
+    Column = (1<<1)+(1<<3)+(1<<5)+(1<<7)+(1<<9)+(1<<11)+
+            (1<<13)+(1<<15)+(1<<17)+(1<<19)+(1<<21)+(1<<23)+(1<<25)+(1<<27)+(1<<29)+(1u<<31);
+  }
+  if ( ColumnNum%2 == 0)
+    Column |= (1<<1)+(1<<11)+(1<<21)+(1u<<31);
+  
+  Prev = ColumnNum - 1;
+  if (Prev < 0)
+    Prev = GRAPH_SIZE - 1;
+
+  
+  if ( Array[ColumnNum].Min != 32000)
+  {
+    int8_t Delta;
+
+    OffsetMin = Offsetmin(Array, ColumnNum);
+    OffsetMax = Offsetmax(Array, ColumnNum);
+    if ( Array[Prev].Min != 32000)
     {
-        Column = 0xFFFFFFFF;
-        goto draw;
+      PrevMin = Offsetmin(Array, Prev);
+      PrevMax = Offsetmax(Array, Prev);
     }
-
-    if ( ColumnNum%10 == 0)
+    else
     {
-        Column = (1<<1)+(1<<3)+(1<<5)+(1<<7)+(1<<9)+(1<<11)+
-                 (1<<13)+(1<<15)+(1<<17)+(1<<19)+(1<<21)+(1<<23)+(1<<25)+(1<<27)+(1<<29)+(1u<<31);
+      PrevMin = OffsetMin;
+      PrevMax = OffsetMax;
     }
-    if ( ColumnNum%2 == 0)
-        Column |= (1<<1)+(1<<11)+(1<<21)+(1u<<31);
-
-    Prev = ColumnNum - 1;
-    if (Prev < 0)
-        Prev = GRAPH_SIZE - 1;
-
-
-    if ( Array[ColumnNum].Min != 32000)
+    
+    Delta = OffsetMax - PrevMax - 1;
+    while (Delta > 0)
     {
-        int8_t Delta;
-
-        OffsetMin = Offsetmin(Array, ColumnNum);
-        OffsetMax = Offsetmax(Array, ColumnNum);
-        if ( Array[Prev].Min != 32000)
-        {
-            PrevMin = Offsetmin(Array, Prev);
-            PrevMax = Offsetmax(Array, Prev);
-        }
-        else
-        {
-            PrevMin = OffsetMin;
-            PrevMax = OffsetMax;
-        }
-
-        Delta = OffsetMax - PrevMax - 1;
-        while (Delta > 0)
-        {
-            Column |= (1<<(OffsetMax-Delta));
-            Delta--;
-        }
-
-        Delta = PrevMin - OffsetMin - 1;
-        while (Delta > 0)
-        {
-            Column |= (1<<(PrevMin-Delta));
-            Delta--;
-        }
+      Column |= (1<<(OffsetMax-Delta));
+      Delta--;
+    }
 
-        Delta = PrevMax - OffsetMax - 1;
-        while (Delta > 0)
-        {
-            Column |= (1<<(PrevMax-Delta));
-            Delta--;
-        }
+    Delta = PrevMin - OffsetMin - 1;
+    while (Delta > 0)
+    {
+      Column |= (1<<(PrevMin-Delta));
+      Delta--;
+    }
 
-        Delta = OffsetMin - PrevMin - 1;
-        while (Delta > 0)
-        {
-            Column |= (1<<(OffsetMin-Delta));
-            Delta--;
-        }
+    Delta = PrevMax - OffsetMax - 1;
+    while (Delta > 0)
+    {
+      Column |= (1<<(PrevMax-Delta));
+      Delta--;
+    }
 
-        Column |= (1<<OffsetMin);
-        Column |= (1<<OffsetMax);
+    Delta = OffsetMin - PrevMin - 1;
+    while (Delta > 0)
+    {
+      Column |= (1<<(OffsetMin-Delta));
+      Delta--;
     }
 
+    Column |= (1<<OffsetMin);
+    Column |= (1<<OffsetMax);
+  }
+
 draw:
-    Column = __RBIT(Column);
-    LcdGotoXY(ColumnNum, 5);
-    LcdSend(Column>>24, LCD_DATA);
-    LcdGotoXY(ColumnNum, 4);
-    LcdSend(Column>>16, LCD_DATA);
-    LcdGotoXY(ColumnNum, 3);
-    LcdSend(Column>>8, LCD_DATA);
-    LcdGotoXY(ColumnNum, 2);
-    LcdSend(Column, LCD_DATA);
+  Column = __RBIT(Column);
+  LcdGotoXY(ColumnNum, 5);
+  LcdSend(Column>>24, LCD_DATA);
+  LcdGotoXY(ColumnNum, 4);
+  LcdSend(Column>>16, LCD_DATA);
+  LcdGotoXY(ColumnNum, 3);
+  LcdSend(Column>>8, LCD_DATA);
+  LcdGotoXY(ColumnNum, 2);
+  LcdSend(Column, LCD_DATA);
 }
 
 void PrintGraph()
 {
-    Graph_t* Array = GraphData.GraphArray;
-    int i;
-    uint8_t Diapason;
-    int16_t Min=32000;
-    int16_t Max=-32000;
-
-    /* Finding extremoum */
-    for(i=0; i<GRAPH_SIZE; i++)
+  Graph_t* Array = GraphData.GraphArray;
+  int i;
+  uint8_t Diapason;
+  int16_t Min=32000;
+  int16_t Max=-32000;
+
+  /* Finding extremoum */
+  for(i=0; i<GRAPH_SIZE;i++)
+  {
+    if (Array[i].Max > Max )
     {
-        if (Array[i].Max > Max )
-        {
-            Max = Array[i].Max;
-            GlobalMaxPoint = i;
-        }
-        if(Array[i].Min < Min)
-        {
-            Min = Array[i].Min;
-            GlobalMinPoint = i;
-        }
+      Max = Array[i].Max;
+      GlobalMaxPoint = i;
     }
-    CalculateExtr(Min, Max, &Min, &Diapason);
-    Max = Min + GraphTable[Diapason].Delta;
-    if ( GlobalDiapason == Diapason && Min == GlobalMin && Max == GlobalMax)
+    if(Array[i].Min < Min)
     {
-        int8_t Next = GraphCurrentPoint + 1;
-        if ( Next >= GRAPH_SIZE )
-            Next = 0;
-
-        OutOneColumn(GraphData.GraphArray, Next);
-        OutOneColumn(GraphData.GraphArray, GraphCurrentPoint);
-        return;
-    }
-    GlobalMin = Min;
-    GlobalMax = Max;
-    GlobalDiapason = Diapason;
-    for ( i = 0; i<GRAPH_SIZE; i++)
-    {
-        OutOneColumn(Array, i);
+      Min = Array[i].Min;
+      GlobalMinPoint = i;
     }
-    OutValueSmall(1, 0, GlobalMin, GraphData.DotPosition, 0);
-    OutValueSmall(1, 7, GraphTable[GlobalDiapason].Delta/3, GraphData.DotPosition, 0);
+  }
+  CalculateExtr(Min, Max, &Min, &Diapason);
+  Max = Min + GraphTable[Diapason].Delta;
+  if ( GlobalDiapason == Diapason && Min == GlobalMin && Max == GlobalMax)
+  {
+    int8_t Next = GraphCurrentPoint + 1;
+    if ( Next >= GRAPH_SIZE )
+      Next = 0;
+      
+    OutOneColumn(GraphData.GraphArray, Next);
+    OutOneColumn(GraphData.GraphArray, GraphCurrentPoint);
+    return;
+  }
+  GlobalMin = Min;
+  GlobalMax = Max;
+  GlobalDiapason = Diapason;
+  for ( i = 0; i<GRAPH_SIZE; i++)
+  {
+    OutOneColumn(Array, i);
+  }
+  OutValueSmall(1, 0, GlobalMin, GraphData.DotPosition, 0);
+  OutValueSmall(1, 7, GraphTable[GlobalDiapason].Delta/3, GraphData.DotPosition, 0);
 }
 
 static void SetupGraph(void);
 void DisplayGraph(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    GlobalDiapason = 0xFF;
+    PrintGraph();
+    return;
+  }
+  if ( (Event& EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        GlobalDiapason = 0xFF;
-        PrintGraph();
+      case KEY_ENTER:
+        CurrentFunc(StartFunction);
         return;
-    }
-    if ( (Event& EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_ENTER:
-            CurrentFunc(StartFunction);
-            return;
-        case KEY_DOWN:
-        case KEY_UP:
-            CurrentFunc(SetupGraph);
-            return;
-        case KEY_ADC:
-        {
-            int16_t ValueMin;
-            int16_t ValueMax;
-            uint8_t Next;
+      case KEY_DOWN:
+      case KEY_UP:
+        CurrentFunc(SetupGraph);
+        return;
+      case KEY_ADC:
+      {
+        int16_t ValueMin;
+        int16_t ValueMax;
+        uint8_t Next;
 
 
-            ValueMin = GraphData.GraphArray[GraphCurrentPoint].Min;
-            ValueMax = GraphData.GraphArray[GraphCurrentPoint].Max;
-            if (ValueMin < GlobalMin || ValueMax > GlobalMax || /* Larger diapason */
-                    GraphCurrentPoint == GlobalMaxPoint || GraphCurrentPoint == GlobalMinPoint) /* Check Diapason */
-            {
-                PrintGraph();
-                return;
-            }
+        ValueMin = GraphData.GraphArray[GraphCurrentPoint].Min;
+        ValueMax = GraphData.GraphArray[GraphCurrentPoint].Max;
+        if (ValueMin < GlobalMin || ValueMax > GlobalMax || /* Larger diapason */
+            GraphCurrentPoint == GlobalMaxPoint || GraphCurrentPoint == GlobalMinPoint) /* Check Diapason */
+        {
+          PrintGraph();
+          return;
+        }
 
-            Next = GraphCurrentPoint + 1;
-            if ( Next >= GRAPH_SIZE)
-                Next = 0;
+        Next = GraphCurrentPoint + 1;
+        if ( Next >= GRAPH_SIZE)
+          Next = 0;
 
-            OutOneColumn(GraphData.GraphArray, GraphCurrentPoint);
-            OutOneColumn(GraphData.GraphArray, Next);
+        OutOneColumn(GraphData.GraphArray, GraphCurrentPoint);
+        OutOneColumn(GraphData.GraphArray, Next);
 
-            return;
-        }
-        }
+        return;
+      }
     }
-    return;
+  }
+  return;
 }
 
 uint16_t TimeInterval = 5; /* 1 second */
@@ -308,83 +308,83 @@ uint16_t TimeInterval = 5; /* 1 second */
 static uint8_t IntervalCorrection = 0;
 static void SetupGraph(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        MenuPos = 0;
-        IntervalCorrection = 0;
-        EncCounter = TimeInterval - 1;
-        goto redraw;
-    }
-    if ( (Event& EV_MASK) == EV_KEY_PRESSED )
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = 0;
+    IntervalCorrection = 0;
+    EncCounter = TimeInterval - 1;
+    goto redraw;
+  }
+  if ( (Event& EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if (IntervalCorrection == 0)
         {
-        case KEY_UP:
-            if (IntervalCorrection == 0)
-            {
-                MenuPos++;
-                if ( MenuPos > 2 )
-                    MenuPos = 0;
-                goto redraw;
-            }
-        case KEY_DOWN:
-            if (IntervalCorrection == 0)
-            {
-                if ( MenuPos == 0 )
-                    MenuPos = 2;
-                else
-                    MenuPos--;
-                goto redraw;
-            }
-            TimeInterval = EncCounter + 1;
-            goto redraw;
+          MenuPos++;
+          if ( MenuPos > 2 )
+            MenuPos = 0;
+          goto redraw;
+        }
+      case KEY_DOWN:
+        if (IntervalCorrection == 0)
+        {
+          if ( MenuPos == 0 )
+            MenuPos = 2;
+          else
+            MenuPos--;
+          goto redraw;
+        }
+        TimeInterval = EncCounter + 1;
+        goto redraw;
 
-        case KEY_ENTER:
-            switch (MenuPos)
+      case KEY_ENTER:
+        switch (MenuPos)
+        {
+          case 1: /* Clear */
+            ClearGraph();
+          case 0: /* Return */
+            CurrentFunc(DisplayGraph);
+            return;
+          default: /* Interval */
+            if ( IntervalCorrection == 0)
+              IntervalCorrection = 1;
+            else
             {
-            case 1: /* Clear */
-                ClearGraph();
-            case 0: /* Return */
-                CurrentFunc(DisplayGraph);
-                return;
-            default: /* Interval */
-                if ( IntervalCorrection == 0)
-                    IntervalCorrection = 1;
-                else
-                {
-                    IntervalCorrection = 0;
-                }
+              IntervalCorrection = 0;
             }
         }
     }
-    return;
-
-redraw:
-    LcdChr(14+1*Y_POSITION+0*X_POSITION + (MenuPos==0?INVERSE:0), "Return");
-    LcdChr(14+2*Y_POSITION+0*X_POSITION + (MenuPos==1?INVERSE:0), "Clear");
-    LcdChr(14+3*Y_POSITION+0*X_POSITION + (MenuPos==2?INVERSE:0), "Interval");
-    OutValueSmall(3, 9, TimeInterval*2, 3, MenuPos==2?1:0);
+  }      
+  return;
+
+redraw:  
+  LcdChr(14+1*Y_POSITION+0*X_POSITION + (MenuPos==0?INVERSE:0), "Return");
+  LcdChr(14+2*Y_POSITION+0*X_POSITION + (MenuPos==1?INVERSE:0), "Clear");
+  LcdChr(14+3*Y_POSITION+0*X_POSITION + (MenuPos==2?INVERSE:0), "Interval");
+  OutValueSmall(3, 9, TimeInterval*2, 3, MenuPos==2?1:0);
 }
 
 void ClearGraph(void)
 {
-    int i;
-
-    for (i = 0; i < GRAPH_SIZE; i++)
-    {
-        IGraphArray[i].Min = VGraphArray[i].Min = 32000;
-        IGraphArray[i].Max = VGraphArray[i].Max = -32000;
-    }
-
-    GraphCurrentPoint = 0;
-    IGraphArray[0].Max =
-        IGraphArray[0].Min = HumanI;
-    VGraphArray[0].Max =
-        VGraphArray[0].Min = HumanV;
-
-    GlobalMin = 32000;
-    GlobalMax = -32000;
+  int i;
+
+  for (i = 0; i < GRAPH_SIZE; i++)
+  {
+    IGraphArray[i].Min = VGraphArray[i].Min = 32000;
+    IGraphArray[i].Max = VGraphArray[i].Max = -32000;
+  }
+
+  GraphCurrentPoint = 0;
+  IGraphArray[0].Max = 
+      IGraphArray[0].Min = HumanI;
+  VGraphArray[0].Max = 
+      VGraphArray[0].Min = HumanV;
+    
+  GlobalMin = 32000;
+  GlobalMax = -32000;
 }
 
 #endif

+ 247 - 247
src/n3310.c

@@ -7,97 +7,97 @@
 
 const uint8_t FontLookup [] =
 {
-    0x00, 0x00, 0x00, 0x00, 0x00 ,  // sp
-    0x00, 0x00, 0x2f, 0x00, 0x00 ,   // !
-    0x00, 0x07, 0x00, 0x07, 0x00 ,   // "
-    0x14, 0x7f, 0x14, 0x7f, 0x14 ,   // #
-    0x24, 0x2a, 0x7f, 0x2a, 0x12 ,   // $
-    0xc4, 0xc8, 0x10, 0x26, 0x46 ,   // %
-    0x36, 0x49, 0x55, 0x22, 0x50 ,   // &
-    0x00, 0x05, 0x03, 0x00, 0x00 ,   // '
-    0x00, 0x1c, 0x22, 0x41, 0x00 ,   // (
-    0x00, 0x41, 0x22, 0x1c, 0x00 ,   // )
-    0x14, 0x08, 0x3E, 0x08, 0x14 ,   // *
-    0x08, 0x08, 0x3E, 0x08, 0x08 ,   // +
-    0x00, 0x00, 0x50, 0x30, 0x00 ,   // ,
-    0x10, 0x10, 0x10, 0x10, 0x10 ,   // -
-    0x00, 0x60, 0x60, 0x00, 0x00 ,   // .
-    0x20, 0x10, 0x08, 0x04, 0x02 ,   // /
-    0x3E, 0x51, 0x49, 0x45, 0x3E ,   // 0
-    0x00, 0x42, 0x7F, 0x40, 0x00 ,   // 1
-    0x42, 0x61, 0x51, 0x49, 0x46 ,   // 2
-    0x21, 0x41, 0x45, 0x4B, 0x31 ,   // 3
-    0x18, 0x14, 0x12, 0x7F, 0x10 ,   // 4
-    0x27, 0x45, 0x45, 0x45, 0x39 ,   // 5
-    0x3C, 0x4A, 0x49, 0x49, 0x30 ,   // 6
-    0x01, 0x71, 0x09, 0x05, 0x03 ,   // 7
-    0x36, 0x49, 0x49, 0x49, 0x36 ,   // 8
-    0x06, 0x49, 0x49, 0x29, 0x1E ,   // 9
-    0x00, 0x36, 0x36, 0x00, 0x00 ,   // :
-    0x00, 0x56, 0x36, 0x00, 0x00 ,   // ;
-    0x08, 0x14, 0x22, 0x41, 0x00 ,   // <
-    0x14, 0x14, 0x14, 0x14, 0x14 ,   // =
-    0x00, 0x41, 0x22, 0x14, 0x08 ,   // >
-    0x02, 0x01, 0x51, 0x09, 0x06 ,   // ?
-    0x32, 0x49, 0x59, 0x51, 0x3E ,   // @
-    0x7E, 0x11, 0x11, 0x11, 0x7E ,   // A
-    0x7F, 0x49, 0x49, 0x49, 0x36 ,   // B
-    0x3E, 0x41, 0x41, 0x41, 0x22 ,   // C
-    0x7F, 0x41, 0x41, 0x22, 0x1C ,   // D
-    0x7F, 0x49, 0x49, 0x49, 0x41 ,   // E
-    0x7F, 0x09, 0x09, 0x09, 0x01 ,   // F
-    0x3E, 0x41, 0x49, 0x49, 0x7A ,   // G
-    0x7F, 0x08, 0x08, 0x08, 0x7F ,   // H
-    0x00, 0x41, 0x7F, 0x41, 0x00 ,   // I
-    0x20, 0x40, 0x41, 0x3F, 0x01 ,   // J
-    0x7F, 0x08, 0x14, 0x22, 0x41 ,   // K
-    0x7F, 0x40, 0x40, 0x40, 0x40 ,   // L
-    0x7F, 0x02, 0x0C, 0x02, 0x7F ,   // M
-    0x7F, 0x04, 0x08, 0x10, 0x7F ,   // N
-    0x3E, 0x41, 0x41, 0x41, 0x3E ,   // O
-    0x7F, 0x09, 0x09, 0x09, 0x06 ,   // P
-    0x3E, 0x41, 0x51, 0x21, 0x5E ,   // Q
-    0x7F, 0x09, 0x19, 0x29, 0x46 ,   // R
-    0x46, 0x49, 0x49, 0x49, 0x31 ,   // S
-    0x01, 0x01, 0x7F, 0x01, 0x01 ,   // T
-    0x3F, 0x40, 0x40, 0x40, 0x3F ,   // U
-    0x1F, 0x20, 0x40, 0x20, 0x1F ,   // V
-    0x3F, 0x40, 0x38, 0x40, 0x3F ,   // W
-    0x63, 0x14, 0x08, 0x14, 0x63 ,   // X
-    0x07, 0x08, 0x70, 0x08, 0x07 ,   // Y
-    0x61, 0x51, 0x49, 0x45, 0x43 ,   // Z
-    0x00, 0x7F, 0x41, 0x41, 0x00 ,   // [
-    0x55, 0x2A, 0x55, 0x2A, 0x55 ,   // 55
-    0x00, 0x41, 0x41, 0x7F, 0x00 ,   // ]
-    0x04, 0x02, 0x01, 0x02, 0x04 ,   // ^
-    0x40, 0x40, 0x40, 0x40, 0x40 ,   // _
-    0x00, 0x01, 0x02, 0x04, 0x00 ,   // '
-    0x20, 0x54, 0x54, 0x54, 0x78 ,   // a
-    0x7F, 0x48, 0x44, 0x44, 0x38 ,   // b
-    0x38, 0x44, 0x44, 0x44, 0x20 ,   // c
-    0x38, 0x44, 0x44, 0x48, 0x7F ,   // d
-    0x38, 0x54, 0x54, 0x54, 0x18 ,   // e
-    0x08, 0x7E, 0x09, 0x01, 0x02 ,   // f
-    0x0C, 0x52, 0x52, 0x52, 0x3E ,   // g
-    0x7F, 0x08, 0x04, 0x04, 0x78 ,   // h
-    0x00, 0x44, 0x7D, 0x40, 0x00 ,   // i
-    0x20, 0x40, 0x44, 0x3D, 0x00 ,   // j
-    0x7F, 0x10, 0x28, 0x44, 0x00 ,   // k
-    0x00, 0x41, 0x7F, 0x40, 0x00 ,   // l
-    0x7C, 0x04, 0x18, 0x04, 0x78 ,   // m
-    0x7C, 0x08, 0x04, 0x04, 0x78 ,   // n
-    0x38, 0x44, 0x44, 0x44, 0x38 ,   // o
-    0x7C, 0x14, 0x14, 0x14, 0x08 ,   // p
-    0x08, 0x14, 0x14, 0x18, 0x7C ,   // q
-    0x7C, 0x08, 0x04, 0x04, 0x08 ,   // r
-    0x48, 0x54, 0x54, 0x54, 0x20 ,   // s
-    0x04, 0x3F, 0x44, 0x40, 0x20 ,   // t
-    0x3C, 0x40, 0x40, 0x20, 0x7C ,   // u
-    0x1C, 0x20, 0x40, 0x20, 0x1C ,   // v
-    0x3C, 0x40, 0x30, 0x40, 0x3C ,   // w
-    0x44, 0x28, 0x10, 0x28, 0x44 ,   // x
-    0x0C, 0x50, 0x50, 0x50, 0x3C ,   // y
-    0x44, 0x64, 0x54, 0x4C, 0x44     // z
+     0x00, 0x00, 0x00, 0x00, 0x00 ,  // sp
+     0x00, 0x00, 0x2f, 0x00, 0x00 ,   // !
+     0x00, 0x07, 0x00, 0x07, 0x00 ,   // "
+     0x14, 0x7f, 0x14, 0x7f, 0x14 ,   // #
+     0x24, 0x2a, 0x7f, 0x2a, 0x12 ,   // $
+     0xc4, 0xc8, 0x10, 0x26, 0x46 ,   // %
+     0x36, 0x49, 0x55, 0x22, 0x50 ,   // &
+     0x00, 0x05, 0x03, 0x00, 0x00 ,   // '
+     0x00, 0x1c, 0x22, 0x41, 0x00 ,   // (
+     0x00, 0x41, 0x22, 0x1c, 0x00 ,   // )
+     0x14, 0x08, 0x3E, 0x08, 0x14 ,   // *
+     0x08, 0x08, 0x3E, 0x08, 0x08 ,   // +
+     0x00, 0x00, 0x50, 0x30, 0x00 ,   // ,
+     0x10, 0x10, 0x10, 0x10, 0x10 ,   // -
+     0x00, 0x60, 0x60, 0x00, 0x00 ,   // .
+     0x20, 0x10, 0x08, 0x04, 0x02 ,   // /
+     0x3E, 0x51, 0x49, 0x45, 0x3E ,   // 0
+     0x00, 0x42, 0x7F, 0x40, 0x00 ,   // 1
+     0x42, 0x61, 0x51, 0x49, 0x46 ,   // 2
+     0x21, 0x41, 0x45, 0x4B, 0x31 ,   // 3
+     0x18, 0x14, 0x12, 0x7F, 0x10 ,   // 4
+     0x27, 0x45, 0x45, 0x45, 0x39 ,   // 5
+     0x3C, 0x4A, 0x49, 0x49, 0x30 ,   // 6
+     0x01, 0x71, 0x09, 0x05, 0x03 ,   // 7
+     0x36, 0x49, 0x49, 0x49, 0x36 ,   // 8
+     0x06, 0x49, 0x49, 0x29, 0x1E ,   // 9
+     0x00, 0x36, 0x36, 0x00, 0x00 ,   // :
+     0x00, 0x56, 0x36, 0x00, 0x00 ,   // ;
+     0x08, 0x14, 0x22, 0x41, 0x00 ,   // <
+     0x14, 0x14, 0x14, 0x14, 0x14 ,   // =
+     0x00, 0x41, 0x22, 0x14, 0x08 ,   // >
+     0x02, 0x01, 0x51, 0x09, 0x06 ,   // ?
+     0x32, 0x49, 0x59, 0x51, 0x3E ,   // @
+     0x7E, 0x11, 0x11, 0x11, 0x7E ,   // A
+     0x7F, 0x49, 0x49, 0x49, 0x36 ,   // B
+     0x3E, 0x41, 0x41, 0x41, 0x22 ,   // C
+     0x7F, 0x41, 0x41, 0x22, 0x1C ,   // D
+     0x7F, 0x49, 0x49, 0x49, 0x41 ,   // E
+     0x7F, 0x09, 0x09, 0x09, 0x01 ,   // F
+     0x3E, 0x41, 0x49, 0x49, 0x7A ,   // G
+     0x7F, 0x08, 0x08, 0x08, 0x7F ,   // H
+     0x00, 0x41, 0x7F, 0x41, 0x00 ,   // I
+     0x20, 0x40, 0x41, 0x3F, 0x01 ,   // J
+     0x7F, 0x08, 0x14, 0x22, 0x41 ,   // K
+     0x7F, 0x40, 0x40, 0x40, 0x40 ,   // L
+     0x7F, 0x02, 0x0C, 0x02, 0x7F ,   // M
+     0x7F, 0x04, 0x08, 0x10, 0x7F ,   // N
+     0x3E, 0x41, 0x41, 0x41, 0x3E ,   // O
+     0x7F, 0x09, 0x09, 0x09, 0x06 ,   // P
+     0x3E, 0x41, 0x51, 0x21, 0x5E ,   // Q
+     0x7F, 0x09, 0x19, 0x29, 0x46 ,   // R
+     0x46, 0x49, 0x49, 0x49, 0x31 ,   // S
+     0x01, 0x01, 0x7F, 0x01, 0x01 ,   // T
+     0x3F, 0x40, 0x40, 0x40, 0x3F ,   // U
+     0x1F, 0x20, 0x40, 0x20, 0x1F ,   // V
+     0x3F, 0x40, 0x38, 0x40, 0x3F ,   // W
+     0x63, 0x14, 0x08, 0x14, 0x63 ,   // X
+     0x07, 0x08, 0x70, 0x08, 0x07 ,   // Y
+     0x61, 0x51, 0x49, 0x45, 0x43 ,   // Z
+     0x00, 0x7F, 0x41, 0x41, 0x00 ,   // [
+     0x55, 0x2A, 0x55, 0x2A, 0x55 ,   // 55
+     0x00, 0x41, 0x41, 0x7F, 0x00 ,   // ]
+     0x04, 0x02, 0x01, 0x02, 0x04 ,   // ^
+     0x40, 0x40, 0x40, 0x40, 0x40 ,   // _
+     0x00, 0x01, 0x02, 0x04, 0x00 ,   // '
+     0x20, 0x54, 0x54, 0x54, 0x78 ,   // a
+     0x7F, 0x48, 0x44, 0x44, 0x38 ,   // b
+     0x38, 0x44, 0x44, 0x44, 0x20 ,   // c
+     0x38, 0x44, 0x44, 0x48, 0x7F ,   // d
+     0x38, 0x54, 0x54, 0x54, 0x18 ,   // e
+     0x08, 0x7E, 0x09, 0x01, 0x02 ,   // f
+     0x0C, 0x52, 0x52, 0x52, 0x3E ,   // g
+     0x7F, 0x08, 0x04, 0x04, 0x78 ,   // h
+     0x00, 0x44, 0x7D, 0x40, 0x00 ,   // i
+     0x20, 0x40, 0x44, 0x3D, 0x00 ,   // j
+     0x7F, 0x10, 0x28, 0x44, 0x00 ,   // k
+     0x00, 0x41, 0x7F, 0x40, 0x00 ,   // l
+     0x7C, 0x04, 0x18, 0x04, 0x78 ,   // m
+     0x7C, 0x08, 0x04, 0x04, 0x78 ,   // n
+     0x38, 0x44, 0x44, 0x44, 0x38 ,   // o
+     0x7C, 0x14, 0x14, 0x14, 0x08 ,   // p
+     0x08, 0x14, 0x14, 0x18, 0x7C ,   // q
+     0x7C, 0x08, 0x04, 0x04, 0x08 ,   // r
+     0x48, 0x54, 0x54, 0x54, 0x20 ,   // s
+     0x04, 0x3F, 0x44, 0x40, 0x20 ,   // t
+     0x3C, 0x40, 0x40, 0x20, 0x7C ,   // u
+     0x1C, 0x20, 0x40, 0x20, 0x1C ,   // v
+     0x3C, 0x40, 0x30, 0x40, 0x3C ,   // w
+     0x44, 0x28, 0x10, 0x28, 0x44 ,   // x
+     0x0C, 0x50, 0x50, 0x50, 0x3C ,   // y
+     0x44, 0x64, 0x54, 0x4C, 0x44     // z
 };
 
 
@@ -115,40 +115,40 @@ const uint8_t FontLookup [] =
 --------------------------------------------------------------------------------------------------*/
 void LcdInit ( uint8_t Contrast )
 {
-    RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; /* Port B Clock */
-
-    GPIOB->CRH &= ~(((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_DC_PIN-8)*4) |
-                    ((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_IN_PIN-8)*4) |
-                    ((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_CLK_PIN-8)*4)|
-                    ((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_RST_PIN-8)*4) ); // Reset all pins
-
-
-    GPIOB->CRH |=  (((GPIO_CRL_MODE0_1)<<(LCD_DC_PIN-8)*4) |
-                    ((GPIO_CRL_MODE0_1)<<(LCD_IN_PIN-8)*4) |
-                    ((GPIO_CRL_MODE0_1)<<(LCD_CLK_PIN-8)*4)|
-                    ((GPIO_CRL_MODE0_1)<<(LCD_RST_PIN-8)*4) ); // Pins in push-pull 10MHz
-
-    GPIOB->BRR = 1<<LCD_RST_PIN; /* RESET to 0 */
-    if (Contrast == 0)
-        Contrast = 60;
-    if (Contrast > 90)
-        Contrast = 90;
-    /* Some delay */
-    {
-        __IO uint32_t Counter;
-        for ( Counter = 0; Counter <10; Counter++)
-            ; /* Blank */
-    }
-    GPIOB->BSRR = 1<<LCD_RST_PIN; /* RESET to 1 */
+  RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; /* Port B Clock */
+
+  GPIOB->CRH &= ~(((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_DC_PIN-8)*4) |
+                  ((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_IN_PIN-8)*4) |
+                  ((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_CLK_PIN-8)*4)|
+                  ((GPIO_CRL_MODE0|GPIO_CRL_CNF0)<<(LCD_RST_PIN-8)*4) ); // Reset all pins
+
+
+  GPIOB->CRH |=  (((GPIO_CRL_MODE0_1)<<(LCD_DC_PIN-8)*4) |
+                  ((GPIO_CRL_MODE0_1)<<(LCD_IN_PIN-8)*4) |
+                  ((GPIO_CRL_MODE0_1)<<(LCD_CLK_PIN-8)*4)|
+                  ((GPIO_CRL_MODE0_1)<<(LCD_RST_PIN-8)*4) ); // Pins in push-pull 10MHz
+    
+  GPIOB->BRR = 1<<LCD_RST_PIN; /* RESET to 0 */
+  if (Contrast == 0)
+    Contrast = 60;
+  if (Contrast > 90)
+    Contrast = 90;
+  /* Some delay */
+  {
+    __IO uint32_t Counter;
+    for ( Counter = 0; Counter <10; Counter++)
+      ; /* Blank */
+  }
+  GPIOB->BSRR = 1<<LCD_RST_PIN; /* RESET to 1 */
 #define FUNCTION_SET 0x20
 #define FUNCTION_PD  0x04
 #define FUNCTION_V   0x02
 #define FUNCTION_EXT 0x01
-    LcdSend( FUNCTION_SET|FUNCTION_EXT, LCD_CMD );  // LCD Extended Commands.
+  LcdSend( FUNCTION_SET|FUNCTION_EXT, LCD_CMD );  // LCD Extended Commands.
 #define SET_VOP      0x80
-    LcdSend( SET_VOP|Contrast, LCD_CMD );  // Set LCD Vop (Contrast). 3.06+0.06*72=4.38V
+  LcdSend( SET_VOP|Contrast, LCD_CMD );  // Set LCD Vop (Contrast). 3.06+0.06*72=4.38V
 #define TEMPERATURE_COEFFICIENT 0x4
-    LcdSend( TEMPERATURE_COEFFICIENT | 2, LCD_CMD );  // Set Temp coefficent. 2 (0-3)
+  LcdSend( TEMPERATURE_COEFFICIENT | 2, LCD_CMD );  // Set Temp coefficent. 2 (0-3)
 #define SET_BIAS 0x10
 #define BIAS_1_10 0x07
 #define BIAS_1_18 0x06
@@ -158,15 +158,15 @@ void LcdInit ( uint8_t Contrast )
 #define BIAS_1_65 0x02
 #define BIAS_1_80 0x01
 #define BIAS_1_100 0x00
-    LcdSend( SET_BIAS|BIAS_1_48, LCD_CMD );  // LCD bias mode 1:48.
+  LcdSend( SET_BIAS|BIAS_1_48, LCD_CMD );  // LCD bias mode 1:48.
 
-    LcdSend( FUNCTION_SET, LCD_CMD );  // LCD Standard Commands, Horizontal addressing mode.
+  LcdSend( FUNCTION_SET, LCD_CMD );  // LCD Standard Commands, Horizontal addressing mode.
 #define DISPLAY_CONTROL 0x08
 #define DISPLAY_BLANK   0x00
 #define DISPLAY_NORMAL  0x04
 #define DISPLAY_ALLON   0x01
 #define DISPLAY_INVERSE 0x05
-    LcdSend( DISPLAY_CONTROL|DISPLAY_NORMAL, LCD_CMD );  // LCD in normal mode.
+  LcdSend( DISPLAY_CONTROL|DISPLAY_NORMAL, LCD_CMD );  // LCD in normal mode.
 
 #define SET_Y 0x40 /* from 0 to 5 */
 #define SET_X 0x80 /* from 0 to 83 */
@@ -176,19 +176,19 @@ void LcdInit ( uint8_t Contrast )
 //Clear display
 void LcdClear()
 {
-    uint16_t j = 7;
-
-    while ( j-- )
-    {
-        uint16_t i = 84;
-
-        LcdSend(SET_Y|j, LCD_CMD );
-        LcdSend(SET_X|0, LCD_CMD);
-        while ( i-- )
-        {
-            LcdSend(0/*xff*/, LCD_DATA);
-        }
-    }
+	uint16_t j = 7;
+  
+	while ( j-- )
+	{
+      uint16_t i = 84;
+
+      LcdSend(SET_Y|j, LCD_CMD ); 
+      LcdSend(SET_X|0, LCD_CMD);
+      while ( i-- )
+      {
+        LcdSend(0/*xff*/, LCD_DATA);
+      }  
+	}
 }
 
 /*--------------------------------------------------------------------------------------------------
@@ -207,21 +207,21 @@ void LcdClear()
 void LcdContrast ( uint8_t Contrast )
 {
     //  LCD Extended Commands.
-    LcdSend( FUNCTION_SET|FUNCTION_EXT, LCD_CMD );  // LCD Extended Commands.
+  LcdSend( FUNCTION_SET|FUNCTION_EXT, LCD_CMD );  // LCD Extended Commands.
 
     // Set LCD Vop (Contrast).
     if ( Contrast > 90 ) /* Limit by 8.5 V */
-        Contrast = 90;
-    LcdSend( SET_VOP | Contrast, LCD_CMD );
+      Contrast = 90;
+  LcdSend( SET_VOP | Contrast, LCD_CMD );
 
     //  LCD Standard Commands, horizontal addressing mode.
-    LcdSend( FUNCTION_SET, LCD_CMD );
+  LcdSend( FUNCTION_SET, LCD_CMD );
 }
 
 void LcdGotoXY(uint8_t X, uint8_t Y)
 {
     LcdSend( SET_X|X, LCD_CMD );
-    LcdSend( SET_Y|Y, LCD_CMD );
+    LcdSend( SET_Y|Y, LCD_CMD ); 
 }
 
 
@@ -241,95 +241,95 @@ void LcdGotoXY(uint8_t X, uint8_t Y)
 
 void LcdChr ( uint32_t Ctrl, const char* Str )
 {
-    unsigned char ch;
-    uint8_t Inverse;
+  unsigned char ch;
+  uint8_t Inverse;
 #if defined(BIG)
 #define INTERNAL_BIG_DOWN
-    uint32_t Big = Ctrl;
-#endif
-    Inverse = ((Ctrl & INVERSE) != 0);
-    LcdGotoXY((Ctrl/X_POSITION & 0x0F)*6 + ((Ctrl/X_OFFSET)& 0x3F),
-              (Ctrl/Y_POSITION) & 0x07);
-
-    Ctrl = Ctrl & 0x7F; /* Only Len */
-    while ( Ctrl != 0 )
+  uint32_t Big = Ctrl;
+#endif  
+  Inverse = ((Ctrl & INVERSE) != 0);
+  LcdGotoXY((Ctrl/X_POSITION & 0x0F)*6 + ((Ctrl/X_OFFSET)& 0x3F), 
+            (Ctrl/Y_POSITION) & 0x07);
+
+  Ctrl = Ctrl & 0x7F; /* Only Len */
+  while ( Ctrl != 0 )
+  {
+    const uint8_t* Start;
+
+    if ( (ch = *Str) != 0)
+      Str++;
+    Ctrl--;
+    if ( ch == 0 ) 
+      ch = ' ';
+    if ( (ch < 0x20) || (ch > 0x7b) )
     {
-        const uint8_t* Start;
-
-        if ( (ch = *Str) != 0)
-            Str++;
-        Ctrl--;
-        if ( ch == 0 )
-            ch = ' ';
-        if ( (ch < 0x20) || (ch > 0x7b) )
-        {
-            //  Convert to a printable character.
-            ch = 92;
-        }
-        ch = ch - 32;
+        //  Convert to a printable character.
+        ch = 92;
+    }
+    ch = ch - 32;
 
-        Start = &FontLookup[ch*4+ch];
+    Start = &FontLookup[ch*4+ch];
 
 #if defined(BIG)
-        if ( (Big & (BIG_UP|BIG_DOWN)) == 0 )
+    if ( (Big & (BIG_UP|BIG_DOWN)) == 0 )
 #endif
+    { 
+      int i;
+      for (i=0; i<=4; i++)
+      {
+        uint8_t E = Start[i];
+        if ( Inverse )
         {
-            int i;
-            for (i=0; i<=4; i++)
-            {
-                uint8_t E = Start[i];
-                if ( Inverse )
-                {
-                    E = ~E;
-                }
-                LcdSend( E, LCD_DATA );
-            }
-            if ( !Inverse )
-                LcdSend( 0, LCD_DATA );
-            else
-                LcdSend( 0xFF, LCD_DATA );
+          E = ~E;
         }
+        LcdSend( E, LCD_DATA );
+      }
+      if ( !Inverse )
+        LcdSend( 0, LCD_DATA );
+      else
+        LcdSend( 0xFF, LCD_DATA );
+    }
 #if defined(BIG)
+    else
+    {
+      int i;
+      for (i=0; i<=4; i++)
+      {
+        uint8_t Element = 0;
+        uint8_t E = Start[i];
+
+        if ( Big & BIG_UP )
+        {
+          if(E & 0x01) Element |= 0x03;
+          if(E & 0x02) Element |= 0x0C;
+          if(E & 0x04) Element |= 0x30;
+          if(E & 0x08) Element |= 0xC0;
+        }
         else
         {
-            int i;
-            for (i=0; i<=4; i++)
-            {
-                uint8_t Element = 0;
-                uint8_t E = Start[i];
-
-                if ( Big & BIG_UP )
-                {
-                    if(E & 0x01) Element |= 0x03;
-                    if(E & 0x02) Element |= 0x0C;
-                    if(E & 0x04) Element |= 0x30;
-                    if(E & 0x08) Element |= 0xC0;
-                }
-                else
-                {
-                    if(E & 0x10) Element |= 0x03;
-                    if(E & 0x20) Element |= 0x0C;
-                    if(E & 0x40) Element |= 0x30;
-                    if(E & 0x80) Element |= 0xC0;
-                }
-                if (Inverse)
-                    Element = ~Element;
-                LcdSend( Element, LCD_DATA );
-                LcdSend( Element, LCD_DATA );
-            } /* For */
-            if ( !Inverse )
-            {
-                LcdSend( 0, LCD_DATA );
-                LcdSend( 0, LCD_DATA );
-            }
-            else
-            {
-                LcdSend( 0xFF, LCD_DATA );
-                LcdSend( 0xFF, LCD_DATA );
-            }
+          if(E & 0x10) Element |= 0x03;
+          if(E & 0x20) Element |= 0x0C;
+          if(E & 0x40) Element |= 0x30;
+          if(E & 0x80) Element |= 0xC0;
         }
-#endif /* BIG */
+        if (Inverse)
+          Element = ~Element;
+        LcdSend( Element, LCD_DATA );
+        LcdSend( Element, LCD_DATA );
+      } /* For */
+      if ( !Inverse )
+      {
+        LcdSend( 0, LCD_DATA );
+        LcdSend( 0, LCD_DATA );
+      }
+      else
+      {
+        LcdSend( 0xFF, LCD_DATA );
+        LcdSend( 0xFF, LCD_DATA );
+      }
     }
+#endif /* BIG */
+  }
 }
 
 
@@ -347,31 +347,31 @@ void LcdChr ( uint32_t Ctrl, const char* Str )
 --------------------------------------------------------------------------------------------------*/
 void LcdSend ( uint8_t Data, LcdCmdData cd )
 {
-    int i;
-
-    if ( cd != LCD_CMD ) /* If data */
-    {
-        GPIOB->BSRR = 1<<LCD_DC_PIN; /* DC pin to hight */
-    }
+  int i;
+
+  if ( cd != LCD_CMD ) /* If data */
+  {
+    GPIOB->BSRR = 1<<LCD_DC_PIN; /* DC pin to hight */
+  }
+  else
+  {
+    GPIOB->BRR = 1<<LCD_DC_PIN; /* DC pin to low */
+  }
+  LCD_DELAY;  
+  i=8;
+  do
+  {
+    if ( Data & 0x80 )
+      GPIOB->BSRR = 1<<LCD_IN_PIN; /* IN pin to hight */
     else
-    {
-        GPIOB->BRR = 1<<LCD_DC_PIN; /* DC pin to low */
-    }
-    LCD_DELAY;
-    i=8;
-    do
-    {
-        if ( Data & 0x80 )
-            GPIOB->BSRR = 1<<LCD_IN_PIN; /* IN pin to hight */
-        else
-            GPIOB->BRR  = 1<<LCD_IN_PIN; /* IN pin to low */
-        LCD_DELAY;
-        Data = Data<<1; /* Some additional delay */
-        GPIOB->BSRR  = 1<<LCD_CLK_PIN; /* CLK pin to hight */
-        LCD_DELAY;
-        i--;
-        GPIOB->BRR  = 1<<LCD_CLK_PIN; /* CLK pin to low */
-    } while(i);
+      GPIOB->BRR  = 1<<LCD_IN_PIN; /* IN pin to low */
+	LCD_DELAY;
+    Data = Data<<1; /* Some additional delay */
+    GPIOB->BSRR  = 1<<LCD_CLK_PIN; /* CLK pin to hight */
+	LCD_DELAY;
+	i--;
+    GPIOB->BRR  = 1<<LCD_CLK_PIN; /* CLK pin to low */
+  }while(i);
 }
 
 /*--------------------------------------------------------------------------------------------------
@@ -394,13 +394,13 @@ void SystemInit()
 
 int main(void)
 {
-    RCC->CFGR |= (RCC_CFGR_HPRE_1|RCC_CFGR_HPRE_3); /* div 8 */
-    LcdInit();
-    LcdClear();
-    LcdChr ( Y_POSITION*1+X_POSITION*1+13, "Hello world" );
-    LcdChr ( Y_POSITION*2+X_POSITION*1+13+INVERSE+X_OFFSET*3, "Hello world" );
-    LcdChr ( Y_POSITION*4+X_POSITION*0+2+BIG_UP, "15" );
-    LcdChr ( Y_POSITION*5+X_POSITION*0+2+BIG_DOWN, "15" );
-    return 0;
+  RCC->CFGR |= (RCC_CFGR_HPRE_1|RCC_CFGR_HPRE_3); /* div 8 */
+  LcdInit();
+  LcdClear();
+  LcdChr ( Y_POSITION*1+X_POSITION*1+13, "Hello world" );
+  LcdChr ( Y_POSITION*2+X_POSITION*1+13+INVERSE+X_OFFSET*3, "Hello world" );
+  LcdChr ( Y_POSITION*4+X_POSITION*0+2+BIG_UP, "15" );  
+  LcdChr ( Y_POSITION*5+X_POSITION*0+2+BIG_DOWN, "15" );  
+  return 0;
 }
 #endif

+ 1 - 1
src/n3310.h

@@ -15,7 +15,7 @@ typedef enum
     LCD_CMD  = 0,
     LCD_DATA = 1
 } LcdCmdData;
-void LcdSend ( uint8_t data, LcdCmdData cd );
+void LcdSend    ( uint8_t data, LcdCmdData cd );
 
 /*--------------------------------------------------------------------------------------------------
                                  Public function prototypes

+ 583 - 584
src/ui.c

@@ -16,41 +16,40 @@ void Configure(void);
 
 static UserMenu_t* Menu;
 
-static CancelButton(void)
+static void CancelButton(void)
 {
-    if (!(Flags & (AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG)) && /* New values are set but not applied */
-            (DAC->DOR1 != 0 && DAC->DOR2 !=0 )) /* Only if the output is enabled 05.10.11 */
-    {
-        CurrentSettings.VoltageDAC = DAC->DOR1;
-        CurrentSettings.CurrentDAC = DAC->DOR2;
-    }
-    CurrentFunc(StartFunction);
-    return;
+  if (!(Flags & (AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG)) && /* New values are set but not applied */
+       (DAC->DOR1 != 0 && DAC->DOR2 !=0 )) /* Only if the output is enabled 05.10.11 */
+  {
+    CurrentSettings.VoltageDAC = DAC->DOR1;
+    CurrentSettings.CurrentDAC = DAC->DOR2;
+  }
+  CurrentFunc(StartFunction);
 }
 
 void HandleUserMenu(void)
 {
-    int NewValue;
-    SubConfig_t* SubConfig;
-
-    if ( Menu->IVFlag == MENU_V_FLAG)
-        SubConfig = &CurrentConfig.V;
-    else
-        SubConfig = &CurrentConfig.I;
-
-    NewValue = (Menu->Value - SubConfig->DACOffset)/ SubConfig->DACRamp;
-    if ( NewValue < 0 )
-        NewValue = 0;
-    if ( NewValue > 4095 )
-        NewValue = 4095;
-    if ( Menu->IVFlag == MENU_V_FLAG)
-        CurrentSettings.VoltageDAC = NewValue;
-    else
-        CurrentSettings.CurrentDAC = NewValue;
-    if ( Flags & (AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG) )
-        ApplyOut();
-    else
-        CurrentFunc(StartFunction);
+  int NewValue;
+  SubConfig_t* SubConfig;
+
+  if ( Menu->IVFlag == MENU_V_FLAG)
+    SubConfig = &CurrentConfig.V;
+  else
+    SubConfig = &CurrentConfig.I;
+
+  NewValue = (Menu->Value - SubConfig->DACOffset)/ SubConfig->DACRamp;
+  if ( NewValue < 0 )
+    NewValue = 0;
+  if ( NewValue > 4095 )
+    NewValue = 4095;
+  if ( Menu->IVFlag == MENU_V_FLAG)
+    CurrentSettings.VoltageDAC = NewValue;
+  else
+    CurrentSettings.CurrentDAC = NewValue;
+  if ( Flags & (AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG) )
+    ApplyOut();
+  else
+    CurrentFunc(StartFunction);
 }
 
 #define MENU_0       0
@@ -71,158 +70,158 @@ void HandleUserMenu(void)
 
 static void DisplayMenu(int IsSetMenu)
 {
-    int i;
-    char* Text;
-
-    for (i=MENU_0; i<=MENU_13; i++)
-    {
-        int x = i/5 * 5;
-        int y = i%5 + 1;
-        int TextPos = (i< MENU_7)?i:i-1;
-        Text = CurrentConfig.Menu[TextPos].Text;
-        LcdChr(X_POSITION*x+Y_POSITION*y+4 + (i==MenuPos)*INVERSE, Text);
-    }
-
-    if (!IsSetMenu)
-        Text = "Cncl";
-    else
-        Text = "Retu";
-    LcdChr(X_POSITION*5+Y_POSITION*3+4 + (MENU_CNCL_RET==MenuPos)*INVERSE, Text);
+  int i;
+  char* Text;
+
+  for (i=MENU_0; i<=MENU_13;i++)
+  {
+    int x = i/5 * 5;
+    int y = i%5 + 1;
+    int TextPos = (i< MENU_7)?i:i-1;
+    Text = CurrentConfig.Menu[TextPos].Text;
+    LcdChr(X_POSITION*x+Y_POSITION*y+4 + (i==MenuPos)*INVERSE, Text);
+  }
+
+  if (!IsSetMenu)
+    Text = "Cncl";
+  else
+    Text = "Retu";
+  LcdChr(X_POSITION*5+Y_POSITION*3+4 + (MENU_CNCL_RET==MenuPos)*INVERSE, Text);
 }
 
 void ConfigureTheMenu(void);
 
 void UConfigureTheMenu()
 {
-    char* Text;
-    SubConfig_t* Config;
+  char* Text;
+  SubConfig_t* Config;
 
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        MenuPos = 0;
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = 0;
 
-        if (Menu->IVFlag != MENU_I_FLAG) /* It can be polluted */
-            Menu->IVFlag = MENU_V_FLAG;
-        else
-            Menu->IVFlag = MENU_I_FLAG;
-
-        if (Menu->Text[0] == 0)
-            Menu->Text[0] = '0';
-        if (Menu->Text[1] == 0)
-            Menu->Text[1] = '1';
-        if (Menu->Text[2] == 0)
-            Menu->Text[2] = '2';
-        if (Menu->Text[3] == 0)
-            Menu->Text[3] = '3';
-        goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+    if (Menu->IVFlag != MENU_I_FLAG) /* It can be polluted */
+      Menu->IVFlag = MENU_V_FLAG;
+    else
+      Menu->IVFlag = MENU_I_FLAG;
+
+    if (Menu->Text[0] == 0)
+      Menu->Text[0] = '0';
+    if (Menu->Text[1] == 0)
+      Menu->Text[1] = '1';
+    if (Menu->Text[2] == 0)
+      Menu->Text[2] = '2';
+    if (Menu->Text[3] == 0)
+      Menu->Text[3] = '3';
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+      case KEY_DOWN:
+        switch(MenuPos)
         {
-        case KEY_UP:
-        case KEY_DOWN:
-            switch(MenuPos)
-            {
-            case 0:
-                if (Menu->IVFlag & MENU_I_FLAG)
-                    Menu->IVFlag = MENU_V_FLAG;
-                else
-                    Menu->IVFlag = MENU_I_FLAG;
-                goto redraw;
-            case 1:
-                if (EncCounter > 999 )
-                    EncCounter = 999;
-                Menu->Value = EncCounter*10 + 1; /* it's better to see changes from 9001 to 9000 that 9000 to 8999 */
-                goto redraw;
-            default:
-                if (EncCounter > 'z')
-                    EncCounter = 'z';
-                Menu->Text[MenuPos-2] = EncCounter;
-                goto redraw;
-            }
-        case KEY_ENTER:
-            switch(MenuPos)
-            {
-            case 0:
-                if (Menu->IVFlag & MENU_V_FLAG)
-                    Menu->IVFlag = MENU_V_FLAG;
-                else
-                    Menu->IVFlag = MENU_I_FLAG;
-                EncCounter = Menu->Value;
-                break;
-            default:
-                EncCounter = Menu->Text[MenuPos - 1];
-            }
-            MenuPos++;
-            if (MenuPos == 6)
-                MenuPos = 0;
+          case 0:
+            if (Menu->IVFlag & MENU_I_FLAG)
+              Menu->IVFlag = MENU_V_FLAG;
+            else
+              Menu->IVFlag = MENU_I_FLAG;
+            goto redraw;
+          case 1:
+            if (EncCounter > 999 )
+              EncCounter = 999;
+            Menu->Value = EncCounter*10 + 1; /* it's better to see changes from 9001 to 9000 that 9000 to 8999 */
+            goto redraw;
+          default:
+            if (EncCounter > 'z')
+              EncCounter = 'z';
+            Menu->Text[MenuPos-2] = EncCounter;
             goto redraw;
         }
+      case KEY_ENTER:
+        switch(MenuPos)
+        {
+          case 0:
+            if (Menu->IVFlag & MENU_V_FLAG)
+              Menu->IVFlag = MENU_V_FLAG;
+            else
+              Menu->IVFlag = MENU_I_FLAG;
+            EncCounter = Menu->Value;
+            break;
+          default:
+            EncCounter = Menu->Text[MenuPos - 1];
+        }
+        MenuPos++;
+        if (MenuPos == 6)
+          MenuPos = 0;
+        goto redraw;
     }
-    if ( (Event & EV_MASK) == EV_KEY_LONG &&
-            (Event & KEY_MASK) == KEY_ENTER )
-    {
-        CurrentFunc(ConfigureTheMenu);
-    }
-    return;
+  }
+  if ( (Event & EV_MASK) == EV_KEY_LONG &&
+       (Event & KEY_MASK) == KEY_ENTER )
+  {
+    CurrentFunc(ConfigureTheMenu);
+  }
+  return;
 
 redraw:
-    if (Menu->IVFlag != MENU_I_FLAG) /* Voltage */
-    {
-        Text = " Voltage";
-        Config = &CurrentConfig.V;
-    }
-    else
-    {
-        Text = " Current";
-        Config = &CurrentConfig.I;
-    }
-    LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuPos)*INVERSE, Text);
-    OutValueSmall(3, 3, Menu->Value, Config->DotPosition, MenuPos == 1);
-    LcdChr(X_POSITION*2+Y_POSITION*5+1 + (2==MenuPos)*INVERSE, &Menu->Text[0]);
-    LcdChr(X_POSITION*3+Y_POSITION*5+1 + (3==MenuPos)*INVERSE, &Menu->Text[1]);
-    LcdChr(X_POSITION*4+Y_POSITION*5+1 + (4==MenuPos)*INVERSE, &Menu->Text[2]);
-    LcdChr(X_POSITION*5+Y_POSITION*5+1 + (5==MenuPos)*INVERSE, &Menu->Text[3]);
+  if (Menu->IVFlag != MENU_I_FLAG) /* Voltage */
+  {
+    Text = " Voltage";
+    Config = &CurrentConfig.V; 
+  }
+  else
+  {
+    Text = " Current";
+    Config = &CurrentConfig.I; 
+  }
+  LcdChr(X_POSITION*0+Y_POSITION*1+14 + (0==MenuPos)*INVERSE, Text);
+  OutValueSmall(3, 3, Menu->Value, Config->DotPosition, MenuPos == 1);
+  LcdChr(X_POSITION*2+Y_POSITION*5+1 + (2==MenuPos)*INVERSE, &Menu->Text[0]);
+  LcdChr(X_POSITION*3+Y_POSITION*5+1 + (3==MenuPos)*INVERSE, &Menu->Text[1]);
+  LcdChr(X_POSITION*4+Y_POSITION*5+1 + (4==MenuPos)*INVERSE, &Menu->Text[2]);
+  LcdChr(X_POSITION*5+Y_POSITION*5+1 + (5==MenuPos)*INVERSE, &Menu->Text[3]);
 }
 
 
 void YesNoCalib(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = 0;
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        MenuPos = 0;
+      case KEY_UP:
+      case KEY_DOWN:
+        if(MenuPos == 0)
+          MenuPos++;
+        else
+          MenuPos = 0;
         goto redraw;
+      case KEY_ENTER:
+        if(MenuPos)
+          CurrentFunc(CalibrationMenu);
+        else
+          CurrentFunc(Configure);
     }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_UP:
-        case KEY_DOWN:
-            if(MenuPos == 0)
-                MenuPos++;
-            else
-                MenuPos = 0;
-            goto redraw;
-        case KEY_ENTER:
-            if(MenuPos)
-                CurrentFunc(CalibrationMenu);
-            else
-                CurrentFunc(Configure);
-        }
-    }
-    return;
+  }
+  return;
 redraw:
-    LcdChr(X_POSITION*0+Y_POSITION*1+14, "Do you want");
-    LcdChr(X_POSITION*0+Y_POSITION*2+14, "to start the");
-    LcdChr(X_POSITION*0+Y_POSITION*3+14, "calibration");
-    LcdChr(X_POSITION*0+Y_POSITION*5+7 + (0==MenuPos)*INVERSE,  "No");
-    LcdChr(X_POSITION*7+Y_POSITION*5+7 + (0!=MenuPos)*INVERSE,  "Yes");
+  LcdChr(X_POSITION*0+Y_POSITION*1+14, "Do you want");
+  LcdChr(X_POSITION*0+Y_POSITION*2+14, "to start the");
+  LcdChr(X_POSITION*0+Y_POSITION*3+14, "calibration");
+  LcdChr(X_POSITION*0+Y_POSITION*5+7 + (0==MenuPos)*INVERSE,  "No");
+  LcdChr(X_POSITION*7+Y_POSITION*5+7 + (0!=MenuPos)*INVERSE,  "Yes");
 }
 
 #define  CONF_MENU_EDIT 0
@@ -233,569 +232,569 @@ redraw:
 
 void Configure(void)
 {
-    if (Event == EV_FUNC_FIRST)
+ if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = CONF_CONTRAST;
+    goto redraw;
+  } 
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        MenuPos = CONF_CONTRAST;
+       case KEY_DOWN:
+        if ( MenuPos == 0 )
+          MenuPos = 4;
+        else
+          MenuPos = MenuPos - 1;
         goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if ( MenuPos == 4 )
+          MenuPos = 0;
+        else
+          MenuPos = MenuPos + 1;
+        goto redraw;
+      case KEY_ENTER:
+        switch(MenuPos)
         {
-        case KEY_DOWN:
-            if ( MenuPos == 0 )
-                MenuPos = 4;
+          case CONF_MENU_EDIT: /* Menu set up */
+            CurrentFunc(ConfigureTheMenu);
+            return;
+          case CONF_CALIBR: /* Calibration */
+            CurrentFunc(YesNoCalib);
+            return;
+          case CONF_BACKUP: /* Save to backup */
+            if ( Flags&BACKUP_SAVE_FLAG )
+              Flags &= ~BACKUP_SAVE_FLAG;
             else
-                MenuPos = MenuPos - 1;
+              Flags |= BACKUP_SAVE_FLAG;
             goto redraw;
-        case KEY_UP:
-            if ( MenuPos == 4 )
-                MenuPos = 0;
+          case CONF_CLOCK: /* Time */
+#if defined(CLOCK_ENABLED)
+            if (IS_ON_CLOCK)
+            {
+              CurrentFunc(SetupTheClock);
+              return;
+            }
             else
-                MenuPos = MenuPos + 1;
-            goto redraw;
-        case KEY_ENTER:
-            switch(MenuPos)
             {
-            case CONF_MENU_EDIT: /* Menu set up */
-                CurrentFunc(ConfigureTheMenu);
-                return;
-            case CONF_CALIBR: /* Calibration */
-                CurrentFunc(YesNoCalib);
-                return;
-            case CONF_BACKUP: /* Save to backup */
-                if ( Flags&BACKUP_SAVE_FLAG )
-                    Flags &= ~BACKUP_SAVE_FLAG;
-                else
-                    Flags |= BACKUP_SAVE_FLAG;
-                goto redraw;
-            case CONF_CLOCK: /* Time */
-#if defined(CLOCK_ENABLED)
-                if (IS_ON_CLOCK)
-                {
-                    CurrentFunc(SetupTheClock);
-                    return;
-                }
-                else
-                {
-                    SwitchOnTheClock();
-                }
-#endif
-                goto redraw;
-            case CONF_CONTRAST:
-                AfterContrast = StartFunction;
-                CurrentFunc(ContrastMenu);
+              SwitchOnTheClock();
             }
+#endif
+            goto redraw;
+          case CONF_CONTRAST:
+            AfterContrast = StartFunction;
+            CurrentFunc(ContrastMenu);
         }
     }
-    return;
+  }
+  return;   
 
 redraw:
-    LcdChr (Y_POSITION*1+X_POSITION*0+14+(CONF_MENU_EDIT==MenuPos)*INVERSE, "Menu Edit" );
-    LcdChr (Y_POSITION*2+X_POSITION*0+14+(CONF_CALIBR==MenuPos)*INVERSE, "Calibration" );
-    LcdChr (Y_POSITION*3+X_POSITION*1+14+(CONF_BACKUP==MenuPos)*INVERSE, "Save Backup");
-    LcdChr (Y_POSITION*3+X_POSITION*0+1+ (CONF_BACKUP==MenuPos)*INVERSE, Flags&BACKUP_SAVE_FLAG?"+":"-" );
-    LcdChr (Y_POSITION*4+X_POSITION*0+14+(CONF_CLOCK==MenuPos)*INVERSE,
+  LcdChr (Y_POSITION*1+X_POSITION*0+14+(CONF_MENU_EDIT==MenuPos)*INVERSE, "Menu Edit" );
+  LcdChr (Y_POSITION*2+X_POSITION*0+14+(CONF_CALIBR==MenuPos)*INVERSE, "Calibration" );
+  LcdChr (Y_POSITION*3+X_POSITION*1+14+(CONF_BACKUP==MenuPos)*INVERSE, "Save Backup");
+  LcdChr (Y_POSITION*3+X_POSITION*0+1+ (CONF_BACKUP==MenuPos)*INVERSE, Flags&BACKUP_SAVE_FLAG?"+":"-" );
+  LcdChr (Y_POSITION*4+X_POSITION*0+14+(CONF_CLOCK==MenuPos)*INVERSE, 
 #if defined(CLOCK_ENABLED)
-            IS_ON_CLOCK?"Setup time":"Time on"
+                              IS_ON_CLOCK?"Setup time":"Time on" 
 #else
-            "Reserved"
-#endif
-           );
-    LcdChr (Y_POSITION*5+X_POSITION*0+14+(CONF_CONTRAST==MenuPos)*INVERSE, "Contrast" );
+                              "Reserved"
+#endif  
+                                                       );
+  LcdChr (Y_POSITION*5+X_POSITION*0+14+(CONF_CONTRAST==MenuPos)*INVERSE, "Contrast" );
 
 }
 
 void ConfigureTheMenu(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = MENU_CNCL_RET;
+    goto redraw;
+  } 
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        MenuPos = MENU_CNCL_RET;
+      case KEY_DOWN:
+        if ( MenuPos == 0 )
+          MenuPos = 14;
+        else
+          MenuPos = MenuPos - 1;
         goto redraw;
-    }
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if ( MenuPos == 14 )
+          MenuPos = 0;
+        else
+          MenuPos = MenuPos + 1;
+        goto redraw;
+      case KEY_ENTER:
+        switch(MenuPos)
         {
-        case KEY_DOWN:
-            if ( MenuPos == 0 )
-                MenuPos = 14;
-            else
-                MenuPos = MenuPos - 1;
-            goto redraw;
-        case KEY_UP:
-            if ( MenuPos == 14 )
-                MenuPos = 0;
-            else
-                MenuPos = MenuPos + 1;
-            goto redraw;
-        case KEY_ENTER:
-            switch(MenuPos)
-            {
-            case MENU_0:
-            case MENU_1:
-            case MENU_2:
-            case MENU_3:
-            case MENU_4:
-            case MENU_5:
-            case MENU_6:
-                Menu=&CurrentConfig.Menu[MenuPos];
-                goto usermenu;
-            case MENU_7:
-            case MENU_8:
-            case MENU_9:
-            case MENU_10:
-            case MENU_11:
-            case MENU_12:
-            case MENU_13:
-                Menu=&CurrentConfig.Menu[MenuPos - 1];
-                goto usermenu;
-            default:
-                CurrentFunc(SaveMenu);
-                return;
-            } /* switch MenuPos*/
-        } /* switch key */
-    }
-    return;
+          case MENU_0:
+          case MENU_1:
+          case MENU_2:
+          case MENU_3:
+          case MENU_4:
+          case MENU_5:
+          case MENU_6:
+            Menu=&CurrentConfig.Menu[MenuPos];
+            goto usermenu;
+          case MENU_7:
+          case MENU_8:
+          case MENU_9:
+          case MENU_10:
+          case MENU_11:
+          case MENU_12:
+          case MENU_13:
+            Menu=&CurrentConfig.Menu[MenuPos - 1];
+            goto usermenu;
+          default:
+            CurrentFunc(SaveMenu);
+            return;
+        } /* switch MenuPos*/
+    } /* switch key */
+  }
+  return;
 usermenu:
-    CurrentFunc(UConfigureTheMenu);
+  CurrentFunc(UConfigureTheMenu);
 
-    return;
+  return;
 redraw:
-    DisplayMenu(1);
+  DisplayMenu(1);
 }
 
 void PredefinedMenu(void)
 {
-    /* 1    6    10 */
-    /* 2    7    11  */
-    /* 3    cncl 12 */
-    /* 4    8    13  */
-    /* 5    9    14  */
-
-    if (Event == EV_FUNC_FIRST)
+ /* 1    6    10 */
+ /* 2    7    11  */
+ /* 3    cncl 12 */
+ /* 4    8    13  */
+ /* 5    9    14  */
+
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = MENU_CNCL_RET;
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        MenuPos = MENU_CNCL_RET;
+      case KEY_DOWN:
+        if ( MenuPos == 0 )
+          MenuPos = 14;
+        else
+          MenuPos = MenuPos - 1;
         goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
+      case KEY_UP:
+        if ( MenuPos == 14 )
+          MenuPos = 0;
+        else
+          MenuPos = MenuPos + 1;
+        goto redraw;
+      case KEY_ENTER:
+        switch(MenuPos)
         {
-        case KEY_DOWN:
-            if ( MenuPos == 0 )
-                MenuPos = 14;
-            else
-                MenuPos = MenuPos - 1;
-            goto redraw;
-        case KEY_UP:
-            if ( MenuPos == 14 )
-                MenuPos = 0;
-            else
-                MenuPos = MenuPos + 1;
-            goto redraw;
-        case KEY_ENTER:
-            switch(MenuPos)
-            {
-            case MENU_CNCL_RET: /* Default cancel input*/
-                CancelButton();
-                return;
-            case MENU_0:
-            case MENU_1:
-            case MENU_2:
-            case MENU_3:
-            case MENU_4:
-            case MENU_5:
-            case MENU_6:
-                Menu=&CurrentConfig.Menu[MenuPos];
-                goto usermenu;
-            case MENU_7:
-            case MENU_8:
-            case MENU_9:
-            case MENU_10:
-            case MENU_11:
-            case MENU_12:
-            case MENU_13:
-                Menu=&CurrentConfig.Menu[MenuPos-1];
-                goto usermenu;
-            } /* switch MenuPos*/
-        } /* switch key */
-    }
-    return;
+          case MENU_CNCL_RET: /* Default cancel input*/
+            CancelButton();
+            return;
+          case MENU_0:
+          case MENU_1:
+          case MENU_2:
+          case MENU_3:
+          case MENU_4:
+          case MENU_5:
+          case MENU_6:
+            Menu=&CurrentConfig.Menu[MenuPos];
+            goto usermenu;
+          case MENU_7:
+          case MENU_8:
+          case MENU_9:
+          case MENU_10:
+          case MENU_11:
+          case MENU_12:
+          case MENU_13:
+            Menu=&CurrentConfig.Menu[MenuPos-1];
+            goto usermenu;
+        } /* switch MenuPos*/
+    } /* switch key */
+  }
+  return;
 usermenu:
-    if ( (Menu->IVFlag != MENU_I_FLAG) &&
-            (Menu->IVFlag != MENU_V_FLAG))  /* Do nothing - invalid menu */
-        return;
-    CurrentFunc(HandleUserMenu);
+  if ( (Menu->IVFlag != MENU_I_FLAG) &&
+     (Menu->IVFlag != MENU_V_FLAG))  /* Do nothing - invalid menu */
     return;
+  CurrentFunc(HandleUserMenu);
+  return;
 redraw:
-    DisplayMenu(0);
+  DisplayMenu(0);
 }
 
 
 void ApplyOut(void)
 {
-    int Delta;
-
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        goto redraw;
-    }
-    if ( CurrentSettings.VoltageDAC == DAC->DOR1 &&
-            CurrentSettings.CurrentDAC == DAC->DOR2 )
-    {
-        CurrentFunc(StartFunction);
-        return;
-    }
-
-    Delta = (int)CurrentSettings.VoltageDAC - (int)(DAC->DOR1);
-    if ( Delta > 50 )
-        Delta = 50;
-    if ( Delta < -50)
-        Delta = -50;
-    DAC_V = (int)(DAC->DOR1) + Delta;
-
-    Delta = (int)CurrentSettings.CurrentDAC - (int)(DAC->DOR2);
-    if ( Delta > 50 )
-        Delta = 50;
-    if ( Delta < -50)
-        Delta = -50;
-    DAC_I = (int)(DAC->DOR2) + Delta;
-
-    OutValueSmall(2, 9, HumanV, CurrentConfig.V.DotPosition, 0);
-    OutValueSmall(5, 9, HumanI, CurrentConfig.I.DotPosition, 0);
-    return;
+  int Delta;
+
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    goto redraw;
+  }
+  if ( CurrentSettings.VoltageDAC == DAC->DOR1 &&
+          CurrentSettings.CurrentDAC == DAC->DOR2 )
+  {
+     CurrentFunc(StartFunction);
+     return;
+  }
+
+  Delta = (int)CurrentSettings.VoltageDAC - (int)(DAC->DOR1);
+  if ( Delta > 50 )
+    Delta = 50;
+  if ( Delta < -50)
+    Delta = -50;
+  DAC_V = (int)(DAC->DOR1) + Delta;
+
+  Delta = (int)CurrentSettings.CurrentDAC - (int)(DAC->DOR2);
+  if ( Delta > 50 )
+    Delta = 50;
+  if ( Delta < -50)
+    Delta = -50;
+  DAC_I = (int)(DAC->DOR2) + Delta;
+
+  OutValueSmall(2, 9, HumanV, CurrentConfig.V.DotPosition, 0);
+  OutValueSmall(5, 9, HumanI, CurrentConfig.I.DotPosition, 0);
+  return;
 
 redraw:
-    LcdChr(Y_POSITION*1+X_POSITION*0+14, " Applying...");
-    OutValue(2, 0, VoltageFromDac(), CurrentConfig.V.DotPosition, 0xFF);
-    OutValue(4, 0, VoltageFromDac(), CurrentConfig.V.DotPosition, 0xFF);
+  LcdChr(Y_POSITION*1+X_POSITION*0+14, " Applying...");
+  OutValue(2, 0, VoltageFromDac(), CurrentConfig.V.DotPosition, 0xFF);
+  OutValue(4, 0, VoltageFromDac(), CurrentConfig.V.DotPosition, 0xFF);
 }
 
 uint32_t OriginalValue;
 void SetNewCurrent(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        LcdChr ( Y_POSITION*1+X_POSITION*0+14, "New current" );
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    LcdChr ( Y_POSITION*1+X_POSITION*0+14, "New current" );
 
-        EncCounter = CurrentSettings.CurrentDAC;
-        OriginalValue = CurrentSettings.CurrentDAC;
-        goto redraw;
-    }
+    EncCounter = CurrentSettings.CurrentDAC;
+    OriginalValue = CurrentSettings.CurrentDAC;
+    goto redraw;
+  } 
 
-    if ( (Event& EV_MASK) != EV_KEY_PRESSED )
-        return;
+  if ( (Event& EV_MASK) != EV_KEY_PRESSED )
+    return;
 
-    switch (Event & KEY_MASK)
-    {
+  switch (Event & KEY_MASK)
+  {
     case KEY_UP:
     case KEY_DOWN:
-        CurrentSettings.CurrentDAC = EncCounter;
-        if (Flags&IMEDDIATE_APPLY_FLAG)
-            DAC_I	= EncCounter;
-        goto redraw;
+      CurrentSettings.CurrentDAC = EncCounter;
+	  if (Flags&IMEDDIATE_APPLY_FLAG)
+	  DAC_I	= EncCounter;
+      goto redraw;
     case KEY_ENTER:
-        if ( CurrentSettings.CurrentDAC != OriginalValue ) /* Current is changed */
-        {
-            if ( (Flags&(AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG)) )
-                CurrentFunc(ApplyOut);
-            else
-                CurrentFunc(StartFunction);
-        }
-        else
+      if ( CurrentSettings.CurrentDAC != OriginalValue ) /* Current is changed */
+      {
+          if ( (Flags&(AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG)) )
+            CurrentFunc(ApplyOut);
+          else
             CurrentFunc(StartFunction);
-    }
-    return;
+      }
+      else
+        CurrentFunc(StartFunction);
+  }
+  return;
 redraw:
-    OutValue(3,2, CurrentFromDac(), CurrentConfig.I.DotPosition, 0xFF);
-    OutValueSmall(5, 0, HumanI, CurrentConfig.I.DotPosition, 0);
+  OutValue(3,2, CurrentFromDac(), CurrentConfig.I.DotPosition, 0xFF);
+  OutValueSmall(5, 0, HumanI, CurrentConfig.I.DotPosition, 0);
 }
 
 void SetNewVoltage(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-        LcdChr ( Y_POSITION*1+X_POSITION*0+14, "New voltage" );
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    LcdChr ( Y_POSITION*1+X_POSITION*0+14, "New voltage" );
 
-        EncCounter = CurrentSettings.VoltageDAC;
-        OriginalValue = CurrentSettings.VoltageDAC;
-        goto redraw;
-    }
+    EncCounter = CurrentSettings.VoltageDAC;
+    OriginalValue = CurrentSettings.VoltageDAC;
+    goto redraw;
+  } 
 
-    if ( (Event& EV_MASK) != EV_KEY_PRESSED )
-        return;
+  if ( (Event& EV_MASK) != EV_KEY_PRESSED )
+    return;
 
-    switch (Event & KEY_MASK)
-    {
+  switch (Event & KEY_MASK)
+  {
     case KEY_UP:
     case KEY_DOWN:
-        CurrentSettings.VoltageDAC = EncCounter;
-        if (Flags&IMEDDIATE_APPLY_FLAG)
-            DAC_V	= EncCounter;
-        goto redraw;
+      CurrentSettings.VoltageDAC = EncCounter;
+	  if (Flags&IMEDDIATE_APPLY_FLAG)
+	  DAC_V	= EncCounter;
+      goto redraw;
     case KEY_ENTER:
-        if ( CurrentSettings.VoltageDAC != OriginalValue ) /* Voltage is changed */
-        {
-            if ( (Flags&(AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG)) )
-                CurrentFunc(ApplyOut);
-            else
-                CurrentFunc(StartFunction);
-        }
-        else
-            CurrentFunc(SetNewCurrent);
-    }
-    return;
+      if ( CurrentSettings.VoltageDAC != OriginalValue ) /* Voltage is changed */
+      {
+          if ( (Flags&(AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG)) )
+            CurrentFunc(ApplyOut);
+          else
+            CurrentFunc(StartFunction);
+      }
+      else
+        CurrentFunc(SetNewCurrent);
+  }
+  return;
 redraw:
-    OutValue(3,2, VoltageFromDac(), CurrentConfig.V.DotPosition, 0xFF);
-    OutValueSmall(5, 0, HumanV, CurrentConfig.V.DotPosition, 0);
+  OutValue(3,2, VoltageFromDac(), CurrentConfig.V.DotPosition, 0xFF);
+  OutValueSmall(5, 0, HumanV, CurrentConfig.V.DotPosition, 0);
 }
 
 void SmallSettings(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = 2; /* Cancel */
+    goto redraw;
+  }
+
+  if ( (Event & EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        MenuPos = 2; /* Cancel */
+      case KEY_UP:
+        MenuPos++;
+        if ( MenuPos > 5 )
+          MenuPos = 0;
         goto redraw;
-    }
-
-    if ( (Event & EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
+      case KEY_DOWN:
+        if ( MenuPos == 0 )
+          MenuPos = 5;
+        else
+          MenuPos--;
+        goto redraw;
+      case KEY_ENTER:
+        switch(MenuPos)
         {
-        case KEY_UP:
-            MenuPos++;
-            if ( MenuPos > 5 )
-                MenuPos = 0;
-            goto redraw;
-        case KEY_DOWN:
-            if ( MenuPos == 0 )
-                MenuPos = 5;
+          case 0: /* Configuration */
+            CurrentFunc(Configure);
+            return;
+          case 1:
+            if (Flags&AUTO_APPLY_FLAG)
+            {
+              Flags &= ~AUTO_APPLY_FLAG;
+              Flags |= IMEDDIATE_APPLY_FLAG;
+            }
+            else if (Flags & IMEDDIATE_APPLY_FLAG)
+            {
+              Flags &= ~(AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG);
+            }
             else
-                MenuPos--;
-            goto redraw;
-        case KEY_ENTER:
-            switch(MenuPos)
             {
-            case 0: /* Configuration */
-                CurrentFunc(Configure);
-                return;
-            case 1:
-                if (Flags&AUTO_APPLY_FLAG)
-                {
-                    Flags &= ~AUTO_APPLY_FLAG;
-                    Flags |= IMEDDIATE_APPLY_FLAG;
-                }
-                else if (Flags & IMEDDIATE_APPLY_FLAG)
-                {
-                    Flags &= ~(AUTO_APPLY_FLAG|IMEDDIATE_APPLY_FLAG);
-                }
-                else
-                {
-                    Flags |= AUTO_APPLY_FLAG;
-                }
-                goto redraw;
-            case 2: /* Cancel */
-                CancelButton();
-                return;
-            case 3: /* Current graph */
+              Flags |= AUTO_APPLY_FLAG;
+            }
+            goto redraw;
+          case 2: /* Cancel */
+            CancelButton();
+            return;
+          case 3: /* Current graph */
 #if defined(GRAPH)
-                GraphData.GraphArray = IGraphArray;
-                GraphData.DotPosition = CurrentConfig.I.DotPosition;
-                CurrentFunc(DisplayGraph);
+            GraphData.GraphArray = IGraphArray;
+            GraphData.DotPosition = CurrentConfig.I.DotPosition;
+            CurrentFunc(DisplayGraph);
 #endif
-                return;
-            case 4: /* Voltage graph */
+            return;
+          case 4: /* Voltage graph */
 #if defined(GRAPH)
-                GraphData.GraphArray = VGraphArray;
-                GraphData.DotPosition = CurrentConfig.V.DotPosition;
-                CurrentFunc(DisplayGraph);
-                return;
+            GraphData.GraphArray = VGraphArray;
+            GraphData.DotPosition = CurrentConfig.V.DotPosition;
+            CurrentFunc(DisplayGraph);
+            return;
 #endif
-            case 5: /* Timer set up */
+          case 5: /* Timer set up */
 #if defined(CLOCK_ENABLED)
-                if (IS_ON_CLOCK)
-                    CurrentFunc(TimerSetup);
+            if (IS_ON_CLOCK)
+              CurrentFunc(TimerSetup);
 #endif
-                return;
+            return;
 
-            } /* switch MenuPos*/
-        } /* switch key */
-    }
-    return;
+        } /* switch MenuPos*/
+    } /* switch key */
+  }
+  return;
 redraw:
-    LcdChr(14+1*Y_POSITION+0*X_POSITION + (MenuPos==0?INVERSE:0), "Settings");
-    LcdChr(
+  LcdChr(14+1*Y_POSITION+0*X_POSITION + (MenuPos==0?INVERSE:0), "Settings");
+  LcdChr(
 #if !defined(CLOCK_ENABLED)
-        14
+  14
 #else
-        5
-#endif
-        + 2*Y_POSITION+0*X_POSITION + (MenuPos==1?INVERSE:0),
-        ( Flags & AUTO_APPLY_FLAG )?
-        "Auto":
-        ( (Flags & IMEDDIATE_APPLY_FLAG)? "Immd":"Manu"));
-    LcdChr(14+3*Y_POSITION+0*X_POSITION + (MenuPos==2?INVERSE:0), "Cancel");
+  5
+#endif  
+     + 2*Y_POSITION+0*X_POSITION + (MenuPos==1?INVERSE:0), 
+    ( Flags & AUTO_APPLY_FLAG )?
+	      "Auto":
+	  ( (Flags & IMEDDIATE_APPLY_FLAG)? "Immd":"Manu"));
+  LcdChr(14+3*Y_POSITION+0*X_POSITION + (MenuPos==2?INVERSE:0), "Cancel");
 #if defined(GRAPH)
-    LcdChr(14+4*Y_POSITION+0*X_POSITION + (MenuPos==3?INVERSE:0), "I Graph");
-    LcdChr(14+5*Y_POSITION+0*X_POSITION + (MenuPos==4?INVERSE:0), "V Graph");
+  LcdChr(14+4*Y_POSITION+0*X_POSITION + (MenuPos==3?INVERSE:0), "I Graph");
+  LcdChr(14+5*Y_POSITION+0*X_POSITION + (MenuPos==4?INVERSE:0), "V Graph");
 #else
-    LcdChr(14+4*Y_POSITION+0*X_POSITION + (MenuPos==3?INVERSE:0), "Reserved");
-    LcdChr(14+5*Y_POSITION+0*X_POSITION + (MenuPos==4?INVERSE:0), "Reserved");
+  LcdChr(14+4*Y_POSITION+0*X_POSITION + (MenuPos==3?INVERSE:0), "Reserved");
+  LcdChr(14+5*Y_POSITION+0*X_POSITION + (MenuPos==4?INVERSE:0), "Reserved");
 #endif
 #if defined(CLOCK_ENABLED)
-    LcdChr(8+2*Y_POSITION+6*X_POSITION + (MenuPos==5?INVERSE:0), (IS_ON_CLOCK)? "Timer":"");
+  LcdChr(8+2*Y_POSITION+6*X_POSITION + (MenuPos==5?INVERSE:0), (IS_ON_CLOCK)? "Timer":"");
 #endif
 }
 
 #if defined(CLOCK_ENABLED)
 static void ApplyWithDelay(void)
 {
-    if (Event == EV_FUNC_FIRST)
-    {
-        LcdBlank(); /* Clear screen */
-    }
-
-    if ( (Event& EV_MASK) == EV_KEY_PRESSED  &&
-            (Event & KEY_MASK) == KEY_CLOCK )
-    {
-        RemainTimerValue = TimerValue;
-        CurrentFunc(ApplyOut);
-    }
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+  }
+
+  if ( (Event& EV_MASK) == EV_KEY_PRESSED  && 
+       (Event & KEY_MASK) == KEY_CLOCK )
+  {
+    RemainTimerValue = TimerValue;
+    CurrentFunc(ApplyOut);
+  }
 }
 #endif
 
 void StartFunction(void)
 {
-    if (Event == EV_FUNC_FIRST)
+  if (Event == EV_FUNC_FIRST)
+  {
+    LcdBlank(); /* Clear screen */
+    MenuPos = 0; /* There are no key ENTER pressed */
+    goto redraw;
+  }
+
+  if ( (Event& EV_MASK) == EV_KEY_PRESSED )
+  {
+    switch (Event & KEY_MASK)
     {
-        LcdBlank(); /* Clear screen */
-        MenuPos = 0; /* There are no key ENTER pressed */
+      case KEY_DOWN:
+        CurrentFunc(SmallSettings);
+        return;
+      case KEY_UP:
+        CurrentFunc(PredefinedMenu);
+        return;
+      case KEY_ADC:
         goto redraw;
-    }
-
-    if ( (Event& EV_MASK) == EV_KEY_PRESSED )
-    {
-        switch (Event & KEY_MASK)
-        {
-        case KEY_DOWN:
-            CurrentFunc(SmallSettings);
-            return;
-        case KEY_UP:
-            CurrentFunc(PredefinedMenu);
-            return;
-        case KEY_ADC:
-            goto redraw;
 #if defined(CLOCK_ENABLED)
-        case KEY_CLOCK:
+      case KEY_CLOCK:
+      {
+        if ( TimerValue != 0 && RemainTimerValue != 0xFFFF )
         {
-            if ( TimerValue != 0 && RemainTimerValue != 0xFFFF )
-            {
-                DisplayClock(RemainTimerValue, 10+0x8000, Y_POSITION*3+X_POSITION*6);
-            }
-            else
-            {
-                LcdChr(Y_POSITION*3+X_POSITION*6+3, "" );
-                DisplayClock((RTC->CNTH<<16) + RTC->CNTL, 10, Y_POSITION*3+X_POSITION*9);
-            }
-            return;
+          DisplayClock(RemainTimerValue, 10+0x8000, Y_POSITION*3+X_POSITION*6);
         }
-#endif
-        case KEY_ENTER:/* Reserve current */
+        else
         {
-            MenuPos = 1; /* Key ENTER was pressed */
-            goto redraw;
-        }
+          LcdChr(Y_POSITION*3+X_POSITION*6+3, "" );
+          DisplayClock((RTC->CNTH<<16) + RTC->CNTL, 10, Y_POSITION*3+X_POSITION*9);
         }
+        return;
+      }
+#endif        
+      case KEY_ENTER:/* Reserve current */
+      {
+        MenuPos = 1; /* Key ENTER was pressed */
+        goto redraw;
+      }
     }
+  }
 
-    if ( (Event & EV_MASK) == EV_KEY_LONG )
+  if ( (Event & EV_MASK) == EV_KEY_LONG ) 
+  {
+    if ( CurrentSettings.VoltageDAC == DAC->DOR1 &&
+         CurrentSettings.CurrentDAC == DAC->DOR2 )
     {
-        if ( CurrentSettings.VoltageDAC == DAC->DOR1 &&
-                CurrentSettings.CurrentDAC == DAC->DOR2 )
-        {
-            /* Long key set OFF output */
-            DAC_V = 0;
-            DAC_I = 0;
-            MenuPos = 0; /* It is long press. The event was handled. No need do anything on key realized */
+      /* Long key set OFF output */
+      DAC_V = 0;
+      DAC_I = 0;
+      MenuPos = 0; /* It is long press. The event was handled. No need do anything on key realized */
 #if defined(CLOCK_ENABLED)
-            RemainTimerValue = 0;
+      RemainTimerValue = 0;
 #endif
-            return;
-        }
+      return;
+    }
 
-        /* Apply seved or set voltage and current */
-        MenuPos = 0;
+    /* Apply seved or set voltage and current */
+    MenuPos = 0;
 #if defined(CLOCK_ENABLED)
-        if (TimerValue != 0)
-        {
-            CurrentFunc(ApplyWithDelay);
-        }
-        else
-#endif
-        {
-            CurrentFunc(ApplyOut);
-        }
-        return;
+    if (TimerValue != 0)
+    {
+      CurrentFunc(ApplyWithDelay);
     }
-
-
-    if ( (Event& EV_MASK) == EV_KEY_REALIZED ) /* realised event current */
+    else
+#endif
     {
-        if (MenuPos) /* No long press */
-            CurrentFunc(SetNewVoltage);
-        return;
+      CurrentFunc(ApplyOut);
     }
-
+    return;   
+  }
+  
+
+  if ( (Event& EV_MASK) == EV_KEY_REALIZED ) /* realised event current */
+  {
+    if (MenuPos) /* No long press */
+      CurrentFunc(SetNewVoltage);
     return;
+  }
 
+  return;
+  
 redraw:
 #if defined(RAW)
-    if ( DisplayRaw == 0)
+  if ( DisplayRaw == 0)
 #endif
-    {
-        OutValue(1, 0, HumanV, CurrentConfig.V.DotPosition, 0xFF);
-        OutValue(4, 0, HumanI, CurrentConfig.I.DotPosition, 0xFF);
-        OutValueSmall(1, 9, VoltageFromDac(),
-                      CurrentConfig.V.DotPosition, CurrentSettings.VoltageDAC != DAC->DOR1);
-        OutValueSmall(5, 9, CurrentFromDac(),
-                      CurrentConfig.I.DotPosition, CurrentSettings.CurrentDAC != DAC->DOR2);
-    }
+  {
+    OutValue(1, 0, HumanV, CurrentConfig.V.DotPosition, 0xFF);
+    OutValue(4, 0, HumanI, CurrentConfig.I.DotPosition, 0xFF);
+    OutValueSmall(1, 9, VoltageFromDac(), 
+                  CurrentConfig.V.DotPosition, CurrentSettings.VoltageDAC != DAC->DOR1);
+    OutValueSmall(5, 9, CurrentFromDac(), 
+                  CurrentConfig.I.DotPosition, CurrentSettings.CurrentDAC != DAC->DOR2);
+  }
 #if defined(RAW)
-    else
-    {
-        OutValue(1, 0, ADCVoltage/(128*16), 4, 0xFF);
-        OutValue(4, 0, ADCCurrent/(128*16), 4, 0xFF);
-        OutValueSmall(1, 9, CurrentSettings.VoltageDAC, 4, CurrentSettings.VoltageDAC != DAC->DOR1);
-        OutValueSmall(5, 9, CurrentSettings.CurrentDAC, 4, CurrentSettings.CurrentDAC != DAC->DOR2);
-    }
+  else
+  {
+    OutValue(1, 0, ADCVoltage/(128*16), 4, 0xFF);
+    OutValue(4, 0, ADCCurrent/(128*16), 4, 0xFF);
+    OutValueSmall(1, 9, CurrentSettings.VoltageDAC, 4, CurrentSettings.VoltageDAC != DAC->DOR1);
+    OutValueSmall(5, 9, CurrentSettings.CurrentDAC, 4, CurrentSettings.CurrentDAC != DAC->DOR2);
+  }
 #endif
 }
 
 int16_t VoltageFromAdc(void)
 {
-    return ADCVoltage*CurrentConfig.V.ADCRamp + CurrentConfig.V.ADCOffset;
+  return ADCVoltage*CurrentConfig.V.ADCRamp + CurrentConfig.V.ADCOffset;
 }
 
 int16_t CurrentFromAdc(void)
 {
-    return ADCCurrent*CurrentConfig.I.ADCRamp + CurrentConfig.I.ADCOffset;
+  return ADCCurrent*CurrentConfig.I.ADCRamp + CurrentConfig.I.ADCOffset;
 }
 
 int16_t CurrentFromDac()
 {
-    return CurrentSettings.CurrentDAC*CurrentConfig.I.DACRamp + CurrentConfig.I.DACOffset;
+  return CurrentSettings.CurrentDAC*CurrentConfig.I.DACRamp + CurrentConfig.I.DACOffset;
 }
 int16_t VoltageFromDac()
 {
-    return CurrentSettings.VoltageDAC*CurrentConfig.V.DACRamp + CurrentConfig.V.DACOffset;
+  return CurrentSettings.VoltageDAC*CurrentConfig.V.DACRamp + CurrentConfig.V.DACOffset;
 }

Vissa filer visades inte eftersom för många filer har ändrats