Browse Source

Merge branch 'devel' of git.shilov.pp.ua:Heaven/MNC-IN2x5 into devel

Vladimir N. Shilov 2 years ago
parent
commit
280a7e49a2
5 changed files with 164 additions and 46 deletions
  1. 0 2
      .vscode/c_cpp_properties.json
  2. 1 0
      Inc/board.h
  3. 1 1
      Inc/clock.h
  4. 72 0
      Src/board.c
  5. 90 43
      Src/clock.c

+ 0 - 2
.vscode/c_cpp_properties.json

@@ -21,7 +21,6 @@
             "includePath": [
                 "${workspaceRoot}/Inc",
                 "${workspaceRoot}/Drivers/CMSIS/Include",
-                "${workspaceRoot}/Drivers/STM32G0xx_HAL_Driver/Inc",
                 "${workspaceRoot}/Drivers/CMSIS/Device/ST/STM32G0xx/Include",
                 "C:/MCU/gcc-arm/arm-none-eabi/include"
             ],
@@ -36,7 +35,6 @@
                     "${workspaceRoot}",
                     "${workspaceRoot}/Inc",
                     "${workspaceRoot}/Drivers/CMSIS/Include",
-                    "${workspaceRoot}/Drivers/STM32G0xx_HAL_Driver/Inc",
                     "${workspaceRoot}/Drivers/CMSIS/Device/ST/STM32G0xx/Include",
                     "C:/MCU/gcc-arm/arm-none-eabi/include",
                     "C:/MCU/gcc-arm/lib/gcc/arm-none-eabi/9.3.1/include",

+ 1 - 0
Inc/board.h

@@ -179,6 +179,7 @@ void Board_Init(void);
 void Blink_Start(void);
 void Blink_Stop(void);
 void showDigits(tube4_t dig);
+void slideDigits(tube4_t dig);
 void tube_PowerOn(tube_pos_t tube);
 void tube_PowerOff(tube_pos_t tube);
 void tube_BrightLevel(tube_pos_t tube, uint8_t bright);

+ 1 - 1
Inc/clock.h

@@ -57,7 +57,7 @@ typedef enum {
 #define BTN_TIME_REPEATED   50
 
 /* Display timeout, sec */
-#define DISP_WDT_TIME   10
+#define DISP_WDT_TIME   15
 
 /* variables */
 extern rtc_t Clock;

+ 72 - 0
Src/board.c

@@ -130,6 +130,78 @@ void showDigits(tube4_t dig)
   } // End of if-else
 }
 
+void lShiftDigits(tube4_t dig) {
+  uint32_t * buf;
+  uint8_t sbuf[12] = {0xf};
+  sbuf[4] = dig.ar[0];
+  sbuf[5] = dig.ar[1];
+  sbuf[6] = dig.ar[2];
+  sbuf[7] = dig.ar[3];
+
+  int i;
+  for (i=0; i<9; i++) {
+    buf = (uint32_t *)&sbuf[i];
+    _show_digits(* buf);
+    tdelay_ms(100);
+  }
+}
+
+void slideDigits(tube4_t dig) {
+  tube4_t buf;
+  const uint8_t pause = 100;;
+
+    buf.s8.tA = 0xf;
+    buf.s8.tB = 0xf;
+    buf.s8.tD = 0xf;
+    buf.s8.tE = 0xf;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tE = dig.s8.tA;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tD = dig.s8.tA;
+    buf.s8.tE = dig.s8.tB;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tB = dig.s8.tA;
+    buf.s8.tD = dig.s8.tB;
+    buf.s8.tE = dig.s8.tD;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tA = dig.s8.tA;
+    buf.s8.tB = dig.s8.tB;
+    buf.s8.tD = dig.s8.tD;
+    buf.s8.tE = dig.s8.tE;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tA = dig.s8.tB;
+    buf.s8.tB = dig.s8.tD;
+    buf.s8.tD = dig.s8.tE;
+    buf.s8.tE = 0xf;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tA = dig.s8.tD;
+    buf.s8.tB = dig.s8.tE;
+    buf.s8.tD = 0xf;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tA = dig.s8.tE;
+    buf.s8.tB = 0xf;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+
+    buf.s8.tA = 0xf;
+    _show_digits(buf.u32);
+    tdelay_ms(pause);
+}
+
 static void _show_digits(const uint32_t digits)
 {
   tube4_t dig;

+ 90 - 43
Src/clock.c

@@ -25,7 +25,9 @@ const uint8_t cie[MAX_BRIGHT_LVL + 1] = {
 };
 volatile static uint8_t dispWDT = 0;
 static in15_pin_t symToFade = 0;
-static uint8_t BrightLevel;
+static uint8_t LightingBright;
+static light_mode_t LightingMode;
+static uint8_t LightingColour;
 static flash_data_t Lighting, setLighting;
 
 /* function prototypes */
@@ -42,6 +44,7 @@ static void valIncrease(uint8_t * val, const uint8_t max);
 static void valDecrease(uint8_t * val, const uint8_t max);
 static void dvalIncrease(uint8_t * val, const uint8_t max);
 static void dvalDecrease(uint8_t * val, const uint8_t max);
+static void showRainbow(void);
 
 /* funcions */
 void Clock_Init(void) {
@@ -49,7 +52,7 @@ void Clock_Init(void) {
   showTime();
 
   flash_result_t flash_res = Flash_Read(&Lighting.u64);
-  if ( flash_res != Flash_Ok) {
+  if ((flash_res != Flash_Ok) || (Lighting.name.DayHour == 0xff)) {
     Lighting.name.DayHour = MORNING_HOUR;
     Lighting.name.NightHour = EVENING_HOUR;
     Lighting.name.DayBright = DAY_BR_LVL;
@@ -57,14 +60,6 @@ void Clock_Init(void) {
     Lighting.name.DayMode = light_Rainbow;
     Lighting.name.NightMode = light_Colour;
     Lighting.name.NightColour = COLOUR_NIXIE;
-  } else {
-    if (Lighting.name.DayHour == 0xff) {
-      /* launch set parameters
-      ES_SetState(stSetDayHour);
-      setDNbegin();
-      setDayHourBegin();
-      white (ES_GetState() != ???); */
-    }
   }
 
   check_DayNight();
@@ -73,14 +68,18 @@ void Clock_Init(void) {
 static void check_DayNight(void) {
   if ((Clock.Hr >= Lighting.name.DayHour) && (Clock.Hr < Lighting.name.NightHour)) {
     Flag.Now_Day = 1;
-    BrightLevel = cie[Lighting.name.DayBright];
+    LightingBright = cie[Lighting.name.DayBright];
+    LightingMode = Lighting.name.DayMode;
+    LightingColour = Lighting.name.DayColour;
   } else {
     Flag.Now_Day = 0;
-    BrightLevel = cie[Lighting.name.NightBright];
+    LightingBright = cie[Lighting.name.NightBright];
+    LightingMode = Lighting.name.NightMode;
+    LightingColour = Lighting.name.NightColour;
   }
 
-  tube_BrightLevel(Tube_All, BrightLevel);
-  //TUBES_BRIGHT(BrightLevel);
+  tube_BrightLevel(Tube_All, LightingBright);
+  TUBES_BRIGHT(LightingBright);
 }
 
 /**
@@ -378,14 +377,23 @@ static void HSV2LED(const uint8_t hue, const uint8_t val) {
   * Show info on tubes.
   */
 void showTime(void) {
+  uint8_t hue;
   MinusFadeIn();
   RTOS_SetTask(MinusFadeOut, 500, 0);
 
-  if (Flag.Now_Day != 0) {
-    uint8_t hue = bcd2bin(Clock.Sec);
-    HSV2LED(hue, BrightLevel);
-  } else {
-    HSV2LED(COLOUR_NIXIE, BrightLevel);
+  switch (LightingMode) {
+  case light_Rainbow:
+    hue = bcd2bin(Clock.Sec);
+    HSV2LED(hue, LightingBright);
+    break;
+
+  case light_Colour:
+    HSV2LED(LightingColour, LightingBright);
+    break;
+  
+  default:
+    LEDS_OFF;
+    break;
   }
 
   tube4_t buf;
@@ -393,7 +401,11 @@ void showTime(void) {
   buf.s8.tB = Clock.Hr & 0xf;
   buf.s8.tD = Clock.Min >> 4;
   buf.s8.tE = Clock.Min & 0xf;
-  showDigits(buf);
+  if (Clock.Min == 0) {
+    slideDigits(buf);
+  } else {
+    showDigits(buf);
+  }
 }
 
 void showMMSS(void) {
@@ -401,7 +413,7 @@ void showMMSS(void) {
   IN15_Minus;
 
   uint8_t hue = bcd2bin(Clock.Sec);
-  HSV2LED(hue, BrightLevel);
+  HSV2LED(hue, LightingBright);
 
   tube4_t buf;
   buf.s8.tA = Clock.Min >> 4;
@@ -448,8 +460,8 @@ void showYear(void) {
 }
 
 void showHumidity(void) {
-  dispWDT = DISP_WDT_TIME;
-  HSV2LED(COLOUR_BLUE, BrightLevel);
+  dispWDT = DISP_WDT_TIME/2;
+  HSV2LED(COLOUR_BLUE, LightingBright);
   symToFade = sym_Percent;
   IN15_FadeIn();
 
@@ -462,8 +474,8 @@ void showHumidity(void) {
 }
 
 void showTemperature(void) {
-  dispWDT = DISP_WDT_TIME;
-  HSV2LED(COLOUR_RED, BrightLevel);
+  dispWDT = DISP_WDT_TIME/2;
+  HSV2LED(COLOUR_RED, LightingBright);
   RTOS_DeleteTask(MinusFadeIn);
   RTOS_DeleteTask(MinusFadeOut);
   symToFade = sym_Plus;
@@ -478,8 +490,8 @@ void showTemperature(void) {
 }
 
 void showPressure(void) {
-  dispWDT = DISP_WDT_TIME;
-  HSV2LED(COLOUR_GREEN, BrightLevel);
+  dispWDT = DISP_WDT_TIME/2;
+  HSV2LED(COLOUR_GREEN, LightingBright);
   symToFade = sym_Pressure;
   IN15_FadeIn();
 
@@ -524,7 +536,7 @@ void setTimeShow(void) {
 void setTimeBegin(void) {
 	RTOS_DeleteTask(MinusFadeOut);
   in15Minus();
-  HSV2LED(COLOUR_NIXIE, BrightLevel);
+  HSV2LED(COLOUR_NIXIE, LightingBright);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   RTC_ReadAll(&setClock);
 }
@@ -577,7 +589,7 @@ void setTimeEnd(void) {
 
 void setDateBegin(void) {
   IN15_OFF;
-  HSV2LED(COLOUR_NIXIE, BrightLevel);
+  HSV2LED(COLOUR_NIXIE, LightingBright);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   RTC_ReadAll(&setClock);
 }
@@ -737,20 +749,22 @@ void showDNbright(void) {
 void showDNmode(void) {
 	dispWDT = DISP_WDT_TIME;
 
+  uint8_t dm, nm; 
   tube4_t buf;
   es_state_t e_st = ES_GetState();
 
   if (e_st == stShowDNmode){
-    buf.s8.tA = Lighting.name.DayMode / 10;
-    buf.s8.tB = Lighting.name.DayMode % 10;
-    buf.s8.tD = Lighting.name.NightMode / 10;
-    buf.s8.tE = Lighting.name.NightMode % 10;
+    dm = Lighting.name.DayMode;
+    nm = Lighting.name.NightMode;
   } else {
-    buf.s8.tA = setLighting.name.DayMode / 10;
-    buf.s8.tB = setLighting.name.DayMode % 10;
-    buf.s8.tD = setLighting.name.NightMode / 10;
-    buf.s8.tE = setLighting.name.NightMode % 10;
+    dm = setLighting.name.DayMode;
+    nm = setLighting.name.NightMode;
   }
+
+  buf.s8.tA = 0xf;
+  buf.s8.tB = dm & 0xf;
+  buf.s8.tD = 0xf;
+  buf.s8.tE = nm & 0xf;
   showDigits(buf);
 }
 
@@ -852,7 +866,7 @@ void setDayColourBegin(void) {
   Flag.Blink_4 = 0;
   Flag.Blink_5 = 0;
   Blink_Start();
-  HSV2LED(setLighting.name.DayColour, BrightLevel);
+  HSV2LED(setLighting.name.DayColour, LightingBright);
   showDNcolour();
 }
 
@@ -862,7 +876,7 @@ void setNightColourBegin(void) {
   Flag.Blink_4 = 1;
   Flag.Blink_5 = 1;
   Blink_Start();
-  HSV2LED(setLighting.name.NightColour, BrightLevel);
+  HSV2LED(setLighting.name.NightColour, LightingBright);
   showDNcolour();
 }
 
@@ -877,11 +891,16 @@ void setIncDayBright(void) {
 
 void setIncDayMode(void) {
   dvalIncrease(&setLighting.name.DayMode, MAX_LIGHT_MODE);
+  if (setLighting.name.DayMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 
 void setIncDayColour(void) {
   dvalIncrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.DayColour, BrightLevel);
+  HSV2LED(setLighting.name.DayColour, LightingBright);
 }
 
 void setDecDayHour(void) {
@@ -895,11 +914,16 @@ void setDecDayBright(void) {
 
 void setDecDayMode(void) {
   dvalDecrease(&setLighting.name.DayMode, MAX_LIGHT_MODE);
+  if (setLighting.name.DayMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 
 void setDecDayColour(void) {
   dvalDecrease(&setLighting.name.DayColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.DayColour, BrightLevel);
+  HSV2LED(setLighting.name.DayColour, LightingBright);
 }
 
 void setIncNightHour(void) {
@@ -913,11 +937,16 @@ void setIncNightBright(void) {
 
 void setIncNightMode(void) {
   dvalIncrease(&setLighting.name.NightMode, MAX_LIGHT_MODE);
+  if (setLighting.name.NightMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 
 void setIncNightColour(void) {
   dvalIncrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.NightColour, BrightLevel);
+  HSV2LED(setLighting.name.NightColour, LightingBright);
 }
 
 void setDecNightHour(void) {
@@ -931,11 +960,16 @@ void setDecNightBright(void) {
 
 void setDecNightMode(void) {
   dvalDecrease(&setLighting.name.NightMode, MAX_LIGHT_MODE);
+  if (setLighting.name.NightMode == light_Rainbow) {
+    RTOS_SetTask(showRainbow, 0, 20);
+  } else {
+    RTOS_DeleteTask(showRainbow);
+  }
 }
 
 void setDecNightColour(void) {
   dvalDecrease(&setLighting.name.NightColour, MAX_COLOR_VAL);
-  HSV2LED(setLighting.name.NightColour, BrightLevel);
+  HSV2LED(setLighting.name.NightColour, LightingBright);
 }
 
 void setDNbreak(void) {
@@ -994,3 +1028,16 @@ static void dvalDecrease(uint8_t * val, uint8_t max) {
     *val = max;
   }
 }
+
+static void showRainbow(void) {
+  static uint8_t hue = 0;
+
+  HSV2LED(hue, LightingBright);
+
+  if (hue < 59) {
+    hue ++;
+  } else {
+    hue = 0;
+    RTOS_DeleteTask(showRainbow);
+  }
+}