浏览代码

Added Time set-up, Blinking.

Vladimir N. Shilov 2 年之前
父节点
当前提交
f095d4b64a
共有 9 个文件被更改,包括 159 次插入75 次删除
  1. 8 0
      Inc/clock.h
  2. 6 5
      Inc/event-system.h
  3. 1 0
      Inc/list_event.h
  4. 0 14
      Inc/main.h
  5. 6 5
      Src/board.c
  6. 122 3
      Src/clock.c
  7. 11 9
      Src/event-system.c
  8. 1 36
      Src/main.c
  9. 4 3
      Src/stm32g0xx_it.c

+ 8 - 0
Inc/clock.h

@@ -11,6 +11,13 @@
 #define FADE_STOP       15
 #define FADE_STEP       1
 
+/* time constant in ms */
+#define BTN_SCAN_PERIOD     10
+#define BTN_SCAN_PAUSE      200
+#define BTN_TIME_PRESSED    30
+#define BTN_TIME_HOLDED     500
+#define BTN_TIME_REPEATED   50
+
 /* Display timeout, sec */
 #define DISP_WDT_TIME   10
 
@@ -18,6 +25,7 @@
 extern rtc_t Clock;
 
 /* function prototypes */
+//void Clock_Init(void);
 void btnProcess(void);
 void new_Second(void);
 

+ 6 - 5
Inc/event-system.h

@@ -35,6 +35,7 @@ void in15Percent(void);
 void in15P(void);
 
 void showTime(void);
+void showMMSS(void);
 void showWD(void);
 void showDay(void);
 void showMonth(void);
@@ -46,11 +47,6 @@ void showTemperature(void);
 void showPressure(void);
 void showSensorData(void);
 
-/*
-void showBright(void);
-void incBright(void);
-void decBright(void);
-
 void setTimeShow(void);
 void setTimeBegin(void);
 void setHHBegin(void);
@@ -61,6 +57,7 @@ void setMMInc(void);
 void setMMDec(void);
 void setTimeEnd(void);
 
+/*
 void setDateBegin(void);
 void setDateEnd(void);
 void setWDMShow(void);
@@ -77,6 +74,10 @@ void setDecWDay(void);
 void setDecMDay(void);
 void setDecMonth(void);
 void setDecYear(void);
+
+void showBright(void);
+void incBright(void);
+void decBright(void);
 */
 
 #endif /* EVENT_SYSTEM_H */

+ 1 - 0
Inc/list_event.h

@@ -22,6 +22,7 @@ typedef enum {
 typedef enum {
   stNoChange = 0x00,
   stShowTime,
+  stShowMMSS,
   stShowWDay,
   stShowMDay,
   stShowMon,

+ 0 - 14
Inc/main.h

@@ -101,20 +101,6 @@ typedef union {
 void Error_Handler(void);
 
 /* Private defines -----------------------------------------------------------*/
-/* time constant in ms */
-#define BTN_SCAN_PERIOD     10
-#define BTN_SCAN_PAUSE      200
-#define BTN_TIME_PRESSED    30
-#define BTN_TIME_HOLDED     500
-#define BTN_TIME_REPEATED   50
-
-typedef struct {
-  uint8_t     time;
-  es_event_t  pressed;
-  es_event_t  holded;
-  uint32_t    pin;
-  //(GPIO_TypeDef *) GPIOA; // ?->IDR
-} btn_t;
 
 #ifdef __cplusplus
 }

+ 6 - 5
Src/board.c

@@ -91,8 +91,8 @@ void Board_Init(void)
   /* Start RGB & Tube Power PWM */
   TIM1_Init();
   TIM3_Init();
-
-  //TIM14_Init();
+  /* Blink timer */
+  TIM14_Init();
 
   //TIM16_Init();
   //TIM17_Init();
@@ -612,8 +612,8 @@ static void TIM14_Init(void)
   TIM14->CCR1 = TIM14_PULSE_VAL;
 
   /* Enable IRQ for Update end CaptureCompare envents or only CC ??? */
-  //TIM14->DIER = (TIM_DIER_UIE | TIM_DIER_CC1IE);
-  TIM14->DIER = TIM_DIER_CC1IE;
+  TIM14->DIER = (TIM_DIER_UIE | TIM_DIER_CC1IE);
+  //TIM14->DIER = TIM_DIER_CC1IE;
 }
 
 /**
@@ -624,7 +624,8 @@ void Blink_Start(void)
   /* enable all channels */
   TUBE_ALL_ON;
 
-  /* clear IRQ flag */
+  /* clear IRQ flags */
+  TIM14->SR |= TIM_SR_UIF;
   TIM14->SR |= TIM_SR_CC1IF;
 
   /* clear counter value */

+ 122 - 3
Src/clock.c

@@ -1,7 +1,17 @@
 #include "clock.h"
 
+/* type defs */
+typedef struct {
+  uint8_t     time;
+  es_event_t  pressed;
+  es_event_t  holded;
+  uint32_t    pin;
+  //(GPIO_TypeDef *) GPIOA; // ?->IDR
+} btn_t;
+
 /* variables */
 rtc_t Clock;
+static rtc_t setClock;
 static btn_t Button[BTN_NUM] = {
   {0, evBTN1Pressed, evBTN1Holded,  BTN1_PIN},
   {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
@@ -19,6 +29,8 @@ static void PercentFadeIn(void);
 static void PressureFadeIn(void);
 //static void IN15_FadeIn(in15_pin_t pin);
 //static void IN15_FadeOut(in15_pin_t pin);
+static void valIncrease(uint8_t * val, uint8_t max);
+static void valDecrease(uint8_t * val, uint8_t max);
 
 /* funcions */
 /**
@@ -279,12 +291,21 @@ void showTime(void) {
   HSV2LED(hue, 255, cie[Lvl_Mdl]);
 
   tube4_t buf;
-/*
   buf.s8.tA = Clock.Hr >> 4;
   buf.s8.tB = Clock.Hr & 0xf;
   buf.s8.tD = Clock.Min >> 4;
   buf.s8.tE = Clock.Min & 0xf;
-*/
+  showDigits(buf);
+}
+
+void showMMSS(void) {
+  RTOS_DeleteTask(MinusFadeOut);
+  IN15_Minus;
+
+  uint8_t hue = bcd2bin(Clock.Sec);
+  HSV2LED(hue, 255, cie[Lvl_Mdl]);
+
+  tube4_t buf;
   buf.s8.tA = Clock.Min >> 4;
   buf.s8.tB = Clock.Min & 0xf;
   buf.s8.tD = Clock.Sec >> 4;
@@ -398,7 +419,6 @@ void showPressure(void) {
 
 /* Simple function for cyclic show all sensor data */
 void showSensorData(void) {
-  ES_SetState(stShowSensorData);
   RTOS_DeleteTask(MinusFadeOut);
   //HSV2LED(1, 255, cie[Lvl_Mdl]); // Nixie color
 
@@ -417,3 +437,102 @@ void showSensorData(void) {
   ES_SetState(stShowTime);
 //  showTime();
 }
+
+void setTimeShow(void) {
+  MinusFadeIn();
+  RTOS_SetTask(MinusFadeOut, 500, 0);
+
+  uint8_t hue = bcd2bin(Clock.Sec);
+  HSV2LED(hue, 255, cie[Lvl_Mdl]);
+
+  tube4_t buf;
+  buf.s8.tA = Clock.Hr >> 4;
+  buf.s8.tB = Clock.Hr & 0xf;
+  buf.s8.tD = Clock.Min >> 4;
+  buf.s8.tE = Clock.Min & 0xf;
+  showDigits(buf);
+}
+
+void setTimeBegin(void) {
+  RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
+  RTC_ReadAll(&setClock);
+}
+
+void setHHBegin(void) {
+  Flag.Blink_1 = 1;
+  Flag.Blink_2 = 1;
+  Flag.Blink_4 = 0;
+  Flag.Blink_5 = 0;
+  Blink_Start();
+  setTimeShow();
+}
+
+void setHHInc(void) {
+  valIncrease(&setClock.Hr, 23);
+}
+
+void setHHDec(void) {
+  valDecrease(&setClock.Hr, 23);
+}
+
+void setMMBegin(void) {
+  Flag.Blink_1 = 0;
+  Flag.Blink_2 = 0;
+  Flag.Blink_4 = 1;
+  Flag.Blink_5 = 1;
+  Blink_Start();
+  setTimeShow();
+}
+
+void setMMInc(void) {
+  valIncrease(&setClock.Min, 59);
+}
+
+void setMMDec(void) {
+  valDecrease(&setClock.Min, 59);
+}
+
+void setTimeEnd(void) {
+  RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
+
+  setClock.Sec = 0;
+  RTC_WriteTime(&setClock);
+
+  Flag.Blink_1 = 0;
+  Flag.Blink_2 = 0;
+  Flag.Blink_4 = 0;
+  Flag.Blink_5 = 0;
+  Blink_Stop();
+
+  RTC_ReadAll(&Clock);
+}
+
+/**
+  * @brief  Increase BCD value.
+  * @param  : val, max
+  * @retval : None
+  */
+static void valIncrease(uint8_t * val, uint8_t max) {
+  uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
+  if (bin < max) {
+    bin ++;
+  } else {
+    bin = 0;
+  }
+  *val = ((bin / 10 ) << 4) | (bin % 10);
+}
+
+/**
+  * @brief  Decrease BCD value.
+  * @param  : value, max
+  * @retval : None
+  */
+static void valDecrease(uint8_t * val, uint8_t max) {
+  uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
+  if (bin > 0) {
+    bin --;
+  } else {
+    bin = max;
+  }
+  *val = ((bin / 10 ) << 4) | (bin % 10);
+}

+ 11 - 9
Src/event-system.c

@@ -36,7 +36,10 @@ const table_state_t stateTable[] = {
   {stShowWDay, evBTN1Pressed, stShowDM,   showDayMon, NULL},
   {stShowDM,   evBTN1Pressed, stShowYear, showYear,   NULL},
   {stShowYear, evBTN1Pressed, stShowTime, showTime,   NULL},
+  {stShowTime, evBTN2Pressed, stShowMMSS, showMMSS,   NULL},
+  {stShowMMSS, evBTN2Pressed, stShowTime, showTime,   NULL},
   {stShowTime, evBTN4Pressed, stShowSensorData, showSensorData, NULL},
+  {stShowSensorData, evBTN4Pressed, stShowTime, showTime, NULL},
 
   /* display wdt */
   {stShowWDay,        evDisplayWDT, stShowTime, showTime, NULL},
@@ -44,21 +47,20 @@ const table_state_t stateTable[] = {
   {stShowMDay,        evDisplayWDT, stShowTime, showTime, NULL},
   {stShowMon,         evDisplayWDT, stShowTime, showTime, NULL},
   {stShowYear,        evDisplayWDT, stShowTime, showTime, NULL},
-  {stShowBright,      evDisplayWDT, stShowTime, showTime, NULL},
+  //{stShowBright,      evDisplayWDT, stShowTime, showTime, NULL},
   {stShowHumidity,    evDisplayWDT, stShowTime, showTime, NULL},
   {stShowTemperature, evDisplayWDT, stShowTime, showTime, NULL},
   {stShowPressure,    evDisplayWDT, stShowTime, showTime, NULL},
 
   /* refresh output */
   {stShowTime, evNewSecond,  stNoChange, showTime,   NULL},
+  {stShowMMSS, evNewSecond,  stNoChange, showMMSS,   NULL},
   {stShowWDay, evRefreshCal, stNoChange, showWD,     NULL},
   {stShowDM,   evRefreshCal, stNoChange, showDayMon, NULL},
   {stShowMDay, evRefreshCal, stNoChange, showDay,    NULL},
   {stShowMon,  evRefreshCal, stNoChange, showMonth,  NULL},
   {stShowYear, evRefreshCal, stNoChange, showYear,   NULL},
-
-  #ifdef BLAH_BLAH_BLAH
-  {stShowYear,   evBTN1Pressed, stShowBright, showBright, NULL},
+//  {stShowYear,   evBTN1Pressed, stShowBright, showBright, NULL},
   {stShowBright, evBTN1Pressed, stShowTime,   showTime,   NULL},
 
   /* set time */
@@ -79,6 +81,7 @@ const table_state_t stateTable[] = {
   {stSetMM,    evDisplayWDT,  stShowTime, showTime,     NULL},
 
   /* set calendar */
+/*
   {stShowWDM, evBTN1Holded,  stSetWDay,  setDateBegin,  setWDayBegin},
   {stSetWDay, evBTN1Holded,  stShowWDM,  setDateEnd,    showWDM},
   {stSetMDay, evBTN1Holded,  stShowWDM,  setDateEnd,    showWDM},
@@ -102,7 +105,7 @@ const table_state_t stateTable[] = {
   {stSetMDay, evDisplayWDT, stShowTime, showTime, NULL},
   {stSetMon,  evDisplayWDT, stShowTime, showTime, NULL},
   {stSetYear, evDisplayWDT, stShowTime, showTime, NULL},
-  /*
+
   {stShowWDay, evBTN3Pressed, stNoChange, incWDay,  showWDM},
   {stShowMDay, evBTN3Pressed, stNoChange, incMDay,  showWDM},
   {stShowMon,  evBTN3Pressed, stNoChange, incMonth, showWDM},
@@ -111,11 +114,10 @@ const table_state_t stateTable[] = {
   {stShowMDay, evBTN2Pressed, stNoChange, decMDay,  showWDM},
   {stShowMon,  evBTN2Pressed, stNoChange, decMonth, showWDM},
   {stShowYear, evBTN2Pressed, stNoChange, decYear,  showYear},
-  */
+*/
   /* set bright */
-  {stShowBright, evBTN3Pressed, stNoChange, incBright, showBright},
-  {stShowBright, evBTN2Pressed, stNoChange, decBright, showBright},
-  #endif // BLAH_BLAH_BLAH
+//  {stShowBright, evBTN3Pressed, stNoChange, incBright, showBright},
+//  {stShowBright, evBTN2Pressed, stNoChange, decBright, showBright},
   /* mandatory empty table row */
   {stNoChange, eventNull, stNoChange, EmptyFunc, EmptyFunc}
 };

+ 1 - 36
Src/main.c

@@ -1,4 +1,3 @@
-/* USER CODE BEGIN Header */
 /**
   ******************************************************************************
   * @file           : main.c
@@ -16,39 +15,19 @@
   *
   ******************************************************************************
   */
-/* USER CODE END Header */
+
 /* Includes ------------------------------------------------------------------*/
 #include "main.h"
 
 /* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-/* USER CODE END Includes */
-
 /* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN PTD */
-/* USER CODE END PTD */
-
 /* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-/* USER CODE END PD */
-
 /* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-/* USER CODE END PM */
-
 /* Private variables ---------------------------------------------------------*/
-/* USER CODE BEGIN PV */
 volatile flag_t Flag = {0};
-/* USER CODE END PV */
 
 /* Private function prototypes -----------------------------------------------*/
-/* USER CODE BEGIN PFP */
-/* USER CODE END PFP */
-
 /* Private user code ---------------------------------------------------------*/
-/* USER CODE BEGIN 0 */
-
-/* USER CODE END 0 */
 
 /**
   * @brief  The application entry point.
@@ -67,8 +46,6 @@ int main(void)
   ES_Init(stShowTime);
 
   /* Init devices at I2C bus */
-//  RTC_Init();
-//  tdelay_ms(10);
   RTC_Init();
   sensor_Init();
 
@@ -80,7 +57,6 @@ int main(void)
   /** Set tasks for Sheduler */
   RTOS_SetTask(btnProcess, 1, BTN_SCAN_PERIOD);
 
-  /* USER CODE BEGIN WHILE */
   /* Infinite loop */
   while (1)
   {
@@ -89,9 +65,7 @@ int main(void)
       Flag.RTC_IRQ = 0;
       new_Second();
     } /* end of New second */
-    /* USER CODE END WHILE */
 
-    /* USER CODE BEGIN 3 */
     event = ES_GetEvent();
     if (event) {
       ES_Dispatch(event);
@@ -101,26 +75,19 @@ int main(void)
 
     __WFI();
   }
-  /* USER CODE END 3 */
 } /* End of mine() */
 
-/* USER CODE BEGIN 4 */
-
-/* USER CODE END 4 */
-
 /**
   * @brief  This function is executed in case of error occurrence.
   * @retval None
   */
 void Error_Handler(void)
 {
-  /* USER CODE BEGIN Error_Handler_Debug */
   /* User can add his own implementation to report the HAL error return state */
   __disable_irq();
   while (1)
   {
   }
-  /* USER CODE END Error_Handler_Debug */
 }
 
 #ifdef  USE_FULL_ASSERT
@@ -133,10 +100,8 @@ void Error_Handler(void)
   */
 void assert_failed(uint8_t *file, uint32_t line)
 {
-  /* USER CODE BEGIN 6 */
   /* User can add his own implementation to report the file name and line number,
      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
-  /* USER CODE END 6 */
 }
 #endif /* USE_FULL_ASSERT */
 

+ 4 - 3
Src/stm32g0xx_it.c

@@ -159,13 +159,15 @@ void TIM14_IRQHandler(void)
   if ((TIM14->SR & TIM_SR_UIF) != 0) {
     /* Update interrupt flag */
     TIM14->SR |= TIM_SR_UIF;
+
+    /* enable all channels */
+    TUBE_ALL_ON;
   }
   if ((TIM14->SR & TIM_SR_CC1IF) != 0) {
-    /* Capture/Compare Interrupt */
+    /* Capture/Compare Interrupt flag */
     TIM14->SR |= TIM_SR_CC1IF;
 
     /* disable unneeded channel */
-/*
     if (Flag.Blink_1 != 0) {
       TUBE_A_OFF;
     }
@@ -181,7 +183,6 @@ void TIM14_IRQHandler(void)
     if (Flag.Blink_5 != 0) {
       TUBE_E_OFF;
     }
-*/
   }
 }